kernel + sh: Another stream overhaul

Certain streams can now be opened by name by prefixing the name
with a colon (':'). The only supported named stream at the moment
is :fb, which streams to/from the background framebuffer.

A new syscall called `get_size` was also added, which should be used
instead of `ryfs_get_size`. This new syscall supports getting the size
of streams.
This commit is contained in:
Ry 2023-03-30 22:16:31 -07:00
parent fa693c71a7
commit 8bea7c39b4
8 changed files with 145 additions and 20 deletions

View File

@ -63,7 +63,7 @@ shell_dir_command_loop:
cmp r0, 0
ifz jmp shell_dir_command_failed_to_open_file
mov r0, shell_dir_command_temp_file_struct
call ryfs_get_size
call get_size
call print_decimal_to_terminal
shell_dir_command_failed_to_open_file:
; new line

View File

@ -16,7 +16,7 @@ shell_type_command:
ifz jmp shell_type_command_file_not_found
mov r0, shell_type_command_file_struct
call ryfs_get_size
call get_size
mov r31, r0
shell_type_command_loop:
mov r0, 1

View File

@ -45,7 +45,7 @@ launch_fxf_name_loop_done:
; allocate memory for the binary
mov r0, launch_fxf_struct
call ryfs_get_size
call get_size
call allocate_memory
cmp r0, 0
ifz jmp allocate_error

View File

@ -42,6 +42,7 @@ seek: jmp [0x00000D14]
tell: jmp [0x00000D18]
read: jmp [0x00000D1C]
write: jmp [0x00000D20]
get_size: jmp [0x00000D24]
; widget jump table
draw_widgets_to_window: jmp [0x00000E10]

View File

@ -33,7 +33,7 @@ launch_fxf_from_disk:
; allocate memory for the binary
mov r0, launch_fxf_struct
call ryfs_get_size
call get_size
call allocate_memory
cmp r0, 0
ifz jmp launch_fxf_from_disk_allocate_error

View File

@ -65,6 +65,7 @@ jump_table:
data.32 tell
data.32 read
data.32 write
data.32 get_size
; widget jump table
org.pad 0x00000610
@ -204,7 +205,7 @@ load_startup_task:
; allocate memory for the startup file
mov r0, startup_file_struct
call ryfs_get_size
call get_size
call allocate_memory
cmp r0, 0
ifz jmp memory_error
@ -239,7 +240,7 @@ load_startup_task:
; we do this by checking to see if the size of startup.cfg is less than or equal to 12 * next_task_id bytes
inc.8 [next_task_id]
mov r0, startup_cfg_struct
call ryfs_get_size
call get_size
movz.8 r1, [next_task_id]
mul r1, 12
cmp r0, r1
@ -385,9 +386,9 @@ get_os_api_version:
#include "allocator.asm"
#include "fxf/fxf.asm"
#include "task.asm"
#include "vfs/vfs.asm"
#include "widget/widget.asm"
#include "window/window.asm"
#include "vfs.asm"
bottom_bar_str_0: data.strz "FOX"
bottom_bar_str_1: data.strz "32"

60
kernel/vfs/fb.asm Normal file
View File

@ -0,0 +1,60 @@
; framebuffer vfs stream routines
framebuffer_vfs_stream_name: data.strz "fb"
; open a framebuffer stream
; inputs:
; r2: file struct: pointer to a blank file struct (stream)
; outputs:
; r0: non-zero
open_stream_fb:
push r2
mov.8 [r2], 0 ; write file_reserved_1
inc r2
mov.16 [r2], 0 ; write file_reserved_2
add r2, 2
mov [r2], 0 ; write file_seek_offset
add r2, 4
mov.8 [r2], 1 ; write file_system_type
inc r2
mov [r2], fb_stream_read ; write file_read_call
add r2, 4
mov [r2], fb_stream_write ; write file_write_call
add r2, 4
mov [r2], 0x0012C000 ; write file_size
add r2, 4
mov [r2], 0 ; write file_reserved_3
add r2, 4
mov [r2], 0 ; write file_reserved_4
add r2, 4
mov [r2], 0 ; write file_reserved_5
pop r2
mov r0, 1
ret
; read a byte from the framebuffer
; inputs:
; r0: seek offset
; outputs:
; r0: byte
fb_stream_read:
add r0, 0x02000000
cmp r0, 0x0212C000
ifgteq mov r0, 0x0212BFFF
movz.8 r0, [r0]
ret
; write a byte to the framebuffer
; inputs:
; r0: pointer to source buffer
; r1: seek offset
; outputs:
; none
fb_stream_write:
add r1, 0x02000000
cmp r1, 0x0212C000
ifgteq mov r1, 0x0212BFFF
mov.8 [r1], [r0]
ret

