Devices that take time, and a filesystem that waits for one

The disk's status has always had a bit meaning "still going", and the header
beside it has always said to honour it. Nothing did, because nothing could: the
host finished the transfer inside the instruction that asked for it, so the bit
could never be seen up and asking about it was asking about something that
cannot happen.

--disk-cycles gives it a latency. The command is still checked at once, because
a refusal is not work - a block that is not there fails before any head moves -
but the transfer is remembered and done when the machine has run that far. Until
then the buffer holds the block BEFORE this one.

That last part is the point. A program that does not wait gets the wrong bytes
rather than an error, which is the failure the bit exists to prevent and the one
that would never have shown up. With a latency of two thousand, CosmOS could not
even mount: sbfsMount reads block zero and looks straight at the buffer.

deviceTick is the general shape rather than a disk feature. Called once per
instruction with the machine's clock, it lets anything whose moment has come
finish - which is what a display that refreshes, or a port that waits on the
host, would want in exactly the same way.

The filesystem watches the bit now, in one small routine reached with RCAL. That
is not decoration: what it hands back is the settled status in A, and CALL puts A
back the way it found it, so an ordinary call cannot carry the one thing this
exists to carry. Two bytes of Stack rather than ten, in a routine that runs on
every block the machine ever touches - the first place in the system where the
new call is the right one rather than merely a cheaper one.

The manifest takes a @N after a disk, the way it already takes :ro, so a test can
ask for a slow one. cosmosSlowDisk lists a directory at two thousand cycles a
block and gets the same listing as everything else, which is the whole assertion:
a filesystem that did not wait would print nonsense rather than fail.

Zero is the default and every other test runs at it. What waiting costs, on a
directory heavy run: 229k cycles at zero, 275k at five hundred, 415k at two
thousand, 1.16M at ten thousand.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01E2JrLzFvuFX9fgi1LDRjrW
This commit is contained in:
Anachronaut
2026-08-25 21:29:57 -04:00
co-authored by Claude Opus 5
parent e0cf0a9a25
commit d4cba36c5e
11 changed files with 161 additions and 15 deletions
+22 -3
View File
@@ -145,9 +145,12 @@ uint8_t consoleReadByte(void);
#define DISK_COMMAND_READ 0x01
#define DISK_COMMAND_WRITE 0x02
// Set while an operation is still going. It always reads clear here, because the host
// finishes before the next instruction does, but a machine with a slower disk would set
// it and a program that ignores it would break there. Honour it anyway.
// Set while an operation is still going, and it now really is set: a disk given a latency
// says busy, takes that many cycles, and finishes then. A program that does not wait gets
// whatever was in the buffer before, which is what the hardware would give it.
//
// It reads clear the whole time when the latency is zero, which is the default and how
// every test here has always run.
#define DISK_STATUS_BUSY 0x01
// Set when the disk cannot be written at all. Unlike the two bits above it, this is not
// about the last operation: it is a standing property of the medium, readable before
@@ -160,6 +163,22 @@ uint8_t consoleReadByte(void);
// so it says so rather than stopping the machine.
#define DISK_STATUS_ERROR 0x02
// ---- Devices that take time ----
//
// A real device does not finish inside the instruction that asked it to. It says it is
// busy, takes as long as it takes, and is done when the machine has run that far - so the
// emulator needs somewhere to notice that time has passed. That is this: called once per
// instruction with the machine's clock, it lets any device whose moment has come finish.
//
// It is written for the disk and is not about the disk. Anything that will take time - a
// display that refreshes, a port that waits on the host - wants exactly this shape.
void deviceTick(unsigned long now);
// How many cycles a block read or write takes. Zero means the answer is there before the
// next instruction is, which is what this machine has always done and what every recorded
// test assumes.
void setDiskLatency(unsigned long cycles);
// Attaches an image, making one if it is not there. A disk is read only if the host will
// not let the file be written, or if writeProtect asks for it, which is the emulated
// equivalent of the tab on the side of a floppy. Returns 1 if it could not attach.