dmgtris/src/main.asm

86 lines
1.5 KiB
NASM
Raw Normal View History

2023-10-16 05:47:11 +00:00
IF !DEF(MAIN_ASM)
DEF MAIN_ASM EQU 1
2023-10-10 08:32:24 +00:00
INCLUDE "globals.asm"
INCLUDE "res/tiles.inc"
INCLUDE "res/gameplay_map.inc"
2023-10-16 05:47:11 +00:00
SECTION "Globals", WRAM0
wStateEventHandler:: ds 2
wStateVBlankHandler:: ds 2
2023-10-18 01:02:46 +00:00
SECTION "Stack", WRAM0
2023-10-18 01:13:20 +00:00
wStack::
2023-10-18 01:02:46 +00:00
ds STACK_SIZE
2023-10-18 01:13:20 +00:00
wStackEnd::
2023-10-18 01:02:46 +00:00
2023-10-10 08:32:24 +00:00
SECTION "Code Entry Point", ROM0
2023-10-13 06:38:10 +00:00
Main::
2023-10-10 08:32:24 +00:00
; Turn off LCD during initialization.
2023-10-13 06:38:10 +00:00
wait_vram
xor a, a
ldh [rLCDC], a
2023-10-11 06:18:12 +00:00
2023-10-18 01:13:20 +00:00
; Set up stack
2023-10-18 01:02:46 +00:00
ld sp, wStackEnd
2023-10-10 08:32:24 +00:00
; We use a single set of tiles for the entire game, so we copy it at the start.
ld de, Tiles
2023-10-11 06:18:12 +00:00
ld hl, _VRAM
2023-10-10 08:32:24 +00:00
ld bc, TilesEnd - Tiles
call UnsafeMemCopy
2023-10-11 06:18:12 +00:00
; Make sure both sprites and bg use the same tile data.
2023-10-13 06:38:10 +00:00
ldh a, [rLCDC]
or LCDCF_BLK01
ldh [rLCDC], a
2023-10-11 06:18:12 +00:00
; Clear OAM.
call ClearOAM
call CopyOAMHandler
; Zero out the ram where needed.
2023-10-18 01:02:46 +00:00
call TimeInit
call IntrInit
call InputInit
call SFXInit
2023-10-11 06:18:12 +00:00
; Set up the interrupt handlers.
2023-10-10 08:32:24 +00:00
call InitializeLCDCInterrupt
2023-10-16 05:47:11 +00:00
; Switch to gameplay state.
call SwitchToGameplay
2023-10-13 06:38:10 +00:00
2023-10-10 08:32:24 +00:00
2023-10-16 05:47:11 +00:00
EventLoop::
2023-10-16 11:27:08 +00:00
; Play the sound effect, if any.
call SFXPlay
2023-10-16 05:47:11 +00:00
; Wrangle inputs and timers at the start of every frame.
2023-10-10 08:32:24 +00:00
call GetInput
call HandleTimers
2023-10-16 05:47:11 +00:00
; Call the current state's event handler.
ld a, [wStateEventHandler]
ld l, a
ld a, [wStateEventHandler + 1]
ld h, a
jp hl
EventLoopPostHandler::
2023-10-10 08:32:24 +00:00
2023-10-18 01:11:05 +00:00
; Wait for vblank.
2023-10-18 02:01:35 +00:00
wait_vblank
2023-10-18 01:11:05 +00:00
; Do OAM DMA.
2023-10-18 02:01:35 +00:00
; This will chain jump into the vblank handler.
jp hOAMDMA
2023-10-16 05:47:11 +00:00
2023-10-18 01:13:20 +00:00
; The VBlank Handler is expected to end with jp EventLoop.
2023-10-10 08:32:24 +00:00
2023-10-16 05:47:11 +00:00
ENDC