diff options
author | Nathan Ringo <nathan@remexre.com> | 2024-11-28 22:33:47 -0600 |
---|---|---|
committer | Nathan Ringo <nathan@remexre.com> | 2024-11-28 22:33:47 -0600 |
commit | b3149099a17d392289db9699b5b5d83444d25173 (patch) | |
tree | 24e84d2ca1469bd87b4379ea2b701218d0465d8f /src/platform | |
parent | 16e22f9cb39a254bccd20613f7c2cfef75ae15a7 (diff) |
Prevent 3DS hangs.
Diffstat (limited to 'src/platform')
-rw-r--r-- | src/platform/3ds.c | 88 |
1 files changed, 42 insertions, 46 deletions
diff --git a/src/platform/3ds.c b/src/platform/3ds.c index 5566121..56d2fa8 100644 --- a/src/platform/3ds.c +++ b/src/platform/3ds.c @@ -46,51 +46,6 @@ noreturn void panic_end(void) { exit(1); } -static void gc_test(void) { - gc_debug(); - - const struct value ZERO = {.bits = (0 << 2) | TAG_FIXNUM}; - - struct object *values = gc_alloc(64, 0); - struct object *value_slot_counts = gc_alloc(64, 0); - gc_root_push(&values); - gc_root_push(&value_slot_counts); - - for (size_t i = 0; i < 10000000; i++) { - if ((rand() & 0b11) == 0) { - size_t value_slot_count = rand() & 63; - if (!value_slot_count) - value_slot_count = 1; - size_t untraced_slot_count = rand() & 63; - struct value value = - alloc_builtin_object(ZERO, value_slot_count, untraced_slot_count); - size_t i = rand() % 63; - gc_write_value_slot(values, i, value); - gc_write_value_slot(value_slot_counts, i, - integer_of_int(value_slot_count)); - } else { - size_t i = rand() & 63; - struct value value = gc_read_value_slot(values, i); - struct value value_slot_count_value = - gc_read_value_slot(value_slot_counts, i); - if (!value.bits) - continue; - assume(get_tag(value) == TAG_BUILTIN_OBJECT); - assume(get_tag(value_slot_count_value) == TAG_FIXNUM); - struct object *obj = untag_ptr(value); - intptr_t value_slot_count = untag_fixnum(value_slot_count_value); - size_t j = rand() % value_slot_count; - size_t k = rand() % 63; - gc_write_value_slot(obj, j, gc_read_value_slot(values, k)); - } - } - - gc_root_pop(); - gc_root_pop(); - - gc_debug(); -} - int main(int argc, char **argv) { gfxInit(GSP_BGR8_OES, GSP_BGR8_OES, false); @@ -111,6 +66,13 @@ int main(int argc, char **argv) { printf("\x1b[29;16HPress Start to exit.\n"); // Main loop + const struct value ZERO = {.bits = (0 << 2) | TAG_FIXNUM}; + + struct object *values = gc_alloc(64, 0); + struct object *value_slot_counts = gc_alloc(64, 0); + gc_root_push(&values); + gc_root_push(&value_slot_counts); + bool gc_test = false; while (aptMainLoop()) { // Scan all the inputs. This should be done once for each frame hidScanInput(); @@ -122,12 +84,45 @@ int main(int argc, char **argv) { if (kDown & KEY_START) break; // break in order to return to hbmenu if (kDown & KEY_A) - gc_test(); + gc_test = true; circlePosition pos; hidCircleRead(&pos); printf("\x1b[0;0H\x1b[K(%" PRId16 ", %" PRId16 ")\n", pos.dx, pos.dy); + if (gc_test) { + for (size_t j = 0; j < 1000; j++) { + if ((rand() & 0b11) == 0) { + size_t value_slot_count = rand() & 7; + if (!value_slot_count) + value_slot_count = 1; + size_t untraced_slot_count = rand() & 7; + struct value value = + alloc_builtin_object(ZERO, value_slot_count, untraced_slot_count); + size_t i = rand() % 63; + gc_write_value_slot(values, i, value); + gc_write_value_slot(value_slot_counts, i, + integer_of_int(value_slot_count)); + } else { + size_t i = rand() & 63; + struct value value = gc_read_value_slot(values, i); + struct value value_slot_count_value = + gc_read_value_slot(value_slot_counts, i); + if (!value.bits) + continue; + assume(get_tag(value) == TAG_BUILTIN_OBJECT); + assume(get_tag(value_slot_count_value) == TAG_FIXNUM); + struct object *obj = untag_ptr(value); + intptr_t value_slot_count = untag_fixnum(value_slot_count_value); + size_t j = rand() % value_slot_count; + size_t k = rand() % 63; + gc_write_value_slot(obj, j, gc_read_value_slot(values, k)); + } + } + gc_debug(); + } + + /* // Get the bottom screen's frame buffer u16 w, h; u8 *fb = gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, &w, &h); @@ -143,6 +138,7 @@ int main(int argc, char **argv) { // Flush and swap framebuffers gfxFlushBuffers(); gfxSwapBuffers(); + */ // Wait for VBlank gspWaitForVBlank(); |