From df67a38f81e0e524418bc6e5f1065d71a59bc453 Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Thu, 16 May 2019 13:13:46 -0400 Subject: [PATCH] Extract fs_cmds.asm from fs.asm --- parts/z80/fs.asm | 86 ------------------------------------------ parts/z80/fs_cmds.asm | 87 +++++++++++++++++++++++++++++++++++++++++++ tools/emul/shell_.asm | 1 + 3 files changed, 88 insertions(+), 86 deletions(-) create mode 100644 parts/z80/fs_cmds.asm diff --git a/parts/z80/fs.asm b/parts/z80/fs.asm index 39a7c50..7f0b520 100644 --- a/parts/z80/fs.asm +++ b/parts/z80/fs.asm @@ -468,12 +468,9 @@ fsTell: ld h, (ix+1) ret -; *** SHELL COMMANDS *** ; Mount the fs subsystem upon the currently selected blockdev at current offset. ; Verify is block is valid and error out if its not, mounting nothing. ; Upon mounting, copy currently selected device in FS_GETC/PUTC/SEEK/TELL. -fsOnCmd: - .db "fson", 0, 0, 0 fsOn: push hl push de @@ -508,86 +505,3 @@ fsOn: pop de pop hl ret - -; Lists filenames in currently active FS -flsCmd: - .db "fls", 0, 0, 0, 0 - call fsBegin - jr nz, .error -.loop: - call fsIsDeleted - jr z, .skip - ld hl, FS_META+FS_META_FNAME_OFFSET - call printstr - call printcrlf -.skip: - call fsNext - jr z, .loop ; Z set? fsNext was successful - xor a - jr .end -.error: - ld a, FS_ERR_NO_FS -.end: - ret - -; Takes one byte block number to allocate as well we one string arg filename -; and allocates a new file in the current fs. -fnewCmd: - .db "fnew", 0b001, 0b1001, 0b001 - push hl - ld a, (hl) - inc hl - call intoHL - call fsAlloc - pop hl - xor a - ret - -; Deletes filename with specified name -fdelCmd: - .db "fdel", 0b1001, 0b001, 0 - push hl - push de - call intoHL ; HL now holds the string we look for - call fsFindFN - jr nz, .notfound - ; Found! delete - xor a - ; Set filename to zero to flag it as deleted - ld (FS_META+FS_META_FNAME_OFFSET), a - call fsWriteMeta - ; a already to 0, our result. - jr .end -.notfound: - ld a, FS_ERR_NOT_FOUND -.end: - pop de - pop hl - ret - - -; Opens specified filename in specified file handle. -; First argument is file handle, second one is file name. -; Example: fopn 0 foo.txt -fopnCmd: - .db "fopn", 0b001, 0b1001, 0b001 - push hl - push de - ld a, (hl) ; file handle index - ld de, FS_HANDLES - call addDE ; DE now stores pointer to file handle - inc hl - call intoHL ; HL now holds the string we look for - call fsFindFN - jr nz, .notfound - ; Found! - ; FS_PTR points to the file we want to open - ex hl, de ; HL now points to the file handle. - call fsOpen - jr .end -.notfound: - ld a, FS_ERR_NOT_FOUND -.end: - pop de - pop hl - ret diff --git a/parts/z80/fs_cmds.asm b/parts/z80/fs_cmds.asm new file mode 100644 index 0000000..4b2dc7a --- /dev/null +++ b/parts/z80/fs_cmds.asm @@ -0,0 +1,87 @@ +; *** SHELL COMMANDS *** +fsOnCmd: + .db "fson", 0, 0, 0 + jp fsOn + +; Lists filenames in currently active FS +flsCmd: + .db "fls", 0, 0, 0, 0 + call fsBegin + jr nz, .error +.loop: + call fsIsDeleted + jr z, .skip + ld hl, FS_META+FS_META_FNAME_OFFSET + call printstr + call printcrlf +.skip: + call fsNext + jr z, .loop ; Z set? fsNext was successful + xor a + jr .end +.error: + ld a, FS_ERR_NO_FS +.end: + ret + +; Takes one byte block number to allocate as well we one string arg filename +; and allocates a new file in the current fs. +fnewCmd: + .db "fnew", 0b001, 0b1001, 0b001 + push hl + ld a, (hl) + inc hl + call intoHL + call fsAlloc + pop hl + xor a + ret + +; Deletes filename with specified name +fdelCmd: + .db "fdel", 0b1001, 0b001, 0 + push hl + push de + call intoHL ; HL now holds the string we look for + call fsFindFN + jr nz, .notfound + ; Found! delete + xor a + ; Set filename to zero to flag it as deleted + ld (FS_META+FS_META_FNAME_OFFSET), a + call fsWriteMeta + ; a already to 0, our result. + jr .end +.notfound: + ld a, FS_ERR_NOT_FOUND +.end: + pop de + pop hl + ret + + +; Opens specified filename in specified file handle. +; First argument is file handle, second one is file name. +; Example: fopn 0 foo.txt +fopnCmd: + .db "fopn", 0b001, 0b1001, 0b001 + push hl + push de + ld a, (hl) ; file handle index + ld de, FS_HANDLES + call addDE ; DE now stores pointer to file handle + inc hl + call intoHL ; HL now holds the string we look for + call fsFindFN + jr nz, .notfound + ; Found! + ; FS_PTR points to the file we want to open + ex hl, de ; HL now points to the file handle. + call fsOpen + jr .end +.notfound: + ld a, FS_ERR_NOT_FOUND +.end: + pop de + pop hl + ret diff --git a/tools/emul/shell_.asm b/tools/emul/shell_.asm index f58ca8c..7b11c15 100644 --- a/tools/emul/shell_.asm +++ b/tools/emul/shell_.asm @@ -28,6 +28,7 @@ BLOCKDEV_COUNT .equ 4 .equ FS_RAMSTART BLOCKDEV_RAMEND .equ FS_HANDLE_COUNT 2 #include "fs.asm" +#include "fs_cmds.asm" SHELL_RAMSTART .equ FS_RAMEND .define SHELL_IO_GETC call blkGetC