Add initial work towards patch support

This commit is contained in:
Robin Jones 2024-01-11 00:38:07 +00:00
parent 0996e88fa1
commit e3ab616137
8 changed files with 184 additions and 0 deletions

View File

@ -46,6 +46,7 @@ SRCS = \
menu/path.c \
menu/png_decoder.c \
menu/rom_info.c \
menu/rom_patcher.c \
menu/settings.c \
menu/sound.c \
menu/usb_comm.c \
@ -58,6 +59,7 @@ SRCS = \
menu/views/load_disk.c \
menu/views/load_emulator.c \
menu/views/load_rom.c \
menu/views/load_patch.c \
menu/views/music_player.c \
menu/views/startup.c \
menu/views/system_info.c \

View File

@ -151,6 +151,7 @@ static struct views_s {
{ view_rtc_init, view_rtc_display }, // MENU_MODE_RTC
{ view_load_rom_init, view_load_rom_display }, // MENU_MODE_LOAD_ROM
{ view_load_disk_init, view_load_disk_display }, // MENU_MODE_LOAD_DISK
{ view_load_rom_patch_init, view_load_rom_patch_display }, // MENU_MODE_LOAD_PATCH
{ view_load_emulator_init, view_load_emulator_display }, // MENU_MODE_LOAD_EMULATOR
{ view_error_init, view_error_display }, // MENU_MODE_ERROR
{ view_fault_init, view_fault_display }, // MENU_MODE_FAULT

View File

@ -12,6 +12,7 @@
#include "boot/boot.h"
#include "disk_info.h"
#include "rom_patcher.h"
#include "flashcart/flashcart.h"
#include "path.h"
#include "rom_info.h"
@ -35,6 +36,7 @@ typedef enum {
MENU_MODE_RTC,
MENU_MODE_LOAD_ROM,
MENU_MODE_LOAD_DISK,
MENU_MODE_LOAD_PATCH,
MENU_MODE_LOAD_EMULATOR,
MENU_MODE_ERROR,
MENU_MODE_FAULT,
@ -47,6 +49,7 @@ typedef enum {
ENTRY_TYPE_DIR,
ENTRY_TYPE_ROM,
ENTRY_TYPE_DISK,
ENTRY_TYPE_PATCH,
ENTRY_TYPE_EMULATOR,
ENTRY_TYPE_SAVE,
ENTRY_TYPE_IMAGE,
@ -102,6 +105,8 @@ typedef struct {
rom_info_t rom_info;
path_t *disk_path;
disk_info_t disk_info;
path_t *patch_path;
//patch_info_t patch_info;
} load;
} menu_t;

0
src/menu/rom_patcher.c Normal file
View File

24
src/menu/rom_patcher.h Normal file
View File

@ -0,0 +1,24 @@
/**
* @file patcher.h
* @brief N64 ROM patcher
* @ingroup menu
*/
#ifndef ROM_PATCHER_H__
#define ROM_PATCHER_H__
#include <stdbool.h>
#include <stdint.h>
/** @brief Patch state enumeration. */
typedef enum {
PATCH_OK,
PATCH_ERR_IO,
PATCH_ERR_NO_FILE,
PATCH_ERR_INVALID,
} rom_patcher_err_t;
rom_patcher_err_t rom_patcher_load (char *path);
#endif

View File

@ -34,6 +34,10 @@ static int compare_entry (const void *pa, const void *pb) {
return -1;
} else if (b->type == ENTRY_TYPE_DISK) {
return 1;
} else if (a->type == ENTRY_TYPE_PATCH) {
return -1;
} else if (b->type == ENTRY_TYPE_PATCH) {
return 1;
} else if (a->type == ENTRY_TYPE_EMULATOR) {
return -1;
} else if (b->type == ENTRY_TYPE_EMULATOR) {
@ -294,6 +298,9 @@ static void process (menu_t *menu) {
case ENTRY_TYPE_DISK:
menu->next_mode = MENU_MODE_LOAD_DISK;
break;
case ENTRY_TYPE_PATCH:
menu->next_mode = MENU_MODE_LOAD_PATCH;
break;
case ENTRY_TYPE_EMULATOR:
menu->next_mode = MENU_MODE_LOAD_EMULATOR;
break;
@ -336,6 +343,7 @@ static void draw (menu_t *menu, surface_t *d) {
case ENTRY_TYPE_DIR: action = "A: Enter"; break;
case ENTRY_TYPE_ROM: action = "A: Load"; break;
case ENTRY_TYPE_DISK: action = "A: Load"; break;
case ENTRY_TYPE_PATCH: action = "A: Load"; break;
case ENTRY_TYPE_IMAGE: action = "A: Show"; break;
case ENTRY_TYPE_MUSIC: action = "A: Play"; break;
default: action = "A: Info"; break;

141
src/menu/views/load_patch.c Normal file
View File

@ -0,0 +1,141 @@
#include "../cart_load.h"
#include "../rom_patcher.h"
#include "boot/boot.h"
#include "views.h"
static bool load_pending;
static bool load_rom;
// static char *convert_error_message (rom_patcher_err_t err) {
// switch (err) {
// case PATCH_ERR_IO: return "I/O error during loading patch file information";
// case PATCH_ERR_NO_FILE: return "Couldn't open patch file";
// case PATCH_ERR_INVALID: return "Invalid patch file";
// default: return "Unknown patch info load error";
// }
// }
static void process (menu_t *menu) {
if (menu->actions.enter) {
load_pending = true;
load_rom = false;
} else if (menu->actions.options && menu->load.rom_path) {
load_pending = true;
load_rom = true;
} else if (menu->actions.back) {
menu->next_mode = MENU_MODE_BROWSER;
}
}
static void draw (menu_t *menu, surface_t *d) {
rdpq_attach(d, NULL);
component_background_draw();
if (load_pending) {
component_loader_draw(0.0f);
} else {
component_layout_draw();
component_main_text_draw(
ALIGN_CENTER, VALIGN_TOP,
"Patch information\n"
"\n"
"%s",
menu->browser.entry->name
);
component_main_text_draw(
ALIGN_LEFT, VALIGN_TOP,
"\n"
"\n"
"\n"
" %s%s",
menu->load.rom_path ? "ROM: " : "",
menu->load.rom_path ? path_last_get(menu->load.rom_path) : ""
);
component_actions_bar_text_draw(
ALIGN_LEFT, VALIGN_TOP,
"A: Load ROM\n"
"B: Exit"
);
if (menu->load.rom_path) {
component_actions_bar_text_draw(
ALIGN_RIGHT, VALIGN_TOP,
"R: Load patched ROM"
);
}
}
rdpq_detach_show();
}
static void draw_progress (float progress) {
surface_t *d = (progress >= 1.0f) ? display_get() : display_try_get();
if (d) {
rdpq_attach(d, NULL);
component_background_draw();
component_loader_draw(progress);
rdpq_detach_show();
}
}
static void load (menu_t *menu) {
cart_load_err_t err;
if (menu->load.rom_path && load_rom) {
err = cart_load_n64_rom_and_save(menu, draw_progress);
if (err != CART_LOAD_OK) {
menu_show_error(menu, cart_load_convert_error_message(err));
return;
}
}
// err = cart_load_rom_and_patch(menu, draw_progress);
// if (err != CART_LOAD_OK) {
// menu_show_error(menu, cart_load_convert_error_message(err));
// return;
// }
menu->next_mode = MENU_MODE_BOOT;
menu->boot_params->device_type = BOOT_DEVICE_TYPE_ROM;
menu->boot_params->tv_type = BOOT_TV_TYPE_PASSTHROUGH;
menu->boot_params->detect_cic_seed = true;
}
void view_load_rom_patch_init (menu_t *menu) {
if (menu->load.patch_path) {
path_free(menu->load.patch_path);
menu->load.patch_path = NULL;
}
load_pending = false;
menu->load.patch_path = path_clone_push(menu->browser.directory, menu->browser.entry->name);
// rom_patcher_err_t err = patch_info_load(path_get(menu->load.patch_path), &menu->load.patch_info);
// if (err != PATCH_OK) {
// menu_show_error(menu, convert_error_message(err));
// }
}
void view_load_rom_patch_display (menu_t *menu, surface_t *display) {
process(menu);
draw(menu, display);
if (load_pending) {
load_pending = false;
load(menu);
}
}

View File

@ -44,6 +44,9 @@ void view_load_rom_display (menu_t *menu, surface_t *display);
void view_load_disk_init (menu_t *menu);
void view_load_disk_display (menu_t *menu, surface_t *display);
void view_load_rom_patch_init (menu_t *menu);
void view_load_rom_patch_display (menu_t *menu, surface_t *display);
void view_settings_init (menu_t *menu);
void view_settings_display (menu_t *menu, surface_t *display);