Genesis Programming/Printable version
This is the print version of Genesis Programming You won't see this message or any elements not part of the book's content when you print or preview this page. |
The current, editable version of this book is available in Wikibooks, the open-content textbooks collection, at
https://en.wikibooks.org/wiki/Genesis_Programming
68000 programming considerations
68000 programming considerations
editROM header
editThe ROM header starts at $000100
and contains information about the cartridge. The following assembly code shows how to declare the header:
- dc.b "SEGA GENESIS"
- dc.b "(C)SEGA 1992.SEP"
- dc.b "YOUR GAME HERE"
- dc.b "YOUR GAME HERE"
- dc.b "GM XXXXXXXX-XX"
- dc.w $D951
- dc.b "J"
- dc.l 0
- dc.l ROM_End
- dc.l $FF0000
- dc.l $FFFFFF
- dc.b (Blank)
- dc.b (Blank)
- dc.b (Blank)
- dc.b (Blank)
- dc.b (Blank)
- dc.b "JUE"
Explanations for each field:
- The name of the console. Should be either "SEGA GENESIS" or "SEGA MEGA DRIVE" (depending on the region you are planning to program your game for). Must be 16 characters long.
- Firm name and build date. Must be 16 characters long, firm name is four characters long.
- Domestic name. Must be 48 characters long.
- International name. Must be 48 characters long.
- Program type and serial number. First two characters are either "GM" (game) or "AL" (educational). After the space, a series of eight digits gives the serial number. The final two digits give the version number.
- Checksum.
- I/O device support (unused)
- Start of the ROM. This should always be 0.
- End of the ROM. It's best to use a label at the end of your source file to determine this.
- Start of RAM. Just about every game starts at $FF0000, but RAM is mirrored at several other places, and you can use those if you want.
- End of RAM. Should be $FFFF after the starting point.
- Backup RAM ID. Fill this with spaces if there is none, otherwise, use this formula:
dc.b "RA",%1x1yy000,%0010000
where x is true when the RAM is for backup and false if not. (I've no idea what the difference is.) yy is 11 if addressing is odd bytes only, 10 if even only, and 00 if both. - Start address of backup RAM. Fill with spaces if there is no backup RAM.
- End address of backup RAM.
- Modem support. Fill with spaces if there is no modem, otherwise follow this formula:
"MOxxxxyy.zzz"
where xxxx is the firm name, yy is the modem number, and zzz is the version number. (This is also unused) - Notes. Put whatever you want here, and fill the empty spaces with zeroes.
- Country codes. J is for Japan, U is for the United States, and E is for Europe. You need to fill in the rest of this field with spaces. So, JU for the country code would tell the Sega that the game is for Japan and the US, JUE would tell it that it is for Japan, the US, and Europe
TMSS
editBack in 1990, Accolade released a few unlicensed games for the Genesis. Sega was not pleased about this, so they invented TMSS and put it on all new consoles they manufactured. TMSS forces the game to write the ASCII string "SEGA" to $A14000 within a short period of time, or the VDP will be deactivated. On version 0 of the console, this location is reserved, and writing here may cause a crash, so the game has to first make sure that it's running on a console that has TMSS. Sega uses the following routine for that:
move.b $A10001,d0 andi.b #$0F,d0 beq.b version_0 move.l #'SEGA',$A14000 version_0:
Checksum
editThe checksum is a 16-bit number (word) located in the header which is present in all licensed games.It was used to check the integrity of the data by storing a pre-calculated number (the checksum) using the original data and comparing it with the checksum of the existing data in the cart, probably to prevent code changes without authorization (in-house).
The checksum is, basically, the sum of the whole cart, all its bytes, starting at address $200. As you can guess, if only a byte is changed the checksum changes too. Somewhat like the CRC/CRC32 algorithms, though those are much more accurate than this method.
You don't need to implement the checksum if you program your own homebrew rom, because the checksum is exclusively checked by software. But, anyway, this is how a typical checksum routine from a licensed game would look.
movea.l #$200,a0 movea.l #ROM_End,a1 move.l (a1),d0 moveq #0,d1 loop: add.w (a0)+,d1 cmp.l a0,d0 bcc.s loop movea.l #$18E,a1 ; Checksum cmp.w (a1),d1 bne.w WrongChecksum
To disable it, comment out that last branch. If you prefer to fix the checksum, grab the Fix Checksum utility from Hacking CulT's download section.
Z80 programming considerations
Memory map
editStart | End | Description |
---|---|---|
0000h | 1FFFh | Z80 RAM |
2000h | 3FFFh | Reserved |
4000h | YM2612 A0 | |
4001h | YM2612 D0 | |
4002h | YM2612 A1 | |
4003h | YM2612 D1 | |
4004h | 5FFFh | Reserved |
6000h | Bank register | |
6001h | 7F10h | Reserved |
7F11h | PSG | |
7F12h | 7FFFh | Reserved |
8000h | FFFFh | 68000 memory bank |
Z80 Architecture
editRead more
editThere is a separate Wikibook on Z80 Assembly.