; ******************************************************************
; Sega Megadrive ROM header
; ******************************************************************
dc.l 0x00FFE000 ; Initial stack pointer value
dc.l EntryPoint ; Start of program
dc.l Exception ; Bus error
dc.l Exception ; Address error
dc.l Exception ; Illegal instruction
dc.l Exception ; Division by zero
dc.l Exception ; CHK exception
dc.l Exception ; TRAPV exception
dc.l Exception ; Privilege violation
dc.l Exception ; TRACE exception
dc.l Exception ; Line-A emulator
dc.l Exception ; Line-F emulator
dc.l Exception ; Unused (reserved)
dc.l Exception ; Unused (reserved)
dc.l Exception ; Unused (reserved)
dc.l Exception ; Unused (reserved)
dc.l Exception ; Unused (reserved)
dc.l Exception ; Unused (reserved)
dc.l Exception ; Unused (reserved)
dc.l Exception ; Unused (reserved)
dc.l Exception ; Unused (reserved)
dc.l Exception ; Unused (reserved)
dc.l Exception ; Unused (reserved)
dc.l Exception ; Unused (reserved)
dc.l Exception ; Spurious exception
dc.l Exception ; IRQ level 1
dc.l Exception ; IRQ level 2
dc.l Exception ; IRQ level 3
dc.l HBlankInterrupt ; IRQ level 4 (horizontal retrace interrupt)
dc.l Exception ; IRQ level 5
dc.l VBlankInterrupt ; IRQ level 6 (vertical retrace interrupt)
dc.l Exception ; IRQ level 7
dc.l Exception ; TRAP #00 exception
dc.l Exception ; TRAP #01 exception
dc.l Exception ; TRAP #02 exception
dc.l Exception ; TRAP #03 exception
dc.l Exception ; TRAP #04 exception
dc.l Exception ; TRAP #05 exception
dc.l Exception ; TRAP #06 exception
dc.l Exception ; TRAP #07 exception
dc.l Exception ; TRAP #08 exception
dc.l Exception ; TRAP #09 exception
dc.l Exception ; TRAP #10 exception
dc.l Exception ; TRAP #11 exception
dc.l Exception ; TRAP #12 exception
dc.l Exception ; TRAP #13 exception
dc.l Exception ; TRAP #14 exception
dc.l Exception ; TRAP #15 exception
dc.l Exception ; Unused (reserved)
dc.l Exception ; Unused (reserved)
dc.l Exception ; Unused (reserved)
dc.l Exception ; Unused (reserved)
dc.l Exception ; Unused (reserved)
dc.l Exception ; Unused (reserved)
dc.l Exception ; Unused (reserved)
dc.l Exception ; Unused (reserved)
dc.l Exception ; Unused (reserved)
dc.l Exception ; Unused (reserved)
dc.l Exception ; Unused (reserved)
dc.l Exception ; Unused (reserved)
dc.l Exception ; Unused (reserved)
dc.l Exception ; Unused (reserved)
dc.l Exception ; Unused (reserved)
dc.l Exception ; Unused (reserved)
dc.b "SEGA GENESIS " ; Console name
dc.b "(C)SEGA 1992.SEP" ; Copyrght holder and release date
dc.b "YOUR GAME HERE " ; Domestic name
dc.b "YOUR GAME HERE " ; International name
dc.b "GM XXXXXXXX-XX" ; Version number
dc.w 0x0000 ; Checksum
dc.b "J " ; I/O support
dc.l 0x00000000 ; Start address of ROM
dc.l __end ; End address of ROM
dc.l 0x00FF0000 ; Start address of RAM
dc.l 0x00FFFFFF ; End address of RAM
dc.l 0x00000000 ; SRAM enabled
dc.l 0x00000000 ; Unused
dc.l 0x00000000 ; Start address of SRAM
dc.l 0x00000000 ; End address of SRAM
dc.l 0x00000000 ; Unused
dc.l 0x00000000 ; Unused
dc.b " " ; Notes (unused)
dc.b "JUE " ; Country codes
EntryPoint:
tst.w 0x00A1000C ; Test reset button
bne GameLoop ; Branch if Not Equal (to zero) - to GameLoop
; ****************************
; Clear the ram
; ****************************
move.l #0x00000000, d0 ; Place a 0 into d0, ready to copy to each longword of RAM
move.l #0x00000000, a0 ; Starting from address 0x0, clearing backwards
move.l #0x00003FFF, d1 ; Clearing 64k's worth of longwords (minus 1, for the loop to be correct)
ClearRamLoop:
move.l d0, -(a0) ; Decrement the address by 1 longword, before moving the zero from d0 to it
dbra d1, ClearRamLoop
; ***************************
; TMSS Code
; ***************************
move.b 0x00A10001, d0 ; Move Megadrive hardware version to d0
andi.b #0x0F, d0 ; The version is stored in last four bits, so mask it with 0F
beq SkipTMSS ; If version is equal to 0, skip TMSS signature
move.l #'SEGA', 0x00A14000 ; Move the string "SEGA" to 0xA14000
SkipTMSS:
; ****************************
; Initalize the Z80
; ****************************
move.w #0x0100, 0x00A11100 ; Request access to the Z80 bus, by writing 0x0100 into the BUSREQ port
move.w #0x0100, 0x00A11200 ; Hold the Z80 in a reset state, by writing 0x0100 into the RESET port
WaitZ80:
btst #0x0, 0x00A11100 ; Test bit 0 of A11100 to see if the 68k has access to the Z80 bus yet
bne WaitZ80 ; If we don't yet have control, branch back up to Wait
move.l #Z80Data, a0 ; Load address of data into a0
move.l #0x00A00000, a1 ; Copy Z80 RAM address to a1
move.l #0x29, d0 ; 42 bytes of init data (minus 1 for counter)
Z80Copy:
move.b (a0)+, (a1) ; Copy data, and increment the source/dest addresses
dbra d0, Z80Copy
move.w #0x0000, 0x00A11200 ; Release reset state
move.w #0x0000, 0x00A11100 ; Release control of bus
; ****************************
; Initaluize the programmable sound generator
; ****************************
move.l #PSGData, a0 ; Load address of PSG data into a0
move.l #0x03, d0 ; 4 bytes of data
CopyPSG:
move.b (a0)+, 0x00C00011 ; Copy data to PSG RAM
dbra d0, CopyPSG
; ****************************
; Initaluize the video display processor
; ****************************
move.l #VDPRegisters, a0 ; Load address of register table into a0
move.l #11, d0 ; 24 registers to write (12 longwords)
CopyVDP:
move.l (a0)+, ($C00004) ; Write register value
dbra d0, CopyVDP ; continue looping until all the registers are setup
; ****************************
; Initaluize the game controllers
; ****************************
; Set IN I/O direction, interrupts off, on all ports
move.b #0x00, 0x000A10009 ; Controller port 1 CTRL
move.b #0x00, 0x000A1000B ; Controller port 2 CTRL
move.b #0x00, 0x000A1000D ; EXP port CTRL
move.l #0x00000000, a0 ; Move 0x0 to a0
movem.l (a0), d0-d7/a1-a7 ; Clear all registers
move #0x2700, sr
; ****************************
; initalize the palette
; ****************************
InitPalette:
move.l #0xC0000003, 0x00C00004 ; Set up VDP to write to CRAM address 0x0000
lea PaletteData, a0 ; Load address of Palette into a0
move.l #0x07, d0 ; 32 bytes of data (8 longwords, minus 1 for counter) in palette
PaletteLoop:
move.l (a0)+, 0x00C00000 ; Move data to VDP data port, and increment source address
dbra d0, PaletteLoop ; loop until all the palette data is in CRAM
move.w #0x8708, 0x00C00004 ; Set background colour to palette 0, colour 8
GameLoop:
jmp GameLoop ; Jump back up to 'GameLoop'
HBlankInterrupt:
VBlankInterrupt:
rte ; Return from Exception
Exception:
rte ; Return from Exception
Z80Data:
dc.w 0xaf01, 0xd91f
dc.w 0x1127, 0x0021
dc.w 0x2600, 0xf977
dc.w 0xedb0, 0xdde1
dc.w 0xfde1, 0xed47
dc.w 0xed4f, 0xd1e1
dc.w 0xf108, 0xd9c1
dc.w 0xd1e1, 0xf1f9
dc.w 0xf3ed, 0x5636
dc.w 0xe9e9, 0x8104
dc.w 0x8f01
PSGData:
dc.w 0x9fbf, 0xdfff
VDPRegisters:
dc.w 0x8024 ; Horiz. interrupt on, plus bit 2 (unknown, but docs say it needs to be on)
dc.w 0x8174 ; Vert. interrupt on, display on, DMA on, V28 mode (28 cells vertically), + bit 2
dc.w 0x8230 ; Pattern table for Scroll Plane A at 0xC000 (bits 3-5)
dc.w 0x8340 ; Pattern table for Window Plane at 0x10000 (bits 1-5)
dc.w 0x8405 ; Pattern table for Scroll Plane B at 0xA000 (bits 0-2)
dc.w 0x8570 ; Sprite table at 0xE000 (bits 0-6)
dc.w 0x8600 ; Unused
dc.w 0x8700 ; Background colour - bits 0-3 = colour, bits 4-5 = palette
dc.w 0x8800 ; Unused
dc.w 0x8900 ; Unused
dc.w 0x8a00 ; Frequency of Horiz. interrupt in Rasters (number of lines travelled by the beam)
dc.w 0x8b08 ; External interrupts on, V/H scrolling on
dc.w 0x8c81 ; Shadows and highlights off, interlace off, H40 mode (40 cells horizontally)
dc.w 0x8d34 ; Horiz. scroll table at 0xD000 (bits 0-5)
dc.w 0x8e00 ; Unused
dc.w 0x8f02 ; Autoincrement off
dc.w 0x9001 ; Vert. scroll 32, Horiz. scroll 64
dc.w 0x9100 ; Window Plane X pos 0 left (pos in bits 0-4, left/right in bit 7)
dc.w 0x9200 ; Window Plane Y pos 0 up (pos in bits 0-4, up/down in bit 7)
dc.w 0x9300 ; DMA length lo byte
dc.w 0x9400 ; DMA length hi byte
dc.w 0x9500 ; DMA source address lo byte
dc.w 0x9600 ; DMA source address mid byte
dc.w 0x9700 ; DMA source address hi byte, memory-to-VRAM mode (bits 6-7)
PaletteData:
dc.w 0x0000 ; Colour 0 - Transparent
dc.w 0x000E ; Colour 1 - Red
dc.w 0x00E0 ; Colour 2 - Green
dc.w 0x0E00 ; Colour 3 - Blue
dc.w 0x0000 ; Colour 4 - Black
dc.w 0x0EEE ; Colour 5 - White
dc.w 0x00EE ; Colour 6 - Yellow
dc.w 0x008E ; Colour 7 - Orange
dc.w 0x0E0E ; Colour 8 - Pink
dc.w 0x0808 ; Colour 9 - Purple
dc.w 0x0444 ; Colour A - Dark grey
dc.w 0x0888 ; Colour B - Light grey
dc.w 0x0EE0 ; Colour C - Turquoise
dc.w 0x000A ; Colour D - Maroon
dc.w 0x0600 ; Colour E - Navy blue
dc.w 0x0060 ; Colour F - Dark green
__end ; Very last line, end of ROM address
Click to expand...