abnercoimbre

Majora's Mask Printf

Aug 31st, 2018
435
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. INCLUDE "hardware.inc" ; Hardware definitions
  2. INCLUDE "ibmpc1.inc" ; Font data (from devrs.com)
  3.  
  4. ; Constants not in hardware.inc
  5. SGB_UNSUPPORTED EQU $00
  6. SGB_SUPPORTED EQU $03
  7. DEST_JAPAN EQU $00
  8. DEST_INTERNATIONAL EQU $01
  9.  
  10. ; Interrupt handler routines
  11. ; ------
  12. ; @abner: Parts of the hardware generate interrupts, and we
  13. ;         may use the sections below to handle each one. In
  14. ;         other words, the program jumps to the relevant section
  15. ;         during an interrupt and executes what's in there (before
  16. ;         returning to the main program).
  17. ;
  18. SECTION "Vblank", ROM0[$0040]
  19.  
  20.   ret ; Do nothing (i.e. exit handler and return to where the program was interrupted).
  21.  
  22. SECTION "LCDC", ROM0[$0048]
  23.  
  24.   ret ; Do nothing
  25.  
  26. SECTION "Timer_Overflow", ROM0[$0050]
  27.  
  28.   ret ; Do nothing
  29.  
  30. SECTION "Serial", ROM0[$0058]
  31.  
  32.   ret ; Do nothing
  33.  
  34. SECTION "p1thru4", ROM0[$0060]
  35.  
  36.   ret ; Do nothing
  37. ; ------
  38.  
  39. ; Boot loader jumps here
  40. ; ------
  41. ; @abner: On startup, the gameboy executes a small program (256 bytes) that reads
  42. ;         memory locations from $100 to $14D -- the area called the ROM header. The
  43. ;         info we provide here is used to perform some necessary setup.
  44. ;
  45. SECTION "start", ROM0[$0100]
  46.   ; $0100 - $0103: Startup handler -- Once ready, the gameboy will run this part.
  47.   nop ; It's tradition to put a nop here
  48.   jp begin
  49.  
  50.   ; $0104 - $0133: The Nintendo Logo.
  51.   NINTENDO_LOGO
  52.  
  53.   ; $0134 - $013E: Cart name, in upper-case letters, followed by zeroes. 15 bytes.
  54.   DB "CHOCOWINE-INSPIRED",0,0,0,0,0,0,0,0,0
  55.  
  56.   ; $0143: Gameboy Color compatibility flag.    
  57.   DB 0
  58.  
  59.   ; $0144 - $0145: "New" Licensee Code, a two character name.
  60.   DB "OK" ; 0,0 would work too (two bytes)
  61.  
  62.   ; $0146: Super Gameboy compatibility flag.
  63.   DB SGB_UNSUPPORTED
  64.  
  65.   ; $0147: Cartridge type. Either no ROM or MBC5 is recommended.
  66.   DB CART_ROM
  67.  
  68.   ; $0148: Rom size.
  69.   DB CART_ROM_256K
  70.  
  71.   ; $0149: Ram size.
  72.   DB CART_RAM_NONE
  73.  
  74.   ; $014A: Destination code.
  75.   DB DEST_INTERNATIONAL
  76.  
  77.   ; $014B: Old licensee code.
  78.   ; $33 indicates new license code will be used.
  79.   ; $33 must be used for SGB games.
  80.   DB $33
  81.  
  82.   ; $014C: ROM version number
  83.   DB 0
  84.  
  85.   ; $014D: Header checksum.
  86.   ; Assembler needs to patch this.
  87.   DB 0
  88.  
  89.   ; $014E- $014F: Global checksum.
  90.   ; Assembler needs to patch this.
  91.   DW 0
  92. ; ------
  93.  
  94. ; $0150: Code!
  95. begin:
  96.   nop
  97.   di ; Disable interrupts
  98.   ld sp, $ffff ; Set stack pointer to highest mem location + 1
  99.  
  100. init:
  101.   ld a, %1110100 ; Background tile palette (11 - black, 10 - dark grey, 01 - light grey, 00 - white)
  102.   ld [rBGP], a ; Memory location that stores the background tile palette
  103.  
  104.   ; Set X/Y scroll registers to 0. This sets the screen to upper right hand corner of our canvas.
  105.   ; NOTE: Gameboy has a tile map RAM (256x256) we call the canvas, but remember our screen is 160x144
  106.   ld a,0
  107.   ld [rSCX], a
  108.   ld [rSCY], a
  109.  
  110.   call StopLCD ; We're about to copy to video RAM. It can be glitchy to do that with the screen on.
  111.  
  112.   ; Load font data into tile memory. mem_CopyMono relies on the 16-bit HL register as a source
  113.   ; memory location, DE as its destination, and BC is a data length indicator.
  114.   ld hl, TileData
  115.   ld de, _VRAM ; $8000
  116.   ld bc, 8*256 ; ASCII - 256 characters, each having 8 bytes of display data
  117.   call mem_CopyMono ; Load font tiles
  118.  
  119.   ; Turn LCD on. Parameters explained in the I/O registers section of the Gameboy reference
  120.   ld a, LCDCF_ON|LCDCF_BG8000|LCDCF_BG9800|LCDCF_BGON|LCDCF_OBJ16|LCDCF_OBJOFF
  121.   ld [rLCDC], a
  122.  
  123.   ; Clear canvas by setting it to ascii character $20 (white space)
  124.   ld a, 32 ; ASCII FOR BLANK SPACE
  125.   ld hl, _SCRN0
  126.   ld bc, SCRN_VX_B * SCRN_VY_B
  127.   call mem_SetVRAM
  128.  
  129.   ; Print "Knzorb (TM)" to the screen
  130.   ld hl, Title
  131.   ld de, _SCRN0+3+(SCRN_VY_B*7)
  132.   ld bc, TitleEnd-Title
  133.   call mem_CopyVRAM
  134.  
  135. ; Epilogue
  136. wait:
  137.   halt
  138.   nop
  139.   jr wait
  140.  
  141. ; ****************************************************************************************
  142. ; Hard-coded Data
  143. ; ****************************************************************************************
  144. Title:
  145.   DB "The Melodist"
  146. TitleEnd:
  147.   nop
  148.  
  149. ; ****************************************************************************************
  150. ; StopLCD: Turn off LCD if it is on (we wait until we know it's off)
  151. ; ****************************************************************************************
  152. StopLCD:
  153.   ld a, [rLCDC]
  154.   rlca ; Put high bit of LCDC into carry flag
  155.   ret nc ; If screen is off just exit
  156.  
  157. ; Loop until we hit VBlank
  158. .wait:
  159.   ld a, [rLY]
  160.   cp 145 ; Screen on scan line 145?
  161.   jr nz, .wait ; No. Wait
  162.  
  163.   ; Turn off LCD
  164.   ld a, [rLCDC]
  165.   res 7, a ; Reset bit 7
  166.   ld [rLCDC], a
  167.  
  168.   ret
  169.  
  170. TileData:
  171.   chr_IBMPC1 1, 8 ; Load entire character set. See ibmpc1.inc for details.
Advertisement
Add Comment
Please, Sign In to add comment