Skip to content

Commit 0bec4ad

Browse files
committed
format librecomp
1 parent 108a240 commit 0bec4ad

23 files changed

Lines changed: 390 additions & 373 deletions

librecomp/include/librecomp/files.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ namespace recomp {
99
std::ifstream open_input_backup_file(const std::filesystem::path& filepath, std::ios_base::openmode mode = std::ios_base::in);
1010
std::ofstream open_output_file_with_backup(const std::filesystem::path& filepath, std::ios_base::openmode mode = std::ios_base::out);
1111
bool finalize_output_file_with_backup(const std::filesystem::path& filepath);
12-
};
12+
}; // namespace recomp
1313

1414
#endif
Lines changed: 36 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#ifndef __RECOMP_GAME__
22
#define __RECOMP_GAME__
33

4-
#include <vector>
54
#include <filesystem>
5+
#include <vector>
66

77
#include "recomp.h"
88
#include "rsp.hpp"
@@ -17,50 +17,46 @@ namespace recomp {
1717
bool is_enabled;
1818

1919
gpr entrypoint_address;
20-
void (*entrypoint)(uint8_t* rdram, recomp_context* context);
20+
void (*entrypoint)(uint8_t *rdram, recomp_context *context);
2121

2222
std::u8string stored_filename() const;
2323
};
24-
enum class RomValidationError {
25-
Good,
26-
FailedToOpen,
27-
NotARom,
28-
IncorrectRom,
29-
NotYet,
30-
IncorrectVersion,
31-
OtherError
32-
};
33-
void register_config_path(std::filesystem::path path);
34-
bool register_game(const recomp::GameEntry& entry);
35-
void check_all_stored_roms();
36-
bool load_stored_rom(std::u8string& game_id);
37-
RomValidationError select_rom(const std::filesystem::path& rom_path, std::u8string& game_id);
38-
bool is_rom_valid(std::u8string& game_id);
39-
bool is_rom_loaded();
40-
void set_rom_contents(std::vector<uint8_t>&& new_rom);
41-
void do_rom_read(uint8_t* rdram, gpr ram_address, uint32_t physical_addr, size_t num_bytes);
42-
void do_rom_pio(uint8_t* rdram, gpr ram_address, uint32_t physical_addr);
43-
44-
/**
45-
* The following arguments contain mandatory callbacks that need to be registered (i.e., can't be `nullptr`):
46-
* - `rsp_callbacks`
47-
* - `renderer_callbacks`
48-
*
49-
* It must be called only once and it must be called before `ultramodern::preinit`.
50-
*/
24+
enum class RomValidationError {
25+
Good,
26+
FailedToOpen,
27+
NotARom,
28+
IncorrectRom,
29+
NotYet,
30+
IncorrectVersion,
31+
OtherError
32+
};
33+
void register_config_path(std::filesystem::path path);
34+
bool register_game(const recomp::GameEntry& entry);
35+
void check_all_stored_roms();
36+
bool load_stored_rom(std::u8string& game_id);
37+
RomValidationError select_rom(const std::filesystem::path& rom_path, std::u8string& game_id);
38+
bool is_rom_valid(std::u8string& game_id);
39+
bool is_rom_loaded();
40+
void set_rom_contents(std::vector<uint8_t>&& new_rom);
41+
void do_rom_read(uint8_t *rdram, gpr ram_address, uint32_t physical_addr, size_t num_bytes);
42+
void do_rom_pio(uint8_t *rdram, gpr ram_address, uint32_t physical_addr);
43+
44+
/**
45+
* The following arguments contain mandatory callbacks that need to be registered (i.e., can't be `nullptr`):
46+
* - `rsp_callbacks`
47+
* - `renderer_callbacks`
48+
*
49+
* It must be called only once and it must be called before `ultramodern::preinit`.
50+
*/
5151
void start(
52-
ultramodern::renderer::WindowHandle window_handle,
53-
const recomp::rsp::callbacks_t& rsp_callbacks,
54-
const ultramodern::renderer::callbacks_t& renderer_callbacks,
55-
const ultramodern::audio_callbacks_t& audio_callbacks,
56-
const ultramodern::input::callbacks_t& input_callbacks,
57-
const ultramodern::gfx_callbacks_t& gfx_callbacks,
52+
ultramodern::renderer::WindowHandle window_handle, const recomp::rsp::callbacks_t& rsp_callbacks,
53+
const ultramodern::renderer::callbacks_t& renderer_callbacks, const ultramodern::audio_callbacks_t& audio_callbacks,
54+
const ultramodern::input::callbacks_t& input_callbacks, const ultramodern::gfx_callbacks_t& gfx_callbacks,
5855
const ultramodern::events::callbacks_t& events_callbacks,
59-
const ultramodern::error_handling::callbacks_t& error_handling_callbacks_
60-
);
56+
const ultramodern::error_handling::callbacks_t& error_handling_callbacks_);
6157

