recomment game time functions

This commit is contained in:
yenatch 2013-09-03 18:56:33 -04:00
parent 340e31d839
commit 2c36afc6c3
1 changed files with 52 additions and 60 deletions

112
main.asm
View File

@ -528,19 +528,16 @@ ResetGameTime: ; 208a
GameTimer: ; 209e GameTimer: ; 209e
; precautionary
nop nop
; save wram bank
ld a, [rSVBK] ld a, [rSVBK]
push af push af
ld a, 1
ld a, $1
ld [rSVBK], a ld [rSVBK], a
call UpdateGameTimer call UpdateGameTimer
; restore wram bank
pop af pop af
ld [rSVBK], a ld [rSVBK], a
ret ret
@ -548,110 +545,105 @@ GameTimer: ; 209e
UpdateGameTimer: ; 20ad UpdateGameTimer: ; 20ad
; increment the game timer by one frame ; Increment the game timer by one frame.
; capped at 999:59:59.00 after exactly 1000 hours ; The game timer is capped at 999:59:59.00.
; pause game update?
; Don't update if game logic is paused.
ld a, [$c2cd] ld a, [$c2cd]
and a and a
ret nz ret nz
; game timer paused? ; Is the timer paused?
ld hl, GameTimerPause ld hl, GameTimerPause
bit 0, [hl] bit 0, [hl]
ret z ret z
; reached cap? (999:00:00.00) ; Is the timer already capped?
ld hl, GameTimeCap ld hl, GameTimeCap
bit 0, [hl] bit 0, [hl]
ret nz ret nz
; increment frame counter
ld hl, GameTimeFrames ; frame counter ; +1 frame
ld hl, GameTimeFrames
ld a, [hl] ld a, [hl]
inc a inc a
; reached 1 second?
cp 60 ; frames/second cp 60 ; frames/second
jr nc, .second ; 20c5 $2 jr nc, .second
; update frame counter
ld [hl], a ld [hl], a
ret ret
.second .second
; reset frame counter
xor a xor a
ld [hl], a ld [hl], a
; increment second counter ; +1 second
ld hl, GameTimeSeconds ld hl, GameTimeSeconds
ld a, [hl] ld a, [hl]
inc a inc a
; reached 1 minute?
cp 60 ; seconds/minute cp 60 ; seconds/minute
jr nc, .minute jr nc, .minute
; update second counter
ld [hl], a ld [hl], a
ret ret
.minute .minute
; reset second counter
xor a xor a
ld [hl], a ld [hl], a
; increment minute counter ; +1 minute
ld hl, GameTimeMinutes ld hl, GameTimeMinutes
ld a, [hl] ld a, [hl]
inc a inc a
; reached 1 hour?
cp 60 ; minutes/hour cp 60 ; minutes/hour
jr nc, .hour jr nc, .hour
; update minute counter
ld [hl], a ld [hl], a
ret ret
.hour .hour
; reset minute counter
xor a xor a
ld [hl], a ld [hl], a
; increment hour counter ; +1 hour
ld a, [GameTimeHours] ld a, [GameTimeHours]
ld h, a ld h, a
ld a, [GameTimeHours+1] ld a, [GameTimeHours + 1]
ld l, a ld l, a
inc hl inc hl
; reached 1000 hours?
; Cap the timer after 1000 hours.
ld a, h ld a, h
cp $3 ; 1000 / $100 cp 1000 / $100
jr c, .updatehr jr c, .ok
ld a, l ld a, l
cp $e8 ; 1000 & $ff cp 1000 % $100
jr c, .updatehr jr c, .ok
; cap at 999:59:59.00
ld hl, GameTimeCap ld hl, GameTimeCap
set 0, [hl] ; stop timer set 0, [hl]
ld a, 59 ld a, 59 ; 999:59:59.00
ld [GameTimeMinutes], a ld [GameTimeMinutes], a
ld [GameTimeSeconds], a ld [GameTimeSeconds], a
; this will never be run again
ret ret
.updatehr
.ok
ld a, h ld a, h
ld [GameTimeHours], a ld [GameTimeHours], a
ld a, l ld a, l
ld [GameTimeHours+1], a ld [GameTimeHours + 1], a
ret ret
; 210f ; 210f