99 lines
1.3 KiB
Z80 Assembly
99 lines
1.3 KiB
Z80 Assembly
.global _start
|
|
|
|
_start:
|
|
call get_free_mailbox
|
|
ld (mailbox_num), hl
|
|
call get_free_frame ; Set up a frame for sending messages at 0x8000
|
|
ld a, c
|
|
ld (msg_phys_addr), a
|
|
ld (msg_phys_addr+1), hl
|
|
ld b, c
|
|
ld e, l
|
|
ld d, h
|
|
ld c, 8
|
|
call set_frame
|
|
setup_msg:
|
|
ld hl, (mailbox_num)
|
|
ld (0x8000), hl
|
|
ld a, 0x0 ; Register FS operation
|
|
ld (0x8002), a
|
|
ld a, 0x61 ; 'a'
|
|
ld (0x8003), a
|
|
ld a, 0x0 ; '\0'
|
|
ld (0x8004), a
|
|
ld (0x8011), hl
|
|
push de
|
|
push bc
|
|
ld de, 2 ; Get the mailbox number for the VFS
|
|
call proc_map_get
|
|
pmg_done:
|
|
pop bc
|
|
pop de
|
|
ld c, b ; Send the message
|
|
ld ix, 0x0000
|
|
call mb_send
|
|
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, loop
|
|
ld hl, (mailbox_num)
|
|
ld de, 3
|
|
call proc_map_set
|
|
msg_loop:
|
|
call yield
|
|
yield_back:
|
|
ld hl, (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, open
|
|
cp 0x1
|
|
jp z, read
|
|
cp 0x2
|
|
jp z, mount
|
|
operation_done:
|
|
pop hl
|
|
pop ix
|
|
pop de
|
|
pop bc
|
|
call mb_send
|
|
jp msg_loop
|
|
|
|
open:
|
|
jp z, operation_done
|
|
|
|
read:
|
|
jp z, operation_done
|
|
|
|
mount:
|
|
jp z, operation_done
|
|
|
|
|
|
|
|
|
|
|
|
mailbox_num: .ds.b 2
|
|
msg_phys_addr: .ds.b 2
|