62-
void start_game(const std::u8string& game_id);
63-
std::u8string current_game_id();
64-
}
58+
void start_game(const std::u8string& game_id);
59+
std::u8string current_game_id();
60+
} // namespace recomp
6561

6662
#endif

librecomp/include/librecomp/helpers.hpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include <ultramodern/ultra64.h>
66

77
template<int index, typename T>
8-
T _arg(uint8_t* rdram, recomp_context* ctx) {
8+
T _arg(uint8_t *rdram, recomp_context *ctx) {
99
static_assert(index < 4, "Only args 0 through 3 supported");
1010
gpr raw_arg = (&ctx->r4)[index];
1111
if constexpr (std::is_same_v<T, float>) {
@@ -15,13 +15,14 @@ T _arg(uint8_t* rdram, recomp_context* ctx) {
1515
}
1616
else {
1717
// static_assert in else workaround
18-
[] <bool flag = false>() {
18+
[]<bool flag = false>() {
1919
static_assert(flag, "Floats in a2/a3 not supported");
20-
}();
20+
}
21+
();
2122
}
2223
}
2324
else if constexpr (std::is_pointer_v<T>) {
24-
static_assert (!std::is_pointer_v<std::remove_pointer_t<T>>, "Double pointers not supported");
25+
static_assert(!std::is_pointer_v<std::remove_pointer_t<T>>, "Double pointers not supported");
2526
return TO_PTR(std::remove_pointer_t<T>, raw_arg);
2627
}
2728
else if constexpr (std::is_integral_v<T>) {
@@ -30,14 +31,15 @@ T _arg(uint8_t* rdram, recomp_context* ctx) {
3031
}
3132
else {
3233
// static_assert in else workaround
33-
[] <bool flag = false>() {
34+
[]<bool flag = false>() {
3435
static_assert(flag, "Unsupported type");
35-
}();
36+
}
37+
();
3638
}
3739
}
3840

39-
template <typename T>
40-
void _return(recomp_context* ctx, T val) {
41+
template<typename T>
42+
void _return(recomp_context *ctx, T val) {
4143
static_assert(sizeof(T) <= 4 && "Only 32-bit value returns supported currently");
4244
if constexpr (std::is_same_v<T, float>) {
4345
ctx->f0.fl = val;
@@ -47,9 +49,10 @@ void _return(recomp_context* ctx, T val) {
4749
}
4850
else {
4951
// static_assert in else workaround
50-
[] <bool flag = false>() {
52+
[]<bool flag = false>() {
5153
static_assert(flag, "Unsupported type");
52-
}();
54+
}
55+
();
5356
}
5457
}
5558

librecomp/include/librecomp/overlays.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
#ifndef __RECOMP_OVERLAYS_H__
22
#define __RECOMP_OVERLAYS_H__
33

4-
#include <cstdint>
54
#include "sections.h"
5+
#include <cstdint>
66

77
namespace recomp {
88
namespace overlays {
99
struct overlay_section_table_data_t {
10-
SectionTableEntry* code_sections;
10+
SectionTableEntry *code_sections;
1111
size_t num_code_sections;
1212
size_t total_num_sections;
1313
};
1414

1515
struct overlays_by_index_t {
16-
int* table;
16+
int *table;
1717
size_t len;
1818
};
1919

2020
void register_overlays(const overlay_section_table_data_t& sections, const overlays_by_index_t& overlays);
2121

22-
void register_patches(const char* patch_data, std::size_t patch_size, SectionTableEntry* code_sections);
23-
void read_patch_data(uint8_t* rdram, gpr patch_data_address);
22+
void register_patches(const char *patch_data, std::size_t patch_size, SectionTableEntry *code_sections);
23+
void read_patch_data(uint8_t *rdram, gpr patch_data_address);
2424

2525
void init_overlays();
26-
}
27-
};
26+
} // namespace overlays
27+
}; // namespace recomp
2828

2929
extern "C" void load_overlays(uint32_t rom, int32_t ram_addr, uint32_t size);
3030
extern "C" void unload_overlays(int32_t ram_addr, uint32_t size);

librecomp/include/librecomp/rsp.hpp

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
#include <cstdio>
55

6-
#include "rsp_vu.hpp"
76
#include "recomp.h"
7+
#include "rsp_vu.hpp"
88
#include "ultramodern/ultra64.h"
99

1010
// TODO: Move these to recomp namespace?
@@ -17,69 +17,64 @@ enum class RspExitReason {
1717
Unsupported
1818
};
1919

20-
using RspUcodeFunc = RspExitReason(uint8_t* rdram);
20+
using RspUcodeFunc = RspExitReason(uint8_t *rdram);
2121

2222
extern uint8_t dmem[];
2323
extern uint16_t rspReciprocals[512];
2424
extern uint16_t rspInverseSquareRoots[512];
2525

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

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

3230
static inline uint32_t RSP_MEM_W_LOAD(uint32_t offset, uint32_t addr) {
3331
uint32_t out;
3432
for (int i = 0; i < 4; i++) {
35-
reinterpret_cast<uint8_t*>(&out)[i ^ 3] = RSP_MEM_BU(offset + i, addr);
33+
reinterpret_cast<uint8_t *>(&out)[i ^ 3] = RSP_MEM_BU(offset + i, addr);
3634
}
3735
return out;
3836
}
3937

4038
static inline void RSP_MEM_W_STORE(uint32_t offset, uint32_t addr, uint32_t val) {
4139
for (int i = 0; i < 4; i++) {
42-
RSP_MEM_BU(offset + i, addr) = reinterpret_cast<uint8_t*>(&val)[i ^ 3];
40+
RSP_MEM_BU(offset + i, addr) = reinterpret_cast<uint8_t *>(&val)[i ^ 3];
4341
}
4442
}
4543

4644
static inline uint32_t RSP_MEM_HU_LOAD(uint32_t offset, uint32_t addr) {
4745
uint16_t out;
4846
for (int i = 0; i < 2; i++) {
49-
reinterpret_cast<uint8_t*>(&out)[(i + 2) ^ 3] = RSP_MEM_BU(offset + i, addr);
47+
reinterpret_cast<uint8_t *>(&out)[(i + 2) ^ 3] = RSP_MEM_BU(offset + i, addr);
5048
}
5149
return out;
5250
}
5351

5452
static inline uint32_t RSP_MEM_H_LOAD(uint32_t offset, uint32_t addr) {
5553
int16_t out;
5654
for (int i = 0; i < 2; i++) {
57-
reinterpret_cast<uint8_t*>(&out)[(i + 2) ^ 3] = RSP_MEM_BU(offset + i, addr);
55+
reinterpret_cast<uint8_t *>(&out)[(i + 2) ^ 3] = RSP_MEM_BU(offset + i, addr);
5856
}
5957
return out;
6058
}
6159

6260
static inline void RSP_MEM_H_STORE(uint32_t offset, uint32_t addr, uint32_t val) {
6361
for (int i = 0; i < 2; i++) {
64-
RSP_MEM_BU(offset + i, addr) = reinterpret_cast<uint8_t*>(&val)[(i + 2) ^ 3];
62+
RSP_MEM_BU(offset + i, addr) = reinterpret_cast<uint8_t *>(&val)[(i + 2) ^ 3];
6563
}
6664
}
6765

68-
#define RSP_ADD32(a, b) \
69-
((int32_t)((a) + (b)))
66+
#define RSP_ADD32(a, b) ((int32_t)((a) + (b)))
7067

71-
#define RSP_SUB32(a, b) \
72-
((int32_t)((a) - (b)))
68+
#define RSP_SUB32(a, b) ((int32_t)((a) - (b)))
7369

74-
#define RSP_SIGNED(val) \
75-
((int32_t)(val))
70+
#define RSP_SIGNED(val) ((int32_t)(val))
7671

7772
#define SET_DMA_DMEM(dmem_addr) dma_dmem_address = (dmem_addr)
7873
#define SET_DMA_DRAM(dram_addr) dma_dram_address = (dram_addr)
7974
#define DO_DMA_READ(rd_len) dma_rdram_to_dmem(rdram, dma_dmem_address, dma_dram_address, (rd_len))
8075
#define DO_DMA_WRITE(wr_len) dma_dmem_to_rdram(rdram, dma_dmem_address, dma_dram_address, (wr_len))
8176

82-
static inline void dma_rdram_to_dmem(uint8_t* rdram, uint32_t dmem_addr, uint32_t dram_addr, uint32_t rd_len) {
77+
static inline void dma_rdram_to_dmem(uint8_t *rdram, uint32_t dmem_addr, uint32_t dram_addr, uint32_t rd_len) {
8378
rd_len += 1; // Read length is inclusive
8479
dram_addr &= 0xFFFFF8;
8580
assert(dmem_addr + rd_len <= 0x1000);
@@ -88,7 +83,7 @@ static inline void dma_rdram_to_dmem(uint8_t* rdram, uint32_t dmem_addr, uint32_
8883
}
8984
}
9085

91-
static inline void dma_dmem_to_rdram(uint8_t* rdram, uint32_t dmem_addr, uint32_t dram_addr, uint32_t wr_len) {
86+
static inline void dma_dmem_to_rdram(uint8_t *rdram, uint32_t dmem_addr, uint32_t dram_addr, uint32_t wr_len) {
9287
wr_len += 1; // Write length is inclusive
9388
dram_addr &= 0xFFFFF8;
9489
assert(dmem_addr + wr_len <= 0x1000);
@@ -100,24 +95,26 @@ static inline void dma_dmem_to_rdram(uint8_t* rdram, uint32_t dmem_addr, uint32_
10095
namespace recomp {
10196
namespace rsp {
10297
struct callbacks_t {
103-
using get_rsp_microcode_t = RspUcodeFunc*(const OSTask* task);
98+
using get_rsp_microcode_t = RspUcodeFunc *(const OSTask *task);
10499

105100
/**
106101
* Return a function pointer to the corresponding RSP microcode function for the given `task_type`.
107102
*
108-
* The full OSTask (`task` parameter) is passed in case the `task_type` number is not enough information to distinguish out the exact microcode function.
103+
* The full OSTask (`task` parameter) is passed in case the `task_type` number is not enough information to distinguish out the
104+
* exact microcode function.
109105
*
110-
* 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.
106+
* This function is allowed to return `nullptr` if no microcode matches the specified task. In this case a message will be
107+
* printed to stderr and the program will exit.
111108
*/
112-
get_rsp_microcode_t* get_rsp_microcode;
109+
get_rsp_microcode_t *get_rsp_microcode;
113110
};
114111

115112
void set_callbacks(const callbacks_t& callbacks);
116113

117114
void constants_init();
118115

119-
bool run_task(uint8_t* rdram, const OSTask* task);
120-
}
121-
}
116+
bool run_task(uint8_t *rdram, const OSTask *task);
117+
} // namespace rsp
118+
} // namespace recomp
122119

123120
#endif

librecomp/include/librecomp/sections.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
#define __SECTIONS_H__
33

44
#include <stdint.h>
5+
56
#include "recomp.h"
67

78
#define ARRLEN(x) (sizeof(x) / sizeof((x)[0]))
89

910
typedef struct {
10-
recomp_func_t* func;
11+
recomp_func_t *func;
1112
uint32_t offset;
1213
} FuncEntry;
1314

librecomp/src/ai.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,24 @@
66

77
#define VI_NTSC_CLOCK 48681812
88

9-
extern "C" void osAiSetFrequency_recomp(uint8_t* rdram, recomp_context* ctx) {
9+
extern "C" void osAiSetFrequency_recomp(uint8_t *rdram, recomp_context *ctx) {
1010
uint32_t freq = ctx->r4;
1111
// This makes actual audio frequency more accurate to console, but may not be desirable
12-
//uint32_t dacRate = (uint32_t)(((float)VI_NTSC_CLOCK / freq) + 0.5f);
13-
//freq = VI_NTSC_CLOCK / dacRate;
12+
// uint32_t dacRate = (uint32_t)(((float)VI_NTSC_CLOCK / freq) + 0.5f);
13+
// freq = VI_NTSC_CLOCK / dacRate;
1414
ctx->r2 = freq;
1515
ultramodern::set_audio_frequency(freq);
1616
}
1717

18-
extern "C" void osAiSetNextBuffer_recomp(uint8_t* rdram, recomp_context* ctx) {
18+
extern "C" void osAiSetNextBuffer_recomp(uint8_t *rdram, recomp_context *ctx) {
1919
ultramodern::queue_audio_buffer(rdram, ctx->r4, ctx->r5);
2020
ctx->r2 = 0;
2121
}
2222

23-
extern "C" void osAiGetLength_recomp(uint8_t* rdram, recomp_context* ctx) {
23+
extern "C" void osAiGetLength_recomp(uint8_t *rdram, recomp_context *ctx) {
2424
ctx->r2 = ultramodern::get_remaining_audio_bytes();
2525
}
2626

27-
extern "C" void osAiGetStatus_recomp(uint8_t* rdram, recomp_context* ctx) {
27+
extern "C" void osAiGetStatus_recomp(uint8_t *rdram, recomp_context *ctx) {
2828
ctx->r2 = 0x00000000; // Pretend the audio DMAs finish instantly
2929
}

0 commit comments

Comments
 (0)