Page 1 of 1

Clearing the RAM really needed?

Posted: Wed Nov 11, 2015 10:54 am
by M-374 LX
Knowing that no RAM address is supposed to be read before being initialized, is it really necessary to clear the entire RAM during the startup instead of simply initializing the used RAM addresses at the proper moment?

The same is supposed for CPU registers.

Re: Clearing the RAM really needed?

Posted: Wed Nov 11, 2015 1:35 pm
by Sik
No, and given you're going to explicitly reinitialize all variables anyway (e.g. what happens when you get a game over? the game will reset to the title screen but RAM won't be clear!), it's pretty pointless in practice. It only encourages lazy programming practices =P

What could help during debugging is maybe filling it with something like 0xDEADBEEF, then when you try to touch uninitialized RAM at least it's easier to see with a debugger. But that's it, really.

Re: Clearing the RAM really needed?

Posted: Wed Nov 11, 2015 7:16 pm
by BigEvilCorporation
For me it was just an educational exercise when I was learning, and one that doesn't require any of the other chips to be initialised first. It was an indication that something was working, and a small block of code demonstrating some basic 68000 concepts like moves, loops, and labels.

The 0xDEADBEEF trick is used in software development all over the place, custom allocators in C/C++ can write this value to freed blocks to help catch bad writes, etc. I'm sure there's some advantages to it in ASM somewhere.

A better use of your time would be to learn how to write a custom exception handler. A basic one just needs a hard coded font with the chars 0123456789ADCDEF and a way to display the exception type ID and registers.

Re: Clearing the RAM really needed?

Posted: Thu Nov 12, 2015 12:22 am
by TmEE co.(TM)
I would say it is a good practice to clear out the RAM with a known value. I have been teaching a friend MD programming and half the time he forgets to initialize his variables and then things fail to run on the hardware.

Re: Clearing the RAM really needed?

Posted: Fri Nov 13, 2015 11:11 am
by Natsumi
its not necessary at the least, but you save yourself a lot of unnecessary headache by clearing the RAM anyway.

Re: Clearing the RAM really needed?

Posted: Fri Nov 13, 2015 5:16 pm
by r57shell
RAM/VRAM clearing is not necessary, but initializing variables/memory is necessary. By default whole memory is filled by some trash, except if you run code after TMSS