JUtility wii (#3061)

* JUtility wii

* lbl_8074CFA4
This commit is contained in:
Jcw87
2026-01-20 20:28:42 -08:00
committed by GitHub
parent c256a9965e
commit 7e0d9c3169
13 changed files with 185 additions and 142 deletions
+16 -16
View File
@@ -6,6 +6,15 @@
#include "JSystem/JUtility/JUTVideo.h"
#include <cstdio>
inline void enter_(int param_0, int param_1, int param_2, const char* fmt, va_list args) {
char buf[0x100];
int ret = vsnprintf(buf, 0x100, fmt, args);
if (ret < 0) {
return;
}
JUTDbPrint::getManager()->enter(param_0, param_1, param_2, buf, ret < 0x100 ? ret : 0xFF);
}
JUTDbPrint::JUTDbPrint(JUTFont* pFont, JKRHeap* pHeap) {
mFont = pFont;
mFirst = NULL;
@@ -50,6 +59,11 @@ void JUTDbPrint::enter(int param_0, int param_1, int param_2, const char* param_
}
}
static void dummy() {
va_list args;
enter_(0, 0, 0, 0, args);
}
void JUTDbPrint::flush() {
this->flush(0, 0, JUTVideo::getManager()->getFbWidth(), JUTVideo::getManager()->getEfbHeight());
}
@@ -89,27 +103,13 @@ void JUTDbPrint::drawString(int posX, int posY, int len, const u8* str) {
void JUTReport(int param_0, int param_1, char const* fmt, ...) {
va_list args;
va_start(args, fmt);
char buf[0x100];
int ret = vsnprintf(buf, 0x100, fmt, args);
enter_(param_0, param_1, 1, fmt, args);
va_end(args);
if (ret < 0) {
return;
}
JUTDbPrint::sDebugPrint->enter(param_0, param_1, 1, buf, ret < 0x100 ? ret : 0xFF);
}
void JUTReport(int param_0, int param_1, int param_2, char const* fmt, ...) {
va_list args;
va_start(args, fmt);
char buf[0x100];
int ret = vsnprintf(buf, 0x100, fmt, args);
enter_(param_0, param_1, param_2, fmt, args);
va_end(args);
if (ret < 0) {
return;
}
JUTDbPrint::sDebugPrint->enter(param_0, param_1, param_2, buf, ret < 0x100 ? ret : 0xFF);
}
+30 -35
View File
@@ -10,8 +10,21 @@
#include <dolphin/dolphin.h>
#include <stdint.h>
struct CallbackObject {
/* 0x00 */ JUTExceptionUserCallback callback;
/* 0x04 */ u16 error;
/* 0x08 */ OSContext* context;
/* 0x0C */ int param_3;
/* 0x10 */ int param_4;
};
OSMessageQueue JUTException::sMessageQueue = {0};
STATIC_ASSERT(sizeof(CallbackObject) == 0x14);
static CallbackObject exCallbackObject;
JSUList<JUTException::JUTExMapFile> JUTException::sMapFileList(false);
static OSTime c3bcnt[4] = {0, 0, 0, 0};
const char* JUTException::sCpuExpName[17] = {
@@ -38,10 +51,16 @@ JUTException* JUTException::sErrorManager;
JUTExceptionUserCallback JUTException::sPreUserCallback;
JUTExceptionUserCallback JUTException::sPostUserCallback;
JUTExceptionUserCallback JUTException::sPostUserCallback;
#if PLATFORM_GCN
const int stack_size = 0x1C00;
#else
const int stack_size = 0x4000;
#endif
JUTException::JUTException(JUTDirectPrint* directPrint)
: JKRThread(0x1C00, 0x10, 0), mDirectPrint(directPrint) {
: JKRThread(stack_size, 0x10, 0), mDirectPrint(directPrint) {
OSSetErrorHandler(__OS_EXCEPTION_DSI, (OSErrorHandler)errorHandler);
OSSetErrorHandler(__OS_EXCEPTION_ISI, (OSErrorHandler)errorHandler);
OSSetErrorHandler(__OS_EXCEPTION_PROGRAM, (OSErrorHandler)errorHandler);
@@ -74,16 +93,6 @@ JUTException* JUTException::create(JUTDirectPrint* directPrint) {
OSMessage JUTException::sMessageBuffer[1] = {0};
struct CallbackObject {
/* 0x00 */ JUTExceptionUserCallback callback;
/* 0x04 */ u16 error;
/* 0x06 */ u16 pad_0x06;
/* 0x08 */ OSContext* context;
/* 0x0C */ int param_3;
/* 0x10 */ int param_4;
/* 0x14 */
};
void* JUTException::run() {
u32 msr = PPCMfmsr();
msr &= ~0x0900;
@@ -118,9 +127,6 @@ void* JUTException::run() {
}
}
STATIC_ASSERT(sizeof(CallbackObject) == 0x14);
static CallbackObject exCallbackObject;
void* JUTException::sConsoleBuffer;
u32 JUTException::sConsoleBufferSize;
@@ -154,8 +160,6 @@ void JUTException::errorHandler(OSError error, OSContext* context, u32 param_3,
OSYieldThread();
}
JSUList<JUTException::JUTExMapFile> JUTException::sMapFileList(false);
void JUTException::panic_f_va(char const* file, int line, char const* format, va_list args) {
char buffer[256];
vsnprintf(buffer, sizeof(buffer) - 1, format, args);
@@ -525,12 +529,8 @@ bool JUTException::isEnablePad() const {
bool JUTException::readPad(u32* out_trigger, u32* out_button) {
bool result = false;
OSTime start_time = OSGetTime();
OSTime ms;
do {
OSTime end_time = OSGetTime();
OSTime ticks = end_time - start_time;
ms = ticks / (OS_TIMER_CLOCK / 1000);
} while (ms < 0x32);
} while (OSTicksToMilliseconds(OSGetTime() - start_time) < 0x32);
if (mGamePad == (JUTGamePad*)0xffffffff) {
JUTGamePad gamePad0(JUTGamePad::EPort1);
@@ -750,24 +750,19 @@ void JUTException::printContext(OSError error, OSContext* context, u32 dsisr, u3
}
void JUTException::waitTime(s32 timeout_ms) {
if (timeout_ms) {
OSTime start_time = OSGetTime();
OSTime ms;
do {
OSTime end_time = OSGetTime();
OSTime ticks = end_time - start_time;
ms = ticks / (OS_TIMER_CLOCK / 1000);
} while (ms < timeout_ms);
if (!timeout_ms) {
return;
}
OSTime start_time = OSGetTime();
do {
} while (OSTicksToMilliseconds(OSGetTime() - start_time) < timeout_ms);
}
void JUTException::createFB() {
_GXRenderModeObj* renderMode = &GXNtsc480Int;
void* end = (void*)OSGetArenaHi();
u16 width = ALIGN_NEXT(renderMode->fbWidth, 16);
u16 height = renderMode->xfbHeight;
u32 pixel_count = width * height;
u32 size = pixel_count * 2;
u32 size = (u16(ALIGN_NEXT(u16(renderMode->fbWidth), 16)) * renderMode->xfbHeight) * 2;
void* begin = (void*)ALIGN_PREV((uintptr_t)end - size, 32);
void* object = (void*)ALIGN_PREV((s32)begin - sizeof(JUTExternalFB), 32);
@@ -807,7 +802,7 @@ void JUTException::appendMapFile(char const* path) {
}
for (JSUListIterator<JUTExMapFile> iterator = sMapFileList.getFirst(); iterator != sMapFileList.getEnd(); iterator++) {
if (strcmp(path, iterator->mPath) == 0) {
if (strcmp(path, iterator.getObject()->mPath) == 0) {
return;
}
}
+25 -13
View File
@@ -50,6 +50,8 @@ void JUTGamePad::initList() {
u32 JUTGamePad::sSuppressPadReset;
u8 data_8074CFA4_debug;
s32 JUTGamePad::sAnalogMode;
BOOL JUTGamePad::init() {
@@ -80,7 +82,7 @@ u32 JUTGamePad::sRumbleSupported;
u32 JUTGamePad::read() {
sRumbleSupported = PADRead(mPadStatus);
switch (getClampMode()) {
switch (sClampMode) {
case EClampStick:
PADClamp(mPadStatus);
break;
@@ -89,17 +91,18 @@ u32 JUTGamePad::read() {
break;
}
u32 reset_mask = 0;
u32 bittest;
u32 reset_mask = 0;
for (int i = 0; i < 4; i++) {
bittest = PAD_CHAN0_BIT >> i;
if (mPadStatus[i].err == 0) {
PADStatus* pad_status = &mPadStatus[i];
u32 stick_status;
stick_status = mPadMStick[i].update(mPadStatus[i].stickX, mPadStatus[i].stickY, sStickMode, EMainStick, mPadButton[i].mButton) << 0x18;
stick_status |= (mPadSStick[i].update(mPadStatus[i].substickX, mPadStatus[i].substickY, sStickMode, ESubStick, mPadButton[i].mButton) << 0x10);
stick_status = mPadMStick[i].update(pad_status->stickX, pad_status->stickY, sStickMode, EMainStick, mPadButton[i].mButton) << 0x18;
stick_status |= (mPadSStick[i].update(pad_status->substickX, pad_status->substickY, sStickMode, ESubStick, mPadButton[i].mButton) << 0x10);
mPadButton[i].update(&mPadStatus[i], stick_status);
mPadButton[i].update(pad_status, stick_status);
} else if (mPadStatus[i].err == -1) {
mPadMStick[i].update(0, 0, sStickMode, EMainStick, 0);
mPadSStick[i].update(0, 0, sStickMode, ESubStick, 0);
@@ -109,6 +112,9 @@ u32 JUTGamePad::read() {
reset_mask |= bittest;
}
} else {
if (data_8074CFA4_debug) {
OS_REPORT("game pad read error (%d)\n", mPadStatus[i].err);
}
mPadButton[i].mTrigger = 0;
mPadButton[i].mRelease = 0;
mPadButton[i].mRepeat = 0;
@@ -135,9 +141,11 @@ u32 JUTGamePad::read() {
}
if (pad->getPadRecord() != NULL && pad->getPadRecord()->isActive()) {
int port = pad->mPortNum;
if (port >= 0 && mPadStatus[port].err == 0) {
pad->getPadRecord()->write(&mPadStatus[port]);
if (pad->mPortNum >= 0) {
int port = pad->mPortNum;
if (mPadStatus[port].err == 0) {
pad->getPadRecord()->write(&mPadStatus[port]);
}
}
}
}
@@ -388,17 +396,21 @@ u32 JUTGamePad::CStick::getButton(u32 buttons) {
if (-sReleasePoint < mPosX && mPosX < sReleasePoint) {
button = button & ~0x3;
} else if (mPosX <= -sPressPoint) {
button = (button & ~0x2) | 1;
button = (button & ~0x2);
button |= 1;
} else if (mPosX >= sPressPoint) {
button = (button & ~0x1) | 2;
button = (button & ~0x1);
button |= 2;
}
if (-sReleasePoint < mPosY && mPosY < sReleasePoint) {
button = button & ~0xC;
} else if (mPosY <= -sPressPoint) {
button = (button & ~0x8) | 4;
button = (button & ~0x8);
button |= 4;
} else if (mPosY >= sPressPoint) {
button = (button & ~0x4) | 8;
button = (button & ~0x4);
button |= 8;
}
return button;
@@ -463,7 +475,7 @@ void JUTGamePad::CRumble::update(s16 port) {
stopMotorHard(port);
mLength = 0;
} else if (mFrameCount == 0) {
if (mStatus[port] == 0) {
if (mStatus[port] == false) {
startMotor(port);
}
return;
+4
View File
@@ -56,9 +56,11 @@ JUTVideo::~JUTVideo() {
}
void JUTVideo::preRetraceProc(u32 retrace_count) {
#if PLATFORM_GCN
if (!sManager) {
return;
}
#endif
if (sManager->mPreCallback) {
(*sManager->mPreCallback)(retrace_count);
@@ -166,9 +168,11 @@ void JUTVideo::drawDoneCallback() {
}
void JUTVideo::postRetraceProc(u32 retrace_count) {
#if PLATFORM_GCN
if (!sManager) {
return;
}
#endif
if (sManager->mPostCallback != NULL) {
sManager->mPostCallback(retrace_count);