Jo Engine 2026.11.1
Jo Sega Saturn Engine
Loading...
Searching...
No Matches
fs.h
Go to the documentation of this file.
1/*
2** Jo Sega Saturn Engine
3** Copyright (c) 2012-2026, Johannes Fetz (johannesfetz@gmail.com)
4** All rights reserved.
5**
6** Redistribution and use in source and binary forms, with or without
7** modification, are permitted provided that the following conditions are met:
8** * Redistributions of source code must retain the above copyright
9** notice, this list of conditions and the following disclaimer.
10** * Redistributions in binary form must reproduce the above copyright
11** notice, this list of conditions and the following disclaimer in the
12** documentation and/or other materials provided with the distribution.
13** * Neither the name of the Johannes Fetz nor the
14** names of its contributors may be used to endorse or promote products
15** derived from this software without specific prior written permission.
16**
17** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20** DISCLAIMED. IN NO EVENT SHALL Johannes Fetz BE LIABLE FOR ANY
21** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27*/
34
35#ifndef __JO_FS_H__
36# define __JO_FS_H__
37
38#ifdef JO_COMPILE_WITH_FS_SUPPORT
39
40/*
41** MACROS
42*/
44# define JO_ROOT_DIR ((const char *)0)
46# define JO_CURRENT_DIR ((const char *)0)
48# define JO_PARENT_DIR ("..")
49
50/*
51** TYPEDEFS
52*/
54typedef void (*jo_fs_async_read_callback)(char *contents, int length, int optional_token);
55
59void jo_fs_cd(const char *const sub_dir);
60
67char* jo_fs_read_file_in_dir(const char *const filename, const char *const sub_dir, int *len);
68
75char *jo_fs_read_file_ptr(const char *const filename, void *buf, int *len);
76
83void jo_fs_get_read_stats(unsigned int * const vblanks, unsigned int * const bytes,
84 unsigned int * const files, const bool reset);
85
91static __jo_force_inline char* jo_fs_read_file(const char *const filename, int *len)
92{
93 return (jo_fs_read_file_ptr(filename, 0, len));
94}
95
103bool jo_fs_read_file_async_ptr(const char *const filename, jo_fs_async_read_callback callback, int optional_token, void *buf);
104
111static __jo_force_inline bool jo_fs_read_file_async(const char *const filename, jo_fs_async_read_callback callback, int optional_token)
112{
113 return (jo_fs_read_file_async_ptr(filename, callback, optional_token, 0));
114}
115
121bool jo_fs_open(jo_file * const file, const char *const filename);
122
126void jo_fs_close(jo_file * const file);
127
132void jo_fs_set_read_sector_count(const int count);
133
140int jo_fs_read_next_bytes(jo_file * const file, char *buffer, unsigned int nbytes);
141
147bool jo_fs_seek_forward(jo_file * const file, unsigned int nbytes);
148
149/*
150** Internal usage
151*/
152
157int __jo_fs_get_file_id(const char * const filename);
158
164void *__jo_fs_open(const int file_id);
165
169void __jo_fs_close(void *handle);
170
175int __jo_fs_get_file_size(void *handle);
176
181int __jo_fs_get_sector_count(void *handle);
182
188bool __jo_fs_seek_sector(void *handle, const int sector);
189
198int __jo_fs_read_sectors(void *handle, int sector_count, void *buf, const int buf_size);
199
206void __jo_cd_play_tracks(const int from_track, const int to_track, const unsigned char play_mode);
207
215void __jo_cd_play_from_fad(const unsigned int fad, const int from_track, const int to_track,
216 const unsigned char play_mode);
217
219# define JO_CD_DRIVE_PAUSE (0x01)
221# define JO_CD_DRIVE_PLAY (0x03)
222
227int __jo_cd_get_status(unsigned int *fad);
228
232void __jo_cd_pause(void);
233
234#endif /* !JO_COMPILE_WITH_FS_SUPPORT */
235
236#endif /* !__JO_FS_H__ */
237
238/*
239** END OF FILE
240*/
int __jo_fs_get_file_size(void *handle)
Get the size of a file in bytes (Internal usage).
void(*) jo_fs_async_read_callback(char *contents, int length, int optional_token)
Function prototype for ().
Definition fs.h:54
char * jo_fs_read_file_in_dir(const char *const filename, const char *const sub_dir, int *len)
Read a file on the CD.
void __jo_cd_pause(void)
Pause the CD drive (Internal usage).
bool jo_fs_seek_forward(jo_file *const file, unsigned int nbytes)
Seek forward from current position of a file.
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_cd_play_tracks(const int from_track, const int to_track, const unsigned char play_mode)
Play CD audio tracks (Internal usage).
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.
Definition fs.h:111
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".
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_close(jo_file *const file)
Close a file.
void * __jo_fs_open(const int file_id)
Open a file (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).
static __jo_force_inline char * jo_fs_read_file(const char *const filename, int *len)
Read a file on the CD.
Definition fs.h:91
int __jo_cd_get_status(unsigned int *fad)
Get the CD drive status (Internal usage).
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().
bool jo_fs_open(jo_file *const file, const char *const filename)
Open a file.
void jo_fs_cd(const char *const sub_dir)
Change the current directory (equivalent of Unix cd command).
void __jo_fs_close(void *handle)
Close a file opened with __jo_fs_open() (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).
bool __jo_fs_seek_sector(void *handle, const int sector)
Set the current position of a file (Internal usage).
int __jo_fs_get_sector_count(void *handle)
Get the size of a file in sectors (Internal usage).
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).
int jo_fs_read_next_bytes(jo_file *const file, char *buffer, unsigned int nbytes)
Read bytes from a file.
#define __jo_force_inline
force inline attribute (and prevent Doxygen prototype parsing bug)
Definition types.h:39
File definition.
Definition types.h:296