dmgtris/src/main.asm

139 lines
2.9 KiB
NASM
Raw Normal View History

2023-10-10 08:32:24 +00:00
INCLUDE "globals.asm"
2023-10-13 06:38:10 +00:00
INCLUDE "memory.asm"
2023-10-10 08:32:24 +00:00
INCLUDE "interrupts.asm"
2023-10-11 06:18:12 +00:00
INCLUDE "sprites.asm"
2023-10-13 06:38:10 +00:00
INCLUDE "rng.asm"
2023-10-13 09:20:28 +00:00
INCLUDE "input.asm"
INCLUDE "time.asm"
INCLUDE "score.asm"
INCLUDE "level.asm"
INCLUDE "field.asm"
2023-10-10 08:32:24 +00:00
INCLUDE "res/tiles.inc"
INCLUDE "res/gameplay_map.inc"
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
; Save some power and turn off the audio.
2023-10-13 06:38:10 +00:00
xor a, a
ldh [rNR52], a
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
; Also to the second bank of tile data.
ld de, Tiles
ld hl, _VRAM + $800
ld bc, TilesEnd - Tiles
call UnsafeMemCopy
; 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
2023-10-10 08:32:24 +00:00
; The tilemap is just for testing for now.
ld de, GameplayTilemap
ld hl, $9800
ld bc, GameplayTilemapEnd - GameplayTilemap
call UnsafeMemCopy
2023-10-11 06:18:12 +00:00
; Clear OAM.
call ClearOAM
call CopyOAMHandler
call SetNumberSpritePositions
; Set up the palettes.
2023-10-10 08:32:24 +00:00
ld a, PALETTE_REGULAR
2023-10-13 09:20:28 +00:00
set_bg_palette
set_obj0_palette
ld a, PALETTE_LIGHTER_1
set_obj1_palette
2023-10-10 08:32:24 +00:00
2023-10-13 06:38:10 +00:00
; Get the timer going. It's used for RNG.
xor a, a
ldh [rTMA], a
ld a, TACF_262KHZ | TACF_START
2023-10-11 06:18:12 +00:00
; Zero out the ram where needed.
2023-10-10 08:32:24 +00:00
call InitializeVariables
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-11 06:18:12 +00:00
; And turn the LCD back on before we start.
2023-10-13 06:38:10 +00:00
ldh a, [rLCDC]
or LCDCF_ON | LCDCF_BGON | LCDCF_OBJON
ldh [rLCDC], a
2023-10-10 08:32:24 +00:00
; Make sure the first game loop starts just like all the future ones.
wait_vblank
wait_vblank_end
2023-10-13 06:38:10 +00:00
; TEMP: Set up the game.
call StartNewGame
2023-10-10 08:32:24 +00:00
GameLoop::
call GetInput
call HandleTimers
; Handle gameplay here
; TODO
2023-10-13 06:38:10 +00:00
ldh a, [hCtr]
inc a
and a, $1F
ldh [hCtr], a
jr nz, :+
call GetNextPiece
: ld a, [wNextPiece]
2023-10-11 06:18:12 +00:00
call ApplyNext
2023-10-10 08:32:24 +00:00
2023-10-13 06:38:10 +00:00
ld a, [wNextPiece]
2023-10-11 06:18:12 +00:00
call ApplyHold
2023-10-10 08:32:24 +00:00
2023-10-11 06:18:12 +00:00
ld hl, wSPRScore1
2023-10-13 09:20:28 +00:00
ld de, wScore
2023-10-11 06:18:12 +00:00
call ApplyNumbers
ld hl, wSPRCLevel1
2023-10-13 09:20:28 +00:00
ld de, wCLevel
2023-10-11 06:18:12 +00:00
call ApplyNumbers
ld hl, wSPRNLevel1
2023-10-13 09:20:28 +00:00
ld de, wNLevel
2023-10-11 06:18:12 +00:00
call ApplyNumbers
2023-10-10 08:32:24 +00:00
GameLoopEnd:
wait_vblank
2023-10-11 06:18:12 +00:00
call hOAMDMA
2023-10-10 08:32:24 +00:00
call BlitField
jp GameLoop
; *****************************************************************************
; * *
; * Functions *
; * *
; *****************************************************************************
SECTION "Functions", ROM0
InitializeVariables:
2023-10-13 09:20:28 +00:00
call TimeInit
call IntrInit
call InputInit
call ScoreInit
call LevelInit
call FieldInit
2023-10-10 08:32:24 +00:00
ret