Unbreak the three example programs the RND merge left behind
All checks were successful
akbasic CI Build / cmake_build (push) Successful in 3m46s
akbasic CI Build / coverage (push) Successful in 4m16s
akbasic CI Build / sanitizers (push) Successful in 8m10s
akbasic CI Build / akgl_build (push) Successful in 8m10s
akbasic CI Build / mutation_test (push) Successful in 17m55s

Adding native RND and ASC (ae2c702) made RND a function name, and a suffixed
identifier that collides with one is refused -- "SYNTAX ERROR Reserved word in
variable name". Three example programs held their PRNG output in a variable
called RND#, or a host field called RND%, and none of them had run since:

  - examples/galaga/ bound RND% as a host field on both ENEMY and GAME. The
    BASIC-visible name is ROLL% now; the C member stays `rnd`. This one was
    caught by example_galaga and example_galaga_interop, which have been
    failing.
  - examples/breakout/characters/breakout.bas and examples/megademo/
    megademo.bas both use RND# for their LCG output, renamed to ROLL#. Neither
    is in any test, so neither failure was visible.

examples/breakout/sprites/breakout.bas was broken a second way: seven REM lines
the reader refuses. Worth recording that the ceiling is not the one the message
names -- src/sink_stdio.c fails when the read filled the buffer without seeing
a terminator, so with AKBASIC_MAX_LINE_LENGTH at 80 the message says "79
character limit" and the real maximum is 78, because a 79-character line leaves
no room for the newline. The sweeps that fixed the corpus and the megademo for
this did not reach this file. The seven comments are reflowed.

The prose went stale with the code. Chapter 21 said "there is no RND verb in
this dialect; issue #16 tracks adding one", chapter 17's historical aside
offered an LCG that no longer parses, and four REM blocks across the two games
said the same thing. All of them now say RND exists, and say why these programs
keep their own generator anyway: the sequence has to be reproducible for a
headless run to be the same game on every machine, which is what lets
interop_test.c assert exact counts.

Chapter 21 also gains the rule that bit them, since a reader writing a host
type will hit it: a host field name is a bare word and shares a namespace with
every verb and function.

None of this came from the submodule bump -- all three were already broken on
main. It was found by running the tutorial games, which nothing else does;
that gap is akbasic issue #58.

Verified: all three run clean under the dummy drivers, and 114/114 default,
116/116 with akgl.

Co-Authored-By: Andrew Kesterson <andrew@aklabs.net>
Co-Authored-By: Claude Code (Claude Opus 5, claude-opus-5[1m]) <noreply@anthropic.com>
This commit is contained in:
2026-08-05 23:26:33 -04:00
parent a15e172c2a
commit 13f1df03ef
10 changed files with 84 additions and 53 deletions

View File

@@ -145,7 +145,7 @@ RX# = 0
N# = 0
MROW# = 0
RMAX# = 2
RND# = 0
ROLL# = 0
SND# = 0
P$ = ""
H$ = ""
@@ -172,7 +172,8 @@ BSG$(4) = "[--]"
BSG$(5) = "[--]"
REM --- the seed -------------------------------------------------------
REM There is no RND in this dialect. TI# is jiffies off the host's clock
REM RND exists now, but this program keeps its own LCG so a headless run
REM is the same game every time. TI# is jiffies off the host's clock
REM and is host uptime rather than zero-based, which makes it a fine seed.
SEED# = TI#
@@ -389,17 +390,18 @@ BY# = PY# - 10
RMAX# = 2
GOSUB RANDOM
BVX# = BSPD#
IF RND# = 0 THEN BVX# = 0 - BSPD#
IF ROLL# = 0 THEN BVX# = 0 - BSPD#
BVY# = 0 - BSPD#
PDEC# = 0
GOSUB SHOWSPR
RETURN
REM A linear congruential generator, because this dialect has no RND.
REM A linear congruential generator. RND(n) would do this in one token
REM now; the LCG stays because its sequence is reproducible.
REM The multiply stays inside int64 for any seed under 2^31.
LABEL RANDOM
SEED# = MOD(((SEED# * 1103515245) + 12345), 2147483648)
RND# = MOD((SEED# / 65536), RMAX#)
ROLL# = MOD((SEED# / 65536), RMAX#)
RETURN
REM ####################################################################
@@ -632,7 +634,7 @@ NUDGE# = 0
STALL# = 0
RMAX# = 4
GOSUB RANDOM
BVX# = (RND# * 3) - 6
BVX# = (ROLL# * 3) - 6
IF BVX# = 0 THEN BVX# = 3
RETURN
@@ -641,7 +643,7 @@ REM like something with a hand on the paddle rather than a mirror.
LABEL DEMOAIM
RMAX# = 81
GOSUB RANDOM
DOFF# = RND# - 40
DOFF# = ROLL# - 40
RETURN
REM ####################################################################

