Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion librecomp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ add_library(librecomp STATIC
"${CMAKE_CURRENT_SOURCE_DIR}/src/eep.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/euc-jp.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/extensions.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/files.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/flash.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/heap.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/math_routines.cpp"
Expand Down
16 changes: 2 additions & 14 deletions librecomp/include/librecomp/game.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,10 @@
#include "recomp.h"
#include "rsp.hpp"
#include <ultramodern/ultramodern.hpp>
#include <ultramodern/save.hpp>

namespace recomp {
enum class SaveType {
None,
Eep4k,
Eep16k,
Sram,
Flashram,
AllowAll, // Allows all save types to work and reports eeprom size as 16kbit.
};

using SaveType = ultramodern::SaveType;
struct GameEntry {
uint64_t rom_hash;
std::string internal_name;
Expand Down Expand Up @@ -109,11 +102,6 @@ namespace recomp {
///
void start(const Configuration& cfg);

SaveType get_save_type();
bool eeprom_allowed();
bool sram_allowed();
bool flashram_allowed();

void start_game(const std::u8string& game_id);
std::u8string current_game_id();
std::string current_mod_game_id();
Expand Down
47 changes: 31 additions & 16 deletions librecomp/src/eep.cpp
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
#include "recomp.h"
#include "librecomp/game.hpp"

#include "ultramodern/ultra64.h"

void save_write(RDRAM_ARG PTR(void) rdram_address, uint32_t offset, uint32_t count);
void save_read(RDRAM_ARG PTR(void) rdram_address, uint32_t offset, uint32_t count);
#include <ultramodern/save.hpp>
#include <ultramodern/ultra64.h>

constexpr int eeprom_block_size = 8;
static std::vector<uint8_t> save_buffer;

extern "C" void osEepromProbe_recomp(uint8_t* rdram, recomp_context* ctx) {
switch (recomp::get_save_type()) {
case recomp::SaveType::AllowAll:
case recomp::SaveType::Eep16k:
switch (ultramodern::get_save_type()) {
case ultramodern::SaveType::AllowAll:
case ultramodern::SaveType::Eep16k:
ctx->r2 = 0x02; // EEPROM_TYPE_16K
break;
case recomp::SaveType::Eep4k:
case ultramodern::SaveType::Eep4k:
ctx->r2 = 0x01; // EEPROM_TYPE_4K
break;
default:
Expand All @@ -24,7 +23,7 @@ extern "C" void osEepromProbe_recomp(uint8_t* rdram, recomp_context* ctx) {
}

extern "C" void osEepromWrite_recomp(uint8_t* rdram, recomp_context* ctx) {
if (!recomp::eeprom_allowed()) {
if (!ultramodern::eeprom_allowed()) {
ultramodern::error_handling::message_box("Attempted to use EEPROM saving with other save type");
ULTRAMODERN_QUICK_EXIT();
}
Expand All @@ -33,13 +32,17 @@ extern "C" void osEepromWrite_recomp(uint8_t* rdram, recomp_context* ctx) {
gpr buffer = ctx->r6;
int32_t nbytes = eeprom_block_size;

save_write(rdram, buffer, eep_address * eeprom_block_size, nbytes);
save_buffer.resize(nbytes);
for (uint32_t i = 0; i < nbytes; i++) {
save_buffer[i] = MEM_B(i, buffer);
}
ultramodern::save_write_ptr(save_buffer.data(), eep_address * eeprom_block_size, nbytes);

ctx->r2 = 0;
}

extern "C" void osEepromLongWrite_recomp(uint8_t* rdram, recomp_context* ctx) {
if (!recomp::eeprom_allowed()) {
if (!ultramodern::eeprom_allowed()) {
ultramodern::error_handling::message_box("Attempted to use EEPROM saving with other save type");
ULTRAMODERN_QUICK_EXIT();
}
Expand All @@ -50,13 +53,17 @@ extern "C" void osEepromLongWrite_recomp(uint8_t* rdram, recomp_context* ctx) {

assert((nbytes % eeprom_block_size) == 0);

save_write(rdram, buffer, eep_address * eeprom_block_size, nbytes);
save_buffer.resize(nbytes);
for (uint32_t i = 0; i < nbytes; i++) {
save_buffer[i] = MEM_B(i, buffer);
}
ultramodern::save_write_ptr(save_buffer.data(), eep_address * eeprom_block_size, nbytes);

ctx->r2 = 0;
}

extern "C" void osEepromRead_recomp(uint8_t* rdram, recomp_context* ctx) {
if (!recomp::eeprom_allowed()) {
if (!ultramodern::eeprom_allowed()) {
ultramodern::error_handling::message_box("Attempted to use EEPROM saving with other save type");
ULTRAMODERN_QUICK_EXIT();
}
Expand All @@ -65,13 +72,17 @@ extern "C" void osEepromRead_recomp(uint8_t* rdram, recomp_context* ctx) {
gpr buffer = ctx->r6;
int32_t nbytes = eeprom_block_size;

save_read(rdram, buffer, eep_address * eeprom_block_size, nbytes);
save_buffer.resize(nbytes);
ultramodern::save_read_ptr(save_buffer.data(), eep_address * eeprom_block_size, nbytes);
for (uint32_t i = 0; i < nbytes; i++) {
MEM_B(i, buffer) = save_buffer[i];
}

ctx->r2 = 0;
}

extern "C" void osEepromLongRead_recomp(uint8_t* rdram, recomp_context* ctx) {
if (!recomp::eeprom_allowed()) {
if (!ultramodern::eeprom_allowed()) {
ultramodern::error_handling::message_box("Attempted to use EEPROM saving with other save type");
ULTRAMODERN_QUICK_EXIT();
}
Expand All @@ -82,7 +93,11 @@ extern "C" void osEepromLongRead_recomp(uint8_t* rdram, recomp_context* ctx) {

assert((nbytes % eeprom_block_size) == 0);

save_read(rdram, buffer, eep_address * eeprom_block_size, nbytes);
save_buffer.resize(nbytes);
ultramodern::save_read_ptr(save_buffer.data(), eep_address * eeprom_block_size, nbytes);
for (uint32_t i = 0; i < nbytes; i++) {
MEM_B(i, buffer) = save_buffer[i];
}

ctx->r2 = 0;
}
49 changes: 25 additions & 24 deletions librecomp/src/flash.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <array>
#include <cassert>
#include <ultramodern/save.hpp>
#include <ultramodern/ultra64.h>
#include <ultramodern/ultramodern.hpp>
#include "recomp.h"
Expand All @@ -15,15 +16,11 @@ constexpr uint32_t page_count = flash_size / page_size;
constexpr uint32_t sector_size = page_size * pages_per_sector;
constexpr uint32_t sector_count = flash_size / sector_size;

void save_write_ptr(const void* in, uint32_t offset, uint32_t count);
void save_write(RDRAM_ARG PTR(void) rdram_address, uint32_t offset, uint32_t count);
void save_read(RDRAM_ARG PTR(void) rdram_address, uint32_t offset, uint32_t count);
void save_clear(uint32_t start, uint32_t size, char value);

std::array<char, page_size> write_buffer;
std::vector<uint8_t> save_buffer;

extern "C" void osFlashInit_recomp(uint8_t * rdram, recomp_context * ctx) {
if (!recomp::flashram_allowed()) {
if (!ultramodern::flashram_allowed()) {
ultramodern::error_handling::message_box("Attempted to use FlashRAM saving with other save type");
ULTRAMODERN_QUICK_EXIT();
}
Expand All @@ -32,7 +29,7 @@ extern "C" void osFlashInit_recomp(uint8_t * rdram, recomp_context * ctx) {
}

extern "C" void osFlashReadStatus_recomp(uint8_t * rdram, recomp_context * ctx) {
if (!recomp::flashram_allowed()) {
if (!ultramodern::flashram_allowed()) {
ultramodern::error_handling::message_box("Attempted to use FlashRAM saving with other save type");
ULTRAMODERN_QUICK_EXIT();
}
Expand All @@ -43,7 +40,7 @@ extern "C" void osFlashReadStatus_recomp(uint8_t * rdram, recomp_context * ctx)
}

extern "C" void osFlashReadId_recomp(uint8_t * rdram, recomp_context * ctx) {
if (!recomp::flashram_allowed()) {
if (!ultramodern::flashram_allowed()) {
ultramodern::error_handling::message_box("Attempted to use FlashRAM saving with other save type");
ULTRAMODERN_QUICK_EXIT();
}
Expand All @@ -57,7 +54,7 @@ extern "C" void osFlashReadId_recomp(uint8_t * rdram, recomp_context * ctx) {
}

extern "C" void osFlashClearStatus_recomp(uint8_t * rdram, recomp_context * ctx) {
if (!recomp::flashram_allowed()) {
if (!ultramodern::flashram_allowed()) {
ultramodern::error_handling::message_box("Attempted to use FlashRAM saving with other save type");
ULTRAMODERN_QUICK_EXIT();
}
Expand All @@ -66,30 +63,30 @@ extern "C" void osFlashClearStatus_recomp(uint8_t * rdram, recomp_context * ctx)
}

extern "C" void osFlashAllErase_recomp(uint8_t * rdram, recomp_context * ctx) {
if (!recomp::flashram_allowed()) {
if (!ultramodern::flashram_allowed()) {
ultramodern::error_handling::message_box("Attempted to use FlashRAM saving with other save type");
ULTRAMODERN_QUICK_EXIT();
}

save_clear(0, ultramodern::save_size, 0xFF);
ultramodern::save_clear(0, ultramodern::save_size, 0xFF);

ctx->r2 = 0;
}

extern "C" void osFlashAllEraseThrough_recomp(uint8_t * rdram, recomp_context * ctx) {
if (!recomp::flashram_allowed()) {
if (!ultramodern::flashram_allowed()) {
ultramodern::error_handling::message_box("Attempted to use FlashRAM saving with other save type");
ULTRAMODERN_QUICK_EXIT();
}

save_clear(0, ultramodern::save_size, 0xFF);
ultramodern::save_clear(0, ultramodern::save_size, 0xFF);

ctx->r2 = 0;
}

// This function is named sector but really means page.
extern "C" void osFlashSectorErase_recomp(uint8_t * rdram, recomp_context * ctx) {
if (!recomp::flashram_allowed()) {
if (!ultramodern::flashram_allowed()) {
ultramodern::error_handling::message_box("Attempted to use FlashRAM saving with other save type");
ULTRAMODERN_QUICK_EXIT();
}
Expand All @@ -102,14 +99,14 @@ extern "C" void osFlashSectorErase_recomp(uint8_t * rdram, recomp_context * ctx)
return;
}

save_clear(page_num * page_size, page_size, 0xFF);
ultramodern::save_clear(page_num * page_size, page_size, 0xFF);

ctx->r2 = 0;
}

// Same naming issue as above.
extern "C" void osFlashSectorEraseThrough_recomp(uint8_t * rdram, recomp_context * ctx) {
if (!recomp::flashram_allowed()) {
if (!ultramodern::flashram_allowed()) {
ultramodern::error_handling::message_box("Attempted to use FlashRAM saving with other save type");
ULTRAMODERN_QUICK_EXIT();
}
Expand All @@ -122,13 +119,13 @@ extern "C" void osFlashSectorEraseThrough_recomp(uint8_t * rdram, recomp_context
return;
}

save_clear(page_num * page_size, page_size, 0xFF);
ultramodern::save_clear(page_num * page_size, page_size, 0xFF);

ctx->r2 = 0;
}

extern "C" void osFlashCheckEraseEnd_recomp(uint8_t * rdram, recomp_context * ctx) {
if (!recomp::flashram_allowed()) {
if (!ultramodern::flashram_allowed()) {
ultramodern::error_handling::message_box("Attempted to use FlashRAM saving with other save type");
ULTRAMODERN_QUICK_EXIT();
}
Expand All @@ -138,7 +135,7 @@ extern "C" void osFlashCheckEraseEnd_recomp(uint8_t * rdram, recomp_context * ct
}

extern "C" void osFlashWriteBuffer_recomp(uint8_t * rdram, recomp_context * ctx) {
if (!recomp::flashram_allowed()) {
if (!ultramodern::flashram_allowed()) {
ultramodern::error_handling::message_box("Attempted to use FlashRAM saving with other save type");
ULTRAMODERN_QUICK_EXIT();
}
Expand All @@ -160,21 +157,21 @@ extern "C" void osFlashWriteBuffer_recomp(uint8_t * rdram, recomp_context * ctx)
}

extern "C" void osFlashWriteArray_recomp(uint8_t * rdram, recomp_context * ctx) {
if (!recomp::flashram_allowed()) {
if (!ultramodern::flashram_allowed()) {
ultramodern::error_handling::message_box("Attempted to use FlashRAM saving with other save type");
ULTRAMODERN_QUICK_EXIT();
}

uint32_t page_num = ctx->r4;

// Copy the write buffer into the save file
save_write_ptr(write_buffer.data(), page_num * page_size, page_size);
ultramodern::save_write_ptr(write_buffer.data(), page_num * page_size, page_size);

ctx->r2 = 0;
}

extern "C" void osFlashReadArray_recomp(uint8_t * rdram, recomp_context * ctx) {
if (!recomp::flashram_allowed()) {
if (!ultramodern::flashram_allowed()) {
ultramodern::error_handling::message_box("Attempted to use FlashRAM saving with other save type");
ULTRAMODERN_QUICK_EXIT();
}
Expand All @@ -190,7 +187,11 @@ extern "C" void osFlashReadArray_recomp(uint8_t * rdram, recomp_context * ctx) {
uint32_t count = n_pages * page_size;

// Read from the save file into the provided buffer
save_read(PASS_RDRAM dramAddr, offset, count);
save_buffer.resize(count);
ultramodern::save_read_ptr(save_buffer.data(), offset, count);
for (uint32_t i = 0; i < count; i++) {
MEM_B(i, dramAddr) = save_buffer[i];
}

// Send the message indicating read completion
ultramodern::enqueue_external_message_src(mq, 0, false, ultramodern::EventMessageSource::Pi);
Expand All @@ -199,7 +200,7 @@ extern "C" void osFlashReadArray_recomp(uint8_t * rdram, recomp_context * ctx) {
}

extern "C" void osFlashChange_recomp(uint8_t * rdram, recomp_context * ctx) {
if (!recomp::flashram_allowed()) {
if (!ultramodern::flashram_allowed()) {
ultramodern::error_handling::message_box("Attempted to use FlashRAM saving with other save type");
ULTRAMODERN_QUICK_EXIT();
}
Expand Down
4 changes: 2 additions & 2 deletions librecomp/src/mod_manifest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#include "json/json.hpp"

#include "recompiler/context.h"
#include "librecomp/files.hpp"
#include "librecomp/mods.hpp"
#include <ultramodern/files.hpp>

static bool read_json(std::ifstream input_file, nlohmann::json &json_out) {
if (!input_file.good()) {
Expand All @@ -27,7 +27,7 @@ static bool read_json_with_backups(const std::filesystem::path &path, nlohmann::
}

// Try reading and parsing the backup file.
if (read_json(recomp::open_input_backup_file(path), json_out)) {
if (read_json(ultramodern::open_input_backup_file(path), json_out)) {
return true;
}

Expand Down
12 changes: 6 additions & 6 deletions librecomp/src/mods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <sstream>
#include <functional>

#include "librecomp/files.hpp"
#include <ultramodern/files.hpp>
#include "librecomp/mods.hpp"
#include "librecomp/overlays.hpp"
#include "librecomp/game.hpp"
Expand Down Expand Up @@ -32,7 +32,7 @@ static bool read_json_with_backups(const std::filesystem::path &path, nlohmann::
}

// Try reading and parsing the backup file.
if (read_json(recomp::open_input_backup_file(path), json_out)) {
if (read_json(ultramodern::open_input_backup_file(path), json_out)) {
return true;
}

Expand Down Expand Up @@ -679,15 +679,15 @@ bool save_mod_config_storage(const std::filesystem::path &path, const std::strin
}
}

std::ofstream output_file = recomp::open_output_file_with_backup(path);
std::ofstream output_file = ultramodern::open_output_file_with_backup(path);
if (!output_file.good()) {
return false;
}

output_file << std::setw(4) << config_json;
output_file.close();

return recomp::finalize_output_file_with_backup(path);
return ultramodern::finalize_output_file_with_backup(path);
}

bool parse_mods_config(const std::filesystem::path &path, std::unordered_set<std::string> &enabled_mods, std::vector<std::string> &mod_order) {
Expand Down Expand Up @@ -720,15 +720,15 @@ bool save_mods_config(const std::filesystem::path &path, const std::unordered_se
config_json["enabled_mods"] = enabled_mods;
config_json["mod_order"] = mod_order;

std::ofstream output_file = recomp::open_output_file_with_backup(path);
std::ofstream output_file = ultramodern::open_output_file_with_backup(path);
if (!output_file.good()) {
return false;
}

output_file << std::setw(4) << config_json;
output_file.close();

return recomp::finalize_output_file_with_backup(path);
return ultramodern::finalize_output_file_with_backup(path);
}

void recomp::mods::ModContext::dirty_mod_configuration_thread_process() {
Expand Down
Loading
Loading