gameboy/main.asm

101 lines
2.7 KiB
NASM
Raw Normal View History

2019-06-14 08:36:52 +00:00
INCLUDE "hardware.inc"
INCLUDE "game/game.asm"
INCLUDE "tools.asm"
2019-06-18 09:08:14 +00:00
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
2019-06-14 08:36:52 +00:00
SECTION "Header", ROM0[$100]
EntryPoint: ;
2019-06-18 09:08:14 +00:00
ei ; Simple nop ; di ; Disable interrupts for now
2019-06-14 08:36:52 +00:00
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
2019-06-18 09:08:14 +00:00
ld a, $01
ld [$FFFF], a ; Force enable VBLANK Interrupt
halt
2019-06-14 08:36:52 +00:00
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
2019-06-18 09:08:14 +00:00
ld de, Page1 ; The start of the font tiles
2019-06-14 08:36:52 +00:00
ld hl, $9000 ; Set registers hl to $9000 which is the beginning of vram
2019-06-18 09:08:14 +00:00
ld bc, Page1End - Page1 ; The total length of font tiles
2019-06-14 08:36:52 +00:00
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
2019-06-19 15:07:02 +00:00
ld a, 7
ld [rWX], a
2019-06-21 12:04:17 +00:00
ld a, SCRN_Y
2019-06-19 15:07:02 +00:00
ld [rWY], a
; Reset OAM memory with zeros
ld hl, _OAMRAM ; Set position of OAM Ram to hl
ld a, 0 ; Fill that memory space with zero
ld b, $FEA0 - _OAMRAM ; Get the full size of the fill
call Memfill
2019-06-21 12:04:17 +00:00
; Reset WRAM memory with zeros
ld hl, _RAM ; Set position of OAM Ram to hl
ld a, $01 ; Fill that memory space with zero
ld bc, $E000 - _RAM ; Get the full size of the fill
call Memfill16
ld hl, _RAM ; Set position of OAM Ram to hl
ld a, $00 ; Fill that memory space with zero
ld bc, $E000 - _RAM ; Get the full size of the fill
call Memfill16
2019-06-19 15:07:02 +00:00
; Initialize other stuff
2019-06-21 12:04:17 +00:00
call InitController
2019-06-19 15:07:02 +00:00
call InitWindow
2019-06-14 08:36:52 +00:00
; Turn the screen on, display background
2019-06-19 15:07:02 +00:00
ld a, LCDCF_ON|LCDCF_BGON|LCDCF_WINON|LCDCF_WIN9C00
2019-06-14 08:36:52 +00:00
ld [rLCDC], a ; Set the screen flags
2019-06-19 15:07:02 +00:00
call WaitVBlank
2019-06-14 08:36:52 +00:00
jp GameLoop
SECTION "Font", ROM0
2019-06-18 09:08:14 +00:00
Page1:
INCBIN "assets/page1.chr"
Page1End:
2019-06-14 08:36:52 +00:00