View File

@ -5,6 +5,12 @@
; file_first_sector: 2 bytes
; file_seek_offset: 4 bytes
; file_system_type: 1 byte (0x00 for RYFS)
; file_reserved_1: 4 bytes
; file_reserved_2: 4 bytes
; file_reserved_3: 4 bytes
; file_reserved_4: 4 bytes
; file_reserved_5: 4 bytes
; file_reserved_6: 4 bytes
; file struct for stream:
; file_reserved_1: 1 byte
@ -13,19 +19,40 @@
; file_system_type: 1 byte (0x01 for stream)
; file_read_call: 4 bytes
; file_write_call: 4 bytes
; file_size: 4 bytes
; file_reserved_3: 4 bytes
; file_reserved_4: 4 bytes
; file_reserved_5: 4 bytes
; open a file from a RYFS-formatted disk
; open a file from a RYFS-formatted disk, or a named stream
; inputs:
; r0: pointer to file name string (8.3 format, for example "testfile.txt" or "test.txt")
; r1: disk ID
; r2: file struct: pointer to a blank file struct
; r0: pointer to file name string (8.3 format if file, for example "testfile.txt" or "test.txt")
; r1: disk ID (ignored if stream)
; r2: file struct: pointer to a blank file struct (8 bytes if file, 16 bytes if stream)
; outputs:
; r0: first file sector, or zero if file wasn't found
; r0: if file: first file sector, or zero if file wasn't found
; if stream: non-zero if stream opened, or zero if not
open:
cmp.8 [r0], ':'
ifz jmp open_stream
call convert_filename
cmp r0, 0
ifz ret
jmp ryfs_open
open_stream:
push r1
inc r0
; fb
mov r1, framebuffer_vfs_stream_name
call compare_string
ifz pop r1
ifz jmp open_stream_fb
pop r1
mov r0, 0
ret
; seek specified file to the specified offset
; inputs:
@ -44,13 +71,38 @@ seek:
tell:
jmp ryfs_tell
; get the exact size of the specified file
; inputs:
; r0: pointer to file struct
; outputs:
; r0: size in bytes
get_size:
push r1
push r0
add r0, 7
movz.8 r1, [r0]
pop r0
cmp.8 r1, 0x00
ifz pop r1
ifz jmp ryfs_get_size
cmp.8 r1, 0x01
ifz pop r1
ifz jmp stream_get_size
pop r1
ret
stream_get_size:
add r0, 16
mov r0, [r0]
ret
; read specified number of bytes into the specified buffer
; inputs:
; r0: number of bytes to read
; r1: pointer to file struct
; r2: pointer to destination buffer
; outputs:
; r0: number of bytes left to read (streams can read short)
; none
read:
push r3
push r1
@ -66,25 +118,26 @@ read:
pop r3
ret
stream_read:
push r0
push r1
push r2
stream_read_loop:
call stream_read_char
call yield_task
cmp.8 [r2], 0
ifz jmp stream_read_out
push r0
push r2
call yield_task
pop r2
pop r0
inc r2
dec r0
ifnz jmp stream_read_loop
stream_read_out:
pop r2
pop r1
pop r0
ret
stream_read_char:
push r0
push r1
@ -100,6 +153,10 @@ stream_read_char:
pop r2
mov.8 [r2], r0
; increment the seek offset
sub r1, 6
inc [r1]
pop r1
pop r0
ret
@ -138,7 +195,6 @@ stream_write_loop:
pop r2
pop r31
ret
stream_write_char:
push r0
push r1
@ -152,6 +208,10 @@ stream_write_char:
add r3, 10
call [r3]
; increment the seek offset
sub r3, 10
inc [r3]
pop r3
pop r1
pop r0
@ -239,3 +299,6 @@ convert_filename_fail:
pop r1
ret
convert_filename_output_string: data.fill 0, 12
; named streams
#include "vfs/fb.asm"