Difference between revisions of "Howto:Initialise a Mega Drive"

From MegaDrive Wiki
Jump to: navigation, search
Line 39: Line 39:
 
Region: dc.b 'JUE            ' ; Region
 
Region: dc.b 'JUE            ' ; Region
 
</source>
 
</source>
 +
 +
The first long in the header is what the CPU will initialize the stack pointer to, and the second long tells it where to start to execute your code. The other entries there should be self explanatory for the different exceptions that can occur, and some games write handlers for them. The rest of the longs that point to 'ErrorTrap' are all unused traps and exceptions, so they point to an endless loop. Note that you must have your 'Hardware system ID' start with 'SEGA' for Model 2 and 3 Mega Drives to load your game.
 +
 +
Once you have your header in place, we can move on to the second part.
 +
 +
== Set up Hardware ==
  
 
[[Category:Howto]]
 
[[Category:Howto]]

Revision as of 19:53, 7 September 2011

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>

The first long in the header is what the CPU will initialize the stack pointer to, and the second long tells it where to start to execute your code. The other entries there should be self explanatory for the different exceptions that can occur, and some games write handlers for them. The rest of the longs that point to 'ErrorTrap' are all unused traps and exceptions, so they point to an endless loop. Note that you must have your 'Hardware system ID' start with 'SEGA' for Model 2 and 3 Mega Drives to load your game.

Once you have your header in place, we can move on to the second part.

Set up Hardware