gameboy/main.asm

115 lines
3.2 KiB
NASM
Raw Permalink 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]
2019-06-21 13:34:11 +00:00
; Game code starts here
; $0100
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
2019-06-21 13:34:11 +00:00
; $0104 - Nintendo logo
db $CE,$ED,$66,$66,$CC,$0D,$00,$0B,$03,$73,$00,$83,$00,$0C,$00,$0D
db $00,$08,$11,$1F,$88,$89,$00,$0E,$DC,$CC,$6E,$E6,$DD,$DD,$D9,$99
db $BB,$BB,$67,$63,$6E,$0E,$EC,$CC,$DD,$DC,$99,$9F,$BB,$B9,$33,$3E
; $0134 - Game Title
db "GAMEBOYGAME", $00, $00, $00, $00, $00
; $0144 - New Licensee code
db $00, $00
; $0146 - SGB Flag
db $00
; $0147 - Cartridge Type (http://gbdev.gg8.se/wiki/articles/The_Cartridge_Header#0147_-_Cartridge_Type)
db $00
; $0148 - ROM Size (http://gbdev.gg8.se/wiki/articles/The_Cartridge_Header#0148_-_ROM_Size)
db $00 ; 32 KByte
; $0149 - RAM Size
db $00
; $014A - Destination Code
db $01
; $014B - Old Licensee code
db $33
; $014C - Mask ROM Version number
db $00
; $014D - $014F - Checksums
db $00, $00, $00
2019-06-14 08:36:52 +00:00
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
; Initialize other stuff
call InitTools
2019-06-21 12:04:17 +00:00
call InitController
2019-06-19 15:07:02 +00:00
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
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