Skip to content

Commit

Permalink
Format librecomp
Browse files Browse the repository at this point in the history
  • Loading branch information
AngheloAlf committed Jun 1, 2024
1 parent 716f786 commit ffc02dd
Show file tree
Hide file tree
Showing 23 changed files with 306 additions and 267 deletions.
4 changes: 2 additions & 2 deletions librecomp/include/disable_warnings.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#ifdef __GNUC__
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wimplicit-function-declaration"
# pragma GCC diagnostic ignored "-Wunused-variable"
# pragma GCC diagnostic ignored "-Wimplicit-function-declaration"
#endif
6 changes: 3 additions & 3 deletions librecomp/include/recomp.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#ifndef __RECOMP_H__
#define __RECOMP_H__

#include <stdlib.h>
#include <stdint.h>
#include <math.h>
#include <assert.h>
#include <math.h>
#include <stdint.h>
#include <stdlib.h>

typedef uint64_t gpr;

Expand Down
57 changes: 32 additions & 25 deletions librecomp/include/recomp_game.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ifndef __RECOMP_GAME__
#define __RECOMP_GAME__

#include <vector>
#include <filesystem>
#include <vector>

#include "recomp.h"
#include "rsp.h"
Expand All @@ -21,29 +21,36 @@ namespace recomp {

std::u8string stored_filename() const;
};
enum class RomValidationError {
Good,
FailedToOpen,
NotARom,
IncorrectRom,
NotYet,
IncorrectVersion,
OtherError
};
void register_config_path(std::filesystem::path path);
bool register_game(const recomp::GameEntry& entry);
void register_patch(const char* patch, std::size_t size);
void check_all_stored_roms();
bool load_stored_rom(std::u8string& game_id);
RomValidationError select_rom(const std::filesystem::path& rom_path, std::u8string& game_id);
bool is_rom_valid(std::u8string& game_id);
bool is_rom_loaded();
void set_rom_contents(std::vector<uint8_t>&& new_rom);
void do_rom_read(uint8_t* rdram, gpr ram_address, uint32_t physical_addr, size_t num_bytes);
void do_rom_pio(uint8_t* rdram, gpr ram_address, uint32_t physical_addr);
void start(ultramodern::WindowHandle window_handle, const recomp::rsp::callbacks_t& rsp_callbacks, const ultramodern::audio_callbacks_t& audio_callbacks, const ultramodern::input_callbacks_t& input_callbacks, const ultramodern::gfx_callbacks_t& gfx_callbacks, const ultramodern::events::callbacks_t& thread_callbacks, const ultramodern::error_handling::callbacks_t& error_handling_callbacks_);
void start_game(const std::u8string& game_id);
std::u8string current_game_id();
}
enum class RomValidationError {
Good,
FailedToOpen,
NotARom,
IncorrectRom,
NotYet,
IncorrectVersion,
OtherError
};

void register_config_path(std::filesystem::path path);
bool register_game(const recomp::GameEntry& entry);
void register_patch(const char* patch, std::size_t size);
void check_all_stored_roms();
bool load_stored_rom(std::u8string& game_id);
RomValidationError select_rom(const std::filesystem::path& rom_path, std::u8string& game_id);
bool is_rom_valid(std::u8string& game_id);
bool is_rom_loaded();
void set_rom_contents(std::vector<uint8_t>&& new_rom);
void do_rom_read(uint8_t* rdram, gpr ram_address, uint32_t physical_addr, size_t num_bytes);
void do_rom_pio(uint8_t* rdram, gpr ram_address, uint32_t physical_addr);

void start(
ultramodern::WindowHandle window_handle, const recomp::rsp::callbacks_t& rsp_callbacks,
const ultramodern::audio_callbacks_t& audio_callbacks, const ultramodern::input_callbacks_t& input_callbacks,
const ultramodern::gfx_callbacks_t& gfx_callbacks, const ultramodern::events::callbacks_t& thread_callbacks,
const ultramodern::error_handling::callbacks_t& error_handling_callbacks_);
void start_game(const std::u8string& game_id);

std::u8string current_game_id();
} // namespace recomp

#endif
14 changes: 8 additions & 6 deletions librecomp/include/recomp_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ T _arg(uint8_t* rdram, recomp_context* ctx) {
}
else {
// static_assert in else workaround
[] <bool flag = false>() {
[]<bool flag = false>() {
static_assert(flag, "Floats in a2/a3 not supported");
}();
}
();
}
}
else if constexpr (std::is_pointer_v<T>) {
static_assert (!std::is_pointer_v<std::remove_pointer_t<T>>, "Double pointers not supported");
static_assert(!std::is_pointer_v<std::remove_pointer_t<T>>, "Double pointers not supported");
return TO_PTR(std::remove_pointer_t<T>, raw_arg);
}
else if constexpr (std::is_integral_v<T>) {
Expand All @@ -30,13 +31,14 @@ T _arg(uint8_t* rdram, recomp_context* ctx) {
}
else {
// static_assert in else workaround
[] <bool flag = false>() {
[]<bool flag = false>() {
static_assert(flag, "Unsupported type");
}();
}
();
}
}

