Skip to content

Commit

Permalink
Add ramdisk as disk 5, and a ryfs_format routine
Browse files Browse the repository at this point in the history
  • Loading branch information
ry755 committed May 5, 2024
1 parent 207c450 commit 895e240
Show file tree
Hide file tree
Showing 5 changed files with 148 additions and 0 deletions.
6 changes: 6 additions & 0 deletions RYFS.asm
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ check_disk:
ifnz jmp check_disk_fail
cmp r0, 4
ifz jmp check_disk_continue
cmp r0, 5
ifnz jmp check_disk_1
ifz call is_ramdisk_formatted
ifnz jmp check_disk_fail
cmp r0, 5
ifz jmp check_disk_continue
check_disk_1:
or r0, 0x80001000
in r0, r0
Expand Down
56 changes: 56 additions & 0 deletions RYFS.okm
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ MODULE RYFS;
EXTERN PROCEDURE read_sector: INT;
EXTERN PROCEDURE write_sector: INT;
EXTERN PROCEDURE copy_memory_bytes: INT;
EXTERN PROCEDURE copy_string: INT;
EXTERN PROCEDURE compare_memory_bytes_wrapper: INT;
EXTERN PROCEDURE brk: INT;

Expand Down Expand Up @@ -178,6 +179,61 @@ MODULE RYFS;
END;
END;

PROCEDURE ryfs_format(diskId: INT; diskSizeInSectors: INT;);
VAR i: INT;
bitmapSectors: CHAR;
BEGIN
(* clear the sector data *)
i := 0;
WHILE i <| 512 DO
PUTCHAR(PTROF(TEMP_SECTOR_BUF) + i, 0);
i := i + 1;
END;

(* write the number of bitmap sectors *)
bitmapSectors := ryfs_ceil(diskSizeInSectors, 4096) /| 4096;
PUTCHAR(PTROF(TEMP_SECTOR_BUF), bitmapSectors);

(* write version number and magic bytes *)
PUTCHAR(PTROF(TEMP_SECTOR_BUF) + 1, 1);
PUTCHAR(PTROF(TEMP_SECTOR_BUF) + 2, 82);
PUTCHAR(PTROF(TEMP_SECTOR_BUF) + 3, 89);

(* write disk size *)
PUTSHORT(PTROF(TEMP_SECTOR_BUF) + 4, diskSizeInSectors);

(* write directory label *)
copy_string("ramdisk", PTROF(TEMP_SECTOR_BUF) + 6);

(* write the directory sector out to disk *)
write_sector(1, diskId, PTROF(TEMP_SECTOR_BUF));

(* clear the sector data *)
i := 0;
WHILE i <| 512 DO
PUTCHAR(PTROF(TEMP_SECTOR_BUF) + i, 0);
i := i + 1;
END;

(* zero the bitmap sectors *)
i := 0;
WHILE i <| bitmapSectors DO
write_sector(i + 2, diskId, PTROF(TEMP_SECTOR_BUF));
i := i + 1;
END;

(* mark the boot sector and directory sector as used *)
ryfs_mark_used(0, diskId);
ryfs_mark_used(1, diskId);

(* mark the bitmap sectors as used *)
i := 0;
WHILE i <| bitmapSectors DO
ryfs_mark_used(i + 2, diskId);
i := i + 1;
END;
END;

PROCEDURE ryfs_seek(offset: INT; struct: POINTER TO ROMFile;);
BEGIN
struct^.seekOffset := offset;
Expand Down
77 changes: 77 additions & 0 deletions disk.asm
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
; disk routines

const TEMP_SECTOR_BUF: 0x01FFF808
const RAMDISK_START: 0x03800000

; read a sector into the specified memory buffer
; inputs:
Expand All @@ -12,6 +13,8 @@ const TEMP_SECTOR_BUF: 0x01FFF808
read_sector:
cmp.8 r1, 4
ifz jmp read_romdisk_sector
cmp.8 r1, 5
ifz jmp read_ramdisk_sector

push r3
push r4
Expand Down Expand Up @@ -54,6 +57,34 @@ read_romdisk_sector:
pop r0
ret

; read a sector from the ramdisk into the specified memory buffer
; inputs:
; r0: sector number
; r2: sector buffer (512 bytes)
; outputs:
; none
read_ramdisk_sector:
push r0
push r1
push r2

; source pointer
mul r0, 512
add r0, RAMDISK_START

; destination pointer
mov r1, r2

; copy 512 bytes
mov r2, 512

call copy_memory_bytes

pop r2
pop r1
pop r0
ret

; check if a RYFS image is included as a romdisk
; inputs:
; none
Expand All @@ -69,6 +100,21 @@ is_romdisk_available:
pop r0
ret

; check if a RYFS filesystem is initialized on the ramdisk
; inputs:
; none
; outputs:
; Z flag: set if available, reset if not
is_ramdisk_formatted:
push r0

mov r0, RAMDISK_START
add r0, 514
cmp.16 [r0], 0x5952

pop r0
ret

; write a sector from the specified memory buffer
; inputs:
; r0: sector number
Expand All @@ -79,6 +125,8 @@ is_romdisk_available:
write_sector:
cmp.8 r1, 4
ifz ret
cmp.8 r1, 5
ifz jmp write_ramdisk_sector

push r3
push r4
Expand All @@ -92,3 +140,32 @@ write_sector:
pop r4
pop r3
ret

; write a sector to ramdisk from the specified memory buffer
; inputs:
; r0: sector number
; r2: sector buffer (512 bytes)
; outputs:
; none
write_ramdisk_sector:
push r0
push r1
push r2

; destination pointer
mov r1, r0
mul r1, 512
add r1, RAMDISK_START

; source pointer
mov r0, r2

; copy 512 bytes
mov r2, 512

call copy_memory_bytes

pop r2
pop r1
pop r0
ret
2 changes: 2 additions & 0 deletions fox32rom.def
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ ryfs_write: jmp [0xF0045024]
is_romdisk_available: jmp [0xF0045028]
ryfs_create: jmp [0xF004502C]
ryfs_delete: jmp [0xF0045030]
ryfs_format: jmp [0xF0045034]
is_ramdisk_formatted: jmp [0xF0045038]

; memory copy/compare jump table
copy_memory_bytes: jmp [0xF0046000]
Expand Down
7 changes: 7 additions & 0 deletions main.asm
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ draw_bottom_bar_loop:
call change_icon
call setup_icon

call is_ramdisk_formatted
ifnz mov r0, 5
ifnz mov r1, 0x00800000
ifnz call ryfs_format

event_loop:
call get_next_event

Expand Down Expand Up @@ -293,6 +298,8 @@ disk_icon_q:
data.32 is_romdisk_available
data.32 ryfs_create
data.32 ryfs_delete
data.32 ryfs_format
data.32 is_ramdisk_formatted

; memory copy/compare jump table
org.pad 0xF0046000
Expand Down

0 comments on commit 895e240

Please sign in to comment.