aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c49
1 files changed, 12 insertions, 37 deletions
diff --git a/src/main.c b/src/main.c
index 62030e5..ea8d459 100644
--- a/src/main.c
+++ b/src/main.c
@@ -124,20 +124,19 @@ file_talk(Device *d, u8 b0, u8 w) {
124 u16 result = 0, length = mempeek16(d->dat, 0xa); 124 u16 result = 0, length = mempeek16(d->dat, 0xa);
125 u16 offset = mempeek16(d->dat, 0x4); 125 u16 offset = mempeek16(d->dat, 0x4);
126 u16 addr = mempeek16(d->dat, b0 - 1); 126 u16 addr = mempeek16(d->dat, b0 - 1);
127 File file = fs_open_file(name, read ? FS_OPEN_READ : FS_OPEN_WRITE); 127 OpenMode mode = FS_OPEN_READ;
128 if (!read) {
129 mode = offset ? FS_OPEN_APPEND : FS_OPEN_WRITE;
130 }
131 File file = fs_open_file(name, mode);
128 if (file.index != FS_NULL) { 132 if (file.index != FS_NULL) {
129 txt_position(9, 9); 133 if(fs_seek(&file, offset, SEEK_SET) != -1) {
130 // TODO: Use file.cur pointer and fs_seek instead of offset. 134 if (read) {
131 // TODO: Remove append, that should be a write mode. 135 result = fs_read(&d->mem[addr], length, &file);
132 if (read) { 136 } else {
133 result = fs_read(&d->mem[addr], length, offset, &file); 137 result = fs_write(&d->mem[addr], length, &file);
134 } else { 138 }
135 result = fs_write(&d->mem[addr], length, offset, offset > 0, &file);
136 txt_printf("WROTE: %d\n", result);
137 } 139 }
138 } else {
139 // txt_position(9, 9);
140 // txt_printf("NOT FOUND");
141 } 140 }
142 mempoke16(d->dat, 0x2, result); 141 mempoke16(d->dat, 0x2, result);
143 } 142 }
@@ -197,7 +196,7 @@ handle_input(Uxn *u) {
197 } 196 }
198 197
199 // Update ctrl_idx. 198 // Update ctrl_idx.
200 ctrl_idx = ctrl_idx + 1 > LEN(ctrl_methods) - 1 ? 0 : ctrl_idx + 1; 199 ctrl_idx = (ctrl_idx + 1 > (int)LEN(ctrl_methods) - 1) ? 0 : ctrl_idx + 1;
201 200
202 // Initialize controller variables here. 201 // Initialize controller variables here.
203 if (ctrl_methods[ctrl_idx] == CONTROL_KEYBOARD) { 202 if (ctrl_methods[ctrl_idx] == CONTROL_KEYBOARD) {
@@ -360,38 +359,14 @@ int main(void) {
360 txt_init(1, TEXT_LAYER); 359 txt_init(1, TEXT_LAYER);
361 txt_position(0,0); 360 txt_position(0,0);
362 361
363 u8 test_data_a[1020];
364 u8 test_data_b[2038];
365 memset(&test_data_a, 0xAA, sizeof(test_data_a));
366 memset(&test_data_b, 0xbb, sizeof(test_data_b));
367
368 txt_position(0, 8);
369 File file_a = fs_open_file("file_a", FS_OPEN_WRITE);
370 File file_b = fs_open_file("file_b", FS_OPEN_WRITE);
371 fs_write(&test_data_b, sizeof(test_data_b), 0, 0, &file_a);
372 fs_write(&test_data_a, sizeof(test_data_a), 0, 0, &file_a);
373 // fs_write(&test_data_a, sizeof(test_data_a), 0, 0, &file_a);
374 // fs_write(&test_data_b, sizeof(test_data_b), 0, 0, &file_b);
375
376 // Main loop. 362 // Main loop.
377 int frame_counter = 0; 363 int frame_counter = 0;
378 evaluxn(&u, 0x0100); 364 evaluxn(&u, 0x0100);
379 u32 flip_cycles = 0;
380 while(true) { 365 while(true) {
381 bios_vblank_wait(); 366 bios_vblank_wait();
382 profile_start();
383 handle_input(&u); 367 handle_input(&u);
384 u32 input_cycles = profile_stop();
385 profile_start();
386 evaluxn(&u, mempeek16(devscreen->dat, 0)); 368 evaluxn(&u, mempeek16(devscreen->dat, 0));
387 u32 eval_cycles = profile_stop();
388 txt_position(0, 8);
389 // txt_printf("INPUT: %lu \n", input_cycles);
390 // txt_printf("EVAL: %lu \n", eval_cycles);
391 // txt_printf("FLIP: %lu \n", flip_cycles);
392 profile_start();
393 flipbuf(&ppu); 369 flipbuf(&ppu);
394 flip_cycles = profile_stop();
395 frame_counter++; 370 frame_counter++;
396 } 371 }
397 372