Howto:Initialise a Mega Drive

From MegaDrive Wiki
Revision as of 19:51, 7 September 2011 by Tristanseifert (talk | contribs)
Jump to: navigation, search

Before you can start running your game's program on the Mega Drive, you will need to initialize it first. Initializing a Mega Drive is usually the first thing you do in your code, and involves things such as writing to the TMSS register to activate the VDP, clearing RAM, initializing controller ports, and the Z80. Optionally, you can also initialize some VDP registers for use later in your code, although you may choose to do that again every screen mode.

Header

Every Mega Drive game has a header at the first 200h bytes of it's ROM. The TMSS checks a specific address in it for the text "SEGA" and then loads your game's code. Early Model 1 Mega Drives do not have a TMSS - but you still need to have "SEGA" in your header. The header's format is like the one below:

<source lang="asm" line="GESHI_FANCY_LINE_NUMBERS">

Vectors: dc.l $FFFE00, EntryPoint, BusError, AddressError dc.l IllegalInstr, ZeroDivide, ChkInstr, TrapvInstr dc.l PrivilegeViol, Trace, Line1010Emu, Line1111Emu dc.l ErrorExcept, ErrorExcept, ErrorExcept, ErrorExcept dc.l ErrorExcept, ErrorExcept, ErrorExcept, ErrorExcept dc.l ErrorExcept, ErrorExcept, ErrorExcept, ErrorExcept dc.l ErrorExcept, ErrorTrap, ErrorTrap, ErrorTrap dc.l Hint, ErrorTrap, VBlank, ErrorTrap dc.l ErrorTrap, ErrorTrap, ErrorTrap, ErrorTrap dc.l ErrorTrap, ErrorTrap, ErrorTrap, ErrorTrap dc.l ErrorTrap, ErrorTrap, ErrorTrap, ErrorTrap dc.l ErrorTrap, ErrorTrap, ErrorTrap, ErrorTrap dc.l ErrorTrap, ErrorTrap, ErrorTrap, ErrorTrap dc.l ErrorTrap, ErrorTrap, ErrorTrap, ErrorTrap dc.l ErrorTrap, ErrorTrap, ErrorTrap, ErrorTrap dc.l ErrorTrap, ErrorTrap, ErrorTrap, ErrorTrap Console: dc.b 'SEGA MEGA DRIVE ' ; Hardware system ID Date: dc.b '(C)XXXX YEAR.MON' ; Release date Title_Local: dc.b 'YOUR GAME TITLE WILL GO HERE... MEEEEEEEEEEEEEP!' ; Domestic name Title_Int: dc.b 'YOUR GAME TITLE WILL GO HERE... MEEEEEEEEEEEEEP!' ; International name Serial: dc.b 'GM 10101010-00' ; Serial/version number Checksum: dc.w 0 dc.b 'J ' ; I/O support RomStartLoc: dc.l StartOfRom ; ROM start RomEndLoc: dc.l EndOfRom-1 ; ROM end RamStartLoc: dc.l $FF0000 ; RAM start RamEndLoc: dc.l $FFFFFF ; RAM end SRAMSupport: dc.l $5241F820 ; change to $5241F820 (NOT $5241E020) to create SRAM dc.l $200000 ; SRAM start dc.l $200200 ; SRAM end (Gives us $200 ($100 useable) bytes of SRAM) Notes: dc.b ' ' Region: dc.b 'JUE ' ; Region </source>