Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- INCLUDE "hardware.inc" ; Hardware definitions
- INCLUDE "ibmpc1.inc" ; Font data (from devrs.com)
- ; Constants not in hardware.inc
- SGB_UNSUPPORTED EQU $00
- SGB_SUPPORTED EQU $03
- DEST_JAPAN EQU $00
- DEST_INTERNATIONAL EQU $01
- ; Interrupt handler routines
- ; ------
- ; @abner: Parts of the hardware generate interrupts, and we
- ; may use the sections below to handle each one. In
- ; other words, the program jumps to the relevant section
- ; during an interrupt and executes what's in there (before
- ; returning to the main program).
- ;
- SECTION "Vblank", ROM0[$0040]
- ret ; Do nothing (i.e. exit handler and return to where the program was interrupted).
- SECTION "LCDC", ROM0[$0048]
- ret ; Do nothing
- SECTION "Timer_Overflow", ROM0[$0050]
- ret ; Do nothing
- SECTION "Serial", ROM0[$0058]
- ret ; Do nothing
- SECTION "p1thru4", ROM0[$0060]
- ret ; Do nothing
- ; ------
- ; Boot loader jumps here
- ; ------
- ; @abner: On startup, the gameboy executes a small program (256 bytes) that reads
- ; memory locations from $100 to $14D -- the area called the ROM header. The
- ; info we provide here is used to perform some necessary setup.
- ;
- SECTION "start", ROM0[$0100]
- ; $0100 - $0103: Startup handler -- Once ready, the gameboy will run this part.
- nop ; It's tradition to put a nop here
- jp begin
- ; $0104 - $0133: The Nintendo Logo.
- NINTENDO_LOGO
- ; $0134 - $013E: Cart name, in upper-case letters, followed by zeroes. 15 bytes.
- DB "CHOCOWINE-INSPIRED",0,0,0,0,0,0,0,0,0
- ; $0143: Gameboy Color compatibility flag.
- DB 0
- ; $0144 - $0145: "New" Licensee Code, a two character name.
- DB "OK" ; 0,0 would work too (two bytes)
- ; $0146: Super Gameboy compatibility flag.
- DB SGB_UNSUPPORTED
- ; $0147: Cartridge type. Either no ROM or MBC5 is recommended.
- DB CART_ROM
- ; $0148: Rom size.
- DB CART_ROM_256K
- ; $0149: Ram size.
- DB CART_RAM_NONE
- ; $014A: Destination code.
- DB DEST_INTERNATIONAL
- ; $014B: Old licensee code.
- ; $33 indicates new license code will be used.
- ; $33 must be used for SGB games.
- DB $33
- ; $014C: ROM version number
- DB 0
- ; $014D: Header checksum.
- ; Assembler needs to patch this.
- DB 0
- ; $014E- $014F: Global checksum.
- ; Assembler needs to patch this.
- DW 0
- ; ------
- ; $0150: Code!
- begin:
- nop
- di ; Disable interrupts
- ld sp, $ffff ; Set stack pointer to highest mem location + 1
- init:
- ld a, %1110100 ; Background tile palette (11 - black, 10 - dark grey, 01 - light grey, 00 - white)
- ld [rBGP], a ; Memory location that stores the background tile palette
- ; Set X/Y scroll registers to 0. This sets the screen to upper right hand corner of our canvas.
- ; NOTE: Gameboy has a tile map RAM (256x256) we call the canvas, but remember our screen is 160x144
- ld a,0
- ld [rSCX], a
- ld [rSCY], a
- call StopLCD ; We're about to copy to video RAM. It can be glitchy to do that with the screen on.
- ; Load font data into tile memory. mem_CopyMono relies on the 16-bit HL register as a source
- ; memory location, DE as its destination, and BC is a data length indicator.
- ld hl, TileData
- ld de, _VRAM ; $8000
- ld bc, 8*256 ; ASCII - 256 characters, each having 8 bytes of display data
- call mem_CopyMono ; Load font tiles
- ; Turn LCD on. Parameters explained in the I/O registers section of the Gameboy reference
- ld a, LCDCF_ON|LCDCF_BG8000|LCDCF_BG9800|LCDCF_BGON|LCDCF_OBJ16|LCDCF_OBJOFF
- ld [rLCDC], a
- ; Clear canvas by setting it to ascii character $20 (white space)
- ld a, 32 ; ASCII FOR BLANK SPACE
- ld hl, _SCRN0
- ld bc, SCRN_VX_B * SCRN_VY_B
- call mem_SetVRAM
- ; Print "Knzorb (TM)" to the screen
- ld hl, Title
- ld de, _SCRN0+3+(SCRN_VY_B*7)
- ld bc, TitleEnd-Title
- call mem_CopyVRAM
- ; Epilogue
- wait:
- halt
- nop
- jr wait
- ; ****************************************************************************************
- ; Hard-coded Data
- ; ****************************************************************************************
- Title:
- DB "The Melodist"
- TitleEnd:
- nop
- ; ****************************************************************************************
- ; StopLCD: Turn off LCD if it is on (we wait until we know it's off)
- ; ****************************************************************************************
- StopLCD:
- ld a, [rLCDC]
- rlca ; Put high bit of LCDC into carry flag
- ret nc ; If screen is off just exit
- ; Loop until we hit VBlank
- .wait:
- ld a, [rLY]
- cp 145 ; Screen on scan line 145?
- jr nz, .wait ; No. Wait
- ; Turn off LCD
- ld a, [rLCDC]
- res 7, a ; Reset bit 7
- ld [rLCDC], a
- ret
- TileData:
- chr_IBMPC1 1, 8 ; Load entire character set. See ibmpc1.inc for details.
Advertisement
Add Comment
Please, Sign In to add comment