Sega MegaDrive

From SizeCoding
Revision as of 16:46, 18 December 2025 by Superogue (talk | contribs)

Jump to: navigation, search

SEGA MegaDrive / Genesis

The SEGA MegaDrive / Genesis is a 16-bit videogame console released by SEGA in 1989.

It features: - 320x240 resolution (PAL) - 4x 16 color palettes - Tile based display chip with 2 scrolling tilemaps - 64 Sprites (up to 4x4tiles in size each) - 64K of dedicated Video Memory (VRAM) - YM2612 Sound Chip

Setting up

The real hardware and BlastEm emulator don't require exact ROM headers, but you might want to distribute an emulator friendly version of your production as well for broader emulator compatibility.

CPU Vector table

This must be the very first thing in the ROM, since the CPU reads it from 0x0000 on bootup. The Vector table is a table of addresses that the CPU needs to know about - things like stack address, "main()" function address, vertical/horizontal interrupt addresses, etc. For any interrupts we don't want to handle, we specify INT_Null (an interrupt at the bottom of the file that doesn't do anything).

        dc.l   0x00FFE000			; Initial stack pointer value
	dc.l   CPU_EntryPoint		; Start of program
	dc.l   CPU_Exception 		; Bus error
	dc.l   CPU_Exception 		; Address error
	dc.l   CPU_Exception 		; Illegal instruction
	dc.l   CPU_Exception 		; Division by zero
	dc.l   CPU_Exception 		; CHK CPU_Exception
	dc.l   CPU_Exception 		; TRAPV CPU_Exception
	dc.l   CPU_Exception 		; Privilege violation
	dc.l   INT_Null				; TRACE exception
	dc.l   INT_Null				; Line-A emulator
	dc.l   INT_Null				; Line-F emulator
	dc.l   INT_Null				; Unused (reserved)
	dc.l   INT_Null				; Unused (reserved)
	dc.l   INT_Null				; Unused (reserved)
	dc.l   INT_Null				; Unused (reserved)
	dc.l   INT_Null				; Unused (reserved)
	dc.l   INT_Null				; Unused (reserved)
	dc.l   INT_Null				; Unused (reserved)
	dc.l   INT_Null				; Unused (reserved)
	dc.l   INT_Null				; Unused (reserved)
	dc.l   INT_Null				; Unused (reserved)
	dc.l   INT_Null				; Unused (reserved)
	dc.l   INT_Null				; Unused (reserved)
	dc.l   INT_Null				; Spurious exception
	dc.l   INT_Null				; IRQ level 1
	dc.l   INT_Null				; IRQ level 2
	dc.l   INT_Null				; IRQ level 3
	dc.l   INT_HInterrupt		; IRQ level 4 (horizontal retrace interrupt)
	dc.l   INT_Null  			; IRQ level 5
	dc.l   INT_VInterrupt		; IRQ level 6 (vertical retrace interrupt)
	dc.l   INT_Null				; IRQ level 7
	dc.l   INT_Null				; TRAP #00 exception
	dc.l   INT_Null				; TRAP #01 exception
	dc.l   INT_Null				; TRAP #02 exception
	dc.l   INT_Null				; TRAP #03 exception
	dc.l   INT_Null				; TRAP #04 exception
	dc.l   INT_Null				; TRAP #05 exception
	dc.l   INT_Null				; TRAP #06 exception
	dc.l   INT_Null				; TRAP #07 exception
	dc.l   INT_Null				; TRAP #08 exception
	dc.l   INT_Null				; TRAP #09 exception
	dc.l   INT_Null				; TRAP #10 exception
	dc.l   INT_Null				; TRAP #11 exception
	dc.l   INT_Null				; TRAP #12 exception
	dc.l   INT_Null				; TRAP #13 exception
	dc.l   INT_Null				; TRAP #14 exception
	dc.l   INT_Null				; TRAP #15 exception
	dc.l   INT_Null				; Unused (reserved)
	dc.l   INT_Null				; Unused (reserved)
	dc.l   INT_Null				; Unused (reserved)
	dc.l   INT_Null				; Unused (reserved)
	dc.l   INT_Null				; Unused (reserved)
	dc.l   INT_Null				; Unused (reserved)
	dc.l   INT_Null				; Unused (reserved)
	dc.l   INT_Null				; Unused (reserved)
	dc.l   INT_Null				; Unused (reserved)
	dc.l   INT_Null				; Unused (reserved)
	dc.l   INT_Null				; Unused (reserved)
	dc.l   INT_Null				; Unused (reserved)
	dc.l   INT_Null				; Unused (reserved)
	dc.l   INT_Null				; Unused (reserved)
	dc.l   INT_Null				; Unused (reserved)
	dc.l   INT_Null				; Unused (reserved)

