#ifndef FILE_H_ #define FILE_H_ #include #include #include "fat.h" #include "nds.h" #include "../bang.h" #include "../types/pathbuf.h" // 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' 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; // Functions. void init_nds_filesystem(); bool nds_filesystem_enabled(); // 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); 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); #endif