Advertisement
Guest User

Hello World - SEGA Mega Drive

a guest
Dec 18th, 2016
1,928
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; Matt Phillips - bigevilcorporation.co.uk
  2.  
  3. ROM_Start
  4.  
  5.     ; CPU vector table
  6.     dc.l   0x00FFE000           ; Initial stack pointer value
  7.     dc.l   CPU_EntryPoint       ; Start of program
  8.     dc.l   CPU_Exception        ; Bus error
  9.     dc.l   CPU_Exception        ; Address error
  10.     dc.l   CPU_Exception        ; Illegal instruction
  11.     dc.l   CPU_Exception        ; Division by zero
  12.     dc.l   CPU_Exception        ; CHK CPU_Exception
  13.     dc.l   CPU_Exception        ; TRAPV CPU_Exception
  14.     dc.l   CPU_Exception        ; Privilege violation
  15.     dc.l   INT_Null             ; TRACE exception
  16.     dc.l   INT_Null             ; Line-A emulator
  17.     dc.l   INT_Null             ; Line-F emulator
  18.     dc.l   INT_Null             ; Unused (reserved)
  19.     dc.l   INT_Null             ; Unused (reserved)
  20.     dc.l   INT_Null             ; Unused (reserved)
  21.     dc.l   INT_Null             ; Unused (reserved)
  22.     dc.l   INT_Null             ; Unused (reserved)
  23.     dc.l   INT_Null             ; Unused (reserved)
  24.     dc.l   INT_Null             ; Unused (reserved)
  25.     dc.l   INT_Null             ; Unused (reserved)
  26.     dc.l   INT_Null             ; Unused (reserved)
  27.     dc.l   INT_Null             ; Unused (reserved)
  28.     dc.l   INT_Null             ; Unused (reserved)
  29.     dc.l   INT_Null             ; Unused (reserved)
  30.     dc.l   INT_Null             ; Spurious exception
  31.     dc.l   INT_Null             ; IRQ level 1
  32.     dc.l   INT_Null             ; IRQ level 2
  33.     dc.l   INT_Null             ; IRQ level 3
  34.     dc.l   INT_HBlank           ; IRQ level 4 (horizontal retrace interrupt)
  35.     dc.l   INT_Null             ; IRQ level 5
  36.     dc.l   INT_VBlank           ; IRQ level 6 (vertical retrace interrupt)
  37.     dc.l   INT_Null             ; IRQ level 7
  38.     dc.l   INT_Null             ; TRAP #00 exception
  39.     dc.l   INT_Null             ; TRAP #01 exception
  40.     dc.l   INT_Null             ; TRAP #02 exception
  41.     dc.l   INT_Null             ; TRAP #03 exception
  42.     dc.l   INT_Null             ; TRAP #04 exception
  43.     dc.l   INT_Null             ; TRAP #05 exception
  44.     dc.l   INT_Null             ; TRAP #06 exception
  45.     dc.l   INT_Null             ; TRAP #07 exception
  46.     dc.l   INT_Null             ; TRAP #08 exception
  47.     dc.l   INT_Null             ; TRAP #09 exception
  48.     dc.l   INT_Null             ; TRAP #10 exception
  49.     dc.l   INT_Null             ; TRAP #11 exception
  50.     dc.l   INT_Null             ; TRAP #12 exception
  51.     dc.l   INT_Null             ; TRAP #13 exception
  52.     dc.l   INT_Null             ; TRAP #14 exception
  53.     dc.l   INT_Null             ; TRAP #15 exception
  54.     dc.l   INT_Null             ; Unused (reserved)
  55.     dc.l   INT_Null             ; Unused (reserved)
  56.     dc.l   INT_Null             ; Unused (reserved)
  57.     dc.l   INT_Null             ; Unused (reserved)
  58.     dc.l   INT_Null             ; Unused (reserved)
  59.     dc.l   INT_Null             ; Unused (reserved)
  60.     dc.l   INT_Null             ; Unused (reserved)
  61.     dc.l   INT_Null             ; Unused (reserved)
  62.     dc.l   INT_Null             ; Unused (reserved)
  63.     dc.l   INT_Null             ; Unused (reserved)
  64.     dc.l   INT_Null             ; Unused (reserved)
  65.     dc.l   INT_Null             ; Unused (reserved)
  66.     dc.l   INT_Null             ; Unused (reserved)
  67.     dc.l   INT_Null             ; Unused (reserved)
  68.     dc.l   INT_Null             ; Unused (reserved)
  69.     dc.l   INT_Null             ; Unused (reserved)
  70.  
  71.     ; ROM metadata
  72.     dc.b "SEGA MEGA DRIVE "                                 ; Console name
  73.     dc.b "AUTHOR NAME HERE"                                 ; Copyright holder and release date
  74.     dc.b "GAME TITLE                                      " ; Domestic name
  75.     dc.b "GAME TITLE                                      " ; International name
  76.     dc.b "GM XXXXXXXX-XX"                                   ; Version number
  77.     dc.w 0x0000                                             ; Checksum
  78.     dc.b "J               "                                 ; I/O support
  79.     dc.l ROM_Start                                          ; Start address of ROM
  80.     dc.l ROM_End-1                                          ; End address of ROM
  81.     dc.l 0x00FF0000                                         ; Start address of RAM
  82.     dc.l 0x00FF0000+0x0000FFFF                              ; End address of RAM
  83.     dc.l 0x00000000                                         ; SRAM enabled
  84.     dc.l 0x00000000                                         ; Unused
  85.     dc.l 0x00000000                                         ; Start address of SRAM
  86.     dc.l 0x00000000                                         ; End address of SRAM
  87.     dc.l 0x00000000                                         ; Unused
  88.     dc.l 0x00000000                                         ; Unused
  89.     dc.b "                                        "         ; Notes (unused)
  90.     dc.b "  E             "                                 ; Country codes
  91.    
  92. ; Initial VDP register values
  93. VDPRegisters:
  94.     dc.b 0x14 ; 0:  H interrupt on, palettes on
  95.     dc.b 0x74 ; 1:  V interrupt on, display on, DMA on, Genesis mode on
  96.     dc.b 0x30 ; 2:  Pattern table for Scroll Plane A at VRAM 0xC000 (bits 3-5 = bits 13-15)
  97.     dc.b 0x00 ; 3:  Pattern table for Window Plane at VRAM 0x0000 (disabled) (bits 1-5 = bits 11-15)
  98.     dc.b 0x07 ; 4:  Pattern table for Scroll Plane B at VRAM 0xE000 (bits 0-2 = bits 11-15)
  99.     dc.b 0x78 ; 5:  Sprite table at VRAM 0xF000 (bits 0-6 = bits 9-15)
  100.     dc.b 0x00 ; 6:  Unused
  101.     dc.b 0x00 ; 7:  Background colour - bits 0-3 = colour, bits 4-5 = palette
  102.     dc.b 0x00 ; 8:  Unused
  103.     dc.b 0x00 ; 9:  Unused
  104.     dc.b 0x08 ; 10: Frequency of Horiz. interrupt in Rasters (number of lines travelled by the beam)
  105.     dc.b 0x00 ; 11: External interrupts off, V scroll fullscreen, H scroll fullscreen
  106.     dc.b 0x81 ; 12: Shadows and highlights off, interlace off, H40 mode (320 x 224 screen res)
  107.     dc.b 0x3F ; 13: Horiz. scroll table at VRAM 0xFC00 (bits 0-5)
  108.     dc.b 0x00 ; 14: Unused
  109.     dc.b 0x02 ; 15: Autoincrement 2 bytes
  110.     dc.b 0x01 ; 16: Vert. scroll 32, Horiz. scroll 64
  111.     dc.b 0x00 ; 17: Window Plane X pos 0 left (pos in bits 0-4, left/right in bit 7)
  112.     dc.b 0x00 ; 18: Window Plane Y pos 0 up (pos in bits 0-4, up/down in bit 7)
  113.     dc.b 0xFF ; 19: DMA length lo byte
  114.     dc.b 0xFF ; 20: DMA length hi byte
  115.     dc.b 0x00 ; 21: DMA source address lo byte
  116.     dc.b 0x00 ; 22: DMA source address mid byte
  117.     dc.b 0x80 ; 23: DMA source address hi byte, memory-to-VRAM mode (bits 6-7)
  118.    
  119.     even
  120.    
  121. ; VDP port addresses
  122. vdp_control             equ 0x00C00004
  123. vdp_data                equ 0x00C00000
  124.  
  125. ; VDP commands
  126. vdp_cmd_vram_write      equ 0x40000000
  127. vdp_cmd_cram_write      equ 0xC0000000
  128.  
  129. ; Hardware version address
  130. hardware_ver_address    equ 0x00A10001
  131.  
  132. ; TMSS
  133. tmss_address            equ 0x00A14000
  134. tmss_signature          equ 'SEGA'
  135.    
  136. ; Data port setup macros
  137. SetVRAMWrite: macro addr
  138.     move.l  #(vdp_cmd_vram_write)|((\addr)&$3FFF)<<16|(\addr)>>14, vdp_control
  139.     endm
  140.    
  141. SetCRAMWrite: macro addr
  142.     move.l  #(vdp_cmd_cram_write)|((\addr)&$3FFF)<<16|(\addr)>>14, vdp_control
  143.     endm
  144.  
  145.     ; Palette
  146. Palette:
  147.     dc.w 0x0000 ; Transparent
  148.     dc.w 0x0000 ; Black
  149.     dc.w 0x0EEE ; White
  150.     dc.w 0x000E ; Red
  151.     dc.w 0x00E0 ; Blue
  152.     dc.w 0x0E00 ; Green
  153.     dc.w 0x0E0E ; Pink
  154.     dc.w 0x0000
  155.     dc.w 0x0000
  156.     dc.w 0x0000
  157.     dc.w 0x0000
  158.     dc.w 0x0000
  159.     dc.w 0x0000
  160.     dc.w 0x0000
  161.     dc.w 0x0000
  162.     dc.w 0x0000
  163.    
  164.     ; Font glyphs for "HELOWRD"
  165. CharacterH:
  166.     dc.l 0x22000220
  167.     dc.l 0x22000220
  168.     dc.l 0x22000220
  169.     dc.l 0x22222220
  170.     dc.l 0x22000220
  171.     dc.l 0x22000220
  172.     dc.l 0x22000220
  173.     dc.l 0x00000000
  174.    
  175. CharacterE:
  176.     dc.l 0x22222220
  177.     dc.l 0x22000000
  178.     dc.l 0x22000000
  179.     dc.l 0x22222220
  180.     dc.l 0x22000000
  181.     dc.l 0x22000000
  182.     dc.l 0x22222220
  183.     dc.l 0x00000000
  184.    
  185. CharacterL:
  186.     dc.l 0x22000000
  187.     dc.l 0x22000000
  188.     dc.l 0x22000000
  189.     dc.l 0x22000000
  190.     dc.l 0x22000000
  191.     dc.l 0x22000000
  192.     dc.l 0x22222220
  193.     dc.l 0x00000000
  194.    
  195. CharacterO:
  196.     dc.l 0x22222220
  197.     dc.l 0x22000220
  198.     dc.l 0x22000220
  199.     dc.l 0x22000220
  200.     dc.l 0x22000220
  201.     dc.l 0x22000220
  202.     dc.l 0x22222220
  203.     dc.l 0x00000000
  204.    
  205. CharacterW:
  206.     dc.l 0x22000220
  207.     dc.l 0x22000220
  208.     dc.l 0x22000220
  209.     dc.l 0x22020220
  210.     dc.l 0x22020220
  211.     dc.l 0x22020220
  212.     dc.l 0x22222220
  213.     dc.l 0x00000000
  214.    
  215. CharacterR:
  216.     dc.l 0x22222200
  217.     dc.l 0x22000220
  218.     dc.l 0x22000220
  219.     dc.l 0x22222200
  220.     dc.l 0x22022000
  221.     dc.l 0x22002200
  222.     dc.l 0x22000220
  223.     dc.l 0x00000000
  224.    
  225. CharacterD:
  226.     dc.l 0x22222200
  227.     dc.l 0x22002220
  228.     dc.l 0x22000220
  229.     dc.l 0x22000220
  230.     dc.l 0x22000220
  231.     dc.l 0x22002220
  232.     dc.l 0x22222200
  233.     dc.l 0x00000000
  234.  
  235. CPU_EntryPoint
  236.  
  237.     jsr VDP_WriteTMSS
  238.     jsr VDP_LoadRegisters
  239.    
  240.     SetCRAMWrite 0x0000
  241.     move.l #Palette, a0
  242.     move.w #0xF, d0         ; Loop counter = 16 words in palette (-1)
  243.     @PalLp:                 ; Start of loop
  244.     move.w (a0)+, vdp_data  ; Write palette entry, post-increment address
  245.     dbra d0, @PalLp         ; Loop until finished
  246.    
  247.     SetVRAMWrite 0x0020
  248.     move.l #CharacterH, a0
  249.     move.w #(8*40)-1, d0    ; Loop counter = 8 longwords in tile (-1)
  250.     @CharLp:                ; Start of loop
  251.     move.l (a0)+, vdp_data  ; Write tile line, post-increment address
  252.     dbra d0, @CharLp        ; Loop until finished
  253.    
  254.     SetVRAMWrite 0xC418
  255.     move.w #0x0001, vdp_data    ; H
  256.     SetVRAMWrite 0xC41A
  257.     move.w #0x0002, vdp_data    ; E
  258.     SetVRAMWrite 0xC41C
  259.     move.w #0x0003, vdp_data    ; L
  260.     SetVRAMWrite 0xC41E
  261.     move.w #0x0003, vdp_data    ; L
  262.     SetVRAMWrite 0xC420
  263.     move.w #0x0004, vdp_data    ; 0
  264.    
  265.     SetVRAMWrite 0xC424
  266.     move.w #0x0005, vdp_data    ; W
  267.     SetVRAMWrite 0xC426
  268.     move.w #0x0004, vdp_data    ; O
  269.     SetVRAMWrite 0xC428
  270.     move.w #0x0006, vdp_data    ; R
  271.     SetVRAMWrite 0xC42A
  272.     move.w #0x0003, vdp_data    ; L
  273.     SetVRAMWrite 0xC42C
  274.     move.w #0x0007, vdp_data    ; D
  275.    
  276.     ; Halt CPU
  277.     stop   #0x2700
  278.  
  279. INT_VBlank:
  280.     rte
  281.  
  282. INT_HBlank:
  283.     rte
  284.  
  285. INT_Null:
  286.     rte
  287.  
  288. CPU_Exception:
  289.     stop   #0x2700
  290.     rte
  291.    
  292. VDP_WriteTMSS:
  293.  
  294.     move.b hardware_ver_address, d0         ; Move Megadrive hardware version to d0
  295.     andi.b #0x0F, d0                        ; The version is stored in last four bits, so mask it with 0F
  296.     beq @Skip                               ; If version is equal to 0, skip TMSS signature
  297.     move.l #tmss_signature, tmss_address    ; Move the string "SEGA" to 0xA14000
  298.     @Skip:
  299.  
  300.     ; Check VDP
  301.     move.w vdp_control, d0                  ; Read VDP status register (hangs if no access)
  302.    
  303.     rts
  304.    
  305. VDP_LoadRegisters:
  306.  
  307.     ; Set VDP registers
  308.     move.l #VDPRegisters, a0    ; Load address of register init table into a0
  309.     move.w #0x17, d0            ; 24 registers to write (-1 for loop counter)
  310.     move.w #0x8000, d1          ; 'Set register 0' command
  311.  
  312.     @CopyVDP:
  313.     move.b (a0)+, d1            ; Move register value to lower byte of d1
  314.     move.w d1, vdp_control      ; Write command and value to VDP control port
  315.     add.w  #0x0100, d1          ; Increment register #
  316.     dbra   d0, @CopyVDP
  317.    
  318.     rts
  319.    
  320. ROM_End
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement