Add ryfs_get_size

This commit is contained in:
Ry 2022-06-23 14:15:52 -07:00
parent e158dd3bc5
commit ad0571d420
3 changed files with 52 additions and 0 deletions

View File

@ -61,6 +61,7 @@ ryfs_open: jmp [0xF0045008]
ryfs_seek: jmp [0xF004500C]
ryfs_read: jmp [0xF0045010]
ryfs_read_whole_file: jmp [0xF0045014]
ryfs_get_size: jmp [0xF0045018]
; memory copy/compare jump table
copy_memory_bytes: jmp [0xF0046000]

View File

@ -208,6 +208,7 @@ get_rom_version:
data.32 ryfs_seek
data.32 ryfs_read
data.32 ryfs_read_whole_file
data.32 ryfs_get_size
; memory copy/compare jump table
org.pad 0xF0046000

View File

@ -267,3 +267,53 @@ ryfs_read_whole_file_last_sector:
pop r1
pop r0
ret
; get the exact size of a file
; inputs:
; r0: pointer to file struct
; outputs:
; r0: file size in bytes
ryfs_get_size:
push r1
push r2
push r10
push r11
mov r10, r0
mov r11, 0 ; byte counter
; read the first sector into the temp buffer
movz.8 r1, [r0] ; file_disk
inc r0
movz.16 r0, [r0] ; file_first_sector
ryfs_get_size_sector_loop:
mov r2, TEMP_SECTOR_BUF
call read_sector
; check to see if this is the last sector
; if this is the last sector, read the sector size field in the header
mov r0, TEMP_SECTOR_BUF
add r0, 2
cmp.16 [r0], 0
ifz jmp ryfs_get_size_last_sector
; there are more sectors left, load them
movz.16 r0, [r0] ; sector number
mov r1, [r10] ; file_disk
add r11, 506
jmp ryfs_get_size_sector_loop
ryfs_get_size_last_sector:
; this is the last sector, read the header to get the reamining number of bytes
mov r0, TEMP_SECTOR_BUF
add r0, 4
movz.16 r0, [r0]
add r11, r0
; return final size
mov r0, r11
pop r11
pop r10
pop r2
pop r1
ret