From 32b02147925566bac93bf71b002860335583574c Mon Sep 17 00:00:00 2001 From: ElectroDeoxys Date: Thu, 9 Sep 2021 08:51:12 +0100 Subject: Split home bank --- src/home/time.asm | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 src/home/time.asm (limited to 'src/home/time.asm') diff --git a/src/home/time.asm b/src/home/time.asm new file mode 100644 index 0000000..83100c7 --- /dev/null +++ b/src/home/time.asm @@ -0,0 +1,93 @@ +; timer interrupt handler +TimerHandler: ; 01e6 (0:01e6) + push af + push hl + push de + push bc + ei + call SerialTimerHandler + ; only trigger every fourth interrupt ≈ 60.24 Hz + ld hl, wTimerCounter + ld a, [hl] + inc [hl] + and $3 + jr nz, .done + ; increment the 60-60-60-255-255 counter + call IncrementPlayTimeCounter + ; check in-timer flag + ld hl, wReentrancyFlag + bit IN_TIMER, [hl] + jr nz, .done + set IN_TIMER, [hl] + ldh a, [hBankROM] + push af + ld a, BANK(SoundTimerHandler) + call BankswitchROM + call SoundTimerHandler + pop af + call BankswitchROM + ; clear in-timer flag + ld hl, wReentrancyFlag + res IN_TIMER, [hl] +.done + pop bc + pop de + pop hl + pop af + reti + +; increment play time counter by a tick +IncrementPlayTimeCounter: ; 021c (0:021c) + ld a, [wPlayTimeCounterEnable] + or a + ret z + ld hl, wPlayTimeCounter + inc [hl] + ld a, [hl] + cp 60 + ret c + ld [hl], $0 + inc hl + inc [hl] + ld a, [hl] + cp 60 + ret c + ld [hl], $0 + inc hl + inc [hl] + ld a, [hl] + cp 60 + ret c + ld [hl], $0 + inc hl + inc [hl] + ret nz + inc hl + inc [hl] + ret + +; setup timer to 16384/68 ≈ 240.94 Hz +SetupTimer: ; 0241 (0:0241) + ld b, -68 ; Value for Normal Speed + call CheckForCGB + jr c, .set_timer + ldh a, [rKEY1] + and $80 + jr z, .set_timer + ld b, $100 - 2 * 68 ; Value for CGB Double Speed +.set_timer + ld a, b + ldh [rTMA], a + ld a, TAC_16384_HZ + ldh [rTAC], a + ld a, TAC_START | TAC_16384_HZ + ldh [rTAC], a + ret + +; return carry if not CGB +CheckForCGB: ; 025c (0:025c) + ld a, [wConsole] + cp CONSOLE_CGB + ret z + scf + ret -- cgit v1.2.3 From 0017fc2d171c87d7bab4c9be90e1069ae95a8071 Mon Sep 17 00:00:00 2001 From: ElectroDeoxys Date: Thu, 9 Sep 2021 08:54:29 +0100 Subject: Remove home bank address comments --- src/home/time.asm | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/home/time.asm') diff --git a/src/home/time.asm b/src/home/time.asm index 83100c7..8b8cda2 100644 --- a/src/home/time.asm +++ b/src/home/time.asm @@ -1,5 +1,5 @@ ; timer interrupt handler -TimerHandler: ; 01e6 (0:01e6) +TimerHandler: push af push hl push de @@ -37,7 +37,7 @@ TimerHandler: ; 01e6 (0:01e6) reti ; increment play time counter by a tick -IncrementPlayTimeCounter: ; 021c (0:021c) +IncrementPlayTimeCounter: ld a, [wPlayTimeCounterEnable] or a ret z @@ -67,7 +67,7 @@ IncrementPlayTimeCounter: ; 021c (0:021c) ret ; setup timer to 16384/68 ≈ 240.94 Hz -SetupTimer: ; 0241 (0:0241) +SetupTimer: ld b, -68 ; Value for Normal Speed call CheckForCGB jr c, .set_timer @@ -85,7 +85,7 @@ SetupTimer: ; 0241 (0:0241) ret ; return carry if not CGB -CheckForCGB: ; 025c (0:025c) +CheckForCGB: ld a, [wConsole] cp CONSOLE_CGB ret z -- cgit v1.2.3