78 lines
2.2 KiB
C
Raw Normal View History

2021-02-09 23:58:02 +01:00
#include "boot/boot.h"
#include "loader/loader.h"
#include "sc64/sc64.h"
#include "sc64/sc64_sd_fs.h"
static const char *MENU_FILE_PATH = "SC64/MENU.z64";
2020-10-08 02:04:42 +02:00
int main(void) {
2021-02-09 23:58:02 +01:00
loader_init();
if (sc64_get_version() != SC64_CART_VERSION_A) {
2021-02-09 23:58:02 +01:00
loader_display_error_and_halt(E_MENU_ERROR_NOT_SC64, "");
}
2020-10-08 02:04:42 +02:00
sc64_enable_rom_switch();
2020-10-08 02:04:42 +02:00
uint32_t boot_mode = sc64_get_boot_mode();
2020-10-08 02:04:42 +02:00
uint32_t skip_menu = (boot_mode & SC64_CART_BOOT_SKIP_MENU);
uint32_t cic_seed_override = (boot_mode & SC64_CART_BOOT_CIC_SEED_OVERRIDE);
uint32_t tv_type_override = (boot_mode & SC64_CART_BOOT_TV_TYPE_OVERRIDE);
uint32_t ddipl_override = (boot_mode & SC64_CART_BOOT_DDIPL_OVERRIDE);
tv_type_t tv_type = ((boot_mode & SC64_CART_BOOT_TV_TYPE_MASK) >> SC64_CART_BOOT_TV_TYPE_BIT);
uint16_t cic_seed = ((boot_mode & SC64_CART_BOOT_CIC_SEED_MASK) >> SC64_CART_BOOT_CIC_SEED_BIT);
if (!skip_menu) {
sc64_sd_fs_error_t sd_error = sc64_sd_fs_load_rom(MENU_FILE_PATH);
2020-10-08 02:04:42 +02:00
menu_load_error_t error = E_MENU_OK;
switch (sd_error) {
case SC64_SD_FS_NO_CARD:
error = E_MENU_ERROR_NO_CARD;
break;
case SC64_SD_FS_NO_FILESYSTEM:
error = E_MENU_ERROR_NO_FILESYSTEM;
break;
case SC64_SD_FS_NO_FILE:
error = E_MENU_ERROR_NO_FILE;
break;
case SC64_SD_FS_READ_ERROR:
error = E_MENU_ERROR_READ_ERROR;
break;
case SC64_SD_FS_OTHER_ERROR:
error = E_MENU_ERROR_OTHER_ERROR;
break;
default:
break;
2020-10-08 02:04:42 +02:00
}
if (error != E_MENU_OK) {
2021-02-09 23:58:02 +01:00
loader_display_error_and_halt(error, MENU_FILE_PATH);
2020-10-08 02:04:42 +02:00
}
}
if (ddipl_override) {
sc64_enable_ddipl();
} else {
sc64_disable_ddipl();
}
cart_header_t *cart_header = boot_load_cart_header();
if (!cic_seed_override) {
cic_seed = boot_get_cic_seed(cart_header);
}
if (!tv_type_override) {
tv_type = boot_get_tv_type(cart_header);
}
2020-10-08 02:04:42 +02:00
2021-02-09 23:58:02 +01:00
loader_cleanup();
boot(cart_header, cic_seed, tv_type, ddipl_override);
2020-10-08 02:04:42 +02:00
}