Skip to content

Commit f5f31cc

Browse files
committed
file io
1 parent 3249a6f commit f5f31cc

File tree

12 files changed

+579
-12
lines changed

12 files changed

+579
-12
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,7 @@ dartmouth.bas:Zone.Identifier
6060
basic
6161
*:Zone.Identifier
6262
examples/trek64.bas:Zone.Identifier
63+
basic
64+
CHARS.DAT
65+
.gitignore
66+
*.DAT

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@ Run this once after unpacking, and macOS will stop treating the binary as “fro
6868
- **`DEF FN`**: define simple user functions, e.g. `DEF FNY(X) = SIN(X)`.
6969
- **`POKE`**: accepted as a no‑op (for compatibility with old listings; it does not touch real memory).
7070
- **`CLR`**: resets all variables to 0/empty, clears GOSUB/FOR stacks and DATA pointer; DEF FN definitions are kept.
71+
- **File I/O (CBM-style)**:
72+
- **`OPEN lfn, device, secondary, "filename"`** — open a file (device 1 = disk/file; secondary 0 = read, 1 = write, 2 = append). Filename is a path in the current directory.
73+
- **`PRINT# lfn, expr [,|; expr ...]`** — write to the open file (like `PRINT` to file).
74+
- **`INPUT# lfn, var [, var ...]`** — read from the open file into variables (one token per variable; comma/newline separated).
75+
- **`GET# lfn, stringvar`** — read one character from the file into a string variable.
76+
- **`CLOSE [lfn [, lfn ...]]`** — close file(s); `CLOSE` with no arguments closes all.
77+
- **`ST`** — system variable set after `INPUT#`/`GET#`: 0 = success, 64 = end of file, 1 = error / file not open. Use e.g. `IF ST <> 0 THEN GOTO done`.
7178
- **Variables**
7279
- **Numeric variables**: `A`, `B1`, `AB`, `ATAKFLAG`, etc. Names may be longer than two characters; CBM-style **first two characters** identify the variable (e.g. `ATAKFLAG` and `ATA` refer to the same variable).
7380
- **String variables**: names ending in `$`, e.g. `A$`, `NAME$`.
@@ -212,6 +219,10 @@ The **`examples`** folder (included in release archives) contains:
212219
- **`chr.bas`**: PETSCII/ANSI color and control-code test (run with `-petscii`).
213220
- **`examples/testdef.bas`**, **`tests/read_data.bas`**: small regressions for `DEF FN` and `READ`/`DATA`.
214221
- **`test_dim2d.bas`**, **`test_get.bas`**: multi-dimensional arrays and `GET` Enter handling.
222+
- **`tests/fileio.bas`**, **`tests/fileeof.bas`**, **`tests/test_get_hash.bas`**: file I/O regression tests.
223+
- **`examples/fileio_basics.bas`**: write and read a file (OPEN, PRINT#, INPUT#, CLOSE) with step-by-step comments.
224+
- **`examples/fileio_loop.bas`**: read until end of file using the ST status variable (ST=0/64/1).
225+
- **`examples/fileio_get.bas`**: read one character at a time with GET#.
215226
- **`guess.bas`**, **`adventure.bas`**, **`printx.bas`**, and others for various features.
216227

217228
### Notes on the BASIC dialect

basic

8.27 KB
Binary file not shown.

0 commit comments

Comments
 (0)