From f3530d5528e07b8bd0b421a799839d0950e227fd Mon Sep 17 00:00:00 2001 From: pjht Date: Sun, 5 Nov 2023 10:34:11 -0600 Subject: [PATCH] Add open to the VFS --- init.z80 | 38 ++++++++++++++++++-- test_fs.z80 | 11 ++++-- vfs.z80 | 101 ++++++++++++++++++++++++++++++++++++++++++++++------ 3 files changed, 135 insertions(+), 15 deletions(-) diff --git a/init.z80 b/init.z80 index 7d0ca14..c7b974e 100644 --- a/init.z80 +++ b/init.z80 @@ -74,9 +74,43 @@ mount_mb_read_done: ld a, b ; Loop if there is no message cp 0 jp nz, mount_loop -ld a, (0xA001) -ld c, a mount_done: +; Set up an open message to the VFS for "/test" +ld hl, (mailbox_num) +ld (0xA000), hl +ld a, 0x2 ; Open operation +ld (0xA002), a +ld a, 0x2F ; '/' +ld (0xA003), a +ld a, 0x74 ; 't' +ld (0xA004), a +ld a, 0x65 ; 'e' +ld (0xA005), a +ld a, 0x73 ; 's' +ld (0xA006), a +ld a, 0x74 ; 't' +ld (0xA007), a +ld a, 0x0 ; '\0' +ld (0xA008), a +push de +push bc +ld de, 2 ; Get the mailbox number for the VFS +call proc_map_get +open_pmg_done: +pop bc +pop de +ld ix, 0x0000 ; Send the message +call mb_send +open_loop: +call yield +open_loop_yield_done: +ld hl, (mailbox_num) +call mb_read ; Read a message +open_mb_read_done: +ld a, b ; Loop if there is no message +cp 0 +jp nz, open_loop +open_done: halt mailbox_num: .ds.b 2 diff --git a/test_fs.z80 b/test_fs.z80 index 8161e80..08e6656 100644 --- a/test_fs.z80 +++ b/test_fs.z80 @@ -82,13 +82,18 @@ call mb_send jp msg_loop open: -jp z, operation_done +halt +ld a, 0xAA +ld (0xB000), a +ld a, 0x55 +ld (0xB001), a +jp operation_done read: -jp z, operation_done +jp operation_done mount: -jp z, operation_done +jp operation_done diff --git a/vfs.z80 b/vfs.z80 index df73774..65227ba 100644 --- a/vfs.z80 +++ b/vfs.z80 @@ -114,15 +114,13 @@ mount: ld a, (mount_count) ld l, 0x0 ld h, a -ld de, data_mount_offset -add hl, de -ld de, 0x9000 +ld de, 0x9000 + data_mount_offset add hl, de push hl pop de push de ld hl, 0xB003 -ld bc, 252 +ld bc, 0xFC ldir ; FS type at 0xB1FF ld a, (fs_count) @@ -141,21 +139,27 @@ jp mount_loop1_done add hl, de djnz mount_loop1 mount_loop1_done: +; hl -> pointer to fs type info +; top of stack -> pointer to open mount info slot ld de, 14 add hl, de pop ix -ld de, 252 +; hl -> pointer to byte 15 of fs type info +; ix -> pointer to open mount info slot +ld de, 0xFD add ix, de +; ix -> pointer to offset 0xFD of mount info +; fs info word starting at 0xE -> mount info word starting at 0xFD ld e, (hl) inc hl ld d, (hl) ld (ix), e ld (ix+1), d -push ix ld hl, (fs_mailbox_num) ld (0x8000), hl ld a, 0x2 ld (0x8002), a +push ix push de ld hl, 0xB0FF ld de, 0x8003 @@ -175,10 +179,9 @@ ld a, b ; Loop if there is no message cp 0 jp nz, mount_wait_loop pop ix +; response byte 1 -> mount info byte at offset 0xFF ld a, (0x8000) ld (ix+2), a -ld a, (0x8001) -ld (ix+3), a ld a, (mount_count) inc a ld (mount_count), a @@ -192,21 +195,99 @@ ld a, (iy) ld b, a ld a, (ix) cp b +jp nz, vfsstrcmp_loopend cp 0 ret z -jp nz, vfsstrcmp_loopend inc ix inc iy jp vfsstrcmp_loop vfsstrcmp_loopend: +ld a, (ix) +cp 0 +ret z ld a, (iy) ld b, a ld a, (ix) sub b ret -; TODO open open: +; Scan mountpoints for largest prefix matching path +ld hl, data_mount_offset + 0x9000 +ld bc, 0 +ld de, 0 +open_mount_scan: +ld a, (hl) +cp 0 +jp z, open_mount_scan_done +push hl +pop ix +ld iy, 0xB003 +push bc +call vfsstrcmp +pop bc +cp 0 +jp nz, open_no_prefix +push hl +pop de +call strlen +open_no_prefix: +ld a, h +inc a +ld h, a +ld l, 0 +jp open_mount_scan +open_mount_scan_done: +; Send open request to FS w/ path-prefix and mount ID +ld hl, 0xB003 +add hl, bc +push de +; mountpoint path -> 0x8003-0x8103 (exclusive end) +ld de, 0x8003 +ld bc, 0x100 +ldir +pop de +; mount info byte 0xFF -> 0x8103 +ld e, 0xFF +ld a, (de) +ld (0x8103), a +; imm 0x0 -> 0x8002 +ld a, 0x0 +ld (0x8002), a +; fs_mailbox_num (16bit) -> 0x8000,0x8001 +ld hl, 0x8000 +ld bc, (fs_mailbox_num) +ld (hl), c +inc hl +ld (hl), b +; mount info word 0xFD -> hl +ld e, 0xFD +ld a, (de) +ld l, a +inc de +ld a, (de) +ld h, a +push hl +ld a, (send_page_addr) +ld c, a +ld de, (send_page_addr+1) +ld ix, 0x0 +call mb_send +; Get request back, pass on to caller (add in alt MB id support?) +open_wait_loop: +call yield +ld hl, (fs_mailbox_num) +call mb_read ; Read a message +ld a, b ; Loop if there is no message +cp 0 +jp nz, open_wait_loop +pop hl +ld (0xB002), hl +; word at 0x8000 -> 0xB000 +ld a, (0x8000) +ld (0xB000), a +ld a, (0x8001) +ld (0xB001), a jp operation_done