View File

@@ -241,7 +241,8 @@ SLX# = 0
SLY# = 0
SLI# = 0
REM The two eraser stamps. Declared here for exactly the same reason -- built
REM inside DRAWPROTOS and left undeclared, they were SHAPE:6 and SHAPE:7 inside
REM inside DRAWPROTOS and left undeclared, they were SHAPE:6 and SHAPE:7
REM inside
REM it and empty everywhere else.
BL$ = ""
HBL$ = ""
@@ -254,10 +255,13 @@ REM cursor through every DATA item in the program in the order they appear
REM in the file, so whichever loader runs first gets the DATA that is
REM written first. The tables are written first.
REM The text layer repaints every row it owns, opaque, so it has to be moved
REM out of the way before anything drawn can be seen. Two rows at the bottom is
REM out of the way before anything drawn can be seen. Two rows at the bottom
REM is
REM enough for the final score, and hands the other thirty-five to the drawing
REM verbs. Everything this game draws then simply stays there -- a drawing goes
REM into a layer the frame composites, so nothing here is captured into a sprite
REM verbs. Everything this game draws then simply stays there -- a drawing
REM goes
REM into a layer the frame composites, so nothing here is captured into a
REM sprite
REM and nothing is redrawn every frame.
WINDOW 0, 35, 49, 36
@@ -293,7 +297,8 @@ ENVELOPE 0, 0, 6, 0, 4
TEMPO 12
COLLISION 2, BRICKHIT
REM The stamps, once. They used to be rebuilt whenever the SSHAPE pool ran dry,
REM The stamps, once. They used to be rebuilt whenever the SSHAPE pool ran
REM dry,
REM because every frame's capture spent another slot; nothing captures now, so
REM eight slots are spent here and never again.
GOSUB DRAWPROTOS
@@ -374,7 +379,8 @@ COLOR 1, 1
FOR K# = 0 TO 15
DRAW 1, 0, 130 + K# TO 67, 130 + K#
NEXT K#
REM And an eighth the width of the HUD strip, for the same reason: the strip is
REM And an eighth the width of the HUD strip, for the same reason: the strip
REM is
REM rewritten whenever a number in it changes, and the old digits have to go
REM somewhere first.
FOR K# = 0 TO 59
@@ -393,7 +399,8 @@ DPLAY# = 1
DHUD# = 1
RETURN
REM Take one brick off the screen: stamp the blank over it. Called when a brick
REM Take one brick off the screen: stamp the blank over it. Called when a
REM brick
REM breaks, so the field is never redrawn as a whole during play -- which is
REM what lets the whole live-list machinery go.
LABEL ERASEBRICK
@@ -444,7 +451,8 @@ WIDTH 1
COLOR 0, 1 : COLOR 1, 4 : COLOR 2, 8 : COLOR 3, 5
COLOR 4, 11 : COLOR 5, 16 : COLOR 6, 6
REM The old strip goes first. Nothing here clears the screen -- a drawing
REM stays, which is the whole point -- so the digits that were there have to be
REM stays, which is the whole point -- so the digits that were there have to
REM be
REM stamped over before the new ones are drawn.
Z$ = HBL$
GSHAPE Z$, 0, 0
@@ -495,7 +503,10 @@ IF SNDON# = 0 THEN VOL 0
RETURN
LABEL PRESSPAUSE
IF STATE# = 2 THEN STATE# = 6 : GMTYP# = 0 : BAN$ = "PAUSED" : GOSUB SETBANNER : RETURN
IF STATE# <> 2 THEN GOTO PRESSPAUSE2
STATE# = 6 : GMTYP# = 0 : BAN$ = "PAUSED" : GOSUB SETBANNER
RETURN
LABEL PRESSPAUSE2
IF STATE# = 6 THEN STATE# = 2 : BAN$ = "" : GOSUB SETBANNER
RETURN