gameboy/main.asm

95 lines
2.4 KiB
NASM

INCLUDE "hardware.inc"
INCLUDE "game/game.asm"
INCLUDE "tools.asm"
SECTION "InterruptVblank", ROM0[$0040]
reti
SECTION "InterruptLCDC", ROM0[$0048]
reti
SECTION "InterruptTimer_Overflow", ROM0[$0050]
reti
SECTION "InterruptSerial", ROM0[$0058]
reti
SECTION "Interruptp1thru4", ROM0[$0060]
reti
SECTION "Header", ROM0[$100]
EntryPoint: ;
ei ; Simple nop ; di ; Disable interrupts for now
jp Start ; Leave this tiny space
REPT $150 - $104
db 0
ENDR
SECTION "Intro code", ROM0
Start:
; First step is to access the VRAM to insert our graphics data.
; To do so, we must wait until we are in VBLANK period.
; Loop until we find ourselves in VBLANK
; Turn off the LCD
.waitVBlank
ld a, $01
ld [$FFFF], a ; Force enable VBLANK Interrupt
halt
xor a ; ld a, 0 ; Reset the accumilator register
; Our target is to set bit 7 reset on the LDC to turn it off
ld [rLCDC], a ; We will have to write to LCDC again later, so it's not a bother, really.
; ----------- Font Begin copying to VRAM -----------
; Start copying our font to vram
ld de, Page1 ; The start of the font tiles
ld hl, $9000 ; Set registers hl to $9000 which is the beginning of vram
ld bc, Page1End - Page1 ; The total length of font tiles
call Memcpy
; ----------- Start the display -----------
; Init the display register
ld a, %11100100 ; Load the palette of white, light gray, dark gray, black
ld a, %00011011 ; Load the palette of white, light gray, dark gray, black
ld [rBGP], a ; Store the palette to display
xor a ; ld a, 0 ; Reset the accumilator
ld [rSCY], a ; Set our scroll Y position to 0
ld [rSCX], a ; Set our scroll X position to 0
ld [rNR52], a ; Turn off sound
ld a, 7
ld [rWX], a
ld a, SCRN_Y
ld [rWY], a
; Initialize other stuff
call InitTools
call InitController
call InitWindow
; Reset OAM memory with zeros
; First reset our shadow OAM
ld hl, shadow_oam ; Set position of OAM Ram to hl
ld a, 0 ; Fill that memory space with zero
ld b, shadow_oam_inuse - shadow_oam ; Get the full size of the fill
call Memfill
; Then call our OAM guy
call RunDMA
; Turn the screen on, display background
ld a, LCDCF_ON|LCDCF_BGON|LCDCF_WINON|LCDCF_WIN9C00
ld [rLCDC], a ; Set the screen flags
call WaitVBlank
jp GameLoop
SECTION "Font", ROM0
Page1:
INCBIN "assets/page1.chr"
Page1End: