Browse Source

core: add BFile syscalls

pull/1/head
lephe 3 months ago
parent
commit
eece35566e
2 changed files with 140 additions and 2 deletions
  1. 81
    0
      include/gint/bfile.h
  2. 59
    2
      src/core/syscalls.S

+ 81
- 0
include/gint/bfile.h View File

@@ -0,0 +1,81 @@
//---
// gint:bfile - BFile interface
//
// The system's file system is a nightmare and the risk of corrupting it
// or the flash by driving it manually is too great to risk. This module
// interfaces with the BFile syscalls for file management.
//---

#ifndef GINT_BFILE
#define GINT_BFILE

#include <stdint.h>

/* BFile_Remove(): Remove a file
Also works if the file does not exist.

@file FONTCHARACTER file path
Returns a BFile error code. */
int BFile_Remove(uint16_t const *file);

/* BFile_Create(): Create a new entry
The file or directory must not exist. For a file the size pointer must point
to the desired file size (which is fixed), for a folder it is ignored.

@file FONTCHARACTER file path
@type Entry type
@size Pointer to file size if [type = BFile_File], ignored otherwise
Returns a BFile error code. */
enum BFile_EntryType
{
BFile_File = 1,
BFile_Folder = 5,
};
int BFile_Create(uint16_t const *file, enum BFile_EntryType type, int *size);

/* BFile_Open(): Open an existing file
The file must exist.

@file FONTCHARACTER file path
@mode Desired access mode
Returns a file descriptor on success, or a negative BFile error code. */
enum BFile_OpenMode
{
BFile_ReadOnly = 0x01,
BFile_WriteOnly = 0x02,
BFile_ReadWrite = BFile_ReadOnly | BFile_WriteOnly,
};
int BFile_Open(uint16_t const *file, enum BFile_OpenMode mode);

/* BFile_Close(): Close a file descriptor
@fd Open file descriptor
Returns a BFile error code. */
int BFile_Close(int fd);

/* BFile_Write(): Write data to an open file
Second and third argument specify the data and length to write.

WARNING: The file systems has shown to become inconsistent if an odd number
of bytes is written with BFile_Write(). Keep it even!

@fd File descriptor open for writing
@data Data to write
@even_size Size to write (must be even, yes)
Returns a BFile error code. */
int BFile_Write(int fd, void const *data, int even_size);

/* BFile_Read(): Read data from an open file
The second and third argument specify where to store and how much to read.
The location from where the data is read depends on [whence]:

* If [whence >= 0], it is taken as an absolute location within the file;
* If [whence == -1], BFile_Read() reads from the current position.

@fd File descriptor open for reading
@data Buffer of at least [size] bytes to store data to
@size Number of bytes to read
@whence Starting position of the data to read in the file
Returns a BFile error code. */
int BFile_Read(int handle, void *data, int size, int whence);

#endif /* GINT_BFILE */

+ 59
- 2
src/core/syscalls.S View File

@@ -1,9 +1,9 @@
/*
** gint:core:syscalls - calls to CASIOWIN
**
** This files can be seen as a list of everywhere gint relies on the
** This file can be seen as a list of everywhere gint relies on the
** underlying OS. Although I wish to make gint free-standing, there are
** still a few hard dependencies, namely:
** still a few hard questions, namely:
** * MMU management, because doing it wrong might break the calculator.
** * Dynamic allocation, because we can't trash the system heap.
** * File system, because it's a mess and we might ruin the ROM.
@@ -16,6 +16,13 @@
.global ___realloc
/* OS version, for debugging purposes */
.global ___os_version
/* Bfile calls */
.global _BFile_Remove
.global _BFile_Create
.global _BFile_Open
.global _BFile_Close
.global _BFile_Write
.global _BFile_Read

.section ".pretext"

@@ -30,6 +37,56 @@ ___os_version:
nop
1: .long 0x02ee

/* BFile driver */

# int BFile_Remove(const uint16_t *file)
_BFile_Remove:
mov.l 1f, r0
mov.l syscall_table, r1
jmp @r1
mov #0, r5
1: .long 0x0439

# int BFile_Create(uint16_t *file, enum { file = 1, folder = 5 }, int *size)
_BFile_Create:
mov.l 1f, r0
mov.l syscall_table, r1
jmp @r1
nop
1: .long 0x0434

# int BFile_Open(const uint16_t *file, int mode)
_BFile_Open:
mov.l 1f, r0
mov.l syscall_table, r1
jmp @r1
mov #0, r6
1: .long 0x042c

# int BFile_Close(int handle)
_BFile_Close:
mov.l 1f, r0
mov.l syscall_table, r1
jmp @r1
nop
1: .long 0x042d

# int BFile_Write(int handle, const void *ram_buffer, int even_size)
_BFile_Write:
mov.l 1f, r0
mov.l syscall_table, r1
jmp @r1
nop
1: .long 0x0435

# int BFile_Read(int handle, void *ram_buffer, int size, int whence)
_BFile_Read:
mov.l 1f, r0
mov.l syscall_table, r1
jmp @r1
nop
1: .long 0x0432

syscall_table:
.long 0x80010070


Loading…
Cancel
Save