Add game timer.

This commit is contained in:
Randy Thiemann 2023-11-03 04:05:54 +01:00
parent ed8bf5d047
commit 6c3957f044
15 changed files with 2726 additions and 2536 deletions

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@ -184,6 +184,8 @@ DEF CLEVEL_BASE_Y EQU 133
DEF NLEVEL_BASE_Y EQU 145
DEF GRADE_BASE_X EQU 145
DEF GRADE_BASE_Y EQU 20
DEF TIME_BASE_X EQU 100
DEF TIME_BASE_Y EQU 153
DEF TELLS_BASE_X EQU 154
DEF TELLS_BASE_Y EQU 61
DEF TELLS_Y_DIST EQU 10
@ -226,6 +228,7 @@ DEF TILE_CLEARING EQU 106
DEF TILE_GHOST EQU 107
DEF TILE_PIECE_SMALL_0 EQU 116
DEF TILE_PIECE_BONE EQU 104
DEF TILE_SMALL_0 EQU 213
DEF GAME_OVER_R10 EQU 147
DEF GAME_OVER_R12 EQU 167
DEF GAME_OVER_R14 EQU 187

View File

@ -322,7 +322,7 @@ sBigGameplayTileMap::
DB $01,$01,$01,$01,$01,$01,$01,$6F,$00,$00
DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
DB $01,$01,$01,$01,$01,$01,$01,$01,$01,$01
DB $6D,$01,$01,$01,$01,$01,$01,$01,$01,$6F
DB $6D,$01,$01,$D4,$01,$01,$DF,$01,$01,$6F
DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
DB $00,$00
sBigGameplayTileMapEnd::

View File

@ -334,7 +334,7 @@ sGameplayTileMap::
DB $01,$01,$01,$01,$01,$01,$01,$6F,$00,$00
DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
DB $01,$01,$01,$01,$01,$01,$01,$01,$01,$01
DB $6D,$01,$01,$01,$01,$01,$01,$01,$01,$6F
DB $6D,$01,$01,$D4,$01,$01,$DF,$01,$01,$6F
DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
DB $00,$00
sGameplayTileMapEnd::

View File

