Compare commits
2 Commits
16
...
fix/megade
| Author | SHA1 | Date | |
|---|---|---|---|
| 01adf80751 | |||
|
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 |
|
| Function | Args | Form | What it gives |
|
||||||
|---|---|---|---|
|
|---|---|---|---|
|
||||||
| `ABS` | 1 | `ABS(n)` | The absolute value of an integer or float. |
|
| `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. |
|
| `ATN` | 1 | `ATN(n)` | Arctangent, in radians. |
|
||||||
| `BUMP` | 1 | `BUMP(1)` | Which sprites have collided, as a bitmask. **Reading clears it.** |
|
| `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. |
|
| `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). |
|
| `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. |
|
| `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.** |
|
| `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. |
|
| `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. |
|
| `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. |
|
| `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
|
LABEL UNSTICK
|
||||||
NUDGE# = 0
|
NUDGE# = 0
|
||||||
STALL# = 0
|
STALL# = 0
|
||||||
BVX# = (RND(4) * 3) - 6
|
RMAX# = 4
|
||||||
|
GOSUB RANDOM
|
||||||
|
BVX# = (RND# * 3) - 6
|
||||||
IF BVX# = 0 THEN BVX# = 3
|
IF BVX# = 0 THEN BVX# = 3
|
||||||
RETURN
|
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
|
**There is no `RND` in this dialect**, and no `INT`, `SQR`, `ASC` or `TIMER` either. A
|
||||||
`RND(n)` returns an integer from zero through `n - 1`. It seeds itself
|
linear congruential generator is nine tokens and does the job. Put the number of possible
|
||||||
from the host clock the first time it is called, so a program only needs the bound:
|
answers in `RMAX#` and read the result from `RND#`:
|
||||||
|
|
||||||
```basic
|
```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
|
SEED# = 12345
|
||||||
RMAX# = 6
|
RMAX# = 6
|
||||||
RND# = 0
|
RND# = 0
|
||||||
@@ -1063,11 +1035,43 @@ RND# = MOD((SEED# / 65536), RMAX#)
|
|||||||
RETURN
|
RETURN
|
||||||
```
|
```
|
||||||
|
|
||||||
The multiplication stays inside a 64-bit integer for any seed below 2147483648. The
|
```output
|
||||||
answer is taken from the middle bits because the low bits of a power-of-two modulus
|
ROLL 1
|
||||||
barely change from one call to the next. This used to be required; it is now built in.
|
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
|
`HELD#` is the flag Step 6's loop tests: while it is 1 the ball sits on the paddle, and
|
||||||
`HOLDBAL` keeps it there:
|
`HOLDBAL` keeps it there:
|
||||||
@@ -1418,7 +1422,9 @@ PX# = PX# + D#
|
|||||||
RETURN
|
RETURN
|
||||||
|
|
||||||
LABEL DEMOAIM
|
LABEL DEMOAIM
|
||||||
DOFF# = RND(81) - 40
|
RMAX# = 81
|
||||||
|
GOSUB RANDOM
|
||||||
|
DOFF# = RND# - 40
|
||||||
RETURN
|
RETURN
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -1495,7 +1501,7 @@ This is the shape of the whole file:
|
|||||||
LABEL SETUP the geometry from Step 2
|
LABEL SETUP the geometry from Step 2
|
||||||
the declaration block from Step 3
|
the declaration block from Step 3
|
||||||
the brick faces from Step 5
|
the brick faces from Step 5
|
||||||
RND(n) seeds itself from the host clock
|
SEED# = TI#
|
||||||
the ceiling from Step 9
|
the ceiling from Step 9
|
||||||
GOSUB MKSPR Step 4
|
GOSUB MKSPR Step 4
|
||||||
GOSUB SNDPROBE Step 14
|
GOSUB SNDPROBE Step 14
|
||||||
@@ -1570,7 +1576,10 @@ BB# = 0
|
|||||||
RX# = 0
|
RX# = 0
|
||||||
N# = 0
|
N# = 0
|
||||||
MROW# = 0
|
MROW# = 0
|
||||||
|
RMAX# = 2
|
||||||
|
RND# = 0
|
||||||
SND# = 0
|
SND# = 0
|
||||||
|
SEED# = 0
|
||||||
P$ = ""
|
P$ = ""
|
||||||
H$ = ""
|
H$ = ""
|
||||||
S$ = ""
|
S$ = ""
|
||||||