os-z80/vfs.z80
2023-09-03 10:03:51 -05:00

221 lines
2.7 KiB
Z80 Assembly

.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
ld de, 1
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
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
ret
; 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
ld de, data_mount_offset
add hl, de
ld de, 0x9000
add hl, de
push hl
pop de
push de
ld hl, 0xB003
ld bc, 252
ldir
ld a, (mount_count)
inc a
ld (mount_count), a
; 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
ld iy, 0xB0FF
push bc
call strcmp
pop bc
cp 0
jp mount_loop1_done
add hl, de
djnz mount_loop1
mount_loop1_done:
ld de, 14
add hl, de
pop ix
ld de, 252
add ix, de
ld e, (hl)
inc hl
ld d, (hl)
ld (ix), e
ld (ix+1), d
push ix
ld a, 0x2
ld (0x8000), a
ld hl, 0xB0FF
ld de, 0x8001
ld bc, 256
ldir
ld a, (send_page_addr)
ld c, a
ld de, (send_page_addr+1)
ld ix, 0x0
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
ld a, (0x8000)
ld (ix+2), a
ld a, (0x8001)
ld (ix+3), a
ret
; 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
cp 0
ret z
jp nz, vfsstrcmp_loopend
inc ix
inc iy
jp vfsstrcmp_loop
vfsstrcmp_loopend:
ld a, (iy)
ld b, a
ld a, (ix)
sub b
ret
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