os-z80/vfs.z80

228 lines
2.9 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
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
; 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:
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
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-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
ld a, (0x8000)
ld (ix+2), a
ld a, (0x8001)
ld (ix+3), 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
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
2023-10-08 10:55:28 -05:00
; TODO open
open:
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