From 057e5377af2d086917b9cd0ffb336231d7d098cb Mon Sep 17 00:00:00 2001 From: user Date: Thu, 16 Jul 2026 11:42:38 +0200 Subject: fs rewrite stage 1: persistent block device (bounce buffer, cart SRAM) - blk.asm: read_block/write_block move 256-byte blocks between battery-backed cart-RAM banks (8-11, the 'disk') and a WRAM bounce buffer. Banking is hidden in those two routines; they inline the 'restore my bank' step so they never touch the stack while the disk bank is mapped over the process's $A000 window (the stack lives there too -- a call/ret would rug-pull it). - format-on-first-boot: superblock magic in block 0; otherwise the disk persists. - cart RAM bumped to 128 KiB (-r 4); process banks 0-7, disk banks 8-11. - debug tool 'blk fill/peek' + syscalls to validate round-trip and persistence. - verified: round-trip incl. cross-bank (block 100 -> bank 11); block survives a reboot via .sav; magic intact (no reformat on 2nd boot). - old WRAM 8-slot FS still backs the tools until stages 2-3. --- c/blk.c | 13 +++++++++++++ c/gbos.h | 2 ++ c/libc.s | 14 ++++++++++++++ 3 files changed, 29 insertions(+) create mode 100644 c/blk.c (limited to 'c') diff --git a/c/blk.c b/c/blk.c new file mode 100644 index 0000000..adf2a58 --- /dev/null +++ b/c/blk.c @@ -0,0 +1,13 @@ +#include "gbos.h" +/* blk: exercise the block device. blk fill | blk peek */ +void main(void) { + char *argv[4]; + unsigned char argc = argv_parse(argv, 4); + if (argc >= 3 && argv[0][0] == 'f') { + bfill(atou(argv[1]), atou(argv[2])); + } else if (argc >= 2 && argv[0][0] == 'p') { + putu(bpeek(atou(argv[1]))); nl(); + } else { + puts("usage: blk fill | blk peek "); nl(); + } +} diff --git a/c/gbos.h b/c/gbos.h index f76d1e0..03a91de 100644 --- a/c/gbos.h +++ b/c/gbos.h @@ -43,4 +43,6 @@ unsigned char psget(unsigned char slot, unsigned char *buf); /* {pid,state,prog} void progname(unsigned char id, char *buf); /* id -> name */ void yield(void); unsigned char reap(void); /* reap a finished bg job, or 0 */ +void bfill(unsigned char block, unsigned char byte); /* [debug] disk */ +unsigned char bpeek(unsigned char block); /* [debug] disk */ #endif diff --git a/c/libc.s b/c/libc.s index 2e2516b..5b81dca 100644 --- a/c/libc.s +++ b/c/libc.s @@ -199,3 +199,17 @@ _reap: ld c, #22 ; SYS_REAP rst #0x30 ret + + .globl _bfill, _bpeek + ;; void bfill(unsigned char block /*A*/, unsigned char byte /*E*/) +_bfill: + ld b, a + ld c, #23 ; SYS_BFILL + rst #0x30 + ret + ;; unsigned char bpeek(unsigned char block /*A*/) -> A +_bpeek: + ld b, a + ld c, #24 ; SYS_BPEEK + rst #0x30 + ret -- cgit v1.3.1-sl0p