Converted manual recompiler edits for overlay loading into patches

This commit is contained in:
Mr-Wiseguy 2024-05-17 02:03:36 -04:00
parent 5bd9956d75
commit 2b0fcd0b77
9 changed files with 100 additions and 21 deletions

10
include/recomp_overlays.h Normal file
View File

@ -0,0 +1,10 @@
#ifndef __RECOMP_OVERLAYS_H__
#define __RECOMP_OVERLAYS_H__
#include <cstdint>
extern "C" void load_overlays(uint32_t rom, int32_t ram_addr, uint32_t size);
extern "C" void unload_overlays(int32_t ram_addr, uint32_t size);
void init_overlays();
#endif

View File

@ -3,6 +3,7 @@
#include "patch_helpers.h" #include "patch_helpers.h"
DECLARE_FUNC(void, recomp_load_overlays, u32 rom, void* ram, u32 size);
DECLARE_FUNC(void, recomp_puts, const char* data, u32 size); DECLARE_FUNC(void, recomp_puts, const char* data, u32 size);
DECLARE_FUNC(void, recomp_exit); DECLARE_FUNC(void, recomp_exit);
DECLARE_FUNC(void, recomp_handle_quicksave_actions, OSMesgQueue* enter_mq, OSMesgQueue* exit_mq); DECLARE_FUNC(void, recomp_handle_quicksave_actions, OSMesgQueue* enter_mq, OSMesgQueue* exit_mq);

View File

@ -9,6 +9,7 @@
#define osFlashWriteArray osFlashWriteArray_recomp #define osFlashWriteArray osFlashWriteArray_recomp
#define osFlashWriteBuffer osFlashWriteBuffer_recomp #define osFlashWriteBuffer osFlashWriteBuffer_recomp
#define osWritebackDCache osWritebackDCache_recomp #define osWritebackDCache osWritebackDCache_recomp
#define osInvalICache osInvalICache_recomp
#define osGetTime osGetTime_recomp #define osGetTime osGetTime_recomp
#define osContStartReadData osContStartReadData_recomp #define osContStartReadData osContStartReadData_recomp

View File

@ -0,0 +1,75 @@
#include "patches.h"
#include "misc_funcs.h"
#include "loadfragment.h"
void Main_ClearMemory(void* begin, void* end);
void Main_InitMemory(void);
void Main_InitScreen(void);
// @recomp Patched to load the code segment in the recomp runtime.
void Main_Init(void) {
DmaRequest dmaReq;
OSMesgQueue mq;
OSMesg msg[1];
size_t prevSize;
osCreateMesgQueue(&mq, msg, ARRAY_COUNT(msg));
prevSize = gDmaMgrDmaBuffSize;
gDmaMgrDmaBuffSize = 0;
// @recomp Load the code segment in the recomp runtime.
recomp_load_overlays(SEGMENT_ROM_START(code), SEGMENT_START(code), SEGMENT_ROM_END(code) - SEGMENT_ROM_START(code));
DmaMgr_SendRequestImpl(&dmaReq, SEGMENT_START(code), SEGMENT_ROM_START(code),
SEGMENT_ROM_END(code) - SEGMENT_ROM_START(code), 0, &mq, NULL);
Main_InitScreen();
Main_InitMemory();
osRecvMesg(&mq, NULL, OS_MESG_BLOCK);
gDmaMgrDmaBuffSize = prevSize;
Main_ClearMemory(SEGMENT_BSS_START(code), SEGMENT_BSS_END(code));
}
void Overlay_Relocate(void* allocatedRamAddr, OverlayRelocationSection* ovlRelocs, uintptr_t vramStart);
// @recomp Patched to load the overlay in the recomp runtime.
size_t Overlay_Load(uintptr_t vromStart, uintptr_t vromEnd, void* ramStart, void* ramEnd, void* allocatedRamAddr) {
uintptr_t vramStart = (uintptr_t)ramStart;
uintptr_t vramEnd = (uintptr_t)ramEnd;
s32 size = vromEnd - vromStart;
uintptr_t end;
OverlayRelocationSection* ovlRelocs;
// @recomp Load the overlay in the recomp runtime.
recomp_load_overlays(vromStart, allocatedRamAddr, vromEnd - vromStart);
if (gOverlayLogSeverity >= 3) {}
if (gOverlayLogSeverity >= 3) {}
end = (uintptr_t)allocatedRamAddr + size;
DmaMgr_SendRequest0(allocatedRamAddr, vromStart, size);
ovlRelocs = (OverlayRelocationSection*)(end - ((s32*)end)[-1]);
if (gOverlayLogSeverity >= 3) {}
if (gOverlayLogSeverity >= 3) {}
Overlay_Relocate(allocatedRamAddr, ovlRelocs, vramStart);
if (ovlRelocs->bssSize != 0) {
if (gOverlayLogSeverity >= 3) {}
bzero((void*)end, ovlRelocs->bssSize);
}
size = vramEnd - vramStart;
osWritebackDCache(allocatedRamAddr, size);
osInvalICache(allocatedRamAddr, size);
if (gOverlayLogSeverity >= 3) {}
return size;
}