This vector table is then followed by the ROM header at 0x100

ROM Header

The ROM Header is a structure located at 0x100 that specifies some metadata about the ROM, like its name, author, version number, release date, region, and any special peripherals used.

Note that the Mega Drive console itself doesn't read any of this, it's more a convenience for the programmer, but most emulators will read the title and region. Further header information at: https://plutiedev.com/rom-header

Memory map

Start address 	End address 	Description 	32X SH-2 address
$000000 	$3FFFFF 	Cartridge ROM/RAM 	$2000000-$23FFFFF
$400000 	$7FFFFF 	Reserved (used by the Mega-CD and 32X)
$800000 	$9FFFFF 	Reserved (used by the 32X)
$840000 	$85FFFF 	32X frame buffer 	$4000000-$401FFFF
$860000 	$87FFFF 	32X frame buffer overwrite mode 	$4020000-$403FFFF
$880000 	$8FFFFF 	32X cartridge ROM (first 512kB bank only)
$900000 	$9FFFFF 	32X cartridge bankswitched ROM (any 512kB bank, controlled by 32X registers)
$A00000 	$A0FFFF 	Z80 memory space
$A10000 	$A10001 	Version register
$A10002 	$A10003 	Controller 1 data
$A10004 	$A10005 	Controller 2 data
$A10006 	$A10007 	Expansion port data
$A10008 	$A10009 	Controller 1 control
$A1000A 	$A1000B 	Controller 2 control
$A1000C 	$A1000D 	Expansion port control
$A1000E 	$A1000F 	Controller 1 serial transmit
$A10010 	$A10011 	Controller 1 serial receive
$A10012 	$A10013 	Controller 1 serial control
$A10014 	$A10015 	Controller 2 serial transmit
$A10016 	$A10017 	Controller 2 serial receive
$A10018 	$A10019 	Controller 2 serial control
$A1001A 	$A1001B 	Expansion port serial transmit
$A1001C 	$A1001D 	Expansion port serial receive
$A1001E 	$A1001F 	Expansion port serial control
$A10020 	$A10FFF 	Reserved
$A11000 	Memory mode register
$A11002 	$A110FF 	Reserved
$A11100 	$A11101 	Z80 bus request
$A11102 	$A111FF 	Reserved
$A11200 	$A11201 	Z80 reset
$A11202 	$A12FFF 	Reserved
$A13000 	$A130FF 	TIME registers; used to send signals to the cartridge
$A130EC 	$A130EF 	"MARS" when 32X is attached
$A130F1 	SRAM access register
$A130F3 	Bank register for address $80000-$FFFFF
$A130F5 	Bank register for address $100000-$17FFFF
$A130F7 	Bank register for address $180000-$1FFFFF
$A130F9 	Bank register for address $200000-$27FFFF
$A130FB 	Bank register for address $280000-$2FFFFF
$A130FD 	Bank register for address $300000-$37FFFF
$A130FF 	Bank register for address $380000-$3FFFFF
$A14000 	$A14003 	TMSS "SEGA"
$A14101 	TMSS/cartridge register
$A14102 	$BFFFFF 	Reserved
$C00000 	$C00001 	VDP data port
$C00002 	$C00003 	VDP data port (mirror)
$C00004 	$C00005 	VDP control port
$C00006 	$C00007 	VDP control port (mirror)
$C00008 	$C00009 	VDP H/V counter
$C0000A 	$C0000F 	VDP H/V counter (mirror)
$C00011 	PSG output
$C00013 	$C00017 	PSG output (mirror)
$C0001C 	$C0001D 	Debug register
$C0001E 	$C0001F 	Debug register (mirror)
$C00020 	$FEFFFF 	Reserved
$FF0000 	$FFFFFF 	68000 RAM

Video display

To be added.

VDP

To be added.

 to be added

For more information, check out https://plutiedev.com/vdp-setup

Sprites

To be added

; to be added

Sound

To be added.

; to be added

Additional Resources