diff options
author | Ben Bridle <ben@derelict.engineering> | 2025-09-19 13:17:14 +1200 |
---|---|---|
committer | Ben Bridle <ben@derelict.engineering> | 2025-09-19 13:32:32 +1200 |
commit | bb1aa5958d1b67707dcf0f6b08bfaf0b408bd46e (patch) | |
tree | b26d07ed58aaf7a5230fc3e28c103d616abfa9b8 /arm9/source/devices/file.h | |
parent | 9612c307f00c4313d73fe0c3a86c05c8d8cd514e (diff) | |
download | bedrock-nds-bb1aa5958d1b67707dcf0f6b08bfaf0b408bd46e.zip |
Massive rewrite
This commit rewrites the emulator halfway from scratch to make it
easier to change and maintain in the future. The emulator core was
rewritten to adhere to the released Bedrock specification (earlier
versions implemented an older prototype specification, which is no
longer relevant).
This commit also adds proper support for running multiple concurrent
Bedrock instances. This was previously supported in a limited manner
for the on-screen keyboard, but now works for any regular program as
well, with switching being performed by pressing the L or R bumper
buttons. This is disabled by default, as programs will still need to
be baked into the emulator and hand-loaded.
Diffstat (limited to 'arm9/source/devices/file.h')
-rw-r--r-- | arm9/source/devices/file.h | 77 |
1 files changed, 38 insertions, 39 deletions
diff --git a/arm9/source/devices/file.h b/arm9/source/devices/file.h index f295e89..3f27bda 100644 --- a/arm9/source/devices/file.h +++ b/arm9/source/devices/file.h @@ -1,55 +1,54 @@ -#include <dirent.h> -#include "../types/pathbuf.h" - -// #include <stdio.h> -// #include <dirent.h> -// #include <string.h> -// #include <sys/stat.h> - #ifndef FILE_H_ #define FILE_H_ - typedef struct { - bool open; // true if an entry is open - bool success; // true if the previous operation was successful - bool is_dir; // true if the open entry is a directory - bool child_is_dir; // true if the selected child is a directory - PathBuf entry; // write buffer for entry port - PathBuf action; // write buffer for action port - PathBuf path; // path of the open entry - PathBuf child_path; // path of the selected child - u32 pointer; // pointer in the open entry, whether dir or file - u32 length; // length of the open entry, whether dir or file - u32 pointer_write; // write cache for pointer - u32 length_write; // write cache for length + #include <dirent.h> + #include <sys/stat.h> + #include "fat.h" + #include "nds.h" + #include "../bang.h" + #include "../types/pathbuf.h" - DIR *dir; // structure pointing to current directory - FILE *file; // opaque ID referencing the open file - FILE *tmpfile; // to open file and keep existing file open - struct dirent *child; // currently-selected directory child information - u32 dir_i; // index of next child to read from dir - bool at_root; // current entry is the root directory - } FileDevice; + // Bedrock file device. + typedef struct { + FILE *file; // Opaque ID referencing current file (if any) + // See ANSI C89 Standard, page 126 + DIR *dir; // Structure referencing current directory (if any) + // See 'libnds/libs/libnds/include/sys/dirent.h:41' + u32 dir_i; // Index of next child to be read from current directory + bool is_root; // True if the current directory is the root directory. + struct dirent *child; // Information about selected child (file or dir) + // See 'libnds/libs/libnds/include/sys/dirent.h:17' - void init_filesystem(); - bool filesystem_enabled(); + PathBuf open; // Write buffer for open port + PathBuf action; // Write buffer for action port + PathBuf path; // Path of current entry + PathBuf child_path; // Path of selected child + u32 address; // Address into current entry (file or dir) + u32 length; // Length of current entry (file or dir) + bool length_cached; // True if length has been calculated. + u32 address_write; // Write cache for address + u32 length_write; // Write cache for length + bool error; // True if error occurred since last read + } FileDevice; - void create_parents(u8 *path); + // Functions. + void init_nds_filesystem(); + bool nds_filesystem_enabled(); - void fs_push_entry(FileDevice *fs, u8 byte); + // Methods. + void fs_reset(FileDevice *fs); + void fs_calculate_length(FileDevice *fs); + bool fs_get_open(FileDevice *fs); + bool fs_get_error(FileDevice *fs); + bool fs_get_type(FileDevice *fs); + bool fs_get_child_type(FileDevice *fs); + void fs_push_open(FileDevice *fs, u8 byte); void fs_push_action(FileDevice *fs, u8 byte); - bool fs_push_byte(PathBuf *buf, u8 byte); - u8 fs_read_byte(FileDevice *fs); void fs_write_byte(FileDevice *fs, u8 byte); - void fs_ascend(FileDevice *fs); void fs_descend(FileDevice *fs); - void fs_seek(FileDevice *fs); void fs_resize(FileDevice *fs); - - void fs_select_child(FileDevice *fs, u32 pointer); - #endif |