From b15be6467bdde9492d653ef2e77cce64bdf41d6c Mon Sep 17 00:00:00 2001 From: Mateusz Faderewski Date: Wed, 6 Sep 2023 00:49:06 +0200 Subject: [PATCH] Improve game boot compatibility --- src/boot/boot.c | 18 +++++++++++++++++- src/boot/boot_io.h | 2 ++ src/boot/reboot.S | 4 +--- src/menu/menu.c | 16 +++++++--------- 4 files changed, 27 insertions(+), 13 deletions(-) diff --git a/src/boot/boot.c b/src/boot/boot.c index d4796291..b4ba7ce4 100644 --- a/src/boot/boot.c +++ b/src/boot/boot.c @@ -87,7 +87,23 @@ void boot (boot_params_t *params) { while (!(cpu_io_read(&SP->SR) & SP_SR_HALT)); - cpu_io_write(&SP->SR, SP_SR_CLR_INTR | SP_SR_SET_HALT); + cpu_io_write(&SP->SR, + SP_SR_CLR_SIG7 | + SP_SR_CLR_SIG6 | + SP_SR_CLR_SIG5 | + SP_SR_CLR_SIG4 | + SP_SR_CLR_SIG3 | + SP_SR_CLR_SIG2 | + SP_SR_CLR_SIG1 | + SP_SR_CLR_SIG0 | + SP_SR_CLR_INTR_BREAK | + SP_SR_CLR_SSTEP | + SP_SR_CLR_INTR | + SP_SR_CLR_BROKE | + SP_SR_SET_HALT + ); + cpu_io_write(&SP->SEMAPHORE, 0); + cpu_io_write(&SP->PC, 0); while (cpu_io_read(&SP->DMA_BUSY)); diff --git a/src/boot/boot_io.h b/src/boot/boot_io.h index 2eede3b5..547a6630 100644 --- a/src/boot/boot_io.h +++ b/src/boot/boot_io.h @@ -37,6 +37,8 @@ typedef struct { io32_t DMA_FULL; io32_t DMA_BUSY; io32_t SEMAPHORE; + io32_t __reserved[0xFFF8]; + io32_t PC; } sp_regs_t; #define SP_BASE (0x04040000UL) diff --git a/src/boot/reboot.S b/src/boot/reboot.S index 775557e3..ec6dc9f2 100644 --- a/src/boot/reboot.S +++ b/src/boot/reboot.S @@ -68,8 +68,6 @@ reset_rdram: 1: addiu $t2, (-1) bnez $t2, 1b - - mtc0 $zero, $9 reset_rdram_skip: prepare_registers: @@ -110,7 +108,7 @@ ra_values: .set ra_table, REBOOT_ADDRESS + (. - reboot_start) .word 0xA4001554 .word 0xA4001550 - .word 0xA4001550 # TODO: Figure out address for MPAL console + .word 0xA4001554 .set reboot_size, (. - reboot_start) .global reboot_size diff --git a/src/menu/menu.c b/src/menu/menu.c index 3ce41cf1..3a25e98f 100644 --- a/src/menu/menu.c +++ b/src/menu/menu.c @@ -29,7 +29,6 @@ static menu_t *menu; -static bool boot_pending; static tv_type_t tv_type; static volatile int frame_counter = 0; @@ -62,8 +61,6 @@ static void menu_init (boot_params_t *boot_params) { fonts_init(); sound_init_default(); - boot_pending = false; - menu = calloc(1, sizeof(menu_t)); assert(menu != NULL); @@ -148,7 +145,7 @@ static struct views_s { void menu_run (boot_params_t *boot_params) { menu_init(boot_params); - while (!boot_pending && (exception_reset_time() < RESET_TIME_LENGTH)) { + while (exception_reset_time() < RESET_TIME_LENGTH) { surface_t *display = (frame_counter >= FRAMERATE_DIVIDER) ? display_try_get() : NULL; if (display != NULL) { @@ -160,7 +157,12 @@ void menu_run (boot_params_t *boot_params) { views[menu->mode].show(menu, display); } else { rdpq_attach_clear(display, NULL); - rdpq_detach_show(); + rdpq_detach_wait(); + display_show(display); + } + + if (menu->mode == MENU_MODE_BOOT) { + break; } while (menu->mode != menu->next_mode) { @@ -169,10 +171,6 @@ void menu_run (boot_params_t *boot_params) { if (views[menu->mode].init) { views[menu->mode].init(menu); } - - if (menu->mode == MENU_MODE_BOOT) { - boot_pending = true; - } } time(&menu->current_time);