View File

@ -50,3 +50,5 @@ recomp_get_mouse_deltas = 0x8F000080;
bcmp_recomp = 0x8F000084; bcmp_recomp = 0x8F000084;
osGetTime_recomp = 0x8F000088; osGetTime_recomp = 0x8F000088;
recomp_autosave_enabled = 0x8F00008C; recomp_autosave_enabled = 0x8F00008C;
recomp_load_overlays = 0x8F000090;
osInvalICache_recomp = 0x8F000094;

View File

@ -1,6 +1,7 @@
#include <cmath> #include <cmath>
#include "recomp.h" #include "recomp.h"
#include "recomp_overlays.h"
#include "recomp_config.h" #include "recomp_config.h"
#include "recomp_input.h" #include "recomp_input.h"
#include "recomp_ui.h" #include "recomp_ui.h"
@ -93,3 +94,11 @@ extern "C" void recomp_time_us(uint8_t* rdram, recomp_context* ctx) {
extern "C" void recomp_autosave_enabled(uint8_t* rdram, recomp_context* ctx) { extern "C" void recomp_autosave_enabled(uint8_t* rdram, recomp_context* ctx) {
_return(ctx, static_cast<s32>(recomp::get_autosave_mode() == recomp::AutosaveMode::On)); _return(ctx, static_cast<s32>(recomp::get_autosave_mode() == recomp::AutosaveMode::On));
} }
extern "C" void recomp_load_overlays(uint8_t * rdram, recomp_context * ctx) {
u32 rom = _arg<0, u32>(rdram, ctx);
PTR(void) ram = _arg<1, PTR(void)>(rdram, ctx);
u32 size = _arg<2, u32>(rdram, ctx);
load_overlays(rom, ram, size);
}

View File

@ -2,6 +2,7 @@
#include <algorithm> #include <algorithm>
#include <vector> #include <vector>
#include "recomp.h" #include "recomp.h"
#include "recomp_overlays.h"
#include "../RecompiledFuncs/recomp_overlays.inl" #include "../RecompiledFuncs/recomp_overlays.inl"
constexpr size_t num_code_sections = ARRLEN(section_table); constexpr size_t num_code_sections = ARRLEN(section_table);

View File

@ -11,6 +11,7 @@
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
#include "recomp.h" #include "recomp.h"
#include "recomp_overlays.h"
#include "recomp_game.h" #include "recomp_game.h"
#include "recomp_config.h" #include "recomp_config.h"
#include "xxHash/xxh3.h" #include "xxHash/xxh3.h"
@ -301,9 +302,6 @@ void run_thread_function(uint8_t* rdram, uint64_t addr, uint64_t sp, uint64_t ar
extern "C" void recomp_entrypoint(uint8_t * rdram, recomp_context * ctx); extern "C" void recomp_entrypoint(uint8_t * rdram, recomp_context * ctx);
gpr get_entrypoint_address(); gpr get_entrypoint_address();
const char* get_rom_name(); const char* get_rom_name();
void init_overlays();
extern "C" void load_overlays(uint32_t rom, int32_t ram_addr, uint32_t size);
extern "C" void unload_overlays(int32_t ram_addr, uint32_t size);
void read_patch_data(uint8_t* rdram, gpr patch_data_address) { void read_patch_data(uint8_t* rdram, gpr patch_data_address) {
for (size_t i = 0; i < sizeof(mm_patches_bin); i++) { for (size_t i = 0; i < sizeof(mm_patches_bin); i++) {

View File

@ -22,24 +22,6 @@ ignored = [
"D_80186028" "D_80186028"
] ]
# Hooks
# Function definition for the overlay loading function.
[[patches.func]]
name = "load_overlays"
args = ["u32", "u32", "u32"]
# Function hooks for overlay loading.
[[patches.hook]]
func = "Main_Init"
text = " load_overlays((uint32_t)ctx->r6, (uint32_t)ctx->r5, (uint32_t)ctx->r7);"
after_vram = 0x800802A4
[[patches.hook]]
func = "Overlay_Load"
text = " load_overlays((uint32_t)ctx->r4, MEM_W(0x10, ctx->r29), (uint32_t)(ctx->r5 - ctx->r4));"
# No after_vram means this will be placed at the start of the function
# Single-instruction patches # Single-instruction patches
# Write audio dlists to kseg0 (cached, 0x80...) addresses instead of kseg1 (uncached, 0xA0...) ones. # Write audio dlists to kseg0 (cached, 0x80...) addresses instead of kseg1 (uncached, 0xA0...) ones.