mirror of
https://github.com/N64Recomp/N64ModernRuntime.git
synced 2026-05-11 03:12:15 +00:00
Expect overlays to be set
This commit is contained in:
parent
32632ab2ff
commit
a18247adab
6 changed files with 27 additions and 20 deletions
|
|
@ -5,6 +5,9 @@ project(N64ModernRuntime)
|
|||
set(CMAKE_CXX_STANDARD 20)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED True)
|
||||
|
||||
|
||||
set(CMAKE_LIBRARY_PATH "/usr/lib/gcc/aarch64-linux-gnu/11")
|
||||
|
||||
add_subdirectory(ultramodern)
|
||||
add_subdirectory(librecomp)
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,11 @@
|
|||
#define __RECOMP_OVERLAYS_H__
|
||||
|
||||
#include <cstdint>
|
||||
#include "sections.h"
|
||||
|
||||
extern "C" SectionTableEntry* get_section_table();
|
||||
extern "C" size_t get_num_sections();
|
||||
extern "C" int* get_overlay_sections_by_index();
|
||||
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -3,9 +3,9 @@
|
|||
#include <vector>
|
||||
#include "recomp.h"
|
||||
#include "recomp_overlays.h"
|
||||
#include "../RecompiledFuncs/recomp_overlays.inl"
|
||||
#include "sections.h"
|
||||
|
||||
constexpr size_t num_code_sections = ARRLEN(section_table);
|
||||
constexpr size_t num_code_sections = ARRLEN(get_section_table());
|
||||
|
||||
// SectionTableEntry sections[] defined in recomp_overlays.inl
|
||||
|
||||
|
|
@ -27,7 +27,7 @@ std::vector<LoadedSection> loaded_sections{};
|
|||
std::unordered_map<int32_t, recomp_func_t*> func_map{};
|
||||
|
||||
void load_overlay(size_t section_table_index, int32_t ram) {
|
||||
const SectionTableEntry& section = section_table[section_table_index];
|
||||
const SectionTableEntry& section = get_section_table()[section_table_index];
|
||||
for (size_t function_index = 0; function_index < section.num_funcs; function_index++) {
|
||||
const FuncEntry& func = section.funcs[function_index];
|
||||
func_map[ram + func.offset] = func.func;
|
||||
|
|
@ -44,34 +44,34 @@ void load_special_overlay(const SectionTableEntry& section, int32_t ram) {
|
|||
}
|
||||
|
||||
|
||||
extern "C" {
|
||||
int32_t section_addresses[num_sections];
|
||||
}
|
||||
//extern "C" {
|
||||
//int32_t section_addresses[get_num_sections()];
|
||||
//}
|
||||
|
||||
extern "C" void load_overlays(uint32_t rom, int32_t ram_addr, uint32_t size) {
|
||||
// Search for the first section that's included in the loaded rom range
|
||||
// Sections were sorted by `init_overlays` so we can use the bounds functions
|
||||
auto lower = std::lower_bound(§ion_table[0], §ion_table[num_code_sections], rom,
|
||||
auto lower = std::lower_bound(&get_section_table()[0], &get_section_table()[num_code_sections], rom,
|
||||
[](const SectionTableEntry& entry, uint32_t addr) {
|
||||
return entry.rom_addr < addr;
|
||||
}
|
||||
);
|
||||
auto upper = std::upper_bound(§ion_table[0], §ion_table[num_code_sections], (uint32_t)(rom + size),
|
||||
auto upper = std::upper_bound(&get_section_table()[0], &get_section_table()[num_code_sections], (uint32_t)(rom + size),
|
||||
[](uint32_t addr, const SectionTableEntry& entry) {
|
||||
return addr < entry.size + entry.rom_addr;
|
||||
}
|
||||
);
|
||||
// Load the overlays that were found
|
||||
for (auto it = lower; it != upper; ++it) {
|
||||
load_overlay(std::distance(§ion_table[0], it), it->rom_addr - rom + ram_addr);
|
||||
load_overlay(std::distance(&get_section_table()[0], it), it->rom_addr - rom + ram_addr);
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" void unload_overlays(int32_t ram_addr, uint32_t size);
|
||||
|
||||
extern "C" void unload_overlay_by_id(uint32_t id) {
|
||||
uint32_t section_table_index = overlay_sections_by_index[id];
|
||||
const SectionTableEntry& section = section_table[section_table_index];
|
||||
uint32_t section_table_index = get_overlay_sections_by_index()[id];
|
||||
const SectionTableEntry& section = get_section_table()[section_table_index];
|
||||
|
||||
auto find_it = std::find_if(loaded_sections.begin(), loaded_sections.end(), [section_table_index](const LoadedSection& s) { return s.section_table_index == section_table_index; });
|
||||
|
||||
|
|
@ -90,8 +90,8 @@ extern "C" void unload_overlay_by_id(uint32_t id) {
|
|||
}
|
||||
|
||||
extern "C" void load_overlay_by_id(uint32_t id, uint32_t ram_addr) {
|
||||
uint32_t section_table_index = overlay_sections_by_index[id];
|
||||
const SectionTableEntry& section = section_table[section_table_index];
|
||||
uint32_t section_table_index = get_overlay_sections_by_index()[id];
|
||||
const SectionTableEntry& section = get_section_table()[section_table_index];
|
||||
int32_t prev_address = section_addresses[section.index];
|
||||
if (/*ram_addr >= 0x80000000 && ram_addr < 0x81000000) {*/ prev_address == section.ram_addr) {
|
||||
load_overlay(section_table_index, ram_addr);
|
||||
|
|
@ -105,7 +105,7 @@ extern "C" void load_overlay_by_id(uint32_t id, uint32_t ram_addr) {
|
|||
|
||||
extern "C" void unload_overlays(int32_t ram_addr, uint32_t size) {
|
||||
for (auto it = loaded_sections.begin(); it != loaded_sections.end();) {
|
||||
const auto& section = section_table[it->section_table_index];
|
||||
const auto& section = get_section_table()[it->section_table_index];
|
||||
|
||||
// Check if the unloaded region overlaps with the loaded section
|
||||
if (ram_addr < (it->loaded_ram_addr + section.size) && (ram_addr + size) >= it->loaded_ram_addr) {
|
||||
|
|
@ -140,11 +140,11 @@ void load_patch_functions();
|
|||
|
||||
void init_overlays() {
|
||||
for (size_t section_index = 0; section_index < num_code_sections; section_index++) {
|
||||
section_addresses[section_table[section_index].index] = section_table[section_index].ram_addr;
|
||||
section_addresses[get_section_table()[section_index].index] = get_section_table()[section_index].ram_addr;
|
||||
}
|
||||
|
||||
// Sort the executable sections by rom address
|
||||
std::sort(§ion_table[0], §ion_table[num_code_sections],
|
||||
std::sort(&get_section_table()[0], &get_section_table()[num_code_sections],
|
||||
[](const SectionTableEntry& a, const SectionTableEntry& b) {
|
||||
return a.rom_addr < b.rom_addr;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,10 +2,11 @@
|
|||
#include <algorithm>
|
||||
#include <vector>
|
||||
#include "recomp.h"
|
||||
#include "../../RecompiledPatches/recomp_overlays.inl"
|
||||
#include "sections.h"
|
||||
#include "recomp_overlays.h"
|
||||
|
||||
void load_special_overlay(const SectionTableEntry& section, int32_t ram);
|
||||
|
||||
void load_patch_functions() {
|
||||
load_special_overlay(section_table[0], section_table[0].ram_addr);
|
||||
load_special_overlay(get_section_table()[0], get_section_table()[0].ram_addr);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@
|
|||
#include "recomp_game.h"
|
||||
#include "xxHash/xxh3.h"
|
||||
#include <ultramodern/ultramodern.hpp>
|
||||
//#include "../../RecompiledPatches/patches_bin.h"
|
||||
|
||||
#ifdef _MSC_VER
|
||||
inline uint32_t byteswap(uint32_t val) {
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@
|
|||
|
||||
#if defined(_WIN32)
|
||||
# define WIN32_LEAN_AND_MEAN
|
||||
# include <Windows.h>
|
||||
#elif defined(__ANDROID__)
|
||||
# include "android/native_window.h"
|
||||
#elif defined(__linux__)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue