aboutsummaryrefslogtreecommitdiffstats
path: root/src/filesystem.c
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2021-05-21 17:41:06 +0200
committerBad Diode <bd@badd10de.dev>2021-05-21 17:41:06 +0200
commit872faecf9660cc2469aa5586f81639f7986b6b8f (patch)
tree76663221fb6f0480a31587abc39c5966fb6adee7 /src/filesystem.c
parentaf98fa608fb4ba98138e2b1239f173e6d74d6d86 (diff)
downloaduxngba-872faecf9660cc2469aa5586f81639f7986b6b8f.tar.gz
uxngba-872faecf9660cc2469aa5586f81639f7986b6b8f.zip
Add fs_read and fs_write functions and some testing
Diffstat (limited to 'src/filesystem.c')
-rw-r--r--src/filesystem.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/filesystem.c b/src/filesystem.c
index 2da77be..1521d69 100644
--- a/src/filesystem.c
+++ b/src/filesystem.c
@@ -116,3 +116,18 @@ fs_write(u8 *src, size_t n_bytes, u16 file_index, u16 offset, bool append) {
116 116
117 return n_bytes; 117 return n_bytes;
118} 118}
119
120int
121fs_read(u8 *dst, size_t n_bytes, u16 file_index, u16 offset) {
122 File *file = &filesystem.files[file_index];
123
124 // Check if the offset is within limits.
125 if (offset + n_bytes >= FILE_MAX_SIZE) {
126 return -1;
127 }
128
129 // Copy n_bytes to destination.
130 _fs_read(dst, FILE_DATA_OFFSET + FILE_MAX_SIZE * file_index + offset, n_bytes);
131
132 return n_bytes;
133}