os-z80/vfs.z80

318 lines
4.5 KiB
Z80 Assembly
Raw Normal View History

2023-09-03 10:03:51 -05:00
.global _start
_start:
call get_free_frame
ld b, c
ld e, l
ld d, h
ld c, 0x9
call set_frame
call get_free_frame
ld a, c
ld (send_page_addr), a
ld (send_page_addr+1), hl
ld b, c
ld e, l
ld d, h
ld c, 0x8
call set_frame
ld hl, 0x9000
ld de, 0x9001
ld bc, 0x1000
ld (hl), 0x0
ldir
call get_free_mailbox
push hl
2023-09-17 11:02:33 -05:00
ld de, 2
2023-09-03 10:03:51 -05:00
call proc_map_set
pop hl
ld (vfs_mailbox_num), hl
call get_free_mailbox
ld (fs_mailbox_num), hl
msg_loop:
call yield
yield_back:
ld hl, (vfs_mailbox_num)
call mb_read
mb_read_done:
ld a, b
cp 1
jp z, msg_loop
msg_read:
push bc
push de
push hl
ld b, c
ld c, 0xB
call set_frame
set_frame_done:
ld hl, (0xB000) ; Load destination mailbox into HL and save it on the stack
push hl
ld hl, 0xB002
; Handling code goes here
ld a, (hl)
inc hl
cp 0x0
jp z, register_fs
cp 0x1
jp z, mount
2023-10-08 10:55:28 -05:00
cp 0x2
jp z, open
2023-09-03 10:03:51 -05:00
operation_done:
pop hl
pop ix
pop de
pop bc
call mb_send
jp msg_loop
register_fs:
ld a, (fs_count)
ld l, a
ld h, 0x0
add hl, hl
add hl, hl
add hl, hl
add hl, hl
ld de, data_fs_offset
add hl, de
ld de, 0x9000
add hl, de
push hl
pop de
ld hl, 0xB003
ld bc, 16
ldir
ld a, (fs_count)
inc a
ld (fs_count), a
2023-09-17 11:02:33 -05:00
jp operation_done
2023-09-03 10:03:51 -05:00
; String pointer 1 in IX, 2 in IY
; Return in A
strcmp:
strcmp_loop:
ld a, (iy)
ld b, a
ld a, (ix)
cp b
jp nz, strcmp_loopend
cp 0
ret z
inc ix
inc iy
jp strcmp_loop
strcmp_loopend:
ld a, (iy)
ld b, a
ld a, (ix)
sub b
ret
mount:
ld a, (mount_count)
ld l, 0x0
ld h, a
2023-11-05 10:34:11 -06:00
ld de, 0x9000 + data_mount_offset
2023-09-03 10:03:51 -05:00
add hl, de
push hl
pop de
push de
ld hl, 0xB003
2023-11-05 10:34:11 -06:00
ld bc, 0xFC
2023-09-03 10:03:51 -05:00
ldir
; FS type at 0xB1FF
ld a, (fs_count)
ld b, a
ld hl, data_fs_offset + 0x9000
ld de, 0x10
mount_loop1:
push hl
pop ix
2023-09-17 11:02:33 -05:00
ld iy, 0xB1FF
2023-09-03 10:03:51 -05:00
push bc
call strcmp
pop bc
cp 0
jp mount_loop1_done
add hl, de
djnz mount_loop1
mount_loop1_done:
2023-11-05 10:34:11 -06:00
; hl -> pointer to fs type info
; top of stack -> pointer to open mount info slot
2023-09-03 10:03:51 -05:00
ld de, 14
add hl, de
pop ix
2023-11-05 10:34:11 -06:00
; hl -> pointer to byte 15 of fs type info
; ix -> pointer to open mount info slot
ld de, 0xFD
2023-09-03 10:03:51 -05:00
add ix, de
2023-11-05 10:34:11 -06:00
; ix -> pointer to offset 0xFD of mount info
; fs info word starting at 0xE -> mount info word starting at 0xFD
2023-09-03 10:03:51 -05:00
ld e, (hl)
inc hl
ld d, (hl)
ld (ix), e
ld (ix+1), d
2023-10-08 10:55:28 -05:00
ld hl, (fs_mailbox_num)
ld (0x8000), hl
2023-09-03 10:03:51 -05:00
ld a, 0x2
2023-10-08 10:55:28 -05:00
ld (0x8002), a
2023-11-05 10:34:11 -06:00
push ix
2023-09-17 11:02:33 -05:00
push de
2023-09-03 10:03:51 -05:00
ld hl, 0xB0FF
2023-10-08 10:55:28 -05:00
ld de, 0x8003
2023-09-03 10:03:51 -05:00
ld bc, 256
ldir
ld a, (send_page_addr)
ld c, a
ld de, (send_page_addr+1)
ld ix, 0x0
2023-09-17 11:02:33 -05:00
pop hl
2023-09-03 10:03:51 -05:00
call mb_send
mount_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, mount_wait_loop
pop ix
2023-11-05 10:34:11 -06:00
; response byte 1 -> mount info byte at offset 0xFF
2023-09-03 10:03:51 -05:00
ld a, (0x8000)
ld (ix+2), a
2023-09-17 11:02:33 -05:00
ld a, (mount_count)
inc a
ld (mount_count), a
jp operation_done
2023-09-03 10:03:51 -05:00
; String pointer 1 in IX, 2 in IY
; Return in A
vfsstrcmp:
vfsstrcmp_loop:
ld a, (iy)
ld b, a
ld a, (ix)
cp b
2023-11-05 10:34:11 -06:00
jp nz, vfsstrcmp_loopend
2023-09-03 10:03:51 -05:00
cp 0
ret z
inc ix
inc iy
jp vfsstrcmp_loop
vfsstrcmp_loopend:
2023-11-05 10:34:11 -06:00
ld a, (ix)
cp 0
ret z
2023-09-03 10:03:51 -05:00
ld a, (iy)
ld b, a
ld a, (ix)
sub b
ret
2023-10-08 10:55:28 -05:00
open:
2023-11-05 10:34:11 -06:00
; 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
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 a, (0x8002)
cp 0
jp nz, mb_override
ld a, (0x8003)
cp 0
jp nz, mb_override
jp no_mb_override
mb_override:
ld hl, (0x8002)
no_mb_override:
2023-11-05 10:34:11 -06:00
ld (0xB002), hl
; word at 0x8000 -> 0xB000
ld a, (0x8000)
ld (0xB000), a
ld a, (0x8001)
ld (0xB001), a
2023-10-08 10:55:28 -05:00
jp operation_done
2023-09-03 10:03:51 -05:00
vfs_mailbox_num: .ds.b 2
fs_mailbox_num: .ds.b 2
send_page_addr: .ds.b 3
fs_count: .ds.b 1
mount_count: .ds.b 1
.equ data_fs_offset, 0x0
.equ data_mount_offset, 0x200
.equ fs_name_offset, 0x0
.equ fs_pid_offset, 0xE
.equ mount_path_offset, 0x0
.equ mount_fs_pid_offset, 0xFD
.equ mount_fs_id_offset, 0xFF