2022-10-15 01:39:40 +02:00
|
|
|
; virtual filesystem routines
|
|
|
|
|
2023-07-14 01:05:17 +02:00
|
|
|
const TEMP_SECTOR_BUF: 0x01FFF808
|
|
|
|
|
2022-10-15 01:39:40 +02:00
|
|
|
; file struct for file:
|
|
|
|
; file_disk: 1 byte
|
|
|
|
; file_first_sector: 2 bytes
|
|
|
|
; file_seek_offset: 4 bytes
|
|
|
|
; file_system_type: 1 byte (0x00 for RYFS)
|
2023-03-31 07:16:31 +02:00
|
|
|
; 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
|
2022-10-15 01:39:40 +02:00
|
|
|
|
|
|
|
; file struct for stream:
|
|
|
|
; file_reserved_1: 1 byte
|
|
|
|
; file_reserved_2: 2 bytes
|
2023-03-31 03:14:16 +02:00
|
|
|
; file_seek_offset: 4 bytes
|
2022-10-15 01:39:40 +02:00
|
|
|
; file_system_type: 1 byte (0x01 for stream)
|
|
|
|
; file_read_call: 4 bytes
|
|
|
|
; file_write_call: 4 bytes
|
2023-03-31 07:16:31 +02:00
|
|
|
; file_size: 4 bytes
|
|
|
|
; file_reserved_3: 4 bytes
|
|
|
|
; file_reserved_4: 4 bytes
|
|
|
|
; file_reserved_5: 4 bytes
|
2022-10-15 01:39:40 +02:00
|
|
|
|
2023-03-31 07:16:31 +02:00
|
|
|
; open a file from a RYFS-formatted disk, or a named stream
|
2022-10-15 01:39:40 +02:00
|
|
|
; inputs:
|
2023-03-31 07:16:31 +02:00
|
|
|
; 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)
|
2022-10-15 01:39:40 +02:00
|
|
|
; outputs:
|
2023-03-31 07:16:31 +02:00
|
|
|
; r0: if file: first file sector, or zero if file wasn't found
|
|
|
|
; if stream: non-zero if stream opened, or zero if not
|
2022-10-15 01:39:40 +02:00
|
|
|
open:
|
2023-03-31 07:16:31 +02:00
|
|
|
cmp.8 [r0], ':'
|
|
|
|
ifz jmp open_stream
|
2023-03-16 01:53:45 +01:00
|
|
|
call convert_filename
|
|
|
|
cmp r0, 0
|
|
|
|
ifz ret
|
2022-10-15 01:39:40 +02:00
|
|
|
jmp ryfs_open
|
2023-03-31 07:16:31 +02:00
|
|
|
open_stream:
|
|
|
|
push r1
|
|
|
|
|
|
|
|
inc r0
|
|
|
|
|
2023-07-14 01:05:17 +02:00
|
|
|
; disk0
|
|
|
|
mov r1, disk0_vfs_stream_name
|
|
|
|
call compare_string
|
|
|
|
ifz pop r1
|
|
|
|
ifz jmp open_stream_disk0
|
|
|
|
|
|
|
|
; disk1
|
|
|
|
mov r1, disk1_vfs_stream_name
|
|
|
|
call compare_string
|
|
|
|
ifz pop r1
|
|
|
|
ifz jmp open_stream_disk1
|
|
|
|
|
|
|
|
; disk2
|
|
|
|
mov r1, disk2_vfs_stream_name
|
|
|
|
call compare_string
|
|
|
|
ifz pop r1
|
|
|
|
ifz jmp open_stream_disk2
|
|
|
|
|
|
|
|
; disk3
|
|
|
|
mov r1, disk3_vfs_stream_name
|
|
|
|
call compare_string
|
|
|
|
ifz pop r1
|
|
|
|
ifz jmp open_stream_disk3
|
|
|
|
|
2023-03-31 07:16:31 +02:00
|
|
|
; fb
|
|
|
|
mov r1, framebuffer_vfs_stream_name
|
|
|
|
call compare_string
|
|
|
|
ifz pop r1
|
|
|
|
ifz jmp open_stream_fb
|
|
|
|
|
2023-07-14 01:05:17 +02:00
|
|
|
; ofb0 - ofb31
|
|
|
|
push r2
|
|
|
|
mov r1, overlay_vfs_stream_name
|
|
|
|
mov r2, 3
|
|
|
|
call compare_memory_bytes
|
|
|
|
pop r2
|
|
|
|
ifz pop r1
|
|
|
|
ifz jmp open_stream_ofb
|
|
|
|
|
|
|
|
; romdisk
|
|
|
|
mov r1, romdisk_vfs_stream_name
|
|
|
|
call compare_string
|
|
|
|
ifz pop r1
|
|
|
|
ifz jmp open_stream_romdisk
|
|
|
|
|
2023-04-02 22:08:55 +02:00
|
|
|
; serial
|
|
|
|
mov r1, serial_vfs_stream_name
|
|
|
|
call compare_string
|
|
|
|
ifz pop r1
|
|
|
|
ifz jmp open_stream_serial
|
|
|
|
|
2023-03-31 07:16:31 +02:00
|
|
|
pop r1
|
|
|
|
mov r0, 0
|
|
|
|
ret
|
2022-10-15 01:39:40 +02:00
|
|
|
|
|
|
|
; seek specified file to the specified offset
|
|
|
|
; inputs:
|
|
|
|
; r0: byte offset
|
|
|
|
; r1: pointer to file struct
|
|
|
|
; outputs:
|
|
|
|
; none
|
|
|
|
seek:
|
2023-03-31 03:14:16 +02:00
|
|
|
jmp ryfs_seek
|
2022-10-15 01:39:40 +02:00
|
|
|
|
|
|
|
; get the seek offset of the specified file
|
|
|
|
; inputs:
|
|
|
|
; r0: pointer to file struct
|
|
|
|
; outputs:
|
|
|
|
; r0: byte offset
|
|
|
|
tell:
|
2023-03-31 03:14:16 +02:00
|
|
|
jmp ryfs_tell
|
2022-10-15 01:39:40 +02:00
|
|
|
|
2023-03-31 07:16:31 +02:00
|
|
|
; 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
|
|
|
|
|
2022-10-15 01:39:40 +02:00
|
|
|
; read specified number of bytes into the specified buffer
|
|
|
|
; inputs:
|
2023-01-30 21:28:33 +01:00
|
|
|
; r0: number of bytes to read
|
2022-10-15 01:39:40 +02:00
|
|
|
; r1: pointer to file struct
|
2023-01-30 21:28:33 +01:00
|
|
|
; r2: pointer to destination buffer
|
2022-10-15 01:39:40 +02:00
|
|
|
; outputs:
|
2023-03-31 07:16:31 +02:00
|
|
|
; none
|
2022-10-15 01:39:40 +02:00
|
|
|
read:
|
2023-09-14 23:58:10 +02:00
|
|
|
cmp r0, 0
|
|
|
|
ifz ret
|
|
|
|
cmp r1, 0
|
|
|
|
ifz ret
|
|
|
|
cmp r2, 0
|
|
|
|
ifz ret
|
2022-10-15 01:39:40 +02:00
|
|
|
push r3
|
|
|
|
push r1
|
|
|
|
add r1, 7
|
|
|
|
movz.8 r3, [r1]
|
|
|
|
pop r1
|
|
|
|
cmp.8 r3, 0x00
|
|
|
|
ifz pop r3
|
|
|
|
ifz jmp ryfs_read
|
|
|
|
cmp.8 r3, 0x01
|
|
|
|
ifz pop r3
|
|
|
|
ifz jmp stream_read
|
|
|
|
pop r3
|
|
|
|
ret
|
|
|
|
stream_read:
|
2023-03-31 07:16:31 +02:00
|
|
|
push r0
|
2023-01-30 21:28:33 +01:00
|
|
|
push r1
|
|
|
|
push r2
|
|
|
|
stream_read_loop:
|
|
|
|
call stream_read_char
|
|
|
|
|
2023-07-14 01:05:17 +02:00
|
|
|
call save_state_and_yield_task
|
2023-01-30 21:28:33 +01:00
|
|
|
|
|
|
|
inc r2
|
|
|
|
dec r0
|
|
|
|
ifnz jmp stream_read_loop
|
|
|
|
|
|
|
|
pop r2
|
|
|
|
pop r1
|
2023-03-31 07:16:31 +02:00
|
|
|
pop r0
|
2023-01-30 21:28:33 +01:00
|
|
|
ret
|
|
|
|
stream_read_char:
|
2022-10-15 01:39:40 +02:00
|
|
|
push r0
|
|
|
|
push r1
|
|
|
|
push r2
|
|
|
|
|
2023-03-31 03:14:16 +02:00
|
|
|
; call [file_read_call] with seek offset in r0
|
2023-07-14 01:05:17 +02:00
|
|
|
add r1, 3
|
2023-03-31 03:14:16 +02:00
|
|
|
mov r0, [r1]
|
2023-07-14 01:05:17 +02:00
|
|
|
add r1, 5
|
2022-10-15 01:39:40 +02:00
|
|
|
call [r1]
|
|
|
|
|
|
|
|
; put the result into [r2]
|
|
|
|
pop r2
|
2023-01-30 21:28:33 +01:00
|
|
|
mov.8 [r2], r0
|
2022-10-15 01:39:40 +02:00
|
|
|
|
2023-03-31 07:16:31 +02:00
|
|
|
; increment the seek offset
|
2023-07-14 01:05:17 +02:00
|
|
|
sub r1, 5
|
2023-03-31 07:16:31 +02:00
|
|
|
inc [r1]
|
|
|
|
|
2022-10-15 01:39:40 +02:00
|
|
|
pop r1
|
|
|
|
pop r0
|
|
|
|
ret
|
|
|
|
|
|
|
|
; write specified number of bytes into the specified file
|
|
|
|
; inputs:
|
2023-01-30 20:42:21 +01:00
|
|
|
; r0: number of bytes to write
|
2022-10-15 01:39:40 +02:00
|
|
|
; r1: pointer to file struct
|
2023-02-09 01:05:08 +01:00
|
|
|
; r2: pointer to source buffer
|
2022-10-15 01:39:40 +02:00
|
|
|
; outputs:
|
|
|
|
; none
|
|
|
|
write:
|
2023-09-14 23:58:10 +02:00
|
|
|
cmp r0, 0
|
|
|
|
ifz ret
|
|
|
|
cmp r1, 0
|
|
|
|
ifz ret
|
2022-10-15 01:39:40 +02:00
|
|
|
push r3
|
|
|
|
push r1
|
|
|
|
add r1, 7
|
|
|
|
movz.8 r3, [r1]
|
|
|
|
pop r1
|
|
|
|
cmp.8 r3, 0x00
|
|
|
|
ifz pop r3
|
2023-01-21 03:53:16 +01:00
|
|
|
ifz jmp ryfs_write
|
2022-10-15 01:39:40 +02:00
|
|
|
cmp.8 r3, 0x01
|
|
|
|
ifz pop r3
|
|
|
|
ifz jmp stream_write
|
|
|
|
pop r3
|
|
|
|
ret
|
|
|
|
stream_write:
|
2023-01-30 20:42:21 +01:00
|
|
|
push r31
|
|
|
|
push r2
|
|
|
|
|
|
|
|
mov r31, r0 ; number of bytes to write = loop count
|
|
|
|
stream_write_loop:
|
|
|
|
call stream_write_char
|
|
|
|
inc r2
|
|
|
|
loop stream_write_loop
|
|
|
|
|
|
|
|
pop r2
|
|
|
|
pop r31
|
|
|
|
ret
|
|
|
|
stream_write_char:
|
2022-10-15 01:39:40 +02:00
|
|
|
push r0
|
|
|
|
push r1
|
2023-03-31 03:14:16 +02:00
|
|
|
push r3
|
2022-10-15 01:39:40 +02:00
|
|
|
|
2023-03-31 03:14:16 +02:00
|
|
|
; call [file_write_call] with pointer to src buf in r0 and seek offset in r1
|
|
|
|
mov r3, r1
|
2023-07-14 01:05:17 +02:00
|
|
|
add r3, 3
|
2022-10-15 01:39:40 +02:00
|
|
|
mov r0, r2
|
2023-03-31 03:14:16 +02:00
|
|
|
mov r1, [r3]
|
2023-07-14 01:05:17 +02:00
|
|
|
add r3, 9
|
2023-03-31 03:14:16 +02:00
|
|
|
call [r3]
|
2022-10-15 01:39:40 +02:00
|
|
|
|
2023-03-31 07:16:31 +02:00
|
|
|
; increment the seek offset
|
2023-07-14 01:05:17 +02:00
|
|
|
sub r3, 9
|
2023-03-31 07:16:31 +02:00
|
|
|
inc [r3]
|
|
|
|
|
2023-03-31 03:14:16 +02:00
|
|
|
pop r3
|
2022-10-15 01:39:40 +02:00
|
|
|
pop r1
|
|
|
|
pop r0
|
|
|
|
ret
|
2023-03-16 01:53:45 +01:00
|
|
|
|
|
|
|
; convert a user-friendly filename (test.txt) to the internal representation (test txt)
|
|
|
|
; inputs:
|
|
|
|
; r0: pointer to null-terminated input string
|
|
|
|
; outputs:
|
|
|
|
; r0: pointer to null-terminated output string, or zero if failure
|
|
|
|
convert_filename:
|
|
|
|
push r1
|
|
|
|
push r2
|
|
|
|
push r3
|
|
|
|
push r31
|
|
|
|
|
|
|
|
; check the length of the filename to ensure it isn't too long
|
|
|
|
mov r1, r0
|
|
|
|
call string_length
|
|
|
|
cmp r0, 12
|
|
|
|
ifgt jmp convert_filename_fail
|
|
|
|
cmp r0, 0
|
|
|
|
ifz jmp convert_filename_fail
|
|
|
|
|
|
|
|
; fill the output string buffer with spaces and a null-terminator
|
|
|
|
mov r2, convert_filename_output_string
|
|
|
|
mov r31, 11
|
|
|
|
convert_filename_space_loop:
|
|
|
|
mov.8 [r2], ' '
|
|
|
|
inc r2
|
|
|
|
loop convert_filename_space_loop
|
|
|
|
mov.8 [r2], 0
|
|
|
|
|
|
|
|
mov r2, convert_filename_output_string
|
|
|
|
mov r3, 0
|
|
|
|
|
|
|
|
; r0: input filename length
|
|
|
|
; r1: pointer to input filename
|
|
|
|
; r2: pointer to output filename
|
|
|
|
; r3: number of characters processed
|
|
|
|
convert_filename_copy_loop:
|
|
|
|
cmp.8 [r1], '.'
|
|
|
|
ifz jmp convert_filename_found_ext
|
|
|
|
mov.8 [r2], [r1]
|
|
|
|
inc r1
|
|
|
|
inc r2
|
|
|
|
inc r3
|
|
|
|
cmp r3, r0
|
|
|
|
ifz jmp convert_filename_done
|
|
|
|
iflt jmp convert_filename_copy_loop
|
|
|
|
convert_filename_found_ext:
|
|
|
|
cmp r3, 0
|
|
|
|
ifz jmp convert_filename_fail
|
|
|
|
cmp r3, 8
|
|
|
|
ifgt jmp convert_filename_fail
|
|
|
|
|
|
|
|
mov r2, convert_filename_output_string
|
|
|
|
add r2, 8
|
|
|
|
inc r1
|
|
|
|
cmp.8 [r1], 0
|
|
|
|
ifz jmp convert_filename_fail
|
|
|
|
mov.8 [r2], [r1]
|
|
|
|
inc r1
|
|
|
|
inc r2
|
|
|
|
cmp.8 [r1], 0
|
|
|
|
ifz jmp convert_filename_done
|
|
|
|
mov.8 [r2], [r1]
|
|
|
|
inc r1
|
|
|
|
inc r2
|
|
|
|
cmp.8 [r1], 0
|
|
|
|
ifz jmp convert_filename_done
|
|
|
|
mov.8 [r2], [r1]
|
|
|
|
convert_filename_done:
|
|
|
|
mov r0, convert_filename_output_string
|
|
|
|
pop r31
|
|
|
|
pop r3
|
|
|
|
pop r2
|
|
|
|
pop r1
|
|
|
|
ret
|
|
|
|
convert_filename_fail:
|
|
|
|
mov r0, 0
|
|
|
|
pop r31
|
|
|
|
pop r3
|
|
|
|
pop r2
|
|
|
|
pop r1
|
|
|
|
ret
|
|
|
|
convert_filename_output_string: data.fill 0, 12
|
2023-03-31 07:16:31 +02:00
|
|
|
|
|
|
|
; named streams
|
2023-07-14 01:05:17 +02:00
|
|
|
#include "vfs/disk0.asm"
|
|
|
|
#include "vfs/disk1.asm"
|
|
|
|
#include "vfs/disk2.asm"
|
|
|
|
#include "vfs/disk3.asm"
|
2023-03-31 07:16:31 +02:00
|
|
|
#include "vfs/fb.asm"
|
2023-07-14 01:05:17 +02:00
|
|
|
#include "vfs/ofb.asm"
|
|
|
|
#include "vfs/romdisk.asm"
|
2023-04-02 22:08:55 +02:00
|
|
|
#include "vfs/serial.asm"
|