Clearing the RAM really needed?

Ask anything your want about Megadrive/Genesis programming.

Moderator: BigEvilCorporation

Post Reply
M-374 LX
Very interested
Posts: 60
Joined: Mon Aug 11, 2008 10:15 pm
Contact:

Clearing the RAM really needed?

Post by M-374 LX » Wed Nov 11, 2015 10:54 am

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.

Sik
Very interested
Posts: 901
Joined: Thu Apr 10, 2008 3:03 pm
Contact:

Re: Clearing the RAM really needed?

Post by Sik » Wed Nov 11, 2015 1:35 pm

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.
Sik is pronounced as "seek", not as "sick".

BigEvilCorporation
Very interested
Posts: 209
Joined: Sat Sep 08, 2012 10:41 am
Contact:

Re: Clearing the RAM really needed?

Post by BigEvilCorporation » Wed Nov 11, 2015 7:16 pm

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.
A blog of my Megadrive programming adventures: http://www.bigevilcorporation.co.uk

TmEE co.(TM)
Very interested
Posts: 2378
Joined: Tue Dec 05, 2006 1:37 pm
Location: Estonia, Rapla City
Contact:

Re: Clearing the RAM really needed?

Post by TmEE co.(TM) » Thu Nov 12, 2015 12:22 am

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.
Mida sa loed ? Nagunii aru ei saa ;)
http://www.tmeeco.eu
Files of all broken links and images of mine are found here : http://www.tmeeco.eu/FileDen

Natsumi
Very interested
Posts: 81
Joined: Mon Oct 05, 2015 3:00 pm
Location: 0x0
Contact:

Re: Clearing the RAM really needed?

Post by Natsumi » Fri Nov 13, 2015 11:11 am

its not necessary at the least, but you save yourself a lot of unnecessary headache by clearing the RAM anyway.

r57shell
Very interested
Posts: 478
Joined: Sun Dec 23, 2012 1:30 pm
Location: Russia
Contact:

Re: Clearing the RAM really needed?

Post by r57shell » Fri Nov 13, 2015 5:16 pm

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
Image

Post Reply