Skip to content

Commit

Permalink
File deletion support, and bump API version
Browse files Browse the repository at this point in the history
  • Loading branch information
ry755 committed May 4, 2024
1 parent 5d23f73 commit 3763406
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
48 changes: 47 additions & 1 deletion RYFS.okm
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ MODULE RYFS;
BEGIN
i := ryfs_open(fileName, diskId, struct);
IF i # 0 THEN
RETURN(i);
ryfs_delete(struct);
END;

firstFreeEntry := ryfs_find_free_entry(diskId);
Expand Down Expand Up @@ -129,6 +129,52 @@ MODULE RYFS;
RETURN(ryfs_open(fileName, diskId, struct));
END;

PROCEDURE ryfs_delete(struct: POINTER TO ROMFile;);
VAR i: INT;
j: INT;
sector: SHORT;
nextSector: SHORT;
sizeInSectors: SHORT;
BEGIN
(* read the directory sector from disk *)
read_sector(1, struct^.diskId, PTROF(TEMP_SECTOR_BUF));

(* reverse-find the directory sector entry from the passed struct *)
i := 1;
WHILE i <| 32 DO
IF GETSHORT(PTROF(TEMP_SECTOR_BUF) + (i * 16)) = struct^.firstSector THEN
(* we found it!! *)
sector := GETSHORT(PTROF(TEMP_SECTOR_BUF) + (i * 16));
sizeInSectors := GETSHORT(PTROF(TEMP_SECTOR_BUF) + (i * 16) + 2);
BREAK();
END;
i := i + 1;
END;

(* clear directory entry *)
j := 0;
WHILE j <| 16 DO
PUTCHAR(PTROF(TEMP_SECTOR_BUF) + (i * 16) + j, 0);
j := j + 1;
END;
write_sector(1, struct^.diskId, PTROF(TEMP_SECTOR_BUF));

i := 0;
WHILE i <| sizeInSectors DO
read_sector(sector, struct^.diskId, PTROF(TEMP_SECTOR_BUF));
nextSector := GETSHORT(PTROF(TEMP_SECTOR_BUF) + 2);
ryfs_mark_free(sector);
j := 0;
WHILE j <| 512 DO
PUTCHAR(PTROF(TEMP_SECTOR_BUF) + j, 0);
j := j + 1;
END;
write_sector(sector, struct^.diskId, PTROF(TEMP_SECTOR_BUF));
sector := nextSector;
i := i + 1;
END;
END;

PROCEDURE ryfs_seek(offset: INT; struct: POINTER TO ROMFile;);
BEGIN
struct^.seekOffset := offset;
Expand Down
1 change: 1 addition & 0 deletions fox32rom.def
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ ryfs_tell: jmp [0xF0045020]
ryfs_write: jmp [0xF0045024]
is_romdisk_available: jmp [0xF0045028]
ryfs_create: jmp [0xF004502C]
ryfs_delete: jmp [0xF0045030]

; memory copy/compare jump table
copy_memory_bytes: jmp [0xF0046000]
Expand Down
3 changes: 2 additions & 1 deletion main.asm
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const FOX32ROM_VERSION_MAJOR: 0
const FOX32ROM_VERSION_MINOR: 7
const FOX32ROM_VERSION_PATCH: 0

const FOX32ROM_API_VERSION: 1
const FOX32ROM_API_VERSION: 2

const SYSTEM_STACK: 0x01FFF800
const BACKGROUND_COLOR: 0xFF674764
Expand Down Expand Up @@ -292,6 +292,7 @@ disk_icon_q:
data.32 ryfs_write
data.32 is_romdisk_available
data.32 ryfs_create
data.32 ryfs_delete

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

0 comments on commit 3763406

Please sign in to comment.