Give Snake back the speed its comment promised, and present in step with the display

Two things, one certain and one likely.

THE CERTAIN ONE IS NOT THE WINDOW'S FAULT. Snake's pause loop said "at the emulated rate
this is about an eighth of a second", and it was, when a cycle was one instruction. A cycle
became one memory access, every loop in the machine got dearer, and this one silently
doubled: the game has been running at half the speed it documents ever since, in a terminal
as much as in a window. Measured rather than guessed - the inner loop is a DECA and a BNA,
one byte and three, so four cycles a turn, and a whole run went from 3,848,610 cycles to
1,920,504 when the outer count came down from 256 to 122. Almost exactly half, which is what
the arithmetic said it would be.

That is the cost model change reaching a program nobody thought to re-measure. Worth looking
for others: any loop tuned by eye before that change is running at half its intended speed.

THE LIKELY ONE is the frame limiter. Without the vsync hint, Raylib sleeps towards sixty
frames a second on its own clock, which beats against a display refreshing on its own -
frames shown twice or skipped, and the machine handed an uneven number of cycles each time,
since it takes its budget from the wall clock. The hint puts presentation in step with the
screen. SetTargetFPS stays for a driver that ignores it.

Snake is one byte bigger, because RSTB became INIB.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01E2JrLzFvuFX9fgi1LDRjrW
This commit is contained in:
Anachronaut
2026-08-28 23:19:53 -04:00
co-authored by Claude Opus 5
parent 43a05b3df1
commit 310804e267
4 changed files with 21 additions and 8 deletions
+12 -5
View File
@@ -591,12 +591,19 @@ drawPut:
; ---- Waiting ----
;
; There is no clock on this machine, so time is counted in instructions. At the emulated
; rate this is about an eighth of a second, which is a speed a person can play at. Running
; the emulator faster or slower moves it, and that is the honest answer: the machine has
; no way to know how long a second is and this program is not going to pretend it does.
; There is no clock on this machine, so time is counted in cycles. At the emulated rate this
; is about an eighth of a second, which is a speed a person can play at. Running the emulator
; faster or slower moves it, and that is the honest answer: the machine has no way to know
; how long a second is and this program is not going to pretend it does.
;
; THE COUNT USED TO BE 256 AND THE COMMENT USED TO SAY INSTRUCTIONS. When a cycle stopped
; being an instruction and became a memory access, every loop in the machine got dearer and
; this one silently doubled - the game has been running at half the speed it says ever since,
; in a terminal as much as in a window. The inner loop is a DECA and a BNA, one byte and
; three, so four cycles a turn: 122 times 256 times 4 is about 125,000, which is an eighth of
; a second at a megahertz.
pause:
RSTB
INIB 0d122
pauseOuter:
RSTA
pauseInner: