Jo Engine 2026.11.1
Jo Sega Saturn Engine
Loading...
Searching...
No Matches
fs.h File Reference

Jo Engine File System function prototypes. More...

Go to the source code of this file.

Macros

#define JO_ROOT_DIR
 Specify the root directory (on the CD) for jo_fs_read_file(), jo_map_load_from_file(), etc.
#define JO_CURRENT_DIR
 Specify the current directory (on the CD) for jo_fs_read_file(), jo_map_load_from_file(), etc.
#define JO_PARENT_DIR
 Specify the parent directory for jo_fs_read_file(), jo_map_load_from_file(), etc.
#define JO_CD_DRIVE_PAUSE
 Drive status: the drive is paused.
#define JO_CD_DRIVE_PLAY
 Drive status: the drive is playing (audio or data).

Typedefs

typedef void(*) jo_fs_async_read_callback(char *contents, int length, int optional_token)
 Function prototype for ().

Functions

void jo_fs_cd (const char *const sub_dir)
 Change the current directory (equivalent of Unix cd command).
char * jo_fs_read_file_in_dir (const char *const filename, const char *const sub_dir, int *len)
 Read a file on the CD.
char * jo_fs_read_file_ptr (const char *const filename, void *buf, int *len)
 Read a file on the CD and put the contents to "buf".
void jo_fs_get_read_stats (unsigned int *const vblanks, unsigned int *const bytes, unsigned int *const files, const bool reset)
 Statistics of the files read by jo_fs_read_file_ptr() (the time of a loading: the CD or the CPU).
static __jo_force_inline char * jo_fs_read_file (const char *const filename, int *len)
 Read a file on the CD.
bool jo_fs_read_file_async_ptr (const char *const filename, jo_fs_async_read_callback callback, int optional_token, void *buf)
 Read a file on the CD asynchronously and put the contents to "buf".
static __jo_force_inline bool jo_fs_read_file_async (const char *const filename, jo_fs_async_read_callback callback, int optional_token)
 Read a file on the CD asynchronously.
bool jo_fs_open (jo_file *const file, const char *const filename)
 Open a file.
void jo_fs_close (jo_file *const file)
 Close a file.
void jo_fs_set_read_sector_count (const int count)
 Set the size of the read buffer of the files opened by jo_fs_open().
int jo_fs_read_next_bytes (jo_file *const file, char *buffer, unsigned int nbytes)
 Read bytes from a file.
bool jo_fs_seek_forward (jo_file *const file, unsigned int nbytes)
 Seek forward from current position of a file.
int __jo_fs_get_file_id (const char *const filename)
 Get the identifier of a file in the current directory (Internal usage).
void * __jo_fs_open (const int file_id)
 Open a file (Internal usage).
void __jo_fs_close (void *handle)
 Close a file opened with __jo_fs_open() (Internal usage).
int __jo_fs_get_file_size (void *handle)
 Get the size of a file in bytes (Internal usage).
int __jo_fs_get_sector_count (void *handle)
 Get the size of a file in sectors (Internal usage).
bool __jo_fs_seek_sector (void *handle, const int sector)
 Set the current position of a file (Internal usage).
int __jo_fs_read_sectors (void *handle, int sector_count, void *buf, const int buf_size)
 Read sectors from the current position of a file (Internal usage).
void __jo_cd_play_tracks (const int from_track, const int to_track, const unsigned char play_mode)
 Play CD audio tracks (Internal usage).
void __jo_cd_play_from_fad (const unsigned int fad, const int from_track, const int to_track, const unsigned char play_mode)
 Play CD audio from a sector (Internal usage).
int __jo_cd_get_status (unsigned int *fad)
 Get the CD drive status (Internal usage).
void __jo_cd_pause (void)
 Pause the CD drive (Internal usage).

Detailed Description

Jo Engine File System function prototypes.

Author
Johannes Fetz
Bug
No known bugs.

Macro Definition Documentation

◆ JO_CD_DRIVE_PAUSE

#define JO_CD_DRIVE_PAUSE

Drive status: the drive is paused.

◆ JO_CD_DRIVE_PLAY

#define JO_CD_DRIVE_PLAY

