diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 315cb6e..5f33e94 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -55,7 +55,7 @@ jobs: run: arm-none-eabi-gcc --version - name: Install AtariST Toolkit Docker image - run: curl -sL https://github.com/sidecartridge/atarist-toolkit-docker/releases/download/v1.0.0/install_atarist_toolkit_docker.sh | bash + run: curl -sL https://github.com/sidecartridge/atarist-toolkit-docker/releases/download/v1.5.0/install_atarist_toolkit_docker.sh | bash - name: Run - remove interactive run: sed -i 's/-it//' /usr/local/bin/stcmd diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 4c34510..ebd7bef 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -53,7 +53,7 @@ jobs: run: arm-none-eabi-gcc --version - name: Install AtariST Toolkit Docker image - run: curl -sL https://github.com/sidecartridge/atarist-toolkit-docker/releases/download/v1.0.0/install_atarist_toolkit_docker.sh | bash + run: curl -sL https://github.com/sidecartridge/atarist-toolkit-docker/releases/download/v1.5.0/install_atarist_toolkit_docker.sh | bash - name: Run - remove interactive run: sed -i 's/-it//' /usr/local/bin/stcmd diff --git a/.gitignore b/.gitignore index aa755c9..ef61c83 100644 --- a/.gitignore +++ b/.gitignore @@ -64,6 +64,7 @@ docs/epics/ cli/__pycache__/ tools/dev/logs/ tools/dev/builds/ +.DS_Store # EmuMD: the emulated microSD card, the TOS images linked from elsewhere, and # what tools/dev/mdfw.sh generates from rp/src/sdcard.c diff --git a/CHANGELOG.md b/CHANGELOG.md index b835a17..cb01899 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,159 @@ # Changelog +## v1.2.0 (unreleased) + +Run programs from the GEM desktop, feed data to a program while it runs, +and load programs that GEMDRIVE used to crash on. + +Most of this release is Neil Rackett's work. Chati-SidecarTridge sent the +odd-sized read fix too, and theimann and p0b-UK found and pinned down the +GEMDRIVE read and seek bugs on their own machines. + +### Run programs from the GEM desktop: the GEMDRIVE Runner + +`[G]` now brings the Runner along. The Atari boots on through its AUTO +folder to the desktop as usual, and a desk accessory, `DEVOPS.ACC`, takes +`runner run`, `load`, `exec`, `unload` and `cd` from there. Programs started +this way find the AUTO-folder drivers, the cookie jar and GEM already +loaded; `[U]` starts too early for any of them. + +- **On by default.** `Ru[n]ner` in the GEMDRIVE section of the menu shows + it, and `[N]` turns it off, which makes `[G]` plain GEMDRIVE as before. +- **Nothing to install.** The firmware writes `DEVOPS.ACC` to the GEMDRIVE + folder itself, and deletes it again when the Runner is off. With + GEMDRIVE as `C:`, GEM loads it from there; with another drive letter, + copy it to the root of your boot drive. +- **`runner status`** says whether the accessory has started. After a + `runner reset`, wait for it before the next command. +- **On the Atari**, the accessory's Desk menu entry shows the current + directory and the last command with its result. +- **Limits.** It starts plain TOS programs, not GEM ones, and `runner res` + is refused under GEM. GEM gives the accessory no turn while a dialog or + menu is open or something is being dragged, so commands wait until then. + +Tested on a Mega STE with TOS 2.06, with and without an ACSI2STM hard disk, +and in Hatari with EmuTOS. + +### The AUTO folder runs from GEMDRIVE + +With GEMDRIVE as `C:` and no other hard disk, nothing in `C:\AUTO` ran, +because TOS looked for it on drive A:. GEMDRIVE now makes `C:` the current +drive as it installs, so AUTO-folder drivers load. With a hard disk whose +driver takes the boot drive, such as an ACSI2STM, TOS runs that drive's +AUTO folder instead. + +### Programs that GEMDRIVE could not load + +- **Programs with an odd file size** crashed in the loader (three bombs) or + started corrupted, because the last byte of every odd-length read arrived + wrong. They now load, and an odd-length `Fread` gets its last byte right. +- **Programs with an odd-sized symbol table** bombed in the loader with an + address error. They now load, as they do with TOS's own loader. +- **A read over 4 KB** that did not end on a 4 KB boundary could write up to + 4 KB past the end of the program's buffer. It now stops where it should. +- **Files and searches left open by a crashed program** no longer pile up. + After a few crashes GEMDRIVE ran out of handles, and GEM could not even + load its accessories, until the cartridge was restarted. Every Atari boot + now starts clean. +- **The current directory** reached the Atari with its bytes swapped: + `Dgetpath` returned `\STDL` as `S\DT`. + +### Files that programs open through GEMDRIVE + +- **`Fseek` never worked**: the RP took the handle for the offset, so a seek + answered "invalid handle" or moved the wrong file. Programs built with + mintlib seek on every file they open, and `fopen(..., "a")` failed and left + the file locked. A seek past either end of a file is now refused with + `ERANGE`, as by TOS, instead of growing the file. +- **`Fdatime`** went by the current drive rather than the file handle, and + its "get" returned whatever was in memory. It now acts on the handle's + file: get returns the file's own date and time, and set changes them. +- **A file a program left open** when it ended, or crashed, stayed open + until the next boot, locked against every other open, including the + API's. GEMDRIVE now closes a program's files when it ends, as TOS does. +- **On a Mega STE with its cache on**, as programs that want speed run, + GEMDRIVE calls were lost or answered wrong: the cache kept old copies of + what the cartridge said. GEMDRIVE now turns the cache off for each call + it answers and back on after; the CPU speed is left alone. The cartridge + also turns it off when the Atari boots, which a reset does not. +- **The 16 KB that GEMDRIVE and the Runner live in** was still free memory + as far as TOS knew, so a program that took nearly all of it could be + given that area and overwrite them, and every program's stack started + inside it. GEMDRIVE now takes the area from TOS when it installs. +- **Programs started with `[U]` hung or crashed as they ended** when they + had used GEMDRIVE. Their calls ran on TOS's small boot-time stack, and + GEMDRIVE's work there overwrote TOS's own variables. GEMDRIVE now does + its work on a stack of its own, and a call it passes on to TOS reaches + it with every register as the program left it. + +### Feed data to a running program: the rom4 area + +1 KB of the cartridge, at `$FA8B00`, that the workstation writes over HTTP +(`PUT /api/v1/rom4`, or `sidecart rom4 write`) and any program on the +Atari can read while it runs, in any mode. Programs find it through shared +variables 20–22. Several writes can go in one request and are applied in +the order given, so a program can be handed a complete update. + +### The boot countdown remembers your choice + +When nobody pressed a key, the countdown always started `[U]`. It now +starts whichever of `[G]` and `[U]` you used last, so a power cycle comes +back the way it went, and the countdown bar says which: `Booting GEMDRIVE +in 20 s`. Until you first use `[G]` it is still `[U]`. + +### Hold SELECT at power-on to go to the Booster + +As in other SidecarTridge apps: hold SELECT while switching on and the +cartridge goes straight to the Booster, to install another app or update +this one. + +### The setup menu + +- **GEMDRIVE settings changed in the menu** — the drive letter, the + relocation address, `_memtop` and the Runner's hook vector — only took + effect from the next boot, so choosing `D:` and pressing `[G]` still + gave GEMDRIVE `C:`. `[G]` and `[U]` now use what the menu shows. + +### The Runner + +- **On a Mega STE with its cache on**, the Runner's commands could be + missed, or their answers lost. The ones that reach a running program, + such as `runner reset` and `runner adv meminfo`, are now seen within + about half a second whatever the program does with the cache, and + DEVOPS.ACC turns the cache off while it talks to the cartridge, for a + desktop set up to run fast. A program the accessory starts still gets + the desktop's cache. +- **`runner meminfo`** gave the address of TOS's ROM header as the running + program's basepage. It now reports the real one. +- **A `load` or `unload` that timed out** was still carried out later, when + the Atari next looked, after the API had reported it as failed. It is now + withdrawn. + +### The API + +- **Every 503 reply** carries `Retry-After: 1`, as documented. Three kinds + of error left it out. +- **The Runner's *busy* reply** had an empty body, so the CLI could only + print `error (503):`. It now carries the usual error message. + +### For developers + +- GEMDRIVE's XBRA header (`SDGD`) now sits right in front of its trap #1 + entry, so tools that walk the GEMDOS chain find it and the handlers + below it. +- `QUESTION.TOS` is a known-answer test for the Runner: it writes + `ANSWER.TXT` containing `42` and exits with 42. `ROM4CHK.TOS` prints the + rom4 area to the debug stream. +- The cartridge code is at 10,076 of its 10,240 bytes. +- **The firmware runs in Hatari.** [EmuMD](https://github.com/neilrackett/emumd) + builds its C code for your computer and runs it in its fork of Hatari, + with the cartridge on the ST's port, a folder as the microSD card and the + HTTP API reachable from your computer. `tools/dev/emu_check.py` boots an + ST, an STE and a Mega STE and checks GEMDRIVE, the Runner and the API; + see `emu/README.md`. `GDTEST.TOS` (`target/atarist/test/gemdos-io`) checks + GEMDOS reads and seeks on the GEMDRIVE drive. +- CI installs `stcmd` from atarist-toolkit-docker v1.5.0. + ## v1.1.0 (2026-09-17) — robustness No new features. Things that used to fail now work, and when something does diff --git a/CLAUDE.md b/CLAUDE.md index 150dad1..306353b 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -26,7 +26,7 @@ Required host environment: Build flow (orchestrated by `build.sh`; every script stops at the first failed step): 1. Copies `version.txt` into `rp/` and `target/atarist/`. -2. Builds the Atari ST target (`target/atarist/build.sh`) via `stcmd make`. Enforces a **10 KB hard limit** on `BOOT.BIN` (the cartridge code budget — `CHANDLER_CARTRIDGE_CODE_SIZE` in `rp/src/include/chandler.h`, mirrored as `CARTRIDGE_CODE_SIZE` in `target/atarist/src/main.s`); a build that exceeds it aborts with `ERROR: cartridge code is N bytes; limit is 10240`. A separate copy (`FIRMWARE.IMG`) is then padded to 64 KB to fill the entire shared region, and `firmware.py` converts it into `rp/src/include/target_firmware.h` (a C byte array embedded in the RP firmware). +2. Builds the Atari ST target (`target/atarist/build.sh`) via `stcmd make`. Enforces a **10 KB hard limit** on `BOOT.BIN` (the cartridge code budget — `CHANDLER_CARTRIDGE_CODE_SIZE` in `rp/src/include/chandler.h`, mirrored as `CARTRIDGE_CODE_SIZE` in `target/atarist/src/main.s`); a build that exceeds it aborts with `ERROR: cartridge code is N bytes; limit is 10240`. A separate copy (`FIRMWARE.IMG`) is then padded to 64 KB to fill the entire shared region, and `firmware.py` converts it into `rp/src/include/target_firmware.h` (a C byte array embedded in the RP firmware). `DEVOPS.ACC` goes the same way, byte for byte (`--byte_array`), into `rp/src/include/devops_acc.h`; the RP writes it to the GEMDRIVE folder when `[G]` starts with the GEMDRIVE Runner on (`runner_installAccessory`). 3. Builds the RP firmware (`rp/build.sh`): pins submodule versions (pico-sdk 2.2.0, pico-extras sdk-2.2.0, fatfs-sdk at a specific commit), empties `rp/build` and `rp/dist`, runs CMake, produces `rp/dist/rp-.uf2` (`rp--debug.uf2` for debug). The FatFs configuration lives at `rp/src/ff/ffconf.h` and shadows the submodule's default via `target_include_directories(... BEFORE PRIVATE)` in `rp/src/CMakeLists.txt`, so the `fatfs-sdk` submodule stays pristine. 4. Computes MD5, renames to `dist/-.uf2`, and substitutes UUID/MD5/version into `dist/.json` from the `desc/app.json` template. @@ -71,9 +71,10 @@ The firmware is a **two-target build**: m68k assembly that runs on the Atari ST ### Atari ST side (`target/atarist/`) - `src/main.s` — m68k cartridge boot + dispatch + terminal. Lives at `$FA0000` in the ST address space (ROM4 cartridge region). Defines the cartridge header (`CA_MAGIC`, `CA_INIT`, …), command magic numbers, and the shared-variable layout used to talk to the RP2040. - `src/devops.ld` — absolute layout of the cartridge image. The 10 KB budget (`CARTRIDGE_CODE_SIZE = $2800`) is split: `main.s` at `$0000` (2 KB), `gemdrive.s` at `$0800` (5 KB), `runner.s` at `$1C00` (3 KB). `main.s` mirrors the last two as `GEMDRIVE_BLOB` / `RUNNER_BLOB`. -- `src/gemdrive.s` — GEMDOS trap-#1 hooks + protocol blob. `gemdrive_install` copies `GEMDRIVE_BLOB_SIZE` bytes into RAM (default `screen_base - 16 KB`) once the user commits a mode, so the resident code survives cartridge teardown. +- `src/gemdrive.s` — GEMDOS trap-#1 hooks + protocol blob. `gemdrive_install` copies `GEMDRIVE_BLOB_SIZE` bytes into RAM (default `screen_base - 16 KB`) once the user commits a mode, so the resident code survives cartridge teardown, and takes that 16 KB zone out of GEMDOS's free memory. A call GEMDRIVE passes on reaches TOS with every register as it came; one it takes costs the caller's stack 4 bytes and runs on GEMDRIVE's own stack at the top of the zone. - `src/runner.s` — Runner foreground loop; self-relocates at `runner_entry` to just above the GEMDRIVE blob inside the same protected 16 KB region (`RUNNER_ABOVE_GEMDRIVE_OFFSET`). -- Dispatch: the RP writes `CMD_START = 4` ([G]) or `CMD_START_RUNNER = 5` ([U]) to the cartridge sentinel; the m68k's vsync-polled `check_commands` dispatches to `rom_function` / `runner_function`, both of which `jsr gemdrive_install` first. +- Dispatch: the RP writes `CMD_START = 4` ([G] with the GEMDRIVE Runner off), `CMD_START_RUNNER = 5` ([U]) or `CMD_START_TSR = 6` ([G] with the GEMDRIVE Runner on, the default; `[N]` toggles the `GEMDRIVE_RUNNER` setting) to the cartridge sentinel; the m68k's vsync-polled `check_commands` dispatches to `rom_function` / `runner_function` / `tsr_function`, all of which `jsr gemdrive_install` first. `tsr_function` calls `RUNNER_BLOB` with the sentinel value still in `d6`; with `CMD_START_TSR` the Runner installs its interrupt hook, sends HELLO and returns, and TOS boots on to the desktop. +- `src/devops_acc.s` — `DEVOPS.ACC`, the GEMDRIVE Runner's desk accessory (TSR mode in the code). Not part of the cartridge image and not bound by its budget: an ordinary TOS executable (`vasm -Ftos`) built by the same Makefile into `dist/`. It polls the sentinel from an AES timer and serves the foreground Runner commands (`run`, `load`, `exec`, `unload`, `cd`) with the Runner's report codes, plus `RUNNER_CMD_DONE_ACC_HELLO` when GEM starts it. Its trace lines go to the debug-capture window, not the screen. Its Desk menu entry opens a status alert (cwd, last command and result). - Adding more m68k modules: add a new `.text_` section in `devops.ld`, mirror the offset with an `equ (ROM4_ADDR + $????)` in `main.s`, add the `.o` target to `target/atarist/Makefile`, and account for it in the 10 KB budget. - Built via `stcmd make release` (m68k assembler in Docker); the cartridge image (header + all `.text_*` sections) must fit in 10 KB. A 64 KB padded copy is then converted to `target_firmware.h` for inclusion in the RP build. @@ -86,12 +87,13 @@ The Atari ST sees a 64 KB window at `$FA0000`–`$FAFFFF` (mirrored RP-side at ` | `$FA2800` | `CMD_MAGIC_SENTINEL` | 4 B | m68k polls here for NOP/RESET/command words | | `$FA2804` | `RANDOM_TOKEN`, `RANDOM_TOKEN_SEED`, 60 × 4 B indexed shared variables | ~768 B | fixed-offset metadata block (first 512 B until `$FA2B00`) | | `$FA2B00` | `APP_FREE` | ~46 KB | contiguous arena for app buffers | +| `$FA8B00` | `ROM4_OFFSET` | 1 KB | rom4 area inside `APP_FREE`: written over HTTP (`/api/v1/rom4`), read by ST programs, found through shared variables 20–22 (`rp/src/include/rom4.h`) | | `$FAE0C0` | `FRAMEBUFFER` | 8000 B | 320×200 monochrome framebuffer; sits at the top of the region so an overrun walks off the end of the 64 KB window instead of corrupting the metadata block | See `programming.md` for the full table and budget rules. ### RP2040 side (`rp/src/`) -- `main.c` — only sets clock/voltage, calls `gconfig_init` (global config) then `aconfig_init` (per-app config), and hands off to `emul_start()`. If config init fails it jumps to the **Booster** app via `reset_jump_to_booster()` to bootstrap. **Don't add features to `main.c`** — put them in `emul.c` or a new module. +- `main.c` — only sets clock/voltage, calls `gconfig_init` (global config) then `aconfig_init` (per-app config), and hands off to `emul_start()`. If config init fails, or SELECT is held at power-on, it jumps to the **Booster** app via `reset_jump_to_booster()`. **Don't add features to `main.c`** — put them in `emul.c` or a new module. - `emul.c` / `emul.h` — the application's main loop and entry point. This is where to add new features. - `romemul.c` / `romemul.pio` — PIO programs and the runtime that emulates the cartridge ROM/RAM bus to the Atari (driven by `READ_*` / `WRITE_*` GPIOs defined in `include/constants.h`). - `gconfig.c` / `aconfig.c` — global vs per-app configuration stored in dedicated flash sectors, on top of `settings/` (a key-value store). @@ -134,15 +136,16 @@ The build assumes Core 0 owns flash writes (`PICO_FLASH_ASSUME_CORE0_SAFE=1`). T ## Editing guardrails - **Never modify** `pico-sdk/`, `pico-extras/`, `fatfs-sdk/` or `emu/emumd/` — they are git submodules pinned to specific upstream revisions, and the build re-pins them on every run. To change FatFs configuration, edit `rp/src/ff/ffconf.h` (project-owned override); the include path is set up so this file wins over the submodule's default. -- Don't touch `main.c` for feature work — start in `emul.c`. +- Don't touch `main.c` for feature work — start in `emul.c`. The one exception is the check for SELECT held at power-on, which jumps to the Booster before any settings are read, so the way out works however broken this app's settings or start-up are; `emul.c` runs too late for that. - **The watchdog fires after 8 s without `health_feed()`.** It is fed only in the main loop, `emul_pollTick`, the Wi-Fi connect loop, the HTTP spin-waits and two slow boot steps. Any new loop or blocking call that can run longer must feed it and set a `health_setPhase()`; don't feed it anywhere else, or a real hang there goes unnoticed. - `panic()` goes to `health_panic` (`PICO_PANIC_FUNCTION`), and the HardFault vector is replaced at boot. Both reboot the RP. Don't call `watchdog_reboot` or jump to Booster without going through `reset.c` / `reset.h`, which record the reason and stop the watchdog. - **Never name an epic, story, iteration or task in anything that is committed** — comments, documentation, changelog, commit messages, PR descriptions. The planning notes live in `docs/epics/`, which is gitignored, so `EPIC-14 STORY-02` tells a reader of this repository nothing and cannot be looked up. Write what the code does and why instead: *"the driver re-applies its own default on every STA re-enable"*, not *"see EPIC-14 STORY-02"*. Check with `git grep -IiE "EPIC-|STORY-|\bepics?\b|\bstor(y|ies)\b"` before tagging a release. - **Keep cartridge-window and flash addresses in `uintptr_t`**, never `uint32_t` or `unsigned int`: the EmuMD build is 64-bit and fails on a cast that cuts a pointer (`-Werror=pointer-to-int-cast`). `uintptr_t` is 32 bits on the RP2040, so the device's code does not change. ARM-only code goes behind `#if defined(__arm__)` (not `__ARM_ARCH`, which Apple silicon defines too). - Match the existing C style (clang-format config in `.clang-format`, exposed as the `clang-format` CMake target when the binary is on `PATH`; clang-tidy config in `.clang-tidy`, used by editors, not by the build). +- **On a Mega STE, m68k code that talks to the cartridge needs the cache off.** The cache answers reads of the cartridge from copies it made before, so with bit 0 of `$FFFF8E21` set a command can be lost and its answer never seen. main.s turns it off at boot and publishes the `_MCH` cookie in shared variable 0 (`CHANDLER_HARDWARE_TYPE` / `SHARED_VARIABLE_HARDWARE_TYPE`); GEMDRIVE's dispatch, the Runner's hook and DEVOPS.ACC check it, turn the cache off around their own traffic and put the caller's setting back. Touch the register only when that variable says Mega STE: no other machine has it, and writing it is a bus error. - **m68k modules `gemdrive.s` and `runner.s` MUST be 100% relocatable and self-contained.** They cannot rely on any cross-module symbol from `main.o` or each other. Concretely: - **No `xref` / `xdef`.** Every macro and helper they call must be defined inside the same assembly unit. The protocol macros live in `inc/sidecart_macros.s` and `bsr.w` into functions defined in `inc/sidecart_functions.s`; both files are `include`'d verbatim at the top/bottom of each module so the bsr's resolve to a private local copy. vasm doesn't export plain labels so vlink doesn't see duplicates between main.o, gemdrive.o, and runner.o. - - **No `jsr` / `jmp` to outside-module symbols.** Both instructions emit absolute addresses, which freezes the call site to a specific runtime address — incompatible with relocation. Use `bsr` / `bra` (PC-relative) for all intra-module control flow. The single allowed exception is the entry-point `jmp` from `main.s`'s `check_commands` dispatch into the relocated blob (e.g. `jmp RUNNER_BLOB`); any future `jsr`/`jmp` to a non-local symbol from inside `gemdrive.s` or `runner.s` requires explicit user approval. + - **No `jsr` / `jmp` to outside-module symbols.** Both instructions emit absolute addresses, which freezes the call site to a specific runtime address — incompatible with relocation. Use `bsr` / `bra` (PC-relative) for all intra-module control flow. The allowed exceptions are the entry points from `main.s` into the blobs: the `jmp` from `check_commands`' dispatch (`jmp RUNNER_BLOB`, `jmp GEMDRIVE_BLOB+4`) and the `jsr RUNNER_BLOB` from `tsr_function`, with which `[G]` sets up the GEMDRIVE Runner (the Runner returns instead of polling when `d6` holds the sentinel that dispatched it); any future `jsr`/`jmp` to a non-local symbol from inside `gemdrive.s` or `runner.s` requires explicit user approval. --- diff --git a/README.md b/README.md index 1deda95..2a04248 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,9 @@ HTTP-management surface stitched on top. m68k (`*(volatile char *)(0xFBFF00 + c)`), captured RP-side and streamed to either an HTTP `tail -f` endpoint or USB CDC. No framing, no overhead, byte-exact. +- **rom4 area** — 1 KB of the cartridge window that the + workstation writes over HTTP and any running ST program reads: + live parameters, scripted input for a test, a driver's state. - **Live setup menu** — graphical status icons (Wi-Fi / SD / USB CDC / Adv Vector), animated countdown bar, USB CDC attach state refreshed live as you plug / unplug. @@ -97,15 +100,17 @@ seconds. From there you have four top-level commands: | Key | Action | | --- | --- | | `[U]` | **Runner mode** (recommended). GEMDRIVE comes up, plus the Runner control surface for `runner run` / `load` / `exec` / etc. | -| `[G]` | GEMDRIVE-only — ST drops straight into the emulated drive but does **not** activate the Runner. Use this if you only want file emulation and don't need the workstation to drive the ST. | +| `[G]` | **GEMDRIVE**. The ST boots on through the AUTO folder to the GEM desktop with the emulated drive. With the **GEMDRIVE Runner** on (`Ru[n]ner`, the default), the Runner comes too: its interrupt hook stays resident and the `DEVOPS.ACC` desk accessory serves `runner run` / `load` / `exec` from the desktop. See [GEMDRIVE Runner](#gemdrive-runner--runner-commands-from-the-gem-desktop). With it off, `[G]` is plain file emulation. | | `[X]` | Return to the Booster menu (e.g. to install another app). | | any key | Halt the auto-launch countdown so the menu stays up indefinitely while you read it. | -If you don't press anything within ~20 s, the firmware **auto-fires -[U]Runner** — Runner is the more useful default for unattended -boots. +If you don't press anything within ~20 s, the firmware **launches +the mode you launched last**, so a power cycle comes back the way it +went. Until you first use `[G]` that is `[U]` Runner, the more useful +default for unattended boots. The countdown bar names the mode it +will launch. -### SELECT button — Pico-side reset / factory-reset +### SELECT button — Booster, reset, factory reset The cartridge's physical **SELECT** button is wired so a press on the Pico itself can recover the device without needing the @@ -113,6 +118,7 @@ ST's keyboard: | Press | Action | | --- | --- | +| Held while the ST is switched on | **Booster.** The Pico goes straight to the Booster app instead of starting DevOps, the same as `[X]` in the setup menu, and works even when DevOps cannot reach its menu. | | Short tap (< 10 s) | **Soft reset** of the Pico. The cartridge boots back into the setup menu. The ST's TOS state is unaffected, but on the next ST cold reset the firmware re-handshakes from scratch. | | Long press (≥ 10 s, hold steady) | **Factory reset.** The Pico erases its flash-stored aconfig (drive letter, reloc address, hook vector, etc.) and reboots. Use this if a setting got the device into a state where the menu won't come up — power-cycle the ST afterwards so it sees the cleared cartridge. | @@ -191,6 +197,7 @@ GEMDRIVE 💾 [D]rive : C: [R]eloc addr: auto (screen-16KB) Mem[t]op : auto (matches reloc) + Ru[n]ner : on Phystop : 0x100000 Screenmem : 0x078000 @@ -211,12 +218,12 @@ Select an option: ▌ | Section | What it shows | Keys | | --- | --- | --- | -| **GEMDRIVE** | Which microSD folder is mounted as the emulated drive, the drive letter assigned to it, the GEMDRIVE relocation address (`auto` = `screen_base − 16 KB`), the patched `_memtop` value, the read-only `_phystop` value (`$42E`) the ST reports, and the read-only screen-memory base (`_v_bas_ad`, `$44E`). A `(!)` marker on the Phystop line means TOS' phystop disagrees with the silicon's MMU bank-config — a reset-resistant program lowered phystop and survived warm reset; **only a power-cycle restores it**. The hard-drive icon appears whenever the section is live. | `[o]` change folder, `[d]` change drive letter, `[r]` change reloc addr, `[t]` change `_memtop`. (Phystop and Screenmem are read-only.) | +| **GEMDRIVE** | Which microSD folder is mounted as the emulated drive, the drive letter assigned to it, the GEMDRIVE relocation address (`auto` = `screen_base − 16 KB`), the patched `_memtop` value, whether `[G]` brings the GEMDRIVE Runner, the read-only `_phystop` value (`$42E`) the ST reports, and the read-only screen-memory base (`_v_bas_ad`, `$44E`). A `(!)` marker on the Phystop line means TOS' phystop disagrees with the silicon's MMU bank-config — a reset-resistant program lowered phystop and survived warm reset; **only a power-cycle restores it**. The hard-drive icon appears whenever the section is live. | `[o]` change folder, `[d]` change drive letter, `[r]` change reloc addr, `[t]` change `_memtop`, `[n]` turn the GEMDRIVE Runner on or off. (Phystop and Screenmem are read-only.) | | **Adv [V]ector** | Which interrupt vector the Advanced Runner installs its hook into — `vbl ($70)` or `etv_timer ($400)`. See *Picking a hook vector* below for the trade-off. The cog icon appears whenever the section is live. | `[V]` toggle between `vbl` / `etv_timer`. | | **API Endpoint** | mDNS hostname and the IP DHCP leased. The Wi-Fi icon appears once the network is up; if there's no IP yet (Wi-Fi still associating) the icon is hidden. | (read-only) | | **USB CDC (Debug serial)** | `connected` / `disconnected` — live-refreshed as you plug or unplug a USB cable into the Pico. The lightbulb icon flips in lock-step. | (read-only) | | **Bottom navigation strip** | Top-level command keys + a one-character prompt area for typing them. | `[G]` / `[U]` / `[X]`. | -| **Animated countdown bar** | Shrinking white bar; the message "Booting in N s — any key halts" is overlaid in inverted colour so it stays readable both halves. Becomes "Countdown stopped. Press [G], [U] or [X] to continue." once any key has been pressed. | (passive — but pressing any key halts the countdown) | +| **Animated countdown bar** | Shrinking white bar; the message "Booting Runner in N s — any key halts" (or "Booting GEMDRIVE …", whichever mode it will launch) is overlaid in inverted colour so it stays readable both halves. Becomes "Countdown stopped. Press [G], [U] or [X] to continue." once any key has been pressed. | (passive — but pressing any key halts the countdown) | ### Picking a hook vector @@ -309,7 +316,7 @@ resolving on your workstation. The API is the **single control surface** for every remote operation in this firmware — file management, program execution, debug streaming. Everything the rest of this README documents (`ping`, `gemdrive`, `runner`, -`debug`) is a thin wrapper around HTTP calls to this service. +`debug`, `rom4`) is a thin wrapper around HTTP calls to this service. | Family | HTTP endpoints | CLI prefix | | --- | --- | --- | @@ -317,6 +324,7 @@ the rest of this README documents (`ping`, `gemdrive`, `runner`, | GEMDRIVE | `GET/PUT/DELETE/POST /api/v1/gemdrive/{volume,files,folders}/…` | `sidecart gemdrive …` | | Runner | `GET/POST /api/v1/runner/…` | `sidecart runner …` | | Debug | `GET /api/v1/debug`, `GET /api/v1/debug/log` | `sidecart debug …` | +| rom4 | `GET /api/v1/rom4`, `GET /api/v1/rom4/data`, `PUT /api/v1/rom4` | `sidecart rom4 …` | You can drive the API directly from any HTTP client (`curl`, `wget`, `httpie`, a browser, a shell script, your editor's @@ -644,7 +652,9 @@ Runner mode is the foreground execution path the firmware ships with. The user picks `[U]` at the setup menu to launch it; the m68k Runner stays in a poll loop waiting for commands from the RP, while GEMDRIVE keeps servicing TOS file I/O so launched -programs can use the emulated drive normally. +programs can use the emulated drive normally. The same commands +work from the GEM desktop when `[G]` starts with the GEMDRIVE Runner +on; see [GEMDRIVE Runner](#gemdrive-runner--runner-commands-from-the-gem-desktop). The Runner exposes its own subset of the HTTP API (`/api/v1/runner/*`) and CLI (`sidecart runner …`) for @@ -662,9 +672,10 @@ The surface splits into three behavioural buckets: report `active : no`. - **Foreground commands** — `runner cd` / `res` / `meminfo` / `run` / `load` / `exec` / `unload`. These speak to the m68k - Runner poll loop. They return `409 runner_inactive` if `[U]` - wasn't picked, and `503 busy` if another foreground command - is already in flight. Cannot reach a wedged ST. + Runner poll loop, or with the GEMDRIVE Runner to `DEVOPS.ACC`. + They return `409 runner_inactive` if the Runner isn't running, + and `503 busy` if another foreground command is already in + flight. Cannot reach a wedged ST. - **VBL-driven commands** — `runner reset` plus the entire `runner adv` family (`jump` / `load` / `meminfo`). These ride the m68k's VBL ISR (`$70`, or `$400` if you switched @@ -693,7 +704,7 @@ loaded : basepage 0x00078000 ``` If Runner mode hasn't been entered yet, prints -`Runner mode is not active. Boot via [U] to enable.` and exits +`Runner is not active. Boot via [U], or [G] with the GEMDRIVE Runner on.` and exits 0. `--json` returns the full envelope (`last_command` / `last_path` / `last_exit_code` / `last_cd_errno` / `last_res_errno` / `loaded_basepage` / `last_load_errno`). @@ -756,7 +767,7 @@ membottom [$432] : 0x00006A04 memtop [$436] : 0x00080000 phystop [$42E] : 0x00080000 screenmem [$44E] : 0x00078000 -basepage [$4F2] : 0x00078000 +basepage [_run] : 0x00078000 bank 0 [$FF8001 nibble] : 512 KB bank 1 [$FF8001 nibble] : 0 KB total RAM : 512 KB @@ -865,7 +876,7 @@ membottom [$432] : 0x00006A04 memtop [$436] : 0x00080000 phystop [$42E] : 0x00080000 screenmem [$44E] : 0x00078000 -basepage [$4F2] : 0x00078000 +basepage [_run] : 0x00078000 bank 0 [$FF8001 nibble] : 512 KB bank 1 [$FF8001 nibble] : 0 KB total RAM : 512 KB @@ -919,6 +930,96 @@ Synchronous — the workstation file is chunked through when `LOCAL` has a header you don't want landing on the ST. Same shell-quoting rule as `adv jump`. +### GEMDRIVE Runner — Runner commands from the GEM desktop + +> Tested on a Mega STE with TOS 2.06, with and without an ACSI2STM +> hard disk, and in Hatari with EmuTOS. Other machines and TOS +> versions have not been tried. + +`[U]` runs the Runner from the cartridge's boot hook, before the +AUTO folder, the desk accessories and GEM have loaded, so a program +it launches finds none of them — no driver from the AUTO folder (an +Xpad provider, say), and on TOS 1.0x no cookie jar. `[G]` with the +GEMDRIVE Runner on installs GEMDRIVE and the Runner's interrupt hook, +then lets the ST boot on to the desktop as usual. The foreground +commands are served from there by a desk accessory, `DEVOPS.ACC`. +The code and the API call this TSR mode. + +The GEMDRIVE Runner is on unless you turn it off: `Ru[n]ner` in the +GEMDRIVE section of the setup menu shows it, and `[N]` toggles it. +With it off, `[G]` is plain GEMDRIVE: no accessory, no interrupt +hook, no Runner. It also deletes `DEVOPS.ACC` from the root of the +GEMDRIVE folder, so GEM does not load an accessory with nothing to +serve. The name is the firmware's: with the Runner on, `[G]` replaces +any `DEVOPS.ACC` there that differs from its own. + +Press `[G]` at the setup menu. The firmware carries the accessory +it was built with and writes it to the root of the GEMDRIVE folder +first, unless an identical copy is already there, so it always +matches the firmware. Once GEM has started it, `runner status` shows +it: + +``` +active : true +mode : GEMDRIVE Runner (DEVOPS.ACC loaded) +``` + +On the ST, the accessory adds **DevOps Runner** to the Desk menu. It +opens an alert with the Runner's current directory and the last +command the accessory ran, with its exit code or result. + +The accessory only runs when GEM gives it a turn, so its commands +wait while the desktop is busy: while this alert or any other dialog +is open, a menu is pulled down, or something is being dragged. +`runner status` shows `busy` until then. `load` and `unload` give up +after their timeout and are withdrawn, so they do not run later; `run`, +`exec` and `cd` wait as long as it takes. `runner meminfo`, +`runner reset` and the `adv` commands come from the interrupt hook and +are not held up. + +With GEMDRIVE as `C:`, GEM starts the accessory from `C:\`, whether +or not there is another hard disk. With another drive letter, `[G]` +still writes `DEVOPS.ACC` to the root of the GEMDRIVE folder: copy it +from there to the root of your boot drive. Until you do, you get plain +GEMDRIVE plus `runner reset`, `runner meminfo` and the `runner adv` +commands. + +TOS runs the AUTO folder from the boot drive. With GEMDRIVE as `C:` +and no other hard disk, that is `C:`, so AUTO programs go in an +`AUTO` folder inside the GEMDRIVE folder. A hard-disk driver that +loads after the cartridge can take the boot drive for its own first +drive: with an ACSI2STM, which moves itself to `D:`, TOS runs +`D:\AUTO` instead, so AUTO programs go there. + +| Command | With the GEMDRIVE Runner | +| --- | --- | +| `runner run` / `load` / `exec` / `unload` / `cd` | Served by `DEVOPS.ACC`. `409 accessory_not_loaded` until it has started. | +| `runner meminfo` | Answered by the interrupt hook, as `runner adv meminfo` is. | +| `runner reset`, `runner adv …` | Unchanged. After a reset the ST boots back into GEMDRIVE with the Runner; wait for `DEVOPS.ACC loaded` again before the next foreground command. | +| `runner res` | `409 unsupported_in_tsr` — changing the resolution under GEM would leave the desktop drawn for the old one. | + +To launch a program the accessory does what the desktop does for a +TOS program: it locks the screen, hides the mouse and clears the +screen. When the program exits it puts back the resolution, screen +address and palette and has the desktop redraw itself. Its +`[RUN ]` / `[EXIT n]` trace lines go to the +[debug stream](#debug-traces) — `sidecart debug tail` or the USB +serial port — rather than the screen. + +Limits: + +- **Plain TOS programs only** — `.TOS`, `.TTP`, games, demos, and + `.PRG` files that don't use GEM. On single-tasking TOS a GEM + program started from an accessory would run inside the + accessory's AES slot. +- **The accessory only runs while the foreground program waits for + GEM events.** While a program it launched is running, only the + interrupt-hook commands work: `runner reset` and + `runner adv meminfo` / `jump` / `load`. +- **It shares the desktop's process**, so the desktop can change the + current directory between commands. The accessory keeps the + Runner's own and sets it again before every command. + ## Debug traces The firmware exposes a lightweight debug-byte capture surface @@ -935,10 +1036,10 @@ discarded. > DPRINTF), it boots *before* the Atari ST. Two side effects: > 1. The setup-menu countdown starts running with no ST > attached, and once it elapses (~20 s by default) the -> firmware auto-commits Runner mode. When you subsequently -> power the ST, it sees the cartridge already in Runner -> state and skips the menu — you never get a chance to -> press `[U]` / `[G]`. +> firmware auto-commits the mode launched last (Runner until +> you first use `[G]`). When you subsequently power the ST, +> it sees the cartridge already in that mode and skips the +> menu — you never get a chance to press `[U]` / `[G]`. > 2. Any Runner state the Pico accumulated before the ST booted > (a previously-loaded program, a stale cwd, etc.) survives > into the new ST session — the Pico has no way to detect @@ -1030,7 +1131,7 @@ usbcdc_dropped : 0 ``` `firmware_mode` flips to `yes` once the user has committed a -mode at the menu (`[U]` / `[G]`) — the capture is +mode at the menu (`[U]` or `[G]`) — the capture is gated on this so menu activity never pollutes the stream. `ring used / capacity` is the snapshot fill of the in-RAM debug ring at the moment of the request. `bytes_dropped` and @@ -1093,6 +1194,43 @@ python3 cli/sidecart.py runner run /HELLODBG.TOS Full endpoint reference + multi-consumer model is in [`docs/api.md`](docs/api.md#debug-traces). +## rom4 area + +The other direction from debug traces: 1 KB of the cartridge +window (`$FA8B00`–`$FA8EFF`) that the workstation writes and any +program on the ST reads, whatever mode the firmware is in. DevOps +gives the bytes no meaning; what they say is up to the program. +They are zeroed when the Pico boots, survive an ST reset, and are +lost when the Pico resets. + +Programs find the area through shared variable 20 at `$FA2860`: +the long there is `'R4A1'` when the area exists, and the next two +longs are its address and size. Read it in C or assembly as shown +in [`docs/api.md`](docs/api.md#rom4-area); the ST cannot write +it. + +```sh +$ python3 cli/sidecart.py rom4 info +address: $FA8B00 +size : 1024 bytes +magic : $52344131 ('R4A1') + +$ python3 cli/sidecart.py rom4 write 0x10 01 02 03 +ok 3 bytes at offset 16 ($010) + +$ python3 cli/sidecart.py rom4 write 0 -f params.bin +$ python3 cli/sidecart.py rom4 read # hex dump +$ python3 cli/sidecart.py rom4 read -o rom4.bin +``` + +Offsets are relative to the area (`0`–`1023`). Each 16-bit word +changes in one store, so the ST never reads half of one, but a +longer write can be seen part done; `PUT /api/v1/rom4` without an +offset takes several ranges in one request, written in order, for +programs that flip a flag after filling a buffer. +`target/atarist/test/rom4/` builds `ROM4CHK.TOS`, which shows the +first 32 bytes of the area and sends them to the debug stream. + ## Project internals This section documents the on-cartridge memory map and module @@ -1112,7 +1250,8 @@ mirrored at RP `0x20030000`. Layout: `RANDOM_TOKEN`, `RANDOM_TOKEN_SEED`, 60 × 4-byte indexed shared variables) sits at `$FA2800`. - The **`APP_FREE`** arena (~46 KB at `$FA2B00`) is the - contiguous space the app uses for its own buffers. + contiguous space the app uses for its own buffers. The 1 KB + **rom4 area** at `$FA8B00` is part of it. - The **framebuffer** (8000 B for 320×200 monochrome) sits at the very top of the region (`$FAE0C0`), so an overrun walks off the end of the 64 KB window instead of corrupting the @@ -1143,7 +1282,11 @@ into three sections: sentinel and hands control to the right blob: `CMD_START = 4` jumps into `GEMDRIVE_BLOB+4` (diagnostic + memtop verify), and `CMD_START_RUNNER = 5` jumps into `RUNNER_BLOB` (the Runner's -poll loop). Adding a new module follows the same pattern: place +poll loop). `CMD_START_TSR = 6`, which `[G]` sends when the GEMDRIVE +Runner is on, calls `RUNNER_BLOB` with the +command still in `d6`, so the Runner installs its interrupt hook +and returns, then goes through `GEMDRIVE_BLOB+4` back to TOS, which +boots on. Adding a new module follows the same pattern: place a new `.text_` section in `devops.ld`, mirror the offset with an `equ` in `main.s`, and add the `.o` target to `target/atarist/Makefile`. @@ -1157,6 +1300,11 @@ outside-module symbols (except the entry-point `jmp` from `main.s`'s dispatch). See `CLAUDE.md` for the full editing guardrails. +`devops_acc.s` is not part of the cartridge image: it builds +`DEVOPS.ACC`, the GEMDRIVE Runner's desk accessory, an ordinary TOS +executable that GEM loads and relocates. It shares the protocol +includes and the Runner's command codes. + ### Building from source The full build (m68k cartridge image + RP firmware UF2) is diff --git a/build.sh b/build.sh index 3e23f59..9115021 100755 --- a/build.sh +++ b/build.sh @@ -24,8 +24,8 @@ cp version.txt rp/ cp version.txt target/ # Display the version information -# Not exported: the stcmd installed by atarist-toolkit-docker's installer -# (as in CI) uses $VERSION as its Docker image tag, and v1.1.0 is no image. +# Not exported: the stcmd from atarist-toolkit-docker installers before +# v1.2.1 used $VERSION as its Docker image tag, and v1.1.0 is no image. VERSION=$(cat version.txt) echo "Version: $VERSION" diff --git a/cli/sidecart.py b/cli/sidecart.py index 4418994..e046db1 100644 --- a/cli/sidecart.py +++ b/cli/sidecart.py @@ -28,6 +28,9 @@ gemdrive mvdir FROM TO POST /api/v1/gemdrive/folders//rename runner … /api/v1/runner/* (see docs/api.md) debug … /api/v1/debug, /api/v1/debug/log + rom4 info GET /api/v1/rom4 + rom4 read [-o FILE] GET /api/v1/rom4/data + rom4 write OFFSET HEX... | -f FILE PUT /api/v1/rom4?offset=N Exit codes: 0 success @@ -50,6 +53,7 @@ python3 cli/sidecart.py gemdrive mvdir OLDNAME NEWNAME python3 cli/sidecart.py runner run /HELLODBG.TOS python3 cli/sidecart.py debug status + python3 cli/sidecart.py rom4 write 0x10 01 02 03 """ from __future__ import annotations @@ -657,6 +661,21 @@ def cmd_runner_unload(args: argparse.Namespace) -> int: return EXIT_OK +def _parse_number(raw: str) -> int: + """Parse decimal, $hex or 0xhex. Raises ValueError. + + Shell gotcha: bash/zsh expand `$78000` as a variable reference, so + `$hex` arguments must be single-quoted: `'$78000'`. The `0x78000` + form needs no quoting. + """ + s = raw.strip() + if s.startswith("$"): + return int(s[1:], 16) + if s.startswith(("0x", "0X")): + return int(s, 16) + return int(s, 10) + + def _parse_adv_jump_address(raw: str) -> int: """Parse a jump-target address from CLI input. @@ -669,15 +688,9 @@ def _parse_adv_jump_address(raw: str) -> int: so `$hex` arguments MUST be single-quoted on the command line: `'$78000'`. Use the `0x78000` form to avoid quoting altogether. """ - s = raw.strip() - if not s: + if not raw.strip(): raise ValueError("address is empty") - if s.startswith("$"): - value = int(s[1:], 16) - elif s.startswith(("0x", "0X")): - value = int(s, 16) - else: - value = int(s, 10) + value = _parse_number(raw) if value < 0 or value > 0xFFFFFF: raise ValueError( f"address 0x{value:X} out of 24-bit range ($0..$FFFFFF)") @@ -731,22 +744,11 @@ def cmd_runner_adv_load(args: argparse.Namespace) -> int: cap: int | None = None if args.size is not None: try: - cap = _parse_adv_jump_address(args.size) + cap = _parse_number(args.size) except ValueError: - # _parse_adv_jump_address enforces even+24bit which doesn't - # apply to a byte count. Fall back to a plain int parse. - s = args.size.strip() - try: - if s.startswith("$"): - cap = int(s[1:], 16) - elif s.startswith(("0x", "0X")): - cap = int(s, 16) - else: - cap = int(s, 10) - except ValueError: - print(f"error: cannot parse size: {args.size!r}", - file=sys.stderr) - return EXIT_BAD_REQUEST + print(f"error: cannot parse size: {args.size!r}", + file=sys.stderr) + return EXIT_BAD_REQUEST if cap <= 0: print(f"error: size must be > 0", file=sys.stderr) return EXIT_BAD_REQUEST @@ -792,6 +794,27 @@ def cmd_runner_adv_load(args: argparse.Namespace) -> int: return EXIT_OK +def _print_meminfo(parsed: dict) -> None: + """The meminfo snapshot, with the ST sysvar each field is read from.""" + print(f"membottom [$432] : 0x{parsed.get('membottom', 0):08X}") + print(f"memtop [$436] : 0x{parsed.get('memtop', 0):08X}") + print(f"phystop [$42E] : 0x{parsed.get('phystop', 0):08X}") + print(f"screenmem [$44E] : 0x{parsed.get('screenmem', 0):08X}") + bp = parsed.get('basepage', 0) + if bp: + print(f"basepage [_run] : 0x{bp:08X}") + else: + print(f"basepage [_run] : 0 (unset)") + b0 = parsed.get('bank0_kb', 0) + b1 = parsed.get('bank1_kb', 0) + if parsed.get('decoded'): + print(f"bank 0 [$FF8001 nibble] : {b0} KB") + print(f"bank 1 [$FF8001 nibble] : {b1} KB") + print(f"total RAM : {b0 + b1} KB") + else: + print(f"banks [$FF8001 nibble] : (unrecognised MMU config)") + + def cmd_runner_adv_meminfo(args: argparse.Namespace) -> int: """POST /api/v1/runner/adv/meminfo — meminfo from inside the VBL ISR.""" url = base_url(args.host) + "/api/v1/runner/adv/meminfo" @@ -812,23 +835,7 @@ def cmd_runner_adv_meminfo(args: argparse.Namespace) -> int: if args.quiet: return EXIT_OK - print(f"membottom [$432] : 0x{parsed.get('membottom', 0):08X}") - print(f"memtop [$436] : 0x{parsed.get('memtop', 0):08X}") - print(f"phystop [$42E] : 0x{parsed.get('phystop', 0):08X}") - print(f"screenmem [$44E] : 0x{parsed.get('screenmem', 0):08X}") - bp = parsed.get('basepage', 0) - if bp: - print(f"basepage [$4F2] : 0x{bp:08X}") - else: - print(f"basepage [$4F2] : 0 (TOS < 1.04 or unset)") - b0 = parsed.get('bank0_kb', 0) - b1 = parsed.get('bank1_kb', 0) - if parsed.get('decoded'): - print(f"bank 0 [$FF8001 nibble] : {b0} KB") - print(f"bank 1 [$FF8001 nibble] : {b1} KB") - print(f"total RAM : {b0 + b1} KB") - else: - print(f"banks [$FF8001 nibble] : (unrecognised MMU config)") + _print_meminfo(parsed) return EXIT_OK @@ -961,6 +968,129 @@ def cmd_debug_status(args: argparse.Namespace) -> int: return EXIT_OK +def cmd_rom4_info(args: argparse.Namespace) -> int: + """GET /api/v1/rom4 — where the rom4 area is and how to find it.""" + url = base_url(args.host) + "/api/v1/rom4" + try: + status, parsed, raw = request_json("GET", url) + except urllib.error.URLError as exc: + print(f"error: cannot reach {url}: {exc.reason}", file=sys.stderr) + return EXIT_NETWORK + + if status != 200 or parsed is None or parsed.get("ok") is not True: + render_error(parsed, raw, status) + return status_to_exit_code(status) + + if args.json: + json.dump(parsed, sys.stdout, separators=(",", ":")) + sys.stdout.write("\n") + return EXIT_OK + if args.quiet: + return EXIT_OK + + magic = parsed.get("magic", 0) + text = magic.to_bytes(4, "big").decode("ascii", errors="replace") + print(f"address: ${parsed.get('address', 0):06X}") + print(f"size : {parsed.get('size', 0)} bytes") + print(f"magic : ${magic:08X} ('{text}')") + return EXIT_OK + + +def cmd_rom4_read(args: argparse.Namespace) -> int: + """GET /api/v1/rom4/data — the whole area as a hex dump or to a file.""" + url = base_url(args.host) + "/api/v1/rom4/data" + try: + status, parsed, raw = request_json( + "GET", url, headers={"Accept": "application/octet-stream"}) + except urllib.error.URLError as exc: + print(f"error: cannot reach {url}: {exc.reason}", file=sys.stderr) + return EXIT_NETWORK + + if status != 200: + render_error(parsed, raw, status) + return status_to_exit_code(status) + + if args.output: + try: + with open(args.output, "wb") as out: + out.write(raw) + except OSError as exc: + print(f"error: cannot write {args.output}: {exc}", + file=sys.stderr) + return EXIT_GENERIC + if args.json: + json.dump({"ok": True, "local": args.output, "size": len(raw)}, + sys.stdout, separators=(",", ":")) + sys.stdout.write("\n") + elif not args.quiet: + print(f"ok rom4 -> {args.output} ({len(raw)} bytes)") + return EXIT_OK + + if args.json: + json.dump({"ok": True, "size": len(raw), "hex": raw.hex()}, + sys.stdout, separators=(",", ":")) + sys.stdout.write("\n") + return EXIT_OK + if args.quiet: + return EXIT_OK + for off in range(0, len(raw), 16): + row = raw[off:off + 16] + text = "".join(chr(b) if 32 <= b < 127 else "." for b in row) + print(f"{off:04X} {row.hex(' ').upper():<47} {text}") + return EXIT_OK + + +def cmd_rom4_write(args: argparse.Namespace) -> int: + """PUT /api/v1/rom4?offset=N — write bytes into the area.""" + try: + offset = _parse_number(args.offset) + except ValueError: + print(f"error: cannot parse offset: {args.offset!r}", file=sys.stderr) + return EXIT_USAGE + + if args.file is not None: + if args.hex: + print("error: give HEX bytes or -f FILE, not both", + file=sys.stderr) + return EXIT_USAGE + try: + with open(args.file, "rb") as f: + data = f.read() + except OSError as exc: + print(f"error: cannot read {args.file}: {exc}", file=sys.stderr) + return EXIT_BAD_REQUEST + else: + if not args.hex: + print("error: give HEX bytes or -f FILE", file=sys.stderr) + return EXIT_USAGE + try: + data = bytes.fromhex(" ".join(args.hex)) + except ValueError: + print("error: HEX must be pairs of hex digits, e.g. 01 02 0A0B", + file=sys.stderr) + return EXIT_USAGE + + url = base_url(args.host) + f"/api/v1/rom4?offset={offset}" + headers = {"Content-Type": "application/octet-stream"} + try: + status, parsed, raw = request_json( + "PUT", url, body=data, headers=headers) + except urllib.error.URLError as exc: + print(f"error: cannot reach {url}: {exc.reason}", file=sys.stderr) + return EXIT_NETWORK + + if status != 200 or parsed is None or parsed.get("ok") is not True: + render_error(parsed, raw, status) + return status_to_exit_code(status) + + if args.json: + json.dump(parsed, sys.stdout, separators=(",", ":")) + sys.stdout.write("\n") + elif not args.quiet: + print(f"ok {len(data)} bytes at offset {offset} (${offset:03X})") + return EXIT_OK + + def cmd_runner_meminfo(args: argparse.Namespace) -> int: """GET /api/v1/runner/meminfo — synchronous system memory snapshot.""" url = base_url(args.host) + "/api/v1/runner/meminfo" @@ -981,24 +1111,7 @@ def cmd_runner_meminfo(args: argparse.Namespace) -> int: if args.quiet: return EXIT_OK - # ST sysvar addresses each field is read from (TOS docs). - print(f"membottom [$432] : 0x{parsed.get('membottom', 0):08X}") - print(f"memtop [$436] : 0x{parsed.get('memtop', 0):08X}") - print(f"phystop [$42E] : 0x{parsed.get('phystop', 0):08X}") - print(f"screenmem [$44E] : 0x{parsed.get('screenmem', 0):08X}") - bp = parsed.get('basepage', 0) - if bp: - print(f"basepage [$4F2] : 0x{bp:08X}") - else: - print(f"basepage [$4F2] : 0 (TOS < 1.04 or unset)") - b0 = parsed.get('bank0_kb', 0) - b1 = parsed.get('bank1_kb', 0) - if parsed.get('decoded'): - print(f"bank 0 [$FF8001 nibble] : {b0} KB") - print(f"bank 1 [$FF8001 nibble] : {b1} KB") - print(f"total RAM : {b0 + b1} KB") - else: - print(f"banks [$FF8001 nibble] : (unrecognised MMU config)") + _print_meminfo(parsed) return EXIT_OK @@ -1098,7 +1211,8 @@ def cmd_runner_status(args: argparse.Namespace) -> int: active = parsed.get("active", False) if not active: - print("Runner mode is not active. Boot via [U] to enable.") + print("Runner is not active. Boot via [U], or [G] with the GEMDRIVE " + "Runner on.") return EXIT_OK busy = parsed.get("busy", False) @@ -1108,6 +1222,9 @@ def cmd_runner_status(args: argparse.Namespace) -> int: last_exit = parsed.get("last_exit_code") last_cd_errno = parsed.get("last_cd_errno") print(f"active : true") + if parsed.get("tsr", False): + accessory = "loaded" if parsed.get("accessory", False) else "not loaded yet" + print(f"mode : GEMDRIVE Runner (DEVOPS.ACC {accessory})") print(f"busy : {'yes' if busy else 'no'}") print(f"cwd : {cwd}") last_res_errno = parsed.get("last_res_errno") @@ -1433,6 +1550,27 @@ def build_parser() -> argparse.ArgumentParser: help="Stream debug bytes as the device emits them. " "Like `tail -f` for the m68k debug output. Runs " "until Ctrl-C, server close, or network drop.") + + rom4 = sub.add_parser( + "rom4", + help="The rom4 area: 1 KB of the cartridge window that ST " + "programs read and the workstation writes.") + rom4_sub = rom4.add_subparsers(dest="rom4_cmd", required=True) + rom4_sub.add_parser( + "info", help="Show the area's ST address, size and magic.") + rom4_read = rom4_sub.add_parser( + "read", help="Hex-dump the whole area, or save it raw with -o.") + rom4_read.add_argument("-o", "--output", default=None, + help="Write the raw 1024 bytes to this file.") + rom4_write = rom4_sub.add_parser( + "write", + help="Write bytes at an offset into the area. Offset: decimal, " + "0xhex, or $hex (single-quote it in the shell).") + rom4_write.add_argument("offset", help="Offset into the area (0-1023).") + rom4_write.add_argument("hex", nargs="*", + help="Bytes as hex, e.g. 01 02 03 or 010203.") + rom4_write.add_argument("-f", "--file", default=None, + help="Write this file's bytes instead.") return p @@ -1505,6 +1643,17 @@ def main(argv: list[str] | None = None) -> int: parser.error(f"unknown debug subcommand: {args.debug_cmd}") return EXIT_USAGE return handler(args) + if args.cmd == "rom4": + rom4_handlers = { + "info": cmd_rom4_info, + "read": cmd_rom4_read, + "write": cmd_rom4_write, + } + handler = rom4_handlers.get(args.rom4_cmd) + if handler is None: + parser.error(f"unknown rom4 subcommand: {args.rom4_cmd}") + return EXIT_USAGE + return handler(args) handler = handlers.get(args.cmd) if handler is None: parser.error(f"unknown subcommand: {args.cmd}") diff --git a/docs/api.md b/docs/api.md index f7871f2..6723135 100644 --- a/docs/api.md +++ b/docs/api.md @@ -85,12 +85,12 @@ python3 cli/sidecart.py gemdrive rm SWITCHER.TOS | `201 Created` | New folder or new file via `PUT`. Carries `Location:`. | | `204 No Content` | Successful delete. | | `206 Partial Content` | `Range:` download. Carries `Content-Range:`. | -| `400 Bad Request` | `bad_request` / `bad_path` / `bad_query` / `name_too_long`. | +| `400 Bad Request` | `bad_request` / `bad_path` / `bad_query` / `name_too_long` / `out_of_range`. | | `404 Not Found` | `not_found`; `is_directory` / `is_file` when path resolves to the other namespace. | | `405 Method Not Allowed` | Always carries `Allow:`. | | `409 Conflict` | Target exists, non-empty folder delete, root delete, file open elsewhere, read-only. | | `411 Length Required` | `PUT` without `Content-Length`. | -| `413 Payload Too Large` | Upload body > 4 MB. | +| `413 Payload Too Large` | Upload body > 4 MB, or a `rom4` body > 1024 bytes. | | `415 Unsupported Media Type` | Wrong request `Content-Type` on a JSON route. | | `416 Range Not Satisfiable` | Range outside file bounds. Carries `Content-Range: bytes */`. | | `422 Unprocessable Entity` | Malformed JSON body, missing required field, listing-on-file, rename-into-own-descendant. | @@ -109,7 +109,8 @@ Clients can switch on `code` reliably. All defined symbols: `too_many_open_files`, `disk_error`, `insufficient_memory`, `internal_error`, `runner_inactive`, `gateway_timeout`, `no_snapshot`, `wrong_hook`, `ram_overflow`, `pexec_failed`, `mfree_failed`, -`program_already_loaded`, `no_program_loaded`. +`program_already_loaded`, `no_program_loaded`, `accessory_not_loaded`, +`unsupported_in_tsr`, `out_of_range`. `too_many_open_files` — FatFs's lock table is full. It is shared with GEMDRIVE (`FF_FS_LOCK`, 28 entries: 8 GEMDRIVE files, 16 GEMDRIVE searches and 2 HTTP @@ -125,7 +126,17 @@ inserting a working card clears it within a few seconds with no reset, and the setup menu shows `SD: NO CARD` meanwhile and refuses `[G]` and `[U]`. Runner-specific codes (see *Runner mode* below): -- `runner_inactive` — the user didn't pick `[U]` at boot. +- `runner_inactive` — the Runner isn't running: the user picked neither + `[U]` nor `[G]` with the GEMDRIVE Runner on. +- `accessory_not_loaded` — TSR mode (`[G]` with the GEMDRIVE Runner + on): `DEVOPS.ACC` has not + reported in yet, so nothing on the ST serves `run`, `cd`, `load`, + `exec` or `unload`. It reports in when GEM starts it at the end of + the boot. `[G]` writes it to the root of the GEMDRIVE folder, where + GEM finds it when GEMDRIVE is `C:`; with another drive letter it + has to be copied to the boot drive by hand. +- `unsupported_in_tsr` — `runner res` in TSR mode: changing the + resolution under GEM would leave the desktop drawn for the old one. - `busy` — another foreground Runner command is in flight. Every m68k-bound foreground verb gates on this lock: `run`, `cd`, `res`, `meminfo`, `load`, `exec`, and `unload`. `reset` and the @@ -134,7 +145,8 @@ Runner-specific codes (see *Runner mode* below): - `gateway_timeout` — the Atari ST didn't reply within the endpoint's spin-wait deadline (10 s for `runner load`, 5 s for `runner unload`, 1 s for `runner meminfo` / `runner adv/meminfo` - / per-chunk `runner adv/load`). + / per-chunk `runner adv/load`). A timed-out `load` or `unload` is + withdrawn, so the ST does not run it later. - `no_snapshot` — the m68k handshake completed but no snapshot was recorded (should not happen in practice). - `wrong_hook` — Advanced Runner command requires the VBL hook (`$70`) @@ -142,6 +154,9 @@ Runner-specific codes (see *Runner mode* below): - `ram_overflow` — `runner adv load`: the requested target range `[address, address+size)` doesn't fit inside `[membottom, phystop)`. +`out_of_range` — a `rom4` write runs past the end of the 1024-byte area +(see *rom4 area* below). Nothing is written. + --- ## Endpoints @@ -536,15 +551,16 @@ fall into three behavioural buckets: `exec` / `unload`. `run` / `cd` / `res` / `exec` are fire-and-forget (`202 Accepted`); `meminfo` / `load` / `unload` are synchronous. Every one of these gates on `409 - runner_inactive` when `[U]` wasn't picked, and on `503 busy` + runner_inactive` when the Runner isn't running, and on `503 busy` (with `Retry-After: 1`) when another foreground command is - already in flight. + already in flight. In TSR mode `DEVOPS.ACC` serves them instead of + the poll loop; see *TSR mode* below. - **VBL-ISR-driven commands** — `reset` plus the entire `/api/v1/runner/adv/*` surface. These ride the m68k's VBL ISR (`$70`, or `$400` if `ADV_HOOK_VECTOR = etv_timer` in the - setup menu). They return `409 runner_inactive` when `[U]` - wasn't picked, but **do not** gate on the busy lock — + setup menu). They return `409 runner_inactive` when the Runner isn't + running, but **do not** gate on the busy lock — escaping wedged state is their job. `adv jump` and `adv load` additionally require the VBL hook specifically (`409 wrong_hook` otherwise); `reset` and `adv meminfo` work on @@ -558,6 +574,41 @@ when the foreground poll loop is blocked — wedged programs, bombs already painted, traps disabled. See the *Advanced Runner* section below the foreground endpoints. +### TSR mode + +TSR mode is what the setup menu calls the GEMDRIVE Runner: `[G]` with +`Ru[n]ner` on, which is the default (`[N]` toggles it). It installs +GEMDRIVE and the Advanced Runner hook, then lets the ST boot on through +the AUTO folder to the GEM desktop instead of entering the poll loop. +The foreground commands are served by the desk accessory `DEVOPS.ACC`, +which GEM starts from `C:\` when GEMDRIVE is `C:`. `[G]` first writes +the copy built into the firmware to the root of the GEMDRIVE folder, +unless an identical one is there. With the GEMDRIVE Runner off, `[G]` +deletes `DEVOPS.ACC` from there instead, whichever firmware wrote it. +The API is the same, with these differences: + +- `run`, `cd`, `load`, `exec` and `unload` answer `409 + accessory_not_loaded` until the accessory has reported in. +- `meminfo` is answered by the Advanced Runner hook, as `adv/meminfo` + is. +- `res` answers `409 unsupported_in_tsr`. +- The accessory only runs when GEM gives it a turn, so the commands it + serves wait, with the Runner `busy`, while a dialog or alert is open, + a menu is pulled down or something is being dragged on the desktop. + `load` and `unload` then time out (`504 gateway_timeout`) and are + withdrawn; `run`, `exec` and `cd` wait until GEM lets the accessory + run. +- `GET /api/v1/runner` reports `"tsr": true`, and `"accessory"` once + the accessory has reported in. +- After `reset` the ST boots back into TSR mode, and the foreground + commands answer `409 accessory_not_loaded` again until the accessory + has reported in, so a script should wait for `"accessory": true`. + +The accessory can only launch plain TOS programs (`.TOS`, `.TTP`, and +`.PRG` files that don't use GEM). It sends its `[RUN ]` / `[EXIT n]` +trace lines to the [debug stream](#debug-traces) rather than the +screen. + > **Shell-quoting note** — several Advanced commands accept a > `$hex` legacy form (e.g. `$78000`, equivalent to `0x78000`). Bash > and zsh expand `$78000` as a variable reference (unset → empty → @@ -583,6 +634,8 @@ curl http://sidecart.local/api/v1/runner { "ok": true, "active": true, + "tsr": false, + "accessory": false, "busy": false, "cwd": "/GAMES/ARKANOID", "last_command": "EXECUTE", @@ -597,6 +650,10 @@ curl http://sidecart.local/api/v1/runner } ``` +`tsr` is `true` when `[G]` started with the GEMDRIVE Runner on; `accessory` is `true` once +`DEVOPS.ACC` has reported in since the ST last booted (always `false` +outside TSR mode). + `last_command` is one of `null`, `RESET`, `EXECUTE`, `CD`, `RES`, `MEMINFO`, `JUMP`, `LOAD`, `PEXEC_LOAD`, `PEXEC_EXEC`, or `PEXEC_UNLOAD`. The `last_cd_errno` / `last_res_errno` fields @@ -690,7 +747,7 @@ do pass `--`, it lands in `cmdline` literally.) Common error codes: `404 not_found` (program file doesn't exist), `400 bad_path` (rejected name), `400 bad_request` (cmdline too -long), `409 runner_inactive`, `503 busy`. +long), `409 runner_inactive`, `409 accessory_not_loaded`, `503 busy`. --- @@ -749,8 +806,9 @@ Response 200: Common error codes: `200 OK` (success — basepage in body), `422 pexec_failed` (GEMDOS errno in `gemdos_errno` field — file too big, out of memory, etc.), `404 not_found`, `409 -runner_inactive`, `409 program_already_loaded`, `503 busy`, -`504 gateway_timeout` (m68k didn't respond within 10 s). +runner_inactive`, `409 accessory_not_loaded`, `409 +program_already_loaded`, `503 busy`, `504 gateway_timeout` (m68k +didn't respond within 10 s). #### `POST /api/v1/runner/exec` — `Pexec(4)` just-go @@ -776,7 +834,8 @@ Response 202: ``` Common error codes: `202 Accepted`, `409 no_program_loaded` (no -prior `load`), `409 runner_inactive`, `503 busy`. +prior `load`), `409 runner_inactive`, `409 accessory_not_loaded`, +`503 busy`. #### `POST /api/v1/runner/unload` — release the basepage @@ -802,7 +861,7 @@ Response 200: Common error codes: `200 OK`, `422 mfree_failed` (GEMDOS errno in `gemdos_errno` — rare, typically means the basepage was already freed), `409 no_program_loaded`, `409 runner_inactive`, -`503 busy`, `504 gateway_timeout`. +`409 accessory_not_loaded`, `503 busy`, `504 gateway_timeout`. #### Full lifecycle example @@ -841,7 +900,8 @@ python3 cli/sidecart.py runner cd ARKANOID # relative to current cwd ``` Common error codes: `404 not_found`, `400 bad_path` (rejected name -or "not a directory"), `409 runner_inactive`, `503 busy`. +or "not a directory"), `409 runner_inactive`, `409 +accessory_not_loaded`, `503 busy`. --- @@ -869,7 +929,7 @@ python3 cli/sidecart.py runner res med ``` Common error codes: `400 bad_request` (unknown rez), `409 -runner_inactive`, `503 busy`. +runner_inactive`, `409 unsupported_in_tsr`, `503 busy`. --- @@ -879,6 +939,8 @@ Synchronous read of the ST's TOS memory cookies and the MMU bank-config register. The handler fires `RUNNER_CMD_MEMINFO` and spins on the chandler loop until the m68k replies, with a 1-second timeout (returned as `504 gateway_timeout` if the m68k is wedged). +In TSR mode the Advanced Runner hook answers instead, with the same +reply. Reported addresses: @@ -888,7 +950,7 @@ Reported addresses: | `memtop` | `$436` | `_memtop` — top of TPA memory available to processes. | | `phystop` | `$42E` | `_phystop` — top of physical RAM. | | `screenmem` | `$44E` | `_v_bas_ad` — logical screen base. | -| `basepage` | `$4F2` | `_run` — current process basepage (TOS ≥ 1.04; 0 on older TOS). | +| `basepage` | `_run` | Basepage of the running process. Found through the OS header that `_sysbase` (`$4F2`) points to: its `p_run` field on TOS 1.02 and later, `$602C` (`$873C` in the Spanish version) on TOS 1.00. | | `bank0_kb`, `bank1_kb` | `$FFFF8001` lower nibble | MMU bank sizes in KB. `0/0` when the nibble is unrecognised. | | `decoded` | derived | `true` when at least one bank size is non-zero. | @@ -1112,7 +1174,7 @@ One cartridge cycle per byte. The 8-bit read result is undefined and MUST be discarded. The capture is gated on the firmware-mode flag — it goes live -the moment the user picks `[U]` / `[G]` in the setup +the moment the user picks `[U]` or `[G]` in the setup menu and the device commits to firmware mode. Pre-commit reads in the debug window are dropped at the RP filter so menu-mode activity never pollutes the diagnostic stream. @@ -1142,7 +1204,7 @@ bytes; safe to poll at any cadence. | Field | Meaning | | --- | --- | -| `firmware_mode` | `true` once `[U]` / `[G]` has committed; until then, debug emits are dropped at the RP filter. | +| `firmware_mode` | `true` once `[U]` or `[G]` has committed; until then, debug emits are dropped at the RP filter. | | `ring_used` | Bytes currently in the producer's ring (capped at `ring_capacity`). | | `ring_capacity` | Ring size (8192 today). | | `bytes_dropped` | Producer-side drops. Always 0 in the current design (the producer overwrites; per-consumer drops are reported separately). | @@ -1245,6 +1307,175 @@ program exits. --- +## rom4 area + +1 KB of the cartridge window that the workstation writes over HTTP and +any program on the ST reads. It is the other direction from *Debug +traces*: data for a program that is already running, such as live +parameters, scripted input for an unattended test, or a driver's state. +DevOps gives the bytes no meaning. + +The area is at `$FA8B00`–`$FA8EFF`. Programs should not hard-code that: +they find it through three shared variables, so the one fixed address +is slot 20, `$FA2860`. + +| Slot | Address | Holds | +| --- | --- | --- | +| 20 | `$FA2860` | Magic `'R4A1'` (`$52344131`) | +| 21 | `$FA2864` | ST address of the area | +| 22 | `$FA2868` | Size in bytes (1024) | + +The RP publishes them when it boots, so the area is there in the setup +menu and in `[G]` and `[U]`, before the ST has booted. A program +that does not find the magic is running without a cartridge, or with +firmware that has no rom4 area, and should carry on without it. + +**C**: + +```c +#define ROM4_SLOT 0xFA2860UL /* shared variable 20 */ + +const volatile unsigned long *slot = (const volatile unsigned long *)ROM4_SLOT; +if (slot[0] == 0x52344131UL) { /* 'R4A1' */ + const volatile unsigned char *area = + (const volatile unsigned char *)slot[1]; + unsigned long size = slot[2]; + /* read area[0] .. area[size - 1] */ +} +``` + +**m68k**: + +```asm +ROM4_SLOT equ $FA2860 ; shared variable 20 + + cmp.l #$52344131,ROM4_SLOT ; 'R4A1' + bne.s .no_rom4 + move.l ROM4_SLOT+4,a0 ; area + move.l ROM4_SLOT+8,d0 ; size in bytes +``` + +Reads work in user mode. The ST cannot write the area: the cartridge +port is read-only, and a write is a bus error. + +**Contents.** All zeros when the RP boots; after that only the +endpoints below change them. They survive an ST reset and are lost when +the RP resets. Each 16-bit word changes in one store, so the ST never +reads half of a word, but a longer write can be seen part done. A +program that needs several bytes to change together runs its own +protocol on top, such as two buffers and a word saying which one is +current, written last. + +Offsets in the API are relative to the area, `0`–`1023`, never ST +addresses. None of these endpoints wait for the ST or the Runner. + +### `GET /api/v1/rom4` — where the area is + +**Response 200**: +```json +{ "ok": true, "address": 16419584, "size": 1024, "magic": 1379156273 } +``` + +**`curl`**: +```sh +curl http://sidecart.local/api/v1/rom4 +``` + +**`sidecart`**: +```sh +python3 cli/sidecart.py rom4 info +``` + +### `GET /api/v1/rom4/data` — read the area + +The whole area: 1024 bytes of `application/octet-stream`, in the order +the ST reads them. + +**`curl`**: +```sh +curl -o rom4.bin http://sidecart.local/api/v1/rom4/data +``` + +**`sidecart`**: +```sh +python3 cli/sidecart.py rom4 read # hex dump +python3 cli/sidecart.py rom4 read -o rom4.bin # raw +``` + +Errors: `503 busy` in the unlikely case that the connection's send +buffer cannot take the whole response. + +### `PUT /api/v1/rom4?offset=` — write bytes + +The body (`Content-Type` ignored) is written at offset `n`, which can +be decimal or `0x` hex. The body is at most 1024 bytes, and +`offset + length` must not pass 1024. + +**`curl`**: +```sh +printf 'ROM4 OK!' | curl -X PUT --data-binary @- \ + 'http://sidecart.local/api/v1/rom4?offset=0x18' +``` + +**Response 200**: +```json +{ "ok": true, "writes": 1 } +``` + +**`sidecart`**: +```sh +python3 cli/sidecart.py rom4 write 0x18 52 4F 4D 34 20 4F 4B 21 +python3 cli/sidecart.py rom4 write 0 -f params.bin +``` + +### `PUT /api/v1/rom4` — write several ranges in one request + +With no `offset`, the body is a run of frames, each a 16-bit offset, a +16-bit length and that many bytes, big-endian: + +``` +[offset hi][offset lo][length hi][length lo][bytes...] [next frame...] +``` + +The frames are written in the order they come, each from its lowest +address up, so one request can fill a buffer and then flip the word +that tells the ST to use it. The body is at most 1024 bytes, frame +headers included. + +```sh +# 4 bytes at 0x100, then the word at 0x000. +printf '\x01\x00\x00\x04\xde\xad\xbe\xef\x00\x00\x00\x02\x00\x01' | \ + curl -X PUT --data-binary @- http://sidecart.local/api/v1/rom4 +{"ok":true,"writes":2} +``` + +The whole body is checked before any of it is written: a frame that +runs past the end of the body or of the area fails the request and +changes nothing. + +Errors for both `PUT` forms: `400 bad_request` (unparseable `offset`, +truncated frame), `400 out_of_range`, `411 length_required`, +`413 payload_too_large`. + +### Verifying the path end-to-end + +`target/atarist/test/rom4/` builds `ROM4CHK.TOS`, which finds the area, +shows its first 32 bytes on screen for three seconds, sends the same +lines to the debug stream and exits with `0`, or with `1` when the +magic is missing: + +```sh +target/atarist/test/rom4/build.sh +python3 cli/sidecart.py rom4 write 0 52 4F 4D 34 20 4F 4B 21 +python3 cli/sidecart.py gemdrive put target/atarist/test/rom4/dist/ROM4CHK.TOS +python3 cli/sidecart.py debug tail # in another shell +python3 cli/sidecart.py runner run /ROM4CHK.TOS +``` + +It runs from the desktop too, in `[G]`. + +--- + ## CLI exit codes `cli/sidecart.py` maps response status to a granular exit code so diff --git a/emu/README.md b/emu/README.md index de8d84d..7967d61 100644 --- a/emu/README.md +++ b/emu/README.md @@ -48,13 +48,18 @@ derives from the cartridge window or the flash is kept in `uintptr_t` in the fir ```sh tools/dev/emu_check.py # ST, STE and Mega STE, about 40 s tools/dev/emu_check.py --machine ste --run target/atarist/test/gemdos-io/dist/GDTEST.TOS -tools/dev/emu_check.py --mode g --reset warm # [G] to the desktop, then a reset +tools/dev/emu_check.py --mode g --run GDTEST.TOS # [G]: GEM, DEVOPS.ACC, the Runner from it +tools/dev/emu_check.py --mode g --menu-keys n # [N] then [G]: the GEMDRIVE Runner off +tools/dev/emu_check.py --mode g --auto PROG.TOS # a program in GEMDRIVE's C:\AUTO +tools/dev/emu_check.py --run QUESTION.TOS@42 --reset cold # expect exit 42, then a cold reset ``` For each machine it makes a card and a flash in `tools/dev/logs/emu/