aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c39
1 files changed, 35 insertions, 4 deletions
diff --git a/src/main.c b/src/main.c
index e30035a..62030e5 100644
--- a/src/main.c
+++ b/src/main.c
@@ -124,13 +124,20 @@ 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 int file_idx = fs_open_file(name, read ? OPEN_READ : OPEN_WRITE); 127 File file = fs_open_file(name, read ? FS_OPEN_READ : FS_OPEN_WRITE);
128 if (file_idx >= 0) { 128 if (file.index != FS_NULL) {
129 txt_position(9, 9);
130 // TODO: Use file.cur pointer and fs_seek instead of offset.
131 // TODO: Remove append, that should be a write mode.
129 if (read) { 132 if (read) {
130 result = fs_read(&d->mem[addr], length, file_idx, offset); 133 result = fs_read(&d->mem[addr], length, offset, &file);
131 } else { 134 } else {
132 result = fs_write(&d->mem[addr], length, file_idx, offset, offset > 0); 135 result = fs_write(&d->mem[addr], length, offset, offset > 0, &file);
136 txt_printf("WROTE: %d\n", result);
133 } 137 }
138 } else {
139 // txt_position(9, 9);
140 // txt_printf("NOT FOUND");
134 } 141 }
135 mempoke16(d->dat, 0x2, result); 142 mempoke16(d->dat, 0x2, result);
136 } 143 }
@@ -353,14 +360,38 @@ int main(void) {
353 txt_init(1, TEXT_LAYER); 360 txt_init(1, TEXT_LAYER);
354 txt_position(0,0); 361 txt_position(0,0);
355 362
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
356 // Main loop. 376 // Main loop.
357 int frame_counter = 0; 377 int frame_counter = 0;
358 evaluxn(&u, 0x0100); 378 evaluxn(&u, 0x0100);
379 u32 flip_cycles = 0;
359 while(true) { 380 while(true) {
360 bios_vblank_wait(); 381 bios_vblank_wait();
382 profile_start();
361 handle_input(&u); 383 handle_input(&u);
384 u32 input_cycles = profile_stop();
385 profile_start();
362 evaluxn(&u, mempeek16(devscreen->dat, 0)); 386 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();
363 flipbuf(&ppu); 393 flipbuf(&ppu);
394 flip_cycles = profile_stop();
364 frame_counter++; 395 frame_counter++;
365 } 396 }
366 397