mirror of
https://github.com/wiiu-env/WiiUPluginLoaderBackend.git
synced 2026-08-14 06:15:54 -05:00
Format the code via clang-format
This commit is contained in:
@@ -1,26 +1,26 @@
|
||||
#include "ConfigUtils.h"
|
||||
|
||||
#include "logger.h"
|
||||
#include "../config/WUPSConfig.h"
|
||||
#include "../globals.h"
|
||||
#include "DrawUtils.h"
|
||||
#include "logger.h"
|
||||
|
||||
#include <coreinit/screen.h>
|
||||
#include <gx2/display.h>
|
||||
#include <memory/mappedmemory.h>
|
||||
#include <padscore/kpad.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <coreinit/screen.h>
|
||||
#include <memory/mappedmemory.h>
|
||||
#include <vpad/input.h>
|
||||
#include <padscore/kpad.h>
|
||||
#include <gx2/display.h>
|
||||
|
||||
#define COLOR_BACKGROUND Color(238, 238, 238, 255)
|
||||
#define COLOR_TEXT Color(51, 51, 51, 255)
|
||||
#define COLOR_TEXT2 Color(72, 72, 72, 255)
|
||||
#define COLOR_DISABLED Color(255, 0, 0, 255)
|
||||
#define COLOR_BORDER Color(204, 204, 204, 255)
|
||||
#define COLOR_BACKGROUND Color(238, 238, 238, 255)
|
||||
#define COLOR_TEXT Color(51, 51, 51, 255)
|
||||
#define COLOR_TEXT2 Color(72, 72, 72, 255)
|
||||
#define COLOR_DISABLED Color(255, 0, 0, 255)
|
||||
#define COLOR_BORDER Color(204, 204, 204, 255)
|
||||
#define COLOR_BORDER_HIGHLIGHTED Color(0x3478e4FF)
|
||||
#define COLOR_WHITE Color(0xFFFFFFFF)
|
||||
#define COLOR_BLACK Color(0, 0, 0, 255)
|
||||
#define COLOR_WHITE Color(0xFFFFFFFF)
|
||||
#define COLOR_BLACK Color(0, 0, 0, 255)
|
||||
|
||||
struct ConfigDisplayItem {
|
||||
WUPSConfig *config{};
|
||||
@@ -124,18 +124,18 @@ void ConfigUtils::displayMenu() {
|
||||
continue;
|
||||
}
|
||||
ConfigDisplayItem cfg;
|
||||
cfg.name = std::string(plugin_data->meta.name);
|
||||
cfg.author = std::string(plugin_data->meta.author);
|
||||
cfg.name = std::string(plugin_data->meta.name);
|
||||
cfg.author = std::string(plugin_data->meta.author);
|
||||
cfg.version = std::string(plugin_data->meta.version);
|
||||
cfg.enabled = true;
|
||||
|
||||
for (uint32_t j = 0; j < plugin_data->info.number_used_hooks; j++) {
|
||||
replacement_data_hook_t *hook_data = &plugin_data->info.hooks[j];
|
||||
if (hook_data->type == WUPS_LOADER_HOOK_GET_CONFIG/*WUPS_LOADER_HOOK_GET_CONFIG*/) {
|
||||
if (hook_data->type == WUPS_LOADER_HOOK_GET_CONFIG /*WUPS_LOADER_HOOK_GET_CONFIG*/) {
|
||||
if (hook_data->func_pointer == nullptr) {
|
||||
break;
|
||||
}
|
||||
auto *cur_config = reinterpret_cast<WUPSConfig *>(((WUPSConfigHandle (*)()) ((uint32_t *) hook_data->func_pointer))());
|
||||
auto *cur_config = reinterpret_cast<WUPSConfig *>(((WUPSConfigHandle(*)())((uint32_t *) hook_data->func_pointer))());
|
||||
if (cur_config == nullptr) {
|
||||
break;
|
||||
}
|
||||
@@ -150,12 +150,12 @@ void ConfigUtils::displayMenu() {
|
||||
return;
|
||||
}
|
||||
|
||||
ConfigDisplayItem *currentConfig = nullptr;
|
||||
ConfigDisplayItem *currentConfig = nullptr;
|
||||
WUPSConfigCategory *currentCategory = nullptr;
|
||||
|
||||
uint32_t selectedBtn = 0;
|
||||
uint32_t start = 0;
|
||||
uint32_t end = MAX_BUTTONS_ON_SCREEN;
|
||||
uint32_t start = 0;
|
||||
uint32_t end = MAX_BUTTONS_ON_SCREEN;
|
||||
if (configs.size() < MAX_BUTTONS_ON_SCREEN) {
|
||||
end = configs.size();
|
||||
}
|
||||
@@ -171,12 +171,12 @@ void ConfigUtils::displayMenu() {
|
||||
|
||||
while (true) {
|
||||
buttonsTriggered = 0;
|
||||
buttonsReleased = 0;
|
||||
buttonsReleased = 0;
|
||||
|
||||
VPADRead(VPAD_CHAN_0, &vpad_data, 1, &vpad_error);
|
||||
if (vpad_error == VPAD_READ_SUCCESS) {
|
||||
buttonsTriggered = vpad_data.trigger;
|
||||
buttonsReleased = vpad_data.release;
|
||||
buttonsReleased = vpad_data.release;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
@@ -212,7 +212,7 @@ void ConfigUtils::displayMenu() {
|
||||
}
|
||||
if (buttonsTriggered & VPAD_BUTTON_X) {
|
||||
configs[selectedBtn].enabled = !configs[selectedBtn].enabled;
|
||||
redraw = true;
|
||||
redraw = true;
|
||||
} else if (buttonsTriggered & VPAD_BUTTON_A) {
|
||||
currentConfig = &configs[selectedBtn];
|
||||
if (currentConfig == nullptr) {
|
||||
@@ -220,8 +220,8 @@ void ConfigUtils::displayMenu() {
|
||||
}
|
||||
|
||||
selectedBtn = 0;
|
||||
start = 0;
|
||||
end = MAX_BUTTONS_ON_SCREEN;
|
||||
start = 0;
|
||||
end = MAX_BUTTONS_ON_SCREEN;
|
||||
|
||||
auto cats = currentConfig->config->getCategories();
|
||||
if (cats.size() < MAX_BUTTONS_ON_SCREEN) {
|
||||
@@ -233,11 +233,11 @@ void ConfigUtils::displayMenu() {
|
||||
}
|
||||
|
||||
if (selectedBtn >= end) {
|
||||
end = selectedBtn + 1;
|
||||
end = selectedBtn + 1;
|
||||
start = end - MAX_BUTTONS_ON_SCREEN;
|
||||
} else if (selectedBtn < start) {
|
||||
start = selectedBtn;
|
||||
end = start + MAX_BUTTONS_ON_SCREEN;
|
||||
end = start + MAX_BUTTONS_ON_SCREEN;
|
||||
}
|
||||
|
||||
if (redraw) {
|
||||
@@ -329,8 +329,8 @@ void ConfigUtils::displayMenu() {
|
||||
}
|
||||
|
||||
selectedBtn = 0;
|
||||
start = 0;
|
||||
end = MAX_BUTTONS_ON_SCREEN;
|
||||
start = 0;
|
||||
end = MAX_BUTTONS_ON_SCREEN;
|
||||
|
||||
auto items = currentCategory->getItems();
|
||||
if (items.size() < MAX_BUTTONS_ON_SCREEN) {
|
||||
@@ -340,11 +340,11 @@ void ConfigUtils::displayMenu() {
|
||||
redraw = true;
|
||||
continue;
|
||||
} else if (buttonsTriggered & VPAD_BUTTON_B) {
|
||||
currentConfig = nullptr;
|
||||
currentConfig = nullptr;
|
||||
currentCategory = nullptr;
|
||||
selectedBtn = 0;
|
||||
start = 0;
|
||||
end = MAX_BUTTONS_ON_SCREEN;
|
||||
selectedBtn = 0;
|
||||
start = 0;
|
||||
end = MAX_BUTTONS_ON_SCREEN;
|
||||
if (configs.size() < MAX_BUTTONS_ON_SCREEN) {
|
||||
end = configs.size();
|
||||
}
|
||||
@@ -353,11 +353,11 @@ void ConfigUtils::displayMenu() {
|
||||
}
|
||||
|
||||
if (selectedBtn >= end) {
|
||||
end = selectedBtn + 1;
|
||||
end = selectedBtn + 1;
|
||||
start = end - MAX_BUTTONS_ON_SCREEN;
|
||||
} else if (selectedBtn < start) {
|
||||
start = selectedBtn;
|
||||
end = start + MAX_BUTTONS_ON_SCREEN;
|
||||
end = start + MAX_BUTTONS_ON_SCREEN;
|
||||
}
|
||||
|
||||
if (redraw) {
|
||||
@@ -434,10 +434,10 @@ void ConfigUtils::displayMenu() {
|
||||
}
|
||||
} else if (buttonsTriggered & VPAD_BUTTON_B) {
|
||||
currentCategory = nullptr;
|
||||
selectedBtn = 0;
|
||||
start = 0;
|
||||
end = MAX_BUTTONS_ON_SCREEN;
|
||||
auto catSize = currentConfig->config->getCategories().size();
|
||||
selectedBtn = 0;
|
||||
start = 0;
|
||||
end = MAX_BUTTONS_ON_SCREEN;
|
||||
auto catSize = currentConfig->config->getCategories().size();
|
||||
if (catSize < MAX_BUTTONS_ON_SCREEN) {
|
||||
end = catSize;
|
||||
}
|
||||
@@ -472,11 +472,11 @@ void ConfigUtils::displayMenu() {
|
||||
}
|
||||
|
||||
if (selectedBtn >= end) {
|
||||
end = selectedBtn + 1;
|
||||
end = selectedBtn + 1;
|
||||
start = end - MAX_BUTTONS_ON_SCREEN;
|
||||
} else if (selectedBtn < start) {
|
||||
start = selectedBtn;
|
||||
end = start + MAX_BUTTONS_ON_SCREEN;
|
||||
end = start + MAX_BUTTONS_ON_SCREEN;
|
||||
}
|
||||
|
||||
if (redraw) {
|
||||
@@ -543,9 +543,9 @@ void ConfigUtils::displayMenu() {
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto &element: configs) {
|
||||
for (const auto &cat: element.config->getCategories()) {
|
||||
for (const auto &item: cat->getItems()) {
|
||||
for (const auto &element : configs) {
|
||||
for (const auto &cat : element.config->getCategories()) {
|
||||
for (const auto &item : cat->getItems()) {
|
||||
if (item->isDirty()) {
|
||||
item->callCallback();
|
||||
}
|
||||
@@ -565,13 +565,13 @@ void ConfigUtils::displayMenu() {
|
||||
if (hook_data->func_pointer == nullptr) {
|
||||
break;
|
||||
}
|
||||
((void (*)()) ((uint32_t *) hook_data->func_pointer))();
|
||||
((void (*)())((uint32_t *) hook_data->func_pointer))();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto &element: configs) {
|
||||
for (const auto &element : configs) {
|
||||
DEBUG_FUNCTION_LINE("Delete %08X", element.config);
|
||||
delete element.config;
|
||||
}
|
||||
@@ -584,8 +584,8 @@ void ConfigUtils::openConfigMenu() {
|
||||
|
||||
uint32_t screen_buf0_size = OSScreenGetBufferSizeEx(SCREEN_TV);
|
||||
uint32_t screen_buf1_size = OSScreenGetBufferSizeEx(SCREEN_DRC);
|
||||
void *screenbuffer0 = MEMAllocFromMappedMemoryForGX2Ex(screen_buf0_size, 0x100);
|
||||
void *screenbuffer1 = MEMAllocFromMappedMemoryForGX2Ex(screen_buf1_size, 0x100);
|
||||
void *screenbuffer0 = MEMAllocFromMappedMemoryForGX2Ex(screen_buf0_size, 0x100);
|
||||
void *screenbuffer1 = MEMAllocFromMappedMemoryForGX2Ex(screen_buf1_size, 0x100);
|
||||
|
||||
bool skipScreen0Free = false;
|
||||
bool skipScreen1Free = false;
|
||||
@@ -593,14 +593,14 @@ void ConfigUtils::openConfigMenu() {
|
||||
if (!screenbuffer0 || !screenbuffer1) {
|
||||
if (screenbuffer0 == nullptr) {
|
||||
if (storedTVBuffer.buffer_size >= screen_buf0_size) {
|
||||
screenbuffer0 = storedTVBuffer.buffer;
|
||||
screenbuffer0 = storedTVBuffer.buffer;
|
||||
skipScreen0Free = true;
|
||||
DEBUG_FUNCTION_LINE("Use storedTVBuffer");
|
||||
}
|
||||
}
|
||||
if (screenbuffer1 == nullptr) {
|
||||
if (storedDRCBuffer.buffer_size >= screen_buf1_size) {
|
||||
screenbuffer1 = storedDRCBuffer.buffer;
|
||||
screenbuffer1 = storedDRCBuffer.buffer;
|
||||
skipScreen1Free = true;
|
||||
DEBUG_FUNCTION_LINE("Use storedDRCBuffer");
|
||||
}
|
||||
@@ -637,7 +637,7 @@ void ConfigUtils::openConfigMenu() {
|
||||
|
||||
DrawUtils::deinitFont();
|
||||
|
||||
error_exit:
|
||||
error_exit:
|
||||
|
||||
if (storedTVBuffer.buffer != nullptr) {
|
||||
GX2SetTVBuffer(storedTVBuffer.buffer, storedTVBuffer.buffer_size, static_cast<GX2TVRenderMode>(storedTVBuffer.mode),
|
||||
|
||||
@@ -2,31 +2,31 @@
|
||||
|
||||
#include <coreinit/memory.h>
|
||||
#include <coreinit/screen.h>
|
||||
#include <png.h>
|
||||
#include <ft2build.h>
|
||||
#include <png.h>
|
||||
#include FT_FREETYPE_H
|
||||
|
||||
// buffer width
|
||||
#define TV_WIDTH 0x500
|
||||
#define TV_WIDTH 0x500
|
||||
#define DRC_WIDTH 0x380
|
||||
|
||||
bool DrawUtils::isBackBuffer;
|
||||
|
||||
uint8_t *DrawUtils::tvBuffer = nullptr;
|
||||
uint32_t DrawUtils::tvSize = 0;
|
||||
uint8_t *DrawUtils::tvBuffer = nullptr;
|
||||
uint32_t DrawUtils::tvSize = 0;
|
||||
uint8_t *DrawUtils::drcBuffer = nullptr;
|
||||
uint32_t DrawUtils::drcSize = 0;
|
||||
uint32_t DrawUtils::drcSize = 0;
|
||||
|
||||
// Don't put those into the clase or we have to include ft everywhere
|
||||
static FT_Library ft_lib = nullptr;
|
||||
static FT_Face ft_face = nullptr;
|
||||
static FT_Face ft_face = nullptr;
|
||||
static Color font_col(0xFFFFFFFF);
|
||||
|
||||
void DrawUtils::initBuffers(void *tvBuffer_, uint32_t tvSize_, void *drcBuffer_, uint32_t drcSize_) {
|
||||
DrawUtils::tvBuffer = (uint8_t *) tvBuffer_;
|
||||
DrawUtils::tvSize = tvSize_;
|
||||
DrawUtils::tvBuffer = (uint8_t *) tvBuffer_;
|
||||
DrawUtils::tvSize = tvSize_;
|
||||
DrawUtils::drcBuffer = (uint8_t *) drcBuffer_;
|
||||
DrawUtils::drcSize = drcSize_;
|
||||
DrawUtils::drcSize = drcSize_;
|
||||
}
|
||||
|
||||
void DrawUtils::beginDraw() {
|
||||
@@ -68,11 +68,11 @@ void DrawUtils::drawPixel(uint32_t x, uint32_t y, uint8_t r, uint8_t g, uint8_t
|
||||
i += drcSize / 2;
|
||||
}
|
||||
if (a == 0xFF) {
|
||||
drcBuffer[i] = r;
|
||||
drcBuffer[i] = r;
|
||||
drcBuffer[i + 1] = g;
|
||||
drcBuffer[i + 2] = b;
|
||||
} else {
|
||||
drcBuffer[i] = r * opacity + drcBuffer[i] * (1 - opacity);
|
||||
drcBuffer[i] = r * opacity + drcBuffer[i] * (1 - opacity);
|
||||
drcBuffer[i + 1] = g * opacity + drcBuffer[i + 1] * (1 - opacity);
|
||||
drcBuffer[i + 2] = b * opacity + drcBuffer[i + 2] * (1 - opacity);
|
||||
}
|
||||
@@ -87,11 +87,11 @@ void DrawUtils::drawPixel(uint32_t x, uint32_t y, uint8_t r, uint8_t g, uint8_t
|
||||
i += tvSize / 2;
|
||||
}
|
||||
if (a == 0xFF) {
|
||||
tvBuffer[i] = r;
|
||||
tvBuffer[i] = r;
|
||||
tvBuffer[i + 1] = g;
|
||||
tvBuffer[i + 2] = b;
|
||||
} else {
|
||||
tvBuffer[i] = r * opacity + tvBuffer[i] * (1 - opacity);
|
||||
tvBuffer[i] = r * opacity + tvBuffer[i] * (1 - opacity);
|
||||
tvBuffer[i + 1] = g * opacity + tvBuffer[i + 1] * (1 - opacity);
|
||||
tvBuffer[i + 2] = b * opacity + tvBuffer[i + 2] * (1 - opacity);
|
||||
}
|
||||
@@ -122,8 +122,8 @@ void DrawUtils::drawBitmap(uint32_t x, uint32_t y, uint32_t target_width, uint32
|
||||
}
|
||||
|
||||
uint32_t dataPos = __builtin_bswap32(*(uint32_t *) &(data[0x0A]));
|
||||
uint32_t width = __builtin_bswap32(*(uint32_t *) &(data[0x12]));
|
||||
uint32_t height = __builtin_bswap32(*(uint32_t *) &(data[0x16]));
|
||||
uint32_t width = __builtin_bswap32(*(uint32_t *) &(data[0x12]));
|
||||
uint32_t height = __builtin_bswap32(*(uint32_t *) &(data[0x16]));
|
||||
|
||||
if (dataPos == 0) {
|
||||
dataPos = 54;
|
||||
@@ -164,17 +164,17 @@ void DrawUtils::drawPNG(uint32_t x, uint32_t y, const uint8_t *data) {
|
||||
|
||||
png_read_info(png_ptr, info_ptr);
|
||||
|
||||
uint32_t width = 0;
|
||||
uint32_t width = 0;
|
||||
uint32_t height = 0;
|
||||
int bitDepth = 0;
|
||||
int colorType = -1;
|
||||
int bitDepth = 0;
|
||||
int colorType = -1;
|
||||
uint32_t retval = png_get_IHDR(png_ptr, info_ptr, &width, &height, &bitDepth, &colorType, nullptr, nullptr, nullptr);
|
||||
if (retval != 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t bytesPerRow = png_get_rowbytes(png_ptr, info_ptr);
|
||||
auto *rowData = new uint8_t[bytesPerRow];
|
||||
auto *rowData = new uint8_t[bytesPerRow];
|
||||
|
||||
for (uint32_t yy = y; yy < y + height; yy++) {
|
||||
png_read_row(png_ptr, (png_bytep) rowData, nullptr);
|
||||
@@ -195,7 +195,7 @@ void DrawUtils::drawPNG(uint32_t x, uint32_t y, const uint8_t *data) {
|
||||
}
|
||||
|
||||
void DrawUtils::initFont() {
|
||||
void *font = nullptr;
|
||||
void *font = nullptr;
|
||||
uint32_t size = 0;
|
||||
OSGetSharedData(OS_SHAREDDATATYPE_FONT_STANDARD, 0, &font, &size);
|
||||
|
||||
@@ -243,7 +243,8 @@ void DrawUtils::print(uint32_t x, uint32_t y, const char *string, bool alignRigh
|
||||
buffer[num] = 0;
|
||||
} else {
|
||||
wchar_t *tmp = buffer;
|
||||
while ((*tmp++ = *string++));
|
||||
while ((*tmp++ = *string++))
|
||||
;
|
||||
}
|
||||
|
||||
print(x, y, buffer, alignRight);
|
||||
@@ -252,7 +253,7 @@ void DrawUtils::print(uint32_t x, uint32_t y, const char *string, bool alignRigh
|
||||
|
||||
void DrawUtils::print(uint32_t x, uint32_t y, const wchar_t *string, bool alignRight) {
|
||||
FT_GlyphSlot slot = ft_face->glyph;
|
||||
FT_Vector pen = {(int) x, (int) y};
|
||||
FT_Vector pen = {(int) x, (int) y};
|
||||
|
||||
if (alignRight) {
|
||||
pen.x -= getTextWidth(string);
|
||||
@@ -283,7 +284,8 @@ uint32_t DrawUtils::getTextWidth(const char *string) {
|
||||
buffer[num] = 0;
|
||||
} else {
|
||||
wchar_t *tmp = buffer;
|
||||
while ((*tmp++ = *string++));
|
||||
while ((*tmp++ = *string++))
|
||||
;
|
||||
}
|
||||
|
||||
uint32_t width = getTextWidth(buffer);
|
||||
@@ -294,7 +296,7 @@ uint32_t DrawUtils::getTextWidth(const char *string) {
|
||||
|
||||
uint32_t DrawUtils::getTextWidth(const wchar_t *string) {
|
||||
FT_GlyphSlot slot = ft_face->glyph;
|
||||
uint32_t width = 0;
|
||||
uint32_t width = 0;
|
||||
|
||||
for (; *string; string++) {
|
||||
FT_Load_Glyph(ft_face, FT_Get_Char_Index(ft_face, *string), FT_LOAD_BITMAP_METRICS_ONLY);
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <cstdint>
|
||||
|
||||
// visible screen sizes
|
||||
#define SCREEN_WIDTH 854
|
||||
#define SCREEN_WIDTH 854
|
||||
#define SCREEN_HEIGHT 480
|
||||
|
||||
union Color {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#include <cstring>
|
||||
#include <coreinit/cache.h>
|
||||
#include <cstring>
|
||||
|
||||
#include "utils/logger.h"
|
||||
#include "ElfUtils.h"
|
||||
#include "utils/logger.h"
|
||||
|
||||
// See https://github.com/decaf-emu/decaf-emu/blob/43366a34e7b55ab9d19b2444aeb0ccd46ac77dea/src/libdecaf/src/cafe/loader/cafe_loader_reloc.cpp#L144
|
||||
bool ElfUtils::elfLinkOne(char type, size_t offset, int32_t addend, uint32_t destination, uint32_t symbol_addr, relocation_trampoline_entry_t *trampoline_data, uint32_t trampoline_data_length,
|
||||
@@ -12,7 +12,7 @@ bool ElfUtils::elfLinkOne(char type, size_t offset, int32_t addend, uint32_t des
|
||||
}
|
||||
|
||||
auto target = destination + offset;
|
||||
auto value = symbol_addr + addend;
|
||||
auto value = symbol_addr + addend;
|
||||
|
||||
auto relValue = value - static_cast<uint32_t>(target);
|
||||
|
||||
@@ -96,19 +96,19 @@ bool ElfUtils::elfLinkOne(char type, size_t offset, int32_t addend, uint32_t des
|
||||
}
|
||||
if (freeSlot == nullptr) {
|
||||
DEBUG_FUNCTION_LINE("***24-bit relative branch cannot hit target. Trampoline data list is full");
|
||||
DEBUG_FUNCTION_LINE("***value %08X - target %08X = distance %08X", value, target, target - (uint32_t) &(freeSlot->trampoline[0]));
|
||||
DEBUG_FUNCTION_LINE("***value %08X - target %08X = distance %08X", value, target, target - (uint32_t) & (freeSlot->trampoline[0]));
|
||||
return false;
|
||||
}
|
||||
if (target - (uint32_t) &(freeSlot->trampoline[0]) > 0x1FFFFFC) {
|
||||
if (target - (uint32_t) & (freeSlot->trampoline[0]) > 0x1FFFFFC) {
|
||||
DEBUG_FUNCTION_LINE("**Cannot link 24-bit jump (too far to tramp buffer).");
|
||||
DEBUG_FUNCTION_LINE("***value %08X - target %08X = distance %08X", value, target, (target - (uint32_t) &(freeSlot->trampoline[0])));
|
||||
DEBUG_FUNCTION_LINE("***value %08X - target %08X = distance %08X", value, target, (target - (uint32_t) & (freeSlot->trampoline[0])));
|
||||
return false;
|
||||
}
|
||||
|
||||
freeSlot->trampoline[0] = 0x3D600000 | ((((uint32_t) value) >> 16) & 0x0000FFFF); // lis r11, real_addr@h
|
||||
freeSlot->trampoline[1] = 0x616B0000 | (((uint32_t) value) & 0x0000ffff); // ori r11, r11, real_addr@l
|
||||
freeSlot->trampoline[2] = 0x7D6903A6; // mtctr r11
|
||||
freeSlot->trampoline[3] = 0x4E800420; // bctr
|
||||
freeSlot->trampoline[1] = 0x616B0000 | (((uint32_t) value) & 0x0000ffff); // ori r11, r11, real_addr@l
|
||||
freeSlot->trampoline[2] = 0x7D6903A6; // mtctr r11
|
||||
freeSlot->trampoline[3] = 0x4E800420; // bctr
|
||||
DCFlushRange((void *) freeSlot->trampoline, sizeof(freeSlot->trampoline));
|
||||
ICInvalidateRange((unsigned char *) freeSlot->trampoline, sizeof(freeSlot->trampoline));
|
||||
|
||||
@@ -122,9 +122,9 @@ bool ElfUtils::elfLinkOne(char type, size_t offset, int32_t addend, uint32_t des
|
||||
// Relocations for the imports may be overridden
|
||||
freeSlot->status = RELOC_TRAMP_IMPORT_DONE;
|
||||
}
|
||||
auto symbolValue = (uint32_t) &(freeSlot->trampoline[0]);
|
||||
value = symbolValue + addend;
|
||||
distance = static_cast<int32_t>(value) - static_cast<int32_t>(target);
|
||||
auto symbolValue = (uint32_t) & (freeSlot->trampoline[0]);
|
||||
value = symbolValue + addend;
|
||||
distance = static_cast<int32_t>(value) - static_cast<int32_t>(target);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,33 +11,33 @@ int32_t LoadFileToMem(const char *relativefilepath, char **fileOut, uint32_t *si
|
||||
uint32_t load_loader_elf_from_sd(unsigned char *baseAddress, const char *relativePath);
|
||||
uint32_t load_loader_elf(unsigned char *baseAddress, char *elf_data, uint32_t fileSize);
|
||||
|
||||
#define R_PPC_NONE 0
|
||||
#define R_PPC_ADDR32 1
|
||||
#define R_PPC_ADDR16_LO 4
|
||||
#define R_PPC_ADDR16_HI 5
|
||||
#define R_PPC_ADDR16_HA 6
|
||||
#define R_PPC_REL24 10
|
||||
#define R_PPC_REL14 11
|
||||
#define R_PPC_DTPMOD32 68
|
||||
#define R_PPC_DTPREL32 78
|
||||
#define R_PPC_EMB_SDA21 109
|
||||
#define R_PPC_EMB_RELSDA 116
|
||||
#define R_PPC_DIAB_SDA21_LO 180
|
||||
#define R_PPC_DIAB_SDA21_HI 181
|
||||
#define R_PPC_DIAB_SDA21_HA 182
|
||||
#define R_PPC_DIAB_RELSDA_LO 183
|
||||
#define R_PPC_DIAB_RELSDA_HI 184
|
||||
#define R_PPC_DIAB_RELSDA_HA 185
|
||||
#define R_PPC_GHS_REL16_HA 251
|
||||
#define R_PPC_GHS_REL16_HI 252
|
||||
#define R_PPC_GHS_REL16_LO 253
|
||||
#define R_PPC_NONE 0
|
||||
#define R_PPC_ADDR32 1
|
||||
#define R_PPC_ADDR16_LO 4
|
||||
#define R_PPC_ADDR16_HI 5
|
||||
#define R_PPC_ADDR16_HA 6
|
||||
#define R_PPC_REL24 10
|
||||
#define R_PPC_REL14 11
|
||||
#define R_PPC_DTPMOD32 68
|
||||
#define R_PPC_DTPREL32 78
|
||||
#define R_PPC_EMB_SDA21 109
|
||||
#define R_PPC_EMB_RELSDA 116
|
||||
#define R_PPC_DIAB_SDA21_LO 180
|
||||
#define R_PPC_DIAB_SDA21_HI 181
|
||||
#define R_PPC_DIAB_SDA21_HA 182
|
||||
#define R_PPC_DIAB_RELSDA_LO 183
|
||||
#define R_PPC_DIAB_RELSDA_HI 184
|
||||
#define R_PPC_DIAB_RELSDA_HA 185
|
||||
#define R_PPC_GHS_REL16_HA 251
|
||||
#define R_PPC_GHS_REL16_HI 252
|
||||
#define R_PPC_GHS_REL16_LO 253
|
||||
|
||||
// Masks for manipulating Power PC relocation targets
|
||||
#define PPC_WORD32 0xFFFFFFFF
|
||||
#define PPC_WORD30 0xFFFFFFFC
|
||||
#define PPC_LOW24 0x03FFFFFC
|
||||
#define PPC_LOW14 0x0020FFFC
|
||||
#define PPC_HALF16 0xFFFF
|
||||
#define PPC_WORD32 0xFFFFFFFF
|
||||
#define PPC_WORD30 0xFFFFFFFC
|
||||
#define PPC_LOW24 0x03FFFFFC
|
||||
#define PPC_LOW14 0x0020FFFC
|
||||
#define PPC_HALF16 0xFFFF
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -1,40 +1,40 @@
|
||||
#include "StorageUtils.h"
|
||||
#include <string>
|
||||
|
||||
#include "utils/logger.h"
|
||||
#include "utils/json.hpp"
|
||||
#include "fs/CFile.hpp"
|
||||
#include "fs/FSUtils.h"
|
||||
#include "utils/json.hpp"
|
||||
#include "utils/logger.h"
|
||||
|
||||
static void processJson(wups_storage_item_t *items, nlohmann::json json) {
|
||||
if (items == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
items->data = (wups_storage_item_t *) malloc(json.size() * sizeof(wups_storage_item_t));
|
||||
items->data = (wups_storage_item_t *) malloc(json.size() * sizeof(wups_storage_item_t));
|
||||
items->data_size = json.size();
|
||||
|
||||
uint32_t index = 0;
|
||||
for (auto it = json.begin(); it != json.end(); ++it) {
|
||||
wups_storage_item_t *item = &((wups_storage_item_t *) items->data)[index];
|
||||
item->type = WUPS_STORAGE_TYPE_INVALID;
|
||||
item->pending_delete = false;
|
||||
item->data = nullptr;
|
||||
item->key = nullptr;
|
||||
item->type = WUPS_STORAGE_TYPE_INVALID;
|
||||
item->pending_delete = false;
|
||||
item->data = nullptr;
|
||||
item->key = nullptr;
|
||||
|
||||
item->key = (char *) malloc(it.key().size() + 1);
|
||||
strcpy(item->key, it.key().c_str());
|
||||
|
||||
if (it.value().is_string()) {
|
||||
item->type = WUPS_STORAGE_TYPE_STRING;
|
||||
uint32_t size = it.value().get<std::string>().size() + 1;
|
||||
item->data = malloc(size);
|
||||
item->type = WUPS_STORAGE_TYPE_STRING;
|
||||
uint32_t size = it.value().get<std::string>().size() + 1;
|
||||
item->data = malloc(size);
|
||||
item->data_size = size;
|
||||
strcpy((char *) item->data, it.value().get<std::string>().c_str());
|
||||
} else if (it.value().is_number_integer()) {
|
||||
item->type = WUPS_STORAGE_TYPE_INT;
|
||||
item->data = malloc(sizeof(int32_t));
|
||||
item->data_size = sizeof(int32_t);
|
||||
item->type = WUPS_STORAGE_TYPE_INT;
|
||||
item->data = malloc(sizeof(int32_t));
|
||||
item->data_size = sizeof(int32_t);
|
||||
*(int32_t *) item->data = it.value().get<int32_t>();
|
||||
} else if (it.value().is_object()) {
|
||||
if (it.value().size() > 0) {
|
||||
@@ -58,7 +58,7 @@ int StorageUtils::OpenStorage(const char *plugin_id, wups_storage_item_t *items)
|
||||
nlohmann::json j;
|
||||
CFile file(filePath, CFile::ReadOnly);
|
||||
if (file.isOpen() && file.size() > 0) {
|
||||
uint8_t *json_data = new uint8_t[file.size() + 1];
|
||||
uint8_t *json_data = new uint8_t[file.size() + 1];
|
||||
json_data[file.size()] = '\0';
|
||||
|
||||
file.read(json_data, file.size());
|
||||
@@ -113,7 +113,7 @@ int StorageUtils::CloseStorage(const char *plugin_id, wups_storage_item_t *items
|
||||
}
|
||||
|
||||
std::string folderPath = "fs:/vol/external01/wiiu/plugins/config/";
|
||||
std::string filePath = folderPath + plugin_id + ".json";
|
||||
std::string filePath = folderPath + plugin_id + ".json";
|
||||
|
||||
FSUtils::CreateSubfolder(folderPath.c_str());
|
||||
|
||||
|
||||
@@ -23,14 +23,14 @@
|
||||
*
|
||||
* for WiiXplorer 2010
|
||||
***************************************************************************/
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <cstdarg>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <string.h>
|
||||
#include <wut_types.h>
|
||||
#include <cstdio>
|
||||
#include <string>
|
||||
#include <utils/StringTools.h>
|
||||
#include <vector>
|
||||
#include <wut_types.h>
|
||||
|
||||
|
||||
BOOL StringTools::EndsWith(const std::string &a, const std::string &b) {
|
||||
@@ -82,7 +82,7 @@ const wchar_t *StringTools::wfmt(const char *format, ...) {
|
||||
static char tmp[512];
|
||||
static wchar_t strWChar[512];
|
||||
strWChar[0] = 0;
|
||||
tmp[0] = 0;
|
||||
tmp[0] = 0;
|
||||
|
||||
if (!format)
|
||||
return (const wchar_t *) strWChar;
|
||||
@@ -95,7 +95,7 @@ const wchar_t *StringTools::wfmt(const char *format, ...) {
|
||||
if ((vsprintf(tmp, format, va) >= 0)) {
|
||||
int bt;
|
||||
int32_t strlength = strlen(tmp);
|
||||
bt = mbstowcs(strWChar, tmp, (strlength < 512) ? strlength : 512);
|
||||
bt = mbstowcs(strWChar, tmp, (strlength < 512) ? strlength : 512);
|
||||
|
||||
if (bt > 0) {
|
||||
strWChar[bt] = 0;
|
||||
@@ -109,13 +109,13 @@ const wchar_t *StringTools::wfmt(const char *format, ...) {
|
||||
|
||||
int32_t StringTools::strprintf(std::string &str, const char *format, ...) {
|
||||
static char tmp[512];
|
||||
tmp[0] = 0;
|
||||
tmp[0] = 0;
|
||||
int32_t result = 0;
|
||||
|
||||
va_list va;
|
||||
va_start(va, format);
|
||||
if ((vsprintf(tmp, format, va) >= 0)) {
|
||||
str = tmp;
|
||||
str = tmp;
|
||||
result = str.size();
|
||||
}
|
||||
va_end(va);
|
||||
|
||||
@@ -26,8 +26,8 @@
|
||||
#ifndef __STRING_TOOLS_H
|
||||
#define __STRING_TOOLS_H
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <wut_types.h>
|
||||
|
||||
class StringTools {
|
||||
@@ -56,7 +56,7 @@ public:
|
||||
if (!path)
|
||||
return path;
|
||||
|
||||
const char *ptr = path;
|
||||
const char *ptr = path;
|
||||
const char *Filename = ptr;
|
||||
|
||||
while (*ptr != '\0') {
|
||||
@@ -86,4 +86,3 @@ public:
|
||||
};
|
||||
|
||||
#endif /* __STRING_TOOLS_H */
|
||||
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
#include <coreinit/cache.h>
|
||||
#include "../plugin/PluginMetaInformationFactory.h"
|
||||
#include "exports.h"
|
||||
#include "../PluginManagement.h"
|
||||
#include "../globals.h"
|
||||
#include "../plugin/PluginContainer.h"
|
||||
#include "../plugin/PluginContainerPersistence.h"
|
||||
#include "../plugin/PluginDataFactory.h"
|
||||
#include "../PluginManagement.h"
|
||||
#include "../globals.h"
|
||||
#include "../plugin/PluginDataPersistence.h"
|
||||
#include "exports.h"
|
||||
#include "../plugin/PluginMetaInformationFactory.h"
|
||||
#include <coreinit/cache.h>
|
||||
#include <wums.h>
|
||||
|
||||
void fillPluginInformation(plugin_information *out, const std::shared_ptr<PluginMetaInformation> &metaInformation) {
|
||||
static void fillPluginInformation(plugin_information *out, const std::shared_ptr<PluginMetaInformation> &metaInformation) {
|
||||
out->plugin_information_version = PLUGIN_INFORMATION_VERSION;
|
||||
strncpy(out->author, metaInformation->getAuthor().c_str(), sizeof(out->author) - 1);
|
||||
strncpy(out->buildTimestamp, metaInformation->getBuildTimestamp().c_str(), sizeof(out->buildTimestamp) - 1);
|
||||
@@ -26,7 +26,7 @@ extern "C" PluginBackendApiErrorType WUPSLoadAndLinkByDataHandle(const plugin_da
|
||||
if (plugin_data_handle_list != nullptr && plugin_data_handle_list_size != 0) {
|
||||
for (uint32_t i = 0; i < plugin_data_handle_list_size; i++) {
|
||||
plugin_data_handle handle = plugin_data_handle_list[i];
|
||||
auto *pluginData = (PluginData *) handle;
|
||||
auto *pluginData = (PluginData *) handle;
|
||||
PluginDataPersistence::save(&gLinkOnReload.plugin_data[gLinkOnReload.number_used_plugins], pluginData);
|
||||
|
||||
gLinkOnReload.number_used_plugins++;
|
||||
@@ -45,7 +45,7 @@ extern "C" PluginBackendApiErrorType WUPSLoadAndLinkByDataHandle(const plugin_da
|
||||
extern "C" PluginBackendApiErrorType WUPSDeletePluginContainer(const plugin_container_handle *handle_list, uint32_t handle_list_size) {
|
||||
if (handle_list != nullptr && handle_list_size != 0) {
|
||||
for (uint32_t i = 0; i < handle_list_size; i++) {
|
||||
auto handle = handle_list[i];
|
||||
auto handle = handle_list[i];
|
||||
auto *pluginContainer = (PluginContainer *) handle;
|
||||
delete pluginContainer;
|
||||
}
|
||||
@@ -56,7 +56,7 @@ extern "C" PluginBackendApiErrorType WUPSDeletePluginContainer(const plugin_cont
|
||||
extern "C" PluginBackendApiErrorType WUPSDeletePluginData(const plugin_data_handle *plugin_data_handle_list, uint32_t plugin_data_handle_list_size) {
|
||||
if (plugin_data_handle_list != nullptr && plugin_data_handle_list_size != 0) {
|
||||
for (uint32_t i = 0; i < plugin_data_handle_list_size; i++) {
|
||||
auto handle = plugin_data_handle_list[i];
|
||||
auto handle = plugin_data_handle_list[i];
|
||||
auto *pluginData = (PluginData *) handle;
|
||||
delete pluginData;
|
||||
}
|
||||
@@ -86,7 +86,7 @@ extern "C" PluginBackendApiErrorType WUPSLoadPluginAsData(GetPluginInformationIn
|
||||
return PLUGIN_BACKEND_API_ERROR_INVALID_ARG;
|
||||
} else {
|
||||
auto *pluginDataHandle = new PluginData(*pluginData.value());
|
||||
*out = (uint32_t) pluginDataHandle;
|
||||
*out = (uint32_t) pluginDataHandle;
|
||||
}
|
||||
|
||||
return PLUGIN_BACKEND_API_ERROR_NONE;
|
||||
@@ -138,9 +138,9 @@ extern "C" PluginBackendApiErrorType WUPSGetPluginDataForContainerHandles(const
|
||||
PluginBackendApiErrorType res = PLUGIN_BACKEND_API_ERROR_NONE;
|
||||
if (plugin_container_handle_list != nullptr && buffer_size != 0) {
|
||||
for (uint32_t i = 0; i < buffer_size; i++) {
|
||||
auto handle = plugin_container_handle_list[i];
|
||||
auto *container = (PluginContainer *) handle;
|
||||
auto *pluginData = new PluginData(*container->getPluginData());
|
||||
auto handle = plugin_container_handle_list[i];
|
||||
auto *container = (PluginContainer *) handle;
|
||||
auto *pluginData = new PluginData(*container->getPluginData());
|
||||
plugin_data_list[i] = (uint32_t) pluginData;
|
||||
}
|
||||
} else {
|
||||
@@ -154,7 +154,7 @@ extern "C" PluginBackendApiErrorType WUPSGetMetaInformation(const plugin_contain
|
||||
PluginBackendApiErrorType res = PLUGIN_BACKEND_API_ERROR_NONE;
|
||||
if (plugin_container_handle_list != nullptr && buffer_size != 0) {
|
||||
for (uint32_t i = 0; i < buffer_size; i++) {
|
||||
auto handle = plugin_container_handle_list[i];
|
||||
auto handle = plugin_container_handle_list[i];
|
||||
auto *container = (PluginContainer *) handle;
|
||||
|
||||
plugin_information_list[i].plugin_information_version = PLUGIN_INFORMATION_VERSION;
|
||||
@@ -180,11 +180,11 @@ extern "C" PluginBackendApiErrorType WUPSGetLoadedPlugins(plugin_container_handl
|
||||
return PLUGIN_BACKEND_API_ERROR_INVALID_ARG;
|
||||
}
|
||||
*plugin_information_version = PLUGIN_INFORMATION_VERSION;
|
||||
auto plugins = PluginContainerPersistence::loadPlugins(gPluginInformation);
|
||||
uint32_t counter = 0;
|
||||
for (auto &plugin: plugins) {
|
||||
auto plugins = PluginContainerPersistence::loadPlugins(gPluginInformation);
|
||||
uint32_t counter = 0;
|
||||
for (auto &plugin : plugins) {
|
||||
if (counter < buffer_size) {
|
||||
auto *container = new PluginContainer(*plugin);
|
||||
auto *container = new PluginContainer(*plugin);
|
||||
io_handles[counter] = (uint32_t) container;
|
||||
counter++;
|
||||
} else {
|
||||
|
||||
@@ -7,8 +7,6 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void fillPluginInformation(plugin_information *out, PluginMetaInformation *metaInformation);
|
||||
|
||||
PluginBackendApiErrorType WUPSLoadAndLinkByDataHandle(const plugin_data_handle *plugin_data_handle_list, uint32_t plugin_data_handle_list_size);
|
||||
|
||||
PluginBackendApiErrorType WUPSDeletePluginContainer(const plugin_container_handle *handle_list, uint32_t handle_list_size);
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// clang-format off
|
||||
/*
|
||||
__ _____ _____ _____
|
||||
__| | __| | | | JSON for Modern C++
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
#ifdef DEBUG
|
||||
#include <stdint.h>
|
||||
#include <whb/log_udp.h>
|
||||
#include <whb/log_cafe.h>
|
||||
#include <whb/log_module.h>
|
||||
#include <whb/log_udp.h>
|
||||
|
||||
uint32_t moduleLogInit = false;
|
||||
uint32_t cafeLogInit = false;
|
||||
uint32_t udpLogInit = false;
|
||||
uint32_t cafeLogInit = false;
|
||||
uint32_t udpLogInit = false;
|
||||
#endif // DEBUG
|
||||
|
||||
void initLogging() {
|
||||
#ifdef DEBUG
|
||||
if (!(moduleLogInit = WHBLogModuleInit())) {
|
||||
cafeLogInit = WHBLogCafeInit();
|
||||
udpLogInit = WHBLogUdpInit();
|
||||
udpLogInit = WHBLogUdpInit();
|
||||
}
|
||||
#endif // DEBUG
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <whb/log.h>
|
||||
#include <string.h>
|
||||
#include <whb/log.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -9,26 +9,28 @@ extern "C" {
|
||||
|
||||
#ifdef DEBUG
|
||||
|
||||
#define __FILENAME_X__ (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)
|
||||
#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILENAME_X__)
|
||||
#define __FILENAME_X__ (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)
|
||||
#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILENAME_X__)
|
||||
|
||||
#define DEBUG_FUNCTION_LINE_VERBOSE(FMT, ARGS...) while (0)
|
||||
|
||||
#define DEBUG_FUNCTION_LINE(FMT, ARGS...)do { \
|
||||
WHBLogPrintf("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \
|
||||
#define DEBUG_FUNCTION_LINE(FMT, ARGS...) \
|
||||
do { \
|
||||
WHBLogPrintf("[%23s]%30s@L%04d: " FMT "", __FILENAME__, __FUNCTION__, __LINE__, ##ARGS); \
|
||||
} while (0)
|
||||
|
||||
#define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...)do { \
|
||||
WHBLogWritef("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \
|
||||
#define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...) \
|
||||
do { \
|
||||
WHBLogWritef("[%23s]%30s@L%04d: " FMT "", __FILENAME__, __FUNCTION__, __LINE__, ##ARGS); \
|
||||
} while (0)
|
||||
|
||||
#else
|
||||
|
||||
#define DEBUG_FUNCTION_LINE_VERBOSE(FMT, ARGS...) while (0)
|
||||
|
||||
#define DEBUG_FUNCTION_LINE(FMT, ARGS...) while (0)
|
||||
#define DEBUG_FUNCTION_LINE(FMT, ARGS...) while (0)
|
||||
|
||||
#define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...) while (0)
|
||||
#define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...) while (0)
|
||||
|
||||
#endif
|
||||
|
||||
@@ -39,4 +41,3 @@ void deinitLogging();
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "utils/logger.h"
|
||||
#include <malloc.h>
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <malloc.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <whb/log.h>
|
||||
#include "utils/logger.h"
|
||||
|
||||
// https://gist.github.com/ccbrown/9722406
|
||||
void dumpHex(const void *data, size_t size) {
|
||||
|
||||
@@ -7,28 +7,29 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define LIMIT(x, min, max) \
|
||||
({ \
|
||||
typeof( x ) _x = x; \
|
||||
typeof( min ) _min = min; \
|
||||
typeof( max ) _max = max; \
|
||||
( ( ( _x ) < ( _min ) ) ? ( _min ) : ( ( _x ) > ( _max ) ) ? ( _max) : ( _x ) ); \
|
||||
})
|
||||
#define LIMIT(x, min, max) \
|
||||
({ \
|
||||
typeof(x) _x = x; \
|
||||
typeof(min) _min = min; \
|
||||
typeof(max) _max = max; \
|
||||
(((_x) < (_min)) ? (_min) : ((_x) > (_max)) ? (_max) \
|
||||
: (_x)); \
|
||||
})
|
||||
|
||||
#define DegToRad(a) ( (a) * 0.01745329252f )
|
||||
#define RadToDeg(a) ( (a) * 57.29577951f )
|
||||
#define DegToRad(a) ((a) *0.01745329252f)
|
||||
#define RadToDeg(a) ((a) *57.29577951f)
|
||||
|
||||
#define ALIGN4(x) (((x) + 3) & ~3)
|
||||
#define ALIGN32(x) (((x) + 31) & ~31)
|
||||
#define ALIGN4(x) (((x) + 3) & ~3)
|
||||
#define ALIGN32(x) (((x) + 31) & ~31)
|
||||
|
||||
// those work only in powers of 2
|
||||
#define ROUNDDOWN(val, align) ((val) & ~(align-1))
|
||||
#define ROUNDUP(val, align) ROUNDDOWN(((val) + (align-1)), align)
|
||||
#define ROUNDDOWN(val, align) ((val) & ~(align - 1))
|
||||
#define ROUNDUP(val, align) ROUNDDOWN(((val) + (align - 1)), align)
|
||||
|
||||
|
||||
#define le16(i) ((((uint16_t) ((i) & 0xFF)) << 8) | ((uint16_t) (((i) & 0xFF00) >> 8)))
|
||||
#define le32(i) ((((uint32_t)le16((i) & 0xFFFF)) << 16) | ((uint32_t)le16(((i) & 0xFFFF0000) >> 16)))
|
||||
#define le64(i) ((((uint64_t)le32((i) & 0xFFFFFFFFLL)) << 32) | ((uint64_t)le32(((i) & 0xFFFFFFFF00000000LL) >> 32)))
|
||||
#define le16(i) ((((uint16_t) ((i) &0xFF)) << 8) | ((uint16_t) (((i) &0xFF00) >> 8)))
|
||||
#define le32(i) ((((uint32_t) le16((i) &0xFFFF)) << 16) | ((uint32_t) le16(((i) &0xFFFF0000) >> 16)))
|
||||
#define le64(i) ((((uint64_t) le32((i) &0xFFFFFFFFLL)) << 32) | ((uint64_t) le32(((i) &0xFFFFFFFF00000000LL) >> 32)))
|
||||
|
||||
//Needs to have log_init() called beforehand.
|
||||
void dumpHex(const void *data, size_t size);
|
||||
|
||||
Reference in New Issue
Block a user