2023-10-10 08:32:24 +00:00
|
|
|
INCLUDE "globals.asm"
|
|
|
|
INCLUDE "memcpy.asm"
|
|
|
|
INCLUDE "hardwarectl.asm"
|
|
|
|
INCLUDE "interrupts.asm"
|
2023-10-11 06:18:12 +00:00
|
|
|
INCLUDE "sprites.asm"
|
2023-10-10 08:32:24 +00:00
|
|
|
INCLUDE "res/tiles.inc"
|
|
|
|
INCLUDE "res/gameplay_map.inc"
|
|
|
|
|
|
|
|
SECTION "Code Entry Point", ROM0
|
|
|
|
MainEntryPoint::
|
|
|
|
; Turn off LCD during initialization.
|
|
|
|
call DisableLCD
|
2023-10-11 06:18:12 +00:00
|
|
|
|
|
|
|
; Save some power and turn off the audio.
|
2023-10-10 08:32:24 +00:00
|
|
|
call DisableAudio
|
|
|
|
|
|
|
|
; 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.
|
|
|
|
call SetTileDataBanks
|
|
|
|
|
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-11 06:18:12 +00:00
|
|
|
set_all_palettes
|
2023-10-10 08:32:24 +00:00
|
|
|
|
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-10 08:32:24 +00:00
|
|
|
call EnableLCD
|
|
|
|
|
|
|
|
; Make sure the first game loop starts just like all the future ones.
|
|
|
|
wait_vblank
|
|
|
|
wait_vblank_end
|
|
|
|
|
|
|
|
|
|
|
|
GameLoop::
|
|
|
|
call GetInput
|
|
|
|
call HandleTimers
|
|
|
|
|
|
|
|
; Handle gameplay here
|
|
|
|
; TODO
|
|
|
|
|
2023-10-11 06:18:12 +00:00
|
|
|
ld a, 0
|
|
|
|
call ApplyNext
|
2023-10-10 08:32:24 +00:00
|
|
|
|
2023-10-11 06:18:12 +00:00
|
|
|
ld a, 4
|
|
|
|
call ApplyHold
|
2023-10-10 08:32:24 +00:00
|
|
|
|
2023-10-11 06:18:12 +00:00
|
|
|
ld hl, wSPRScore1
|
|
|
|
ld de, hScore
|
|
|
|
call ApplyNumbers
|
|
|
|
|
|
|
|
ld hl, wSPRCLevel1
|
|
|
|
ld de, hCLevel
|
|
|
|
call ApplyNumbers
|
|
|
|
|
|
|
|
ld hl, wSPRNLevel1
|
|
|
|
ld de, hNLevel
|
|
|
|
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:
|
|
|
|
xor a, a
|
|
|
|
ld [wLCDCCtr], a
|
2023-10-11 06:18:12 +00:00
|
|
|
ld hl, wField
|
|
|
|
ld bc, 10*22
|
|
|
|
ld d, TILE_FIELD_EMPTY
|
|
|
|
call UnsafeMemSet
|
|
|
|
ld hl, hScore
|
|
|
|
ld bc, (6*3)
|
|
|
|
ld d, 0
|
|
|
|
call UnsafeMemSet
|
2023-10-10 08:32:24 +00:00
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
|
|
BlitField:
|
2023-10-11 06:18:12 +00:00
|
|
|
; The first 14 rows can be blitted without checking for vram access.
|
|
|
|
ld de, wField + (2*10)
|
2023-10-10 08:32:24 +00:00
|
|
|
DEF row = 0
|
2023-10-11 06:18:12 +00:00
|
|
|
REPT 14
|
|
|
|
ld hl, FIELD_TOP_LEFT+(32*row)
|
2023-10-10 08:32:24 +00:00
|
|
|
REPT 10
|
|
|
|
ld a, [de]
|
|
|
|
ld [hl+], a
|
|
|
|
inc de
|
|
|
|
ENDR
|
|
|
|
DEF row += 1
|
|
|
|
ENDR
|
|
|
|
|
2023-10-11 06:18:12 +00:00
|
|
|
; The last 6 rows need some care.
|
|
|
|
REPT 6
|
|
|
|
ld hl, FIELD_TOP_LEFT+(32*row)
|
2023-10-10 08:32:24 +00:00
|
|
|
REPT 2
|
|
|
|
: ldh a, [rSTAT]
|
|
|
|
and STATF_LCD
|
|
|
|
cp STATF_HBL
|
|
|
|
jr z, :-
|
|
|
|
: ldh a, [rSTAT]
|
|
|
|
and STATF_LCD
|
|
|
|
cp STATF_HBL
|
|
|
|
jr nz, :-
|
|
|
|
REPT 5
|
|
|
|
ld a, [de]
|
|
|
|
ld [hl+], a
|
|
|
|
inc de
|
|
|
|
ENDR
|
|
|
|
ENDR
|
|
|
|
DEF row += 1
|
|
|
|
ENDR
|
|
|
|
ret
|
|
|
|
|
|
|
|
GetInput:
|
|
|
|
ret
|
|
|
|
|
|
|
|
HandleTimers:
|
|
|
|
ld a, [wEvenFrame]
|
|
|
|
inc a
|
|
|
|
and 1
|
|
|
|
ld [wEvenFrame], a
|
|
|
|
ret
|