From 4f2d40ca35e0e39886dc881d06256fc25ba27a77 Mon Sep 17 00:00:00 2001 From: user Date: Thu, 16 Jul 2026 12:20:57 +0200 Subject: fs rewrite stage 2: inodes + root directory (block-based, persistent) - fs.asm: a real block filesystem on the persistent block device - superblock, block/inode bitmaps, a 32-entry inode table (type, size, 8 direct block pointers -> files up to 2 KiB), and a root directory of 16-byte entries. Metadata cached in WRAMX; one-block data cache streams file/dir blocks. - same syscall interface (open/getb/putb/list/remove) -> tools unchanged; ls now enumerates until flist() runs out (16 files, was hardcoded 8). - old 8-slot WRAM FS removed; cart RAM partitioned: process banks 0-7, disk 8-11. - two register-clobber bugs fixed: alloc_block/alloc_inode returned the bitmap-block number (write_bitmap clobbers C); db_use loaded the wrong block on a transition (db_flush->write_block clobbers C) -> multi-block files broke. - verified: 10+ files, multi-block (300-byte) files, delete, and persistence across reboots. Debug 'blk' disk tool retained (fill/peek). - README: document the block filesystem. --- src/blk.asm | 65 ++++++++++++------------------------------------------------- 1 file changed, 12 insertions(+), 53 deletions(-) (limited to 'src/blk.asm') diff --git a/src/blk.asm b/src/blk.asm index ea04e95..2be961e 100644 --- a/src/blk.asm +++ b/src/blk.asm @@ -83,57 +83,6 @@ write_block:: restore_bank ret -; ----------------------------------------------------------------------------- -; blk_format - write a fresh superblock (magic) to block 0. (mkfs, stage 1) -; ----------------------------------------------------------------------------- -blk_format:: - ld hl, wCopyBuf ; zero the buffer - ld b, 0 - xor a -.z - ld [hl+], a - dec b - jr nz, .z - ld hl, wCopyBuf - ld a, SUPER_MAG0 - ld [hl+], a - ld a, SUPER_MAG1 - ld [hl+], a - ld a, SUPER_MAG2 - ld [hl+], a - ld a, SUPER_MAG3 - ld [hl], a - ld a, SUPER_BLOCK - ld hl, wCopyBuf - call write_block - ret - -; ----------------------------------------------------------------------------- -; blk_init - format the disk only if it isn't already formatted (magic check). -; Called at boot; the disk otherwise persists across power cycles (.sav). -; ----------------------------------------------------------------------------- -blk_init:: - ld a, SUPER_BLOCK - ld hl, wCopyBuf - call read_block - ld hl, wCopyBuf - ld a, [hl+] - cp SUPER_MAG0 - jr nz, .fmt - ld a, [hl+] - cp SUPER_MAG1 - jr nz, .fmt - ld a, [hl+] - cp SUPER_MAG2 - jr nz, .fmt - ld a, [hl] - cp SUPER_MAG3 - jr nz, .fmt - ret ; already formatted -.fmt - call blk_format - ret - ; ============================================================================= ; [debug] block poke/peek syscalls, to validate the layer + persistence. ; ============================================================================= @@ -152,10 +101,20 @@ sys_bfill:: xor a ret -; sys_bpeek(B = block) -> A = block's first byte +; sys_bpeek(B = block, E = offset) -> A = block[offset] sys_bpeek:: + ld a, e + ld [wFsByte], a ; stash offset ld a, b ld hl, wCopyBuf call read_block - ld a, [wCopyBuf] + ld hl, wCopyBuf + ld a, [wFsByte] + add l + ld l, a + ld a, h + adc 0 + ld h, a + ld a, [hl] ret + -- cgit v1.3.1-sl0p