Skip to content

Commit

Permalink
format files again
Browse files Browse the repository at this point in the history
  • Loading branch information
AngheloAlf committed May 25, 2024
1 parent fe500e3 commit c69f43c
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 38 deletions.
3 changes: 2 additions & 1 deletion librecomp/include/recomp_overlays.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define __RECOMP_OVERLAYS_H__

#include <cstdint>

#include "sections.h"

namespace recomp {
Expand All @@ -18,7 +19,7 @@ namespace recomp {

extern void register_overlays(const overlay_section_table_data_t& sections, const overlays_by_index_t& overlays);
extern void register_patch_section(SectionTableEntry* code_sections);
};
}; // namespace recomp

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);
Expand Down
21 changes: 11 additions & 10 deletions librecomp/src/overlays.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
#include "recomp_overlays.h"
#include "sections.h"

static recomp::overlay_section_table_data_t sections_info {};
static recomp::overlays_by_index_t overlays_info {};
static recomp::overlay_section_table_data_t sections_info{};
static recomp::overlays_by_index_t overlays_info{};

void recomp::register_overlays(const recomp::overlay_section_table_data_t& sections, const recomp::overlays_by_index_t& overlays) {
sections_info = sections;
Expand Down Expand Up @@ -58,12 +58,13 @@ int32_t* section_addresses = nullptr;
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(&sections_info.code_sections[0], &sections_info.code_sections[sections_info.num_code_sections], rom,
auto lower = std::lower_bound(
&sections_info.code_sections[0], &sections_info.code_sections[sections_info.num_code_sections], rom,
[](const SectionTableEntry& entry, uint32_t addr) {
return entry.rom_addr < addr;
}
);
auto upper = std::upper_bound(&sections_info.code_sections[0], &sections_info.code_sections[sections_info.num_code_sections], (uint32_t)(rom + size),
});
auto upper = std::upper_bound(
&sections_info.code_sections[0], &sections_info.code_sections[sections_info.num_code_sections], (uint32_t)(rom + size),
[](uint32_t addr, const SectionTableEntry& entry) {
return addr < entry.size + entry.rom_addr;
});
Expand Down Expand Up @@ -146,18 +147,18 @@ extern "C" void unload_overlays(int32_t ram_addr, uint32_t size) {
void load_patch_functions();

void init_overlays() {
section_addresses = (int32_t *)malloc(sections_info.total_num_sections * sizeof(int32_t));
section_addresses = (int32_t*)malloc(sections_info.total_num_sections * sizeof(int32_t));

for (size_t section_index = 0; section_index < sections_info.total_num_sections; section_index++) {
section_addresses[sections_info.code_sections[section_index].index] = sections_info.code_sections[section_index].ram_addr;
}

// Sort the executable sections by rom address
std::sort(&sections_info.code_sections[0], &sections_info.code_sections[sections_info.num_code_sections],
std::sort(
&sections_info.code_sections[0], &sections_info.code_sections[sections_info.num_code_sections],
[](const SectionTableEntry& a, const SectionTableEntry& b) {
return a.rom_addr < b.rom_addr;
}
);
});

load_patch_functions();
}
Expand Down
2 changes: 1 addition & 1 deletion librecomp/src/patch_loading.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#include <vector>

#include "recomp.h"
#include "sections.h"
#include "recomp_overlays.h"
#include "sections.h"

static SectionTableEntry* code_sections = nullptr;

Expand Down
52 changes: 26 additions & 26 deletions librecomp/src/recomp.cpp
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
#include <array>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <optional>
#include <mutex>
#include <array>
#include <memory>
#include <mutex>
#include <optional>
#include <unordered_map>
#include <unordered_set>

#ifdef _WIN32
#include <Shlobj.h>
# include <Shlobj.h>
#elif defined(__linux__)
#include <pwd.h>
# include <pwd.h>
#endif

#include "recomp.h"
Expand Down Expand Up @@ -89,7 +88,7 @@ static std::vector<uint8_t> read_file(const std::filesystem::path& path) {

bool write_file(const std::filesystem::path& path, const std::vector<uint8_t>& data) {
std::ofstream out_file{ path, std::ios::binary };
recomp::g

if (!out_file.good()) {
return false;
}
Expand All @@ -107,7 +106,7 @@ std::filesystem::path recomp::get_app_folder_path() {
PWSTR known_path = NULL;
HRESULT result = SHGetKnownFolderPath(FOLDERID_LocalAppData, 0, NULL, &known_path);
if (result == S_OK) {
recomp_dir = std::filesystem::path{known_path} / recomp::get_program_id();
recomp_dir = std::filesystem::path{ known_path } / recomp::get_program_id();
}

CoTaskMemFree(known_path);
Expand All @@ -118,9 +117,9 @@ std::filesystem::path recomp::get_app_folder_path() {
homedir = getpwuid(getuid())->pw_dir;
}

if (homedir != nullptr) {
recomp_dir = std::filesystem::path{homedir} / (std::u8string{u8".config/"} + recomp::get_program_id());
}
if (homedir != nullptr) {
recomp_dir = std::filesystem::path{ homedir } / (std::u8string{ u8".config/" } + recomp::get_program_id());
}
#endif

return recomp_dir;
Expand Down Expand Up @@ -455,20 +454,20 @@ void recomp::start(
std::unique_ptr<uint8_t[]> rdram_buffer = std::make_unique<uint8_t[]>(ultramodern::rdram_size);
std::memset(rdram_buffer.get(), 0, ultramodern::rdram_size);

std::thread game_thread{[](ultramodern::WindowHandle window_handle, uint8_t* rdram) {
debug_printf("[Recomp] Starting\n");
std::thread game_thread{
[](ultramodern::WindowHandle window_handle, uint8_t* rdram) {
debug_printf("[Recomp] Starting\n");

ultramodern::set_native_thread_name("Game Start Thread");
ultramodern::set_native_thread_name("Game Start Thread");

ultramodern::preinit(rdram, window_handle);
ultramodern::preinit(rdram, window_handle);

game_status.wait(GameStatus::None);
recomp_context context{};

switch (game_status.load()) {
// TODO refactor this to allow a project to specify what entrypoint function to run for a give game.
case GameStatus::Running:
{
case GameStatus::Running: {
if (!recomp::load_stored_rom(current_game.value())) {
recomp::message_box("Error opening stored ROM! Please restart this program.");
}
Expand All @@ -481,20 +480,21 @@ void recomp::start(
try {
recomp_entrypoint(rdram, &context);
} catch (ultramodern::thread_terminated& terminated) {

}
}
break;
} break;

case GameStatus::Quit:
break;
case GameStatus::Quit:
break;

case GameStatus::None:
break;
}
case GameStatus::None:
break;
}

debug_printf("[Recomp] Quitting\n");
}, window_handle, rdram_buffer.get(),};
debug_printf("[Recomp] Quitting\n");
},
window_handle,
rdram_buffer.get(),
};

while (!exited) {
ultramodern::sleep_milliseconds(1);
Expand Down

0 comments on commit c69f43c

Please sign in to comment.