template <typename T>
template<typename T>
void _return(recomp_context* ctx, T val) {
static_assert(sizeof(T) <= 4 && "Only 32-bit value returns supported currently");
if (std::is_same_v<T, float>) {
Expand Down
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 @@ -19,7 +20,7 @@ namespace recomp {
void register_overlays(const overlay_section_table_data_t& sections, const overlays_by_index_t& overlays);
void register_patch_section(SectionTableEntry* code_sections);
void load_patch_functions();
};
}; // 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
28 changes: 13 additions & 15 deletions librecomp/include/rsp.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@

#include <cstdio>

#include "rsp_vu.h"
#include "recomp.h"
#include "rsp_vu.h"

#include "ultramodern/ultra64.h"

// TODO: Move these to recomp namespace?
Expand All @@ -23,11 +24,9 @@ extern uint8_t dmem[];
extern uint16_t rspReciprocals[512];
extern uint16_t rspInverseSquareRoots[512];

#define RSP_MEM_B(offset, addr) \
(*reinterpret_cast<int8_t*>(dmem + (0xFFF & (((offset) + (addr)) ^ 3))))
#define RSP_MEM_B(offset, addr) (*reinterpret_cast<int8_t*>(dmem + (0xFFF & (((offset) + (addr)) ^ 3))))

#define RSP_MEM_BU(offset, addr) \
(*reinterpret_cast<uint8_t*>(dmem + (0xFFF & (((offset) + (addr)) ^ 3))))
#define RSP_MEM_BU(offset, addr) (*reinterpret_cast<uint8_t*>(dmem + (0xFFF & (((offset) + (addr)) ^ 3))))

static inline uint32_t RSP_MEM_W_LOAD(uint32_t offset, uint32_t addr) {
uint32_t out;
Expand Down Expand Up @@ -65,14 +64,11 @@ static inline void RSP_MEM_H_STORE(uint32_t offset, uint32_t addr, uint32_t val)
}
}

#define RSP_ADD32(a, b) \
((int32_t)((a) + (b)))
#define RSP_ADD32(a, b) ((int32_t)((a) + (b)))

#define RSP_SUB32(a, b) \
((int32_t)((a) - (b)))
#define RSP_SUB32(a, b) ((int32_t)((a) - (b)))

#define RSP_SIGNED(val) \
((int32_t)(val))
#define RSP_SIGNED(val) ((int32_t)(val))

#define SET_DMA_DMEM(dmem_addr) dma_dmem_address = (dmem_addr)
#define SET_DMA_DRAM(dram_addr) dma_dram_address = (dram_addr)
Expand Down Expand Up @@ -105,9 +101,11 @@ namespace recomp {
/**
* Return a function pointer to the corresponding RSP microcode function for the given `task_type`.
*
* The full OSTask (`task` parameter) is passed in case the `task_type` number is not enough information to distinguish out the exact microcode function.
* The full OSTask (`task` parameter) is passed in case the `task_type` number is not enough information to distinguish out the
* exact microcode function.
*
* This function is allowed to return `nullptr` if no microcode matches the specified task. In this case a message will be printed to stderr and the program will exit.
* This function is allowed to return `nullptr` if no microcode matches the specified task. In this case a message will be
* printed to stderr and the program will exit.
*/
get_rsp_microcode_t* get_rsp_microcode;
};
Expand All @@ -117,7 +115,7 @@ namespace recomp {
void constants_init();

bool run_task(uint8_t* rdram, const OSTask* task);
}
}
} // namespace rsp
} // namespace recomp

#endif
3 changes: 2 additions & 1 deletion librecomp/include/sections.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define __SECTIONS_H__

#include <stdint.h>

#include "recomp.h"