Drive status: the drive is playing (audio or data).

◆ JO_CURRENT_DIR

#define JO_CURRENT_DIR

Specify the current directory (on the CD) for jo_fs_read_file(), jo_map_load_from_file(), etc.

◆ JO_PARENT_DIR

#define JO_PARENT_DIR

Specify the parent directory for jo_fs_read_file(), jo_map_load_from_file(), etc.

◆ JO_ROOT_DIR

#define JO_ROOT_DIR

Specify the root directory (on the CD) for jo_fs_read_file(), jo_map_load_from_file(), etc.

Typedef Documentation

◆ jo_fs_async_read_callback

typedef void(*) jo_fs_async_read_callback(char *contents, int length, int optional_token)

Function prototype for ().

Function Documentation

◆ __jo_cd_get_status()

int __jo_cd_get_status ( unsigned int * fad)

Get the CD drive status (Internal usage).

Parameters
fadCurrent sector (frame address) of the pickup (output, can be JO_NULL)
Returns
Drive status (JO_CD_DRIVE_PAUSE, JO_CD_DRIVE_PLAY, etc) or -1 if the CD block doesn't answer

◆ __jo_cd_pause()

void __jo_cd_pause ( void )

Pause the CD drive (Internal usage).

Remarks
Stops the CD audio, the pickup stays at the current position

◆ __jo_cd_play_from_fad()

void __jo_cd_play_from_fad ( const unsigned int fad,
const int from_track,
const int to_track,
const unsigned char play_mode )

Play CD audio from a sector (Internal usage).

Parameters
fadFirst sector (frame address)
from_trackFirst track (played from its start if fad is not before the end of to_track)
to_trackLast track (played until its end)
play_mode0x00: no repeat, 0x01~0x0e: maximum repeats, 0x0f: endless repeat
Remarks
Used to resume the CD audio after a pause. Any data read in progress is cancelled

◆ __jo_cd_play_tracks()

void __jo_cd_play_tracks ( const int from_track,
const int to_track,
const unsigned char play_mode )

Play CD audio tracks (Internal usage).

Parameters
from_trackFirst track (the first audio track is usually 2)
to_trackLast track (played until its end)
play_mode0x00: no repeat, 0x01~0x0e: maximum repeats, 0x0f: endless repeat
Remarks
Any data read in progress is cancelled

◆ __jo_fs_close()

void __jo_fs_close ( void * handle)

Close a file opened with __jo_fs_open() (Internal usage).

Parameters
handleFile handle (JO_NULL is ignored)

◆ __jo_fs_get_file_id()

int __jo_fs_get_file_id ( const char *const filename)

Get the identifier of a file in the current directory (Internal usage).

Parameters
filenameFilename (upper case, like "A.TXT")
Returns
File identifier or -1 if the file doesn't exist

◆ __jo_fs_get_file_size()

int __jo_fs_get_file_size ( void * handle)

Get the size of a file in bytes (Internal usage).

Parameters
handleFile handle
Returns
File size in bytes

◆ __jo_fs_get_sector_count()

int __jo_fs_get_sector_count ( void * handle)

Get the size of a file in sectors (Internal usage).

Parameters
handleFile handle
Returns
File size in sectors (2048 bytes)

◆ __jo_fs_open()

void * __jo_fs_open ( const int file_id)

Open a file (Internal usage).

Parameters
file_idFile identifier (see __jo_fs_get_file_id())
Returns
File handle or JO_NULL if the identifier is invalid or if too many files are opened
Remarks
JO_MAX_FS_BACKGROUND_JOBS files can be opened at the same time

◆ __jo_fs_read_sectors()

int __jo_fs_read_sectors ( void * handle,
int sector_count,
void * buf,
const int buf_size )

Read sectors from the current position of a file (Internal usage).

Parameters
handleFile handle
sector_countNumber of sectors to read
bufOutput buffer
buf_sizeSize of the output buffer (bytes after it are not written)
Returns
Number of bytes stored in buf, 0 at the end of the file, or -1 if the read failed
Remarks
The current position moves forward even if buf is too small

◆ __jo_fs_seek_sector()

