aboutsummaryrefslogtreecommitdiffstats
path: root/src/syscall.asm
diff options
context:
space:
mode:
authoruser <user@clank>2026-07-18 22:06:35 +0200
committeruser <user@clank>2026-07-18 22:06:35 +0200
commit4425150cb6f52d15f513690a75645639358a2030 (patch)
treeb186e048c286f7fb9b78552fb10ebf417ac5178c /src/syscall.asm
parentterm: latch SCY in VBlank - fix ring-scroll shear on live displays (diff)
downloadgbos-4425150cb6f52d15f513690a75645639358a2030.tar.gz
gbos-4425150cb6f52d15f513690a75645639358a2030.tar.xz
gbos-4425150cb6f52d15f513690a75645639358a2030.zip
kernel: CGB double-speed mode - 2x everything (1.99x measured)
KEY1 prepare + STOP at KernelInit (skipped on warm reboot if already fast). The PPU/LCD keep their normal rate; the timer and DIV double with the CPU, compensated at the two consumers: - TimerISR now fires at 128 Hz; a toggle byte keeps wTicks at 64 Hz (uptime semantics unchanged) - sys_sleep halves the DIV-delta accumulator's high byte (256 DIV ticks = 1/128 s in double speed) so gsleep/msleep stay real-time Measured: count 60 (scroll-heavy) 3.77s -> 1.89s wall; wTicks 64 Hz over 4s; ping's 800ms msleep pacing unchanged (2.77s for 4 echoes). sl0pboy already emulated KEY1/STOP + per-speed timer/PPU rates.
Diffstat (limited to 'src/syscall.asm')
-rw-r--r--src/syscall.asm9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/syscall.asm b/src/syscall.asm
index e3f0b1b..4bcb601 100644
--- a/src/syscall.asm
+++ b/src/syscall.asm
@@ -277,8 +277,10 @@ ENDR
; -----------------------------------------------------------------------------
; sys_sleep(B = 1/64-second units) - cooperative delay driven by the DIV timer.
-; DIV (FF04) free-runs at 16384 Hz, so 256 ticks = 1/64 s. We accumulate DIV
-; deltas across SchedYields (other procs run) until enough units have elapsed.
+; DIV free-runs at 16384 Hz - 32768 Hz in double-speed mode, where 256 ticks
+; = 1/128 s - so the accumulated high byte is halved before comparing against
+; the target. We accumulate DIV deltas across SchedYields (other procs run)
+; until enough 1/64-second units have elapsed.
; -----------------------------------------------------------------------------
sys_sleep:
ld a, b
@@ -305,7 +307,8 @@ sys_sleep:
ld [wSleepAcc], a
ld a, [wSleepAcc+1]
adc 0
- ld [wSleepAcc+1], a ; acc high byte = elapsed 1/64-second units
+ ld [wSleepAcc+1], a ; acc high byte = elapsed 1/128-second units
+ srl a ; /2: double-speed DIV -> 1/64-second units
ld b, a
ld a, [wSleepTarget]
cp b