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:
brad ArantandClaude Opus 5.5 committed 2026-11-28 08:50:15 -08:00
1 parent 29a15bf7c7
commit 767377f38d
9 files changed
+11631 -11174

No files matched your search

+17 -10
View File
@@ -157,7 +157,10 @@ edit the line being typed.
- **Commands**: `RUN [line]`, `LIST [a][-b]`, `NEW` (also `SCRATCH`).
- **Files in flash**: `SAVE "NAME"`, `LOAD "NAME"`, `RUN "NAME"`, `DIR`,
`DEL "NAME"`.
`DEL "NAME"`; data files with `OPEN "NAME" FOR INPUT|OUTPUT|APPEND AS #n`,
`PRINT #n`, `INPUT #n`, `LINE INPUT #n`, `EOF(n)`, `CLOSE [#n]`.
- **Date**: `DATE "2026-11-28 09:30"` sets the clock (the PC tools do it when
they connect), `DATE$` reads it, and `DIR` shows when each file was made.
- **Statements**:
- Assignment and output: `LET` (optional), `PRINT` (`,` for 15-column zones,
`;` to join, `TAB(n)`), `INPUT ["prompt";] vars`
@@ -179,12 +182,12 @@ edit the line being typed.
- **Functions**:
- Numeric: `SIN COS TAN ATN EXP LOG ABS SQR INT RND SGN`, `FNx`
- Strings: `LEN VAL ASC`, `CHR$ STR$ LEFT$ RIGHT$ MID$`
- Machine: `PEEK(addr)`, `INP(port)`, `TIM` (seconds since reset),
- Machine: `PEEK(addr)`, `INP(port)`, `TIM` (seconds since reset), `DATE$`, `EOF(n)`,
`POINT(x,y)` (graphics pixel colour)
- Spaces are optional, as at Dartmouth: `FORI=1TO10` works.
- `DATA` takes the rest of its line.
About 22 KB of program space is free.
About 21.5 KB of program space is free.
**Graphics:** the layer is 320×240 pixels in the 16 terminal colours, each
pixel a 2×2 block, with (0,0) at the top left. Colour 0 is transparent. Text is
@@ -194,10 +197,12 @@ drawn on top, and the graphics show through blank text.
statement and function, with examples, error messages and limits.
`docs/build-manual.sh` rebuilds the PDF from it.
**Saving programs on the board:** BASIC keeps programs in the configuration
flash above the bitstream, from 240000h to the end of the 4 MB chip. There is
room for 64 programs, 1,784 KB in all and up to 32 KB of listing each, and they
survive power-off.
**Files on the board:** BASIC keeps saved programs and data files in the
configuration flash above the bitstream, from 240000h to the end of the 4 MB
chip. There is room for 64 files, 1,784 KB in all and up to 32 KB each, and
they survive power-off. Each directory entry records the file's creation date
(directory format `BFS2`; a `BFS1` directory from before dates is converted
when read).
- **Layout:** the area is 448 blocks of 4 KB. Blocks 0 and 1 hold the
directory, written alternately with a sequence number and checksum, so a
@@ -229,6 +234,7 @@ tools/get-bas.py myprog.bas --baud 9600 # LIST it
tools/get-bas.py --baud 9600 --cmd 'DIR' --cmd 'SAVE "DEMO"' # run commands, show replies
```
Both tools set BASIC's date from the PC's clock first (`--no-date` to skip).
If the port is left root-only (`crw-------`) after stopping the getty,
`sudo chmod 666 /dev/ttyUSB1` opens it. `sudo systemctl unmask --runtime
serial-getty@ttyUSB1` (or a reboot) brings the getty back; flip SW14 down
@@ -348,9 +354,10 @@ older boards, Macronix `mx25l3273f` on newer ones).
- It switches to Z-80 mode, types `PRINT 2+2` and a short program over the
UART, and checks BASIC's output on the screen.
- It draws graphics from BASIC and checks the pixels.
- Against a model flash (`sim/spiflash_model.v`) it saves, loads, runs and
lists a program, then tries to erase address 0 and checks the model saw no
write below 240000h.
- Against a model flash (`sim/spiflash_model.v`) it sets the date, saves,
loads, runs and lists a program (checking the date in `DIR`), tries to erase
address 0 and checks the model saw no write below 240000h, then writes a data
file and reads it back.
```bash
VIVADO=~/vivado/2025.2/Vivado ./scripts/sim.sh