@ -1472,8 +1472,8 @@ sGameplayTilesM::
DB $42,$42,$42,$42,$EC,$EC,$00,$00
DB $FE,$FE,$DB,$DB,$DB,$DB,$DB,$DB
DB $DB,$DB,$DB,$DB,$DB,$DB,$00,$00
DB $00,$00,$18,$18,$18,$18,$00,$00
DB $00,$00,$18,$18,$18,$18,$00,$00
DB $00,$00,$06,$06,$06,$06,$00,$00
DB $00,$00,$06,$06,$06,$06,$00,$00
DB $00,$00,$3C,$3C,$66,$66,$6E,$6E
DB $76,$76,$66,$66,$3C,$3C,$00,$00
DB $00,$00,$0C,$0C,$1C,$1C,$0C,$0C
@ -1494,8 +1494,8 @@ sGameplayTilesM::
DB $66,$66,$66,$66,$3C,$3C,$00,$00
DB $00,$00,$1C,$1C,$36,$36,$36,$36
DB $1E,$1E,$06,$06,$1C,$1C,$00,$00
DB $00,$00,$00,$00,$00,$00,$00,$00
DB $00,$00,$00,$00,$00,$00,$00,$00
DB $00,$00,$60,$60,$60,$60,$00,$00
DB $00,$00,$60,$60,$60,$60,$00,$00
DB $00,$00,$00,$00,$00,$00,$00,$00
DB $00,$00,$00,$00,$00,$00,$00,$00
DB $00,$00,$00,$00,$00,$00,$00,$00
@ -1891,8 +1891,8 @@ sGameplayTilesC::
DB $42,$42,$42,$42,$EC,$EC,$00,$00
DB $FE,$FE,$DB,$DB,$DB,$DB,$DB,$DB
DB $DB,$DB,$DB,$DB,$DB,$DB,$00,$00
DB $00,$00,$18,$18,$18,$18,$00,$00
DB $00,$00,$18,$18,$18,$18,$00,$00
DB $00,$00,$06,$06,$06,$06,$00,$00
DB $00,$00,$06,$06,$06,$06,$00,$00
DB $00,$00,$3C,$3C,$66,$66,$6E,$6E
DB $76,$76,$66,$66,$3C,$3C,$00,$00
DB $00,$00,$0C,$0C,$1C,$1C,$0C,$0C
@ -1913,8 +1913,8 @@ sGameplayTilesC::
DB $66,$66,$66,$66,$3C,$3C,$00,$00
DB $00,$00,$1C,$1C,$36,$36,$36,$36
DB $1E,$1E,$06,$06,$1C,$1C,$00,$00
DB $00,$00,$00,$00,$00,$00,$00,$00
DB $00,$00,$00,$00,$00,$00,$00,$00
DB $00,$00,$60,$60,$60,$60,$00,$00
DB $00,$00,$60,$60,$60,$60,$00,$00
DB $00,$00,$00,$00,$00,$00,$00,$00
DB $00,$00,$00,$00,$00,$00,$00,$00
DB $00,$00,$00,$00,$00,$00,$00,$00

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -60,13 +60,14 @@ wSPRModeDrop:: ds 4
wSPRModeHiG:: ds 4
wSPRGrade1:: ds 4
wSPRGrade2:: ds 4
wUnused0:: ds 4
wUnused1:: ds 4
wUnused2:: ds 4
wUnused3:: ds 4
wUnused4:: ds 4
wUnused5:: ds 4
wSPRTimeM1:: ds 4
wSPRTimeM2:: ds 4
wSPRTimeS1:: ds 4
wSPRTimeS2:: ds 4
wSPRTimeCS1:: ds 4
wSPRTimeCS2:: ds 4
ENDU
wScratch: ds 2
SECTION "OAM DMA Code", ROM0
@ -381,6 +382,146 @@ ApplyHold::
ret
; Draw the time.
ApplyTime::
; Set the Y position of the time objects.
ld a, TIME_BASE_Y
ld [wSPRTimeM1], a
ld [wSPRTimeM2], a
ld [wSPRTimeS1], a
ld [wSPRTimeS2], a
ld [wSPRTimeCS1], a
ld [wSPRTimeCS2], a
; Set the X position of the time objects.
ldh a, [rSCX]
ld b, a
ld a, TIME_BASE_X
sub a, b
ld [wSPRTimeM1+1], a
add a, 8
ld [wSPRTimeM2+1], a
add a, 12
ld [wSPRTimeS1+1], a
add a, 8
ld [wSPRTimeS2+1], a
add a, 12
ld [wSPRTimeCS1+1], a
add a, 8
ld [wSPRTimeCS2+1], a
; Set the palette of the time objects.
ld a, OAMF_PAL0 | $07
ld [wSPRTimeM1+3], a
ld [wSPRTimeM2+3], a
ld [wSPRTimeS1+3], a
ld [wSPRTimeS2+3], a
ld [wSPRTimeCS1+3], a
ld [wSPRTimeCS2+3], a
; Minutes. Hex to BCD.
ld a, [wMinutes]
ld c, a
ld b, 8
xor a, a
.loop0
sla c
adc a, a
daa
dec b
jr nz, .loop0
; Save to scratch.
ld b, a
and a, $0F
ld [wScratch+1], a
ld a, b
and a, $F0
swap a
ld [wScratch], a
; Apply to sprites.
ld de, wScratch
ld hl, wSPRTimeM1+2
ld bc, 4
ld a, [de]
add a, TILE_SMALL_0
ld [hl], a
add hl, bc
inc de
ld a, [de]
add a, TILE_SMALL_0
ld [hl], a
; Seconds. Hex to BCD.
ld a, [wSeconds]
ld c, a
ld b, 8
xor a, a
.loop1
sla c
adc a, a
daa
dec b
jr nz, .loop1
; Save to scratch.
ld b, a
and a, $0F
ld [wScratch+1], a
ld a, b
and a, $F0
swap a
ld [wScratch], a
; Apply to sprites.
ld de, wScratch
ld hl, wSPRTimeS1+2
ld bc, 4
ld a, [de]
add a, TILE_SMALL_0
ld [hl], a
add hl, bc
inc de
ld a, [de]
add a, TILE_SMALL_0
ld [hl], a
; Centiseconds. Frames using LUT.
ld a, [wFrames]
ld c, a
ld b, 0
ld hl, sFramesToCS
add hl, bc
ld a, [hl]
; Save to scratch.
ld b, a
and a, $0F
ld [wScratch+1], a
ld a, b
and a, $F0
swap a
ld [wScratch], a
; Apply to sprites.
ld de, wScratch
ld hl, wSPRTimeCS1+2
ld bc, 4
ld a, [de]
add a, TILE_SMALL_0
ld [hl], a
add hl, bc
inc de
ld a, [de]
add a, TILE_SMALL_0
ld [hl], a
ret
; Generic function to draw a BCD number (8 digits) as 8 sprites.
@ -482,6 +623,7 @@ ApplyNumbers6::
ld [hl], a
ret
; Generic function to draw a BCD number (4 digits) as 4 sprites.
; Address of first sprite in hl.
; Address of first digit in de.
@ -712,6 +854,7 @@ SetNumberSpritePositions::
ld [hl], a
ret
GradeRendering::
; Set the Y position of the grade objects.
ld a, GRADE_BASE_Y

