Skip to content

Commit 6967396

Browse files
committed
LOWERCASE built-in commands for readability
1 parent b37f177 commit 6967396

12 files changed

Lines changed: 2336 additions & 1072 deletions

AGENTS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ done
4141

4242
**Trek demo** (interactive, piped): `sh tests/trek_test.sh` — runs `examples/trek.bas` with `tests/trek.txt` plus `xxx` and `no` appended (resign and don't restart).
4343

44+
**Trek-new regression** (deterministic): `sh tests/trek_new_regression.sh` — runs `examples/trek-new.bas` with fixed RND and three piped scenarios (`tests/fixtures/trek_new/`); see `examples/README.md`.
45+
4446
**IF AND/OR THEN**: `tests/if_and_or_then_test.bas` — regression test for `IF X=13 AND Y=0 THEN` (trek.bas line 5930 pattern); ensures AND/OR in conditions are not parsed as bitwise.
4547

4648
**GFX unit test**: `./gfx_video_test` (headless, no display needed).

examples/README.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# RGC-BASIC examples
2+
3+
Runnable demos and tutorial programs. From the repo root, most terminal examples run as:
4+
5+
```sh
6+
make
7+
./basic -petscii examples/yourprogram.bas
8+
```
9+
10+
Use `make basic-gfx` and `./basic-gfx` for Raylib graphical examples (needs a display).
11+
12+
## Super Star Trek (`trek-new.bas`)
13+
14+
Structured, label-free port of Mike Mayfield’s **Super Star Trek** (1974), kept for teaching modern RGC-BASIC: `FUNCTION` handlers, `SELECT CASE` state dispatch, `EXIT`/`CONTINUE`, no `GOTO` between routines.
15+
16+
Classic line-number version: `trek.bas`. Smoke test for that build: `sh tests/trek_test.sh`.
17+
18+
### Reading order (source tour)
19+
20+
Read the `.bas` file in this order the first time through:
21+
22+
1. **Constants and data** (top): state IDs (`ST_*`), sector tokens, `DIM` / `COURSE_VEC` / `DEVICE_DAMAGE`, `DEF FND` / `DEF FNR`.
23+
2. **Main loop** (`DO` / `SELECT CASE GameState`): dispatches to state functions until `ST_QUIT`.
24+
3. **`SetupGame()`** — title, galaxy generation (`G` packing with `K3`/`B3` per quadrant), mission briefing.
25+
4. **`EnterQuadrant()`** — decode current quadrant, place Enterprise / Klingons / base / stars, then short scan.
26+
5. **`DoCommand()`** — energy check, command prompt, `SELECT CASE CMD` to handlers.
27+
6. **Command handlers**`Nav`, `ShortRangeScan`, `Lrs`, `Phasers`, `Torpedo`, `Shields`, `Damage`, `Computer` (+ computer sub-functions).
28+
7. **Combat / movement helpers**`KlingonsFire`, `ManeuverEnergy`, `FindEmpty`, `PlaceToken`, `CheckSector`.
29+
8. **End states**`ShipDestroyed`, `ShowVictory`, `ShowMissionEnd`, `AskPlayAgain`, etc.
30+
9. **I/O utilities**`GetInput`, `Pause`, `ShowKey`, `ShowCommands`, `QuadrantName`.
31+
32+
Galaxy cell encoding: `G(quadrant) = K3*100 + B3*10 + stars` (see the decode comment in `EnterQuadrant()`).
33+
34+
### Source style (`trek-new.bas`)
35+
36+
Tutorial readability convention (not required for other examples):
37+
38+
- **Built-ins** lower case: `print`, `if`, `for`, `function`, `select case`, `return`, …
39+
- **Game state / arrays** upper case: `SHIP_ENERGY`, `QUADRANT_X`, `COURSE_VEC`, …
40+
- **Your routines** PascalCase: `SetupGame()`, `DoCommand()`, `ShortRangeScan()`, …
41+
- **Player-facing strings** upper case inside literals (classic trek voice)
42+
43+
Re-apply built-in lowercasing after large edits:
44+
45+
```sh
46+
python3 tools/lowercase_builtin_keywords.py examples/trek-new.bas
47+
```
48+
49+
### Deterministic regression
50+
51+
Refactors should not change gameplay output for fixed input. From repo root:
52+
53+
```sh
54+
make
55+
sh tests/trek_new_regression.sh
56+
```
57+
58+
Three piped scenarios live under `tests/fixtures/trek_new/`:
59+
60+
| Scenario | Input file | Exercises (briefly) |
61+
|----------|------------|---------------------|
62+
| A | `input_A.txt` | SRS/LRS, computer modes, damage report, warp, galaxy map |
63+
| B | `input_B.txt` | Play-again restart (`aye` then `xxx` / `no`) |
64+
| C | `input_C.txt` | Warp, phasers, torpedo hits, damage |
65+
66+
The harness copies the program to a temp file with `RND(-1)` and `RND(-TI)` replaced by `RND(1)` so output is stable across machines. Goldens are `golden_A.txt`, `golden_B.txt`, `golden_C.txt` (PETSCII terminal bytes).
67+
68+
After an intentional output change:
69+
70+
```sh
71+
UPDATE_GOLDEN=1 sh tests/trek_new_regression.sh
72+
```
73+
74+
Review the `git diff` on `tests/fixtures/trek_new/golden_*.txt` before committing.
75+
76+
Lint (modern tier):
77+
78+
```sh
79+
python3 -m tools.rgc_lint.cli --tier=modern examples/trek-new.bas
80+
```

0 commit comments

Comments
 (0)