BASIC: file dates and data files
DATE "YYYY-MM-DD[ HH:MM[:SS]]" sets a clock kept from the millisecond counter, DATE prints it and DATE$ returns it. Directory entries now record each file's creation date (format BFS2; a BFS1 directory is widened when read), and DIR shows it. send-bas.py and get-bas.py set the date from the PC when they connect (--no-date to skip). Data files: OPEN "NAME" FOR INPUT|OUTPUT|APPEND AS #n (n = 1-3), PRINT #n, INPUT #n, LINE INPUT [#n,], EOF(n), CLOSE [#n]. SAVE and LOAD now use the same channel code. A written file replaces the old one only at CLOSE; APPEND shares the old file's full blocks and copies the last part block. New errors FILE ALREADY OPEN, FILE NOT OPEN, INPUT PAST END; PROGRAM TOO BIG TO SAVE becomes FILE TOO BIG. The program area shrinks from 23000 to 22100 bytes to keep the stack at about 3 KB beside the file buffers. Code now ends at 7EBFh. The simulation sets the date, checks it in DIR and round-trips a data file, waiting for expected rows instead of fixed delays. Tested on the board: dates, write/append/read, EOF, the BFS1 conversion. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
29a15bf7c7
commit
767377f38d
9 files changed
+11631
-11174
No files matched your search
+97
-15
@@ -70,6 +70,7 @@ case, except inside quotes.
|
||||
| `LOAD "NAME"` | Bring a saved program back |
|
||||
| `RUN "NAME"` | Load a saved program and run it |
|
||||
| `DIR` / `DEL "NAME"` | List the saved programs / delete one |
|
||||
| `DATE "2026-11-28 09:30"` | Set the date and time, which `SAVE` records |
|
||||
|
||||
## 2. Program lines
|
||||
|
||||
@@ -201,6 +202,11 @@ with `?? `. A string can be typed bare or in quotes; quotes are needed if it
|
||||
contains a comma. Typing something that isn't a number for a numeric variable
|
||||
gives `?REDO` and asks again. Ctrl-C stops the program.
|
||||
|
||||
`LINE INPUT A$` (or `LINE INPUT "PROMPT"; A$`) takes the whole line into one
|
||||
string, commas and quotes included, and prints no `? `.
|
||||
|
||||
`PRINT #`, `INPUT #` and `LINE INPUT #` do the same with a file (section 10).
|
||||
|
||||
### IF … THEN — decisions
|
||||
|
||||
```
|
||||
@@ -344,6 +350,8 @@ A whole number from 1 to 6: `1 + INT(RND * 6)`.
|
||||
| Function | Result |
|
||||
|---|---|
|
||||
| `TIM` | Seconds since the Z-80 was reset, to the millisecond |
|
||||
| `DATE$` | The date and time as `"2026-11-28 09:30:15"`, or `""` if not set (section 10) |
|
||||
| `EOF(N)` | -1 (true) when file *N* has been read to the end, else 0 (section 10) |
|
||||
| `POINT(X, Y)` | Colour of the graphics pixel at *X, Y* (0 off screen) |
|
||||
| `PEEK(A)` | Byte at memory address *A* |
|
||||
| `INP(P)` | Byte from I/O port *P* |
|
||||
@@ -464,8 +472,8 @@ stays where it is.
|
||||
| Addresses | Contents |
|
||||
|---|---|
|
||||
| 0000–7FFF | BASIC itself (writes here are ignored) |
|
||||
| 8000–EBFF | BASIC's variables, your program and arrays |
|
||||
| EC00–FFFF | The Z-80 stack |
|
||||
| 8000–F3FF | BASIC's variables, your program and arrays, file buffers |
|
||||
| F400–FFFF | The Z-80 stack |
|
||||
|
||||
`PEEK` can read anything; `POKE` can change anything from 8000 up, including
|
||||
BASIC's own data. Poke with care.
|
||||
@@ -516,12 +524,13 @@ Constants in a program are converted from text every time they are used, so a
|
||||
loop runs a little faster if a constant used inside it is put into a variable
|
||||
first.
|
||||
|
||||
## 10. Saving programs
|
||||
## 10. Files in the flash
|
||||
|
||||
### In the board's flash
|
||||
The board's configuration flash has room for files next to the bitstream it
|
||||
boots from: saved programs, and data files that programs write and read. They
|
||||
stay there when the power is off.
|
||||
|
||||
The board's configuration flash has room for programs next to the bitstream it
|
||||
boots from. They stay there when the power is off.
|
||||
### Saving programs
|
||||
|
||||
| Command | Does |
|
||||
|---|---|
|
||||
@@ -534,19 +543,88 @@ boots from. They stay there when the power is off.
|
||||
```
|
||||
SAVE "SPIRO"
|
||||
DIR
|
||||
SPIRO 212
|
||||
SPIRO 212 2026-11-28 09:30
|
||||
1 FILE, 1780K FREE
|
||||
```
|
||||
|
||||
- Names are 1 to 8 letters and digits; lower case becomes upper case. The name
|
||||
can be any string expression, so `SAVE N$` works.
|
||||
- Up to 64 programs, 1,784 KB in all. A program is saved as its listing, in 4 KB
|
||||
blocks; one can use at most 8 blocks (32 KB of listing).
|
||||
- Up to 64 files, 1,784 KB in all. A program is saved as its listing, in 4 KB
|
||||
blocks; a file can use at most 8 blocks (32 KB).
|
||||
- Variables aren't saved, and `LOAD` clears them.
|
||||
- Each block is read back and checked after it is written.
|
||||
- If the power goes off while saving, you keep the old version of that program:
|
||||
the new copy is written to free space first and the list of programs is
|
||||
- If the power goes off while saving, you keep the old version of that file:
|
||||
the new copy is written to free space first and the list of files is
|
||||
switched over to it last.
|
||||
- `DIR` lists programs and data files alike; `LOAD` of a data file keeps only
|
||||
its lines that start with a number.
|
||||
|
||||
### The date
|
||||
|
||||
`DIR` shows the date and time each file was created. Saving over a file keeps
|
||||
its original date.
|
||||
|
||||
The board has no clock that runs with the power off, so BASIC only knows the
|
||||
date once it has been told, and keeps time from then until the Z-80 is
|
||||
restarted (**BTND**, **BTNC**, power-off or reprogramming).
|
||||
|
||||
| | |
|
||||
|---|---|
|
||||
| `DATE "2026-11-28 09:30"` | Set the date and time (seconds optional: `"2026-11-28 09:30:15"`; the time is optional too) |
|
||||
| `DATE` | Print the date and time, or `DATE NOT SET` |
|
||||
| `DATE$` | The date and time as a string, `""` if not set |
|
||||
|
||||
`send-bas.py` and `get-bas.py` set it from the PC's clock each time they
|
||||
connect (section 11; `--no-date` stops them). A file saved before the date is set has no date in
|
||||
`DIR`, and gets one when it is next saved after the date is set.
|
||||
|
||||
```
|
||||
PRINT "TODAY IS "; LEFT$(DATE$, 10)
|
||||
```
|
||||
|
||||
### Data files
|
||||
|
||||
A program can write text to a file and read it back, with up to three files
|
||||
open at once, numbered 1 to 3.
|
||||
|
||||
| Statement | Does |
|
||||
|---|---|
|
||||
| `OPEN "NAME" FOR OUTPUT AS #1` | Start a new file (replacing any file of that name when it is closed) |
|
||||
| `OPEN "NAME" FOR APPEND AS #1` | Add to the end of a file (or start it if there isn't one) |
|
||||
| `OPEN "NAME" FOR INPUT AS #1` | Read a file from the start |
|
||||
| `PRINT #1, items` | Write, just as `PRINT` writes to the screen |
|
||||
| `INPUT #1, A, B$` | Read values separated by commas or line ends |
|
||||
| `LINE INPUT #1, A$` | Read a whole line |
|
||||
| `EOF(1)` | -1 once everything has been read |
|
||||
| `CLOSE #1` | Finish with a file; `CLOSE` alone closes them all |
|
||||
|
||||
The `#` is optional everywhere, and the name can be any string expression.
|
||||
|
||||
```
|
||||
10 OPEN "SCORES" FOR OUTPUT AS #1
|
||||
20 FOR I = 1 TO 5
|
||||
30 PRINT #1, "PLAYER"; I; ","; I * 100
|
||||
40 NEXT I
|
||||
50 CLOSE #1
|
||||
60 OPEN "SCORES" FOR INPUT AS #1
|
||||
70 IF EOF(1) THEN CLOSE #1: END
|
||||
80 INPUT #1, N$, S
|
||||
90 PRINT N$, S
|
||||
100 GOTO 70
|
||||
```
|
||||
|
||||
- A file written with `OUTPUT` or `APPEND` only appears, or changes, when it is
|
||||
closed. Until then `DIR` and other readers see the old version, and a power
|
||||
cut leaves the old version. `END`, the end of the program, `RUN`, `NEW`,
|
||||
`LOAD` and `BYE` close every open file; an error or Ctrl-C doesn't, so the
|
||||
file can still be closed by hand.
|
||||
- `PRINT #` writes exactly what `PRINT` would show, so numbers have their
|
||||
spaces, and the separator for `INPUT #` must be written as `","` as above.
|
||||
A string that contains a comma needs quotes around it for `INPUT #`, or read
|
||||
it with `LINE INPUT #`.
|
||||
- `APPEND` copies the file's last part-filled 4 KB block to a new one; the full
|
||||
blocks are shared with the old version, so appending to a big file is quick.
|
||||
- Lines are separated by a single line feed (code 10).
|
||||
|
||||
The flash also holds the bitstream the board starts from. The hardware refuses
|
||||
to erase or write anything below the area kept for programs, so no program can
|
||||
@@ -639,7 +717,7 @@ An error stops the program and reports the line, for example
|
||||
| `OUT OF MEMORY` | The program and arrays don't fit |
|
||||
| `TYPE MISMATCH` | A string where a number belongs, or the other way round |
|
||||
| `STRING TOO LONG` | A string over 79 characters, or a program line too long to store |
|
||||
| `ILLEGAL FUNCTION CALL` | A bad argument: `SQR(-1)`, `LOG(0)`, a colour over 15, `AND` on a number beyond ±32767 |
|
||||
| `ILLEGAL FUNCTION CALL` | A bad argument: `SQR(-1)`, `LOG(0)`, a colour over 15, `AND` on a number beyond ±32767, a file number other than 1–3, an impossible `DATE` |
|
||||
| `UNDEFINED FUNCTION` | `FNx` used before its `DEF` |
|
||||
| `FOR NESTED TOO DEEPLY` | More than 16 loops open |
|
||||
| `GOSUB NESTED TOO DEEPLY` | More than 32 subroutines in progress |
|
||||
@@ -647,7 +725,10 @@ An error stops the program and reports the line, for example
|
||||
| `BAD FILE NAME` | A name that is empty, longer than 8 or not just letters and digits |
|
||||
| `DISK FULL` | Not enough free flash for the program |
|
||||
| `TOO MANY FILES` | 64 programs are saved already |
|
||||
| `PROGRAM TOO BIG TO SAVE` | The listing is over 32 KB |
|
||||
| `FILE TOO BIG` | A program listing or data file over 32 KB |
|
||||
| `FILE ALREADY OPEN` | `OPEN` with a number that is already in use |
|
||||
| `FILE NOT OPEN` | `PRINT #`, `INPUT #`, `LINE INPUT #` or `EOF` on a number that isn't open that way |
|
||||
| `INPUT PAST END` | `INPUT #` or `LINE INPUT #` after the last line |
|
||||
| `FLASH ERROR` | The flash didn't answer, or read back wrong after writing |
|
||||
| `BREAK IN n` | You pressed Ctrl-C |
|
||||
| `STOP IN n` | The program ran `STOP` |
|
||||
@@ -700,7 +781,7 @@ bouncing ball and a Mandelbrot set, then prints how long it all took.
|
||||
|
||||
| Item | Limit |
|
||||
|---|---|
|
||||
| Program and arrays together | about 22 KB |
|
||||
| Program and arrays together | about 21.5 KB |
|
||||
| Line numbers | 0 – 65535 |
|
||||
| Line length | 250 characters typed |
|
||||
| Numeric variables | A–Z and A0–Z9 |
|
||||
@@ -710,4 +791,5 @@ bouncing ball and a Mandelbrot set, then prints how long it all took.
|
||||
| FOR nesting / GOSUB nesting | 16 / 32 |
|
||||
| Graphics | 320 × 240, 16 colours |
|
||||
| Text | 80 × 30 |
|
||||
| Saved programs | 64, 1,784 KB in all, 32 KB of listing each |
|
||||
| Files in flash | 64, 1,784 KB in all, 32 KB each |
|
||||
| Open data files | 3 |
|
||||
Binary file not shown.
Reference in new issue
Block a user