203 lines
3.4 KiB
Z80 Assembly
203 lines
3.4 KiB
Z80 Assembly
.global libvfs_init
|
|
; Pointer to message frame in HL
|
|
; Physical address of message frame in C:DE
|
|
; Clobbers A, BC, DE, HL, IX
|
|
libvfs_init:
|
|
ld (msg_frame_ptr), hl
|
|
ld a, c
|
|
ld (msg_frame_phys), a
|
|
ld (msg_frame_phys+1), de
|
|
call get_free_mailbox ; Initialize a mailbox
|
|
ld (mailbox_num), hl
|
|
ret
|
|
|
|
.global libvfs_register_fs
|
|
; Registers a FS with the VFS
|
|
; Mailbox in HL, pointer to name in IX
|
|
; Clobbers A, BC, DE, HL, IX, IY
|
|
libvfs_register_fs:
|
|
push hl
|
|
ld iy, (msg_frame_ptr)
|
|
ld hl, (mailbox_num)
|
|
ld (iy), l
|
|
ld (iy+1), h
|
|
ld a, 0x0 ; Register FS operation
|
|
ld (iy+2), a
|
|
ld bc, 7
|
|
push ix
|
|
pop hl
|
|
ld d, iyh
|
|
ld e, 0x3
|
|
call strcpy
|
|
pop hl
|
|
ld (iy+0x11), l
|
|
ld (iy+0x12), h
|
|
ld de, 2 ; Get the mailbox number for the VFS
|
|
call proc_map_get
|
|
pmg_done:
|
|
ld a, (msg_frame_phys)
|
|
ld c, a
|
|
ld de, (msg_frame_phys+1)
|
|
ld ix, 0x0000
|
|
call mb_send
|
|
reg_fs_loop:
|
|
call yield
|
|
loop_yield_done:
|
|
ld hl, (mailbox_num)
|
|
call mb_read ; Read a message
|
|
reg_fs_mb_read_done:
|
|
ld a, b ; Loop if there is no message
|
|
cp 0
|
|
jp nz, reg_fs_loop
|
|
ret
|
|
|
|
.global libvfs_mount
|
|
; Mounts a FS
|
|
; Device string in BC
|
|
; Path string in DE
|
|
; FS name string in HL
|
|
; Clobbers A, BC, DE, HL, IX, IY
|
|
libvfs_mount:
|
|
push hl
|
|
push bc
|
|
push de
|
|
ld iy, (msg_frame_ptr)
|
|
ld hl, (mailbox_num)
|
|
ld (iy), l
|
|
ld (iy+1), h
|
|
ld a, 0x1 ; Mount operation
|
|
ld (iy+2), a
|
|
ld d, iyh
|
|
ld e, 0x3
|
|
pop hl
|
|
call strcpy
|
|
ld d, iyh
|
|
ld e, 0xFF
|
|
pop hl
|
|
call strcpy
|
|
ld d, iyh
|
|
inc d
|
|
ld e, 0xFF
|
|
pop hl
|
|
call strcpy
|
|
ld de, 2 ; Get the mailbox number for the VFS
|
|
call proc_map_get
|
|
mount_pmg_done:
|
|
; Send the message
|
|
ld a, (msg_frame_phys)
|
|
ld c, a
|
|
ld de, (msg_frame_phys+1)
|
|
ld ix, 0x0000
|
|
call mb_send
|
|
mount_loop:
|
|
call yield
|
|
mount_loop_yield_done:
|
|
ld hl, (mailbox_num)
|
|
call mb_read ; Read a message
|
|
mount_mb_read_done:
|
|
ld a, b ; Loop if there is no message
|
|
cp 0
|
|
jp nz, mount_loop
|
|
mount_done:
|
|
ret
|
|
|
|
.global libvfs_open
|
|
; Opens a file
|
|
; Path in HL
|
|
; Pointer to 4-byte buffer in DE (file info saved there)
|
|
; FD returned in DE, MBID of FS in HL
|
|
; Clobbers A, BC, DE, HL, IX, IY
|
|
libvfs_open:
|
|
push de
|
|
push hl
|
|
ld iy, (msg_frame_ptr)
|
|
ld hl, (mailbox_num)
|
|
ld (iy), l
|
|
ld (iy+1), h
|
|
ld a, 0x2 ; Open operation
|
|
ld (iy+2), a
|
|
ld d, iyh
|
|
ld e, 0x3
|
|
pop hl
|
|
call strcpy
|
|
ld de, 2 ; Get the mailbox number for the VFS
|
|
call proc_map_get
|
|
open_pmg_done:
|
|
; Send the message
|
|
ld a, (msg_frame_phys)
|
|
ld c, a
|
|
ld de, (msg_frame_phys+1)
|
|
ld ix, 0x0000
|
|
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:
|
|
ld hl, (msg_frame_ptr)
|
|
pop de
|
|
ld bc, 4
|
|
ldir
|
|
ret
|
|
|
|
.global libvfs_read
|
|
; Reads data from an open file
|
|
; Pointer to file struct in HL
|
|
; Data length in BC
|
|
; Offset in DE
|
|
; Buffer returned in HL
|
|
; BUFFER INVALIDATED WHEN MESSAGE IS NEXT SENT
|
|
; WITH FRAME GIVEN ON INIT
|
|
libvfs_read:
|
|
push hl
|
|
ld iy, (msg_frame_ptr)
|
|
ld hl, (mailbox_num)
|
|
ld (iy), l
|
|
ld (iy+1), h
|
|
pop hl
|
|
ld a, 0x1 ; Read operation
|
|
ld (iy+2), a
|
|
ld a, (hl)
|
|
ld (iy+3), c
|
|
inc hl
|
|
ld a, (hl)
|
|
ld (iy+4), b
|
|
inc hl
|
|
ld (iy+5), e
|
|
ld (iy+6), d
|
|
ld (iy+7), c
|
|
ld (iy+8), b
|
|
; Send the message
|
|
ld c, (hl)
|
|
inc hl
|
|
ld b, (hl)
|
|
push bc
|
|
pop hl
|
|
ld a, (msg_frame_phys)
|
|
ld c, a
|
|
ld de, (msg_frame_phys+1)
|
|
ld ix, 0x0000
|
|
call mb_send
|
|
read_loop:
|
|
call yield
|
|
read_loop_yield_done:
|
|
ld hl, (mailbox_num)
|
|
call mb_read ; Read a message
|
|
read_mb_read_done:
|
|
ld a, b ; Loop if there is no message
|
|
cp 0
|
|
jp nz, read_loop
|
|
read_done:
|
|
ld hl, (msg_frame_ptr)
|
|
ret
|
|
|
|
.bss
|
|
mailbox_num: .ds.b 2
|
|
msg_frame_ptr: .ds.b 2
|
|
msg_frame_phys: .ds.b 3
|