bool __jo_fs_seek_sector ( void * handle,
const int sector )

Set the current position of a file (Internal usage).

Parameters
handleFile handle
sectorSector index from the beginning of the file
Returns
false if the position is outside of the file

◆ jo_fs_cd()

void jo_fs_cd ( const char *const sub_dir)

Change the current directory (equivalent of Unix cd command).

Parameters
sub_dirSub directory name (use JO_PARENT_DIR for parent directory)

◆ jo_fs_close()

void jo_fs_close ( jo_file *const file)

Close a file.

Parameters
filePointer to an allocated and valid jo_file struct

◆ jo_fs_get_read_stats()

void jo_fs_get_read_stats ( unsigned int *const vblanks,
unsigned int *const bytes,
unsigned int *const files,
const bool reset )

Statistics of the files read by jo_fs_read_file_ptr() (the time of a loading: the CD or the CPU).

Parameters
vblanksTime spent reading (VBLANK count), JO_NULL: not wanted
bytesBytes read
filesFiles read
resetThe counts start again from 0

◆ jo_fs_open()

bool jo_fs_open ( jo_file *const file,
const char *const filename )

Open a file.

Parameters
filePointer to an allocated jo_file struct
filenameFilename (upper case and shorter as possible like "A.TXT")
Returns
true if succeed

◆ jo_fs_read_file()

__jo_force_inline char * jo_fs_read_file ( const char *const filename,
int * len )
static

Read a file on the CD.

Parameters
filenameFilename (upper case and shorter as possible like "A.TXT")
lenreturn the file length
Returns
The stream

◆ jo_fs_read_file_async()

__jo_force_inline bool jo_fs_read_file_async ( const char *const filename,
jo_fs_async_read_callback callback,
int optional_token )
static

Read a file on the CD asynchronously.

Parameters
filenameFilename (upper case and shorter as possible like "A.TXT")
callbackCallback called when the file is loaded
optional_tokenUser value to identify the file
Returns
true if succeed

◆ jo_fs_read_file_async_ptr()

bool jo_fs_read_file_async_ptr ( const char *const filename,
jo_fs_async_read_callback callback,
int optional_token,
void * buf )

Read a file on the CD asynchronously and put the contents to "buf".

Parameters
filenameFilename (upper case and shorter as possible like "A.TXT")
callbackCallback called when the file is loaded
optional_tokenUser value to identify the file
bufOutput buffer
Returns
true if succeed

◆ jo_fs_read_file_in_dir()

char * jo_fs_read_file_in_dir ( const char *const filename,
const char *const sub_dir,
int * len )

Read a file on the CD.

Parameters
filenameFilename (upper case and shorter as possible like "A.TXT")
sub_dirSub directory name (use JO_ROOT_DIR if the file is on the root directory)
lenreturn the file length
Returns
The stream

◆ jo_fs_read_file_ptr()

char * jo_fs_read_file_ptr ( const char *const filename,
void * buf,
int * len )

Read a file on the CD and put the contents to "buf".

Parameters
filenameFilename (upper case and shorter as possible like "A.TXT")
bufOutput buffer
lenreturn the file length
Returns
The stream

◆ jo_fs_read_next_bytes()

int jo_fs_read_next_bytes ( jo_file *const file,
char * buffer,
unsigned int nbytes )

Read bytes from a file.

Parameters
filePointer to an allocated and valid jo_file struct
bufferPointer to an allocated buffer (length >= nbytes)
nbytesnumber of bytes to read
Returns
Number of bytes read (<= 0 means EOF)

◆ jo_fs_seek_forward()

bool jo_fs_seek_forward ( jo_file *const file,
unsigned int nbytes )

Seek forward from current position of a file.

Parameters
filePointer to an allocated and valid jo_file struct
nbytesnumber of bytes to skip
Returns
true if succeed

◆ jo_fs_set_read_sector_count()

void jo_fs_set_read_sector_count ( const int count)

Set the size of the read buffer of the files opened by jo_fs_open().

Parameters
countNumber of sectors (2048 bytes) read at once by jo_fs_read_next_bytes() (1 by default)
Remarks
Only the files opened after this call use the new size