dmgtris/src/main.asm

163 lines
3.3 KiB
NASM
Raw Permalink 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"
2023-10-28 17:04:55 +00:00
INCLUDE "res/other_data.inc"
2023-10-10 08:32:24 +00:00
2023-10-16 05:47:11 +00:00
2023-10-21 18:49:52 +00:00
SECTION "High Globals", HRAM
2023-10-18 02:09:12 +00:00
hGameState:: ds 1
2023-10-23 10:16:16 +00:00
2023-10-16 05:47:11 +00:00
2023-10-23 04:17:34 +00:00
SECTION "Globals", WRAM0
2023-10-23 10:16:16 +00:00
wSwapABState:: ds 1
wRNGModeState:: ds 1
wRotModeState:: ds 1
wDropModeState:: ds 1
wSpeedCurveState:: ds 1
wAlways20GState:: ds 1
2023-11-23 04:13:02 +00:00
wBGMode:: ds 1
2023-10-23 04:17:34 +00:00
wInitialA:: ds 1
wInitialB:: ds 1
wInitialC:: 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-27 19:37:32 +00:00
; Main entry point. Does some set up and then goes into an infinite event loop initialized on the title screen.
2023-10-13 06:38:10 +00:00
Main::
2023-10-23 04:17:34 +00:00
; Load the initial registers. For reasons.
ld [wInitialA], a
ld a, b
ld [wInitialB], a
ld a, c
ld [wInitialC], a
2023-10-21 22:34:55 +00:00
2023-11-07 04:30:03 +00:00
; Initialize the mapper.
ld a, CART_SRAM_ENABLE
ld [rRAMG], a
xor a, a
ld [rRAMB], a
ld a, BANK_OTHER
ld [rROMB0], a
2023-10-18 01:13:20 +00:00
; Set up stack
2023-11-07 08:14:43 +00:00
ld sp, wStackEnd-1
2023-10-18 01:02:46 +00:00
2023-11-07 08:14:43 +00:00
; GBC? Double speed.
2023-10-24 07:04:39 +00:00
ld a, [wInitialA]
cp a, $11
jr nz, .notgbc
ld a, KEY1F_PREPARE
ldh [rKEY1], a
stop
.notgbc
2023-11-07 08:14:43 +00:00
; Harvest entropy
call HarvestEntropy
; Let the console have some fun with the initial screen.
call InputInit
call BankingInit
2023-12-05 05:19:46 +00:00
xor a, a
ldh [hFilterMode], a
call DoIntroEffect
2023-11-07 08:14:43 +00:00
; Turn off LCD during initialization.
wait_vram
xor a, a
ldh [rLCDC], a
2023-12-05 05:19:46 +00:00
ld [wSpritePal], a
2023-11-07 08:14:43 +00:00
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
2023-10-25 04:40:08 +00:00
; Other initialization.
call RestoreSRAM
2023-10-18 01:02:46 +00:00
call InputInit
call TimeInit
2023-10-18 01:02:46 +00:00
call SFXInit
2023-11-07 08:14:43 +00:00
call BankingInit
xor a, a
2023-11-13 01:18:13 +00:00
ld [wKillScreenActive], a
ld [wSkippedSectionsBCD], a
2023-11-07 08:14:43 +00:00
ldh [hMode], a
2023-10-11 06:18:12 +00:00
; Switch to title 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-27 19:37:32 +00:00
; Event loop time!
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-27 10:20:33 +00:00
call SFXPlayNoise
2023-10-16 11:27:08 +00:00
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-11-20 04:59:48 +00:00
call HandleSectionTimers
2023-10-10 08:32:24 +00:00
2023-10-16 05:47:11 +00:00
; Call the current state's event handler.
ld hl, .eventloopjumps
2023-10-18 02:09:12 +00:00
ldh a, [hGameState]
ld b, 0
ld c, a
add hl, bc
jp hl
.eventloopjumps
2023-10-20 16:09:06 +00:00
jp TitleEventLoopHandler
jp GamePlayEventLoopHandler
2023-10-28 17:04:55 +00:00
jp GamePlayBigEventLoopHandler
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.
call hOAMDMA
2023-10-16 05:47:11 +00:00
; Call the current state's vblank handler.
ld hl, .vblankjumps
ldh a, [hGameState]
ld b, 0
ld c, a
add hl, bc
jp hl
.vblankjumps
jp TitleVBlankHandler
jp BlitField
2023-10-28 20:27:58 +00:00
jp BigBlitField
; 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