Compare commits
2 Commits
16
...
1e514f679b
| Author | SHA1 | Date | |
|---|---|---|---|
|
1e514f679b
|
|||
|
17af2d406c
|
@@ -9,7 +9,6 @@ so a call with the wrong number is a syntax error rather than a surprise.
|
||||
| Function | Args | Form | What it gives |
|
||||
|---|---|---|---|
|
||||
| `ABS` | 1 | `ABS(n)` | The absolute value of an integer or float. |
|
||||
| `ASC` | 1 | `ASC(A$)` | The Unicode code point of a string's first character. |
|
||||
| `ATN` | 1 | `ATN(n)` | Arctangent, in radians. |
|
||||
| `BUMP` | 1 | `BUMP(1)` | Which sprites have collided, as a bitmask. **Reading clears it.** |
|
||||
| `CHR` | 1 | `CHR(n)` | The character for a Unicode code point, as a string. |
|
||||
@@ -30,7 +29,6 @@ so a call with the wrong number is a syntax error rather than a surprise.
|
||||
| `RGR` | 1 | `RGR(f)` | The `GRAPHIC` mode (0), the drawing surface's width (1) or height (2) in pixels, or a character cell's width (3) or height (4). |
|
||||
| `RIGHT` | 2 | `RIGHT(A$, n)` | The rightmost `n` characters. Clamped. |
|
||||
| `RMENU` | 2 | `RMENU(n, f)` | A menu's state: field 0 the highlighted entry, field 1 whether it has been confirmed. **Reading field 1 clears it.** |
|
||||
| `RND` | 1 | `RND(n)` | A random integer from 0 up to but not including `n`. |
|
||||
| `RWINDOW` | 1 | `RWINDOW(f)` | The current text window's rows (0) or columns (1). Field 2 is a C128 screen mode and is refused. |
|
||||
| `RSPCOLOR` | 1 | `RSPCOLOR(n)` | One of `SPRCOLOR`'s two shared registers, 1 or 2. |
|
||||
| `RSPHIT` | 2 | `RSPHIT(n, f)` | One of `SPRHIT`'s settings for sprite `n`, in `SPRHIT`'s own argument order: 0 the kind, 1 to 4 the two corners. |
|
||||
|
||||
@@ -1005,48 +1005,20 @@ IF NUDGE# = 1 THEN GOSUB UNSTICK
|
||||
LABEL UNSTICK
|
||||
NUDGE# = 0
|
||||
STALL# = 0
|
||||
BVX# = (RND(4) * 3) - 6
|
||||
RMAX# = 4
|
||||
GOSUB RANDOM
|
||||
BVX# = (RND# * 3) - 6
|
||||
IF BVX# = 0 THEN BVX# = 3
|
||||
RETURN
|
||||
```
|
||||
|
||||
### Random numbers are built in
|
||||
### You have to write your own random numbers
|
||||
|
||||
There is no `INT`, `SQR` or `TIMER` in this dialect, but
|
||||
`RND(n)` returns an integer from zero through `n - 1`. It seeds itself
|
||||
from the host clock the first time it is called, so a program only needs the bound:
|
||||
**There is no `RND` in this dialect**, and no `INT`, `SQR`, `ASC` or `TIMER` either. A
|
||||
linear congruential generator is nine tokens and does the job. Put the number of possible
|
||||
answers in `RMAX#` and read the result from `RND#`:
|
||||
|
||||
```basic
|
||||
I# = 0
|
||||
FOR I# = 1 TO 5
|
||||
PRINT "ROLL " + (RND(6) + 1)
|
||||
NEXT I#
|
||||
END
|
||||
```
|
||||
|
||||
Use `RND` for the serve, too, so the ball does not always leave in the same direction:
|
||||
|
||||
```basic norun
|
||||
LABEL SERVE
|
||||
PX# = (SCW# - PW#) / 2
|
||||
HELD# = 1
|
||||
BX# = PX# + ((PW# / 2) - 4)
|
||||
BY# = PY# - 10
|
||||
BVX# = BSPD#
|
||||
IF RND(2) = 0 THEN BVX# = 0 - BSPD#
|
||||
BVY# = 0 - BSPD#
|
||||
PDEC# = 0
|
||||
GOSUB SHOWSPR
|
||||
RETURN
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>Historical aside: the LCG this chapter used to teach</summary>
|
||||
|
||||
Before `RND` existed, this nine-token linear congruential generator was copied into
|
||||
every program. It remains a useful from-scratch PRNG example:
|
||||
|
||||
```basic norun
|
||||
SEED# = 12345
|
||||
RMAX# = 6
|
||||
RND# = 0
|
||||
@@ -1063,11 +1035,43 @@ RND# = MOD((SEED# / 65536), RMAX#)
|
||||
RETURN
|
||||
```
|
||||
|
||||
The multiplication stays inside a 64-bit integer for any seed below 2147483648. The
|
||||
answer is taken from the middle bits because the low bits of a power-of-two modulus
|
||||
barely change from one call to the next. This used to be required; it is now built in.
|
||||
```output
|
||||
ROLL 1
|
||||
ROLL 5
|
||||
ROLL 2
|
||||
ROLL 1
|
||||
ROLL 2
|
||||
```
|
||||
|
||||
</details>
|
||||
The multiplication stays inside a 64-bit integer for any seed below 2147483648, which is
|
||||
why the modulus is that number. The answer is taken from the middle bits — `SEED# / 65536`
|
||||
— because the low bits of a power-of-two modulus barely change from one call to the next.
|
||||
Integer division truncating for free is the `INT` you do not have.
|
||||
|
||||
Seed it from the clock at startup. `TI#` is the host's uptime in sixtieths of a second,
|
||||
which is different every time the game is run:
|
||||
|
||||
```basic norun
|
||||
SEED# = TI#
|
||||
```
|
||||
|
||||
Use `RANDOM` for the serve, too, so the ball does not always leave in the same direction:
|
||||
|
||||
```basic norun
|
||||
LABEL SERVE
|
||||
PX# = (SCW# - PW#) / 2
|
||||
HELD# = 1
|
||||
BX# = PX# + ((PW# / 2) - 4)
|
||||
BY# = PY# - 10
|
||||
RMAX# = 2
|
||||
GOSUB RANDOM
|
||||
BVX# = BSPD#
|
||||
IF RND# = 0 THEN BVX# = 0 - BSPD#
|
||||
BVY# = 0 - BSPD#
|
||||
PDEC# = 0
|
||||
GOSUB SHOWSPR
|
||||
RETURN
|
||||
```
|
||||
|
||||
`HELD#` is the flag Step 6's loop tests: while it is 1 the ball sits on the paddle, and
|
||||
`HOLDBAL` keeps it there:
|
||||
@@ -1418,7 +1422,9 @@ PX# = PX# + D#
|
||||
RETURN
|
||||
|
||||
LABEL DEMOAIM
|
||||
DOFF# = RND(81) - 40
|
||||
RMAX# = 81
|
||||
GOSUB RANDOM
|
||||
DOFF# = RND# - 40
|
||||
RETURN
|
||||
```
|
||||
|
||||
@@ -1495,7 +1501,7 @@ This is the shape of the whole file:
|
||||
LABEL SETUP the geometry from Step 2
|
||||
the declaration block from Step 3
|
||||
the brick faces from Step 5
|
||||
RND(n) seeds itself from the host clock
|
||||
SEED# = TI#
|
||||
the ceiling from Step 9
|
||||
GOSUB MKSPR Step 4
|
||||
GOSUB SNDPROBE Step 14
|
||||
@@ -1570,7 +1576,10 @@ BB# = 0
|
||||
RX# = 0
|
||||
N# = 0
|
||||
MROW# = 0
|
||||
RMAX# = 2
|
||||
RND# = 0
|
||||
SND# = 0
|
||||
SEED# = 0
|
||||
P$ = ""
|
||||
H$ = ""
|
||||
S$ = ""
|
||||
|
||||
@@ -56,7 +56,10 @@ This is a tour of the interpreter's edges, on purpose:
|
||||
counterpoint: a genuine 24x21 `SPRSAV` type-in sprite, 63 bytes, which is
|
||||
everything `DATA` has room to say. The paint is the reveal, and the exit is a
|
||||
stride-63 column dissolve — 63 is coprime to 160, so the walk hits every
|
||||
column once and looks random while carrying no state.
|
||||
column once and looks random while carrying no state. The strings come in
|
||||
64-character chunks because a source line is 80 columns, like the machines
|
||||
this pretends to be — the decoder carries its cursor from one `IM$` entry to
|
||||
the next, and the generator refuses to cut inside a run.
|
||||
- **And then the picture is video.** Six delta frames loop the floor grid toward
|
||||
you and crawl the sun's slice pattern — full motion video, 1.3 KB total, about
|
||||
220 bytes a frame. A delta re-encodes only the rows that changed: an `R`
|
||||
@@ -82,6 +85,10 @@ This is a tour of the interpreter's edges, on purpose:
|
||||
batch a bar of noise drums. Noise is real: `ENVELOPE`'s sixth argument is a
|
||||
waveform, 0 to 3, which Chapter 7 forgot to mention. Voice 1 carries the tune so
|
||||
the collision blips (voice 2) and scene sweeps (voice 3) never steal its channel.
|
||||
A batch is four `PLAY` statements, one bar each — the 80-column line limit will
|
||||
not hold four bars in one string, and it does not need to: the parser's voice,
|
||||
envelope and duration state persists across statements and every `PLAY` appends
|
||||
to the same queue, so four bars queue exactly as one line would.
|
||||
|
||||
It also probes for its hardware like a proper boot loader, with one `TRAP` per
|
||||
device: no graphics refuses by name and exits, no audio mutes the soundtrack, no
|
||||
|
||||
@@ -461,38 +461,78 @@ BS% = W# / 160
|
||||
IF BS% < 1 THEN BS% = 1
|
||||
REM ---- PICTURE-BEGIN (generated by vaporwave.py; do not
|
||||
REM ---- hand-edit -- rerun the script to change the picture)
|
||||
DIM IM$(16)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A9APRCME9E9E9E9EPRCRA9A9A9A9APRCTE9E9E9E9EPRC1A9A9"
|
||||
IM$(51) = "A9A9APRC3E9E9E9E9EPRDFA9A9A9A9APRDIE9E9E9E9EP"
|
||||
IM$(52) = "RBSQ9QTKPQHK3RBTQ9QOI9IWRBYQ9QPKDQHKPQHKHRBZQ9QTI9ILRB4Q9QSIAKH"
|
||||
IM$(53) = "I5KHIBRB6Q9QTC9CMRCAQ9QXI9IERCEE9E9E9E9EPRCFA9A9A9A9APRCGE9E9E9"
|
||||
IM$(54) = "E9EPRCMA9A9A9A9APRCNE9E9E9E9EPRCTA9A9A9A9APRCUE9E9E9E9EPRC3A9A9"
|
||||
IM$(55) = "A9A9APRC5E9E9E9E9EPRDIA9A9A9A9AP"
|
||||
REM ---- PICTURE-END
|
||||
SS# = 0
|
||||
SE# = NS# - 1
|
||||
@@ -1317,13 +1357,25 @@ TB# = TB# + 1
|
||||
IF TB# > 2 THEN TB# = 0
|
||||
RETURN
|
||||
|
||||
REM A batch is four PLAY statements, one bar each: the parser's V, T,
|
||||
REM U and duration state persists across statements and every PLAY
|
||||
REM appends to the same queue, so four bars queue exactly as one long
|
||||
REM string would -- which the 80-column line limit no longer allows.
|
||||
REM Each bar restates the prefix anyway, so a bar dropped by QFULL
|
||||
REM never leaves the next one playing with drum-kit state.
|
||||
LABEL TUNEA
|
||||
PLAY "V1T3U9S O1AO2AO3AO2AO3AO4CEAO1AO2AO4CEAO5CO4AE O1FO2FO3FO2FO3FAO4CFO1FO2FO3AO4CFAO5CO4A O1CO2CO3CO2CO3CEGO4CO1CO2CO3EGO4CEGO5C O1GO2GO3GO2GO3GBO4DGO1GO2GO3BO4DGBO5DO4B"
|
||||
PLAY "V1T3U9S O1AO2AO3AO2AO3AO4CEAO1AO2AO4CEAO5CO4AE"
|
||||
PLAY "V1T3U9S O1FO2FO3FO2FO3FAO4CFO1FO2FO3AO4CFAO5CO4A"
|
||||
PLAY "V1T3U9S O1CO2CO3CO2CO3CEGO4CO1CO2CO3EGO4CEGO5C"
|
||||
PLAY "V1T3U9S O1GO2GO3GO2GO3GBO4DGO1GO2GO3BO4DGBO5DO4B"
|
||||
MT# = TI# + 270
|
||||
RETURN
|
||||
|
||||
LABEL TUNEB
|
||||
PLAY "V1T3U9S O1AO2AO3AO2AO3AO4CEAO1AO2AO4CEAO5CEO4A O1FO2FO3FO2FO3FAO4CFO1FO2FO3AO4CFAO5CO4A O1DO2DO3DO2DO3DFAO4DO1DO2DO3FAO4DFAO5D O1EO2EO3EO2EO3E#GBO4EO1EO2EO3#GBO4E#GBO5E"
|
||||
PLAY "V1T3U9S O1AO2AO3AO2AO3AO4CEAO1AO2AO4CEAO5CEO4A"
|
||||
PLAY "V1T3U9S O1FO2FO3FO2FO3FAO4CFO1FO2FO3AO4CFAO5CO4A"
|
||||
PLAY "V1T3U9S O1DO2DO3DO2DO3DFAO4DO1DO2DO3FAO4DFAO5D"
|
||||
PLAY "V1T3U9S O1EO2EO3EO2EO3E#GBO4EO1EO2EO3#GBO4E#GBO5E"
|
||||
MT# = TI# + 270
|
||||
RETURN
|
||||
|
||||
|
||||
@@ -58,7 +58,14 @@ SKIP = "Q"
|
||||
ROWREC = "R"
|
||||
LENCH = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
||||
MAXRUN = len(LENCH)
|
||||
PAYLOAD = 240
|
||||
|
||||
# The interpreter reads source through an 80-byte line buffer and refuses
|
||||
# any line that fills it (AKBASIC_MAX_LINE_LENGTH, sink_stdio.c), so a
|
||||
# stored line is at most 78 characters plus its newline. 'IM$(NN) = "' and
|
||||
# the closing quote spend 12 of those; 64 keeps the emitted lines under
|
||||
# the ceiling with margin to spare while the index stays two digits.
|
||||
PAYLOAD = 64
|
||||
MAXLINE = 78
|
||||
|
||||
SUN_CX, SUN_CY, SUN_R = 80, 50, 30
|
||||
HORIZON = 74
|
||||
@@ -206,13 +213,32 @@ def encode_delta(prev, cur):
|
||||
|
||||
|
||||
def chop(blob):
|
||||
return [blob[i:i + PAYLOAD] for i in range(0, len(blob), PAYLOAD)]
|
||||
"""Split a stream into strings of at most PAYLOAD characters, cutting
|
||||
only between records. The decoder reads a record's tail characters
|
||||
with MID on the string it is walking, so a run (two characters) or a
|
||||
row record (three) that straddled two IM$ entries would decode as
|
||||
garbage; DRAWSTREAM only carries the cursor, never a partial record."""
|
||||
out, cur = [], ""
|
||||
p = 0
|
||||
while p < len(blob):
|
||||
n = 3 if blob[p] == ROWREC else 2
|
||||
if len(cur) + n > PAYLOAD:
|
||||
out.append(cur)
|
||||
cur = ""
|
||||
cur += blob[p:p + n]
|
||||
p += n
|
||||
if cur:
|
||||
out.append(cur)
|
||||
return out
|
||||
|
||||
|
||||
def simulate(raster, blob):
|
||||
def simulate(raster, blob, x=0, y=0):
|
||||
"""Apply one encoded stream to a raster exactly the way the BASIC
|
||||
decoder does, skips-draw-nothing and all."""
|
||||
x = y = p = 0
|
||||
decoder does, skips-draw-nothing and all. The cursor comes in and
|
||||
goes back out because DRAWSTREAM carries it from one IM$ entry to
|
||||
the next -- decoding the chopped strings one at a time with the
|
||||
cursor threaded through is exactly what the demo will execute."""
|
||||
p = 0
|
||||
while p < len(blob):
|
||||
c = blob[p]
|
||||
if c == ROWREC:
|
||||