mirror of
https://github.com/hsoft/collapseos.git
synced 2024-11-08 11:58:05 +11:00
ae028e3a86
This huge refactoring remove the Seek and Tell routine from blockdev implementation requirements and change GetC and PutC's API so that they take an address to read and write (through HL/DE) at each call. The "PTR" approach in blockdev implementation was very redundant from device to device and it made more sense to generalize. It's possible that future device aren't "random access", but we'll be able to add more device types later. Another important change in this commit is that the "blockdev handle" is now opaque. Previously, consumers of the API would happily call routines directly from one of the 4 offsets. We can't do that any more. This makes the API more solid for future improvements. This change forced me to change a lot of things in fs, but overall, things are now simpler. No more `FS_PTR`: the "device handle" now holds the active pointer. Lots, lots of changes, but it also feels a lot cleaner and solid.
90 lines
1.6 KiB
NASM
90 lines
1.6 KiB
NASM
; *** SHELL COMMANDS ***
|
|
fsOnCmd:
|
|
.db "fson", 0, 0, 0
|
|
jp fsOn
|
|
|
|
; Lists filenames in currently active FS
|
|
flsCmd:
|
|
.db "fls", 0, 0, 0, 0
|
|
call fsIsOn
|
|
jr nz, .error
|
|
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
|
|
push de \ pop ix ; IX now points to the file handle.
|
|
call fsOpen
|
|
jr .end
|
|
.notfound:
|
|
ld a, FS_ERR_NOT_FOUND
|
|
.end:
|
|
pop de
|
|
pop hl
|
|
ret
|