dmgtris/src/main.asm

107 lines
2.3 KiB
NASM
Raw Normal View History

2023-10-21 15:28:38 +00:00
; DMGTRIS
; Copyright (C) 2023 - Randy Thiemann <randy.thiemann@gmail.com>
; This program is free software: you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation, either version 3 of the License, or
; (at your option) any later version.
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
; You should have received a copy of the GNU General Public License
; along with this program. If not, see <https://www.gnu.org/licenses/>.
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-20 16:09:06 +00:00
INCLUDE "res/title_map.inc"
2023-10-10 08:32:24 +00:00
2023-10-16 05:47:11 +00:00
2023-10-18 02:09:12 +00:00
SECTION "Globals", HRAM
hGameState:: ds 1
2023-10-21 12:07:28 +00:00
hSwapAB:: ds 1
2023-10-16 05:47:11 +00:00
2023-10-18 01:02:46 +00:00
SECTION "Stack", WRAM0
2023-10-18 01:13:20 +00:00
wStack::
2023-10-18 09:59:22 +00:00
ds STACK_SIZE + 1
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 09:59:22 +00:00
ld sp, wStackEnd-1
2023-10-18 01:02:46 +00:00
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
; Clear OAM.
call ClearOAM
2023-10-20 16:09:06 +00:00
call SetNumberSpritePositions
2023-10-11 06:18:12 +00:00
call CopyOAMHandler
; Zero out the ram where needed.
2023-10-21 12:07:28 +00:00
xor a, a
ldh [hSwapAB], a
2023-10-21 14:31:26 +00:00
ld hl, sSpeedCurve
ld a, l
ldh [hStartSpeed], a
ld a, h
ldh [hStartSpeed+1], a
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.
2023-10-20 16:09:06 +00:00
call SwitchToTitle
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.
2023-10-18 02:45:58 +00:00
ld b, 0
2023-10-18 02:09:12 +00:00
ldh a, [hGameState]
2023-10-18 02:45:58 +00:00
cp a, b
2023-10-18 02:09:12 +00:00
jp nz, GamePlayEventLoopHandler
2023-10-20 16:09:06 +00:00
jp TitleEventLoopHandler
2023-10-16 05:47:11 +00:00
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