![]() |
![]() |
Sega Megadrive Assembly Programming BasicsCopyright, Lewis Bassett, December 2005
Section 4 - Padding the ROM The Sega Megadrive requires that all ROMs are a vallid size, otherwise the BIOS will reject it. We can pad out the final ROM with 'FF's by using assembler directives. This allows us to make sure that the final ROM is a vallid size, so that the Megadrive will recognise it and accept it. The Megadrive BIOS requires that all ROMs are a size that is to the power of two. For example, 32 Kilobytes, or 64 Kilobytes is acceptable. Any size which is greater than a power of two value, but less than the next power of two value is invallid, and will be rejected. We can pad our ROMs by using the 'org' directive. The ORG directive works by skipping to a certain address, so that anything that is defined and assembled afterwards is from then on. The ORG directive is used along with an address (in bytes) to skip to. Simply multiply the (vallid) number of kilobytes you want you ROM to be, with 1024. This will give you the ammount of bytes to skip to. I also like to convert the number to hexadecimal (using a calculator), as it's alot neater. After the ORG directive, you simple define some blank data (since the ORG statement actually means, 'put everything after this address'. Here's an example of padding the ROM to 128 Kilobytes: org $20000-2; $20000 is 131072, which when divided by 1024 is 128. dc.w $ffff; ROMEnd:Notice how I've instructed the assembler to subtract two from the address I want to pad to. This is because I also need to leave room to define a word (two bytes), as blank data. If I didn't do this, my ROM would be two bytes larger that 128 Kilobytes, and so would be an invallid size. One last thing. Remember in the header we inserted a reference to the code label 'ROMEnd' for the address of the end of the ROM. To make sure the correct value gets stored, we need to insert the code label 'ROMEnd' at the end of our ROM, which I've done. In the next section, I'll bring everything together and show you a template for a working Megadrive program. |