#define ARRLEN(x) (sizeof(x) / sizeof((x)[0]))
Expand All @@ -15,7 +16,7 @@ typedef struct {
uint32_t rom_addr;
uint32_t ram_addr;
uint32_t size;
FuncEntry *funcs;
FuncEntry* funcs;
size_t num_funcs;
size_t index;
} SectionTableEntry;
Expand Down
4 changes: 2 additions & 2 deletions librecomp/src/ai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
extern "C" void osAiSetFrequency_recomp(uint8_t* rdram, recomp_context* ctx) {
uint32_t freq = ctx->r4;
// This makes actual audio frequency more accurate to console, but may not be desirable
//uint32_t dacRate = (uint32_t)(((float)VI_NTSC_CLOCK / freq) + 0.5f);
//freq = VI_NTSC_CLOCK / dacRate;
// uint32_t dacRate = (uint32_t)(((float)VI_NTSC_CLOCK / freq) + 0.5f);
// freq = VI_NTSC_CLOCK / dacRate;
ctx->r2 = freq;
ultramodern::set_audio_frequency(freq);
}
Expand Down
19 changes: 11 additions & 8 deletions librecomp/src/cont.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <ultramodern/ultramodern.hpp>
#include "ultramodern/ultramodern.hpp"

#include "recomp_helpers.h"

static ultramodern::input_callbacks_t input_callbacks;
Expand All @@ -18,7 +19,9 @@ extern "C" void recomp_measure_latency(uint8_t* rdram, recomp_context* ctx) {
}

void ultramodern::measure_input_latency() {
// printf("Delta: %ld micros\n", std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now() - input_poll_time));
#if 0
// printf("Delta: %ld micros\n", std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now() - input_poll_time));
#endif
}

void set_input_callbacks(const ultramodern::input_callbacks_t& callbacks) {
Expand All @@ -36,8 +39,8 @@ extern "C" void osContInit_recomp(uint8_t* rdram, recomp_context* ctx) {

// Mark controller 0 as present
MEM_H(0, status) = 0x0005; // type: CONT_TYPE_NORMAL (from joybus)
MEM_B(2, status) = 0x00; // status: 0 (from joybus)
MEM_B(3, status) = 0x00; // errno: 0 (from libultra)
MEM_B(2, status) = 0x00; // status: 0 (from joybus)
MEM_B(3, status) = 0x00; // errno: 0 (from libultra)

max_controllers = 4;

Expand Down Expand Up @@ -85,17 +88,17 @@ extern "C" void osContGetReadData_recomp(uint8_t* rdram, recomp_context* ctx) {
}
}

extern "C" void osContStartQuery_recomp(uint8_t * rdram, recomp_context * ctx) {
extern "C" void osContStartQuery_recomp(uint8_t* rdram, recomp_context* ctx) {
ultramodern::send_si_message(rdram);
}

extern "C" void osContGetQuery_recomp(uint8_t * rdram, recomp_context * ctx) {
extern "C" void osContGetQuery_recomp(uint8_t* rdram, recomp_context* ctx) {
PTR(void) status = _arg<0, PTR(void)>(rdram, ctx);

// Mark controller 0 as present
MEM_H(0, status) = 0x0005; // type: CONT_TYPE_NORMAL (from joybus)
MEM_B(2, status) = 0x01; // status: 0x01 (from joybus, indicates that a pak is plugged into the controller)
MEM_B(3, status) = 0x00; // errno: 0 (from libultra)
MEM_B(2, status) = 0x01; // status: 0x01 (from joybus, indicates that a pak is plugged into the controller)
MEM_B(3, status) = 0x00; // errno: 0 (from libultra)

// Mark controllers 1-3 as not connected
for (size_t controller = 1; controller < max_controllers; controller++) {
Expand Down
7 changes: 4 additions & 3 deletions librecomp/src/eep.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "recomp.h"
#include <ultramodern/ultra64.h>

#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);
Expand All @@ -15,7 +16,7 @@ extern "C" void osEepromProbe_recomp(uint8_t* rdram, recomp_context* ctx) {
}

extern "C" void osEepromWrite_recomp(uint8_t* rdram, recomp_context* ctx) {
assert(false);// ctx->r2 = 8; // CONT_NO_RESPONSE_ERROR
assert(false); // ctx->r2 = 8; // CONT_NO_RESPONSE_ERROR
}

extern "C" void osEepromLongWrite_recomp(uint8_t* rdram, recomp_context* ctx) {
Expand All @@ -32,7 +33,7 @@ extern "C" void osEepromLongWrite_recomp(uint8_t* rdram, recomp_context* ctx) {
}

extern "C" void osEepromRead_recomp(uint8_t* rdram, recomp_context* ctx) {
assert(false);// ctx->r2 = 8; // CONT_NO_RESPONSE_ERROR
assert(false); // ctx->r2 = 8; // CONT_NO_RESPONSE_ERROR
}

extern "C" void osEepromLongRead_recomp(uint8_t* rdram, recomp_context* ctx) {
Expand Down
Loading

0 comments on commit ffc02dd

Please sign in to comment.