View File

@ -172,6 +172,7 @@ GamePlayEventLoopHandlerB::
; Draw "READY" and wait a bit.
.leadyMode
call ResetGameTime
ldh a, [hModeCounter]
cp a, LEADY_TIME
jr nz, .firstleadyiterskip
@ -196,6 +197,7 @@ GamePlayEventLoopHandlerB::
; Draw "GO" and wait a bit.
.goMode
call ResetGameTime
ldh a, [hModeCounter]
dec a
jr nz, .notdonego
@ -626,6 +628,7 @@ GamePlayEventLoopHandlerB::
call SetNumberSpritePositions
call ApplyTells
call ApplyTime
jp GBCGameplayProcess
@ -806,6 +809,7 @@ GamePlayBigEventLoopHandlerB:
; Draw "READY" and wait a bit.
.leadyMode
call ResetGameTime
ldh a, [hModeCounter]
cp a, LEADY_TIME
jr nz, .firstleadyiterskip
@ -830,6 +834,7 @@ GamePlayBigEventLoopHandlerB:
; Draw "GO" and wait a bit.
.goMode
call ResetGameTime
ldh a, [hModeCounter]
dec a
jr nz, .notdonego
@ -1255,6 +1260,7 @@ GamePlayBigEventLoopHandlerB:
call SetNumberSpritePositions
call ApplyTells
call ApplyTime
jp GBCBigGameplayProcess

View File

@ -33,6 +33,20 @@ wSeconds:: ds 1
wFrames:: ds 1
SECTION "Time Data", ROM0
sFramesToCS::
db $00, $02, $03, $05, $07, $10
db $12, $13, $15, $17, $18, $20
db $22, $23, $25, $27, $28, $30
db $32, $33, $35, $37, $38, $40
db $42, $43, $45, $47, $48, $50
db $52, $53, $55, $57, $58, $60
db $62, $63, $65, $67, $68, $70
db $72, $73, $75, $77, $78, $80
db $82, $83, $85, $87, $88, $90
db $92, $93, $95, $97, $98, $00
SECTION "Time Functions", ROM0
; Zeroes all timers and gets the free-running timer ticking.
TimeInit::
@ -106,6 +120,17 @@ HandleTimers::
cp a, MODE_PRE_GAME_OVER
ret z
ld a, [wMinutes]
cp a, 99
jr nz, .go
ld a, [wSeconds]
cp a, 59
jr nz, .go
ld a, [wFrames]
cp a, 59
ret z
.go
ld a, [wFrames]
inc a
ld [wFrames], a