From b791f26f44c9344108a4166f6b3347085000b421 Mon Sep 17 00:00:00 2001 From: SwareJonge <41187958+SwareJonge@users.noreply.github.com> Date: Mon, 16 Jun 2025 22:11:30 +0200 Subject: [PATCH 1/9] match JFramework --- configure.py | 2 +- include/JSystem/JFramework/JFWDisplay.h | 164 ++++++ include/JSystem/JFramework/JFWSystem.h | 70 +++ include/JSystem/JGeometry.h | 1 + include/JSystem/JSystem.h | 2 +- include/JSystem/JUtility/JUTDbPrint.h | 48 ++ include/JSystem/JUtility/JUTDirectPrint.h | 2 +- include/JSystem/JUtility/JUTException.h | 149 +++++ include/JSystem/JUtility/JUTFader.h | 49 ++ include/JSystem/JUtility/JUTGraphFifo.h | 43 ++ include/JSystem/JUtility/JUTVideo.h | 19 +- include/JSystem/JUtility/JUTXfb.h | 84 +++ include/dolphin/vi.h | 2 + src/static/JSystem/JFramework/.gitkeep | 0 src/static/JSystem/JFramework/JFWDisplay.cpp | 548 +++++++++++++++++++ src/static/JSystem/JFramework/JFWSystem.cpp | 93 ++++ 16 files changed, 1262 insertions(+), 14 deletions(-) create mode 100644 include/JSystem/JFramework/JFWDisplay.h create mode 100644 include/JSystem/JFramework/JFWSystem.h create mode 100644 include/JSystem/JUtility/JUTException.h create mode 100644 include/JSystem/JUtility/JUTFader.h create mode 100644 include/JSystem/JUtility/JUTGraphFifo.h create mode 100644 include/JSystem/JUtility/JUTXfb.h delete mode 100644 src/static/JSystem/JFramework/.gitkeep create mode 100644 src/static/JSystem/JFramework/JFWDisplay.cpp create mode 100644 src/static/JSystem/JFramework/JFWSystem.cpp diff --git a/configure.py b/configure.py index 1fe8bced..4b04f89b 100644 --- a/configure.py +++ b/configure.py @@ -618,7 +618,7 @@ config.libs = [ JSystemLib( "JFramework", [ - Object(NonMatching, "JSystem/JFramework/JFWDisplay.cpp"), + Object(Matching, "JSystem/JFramework/JFWDisplay.cpp"), Object(NonMatching, "JSystem/JFramework/JFWSystem.cpp"), ], ), diff --git a/include/JSystem/JFramework/JFWDisplay.h b/include/JSystem/JFramework/JFWDisplay.h new file mode 100644 index 00000000..c118717c --- /dev/null +++ b/include/JSystem/JFramework/JFWDisplay.h @@ -0,0 +1,164 @@ +#ifndef _JSYSTEM_JFW_JFWDISPLAY_H +#define _JSYSTEM_JFW_JFWDISPLAY_H + +#include +#include +#include "JSystem/JKernel/JKRHeap.h" +#include "JSystem/JUtility/JUTDirectPrint.h" +#include "JSystem/JUtility/JUTFader.h" +#include "JSystem/JUtility/JUTProcBar.h" +#include "JSystem/JUtility/JUTVideo.h" +#include "JSystem/JUtility/JUTXfb.h" +#include "JSystem/JUtility/TColor.h" +#include "types.h" + +typedef void (*JFWDisplayUnkFunc)(void); + +extern GC_Mtx e_mtx; + +class JFWAlarm : public OSAlarm { // everything here seems to be auto inlined or unused +public: + // Contructor and Destructor are both present in map but unused, not sure if it belongs here + JFWAlarm() {} + ~JFWAlarm() {} + void createAlarm() { OSCreateAlarm(this); } + void cancelAlarm() { OSCancelAlarm(this); } + + OSThread *getThread() const { return mThread; } + void setThread(OSThread *thread) { mThread = thread; } + + static JSUList sList;// + +public: + /* 0x28 */ OSThread *mThread; +}; + +class JFWDisplay +{ +public: + enum EDrawDone + { + /* 0x0 */ UNK_METHOD_0 = 0, + /* 0x1 */ UNK_METHOD_1 = 1 + }; + + static JFWDisplay *createManager(const _GXRenderModeObj *, JKRHeap *, JUTXfb::EXfbNumber, bool); // 0x80015bfc + void waitBlanking(int); // 0x8001684c + void threadSleep(s64); // 0x800169fc + void clearEfb_init(); // 0x80016ab8 + void clearEfb(); // 0x80016b2c + void clearEfb(_GXColor); // 0x80016b58 + void clearEfb(int, int, int, int, _GXColor); // 0x80016b9c + void calcCombinationRatio(); // 0x80016f0c + + void ctor_subroutine(const GXRenderModeObj *, bool); + JFWDisplay(const GXRenderModeObj *, JKRHeap *, JUTXfb::EXfbNumber, bool); + + static void destroyManager(); + void prepareCopyDisp(); + void drawendXfb_single(); + void exchangeXfb_double(); + void exchangeXfb_triple(); + void copyXfb_triple(); + void preGX(); + void endGX(); + void* changeToSingleXfb(int); + void* changeToDoubleXfb(); + + // UNUSED + JFWDisplay(void *, bool); + JFWDisplay(void *, void *, bool); + JFWDisplay(void *, void *, void *, bool); + void createManager(const _GXRenderModeObj *, void *, bool); + void createManager(const _GXRenderModeObj *, void *, void *, bool); + void createManager(const _GXRenderModeObj *, void *, void *, void *, bool); + void deleteToSingleXfb(int); + void deleteToSingleXfb(void *); + void addToDoubleXfb(void *, bool); + void addToDoubleXfb(JKRHeap *); + void clearAllXfb(); + s32 frameToTick(float); + static void setForOSResetSystem(); + + // Virtual functions + virtual void beginRender(); // 0x80015e0c + virtual void endRender(); // 0x8001633c + virtual void endFrame(); // 0x8001669c + virtual ~JFWDisplay(); // 0x80015b80 + + static JFWDisplay *getManager() { return sManager; } + + int getEfbHeight() const { + return JUTVideo::getManager()->getEfbHeight(); + } + + int getEfbWidth() const { + return JUTVideo::getManager()->getFbWidth(); + } + + JUTFader *getFader() const { return mFader; } + void setFader(JUTFader * fader) { mFader = fader; } + + bool startFadeOut(int duration) { + if (mFader != nullptr) { + return mFader->startFadeOut(duration); + } + return true; + } + + bool startFadeIn(int duration) { + if (mFader != nullptr) { + return mFader->startFadeIn(duration); + } + return true; + } + + void setTickRate(u32 rate) { + mTickRate = rate; + mFrameRate = 0; + } + JUtility::TColor getClearColor() const { + return mClearColor; + } + + void setClearColor(u8 r, u8 g, u8 b, u8 a) { + mClearColor.set(r, g, b, a); + } + + void setClearColor(JUtility::TColor color) + { + mClearColor = color; + } + + void setFBAlpha(bool enable) { + mEnableAlpha = enable; + } + + bool getFBAlpha() + { + return mEnableAlpha; + } + + static JFWDisplay *sManager; // 0x80415718 + +private: + JUTFader *mFader; // 04 + const GXRenderModeObj *mRMode; // 08 + JUtility::TColor mClearColor; // 0c + u32 mZClear; // 10 + JUTXfb *mXfb; // 14 + u16 mGamma; // 18 + EDrawDone mDrawDoneMethod; // 1c + u16 mFrameRate; // 20 + u32 mTickRate; // 24 + bool mEnableAlpha; // 28 + u16 mClamp; // 2a + f32 mCombinationRatio; // 2c + u32 mStartTick; // 30, tick of when the frame starts rendering + u32 mFrameTime; // 34, time it took to render a frame/amount of ticks beginRender took + u32 mVideoFrameTime; // 38, time between mStartTick and the last Video Tick + s16 mDrawingXfbNo; // 3c + bool mIsSingleXfb; // 3e +}; + +#endif diff --git a/include/JSystem/JFramework/JFWSystem.h b/include/JSystem/JFramework/JFWSystem.h new file mode 100644 index 00000000..a8a59343 --- /dev/null +++ b/include/JSystem/JFramework/JFWSystem.h @@ -0,0 +1,70 @@ +#ifndef _JSYSTEM_JFW_JFWSYSTEM_H +#define _JSYSTEM_JFW_JFWSYSTEM_H + +#include +#include "JSystem/JKernel/JKRHeap.h" +#include "JSystem/JKernel/JKRThread.h" +#include "JSystem/JUtility/JUTAssertion.h" +#include "JSystem/JUtility/JUTConsole.h" +#include "JSystem/JUtility/JUTDbPrint.h" +#include "JSystem/JUtility/JUTFont.h" +#include "types.h" + +// Maybe these are namespaces? +struct JFWSystem +{ + struct CSetUpParam + { + static int maxStdHeaps; + static u32 sysHeapSize; + static u32 fifoBufSize; + static u32 aramAudioBufSize; + static u32 aramGraphBufSize; + static s32 streamPriority; + static s32 decompPriority; + static s32 aPiecePriority; + static const ResFONT *systemFontRes; + static const _GXRenderModeObj *renderMode; + static u32 exConsoleBufferSize; + }; + + static void firstInit(); + static void init(); + + static JKRHeap *rootHeap; + static JKRHeap *systemHeap; + static JKRThread *mainThread; + static JUTDbPrint *debugPrint; + static JUTFont *systemFont; + static JUTConsoleManager *systemConsoleManager; + static JUTConsole *systemConsole; + static bool sInitCalled; + + + + // No idea how they formatted this lol + static void setMaxStdHeap(int stdHeaps) { + JUT_ASSERT(sInitCalled == 0); + CSetUpParam::maxStdHeaps = stdHeaps; } + static void setSysHeapSize(u32 heapSize) { + JUT_ASSERT(sInitCalled == 0); + CSetUpParam::sysHeapSize = heapSize; } + static void setFifoBufSize(u32 bufSize) { + JUT_ASSERT(sInitCalled == 0); + CSetUpParam::fifoBufSize = bufSize; } + + // Inlines for Aram + static void setAramAudioBufSize(u32 bufSize) { + JUT_ASSERT(sInitCalled == 0); + CSetUpParam::aramAudioBufSize = bufSize; } + static void setAramGraphBufSize(u32 bufSize) { + JUT_ASSERT(sInitCalled == 0); + CSetUpParam::aramGraphBufSize = bufSize; } + // probably some more inlines for other variables, not used by MKDD + static void setRenderMode(const _GXRenderModeObj * rmode) { +#line 80 + JUT_ASSERT(sInitCalled == 0); + CSetUpParam::renderMode = rmode; } +}; + +#endif diff --git a/include/JSystem/JGeometry.h b/include/JSystem/JGeometry.h index e24f4d10..d1928131 100644 --- a/include/JSystem/JGeometry.h +++ b/include/JSystem/JGeometry.h @@ -1,6 +1,7 @@ #ifndef _JSYSTEM_JGEOMETRY_H #define _JSYSTEM_JGEOMETRY_H +#include #include "types.h" #ifdef __cplusplus diff --git a/include/JSystem/JSystem.h b/include/JSystem/JSystem.h index b29ca1cf..d3e26b25 100644 --- a/include/JSystem/JSystem.h +++ b/include/JSystem/JSystem.h @@ -3,6 +3,6 @@ #include "JSystem/JKernel/JKRAram.h" #include "JSystem/JMacro.h" -//#include "JSystem/JUtility/JUTException.h" +#include "JSystem/JUtility/JUTException.h" #endif diff --git a/include/JSystem/JUtility/JUTDbPrint.h b/include/JSystem/JUtility/JUTDbPrint.h index c8474fa9..25b8c9b7 100644 --- a/include/JSystem/JUtility/JUTDbPrint.h +++ b/include/JSystem/JUtility/JUTDbPrint.h @@ -2,6 +2,54 @@ #define _JSYSTEM_JUT_JUTDBPRINT_H #ifdef __cplusplus + +#include "JSystem/JUtility/TColor.h" +#include "JSystem/JUtility/JUTFont.h" +#include "JSystem/JKernel/JKRHeap.h" + +struct JUTDbPrintList +{ + JUTDbPrintList *mNext; // _00 + s16 mX; // _04 + s16 mY; // _06 + s16 mDuration; // _08 + s16 mLen; // _0A + u8 mStr; // _0C +}; + +struct JUTDbPrint +{ + JUTDbPrint(JUTFont *, JKRHeap *); // unused/inlined + + ~JUTDbPrint(); // unused/inlined + + JUTFont *changeFont(JUTFont *); + void flush(); + void flush(int, int, int, int); + void drawString(int, int, int, const u8 *); + + // Unused/inlined: + void enter(int, int, int, const char *, int); + void print(int, int, const char *, ...); + void print(int, int, int, const char *, ...); + void reset(); + + void setVisible(bool visible) { mVisible = visible; } + JUTFont *getFont() const { return mFont; } + JUTDbPrintList *getList() const { return mList; } + + static JUTDbPrint *start(JUTFont *, JKRHeap *); + static JUTDbPrint *getManager() { return sDebugPrint; } + + static JUTDbPrint *sDebugPrint; + + JUTDbPrintList *mList; // _00 + JUTFont *mFont; // _04 + JUtility::TColor mColor; // _08 + bool mVisible; // _0C + JKRHeap *mHeap; // _10 +}; + extern "C" { #endif diff --git a/include/JSystem/JUtility/JUTDirectPrint.h b/include/JSystem/JUtility/JUTDirectPrint.h index 774e3ce3..cda094d6 100644 --- a/include/JSystem/JUtility/JUTDirectPrint.h +++ b/include/JSystem/JUtility/JUTDirectPrint.h @@ -40,7 +40,7 @@ private: void *mFramebuffer; // _00 u16 mFbWidth; // _04 u16 mFbHeight; // _06 - u16 mStride; // _08, aligned width? + u16 mStride; // _08 size_t mFbSize; // _0C u8 _10[0x4]; // _10 - unknown u16 *mFrameMemory; // _14 diff --git a/include/JSystem/JUtility/JUTException.h b/include/JSystem/JUtility/JUTException.h new file mode 100644 index 00000000..0413deca --- /dev/null +++ b/include/JSystem/JUtility/JUTException.h @@ -0,0 +1,149 @@ +#ifndef _JSYSTEM_JUT_JUTEXCEPTION_H +#define _JSYSTEM_JUT_JUTEXCEPTION_H + +#include +#include "JSystem/JKernel/JKRThread.h" +#include "JSystem/JSupport/JSUList.h" +#include "JSystem/JUtility/JUTGamePad.h" +#include "JSystem/JUtility/JUTXfb.h" +#include "types.h" + +struct JUTConsole; +struct JUTDirectPrint; + +typedef void (*JUTErrorHandler)(s32 error, OSContext *context, u32 dsisr, u32 dar); + +enum ExPrintFlags +{ + EXPRINTFLAG_GPR = 0x1, + EXPRINTFLAG_GPRMap = 0x2, + EXPRINTFLAG_SRR0Map = 0x4, + EXPRINTFLAG_Float = 0x8, + EXPRINTFLAG_Stack = 0x10, + + EXPRINTFLAG_All = 0x1F, +}; + +/** + * @size{0xA4} + */ +struct JUTException : public JKRThread +{ + enum EInfoPage + { + INFOPAGE_GPR = 1, + INFOPAGE_Float = 2, + INFOPAGE_Stack = 3, + INFOPAGE_GPRMap = 4, + INFOPAGE_SRR0Map = 5, + }; + + // size: 0x14 + struct JUTExMapFile + { + inline JUTExMapFile(const char *fileName) + : mLink(this) + { + mFileName = (char *)fileName; + } + + char *mFileName; // _00 + JSULink mLink; // _04 + }; + + /** @fabricated */ + struct ExCallbackObject + { + JUTErrorHandler mErrorHandler; // _00 + s32 mError; // _04 + OSContext *mContext; // _08 + u32 _0C; // _0C + u32 _10; // _10 + }; + + JUTException(JUTDirectPrint *); // unused/inlined + + virtual ~JUTException(){}; // _08 (weak) + virtual void *run(); // _0C + + void showFloat(OSContext *); + void showStack(OSContext *); + void showMainInfo(u16, OSContext *, u32, u32); + bool showMapInfo_subroutine(u32, bool); + void showGPRMap(OSContext *); + void printDebugInfo(JUTException::EInfoPage, u16, OSContext *, u32, u32); + bool readPad(u32 *, u32 *); + void printContext(u16, OSContext *, u32, u32); + void createFB(); + + static void waitTime(long); + static JUTErrorHandler setPreUserCallback(JUTErrorHandler); + static void appendMapFile(const char *); + static bool queryMapAddress(char *, u32, long, u32 *, u32 *, char *, u32, bool, bool); + static bool queryMapAddress_single(char *, u32, long, u32 *, u32 *, char *, u32, bool, bool); + + static JUTException *create(JUTDirectPrint *); + static void createConsole(void *buffer, u32 bufferSize); + static void panic_f(const char *file, int line, const char *msg, ...); + static void errorHandler(u16, OSContext *, u32, u32); + static void setFPException(u32); + static bool searchPartialModule(u32, u32 *, u32 *, u32 *, u32 *); + + // unused/inlined: + static void panic_f_va(const char *, int, const char *, va_list); + static JUTErrorHandler setPostUserCallback(JUTErrorHandler); + + // Inline + static void panic(const char *file, int line, const char *msg) { + panic_f(file, line, "%s", msg); + } + + void showFloatSub(int, f32); + void showGPR(OSContext *); + void showSRR0Map(OSContext *); + bool isEnablePad() const; + u32 getFpscr(); + void setFpscr(u32); + void enableFpuException(); + void disableFpuException(); + + JUTExternalFB *getFrameMemory() const { return mFrameMemory; } + + void setTraceSuppress(u32 supress) { mTraceSuppress = supress; } + void setGamePad(JUTGamePad *gamePad) + { + mGamePad = gamePad; + mPadPort = JUTGamePad::Port_Invalid; + } + + static JUTException *getManager() { return sErrorManager; } + static JUTConsole *getConsole() { return sConsole; } + + static JUTConsole *sConsole; + static void *sConsoleBuffer; + static size_t sConsoleBufferSize; + static JUTException *sErrorManager; + static OSMessageQueue sMessageQueue; + static void *sMessageBuffer[1]; + static JUTErrorHandler sPreUserCallback; + static JUTErrorHandler sPostUserCallback; + static u32 msr; + static u32 fpscr; + static const char *sCpuExpName[32]; + static JSUList sMapFileList; + + // _00 = VTBL + // _00-_7C = JKRThread + JUTExternalFB *mFrameMemory; // _7C + JUTDirectPrint *mDirectPrint; // _80 + JUTGamePad *mGamePad; // _84 + JUTGamePad::EPadPort mPadPort; // _88 + int mPrintWaitTime0; // _8C + int mPrintWaitTime1; // _90 + u32 mTraceSuppress; // _94 + u32 _98; // _98 + u32 mPrintFlags; // _9C, see ExPrintFlags enum + u32 mStackPointer; // _A0 +}; + +#endif \ No newline at end of file diff --git a/include/JSystem/JUtility/JUTFader.h b/include/JSystem/JUtility/JUTFader.h new file mode 100644 index 00000000..f6ff4410 --- /dev/null +++ b/include/JSystem/JUtility/JUTFader.h @@ -0,0 +1,49 @@ +#ifndef _JUTFADER_H +#define _JUTFADER_H + +#include "JSystem/JGeometry.h" +#include "JSystem/JUtility/TColor.h" +#include "JSystem/JUtility/JUTVideo.h" +#include "types.h" + +struct JUTFader +{ + enum EStatus + { + Status_Out = 0, + Status_In = 1, + Status_FadingIn = 2, + Status_FadingOut = 3 + }; + + JUTFader(int, int, int, int, JUtility::TColor); + + virtual ~JUTFader() {} // _08 (weak) + virtual bool startFadeIn(int duration); // _0C + virtual bool startFadeOut(int duration); // _10 + virtual void draw(); // _14 + + void control(); + + // unused/inlined: + void start(int); + void setStatus(EStatus, int); + void setResetState(bool reset) { mResetting = reset; } + + EStatus getStatus() const { return mStatus; } + + void setColor(JUtility::TColor color) { mColor.set(color.r, color.g, color.b, mColor.a); } + + // _00 VTBL + EStatus mStatus; // _04 - current status + u16 mTicksTarget; // _08 - ticks (calls to control()) to run a fade in/out for + u16 mTicksRun; // _0A - ticks the current fade has run + bool mResetting; // _0C - probably exclusive to mkdd, holds true when starting the fadeout for reset, sets back to false when fading in + u8 _0D[3]; // padding + JUtility::TColor mColor; // _10 - color of fade + JGeometry::TBox2f mViewBox; // _14 - ortho box to render within + int mEStatus; // _24 - ??? + EStatus _28; // _28 - ??? +}; + +#endif \ No newline at end of file diff --git a/include/JSystem/JUtility/JUTGraphFifo.h b/include/JSystem/JUtility/JUTGraphFifo.h new file mode 100644 index 00000000..c52f58c4 --- /dev/null +++ b/include/JSystem/JUtility/JUTGraphFifo.h @@ -0,0 +1,43 @@ +#ifndef _JSYSTEM_JUT_JUTGRAPHFIFO_H +#define _JSYSTEM_JUT_JUTGRAPHFIFO_H + +#include "types.h" +#include + +struct JUTGraphFifo +{ + JUTGraphFifo(u32); + + virtual ~JUTGraphFifo(); // _08 + + void becomeCurrent(); + void setBreakPt(); + + void getGpStatus() + { + GXGetGPStatus((GXBool*)&mGpStatus[0], (GXBool*)&mGpStatus[1], (GXBool*)&mGpStatus[2], (GXBool*)&mGpStatus[3], + (GXBool*)&mGpStatus[4]); + } + + bool isGPActive() + { + getGpStatus(); + return mGpStatus[2] == false; + } + + void save() { GXSaveCPUFifo(this->mFifo); } + + static JUTGraphFifo *sCurrentFifo; + static GXBool mGpStatus[5]; + static bool sInitiated; + + // _00 = VTBL + GXFifoObj* mFifo; // _04 + void* mBase; // _08 + u32 mSize; // _0C + u8 _10[0xC]; // _10 +}; + +inline void JUTCreateFifo(u32 bufSize) { new JUTGraphFifo(bufSize); } + +#endif \ No newline at end of file diff --git a/include/JSystem/JUtility/JUTVideo.h b/include/JSystem/JUtility/JUTVideo.h index f5617392..75b7a7a1 100644 --- a/include/JSystem/JUtility/JUTVideo.h +++ b/include/JSystem/JUtility/JUTVideo.h @@ -8,46 +8,43 @@ #include "dolphin/vi.h" #ifdef __cplusplus -/** - * @size{0x58} - */ typedef u8 (*Pattern)[2]; struct JUTVideo { - JUTVideo(const _GXRenderModeObj *); + JUTVideo(const GXRenderModeObj*); virtual ~JUTVideo(); // _08 - static JUTVideo *createManager(const _GXRenderModeObj *); + static JUTVideo *createManager(const GXRenderModeObj*); static void destroyManager(); static void preRetraceProc(unsigned long); static void postRetraceProc(unsigned long); static void drawDoneCallback(); - u16 getEfbHeight() const { return mRenderModeObj->efbHeight; } - u16 getFbWidth() const { return mRenderModeObj->fbWidth; } + u32 getEfbHeight() const { return mRenderModeObj->efbHeight; } + u32 getXfbHeight() const { return mRenderModeObj->xfbHeight; } + u32 getFbWidth() const { return (u16)mRenderModeObj->fbWidth; } // cast required for callDirectDraw void getBounds(u16& width, u16& height) const { width = getFbWidth(); height = getEfbHeight(); } - _GXRenderModeObj *getRenderMode() const { return mRenderModeObj; } - u16 getXfbHeight() const { return mRenderModeObj->xfbHeight; } + GXRenderModeObj *getRenderMode() const { return mRenderModeObj; } u32 isAntiAliasing() const { return mRenderModeObj->aa; } Pattern getSamplePattern() const { return mRenderModeObj->sample_pattern; } u8 *getVFilter() const { return mRenderModeObj->vfilter; } OSMessageQueue *getMessageQueue() { return &mMessageQueue; }; static void drawDoneStart(); static void dummyNoDrawWait(); - void setRenderMode(const _GXRenderModeObj *); + void setRenderMode(const GXRenderModeObj*); void waitRetraceIfNeed(); // blr, global VIRetraceCallback setPostRetraceCallback(VIRetraceCallback); // Unused/inlined: void getDrawWait(); VIRetraceCallback setPreRetraceCallback(VIRetraceCallback); - void getPixelAspect(const _GXRenderModeObj *); + void getPixelAspect(const GXRenderModeObj*); void getPixelAspect() const; // Static inline gets diff --git a/include/JSystem/JUtility/JUTXfb.h b/include/JSystem/JUtility/JUTXfb.h new file mode 100644 index 00000000..2016c719 --- /dev/null +++ b/include/JSystem/JUtility/JUTXfb.h @@ -0,0 +1,84 @@ +#ifndef _JSYSTEM_JUT_JUTXFB_H +#define _JSYSTEM_JUT_JUTXFB_H + +#include +#include +#include "types.h" + +struct JUTExternalFB +{ + JUTExternalFB(GXRenderModeObj *, GXGamma, void *, u32); + + GXRenderModeObj *mRenderModeObj; // _00 + u32 mSize; // _04 + u8 _08[4]; // _08 + u16 _0C; // _0C + u16 mGamma; // _0E, treat as GXGamma + bool _10; // _10 +}; + +class JUTXfb +{ +public: + enum EXfbNumber + { + Unset = 0, + SingleBuffer = 1, + DoubleBuffer = 2, + TripleBuffer = 3 + }; + + void clearIndex(); + void common_init(int); + JUTXfb(const GXRenderModeObj*, JKRHeap*, JUTXfb::EXfbNumber); + ~JUTXfb(); + void delXfb(int); + static JUTXfb *createManager(const GXRenderModeObj* rmode, JKRHeap*, JUTXfb::EXfbNumber); + static void destroyManager(); + void initiate(u16, u16, JKRHeap*, JUTXfb::EXfbNumber); + u32 accumeXfbSize(); + + int getBufferNum() const { return mBufferNum; } + int getDrawnXfbIndex() const { return mDrawnXfbIndex; } + s16 getDrawingXfbIndex() const { return mDrawingXfbIndex; } + s16 getDisplayingXfbIndex() const { return mDisplayingXfbIndex; } + int getSDrawingFlag() const { return mSDrawingFlag; } + + void *getXfb(int index) const { + return mBuffer[index]; + } + + void *getDrawnXfb() const { + return (mDrawnXfbIndex >= 0) ? mBuffer[mDrawnXfbIndex] : nullptr; + } + + void *getDrawingXfb() const { + return (mDrawingXfbIndex >= 0) ? mBuffer[mDrawingXfbIndex] : nullptr; + } + + void *getDisplayingXfb() const { + return (mDisplayingXfbIndex >= 0) ? mBuffer[mDisplayingXfbIndex] : nullptr; + } + + void setBufferNum(int num) { mBufferNum = num; } + void setDisplayingXfbIndex(s16 index) { mDisplayingXfbIndex = index; } + void setSDrawingFlag(s32 flag) { mSDrawingFlag = flag; } + void setDrawnXfbIndex(s16 index) { mDrawnXfbIndex = index; } + void setDrawingXfbIndex(s16 index) { mDrawingXfbIndex = index; } + + static JUTXfb *getManager() { return sManager; } + +private: + static JUTXfb *sManager; + +private: + void *mBuffer[3]; // 00 + bool mXfbAllocated[3]; // 0c + int mBufferNum; // 10 + s16 mDrawingXfbIndex; // 14 + s16 mDrawnXfbIndex; // 16 + s16 mDisplayingXfbIndex; // 18 + s32 mSDrawingFlag; // 1a +}; + +#endif diff --git a/include/dolphin/vi.h b/include/dolphin/vi.h index 0339998f..215a27e0 100644 --- a/include/dolphin/vi.h +++ b/include/dolphin/vi.h @@ -76,6 +76,8 @@ u32 VIGetRetraceCount(); u32 VIGetDTVStatus(); void VIFlush(); +void VISetNextFrameBuffer(void *fb); + #ifdef __cplusplus }; #endif diff --git a/src/static/JSystem/JFramework/.gitkeep b/src/static/JSystem/JFramework/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/src/static/JSystem/JFramework/JFWDisplay.cpp b/src/static/JSystem/JFramework/JFWDisplay.cpp new file mode 100644 index 00000000..b35b2b56 --- /dev/null +++ b/src/static/JSystem/JFramework/JFWDisplay.cpp @@ -0,0 +1,548 @@ +#include +#include +#include "JSystem/J2D/J2DGrafContext.h" +#include "JSystem/JUtility/JUTAssertion.h" +#include "JSystem/JUtility/JUTConsole.h" +#include "JSystem/JUtility/JUTDbPrint.h" +#include "JSystem/JUtility/JUTVideo.h" +#include "JSystem/JUtility/JUTProcBar.h" +#include "JSystem/JFramework/JFWDisplay.h" + +// Sources: https://github.com/zeldaret/tp/blob/master/libs/JSystem/JFramework/JFWDisplay.cpp +// https://github.com/kiwi515/ogws/blob/master/src/egg/core/eggAsyncDisplay.cpp +// gpHang: https://github.com/valentinaslover/paper-mar/blob/master/source/sdk/DEMOInit.c#L280 + +GC_Mtx e_mtx = {{1.0f, 0.0f, 0.0f, 0.0f}, {0.0f, 1.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 1.0f, 0.0f}}; + +JFWDisplay* JFWDisplay::sManager; + +extern void JFWThreadAlarmHandler(OSAlarm*, OSContext*); +extern void JFWGXAbortAlarmHandler(OSAlarm*, OSContext*); +void waitForTick(u32, u16); +void diagnoseGpHang(); + +inline void JFWDrawDoneAlarm() { + OSAlarm alarm; + OSCreateAlarm(&alarm); + OSSetAlarm(&alarm, (OS_TIMER_CLOCK), JFWGXAbortAlarmHandler); + GXDrawDone(); + OSCancelAlarm(&alarm); +} + +void JFWDisplay::ctor_subroutine(const GXRenderModeObj* rmode, bool enableAlpha) { + mEnableAlpha = enableAlpha; + mClamp = GX_CLAMP_TOP | GX_CLAMP_BOTTOM; + mClearColor.set(0, 0, 0, 0); + + mZClear = 0xFFFFFF; + mRMode = (rmode) ? rmode : JUTVideo::sManager->getRenderMode(); + + mGamma = 0; + mFader = nullptr; + mFrameRate = 1; + mTickRate = 0; + mCombinationRatio = 0.0f; + + mFrameTime = 0; + mStartTick = OSGetTick(); + mVideoFrameTime = 0; + mDrawingXfbNo = 0; + mIsSingleXfb = false; + mDrawDoneMethod = UNK_METHOD_0; + clearEfb_init(); + JUTProcBar::create(); + JUTProcBar::clear(); +} + +JFWDisplay::JFWDisplay(const _GXRenderModeObj* rmode, JKRHeap* heap, JUTXfb::EXfbNumber bufferCount, bool p3) { + ctor_subroutine(rmode, p3); + mXfb = JUTXfb::createManager(rmode, heap, bufferCount); +} + +JFWDisplay::~JFWDisplay() { + waitBlanking(2); + JUTProcBar::destroy(); + JUTXfb::destroyManager(); +} + +JFWDisplay *JFWDisplay::createManager(const GXRenderModeObj* rmode, JKRHeap* heap, JUTXfb::EXfbNumber bufferCount, bool p4) { + JUT_CONFIRM_MESSAGE(sManager == 0); + + if (sManager == nullptr) + sManager = new JFWDisplay(rmode, heap, bufferCount, p4); + + return sManager; +} + +void JFWDisplay::destroyManager() { + JUT_CONFIRM_MESSAGE(sManager); + delete sManager; + sManager = nullptr; +} + +void callDirectDraw() { + JUTChangeFrameBuffer(JUTXfb::getManager()->getDrawingXfb(), + JUTVideo::getManager()->getEfbHeight(), + JUTVideo::getManager()->getFbWidth()); + JUTAssertion::flushMessage(); +} + +void JFWDisplay::prepareCopyDisp() { + GXRenderModeObj* rmode = JUTVideo::getManager()->getRenderMode(); + u16 width = (u16)JUTVideo::getManager()->getFbWidth(); + u16 height = (u16)JUTVideo::getManager()->getEfbHeight(); + u16 xfbHeight = (u16)JUTVideo::getManager()->getXfbHeight(); + + GXSetCopyClear(mClearColor, mZClear); + GXSetDispCopySrc(0, 0, width, height); + GXSetDispCopyDst(width, xfbHeight); + GXSetDispCopyYScale(xfbHeight / (f32)height); + VIFlush(); + GXSetCopyFilter((GXBool)rmode->aa, rmode->sample_pattern, GX_ENABLE, rmode->vfilter); + GXSetCopyClamp((GXFBClamp)mClamp); + GXSetDispCopyGamma((GXGamma)mGamma); + GXSetZMode(GX_ENABLE, GX_LEQUAL, GX_ENABLE); + if (mEnableAlpha) { + GXSetAlphaUpdate(GX_ENABLE); + } +} + +void JFWDisplay::drawendXfb_single() { + JUTXfb *manager = JUTXfb::getManager(); + if (manager->getDrawingXfbIndex() >= 0) { + prepareCopyDisp(); + JFWDrawDoneAlarm(); + GXFlush(); + manager->setDrawnXfbIndex(manager->getDrawingXfbIndex()); + } +} + +void JFWDisplay::exchangeXfb_double() { + JUTXfb *xfbMng = JUTXfb::getManager(); + + if (xfbMng->getDrawnXfbIndex() == xfbMng->getDisplayingXfbIndex()) { + if (xfbMng->getDrawingXfbIndex() >= 0) + { + prepareCopyDisp(); + GXCopyDisp(xfbMng->getDrawingXfb(), GX_TRUE); + if (mDrawDoneMethod == UNK_METHOD_0) { + GXDrawDone(); + JUTVideo::dummyNoDrawWait(); + } + else { + JUTVideo::drawDoneStart(); + } + + if (mDrawDoneMethod == UNK_METHOD_0) { + callDirectDraw(); + } + } + int cur_xfb_index = xfbMng->getDrawingXfbIndex(); + xfbMng->setDrawnXfbIndex(cur_xfb_index); + xfbMng->setDrawingXfbIndex(cur_xfb_index >= 0 ? cur_xfb_index ^ 1 : 0); + } + else { + clearEfb(JUtility::TColor(0, 0, 0, 0xff)); + if (xfbMng->getDrawingXfbIndex() < 0) { + xfbMng->setDrawingXfbIndex(0); + } + } +} + +void JFWDisplay::exchangeXfb_triple() { + JUTXfb *xfbMng = JUTXfb::getManager(); + + if (xfbMng->getDrawingXfbIndex() >= 0) { + callDirectDraw(); + } + + xfbMng->setDrawnXfbIndex(xfbMng->getDrawingXfbIndex()); + + s16 drawing_idx = xfbMng->getDrawingXfbIndex() + 1; + do { + if (drawing_idx >= 3 || drawing_idx < 0) { + drawing_idx = 0; + } + } while (drawing_idx == xfbMng->getDisplayingXfbIndex()); + xfbMng->setDrawingXfbIndex(drawing_idx); +} + +void JFWDisplay::copyXfb_triple() { + JUTXfb *xfbMng = JUTXfb::getManager(); + + if (xfbMng->getDrawingXfbIndex() >= 0) { + prepareCopyDisp(); + GXCopyDisp(xfbMng->getDrawingXfb(), GX_TRUE); + GXPixModeSync(); + } +} + +void JFWDisplay::preGX() { + GXInvalidateTexAll(); + GXInvalidateVtxCache(); + + if (mRMode->aa) { + GXSetPixelFmt(GX_PF_RGB565_Z16, GX_ZC_LINEAR); + GXSetDither(GX_ENABLE); + } + else { + if (mEnableAlpha) { + GXSetPixelFmt(GX_PF_RGBA6_Z24, GX_ZC_LINEAR); + GXSetDither(GX_ENABLE); + } + else { + GXSetPixelFmt(GX_PF_RGB8_Z24, GX_ZC_LINEAR); + GXSetDither(GX_DISABLE); + } + } +} + +void JFWDisplay::endGX() { + u32 width = JUTVideo::getManager()->getFbWidth(); + u32 height = JUTVideo::getManager()->getEfbHeight(); + + J2DOrthoGraph ortho(0.0f, 0.0f, width, height, -1.0f, 1.0f); + + if (mFader != nullptr) { + ortho.setPort(); + mFader->control(); + } + + JUTDbPrint::getManager()->flush(); + + if (JUTConsoleManager::getManager() != nullptr) { + JUTConsoleManager::getManager()->draw(); + } + + ortho.setPort(); + JUTProcBar::getManager()->draw(); + + if (mDrawDoneMethod != UNK_METHOD_0 || JUTXfb::getManager()->getBufferNum() == 1) { + JUTAssertion::flushMessage_dbPrint(); + } + GXFlush(); +} + +void JFWDisplay::beginRender() { + JUTProcBar::getManager()->wholeLoopEnd(); + JUTProcBar::getManager()->wholeLoopStart(); + JUTProcBar::getManager()->idleStart(); + + waitForTick(mTickRate, mFrameRate); + JUTVideo::getManager()->waitRetraceIfNeed(); + + u32 tick = OSGetTick(); + mFrameTime = tick - mStartTick; + mStartTick = tick; + mVideoFrameTime = mStartTick - JUTVideo::getVideoLastTick(); + + JUTProcBar::getManager()->idleEnd(); + JUTProcBar::getManager()->gpStart(); + + JUTXfb * xfbMgr = JUTXfb::getManager(); + switch (xfbMgr->getBufferNum()) { + case 1: + if (xfbMgr->getSDrawingFlag() != 2) { + xfbMgr->setSDrawingFlag(1); + clearEfb(JUtility::TColor(0, 0, 0, 0xff)); + } + else { + xfbMgr->setSDrawingFlag(1); + } + xfbMgr->setDrawingXfbIndex(mDrawingXfbNo); + break; + case 2: + exchangeXfb_double(); + break; + case 3: + exchangeXfb_triple(); + break; + default: + break; + } + + preGX(); +} + +void JFWDisplay::endRender() { + endGX(); + + switch (JUTXfb::getManager()->getBufferNum()) + { + case 1: + drawendXfb_single(); + case 2: + break; + case 3: + copyXfb_triple(); + default: + break; + } + + JUTProcBar::getManager()->cpuStart(); + calcCombinationRatio(); +} + +void JFWDisplay::endFrame() { + JUTProcBar::getManager()->cpuEnd(); + JUTProcBar::getManager()->gpWaitStart(); + + switch (JUTXfb::getManager()->getBufferNum()) { + case 1: + break; + case 2: + JFWDrawDoneAlarm(); + GXFlush(); + break; + case 3: + JFWDrawDoneAlarm(); + GXFlush(); + break; + default: + break; + } + + JUTProcBar::getManager()->gpWaitEnd(); + JUTProcBar::getManager()->gpEnd(); + + + static u32 prevFrame = VIGetRetraceCount(); + u32 retrace_cnt = VIGetRetraceCount(); + JUTProcBar::getManager()->setCostFrame(retrace_cnt - prevFrame); + prevFrame = retrace_cnt; + +} + +void JFWDisplay::waitBlanking(int p1) { + while (p1-- > 0) { + waitForTick(mTickRate, mFrameRate); + } +} + +void waitForTick(u32 p1, u16 p2) { + if (p1 != 0) { + static s64 nextTick = OSGetTime(); + s64 time = OSGetTime(); + while (time < nextTick) { + JFWDisplay::getManager()->threadSleep((nextTick - time)); + time = OSGetTime(); + } + nextTick = time + p1; + } + else { + static u32 nextCount = VIGetRetraceCount(); + u32 uVar1 = (p2 == 0) ? 1 : p2; + OSMessage msg; + do { + if (!OSReceiveMessage(JUTVideo::getManager()->getMessageQueue(), &msg, OS_MESSAGE_BLOCK)) { + msg = 0; + } + } while (((int)msg - (int)nextCount) < 0); + nextCount = (int)msg + uVar1; + } +} + +void JFWThreadAlarmHandler(OSAlarm* p_alarm, OSContext* p_ctx) { + JFWAlarm *alarm = static_cast(p_alarm); + OSResumeThread(alarm->getThread()); +} + +void JFWDisplay::threadSleep(s64 time) { + JFWAlarm alarm; + alarm.createAlarm(); + alarm.setThread(OSGetCurrentThread()); + s32 status = OSDisableInterrupts(); + + OSSetAlarm(&alarm, time, JFWThreadAlarmHandler); + OSSuspendThread(alarm.getThread()); + OSRestoreInterrupts(status); +} + +static GXTexObj clear_z_tobj; +static u8 clear_z_TX[] __attribute__((aligned(32))) = { + 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, + 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, + 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, + 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff +}; + +void* JFWDisplay::changeToSingleXfb(int index) { + JUTXfb* xfb = JUTXfb::getManager(); + s16 xfbNo = !index ? 1 : 0; + + // Check if xfb is single buffered + if (xfb->getBufferNum() != 2) { + return nullptr; + } + + if (mIsSingleXfb) { + return nullptr; + } + + VIWaitForRetrace(); + + if (xfbNo != xfb->getDisplayingXfbIndex()) { + u32 xfbSize = xfb->accumeXfbSize(); + DCInvalidateRange(xfb->getDrawingXfb(), xfbSize); + memcpy(xfb->getDrawingXfb(), xfb->getDisplayingXfb(), xfbSize); + DCStoreRange(xfb->getDrawingXfb(), xfbSize); + xfb->setDrawnXfbIndex(xfb->getDrawingXfbIndex()); + VISetNextFrameBuffer(xfb->getDrawingXfb()); + VIFlush(); + VIWaitForRetrace(); + } + + xfb->setSDrawingFlag(99); + xfb->setBufferNum(1); + mDrawingXfbNo = xfbNo; + mIsSingleXfb = true; + return xfb->getXfb(index); +} + +void* JFWDisplay::changeToDoubleXfb() { + JUTXfb* xfb = JUTXfb::getManager(); + + // Check if xfb is not single buffered already + if (!mIsSingleXfb) { + return nullptr; + } + + VIWaitForRetrace(); + if (xfb->getSDrawingFlag() != 0) { + VIWaitForRetrace(); + } + + s16 xfbNo = !mDrawingXfbNo ? 1 : 0; + xfb->setDrawnXfbIndex(mDrawingXfbNo); + xfb->setDisplayingXfbIndex(xfbNo); + xfb->setDrawingXfbIndex(xfbNo); + xfb->setBufferNum(2); + mIsSingleXfb = false; + return xfb->getXfb(xfbNo); +} + +void JFWDisplay::clearEfb_init() { + GXInitTexObj(&clear_z_tobj, &clear_z_TX, 4, 4, GX_TF_Z24X8, GX_REPEAT, GX_REPEAT, GX_FALSE); + GXInitTexObjLOD(&clear_z_tobj, GX_NEAR, GX_NEAR, 0.0f, 0.0f, 0.0f, GX_FALSE, GX_FALSE, + GX_ANISO_1); +} + +void JFWDisplay::clearEfb(GXColor color) { + Mtx44 mtx; + u16 height = mRMode->efbHeight; + u16 width = mRMode->fbWidth; + + C_MTXOrtho(mtx, 0.0f, height, 0.0f, width, 0.0f, 1.0f); + GXSetProjection(mtx, GX_ORTHOGRAPHIC); + GXSetViewport(0.0f, 0.0f, width, height, 0.0f, 1.0f); + GXSetScissor(0, 0, width, height); + + GXLoadPosMtxImm(e_mtx, GX_PNMTX0); + GXSetCurrentMtx(0); + GXClearVtxDesc(); + GXSetVtxDesc(GX_VA_POS, GX_DIRECT); + GXSetVtxDesc(GX_VA_TEX0, GX_DIRECT); + GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_CLR_RGB, GX_RGBX8, 0); + GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_CLR_RGBA, GX_RGB565, 0); + GXSetNumChans(0); + GXSetChanCtrl(GX_COLOR0A0, GX_DISABLE, GX_SRC_REG, GX_SRC_REG, GX_LIGHT_NULL, GX_DF_NONE, GX_AF_NONE); + GXSetChanCtrl(GX_COLOR1A1, GX_DISABLE, GX_SRC_REG, GX_SRC_REG, GX_LIGHT_NULL, GX_DF_NONE, GX_AF_NONE); + GXSetNumTexGens(1); + GXSetTexCoordGen2(GX_TEXCOORD0, GX_TG_MTX2x4, GX_TG_TEX0, 60, GX_DISABLE, 125); + GXLoadTexObj(&clear_z_tobj, GX_TEXMAP0); + GXSetNumTevStages(1); + GXSetTevColor(GX_TEVREG0, color); + GXSetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR_NULL); + GXSetTevColorIn(GX_TEVSTAGE0, GX_CC_ZERO, GX_CC_ZERO, GX_CC_ZERO, GX_CC_C0); + GXSetTevColorOp(GX_TEVSTAGE0, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_ENABLE, GX_TEVPREV); + GXSetTevAlphaIn(GX_TEVSTAGE0, GX_CA_ZERO, GX_CA_ZERO, GX_CA_ZERO, GX_CA_A0); + GXSetTevAlphaOp(GX_TEVSTAGE0, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_ENABLE, GX_TEVPREV); + GXSetAlphaCompare(GX_ALWAYS, 0, GX_AOP_OR, GX_ALWAYS, 0); + GXSetZTexture(GX_ZT_REPLACE, GX_TF_Z24X8, 0); + GXSetZCompLoc(GX_DISABLE); + GXSetBlendMode(GX_BM_NONE, GX_BL_ZERO, GX_BL_ZERO, GX_LO_NOOP); + + if (mEnableAlpha) { + GXSetAlphaUpdate(GX_ENABLE); + GXSetDstAlpha(GX_ENABLE, 0); + } + GXSetZMode(GX_ENABLE, GX_ALWAYS, GX_ENABLE); + GXSetCullMode(GX_CULL_BACK); + + GXBegin(GX_QUADS, GX_VTXFMT0, 4); + GXPosition2u16(0, 0); + GXTexCoord2u8(0, 0); + + GXPosition2u16(0 + width, 0); + GXTexCoord2u8(1, 0); + + GXPosition2u16(0 + width, 0 + height); + GXTexCoord2u8(1, 1); + + GXPosition2u16(0, 0 + height); + GXTexCoord2u8(0, 1); + GXEnd(); + + GXSetZTexture(GX_ZT_DISABLE, GX_TF_Z24X8, 0); + GXSetZCompLoc(GX_ENABLE); + if (mEnableAlpha) { + GXSetDstAlpha(GX_DISABLE, 0); + } +} + +void JFWDisplay::calcCombinationRatio() { + u32 vidInterval = JUTVideo::getVideoInterval(); + s32 unk30 = mFrameTime * 2; + + s32 i = vidInterval; + for (; i < unk30; i += vidInterval) { + } + + s32 tmp = (i - unk30) - mVideoFrameTime; + if (tmp < 0) { + tmp += vidInterval; + } + mCombinationRatio = (f32)tmp / (f32)mFrameTime; + if (mCombinationRatio > 1.0f) { + mCombinationRatio = 1.0f; + } +} + +void JFWGXAbortAlarmHandler(OSAlarm *param_0, OSContext *param_1) { + diagnoseGpHang(); + GXAbortFrame(); + GXSetDrawDone(); +} + +void diagnoseGpHang() { + u32 xfTop0, xfBot0, suRdy0, r0Rdy0; + u32 xfTop1, xfBot1, suRdy1, r0Rdy1; + u32 xfTopD, xfBotD, suRdyD, r0RdyD; + GXBool readIdle, cmdIdle, junk; + + GXReadXfRasMetric(&xfBot0, &xfTop0, &r0Rdy0, &suRdy0); + GXReadXfRasMetric(&xfBot1, &xfTop1, &r0Rdy1, &suRdy1); + + xfTopD = (xfTop1 - xfTop0) == 0; + xfBotD = (xfBot1 - xfBot0) == 0; + suRdyD = (suRdy1 - suRdy0) > 0; + r0RdyD = (r0Rdy1 - r0Rdy0) > 0; + + GXGetGPStatus(&junk, &junk, &readIdle, &cmdIdle, &junk); + OSReport("GP status %d%d%d%d%d%d --> ", readIdle, cmdIdle, xfTopD, xfBotD, suRdyD, r0RdyD); + + if (!xfBotD && suRdyD) + OSReport("GP hang due to XF stall bug.\n"); + else if (!xfTopD && xfBotD && suRdyD) + OSReport("GP hang due to unterminated primitive.\n"); + else if (!cmdIdle && xfTopD && xfBotD && suRdyD) + OSReport("GP hang due to illegal instruction.\n"); + else if (readIdle && cmdIdle && xfTopD && xfBotD && suRdyD && r0RdyD) + OSReport("GP appears to be not hung (waiting for input).\n"); + else + OSReport("GP is in unknown state.\n"); +} diff --git a/src/static/JSystem/JFramework/JFWSystem.cpp b/src/static/JSystem/JFramework/JFWSystem.cpp new file mode 100644 index 00000000..d96c1a3a --- /dev/null +++ b/src/static/JSystem/JFramework/JFWSystem.cpp @@ -0,0 +1,93 @@ +#include "dolphin/dvd.h" +#include "dolphin/gx.h" +#include "dolphin/os.h" +#include "JSystem/JKernel/JKRAram.h" +#include "JSystem/JKernel/JKRHeap.h" +#include "JSystem/JKernel/JKRExpHeap.h" +#include "JSystem/JKernel/JKRThread.h" +#include "JSystem/JUtility/JUTConsole.h" +#include "JSystem/JUtility/JUTAssertion.h" +#include "JSystem/JUtility/JUTDbPrint.h" +#include "JSystem/JUtility/JUTDirectPrint.h" +#include "JSystem/JUtility/JUTException.h" +#include "JSystem/JUtility/JUTFont.h" +#include "JSystem/JUtility/JUTGamePad.h" +#include "JSystem/JUtility/JUTGraphFifo.h" +#include "JSystem/JUtility/JUTVideo.h" +#include "JSystem/JFramework/JFWSystem.h" + +int JFWSystem::CSetUpParam::maxStdHeaps = 2; +u32 JFWSystem::CSetUpParam::sysHeapSize = 0x400000; +u32 JFWSystem::CSetUpParam::fifoBufSize = 0x40000; +u32 JFWSystem::CSetUpParam::aramAudioBufSize = 0x800000; +u32 JFWSystem::CSetUpParam::aramGraphBufSize = 0x600000; +s32 JFWSystem::CSetUpParam::streamPriority = 8; +s32 JFWSystem::CSetUpParam::decompPriority = 7; +s32 JFWSystem::CSetUpParam::aPiecePriority = 6; +const ResFONT *JFWSystem::CSetUpParam::systemFontRes = &JUTResFONT_Ascfont_fix12; +const _GXRenderModeObj *JFWSystem::CSetUpParam::renderMode = &GXNtsc480IntDf; +u32 JFWSystem::CSetUpParam::exConsoleBufferSize = 0x24FC; + +JKRHeap *JFWSystem::rootHeap; +JKRHeap *JFWSystem::systemHeap; +JKRThread *JFWSystem::mainThread; +JUTDbPrint *JFWSystem::debugPrint; +JUTFont *JFWSystem::systemFont; +JUTConsoleManager *JFWSystem::systemConsoleManager; +JUTConsole *JFWSystem::systemConsole; +bool JFWSystem::sInitCalled; + +void JFWSystem::firstInit() +{ +#line 80 + JUT_ASSERT(rootHeap == 0); + OSInit(); + DVDInit(); + rootHeap = JKRExpHeap::createRoot(CSetUpParam::maxStdHeaps, false); + systemHeap = JKRExpHeap::create(CSetUpParam::sysHeapSize, rootHeap, false); +} + +void JFWSystem::init() +{ +#line 101 + JUT_ASSERT(sInitCalled == false); + + if (rootHeap == 0) + firstInit(); + + sInitCalled = true; + JKRAram::create(CSetUpParam::aramAudioBufSize, CSetUpParam::aramGraphBufSize, CSetUpParam::streamPriority, CSetUpParam::decompPriority, + CSetUpParam::aPiecePriority); + + mainThread = new JKRThread(OSGetCurrentThread(), 4); + JUTVideo::createManager(CSetUpParam::renderMode); + JUTCreateFifo(CSetUpParam::fifoBufSize); + JUTGamePad::init(); + JUTDirectPrint *directPrint = JUTDirectPrint::start(); + JUTAssertion::create(); + JUTException::create(directPrint); + systemFont = new JUTResFont(CSetUpParam::systemFontRes, nullptr); + debugPrint = JUTDbPrint::start(nullptr, nullptr); + debugPrint->changeFont(systemFont); + systemConsoleManager = JUTConsoleManager::createManager(nullptr); + systemConsole = JUTConsole::create(60, 200, nullptr); + systemConsole->setFont(systemFont); + + if (CSetUpParam::renderMode->efbHeight < 300) + { + systemConsole->setFontSize(systemFont->getWidth() * 0.85f, systemFont->getHeight() * 0.5f); + systemConsole->setPosition(20, 25); + } + else + { + systemConsole->setFontSize(systemFont->getWidth() * 0.85f, systemFont->getHeight()); + systemConsole->setPosition(20, 50); + } + systemConsole->setHeight(25); + systemConsole->setVisible(false); + systemConsole->setOutput(JUTConsole::OUTPUT_OSREPORT | JUTConsole::OUTPUT_CONSOLE); + JUTSetReportConsole(systemConsole); + JUTSetWarningConsole(systemConsole); + void *mem = systemHeap->alloc(CSetUpParam::exConsoleBufferSize, 4); + JUTException::createConsole(mem, CSetUpParam::exConsoleBufferSize); +} \ No newline at end of file From 0ab7bf6cd969979d0b9648cb8b101f5d4dbdf963 Mon Sep 17 00:00:00 2001 From: SwareJonge <41187958+SwareJonge@users.noreply.github.com> Date: Mon, 16 Jun 2025 23:07:08 +0200 Subject: [PATCH 2/9] Match JUTConsole --- configure.py | 4 +- include/JSystem/JGadget/linklist.h | 4 +- include/JSystem/JUtility/JUTConsole.h | 21 +- include/MSL_C/printf.h | 2 + src/static/JSystem/JFramework/JFWSystem.cpp | 2 +- src/static/JSystem/JUtility/JUTConsole.cpp | 574 ++++++++++++++++++++ 6 files changed, 595 insertions(+), 12 deletions(-) create mode 100644 src/static/JSystem/JUtility/JUTConsole.cpp diff --git a/configure.py b/configure.py index 4b04f89b..5bd9325e 100644 --- a/configure.py +++ b/configure.py @@ -619,7 +619,7 @@ config.libs = [ "JFramework", [ Object(Matching, "JSystem/JFramework/JFWDisplay.cpp"), - Object(NonMatching, "JSystem/JFramework/JFWSystem.cpp"), + Object(Matching, "JSystem/JFramework/JFWSystem.cpp"), ], ), JSystemLib( @@ -666,7 +666,7 @@ config.libs = [ "JUtility", [ Object(NonMatching, "JSystem/JUtility/JUTAssert.cpp"), - Object(NonMatching, "JSystem/JUtility/JUTConsole.cpp"), + Object(Matching, "JSystem/JUtility/JUTConsole.cpp"), Object(NonMatching, "JSystem/JUtility/JUTDbPrint.cpp"), Object(NonMatching, "JSystem/JUtility/JUTDirectFile.cpp"), Object(NonMatching, "JSystem/JUtility/JUTDirectPrint.cpp"), diff --git a/include/JSystem/JGadget/linklist.h b/include/JSystem/JGadget/linklist.h index bb4622ff..7458f155 100644 --- a/include/JSystem/JGadget/linklist.h +++ b/include/JSystem/JGadget/linklist.h @@ -148,7 +148,7 @@ public: } } - s32 size() const { return this->size_; } + u32 size() const { return this->size_; } bool empty() const { return this->size() == 0; } void clear() { this->erase(this->begin(), this->end()); } iterator erase(iterator itStart, iterator itEnd); @@ -179,7 +179,7 @@ private: bool Iterator_isEnd_(const_iterator it) const { return it.p_ == &this->oNode_; } - s32 size_; + u32 size_; TLinkListNode oNode_; }; diff --git a/include/JSystem/JUtility/JUTConsole.h b/include/JSystem/JUtility/JUTConsole.h index dd710d4b..eabab006 100644 --- a/include/JSystem/JUtility/JUTConsole.h +++ b/include/JSystem/JUtility/JUTConsole.h @@ -13,7 +13,7 @@ inline s32 colorCheck(s32 diff, s32 t) return ret + 1; } -class JUTConsole : public JKRDisposer +class JUTConsole : JKRDisposer { public: enum EConsoleType @@ -101,12 +101,21 @@ public: return diff += mMaxLines; } + u8 getLineAttr(int i) const { + return mBuf[(_20 + 2) * i]; + } + + int prevIndex(int n) const { + return (--n < 0) ? mMaxLines - 1 : n; + + } + void scrollToLastLine() { scroll(mMaxLines); } void scrollToFirstLine() { scroll(-mMaxLines); } // _00 = VTBL // _00-_18 = JKRDisposer - JGadget::TLinkListNode mNode; // _18 + JGadget::TLinkListNode mNode; // _18 u32 _20; // _20 u32 mMaxLines; // _24, might be int u8 *mBuf; // _28 @@ -124,11 +133,9 @@ public: u32 mOutput; // _58 JUtility::TColor _5C; // _5C JUtility::TColor _60; // _60 - int _64; // _64 - bool mIsVisible; // _68 - bool _69; // _69 - bool _6A; // _6A - bool _6B; // _6B + bool mIsVisible; // _64 + bool _65; // _65 + bool _66; // _66 }; // Size: 0x6C class JUTConsoleManager diff --git a/include/MSL_C/printf.h b/include/MSL_C/printf.h index aa712edd..f8269cc1 100644 --- a/include/MSL_C/printf.h +++ b/include/MSL_C/printf.h @@ -10,6 +10,8 @@ extern "C" { #endif extern int vprintf(const char*, va_list); +extern int vsprintf(char*, const char*, va_list); +extern int vsnprintf(char*, size_t, const char*, va_list); extern int printf(const char*, ...); int snprintf(char* s, size_t n, const char* format, ...); diff --git a/src/static/JSystem/JFramework/JFWSystem.cpp b/src/static/JSystem/JFramework/JFWSystem.cpp index d96c1a3a..34b33d48 100644 --- a/src/static/JSystem/JFramework/JFWSystem.cpp +++ b/src/static/JSystem/JFramework/JFWSystem.cpp @@ -26,7 +26,7 @@ s32 JFWSystem::CSetUpParam::decompPriority = 7; s32 JFWSystem::CSetUpParam::aPiecePriority = 6; const ResFONT *JFWSystem::CSetUpParam::systemFontRes = &JUTResFONT_Ascfont_fix12; const _GXRenderModeObj *JFWSystem::CSetUpParam::renderMode = &GXNtsc480IntDf; -u32 JFWSystem::CSetUpParam::exConsoleBufferSize = 0x24FC; +u32 JFWSystem::CSetUpParam::exConsoleBufferSize = 0x24F8; JKRHeap *JFWSystem::rootHeap; JKRHeap *JFWSystem::systemHeap; diff --git a/src/static/JSystem/JUtility/JUTConsole.cpp b/src/static/JSystem/JUtility/JUTConsole.cpp new file mode 100644 index 00000000..ddcda5eb --- /dev/null +++ b/src/static/JSystem/JUtility/JUTConsole.cpp @@ -0,0 +1,574 @@ +#include + +#include +#include +#include "JSystem/J2D/J2DGrafContext.h" +#include "JSystem/JKernel/JKRHeap.h" +#include "JSystem/JUtility/JUTConsole.h" +#include "JSystem/JUtility/JUTDirectPrint.h" +#include "JSystem/JUtility/JUTVideo.h" + +#define OUTPUT_NONE 0 +#define OUTPUT_CONSOLE 1 +#define OUTPUT_OSREPORT 2 +#define OUTPUT_ALL (OUTPUT_OSREPORT | OUTPUT_CONSOLE) + +JUTConsoleManager *JUTConsoleManager::sManager; + +JUTConsole *JUTConsole::create(uint param_0, uint maxLines, JKRHeap *pHeap) +{ + JUTConsoleManager *const pManager = JUTConsoleManager::getManager(); + JUT_ASSERT(pManager != 0); + + u8 *buffer = (u8*)JKRAllocFromHeap(pHeap, getObjectSizeFromBufferSize(param_0, maxLines), 0); + + JUTConsole *newConsole = new (buffer) JUTConsole(param_0, maxLines, true); + newConsole->mBuf = buffer + sizeof(JUTConsole); + newConsole->clear(); + + pManager->appendConsole(newConsole); + return newConsole; +} + +JUTConsole *JUTConsole::create(uint param_0, void *buffer, u32 bufferSize) +{ + JUTConsoleManager *const pManager = JUTConsoleManager::getManager(); + JUT_ASSERT(pManager != 0); + JUT_ASSERT(( (u32)buffer & 0x3 ) == 0); + u32 maxLines = getLineFromObjectSize(bufferSize, param_0); + + JUTConsole *newConsole = new (buffer) JUTConsole(param_0, maxLines, false); + newConsole->mBuf = (u8 *)buffer + sizeof(JUTConsole); + newConsole->clear(); + + pManager->appendConsole(newConsole); + return newConsole; +} + +// unused +void JUTConsole::destroy(JUTConsole *console) { + JUT_ASSERT(console != 0); + delete console; +} + +JUTConsole::JUTConsole(uint p1, uint maxLines, bool p3) +{ + _2C = p3; + _20 = p1; + mMaxLines = maxLines; + + mPositionX = 30; + mPositionY = 50; + mHeight = 20; + + if (mHeight > mMaxLines) + { + mHeight = mMaxLines; + } + + mFont = nullptr; + mIsVisible = true; + _65 = false; + _66 = false; + mOutput = 1; + + _5C = JUtility::TColor(0, 0, 0, 100); + _60 = JUtility::TColor(0, 0, 0, 230); +} + +JUTConsole::~JUTConsole() { + JUT_ASSERT(JUTConsoleManager::getManager()) + JUTConsoleManager::getManager()->removeConsole(this); +} + +size_t JUTConsole::getObjectSizeFromBufferSize(unsigned int p1, unsigned int maxLines) +{ + int objSize = (p1 + 2) * maxLines + sizeof(JUTConsole); + return objSize; +} + +size_t JUTConsole::getLineFromObjectSize(u32 bufferSize, unsigned int param_1) +{ + bufferSize -= sizeof(JUTConsole); + int line = (bufferSize) / (param_1 + 2); + return line; +} + +void JUTConsole::clear() +{ + _30 = 0; + _34 = 0; + _38 = 0; + _3C = 0; + + for (int i = 0; i < mMaxLines; i++) + { + setLineAttr(i, 0); + } + setLineAttr(0, -1); + *getLinePtr(0) = 0; +} + +void JUTConsole::doDraw(JUTConsole::EConsoleType consoleType) const +{ + f32 font_yOffset; + s32 changeLine_1; + s32 changeLine_2; + + if (mIsVisible && (mFont || consoleType == CONSOLE_TYPE_2)) + { + if (mHeight != 0) + { + bool isConsoleType0 = consoleType == CONSOLE_TYPE_0 ? true : false; + font_yOffset = 2.0f + mFontSizeY; + + if (consoleType != CONSOLE_TYPE_2) + { + if (!JUTVideo::getManager()) + { + J2DOrthoGraph ortho(0.0f, 0.0f, 640.0f, 480.0f, -1.0f, 1.0f); + ortho.setPort(); + } + else + { + f32 w = JUTVideo::getManager()->getFbWidth(); + f32 h = JUTVideo::getManager()->getEfbHeight(); + J2DOrthoGraph ortho(0.0f, 0.0f, w, h, -1.0f, 1.0f); + ortho.setPort(); + } + + const JUtility::TColor *color; + if (isConsoleType0) + { + color = &_60; + } + else + { + color = &_5C; + } + + J2DFillBox(mPositionX - 2, (int)(mPositionY - font_yOffset), + (int)((mFontSizeX * _20) + 4.0f), (int)(font_yOffset * mHeight), + *color); + mFont->setGX(); + + if (isConsoleType0) + { + s32 s = (diffIndex(_30, _38) - mHeight) + 1; + if (s <= 0) + { + mFont->setCharColor(JUtility::TColor(255, 255, 255, 255)); + } + else if (_30 == _34) + { + mFont->setCharColor(JUtility::TColor(255, 230, 230, 255)); + } + else + { + mFont->setCharColor(JUtility::TColor(230, 230, 255, 255)); + } + } + else + { + mFont->setCharColor(JUtility::TColor(230, 230, 230, 255)); + } + } + else + { + JUTDirectPrint::getManager()->erase(mPositionX - 3, mPositionY - 2, + (_20 * 6) + 6, + (int)(font_yOffset * mHeight) + 4); + } + + char *linePtr; + s32 curLine = _30; + s32 yFactor = 0; + + do + { + linePtr = (char *)getLinePtr(curLine); + + if ((u8)linePtr[-1] != 0) + { + if (consoleType != CONSOLE_TYPE_2) + { + mFont->drawString_scale(mPositionX, ((yFactor * font_yOffset) + mPositionY), + mFontSizeX, mFontSizeY, linePtr, true); + } + else + { + JUTDirectPrint::getManager()->drawString( + mPositionX, ((yFactor * font_yOffset) + mPositionY), linePtr); + } + + changeLine_1 = curLine + 1; + changeLine_2 = ((((s32)changeLine_1 )>= (s32)mMaxLines)) ? 0 : changeLine_1; + yFactor += 1; + curLine = changeLine_2; + } + else + { + break; + } + } while (yFactor < mHeight && changeLine_2 != _34); + } + } +} + +void JUTConsole::print_f(char const *text, ...) +{ + va_list args; + va_start(args, text); + JUTConsole_print_f_va_(this, text, args); + va_end(args); +} + +void JUTConsole::print(char const *param_0) +{ + if (mOutput & OUTPUT_OSREPORT) + { + //JUT_REPORT_MSG("%s", param_0); + } + if (mOutput & OUTPUT_CONSOLE) + { + const u8 *r29 = (const u8 *)param_0; + u8 *r28 = getLinePtr(_38) + _3C; + while (*r29 != 0) + { + if (_66 && _34 == nextIndex(_38)) + { + break; + } + if (*r29 == '\n') + { + r29++; + _3C = _20; + } + else if (*r29 == '\t') + { + r29++; + while (_3C < _20) + { + *(r28++) = ' '; + _3C++; + if (_3C % 8 == 0) + { + break; + } + } + } + else if (mFont && mFont->isLeadByte(*r29)) + { + if (_3C + 1 < _20) + { + *(r28++) = *(r29++); + *(r28++) = *(r29++); + _3C++; + _3C++; + } + else + { + *(r28++) = 0; + _3C++; + } + } + else + { + *(r28++) = *(r29++); + _3C++; + } + if (_3C < _20) + { + continue; + } + *r28 = 0; + _38 = nextIndex(_38); + _3C = 0; + setLineAttr(_38, 0xff); + r28 = getLinePtr(_38); + *r28 = 0; + int local_28 = diffIndex(_30, _38); + if (local_28 == mHeight) + { + _30 = nextIndex(_30); + } + if (_38 == _34) + { + _34 = nextIndex(_34); + } + if (_38 == _30) + { + _30 = nextIndex(_30); + } + + } + *r28 = 0; + } +} + +void JUTConsole_print_f_va_(JUTConsole *console, const char *text, va_list args) +{ + char buf[1024]; + JUT_ASSERT(console!=0); + vsnprintf(buf, sizeof(buf), text, args); + console->print(buf); +} + +void JUTConsole::dumpToTerminal(unsigned int n) { + if (n == 0) { + return; + } + + int lineNo = _34; + if (n != 0xffffffff) { + lineNo = _38; + while (n--) { + int prevIdx = prevIndex(lineNo); + if (!getLineAttr(prevIdx)) { + break; + } + lineNo = prevIdx; + if (prevIdx == _34) { + break; + } + } + } + //OSReport("\n:::dump of console[%x]--------------------------------\n", this); + int i = 0; + do { + u8* line = getLinePtr(lineNo); + if ((u8)line[-1] == 0) { + break; + } + if (_65) { + OSReport("[%03d] %s\n",i, line); + } + else { + OSReport("%s\n", line); + } + lineNo = nextIndex(lineNo); + i++; + } while (lineNo != _34); + + //OSReport(":::dump of console[%x] END----------------------------\n", this); +} + +void JUTConsole::scroll(int scrollAmnt) +{ + if (scrollAmnt < 0) + { + int diff = diffIndex(_34, _30); + if (scrollAmnt < -diff) + { + scrollAmnt = -diff; + } + } + else + { + if (scrollAmnt > 0) + { + if (diffIndex(_34, _38) + 1 <= mHeight) + { + scrollAmnt = 0; + } + else + { + int diff = diffIndex(_30, _38) - mHeight + 1; + if (scrollAmnt > diff) + { + scrollAmnt = diff; + } + } + } + } + + _30 += scrollAmnt; + if (_30 < 0) + { + _30 += mMaxLines; + } + + if (_30 >= mMaxLines) + { + _30 -= mMaxLines; + } +} + +int JUTConsole::getUsedLine() const +{ + int usedLine = diffIndex(_34, _38); + return usedLine; +} + +int JUTConsole::getLineOffset() const +{ + int offset = diffIndex(_34, _30); + return offset; +} + +JUTConsoleManager::JUTConsoleManager() +{ + mActiveConsole = nullptr; + mDirectConsole = nullptr; +} + +JUTConsoleManager *JUTConsoleManager::createManager(JKRHeap *pHeap) +{ + JUT_ASSERT(sManager == 0); + if (pHeap == nullptr) + { + pHeap = JKRGetCurrentHeap(); + } + sManager = new (pHeap, 0) JUTConsoleManager(); + return sManager; +} + +void JUTConsoleManager::appendConsole(JUTConsole *const console) +{ + JUT_ASSERT(sManager != 0 && console != 0); + + // not sure why this assert was 3 lines later + JUT_ASSERT(soLink_.Find( console ) == soLink_.end()); + soLink_.Push_back(console); + if (mActiveConsole == nullptr) + { + mActiveConsole = console; + } +} + +void JUTConsoleManager::removeConsole(JUTConsole *const console) +{ + JUT_ASSERT(sManager != 0 && console != 0); + JUT_ASSERT(soLink_.Find( console ) != soLink_.end()); + + if (mActiveConsole == console) + { + if(soLink_.size() <= 1) { + mActiveConsole = nullptr; + } + else { + mActiveConsole = console != &soLink_.back() ? soLink_.Element_toValue(console->mNode.getNext()) : &soLink_.front(); + } + } + if (JUTGetWarningConsole() == console) + JUTSetWarningConsole(nullptr); + if (JUTGetReportConsole() == console) + JUTSetReportConsole(nullptr); + + soLink_.Remove(console); +} + +void JUTConsoleManager::draw() const +{ + // this cast is needed to match release, luckily doesn't affect tp debug either, so maybe there's another temp or cast somewhere? + JGadget::TLinkList::const_iterator it = ((const JUTConsoleManager *)this)->soLink_.begin(); + JGadget::TLinkList::const_iterator itEnd = soLink_.end(); + + for (; it != itEnd; ++it) + { + const JUTConsole &console = *it; + if (&console != mActiveConsole) + { + console.doDraw(JUTConsole::CONSOLE_TYPE_1); + } + } + + if (mActiveConsole) + mActiveConsole->doDraw(JUTConsole::CONSOLE_TYPE_0); +} + + +void JUTConsoleManager::drawDirect(bool waitRetrace) const { + if(mDirectConsole) { + if(waitRetrace) { + BOOL interrupt = OSEnableInterrupts(); + u32 retrace_count = VIGetRetraceCount(); + do + { + } while (retrace_count == VIGetRetraceCount()); + OSRestoreInterrupts(interrupt); + } + mDirectConsole->doDraw(JUTConsole::CONSOLE_TYPE_2); + } +} + +void JUTConsoleManager::setDirectConsole(JUTConsole *console) { + if (mDirectConsole != nullptr) { + appendConsole(mDirectConsole); + } + if(console != nullptr) { + removeConsole(console); + } + mDirectConsole = console; +} + +static JUTConsole *sReportConsole; +static JUTConsole *sWarningConsole; + +// C Functions +void JUTSetReportConsole(JUTConsole *console) { + sReportConsole = console; +} + +JUTConsole *JUTGetReportConsole() { + return sReportConsole; +} + +void JUTSetWarningConsole(JUTConsole *console) { + sWarningConsole = console; +} + +JUTConsole *JUTGetWarningConsole() { + return sWarningConsole; +} + +void JUTReportConsole_f_va(const char *text, va_list args) { + char buf[256]; + if(!JUTGetReportConsole()) { + vsnprintf(buf, sizeof(buf), text, args); + //JUT_REPORT_MSG("%s", buf); + } + else if (JUTGetReportConsole()->getOutput() & OUTPUT_ALL) { + vsnprintf(buf, sizeof(buf), text, args); + JUTGetReportConsole()->print(buf); + } +} + +void JUTReportConsole_f(const char *text, ...) +{ + va_list vl; + va_start(vl, text); + JUTReportConsole_f_va(text, vl); + va_end(vl); +} + +void JUTReportConsole(const char *text) { + JUTReportConsole_f("%s", text); +} + +void JUTWarningConsole_f_va(const char *text, va_list args) +{ + char buf[256]; + if (!JUTGetWarningConsole()) + { + vsnprintf(buf, sizeof(buf), text, args); + OSReport("%s", buf); + } + else if (JUTGetWarningConsole()->getOutput() & OUTPUT_ALL) + { + vsnprintf(buf, sizeof(buf), text, args); + JUTGetWarningConsole()->print(buf); + } +} + +void JUTWarningConsole_f(const char *text, ...) +{ + va_list vl; + va_start(vl, text); + JUTReportConsole_f_va(text, vl); + va_end(vl); +} + +void JUTWarningConsole(const char *text) { + JUTReportConsole_f("%s", text); +} \ No newline at end of file From 37e7b7bf745c1f63e5a145eb3d97dab2a24c7fb4 Mon Sep 17 00:00:00 2001 From: SwareJonge <41187958+SwareJonge@users.noreply.github.com> Date: Tue, 17 Jun 2025 00:00:16 +0200 Subject: [PATCH 3/9] match JSupport --- configure.py | 4 +- include/JSystem/JKernel/JKRArchive.h | 12 +- include/JSystem/JKernel/JKRFileLoader.h | 1 - include/JSystem/JSupport/JSUFileInputStream.h | 6 + include/JSystem/JSupport/JSUInputStream.h | 9 + .../JSystem/JSupport/JSURandomInputStream.h | 17 ++ src/static/JSystem/JKernel/JKRArchivePub.cpp | 7 +- src/static/JSystem/JSupport/JSUFileStream.cpp | 4 + src/static/JSystem/JSupport/JSUList.cpp | 166 ++++++++++++++++++ 9 files changed, 212 insertions(+), 14 deletions(-) create mode 100644 src/static/JSystem/JSupport/JSUList.cpp diff --git a/configure.py b/configure.py index 5bd9325e..9e9fd86c 100644 --- a/configure.py +++ b/configure.py @@ -657,9 +657,9 @@ config.libs = [ JSystemLib( "JSupport", [ - Object(NonMatching, "JSystem/JSupport/JSUFileStream.cpp"), + Object(Matching, "JSystem/JSupport/JSUFileStream.cpp"), Object(Matching, "JSystem/JSupport/JSUInputStream.cpp"), - Object(NonMatching, "JSystem/JSupport/JSUList.cpp"), + Object(Matching, "JSystem/JSupport/JSUList.cpp"), ], ), JSystemLib( diff --git a/include/JSystem/JKernel/JKRArchive.h b/include/JSystem/JKernel/JKRArchive.h index 0028b253..ad5b8138 100644 --- a/include/JSystem/JKernel/JKRArchive.h +++ b/include/JSystem/JKernel/JKRArchive.h @@ -130,17 +130,17 @@ public: JKRArchive(s32, EMountMode); virtual ~JKRArchive(); // _08 - virtual bool becomeCurrent(const char*); // _10 + virtual bool becomeCurrent(const char*); // _10 virtual void* getResource(const char* path); // _14 virtual void* getResource(u32 type, const char* name); // _18 virtual size_t readResource(void* resourceBuffer, u32 bufferSize, const char* path, JKRExpandSwitch expandSwitch); // _1C virtual size_t readResource(void* resourceBuffer, u32 bufferSize, u32 type, const char* name); // _20 virtual void removeResourceAll(); // _24 - virtual bool removeResource(void*); // _28 - virtual bool detachResource(void*); // _2C - virtual s32 getResSize(const void*) const; // _30 - virtual u32 countFile(const char*) const; // _34 - virtual JKRFileFinder* getFirstFile(const char*) const; // _38 + virtual bool removeResource(void*); // _28 + virtual bool detachResource(void*); // _2C + virtual s32 getResSize(const void*) const; // _30 + virtual u32 countFile(const char*) const; // _34 + virtual JKRFileFinder* getFirstFile(const char*) const; // _38 virtual void* fetchResource(SDIFileEntry* entry, u32* outSize) = 0; // _40 virtual void* fetchResource(void* resourceBuffer, u32 bufferSize, SDIFileEntry* entry, u32* resSize, JKRExpandSwitch expandSwitch) = 0; // _44 diff --git a/include/JSystem/JKernel/JKRFileLoader.h b/include/JSystem/JKernel/JKRFileLoader.h index aa69b0dc..ef46ff9b 100644 --- a/include/JSystem/JKernel/JKRFileLoader.h +++ b/include/JSystem/JKernel/JKRFileLoader.h @@ -56,7 +56,6 @@ protected: const char* mVolumeName; // 0x28 u32 mVolumeType; // 0x2C bool mIsMounted; // 0x30 - u8 field_0x31[3]; // 0x31 u32 mMountCount; // 0x34 }; diff --git a/include/JSystem/JSupport/JSUFileInputStream.h b/include/JSystem/JSupport/JSUFileInputStream.h index 254cd086..fbcc0915 100644 --- a/include/JSystem/JSupport/JSUFileInputStream.h +++ b/include/JSystem/JSupport/JSUFileInputStream.h @@ -23,6 +23,12 @@ protected: const void* mObject; s32 mPosition; }; + +class JSUFileOutputStream : public JSURandomOutputStream { +public: + JSUFileOutputStream(JKRFile *); +}; + #endif #endif diff --git a/include/JSystem/JSupport/JSUInputStream.h b/include/JSystem/JSupport/JSUInputStream.h index 5a0da358..6a6a4fd2 100644 --- a/include/JSystem/JSupport/JSUInputStream.h +++ b/include/JSystem/JSupport/JSUInputStream.h @@ -107,6 +107,15 @@ public: return *this; } }; + +class JSUOutputStream : protected JSUIosBase { +public: + virtual ~JSUOutputStream(); + virtual int getAvailable() const = 0; + virtual int skip(s32 amount); + virtual int readData(void* buf, s32 size) = 0; +}; + #endif #endif diff --git a/include/JSystem/JSupport/JSURandomInputStream.h b/include/JSystem/JSupport/JSURandomInputStream.h index 94ca235b..fb59ebb1 100644 --- a/include/JSystem/JSupport/JSURandomInputStream.h +++ b/include/JSystem/JSupport/JSURandomInputStream.h @@ -21,6 +21,23 @@ public: int peek(void* buf, s32 len); int seek(s32 offset, JSUStreamSeekFrom from); }; + +class JSURandomOutputStream : public JSUOutputStream { +public: + virtual ~JSURandomOutputStream() { } + + virtual int getAvailable() const; + virtual int skip(s32 amount); + virtual int readData(void* buf, s32 count) = 0; + virtual int getLength() const = 0; + virtual int getPosition() const = 0; + virtual int seekPos(s32 offset, JSUStreamSeekFrom from) = 0; + + int align(s32 alignment); + int peek(void* buf, s32 len); + int seek(s32 offset, JSUStreamSeekFrom from); +}; + #endif #endif diff --git a/src/static/JSystem/JKernel/JKRArchivePub.cpp b/src/static/JSystem/JKernel/JKRArchivePub.cpp index e7d41f92..c3fffbd0 100644 --- a/src/static/JSystem/JKernel/JKRArchivePub.cpp +++ b/src/static/JSystem/JKernel/JKRArchivePub.cpp @@ -18,9 +18,8 @@ JKRArchive* JKRArchive::check_mount_already(s32 entryNum, JKRHeap* pHeap) { heap = JKRGetCurrentHeap(); } - JSUList& volumeList = JKRArchive::sVolumeList; JSUListIterator iterator; - for (iterator = volumeList.getFirst(); iterator != volumeList.getEnd(); + for (iterator = sVolumeList.getFirst(); iterator != sVolumeList.getEnd(); ++iterator) { if (iterator->getVolumeType() == 'RARC') { JKRArchive* archive = @@ -36,9 +35,7 @@ JKRArchive* JKRArchive::check_mount_already(s32 entryNum, JKRHeap* pHeap) { } JKRArchive* JKRArchive::check_mount_already(s32 entryNum) { - JSUList& volumeList = JKRArchive::sVolumeList; - JSUListIterator iterator; - for (iterator = volumeList.getFirst(); iterator != volumeList.getEnd(); + for (JSUListIterator iterator = sVolumeList.getFirst(); iterator != sVolumeList.getEnd(); ++iterator) { if (iterator->getVolumeType() == 'RARC') { JKRArchive* archive = diff --git a/src/static/JSystem/JSupport/JSUFileStream.cpp b/src/static/JSystem/JSupport/JSUFileStream.cpp index 6dfa820d..ae299a09 100644 --- a/src/static/JSystem/JSupport/JSUFileStream.cpp +++ b/src/static/JSystem/JSupport/JSUFileStream.cpp @@ -49,3 +49,7 @@ int JSUFileInputStream::seekPos(s32 offset, JSUStreamSeekFrom from) { return this->mPosition - pos; } + +JSUFileOutputStream::JSUFileOutputStream(JKRFile *file) { + +} \ No newline at end of file diff --git a/src/static/JSystem/JSupport/JSUList.cpp b/src/static/JSystem/JSupport/JSUList.cpp new file mode 100644 index 00000000..c1a8cf26 --- /dev/null +++ b/src/static/JSystem/JSupport/JSUList.cpp @@ -0,0 +1,166 @@ +#include "JSystem/JSupport/JSUList.h" + +JSUPtrLink::JSUPtrLink(void *pData) { + mPtrList = 0; + mData = pData; + mPrev = 0; + mNext = 0; +} + +JSUPtrLink::~JSUPtrLink() { + if (mPtrList) { + mPtrList->remove(this); + } +} + +JSUPtrList::JSUPtrList(bool doInitialize) { + if (doInitialize) { + initiate(); + } +} + +JSUPtrList::~JSUPtrList() { + JSUPtrLink* curHead = mHead; + + for (int i = 0; i < mLinkCount; i++) { + curHead->mPtrList = 0; + curHead = curHead->mNext; + } +} + +void JSUPtrList::initiate() { + mHead = 0; + mTail = 0; + mLinkCount = 0; +} + +void JSUPtrList::setFirst(JSUPtrLink *pLink) { + pLink->mPtrList = this; + pLink->mPrev = 0; + pLink->mNext = 0; + mTail = pLink; + mHead = pLink; + mLinkCount = 1; +} + +bool JSUPtrList::append(JSUPtrLink *pLink) { + bool validity = (pLink->mPtrList == 0); + + if (!validity) { + validity = pLink->mPtrList->remove(pLink); + } + + if (validity) { + if (!mLinkCount) { + setFirst(pLink); + } + else { + pLink->mPtrList = this; + pLink->mPrev = mTail; + pLink->mNext = 0; + mTail->mNext = pLink; + mTail = pLink; + mLinkCount = mLinkCount + 1; + } + } + + return validity; +} + +bool JSUPtrList::prepend(JSUPtrLink *pLink) { + bool validity = (pLink->mPtrList == 0); + + if (!validity) { + validity = pLink->mPtrList->remove(pLink); + } + + if (validity) { + if (!mLinkCount) { + setFirst(pLink); + } + else { + pLink->mPtrList = this; + pLink->mPrev = 0; + pLink->mNext = mHead; + mHead->mPrev = pLink; + mHead = pLink; + mLinkCount = mLinkCount + 1; + } + } + + return validity; +} + +bool JSUPtrList::insert(JSUPtrLink *pLink_1, JSUPtrLink *pLink_2) { + if (pLink_1 == mHead) { + return prepend(pLink_2); + } + if (!pLink_1) { + return append(pLink_2); + } + if (pLink_1->mPtrList != this) { + return false; + } + + JSUPtrList* link2PtrList = pLink_2->mPtrList; + + bool validity = (link2PtrList == 0); + + if (!validity) { + validity = link2PtrList->remove(pLink_2); + } + + if (validity) { + JSUPtrLink* prev = pLink_1->mPrev; + pLink_2->mPtrList = this; + pLink_2->mPrev = prev; + pLink_2->mNext = pLink_1; + prev->mNext = pLink_2; + pLink_1->mPrev = pLink_2; + mLinkCount++; + } + + return validity; +} + +bool JSUPtrList::remove(JSUPtrLink *pLink) { + bool isSameList = (pLink->mPtrList == this); + + if (isSameList) { + if (mLinkCount == 1) { + mHead = 0; + mTail = 0; + } + else if (pLink == mHead) { + pLink->mNext->mPrev = 0; + mHead = pLink->mNext; + } + else if (pLink == mTail) { + pLink->mPrev->mNext = 0; + mTail = pLink->mPrev; + } + else { + pLink->mPrev->mNext = pLink->mNext; + pLink->mNext->mPrev = pLink->mPrev; + } + + pLink->mPtrList = 0; + mLinkCount--; + } + + return isSameList; +} + +JSUPtrLink *JSUPtrList::getNthLink(u32 n) const +{ + if (n >= mLinkCount) + { + return nullptr; + } + JSUPtrLink *curHead = mHead; + for (int i = 0; i < n; i++) + { + curHead = curHead->mNext; + } + return curHead; +} \ No newline at end of file From f61c92a59fe6f5026cec9bd516bc3b06750751a8 Mon Sep 17 00:00:00 2001 From: SwareJonge <41187958+SwareJonge@users.noreply.github.com> Date: Tue, 17 Jun 2025 00:38:54 +0200 Subject: [PATCH 4/9] match J2D --- configure.py | 4 +- include/MSL_C/math.h | 2 + src/static/JSystem/J2DGraph/.gitkeep | 0 .../JSystem/J2DGraph/J2DGrafContext.cpp | 201 ++++++++++++++++++ src/static/JSystem/J2DGraph/J2DOrthoGraph.cpp | 97 +++++++++ 5 files changed, 302 insertions(+), 2 deletions(-) delete mode 100644 src/static/JSystem/J2DGraph/.gitkeep create mode 100644 src/static/JSystem/J2DGraph/J2DGrafContext.cpp create mode 100644 src/static/JSystem/J2DGraph/J2DOrthoGraph.cpp diff --git a/configure.py b/configure.py index 9e9fd86c..06f195db 100644 --- a/configure.py +++ b/configure.py @@ -611,8 +611,8 @@ config.libs = [ JSystemLib( "J2DGraph", [ - Object(NonMatching, "JSystem/J2DGraph/J2DGrafContext.cpp"), - Object(NonMatching, "JSystem/J2DGraph/J2DOrthoGraph.cpp"), + Object(Matching, "JSystem/J2DGraph/J2DGrafContext.cpp"), + Object(Matching, "JSystem/J2DGraph/J2DOrthoGraph.cpp"), ], ), JSystemLib( diff --git a/include/MSL_C/math.h b/include/MSL_C/math.h index 3fc61d26..a90549c7 100644 --- a/include/MSL_C/math.h +++ b/include/MSL_C/math.h @@ -21,6 +21,8 @@ extern double sin(double deg); extern double cos(double deg); extern double tan(double deg); +extern double ceil(double); + #ifdef __cplusplus } #endif diff --git a/src/static/JSystem/J2DGraph/.gitkeep b/src/static/JSystem/J2DGraph/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/src/static/JSystem/J2DGraph/J2DGrafContext.cpp b/src/static/JSystem/J2DGraph/J2DGrafContext.cpp new file mode 100644 index 00000000..a672729b --- /dev/null +++ b/src/static/JSystem/J2DGraph/J2DGrafContext.cpp @@ -0,0 +1,201 @@ +#include "JSystem/J2D/J2DGrafContext.h" +#include "MSL_C/math.h" + +J2DGrafContext::J2DGrafContext(f32 left, f32 top, f32 right, f32 bottom) + : mBounds(left, top, left + right, top + bottom) + , mScissorBounds(left, top, left + right, top + bottom) +{ + JUtility::TColor color(-1); + setColor(color); + setLineWidth(6); +} + +void J2DGrafContext::setPort() +{ + setScissor(); + setup2D(); + + GXSetViewport(mBounds.i.x, mBounds.i.y, mBounds.f.x - mBounds.i.x, mBounds.f.y - mBounds.i.y, 0.0f, 1.0f); +} + +void J2DGrafContext::setup2D() +{ + GXSetNumIndStages(0); + for (int i = 0; i < 8; i++) { + GXSetTevDirect((GXTevStageID)i); + } + + GXSetAlphaCompare(GX_ALWAYS, 0, GX_AOP_AND, GX_ALWAYS, 0); + GXSetZMode(0, GX_LEQUAL, 0); + GXSetTevOp(GX_TEVSTAGE0, GX_PASSCLR); + + GXSetNumChans(1); + GXSetNumTevStages(1); + GXSetNumTexGens(0); + GXSetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD_NULL, GX_TEXMAP_NULL, GX_COLOR0A0); + GXSetCullMode(GX_CULL_NONE); + + GXLoadPosMtxImm(mPosMtx, 0); + GC_Mtx m; + PSMTXIdentity(m); + GXLoadTexMtxImm(m, 60, GX_MTX3x4); + + GXSetChanCtrl(GX_COLOR0A0, 0, GX_SRC_REG, GX_SRC_VTX, GX_LIGHT_NULL, GX_DF_NONE, GX_AF_NONE); + GXSetChanCtrl(GX_COLOR1A1, 0, GX_SRC_REG, GX_SRC_REG, GX_LIGHT_NULL, GX_DF_NONE, GX_AF_NONE); + + GXSetCurrentMtx(0); + GXSetTexCoordGen2(GX_TEXCOORD0, GX_TG_MTX2x4, GX_TG_TEX0, 60, 0, 125); + + GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_CLR0, GX_POS_XYZ, GX_RGBA8, 0); + GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_RGBA4, 0); + GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_POS_XYZ, GX_RGBX8, 0xF); + GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX1, GX_POS_XYZ, GX_RGBX8, 0xF); + + GXSetLineWidth(mLineWidth, GX_TO_ZERO); + + GXClearVtxDesc(); + GXSetVtxDesc(GX_VA_POS, GX_DIRECT); + GXSetVtxDesc(GX_VA_CLR0, GX_DIRECT); + GXSetVtxDesc(GX_VA_TEX0, GX_NONE); +} + +void J2DGrafContext::setScissor() +{ + JGeometry::TBox2f hardBounds(0, 0, 1024, 1000); + JGeometry::TBox2f newBounds(mScissorBounds); + + mScissorBounds.intersect(hardBounds); + newBounds.absolute(); + newBounds.addPos(0.0f, -1.0f); + + if (newBounds.intersect(hardBounds)) { + GXSetScissor(newBounds.i.x, newBounds.i.y, newBounds.getWidth(), newBounds.getHeight()); + } else { + GXSetScissor(0, 0, 0, 0); + } +} + +void J2DGrafContext::scissor(const JGeometry::TBox2f& bounds) { mScissorBounds = bounds; } + +void J2DGrafContext::place(const JGeometry::TBox2f& bounds) +{ + mBounds = bounds; + mScissorBounds = bounds; +} + +void J2DGrafContext::setColor(JUtility::TColor colorTL, JUtility::TColor colorTR, JUtility::TColor colorBR, JUtility::TColor colorBL) +{ + mColorTL = colorTL; + mColorTR = colorTR; + mColorBR = colorBR; + mColorBL = colorBL; + + _B0.mType = 1; + _B0.mSrcFactor = 4; + _B0.mDestFactor = 5; + + mLinePart.mType = 1; + mLinePart.mSrcFactor = 4; + mLinePart.mDestFactor = 5; + + mBoxPart.mType = 1; + mBoxPart.mSrcFactor = 4; + mBoxPart.mDestFactor = 5; + + if ((u8)u32(mColorTL) != 0xFF) { + return; + } + + _B0.mType = 0; + _B0.mSrcFactor = 1; + _B0.mDestFactor = 0; + + if ((u8)u32(mColorBR) != 0xFF) { + return; + } + + mLinePart.mType = 0; + mLinePart.mSrcFactor = 1; + mLinePart.mDestFactor = 0; + + if ((u8)u32(mColorTR) != 0xFF) { + return; + } + if ((u8)u32(mColorBL) != 0xFF) { + return; + } + + mBoxPart.mType = 0; + mBoxPart.mSrcFactor = 1; + mBoxPart.mDestFactor = 0; +} + +void J2DGrafContext::setLineWidth(u8 width) +{ + mLineWidth = width; + GXSetLineWidth(mLineWidth, GX_TO_ZERO); +} + +void J2DGrafContext::fillBox(const JGeometry::TBox2f& box) +{ + GXSetBlendMode((GXBlendMode)mBoxPart.mType, (GXBlendFactor)mBoxPart.mSrcFactor, (GXBlendFactor)mBoxPart.mDestFactor, GX_LO_SET); + GXLoadPosMtxImm(mPosMtx, 0); + GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_CLR_RGBA, GX_F32, 0); + + GXBegin(GX_QUADS, GX_VTXFMT0, 4); + GXPosition3f32(box.i.x, box.i.y, 0.0f); + GXColor1u32(mColorTL); + GXPosition3f32(box.f.x, box.i.y, 0.0f); + GXColor1u32(mColorTR); + GXPosition3f32(box.f.x, box.f.y, 0.0f); + GXColor1u32(mColorBL); + GXPosition3f32(box.i.x, box.f.y, 0.0f); + GXColor1u32(mColorBR); + GXEnd(); + + GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_CLR_RGBA, GX_RGBA4, 0); +} + +void J2DGrafContext::drawFrame(const JGeometry::TBox2f& box) +{ + GXSetBlendMode((GXBlendMode)mBoxPart.mType, (GXBlendFactor)mBoxPart.mSrcFactor, (GXBlendFactor)mBoxPart.mDestFactor, GX_LO_SET); + GXLoadPosMtxImm(mPosMtx, 0); + GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_CLR_RGBA, GX_F32, 0); + + GXBegin(GX_LINESTRIP, GX_VTXFMT0, 5); + GXPosition3f32(box.i.x, box.i.y, 0.0f); + GXColor1u32(mColorTL); + GXPosition3f32(box.f.x, box.i.y, 0.0f); + GXColor1u32(mColorTR); + GXPosition3f32(box.f.x, box.f.y, 0.0f); + GXColor1u32(mColorBL); + GXPosition3f32(box.i.x, box.f.y, 0.0f); + GXColor1u32(mColorBR); + GXPosition3f32(box.i.x, box.i.y, 0.0f); + GXColor1u32(mColorTL); + GXEnd(); + + GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_CLR_RGBA, GX_RGBA4, 0); +} + +void J2DGrafContext::line(JGeometry::TVec2f start, JGeometry::TVec2f end) +{ + GXSetBlendMode((GXBlendMode)mLinePart.mType, (GXBlendFactor)mLinePart.mSrcFactor, (GXBlendFactor)mLinePart.mDestFactor, GX_LO_SET); + GXLoadPosMtxImm(mPosMtx, 0); + GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_CLR_RGBA, GX_F32, 0); + + GXBegin(GX_LINES, GX_VTXFMT0, 2); + GXPosition3f32(start.x, start.y, 0.0f); + GXColor1u32(mColorTL); + GXPosition3f32(end.x, end.y, 0.0f); + GXColor1u32(mColorBR); + GXEnd(); + + GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_CLR_RGBA, GX_RGBA4, 0); +} + +void J2DGrafContext::lineTo(JGeometry::TVec2f pos) +{ + line(mPrevPos, pos); + mPrevPos = pos; +} \ No newline at end of file diff --git a/src/static/JSystem/J2DGraph/J2DOrthoGraph.cpp b/src/static/JSystem/J2DGraph/J2DOrthoGraph.cpp new file mode 100644 index 00000000..7d7ec7b7 --- /dev/null +++ b/src/static/JSystem/J2DGraph/J2DOrthoGraph.cpp @@ -0,0 +1,97 @@ +#include "JSystem/J2D/J2DGrafContext.h" + +J2DOrthoGraph::J2DOrthoGraph() + : J2DGrafContext(0.0f, 0.0f, 0.0f, 0.0f) +{ + setLookat(); +} + +J2DOrthoGraph::J2DOrthoGraph(f32 left, f32 top, f32 right, f32 bottom, f32 near, f32 far) + : J2DGrafContext(left, top, right, bottom) +{ + mOrtho = JGeometry::TBox2f(0, 0, right, bottom); + mNear = near; + mFar = far; + setLookat(); +} + +void J2DOrthoGraph::setPort() +{ + J2DGrafContext::setPort(); + C_MTXOrtho(mMtx44, mOrtho.i.y, 0.5f + mOrtho.f.y, mOrtho.i.x, mOrtho.f.x, mNear, mFar); + GXSetProjection(mMtx44, GX_ORTHOGRAPHIC); +} + + +void J2DOrthoGraph::setOrtho(const JGeometry::TBox2f& bounds, f32 far, f32 near) +{ + mOrtho = bounds; + mNear = -near; + mFar = -far; +} + +void J2DOrthoGraph::setLookat() +{ + PSMTXIdentity(mPosMtx); + GXLoadPosMtxImm(mPosMtx, 0); +} + +void J2DOrthoGraph::scissorBounds(JGeometry::TBox2f* out, const JGeometry::TBox2f* src) +{ + f32 widthPower = this->getWidthPower(); + f32 heightPower = this->getHeightPower(); + f32 ix = mBounds.i.x >= 0 ? mBounds.i.x : 0; + f32 iy = mBounds.i.y >= 0 ? mBounds.i.y : 0; + f32 f0 = ix + widthPower * (src->i.x - mOrtho.i.x); + f32 f2 = ix + widthPower * (src->f.x - mOrtho.i.x); + f32 f1 = iy + heightPower * (src->i.y - mOrtho.i.y); + f32 f3 = iy + heightPower * (src->f.y - mOrtho.i.y); + out->set(f0, f1, f2, f3); + out->intersect(mScissorBounds); +} + +void J2DDrawLine(f32 x1, f32 y1, f32 x2, f32 y2, JUtility::TColor color, int line_width) +{ + J2DOrthoGraph oGrph; + oGrph.setLineWidth(line_width); + oGrph.setColor(color); + oGrph.moveTo(x1, y1); + oGrph.lineTo(x2, y2); +} + +void J2DFillBox(f32 l, f32 b, f32 x, f32 y, JUtility::TColor color) +{ + J2DFillBox(JGeometry::TBox2f(l, b, l + x, b + y), color); +} + +void J2DFillBox(const JGeometry::TBox2f& box, JUtility::TColor color) +{ + J2DOrthoGraph oGrph; + oGrph.setColor(color); + oGrph.fillBox(box); +} + +void J2DFillBox(f32 l, f32 b, f32 x, f32 y, JUtility::TColor c1, JUtility::TColor c2, JUtility::TColor c3, JUtility::TColor c4) +{ + J2DFillBox(JGeometry::TBox2f(l, b, l + x, b + y), c1, c2, c3, c4); +} + +void J2DFillBox(const JGeometry::TBox2f &box, JUtility::TColor c1, JUtility::TColor c2, JUtility::TColor c3, JUtility::TColor c4) +{ + J2DOrthoGraph oGrph; + oGrph.setColor(c1, c2, c3, c4); + oGrph.fillBox(box); +} + +void J2DDrawFrame(f32 l, f32 b, f32 x, f32 y, JUtility::TColor color, u8 line_width) +{ + J2DDrawFrame(JGeometry::TBox2f(l, b, l + x, b + y), color, line_width); +} + +void J2DDrawFrame(const JGeometry::TBox2f& box, JUtility::TColor color, u8 line_width) +{ + J2DOrthoGraph oGrph; + oGrph.setColor(color); + oGrph.setLineWidth(line_width); + oGrph.drawFrame(box); +} From 22e1bfab3a3ba88dd81b374f7fbb280c743c80ff Mon Sep 17 00:00:00 2001 From: SwareJonge <41187958+SwareJonge@users.noreply.github.com> Date: Tue, 17 Jun 2025 05:01:41 +0200 Subject: [PATCH 5/9] big progress on JUtility --- configure.py | 22 +- include/JSystem/JUtility/JUTDbPrint.h | 3 +- include/JSystem/JUtility/JUTDirectFile.h | 34 + include/JSystem/JUtility/JUTDirectPrint.h | 22 +- include/JSystem/JUtility/JUTException.h | 2 +- include/JSystem/JUtility/JUTFader.h | 3 - include/JSystem/JUtility/JUTVideo.h | 4 +- include/dolphin/gx/GXFrameBuffer.h | 2 +- include/dolphin/os.h | 4 + include/dolphin/os/OSError.h | 6 +- include/dolphin/os/OSMemory.h | 2 + include/dolphin/vi.h | 12 +- include/libc/string.h | 1 + src/static/JSystem/J2DGraph/J2DOrthoGraph.cpp | 12 +- src/static/JSystem/JUtility/JUTAssert.cpp | 71 ++ src/static/JSystem/JUtility/JUTDbPrint.cpp | 130 ++ src/static/JSystem/JUtility/JUTDirectFile.cpp | 186 +++ .../JSystem/JUtility/JUTDirectPrint.cpp | 203 ++++ src/static/JSystem/JUtility/JUTException.cpp | 1047 +++++++++++++++++ src/static/JSystem/JUtility/JUTFader.cpp | 117 ++ src/static/JSystem/JUtility/JUTFont.cpp | 52 + src/static/JSystem/JUtility/JUTGraphFifo.cpp | 45 + src/static/JSystem/JUtility/JUTProcBar.cpp | 298 +++++ src/static/JSystem/JUtility/JUTResFont.cpp | 528 +++++++++ src/static/JSystem/JUtility/JUTVideo.cpp | 226 ++++ src/static/JSystem/JUtility/JUTXfb.cpp | 115 ++ src/static/dolphin/os/OSError.c | 2 +- src/static/dolphin/os/OSMemory.c | 2 - 28 files changed, 3103 insertions(+), 48 deletions(-) create mode 100644 include/JSystem/JUtility/JUTDirectFile.h create mode 100644 src/static/JSystem/JUtility/JUTAssert.cpp create mode 100644 src/static/JSystem/JUtility/JUTDbPrint.cpp create mode 100644 src/static/JSystem/JUtility/JUTDirectFile.cpp create mode 100644 src/static/JSystem/JUtility/JUTDirectPrint.cpp create mode 100644 src/static/JSystem/JUtility/JUTException.cpp create mode 100644 src/static/JSystem/JUtility/JUTFader.cpp create mode 100644 src/static/JSystem/JUtility/JUTFont.cpp create mode 100644 src/static/JSystem/JUtility/JUTGraphFifo.cpp create mode 100644 src/static/JSystem/JUtility/JUTProcBar.cpp create mode 100644 src/static/JSystem/JUtility/JUTResFont.cpp create mode 100644 src/static/JSystem/JUtility/JUTVideo.cpp create mode 100644 src/static/JSystem/JUtility/JUTXfb.cpp diff --git a/configure.py b/configure.py index 06f195db..12caee21 100644 --- a/configure.py +++ b/configure.py @@ -665,21 +665,21 @@ config.libs = [ JSystemLib( "JUtility", [ - Object(NonMatching, "JSystem/JUtility/JUTAssert.cpp"), + Object(Matching, "JSystem/JUtility/JUTAssert.cpp"), Object(Matching, "JSystem/JUtility/JUTConsole.cpp"), - Object(NonMatching, "JSystem/JUtility/JUTDbPrint.cpp"), - Object(NonMatching, "JSystem/JUtility/JUTDirectFile.cpp"), - Object(NonMatching, "JSystem/JUtility/JUTDirectPrint.cpp"), + Object(Matching, "JSystem/JUtility/JUTDbPrint.cpp"), + Object(Matching, "JSystem/JUtility/JUTDirectFile.cpp"), + Object(Matching, "JSystem/JUtility/JUTDirectPrint.cpp"), Object(NonMatching, "JSystem/JUtility/JUTException.cpp"), - Object(NonMatching, "JSystem/JUtility/JUTFader.cpp"), - Object(NonMatching, "JSystem/JUtility/JUTFont.cpp"), + Object(Matching, "JSystem/JUtility/JUTFader.cpp"), + Object(Matching, "JSystem/JUtility/JUTFont.cpp"), Object(Matching, "JSystem/JUtility/JUTFontData_Ascfont_fix12.s"), Object(Matching, "JSystem/JUtility/JUTGamePad.cpp"), - Object(NonMatching, "JSystem/JUtility/JUTGraphFifo.cpp"), - Object(NonMatching, "JSystem/JUtility/JUTProcBar.cpp"), - Object(NonMatching, "JSystem/JUtility/JUTResFont.cpp"), - Object(NonMatching, "JSystem/JUtility/JUTVideo.cpp"), - Object(NonMatching, "JSystem/JUtility/JUTXfb.cpp"), + Object(Matching, "JSystem/JUtility/JUTGraphFifo.cpp"), + Object(Matching, "JSystem/JUtility/JUTProcBar.cpp"), + Object(Matching, "JSystem/JUtility/JUTResFont.cpp"), + Object(Matching, "JSystem/JUtility/JUTVideo.cpp"), + Object(Matching, "JSystem/JUtility/JUTXfb.cpp"), ], ), # { diff --git a/include/JSystem/JUtility/JUTDbPrint.h b/include/JSystem/JUtility/JUTDbPrint.h index 25b8c9b7..81640cd1 100644 --- a/include/JSystem/JUtility/JUTDbPrint.h +++ b/include/JSystem/JUtility/JUTDbPrint.h @@ -50,13 +50,14 @@ struct JUTDbPrint JKRHeap *mHeap; // _10 }; +void JUTReport(int x, int y, int show_count, const char* fmt, ...); + extern "C" { #endif void* JC_JUTDbPrint_getManager(void); void JC_JUTDbPrint_setVisible(void*, int); // I know these are C++ but these were used to match a c function so I'll fix these when I need them or fix zurumode update. -void JUTReport(int x, int y, int show_count, const char* fmt, ...); #ifdef __cplusplus } diff --git a/include/JSystem/JUtility/JUTDirectFile.h b/include/JSystem/JUtility/JUTDirectFile.h new file mode 100644 index 00000000..1f028940 --- /dev/null +++ b/include/JSystem/JUtility/JUTDirectFile.h @@ -0,0 +1,34 @@ +#ifndef _JSYSTEM_JUT_JUTDIRECTFILE_H +#define _JSYSTEM_JUT_JUTDIRECTFILE_H + +#include +#include "types.h" + +#define JUTDF_BUFSIZE (0x800) + +struct JUTDirectFile +{ + JUTDirectFile(); + + ~JUTDirectFile(); + + bool fopen(const char *); + void fclose(); + int fgets(void *, int); + + // unused/inlined + int fetch32byte(); + void fread(void *, u32); + void setPos(u32); + void fgetc(); + + u8 mBuffer[0x820]; // _000, 0x20 header, 0x800 sector + u8 *mSectorStart; // _820, ptr to 0x800 buffer + u32 mToRead; // _824, length (max 32 bytes) to read + u32 mLength; // _828, length of file + u32 mPos; // _82C, position in file + bool mIsOpen; // _830, is file open + DVDFileInfo mFileInfo; // _834 +}; + +#endif \ No newline at end of file diff --git a/include/JSystem/JUtility/JUTDirectPrint.h b/include/JSystem/JUtility/JUTDirectPrint.h index cda094d6..8f126d01 100644 --- a/include/JSystem/JUtility/JUTDirectPrint.h +++ b/include/JSystem/JUtility/JUTDirectPrint.h @@ -2,10 +2,10 @@ #define JUTDIRECTPRINT_H #include "types.h" -// #include "va_args.h" -#include "JSystem/JUtility/TColor.h" +#include "libc/stdarg.h" #ifdef __cplusplus + class JUTDirectPrint { private: @@ -14,20 +14,17 @@ private: public: static JUTDirectPrint *start(); void erase(int x, int y, int w, int h); - void setCharColor(JUtility::TColor color); - void setCharColor(u8 r, u8 g, u8 b); void drawChar(int, int, int); void drawString(u16 x, u16 y, char *text); void drawString_f(u16 x, u16 y, const char * text, ...); void changeFrameBuffer(void *framebuffer, u16 w, u16 h ); - - // Inline/Unused - void printSub(u16, u16, const char *, va_list *, bool); + void printSub(u16, u16, const char *, va_list, bool); // TODO: Function signature void print(u16, u16, const char *, ...); bool isActive() const { return mFramebuffer != nullptr; } void *getFrameBuffer() { return mFramebuffer; } - JUtility::TColor getCharColor() const { return mCharColor; } + + void changeFrameBuffer(void* fb) { changeFrameBuffer(fb, mFbWidth, mFbHeight); } static JUTDirectPrint *getManager() { return sDirectPrint; } @@ -44,15 +41,6 @@ private: size_t mFbSize; // _0C u8 _10[0x4]; // _10 - unknown u16 *mFrameMemory; // _14 - JUtility::TColor mCharColor; // _18, Color in RGBA format - u16 mCharColorY; // _1C, 1C-2C = color in YCbCr - u16 mCharColorCb; // _1E - u16 mCharColorCb2; // _20 - u16 mCharColorCb4; // _22 - u16 mCharColorCr; // _24 - u16 mCharColorCr2; // _26 - u16 mCharColorCr4; // _28 - u16 _2A; // _2A }; inline void JUTChangeFrameBuffer(void *buffer, u16 height, u16 width) diff --git a/include/JSystem/JUtility/JUTException.h b/include/JSystem/JUtility/JUTException.h index 0413deca..46bc7932 100644 --- a/include/JSystem/JUtility/JUTException.h +++ b/include/JSystem/JUtility/JUTException.h @@ -11,7 +11,7 @@ struct JUTConsole; struct JUTDirectPrint; -typedef void (*JUTErrorHandler)(s32 error, OSContext *context, u32 dsisr, u32 dar); +typedef void (*JUTErrorHandler)(OSError error, OSContext *context, u32 dsisr, u32 dar); enum ExPrintFlags { diff --git a/include/JSystem/JUtility/JUTFader.h b/include/JSystem/JUtility/JUTFader.h index f6ff4410..8e07a3da 100644 --- a/include/JSystem/JUtility/JUTFader.h +++ b/include/JSystem/JUtility/JUTFader.h @@ -28,7 +28,6 @@ struct JUTFader // unused/inlined: void start(int); void setStatus(EStatus, int); - void setResetState(bool reset) { mResetting = reset; } EStatus getStatus() const { return mStatus; } @@ -38,8 +37,6 @@ struct JUTFader EStatus mStatus; // _04 - current status u16 mTicksTarget; // _08 - ticks (calls to control()) to run a fade in/out for u16 mTicksRun; // _0A - ticks the current fade has run - bool mResetting; // _0C - probably exclusive to mkdd, holds true when starting the fadeout for reset, sets back to false when fading in - u8 _0D[3]; // padding JUtility::TColor mColor; // _10 - color of fade JGeometry::TBox2f mViewBox; // _14 - ortho box to render within int mEStatus; // _24 - ??? diff --git a/include/JSystem/JUtility/JUTVideo.h b/include/JSystem/JUtility/JUTVideo.h index 75b7a7a1..6c62f6cd 100644 --- a/include/JSystem/JUtility/JUTVideo.h +++ b/include/JSystem/JUtility/JUTVideo.h @@ -24,8 +24,8 @@ struct JUTVideo static void drawDoneCallback(); u32 getEfbHeight() const { return mRenderModeObj->efbHeight; } - u32 getXfbHeight() const { return mRenderModeObj->xfbHeight; } - u32 getFbWidth() const { return (u16)mRenderModeObj->fbWidth; } // cast required for callDirectDraw + u32 getXfbHeight() const { return mRenderModeObj->xfbHeight & 0xffff; } + u32 getFbWidth() const { return (u16)mRenderModeObj->fbWidth; } void getBounds(u16& width, u16& height) const { width = getFbWidth(); height = getEfbHeight(); diff --git a/include/dolphin/gx/GXFrameBuffer.h b/include/dolphin/gx/GXFrameBuffer.h index 1d695495..5c72166f 100644 --- a/include/dolphin/gx/GXFrameBuffer.h +++ b/include/dolphin/gx/GXFrameBuffer.h @@ -13,7 +13,7 @@ extern "C" { // extern GXRenderModeObj GXNtsc240Int; // extern GXRenderModeObj GXNtsc240IntAa; extern GXRenderModeObj GXNtsc480IntDf; -// extern GXRenderModeObj GXNtsc480Int; +extern GXRenderModeObj GXNtsc480Int; // extern GXRenderModeObj GXNtsc480IntAa; // extern GXRenderModeObj GXNtsc480Prog; // extern GXRenderModeObj GXNtsc480ProgSoft; diff --git a/include/dolphin/os.h b/include/dolphin/os.h index 6f916968..7a8d58c4 100644 --- a/include/dolphin/os.h +++ b/include/dolphin/os.h @@ -3,9 +3,13 @@ #include "types.h" #include "dolphin/os/OSAlloc.h" +#include "dolphin/os/OSArena.h" #include "dolphin/os/OSCache.h" #include "dolphin/os/OSContext.h" +#include "dolphin/os/OSError.h" #include "dolphin/os/OSInterrupt.h" +#include "dolphin/os/OSModule.h" +#include "dolphin/os/OSMemory.h" #include "dolphin/os/OSMessage.h" #include "libforest/osreport.h" /* OSReport funcs */ #include "dolphin/os/OSReset.h" diff --git a/include/dolphin/os/OSError.h b/include/dolphin/os/OSError.h index 61ebbcd9..487c159f 100644 --- a/include/dolphin/os/OSError.h +++ b/include/dolphin/os/OSError.h @@ -26,10 +26,14 @@ typedef void (*OSErrorHandler)(OSError error, OSContext *context, ...); #define OS_ERROR_SYSTEM_INTERRUPT 13 #define OS_ERROR_THERMAL_INTERRUPT 14 #define OS_ERROR_PROTECTION 15 -#define OS_ERROR_MAX (OS_ERROR_THERMAL_INTERRUPT + 1) +#define OS_ERROR_FPE 16 +#define OS_ERROR_MAX (OS_ERROR_FPE + 1) OSErrorHandler OSSetErrorHandler(OSError error, OSErrorHandler handler); +extern OSErrorHandler __OSErrorTable[OS_ERROR_MAX]; +extern u32 __OSFpscrEnableBits; + #ifdef __cplusplus } #endif diff --git a/include/dolphin/os/OSMemory.h b/include/dolphin/os/OSMemory.h index 601cf2cc..b9cb9c73 100644 --- a/include/dolphin/os/OSMemory.h +++ b/include/dolphin/os/OSMemory.h @@ -11,6 +11,8 @@ static void Config24MB(); static void Config48MB(); u32 OSGetConsoleSimulatedMemSize(void); +void OSProtectRange(u32 chan, void* addr, u32 nBytes, u32 control); + #ifdef __cplusplus } #endif diff --git a/include/dolphin/vi.h b/include/dolphin/vi.h index 215a27e0..a33f54ea 100644 --- a/include/dolphin/vi.h +++ b/include/dolphin/vi.h @@ -69,14 +69,22 @@ typedef void (*VIRetraceCallback)(u32 retraceCount); #define VIPadFrameBufferWidth(width) ((u16)(((u16)(width) + 15) & ~15)) +void VIConfigure(const struct _GXRenderModeObj *rm); + void VISetBlack(BOOL); void VIWaitForRetrace(); void VIConfigurePan(u16 x_origin, u16 y_origin, u16 width, u16 height); u32 VIGetRetraceCount(); u32 VIGetDTVStatus(); -void VIFlush(); -void VISetNextFrameBuffer(void *fb); +VIRetraceCallback VISetPreRetraceCallback(VIRetraceCallback callback); +VIRetraceCallback VISetPostRetraceCallback(VIRetraceCallback callback); +void* VIGetNextFrameBuffer(); +void* VIGetCurrentFrameBuffer(); +void VISetNextFrameBuffer(void* fb); + +void VIInit(); +void VIFlush(); #ifdef __cplusplus }; diff --git a/include/libc/string.h b/include/libc/string.h index 2c7fc662..5a87f32e 100644 --- a/include/libc/string.h +++ b/include/libc/string.h @@ -13,6 +13,7 @@ void *memset(void *dest, int ch, size_t count); int memcmp(const void *ptr1, const void *ptr2, size_t num); size_t strlen(const char *s); +long strtol(const char *str, char **end, int base); char *strcpy(char *dest, const char *src); char *strncpy(char *dest, const char *src, size_t num); int strcmp(const char *s1, const char *s2); diff --git a/src/static/JSystem/J2DGraph/J2DOrthoGraph.cpp b/src/static/JSystem/J2DGraph/J2DOrthoGraph.cpp index 7d7ec7b7..c9befb4d 100644 --- a/src/static/JSystem/J2DGraph/J2DOrthoGraph.cpp +++ b/src/static/JSystem/J2DGraph/J2DOrthoGraph.cpp @@ -59,9 +59,9 @@ void J2DDrawLine(f32 x1, f32 y1, f32 x2, f32 y2, JUtility::TColor color, int lin oGrph.lineTo(x2, y2); } -void J2DFillBox(f32 l, f32 b, f32 x, f32 y, JUtility::TColor color) +void J2DFillBox(f32 l, f32 t, f32 x, f32 y, JUtility::TColor color) { - J2DFillBox(JGeometry::TBox2f(l, b, l + x, b + y), color); + J2DFillBox(JGeometry::TBox2f(l, t, l + x, t + y), color); } void J2DFillBox(const JGeometry::TBox2f& box, JUtility::TColor color) @@ -71,9 +71,9 @@ void J2DFillBox(const JGeometry::TBox2f& box, JUtility::TColor color) oGrph.fillBox(box); } -void J2DFillBox(f32 l, f32 b, f32 x, f32 y, JUtility::TColor c1, JUtility::TColor c2, JUtility::TColor c3, JUtility::TColor c4) +void J2DFillBox(f32 l, f32 t, f32 x, f32 y, JUtility::TColor c1, JUtility::TColor c2, JUtility::TColor c3, JUtility::TColor c4) { - J2DFillBox(JGeometry::TBox2f(l, b, l + x, b + y), c1, c2, c3, c4); + J2DFillBox(JGeometry::TBox2f(l, t, l + x, t + y), c1, c2, c3, c4); } void J2DFillBox(const JGeometry::TBox2f &box, JUtility::TColor c1, JUtility::TColor c2, JUtility::TColor c3, JUtility::TColor c4) @@ -83,9 +83,9 @@ void J2DFillBox(const JGeometry::TBox2f &box, JUtility::TColor c1, JUtility::TCo oGrph.fillBox(box); } -void J2DDrawFrame(f32 l, f32 b, f32 x, f32 y, JUtility::TColor color, u8 line_width) +void J2DDrawFrame(f32 l, f32 t, f32 x, f32 y, JUtility::TColor color, u8 line_width) { - J2DDrawFrame(JGeometry::TBox2f(l, b, l + x, b + y), color, line_width); + J2DDrawFrame(JGeometry::TBox2f(l, t, l + x, t + y), color, line_width); } void J2DDrawFrame(const JGeometry::TBox2f& box, JUtility::TColor color, u8 line_width) diff --git a/src/static/JSystem/JUtility/JUTAssert.cpp b/src/static/JSystem/JUtility/JUTAssert.cpp new file mode 100644 index 00000000..bea09b5b --- /dev/null +++ b/src/static/JSystem/JUtility/JUTAssert.cpp @@ -0,0 +1,71 @@ +#include +#include +#include "JSystem/JUtility/JUTAssertion.h" +#include "JSystem/JUtility/JUTConsole.h" +#include "JSystem/JUtility/JUTDbPrint.h" +#include "JSystem/JUtility/JUTDirectPrint.h" + +namespace JUTAssertion +{ + namespace + { + static u32 sMessageLife; + static u32 sMessageOwner; + static bool mSynchro; + static char sMessageFileLine[64]; + static char sMessageString[96]; + + static u32 sDisplayTime = -1; + static u32 sDevice = 3; + static bool sVisible = true; + } + + void create() {} + + u32 flush_subroutine() + { + if (sMessageLife == 0) { + return 0; + } + if (sMessageLife != -1) { + sMessageLife--; + } + if (sMessageLife < 5) { + return 0; + } + return sMessageLife; + } + + void flushMessage() + { + if (flush_subroutine() && sVisible == true) + { + JUTDirectPrint::getManager()->drawString(16, 16, sMessageFileLine); + JUTDirectPrint::getManager()->drawString(16, 24, sMessageString); + } + } + + void flushMessage_dbPrint() + { + if (flush_subroutine() && sVisible == true && JUTDbPrint::getManager()) + { + JUTFont *font = JUTDbPrint::getManager()->getFont(); + if (font) + { + u8 tmp = ((VIGetRetraceCount() & 60) << 2) | 0xF; + font->setGX(); + font->setCharColor(JUtility::TColor(255, tmp, tmp, 255)); + font->drawString(30, 36, sMessageFileLine, true); + font->drawString(30, 54, sMessageString, true); + } + } + } + + void changeDisplayTime(u32 time) { + sDisplayTime = time; + } + + void changeDevice(u32 device) { + sDevice = device; + } +} \ No newline at end of file diff --git a/src/static/JSystem/JUtility/JUTDbPrint.cpp b/src/static/JSystem/JUtility/JUTDbPrint.cpp new file mode 100644 index 00000000..cd63fdd9 --- /dev/null +++ b/src/static/JSystem/JUtility/JUTDbPrint.cpp @@ -0,0 +1,130 @@ +#include "MSL_C/printf.h" +#include "JSystem/JUtility/JUTDbPrint.h" +#include "JSystem/J2D/J2DGrafContext.h" +#include "JSystem/JKernel/JKRHeap.h" +#include "JSystem/JUtility/JUTFont.h" +#include "JSystem/JUtility/JUTVideo.h" +#include "types.h" + +JUTDbPrint *JUTDbPrint::sDebugPrint; + +JUTDbPrint::JUTDbPrint(JUTFont *font, JKRHeap *heap) + : mColor() +{ + mFont = font; + mList = nullptr; + mHeap = (heap) ? heap : JKRHeap::getCurrentHeap(); + mColor = TCOLOR_WHITE; + mVisible = true; +} + +JUTDbPrint::~JUTDbPrint() {} + +JUTDbPrint *JUTDbPrint::start(JUTFont *font, JKRHeap *heap) +{ + if (!sDebugPrint) + { + if (!heap) + { + heap = JKRHeap::getCurrentHeap(); + } + sDebugPrint = new JUTDbPrint(font, heap); + } + return sDebugPrint; +} + +JUTFont *JUTDbPrint::changeFont(JUTFont *newFont) +{ + JUTFont *oldFont = mFont; + if (newFont) + { + mFont = newFont; + } + return oldFont; +} + +void JUTDbPrint::enter(int x, int y, int duration, const char *txt, int len) +{ + if(len > 0) { + JUTDbPrintList *pList = (JUTDbPrintList *)JKRAllocFromHeap(mHeap, sizeof(JUTDbPrintList) + len, -4); + if (pList) + { + pList->mX = x; + pList->mY = y; + pList->mDuration = duration; + pList->mLen = len; + strcpy((char *)&pList->mStr, txt); + pList->mNext = mList; + mList = pList; + } + } +} + +void JUTDbPrint::flush() { + // eyebrow raise emoji + JUTDbPrintList *pList = (JUTDbPrintList *)&mList; + JUTDbPrintList *currList = mList; + + if (mFont) + { + if (currList) + { + J2DOrthoGraph orthograph(0.0f, 0.0f, 640.0f, 480.0f, -1.0f, 1.0f); + orthograph.setPort(); + mFont->setGX(); + mFont->setCharColor(mColor); + while (currList) + { + if (mVisible) + { + drawString(currList->mX, currList->mY, currList->mLen, &currList->mStr); + } + if (--currList->mDuration <= 0) + { + JUTDbPrintList *next = currList->mNext; + JKRFreeToHeap(mHeap, currList); + pList->mNext = next; + currList = next; + } + else + { + pList = currList; + currList = currList->mNext; + } + } + } + } } + +void JUTDbPrint::flush(int left, int top, int right, int bottom) +{ + +} + +void JUTDbPrint::drawString(int x, int y, int len, const unsigned char *str) +{ + mFont->drawString_size(x, y, reinterpret_cast(str), len, true); +} + +void JUTReport(int x, int y, const char *fmt, ...) +{ + va_list vl; + va_start(vl, fmt); + char buf[128]; + s32 n = vsnprintf(buf, sizeof(buf), fmt, vl); + if (n >= 0) { + JUTDbPrint::getManager()->enter(x, y, 1, buf, n < 256 ? n : 255); + } + va_end(); +} + +void JUTReport(int x, int y, int duration, const char *fmt, ...) +{ + va_list vl; + va_start(vl, fmt); + char buf[256]; + s32 n = vsnprintf(buf, sizeof(buf), fmt, vl); + if (n >= 0) { + JUTDbPrint::getManager()->enter(x, y, duration, buf, n < 256 ? n : 255); + } + va_end(vl); +} diff --git a/src/static/JSystem/JUtility/JUTDirectFile.cpp b/src/static/JSystem/JUtility/JUTDirectFile.cpp new file mode 100644 index 00000000..f78d5828 --- /dev/null +++ b/src/static/JSystem/JUtility/JUTDirectFile.cpp @@ -0,0 +1,186 @@ +#include +#include "JSystem/JUtility/JUTDirectFile.h" + +int JUTDirectFile::fetch32byte() +{ + mToRead = mLength - ALIGN_PREV(mPos, DVD_MIN_TRANSFER_SIZE); + + if (mToRead > JUTDF_BUFSIZE) + { + mToRead = JUTDF_BUFSIZE; + } + int interrupts = OSEnableInterrupts(); + int readRes = DVDReadAsync(&mFileInfo, mSectorStart, ALIGN_NEXT(mToRead, DVD_MIN_TRANSFER_SIZE), + ALIGN_PREV(mPos, DVD_MIN_TRANSFER_SIZE), nullptr); + OSRestoreInterrupts(interrupts); + if (!readRes) + { + return -1; + } + else + { + interrupts = OSEnableInterrupts(); + while (DVDGetCommandBlockStatus(&mFileInfo.cb)) + { + ; + } + OSRestoreInterrupts(interrupts); + return mToRead; + } +} + +JUTDirectFile::JUTDirectFile() +{ + mLength = 0; + mPos = 0; + mToRead = 0; + mSectorStart = (u8 *)ALIGN_NEXT((u32)mBuffer, DVD_MIN_TRANSFER_SIZE); + mIsOpen = false; +} + +JUTDirectFile::~JUTDirectFile() { mIsOpen = false; } + +bool JUTDirectFile::fopen(const char *filename) +{ + if (!filename) + { + return false; + } + + int interrupts = OSEnableInterrupts(); + int dvdRes = DVDOpen(const_cast(filename), &mFileInfo); + OSRestoreInterrupts(interrupts); + + if (!dvdRes) + { + mIsOpen = false; + return false; + } + + int interrupts2 = OSEnableInterrupts(); + mLength = mFileInfo.length; + OSRestoreInterrupts(interrupts2); + + mPos = 0; + mIsOpen = true; + return true; +} + +void JUTDirectFile::fclose() +{ + if (mIsOpen) + { + int interrupts = OSEnableInterrupts(); + DVDClose(&mFileInfo); + OSRestoreInterrupts(interrupts); + mIsOpen = false; + } +} +/* + * Gets data of length 'len' and stores in 'buf'. + * Returns actual length gotten in bytes, or -1 if error. + */ +int JUTDirectFile::fgets(void *buf, int len) +{ + // if file isn't open, return error (-1). + if (!mIsOpen) + { + return -1; + } + + // if desired length to get is 0, get... 0 bytes. + if (len == 0) + { + return 0; + } + + // if desired length to get is 1, return 1. + // (final byte gotten is always 0, so len 1 is pointless). + if (len == 1) + { + return 1; + } + + // if buffer to read into doesn't exist, return error. + if (!buf) + { + return -1; + } + + // if we're already beyond the file length, return error. + if (mPos >= mLength) + { + return -1; + } + + int readMax; + u8 *byteBuf = (u8 *)buf; + readMax = len - 1; // desired bytes of data to get (last value is then 0). + int readCount = 0; + + while (mPos < mLength) + { + // if there's nothing left to read, return error. + if (mToRead == 0 && fetch32byte() < 0) + { + return -1; + } + + // read in each chunk. + u32 currPos = mPos & (JUTDF_BUFSIZE - 1); + u32 chunkSize = (mToRead - currPos); + if (readCount + chunkSize > readMax) + { + chunkSize = len - readCount - 1; + } + + BOOL isAtEnd = FALSE; + for (int i = 0; i < chunkSize; i++) + { + u8 byte = mSectorStart[currPos++]; + *byteBuf++ = byte; + + // if we hit the end of a line, stop reading. + if (byte == '\n') + { + chunkSize = i + 1; + isAtEnd = TRUE; + break; + } + } + + // if we exceed the buffer size, stop reading. + if (currPos >= JUTDF_BUFSIZE) + { + mToRead = 0; + } + + // if we hit the end of a line, set final byte to 0 and stop reading. + if (isAtEnd == TRUE) + { + readCount += chunkSize; + *byteBuf = 0; + mPos += chunkSize; + break; + } + + // we should have read the full chunkSize, so update count/pos. + readCount += chunkSize; + mPos += chunkSize; + + // if we're at (or beyond) our desired length, set final byte to 0 and stop reading. + if (readCount >= readMax) + { + *byteBuf = 0; + break; + } + } + + // if got to the end of the data, set final byte to 0. + if (mPos >= mLength) + { + *byteBuf = 0; + } + + return readCount; +} \ No newline at end of file diff --git a/src/static/JSystem/JUtility/JUTDirectPrint.cpp b/src/static/JSystem/JUtility/JUTDirectPrint.cpp new file mode 100644 index 00000000..32aa8d59 --- /dev/null +++ b/src/static/JSystem/JUtility/JUTDirectPrint.cpp @@ -0,0 +1,203 @@ +#include + +#include "MSL_C/printf.h" +#include "JSystem/JUtility/JUTDirectPrint.h" + +JUTDirectPrint *JUTDirectPrint::sDirectPrint; + +JUTDirectPrint::JUTDirectPrint() +{ + changeFrameBuffer(nullptr, 0, 0); +} + +JUTDirectPrint *JUTDirectPrint::start() +{ + if (!sDirectPrint) { + sDirectPrint = new JUTDirectPrint(); + } + + return sDirectPrint; +} + +void JUTDirectPrint::erase(int x, int y, int width, int height) +{ + if (!mFramebuffer) { + return; + } + + if (400 < mFbWidth) + { + x = x << 1; + width = width << 1; + } + + if (300 < mFbHeight) + { + y = y << 1; + height = height << 1; + } + + u16 *pixel = mFrameMemory + mStride * y + x; + for (int i = 0; i < height; i++) + { + for (int j = 0; j < width; j++) + { + *pixel = 0x1080; + pixel = pixel + 1; + } + + pixel += mStride - width; + } +} + +u8 JUTDirectPrint::sAsciiTable[128] = { + 0x7A, 0x7A, 0x7A, 0x7A, 0x7A, 0x7A, 0x7A, 0x7A, 0x7A, 0xFD, 0xFE, 0x7A, 0x7A, 0x7A, 0x7A, 0x7A, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0x29, 0x64, 0x65, 0x66, 0x2B, 0x67, 0x68, 0x25, 0x26, 0x69, 0x2A, 0x6A, 0x27, 0x2C, 0x6B, + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x24, 0x6C, 0x6D, 0x6E, 0x6F, 0x28, + 0x70, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, + 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x71, 0x72, 0x73, 0x74, 0x75, + 0xFF, 0x7D, 0x7E, 0x7F, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x8B, + 0x8C, 0x8D, 0x8E, 0x8F, 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x76, 0x77, 0x78, 0x79, 0x7A, +}; + +u32 JUTDirectPrint::sFontData[64] = { + 0x70871C30, 0x8988A250, 0x88808290, 0x88830C90, 0x888402F8, 0x88882210, 0x71CF9C10, 0xF9CF9C70, + 0x8208A288, 0xF200A288, 0x0BC11C78, 0x0A222208, 0x8A222208, 0x71C21C70, 0x23C738F8, 0x5228A480, + 0x8A282280, 0x8BC822F0, 0xFA282280, 0x8A28A480, 0x8BC738F8, 0xF9C89C08, 0x82288808, 0x82088808, + 0xF2EF8808, 0x82288888, 0x82288888, 0x81C89C70, 0x8A08A270, 0x920DA288, 0xA20AB288, 0xC20AAA88, + 0xA208A688, 0x9208A288, 0x8BE8A270, 0xF1CF1CF8, 0x8A28A220, 0x8A28A020, 0xF22F1C20, 0x82AA0220, + 0x82492220, 0x81A89C20, 0x8A28A288, 0x8A28A288, 0x8A289488, 0x8A2A8850, 0x894A9420, 0x894AA220, + 0x70852220, 0xF8011000, 0x08020800, 0x10840400, 0x20040470, 0x40840400, 0x80020800, 0xF8011000, + 0x70800000, 0x88822200, 0x08820400, 0x108F8800, 0x20821000, 0x00022200, 0x20800020, 0x00000000, +}; + +u32 JUTDirectPrint::sFontData2[77] = { + 0x51421820, 0x53E7A420, 0x014A2C40, 0x01471000, 0x0142AA00, 0x03EAA400, 0x01471A78, 0x00000000, + 0x50008010, 0x20010820, 0xF8020040, 0x20420820, 0x50441010, 0x00880000, 0x00070E00, 0x01088840, + 0x78898820, 0x004A8810, 0x788A8810, 0x01098808, 0x00040E04, 0x70800620, 0x11400820, 0x12200820, + 0x10001020, 0x10000820, 0x100F8820, 0x70000620, 0x60070000, 0x110F82A0, 0x12AA8AE0, 0x084F92A0, + 0x100FBE1C, 0x10089008, 0x60070808, 0x00000000, 0x02000200, 0x7A078270, 0x8BC81E88, 0x8A2822F8, + 0x9A282280, 0x6BC79E78, 0x30000000, 0x48080810, 0x41E80000, 0x422F1830, 0xFBE88810, 0x40288890, + 0x43C89C60, 0x81000000, 0x81000000, 0x990F3C70, 0xA10AA288, 0xE10AA288, 0xA10AA288, 0x98CAA270, + 0x00000000, 0x00000020, 0xF1EF1E20, 0x8A28A0F8, 0x8A281C20, 0xF1E80220, 0x80283C38, 0x00000000, + 0x00000000, 0x8A28B688, 0x8A2A8888, 0x8A2A8878, 0x894A8808, 0x788536F0, 0x00000000, 0x00000000, + 0xF8000000, 0x10000000, 0x20000000, 0x40000000, 0xF8000000, +}; + +void JUTDirectPrint::drawChar(int position_x, int position_y, int ch) { + int codepoint = (100 <= ch) ? ch - 100 : ch; + int col_index = (codepoint % 5) * 6; + int row_index = (codepoint / 5) * 7; + + const u32 *font_data = (100 > ch) ? sFontData + row_index : sFontData2 + row_index; + + int scale_x = (mFbWidth < 400) ? 1 : 2; + int scale_y = (mFbHeight < 300) ? 1 : 2; + + u16 *pixel = mFrameMemory + mStride * position_y * scale_y + position_x * scale_x; + for (int y = 0; y < 7; y++) { + u32 data = *font_data << col_index; + font_data += 1; + + for (int x = 0; x < 6; x++) { + u16 value = (data & 0x80000000) ? 0xeb80 : 0x80; + + for (int y2 = 0; y2 < scale_y; y2++) { + int tmp = mStride * y2; + for (int x2 = 0; x2 < scale_x; x2++) { + u16* row = &pixel[tmp]; + row[x2] = value; + } + } + + data <<= 1; + pixel += scale_x; + } + + pixel += mStride * scale_y - 6 * scale_x; + } +} + +void JUTDirectPrint::changeFrameBuffer(void *fb, u16 width, u16 height) +{ + mFramebuffer = fb; + mFrameMemory = (u16 *)fb; + mFbWidth = width; + mFbHeight = height; + mStride = ALIGN_NEXT((u16)width, 16); + mFbSize = (u32)mStride * (u32)mFbHeight * 2; +} + +void JUTDirectPrint::printSub(u16 position_x, u16 position_y, const char *format, va_list args, bool clear) +{ + char buffer[256]; + if (!mFrameMemory) + { + return; + } + + int buffer_length = vsnprintf(buffer, sizeof(buffer), format, args); + u16 x = position_x; + if (buffer_length > 0) + { + if (clear) + { + erase(position_x - 6, position_y - 3, (buffer_length + 2) * 6, 0xd); + } + + char *ptr = buffer; + for (; 0 < buffer_length; buffer_length--, ptr++) + { + int codepoint = sAsciiTable[*ptr & 0x7f]; + if (codepoint == 0xfe) + { + position_x = x; + position_y += 7; + } + else if (codepoint == 0xfd) + { + s32 current_position = (int)position_x; + s32 tab = (current_position - x + 0x2f) % 0x30; + position_x = current_position + 0x30 - tab; + } + else + { + if (codepoint != 0xff) + { + drawChar(position_x, position_y, codepoint); + } + position_x += 6; + } + } + } + + DCFlushRange(mFrameMemory, mFbSize); +} + +void JUTDirectPrint::print(u16 position_x, u16 position_y, char const *format, ...) +{ + if (mFrameMemory) + { + va_list args; + va_start(args, format); + printSub(position_x, position_y, format, args, true); + va_end(args); + } +} + +void JUTDirectPrint::drawString(u16 position_x, u16 position_y, char *text) +{ + drawString_f(position_x, position_y, "%s", text); +} + +void JUTDirectPrint::drawString_f(u16 position_x, u16 position_y, char const *format, ...) +{ + if (mFrameMemory) + { + va_list args; + va_start(args, format); + printSub(position_x, position_y, format, args, false); + va_end(args); + } +} \ No newline at end of file diff --git a/src/static/JSystem/JUtility/JUTException.cpp b/src/static/JSystem/JUtility/JUTException.cpp new file mode 100644 index 00000000..48bce331 --- /dev/null +++ b/src/static/JSystem/JUtility/JUTException.cpp @@ -0,0 +1,1047 @@ +#include +#include +#include +#include "MSL_C/w_math.h" +#include "MSL_C/printf.h" +#include "libc/string.h" + +#include "JSystem/JUtility/JUTException.h" +#include "JSystem/JUtility/JUTDirectPrint.h" +#include "JSystem/JUtility/JUTDirectFile.h" + +extern long __fpclassifyf(float x); +long __fpclassifyd(double x); +#define fpclassify(x) (sizeof(x) == sizeof(float) ? __fpclassifyf((float)(x)) : __fpclassifyd((double)(x))) + +#define isinf(x) ((fpclassify(x) == 2)) +#define isnan(x) ((fpclassify(x) == 1)) +#define isfinite(x) ((fpclassify(x) > 2)) + +struct CallbackObject +{ + JUTErrorHandler callback; + u16 error; + OSContext *context; + u32 dsisr; + u32 dar; +}; + +void search_name_part(u8 *, u8 *, int); + +OSMessageQueue JUTException::sMessageQueue = {}; +static OSTime c3bcnt[4] = {0, 0, 0, 0}; +const char *JUTException::sCpuExpName[] = { + "SYSTEM RESET", + "MACHINE CHECK", + "DSI", + "ISI", + "EXTERNAL INTERRUPT", + "ALIGNMENT", + "PROGRAM", + "FLOATING POINT", + "DECREMENTER", + "SYSTEM CALL", + "TRACE", + "PERFORMACE MONITOR", + "BREAK POINT", + "SYSTEM INTERRUPT", + "THERMAL INTERRUPT", + "PROTECTION", + "FLOATING POINT" +}; + +JUTException *JUTException::sErrorManager; +JUTErrorHandler JUTException::sPreUserCallback; +JUTErrorHandler JUTException::sPostUserCallback; +static CallbackObject exCallbackObject; +void *JUTException::sConsoleBuffer; +u32 JUTException::sConsoleBufferSize; +JUTConsole *JUTException::sConsole; +u32 JUTException::msr; +u32 JUTException::fpscr; +void *JUTException::sMessageBuffer[1] = { nullptr}; + +JSUList JUTException::sMapFileList(false); + +JUTException::JUTException(JUTDirectPrint *directPrint) :JKRThread(0x4000, 0x10, 0) { + mDirectPrint = directPrint; + + OSSetErrorHandler(OS_ERROR_DSI, (OSErrorHandler)errorHandler); + OSSetErrorHandler(OS_ERROR_ISI, (OSErrorHandler)errorHandler); + OSSetErrorHandler(OS_ERROR_PROGRAM, (OSErrorHandler)errorHandler); + OSSetErrorHandler(OS_ERROR_ALIGNMENT, (OSErrorHandler)errorHandler); + OSSetErrorHandler(OS_ERROR_PROTECTION, (OSErrorHandler)errorHandler); + setFPException(0); + + sPreUserCallback = nullptr; + sPostUserCallback = nullptr; + mGamePad = nullptr; + mPadPort = JUTGamePad::Port_Invalid; + mPrintWaitTime0 = 10; + mPrintWaitTime1 = 10; + mTraceSuppress = 0xffffffff; + _98 = 0; + mPrintFlags = EXPRINTFLAG_All; +} + +JUTException *JUTException::create(JUTDirectPrint *directPrint) { + if(sErrorManager == nullptr) { + sErrorManager = new (JKRGetSystemHeap(), 0) JUTException(directPrint); + sErrorManager->resume(); + } + return sErrorManager; +} + +void *JUTException::run() +{ + PPCMtmsr(PPCMfmsr() & ~0x0900); + OSInitMessageQueue(&sMessageQueue, sMessageBuffer, 1); + OSMessage message; + while (true) + { + OSReceiveMessage(&sMessageQueue, &message, OS_MESSAGE_BLOCK); + CallbackObject *cb = (CallbackObject *)message; + JUTErrorHandler callback = cb->callback; + u16 error = cb->error; + OSContext *context = cb->context; + u32 dsisr = cb->dsisr; + u32 dar = cb->dar; + + if (error < OS_ERROR_MAX) + mStackPointer = context->gpr[1]; + + + if (mFrameMemory == nullptr) + sErrorManager->createFB(); + + if (callback) + callback(error, context, dsisr, dar); + + OSDisableInterrupts(); + + sErrorManager->printContext(error, context, dsisr, dar); + } +} + +void JUTException::errorHandler(OSError error, OSContext *context, u32 dsisr, u32 dar) +{ + msr = PPCMfmsr(); + fpscr = context->fpscr; + OSFillFPUContext(context); + OSSetErrorHandler(error, nullptr); + if (error == OS_ERROR_PROTECTION) + { + OSProtectRange(0, nullptr, 0, 3); + OSProtectRange(1, nullptr, 0, 3); + OSProtectRange(2, nullptr, 0, 3); + OSProtectRange(3, nullptr, 0, 3); + } + + exCallbackObject.callback = sPreUserCallback; + exCallbackObject.error = error; + exCallbackObject.context = context; + exCallbackObject.dsisr = dsisr; + exCallbackObject.dar = dar; + + OSSendMessage(&sMessageQueue, &exCallbackObject, OS_MESSAGE_BLOCK); + OSEnableScheduler(); + OSYieldThread(); +} + +void JUTException::setFPException(u32 fpscr_enable_bits) +{ + __OSFpscrEnableBits = fpscr_enable_bits; + if (fpscr_enable_bits) + { + OSSetErrorHandler(OS_ERROR_FPE, (OSErrorHandler)errorHandler); + } + else + { + OSSetErrorHandler(OS_ERROR_FPE, nullptr); + } +} + +void JUTException::showFloatSub(int index, f32 value) +{ + if (isnan(value)) + { + sConsole->print_f("F%02d: Nan ", index); + } + else if (isinf(value)) + { + if ((*(u8*)(&value)) & 0x80) // signed + { + sConsole->print_f("F%02d:+Inf ", index); + } + else + { + sConsole->print_f("F%02d:-Inf ", index); + } + } + else if (value == 0.0f) + { + sConsole->print_f("F%02d: 0.0 ", index); + } + else + { + sConsole->print_f("F%02d:%+.3E", index, value); + } +} + +void JUTException::showFloat(OSContext *context) +{ + if (!sConsole) + { + return; + } + + sConsole->print("-------------------------------- FPR\n"); + for (int i = 0; i < 10; i++) + { + showFloatSub(i, context->fpr[i]); + sConsole->print(" "); + showFloatSub(i + 11, context->fpr[i + 11]); + sConsole->print(" "); + showFloatSub(i + 22, context->fpr[i + 22]); + sConsole->print("\n"); + } + showFloatSub(10, context->fpr[10]); + sConsole->print(" "); + showFloatSub(21, context->fpr[21]); + sConsole->print("\n"); +} + +bool JUTException::searchPartialModule(u32 address, u32 *module_id, u32 *section_id, u32 *section_offset, u32 *name_offset) +{ + if (!address) + { + return false; + } + + OSModuleInfo *module = *(OSModuleInfo **)0x800030C8; + for (; module != nullptr; module = module->link.next) + { + OSSectionInfo *section = OSGetSectionInfo(module); + for (u32 i = 0; i < module->numSections; section++, i++) + { + if (section->size != 0) + { + u32 addr = section->offset & ~0x01; + if ((addr <= address) && (address < addr + section->size)) + { + if (module_id) + *module_id = module->id; + if (section_id) + *section_id = i; + if (section_offset) + *section_offset = address - addr; + if (name_offset) + *name_offset = module->nameOfs; + return true; + } + } + } + } + + return false; +} + +void search_name_part(u8 *src, u8 *dst, int dst_length) +{ + for (u8 *p = src; *p; p++) + { + if (*p == '\\') + { + src = p; + } + } + + if (*src == '\\') + { + src++; + } + + for (int i = 0; (*src != 0) && (i < dst_length);) + { + if (*src == '.') + break; + *dst++ = *src++; + i++; + } + + *dst = '\0'; +} + +void JUTException::showStack(OSContext *context) +{ + if (!sConsole) + { + return; + } + + u32 i; + + sConsole->print("-------------------------------- TRACE\n"); + u32 *stackPointer = (u32 *)mStackPointer; + sConsole->print_f("Address: BackChain LR save\n"); + + for (i = 0; (stackPointer != nullptr) && (stackPointer != (u32 *)0xFFFFFFFF) && (i++ < 0x10);) + { + if (i > mTraceSuppress) + { + sConsole->print("Suppress trace.\n"); + return; + } + + sConsole->print_f("%08X: %08X %08X\n", stackPointer, stackPointer[0], stackPointer[1]); + showMapInfo_subroutine(stackPointer[1], false); + JUTConsoleManager::getManager()->drawDirect(true); + waitTime(mPrintWaitTime1); + stackPointer = (u32 *)stackPointer[0]; + } +} + +void JUTException::showMainInfo(u16 error, OSContext *context, u32 dsisr, u32 dar) +{ + if (!sConsole) + { + return; + } + + sConsole->print_f("CONTEXT:%08XH (%s EXCEPTION)\n", context, sCpuExpName[error]); + sConsole->print_f("SRR0: %08XH SRR1:%08XH\n", context->srr0, context->srr1); + sConsole->print_f("DSISR: %08XH DAR: %08XH\n", dsisr, dar); +} + +void JUTException::showGPR(OSContext *context) +{ + if (!sConsole) + { + return; + } + + sConsole->print("-------------------------------- GPR\n"); + for (int i = 0; i < 10; i++) + { + sConsole->print_f("R%02d:%08XH R%02d:%08XH R%02d:%08XH\n", i, context->gpr[i], i + 11, + context->gpr[i + 11], i + 22, context->gpr[i + 22]); + } + sConsole->print_f("R%02d:%08XH R%02d:%08XH\n", 10, context->gpr[10], 21, context->gpr[21]); +} + +bool JUTException::showMapInfo_subroutine(u32 address, bool begin_with_newline) +{ + if ((address < 0x80000000) || (0x82ffffff < address)) + { + return false; + } + + u32 name_offset; + u32 module_id; + u32 section_id; + u32 section_offset; + u8 name_part[36]; + + const char *new_line = "\n"; + if (begin_with_newline == false) + { + new_line = ""; + } + + bool result = + searchPartialModule(address, &module_id, §ion_id, §ion_offset, &name_offset); + if (result == true) + { + search_name_part((u8 *)name_offset, name_part, 32); + sConsole->print_f("%s %s:%x section:%d\n", new_line, name_part, section_offset, section_id); + begin_with_newline = false; + } + + JSUListIterator last = sMapFileList.getEnd(); + JSUListIterator first = sMapFileList.getFirst(); + if (first != last) + { + u32 out_addr; + u32 out_size; + char out_line[256]; + + if (result == true) + { + result = + queryMapAddress((char *)name_part, section_offset, section_id, &out_addr, &out_size, + out_line, sizeof(out_line), true, begin_with_newline); + } + else + { + result = queryMapAddress(nullptr, address, -1, &out_addr, &out_size, out_line, + sizeof(out_line), true, begin_with_newline); + } + + if (result == true) + { + return true; + } + } + + return false; +} + +void JUTException::showGPRMap(OSContext *context) +{ + if (!sConsole) + { + return; + } + + bool found_address_register = false; + sConsole->print("-------------------------------- GPRMAP\n"); + + for (int i = 0; i < 31; i++) + { + u32 address = context->gpr[i]; + + if (address >= 0x80000000 && 0x83000000 - 1 >= address) + { + found_address_register = true; + + sConsole->print_f("R%02d: %08XH", i, address); + if (!showMapInfo_subroutine(address, true)) + { + sConsole->print(" no information\n"); + } + JUTConsoleManager::sManager->drawDirect(true); + waitTime(mPrintWaitTime1); + } + } + + if (!found_address_register) + { + sConsole->print(" no register which seem to address.\n"); + } +} + +void JUTException::showSRR0Map(OSContext *context) +{ + if (!sConsole) + { + return; + } + + sConsole->print("-------------------------------- SRR0MAP\n"); + u32 address = context->srr0; + if (address >= 0x80000000 && 0x83000000 - 1 >= address) + { + sConsole->print_f("SRR0: %08XH", address); + if (showMapInfo_subroutine(address, true) == false) + { + sConsole->print(" no information\n"); + } + JUTConsoleManager::getManager()->drawDirect(true); + } +} + +void JUTException::printDebugInfo(JUTException::EInfoPage page, OSError error, OSContext *context, u32 param_3, u32 param_4) +{ + switch (page) + { + case INFOPAGE_GPR: + return showGPR(context); + case INFOPAGE_Float: + showFloat(context); + if (sConsole) + { + sConsole->print_f(" MSR:%08XH\t FPSCR:%08XH\n", msr, fpscr); + } + break; + case INFOPAGE_Stack: + return showStack(context); + case INFOPAGE_GPRMap: + return showGPRMap(context); + case INFOPAGE_SRR0Map: + return showSRR0Map(context); + } +} + +bool JUTException::isEnablePad() const +{ + if (mGamePad == (JUTGamePad *)0xFFFFFFFF) + return true; + + if (mPadPort >= JUTGamePad::Port1) + return true; + + if(mGamePad) { + return true; + } + return false; +} + +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); + + if (mGamePad == (JUTGamePad *)0xffffffff) + { + JUTGamePad gamePad0(JUTGamePad::Port1); + JUTGamePad gamePad1(JUTGamePad::Port2); + JUTGamePad gamePad2(JUTGamePad::Port3); + JUTGamePad gamePad3(JUTGamePad::Port4); + //JUTGamePad::read(); + + c3bcnt[0] = + (gamePad0.isPushing3ButtonReset() ? (c3bcnt[0] != 0 ? c3bcnt[0] : OSGetTime()) : 0); + c3bcnt[1] = + (gamePad1.isPushing3ButtonReset() ? (c3bcnt[1] != 0 ? c3bcnt[1] : OSGetTime()) : 0); + c3bcnt[2] = + (gamePad2.isPushing3ButtonReset() ? (c3bcnt[2] != 0 ? c3bcnt[2] : OSGetTime()) : 0); + c3bcnt[3] = + (gamePad3.isPushing3ButtonReset() ? (c3bcnt[3] != 0 ? c3bcnt[3] : OSGetTime()) : 0); + + OSTime resetTime0 = (c3bcnt[0] != 0) ? (OSGetTime() - c3bcnt[0]) : 0; + OSTime resetTime1 = (c3bcnt[1] != 0) ? (OSGetTime() - c3bcnt[1]) : 0; + OSTime resetTime2 = (c3bcnt[2] != 0) ? (OSGetTime() - c3bcnt[2]) : 0; + OSTime resetTime3 = (c3bcnt[3] != 0) ? (OSGetTime() - c3bcnt[3]) : 0; + + gamePad0.checkResetCallback(resetTime0); + gamePad1.checkResetCallback(resetTime1); + gamePad2.checkResetCallback(resetTime2); + gamePad3.checkResetCallback(resetTime3); + + if (out_trigger) + { + *out_trigger = gamePad0.getTrigger() | gamePad1.getTrigger() | gamePad2.getTrigger() | + gamePad3.getTrigger(); + } + if (out_button) + { + *out_button = gamePad0.getButton() | gamePad1.getButton() | gamePad2.getButton() | + gamePad3.getButton(); + } + + result = true; + } + else if (mPadPort >= JUTGamePad::Port1) + { + JUTGamePad gamePad(mPadPort); + OSTime &gamePadTime = c3bcnt[0]; + gamePadTime = + (gamePad.isPushing3ButtonReset() ? (gamePadTime != 0 ? gamePadTime : OSGetTime()) : 0); + + OSTime resetTime = (gamePadTime != 0) ? (OSGetTime() - gamePadTime) : 0; + gamePad.checkResetCallback(resetTime); + + //JUTGamePad::read(); + if (out_trigger) + { + *out_trigger = gamePad.getTrigger(); + } + if (out_button) + { + *out_button = gamePad.getButton(); + } + + result = true; + } + else if (mGamePad) + { + //JUTGamePad::read(); + if (out_trigger) + { + *out_trigger = mGamePad->getTrigger(); + } + if (out_button) + { + *out_button = mGamePad->getButton(); + } + + result = true; + } + + return result; +} + +void JUTException::printContext(OSError error, OSContext *context, u32 dsisr, u32 dar) +{ + bool is_pad_enabled = isEnablePad() ? false : true; + if (!sErrorManager->mDirectPrint->isActive()) + { + return; + } + VISetPreRetraceCallback(nullptr); + VISetPostRetraceCallback(nullptr); + VISetBlack(FALSE); + VIFlush(); + + if (!sConsole) + { + return; + } + + if(error < OS_ERROR_MAX) + sConsole->print_f("******** EXCEPTION OCCURRED! ********\nFrameMemory:%XH\n", getFrameMemory()); + else + sConsole->print_f("******** USER HALT ********\nFrameMemory:%XH\n", getFrameMemory()); + + int post_callback_executed = false; + while (true) + { + showMainInfo(error, context, dsisr, dar); + + JUTConsoleManager::sManager->drawDirect(true); + waitTime(mPrintWaitTime0); + + if ((mPrintFlags & EXPRINTFLAG_GPR) != 0) + { + printDebugInfo(INFOPAGE_GPR, error, context, dsisr, dar); + JUTConsoleManager::sManager->drawDirect(true); + waitTime(mPrintWaitTime0); + } + if ((mPrintFlags & EXPRINTFLAG_SRR0Map) != 0) + { + printDebugInfo(INFOPAGE_SRR0Map, error, context, dsisr, dar); + JUTConsoleManager::sManager->drawDirect(true); + waitTime(mPrintWaitTime0); + } + if ((mPrintFlags & EXPRINTFLAG_GPRMap) != 0) + { + printDebugInfo(INFOPAGE_GPRMap, error, context, dsisr, dar); + JUTConsoleManager::sManager->drawDirect(true); + waitTime(mPrintWaitTime0); + } + if ((mPrintFlags & EXPRINTFLAG_Float) != 0) + { + printDebugInfo(INFOPAGE_Float, error, context, dsisr, dar); + JUTConsoleManager::sManager->drawDirect(true); + waitTime(mPrintWaitTime0); + } + if ((mPrintFlags & EXPRINTFLAG_Stack) != 0) + { + printDebugInfo(INFOPAGE_Stack, error, context, dsisr, dar); + JUTConsoleManager::sManager->drawDirect(true); + waitTime(mPrintWaitTime1); + } + + sConsole->print("--------------------------------\n"); + JUTConsoleManager::sManager->drawDirect(true); + + if (post_callback_executed == 0 && sPostUserCallback) + { + BOOL enable = OSEnableInterrupts(); + post_callback_executed = true; + (*sPostUserCallback)(error, context, dsisr, dar); + OSRestoreInterrupts(enable); + } + + if (_98 == 0 || !is_pad_enabled) + { + break; + } + + sConsole->setOutput(sConsole->getOutput() & 1); + } + + if (!is_pad_enabled) + { + OSEnableInterrupts(); + + u32 button; + u32 trigger; + + int down = 0; + int up = 0; + do + { + readPad(&trigger, &button); + + bool draw = false; + if (trigger == 0x100) + { + sConsole->scrollToLastLine(); + draw = true; + } + + if (trigger == 0x200) + { + sConsole->scrollToFirstLine(); + draw = true; + } + + if (button == 8) + { + JUTConsole *console = sConsole; + up = (down < 3) ? -1 : ((down < 5) ? -2 : ((down < 7) ? -4 : -8)); + + console->scroll(up); + draw = true; + up = 0; + down++; + } + else if (button == 4) + { + JUTConsole *console = sConsole; + down = (up < 3) ? 1 : ((up < 5) ? 2 : ((up < 7) ? 4 : 8)); + + console->scroll(down); + draw = true; + down = 0; + up++; + } + else + { + down = 0; + up = 0; + } + + if (draw == true) + { + u32 start = VIGetRetraceCount(); + while (start == VIGetRetraceCount()) + ; + JUTConsoleManager::sManager->drawDirect(true); + } + + waitTime(30); + } while (true); + } + + while (true) + { + sConsole->scrollToFirstLine(); + JUTConsoleManager::sManager->drawDirect(true); + waitTime(2000); + + int line_offset; + int used_line; + u32 height; + next: + for (u32 i = sConsole->getHeight(); i > 0; i--) + { + sConsole->scroll(1); + JUTConsoleManager::sManager->drawDirect(true); + + height = sConsole->getHeight(); + JUTConsole *console = sConsole; + line_offset = console->getLineOffset(); + used_line = console->getUsedLine(); + if ((used_line - height) + 1U <= line_offset) + break; + waitTime(20); + } + + waitTime(3000); + height = sConsole->getHeight(); + JUTConsole *console = sConsole; + line_offset = console->getLineOffset(); + used_line = console->getUsedLine(); + if ((used_line - height) + 1U <= line_offset) + { + continue; + } + goto next; + } +} + +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); + } +} + +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; + + void *begin = (void *)ALIGN_PREV((u32)end - size, 32); + void *object = (void *)ALIGN_PREV((s32)begin - sizeof(JUTExternalFB), 32); + JUTExternalFB *fb = new (object) JUTExternalFB(renderMode, GX_GM_1_7, begin, size); + + mDirectPrint->changeFrameBuffer(object); + VIConfigure(renderMode); + VISetNextFrameBuffer(begin); + VISetBlack(FALSE); + VIFlush(); + + mFrameMemory = (JUTExternalFB *)object; +} + +u32 JUTException::getFpscr() { + // TODO: misses stack frame + register u32 ret; + asm { + mfmsr r5 + ori r5, r5, 0x2000 + mtmsr r5 + isync + mffs f1 + stfd f1, 8(r1) + lwz ret, 12(r1) + } + return ret; +} + +JUTErrorHandler JUTException::setPreUserCallback(JUTErrorHandler callback) +{ + JUTErrorHandler previous = sPreUserCallback; + sPreUserCallback = callback; + return previous; +} + +JUTErrorHandler JUTException::setPostUserCallback(JUTErrorHandler callback) +{ + JUTErrorHandler previous = sPostUserCallback; + sPostUserCallback = callback; + return previous; +} + +void JUTException::appendMapFile(const char *path) +{ + if (!path) + { + return; + } + + JSUListIterator iterator; + for (iterator = sMapFileList.getFirst(); iterator != sMapFileList.getEnd(); ++iterator) + { + if (strcmp(path, iterator->mFileName) == 0) + { + return; + } + } + + JUTExMapFile *mapFile = new JUTExMapFile((char *)path); + sMapFileList.append(&mapFile->mLink); +} + +bool JUTException::queryMapAddress(char *mapPath, u32 address, s32 section_id, u32 *out_addr, u32 *out_size, char *out_line, u32 line_length, bool print, bool begin_with_newline) +{ + if (mapPath) + { + char buffer[80]; + strcpy(buffer, mapPath); + strcat(buffer, ".map"); + if (queryMapAddress_single(buffer, address, section_id, out_addr, out_size, out_line, + line_length, print, begin_with_newline) == true) + { + return true; + } + } + else if (sMapFileList.getFirst() != sMapFileList.getEnd()) + { + if (queryMapAddress_single(sMapFileList.getFirst()->getObject()->mFileName, address, -1, + out_addr, out_size, out_line, line_length, print, + begin_with_newline) == true) + { + return true; + } + } + + return false; +} + +bool JUTException::queryMapAddress_single(char *mapPath, u32 address, s32 section_id, u32 *out_addr, u32 *out_size, char *out_line, u32 line_length, bool print, bool begin_with_newline) +{ + /* fake match on TP debug? */ + if (!mapPath) + { + return false; + } + + char section_name[16]; + char buffer[0x200]; + JUTDirectFile file; + int section_idx = 0; + if (!file.fopen(mapPath)) + { + return false; + } + + bool result = false; + bool found_section; + + while (true) + { + section_idx++; + found_section = false; + while (true) + { + char *src; + char *dst; + + if (file.fgets(buffer, sizeof(buffer)) < 0) + break; + if (buffer[0] != '.') + continue; + + int i = 0; + src = buffer + 1; + while (*src != '\0') + { + section_name[i] = *src; + if (*src == ' ' || i == 0xf) + break; + i++; + src++; + } + + section_name[i] = 0; + if (*src == 0) + break; + + if (src[1] == 's' && src[2] == 'e' && src[3] == 'c' && src[4] == 't') + { + found_section = true; + break; + } + } + + if (!found_section) + break; + + if (section_id >= 0 && section_id != section_idx) + continue; + + int length; + + while (true) + { + if ((length = file.fgets(buffer, sizeof(buffer))) <= 4) + break; + if ((length < 28)) + continue; + if ((buffer[28] == '4')) + { + u32 addr = ((buffer[18] - '0') << 28) | strtol(buffer + 19, nullptr, 16); + int size = strtol(buffer + 11, nullptr, 16); + if ((addr <= address && address < addr + size)) + { + if (out_addr) + *out_addr = addr; + + if (out_size) + *out_size = size; + + if (out_line) + { + const u8 *src = (const u8 *)&buffer[0x1e]; + u8 *dst = (u8 *)out_line; + u32 i = 0; + + for (i = 0; i < line_length - 1; ++src) + { + if ((u32)(*src) < ' ' && (u32)*src != '\t') + break; + if ((*src == ' ' || (u32)*src == '\t') && (i != 0)) + { + if (dst[-1] != ' ') + { + *dst = ' '; + dst++; + ++i; + } + } + else + { + *dst++ = *src; + i++; + } + } + + if (i != 0 && dst[-1] == ' ') + { + dst--; + i--; + } + *dst = 0; + + if (print) + { + if (begin_with_newline) + { + sConsole->print("\n"); + } + sConsole->print_f(" [%08X]: .%s [%08X: %XH]\n %s\n", address, section_name, addr, size, out_line); + begin_with_newline = false; + } + } + result = true; + break; + } + } + (void)0; // memes + } + + //if (!result) + //{ + if ((section_id < 0 || section_id != section_idx)) + { + goto cont; + } + //} + if (print && begin_with_newline) + { + sConsole->print("\n"); + } + break; + cont:; + } + + file.fclose(); + return result ? true : false; +} + +void JUTException::createConsole(void *console_buffer, u32 console_buffer_size) +{ + if (!console_buffer || !console_buffer_size) + { + return; + } + + u32 lines = JUTConsole::getLineFromObjectSize(console_buffer_size, 0x32); + if (lines != 0) + { + sConsoleBuffer = console_buffer; + sConsoleBufferSize = console_buffer_size; + sConsole = JUTConsole::create(0x32, console_buffer, console_buffer_size); + + JUTConsoleManager *manager = JUTConsoleManager::sManager; + manager->setDirectConsole(sConsole); + + sConsole->setFontSize(10.0, 6.0); + sConsole->setPosition(15, 26); + sConsole->setHeight(23); + sConsole->setVisible(true); + sConsole->setOutput(JUTConsole::OUTPUT_OSR_AND_CONSOLE); + } +} + +JUTExternalFB::JUTExternalFB(GXRenderModeObj *renderMode, GXGamma gamma, void *buffer, u32 size) +{ + mRenderModeObj = renderMode; + mSize = size; + _0C = 1; + mGamma = gamma; + _10 = false; +} \ No newline at end of file diff --git a/src/static/JSystem/JUtility/JUTFader.cpp b/src/static/JSystem/JUtility/JUTFader.cpp new file mode 100644 index 00000000..465aaa70 --- /dev/null +++ b/src/static/JSystem/JUtility/JUTFader.cpp @@ -0,0 +1,117 @@ +#include "types.h" +#include "JSystem/JUtility/JUTFader.h" +#include "JSystem/JUtility/TColor.h" +#include "JSystem/J2D/J2DGrafContext.h" + +JUTFader::JUTFader(int p1, int p2, int p3, int p4, JUtility::TColor color) + : mColor(color), mViewBox(p1, p2, p1 + p3, p2 + p4) +{ + mStatus = Status_Out; + mTicksTarget = 0; + mTicksRun = 0; + _28 = Status_Out; + mEStatus = -1; +} + +void JUTFader::control() +{ + if (0 <= mEStatus && mEStatus-- == 0) + mStatus = _28; + + if (mStatus == Status_In) + return; + + switch (mStatus) + { + case Status_Out: + mColor.a = 0xFF; + break; + case Status_FadingIn: + mColor.a = 0xFF - ((++mTicksRun * 0xFF) / mTicksTarget); + if (mTicksRun >= mTicksTarget) + { + mStatus = Status_In; + } + break; + case Status_FadingOut: + mColor.a = ((++mTicksRun * 0xFF) / mTicksTarget); + if (mTicksRun >= mTicksTarget) + { + mStatus = Status_Out; + } + break; + } + draw(); +} + +void JUTFader::draw() +{ + if (mColor.a == 0) + return; + + J2DOrthoGraph orthograph; + orthograph.setColor(mColor); + orthograph.fillBox(mViewBox); +} + +void JUTFader::start(int) +{ + // UNUSED FUNCTION +} + +bool JUTFader::startFadeIn(int duration) +{ + bool fadingOut = mStatus == Status_Out; + + if (fadingOut) { + mStatus = Status_FadingIn; + mTicksRun = 0; + mTicksTarget = duration; + } + + return fadingOut; +} + +bool JUTFader::startFadeOut(int duration) +{ + bool fadingIn = mStatus == Status_In; + + if (fadingIn) { + mStatus = Status_FadingOut; + mTicksRun = 0; + mTicksTarget = duration; + } + + return fadingIn; +} + +void JUTFader::setStatus(JUTFader::EStatus i_status, int param_1) +{ + switch (i_status) + { + case Status_Out: + if (param_1 != 0) + { + _28 = Status_Out; + mEStatus = (u16)param_1; + break; + } + + mStatus = Status_Out; + _28 = Status_Out; + mEStatus = 0; + break; + case Status_In: + if (param_1 != 0) + { + _28 = Status_In; + mEStatus = (u16)param_1; + break; + } + + mStatus = Status_In; + _28 = Status_In; + mEStatus = 0; + break; + } +} \ No newline at end of file diff --git a/src/static/JSystem/JUtility/JUTFont.cpp b/src/static/JSystem/JUtility/JUTFont.cpp new file mode 100644 index 00000000..a990eb2b --- /dev/null +++ b/src/static/JSystem/JUtility/JUTFont.cpp @@ -0,0 +1,52 @@ +#include "JSystem/JUtility/JUTFont.h" +#include "JSystem/JUtility/JUTAssertion.h" + +JUTFont::JUTFont() : mColor1(), mColor2(), mColor3(), mColor4() +{ + mValid = false; +} + +void JUTFont::initialize_state() +{ + setCharColor(JUtility::TColor()); + setFixedWidth(false, 0); + mValid = false; +} + +void JUTFont::setCharColor(JUtility::TColor color) +{ + mColor1 = color; + mColor2 = color; + mColor3 = color; + mColor4 = color; +} + +void JUTFont::setGradColor(JUtility::TColor color, JUtility::TColor color2) +{ + mColor1 = color; + mColor2 = color; + mColor3 = color2; + mColor4 = color2; +} + +f32 JUTFont::drawString_size_scale(f32 w, f32 x, f32 y, f32 z, const char *str, u32 usz, bool flag) +{ + int str_int; + f32 w_old = w; + + for (; usz != 0; usz--, str++) + { + str_int = (u8)*str; + if (isLeadByte(str_int)) + { + JUT_ASSERT(usz >= 2); + usz--; + str++; + str_int <<= 8; + str_int |= (u8)*str; + } + w += (drawChar_scale(w, x, y, z, str_int, flag)); + flag = true; + } + return w - w_old; +} \ No newline at end of file diff --git a/src/static/JSystem/JUtility/JUTGraphFifo.cpp b/src/static/JSystem/JUtility/JUTGraphFifo.cpp new file mode 100644 index 00000000..86a328f5 --- /dev/null +++ b/src/static/JSystem/JUtility/JUTGraphFifo.cpp @@ -0,0 +1,45 @@ +#include +#include "JSystem/JKernel/JKRHeap.h" +#include "JSystem/JUtility/JUTGraphFifo.h" + +bool JUTGraphFifo::sInitiated; +JUTGraphFifo *JUTGraphFifo::sCurrentFifo; +GXBool JUTGraphFifo::mGpStatus[5]; + +JUTGraphFifo::JUTGraphFifo(u32 size) +{ + mSize = ALIGN_NEXT(size, 32); + if (sInitiated) + { + mFifo = (GXFifoObj *)JKRAllocFromSysHeap(mSize + sizeof(GXFifoObj), 32); + mBase = mFifo + 1; + GXInitFifoBase(mFifo, mBase, mSize); + GXInitFifoPtrs(mFifo, mBase, mBase); + } + else + { + /** TODO: Figure out what has sizeof 0xA0. */ + mBase = JKRAllocFromSysHeap(mSize + 0xA0, 32); + mBase = (void *)ALIGN_NEXT((u32)mBase, 32); + mFifo = GXInit(mBase, mSize); + sInitiated = true; + sCurrentFifo = this; + } +} + +JUTGraphFifo::~JUTGraphFifo() +{ + sCurrentFifo->save(); + + while (isGPActive()) + { + ; + } + + if (sCurrentFifo == this) + { + sCurrentFifo = nullptr; + } + + JKRFreeToSysHeap(mBase); +} \ No newline at end of file diff --git a/src/static/JSystem/JUtility/JUTProcBar.cpp b/src/static/JSystem/JUtility/JUTProcBar.cpp new file mode 100644 index 00000000..804609a6 --- /dev/null +++ b/src/static/JSystem/JUtility/JUTProcBar.cpp @@ -0,0 +1,298 @@ +#include "JSystem/J2D/J2DGrafContext.h" +#include "JSystem/JUtility/JUTVideo.h" +#include "JSystem/JUtility/JUTProcBar.h" + + +JUTProcBar *JUTProcBar::sManager; + +f32 oneFrameRate = 8.0f; +f32 oneFrameRateUser = 10.0f; + +JUTProcBar::JUTProcBar() { + mVisible = true; + mHeapBarVisible = true; + _108 = 0; + + u16 height = JUTVideo::getManager()->getXfbHeight(); + if (JUTVideo::getManager()->getXfbHeight() > 400) { + + mParams.setBarWidth(2); + mParams.setPosition(39, height - 40); + mParams.setWidth(562); + mParams.setUserPosition(height - 70); + } + else { + mParams.setBarWidth(1); + mParams.setPosition(39, height - 20); + mParams.setWidth(562); + mParams.setUserPosition(height - 35); + } + _110 = 1; + _128 = 0; + mWatchHeap = nullptr; +} + +JUTProcBar::~JUTProcBar() { + sManager = nullptr; +} + +JUTProcBar *JUTProcBar::create() { + if (!sManager) { + sManager = new JUTProcBar(); + } + return sManager; +} + +void JUTProcBar::destroy() { + if (sManager) { + delete sManager; + } + sManager = nullptr; +} + +void JUTProcBar::clear() { + sManager->idleStart(); + sManager->cpuStart(); + sManager->gpStart(); + sManager->wholeLoopStart(); + sManager->mCostFrame = 0; + oneFrameRate = 8.0f; + oneFrameRateUser = 10.0f; +} + +// Matches +void JUTProcBar::bar_subroutine(int param_0, int param_1, int param_2, int param_3, int param_4, + int param_5, int param_6, JUtility::TColor param_7, + JUtility::TColor param_8) { + int var2 = param_5 * param_3 / param_4; + int var1 = param_6 * param_3 / param_4; + + J2DFillBox(param_0, param_1, var2, param_2, param_7); + if (var1 >= 0) + { + if (var1 < 6) + J2DFillBox(param_0, param_1, var1, param_2, param_8); + else + J2DFillBox(param_0 + var1 - 6, param_1, 6.0f, param_2, param_8); + } +} + +// Matched +// perhaps rewrite this function, kinda annoying to read +void JUTProcBar::adjustMeterLength(u32 param_0, f32 *param_1, f32 param_2, f32 param_3, + int *param_4) { + BOOL var2 = false; + float var1 = *param_1; + while (var1 > param_2) + { + if (param_0 * var1 * 20.0f / 16666.0f <= mParams.mWidth - 30.0f) + break; + + var1 -= 0.1f; + var2 = true; + } + + if (var1 >= param_3) + *param_4 = 0; + if (var1 > param_3 - 0.2f) + var1 = param_3; + + while (!var2 && var1 < param_3) + { + (*param_4)++; + if (*param_4 < 0x1e) + break; + if ((param_0 * var1 * 20.0f / 16666.0f) < (mParams.mWidth - 60.0f)) + var1 += 0.2f; + break; + } + *param_1 = var1; +} + +void JUTProcBar::draw() { + drawProcessBar(); + drawHeapBar(); +} + +/* +MKDD: https://decomp.me/scratch/1Q2Ke +TP: https://decomp.me/scratch/YKjcF +*/ +void JUTProcBar::drawProcessBar() { + if (mVisible) + { + int frameDuration = 16666; // duration in miliseconds? for how long a frame takes, + if (JUTVideo::getManager() && ((JUTVideo::getManager()->getRenderMode()->viTVmode >> 2) & 0x0f) == VI_PAL) // possibly a define + frameDuration = 20000; // duration for PAL + + static int cnt = 0; + adjustMeterLength(mWholeLoop.mCost, &oneFrameRate, 1.0f, 10.0f, &cnt); + int r28 = oneFrameRate * 20.0f; + int r27 = mParams.mBarWidth * 8; + int r26 = mParams.mBarWidth * 2; + int r25 = mParams.mBarWidth * 10; + int r24 = (mParams.mWidth - 4 + r28) / r28; + + mIdle.accumePeek(); + mGp.accumePeek(); + mCpu.accumePeek(); + + u32 totalTime = (mGp.mCost - mGpWait.mCost) - mCpu.mCost; // unsure of types + u32 gpuTime = (mGp.mCost - mGpWait.mCost); + J2DFillBox(mParams.mPosX, mParams.mPosY, mParams.mWidth, r27, JUtility::TColor(0, 0, 50, 200)); + J2DDrawFrame(mParams.mPosX, mParams.mPosY, mParams.mWidth, r27, JUtility::TColor(50, 50, 150, 255), 6); + if (mCostFrame > r24) + J2DFillBox(mParams.mPosX, mParams.mPosY + r27 + 1, mParams.mWidth, 1.0f, JUtility::TColor(250, 0, 0, 200)); + else + J2DFillBox(mParams.mPosX, mParams.mPosY + r27 + 1, mCostFrame * r28 + 2, 1.0f, JUtility::TColor(0, 250, 250, 200)); + + int stack92 = mWholeLoop.mCost * r28 / frameDuration; + if (stack92 > mParams.mWidth) + J2DFillBox(mParams.mPosX, mParams.mPosY, mParams.mWidth, 1.0f, JUtility::TColor(255, 100, 0, 255)); + else + J2DFillBox(mParams.mPosX, mParams.mPosY, stack92, 1.0f, JUtility::TColor(50, 255, 0, 255)); + + if (_110 == 0) + { + int r23 = mParams.mPosY + mParams.mBarWidth; + bar_subroutine(mParams.mPosX + 1, r23, r26, r28, frameDuration, mGp.mCost, mGp._08, JUtility::TColor(80, 255, 80, 255), JUtility::TColor(100, 255, 120, 255)); + r23 += mParams.mBarWidth * 2; + bar_subroutine(mParams.mPosX + 1, r23, r26, r28, frameDuration, mCpu.mCost, mCpu._08, JUtility::TColor(255, 80, 80, 255), JUtility::TColor(255, 100, 100, 255)); + r23 += mParams.mBarWidth * 2; + bar_subroutine(mParams.mPosX + 1, r23, r26, r28, frameDuration, mIdle.mCost, mIdle._08, JUtility::TColor(180, 180, 160, 255), JUtility::TColor(200, 200, 200, 255)); + } + else + { + int r22 = mParams.mPosY + mParams.mBarWidth; + int r21 = mParams.mPosX + 1; + bar_subroutine(r21, r22, r26, r28, frameDuration, gpuTime, -1, JUtility::TColor(80, 255, 80, 255), JUtility::TColor(80, 255, 80, 255)); + int thingy1 = gpuTime * r28 / frameDuration + r21; + J2DFillBox(thingy1, r22, mGpWait.calcBarSize(r28, frameDuration), r26, JUtility::TColor(0, 255, 0, 255)); + int r30 = mGp.calcBarSize(r28, frameDuration) + r21; + r21 += totalTime * r28 / frameDuration; + r22 += mParams.mBarWidth * 2; + bar_subroutine(r21, r22, r26, r28, frameDuration, mCpu.mCost, -1, JUtility::TColor(255, 80, 80, 255), JUtility::TColor(255, 80, 80, 255)); + r22 += mParams.mBarWidth * 2; + bar_subroutine(r30, r22, r26, r28, frameDuration, mIdle.mCost, -1, JUtility::TColor(180, 180, 160, 255), JUtility::TColor(180, 180, 160, 255)); + } + for (int i = 1; i < r24; i++) + { + int temp2 = mParams.mPosX + i * r28 + 1; + J2DDrawLine(temp2, mParams.mPosY + mParams.mBarWidth, temp2, mParams.mPosY + r27 - mParams.mBarWidth, (i % 5) != 0 ? JUtility::TColor(100, 100, 255, 255) : JUtility::TColor(180, 255, 255, 255), 12); + } + u32 temp3 = 0; + for (int i = 0; i < 8; i++) + { + CTime *time = &mUsers[i]; + if (++time->_0C >= 0x10 || time->mCost > time->_08) { + time->_08 = time->mCost; + time->_0C = 0; + } + if (time->_08 > temp3) + temp3 = time->_08; + } + if ((temp3 ? true : false) == true) + { + static int cntUser = 0; + adjustMeterLength(temp3, &oneFrameRateUser, 1.0f, 10.0f, &cntUser); + int r21 = oneFrameRateUser * 20.0f; + J2DFillBox(mParams.mPosX, mParams.mUserPosition, mParams.mWidth, r25, JUtility::TColor(0, 0, 50, 200)); + J2DDrawFrame(mParams.mPosX, mParams.mUserPosition, mParams.mWidth, r25, JUtility::TColor(50, 50, 150, 255), 6); + for (int i = 0; i < 8; i++) + { + CTime *time = &mUsers[i]; + if (++time->_0C >= 0x10 || time->mCost > time->_08) { + time->_08 = time->mCost; + time->_0C = 0; + } + if (time->mCost != 0 || time->_08 != 0) + { + int temp4 = time->mCost * r21 / frameDuration; + int temp5 = time->_08 * r21 / frameDuration; + time->mCost = 0; + J2DFillBox(mParams.mPosX + 1, mParams.mUserPosition + mParams.mBarWidth + i * mParams.mBarWidth, temp4, mParams.mBarWidth, JUtility::TColor(time->mR, time->mG, time->mB, 255)); + + if (temp5 < 3u) + J2DFillBox(mParams.mPosX, mParams.mUserPosition + mParams.mBarWidth + i * mParams.mBarWidth, temp5, mParams.mBarWidth, JUtility::TColor(255, 200, 50, 255)); + else + J2DFillBox(mParams.mPosX + temp5 - 3, mParams.mUserPosition + mParams.mBarWidth + i * mParams.mBarWidth, 3.0f, mParams.mBarWidth, JUtility::TColor(255, 200, 50, 255)); + } + } + + int r22 = (mParams.mWidth - 4 + r21) / r21; + + for (int i = 1; i < r22; i++) + { + int temp6 = mParams.mPosX + i * r21 + 1; + J2DDrawLine(temp6, mParams.mUserPosition + mParams.mBarWidth, temp6, mParams.mUserPosition + r25 - mParams.mBarWidth, (i % 5) != 0 ? JUtility::TColor(100, 100, 255, 255) : JUtility::TColor(180, 255, 255, 255), 12); + } + } + _108 = 0; + } +} + +int addrToXPos(void *param_0, int param_1) { + return param_1 * (((u32)param_0 - 0x80000000) / (float)JKRHeap::getMemorySize()); +} + +int byteToXLen(int param_0, int param_1) { + return param_1 * (param_0 / (float)JKRHeap::getMemorySize()); +} + +static void heapBar(JKRHeap *param_0, int param_1, int param_2, int param_3, int param_4, + int param_5) +{ + int stack52 = param_1 + addrToXPos(param_0->getStartAddr(), param_4); + int var1 = param_1 + addrToXPos(param_0->getEndAddr(), param_4); + int stack36 = byteToXLen(param_0->getTotalFreeSize(), param_4); + J2DFillBox(stack52, param_2 - param_5 * 2 + param_5 / 2, var1 - stack52, param_5 / 2, + JUtility::TColor(255, 0, 200, 255)); + J2DFillBox(stack52, param_2 - param_5 * 2 + param_5 / 2, stack36, param_5 / 2, + JUtility::TColor(255, 180, 250, 255)); +} + +/* +Probably close to TP Debug, currently matches TP and MKDD(pik2 probably too) +MKDD(Debug): https://decomp.me/scratch/BUM6J +MKDD(Releae) https://decomp.me/scratch/bxY1q +TP(O3): https://decomp.me/scratch/Mi52V +*/ +void JUTProcBar::drawHeapBar() +{ + if (mHeapBarVisible) + { + int start; // required/workaround for regswaps, end might be a shared variable too, however doesn't seem to be needed? + int posX = mParams.mPosX; + int posY = mParams.mPosY; + int barHeight = mParams.mBarWidth * 2; + int width = mParams.mWidth; + int height = mParams.mBarWidth * 2; + + // draw main box in opaque bordeaux red and main frame in purple? + J2DFillBox(posX, posY - (height * 2), width, height, JUtility::TColor(100, 0, 50, 200)); + J2DDrawFrame(posX, posY - (height * 2), width, height, JUtility::TColor(100, 50, 150, 255), 6); + + // Draws a pink line that shows the size of the memstart to start of arenalow? + start = posX + addrToXPos(JKRHeap::getCodeStart(), width); + int codeEnd = posX + addrToXPos(JKRHeap::getCodeEnd(), width); + J2DFillBox(start, posY - (height * 2), codeEnd - start, height, JUtility::TColor(255, 50, 150, 255)); + + // draws a dark blue line that shows how much memory is free? + start = posX + addrToXPos(JKRHeap::getUserRamStart(), width); + int userEnd = posX + addrToXPos(JKRHeap::getUserRamEnd(), width); + J2DFillBox(start, posY - (height * 2), userEnd - start, height, JUtility::TColor(0, 50, 150, 255)); + + // draws a light blue line that shows how much memory is free in the root heap(blends to light pink, not sure how this works) + int size = byteToXLen(JKRHeap::getRootHeap()->getTotalFreeSize(), width); + J2DFillBox(start, posY - (height * 2), size, height / 2, JUtility::TColor(0, 250, 250, 255)); + if (_128 == 0) + { + // draws a line of either the watch heap(if available), otherwise draw the current heap + JKRHeap *heap = mWatchHeap ? mWatchHeap : JKRGetCurrentHeap(); + if (heap != JKRHeap::getSystemHeap()) { + heapBar(heap, posX, posY, barHeight, width, height); + } + + } + } +} diff --git a/src/static/JSystem/JUtility/JUTResFont.cpp b/src/static/JSystem/JUtility/JUTResFont.cpp new file mode 100644 index 00000000..d82e6d1e --- /dev/null +++ b/src/static/JSystem/JUtility/JUTResFont.cpp @@ -0,0 +1,528 @@ +#include +#include "JSystem/JKernel/JKRHeap.h" +#include "JSystem/JSupport.h" +#include "JSystem/JUtility/JUTConsole.h" +#include "JSystem/JUtility/JUTAssertion.h" +#include "JSystem/JUtility/JUTFont.h" +#include "types.h" + +JUTFont::IsLeadByte const JUTResFont::saoAboutEncoding_[3] = {JUTFont::isLeadByte_1Byte, JUTFont::isLeadByte_2Byte, JUTFont::isLeadByte_ShiftJIS}; +const u32 suAboutEncoding_ = 3; + +JUTResFont::JUTResFont() +{ + initialize_state(); +} + +JUTResFont::JUTResFont(const ResFONT *resource, JKRHeap *heap) +{ + initialize_state(); + JUTResFont::initiate(resource, heap); +} + +JUTResFont::~JUTResFont() +{ + if (mValid) + { + deleteMemBlocks_ResFont(); + initialize_state(); + JUTFont::initialize_state(); + } +} + +void JUTResFont::deleteMemBlocks_ResFont() { delete[] mMemBlocks; } + +void JUTResFont::initialize_state() +{ + mResource = nullptr; + mMemBlocks = nullptr; + mWidthBlocks = nullptr; + mGlyphBlocks = nullptr; + mMapBlocks = nullptr; + mWidth = 0; + mHeight = 0; + _44 = -1; +} + +bool JUTResFont::initiate(const ResFONT *resource, JKRHeap *heap) +{ + if (!protected_initiate(resource, heap)) + { + deleteMemBlocks_ResFont(); + initialize_state(); + JUTFont::initialize_state(); + mValid = false; + return false; + } + return true; +} + +bool JUTResFont::protected_initiate(const ResFONT *resource, JKRHeap *heap) +{ + void **blocks; + + deleteMemBlocks_ResFont(); + initialize_state(); + JUTFont::initialize_state(); + + if (!resource) + { + return false; + } + + mResource = resource; + mValid = true; + + countBlock(); + u32 blockNum = mWidthBlockCount + mGlyphBlockCount + mMapBlockCount; + + mMemBlocks = new (heap, 0) void *[blockNum]; + blocks = mMemBlocks; + if (mMemBlocks == nullptr) + { + return false; + } + else + { + if (mWidthBlockCount != 0) + { + mWidthBlocks = (ResFONT::WidthBlock **)blocks; + blocks += mWidthBlockCount; + } + + if (mGlyphBlockCount != 0) + { + mGlyphBlocks = (ResFONT::GlyphBlock **)blocks; + blocks += mGlyphBlockCount; + } + + if (mMapBlockCount != 0) + { + mMapBlocks = (ResFONT::MapBlock **)blocks; + } + } + + setBlock(); + return true; +} + +void JUTResFont::countBlock() +{ + mWidthBlockCount = 0; + mGlyphBlockCount = 0; + mMapBlockCount = 0; + + BlockHeader *data = (BlockHeader *)mResource->mData; + for (u32 i = 0; i < mResource->mNumBlocks; i++, data = (BlockHeader *)data->getNext()) + { + int magic = data->mMagic; + switch (magic) + { + case 'WID1': + mWidthBlockCount++; + break; + + case 'GLY1': + mGlyphBlockCount++; + break; + + case 'MAP1': + mMapBlockCount++; + break; + + case 'INF1': + // mInfoBlock; + break; + + default: + JUTReportConsole("JUTResFont: Unknown data block\n"); + } + }; +} + +void JUTResFont::setBlock() +{ + int widthNum = 0; + int glyphNum = 0; + int mapNum = 0; + mMaxCode = -1; + + BlockHeader *data = (BlockHeader *)mResource->mData; + for (u32 i = 0; i < mResource->mNumBlocks; i++, data = (BlockHeader *)data->getNext()) + { + int magic = data->mMagic; + switch (magic) + { + case 'INF1': + mInfoBlock = (ResFONT::InfoBlock *)data; + u32 u = mInfoBlock->mFontType; +#line 244 + JUT_ASSERT(u < suAboutEncoding_); + mIsLeadByte = (IsLeadByte *)&saoAboutEncoding_[u]; + break; + + case 'WID1': + mWidthBlocks[widthNum] = (ResFONT::WidthBlock *)data; + widthNum++; + break; + + case 'GLY1': + mGlyphBlocks[glyphNum] = (ResFONT::GlyphBlock *)data; + glyphNum++; + break; + + case 'MAP1': + mMapBlocks[mapNum] = (ResFONT::MapBlock *)data; + if (mMaxCode > mMapBlocks[mapNum]->mStartCode) + { + mMaxCode = mMapBlocks[mapNum]->mStartCode; + } + mapNum++; + break; + + default: + JUTReportConsole("Unknown data block\n"); + break; + } + } +} + +void JUTResFont::setGX() +{ + GXSetNumChans(1); + GXSetNumTevStages(1); + GXSetNumTexGens(1); + + GXSetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR0A0); + GXSetChanCtrl(GX_COLOR0A0, GX_FALSE, GX_SRC_REG, GX_SRC_VTX, GX_LIGHT_NULL, GX_DF_NONE, GX_AF_NONE); + + GXSetTevOp(GX_TEVSTAGE0, GX_MODULATE); + + GXSetBlendMode(GX_BM_BLEND, GX_BL_SRCALPHA, GX_BL_INVSRCALPHA, GX_LO_SET); + GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_CLR_RGBA, GX_RGBA4, 0); + GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_CLR0, GX_CLR_RGBA, GX_RGBA8, 0); + GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_CLR_RGBA, GX_RGBX8, 15); + + GXClearVtxDesc(); + GXSetVtxDesc(GX_VA_POS, GX_DIRECT); + GXSetVtxDesc(GX_VA_CLR0, GX_DIRECT); + GXSetVtxDesc(GX_VA_TEX0, GX_DIRECT); +} + +void JUTResFont::setGX(JUtility::TColor color0, JUtility::TColor color1) +{ + if (u32(color0) == 0 && u32(color1) == -1) + { + setGX(); + } + else + { + GXSetNumChans(1); + GXSetNumTevStages(2); + GXSetNumTexGens(1); + + GXSetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR_NULL); + GXSetChanCtrl(GX_COLOR0A0, GX_FALSE, GX_SRC_REG, GX_SRC_VTX, GX_LIGHT_NULL, GX_DF_NONE, GX_AF_NONE); + + GXSetTevColor(GX_TEVREG0, color0); + GXSetTevColor(GX_TEVREG1, color1); + + GXSetTevColorIn(GX_TEVSTAGE0, GX_CC_C0, GX_CC_C1, GX_CC_TEXC, GX_CC_ZERO); + GXSetTevAlphaIn(GX_TEVSTAGE0, GX_CA_A0, GX_CA_A1, GX_CA_TEXA, GX_CA_ZERO); + GXSetTevColorOp(GX_TEVSTAGE0, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_TRUE, GX_TEVPREV); + GXSetTevAlphaOp(GX_TEVSTAGE0, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_TRUE, GX_TEVPREV); + + GXSetTevOrder(GX_TEVSTAGE1, GX_TEXCOORD_NULL, GX_TEXMAP_NULL, GX_COLOR0A0); + GXSetTevColorIn(GX_TEVSTAGE1, GX_CC_ZERO, GX_CC_CPREV, GX_CC_RASC, GX_CC_ZERO); + GXSetTevAlphaIn(GX_TEVSTAGE1, GX_CA_ZERO, GX_CA_APREV, GX_CA_RASA, GX_CA_ZERO); + GXSetTevColorOp(GX_TEVSTAGE1, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_TRUE, GX_TEVPREV); + GXSetTevAlphaOp(GX_TEVSTAGE1, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_TRUE, GX_TEVPREV); + + GXSetBlendMode(GX_BM_BLEND, GX_BL_SRCALPHA, GX_BL_INVSRCALPHA, GX_LO_SET); + GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_S16, 0); + GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_CLR0, GX_CLR_RGBA, GX_RGBA8, 0); + GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_CLR_RGBA, GX_RGBX8, 15); + + GXClearVtxDesc(); + GXSetVtxDesc(GX_VA_POS, GX_DIRECT); + GXSetVtxDesc(GX_VA_CLR0, GX_DIRECT); + GXSetVtxDesc(GX_VA_TEX0, GX_DIRECT); + } +} + +f32 JUTResFont::drawChar_scale(f32 pos_x, f32 pos_y, f32 scale_x, f32 scale_y, int chr, bool flag) +{ + JUTFont::TWidth width; + f32 posMinX; + // declaration order matters! + f32 posMinY, scaled_height; + f32 posMaxX; + +#line 378 + JUT_ASSERT(mValid); + + loadFont(chr, GX_TEXMAP0, &width); + + if ((mFixed) || (!flag)) + { + posMinX = pos_x; + } + else + { + posMinX = (pos_x - width.w0 * (scale_x / getCellWidth())); + } + + f32 retval = mFixedWidth * (scale_x / getCellWidth()); + if (!mFixed) + { + if (!flag) + { + retval = (width.w1 + width.w0) * (scale_x / getCellWidth()); + } + else + { + retval = width.w1 * (scale_x / getCellWidth()); + } + } + posMaxX = posMinX + scale_x; + // getAscent needs to be called before getHeight for the sake of weak function order + posMinY = pos_y - getAscent() * (scale_y / getHeight()); + scaled_height = scale_y / getHeight(); + f32 descent = getDescent(); + f32 posMaxY = descent * scaled_height + pos_y; + + // glyph section + ResFONT::GlyphBlock *used_glyphs = mGlyphBlocks[_66]; + u16 tex_width = used_glyphs->mTextureWidth; + u16 tex_height = used_glyphs->mTextureHeight; + int t_width = mWidth; + int t_height = mHeight; + int shift_width = (t_width + used_glyphs->mCellWidth) << 15; + int texMinX = (t_width << 15) / tex_width; + int texMinY = (t_height << 15) / tex_height; + int shift_height = t_height + used_glyphs->mCellHeight << 15; + const u32 texMaxX = shift_width / tex_width; + const u32 texMaxY = shift_height / tex_height; + // end glyph section + GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_F32, 0); + + GXBegin(GX_QUADS, GX_VTXFMT0, 4); + // Bottom left + GXPosition3f32(posMinX, posMinY, 0.0f); + GXColor1u32(mColor1); + GXPosition2u16(texMinX, texMinY); + + // Bottom right + GXPosition3f32(posMaxX, posMinY, 0.0f); + GXColor1u32(mColor2); + GXPosition2u16(texMaxX, texMinY); + + // Top right + GXPosition3f32(posMaxX, posMaxY, 0.0f); + GXColor1u32(mColor4); + GXPosition2u16(texMaxX, texMaxY); + + // Top left + GXPosition3f32(posMinX, posMaxY, 0.0f); + GXColor1u32(mColor3); + GXPosition2u16(texMinX, texMaxY); + GXEnd(); + + GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_S16, 0); + + return retval; +} + +void JUTResFont::loadFont(int chr, GXTexMapID id, JUTFont::TWidth *width) +{ + if (width) + { + getWidthEntry(chr, width); + } + int fontcode = getFontCode(chr); + loadImage(fontcode, id); +} + +void JUTResFont::getWidthEntry(int chr, JUTFont::TWidth *width) const +{ + int fontcode = getFontCode(chr); + width->w0 = 0; + width->w1 = mInfoBlock->mWidth; + + for (int i = 0; i < mWidthBlockCount; i++) + { + if (mWidthBlocks[i]->mStartCode <= fontcode && fontcode <= mWidthBlocks[i]->mEndCode) + { + *width = mWidthBlocks[i]->mChunkNum[(fontcode - mWidthBlocks[i]->mStartCode)]; + break; + } + } + return; +} + +int JUTResFont::getCellWidth() const +{ + ResFONT::GlyphBlock *glyph; + ResFONT::GlyphBlock **glyphs; + + glyphs = mGlyphBlocks; + if (glyphs) + { + glyph = *glyphs; + if (glyph) + { + return glyph->mCellWidth; + } + } + return getWidth(); +} + +int JUTResFont::getCellHeight() const +{ + ResFONT::GlyphBlock *glyph; + ResFONT::GlyphBlock **glyphs; + + glyphs = mGlyphBlocks; + if (glyphs) + { + glyph = *glyphs; + if (glyph) + { + return glyph->mCellHeight; + } + } + return getHeight(); +} + +bool JUTResFont::isLeadByte(int chr) const { return (*mIsLeadByte)(chr); } + +// regswaps +int JUTResFont::getFontCode(int chr) const +{ + static const u16 halftofull[95] = { + 0x8140, 0x8149, 0x8168, 0x8194, 0x8190, 0x8193, 0x8195, 0x8166, 0x8169, 0x816A, 0x8196, 0x817B, + 0x8143, 0x817C, 0x8144, 0x815E, 0x824F, 0x8250, 0x8251, 0x8252, 0x8253, 0x8254, 0x8255, 0x8256, + 0x8257, 0x8258, 0x8146, 0x8147, 0x8183, 0x8181, 0x8184, 0x8148, 0x8197, 0x8260, 0x8261, 0x8262, + 0x8263, 0x8264, 0x8265, 0x8266, 0x8267, 0x8268, 0x8269, 0x826A, 0x826B, 0x826C, 0x826D, 0x826E, + 0x826F, 0x8270, 0x8271, 0x8272, 0x8273, 0x8274, 0x8275, 0x8276, 0x8277, 0x8278, 0x8279, 0x816D, + 0x818F, 0x816E, 0x814F, 0x8151, 0x8165, 0x8281, 0x8282, 0x8283, 0x8284, 0x8285, 0x8286, 0x8287, + 0x8288, 0x8289, 0x828A, 0x828B, 0x828C, 0x828D, 0x828E, 0x828F, 0x8290, 0x8291, 0x8292, 0x8293, + 0x8294, 0x8295, 0x8296, 0x8297, 0x8298, 0x8299, 0x829A, 0x816F, 0x8162, 0x8170, 0x8160, + }; + + int ret = mInfoBlock->mDefaultCode; + if ((getFontType() == 2) && (mMaxCode >= 0x8000U) && (chr >= 0x20) && (chr < 0x7FU)) + { + chr = halftofull[chr - 32]; + } + + for (int i = 0; i < mMapBlockCount; i++) + { + if ((mMapBlocks[i]->mStartCode <= chr) && (chr <= mMapBlocks[i]->mEndCode)) + { + if (mMapBlocks[i]->mMappingMethod == 0) + { + ret = chr - mMapBlocks[i]->mStartCode; + break; + } + else if (mMapBlocks[i]->mMappingMethod == 2) + { + ret = *(&mMapBlocks[i]->mLeading + ((chr - mMapBlocks[i]->mStartCode))); // type punning sin + break; + } + else if (mMapBlocks[i]->mMappingMethod == 3) + { + + u16 *leading_temp = &mMapBlocks[i]->mLeading; + int phi_r5 = 0; + int phi_r6_2 = mMapBlocks[i]->mNumEntries - 1; + + while (phi_r6_2 >= phi_r5) + { + int temp_r7 = (phi_r6_2 + phi_r5) / 2; + + if (chr < leading_temp[temp_r7 * 2]) + { + phi_r6_2 = temp_r7 - 1; + continue; + } + + if (chr > leading_temp[temp_r7 * 2]) + { + phi_r5 = temp_r7 + 1; + continue; + } + + ret = leading_temp[temp_r7 * 2 + 1]; // jank? possibly type punning fuckery + break; + } // loop closes here + } + else if (mMapBlocks[i]->mMappingMethod == 1) + { + u16 *phi_r5_2 = nullptr; + if (mMapBlocks[i]->mNumEntries == 1) + { + phi_r5_2 = &mMapBlocks[i]->mLeading; + } + ret = JUTResFont::convertSjis(chr, phi_r5_2); + break; + } + break; + } + } + return ret; +} + +void JUTResFont::loadImage(int code, GXTexMapID id) +{ + + int i = 0; + for (; i < mGlyphBlockCount; i++) + { + if (mGlyphBlocks[i]->mStartCode <= code && code <= mGlyphBlocks[i]->mEndCode) + { + code -= mGlyphBlocks[i]->mStartCode; + break; + } + } + + if (i == mGlyphBlockCount) + return; + + s32 pageNumCells = mGlyphBlocks[i]->mNumRows * mGlyphBlocks[i]->mNumColumns; + s32 pageIdx = code / pageNumCells; + s32 cellIdxInPage = code % pageNumCells; + s32 cellCol = (cellIdxInPage % mGlyphBlocks[i]->mNumRows); + s32 cellRow = (cellIdxInPage / mGlyphBlocks[i]->mNumRows); + mWidth = cellCol * mGlyphBlocks[i]->mCellWidth; + mHeight = cellRow * mGlyphBlocks[i]->mCellHeight; + + if (pageIdx != _44 || i != _66) + { + GXInitTexObj(&_24, &mGlyphBlocks[i]->mData[pageIdx * mGlyphBlocks[i]->mTextureSize], mGlyphBlocks[i]->mTextureWidth, + mGlyphBlocks[i]->mTextureHeight, (GXTexFmt)mGlyphBlocks[i]->mTextureFormat, GX_CLAMP, GX_CLAMP, 0); + + GXInitTexObjLOD(&_24, GX_LINEAR, GX_LINEAR, 0.0f, 0.0f, 0.0f, 0U, 0U, GX_ANISO_1); + _44 = pageIdx; + _66 = i; + } + + GXLoadTexObj(&_24, id); +} + +// probably needs some work to match TP(debug) +int JUTResFont::convertSjis(int inChr, u16 *inLead) const +{ + u8 hi = JSUHiByte(inChr); + u16 lead = JSULoByte(inChr); + int out = lead - 0x40; + if (0x40 <= out) + { + out--; + } + lead = 0x31c; + if(inLead) { + lead = *inLead; + } + return out + (hi - 0x88) * 0xbc + -0x5e + lead; +} diff --git a/src/static/JSystem/JUtility/JUTVideo.cpp b/src/static/JSystem/JUtility/JUTVideo.cpp new file mode 100644 index 00000000..b3a85747 --- /dev/null +++ b/src/static/JSystem/JUtility/JUTVideo.cpp @@ -0,0 +1,226 @@ +#include +#include "JSystem/JUtility/JUTDirectPrint.h" +#include "JSystem/JUtility/JUTVideo.h" +#include "JSystem/JUtility/JUTXfb.h" + +JUTVideo *JUTVideo::sManager; +OSTick JUTVideo::sVideoLastTick; +OSTick JUTVideo::sVideoInterval; + +bool sDrawWaiting; + +JUTVideo *JUTVideo::createManager(const GXRenderModeObj *renderModeObj) +{ + if (sManager == nullptr) + { + sManager = new JUTVideo(renderModeObj); + } + return sManager; +} + +void JUTVideo::destroyManager() +{ + if (sManager != nullptr) + { + delete sManager; + sManager = nullptr; + } +} + +JUTVideo::JUTVideo(const GXRenderModeObj *renderModeObj) +{ + mRenderModeObj = nullptr; + VIInit(); + setRenderMode(renderModeObj); + mIsSetBlack = true; + mSetBlackFrameCount = 2; + VISetBlack(TRUE); + VIFlush(); + _08 = 0; + mRetraceCount = VIGetRetraceCount(); + _10 = 1; + _18 = 0; + sVideoLastTick = OSGetTick(); + sVideoInterval = 670000; + mPreviousPreRetraceCallback = VISetPreRetraceCallback(preRetraceProc); + mPreviousPostRetraceCallback = VISetPostRetraceCallback(postRetraceProc); + mPreRetraceCallback = nullptr; + mPostRetraceCallback = nullptr; + OSInitMessageQueue(&mMessageQueue, &mMessage, 1); + GXSetDrawDoneCallback(drawDoneCallback); +} + +JUTVideo::~JUTVideo() +{ + VISetPreRetraceCallback(mPreviousPreRetraceCallback); + VISetPostRetraceCallback(mPreviousPostRetraceCallback); +} + +void JUTVideo::preRetraceProc(u32 retrace_count) +{ + if (sManager->mPreRetraceCallback) + { + (*sManager->mPreRetraceCallback)(retrace_count); + } + + OSTick tick = OSGetTick(); + sVideoInterval = OSDiffTick(tick, sVideoLastTick); + sVideoLastTick = tick; + + JUTXfb *xfb = JUTXfb::getManager(); + if (!xfb) + { + VISetBlack(TRUE); + VIFlush(); + return; + } + + static void *frameBuffer = nullptr; + + if (frameBuffer) + { + JUTVideo *videoManager = JUTGetVideoManager(); + const GXRenderModeObj *renderMode = videoManager->getRenderMode(); + JUTDirectPrint *directPrint = JUTDirectPrint::getManager(); + directPrint->changeFrameBuffer(frameBuffer, renderMode->fbWidth, renderMode->efbHeight); + } + + if (sManager->mIsSetBlack == 1) + { + s32 frame_count = sManager->mSetBlackFrameCount; + if (frame_count > 0) + { + frame_count--; + } + + sManager->mSetBlackFrameCount = frame_count; + sManager->mIsSetBlack = frame_count != 0 ? true : false; + VISetBlack(TRUE); + VIFlush(); + return; + } + + if (!xfb) + { + VISetBlack(TRUE); + VIFlush(); + return; + } + + if (xfb->getBufferNum() == 3 || xfb->getBufferNum() == 2) + { + if (!sDrawWaiting) + { + s16 index = xfb->getDrawnXfbIndex(); + xfb->setDisplayingXfbIndex(index); + if (index < 0) + { + VISetBlack(TRUE); + VIFlush(); + } + else + { + VISetBlack(FALSE); + VISetNextFrameBuffer(xfb->getDisplayingXfb()); + VIFlush(); + frameBuffer = xfb->getDisplayingXfb(); + } + } + } + else if (xfb->getBufferNum() == 1) + { + if (xfb->getSDrawingFlag() == 0) + { + s16 index = xfb->getDrawnXfbIndex(); + if (index >= 0) + { + xfb->setDisplayingXfbIndex(index); + GXCopyDisp(xfb->getDisplayingXfb(), GX_TRUE); + GXFlush(); + xfb->setSDrawingFlag(2); + frameBuffer = xfb->getDisplayingXfb(); + VISetBlack(FALSE); + + } + else + { + VISetBlack(TRUE); + } + } + VIFlush(); + } +} + +void JUTVideo::drawDoneStart() +{ + sDrawWaiting = true; + GXSetDrawDone(); +} + +void JUTVideo::dummyNoDrawWait() { sDrawWaiting = false; } + +void JUTVideo::drawDoneCallback() +{ + JUTXfb *xfb = JUTXfb::getManager(); + if (!xfb) + { + return; + } + + sDrawWaiting = false; + + if (xfb->getBufferNum() == JUTXfb::SingleBuffer && xfb->getSDrawingFlag() == 1) + { + xfb->setSDrawingFlag(0); + if (xfb->getDrawnXfb()) + { + VISetNextFrameBuffer(xfb->getDrawnXfb()); + VIFlush(); + } + } +} + +void JUTVideo::postRetraceProc(u32 p1) +{ + if (sManager->mPostRetraceCallback != nullptr) + { + sManager->mPostRetraceCallback(p1); + } + u32 retraceCount = VIGetRetraceCount(); + OSSendMessage(&sManager->mMessageQueue, (void *)retraceCount, OS_MESSAGE_NOBLOCK); +} + +void JUTVideo::setRenderMode(const GXRenderModeObj *newRenderModeObj) +{ + if (mRenderModeObj && newRenderModeObj->viTVmode != mRenderModeObj->viTVmode) + { + mIsSetBlack = true; + mSetBlackFrameCount = 4; + } + + mRenderModeObj = (GXRenderModeObj *)newRenderModeObj; + VIConfigure(mRenderModeObj); + VIFlush(); + + if (mIsSetBlack) + { + VIWaitForRetrace(); + VIWaitForRetrace(); + } +} + +void JUTVideo::waitRetraceIfNeed() {} + +VIRetraceCallback JUTVideo::setPreRetraceCallback(VIRetraceCallback newCB) +{ + VIRetraceCallback oldCB = mPreRetraceCallback; + mPreRetraceCallback = newCB; + return oldCB; +} + +VIRetraceCallback JUTVideo::setPostRetraceCallback(VIRetraceCallback newCB) +{ + VIRetraceCallback oldCB = mPostRetraceCallback; + mPostRetraceCallback = newCB; + return oldCB; +} \ No newline at end of file diff --git a/src/static/JSystem/JUtility/JUTXfb.cpp b/src/static/JSystem/JUtility/JUTXfb.cpp new file mode 100644 index 00000000..521ed13b --- /dev/null +++ b/src/static/JSystem/JUtility/JUTXfb.cpp @@ -0,0 +1,115 @@ +#include +#include +#include "JSystem/JUtility/JUTAssertion.h" +#include "JSystem/JKernel/JKRHeap.h" +#include "JSystem/JUtility/JUTVideo.h" +#include "JSystem/JUtility/JUTXfb.h" + +JUTXfb *JUTXfb::sManager; + +void JUTXfb::clearIndex() +{ + mDrawingXfbIndex = -1; + mDrawnXfbIndex = -1; + mDisplayingXfbIndex = -1; +} + +void JUTXfb::common_init(int xfbNum) { + mBufferNum = xfbNum; + clearIndex(); + mSDrawingFlag = 99; +} + +JUTXfb::JUTXfb(const GXRenderModeObj *rmode, JKRHeap *heap, JUTXfb::EXfbNumber number) +{ + common_init(number); + + if (rmode) + { + initiate(rmode->fbWidth, rmode->xfbHeight, heap, number); + } + else + { + u16 efbWidth = JUTVideo::getManager()->getRenderMode()->fbWidth; + u16 xfbHeight = JUTVideo::getManager()->getRenderMode()->xfbHeight; + u16 efbHeight = JUTVideo::getManager()->getRenderMode()->efbHeight; + + initiate(efbWidth, xfbHeight, heap, number); + } +} + +JUTXfb::~JUTXfb() +{ + for (int i = 0; i < 3; i++) + { + delXfb(i); + } + sManager = nullptr; +} + +void JUTXfb::delXfb(int xfbIdx) +{ + if (mXfbAllocated[xfbIdx] && mBuffer[xfbIdx]) + { + delete mBuffer[xfbIdx]; + } +} + +JUTXfb *JUTXfb::createManager(const GXRenderModeObj* rmode, JKRHeap *heap, JUTXfb::EXfbNumber number) +{ + JUT_CONFIRM_MESSAGE(sManager == 0); + if (sManager == nullptr) + { + sManager = new JUTXfb(rmode, heap, number); + } + return sManager; +} + +void JUTXfb::destroyManager() +{ + JUT_CONFIRM_MESSAGE(sManager); + delete sManager; + sManager = nullptr; +} + +void JUTXfb::initiate(u16 w, u16 h, JKRHeap *heap, JUTXfb::EXfbNumber number) +{ + if (heap == nullptr) + { + heap = JKRGetSystemHeap(); + } + + u32 size = (u16)ALIGN_NEXT((u16)w, 16) * h; + + mBuffer[0] = new (heap, 32) u16[size]; + mXfbAllocated[0] = true; + if (number >= DoubleBuffer) + { + mBuffer[1] = new (heap, 32) u16[size]; + mXfbAllocated[1] = true; + } + else + { + mBuffer[1] = nullptr; + mXfbAllocated[1] = false; + } + + if (number >= TripleBuffer) + { + mBuffer[2] = new (heap, 32) u16[size]; + mXfbAllocated[2] = true; + } + else + { + mBuffer[2] = nullptr; + mXfbAllocated[2] = false; + } +} + +u32 JUTXfb::accumeXfbSize() +{ + JUTVideo *video = JUTVideo::getManager(); + u16 height = video->getXfbHeight(); + u16 width = video->getFbWidth(); + return (u16)ALIGN_NEXT(width, 16) * height * 2; +} diff --git a/src/static/dolphin/os/OSError.c b/src/static/dolphin/os/OSError.c index 183d4e44..3f07bf04 100644 --- a/src/static/dolphin/os/OSError.c +++ b/src/static/dolphin/os/OSError.c @@ -6,7 +6,7 @@ #include "dolphin/hw_regs.h" // #include "va_args.h" -OSErrorHandler __OSErrorTable[16]; +OSErrorHandler __OSErrorTable[OS_ERROR_MAX]; extern volatile __OSInterrupt __OSLastInterrupt; extern volatile u32 __OSLastInterruptSrr0; diff --git a/src/static/dolphin/os/OSMemory.c b/src/static/dolphin/os/OSMemory.c index 0d961449..fe0af603 100644 --- a/src/static/dolphin/os/OSMemory.c +++ b/src/static/dolphin/os/OSMemory.c @@ -3,8 +3,6 @@ #include "dolphin/os/OSInterrupt.h" #include "dolphin/hw_regs.h" -extern OSErrorHandler __OSErrorTable[16]; - u32 OSGetConsoleSimulatedMemSize(void){ return(SIM_MEM); } From 06da04110e3a0d87da711c7d70961c340b4e2f16 Mon Sep 17 00:00:00 2001 From: SwareJonge <41187958+SwareJonge@users.noreply.github.com> Date: Tue, 17 Jun 2025 22:09:34 +0200 Subject: [PATCH 6/9] Match JUTException --- configure.py | 2 +- include/JSystem/JKernel/JKRArchive.h | 12 +- include/JSystem/JUtility/JUTException.h | 15 +- include/JSystem/JUtility/JUTGamePad.h | 2 +- include/MSL_C/MSL_Common/float.h | 92 +++++++ .../MSL_C/MSL_Common_Embedded/Math/fdlibm.h | 234 ++++++++++++++++++ include/MSL_C/w_math.h | 11 +- src/static/JSystem/JKernel/JKRArchivePri.cpp | 5 - src/static/JSystem/JUtility/JUTException.cpp | 184 +++++--------- 9 files changed, 409 insertions(+), 148 deletions(-) create mode 100644 include/MSL_C/MSL_Common/float.h create mode 100644 include/MSL_C/MSL_Common_Embedded/Math/fdlibm.h diff --git a/configure.py b/configure.py index 12caee21..030f185b 100644 --- a/configure.py +++ b/configure.py @@ -670,7 +670,7 @@ config.libs = [ Object(Matching, "JSystem/JUtility/JUTDbPrint.cpp"), Object(Matching, "JSystem/JUtility/JUTDirectFile.cpp"), Object(Matching, "JSystem/JUtility/JUTDirectPrint.cpp"), - Object(NonMatching, "JSystem/JUtility/JUTException.cpp"), + Object(Matching, "JSystem/JUtility/JUTException.cpp"), Object(Matching, "JSystem/JUtility/JUTFader.cpp"), Object(Matching, "JSystem/JUtility/JUTFont.cpp"), Object(Matching, "JSystem/JUtility/JUTFontData_Ascfont_fix12.s"), diff --git a/include/JSystem/JKernel/JKRArchive.h b/include/JSystem/JKernel/JKRArchive.h index ad5b8138..6b8e685e 100644 --- a/include/JSystem/JKernel/JKRArchive.h +++ b/include/JSystem/JKernel/JKRArchive.h @@ -128,8 +128,9 @@ public: }; JKRArchive(s32, EMountMode); - - virtual ~JKRArchive(); // _08 +private: + ~JKRArchive(); +public: // _08 virtual bool becomeCurrent(const char*); // _10 virtual void* getResource(const char* path); // _14 virtual void* getResource(u32 type, const char* name); // _18 @@ -161,12 +162,11 @@ public: static JKRArchive* mount(void*, JKRHeap*, EMountDirection); static JKRArchive* mount(s32, EMountMode, JKRHeap*, EMountDirection); static void* getGlbResource(u32 type, const char* name, JKRArchive* archive); - - // Unused/inlined: - JKRArchive(); - JKRArchive(const char* p1, EMountMode mountMode); static JKRArchive* check_mount_already(s32); static JKRArchive* check_mount_already(s32, JKRHeap*); + + JKRArchive(); + JKRArchive(const char* p1, EMountMode mountMode); SDIDirEntry* findResType(u32) const; SDIFileEntry* findTypeResource(u32, u32) const; diff --git a/include/JSystem/JUtility/JUTException.h b/include/JSystem/JUtility/JUTException.h index 46bc7932..93229ee2 100644 --- a/include/JSystem/JUtility/JUTException.h +++ b/include/JSystem/JUtility/JUTException.h @@ -17,11 +17,9 @@ enum ExPrintFlags { EXPRINTFLAG_GPR = 0x1, EXPRINTFLAG_GPRMap = 0x2, - EXPRINTFLAG_SRR0Map = 0x4, - EXPRINTFLAG_Float = 0x8, - EXPRINTFLAG_Stack = 0x10, - - EXPRINTFLAG_All = 0x1F, + EXPRINTFLAG_Float = 0x4, + EXPRINTFLAG_Stack = 0x8, + EXPRINTFLAG_All = 0xF, }; /** @@ -35,7 +33,7 @@ struct JUTException : public JKRThread INFOPAGE_Float = 2, INFOPAGE_Stack = 3, INFOPAGE_GPRMap = 4, - INFOPAGE_SRR0Map = 5, + }; // size: 0x14 @@ -102,7 +100,7 @@ struct JUTException : public JKRThread void showGPR(OSContext *); void showSRR0Map(OSContext *); bool isEnablePad() const; - u32 getFpscr(); + static u32 getFpscr(); void setFpscr(u32); void enableFpuException(); void disableFpuException(); @@ -129,7 +127,7 @@ struct JUTException : public JKRThread static JUTErrorHandler sPostUserCallback; static u32 msr; static u32 fpscr; - static const char *sCpuExpName[32]; + static const char *sCpuExpName[16]; static JSUList sMapFileList; // _00 = VTBL @@ -143,7 +141,6 @@ struct JUTException : public JKRThread u32 mTraceSuppress; // _94 u32 _98; // _98 u32 mPrintFlags; // _9C, see ExPrintFlags enum - u32 mStackPointer; // _A0 }; #endif \ No newline at end of file diff --git a/include/JSystem/JUtility/JUTGamePad.h b/include/JSystem/JUtility/JUTGamePad.h index 25310195..8540bd92 100644 --- a/include/JSystem/JUtility/JUTGamePad.h +++ b/include/JSystem/JUtility/JUTGamePad.h @@ -93,7 +93,7 @@ public: void clearForReset(); static void init(); void initList(); - void read(); + static void read(); static bool recalibrate(u32); void setButtonRepeat(u32, u32, u32); void update(); diff --git a/include/MSL_C/MSL_Common/float.h b/include/MSL_C/MSL_Common/float.h new file mode 100644 index 00000000..018d307a --- /dev/null +++ b/include/MSL_C/MSL_Common/float.h @@ -0,0 +1,92 @@ +#ifndef _MSL_COMMON_FLOAT_H +#define _MSL_COMMON_FLOAT_H + +#include "MSL_C/MSL_Common_Embedded/Math/fdlibm.h" + +#define FP_SNAN 0 +#define FP_QNAN 1 +#define FP_INFINITE 2 +#define FP_ZERO 3 +#define FP_NORMAL 4 +#define FP_SUBNORMAL 5 + +#define FP_NAN FP_QNAN + +#define fpclassify(x) \ + ((sizeof(x) == sizeof(float)) ? __fpclassifyf(x) : __fpclassifyd(x)) +#define signbit(x) \ + ((sizeof(x) == sizeof(float)) ? __signbitf(x) : __signbitd(x)) +#define isfinite(x) ((fpclassify(x) > 2)) +#define isnan(x) ((fpclassify(x) == FP_NAN)) +#define isinf(x) ((fpclassify(x) == FP_INFINITE)) + +#define __signbitf(x) ((int)(__HI(x) & 0x80000000)) + +// TODO: OK? +#define __signbitd(x) ((int)(__HI(x) & 0x80000000)) + +extern unsigned long __float_nan[]; +extern unsigned long __float_huge[]; +extern unsigned long __float_max[]; +extern unsigned long __float_epsilon[]; + +inline int __fpclassifyf(float __value) +{ + unsigned long integer = *(unsigned long*)&__value; + + switch (integer & 0x7f800000) { + case 0x7f800000: + if ((integer & 0x7fffff) != 0) { + return FP_QNAN; + } + return FP_INFINITE; + + case 0: + if ((integer & 0x7fffff) != 0) { + return FP_SUBNORMAL; + } + return FP_ZERO; + } + + return FP_NORMAL; +} + +inline int __fpclassifyd(double __value) +{ + switch (__HI(__value) & 0x7ff00000) { + case 0x7ff00000: { + if ((__HI(__value) & 0x000fffff) || (__LO(__value) & 0xffffffff)) + return FP_QNAN; + else + return FP_INFINITE; + break; + } + case 0: { + if ((__HI(__value) & 0x000fffff) || (__LO(__value) & 0xffffffff)) + return FP_SUBNORMAL; + else + return FP_ZERO; + break; + } + } + return FP_NORMAL; +} + +#define FLT_MANT_DIG 24 +#define FLT_DIG 6 +#define FLT_MIN_EXP (-125) +#define FLT_MIN_10_EXP (-37) +#define FLT_MAX_EXP 128 +#define FLT_MAX_10_EXP 38 + +//#define FLT_MAX 3.40282346638528860e+38f +#define FLT_EPSILON 1.1920928955078125e-07f + +#define DBL_MANT_DIG 53 +#define DBL_DIG 15 +#define DBL_MIN_EXP (-1021) +#define DBL_MIN_10_EXP (-308) +#define DBL_MAX_EXP 1024 +#define DBL_MAX_10_EXP 308 + +#endif /* _MSL_COMMON_FLOAT_H */ \ No newline at end of file diff --git a/include/MSL_C/MSL_Common_Embedded/Math/fdlibm.h b/include/MSL_C/MSL_Common_Embedded/Math/fdlibm.h new file mode 100644 index 00000000..857a606b --- /dev/null +++ b/include/MSL_C/MSL_Common_Embedded/Math/fdlibm.h @@ -0,0 +1,234 @@ +#ifndef _FDLIBM_H +#define _FDLIBM_H + +/* @(#)fdlibm.h 1.5 04/04/22 */ +/** + * ==================================================== + * Copyright (C) 2004 by Sun Microsystems, Inc. All rights reserved. + * + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +#ifdef __cplusplus +extern "C" { +#endif // ifdef __cplusplus + +/* Sometimes it's necessary to define __LITTLE_ENDIAN explicitly + but these catch some common cases. */ + +#if defined(i386) || defined(i486) || defined(intel) || defined(x86) \ + || defined(i86pc) || defined(__alpha) || defined(__osf__) +#define __LITTLE_ENDIAN +#endif + +#ifdef __LITTLE_ENDIAN +#define __HI(x) *(1 + (int*)&x) +#define __LO(x) *(int*)&x +#define __HIp(x) *(1 + (int*)x) +#define __LOp(x) *(int*)x +#else +#define __HI(x) *(int*)&x +#define __LO(x) *(1 + (int*)&x) +#define __HIp(x) *(int*)x +#define __LOp(x) *(1 + (int*)x) +#endif + +// NOTE: should be enabled according to w_atan2.c +#define _IEEE_LIBM + +// TODO: should __STDC__ actually be defined? +// #ifdef __STDC__ +#define __P(p) p +// #else +// #define __P(p) () +// #endif + +/** + * ANSI/POSIX + */ + +extern int signgam; + +#define MAXFLOAT ((f32)3.40282346638528860e+38) + +enum fdversion { fdlibm_ieee = -1, fdlibm_svid, fdlibm_xopen, fdlibm_posix }; + +#define _LIB_VERSION_TYPE enum fdversion +#define _LIB_VERSION _fdlib_version + +/* if global variable _LIB_VERSION is not desirable, one may + * change the following to be a constant by: + * #define _LIB_VERSION_TYPE const enum version + * In that case, after one initializes the value _LIB_VERSION (see + * s_lib_version.c) during compile time, it cannot be modified + * in the middle of a program + */ +extern _LIB_VERSION_TYPE _LIB_VERSION; + +#define _IEEE_ fdlibm_ieee +#define _SVID_ fdlibm_svid +#define _XOPEN_ fdlibm_xopen +#define _POSIX_ fdlibm_posix + +struct exception { + int type; + char* name; + double arg1; + double arg2; + double retval; +}; + +#define HUGE MAXFLOAT + +/** + * set X_TLOSS = pi*2**52, which is possibly defined in + * (one may replace the following line by "#include ") + */ + +#define X_TLOSS 1.41484755040568800000e+16 + +#define DOMAIN 1 +#define SING 2 +#define OVERFLOW 3 +#define UNDERFLOW 4 +#define TLOSS 5 +#define PLOSS 6 + +/** + * ANSI/POSIX + */ +extern double acos __P((double)); +extern double asin __P((double)); +extern double atan __P((double)); +extern double atan2 __P((double, double)); +extern double cos __P((double)); +extern double sin __P((double)); +extern double tan __P((double)); + +extern double cosh __P((double)); +extern double sinh __P((double)); +extern double tanh __P((double)); + +extern double exp __P((double)); +extern double frexp __P((double, int*)); +extern double ldexp __P((double, int)); +extern double scalbn __P((double, int)); +extern double log __P((double)); +extern double log10 __P((double)); +extern double modf __P((double, double*)); + +extern double pow __P((double, double)); +extern double sqrt __P((double)); + +extern double ceil __P((double)); +extern double fabs __P((double)); +// NOTE: I have no idea how they got it to mangle like this +extern double fabs__Fd(double); +extern double floor __P((double)); +extern double fmod __P((double, double)); + +extern double erf __P((double)); +extern double erfc __P((double)); +extern double gamma __P((double)); +extern double hypot __P((double, double)); +extern int isnan __P((double)); +extern int finite __P((double)); +extern double j0 __P((double)); +extern double j1 __P((double)); +extern double jn __P((int, double)); +extern double lgamma __P((double)); +extern double y0 __P((double)); +extern double y1 __P((double)); +extern double yn __P((int, double)); + +extern double acosh __P((double)); +extern double asinh __P((double)); +extern double atanh __P((double)); +extern double cbrt __P((double)); +extern double logb __P((double)); +extern double nextafter __P((double, double)); +extern double remainder __P((double, double)); +#ifdef _SCALB_INT +extern double scalb __P((double, int)); +#else +extern double scalb __P((double, double)); +#endif + +extern int matherr __P((struct exception*)); + +/** + * IEEE Test Vector + */ +extern double significand __P((double)); + +/** + * Functions callable from C, intended to support IEEE arithmetic. + */ +extern double copysign __P((double, double)); +extern int ilogb __P((double)); +extern double rint __P((double)); +extern double scalbn __P((double, int)); + +/** + * BSD math library entry points + */ +extern double expm1 __P((double)); +extern double log1p __P((double)); + +/** + * Reentrant version of gamma & lgamma; passes signgam back by reference + * as the second argument; user must allocate space for signgam. + */ +#ifdef _REENTRANT +extern double gamma_r __P((double, int*)); +extern double lgamma_r __P((double, int*)); +#endif /* _REENTRANT */ + +/* ieee style elementary functions */ +extern double __ieee754_sqrt __P((double)); +extern double __ieee754_acos __P((double)); +extern double __ieee754_acosh __P((double)); +extern double __ieee754_log __P((double)); +extern double __ieee754_atanh __P((double)); +extern double __ieee754_asin __P((double)); +extern double __ieee754_atan2 __P((double, double)); +extern double __ieee754_exp __P((double)); +extern double __ieee754_cosh __P((double)); +extern double __ieee754_fmod __P((double, double)); +extern double __ieee754_pow __P((double, double)); +extern double __ieee754_lgamma_r __P((double, int*)); +extern double __ieee754_gamma_r __P((double, int*)); +extern double __ieee754_lgamma __P((double)); +extern double __ieee754_gamma __P((double)); +extern double __ieee754_log10 __P((double)); +extern double __ieee754_sinh __P((double)); +extern double __ieee754_hypot __P((double, double)); +extern double __ieee754_j0 __P((double)); +extern double __ieee754_j1 __P((double)); +extern double __ieee754_y0 __P((double)); +extern double __ieee754_y1 __P((double)); +extern double __ieee754_jn __P((int, double)); +extern double __ieee754_yn __P((int, double)); +extern double __ieee754_remainder __P((double, double)); +extern int __ieee754_rem_pio2 __P((double, double*)); +#ifdef _SCALB_INT +extern double __ieee754_scalb __P((double, int)); +#else +extern double __ieee754_scalb __P((double, double)); +#endif + +/* fdlibm kernel function */ +extern double __kernel_standard __P((double, double, int)); +extern double __kernel_sin __P((double, double, int)); +extern double __kernel_cos __P((double, double)); +extern double __kernel_tan __P((double, double, int)); +extern int __kernel_rem_pio2 __P((double*, double*, int, int, int, const int*)); + +#ifdef __cplusplus +}; +#endif // ifdef __cplusplus + +#endif \ No newline at end of file diff --git a/include/MSL_C/w_math.h b/include/MSL_C/w_math.h index 270273ee..17fc0f20 100644 --- a/include/MSL_C/w_math.h +++ b/include/MSL_C/w_math.h @@ -1,6 +1,8 @@ #ifndef W_MATH_H #define W_MATH_H +#include "MSL_C/MSL_Common/float.h" + #ifndef BUGFIXES #define SQRTF_LINKAGE extern #else @@ -47,11 +49,6 @@ inline float fabsf(float x) { return (float)fabs((double)x); } -int __float_huge[]; -int __float_nan[]; -int __double_huge[]; -int __extended_huge[]; - #define INFINITY (*(float*)__float_huge) #define NAN (*(float*)__float_nan) #define HUGE_VALF (*(float*)__float_huge) @@ -76,8 +73,8 @@ extern inline double sqrt(double x) { extern "C" { #endif -double atan2(double, double); -double acos(float); +//double atan2(double, double); +//double acos(float); #ifdef __cplusplus } diff --git a/src/static/JSystem/JKernel/JKRArchivePri.cpp b/src/static/JSystem/JKernel/JKRArchivePri.cpp index f9265507..e695b4eb 100644 --- a/src/static/JSystem/JKernel/JKRArchivePri.cpp +++ b/src/static/JSystem/JKernel/JKRArchivePri.cpp @@ -33,11 +33,6 @@ JKRArchive::JKRArchive(s32 entryNum, JKRArchive::EMountMode mountMode) } } -JKRArchive::JKRArchive(const char* p1, JKRArchive::EMountMode mountMode) -{ - // UNUSED FUNCTION -} - JKRArchive::~JKRArchive() {} bool JKRArchive::isSameName(JKRArchive::CArcName& archiveName, diff --git a/src/static/JSystem/JUtility/JUTException.cpp b/src/static/JSystem/JUtility/JUTException.cpp index 48bce331..a03ea119 100644 --- a/src/static/JSystem/JUtility/JUTException.cpp +++ b/src/static/JSystem/JUtility/JUTException.cpp @@ -1,7 +1,9 @@ +#include "MSL_C/MSL_Common/float.h" + #include #include #include -#include "MSL_C/w_math.h" + #include "MSL_C/printf.h" #include "libc/string.h" @@ -9,25 +11,19 @@ #include "JSystem/JUtility/JUTDirectPrint.h" #include "JSystem/JUtility/JUTDirectFile.h" -extern long __fpclassifyf(float x); -long __fpclassifyd(double x); -#define fpclassify(x) (sizeof(x) == sizeof(float) ? __fpclassifyf((float)(x)) : __fpclassifyd((double)(x))) - -#define isinf(x) ((fpclassify(x) == 2)) -#define isnan(x) ((fpclassify(x) == 1)) -#define isfinite(x) ((fpclassify(x) > 2)) struct CallbackObject { JUTErrorHandler callback; u16 error; - OSContext *context; + OSContext* context; u32 dsisr; u32 dar; }; void search_name_part(u8 *, u8 *, int); +void *JUTException::sMessageBuffer[1] = { nullptr}; OSMessageQueue JUTException::sMessageQueue = {}; static OSTime c3bcnt[4] = {0, 0, 0, 0}; const char *JUTException::sCpuExpName[] = { @@ -46,8 +42,7 @@ const char *JUTException::sCpuExpName[] = { "BREAK POINT", "SYSTEM INTERRUPT", "THERMAL INTERRUPT", - "PROTECTION", - "FLOATING POINT" + "PROTECTION" }; JUTException *JUTException::sErrorManager; @@ -59,31 +54,10 @@ u32 JUTException::sConsoleBufferSize; JUTConsole *JUTException::sConsole; u32 JUTException::msr; u32 JUTException::fpscr; -void *JUTException::sMessageBuffer[1] = { nullptr}; + JSUList JUTException::sMapFileList(false); -JUTException::JUTException(JUTDirectPrint *directPrint) :JKRThread(0x4000, 0x10, 0) { - mDirectPrint = directPrint; - - OSSetErrorHandler(OS_ERROR_DSI, (OSErrorHandler)errorHandler); - OSSetErrorHandler(OS_ERROR_ISI, (OSErrorHandler)errorHandler); - OSSetErrorHandler(OS_ERROR_PROGRAM, (OSErrorHandler)errorHandler); - OSSetErrorHandler(OS_ERROR_ALIGNMENT, (OSErrorHandler)errorHandler); - OSSetErrorHandler(OS_ERROR_PROTECTION, (OSErrorHandler)errorHandler); - setFPException(0); - - sPreUserCallback = nullptr; - sPostUserCallback = nullptr; - mGamePad = nullptr; - mPadPort = JUTGamePad::Port_Invalid; - mPrintWaitTime0 = 10; - mPrintWaitTime1 = 10; - mTraceSuppress = 0xffffffff; - _98 = 0; - mPrintFlags = EXPRINTFLAG_All; -} - JUTException *JUTException::create(JUTDirectPrint *directPrint) { if(sErrorManager == nullptr) { sErrorManager = new (JKRGetSystemHeap(), 0) JUTException(directPrint); @@ -107,11 +81,8 @@ void *JUTException::run() u32 dsisr = cb->dsisr; u32 dar = cb->dar; - if (error < OS_ERROR_MAX) - mStackPointer = context->gpr[1]; - - - if (mFrameMemory == nullptr) + mFrameMemory = (JUTExternalFB*)sErrorManager->mDirectPrint->getFrameBuffer(); + if (!sErrorManager->mDirectPrint->getFrameBuffer()) sErrorManager->createFB(); if (callback) @@ -123,10 +94,30 @@ void *JUTException::run() } } +JUTException::JUTException(JUTDirectPrint *directPrint) : JKRThread(0x4000, 0x10, 0) { + mDirectPrint = directPrint; + + OSSetErrorHandler(OS_ERROR_DSI, (OSErrorHandler)errorHandler); + OSSetErrorHandler(OS_ERROR_ISI, (OSErrorHandler)errorHandler); + OSSetErrorHandler(OS_ERROR_PROGRAM, (OSErrorHandler)errorHandler); + OSSetErrorHandler(OS_ERROR_ALIGNMENT, (OSErrorHandler)errorHandler); + OSSetErrorHandler(OS_ERROR_PROTECTION, (OSErrorHandler)errorHandler); + + sPreUserCallback = nullptr; + sPostUserCallback = nullptr; + mGamePad = nullptr; + mPadPort = JUTGamePad::Port_Invalid; + mPrintWaitTime0 = 10; + mPrintWaitTime1 = 10; + mTraceSuppress = 0xffffffff; + _98 = 0; + mPrintFlags = 0xff; +} + void JUTException::errorHandler(OSError error, OSContext *context, u32 dsisr, u32 dar) { msr = PPCMfmsr(); - fpscr = context->fpscr; + fpscr = getFpscr(); OSFillFPUContext(context); OSSetErrorHandler(error, nullptr); if (error == OS_ERROR_PROTECTION) @@ -148,19 +139,6 @@ void JUTException::errorHandler(OSError error, OSContext *context, u32 dsisr, u3 OSYieldThread(); } -void JUTException::setFPException(u32 fpscr_enable_bits) -{ - __OSFpscrEnableBits = fpscr_enable_bits; - if (fpscr_enable_bits) - { - OSSetErrorHandler(OS_ERROR_FPE, (OSErrorHandler)errorHandler); - } - else - { - OSSetErrorHandler(OS_ERROR_FPE, nullptr); - } -} - void JUTException::showFloatSub(int index, f32 value) { if (isnan(value)) @@ -280,25 +258,26 @@ void JUTException::showStack(OSContext *context) } u32 i; - + u32* stackPointer; sConsole->print("-------------------------------- TRACE\n"); - u32 *stackPointer = (u32 *)mStackPointer; sConsole->print_f("Address: BackChain LR save\n"); - for (i = 0; (stackPointer != nullptr) && (stackPointer != (u32 *)0xFFFFFFFF) && (i++ < 0x10);) - { - if (i > mTraceSuppress) - { - sConsole->print("Suppress trace.\n"); - return; - } + for (i = 0, stackPointer = (u32*)context->gpr[1]; + (stackPointer != nullptr) && (stackPointer != (u32*)0xFFFFFFFF) + && (i++ < 0x10);) { + if (i > mTraceSuppress) { + sConsole->print("Suppress trace.\n"); + return; + } - sConsole->print_f("%08X: %08X %08X\n", stackPointer, stackPointer[0], stackPointer[1]); - showMapInfo_subroutine(stackPointer[1], false); - JUTConsoleManager::getManager()->drawDirect(true); - waitTime(mPrintWaitTime1); - stackPointer = (u32 *)stackPointer[0]; - } + sConsole->print_f("%08X: %08X %08X\n", stackPointer, + stackPointer[0], stackPointer[1]); + showMapInfo_subroutine(stackPointer[1], false); + JUTConsoleManager* manager = JUTConsoleManager::sManager; + manager->drawDirect(true); + waitTime(mPrintWaitTime1); + stackPointer = (u32*)stackPointer[0]; + } } void JUTException::showMainInfo(u16 error, OSContext *context, u32 dsisr, u32 dar) @@ -420,26 +399,6 @@ void JUTException::showGPRMap(OSContext *context) } } -void JUTException::showSRR0Map(OSContext *context) -{ - if (!sConsole) - { - return; - } - - sConsole->print("-------------------------------- SRR0MAP\n"); - u32 address = context->srr0; - if (address >= 0x80000000 && 0x83000000 - 1 >= address) - { - sConsole->print_f("SRR0: %08XH", address); - if (showMapInfo_subroutine(address, true) == false) - { - sConsole->print(" no information\n"); - } - JUTConsoleManager::getManager()->drawDirect(true); - } -} - void JUTException::printDebugInfo(JUTException::EInfoPage page, OSError error, OSContext *context, u32 param_3, u32 param_4) { switch (page) @@ -457,8 +416,6 @@ void JUTException::printDebugInfo(JUTException::EInfoPage page, OSError error, O return showStack(context); case INFOPAGE_GPRMap: return showGPRMap(context); - case INFOPAGE_SRR0Map: - return showSRR0Map(context); } } @@ -494,7 +451,7 @@ bool JUTException::readPad(u32 *out_trigger, u32 *out_button) JUTGamePad gamePad1(JUTGamePad::Port2); JUTGamePad gamePad2(JUTGamePad::Port3); JUTGamePad gamePad3(JUTGamePad::Port4); - //JUTGamePad::read(); + JUTGamePad::read(); c3bcnt[0] = (gamePad0.isPushing3ButtonReset() ? (c3bcnt[0] != 0 ? c3bcnt[0] : OSGetTime()) : 0); @@ -538,7 +495,7 @@ bool JUTException::readPad(u32 *out_trigger, u32 *out_button) OSTime resetTime = (gamePadTime != 0) ? (OSGetTime() - gamePadTime) : 0; gamePad.checkResetCallback(resetTime); - //JUTGamePad::read(); + JUTGamePad::read(); if (out_trigger) { *out_trigger = gamePad.getTrigger(); @@ -552,7 +509,7 @@ bool JUTException::readPad(u32 *out_trigger, u32 *out_button) } else if (mGamePad) { - //JUTGamePad::read(); + JUTGamePad::read(); if (out_trigger) { *out_trigger = mGamePad->getTrigger(); @@ -575,20 +532,14 @@ void JUTException::printContext(OSError error, OSContext *context, u32 dsisr, u3 { return; } - VISetPreRetraceCallback(nullptr); - VISetPostRetraceCallback(nullptr); - VISetBlack(FALSE); - VIFlush(); if (!sConsole) { return; } - if(error < OS_ERROR_MAX) - sConsole->print_f("******** EXCEPTION OCCURRED! ********\nFrameMemory:%XH\n", getFrameMemory()); - else - sConsole->print_f("******** USER HALT ********\nFrameMemory:%XH\n", getFrameMemory()); + sConsole->print_f("******** EXCEPTION OCCURRED! ********\nFrameMemory:%XH\n", + getFrameMemory()); int post_callback_executed = false; while (true) @@ -604,12 +555,6 @@ void JUTException::printContext(OSError error, OSContext *context, u32 dsisr, u3 JUTConsoleManager::sManager->drawDirect(true); waitTime(mPrintWaitTime0); } - if ((mPrintFlags & EXPRINTFLAG_SRR0Map) != 0) - { - printDebugInfo(INFOPAGE_SRR0Map, error, context, dsisr, dar); - JUTConsoleManager::sManager->drawDirect(true); - waitTime(mPrintWaitTime0); - } if ((mPrintFlags & EXPRINTFLAG_GPRMap) != 0) { printDebugInfo(INFOPAGE_GPRMap, error, context, dsisr, dar); @@ -786,19 +731,20 @@ void JUTException::createFB() mFrameMemory = (JUTExternalFB *)object; } -u32 JUTException::getFpscr() { - // TODO: misses stack frame - register u32 ret; - asm { - mfmsr r5 - ori r5, r5, 0x2000 - mtmsr r5 - isync - mffs f1 - stfd f1, 8(r1) - lwz ret, 12(r1) - } - return ret; +asm u32 JUTException::getFpscr() { // TODO: figure out if this is possible with asm + + // clang-format off + fralloc + mfmsr r5 + ori r5, r5, 0x2000 + mtmsr r5 + isync + mffs f1 + stfd f1, 8(r1) + lwz r3, 12(r1) + frfree + blr + // clang-format on } JUTErrorHandler JUTException::setPreUserCallback(JUTErrorHandler callback) From c5e5f478809e35def2814894ca69e19a3099cb9a Mon Sep 17 00:00:00 2001 From: SwareJonge <41187958+SwareJonge@users.noreply.github.com> Date: Tue, 17 Jun 2025 23:03:25 +0200 Subject: [PATCH 7/9] Fix JKRArchive --- configure.py | 4 ++-- include/JSystem/JKernel/JKRArchive.h | 12 ++++++------ include/JSystem/JUtility/JUTException.h | 2 +- include/libc/ctype.h | 8 ++++++++ src/static/JSystem/JUtility/JUTException.cpp | 2 +- 5 files changed, 18 insertions(+), 10 deletions(-) diff --git a/configure.py b/configure.py index 030f185b..a76bfba2 100644 --- a/configure.py +++ b/configure.py @@ -637,8 +637,8 @@ config.libs = [ Object(Matching, "JSystem/JKernel/JKRAramHeap.cpp"), Object(Matching, "JSystem/JKernel/JKRAramPiece.cpp"), Object(Matching, "JSystem/JKernel/JKRAramStream.cpp"), - Object(NonMatching, "JSystem/JKernel/JKRArchivePri.cpp"), - Object(NonMatching, "JSystem/JKernel/JKRArchivePub.cpp"), + Object(Matching, "JSystem/JKernel/JKRArchivePri.cpp"), + Object(Matching, "JSystem/JKernel/JKRArchivePub.cpp"), Object(Matching, "JSystem/JKernel/JKRCompArchive.cpp"), Object(Matching, "JSystem/JKernel/JKRDecomp.cpp"), Object(Matching, "JSystem/JKernel/JKRDisposer.cpp"), diff --git a/include/JSystem/JKernel/JKRArchive.h b/include/JSystem/JKernel/JKRArchive.h index 6b8e685e..752078f7 100644 --- a/include/JSystem/JKernel/JKRArchive.h +++ b/include/JSystem/JKernel/JKRArchive.h @@ -127,10 +127,7 @@ public: u32 _1C; // _1C }; - JKRArchive(s32, EMountMode); -private: - ~JKRArchive(); -public: // _08 +public: virtual bool becomeCurrent(const char*); // _10 virtual void* getResource(const char* path); // _14 virtual void* getResource(u32 type, const char* name); // _18 @@ -145,6 +142,11 @@ public: virtual void* fetchResource(SDIFileEntry* entry, u32* outSize) = 0; // _40 virtual void* fetchResource(void* resourceBuffer, u32 bufferSize, SDIFileEntry* entry, u32* resSize, JKRExpandSwitch expandSwitch) = 0; // _44 + JKRArchive(s32, EMountMode); + JKRArchive(); + JKRArchive(const char* p1, EMountMode mountMode); + ~JKRArchive(); + SDIDirEntry* findDirectory(const char*, u32) const; SDIFileEntry* findFsResource(const char*, u32) const; SDIFileEntry* findIdResource(u16) const; @@ -165,8 +167,6 @@ public: static JKRArchive* check_mount_already(s32); static JKRArchive* check_mount_already(s32, JKRHeap*); - JKRArchive(); - JKRArchive(const char* p1, EMountMode mountMode); SDIDirEntry* findResType(u32) const; SDIFileEntry* findTypeResource(u32, u32) const; diff --git a/include/JSystem/JUtility/JUTException.h b/include/JSystem/JUtility/JUTException.h index 93229ee2..14514ea4 100644 --- a/include/JSystem/JUtility/JUTException.h +++ b/include/JSystem/JUtility/JUTException.h @@ -19,7 +19,7 @@ enum ExPrintFlags EXPRINTFLAG_GPRMap = 0x2, EXPRINTFLAG_Float = 0x4, EXPRINTFLAG_Stack = 0x8, - EXPRINTFLAG_All = 0xF, + EXPRINTFLAG_All = 0xFF, }; /** diff --git a/include/libc/ctype.h b/include/libc/ctype.h index 9731e067..e9689a2f 100644 --- a/include/libc/ctype.h +++ b/include/libc/ctype.h @@ -1,6 +1,14 @@ #ifndef _DOLPHIN_LIBC_CTYPE_H_ #define _DOLPHIN_LIBC_CTYPE_H_ +#ifdef __cplusplus +extern "C" { +#endif + int tolower(int c); +#ifdef __cplusplus +} +#endif + #endif // _DOLPHIN_LIBC_CTYPE_H_ diff --git a/src/static/JSystem/JUtility/JUTException.cpp b/src/static/JSystem/JUtility/JUTException.cpp index a03ea119..c3b04d85 100644 --- a/src/static/JSystem/JUtility/JUTException.cpp +++ b/src/static/JSystem/JUtility/JUTException.cpp @@ -111,7 +111,7 @@ JUTException::JUTException(JUTDirectPrint *directPrint) : JKRThread(0x4000, 0x10 mPrintWaitTime1 = 10; mTraceSuppress = 0xffffffff; _98 = 0; - mPrintFlags = 0xff; + mPrintFlags = EXPRINTFLAG_All; } void JUTException::errorHandler(OSError error, OSContext *context, u32 dsisr, u32 dar) From c545a42c15693d4452d6ae6feab2c8687f9e64a1 Mon Sep 17 00:00:00 2001 From: SwareJonge <41187958+SwareJonge@users.noreply.github.com> Date: Tue, 17 Jun 2025 23:46:35 +0200 Subject: [PATCH 8/9] clean up and format code --- include/JSystem/J2D/J2DGXColorS10.h | 33 +- include/JSystem/J2D/J2DGrafContext.h | 181 +++-- include/JSystem/J2D/J2DIndBlock.h | 126 +-- include/JSystem/J2D/J2DTypes.h | 181 +++-- include/JSystem/J3D/J3DTypes.h | 46 +- include/JSystem/JFramework/JFWDisplay.h | 106 +-- include/JSystem/JFramework/JFWSystem.h | 53 +- include/JSystem/JGadget/define.h | 35 +- include/JSystem/JGadget/linklist.h | 8 - include/JSystem/JGeometry.h | 444 ++++++----- include/JSystem/JKernel/JKRAram.h | 435 +++++----- include/JSystem/JKernel/JKRArchive.h | 253 +++--- include/JSystem/JKernel/JKRDecomp.h | 104 ++- include/JSystem/JKernel/JKRDisposer.h | 8 +- include/JSystem/JKernel/JKRDvdAramRipper.h | 21 +- include/JSystem/JKernel/JKRDvdFile.h | 109 +-- include/JSystem/JKernel/JKRDvdRipper.h | 51 +- include/JSystem/JKernel/JKREnum.h | 9 +- include/JSystem/JKernel/JKRExpHeap.h | 108 ++- include/JSystem/JKernel/JKRFile.h | 32 +- include/JSystem/JKernel/JKRFileFinder.h | 36 +- include/JSystem/JKernel/JKRFileLoader.h | 54 +- include/JSystem/JKernel/JKRHeap.h | 194 ++--- include/JSystem/JKernel/JKRMacro.h | 6 +- include/JSystem/JKernel/JKRThread.h | 257 +++--- include/JSystem/JMacro.h | 2 +- include/JSystem/JSupport.h | 10 +- include/JSystem/JSupport/JSUFileInputStream.h | 34 +- include/JSystem/JSupport/JSUInputStream.h | 196 ++--- include/JSystem/JSupport/JSUIosBase.h | 22 +- include/JSystem/JSupport/JSUList.h | 309 +++++--- .../JSystem/JSupport/JSURandomInputStream.h | 48 +- include/JSystem/JSupport/JSUStreamEnum.h | 11 +- include/JSystem/JUtility/JUTAssertion.h | 48 +- include/JSystem/JUtility/JUTConsole.h | 162 ++-- include/JSystem/JUtility/JUTDbPrint.h | 54 +- include/JSystem/JUtility/JUTDirectFile.h | 13 +- include/JSystem/JUtility/JUTDirectPrint.h | 56 +- include/JSystem/JUtility/JUTEnum.h | 40 +- include/JSystem/JUtility/JUTException.h | 116 +-- include/JSystem/JUtility/JUTFader.h | 24 +- include/JSystem/JUtility/JUTFont.h | 319 ++++---- include/JSystem/JUtility/JUTGamePad.h | 140 ++-- include/JSystem/JUtility/JUTGraphFifo.h | 21 +- include/JSystem/JUtility/JUTProcBar.h | 142 ++-- include/JSystem/JUtility/JUTVideo.h | 55 +- include/JSystem/JUtility/JUTXfb.h | 82 +- include/JSystem/JUtility/TColor.h | 87 +- include/JSystem/ResTIMG.h | 71 +- .../JSystem/J2DGraph/J2DGrafContext.cpp | 78 +- src/static/JSystem/J2DGraph/J2DOrthoGraph.cpp | 43 +- src/static/JSystem/JFramework/JFWDisplay.cpp | 190 ++--- src/static/JSystem/JFramework/JFWSystem.cpp | 45 +- src/static/JSystem/JGadget/linklist.cpp | 16 +- src/static/JSystem/JKernel/JKRAram.cpp | 742 +++++++++--------- src/static/JSystem/JKernel/JKRAramArchive.cpp | 475 ++++++----- src/static/JSystem/JKernel/JKRAramBlock.cpp | 54 +- src/static/JSystem/JKernel/JKRAramHeap.cpp | 201 +++-- src/static/JSystem/JKernel/JKRAramPiece.cpp | 198 +++-- src/static/JSystem/JKernel/JKRAramStream.cpp | 286 ++++--- src/static/JSystem/JKernel/JKRArchivePri.cpp | 138 ++-- src/static/JSystem/JKernel/JKRArchivePub.cpp | 482 ++++++------ src/static/JSystem/JKernel/JKRCompArchive.cpp | 540 ++++++------- src/static/JSystem/JKernel/JKRDecomp.cpp | 421 +++++----- src/static/JSystem/JKernel/JKRDisposer.cpp | 14 +- .../JSystem/JKernel/JKRDvdAramRipper.cpp | 566 ++++++------- src/static/JSystem/JKernel/JKRDvdArchive.cpp | 314 +++----- src/static/JSystem/JKernel/JKRDvdFile.cpp | 142 ++-- src/static/JSystem/JKernel/JKRDvdRipper.cpp | 715 ++++++++--------- src/static/JSystem/JKernel/JKRExpHeap.cpp | 557 +++++-------- src/static/JSystem/JKernel/JKRFile.cpp | 18 +- src/static/JSystem/JKernel/JKRFileFinder.cpp | 24 +- src/static/JSystem/JKernel/JKRFileLoader.cpp | 76 +- src/static/JSystem/JKernel/JKRHeap.cpp | 269 +++---- src/static/JSystem/JKernel/JKRMemArchive.cpp | 156 ++-- src/static/JSystem/JKernel/JKRThread.cpp | 145 ++-- src/static/JSystem/JSupport/JSUFileStream.cpp | 72 +- .../JSystem/JSupport/JSUInputStream.cpp | 150 ++-- src/static/JSystem/JSupport/JSUList.cpp | 40 +- src/static/JSystem/JUtility/JUTAssert.cpp | 105 ++- src/static/JSystem/JUtility/JUTConsole.cpp | 350 +++------ src/static/JSystem/JUtility/JUTDbPrint.cpp | 89 +-- src/static/JSystem/JUtility/JUTDirectFile.cpp | 91 +-- .../JSystem/JUtility/JUTDirectPrint.cpp | 114 ++- src/static/JSystem/JUtility/JUTException.cpp | 591 ++++++-------- src/static/JSystem/JUtility/JUTFader.cpp | 97 +-- src/static/JSystem/JUtility/JUTFont.cpp | 23 +- src/static/JSystem/JUtility/JUTGamePad.cpp | 669 ++++++++-------- src/static/JSystem/JUtility/JUTGraphFifo.cpp | 27 +- src/static/JSystem/JUtility/JUTProcBar.cpp | 142 ++-- src/static/JSystem/JUtility/JUTResFont.cpp | 329 ++++---- src/static/JSystem/JUtility/JUTVideo.cpp | 135 ++-- src/static/JSystem/JUtility/JUTXfb.cpp | 61 +- 93 files changed, 7033 insertions(+), 7909 deletions(-) diff --git a/include/JSystem/J2D/J2DGXColorS10.h b/include/JSystem/J2D/J2DGXColorS10.h index 58992784..f88297e8 100644 --- a/include/JSystem/J2D/J2DGXColorS10.h +++ b/include/JSystem/J2D/J2DGXColorS10.h @@ -10,40 +10,45 @@ * Everything is fabricated here except for the default ctor. * Copied from J3DGXColorS10. */ -struct J2DGXColorS10 : public GXColorS10 -{ - J2DGXColorS10() {} +struct J2DGXColorS10 : public GXColorS10 { + J2DGXColorS10() { + } - J2DGXColorS10(u16 _r, u16 _g, u16 _b, u16 _a) - { + J2DGXColorS10(u16 _r, u16 _g, u16 _b, u16 _a) { r = _r; g = _g; b = _b; a = _a; } - J2DGXColorS10(const J2DGXColorS10 &other) - { + J2DGXColorS10(const J2DGXColorS10& other) { r = other.r; g = other.g; b = other.b; a = other.a; } - J2DGXColorS10(const u64 &other) - { - GXColorS10 *otherBytes = (GXColorS10 *)&other; + J2DGXColorS10(const u64& other) { + GXColorS10* otherBytes = (GXColorS10*)&other; r = otherBytes->r; g = otherBytes->g; b = otherBytes->b; a = otherBytes->a; } - inline operator u64() const { return toUInt64(); } - inline u32 toUInt64() const { return *(u64 *)&r; } + inline operator u64() const { + return toUInt64(); + } + inline u32 toUInt64() const { + return *(u64*)&r; + } - inline operator JUtility::TColor() const { return toTColor(); } - inline JUtility::TColor toTColor() const { return JUtility::TColor(r, g, b, a); } + inline operator JUtility::TColor() const { + return toTColor(); + } + inline JUtility::TColor toTColor() const { + return JUtility::TColor(r, g, b, a); + } }; #endif diff --git a/include/JSystem/J2D/J2DGrafContext.h b/include/JSystem/J2D/J2DGrafContext.h index 563b2194..c165338b 100644 --- a/include/JSystem/J2D/J2DGrafContext.h +++ b/include/JSystem/J2D/J2DGrafContext.h @@ -11,115 +11,136 @@ * @fabricated */ enum J2DGrafType { - J2DGraf_Base = 0, - J2DGraf_Ortho = 1, - J2DGraf_Persp = 2, + J2DGraf_Base = 0, + J2DGraf_Ortho = 1, + J2DGraf_Persp = 2, }; struct J2DGrafBlend { - u8 mType; // _00 - u8 mSrcFactor; // _01 - u8 mDestFactor; // _02 + u8 mType; // _00 + u8 mSrcFactor; // _01 + u8 mDestFactor; // _02 }; #ifdef __cplusplus struct J2DGrafContext { - J2DGrafContext(f32, f32, f32, f32); + J2DGrafContext(f32, f32, f32, f32); - virtual ~J2DGrafContext() { } // _08 (weak) - virtual void place(const JGeometry::TBox2f&); // _0C - virtual void place(f32 x, f32 y, f32 width, f32 height) - { - JGeometry::TBox2f box(x, y, x + width, y + height); - place(box); - } // _10 (weak) - virtual void setPort(); // _14 - virtual void setup2D(); // _18 - virtual void setScissor(); // _1C - virtual J2DGrafType getGrafType() const { return J2DGraf_Base; } // _20 (weak) - virtual void setLookat() { } // _24 (weak) + virtual ~J2DGrafContext() { + } // _08 (weak) + virtual void place(const JGeometry::TBox2f&); // _0C + virtual void place(f32 x, f32 y, f32 width, f32 height) { + JGeometry::TBox2f box(x, y, x + width, y + height); + place(box); + } // _10 (weak) + virtual void setPort(); // _14 + virtual void setup2D(); // _18 + virtual void setScissor(); // _1C + virtual J2DGrafType getGrafType() const { + return J2DGraf_Base; + } // _20 (weak) + virtual void setLookat() { + } // _24 (weak) - void drawFrame(const JGeometry::TBox2f&); - void fillBox(const JGeometry::TBox2f&); - void lineTo(JGeometry::TVec2f); + void drawFrame(const JGeometry::TBox2f&); + void fillBox(const JGeometry::TBox2f&); + void lineTo(JGeometry::TVec2f); - void lineTo(f32 x, f32 y) { lineTo(JGeometry::TVec2f(x, y)); } - void moveTo(f32 x, f32 y) { moveTo(JGeometry::TVec2f(x, y)); } + void lineTo(f32 x, f32 y) { + lineTo(JGeometry::TVec2f(x, y)); + } + void moveTo(f32 x, f32 y) { + moveTo(JGeometry::TVec2f(x, y)); + } - void moveTo(JGeometry::TVec2f pos) { mPrevPos = pos; } + void moveTo(JGeometry::TVec2f pos) { + mPrevPos = pos; + } - void scissor(const JGeometry::TBox2f&); - void setColor(JUtility::TColor c) { setColor(c, c, c, c); } - void setColor(JUtility::TColor, JUtility::TColor, JUtility::TColor, JUtility::TColor); - void setLineWidth(u8); + void scissor(const JGeometry::TBox2f&); + void setColor(JUtility::TColor c) { + setColor(c, c, c, c); + } + void setColor(JUtility::TColor, JUtility::TColor, JUtility::TColor, JUtility::TColor); + void setLineWidth(u8); - // inlined - void line(JGeometry::TVec2f, JGeometry::TVec2f); + // inlined + void line(JGeometry::TVec2f, JGeometry::TVec2f); - // _00 VTBL - JGeometry::TBox2f mBounds; // _04 - JGeometry::TBox2f mScissorBounds; // _14 - JUtility::TColor mColorTL; // _24, top left - JUtility::TColor mColorTR; // _28, top right - JUtility::TColor mColorBR; // _2C, bottom right - JUtility::TColor mColorBL; // _30, bottom left - u8 mLineWidth; // _34 - JGeometry::TVec2f mPrevPos; // _38 - Mtx44 mMtx44; // _40 - GC_Mtx mPosMtx; // _80 - J2DGrafBlend _B0; // _B0 - J2DGrafBlend mLinePart; // _B3 - J2DGrafBlend mBoxPart; // _B6 + // _00 VTBL + JGeometry::TBox2f mBounds; // _04 + JGeometry::TBox2f mScissorBounds; // _14 + JUtility::TColor mColorTL; // _24, top left + JUtility::TColor mColorTR; // _28, top right + JUtility::TColor mColorBR; // _2C, bottom right + JUtility::TColor mColorBL; // _30, bottom left + u8 mLineWidth; // _34 + JGeometry::TVec2f mPrevPos; // _38 + Mtx44 mMtx44; // _40 + GC_Mtx mPosMtx; // _80 + J2DGrafBlend _B0; // _B0 + J2DGrafBlend mLinePart; // _B3 + J2DGrafBlend mBoxPart; // _B6 }; struct J2DPerspGraph : public J2DGrafContext { - J2DPerspGraph(); + J2DPerspGraph(); - virtual ~J2DPerspGraph() { } // _08 (weak) - virtual void setPort(); // _14 - virtual J2DGrafType getGrafType() const { return J2DGraf_Persp; } // _20 (weak) - virtual void setLookat(); // _24 + virtual ~J2DPerspGraph() { + } // _08 (weak) + virtual void setPort(); // _14 + virtual J2DGrafType getGrafType() const { + return J2DGraf_Persp; + } // _20 (weak) + virtual void setLookat(); // _24 - void makeLookat(); - void set(f32, f32, f32); - void setFovy(f32); + void makeLookat(); + void set(f32, f32, f32); + void setFovy(f32); - inline f32 getFovY() const { return mFovY; } + inline f32 getFovY() const { + return mFovY; + } - // _00 = VTBL - // _00-_BC = J2DGrafContext - f32 mFovY; // _BC - f32 _C0; // _C0 - f32 _C4; // _C4 - f32 _C8; // _C8 + // _00 = VTBL + // _00-_BC = J2DGrafContext + f32 mFovY; // _BC + f32 _C0; // _C0 + f32 _C4; // _C4 + f32 _C8; // _C8 }; struct J2DOrthoGraph : public J2DGrafContext { - J2DOrthoGraph(); - J2DOrthoGraph(f32, f32, f32, f32, f32, f32); + J2DOrthoGraph(); + J2DOrthoGraph(f32, f32, f32, f32, f32, f32); - virtual ~J2DOrthoGraph() {}; // _08 (weak) - virtual void setPort(); // _14 - virtual J2DGrafType getGrafType() const { return J2DGraf_Ortho; }; // _20 (weak) - virtual void setLookat(); // _24 + virtual ~J2DOrthoGraph() {}; // _08 (weak) + virtual void setPort(); // _14 + virtual J2DGrafType getGrafType() const { + return J2DGraf_Ortho; + }; // _20 (weak) + virtual void setLookat(); // _24 - void setOrtho(JGeometry::TBox2f const&, f32, f32); - void scissorBounds(JGeometry::TBox2f*, JGeometry::TBox2f const*); + void setOrtho(JGeometry::TBox2f const&, f32, f32); + void scissorBounds(JGeometry::TBox2f*, JGeometry::TBox2f const*); - f32 getWidthPower() const { return mBounds.getWidth() / mOrtho.getWidth(); } - f32 getHeightPower() const { return mBounds.getHeight() / mOrtho.getHeight(); } + f32 getWidthPower() const { + return mBounds.getWidth() / mOrtho.getWidth(); + } + f32 getHeightPower() const { + return mBounds.getHeight() / mOrtho.getHeight(); + } - void setOrtho(f32 param_0, f32 param_1, f32 param_2, f32 param_3, f32 param_4, f32 param_5) - { - JGeometry::TBox2 ortho(param_0, param_1, param_0 + param_2, param_1 + param_3); - setOrtho(ortho, param_4, param_5); - } + void setOrtho(f32 param_0, f32 param_1, f32 param_2, f32 param_3, f32 param_4, f32 param_5) { + JGeometry::TBox2 ortho(param_0, param_1, param_0 + param_2, param_1 + param_3); + setOrtho(ortho, param_4, param_5); + } - // _00 = VTBL - // _00-_BC = J2DGrafContext - JGeometry::TBox2f mOrtho; // _BC - f32 mNear; // _CC - f32 mFar; // _D0 + // _00 = VTBL + // _00-_BC = J2DGrafContext + JGeometry::TBox2f mOrtho; // _BC + f32 mNear; // _CC + f32 mFar; // _D0 }; void J2DFillBox(f32 param_0, f32 param_1, f32 param_2, f32 param_3, JUtility::TColor color); diff --git a/include/JSystem/J2D/J2DIndBlock.h b/include/JSystem/J2D/J2DIndBlock.h index d78749e4..fccf23fd 100644 --- a/include/JSystem/J2D/J2DIndBlock.h +++ b/include/JSystem/J2D/J2DIndBlock.h @@ -8,11 +8,14 @@ #ifdef __cplusplus typedef float Mtx23[2][3]; -struct J2DIndTexCoordScaleInfo -{ +struct J2DIndTexCoordScaleInfo { - GXIndTexScale getScaleS() const { return (GXIndTexScale)mScaleS; } - GXIndTexScale getScaleT() const { return (GXIndTexScale)mScaleT; } + GXIndTexScale getScaleS() const { + return (GXIndTexScale)mScaleS; + } + GXIndTexScale getScaleT() const { + return (GXIndTexScale)mScaleT; + } u8 mScaleS; // _00 u8 mScaleT; // _01 @@ -21,19 +24,18 @@ struct J2DIndTexCoordScaleInfo /** * @size{0x2} */ -struct J2DIndTexCoordScale -{ +struct J2DIndTexCoordScale { J2DIndTexCoordScale(); - ~J2DIndTexCoordScale() {} + ~J2DIndTexCoordScale() { + } void load(u8); J2DIndTexCoordScaleInfo mScaleInfo; // _00 }; -struct J2DIndTexMtxInfo -{ +struct J2DIndTexMtxInfo { Mtx23 mMtx; // _00 s8 mScale; // _18 }; @@ -41,11 +43,11 @@ struct J2DIndTexMtxInfo /** * @size{0x1C} */ -struct J2DIndTexMtx -{ +struct J2DIndTexMtx { J2DIndTexMtx(); - ~J2DIndTexMtx() {} + ~J2DIndTexMtx() { + } void load(u8); @@ -57,8 +59,7 @@ extern J2DIndTexMtxInfo j2dDefaultIndTexMtxInfo; /** * @size{0x2} */ -struct J2DIndTexOrder -{ +struct J2DIndTexOrder { J2DIndTexOrder(); void load(u8); @@ -66,29 +67,40 @@ struct J2DIndTexOrder u8 mMap; // _01 }; -struct J2DIndBlock -{ - virtual void initialize() {} // _08 (weak) - virtual void setGX() {} // _0C (weak) - virtual u32 getType() = 0; // _10 - virtual void setIndTexStageNum(u8 texStageNum) {} // _14 (weak) - virtual u8 getIndTexStageNum() const { return 0; } // _18 (weak) - virtual void setIndTexOrder(unsigned long index, J2DIndTexOrder order) {} // _1C (weak) - virtual J2DIndTexOrder *getIndTexOrder(unsigned long index) { return nullptr; } // _20 (weak) - virtual void setIndTexMtx(unsigned long index, J2DIndTexMtx texMtx) {} // _24 (weak) - virtual J2DIndTexMtx *getIndTexMtx(unsigned long index) { return nullptr; } // _28 (weak) - virtual void setIndTexCoordScale(unsigned long index, J2DIndTexCoordScale scale) {} // _2C (weak) - virtual J2DIndTexCoordScale *getIndTexCoordScale(unsigned long index) { return nullptr; } // _30 (weak) - virtual ~J2DIndBlock() {} // _34 (weak) +struct J2DIndBlock { + virtual void initialize() { + } // _08 (weak) + virtual void setGX() { + } // _0C (weak) + virtual u32 getType() = 0; // _10 + virtual void setIndTexStageNum(u8 texStageNum) { + } // _14 (weak) + virtual u8 getIndTexStageNum() const { + return 0; + } // _18 (weak) + virtual void setIndTexOrder(unsigned long index, J2DIndTexOrder order) { + } // _1C (weak) + virtual J2DIndTexOrder* getIndTexOrder(unsigned long index) { + return nullptr; + } // _20 (weak) + virtual void setIndTexMtx(unsigned long index, J2DIndTexMtx texMtx) { + } // _24 (weak) + virtual J2DIndTexMtx* getIndTexMtx(unsigned long index) { + return nullptr; + } // _28 (weak) + virtual void setIndTexCoordScale(unsigned long index, J2DIndTexCoordScale scale) { + } // _2C (weak) + virtual J2DIndTexCoordScale* getIndTexCoordScale(unsigned long index) { + return nullptr; + } // _30 (weak) + virtual ~J2DIndBlock() { + } // _34 (weak) // _00 VTBL }; -struct J2DIndBlockNull : public J2DIndBlock -{ - inline J2DIndBlockNull() - : J2DIndBlock() - { +struct J2DIndBlockNull : public J2DIndBlock { + inline J2DIndBlockNull() : J2DIndBlock() { } virtual void setGX(); // _0C (weak) @@ -96,26 +108,40 @@ struct J2DIndBlockNull : public J2DIndBlock virtual ~J2DIndBlockNull(); // _34 (weak) }; -struct J2DIndBlockFull : public J2DIndBlock -{ - inline J2DIndBlockFull() - : J2DIndBlock(), mTexOrders(), mTexMtxes(), mTexCoordScales() - { +struct J2DIndBlockFull : public J2DIndBlock { + inline J2DIndBlockFull() : J2DIndBlock(), mTexOrders(), mTexMtxes(), mTexCoordScales() { initialize(); } - virtual void initialize(); // _08 - virtual void setGX(); // _0C - virtual u32 getType() { return JBT_IndFull; } // _10 (weak) - virtual void setIndTexStageNum(u8 texStageNum) { mTexStageNum = texStageNum; } // _14 (weak) - virtual u8 getIndTexStageNum() const { return mTexStageNum; } // _18 (weak) - virtual void setIndTexOrder(unsigned long index, J2DIndTexOrder order) { mTexOrders[index] = order; } // _1C (weak) - virtual J2DIndTexOrder *getIndTexOrder(unsigned long index) { return mTexOrders + index; } // _20 (weak) - virtual void setIndTexMtx(unsigned long, J2DIndTexMtx); // _24 (weak) - virtual J2DIndTexMtx *getIndTexMtx(unsigned long index) { return mTexMtxes + index; } // _28 (weak) - virtual void setIndTexCoordScale(unsigned long index, J2DIndTexCoordScale scale) { mTexCoordScales[index] = scale; } // _2C (weak) - virtual J2DIndTexCoordScale *getIndTexCoordScale(unsigned long index) { return mTexCoordScales + index; } // _30 (weak) - virtual ~J2DIndBlockFull() {} // _34 (weak) + virtual void initialize(); // _08 + virtual void setGX(); // _0C + virtual u32 getType() { + return JBT_IndFull; + } // _10 (weak) + virtual void setIndTexStageNum(u8 texStageNum) { + mTexStageNum = texStageNum; + } // _14 (weak) + virtual u8 getIndTexStageNum() const { + return mTexStageNum; + } // _18 (weak) + virtual void setIndTexOrder(unsigned long index, J2DIndTexOrder order) { + mTexOrders[index] = order; + } // _1C (weak) + virtual J2DIndTexOrder* getIndTexOrder(unsigned long index) { + return mTexOrders + index; + } // _20 (weak) + virtual void setIndTexMtx(unsigned long, J2DIndTexMtx); // _24 (weak) + virtual J2DIndTexMtx* getIndTexMtx(unsigned long index) { + return mTexMtxes + index; + } // _28 (weak) + virtual void setIndTexCoordScale(unsigned long index, J2DIndTexCoordScale scale) { + mTexCoordScales[index] = scale; + } // _2C (weak) + virtual J2DIndTexCoordScale* getIndTexCoordScale(unsigned long index) { + return mTexCoordScales + index; + } // _30 (weak) + virtual ~J2DIndBlockFull() { + } // _34 (weak) u8 mTexStageNum; // _04 J2DIndTexOrder mTexOrders[4]; // _05 diff --git a/include/JSystem/J2D/J2DTypes.h b/include/JSystem/J2D/J2DTypes.h index b2572ea5..d995bf76 100644 --- a/include/JSystem/J2D/J2DTypes.h +++ b/include/JSystem/J2D/J2DTypes.h @@ -2,7 +2,8 @@ #define J2DTYPES_H /** - * Header for J2D POD and nearly POD types, as well as defines, typedefs, and enums that aren't specific to a particular non-POD type. + * Header for J2D POD and nearly POD types, as well as defines, typedefs, and enums that aren't specific to a particular + * non-POD type. */ #include #include "JSystem/J2D/J2DGXColorS10.h" @@ -13,29 +14,23 @@ #ifdef __cplusplus struct JUTTexture; -enum J2DBinding -{ +enum J2DBinding { J2DBIND_Unk15 = 15, }; -enum J2DMirror -{ +enum J2DMirror { J2DMIRROR_Unk0 = 0, }; extern u16 j2dDefaultAlphaCmp; -struct J2DAlphaCompInfo -{ +struct J2DAlphaCompInfo { // TODO: work out what goes in this }; -struct J2DAlphaComp -{ +struct J2DAlphaComp { /** @fabricated */ - J2DAlphaComp() - : mAlphaComp(j2dDefaultAlphaCmp), mRef0(0), mRef1(0) - { + J2DAlphaComp() : mAlphaComp(j2dDefaultAlphaCmp), mRef0(0), mRef1(0) { } u16 mAlphaComp; // _00 @@ -43,19 +38,17 @@ struct J2DAlphaComp u8 mRef1; // _03 }; -struct J2DBlendInfo -{ - J2DBlendInfo() {} +struct J2DBlendInfo { + J2DBlendInfo() { + } - J2DBlendInfo(u8 type, u8 srcFactor, u8 destFactor) - { + J2DBlendInfo(u8 type, u8 srcFactor, u8 destFactor) { mType = type; mSrcFactor = srcFactor; mDestFactor = destFactor; } - void operator=(J2DBlendInfo const &other) - { + void operator=(J2DBlendInfo const& other) { mType = other.mType; mSrcFactor = other.mSrcFactor; mDestFactor = other.mDestFactor; @@ -68,23 +61,20 @@ struct J2DBlendInfo extern J2DBlendInfo j2dDefaultBlendInfo; -struct J2DBlend -{ - J2DBlend() { mBlendInfo = j2dDefaultBlendInfo; } - - J2DBlend(u8 type, u8 srcFactor, u8 destFactor, u8 op) - : mBlendInfo(type, srcFactor, destFactor), mOp(op) - { +struct J2DBlend { + J2DBlend() { + mBlendInfo = j2dDefaultBlendInfo; } - void operator=(J2DBlend const &other) - { + J2DBlend(u8 type, u8 srcFactor, u8 destFactor, u8 op) : mBlendInfo(type, srcFactor, destFactor), mOp(op) { + } + + void operator=(J2DBlend const& other) { mBlendInfo = other.mBlendInfo; mOp = other.mOp; } - inline void set(J2DBlend blend) - { + inline void set(J2DBlend blend) { mBlendInfo = blend.mBlendInfo; mOp = blend.mOp; } @@ -93,8 +83,7 @@ struct J2DBlend u8 mOp; // _03 }; -struct J2DColorChanInfo -{ +struct J2DColorChanInfo { u8 _00; // _00, should these be one u16? u8 _01; // _01 }; @@ -104,17 +93,19 @@ extern J2DColorChanInfo j2dDefaultColorChanInfo; /** * @size{0x2} */ -struct J2DColorChan -{ - J2DColorChan() { mData = j2dDefaultColorChanInfo._01; } +struct J2DColorChan { + J2DColorChan() { + mData = j2dDefaultColorChanInfo._01; + } - u16 getMatSrc() const { return mData & 1; } + u16 getMatSrc() const { + return mData & 1; + } u16 mData; // _00, should this be J2DColorChanInfo? }; -struct J2DTevOrderInfo -{ +struct J2DTevOrderInfo { u8 mTexCoord; // _00 u8 mTexMap; // _01 u8 mColor; // _02 @@ -122,42 +113,45 @@ struct J2DTevOrderInfo extern J2DTevOrderInfo j2dDefaultTevOrderInfoNull; -struct J2DTevOrder -{ - J2DTevOrder() { mTevOrderInfo = j2dDefaultTevOrderInfoNull; } +struct J2DTevOrder { + J2DTevOrder() { + mTevOrderInfo = j2dDefaultTevOrderInfoNull; + } /** @fabricated */ - inline J2DTevOrder(u8 texCoord, u8 texMap, u8 color) - { + inline J2DTevOrder(u8 texCoord, u8 texMap, u8 color) { mTevOrderInfo.mTexCoord = texCoord; mTevOrderInfo.mTexMap = texMap; mTevOrderInfo.mColor = color; } /** @fabricated */ - inline J2DTevOrder &operator=(const J2DTevOrderInfo &other) - { + inline J2DTevOrder& operator=(const J2DTevOrderInfo& other) { mTevOrderInfo = other; return *this; } /** @fabricated */ - inline J2DTevOrder &operator=(const J2DTevOrder &other) - { + inline J2DTevOrder& operator=(const J2DTevOrder& other) { mTevOrderInfo = other.mTevOrderInfo; return *this; } - inline GXChannelID getColor() const { return (GXChannelID)mTevOrderInfo.mColor; } - inline GXTexMapID getTexMap() const { return (GXTexMapID)mTevOrderInfo.mTexMap; } - inline GXTexCoordID getTexCoord() const { return (GXTexCoordID)mTevOrderInfo.mTexCoord; } + inline GXChannelID getColor() const { + return (GXChannelID)mTevOrderInfo.mColor; + } + inline GXTexMapID getTexMap() const { + return (GXTexMapID)mTevOrderInfo.mTexMap; + } + inline GXTexCoordID getTexCoord() const { + return (GXTexCoordID)mTevOrderInfo.mTexCoord; + } J2DTevOrderInfo mTevOrderInfo; // _00 u8 _03; // _03 }; -struct J2DTevStageInfo -{ +struct J2DTevStageInfo { u8 _00; // _00 bool _01; // _01 u8 _02; // _02 @@ -181,8 +175,7 @@ struct J2DTevStageInfo }; #pragma reverse_bitfields on -struct J2DTevStage_0x1 -{ +struct J2DTevStage_0x1 { // LSB u8 _0 : 2; u8 _2 : 1; @@ -192,8 +185,7 @@ struct J2DTevStage_0x1 // MSB }; -struct J2DTevStage_0x4 -{ +struct J2DTevStage_0x4 { // LSB u8 _0 : 1; u8 _1 : 3; @@ -210,15 +202,13 @@ struct J2DTevStage_0x4 // u8 _0 : 2; // MSB }; -struct J2DTevStage -{ +struct J2DTevStage { J2DTevStage(); - void setTevStageInfo(const J2DTevStageInfo &info); + void setTevStageInfo(const J2DTevStageInfo& info); /** @fabricated */ - inline J2DTevStage &operator=(const J2DTevStage &other) - { + inline J2DTevStage& operator=(const J2DTevStage& other) { _01 = other._01; _02 = other._02; _03 = other._03; @@ -233,8 +223,7 @@ struct J2DTevStage u8 _02; // _02 u8 _03; // _03 // u8 _04; // _04 - union - { + union { J2DTevStage_0x4 asStruct; u8 asBytes[4]; } _04; // _04 @@ -269,14 +258,12 @@ struct J2DTevStage // } _06; // _06 }; -struct J2DTevSwapModeInfo -{ +struct J2DTevSwapModeInfo { u8 _00; u8 _01; }; -struct J2DTevSwapModeTableInfo -{ +struct J2DTevSwapModeTableInfo { // TODO: work out what goes in this }; @@ -284,13 +271,11 @@ struct J2DTevSwapModeTableInfo // u8 _00 : 2; // }; -struct J2DTevSwapModeTable -{ +struct J2DTevSwapModeTable { J2DTevSwapModeTable(); /** @fabricated */ - inline J2DTevSwapModeTable(u8 p1, u8 p2, u8 p3, u8 p4) - { + inline J2DTevSwapModeTable(u8 p1, u8 p2, u8 p3, u8 p4) { _0 = p1; _2 = p2; _4 = p3; @@ -310,27 +295,43 @@ struct J2DTevSwapModeTable }; #pragma reverse_bitfields reset -struct J2DIndTevStage -{ +struct J2DIndTevStage { J2DIndTevStage(); void load(u8); - GXIndTexStageID getIndStage() const { return (GXIndTexStageID)(mFlags & 0x03); } - GXIndTexFormat getIndFormat() const { return (GXIndTexFormat)((mFlags >> 2) & 0x03); } - GXIndTexBiasSel getBiasSel() const { return (GXIndTexBiasSel)((mFlags >> 4) & 0x07); } - GXIndTexWrap getWrapS() const { return (GXIndTexWrap)((mFlags >> 8) & 0x07); } - GXIndTexWrap getWrapT() const { return (GXIndTexWrap)((mFlags >> 11) & 0x07); } - GXIndTexMtxID getMtxSel() const { return (GXIndTexMtxID)((mFlags >> 16) & 0x0F); } - GXBool getPrev() const { return (GXBool)((mFlags >> 20) & 0x01); } - GXBool getLod() const { return (GXBool)((mFlags >> 21) & 0x01); } - GXIndTexAlphaSel getAlphaSel() const { return (GXIndTexAlphaSel)((mFlags >> 22) & 0x03); } + GXIndTexStageID getIndStage() const { + return (GXIndTexStageID)(mFlags & 0x03); + } + GXIndTexFormat getIndFormat() const { + return (GXIndTexFormat)((mFlags >> 2) & 0x03); + } + GXIndTexBiasSel getBiasSel() const { + return (GXIndTexBiasSel)((mFlags >> 4) & 0x07); + } + GXIndTexWrap getWrapS() const { + return (GXIndTexWrap)((mFlags >> 8) & 0x07); + } + GXIndTexWrap getWrapT() const { + return (GXIndTexWrap)((mFlags >> 11) & 0x07); + } + GXIndTexMtxID getMtxSel() const { + return (GXIndTexMtxID)((mFlags >> 16) & 0x0F); + } + GXBool getPrev() const { + return (GXBool)((mFlags >> 20) & 0x01); + } + GXBool getLod() const { + return (GXBool)((mFlags >> 21) & 0x01); + } + GXIndTexAlphaSel getAlphaSel() const { + return (GXIndTexAlphaSel)((mFlags >> 22) & 0x03); + } u32 mFlags; // _00 }; -struct J2DTexCoordInfo -{ +struct J2DTexCoordInfo { u8 mTexGenType; // _00 u8 mTexGenSrc; // _01 u8 mTexGenMtx; // _02 @@ -338,16 +339,14 @@ struct J2DTexCoordInfo u8 _03; // _03 - padding? }; -struct J2DTexCoord -{ +struct J2DTexCoord { J2DTexCoord(); // J2DTexCoordInfo _00; J2DTexCoordInfo mTexCoordInfo; // _00 }; -struct J2DTextureSRTInfo -{ +struct J2DTextureSRTInfo { f32 _00; // _00 f32 _04; // _04 f32 _08; // _08 @@ -371,15 +370,13 @@ extern const u8 j2dDefaultDither; extern u8 j2dDefaultTevSwapTable; // j2dDefaultAlphaCmp declared earlier in file. -enum J2DTextBoxHBinding -{ +enum J2DTextBoxHBinding { J2DHBIND_Center = 0, J2DHBIND_Right = 1, J2DHBIND_Left = 2, }; -enum J2DTextBoxVBinding -{ +enum J2DTextBoxVBinding { J2DVBIND_Center = 0, J2DVBIND_Bottom = 1, J2DVBIND_Top = 2, diff --git a/include/JSystem/J3D/J3DTypes.h b/include/JSystem/J3D/J3DTypes.h index 35b62165..e3768d1c 100644 --- a/include/JSystem/J3D/J3DTypes.h +++ b/include/JSystem/J3D/J3DTypes.h @@ -5,29 +5,29 @@ #ifdef __cplusplus enum JBlockType { - JBT_ColorAmbientOn = 'CLAB', - JBT_ColorNull = 'CLNL', - JBT_ColorLightOff = 'CLOF', - JBT_ColorLightOn = 'CLON', - JBT_IndFull = 'IBLF', - JBT_IndNull = 'IBLN', - JBT_PETexEdge = 'PEED', - JBT_PEFogOff = 'PEFG', - JBT_PEFull = 'PEFL', - JBT_PENull = 'PENL', - JBT_PEOpa = 'PEOP', - JBT_PEXlu = 'PEXL', - JBT_TexGen4 = 'TGB4', - JBT_TexGenBasic = 'TGBC', - JBT_TexGenNull = 'TGNL', - JBT_TexGenPatched = 'TGPT', - JBT_Tev16 = 'TV16', - JBT_Tev1 = 'TVB1', - JBT_Tev2 = 'TVB2', - JBT_Tev4 = 'TVB4', - JBT_Tev8 = 'TVB8', - JBT_TevNull = 'TVNL', - JBT_TevPatched = 'TVPT' + JBT_ColorAmbientOn = 'CLAB', + JBT_ColorNull = 'CLNL', + JBT_ColorLightOff = 'CLOF', + JBT_ColorLightOn = 'CLON', + JBT_IndFull = 'IBLF', + JBT_IndNull = 'IBLN', + JBT_PETexEdge = 'PEED', + JBT_PEFogOff = 'PEFG', + JBT_PEFull = 'PEFL', + JBT_PENull = 'PENL', + JBT_PEOpa = 'PEOP', + JBT_PEXlu = 'PEXL', + JBT_TexGen4 = 'TGB4', + JBT_TexGenBasic = 'TGBC', + JBT_TexGenNull = 'TGNL', + JBT_TexGenPatched = 'TGPT', + JBT_Tev16 = 'TV16', + JBT_Tev1 = 'TVB1', + JBT_Tev2 = 'TVB2', + JBT_Tev4 = 'TVB4', + JBT_Tev8 = 'TVB8', + JBT_TevNull = 'TVNL', + JBT_TevPatched = 'TVPT' }; #endif diff --git a/include/JSystem/JFramework/JFWDisplay.h b/include/JSystem/JFramework/JFWDisplay.h index c118717c..64942c8b 100644 --- a/include/JSystem/JFramework/JFWDisplay.h +++ b/include/JSystem/JFramework/JFWDisplay.h @@ -17,42 +17,50 @@ typedef void (*JFWDisplayUnkFunc)(void); extern GC_Mtx e_mtx; class JFWAlarm : public OSAlarm { // everything here seems to be auto inlined or unused -public: + public: // Contructor and Destructor are both present in map but unused, not sure if it belongs here - JFWAlarm() {} - ~JFWAlarm() {} - void createAlarm() { OSCreateAlarm(this); } - void cancelAlarm() { OSCancelAlarm(this); } + JFWAlarm() { + } + ~JFWAlarm() { + } + void createAlarm() { + OSCreateAlarm(this); + } + void cancelAlarm() { + OSCancelAlarm(this); + } - OSThread *getThread() const { return mThread; } - void setThread(OSThread *thread) { mThread = thread; } + OSThread* getThread() const { + return mThread; + } + void setThread(OSThread* thread) { + mThread = thread; + } - static JSUList sList;// + static JSUList sList; // -public: - /* 0x28 */ OSThread *mThread; + public: + /* 0x28 */ OSThread* mThread; }; -class JFWDisplay -{ -public: - enum EDrawDone - { +class JFWDisplay { + public: + enum EDrawDone { /* 0x0 */ UNK_METHOD_0 = 0, /* 0x1 */ UNK_METHOD_1 = 1 }; - static JFWDisplay *createManager(const _GXRenderModeObj *, JKRHeap *, JUTXfb::EXfbNumber, bool); // 0x80015bfc - void waitBlanking(int); // 0x8001684c - void threadSleep(s64); // 0x800169fc - void clearEfb_init(); // 0x80016ab8 - void clearEfb(); // 0x80016b2c - void clearEfb(_GXColor); // 0x80016b58 - void clearEfb(int, int, int, int, _GXColor); // 0x80016b9c - void calcCombinationRatio(); // 0x80016f0c + static JFWDisplay* createManager(const _GXRenderModeObj*, JKRHeap*, JUTXfb::EXfbNumber, bool); // 0x80015bfc + void waitBlanking(int); // 0x8001684c + void threadSleep(s64); // 0x800169fc + void clearEfb_init(); // 0x80016ab8 + void clearEfb(); // 0x80016b2c + void clearEfb(_GXColor); // 0x80016b58 + void clearEfb(int, int, int, int, _GXColor); // 0x80016b9c + void calcCombinationRatio(); // 0x80016f0c - void ctor_subroutine(const GXRenderModeObj *, bool); - JFWDisplay(const GXRenderModeObj *, JKRHeap *, JUTXfb::EXfbNumber, bool); + void ctor_subroutine(const GXRenderModeObj*, bool); + JFWDisplay(const GXRenderModeObj*, JKRHeap*, JUTXfb::EXfbNumber, bool); static void destroyManager(); void prepareCopyDisp(); @@ -66,16 +74,16 @@ public: void* changeToDoubleXfb(); // UNUSED - JFWDisplay(void *, bool); - JFWDisplay(void *, void *, bool); - JFWDisplay(void *, void *, void *, bool); - void createManager(const _GXRenderModeObj *, void *, bool); - void createManager(const _GXRenderModeObj *, void *, void *, bool); - void createManager(const _GXRenderModeObj *, void *, void *, void *, bool); + JFWDisplay(void*, bool); + JFWDisplay(void*, void*, bool); + JFWDisplay(void*, void*, void*, bool); + void createManager(const _GXRenderModeObj*, void*, bool); + void createManager(const _GXRenderModeObj*, void*, void*, bool); + void createManager(const _GXRenderModeObj*, void*, void*, void*, bool); void deleteToSingleXfb(int); - void deleteToSingleXfb(void *); - void addToDoubleXfb(void *, bool); - void addToDoubleXfb(JKRHeap *); + void deleteToSingleXfb(void*); + void addToDoubleXfb(void*, bool); + void addToDoubleXfb(JKRHeap*); void clearAllXfb(); s32 frameToTick(float); static void setForOSResetSystem(); @@ -86,7 +94,9 @@ public: virtual void endFrame(); // 0x8001669c virtual ~JFWDisplay(); // 0x80015b80 - static JFWDisplay *getManager() { return sManager; } + static JFWDisplay* getManager() { + return sManager; + } int getEfbHeight() const { return JUTVideo::getManager()->getEfbHeight(); @@ -96,8 +106,12 @@ public: return JUTVideo::getManager()->getFbWidth(); } - JUTFader *getFader() const { return mFader; } - void setFader(JUTFader * fader) { mFader = fader; } + JUTFader* getFader() const { + return mFader; + } + void setFader(JUTFader* fader) { + mFader = fader; + } bool startFadeOut(int duration) { if (mFader != nullptr) { @@ -125,8 +139,7 @@ public: mClearColor.set(r, g, b, a); } - void setClearColor(JUtility::TColor color) - { + void setClearColor(JUtility::TColor color) { mClearColor = color; } @@ -134,19 +147,18 @@ public: mEnableAlpha = enable; } - bool getFBAlpha() - { + bool getFBAlpha() { return mEnableAlpha; } - static JFWDisplay *sManager; // 0x80415718 + static JFWDisplay* sManager; // 0x80415718 -private: - JUTFader *mFader; // 04 - const GXRenderModeObj *mRMode; // 08 + private: + JUTFader* mFader; // 04 + const GXRenderModeObj* mRMode; // 08 JUtility::TColor mClearColor; // 0c u32 mZClear; // 10 - JUTXfb *mXfb; // 14 + JUTXfb* mXfb; // 14 u16 mGamma; // 18 EDrawDone mDrawDoneMethod; // 1c u16 mFrameRate; // 20 @@ -156,7 +168,7 @@ private: f32 mCombinationRatio; // 2c u32 mStartTick; // 30, tick of when the frame starts rendering u32 mFrameTime; // 34, time it took to render a frame/amount of ticks beginRender took - u32 mVideoFrameTime; // 38, time between mStartTick and the last Video Tick + u32 mVideoFrameTime; // 38, time between mStartTick and the last Video Tick s16 mDrawingXfbNo; // 3c bool mIsSingleXfb; // 3e }; diff --git a/include/JSystem/JFramework/JFWSystem.h b/include/JSystem/JFramework/JFWSystem.h index a8a59343..7818ef1d 100644 --- a/include/JSystem/JFramework/JFWSystem.h +++ b/include/JSystem/JFramework/JFWSystem.h @@ -11,10 +11,8 @@ #include "types.h" // Maybe these are namespaces? -struct JFWSystem -{ - struct CSetUpParam - { +struct JFWSystem { + struct CSetUpParam { static int maxStdHeaps; static u32 sysHeapSize; static u32 fifoBufSize; @@ -23,48 +21,47 @@ struct JFWSystem static s32 streamPriority; static s32 decompPriority; static s32 aPiecePriority; - static const ResFONT *systemFontRes; - static const _GXRenderModeObj *renderMode; + static const ResFONT* systemFontRes; + static const _GXRenderModeObj* renderMode; static u32 exConsoleBufferSize; }; static void firstInit(); static void init(); - static JKRHeap *rootHeap; - static JKRHeap *systemHeap; - static JKRThread *mainThread; - static JUTDbPrint *debugPrint; - static JUTFont *systemFont; - static JUTConsoleManager *systemConsoleManager; - static JUTConsole *systemConsole; + static JKRHeap* rootHeap; + static JKRHeap* systemHeap; + static JKRThread* mainThread; + static JUTDbPrint* debugPrint; + static JUTFont* systemFont; + static JUTConsoleManager* systemConsoleManager; + static JUTConsole* systemConsole; static bool sInitCalled; - - - // No idea how they formatted this lol - static void setMaxStdHeap(int stdHeaps) { + static void setMaxStdHeap(int stdHeaps) { JUT_ASSERT(sInitCalled == 0); - CSetUpParam::maxStdHeaps = stdHeaps; } + CSetUpParam::maxStdHeaps = stdHeaps; + } static void setSysHeapSize(u32 heapSize) { JUT_ASSERT(sInitCalled == 0); - CSetUpParam::sysHeapSize = heapSize; } + CSetUpParam::sysHeapSize = heapSize; + } static void setFifoBufSize(u32 bufSize) { JUT_ASSERT(sInitCalled == 0); - CSetUpParam::fifoBufSize = bufSize; } - - // Inlines for Aram + CSetUpParam::fifoBufSize = bufSize; + } static void setAramAudioBufSize(u32 bufSize) { JUT_ASSERT(sInitCalled == 0); - CSetUpParam::aramAudioBufSize = bufSize; } + CSetUpParam::aramAudioBufSize = bufSize; + } static void setAramGraphBufSize(u32 bufSize) { JUT_ASSERT(sInitCalled == 0); - CSetUpParam::aramGraphBufSize = bufSize; } - // probably some more inlines for other variables, not used by MKDD - static void setRenderMode(const _GXRenderModeObj * rmode) { -#line 80 + CSetUpParam::aramGraphBufSize = bufSize; + } + static void setRenderMode(const _GXRenderModeObj* rmode) { JUT_ASSERT(sInitCalled == 0); - CSetUpParam::renderMode = rmode; } + CSetUpParam::renderMode = rmode; + } }; #endif diff --git a/include/JSystem/JGadget/define.h b/include/JSystem/JGadget/define.h index a589b3f0..c56e355c 100644 --- a/include/JSystem/JGadget/define.h +++ b/include/JSystem/JGadget/define.h @@ -7,30 +7,31 @@ extern "C" { class JGadget_outMessage { -public: - typedef void (*MessageFunc)(const char*, int, const char*); + public: + typedef void (*MessageFunc)(const char*, int, const char*); - static void warning(const char*, int, const char*); + static void warning(const char*, int, const char*); - JGadget_outMessage(MessageFunc fn, const char* file, int line); - ~JGadget_outMessage(); + JGadget_outMessage(MessageFunc fn, const char* file, int line); + ~JGadget_outMessage(); - JGadget_outMessage& operator<<(const char* str); + JGadget_outMessage& operator<<(const char* str); -private: - MessageFunc mMsgFunc; - char mBuffer[256]; - char* mWrite_p; - char* mFile; - int mLine; + private: + MessageFunc mMsgFunc; + char mBuffer[256]; + char* mWrite_p; + char* mFile; + int mLine; }; -#define JGADGET_ASSERTWARN(cond) \ - ((cond) || (false)) - -#define JGADGET_EXITWARN(cond) \ - if (!(cond)) { false; return false; } +#define JGADGET_ASSERTWARN(cond) ((cond) || (false)) +#define JGADGET_EXITWARN(cond) \ + if (!(cond)) { \ + false; \ + return false; \ + } } #endif diff --git a/include/JSystem/JGadget/linklist.h b/include/JSystem/JGadget/linklist.h index 7458f155..8261c6ba 100644 --- a/include/JSystem/JGadget/linklist.h +++ b/include/JSystem/JGadget/linklist.h @@ -210,7 +210,6 @@ public: T* operator->() const { return TLinkList::Element_toValue(mIt.operator->()); } T& operator*() const { T* p = this->operator->(); - #line 541 JUT_ASSERT(p!=0); return *p; } @@ -239,7 +238,6 @@ public: const T* operator->() const { return TLinkList::Element_toValue(mIt.operator->()); } const T& operator*() const { const T* p = this->operator->(); - #line 586 JUT_ASSERT(p!=0); return *p; } @@ -262,37 +260,31 @@ public: void Push_back(T* p) { Insert(end(), p); } T& front() { - #line 642 JUT_ASSERT(!empty()); return *begin(); } T& back() { - #line 652 JUT_ASSERT(!empty()); return *--end(); } static TLinkListNode* Element_toNode(T* p) { - #line 753 JUT_ASSERT(p!=0); return (TLinkListNode*)((char*)p - O); } static const TLinkListNode* Element_toNode(const T* p) { - #line 758 JUT_ASSERT(p!=0); return (const TLinkListNode*)((const char*)p - O); } static T* Element_toValue(TLinkListNode* p) { - #line 763 JUT_ASSERT(p!=0); return (T*)((char*)p + O); } static const T* Element_toValue(const TLinkListNode* p) { - #line 768 JUT_ASSERT(p!=0); return (const T*)((const char*)p + O); } diff --git a/include/JSystem/JGeometry.h b/include/JSystem/JGeometry.h index d1928131..ae0c7d44 100644 --- a/include/JSystem/JGeometry.h +++ b/include/JSystem/JGeometry.h @@ -5,232 +5,223 @@ #include "types.h" #ifdef __cplusplus -inline f32 fsqrt_step(f32 mag) -{ - f32 root = __frsqrte(mag); - return 0.5f * root * (3.0f - mag * (root * root)); +inline f32 fsqrt_step(f32 mag) { + f32 root = __frsqrte(mag); + return 0.5f * root * (3.0f - mag * (root * root)); } namespace JGeometry { -template -struct TVec2 { - TVec2() { } - TVec2(T v) { set(v); } - TVec2(T x, T y) { set(x, y); } +template struct TVec2 { + TVec2() { + } + TVec2(T v) { + set(v); + } + TVec2(T x, T y) { + set(x, y); + } - void set(T v) { y = x = v; } + void set(T v) { + y = x = v; + } - void set(T x, T y) - { - this->x = x; - this->y = y; - } + void set(T x, T y) { + this->x = x; + this->y = y; + } - void set(const TVec2& other) - { - x = other.x; - y = other.y; - } + void set(const TVec2& other) { + x = other.x; + y = other.y; + } - void setMin(const TVec2& min) - { - if (x >= min.x) - x = min.x; - if (y >= min.y) - y = min.y; - } + void setMin(const TVec2& min) { + if (x >= min.x) + x = min.x; + if (y >= min.y) + y = min.y; + } - void setMax(const TVec2& max) - { - if (x <= max.x) - x = max.x; - if (y <= max.y) - y = max.y; - } + void setMax(const TVec2& max) { + if (x <= max.x) + x = max.x; + if (y <= max.y) + y = max.y; + } - void add(const TVec2& other) - { - x += other.x; - y += other.y; - } + void add(const TVec2& other) { + x += other.x; + y += other.y; + } - /** @fabricated */ - // TVec2 adding(const TVec2& other) { return TVec2(x + other.x, y + other.y); } + /** @fabricated */ + // TVec2 adding(const TVec2& other) { return TVec2(x + other.x, y + other.y); } - /** @fabricated */ - TVec2 adding(T xDelta, T yDelta) { return TVec2(x + xDelta, y + yDelta); } + /** @fabricated */ + TVec2 adding(T xDelta, T yDelta) { + return TVec2(x + xDelta, y + yDelta); + } - /** @fabricated */ - void add(T xDelta, T yDelta) - { - x += xDelta; - y += yDelta; - } + /** @fabricated */ + void add(T xDelta, T yDelta) { + x += xDelta; + y += yDelta; + } - TVec2& operator+=(const TVec2& other) - { - x += other.x; - y += other.y; - return *this; - } + TVec2& operator+=(const TVec2& other) { + x += other.x; + y += other.y; + return *this; + } - TVec2& operator*=(const TVec2& other) - { - x *= other.x; - y *= other.y; - return *this; - } + TVec2& operator*=(const TVec2& other) { + x *= other.x; + y *= other.y; + return *this; + } - bool isAbove(const TVec2& other) const { return (x >= other.x) && (y >= other.y) ? true : false; } + bool isAbove(const TVec2& other) const { + return (x >= other.x) && (y >= other.y) ? true : false; + } - T x; - T y; + T x; + T y; }; -template -struct TVec3 { - // inline TVec3() { } - // inline TVec3(T value) - // : x(value) - // , y(value) - // , z(value) - // { - // } - // inline TVec3(T inX, T inY, T inZ) - // : x(inX) - // , y(inY) - // , z(inZ) {}; +template struct TVec3 { + // inline TVec3() { } + // inline TVec3(T value) + // : x(value) + // , y(value) + // , z(value) + // { + // } + // inline TVec3(T inX, T inY, T inZ) + // : x(inX) + // , y(inY) + // , z(inZ) {}; - // // TODO: Determine if this could've actually existed, or if I'm just making it up. - // inline TVec3(const TVec3& other) - // { - // x = other.x; - // y = other.y; - // z = other.z; - // } + // // TODO: Determine if this could've actually existed, or if I'm just making it up. + // inline TVec3(const TVec3& other) + // { + // x = other.x; + // y = other.y; + // z = other.z; + // } - // TODO: Determine if this could've actually existed, or if I'm just making - // it up. - inline TVec3& operator=(const TVec3& other) - { - x = other.x; - y = other.y; - z = other.z; - return *this; - } + // TODO: Determine if this could've actually existed, or if I'm just making + // it up. + inline TVec3& operator=(const TVec3& other) { + x = other.x; + y = other.y; + z = other.z; + return *this; + } - void set(T x, T y, T z) - { - this->x = x; - this->y = y; - this->z = z; - } + void set(T x, T y, T z) { + this->x = x; + this->y = y; + this->z = z; + } - void set(const TVec3& other) - { - x = other.x; - y = other.y; - z = other.z; - } + void set(const TVec3& other) { + x = other.x; + y = other.y; + z = other.z; + } - void setMin(const TVec3& min) - { - if (x >= min.x) - x = min.x; - if (y >= min.y) - y = min.y; - if (z >= min.z) - z = min.z; - } + void setMin(const TVec3& min) { + if (x >= min.x) + x = min.x; + if (y >= min.y) + y = min.y; + if (z >= min.z) + z = min.z; + } - void setMax(const TVec3& max) - { - if (x <= max.x) - x = max.x; - if (y <= max.y) - y = max.y; - if (z >= max.z) - z = max.z; - } + void setMax(const TVec3& max) { + if (x <= max.x) + x = max.x; + if (y <= max.y) + y = max.y; + if (z >= max.z) + z = max.z; + } - // inline operator Vec() const { return *this; } - inline operator Vec() const - { - Vec other; - other.x = x; - other.y = y; - other.z = z; - return other; - } + // inline operator Vec() const { return *this; } + inline operator Vec() const { + Vec other; + other.x = x; + other.y = y; + other.z = z; + return other; + } - // inline TVec3(Vec& vec) - // { - // x = vec.x; - // y = vec.y; - // z = vec.z; - // } + // inline TVec3(Vec& vec) + // { + // x = vec.x; + // y = vec.y; + // z = vec.z; + // } - void zero() { x = y = z = 0.0f; } + void zero() { + x = y = z = 0.0f; + } - f32 squared() const { return x * x + y * y + z * z; } + f32 squared() const { + return x * x + y * y + z * z; + } - void normalize() - { - f32 sq = squared(); - if (sq <= FLT_EPSILON * 32.0f) { - return; - } - f32 norm; - if (sq <= 0.0f) { - norm = sq; - } else { - norm = fsqrt_step(sq); - } - x *= norm; - y *= norm; - z *= norm; - } + void normalize() { + f32 sq = squared(); + if (sq <= FLT_EPSILON * 32.0f) { + return; + } + f32 norm; + if (sq <= 0.0f) { + norm = sq; + } else { + norm = fsqrt_step(sq); + } + x *= norm; + y *= norm; + z *= norm; + } - void normalize(const TVec3& other) - { - f32 sq = other.squared(); - if (sq <= FLT_EPSILON * 32.0f) { - zero(); - return; - } - f32 norm; - if (sq <= 0.0f) { - norm = sq; - } else { - norm = fsqrt_step(sq); - } - x = other.x * norm; - y = other.y * norm; - z = other.z * norm; - } + void normalize(const TVec3& other) { + f32 sq = other.squared(); + if (sq <= FLT_EPSILON * 32.0f) { + zero(); + return; + } + f32 norm; + if (sq <= 0.0f) { + norm = sq; + } else { + norm = fsqrt_step(sq); + } + x = other.x * norm; + y = other.y * norm; + z = other.z * norm; + } - bool isAbove(const TVec3& other) const { return (x >= other.x) && (y >= other.y) && (z >= other.z); } + bool isAbove(const TVec3& other) const { + return (x >= other.x) && (y >= other.y) && (z >= other.z); + } - T x; - T y; - T z; + T x; + T y; + T z; }; // Size: 0x10 -template -struct TBox { - TBox() - : i() - , f() - { - } - TBox(const TBox& other) - : i(other.f) - , f(other.y) - { - } +template struct TBox { + TBox() : i(), f() { + } + TBox(const TBox& other) : i(other.f), f(other.y) { + } - T i, f; + T i, f; }; // clang-format off @@ -315,44 +306,47 @@ struct TBox2 : TBox > { }; // clang-format on -template -struct TBox3 { - // TBox3() {} - // TBox2(const TBox2& other) { set(other); } - // TBox3(const TVec3& i, const TVec3 f) { set(i, f); } - // // TBox2(const TVec2& i, T x1, T y1) { set(i, x1, y1); } - // // TBox2(T x0, T y0, const TVec2& f) { set(x0, y0, f); } - // TBox3(T x0, T y0, T z0, T x1, T y1, T z1) { set(x0, y0, z0, x1, y1, z1); } - // TBox3(T x0, T y0, TVec3& f) { set(x0, y0, z0, x0 + f.x, y0 + f.y, z0 + f.z); } - // TBox3(T val) - // { - // f.x = f.y = f.z = val; - // i.x = i.y = i.z = val; - // } +template struct TBox3 { + // TBox3() {} + // TBox2(const TBox2& other) { set(other); } + // TBox3(const TVec3& i, const TVec3 f) { set(i, f); } + // // TBox2(const TVec2& i, T x1, T y1) { set(i, x1, y1); } + // // TBox2(T x0, T y0, const TVec2& f) { set(x0, y0, f); } + // TBox3(T x0, T y0, T z0, T x1, T y1, T z1) { set(x0, y0, z0, x1, y1, z1); } + // TBox3(T x0, T y0, TVec3& f) { set(x0, y0, z0, x0 + f.x, y0 + f.y, z0 + f.z); } + // TBox3(T val) + // { + // f.x = f.y = f.z = val; + // i.x = i.y = i.z = val; + // } - inline bool isValid() { return mMax.isAbove(mMin); } + inline bool isValid() { + return mMax.isAbove(mMin); + } - void absolute() - { - if (!this->isValid()) { - TBox3 box(*this); - this->mMin.setMin(box.mMin); - this->mMin.setMin(box.mMax); - this->mMax.setMax(box.mMin); - this->mMax.setMax(box.mMax); - } - } + void absolute() { + if (!this->isValid()) { + TBox3 box(*this); + this->mMin.setMin(box.mMin); + this->mMin.setMin(box.mMax); + this->mMax.setMax(box.mMin); + this->mMax.setMax(box.mMax); + } + } - void set(const TBox3& other) { set(other.mMin, other.mMax); } - void set(const TVec3& i, const TVec3& f) { this->mMin.set(i), this->mMax.set(f); } - void set(T x0, T y0, T z0, T x1, T y1, T z1) - { - this->mMin.set(x0, y0); - this->mMax.set(x1, y1); - } + void set(const TBox3& other) { + set(other.mMin, other.mMax); + } + void set(const TVec3& i, const TVec3& f) { + this->mMin.set(i), this->mMax.set(f); + } + void set(T x0, T y0, T z0, T x1, T y1, T z1) { + this->mMin.set(x0, y0); + this->mMax.set(x1, y1); + } - TVec3 mMin; // _00 - TVec3 mMax; // _0C + TVec3 mMin; // _00 + TVec3 mMax; // _0C }; typedef TVec2 TVec2f; @@ -363,4 +357,4 @@ typedef TBox3 TBox3f; } // namespace JGeometry #endif -#endif \ No newline at end of file +#endif diff --git a/include/JSystem/JKernel/JKRAram.h b/include/JSystem/JKernel/JKRAram.h index 0f50d9e9..981bad61 100644 --- a/include/JSystem/JKernel/JKRAram.h +++ b/include/JSystem/JKernel/JKRAram.h @@ -25,291 +25,290 @@ class JKRAramHeap; class JKRDecompCommand; class JKRAMCommand; -class JKRAramBlock -{ -public: - JKRAramBlock(u32 address, u32 size, u32 freeSize, u8 groupID, bool tempMemory); +class JKRAramBlock { + public: + JKRAramBlock(u32 address, u32 size, u32 freeSize, u8 groupID, bool tempMemory); - virtual ~JKRAramBlock(); + virtual ~JKRAramBlock(); - JKRAramBlock* allocHead(u32 size, u8 groupID, JKRAramHeap* heap); - JKRAramBlock* allocTail(u32 size, u8 groupID, JKRAramHeap* heap); + JKRAramBlock* allocHead(u32 size, u8 groupID, JKRAramHeap* heap); + JKRAramBlock* allocTail(u32 size, u8 groupID, JKRAramHeap* heap); - u32 getAddress() const { return this->mAddress; } - u32 getSize() const { return this->mSize; } - u32 getFreeSize() const { return this->mFreeSize; } - bool isTempMemory() const { return this->mIsTempMemory; } - void newGroupID(u8 groupID) { this->mGroupID = groupID; } + u32 getAddress() const { + return this->mAddress; + } + u32 getSize() const { + return this->mSize; + } + u32 getFreeSize() const { + return this->mFreeSize; + } + bool isTempMemory() const { + return this->mIsTempMemory; + } + void newGroupID(u8 groupID) { + this->mGroupID = groupID; + } - JSULink mLink; - u32 mAddress; - u32 mSize; - u32 mFreeSize; - u8 mGroupID; - bool mIsTempMemory; + JSULink mLink; + u32 mAddress; + u32 mSize; + u32 mFreeSize; + u8 mGroupID; + bool mIsTempMemory; - friend class JKRAramHeap; + friend class JKRAramHeap; }; -class JKRAramHeap : public JKRDisposer -{ -public: - enum EAllocMode - { - Head = 0, - Tail = 1 - }; +class JKRAramHeap : public JKRDisposer { + public: + enum EAllocMode { Head = 0, Tail = 1 }; - JKRAramHeap(u32 baseAddress, u32 size); + JKRAramHeap(u32 baseAddress, u32 size); - virtual ~JKRAramHeap(); + virtual ~JKRAramHeap(); - JKRAramBlock* alloc(u32 size, EAllocMode mode); - void free(JKRAramBlock* block); - JKRAramBlock* allocFromHead(u32 size); - JKRAramBlock* allocFromTail(u32 size); - u32 getFreeSize(); - u32 getTotalFreeSize(); - u32 getUsedSize(u8 groupID); - void dump(); + JKRAramBlock* alloc(u32 size, EAllocMode mode); + void free(JKRAramBlock* block); + JKRAramBlock* allocFromHead(u32 size); + JKRAramBlock* allocFromTail(u32 size); + u32 getFreeSize(); + u32 getTotalFreeSize(); + u32 getUsedSize(u8 groupID); + void dump(); - u8 getCurrentGroupID() const { return this->mGroupID; } - JKRHeap* getMgrHeap() const { return this->mHeap; } + u8 getCurrentGroupID() const { + return this->mGroupID; + } + JKRHeap* getMgrHeap() const { + return this->mHeap; + } - void lock() { OSLockMutex(&this->mMutex); } - void unlock() { OSUnlockMutex(&this->mMutex); } + void lock() { + OSLockMutex(&this->mMutex); + } + void unlock() { + OSUnlockMutex(&this->mMutex); + } - static JSUList sAramList; + static JSUList sAramList; - OSMutex mMutex; - JKRHeap* mHeap; - u32 mHeadAddress; - u32 mTailAddress; - u32 mSize; - u8 mGroupID; + OSMutex mMutex; + JKRHeap* mHeap; + u32 mHeadAddress; + u32 mTailAddress; + u32 mSize; + u8 mGroupID; - friend class JKRAramBlock; + friend class JKRAramBlock; }; -class JKRAram : public JKRThread -{ -public: - JKRAram(u32, u32, long); +class JKRAram : public JKRThread { + public: + JKRAram(u32, u32, long); - virtual ~JKRAram(); // _08 - virtual void* run(); // _0C + virtual ~JKRAram(); // _08 + virtual void* run(); // _0C - static bool checkOkAddress(u8* addr, u32 size, JKRAramBlock* block, u32 param_4); - static void changeGroupIdIfNeed(u8* data, int groupId); + static bool checkOkAddress(u8* addr, u32 size, JKRAramBlock* block, u32 param_4); + static void changeGroupIdIfNeed(u8* data, int groupId); - static JKRAram* create(u32, u32, long, long, long); - static JKRAramBlock* mainRamToAram(u8*, u32, u32, JKRExpandSwitch, u32, JKRHeap*, int); - static JKRAramBlock* mainRamToAram(u8*, JKRAramBlock* block, u32, JKRExpandSwitch, u32, JKRHeap*, int); - static u8* aramToMainRam(u32, u8*, u32, JKRExpandSwitch, u32, JKRHeap*, int, u32*); - static u8* aramToMainRam(JKRAramBlock*, u8*, u32, u32, JKRExpandSwitch, u32, JKRHeap*, int, u32*); + static JKRAram* create(u32, u32, long, long, long); + static JKRAramBlock* mainRamToAram(u8*, u32, u32, JKRExpandSwitch, u32, JKRHeap*, int); + static JKRAramBlock* mainRamToAram(u8*, JKRAramBlock* block, u32, JKRExpandSwitch, u32, JKRHeap*, int); + static u8* aramToMainRam(u32, u8*, u32, JKRExpandSwitch, u32, JKRHeap*, int, u32*); + static u8* aramToMainRam(JKRAramBlock*, u8*, u32, u32, JKRExpandSwitch, u32, JKRHeap*, int, u32*); - void aramSync(JKRAMCommand*, int); + void aramSync(JKRAMCommand*, int); - u32 getAudioMemory() const - { - return mAudioMemoryPtr; - } + u32 getAudioMemory() const { + return mAudioMemoryPtr; + } - u32 getAudioMemSize() const - { - return mAudioMemorySize; - } + u32 getAudioMemSize() const { + return mAudioMemorySize; + } - static u32 getSZSBufferSize() - { - return sSZSBufferSize; - } + static u32 getSZSBufferSize() { + return sSZSBufferSize; + } - static JKRAramHeap* getAramHeap() - { - return sAramObject->mAramHeap; - } + static JKRAramHeap* getAramHeap() { + return sAramObject->mAramHeap; + } - static JKRAram* getManager() - { - return sAramObject; - } + static JKRAram* getManager() { + return sAramObject; + } - static u8 decideAramGroupId(int id) - { - if (id < 0) - return getAramHeap()->getCurrentGroupID(); - else - return id; - } + static u8 decideAramGroupId(int id) { + if (id < 0) + return getAramHeap()->getCurrentGroupID(); + else + return id; + } - static u32 sSZSBufferSize; + static u32 sSZSBufferSize; - static JKRAram* sAramObject; - static OSMessage sMessageBuffer[4]; - static OSMessageQueue sMessageQueue; - static JSUList sAramCommandList; + static JKRAram* sAramObject; + static OSMessage sMessageBuffer[4]; + static OSMessageQueue sMessageQueue; + static JSUList sAramCommandList; - u32 mAudioMemoryPtr; // _7C - u32 mAudioMemorySize; // _80 - u32 mGraphMemoryPtr; // _84 - u32 mGraphMemorySize; // _88 - u32 mUserMemoryPtr; // _8C - u32 mUserMemorySize; // _90 - JKRAramHeap* mAramHeap; // _94 - u32 mStackArray[3]; // _98 + u32 mAudioMemoryPtr; // _7C + u32 mAudioMemorySize; // _80 + u32 mGraphMemoryPtr; // _84 + u32 mGraphMemorySize; // _88 + u32 mUserMemoryPtr; // _8C + u32 mUserMemorySize; // _90 + JKRAramHeap* mAramHeap; // _94 + u32 mStackArray[3]; // _98 }; -class JKRAMCommand : public ARQRequest -{ -public: - typedef void (*AMCommandCallback)(u32); +class JKRAMCommand : public ARQRequest { + public: + typedef void (*AMCommandCallback)(u32); - JKRAMCommand(); - ~JKRAMCommand(); + JKRAMCommand(); + ~JKRAMCommand(); - JSULink mAramPieceCommandLink; - JSULink mLink30; - s32 mDirection; - u32 mLength; - u32 mSource; - u32 mDestination; - JKRAramBlock* mAramBlock; - u8 _54[4]; - AMCommandCallback mCallback; - OSMessageQueue* mCompletedMesgQueue; - s32 mCallbackType; - JKRDecompCommand* mDecompCommand; - OSMessageQueue mMesgQueue; - OSMessage mMesgBuffer[1]; - void* _8C; - void* _90; - void* _94; + JSULink mAramPieceCommandLink; + JSULink mLink30; + s32 mDirection; + u32 mLength; + u32 mSource; + u32 mDestination; + JKRAramBlock* mAramBlock; + u8 _54[4]; + AMCommandCallback mCallback; + OSMessageQueue* mCompletedMesgQueue; + s32 mCallbackType; + JKRDecompCommand* mDecompCommand; + OSMessageQueue mMesgQueue; + OSMessage mMesgBuffer[1]; + void* _8C; + void* _90; + void* _94; }; -class JKRAramCommand -{ -public: - inline void setting(BOOL active, void* arg) - { - this->mActive = active; - this->mArg = arg; - } +class JKRAramCommand { + public: + inline void setting(BOOL active, void* arg) { + this->mActive = active; + this->mArg = arg; + } - BOOL mActive; - void* mArg; + BOOL mActive; + void* mArg; }; -class JKRAramPiece -{ -public: - static JKRAMCommand* prepareCommand(int direction, u32 source, u32 destination, u32 length, JKRAramBlock* aramBlock, JKRAMCommand::AMCommandCallback callback); - static void sendCommand(JKRAMCommand* cmd); - static JKRAMCommand* orderAsync(int direction, u32 source, u32 destination, u32 length, JKRAramBlock* aramBlock, JKRAMCommand::AMCommandCallback callback); - static bool sync(JKRAMCommand* cmd, BOOL noBlock); - static bool orderSync(int direction, u32 source, u32 destination, u32 length, JKRAramBlock* aramBlock); - static void startDMA(JKRAMCommand* cmd); - static void doneDMA(u32 arg); +class JKRAramPiece { + public: + static JKRAMCommand* prepareCommand(int direction, u32 source, u32 destination, u32 length, JKRAramBlock* aramBlock, + JKRAMCommand::AMCommandCallback callback); + static void sendCommand(JKRAMCommand* cmd); + static JKRAMCommand* orderAsync(int direction, u32 source, u32 destination, u32 length, JKRAramBlock* aramBlock, + JKRAMCommand::AMCommandCallback callback); + static bool sync(JKRAMCommand* cmd, BOOL noBlock); + static bool orderSync(int direction, u32 source, u32 destination, u32 length, JKRAramBlock* aramBlock); + static void startDMA(JKRAMCommand* cmd); + static void doneDMA(u32 arg); - static OSMutex mMutex; - static JSUList sAramPieceCommandList; + static OSMutex mMutex; + static JSUList sAramPieceCommandList; -private: - static void lock() { OSLockMutex(&mMutex); } - static void unlock() { OSUnlockMutex(&mMutex); } + private: + static void lock() { + OSLockMutex(&mMutex); + } + static void unlock() { + OSUnlockMutex(&mMutex); + } }; -class JKRAramStreamCommand -{ -public: - enum ECommandType - { - ECT_UNK = 0, - ECT_READ = 1, - ECT_WRITE = 2, - }; +class JKRAramStreamCommand { + public: + enum ECommandType { + ECT_UNK = 0, + ECT_READ = 1, + ECT_WRITE = 2, + }; - JKRAramStreamCommand(); + JKRAramStreamCommand(); - ECommandType type; // _00 - u32 mAddress; // _04 - u32 mSize; // _08 - u32 _0C; // _0C - JSUFileInputStream* mStream; // _10 - u32 mOffset; // _14 - u8* mTransferBuffer; // _18 - u32 mTransferBufferSize; // _1C - JKRHeap* mHeap; // _20 - bool mAllocatedTransferBuffer; // _24 - u32 _28; // _28 - OSMessageQueue mMessageQueue; // _2C - void* mMessage; // _4C - u32 _50; // _50 - u32 _54; // _54 + ECommandType type; // _00 + u32 mAddress; // _04 + u32 mSize; // _08 + u32 _0C; // _0C + JSUFileInputStream* mStream; // _10 + u32 mOffset; // _14 + u8* mTransferBuffer; // _18 + u32 mTransferBufferSize; // _1C + JKRHeap* mHeap; // _20 + bool mAllocatedTransferBuffer; // _24 + u32 _28; // _28 + OSMessageQueue mMessageQueue; // _2C + void* mMessage; // _4C + u32 _50; // _50 + u32 _54; // _54 }; -class JKRAramStream : public JKRThread -{ -public: - JKRAramStream(long); +class JKRAramStream : public JKRThread { + public: + JKRAramStream(long); - virtual ~JKRAramStream(); // _08 - virtual void* run(); // _0C + virtual ~JKRAramStream(); // _08 + virtual void* run(); // _0C - static JKRAramStream* create(s32); + static JKRAramStream* create(s32); - static u32 readFromAram(); - static s32 writeToAram(JKRAramStreamCommand*); - static JKRAramStreamCommand* write_StreamToAram_Async(JSUFileInputStream*, JKRAramBlock*, u32, u32); - static JKRAramStreamCommand* write_StreamToAram_Async(JSUFileInputStream*, u32, u32, u32); - static JKRAramStreamCommand* sync(JKRAramStreamCommand*, BOOL); - static void setTransBuffer(u8*, u32, JKRHeap*); + static u32 readFromAram(); + static s32 writeToAram(JKRAramStreamCommand*); + static JKRAramStreamCommand* write_StreamToAram_Async(JSUFileInputStream*, JKRAramBlock*, u32, u32); + static JKRAramStreamCommand* write_StreamToAram_Async(JSUFileInputStream*, u32, u32, u32); + static JKRAramStreamCommand* sync(JKRAramStreamCommand*, BOOL); + static void setTransBuffer(u8*, u32, JKRHeap*); - static JKRAramStream* sAramStreamObject; - static OSMessage sMessageBuffer[4]; - static OSMessageQueue sMessageQueue; + static JKRAramStream* sAramStreamObject; + static OSMessage sMessageBuffer[4]; + static OSMessageQueue sMessageQueue; - static u8* transBuffer; - static JKRHeap* transHeap; - static u32 transSize; + static u8* transBuffer; + static JKRHeap* transHeap; + static u32 transSize; - // _00 = VTBL - // _00-_7C = JKRThread + // _00 = VTBL + // _00-_7C = JKRThread }; -inline JKRAramBlock* JKRAllocFromAram(u32 size, JKRAramHeap::EAllocMode allocMode) -{ - return JKRAram::getAramHeap()->alloc(size, allocMode); +inline JKRAramBlock* JKRAllocFromAram(u32 size, JKRAramHeap::EAllocMode allocMode) { + return JKRAram::getAramHeap()->alloc(size, allocMode); } -inline void JKRFreeToAram(JKRAramBlock* block) -{ - JKRAram::getAramHeap()->free(block); +inline void JKRFreeToAram(JKRAramBlock* block) { + JKRAram::getAramHeap()->free(block); } -inline u8* JKRAramToMainRam(u32 address, u8* buf, u32 bufSize, JKRExpandSwitch expandSwitch, u32 p5, JKRHeap* heap, int id, u32* pSize) -{ - return JKRAram::aramToMainRam(address, buf, bufSize, expandSwitch, p5, heap, id, pSize); +inline u8* JKRAramToMainRam(u32 address, u8* buf, u32 bufSize, JKRExpandSwitch expandSwitch, u32 p5, JKRHeap* heap, + int id, u32* pSize) { + return JKRAram::aramToMainRam(address, buf, bufSize, expandSwitch, p5, heap, id, pSize); } -inline JKRAramBlock* JKRMainRamToAram(u8* buf, u32 bufSize, u32 alignedSize, JKRExpandSwitch expandSwitch, u32 fileSize, JKRHeap* heap, int id, u32) -{ - return JKRAram::mainRamToAram(buf, bufSize, alignedSize, expandSwitch, fileSize, heap, id); +inline JKRAramBlock* JKRMainRamToAram(u8* buf, u32 bufSize, u32 alignedSize, JKRExpandSwitch expandSwitch, u32 fileSize, + JKRHeap* heap, int id, u32) { + return JKRAram::mainRamToAram(buf, bufSize, alignedSize, expandSwitch, fileSize, heap, id); } -inline JKRAramStream* JKRCreateAramStreamManager(s32 priority) -{ - return JKRAramStream::create(priority); +inline JKRAramStream* JKRCreateAramStreamManager(s32 priority) { + return JKRAramStream::create(priority); } -inline bool JKRAramPcs(int direction, u32 source, u32 destination, u32 length, JKRAramBlock* block) -{ - return JKRAramPiece::orderSync(direction, source, destination, length, block); +inline bool JKRAramPcs(int direction, u32 source, u32 destination, u32 length, JKRAramBlock* block) { + return JKRAramPiece::orderSync(direction, source, destination, length, block); } -inline void JKRAramPcs_SendCommand(JKRAMCommand* cmd) -{ - JKRAramPiece::sendCommand(cmd); +inline void JKRAramPcs_SendCommand(JKRAMCommand* cmd) { + JKRAramPiece::sendCommand(cmd); } #endif diff --git a/include/JSystem/JKernel/JKRArchive.h b/include/JSystem/JKernel/JKRArchive.h index 752078f7..fc080db2 100644 --- a/include/JSystem/JKernel/JKRArchive.h +++ b/include/JSystem/JKernel/JKRArchive.h @@ -12,17 +12,14 @@ #define JKRARCHIVE_ATTR_COMPRESSION 0x04 #define JKRARCHIVE_ATTR_YAY0 0x80 -inline u32 read_big_endian_u32(void* ptr) -{ +inline u32 read_big_endian_u32(void* ptr) { u8* uptr = (u8*)ptr; return ((u32)uptr[0] << 0x18) | ((u32)uptr[1] << 0x10) | ((u32)uptr[2] << 8) | (u32)uptr[3]; } -class JKRArchive : public JKRFileLoader -{ -public: - enum EMountMode - { +class JKRArchive : public JKRFileLoader { + public: + enum EMountMode { UNKNOWN_MOUNT_MODE = 0, MOUNT_MEM = 1, MOUNT_ARAM = 2, @@ -30,26 +27,33 @@ public: MOUNT_COMP = 4, }; - enum EMountDirection - { + enum EMountDirection { UNKNOWN_MOUNT_DIRECTION = 0, MOUNT_DIRECTION_HEAD = 1, MOUNT_DIRECTION_TAIL = 2, }; - class CArcName - { - public: - CArcName(const char** p1, char p2) { p1[0] = store(p1[0], p2); } + class CArcName { + public: + CArcName(const char** p1, char p2) { + p1[0] = store(p1[0], p2); + } - const char* getString() const { return mString; } - u16 getHash() const { return mHash; } + const char* getString() const { + return mString; + } + u16 getHash() const { + return mHash; + } void store(const char*); const char* store(const char*, char); // Unused/inlined: - CArcName() {} - CArcName(const char* data) { store(data); } + CArcName() { + } + CArcName(const char* data) { + store(data); + } u16 mHash; // _00 u16 _02; // _02 @@ -57,23 +61,50 @@ public: u8 _104[4]; // _104, unknown, used to fix stack size }; - struct SDIFileEntry - { - u16 getNameHash() const { return mHash; } - u32 getNameOffset() const { return mFlag & 0xFFFFFF; } - u32 getFlags() const { return mFlag >> 24; } - u32 getAttr() const { return getFlags(); } - u32 getSize() { return mSize; } - u16 getFileID() const { return mFileID; } - bool isDirectory() const { return (getFlags() & 0x02) != 0; } - bool isCompressed() const { return (getFlags() & 0x04) != 0; } - u8 getCompressFlag() const { return (getFlags() & 0x04); } // apparently both necessary? - bool isYAZ0Compressed() const { return (getFlags() & 0x80) != 0; } + struct SDIFileEntry { + u16 getNameHash() const { + return mHash; + } + u32 getNameOffset() const { + return mFlag & 0xFFFFFF; + } + u32 getFlags() const { + return mFlag >> 24; + } + u32 getAttr() const { + return getFlags(); + } + u32 getSize() { + return mSize; + } + u16 getFileID() const { + return mFileID; + } + bool isDirectory() const { + return (getFlags() & 0x02) != 0; + } + bool isCompressed() const { + return (getFlags() & 0x04) != 0; + } + u8 getCompressFlag() const { + return (getFlags() & 0x04); + } // apparently both necessary? + bool isYAZ0Compressed() const { + return (getFlags() & 0x80) != 0; + } - bool getFlag01() const { return (getFlags() & 0x01) != 0; } - bool getFlag04() { return mFlag >> 0x18 & 0x04; } - bool getFlag10() { return mFlag >> 0x18 & 0x10; } - bool getFlag80() { return mFlag >> 0x18 & 0x80; } + bool getFlag01() const { + return (getFlags() & 0x01) != 0; + } + bool getFlag04() { + return mFlag >> 0x18 & 0x04; + } + bool getFlag10() { + return mFlag >> 0x18 & 0x10; + } + bool getFlag80() { + return mFlag >> 0x18 & 0x80; + } u16 mFileID; // _00 u16 mHash; // _02 @@ -83,16 +114,14 @@ public: void* mData; // _10 }; - struct SDirEntry - { + struct SDirEntry { u8 mFlags; // _00 u8 _01; // _01 u16 mID; // _02 char* mName; // _04 }; - struct SDIDirEntry - { + struct SDIDirEntry { u32 mType; // _00 u32 mOffset; // _04 u16 _08; // _08 @@ -101,8 +130,7 @@ public: }; // NB: Fabricated name - struct SArcDataInfo - { + struct SArcDataInfo { u32 num_nodes; // _00 u32 node_offset; // _04 u32 num_file_entries; // _08 @@ -115,8 +143,7 @@ public: }; // NB: Fabricated name - need to check size - struct SArcHeader - { + struct SArcHeader { u32 signature; // _00 u32 file_length; // _04 u32 header_length; // _08 @@ -127,26 +154,28 @@ public: u32 _1C; // _1C }; -public: - virtual bool becomeCurrent(const char*); // _10 - virtual void* getResource(const char* path); // _14 - virtual void* getResource(u32 type, const char* name); // _18 - virtual size_t readResource(void* resourceBuffer, u32 bufferSize, const char* path, JKRExpandSwitch expandSwitch); // _1C - virtual size_t readResource(void* resourceBuffer, u32 bufferSize, u32 type, const char* name); // _20 - virtual void removeResourceAll(); // _24 - virtual bool removeResource(void*); // _28 - virtual bool detachResource(void*); // _2C - virtual s32 getResSize(const void*) const; // _30 - virtual u32 countFile(const char*) const; // _34 - virtual JKRFileFinder* getFirstFile(const char*) const; // _38 - virtual void* fetchResource(SDIFileEntry* entry, u32* outSize) = 0; // _40 - virtual void* fetchResource(void* resourceBuffer, u32 bufferSize, SDIFileEntry* entry, u32* resSize, JKRExpandSwitch expandSwitch) = 0; // _44 + public: + virtual bool becomeCurrent(const char*); // _10 + virtual void* getResource(const char* path); // _14 + virtual void* getResource(u32 type, const char* name); // _18 + virtual size_t readResource(void* resourceBuffer, u32 bufferSize, const char* path, + JKRExpandSwitch expandSwitch); // _1C + virtual size_t readResource(void* resourceBuffer, u32 bufferSize, u32 type, const char* name); // _20 + virtual void removeResourceAll(); // _24 + virtual bool removeResource(void*); // _28 + virtual bool detachResource(void*); // _2C + virtual s32 getResSize(const void*) const; // _30 + virtual u32 countFile(const char*) const; // _34 + virtual JKRFileFinder* getFirstFile(const char*) const; // _38 + virtual void* fetchResource(SDIFileEntry* entry, u32* outSize) = 0; // _40 + virtual void* fetchResource(void* resourceBuffer, u32 bufferSize, SDIFileEntry* entry, u32* resSize, + JKRExpandSwitch expandSwitch) = 0; // _44 JKRArchive(s32, EMountMode); JKRArchive(); JKRArchive(const char* p1, EMountMode mountMode); ~JKRArchive(); - + SDIDirEntry* findDirectory(const char*, u32) const; SDIFileEntry* findFsResource(const char*, u32) const; SDIFileEntry* findIdResource(u16) const; @@ -170,8 +199,7 @@ public: SDIDirEntry* findResType(u32) const; SDIFileEntry* findTypeResource(u32, u32) const; - static int convertAttrToCompressionType(int attr) - { + static int convertAttrToCompressionType(int attr) { int compression; if (FLAG_ON(attr, JKRARCHIVE_ATTR_COMPRESSION)) compression = JKRCOMPRESSION_NONE; @@ -183,15 +211,25 @@ public: return compression; } - u32 getMountMode() const { return mMountMode; } - u32 countFile() const { return mArcInfoBlock->num_file_entries; } - int countDirectory() const { return mArcInfoBlock->num_nodes; } - static u32 getCurrentDirID() { return sCurrentDirID; } - static void setCurrentDirID(u32 dirID) { sCurrentDirID = dirID; } + u32 getMountMode() const { + return mMountMode; + } + u32 countFile() const { + return mArcInfoBlock->num_file_entries; + } + int countDirectory() const { + return mArcInfoBlock->num_nodes; + } + static u32 getCurrentDirID() { + return sCurrentDirID; + } + static void setCurrentDirID(u32 dirID) { + sCurrentDirID = dirID; + } static u32 sCurrentDirID; -protected: + protected: // _00 = VTBL // _00-_38 = JKRFileLoader JKRHeap* mHeap; // _38 @@ -206,20 +244,15 @@ protected: EMountDirection mMountDirection; // _5C }; -enum JKRMemBreakFlag -{ - MBF_0 = 0, - MBF_1 = 1 -}; +enum JKRMemBreakFlag { MBF_0 = 0, MBF_1 = 1 }; -class JKRAramArchive : public JKRArchive -{ -public: +class JKRAramArchive : public JKRArchive { + public: JKRAramArchive(); JKRAramArchive(s32, EMountDirection); - virtual ~JKRAramArchive(); // _08 - virtual void* fetchResource(SDIFileEntry*, u32*); // _40 + virtual ~JKRAramArchive(); // _08 + virtual void* fetchResource(SDIFileEntry*, u32*); // _40 virtual void* fetchResource(void*, u32, SDIFileEntry*, u32*, JKRExpandSwitch expandSwitch); // _44 bool open(s32); @@ -239,15 +272,15 @@ public: JKRFile* mDvdFile; // _64 }; -struct JKRCompArchive : public JKRArchive -{ +struct JKRCompArchive : public JKRArchive { JKRCompArchive(s32, EMountDirection); - virtual ~JKRCompArchive(); // _08 - virtual void removeResourceAll(); // _24 - virtual bool removeResource(void*); // _28 - virtual void* fetchResource(SDIFileEntry* entry, u32* outSize); // _40 - virtual void* fetchResource(void* resourceBuffer, u32 bufferSize, SDIFileEntry* entry, u32* resSize, JKRExpandSwitch expandSwitch); // _44 + virtual ~JKRCompArchive(); // _08 + virtual void removeResourceAll(); // _24 + virtual bool removeResource(void*); // _28 + virtual void* fetchResource(SDIFileEntry* entry, u32* outSize); // _40 + virtual void* fetchResource(void* resourceBuffer, u32 bufferSize, SDIFileEntry* entry, u32* resSize, + JKRExpandSwitch expandSwitch); // _44 bool open(s32); @@ -259,23 +292,23 @@ struct JKRCompArchive : public JKRArchive // _00 = VTBL // _00-_5C = JKRArchive - u32 _60; // _60 - JKRAramBlock* mAramPart; // _64 - u32 _68; // _68 - JKRFile* mDvdFile; // _6C - u32 mSizeOfMemPart; // _70 - u32 mSizeOfAramPart; // _74 - u32 _78; // _78 + u32 _60; // _60 + JKRAramBlock* mAramPart; // _64 + u32 _68; // _68 + JKRFile* mDvdFile; // _6C + u32 mSizeOfMemPart; // _70 + u32 mSizeOfAramPart; // _74 + u32 _78; // _78 }; -struct JKRDvdArchive : public JKRArchive -{ +struct JKRDvdArchive : public JKRArchive { JKRDvdArchive(); JKRDvdArchive(s32, JKRArchive::EMountDirection); - virtual ~JKRDvdArchive(); // _00 - virtual void* fetchResource(SDIFileEntry* entry, u32* outSize); // _38 - virtual void* fetchResource(void* resourceBuffer, u32 bufferSize, SDIFileEntry* entry, u32* resSize, JKRExpandSwitch expandSwitch); // _3C + virtual ~JKRDvdArchive(); // _00 + virtual void* fetchResource(SDIFileEntry* entry, u32* outSize); // _38 + virtual void* fetchResource(void* resourceBuffer, u32 bufferSize, SDIFileEntry* entry, u32* resSize, + JKRExpandSwitch expandSwitch); // _3C bool open(s32); static u32 fetchResource_subroutine(s32, u32, u32, u8*, u32, int, int); @@ -289,22 +322,22 @@ struct JKRDvdArchive : public JKRArchive // _00 = VTBL // _00-_5C = JKRArchive - int _60; // _60 - JKRFile* mDvdFile; // _64 + int _60; // _60 + JKRFile* mDvdFile; // _64 }; -struct JKRMemArchive : public JKRArchive -{ +struct JKRMemArchive : public JKRArchive { JKRMemArchive(); // unused/inlined JKRMemArchive(s32, EMountDirection); JKRMemArchive(void*, u32, JKRMemBreakFlag); JKRMemArchive(const char*, EMountDirection); // unused/inlined - virtual ~JKRMemArchive(); // _08 - virtual void removeResourceAll(); // _24 - virtual bool removeResource(void*); // _28 - virtual void* fetchResource(SDIFileEntry* entry, u32* outSize); // _40 - virtual void* fetchResource(void* resourceBuffer, u32 bufferSize, SDIFileEntry* entry, u32* resSize, JKRExpandSwitch expandSwitch); // _44 + virtual ~JKRMemArchive(); // _08 + virtual void removeResourceAll(); // _24 + virtual bool removeResource(void*); // _28 + virtual void* fetchResource(SDIFileEntry* entry, u32* outSize); // _40 + virtual void* fetchResource(void* resourceBuffer, u32 bufferSize, SDIFileEntry* entry, u32* resSize, + JKRExpandSwitch expandSwitch); // _44 bool open(s32, EMountDirection); bool open(void*, u32, JKRMemBreakFlag); @@ -320,23 +353,21 @@ struct JKRMemArchive : public JKRArchive // _00 = VTBL // _00-_60 = JKRArchive - SArcHeader* mArcHeader; // _60 - u8* mArchiveData; // _64 - bool mIsOpen; // _68 + SArcHeader* mArcHeader; // _60 + u8* mArchiveData; // _64 + bool mIsOpen; // _68 }; -inline int JKRConvertAttrToCompressionType(int attr) -{ +inline int JKRConvertAttrToCompressionType(int attr) { return JKRArchive::convertAttrToCompressionType(attr); } -inline JKRArchive* JKRMountArchive(const char* path, JKRArchive::EMountMode mountMode, JKRHeap* heap, JKRArchive::EMountDirection mountDirection) -{ +inline JKRArchive* JKRMountArchive(const char* path, JKRArchive::EMountMode mountMode, JKRHeap* heap, + JKRArchive::EMountDirection mountDirection) { return JKRArchive::mount(path, mountMode, heap, mountDirection); } -inline JKRArchive* JKRMountArchive(void* inBuf, JKRHeap* heap, JKRArchive::EMountDirection mountDirection) -{ +inline JKRArchive* JKRMountArchive(void* inBuf, JKRHeap* heap, JKRArchive::EMountDirection mountDirection) { return JKRArchive::mount(inBuf, heap, mountDirection); } diff --git a/include/JSystem/JKernel/JKRDecomp.h b/include/JSystem/JKernel/JKRDecomp.h index 8a3e6497..7ed5e688 100644 --- a/include/JSystem/JKernel/JKRDecomp.h +++ b/include/JSystem/JKernel/JKRDecomp.h @@ -13,96 +13,92 @@ #define JKRDECOMP_STACK_SIZE 0x4000 #define JKRDECOMP_THREAD_MSG_BUF_COUNT 16 -#define JKRDECOMP_READU32BE(ptr, offset) (((u32)ptr[offset] << 24) | ((u32)ptr[offset + 1] << 16) | ((u32)ptr[offset + 2] << 8) | (u32)ptr[offset + 3]) +#define JKRDECOMP_READU32BE(ptr, offset) \ + (((u32)ptr[offset] << 24) | ((u32)ptr[offset + 1] << 16) | ((u32)ptr[offset + 2] << 8) | (u32)ptr[offset + 3]) #define SZ_MIN_BACKSIZE 3 #define SZ_DEFAULT_BACKSIZE 15 + SZ_MIN_BACKSIZE -#define SZP_GETBACKOFS(buf) (((*((u8*)buf) & 0xF) << 8) | (*(((u8*)buf)+1))) +#define SZP_GETBACKOFS(buf) (((*((u8*)buf) & 0xF) << 8) | (*(((u8*)buf) + 1))) #define SZP_GETCOUNT(buf) (*((u16*)buf) >> 12) typedef void DecompCallback(u32); class JKRDecompCommand { -public: - enum TransferType { - MRAM = 0, - ARAM = 1 - }; + public: + enum TransferType { MRAM = 0, ARAM = 1 }; - JKRDecompCommand(); - ~JKRDecompCommand(); + JKRDecompCommand(); + ~JKRDecompCommand(); - u8 _00[4]; - u8* mSrcBuffer; - u8* mDstBuffer; - u32 mSrcLength; - u32 mSkipCount; - DecompCallback* mCallback; - JKRDecompCommand* mCmd; - OSMessageQueue* pMesgQueue1C; - TransferType transferType; - JKRAMCommand* mAMCommand; - OSMessageQueue mMesgQueue; - OSMessage mMesgBuffer[1]; + u8 _00[4]; + u8* mSrcBuffer; + u8* mDstBuffer; + u32 mSrcLength; + u32 mSkipCount; + DecompCallback* mCallback; + JKRDecompCommand* mCmd; + OSMessageQueue* pMesgQueue1C; + TransferType transferType; + JKRAMCommand* mAMCommand; + OSMessageQueue mMesgQueue; + OSMessage mMesgBuffer[1]; }; class JKRDecomp : public JKRThread { -public: - enum CompressionMode { - NONE = 0, - SZP = 1, - SZS = 2 - }; + public: + enum CompressionMode { NONE = 0, SZP = 1, SZS = 2 }; - JKRDecomp(s32 decompPriority); + JKRDecomp(s32 decompPriority); - virtual ~JKRDecomp(); + virtual ~JKRDecomp(); - virtual void* run(); + virtual void* run(); - static JKRDecompCommand* prepareCommand(u8* srcBuffer, u8* dstBuffer, u32 srcLength, u32 skipCount, DecompCallback* callback); - static CompressionMode checkCompressed(u8* buf); - static JKRDecomp* create(s32 decompPriority); - static void decode(u8* srcBuffer, u8* dstBuffer, u32 srcLength, u32 skipCount); - static void decodeSZP(u8* srcBuffer, u8* dstBuffer, u32 srcLength, u32 skipCount); - static void decodeSZS(u8* srcBuffer, u8* dstBuffer, u32 srcLength, u32 skipCount); - static bool orderSync(u8* srcBuffer, u8* dstBuffer, u32 srcLength, u32 skipCount); - static JKRDecompCommand* orderAsync(u8* srcBuffer, u8* dstBuffer, u32 srcLength, u32 skipCount, DecompCallback* callback); - static bool sync(JKRDecompCommand* cmd, BOOL noBlock); - static BOOL sendCommand(JKRDecompCommand* cmd); + static JKRDecompCommand* prepareCommand(u8* srcBuffer, u8* dstBuffer, u32 srcLength, u32 skipCount, + DecompCallback* callback); + static CompressionMode checkCompressed(u8* buf); + static JKRDecomp* create(s32 decompPriority); + static void decode(u8* srcBuffer, u8* dstBuffer, u32 srcLength, u32 skipCount); + static void decodeSZP(u8* srcBuffer, u8* dstBuffer, u32 srcLength, u32 skipCount); + static void decodeSZS(u8* srcBuffer, u8* dstBuffer, u32 srcLength, u32 skipCount); + static bool orderSync(u8* srcBuffer, u8* dstBuffer, u32 srcLength, u32 skipCount); + static JKRDecompCommand* orderAsync(u8* srcBuffer, u8* dstBuffer, u32 srcLength, u32 skipCount, + DecompCallback* callback); + static bool sync(JKRDecompCommand* cmd, BOOL noBlock); + static BOOL sendCommand(JKRDecompCommand* cmd); - static OSMessageQueue sMessageQueue; - static OSMessage sMessageBuffer[JKRDECOMP_MSG_BUF_COUNT]; - static JKRDecomp* sDecompObject; + static OSMessageQueue sMessageQueue; + static OSMessage sMessageBuffer[JKRDECOMP_MSG_BUF_COUNT]; + static JKRDecomp* sDecompObject; }; inline JKRDecomp* JKRCreateDecompManager(s32 priority) { - return JKRDecomp::create(priority); + return JKRDecomp::create(priority); } -inline int JKRCheckCompressed_noASR(u8* pBuf) -{ - int compression = JKRDecomp::checkCompressed(pBuf); - if (compression == JKRCOMPRESSION_ASR) - compression = JKRCOMPRESSION_NONE; - return compression; +inline int JKRCheckCompressed_noASR(u8* pBuf) { + int compression = JKRDecomp::checkCompressed(pBuf); + if (compression == JKRCOMPRESSION_ASR) + compression = JKRCOMPRESSION_NONE; + return compression; } inline JKRDecomp::CompressionMode JKRCheckCompressed(u8* buf) { - return JKRDecomp::checkCompressed(buf); + return JKRDecomp::checkCompressed(buf); } inline u32 JKRDecompExpandSize(u8* buf) { - return (buf[4] << 24) | (buf[5] << 16) | (buf[6] << 8) | buf[7]; + return (buf[4] << 24) | (buf[5] << 16) | (buf[6] << 8) | buf[7]; } inline void JKRDecompress(u8* src, u8* dst, u32 srcLength, u32 skipCount) { - JKRDecomp::orderSync(src, dst, srcLength, skipCount); + JKRDecomp::orderSync(src, dst, srcLength, skipCount); } int JKRDecompressFromDVD(JKRDvdFile* srcFile, void* buf, u32 size, u32 maxDest, u32 fileOffset, u32 srcOffset); -int JKRDecompressFromDVDToAram(JKRDvdFile* srcFile, u32 address, u32 fileSize, u32 maxDest, u32 fileOffset, u32 srcOffset); +int JKRDecompressFromDVDToAram(JKRDvdFile* srcFile, u32 address, u32 fileSize, u32 maxDest, u32 fileOffset, + u32 srcOffset); int JKRDecompressFromAramToMainRam(u32 srcAddress, void* dst, u32 fileSize, u32 maxDest, u32 fileOffset); #endif diff --git a/include/JSystem/JKernel/JKRDisposer.h b/include/JSystem/JKernel/JKRDisposer.h index d7ac2894..46eaab76 100644 --- a/include/JSystem/JKernel/JKRDisposer.h +++ b/include/JSystem/JKernel/JKRDisposer.h @@ -9,17 +9,15 @@ extern "C" { class JKRHeap; -class JKRDisposer -{ -public: +class JKRDisposer { + public: JKRDisposer(); virtual ~JKRDisposer(); -public: + public: JKRHeap* mRootHeap; // _4 JSULink mPointerLinks; // _8 }; - } #endif diff --git a/include/JSystem/JKernel/JKRDvdAramRipper.h b/include/JSystem/JKernel/JKRDvdAramRipper.h index d9cead77..658dcc19 100644 --- a/include/JSystem/JKernel/JKRDvdAramRipper.h +++ b/include/JSystem/JKernel/JKRDvdAramRipper.h @@ -7,9 +7,8 @@ #include "types.h" #ifdef __cplusplus -class JKRADCommand -{ -public: +class JKRADCommand { + public: typedef void (*LoadCallback)(u32); JKRADCommand(); ~JKRADCommand(); @@ -30,9 +29,8 @@ public: JKRAramStreamCommand* mStreamCommand; // _48 }; -class JKRDvdAramRipper -{ -public: +class JKRDvdAramRipper { + public: static JKRAramBlock* loadToAram(char const*, u32, JKRExpandSwitch, u32, u32); static JKRAramBlock* loadToAram(s32, u32, JKRExpandSwitch, u32, u32); static JKRAramBlock* loadToAram(JKRDvdFile*, u32, JKRExpandSwitch, u32, u32); @@ -47,16 +45,19 @@ public: static void countLeftSync(); static void afterAramAsync(JKRADCommand*); - static int getSZSBufferSize() { return sSZSBufferSize; } - static bool isErrorRetry() { return errorRetry; } + static int getSZSBufferSize() { + return sSZSBufferSize; + } + static bool isErrorRetry() { + return errorRetry; + } static bool errorRetry; static int sSZSBufferSize; static JSUList sDvdAramAsyncList; }; -inline JKRAramBlock* JKRDvdToAram(s32 entrynum, u32 p2, JKRExpandSwitch expSwitch, u32 p4, u32 p5) -{ +inline JKRAramBlock* JKRDvdToAram(s32 entrynum, u32 p2, JKRExpandSwitch expSwitch, u32 p4, u32 p5) { return JKRDvdAramRipper::loadToAram(entrynum, p2, expSwitch, p4, p5); } diff --git a/include/JSystem/JKernel/JKRDvdFile.h b/include/JSystem/JKernel/JKRDvdFile.h index d086a9c9..f39a43ab 100644 --- a/include/JSystem/JKernel/JKRDvdFile.h +++ b/include/JSystem/JKernel/JKRDvdFile.h @@ -9,73 +9,76 @@ class JKRDvdFile; struct JKRDvdFileInfo : public DVDFileInfo { - JKRDvdFile* mFile; + JKRDvdFile* mFile; }; class JKRDvdFile : public JKRFile { -public: - JKRDvdFile(); - JKRDvdFile(const char* filename); - JKRDvdFile(s32 entrynum); + public: + JKRDvdFile(); + JKRDvdFile(const char* filename); + JKRDvdFile(s32 entrynum); - virtual ~JKRDvdFile(); + virtual ~JKRDvdFile(); - virtual bool open(const char* filename); - virtual bool close(); - virtual int readData(void* data, s32 length, s32 ofs); - virtual int writeData(const void* data, s32 length, s32 ofs); - virtual u32 getFileSize() const { return this->mDvdFileInfo.length; } - virtual bool open(s32 entrynum); - - inline DVDFileInfo* getFileInfo() { - return &this->mDvdFileInfo; - } - - inline int readDataAsync(void* addr, s32 length, s32 offset) { - OSLockMutex(&this->mDvdMutex); - s32 retAddr; - - if (this->mDvdThread != nullptr) { - OSUnlockMutex(&this->mDvdMutex); - retAddr = -1; + virtual bool open(const char* filename); + virtual bool close(); + virtual int readData(void* data, s32 length, s32 ofs); + virtual int writeData(const void* data, s32 length, s32 ofs); + virtual u32 getFileSize() const { + return this->mDvdFileInfo.length; } - else { - this->mDvdThread = OSGetCurrentThread(); - retAddr = -1; - if (DVDReadAsync(&this->mDvdFileInfo, addr, length, offset, JKRDvdFile::doneProcess)) { - retAddr = this->sync(); - } + virtual bool open(s32 entrynum); - this->mDvdThread = nullptr; - OSUnlockMutex(&this->mDvdMutex); + inline DVDFileInfo* getFileInfo() { + return &this->mDvdFileInfo; } - return retAddr; - } + inline int readDataAsync(void* addr, s32 length, s32 offset) { + OSLockMutex(&this->mDvdMutex); + s32 retAddr; - inline int writeDataAsync(const void* data, s32 length, s32 offset) { return -1; } + if (this->mDvdThread != nullptr) { + OSUnlockMutex(&this->mDvdMutex); + retAddr = -1; + } else { + this->mDvdThread = OSGetCurrentThread(); + retAddr = -1; + if (DVDReadAsync(&this->mDvdFileInfo, addr, length, offset, JKRDvdFile::doneProcess)) { + retAddr = this->sync(); + } - void initiate(); - s32 sync(); + this->mDvdThread = nullptr; + OSUnlockMutex(&this->mDvdMutex); + } - static void doneProcess(s32 result, DVDFileInfo* info); + return retAddr; + } - static JSUList sDvdList; + inline int writeDataAsync(const void* data, s32 length, s32 offset) { + return -1; + } -public: - OSMutex mDvdMutex; - OSMutex mAramMutex; - JKRAramBlock* mAramBlock; - OSThread* mAramThread; - JSUFileInputStream* mInputStream; - u32 _58; - JKRDvdFileInfo mDvdFileInfo; - OSMessageQueue mAramMessageQueue; - OSMessage mAramMessage; - OSMessageQueue mDvdMessageQueue; - OSMessage mDvdMessage; - JSULink mLink; - OSThread* mDvdThread; + void initiate(); + s32 sync(); + + static void doneProcess(s32 result, DVDFileInfo* info); + + static JSUList sDvdList; + + public: + OSMutex mDvdMutex; + OSMutex mAramMutex; + JKRAramBlock* mAramBlock; + OSThread* mAramThread; + JSUFileInputStream* mInputStream; + u32 _58; + JKRDvdFileInfo mDvdFileInfo; + OSMessageQueue mAramMessageQueue; + OSMessage mAramMessage; + OSMessageQueue mDvdMessageQueue; + OSMessage mDvdMessage; + JSULink mLink; + OSThread* mDvdThread; }; #endif diff --git a/include/JSystem/JKernel/JKRDvdRipper.h b/include/JSystem/JKernel/JKRDvdRipper.h index 8699bc5e..cc8aca11 100644 --- a/include/JSystem/JKernel/JKRDvdRipper.h +++ b/include/JSystem/JKernel/JKRDvdRipper.h @@ -12,47 +12,50 @@ #define DMA_BUFFERSIZE 0x100 struct SZPHeader { - u32 magic; - u32 decompSize; + u32 magic; + u32 decompSize; }; struct SYaz0Header { - u32 signature; - u32 length; + u32 signature; + u32 length; }; class JKRDMCommand { - JKRDMCommand(); - ~JKRDMCommand(); + JKRDMCommand(); + ~JKRDMCommand(); }; class JKRDvdRipper { -public: - enum EAllocDirection { - ALLOC_DIR_DEFAULT = 0, - ALLOC_DIR_TOP = 1, - ALLOC_DIR_BOTTOM = 2 - }; + public: + enum EAllocDirection { ALLOC_DIR_DEFAULT = 0, ALLOC_DIR_TOP = 1, ALLOC_DIR_BOTTOM = 2 }; - static void* loadToMainRAM(const char* file, u8* buf, JKRExpandSwitch expandSwitch, u32 maxDest, JKRHeap* heap, EAllocDirection allocDir, u32 offset, int* compressMode); - static void* loadToMainRAM(s32 entrynum, u8* buf, JKRExpandSwitch expandSwitch, u32 maxDest, JKRHeap* heap, EAllocDirection allocDir, u32 offset, int* compressMode); - static void* loadToMainRAM(JKRDvdFile* file, u8* buf, JKRExpandSwitch expandSwitch, u32 maxDest, JKRHeap* heap, EAllocDirection allocDir, u32 offset, int* compressMode); + static void* loadToMainRAM(const char* file, u8* buf, JKRExpandSwitch expandSwitch, u32 maxDest, JKRHeap* heap, + EAllocDirection allocDir, u32 offset, int* compressMode); + static void* loadToMainRAM(s32 entrynum, u8* buf, JKRExpandSwitch expandSwitch, u32 maxDest, JKRHeap* heap, + EAllocDirection allocDir, u32 offset, int* compressMode); + static void* loadToMainRAM(JKRDvdFile* file, u8* buf, JKRExpandSwitch expandSwitch, u32 maxDest, JKRHeap* heap, + EAllocDirection allocDir, u32 offset, int* compressMode); - static inline bool isErrorRetry() { return JKRDvdRipper::errorRetry; } + static inline bool isErrorRetry() { + return JKRDvdRipper::errorRetry; + } - static JSUList sDvdAsyncList; + static JSUList sDvdAsyncList; - static bool errorRetry; + static bool errorRetry; }; -inline void* JKRDvdToMainRam(long entryNum, u8* dst, JKRExpandSwitch expandSwitch, u32 fileSize, JKRHeap* heap, JKRDvdRipper::EAllocDirection allocDirection, u32 startOffset, int* pCompression) -{ - return JKRDvdRipper::loadToMainRAM(entryNum, dst, expandSwitch, fileSize, heap, allocDirection, startOffset, pCompression); +inline void* JKRDvdToMainRam(long entryNum, u8* dst, JKRExpandSwitch expandSwitch, u32 fileSize, JKRHeap* heap, + JKRDvdRipper::EAllocDirection allocDirection, u32 startOffset, int* pCompression) { + return JKRDvdRipper::loadToMainRAM(entryNum, dst, expandSwitch, fileSize, heap, allocDirection, startOffset, + pCompression); } -inline void* JKRDvdToMainRam(const char* path, u8* dst, JKRExpandSwitch expandSwitch, u32 fileSize, JKRHeap* heap, JKRDvdRipper::EAllocDirection allocDirection, u32 startOffset, int* pCompression) -{ - return JKRDvdRipper::loadToMainRAM(path, dst, expandSwitch, fileSize, heap, allocDirection, startOffset, pCompression); +inline void* JKRDvdToMainRam(const char* path, u8* dst, JKRExpandSwitch expandSwitch, u32 fileSize, JKRHeap* heap, + JKRDvdRipper::EAllocDirection allocDirection, u32 startOffset, int* pCompression) { + return JKRDvdRipper::loadToMainRAM(path, dst, expandSwitch, fileSize, heap, allocDirection, startOffset, + pCompression); } #endif diff --git a/include/JSystem/JKernel/JKREnum.h b/include/JSystem/JKernel/JKREnum.h index 361d0c66..105524dd 100644 --- a/include/JSystem/JKernel/JKREnum.h +++ b/include/JSystem/JKernel/JKREnum.h @@ -12,11 +12,10 @@ extern "C" { #define JKRCOMPRESSION_YAZ0 2 #define JKRCOMPRESSION_ASR 3 -typedef enum JKRExpandSwitch -{ - EXPAND_SWITCH_DEFAULT, /* Do nothing? treated same as 2 */ - EXPAND_SWITCH_DECOMPRESS, /* Check for compression and decompress */ - EXPAND_SWITCH_NONE /* Do nothing */ +typedef enum JKRExpandSwitch { + EXPAND_SWITCH_DEFAULT, /* Do nothing? treated same as 2 */ + EXPAND_SWITCH_DECOMPRESS, /* Check for compression and decompress */ + EXPAND_SWITCH_NONE /* Do nothing */ } JKRExpandSwitch; #ifdef __cplusplus diff --git a/include/JSystem/JKernel/JKRExpHeap.h b/include/JSystem/JKernel/JKRExpHeap.h index 7f550387..a0f5c614 100644 --- a/include/JSystem/JKernel/JKRExpHeap.h +++ b/include/JSystem/JKernel/JKRExpHeap.h @@ -5,28 +5,46 @@ #include "types.h" #ifdef __cplusplus -class JKRExpHeap : public JKRHeap -{ -public: - class CMemBlock - { - public: +class JKRExpHeap : public JKRHeap { + public: + class CMemBlock { + public: CMemBlock* allocBack(u32, u8, u8, u8, u8); CMemBlock* allocFore(u32, u8, u8, u8, u8); void* free(JKRExpHeap*); static CMemBlock* getHeapBlock(void*); void initiate(CMemBlock*, CMemBlock*, u32, u8, u8); - void newGroupId(u8 groupId) { mGroupID = groupId; } - bool isValid() const { return mUsageHeader == 'HM'; } - bool _isTempMemBlock() const { return (mFlags & 0x80) ? true : false; } - int getAlignment() const { return mFlags & 0x7f; } - void* getContent() const { return (void*)(this + 1); } - CMemBlock* getPrevBlock() const { return mPrev; } - CMemBlock* getNextBlock() const { return mNext; } - u32 getSize() const { return mAllocatedSpace; } - u8 getGroupId() const { return mGroupID; } - static CMemBlock* getBlock(void* data) { return (CMemBlock*)((u32)data + -0x10); } + void newGroupId(u8 groupId) { + mGroupID = groupId; + } + bool isValid() const { + return mUsageHeader == 'HM'; + } + bool _isTempMemBlock() const { + return (mFlags & 0x80) ? true : false; + } + int getAlignment() const { + return mFlags & 0x7f; + } + void* getContent() const { + return (void*)(this + 1); + } + CMemBlock* getPrevBlock() const { + return mPrev; + } + CMemBlock* getNextBlock() const { + return mNext; + } + u32 getSize() const { + return mAllocatedSpace; + } + u8 getGroupId() const { + return mGroupID; + } + static CMemBlock* getBlock(void* data) { + return (CMemBlock*)((u32)data + -0x10); + } u16 mUsageHeader; // _00 u8 mFlags; // _02, a|bbbbbbb = a=temp, b=aln @@ -38,24 +56,28 @@ public: JKRExpHeap(void*, u32, JKRHeap*, bool); - virtual ~JKRExpHeap(); // _08 - virtual void* do_alloc(u32, int); // _10 - virtual void do_free(void*); // _14 - virtual void do_freeTail(); // _18 - virtual void do_freeAll(); // _1C - virtual s32 do_resize(void*, u32); // _20 - virtual s32 do_getSize(void*); // _24 - virtual s32 do_getFreeSize(); // _28 - virtual s32 do_getTotalFreeSize(); // _2C - virtual bool check(); // _34 - virtual bool dump_sort(); // _38 - virtual bool dump(); // _3C - virtual s32 do_changeGroupID(u8); // _40 - virtual void state_register(TState*, u32) const; // _48 - virtual bool state_compare(const TState&, const TState&) const; // _4C + virtual ~JKRExpHeap(); // _08 + virtual void* do_alloc(u32, int); // _10 + virtual void do_free(void*); // _14 + virtual void do_freeTail(); // _18 + virtual void do_freeAll(); // _1C + virtual s32 do_resize(void*, u32); // _20 + virtual s32 do_getSize(void*); // _24 + virtual s32 do_getFreeSize(); // _28 + virtual s32 do_getTotalFreeSize(); // _2C + virtual bool check(); // _34 + virtual bool dump_sort(); // _38 + virtual bool dump(); // _3C + virtual s32 do_changeGroupID(u8); // _40 + virtual void state_register(TState*, u32) const; // _48 + virtual bool state_compare(const TState&, const TState&) const; // _4C - virtual u8 do_getCurrentGroupId() { return mCurrentGroupID; } // _44 (weak) - virtual u32 getHeapType() { return 'EXPH'; } // _30 (weak) + virtual u8 do_getCurrentGroupId() { + return mCurrentGroupID; + } // _44 (weak) + virtual u32 getHeapType() { + return 'EXPH'; + } // _30 (weak) void* allocFromHead(u32, int); void* allocFromHead(u32); @@ -76,17 +98,22 @@ public: bool isEmpty(); s32 getUsedSize(u8 groupId) const; - CMemBlock* getHeadUsedList() const { return mHeadUsedList; } - void setAllocationMode(EAllocMode mode) { mCurrentAllocMode = mode; } + CMemBlock* getHeadUsedList() const { + return mHeadUsedList; + } + void setAllocationMode(EAllocMode mode) { + mCurrentAllocMode = mode; + } - static s32 getUsedSize_(JKRExpHeap* expHeap) - { + static s32 getUsedSize_(JKRExpHeap* expHeap) { // s32 totalFreeSize = expHeap->getTotalFreeSize(); return expHeap->mSize - expHeap->getTotalFreeSize(); } - static u32 getState_(TState* state) { return getState_buf_(state); } // might instead be a pointer to a next state? + static u32 getState_(TState* state) { + return getState_buf_(state); + } // might instead be a pointer to a next state? -private: + private: // _00 = VTBL // _00-_6C = JKRHeap u8 mCurrentAllocMode; // _6C @@ -100,8 +127,7 @@ private: CMemBlock* mTailUsedList; // _84 }; -inline JKRExpHeap* JKRCreateExpHeap(u32 size, JKRHeap* parent, bool errorFlag) -{ +inline JKRExpHeap* JKRCreateExpHeap(u32 size, JKRHeap* parent, bool errorFlag) { return JKRExpHeap::create(size, parent, errorFlag); } #endif diff --git a/include/JSystem/JKernel/JKRFile.h b/include/JSystem/JKernel/JKRFile.h index caf7a06f..e31fb6bd 100644 --- a/include/JSystem/JKernel/JKRFile.h +++ b/include/JSystem/JKernel/JKRFile.h @@ -10,25 +10,25 @@ #ifdef __cplusplus class JKRFile : public JKRDisposer { -public: - inline JKRFile() - : JKRDisposer() - , mFileOpen(false) - { - } + public: + inline JKRFile() : JKRDisposer(), mFileOpen(false) { + } - virtual ~JKRFile() { } - virtual bool open(const char* path) = 0; - virtual bool close() = 0; - virtual int readData(void* data, s32 length, s32 ofs) = 0; - virtual int writeData(const void* data, s32 length, s32 ofs) = 0; - virtual u32 getFileSize() const = 0; + virtual ~JKRFile() { + } + virtual bool open(const char* path) = 0; + virtual bool close() = 0; + virtual int readData(void* data, s32 length, s32 ofs) = 0; + virtual int writeData(const void* data, s32 length, s32 ofs) = 0; + virtual u32 getFileSize() const = 0; - void read(void* data, s32 length, s32 ofs); - bool isAvailable() { return this->mFileOpen; } + void read(void* data, s32 length, s32 ofs); + bool isAvailable() { + return this->mFileOpen; + } -protected: - bool mFileOpen; + protected: + bool mFileOpen; }; #endif diff --git a/include/JSystem/JKernel/JKRFileFinder.h b/include/JSystem/JKernel/JKRFileFinder.h index 0e87b12b..297f83b9 100644 --- a/include/JSystem/JKernel/JKRFileFinder.h +++ b/include/JSystem/JKernel/JKRFileFinder.h @@ -8,44 +8,40 @@ #ifdef __cplusplus class JKRArchive; -struct JKRFileFinderBase -{ +struct JKRFileFinderBase { char* mFileName; // _00 int mFileIndex; // _04 u16 mFileID; // _08 u16 mFileTypeFlags; // _0A }; -class JKRFileFinder -{ -public: - JKRFileFinder() - : mIsAvailable(false), mIsDir(false) - { +class JKRFileFinder { + public: + JKRFileFinder() : mIsAvailable(false), mIsDir(false) { } JKRFileFinderBase mBase; - virtual ~JKRFileFinder() {} // _08 (weak) + virtual ~JKRFileFinder() { + } // _08 (weak) virtual bool findNextFile() = 0; // _0C - bool isAvailable() const - { + bool isAvailable() const { return mIsAvailable; } // _00 = VTBL bool mIsAvailable; // _10 - bool mIsDir; // _11 + bool mIsDir; // _11 }; -class JKRArcFinder : public JKRFileFinder -{ -public: +class JKRArcFinder : public JKRFileFinder { + public: JKRArcFinder(JKRArchive*, long, long); - virtual ~JKRArcFinder() {} // _08 (weak) + virtual ~JKRArcFinder() { + } // _08 (weak) virtual bool findNextFile(); // _0C // _00 = VTBL @@ -56,15 +52,13 @@ public: long mNextIndex; // _20 }; -class JKRDvdFinder : public JKRFileFinder -{ -public: +class JKRDvdFinder : public JKRFileFinder { + public: JKRDvdFinder(const char*); virtual ~JKRDvdFinder() // _08 (weak) { - if (mIsDvdOpen) - { + if (mIsDvdOpen) { DVDCloseDir(&mDir); } } diff --git a/include/JSystem/JKernel/JKRFileLoader.h b/include/JSystem/JKernel/JKRFileLoader.h index ef46ff9b..0d7ccd79 100644 --- a/include/JSystem/JKernel/JKRFileLoader.h +++ b/include/JSystem/JKernel/JKRFileLoader.h @@ -7,27 +7,31 @@ #ifdef __cplusplus class JKRFileFinder; -class JKRFileLoader : public JKRDisposer -{ -public: +class JKRFileLoader : public JKRDisposer { + public: JKRFileLoader(); - virtual ~JKRFileLoader(); // _08 - virtual void unmount(); // _0C - virtual bool becomeCurrent(const char*) = 0; // _10 - virtual void* getResource(const char* path) = 0; // _14 - virtual void* getResource(u32 type, const char* name) = 0; // _18 - virtual size_t readResource(void* resourceBuffer, u32 bufferSize, const char* path, JKRExpandSwitch expandSwitch) = 0; // _1C - virtual size_t readResource(void* resourceBuffer, u32 bufferSize, u32 type, const char* name) = 0; // _20 - virtual void removeResourceAll() = 0; // _24 - virtual bool removeResource(void*) = 0; // _28 - virtual bool detachResource(void*) = 0; // _2C - virtual long getResSize(const void*) const = 0; // _30 - virtual u32 countFile(const char*) const = 0; // _34 - virtual JKRFileFinder* getFirstFile(const char*) const = 0; // _38 + virtual ~JKRFileLoader(); // _08 + virtual void unmount(); // _0C + virtual bool becomeCurrent(const char*) = 0; // _10 + virtual void* getResource(const char* path) = 0; // _14 + virtual void* getResource(u32 type, const char* name) = 0; // _18 + virtual size_t readResource(void* resourceBuffer, u32 bufferSize, const char* path, + JKRExpandSwitch expandSwitch) = 0; // _1C + virtual size_t readResource(void* resourceBuffer, u32 bufferSize, u32 type, const char* name) = 0; // _20 + virtual void removeResourceAll() = 0; // _24 + virtual bool removeResource(void*) = 0; // _28 + virtual bool detachResource(void*) = 0; // _2C + virtual long getResSize(const void*) const = 0; // _30 + virtual u32 countFile(const char*) const = 0; // _34 + virtual JKRFileFinder* getFirstFile(const char*) const = 0; // _38 - bool isMounted() const { return mIsMounted; } - u32 getVolumeType() const { return mVolumeType; } + bool isMounted() const { + return mIsMounted; + } + u32 getVolumeType() const { + return mVolumeType; + } static void changeDirectory(const char* dir); @@ -42,14 +46,20 @@ public: static JKRFileFinder* findFirstFile(const char*); static const char* fetchVolumeName(char*, long, const char*); - static JKRFileLoader* getCurrentVolume() { return sCurrentVolume; } - static void setCurrentVolume(JKRFileLoader* fileLoader) { sCurrentVolume = fileLoader; } - static JSUList& getVolumeList() { return sVolumeList; } + static JKRFileLoader* getCurrentVolume() { + return sCurrentVolume; + } + static void setCurrentVolume(JKRFileLoader* fileLoader) { + sCurrentVolume = fileLoader; + } + static JSUList& getVolumeList() { + return sVolumeList; + } static JKRFileLoader* sCurrentVolume; static JSUList sVolumeList; -protected: + protected: /* 0x00 */ // vtable /* 0x04 */ // JKRDisposer JSULink mFileLoaderLink; // 0x18 diff --git a/include/JSystem/JKernel/JKRHeap.h b/include/JSystem/JKernel/JKRHeap.h index a890657c..84403126 100644 --- a/include/JSystem/JKernel/JKRHeap.h +++ b/include/JSystem/JKernel/JKRHeap.h @@ -9,31 +9,24 @@ #ifdef __cplusplus typedef void JKRHeapErrorHandler(void*, u32, int); -class JKRHeap : public JKRDisposer -{ -public: - enum EAllocMode - { +class JKRHeap : public JKRDisposer { + public: + enum EAllocMode { HEAPALLOC_Unk1 = 1, }; - struct TState - { // NB: this struct doesn't agree with TP's struct - struct TLocation - { - TLocation() : _00(nullptr), _04(-1) - { + struct TState { // NB: this struct doesn't agree with TP's struct + struct TLocation { + TLocation() : _00(nullptr), _04(-1) { } void* _00; // _00 int _04; // _04 }; - struct TArgument - { + struct TArgument { TArgument(const JKRHeap* heap, u32 p2, bool p3) - : mHeap((heap) ? heap : JKRHeap::sCurrentHeap), mId(p2), mIsCompareOnDestructed(p3) - { + : mHeap((heap) ? heap : JKRHeap::sCurrentHeap), mId(p2), mIsCompareOnDestructed(p3) { } const JKRHeap* mHeap; // _00 @@ -42,24 +35,35 @@ public: }; TState(const JKRHeap* heap, u32 id, bool isCompareOnDestructed) - : mUsedSize(0), mCheckCode(0), mArgument(heap, id, isCompareOnDestructed) - { + : mUsedSize(0), mCheckCode(0), mArgument(heap, id, isCompareOnDestructed) { mArgument.mHeap->state_register(this, mArgument.mId); } - TState(JKRHeap* heap) - : mUsedSize(0), mCheckCode(0), mArgument(heap, 0xFFFFFFFF, true) - { + TState(JKRHeap* heap) : mUsedSize(0), mCheckCode(0), mArgument(heap, 0xFFFFFFFF, true) { } ~TState(); - void dump() const { mArgument.mHeap->state_dump(*this); } - bool isVerbose() { return bVerbose_; }; - bool isCompareOnDestructed() const { return mArgument.mIsCompareOnDestructed; }; - u32 getUsedSize() const { return mUsedSize; } - u32 getCheckCode() const { return mCheckCode; } - const JKRHeap* getHeap() const { return mArgument.mHeap; } - u32 getId() const { return mArgument.mId; } + void dump() const { + mArgument.mHeap->state_dump(*this); + } + bool isVerbose() { + return bVerbose_; + }; + bool isCompareOnDestructed() const { + return mArgument.mIsCompareOnDestructed; + }; + u32 getUsedSize() const { + return mUsedSize; + } + u32 getCheckCode() const { + return mCheckCode; + } + const JKRHeap* getHeap() const { + return mArgument.mHeap; + } + u32 getId() const { + return mArgument.mId; + } // unused/inlined: TState(const JKRHeap::TState::TArgument& arg, const JKRHeap::TState::TLocation& location); @@ -76,7 +80,7 @@ public: TLocation mLocation; // _1C }; -public: + public: JKRHeap(void*, u32, JKRHeap*, bool); bool setErrorFlag(bool errorFlag); @@ -94,10 +98,16 @@ public: virtual s32 do_getTotalFreeSize() = 0; virtual u32 getHeapType() = 0; virtual bool check() = 0; - virtual bool dump_sort() { return true; } + virtual bool dump_sort() { + return true; + } virtual bool dump() = 0; - virtual s32 do_changeGroupID(u8 newGroupID) { return 0; } - virtual u8 do_getCurrentGroupId() { return 0; } + virtual s32 do_changeGroupID(u8 newGroupID) { + return 0; + } + virtual u8 do_getCurrentGroupId() { + return 0; + } virtual void state_register(JKRHeap::TState*, u32) const; virtual bool state_compare(JKRHeap::TState const&, JKRHeap::TState const&) const; virtual void state_dump(JKRHeap::TState const&) const; @@ -125,56 +135,68 @@ public: JKRHeap* find(void*) const; // 0x80084640 JKRHeap* findAllHeap(void*) const; // 0x8008492c void dispose_subroutine(u32 begin, u32 end); - bool dispose(void*, u32); // 0x80084b9c + bool dispose(void*, u32); // 0x80084b9c void dispose(void*, void*); // 0x80084c2c - void dispose(); // 0x80084cb8 + void dispose(); // 0x80084cb8 - void appendDisposer(JKRDisposer* disposer) - { + void appendDisposer(JKRDisposer* disposer) { mDisposerList.append(&disposer->mPointerLinks); } - void removeDisposer(JKRDisposer* disposer) - { + void removeDisposer(JKRDisposer* disposer) { mDisposerList.remove(&disposer->mPointerLinks); } - void setDebugFill(bool debugFill) { mDebugFill = debugFill; } - bool getDebugFill() const { return mDebugFill; } - void* getStartAddr() const { return (void*)mStart; } - void* getEndAddr() const { return (void*)mEnd; } - u32 getHeapSize() const { return mSize; } - bool getErrorFlag() const { return mErrorFlag; } - void callErrorHandler(JKRHeap* heap, u32 size, int alignment) - { - if (mErrorHandler) - { + void setDebugFill(bool debugFill) { + mDebugFill = debugFill; + } + bool getDebugFill() const { + return mDebugFill; + } + void* getStartAddr() const { + return (void*)mStart; + } + void* getEndAddr() const { + return (void*)mEnd; + } + u32 getHeapSize() const { + return mSize; + } + bool getErrorFlag() const { + return mErrorFlag; + } + void callErrorHandler(JKRHeap* heap, u32 size, int alignment) { + if (mErrorHandler) { (*mErrorHandler)(heap, size, alignment); } } // TState related - static u32 getState_buf_(TState* state) { return state->mBuf; } // might instead be a pointer to a next state? - static void setState_u32ID_(TState* state, u32 id) - { + static u32 getState_buf_(TState* state) { + return state->mBuf; + } // might instead be a pointer to a next state? + static void setState_u32ID_(TState* state, u32 id) { state->mArgument.mId = id; } - static void setState_uUsedSize_(TState* state, u32 usedSize) - { + static void setState_uUsedSize_(TState* state, u32 usedSize) { state->mUsedSize = usedSize; } - static void setState_u32CheckCode_(TState* state, u32 checkCode) { state->mCheckCode = checkCode; } + static void setState_u32CheckCode_(TState* state, u32 checkCode) { + state->mCheckCode = checkCode; + } - void lock() const { OSLockMutex(const_cast(&mMutex)); } - void unlock() const { OSUnlockMutex(const_cast(&mMutex)); } + void lock() const { + OSLockMutex(const_cast(&mMutex)); + } + void unlock() const { + OSUnlockMutex(const_cast(&mMutex)); + } - JKRHeap* getParent() - { + JKRHeap* getParent() { return mChildTree.getParent()->getObject(); } - const JSUTree& getHeapTree() - { + const JSUTree& getHeapTree() { return mChildTree; } @@ -190,43 +212,35 @@ public: static JKRHeap* findFromRoot(void*); static JKRHeapErrorHandler* setErrorHandler(JKRHeapErrorHandler*); - static void* getCodeStart() - { + static void* getCodeStart() { return mCodeStart; } - static void* getCodeEnd() - { + static void* getCodeEnd() { return mCodeEnd; } - static void* getUserRamStart() - { + static void* getUserRamStart() { return mUserRamStart; } - static void* getUserRamEnd() - { + static void* getUserRamEnd() { return mUserRamEnd; } - static u32 getMemorySize() - { + static u32 getMemorySize() { return mMemorySize; } - static JKRHeap* getCurrentHeap() - { + static JKRHeap* getCurrentHeap() { return sCurrentHeap; } - static JKRHeap* getRootHeap() - { + static JKRHeap* getRootHeap() { return sRootHeap; } - static JKRHeap* getSystemHeap() - { + static JKRHeap* getSystemHeap() { return sSystemHeap; } @@ -245,7 +259,7 @@ public: static JKRHeapErrorHandler* mErrorHandler; -protected: + protected: /* 0x00 */ // vtable /* 0x04 */ // JKRDisposer /* 0x18 */ OSMutex mMutex; @@ -263,43 +277,35 @@ protected: /* 0x6A */ u8 padding_0x6a[2]; }; -inline JKRHeap* JKRGetCurrentHeap() -{ +inline JKRHeap* JKRGetCurrentHeap() { return JKRHeap::getCurrentHeap(); } -inline JKRHeap* JKRGetSystemHeap() -{ +inline JKRHeap* JKRGetSystemHeap() { return JKRHeap::getSystemHeap(); } -inline JKRHeap* JKRGetRootHeap() -{ +inline JKRHeap* JKRGetRootHeap() { return JKRHeap::getRootHeap(); } -inline void* JKRAllocFromSysHeap(u32 size, int alignment) -{ +inline void* JKRAllocFromSysHeap(u32 size, int alignment) { return JKRHeap::getSystemHeap()->alloc(size, alignment); } -inline void* JKRAllocFromHeap(JKRHeap* heap, u32 size, int alignment) -{ +inline void* JKRAllocFromHeap(JKRHeap* heap, u32 size, int alignment) { return JKRHeap::alloc(size, alignment, heap); } -inline void JKRFree(void* pBuf) -{ +inline void JKRFree(void* pBuf) { JKRHeap::free(pBuf, nullptr); } -inline void JKRFreeToHeap(JKRHeap* heap, void* ptr) -{ +inline void JKRFreeToHeap(JKRHeap* heap, void* ptr) { JKRHeap::free(ptr, heap); } -inline void JKRFreeToSysHeap(void* buf) -{ +inline void JKRFreeToSysHeap(void* buf) { JKRHeap::getSystemHeap()->free(buf); } @@ -308,7 +314,9 @@ void JKRDefaultMemoryErrorRoutine(void*, u32, int); void* operator new(size_t); void* operator new(size_t, s32); void* operator new(size_t, JKRHeap*, int); -inline void* operator new(size_t, void* buf) { return buf; } // i believe this is actually part of MSL_C? +inline void* operator new(size_t, void* buf) { + return buf; +} // i believe this is actually part of MSL_C? void* operator new[](size_t); void* operator new[](size_t, s32); diff --git a/include/JSystem/JKernel/JKRMacro.h b/include/JSystem/JKernel/JKRMacro.h index aab0dd47..a02015d3 100644 --- a/include/JSystem/JKernel/JKRMacro.h +++ b/include/JSystem/JKernel/JKRMacro.h @@ -2,13 +2,13 @@ #define JKRMACRO_H #ifdef __cplusplus -#define JKR_ISALIGNED(addr, alignment) ((((u32)addr) & (((u32)alignment)-1)) == 0) +#define JKR_ISALIGNED(addr, alignment) ((((u32)addr) & (((u32)alignment) - 1)) == 0) #define JKR_ISALIGNED32(addr) (JKR_ISALIGNED(addr, 32)) -#define JKR_ISNOTALIGNED(addr, alignment) ((((u32)addr) & (((u32)alignment)-1)) != 0) +#define JKR_ISNOTALIGNED(addr, alignment) ((((u32)addr) & (((u32)alignment) - 1)) != 0) #define JKR_ISNOTALIGNED32(addr) (JKR_ISNOTALIGNED(addr, 32)) -#define JKR_ALIGN(addr, alignment) (((u32)addr) & (~(((u32)alignment)-1))) +#define JKR_ALIGN(addr, alignment) (((u32)addr) & (~(((u32)alignment) - 1))) #define JKR_ALIGN32(addr) (JKR_ALIGN(addr, 32)) #endif diff --git a/include/JSystem/JKernel/JKRThread.h b/include/JSystem/JKernel/JKRThread.h index 05f1beff..726e4ee9 100644 --- a/include/JSystem/JKernel/JKRThread.h +++ b/include/JSystem/JKernel/JKRThread.h @@ -12,169 +12,178 @@ #ifdef __cplusplus struct JKRThread; -//class JUTConsole; +// class JUTConsole; -struct JKRThreadName_ -{ - s32 id; - char* name; +struct JKRThreadName_ { + s32 id; + char* name; }; typedef void (*JKRThreadSwitch_PreCallback)(OSThread* current, OSThread* next); typedef void (*JKRThreadSwitch_PostCallback)(OSThread* current, OSThread* next); -class JKRThreadSwitch -{ -public: - JKRThreadSwitch(JKRHeap*); - virtual void draw(JKRThreadName_* param_1, JUTConsole* param_2); - virtual void draw(JKRThreadName_* param_1); - virtual ~JKRThreadSwitch(); +class JKRThreadSwitch { + public: + JKRThreadSwitch(JKRHeap*); + virtual void draw(JKRThreadName_* param_1, JUTConsole* param_2); + virtual void draw(JKRThreadName_* param_1); + virtual ~JKRThreadSwitch(); - static JKRThreadSwitch* createManager(JKRHeap* heap); + static JKRThreadSwitch* createManager(JKRHeap* heap); - JKRThread* enter(JKRThread* param_1, int param_2); - static void callback(OSThread* param_1, OSThread* param_2); + JKRThread* enter(JKRThread* param_1, int param_2); + static void callback(OSThread* param_1, OSThread* param_2); - static u32 getTotalCount() { return sTotalCount; } + static u32 getTotalCount() { + return sTotalCount; + } -private: - static JKRThreadSwitch* sManager; - static u32 sTotalCount; - static u64 sTotalStart; - static JKRThreadSwitch_PreCallback mUserPreCallback; - static JKRThreadSwitch_PostCallback mUserPostCallback; + private: + static JKRThreadSwitch* sManager; + static u32 sTotalCount; + static u64 sTotalStart; + static JKRThreadSwitch_PreCallback mUserPreCallback; + static JKRThreadSwitch_PostCallback mUserPostCallback; -private: - JKRHeap* mHeap; // _04 - bool mSetNextHeap; // _08 - u8 _09[3]; // _09, padding? - u32 _0C; // _0C - u32 _10; // _10 - u8 _14[4]; // _14 - unknown/padding - s64 _18; // _18 - JUTConsole* mConsole; // _20 - JKRThreadName_* mThreadName; // _24 + private: + JKRHeap* mHeap; // _04 + bool mSetNextHeap; // _08 + u8 _09[3]; // _09, padding? + u32 _0C; // _0C + u32 _10; // _10 + u8 _14[4]; // _14 - unknown/padding + s64 _18; // _18 + JUTConsole* mConsole; // _20 + JKRThreadName_* mThreadName; // _24 }; class JKRThread : public JKRDisposer { -public: - JKRThread(u32 stackSize, int msgCount, int threadPrio); - JKRThread(OSThread* osThread, int msgCount); + public: + JKRThread(u32 stackSize, int msgCount, int threadPrio); + JKRThread(OSThread* osThread, int msgCount); - virtual ~JKRThread(); - virtual void* run() { return nullptr; } - - static void* start(void* param); - static JSUList* getList() { return &JKRThread::sThreadList; } - - OSThread* getThreadRecord() const { return this->mThreadRecord; } - void* getStack() const { return this->mStackMemory; } - - void resume() { OSResumeThread(this->mThreadRecord); } - void jamMessageBlock(OSMessage msg) { OSJamMessage(&this->mMesgQueue, msg, OS_MESSAGE_BLOCK); } - void sendMessage(OSMessage msg) { OSSendMessage(&this->mMesgQueue, msg, OS_MESSAGE_NOBLOCK); } - - OSMessage waitMessage(int* received) { - OSMessage mesg; - BOOL retrieved = OSReceiveMessage(&this->mMesgQueue, &mesg, OS_MESSAGE_NOBLOCK); - if (received != nullptr) { - *received = retrieved; + virtual ~JKRThread(); + virtual void* run() { + return nullptr; } - return mesg; - } - OSMessage waitMeessageBlock() { - OSMessage mesg; - OSReceiveMessage(&this->mMesgQueue, &mesg, OS_MESSAGE_BLOCK); - return mesg; - } + static void* start(void* param); + static JSUList* getList() { + return &JKRThread::sThreadList; + } - static JSUList sThreadList; + OSThread* getThreadRecord() const { + return this->mThreadRecord; + } + void* getStack() const { + return this->mStackMemory; + } -protected: - JSULink mLink; - JKRHeap* mHeap; - OSThread* mThreadRecord; - OSMessageQueue mMesgQueue; - OSMessage* mMesgBuffer; - int mMesgCount; - void* mStackMemory; - u32 mStackSize; + void resume() { + OSResumeThread(this->mThreadRecord); + } + void jamMessageBlock(OSMessage msg) { + OSJamMessage(&this->mMesgQueue, msg, OS_MESSAGE_BLOCK); + } + void sendMessage(OSMessage msg) { + OSSendMessage(&this->mMesgQueue, msg, OS_MESSAGE_NOBLOCK); + } + + OSMessage waitMessage(int* received) { + OSMessage mesg; + BOOL retrieved = OSReceiveMessage(&this->mMesgQueue, &mesg, OS_MESSAGE_NOBLOCK); + if (received != nullptr) { + *received = retrieved; + } + return mesg; + } + + OSMessage waitMeessageBlock() { + OSMessage mesg; + OSReceiveMessage(&this->mMesgQueue, &mesg, OS_MESSAGE_BLOCK); + return mesg; + } + + static JSUList sThreadList; + + protected: + JSULink mLink; + JKRHeap* mHeap; + OSThread* mThreadRecord; + OSMessageQueue mMesgQueue; + OSMessage* mMesgBuffer; + int mMesgCount; + void* mStackMemory; + u32 mStackSize; }; // Unused class, function definitions from Sunshine and MKDD -class JKRTask : public JKRThread -{ - typedef void (*RequestCallback)(void*); +class JKRTask : public JKRThread { + typedef void (*RequestCallback)(void*); - /** - * @fabricated - * @size{0xC} - */ - struct Request - { - RequestCallback mCb; - void* mArg; - void* mMsg; - }; + /** + * @fabricated + * @size{0xC} + */ + struct Request { + RequestCallback mCb; + void* mArg; + void* mMsg; + }; - JKRTask(); // unused/inlined + JKRTask(); // unused/inlined - virtual ~JKRTask(); // _08 - virtual void* run(); // _0C + virtual ~JKRTask(); // _08 + virtual void* run(); // _0C - bool request(RequestCallback, void*, void*); + bool request(RequestCallback, void*, void*); - static JKRTask* create(); + static JKRTask* create(); - // unused/inlined: - Request* searchBlank(); - void requestJam(RequestCallback, void*, void*); - void cancelAll(); - void createTaskEndMessageQueue(int, JKRHeap*); - void destroyTaskEndMessageQueue(); - void waitQueueMessageBlock(OSMessageQueue*, int*); - void waitQueueMessage(OSMessageQueue*, int*); + // unused/inlined: + Request* searchBlank(); + void requestJam(RequestCallback, void*, void*); + void cancelAll(); + void createTaskEndMessageQueue(int, JKRHeap*); + void destroyTaskEndMessageQueue(); + void waitQueueMessageBlock(OSMessageQueue*, int*); + void waitQueueMessage(OSMessageQueue*, int*); - OSMessage waitMessageBlock() - { - OSMessage msg; - OSReceiveMessage(&mMesgQueue, &msg, OS_MESSAGE_BLOCK); - return msg; - } + OSMessage waitMessageBlock() { + OSMessage msg; + OSReceiveMessage(&mMesgQueue, &msg, OS_MESSAGE_BLOCK); + return msg; + } - void destroy(); + void destroy(); - // Unused - static OSMessage* sEndMesgBuffer; - static u32 sEndMesgBufSize; + // Unused + static OSMessage* sEndMesgBuffer; + static u32 sEndMesgBufSize; - // u32 _78; // _78 - //JSULink mTaskLink; // _7C, this didn't exist yet - Request* mRequest; // _8C - ptr to request array - u32 mRequestCnt; // _90 - amount of requests - OSMessageQueue* mTaskMsgQueue; // _94 + // u32 _78; // _78 + // JSULink mTaskLink; // _7C, this didn't exist yet + Request* mRequest; // _8C - ptr to request array + u32 mRequestCnt; // _90 - amount of requests + OSMessageQueue* mTaskMsgQueue; // _94 - static JSUList sTaskList; - static u8 sEndMesgQueue[32]; // Unused + static JSUList sTaskList; + static u8 sEndMesgQueue[32]; // Unused }; /** @unused */ -struct JKRIdleThread : public JKRThread -{ - virtual ~JKRIdleThread() {}; // _08 - virtual void* run() // _0C - { - while (true) +struct JKRIdleThread : public JKRThread { + virtual ~JKRIdleThread() {}; // _08 + virtual void* run() // _0C { - } - }; - virtual void destroy() {} // 0x10 + while (true) {} + }; + virtual void destroy() { + } // 0x10 - static void create(JKRHeap*, int, u32); + static void create(JKRHeap*, int, u32); - static JKRIdleThread* sThread; + static JKRIdleThread* sThread; }; #endif diff --git a/include/JSystem/JMacro.h b/include/JSystem/JMacro.h index 878fd9db..7ab3d39e 100644 --- a/include/JSystem/JMacro.h +++ b/include/JSystem/JMacro.h @@ -18,7 +18,7 @@ #ifdef JSYSTEM_DEBUG #define JPANICLINE(line) () -#define JPANIC(line, msg) () /* TODO: JUTException */ +#define JPANIC(line, msg) () /* TODO: JUTException */ #define JPANICF(line, msg, ...) () /* TODO: JUTException */ #else #define JPANICLINE(line) (OSErrorLine(line, "Abort.")) diff --git a/include/JSystem/JSupport.h b/include/JSystem/JSupport.h index 1d973537..5ac1f974 100644 --- a/include/JSystem/JSupport.h +++ b/include/JSystem/JSupport.h @@ -3,7 +3,11 @@ #include "types.h" -inline u8 JSULoByte(u16 in) { return in & 0xff; } -inline u8 JSUHiByte(u16 in) { return in >> 8; } +inline u8 JSULoByte(u16 in) { + return in & 0xff; +} +inline u8 JSUHiByte(u16 in) { + return in >> 8; +} -#endif \ No newline at end of file +#endif diff --git a/include/JSystem/JSupport/JSUFileInputStream.h b/include/JSystem/JSupport/JSUFileInputStream.h index fbcc0915..5ba1b8e4 100644 --- a/include/JSystem/JSupport/JSUFileInputStream.h +++ b/include/JSystem/JSupport/JSUFileInputStream.h @@ -7,26 +7,30 @@ #ifdef __cplusplus class JSUFileInputStream : public JSURandomInputStream { -public: - JSUFileInputStream(JKRFile* file); + public: + JSUFileInputStream(JKRFile* file); - virtual int readData(void* buf, s32 len); - virtual int getLength() const { return ((JKRFile*)this->mObject)->getFileSize(); } - virtual int getPosition() const { return this->mPosition; } - virtual int seekPos(s32 offset, JSUStreamSeekFrom from); + virtual int readData(void* buf, s32 len); + virtual int getLength() const { + return ((JKRFile*)this->mObject)->getFileSize(); + } + virtual int getPosition() const { + return this->mPosition; + } + virtual int seekPos(s32 offset, JSUStreamSeekFrom from); - /* These two functions are shown in the symbol map, but are unused. */ - // bool open(const char* path); - // bool close(); - -protected: - const void* mObject; - s32 mPosition; + /* These two functions are shown in the symbol map, but are unused. */ + // bool open(const char* path); + // bool close(); + + protected: + const void* mObject; + s32 mPosition; }; class JSUFileOutputStream : public JSURandomOutputStream { -public: - JSUFileOutputStream(JKRFile *); + public: + JSUFileOutputStream(JKRFile*); }; #endif diff --git a/include/JSystem/JSupport/JSUInputStream.h b/include/JSystem/JSupport/JSUInputStream.h index 6a6a4fd2..a4be1226 100644 --- a/include/JSystem/JSupport/JSUInputStream.h +++ b/include/JSystem/JSupport/JSUInputStream.h @@ -6,114 +6,132 @@ #ifdef __cplusplus class JSUInputStream : public JSUIosBase { -public: - virtual ~JSUInputStream(); - virtual int getAvailable() const = 0; - virtual int skip(s32 amount); - virtual int readData(void* buf, s32 size) = 0; + public: + virtual ~JSUInputStream(); + virtual int getAvailable() const = 0; + virtual int skip(s32 amount); + virtual int readData(void* buf, s32 size) = 0; - int read(void* buf, s32 size); - char* read(char* buf); - char* readString(); - char* readString(char* buf, u16 len); + int read(void* buf, s32 size); + char* read(char* buf); + char* readString(); + char* readString(char* buf, u16 len); - int read(s8& p) { return this->read(&p, sizeof(s8)); } /* @fabricated */ - int read(u8& p) { return this->read(&p, sizeof(u8)); } - int read(bool& p) { return this->read(&p, sizeof(bool)); } - int read(s16& p) { return this->read(&p, sizeof(s16)); } /* @fabricated */ - int read(u16& p) { return this->read(&p, sizeof(u16)); } /* @fabricated */ - int read(s32& p) { return this->read(&p, sizeof(s32)); } /* @fabricated */ - int read(u32& p) { return this->read(&p, sizeof(u32)); } - int read(s64& p) { return this->read(&p, sizeof(s64)); } /* @fabricated */ - int read(u64& p) { return this->read(&p, sizeof(u64)); } /* @fabricated */ + int read(s8& p) { + return this->read(&p, sizeof(s8)); + } /* @fabricated */ + int read(u8& p) { + return this->read(&p, sizeof(u8)); + } + int read(bool& p) { + return this->read(&p, sizeof(bool)); + } + int read(s16& p) { + return this->read(&p, sizeof(s16)); + } /* @fabricated */ + int read(u16& p) { + return this->read(&p, sizeof(u16)); + } /* @fabricated */ + int read(s32& p) { + return this->read(&p, sizeof(s32)); + } /* @fabricated */ + int read(u32& p) { + return this->read(&p, sizeof(u32)); + } + int read(s64& p) { + return this->read(&p, sizeof(s64)); + } /* @fabricated */ + int read(u64& p) { + return this->read(&p, sizeof(u64)); + } /* @fabricated */ - u8 read8b() { - u8 b; - this->read(&b, sizeof(u8)); - return b; - } + u8 read8b() { + u8 b; + this->read(&b, sizeof(u8)); + return b; + } - u16 read16b() { - u16 s; - this->read(&s, sizeof(u16)); - return s; - } + u16 read16b() { + u16 s; + this->read(&s, sizeof(u16)); + return s; + } - u32 read32b() { - u32 i; - this->read(&i, sizeof(u32)); - return i; - } + u32 read32b() { + u32 i; + this->read(&i, sizeof(u32)); + return i; + } - /* @fabricated */ - s8 readS8() { - s8 b; - this->read(&b, sizeof(s8)); - return b; - } + /* @fabricated */ + s8 readS8() { + s8 b; + this->read(&b, sizeof(s8)); + return b; + } - u8 readU8() { - u8 b; - this->read(&b, sizeof(u8)); - return b; - } + u8 readU8() { + u8 b; + this->read(&b, sizeof(u8)); + return b; + } - s16 readS16() { - s16 s; - this->read(&s, sizeof(s16)); - return s; - } + s16 readS16() { + s16 s; + this->read(&s, sizeof(s16)); + return s; + } - u16 readU16() { - u16 s; - this->read(&s, sizeof(u16)); - return s; - } + u16 readU16() { + u16 s; + this->read(&s, sizeof(u16)); + return s; + } - s32 readS32() { - s32 i; - this->read(&i, sizeof(s32)); - return i; - } + s32 readS32() { + s32 i; + this->read(&i, sizeof(s32)); + return i; + } - u32 readU32() { - u32 i; - this->read(&i, sizeof(u32)); - return i; - } + u32 readU32() { + u32 i; + this->read(&i, sizeof(u32)); + return i; + } - JSUInputStream& operator>>(s8& p) { - this->read(&p, sizeof(s8)); - return *this; - } + JSUInputStream& operator>>(s8& p) { + this->read(&p, sizeof(s8)); + return *this; + } - JSUInputStream& operator>>(u8& p) { - this->read(&p, sizeof(u8)); - return *this; - } + JSUInputStream& operator>>(u8& p) { + this->read(&p, sizeof(u8)); + return *this; + } - JSUInputStream& operator>>(s16& p) { - this->read(&p, sizeof(s16)); - return *this; - } + JSUInputStream& operator>>(s16& p) { + this->read(&p, sizeof(s16)); + return *this; + } - JSUInputStream& operator>>(u16& p) { - this->read(&p, sizeof(u16)); - return *this; - } + JSUInputStream& operator>>(u16& p) { + this->read(&p, sizeof(u16)); + return *this; + } - JSUInputStream& operator>>(u32& p) { - this->read(&p, sizeof(u32)); - return *this; - } + JSUInputStream& operator>>(u32& p) { + this->read(&p, sizeof(u32)); + return *this; + } }; class JSUOutputStream : protected JSUIosBase { -public: - virtual ~JSUOutputStream(); - virtual int getAvailable() const = 0; - virtual int skip(s32 amount); - virtual int readData(void* buf, s32 size) = 0; + public: + virtual ~JSUOutputStream(); + virtual int getAvailable() const = 0; + virtual int skip(s32 amount); + virtual int readData(void* buf, s32 size) = 0; }; #endif diff --git a/include/JSystem/JSupport/JSUIosBase.h b/include/JSystem/JSupport/JSUIosBase.h index e1b01231..66a97624 100644 --- a/include/JSystem/JSupport/JSUIosBase.h +++ b/include/JSystem/JSupport/JSUIosBase.h @@ -6,16 +6,24 @@ #ifdef __cplusplus class JSUIosBase { -public: - inline JSUIosBase() : mState(GOOD) { } + public: + inline JSUIosBase() : mState(GOOD) { + } - virtual ~JSUIosBase() { } + virtual ~JSUIosBase() { + } - bool isGood() { return !this->mState; } - void clrState(EIoState ioState) { this->mState &= ~ioState; } - void setState(EIoState ioState) { this->mState |= ioState; } + bool isGood() { + return !this->mState; + } + void clrState(EIoState ioState) { + this->mState &= ~ioState; + } + void setState(EIoState ioState) { + this->mState |= ioState; + } - u8 mState; + u8 mState; }; #endif diff --git a/include/JSystem/JSupport/JSUList.h b/include/JSystem/JSupport/JSUList.h index 09612855..603e9ab4 100644 --- a/include/JSystem/JSupport/JSUList.h +++ b/include/JSystem/JSupport/JSUList.h @@ -5,11 +5,9 @@ class JSUPtrLink; -class JSUPtrList -{ -public: - JSUPtrList() - { +class JSUPtrList { + public: + JSUPtrList() { initiate(); } @@ -17,207 +15,268 @@ public: ~JSUPtrList(); void initiate(); - void setFirst(JSUPtrLink *); - bool append(JSUPtrLink *); - bool prepend(JSUPtrLink *); - bool insert(JSUPtrLink *, JSUPtrLink *); - bool remove(JSUPtrLink *); - JSUPtrLink *getNthLink(u32 idx) const; + void setFirst(JSUPtrLink*); + bool append(JSUPtrLink*); + bool prepend(JSUPtrLink*); + bool insert(JSUPtrLink*, JSUPtrLink*); + bool remove(JSUPtrLink*); + JSUPtrLink* getNthLink(u32 idx) const; - JSUPtrLink *getFirstLink() const { return mHead; } - JSUPtrLink *getLastLink() const { return mTail; } - u32 getNumLinks() const { return mLinkCount; } + JSUPtrLink* getFirstLink() const { + return mHead; + } + JSUPtrLink* getLastLink() const { + return mTail; + } + u32 getNumLinks() const { + return mLinkCount; + } - JSUPtrLink *mHead; // _0 - JSUPtrLink *mTail; // _4 + JSUPtrLink* mHead; // _0 + JSUPtrLink* mTail; // _4 u32 mLinkCount; // _8 }; -class JSUPtrLink -{ -public: - JSUPtrLink(void *); +class JSUPtrLink { + public: + JSUPtrLink(void*); ~JSUPtrLink(); - void *getObjectPtr() const { return mData; } - JSUPtrList *getList() const { return mPtrList; } - JSUPtrLink *getNext() const { return mNext; } - JSUPtrLink *getPrev() const { return mPrev; } + void* getObjectPtr() const { + return mData; + } + JSUPtrList* getList() const { + return mPtrList; + } + JSUPtrLink* getNext() const { + return mNext; + } + JSUPtrLink* getPrev() const { + return mPrev; + } - void *mData; // _0 - JSUPtrList *mPtrList; // _4 - JSUPtrLink *mPrev; // _8 - JSUPtrLink *mNext; // _C + void* mData; // _0 + JSUPtrList* mPtrList; // _4 + JSUPtrLink* mPrev; // _8 + JSUPtrLink* mNext; // _C }; -template -class JSULink; // friend class? i'm C++ noob +template class JSULink; // friend class? i'm C++ noob -template -class JSUList : public JSUPtrList -{ -public: - JSUList(bool thing) : JSUPtrList(thing) - { +template class JSUList : public JSUPtrList { + public: + JSUList(bool thing) : JSUPtrList(thing) { } - JSUList() : JSUPtrList() - { + JSUList() : JSUPtrList() { } - bool append(JSULink *link) { return JSUPtrList::append((JSUPtrLink *)link); } - bool prepend(JSULink *link) { return JSUPtrList::prepend((JSUPtrLink *)link); } - bool insert(JSULink *before, JSULink *link) { return JSUPtrList::insert((JSUPtrLink *)before, (JSUPtrLink *)link); } - bool remove(JSULink *link) { return JSUPtrList::remove((JSUPtrLink *)link); } + bool append(JSULink* link) { + return JSUPtrList::append((JSUPtrLink*)link); + } + bool prepend(JSULink* link) { + return JSUPtrList::prepend((JSUPtrLink*)link); + } + bool insert(JSULink* before, JSULink* link) { + return JSUPtrList::insert((JSUPtrLink*)before, (JSUPtrLink*)link); + } + bool remove(JSULink* link) { + return JSUPtrList::remove((JSUPtrLink*)link); + } - JSULink *getFirst() const { return (JSULink *)getFirstLink(); } - JSULink *getLast() const { return (JSULink *)getLastLink(); } - JSULink *getEnd() const { return nullptr; } + JSULink* getFirst() const { + return (JSULink*)getFirstLink(); + } + JSULink* getLast() const { + return (JSULink*)getLastLink(); + } + JSULink* getEnd() const { + return nullptr; + } - u32 getNumLinks() const { return mLinkCount; } + u32 getNumLinks() const { + return mLinkCount; + } }; -template -class JSUListIterator -{ -public: - JSUListIterator() - : mLink(nullptr) - { +template class JSUListIterator { + public: + JSUListIterator() : mLink(nullptr) { } - JSUListIterator(JSULink *link) - : mLink(link) - { + JSUListIterator(JSULink* link) : mLink(link) { } - JSUListIterator(JSUList *list) - : mLink(list->getFirst()) - { + JSUListIterator(JSUList* list) : mLink(list->getFirst()) { } - JSUListIterator &operator=(JSULink *link) - { + JSUListIterator& operator=(JSULink* link) { this->mLink = link; return *this; } - T *getObject() { return this->mLink->getObject(); } + T* getObject() { + return this->mLink->getObject(); + } - bool operator==(JSULink const *other) const { return this->mLink == other; } - bool operator!=(JSULink const *other) const { return this->mLink != other; } - bool operator==(JSUListIterator const &other) const { return this->mLink == other.mLink; } - bool operator!=(JSUListIterator const &other) const { return this->mLink != other.mLink; } + bool operator==(JSULink const* other) const { + return this->mLink == other; + } + bool operator!=(JSULink const* other) const { + return this->mLink != other; + } + bool operator==(JSUListIterator const& other) const { + return this->mLink == other.mLink; + } + bool operator!=(JSUListIterator const& other) const { + return this->mLink != other.mLink; + } - JSUListIterator operator++(int) - { + JSUListIterator operator++(int) { JSUListIterator prev = *this; this->mLink = this->mLink->getNext(); return prev; } - JSUListIterator &operator++() - { + JSUListIterator& operator++() { this->mLink = this->mLink->getNext(); return *this; } - JSUListIterator operator--(int) - { + JSUListIterator operator--(int) { JSUListIterator prev = *this; this->mLink = this->mLink->getPrev(); return prev; } - JSUListIterator &operator--() - { + JSUListIterator& operator--() { this->mLink = this->mLink->getPrev(); return *this; } - T &operator*() { return *this->getObject(); } + T& operator*() { + return *this->getObject(); + } - T *operator->() { return this->getObject(); } + T* operator->() { + return this->getObject(); + } // private: - JSULink *mLink; + JSULink* mLink; }; -template -class JSULink : public JSUPtrLink -{ -public: - JSULink(void *pData) : JSUPtrLink(pData) - { +template class JSULink : public JSUPtrLink { + public: + JSULink(void* pData) : JSUPtrLink(pData) { } - T *getObject() const { return (T *)mData; } - JSUList *getList() const { return (JSUList *)JSUPtrLink::getList(); } // fabricated, offcial name: getSupervisor - JSULink *getNext() const { return (JSULink *)JSUPtrLink::getNext(); } - JSULink *getPrev() const { return (JSULink *)JSUPtrLink::getPrev(); } + T* getObject() const { + return (T*)mData; + } + JSUList* getList() const { + return (JSUList*)JSUPtrLink::getList(); + } // fabricated, offcial name: getSupervisor + JSULink* getNext() const { + return (JSULink*)JSUPtrLink::getNext(); + } + JSULink* getPrev() const { + return (JSULink*)JSUPtrLink::getPrev(); + } - ~JSULink() - { + ~JSULink() { } }; template // TODO: most of these inlines are probably wrong: rework -class JSUTree : public JSUList, public JSULink -{ -public: - JSUTree(T *owner) : JSUList(), JSULink(owner) {} - ~JSUTree() {} +class JSUTree : public JSUList, public JSULink { + public: + JSUTree(T* owner) : JSUList(), JSULink(owner) { + } + ~JSUTree() { + } - bool appendChild(JSUTree *child) { return this->append(child); } - bool prependChild(JSUTree *child) { return this->prepend(child); } - bool removeChild(JSUTree *child) { return this->remove(child); } - bool insertChild(JSUTree *before, JSUTree *child) { return this->insert(before, child); } + bool appendChild(JSUTree* child) { + return this->append(child); + } + bool prependChild(JSUTree* child) { + return this->prepend(child); + } + bool removeChild(JSUTree* child) { + return this->remove(child); + } + bool insertChild(JSUTree* before, JSUTree* child) { + return this->insert(before, child); + } - JSUTree *getEndChild() const { return nullptr; } - JSUTree *getFirstChild() const { return (JSUTree *)this->getFirstLink(); } - JSUTree *getLastChild() const { return (JSUTree *)this->getLast(); } - JSUTree *getNextChild() const { return (JSUTree *)this->mNext; } - JSUTree *getPrevChild() const { return (JSUTree *)this->getPrev(); } - u32 getNumChildren() const { return this->mLinkCount; } - T *getObject() const { return (T *)this->mData; } - JSUTree *getParent() const { return (JSUTree *)this->mPtrList; } + JSUTree* getEndChild() const { + return nullptr; + } + JSUTree* getFirstChild() const { + return (JSUTree*)this->getFirstLink(); + } + JSUTree* getLastChild() const { + return (JSUTree*)this->getLast(); + } + JSUTree* getNextChild() const { + return (JSUTree*)this->mNext; + } + JSUTree* getPrevChild() const { + return (JSUTree*)this->getPrev(); + } + u32 getNumChildren() const { + return this->mLinkCount; + } + T* getObject() const { + return (T*)this->mData; + } + JSUTree* getParent() const { + return (JSUTree*)this->mPtrList; + } }; -template -class JSUTreeIterator -{ -public: - JSUTreeIterator() : mTree(nullptr) {} - JSUTreeIterator(JSUTree *tree) : mTree(tree) {} +template class JSUTreeIterator { + public: + JSUTreeIterator() : mTree(nullptr) { + } + JSUTreeIterator(JSUTree* tree) : mTree(tree) { + } - JSUTreeIterator &operator=(JSUTree *tree) - { + JSUTreeIterator& operator=(JSUTree* tree) { this->mTree = tree; return *this; } - T *getObject() const { return mTree->getObject(); } + T* getObject() const { + return mTree->getObject(); + } - bool operator==(JSUTree *other) { return this->mTree == other; } + bool operator==(JSUTree* other) { + return this->mTree == other; + } - bool operator!=(const JSUTree *other) const { return this->mTree != other; } + bool operator!=(const JSUTree* other) const { + return this->mTree != other; + } - JSUTreeIterator operator++(int) - { + JSUTreeIterator operator++(int) { JSUTreeIterator prev = *this; this->mTree = this->mTree->getNextChild(); return prev; } - JSUTreeIterator &operator++() - { + JSUTreeIterator& operator++() { this->mTree = this->mTree->getNextChild(); return *this; } - T &operator*() { return *this->getObject(); } + T& operator*() { + return *this->getObject(); + } - T *operator->() const { return mTree->getObject(); } + T* operator->() const { + return mTree->getObject(); + } -private: - JSUTree *mTree; + private: + JSUTree* mTree; }; #endif /* JSULIST_H */ diff --git a/include/JSystem/JSupport/JSURandomInputStream.h b/include/JSystem/JSupport/JSURandomInputStream.h index fb59ebb1..a5111dfb 100644 --- a/include/JSystem/JSupport/JSURandomInputStream.h +++ b/include/JSystem/JSupport/JSURandomInputStream.h @@ -7,35 +7,39 @@ #ifdef __cplusplus class JSURandomInputStream : public JSUInputStream { -public: - virtual ~JSURandomInputStream() { } + public: + virtual ~JSURandomInputStream() { + } - virtual int getAvailable() const { return this->getLength() - this->getPosition(); } - virtual int skip(s32 amount); - virtual int readData(void* buf, s32 count) = 0; - virtual int getLength() const = 0; - virtual int getPosition() const = 0; - virtual int seekPos(s32 offset, JSUStreamSeekFrom from) = 0; + virtual int getAvailable() const { + return this->getLength() - this->getPosition(); + } + virtual int skip(s32 amount); + virtual int readData(void* buf, s32 count) = 0; + virtual int getLength() const = 0; + virtual int getPosition() const = 0; + virtual int seekPos(s32 offset, JSUStreamSeekFrom from) = 0; - int align(s32 alignment); - int peek(void* buf, s32 len); - int seek(s32 offset, JSUStreamSeekFrom from); + int align(s32 alignment); + int peek(void* buf, s32 len); + int seek(s32 offset, JSUStreamSeekFrom from); }; class JSURandomOutputStream : public JSUOutputStream { -public: - virtual ~JSURandomOutputStream() { } + public: + virtual ~JSURandomOutputStream() { + } - virtual int getAvailable() const; - virtual int skip(s32 amount); - virtual int readData(void* buf, s32 count) = 0; - virtual int getLength() const = 0; - virtual int getPosition() const = 0; - virtual int seekPos(s32 offset, JSUStreamSeekFrom from) = 0; + virtual int getAvailable() const; + virtual int skip(s32 amount); + virtual int readData(void* buf, s32 count) = 0; + virtual int getLength() const = 0; + virtual int getPosition() const = 0; + virtual int seekPos(s32 offset, JSUStreamSeekFrom from) = 0; - int align(s32 alignment); - int peek(void* buf, s32 len); - int seek(s32 offset, JSUStreamSeekFrom from); + int align(s32 alignment); + int peek(void* buf, s32 len); + int seek(s32 offset, JSUStreamSeekFrom from); }; #endif diff --git a/include/JSystem/JSupport/JSUStreamEnum.h b/include/JSystem/JSupport/JSUStreamEnum.h index 8f1aaa81..536bbf03 100644 --- a/include/JSystem/JSupport/JSUStreamEnum.h +++ b/include/JSystem/JSupport/JSUStreamEnum.h @@ -1,15 +1,8 @@ #ifndef JSUSTREAMENUM_H #define JSUSTREAMENUM_H -enum JSUStreamSeekFrom { - SEEK_SET = 0, - SEEK_CUR = 1, - SEEK_END = 2 -}; +enum JSUStreamSeekFrom { SEEK_SET = 0, SEEK_CUR = 1, SEEK_END = 2 }; -enum EIoState { - GOOD = 0, - EOF = 1 -}; +enum EIoState { GOOD = 0, EOF = 1 }; #endif diff --git a/include/JSystem/JUtility/JUTAssertion.h b/include/JSystem/JUtility/JUTAssertion.h index de3a3506..26fa66f8 100644 --- a/include/JSystem/JUtility/JUTAssertion.h +++ b/include/JSystem/JUtility/JUTAssertion.h @@ -5,36 +5,33 @@ #include "dolphin/os.h" #ifdef __cplusplus -extern "C" -{ +extern "C" { -namespace JUTAssertion -{ - void create(); - void flushMessage(); - void flushMessage_dbPrint(); - u32 getSDevice(void); +namespace JUTAssertion { +void create(); +void flushMessage(); +void flushMessage_dbPrint(); +u32 getSDevice(void); - void showAssert_f(u32 device, char const *file, int line, char const *errormsg, ...); - inline void showAssert(u32 device, char const *file, int line, char const *errormsg) { +void showAssert_f(u32 device, char const* file, int line, char const* errormsg, ...); +inline void showAssert(u32 device, char const* file, int line, char const* errormsg) { showAssert_f(device, file, line, "%s", errormsg); - } - - void setConfirmMessage(u32 device, char *file, int line, bool condition, const char *msg); - void setWarningMessage_f(u32 device, char *file, int line, char const *, ...); - inline void setWarningMessage(u32 device, char *file, int line, char const *errormsg) { - setWarningMessage_f(device, file, line, "%s", errormsg); - } - - void setLogMessage_f(u32 device, char *file, int line, char const *fmt, ...); - extern "C" - { - void showAssert_f_va(u32 device, const char *file, int line, const char *fmt, va_list vl); - void setWarningMessage_f_va(u32 device, char *file, int line, const char *fmt, va_list vl); - void setLogMessage_f_va(u32 device, char *file, int line, const char *fmt, va_list vl); - } } +void setConfirmMessage(u32 device, char* file, int line, bool condition, const char* msg); +void setWarningMessage_f(u32 device, char* file, int line, char const*, ...); +inline void setWarningMessage(u32 device, char* file, int line, char const* errormsg) { + setWarningMessage_f(device, file, line, "%s", errormsg); +} + +void setLogMessage_f(u32 device, char* file, int line, char const* fmt, ...); +extern "C" { +void showAssert_f_va(u32 device, const char* file, int line, const char* fmt, va_list vl); +void setWarningMessage_f_va(u32 device, char* file, int line, const char* fmt, va_list vl); +void setLogMessage_f_va(u32 device, char* file, int line, const char* fmt, va_list vl); +} +} // namespace JUTAssertion + #define JUT_PANIC(...) #define JUT_PANIC_F(...) #define JUT_CONFIRM_MESSAGE(...) @@ -46,7 +43,6 @@ namespace JUTAssertion #define JUT_LOG_F(...) #define JUT_ASSERT(...) #define JUT_ASSERT_F(...) - } #endif diff --git a/include/JSystem/JUtility/JUTConsole.h b/include/JSystem/JUtility/JUTConsole.h index eabab006..a981d958 100644 --- a/include/JSystem/JUtility/JUTConsole.h +++ b/include/JSystem/JUtility/JUTConsole.h @@ -7,24 +7,20 @@ #include "JSystem/JUtility/JUTFont.h" #ifdef __cplusplus -inline s32 colorCheck(s32 diff, s32 t) -{ +inline s32 colorCheck(s32 diff, s32 t) { s32 ret = diff - t; return ret + 1; } -class JUTConsole : JKRDisposer -{ -public: - enum EConsoleType - { +class JUTConsole : JKRDisposer { + public: + enum EConsoleType { CONSOLE_TYPE_0 = 0, CONSOLE_TYPE_1 = 1, CONSOLE_TYPE_2 = 2, }; - enum OutputFlag - { + enum OutputFlag { /* 0x0 */ OUTPUT_NONE, /* 0x1 */ OUTPUT_OSREPORT, /* 0x2 */ OUTPUT_CONSOLE, @@ -35,67 +31,77 @@ public: // _00 VTBL - static JUTConsole *create(uint, uint, JKRHeap *); - static JUTConsole *create(uint, void *, u32); - static void destroy(JUTConsole *); // UNUSED + static JUTConsole* create(uint, uint, JKRHeap*); + static JUTConsole* create(uint, void*, u32); + static void destroy(JUTConsole*); // UNUSED JUTConsole(uint, uint, bool); static size_t getObjectSizeFromBufferSize(uint, uint); static size_t getLineFromObjectSize(u32, uint); void clear(); void doDraw(JUTConsole::EConsoleType) const; - void print_f(char const *, ...); - void print(char const *); + void print_f(char const*, ...); + void print(char const*); void dumpToTerminal(uint); void scroll(int); int getUsedLine() const; int getLineOffset() const; - void setOutput(uint output) { mOutput = output; } - void setPosition(int x, int y) - { + void setOutput(uint output) { + mOutput = output; + } + void setPosition(int x, int y) { mPositionX = x; mPositionY = y; } - void setFontSize(f32 x, f32 y) - { + void setFontSize(f32 x, f32 y) { mFontSizeX = x; mFontSizeY = y; } - void setHeight(u32 height) - { + void setHeight(u32 height) { mHeight = height; - if (mHeight > mMaxLines) - { + if (mHeight > mMaxLines) { mHeight = mMaxLines; } } - void setFont(JUTFont *p_font) - { + void setFont(JUTFont* p_font) { mFont = p_font; setFontSize(p_font->getWidth(), p_font->getHeight()); } - int nextIndex(int index) const - { + int nextIndex(int index) const { return ++index >= (int)mMaxLines ? 0 : index; } - u32 getOutput() const { return mOutput; } - int getPositionY() const { return mPositionY; } - int getPositionX() const { return mPositionX; } - u32 getHeight() const { return mHeight; } + u32 getOutput() const { + return mOutput; + } + int getPositionY() const { + return mPositionY; + } + int getPositionX() const { + return mPositionX; + } + u32 getHeight() const { + return mHeight; + } - bool isVisible() const { return mIsVisible; } - void setVisible(bool visible) { mIsVisible = visible; } + bool isVisible() const { + return mIsVisible; + } + void setVisible(bool visible) { + mIsVisible = visible; + } - void setLineAttr(int param_0, u8 param_1) { mBuf[(_20 + 2) * param_0] = param_1; } - u8 *getLinePtr(int param_0) const { return &mBuf[(_20 + 2) * param_0] + 1; } - int diffIndex(int param_0, int param_1) const - { + void setLineAttr(int param_0, u8 param_1) { + mBuf[(_20 + 2) * param_0] = param_1; + } + u8* getLinePtr(int param_0) const { + return &mBuf[(_20 + 2) * param_0] + 1; + } + int diffIndex(int param_0, int param_1) const { int diff = param_1 - param_0; - if (diff >= 0) - { + if (diff >= 0) { return diff; } return diff += mMaxLines; @@ -107,57 +113,61 @@ public: int prevIndex(int n) const { return (--n < 0) ? mMaxLines - 1 : n; - } - void scrollToLastLine() { scroll(mMaxLines); } - void scrollToFirstLine() { scroll(-mMaxLines); } + void scrollToLastLine() { + scroll(mMaxLines); + } + void scrollToFirstLine() { + scroll(-mMaxLines); + } // _00 = VTBL // _00-_18 = JKRDisposer - JGadget::TLinkListNode mNode; // _18 - u32 _20; // _20 - u32 mMaxLines; // _24, might be int - u8 *mBuf; // _28 - bool _2C; // _2C - int _30; // _30 - int _34; // _34 - int _38; // _38 - int _3C; // _3C - int mPositionX; // _40 - int mPositionY; // _44 - u32 mHeight; // _48 - JUTFont *mFont; // _4C - f32 mFontSizeX; // _50 - f32 mFontSizeY; // _54 - u32 mOutput; // _58 - JUtility::TColor _5C; // _5C - JUtility::TColor _60; // _60 - bool mIsVisible; // _64 - bool _65; // _65 - bool _66; // _66 + JGadget::TLinkListNode mNode; // _18 + u32 _20; // _20 + u32 mMaxLines; // _24, might be int + u8* mBuf; // _28 + bool _2C; // _2C + int _30; // _30 + int _34; // _34 + int _38; // _38 + int _3C; // _3C + int mPositionX; // _40 + int mPositionY; // _44 + u32 mHeight; // _48 + JUTFont* mFont; // _4C + f32 mFontSizeX; // _50 + f32 mFontSizeY; // _54 + u32 mOutput; // _58 + JUtility::TColor _5C; // _5C + JUtility::TColor _60; // _60 + bool mIsVisible; // _64 + bool _65; // _65 + bool _66; // _66 }; // Size: 0x6C -class JUTConsoleManager -{ -public: +class JUTConsoleManager { + public: JUTConsoleManager(); - static JUTConsoleManager *createManager(JKRHeap *); - void appendConsole(JUTConsole *console); - void removeConsole(JUTConsole *console); + static JUTConsoleManager* createManager(JKRHeap*); + void appendConsole(JUTConsole* console); + void removeConsole(JUTConsole* console); void draw() const; void drawDirect(bool) const; - void setDirectConsole(JUTConsole *); + void setDirectConsole(JUTConsole*); - static JUTConsoleManager *getManager() { return sManager; } + static JUTConsoleManager* getManager() { + return sManager; + } - static JUTConsoleManager *sManager; + static JUTConsoleManager* sManager; -private: + private: JGadget::TLinkList soLink_; // _00 - JUTConsole *mActiveConsole; // _0C - JUTConsole *mDirectConsole; // _10 -}; // Size: 0x14 + JUTConsole* mActiveConsole; // _0C + JUTConsole* mDirectConsole; // _10 +}; // Size: 0x14 extern "C" { void JUTConsole_print_f_va_(JUTConsole*, const char*, va_list); diff --git a/include/JSystem/JUtility/JUTDbPrint.h b/include/JSystem/JUtility/JUTDbPrint.h index 81640cd1..1a38f878 100644 --- a/include/JSystem/JUtility/JUTDbPrint.h +++ b/include/JSystem/JUtility/JUTDbPrint.h @@ -7,9 +7,8 @@ #include "JSystem/JUtility/JUTFont.h" #include "JSystem/JKernel/JKRHeap.h" -struct JUTDbPrintList -{ - JUTDbPrintList *mNext; // _00 +struct JUTDbPrintList { + JUTDbPrintList* mNext; // _00 s16 mX; // _04 s16 mY; // _06 s16 mDuration; // _08 @@ -17,37 +16,44 @@ struct JUTDbPrintList u8 mStr; // _0C }; -struct JUTDbPrint -{ - JUTDbPrint(JUTFont *, JKRHeap *); // unused/inlined +struct JUTDbPrint { + JUTDbPrint(JUTFont*, JKRHeap*); // unused/inlined ~JUTDbPrint(); // unused/inlined - JUTFont *changeFont(JUTFont *); + JUTFont* changeFont(JUTFont*); void flush(); void flush(int, int, int, int); - void drawString(int, int, int, const u8 *); + void drawString(int, int, int, const u8*); // Unused/inlined: - void enter(int, int, int, const char *, int); - void print(int, int, const char *, ...); - void print(int, int, int, const char *, ...); + void enter(int, int, int, const char*, int); + void print(int, int, const char*, ...); + void print(int, int, int, const char*, ...); void reset(); - void setVisible(bool visible) { mVisible = visible; } - JUTFont *getFont() const { return mFont; } - JUTDbPrintList *getList() const { return mList; } + void setVisible(bool visible) { + mVisible = visible; + } + JUTFont* getFont() const { + return mFont; + } + JUTDbPrintList* getList() const { + return mList; + } - static JUTDbPrint *start(JUTFont *, JKRHeap *); - static JUTDbPrint *getManager() { return sDebugPrint; } + static JUTDbPrint* start(JUTFont*, JKRHeap*); + static JUTDbPrint* getManager() { + return sDebugPrint; + } - static JUTDbPrint *sDebugPrint; + static JUTDbPrint* sDebugPrint; - JUTDbPrintList *mList; // _00 - JUTFont *mFont; // _04 + JUTDbPrintList* mList; // _00 + JUTFont* mFont; // _04 JUtility::TColor mColor; // _08 - bool mVisible; // _0C - JKRHeap *mHeap; // _10 + bool mVisible; // _0C + JKRHeap* mHeap; // _10 }; void JUTReport(int x, int y, int show_count, const char* fmt, ...); @@ -55,9 +61,9 @@ void JUTReport(int x, int y, int show_count, const char* fmt, ...); extern "C" { #endif -void* JC_JUTDbPrint_getManager(void); -void JC_JUTDbPrint_setVisible(void*, int); // I know these are C++ but these were used to match a c function so I'll fix these when I need them or fix zurumode update. - +void* JC_JUTDbPrint_getManager(void); +void JC_JUTDbPrint_setVisible(void*, int); // I know these are C++ but these were used to match a c function so I'll fix + // these when I need them or fix zurumode update. #ifdef __cplusplus } diff --git a/include/JSystem/JUtility/JUTDirectFile.h b/include/JSystem/JUtility/JUTDirectFile.h index 1f028940..9001e328 100644 --- a/include/JSystem/JUtility/JUTDirectFile.h +++ b/include/JSystem/JUtility/JUTDirectFile.h @@ -6,24 +6,23 @@ #define JUTDF_BUFSIZE (0x800) -struct JUTDirectFile -{ +struct JUTDirectFile { JUTDirectFile(); ~JUTDirectFile(); - bool fopen(const char *); + bool fopen(const char*); void fclose(); - int fgets(void *, int); + int fgets(void*, int); // unused/inlined int fetch32byte(); - void fread(void *, u32); + void fread(void*, u32); void setPos(u32); void fgetc(); u8 mBuffer[0x820]; // _000, 0x20 header, 0x800 sector - u8 *mSectorStart; // _820, ptr to 0x800 buffer + u8* mSectorStart; // _820, ptr to 0x800 buffer u32 mToRead; // _824, length (max 32 bytes) to read u32 mLength; // _828, length of file u32 mPos; // _82C, position in file @@ -31,4 +30,4 @@ struct JUTDirectFile DVDFileInfo mFileInfo; // _834 }; -#endif \ No newline at end of file +#endif diff --git a/include/JSystem/JUtility/JUTDirectPrint.h b/include/JSystem/JUtility/JUTDirectPrint.h index 8f126d01..3638eaa9 100644 --- a/include/JSystem/JUtility/JUTDirectPrint.h +++ b/include/JSystem/JUtility/JUTDirectPrint.h @@ -6,45 +6,51 @@ #ifdef __cplusplus -class JUTDirectPrint -{ -private: +class JUTDirectPrint { + private: JUTDirectPrint(); -public: - static JUTDirectPrint *start(); + public: + static JUTDirectPrint* start(); void erase(int x, int y, int w, int h); void drawChar(int, int, int); - void drawString(u16 x, u16 y, char *text); - void drawString_f(u16 x, u16 y, const char * text, ...); - void changeFrameBuffer(void *framebuffer, u16 w, u16 h ); - void printSub(u16, u16, const char *, va_list, bool); // TODO: Function signature - void print(u16, u16, const char *, ...); + void drawString(u16 x, u16 y, char* text); + void drawString_f(u16 x, u16 y, const char* text, ...); + void changeFrameBuffer(void* framebuffer, u16 w, u16 h); + void printSub(u16, u16, const char*, va_list, bool); // TODO: Function signature + void print(u16, u16, const char*, ...); - bool isActive() const { return mFramebuffer != nullptr; } - void *getFrameBuffer() { return mFramebuffer; } + bool isActive() const { + return mFramebuffer != nullptr; + } + void* getFrameBuffer() { + return mFramebuffer; + } - void changeFrameBuffer(void* fb) { changeFrameBuffer(fb, mFbWidth, mFbHeight); } + void changeFrameBuffer(void* fb) { + changeFrameBuffer(fb, mFbWidth, mFbHeight); + } - static JUTDirectPrint *getManager() { return sDirectPrint; } + static JUTDirectPrint* getManager() { + return sDirectPrint; + } -private: + private: static u8 sAsciiTable[128]; static u32 sFontData[64]; static u32 sFontData2[77]; - static JUTDirectPrint *sDirectPrint; + static JUTDirectPrint* sDirectPrint; - void *mFramebuffer; // _00 - u16 mFbWidth; // _04 - u16 mFbHeight; // _06 - u16 mStride; // _08 - size_t mFbSize; // _0C - u8 _10[0x4]; // _10 - unknown - u16 *mFrameMemory; // _14 + void* mFramebuffer; // _00 + u16 mFbWidth; // _04 + u16 mFbHeight; // _06 + u16 mStride; // _08 + size_t mFbSize; // _0C + u8 _10[0x4]; // _10 - unknown + u16* mFrameMemory; // _14 }; -inline void JUTChangeFrameBuffer(void *buffer, u16 height, u16 width) -{ +inline void JUTChangeFrameBuffer(void* buffer, u16 height, u16 width) { JUTDirectPrint::getManager()->changeFrameBuffer(buffer, width, height); } #endif diff --git a/include/JSystem/JUtility/JUTEnum.h b/include/JSystem/JUtility/JUTEnum.h index a5019ba0..fc950176 100644 --- a/include/JSystem/JUtility/JUTEnum.h +++ b/include/JSystem/JUtility/JUTEnum.h @@ -8,26 +8,26 @@ extern "C" { #endif enum EButtons { - MAINSTICK_UP = 0x8000000, - MAINSTICK_DOWN = 0x4000000, - MAINSTICK_RIGHT = 0x2000000, - MAINSTICK_LEFT = 0x1000000, - CSTICK_UP = 0x80000, - CSTICK_DOWN = 0x40000, - CSTICK_RIGHT = 0x20000, - CSTICK_LEFT = 0x10000, - START = 0x1000, - Y = 0x800, - X = 0x400, - B = 0x200, - A = 0x100, - L = 0x40, - R = 0x20, - Z = 0x10, - DPAD_UP = 0x8, - DPAD_DOWN = 0x4, - DPAD_RIGHT = 0x2, - DPAD_LEFT = 0x1 + MAINSTICK_UP = 0x8000000, + MAINSTICK_DOWN = 0x4000000, + MAINSTICK_RIGHT = 0x2000000, + MAINSTICK_LEFT = 0x1000000, + CSTICK_UP = 0x80000, + CSTICK_DOWN = 0x40000, + CSTICK_RIGHT = 0x20000, + CSTICK_LEFT = 0x10000, + START = 0x1000, + Y = 0x800, + X = 0x400, + B = 0x200, + A = 0x100, + L = 0x40, + R = 0x20, + Z = 0x10, + DPAD_UP = 0x8, + DPAD_DOWN = 0x4, + DPAD_RIGHT = 0x2, + DPAD_LEFT = 0x1 }; #ifdef __cplusplus diff --git a/include/JSystem/JUtility/JUTException.h b/include/JSystem/JUtility/JUTException.h index 14514ea4..0e2894db 100644 --- a/include/JSystem/JUtility/JUTException.h +++ b/include/JSystem/JUtility/JUTException.h @@ -11,10 +11,9 @@ struct JUTConsole; struct JUTDirectPrint; -typedef void (*JUTErrorHandler)(OSError error, OSContext *context, u32 dsisr, u32 dar); +typedef void (*JUTErrorHandler)(OSError error, OSContext* context, u32 dsisr, u32 dar); -enum ExPrintFlags -{ +enum ExPrintFlags { EXPRINTFLAG_GPR = 0x1, EXPRINTFLAG_GPRMap = 0x2, EXPRINTFLAG_Float = 0x4, @@ -25,116 +24,117 @@ enum ExPrintFlags /** * @size{0xA4} */ -struct JUTException : public JKRThread -{ - enum EInfoPage - { +struct JUTException : public JKRThread { + enum EInfoPage { INFOPAGE_GPR = 1, INFOPAGE_Float = 2, INFOPAGE_Stack = 3, INFOPAGE_GPRMap = 4, - + }; // size: 0x14 - struct JUTExMapFile - { - inline JUTExMapFile(const char *fileName) - : mLink(this) - { - mFileName = (char *)fileName; + struct JUTExMapFile { + inline JUTExMapFile(const char* fileName) : mLink(this) { + mFileName = (char*)fileName; } - char *mFileName; // _00 + char* mFileName; // _00 JSULink mLink; // _04 }; /** @fabricated */ - struct ExCallbackObject - { + struct ExCallbackObject { JUTErrorHandler mErrorHandler; // _00 - s32 mError; // _04 - OSContext *mContext; // _08 - u32 _0C; // _0C - u32 _10; // _10 + s32 mError; // _04 + OSContext* mContext; // _08 + u32 _0C; // _0C + u32 _10; // _10 }; - JUTException(JUTDirectPrint *); // unused/inlined + JUTException(JUTDirectPrint*); // unused/inlined - virtual ~JUTException(){}; // _08 (weak) - virtual void *run(); // _0C + virtual ~JUTException() {}; // _08 (weak) + virtual void* run(); // _0C - void showFloat(OSContext *); - void showStack(OSContext *); - void showMainInfo(u16, OSContext *, u32, u32); + void showFloat(OSContext*); + void showStack(OSContext*); + void showMainInfo(u16, OSContext*, u32, u32); bool showMapInfo_subroutine(u32, bool); - void showGPRMap(OSContext *); - void printDebugInfo(JUTException::EInfoPage, u16, OSContext *, u32, u32); - bool readPad(u32 *, u32 *); - void printContext(u16, OSContext *, u32, u32); + void showGPRMap(OSContext*); + void printDebugInfo(JUTException::EInfoPage, u16, OSContext*, u32, u32); + bool readPad(u32*, u32*); + void printContext(u16, OSContext*, u32, u32); void createFB(); static void waitTime(long); static JUTErrorHandler setPreUserCallback(JUTErrorHandler); - static void appendMapFile(const char *); - static bool queryMapAddress(char *, u32, long, u32 *, u32 *, char *, u32, bool, bool); - static bool queryMapAddress_single(char *, u32, long, u32 *, u32 *, char *, u32, bool, bool); + static void appendMapFile(const char*); + static bool queryMapAddress(char*, u32, long, u32*, u32*, char*, u32, bool, bool); + static bool queryMapAddress_single(char*, u32, long, u32*, u32*, char*, u32, bool, bool); - static JUTException *create(JUTDirectPrint *); - static void createConsole(void *buffer, u32 bufferSize); - static void panic_f(const char *file, int line, const char *msg, ...); - static void errorHandler(u16, OSContext *, u32, u32); + static JUTException* create(JUTDirectPrint*); + static void createConsole(void* buffer, u32 bufferSize); + static void panic_f(const char* file, int line, const char* msg, ...); + static void errorHandler(u16, OSContext*, u32, u32); static void setFPException(u32); - static bool searchPartialModule(u32, u32 *, u32 *, u32 *, u32 *); + static bool searchPartialModule(u32, u32*, u32*, u32*, u32*); // unused/inlined: - static void panic_f_va(const char *, int, const char *, va_list); + static void panic_f_va(const char*, int, const char*, va_list); static JUTErrorHandler setPostUserCallback(JUTErrorHandler); // Inline - static void panic(const char *file, int line, const char *msg) { + static void panic(const char* file, int line, const char* msg) { panic_f(file, line, "%s", msg); } void showFloatSub(int, f32); - void showGPR(OSContext *); - void showSRR0Map(OSContext *); + void showGPR(OSContext*); + void showSRR0Map(OSContext*); bool isEnablePad() const; static u32 getFpscr(); void setFpscr(u32); void enableFpuException(); void disableFpuException(); - JUTExternalFB *getFrameMemory() const { return mFrameMemory; } + JUTExternalFB* getFrameMemory() const { + return mFrameMemory; + } - void setTraceSuppress(u32 supress) { mTraceSuppress = supress; } - void setGamePad(JUTGamePad *gamePad) - { + void setTraceSuppress(u32 supress) { + mTraceSuppress = supress; + } + void setGamePad(JUTGamePad* gamePad) { mGamePad = gamePad; mPadPort = JUTGamePad::Port_Invalid; } - static JUTException *getManager() { return sErrorManager; } - static JUTConsole *getConsole() { return sConsole; } + static JUTException* getManager() { + return sErrorManager; + } + static JUTConsole* getConsole() { + return sConsole; + } - static JUTConsole *sConsole; - static void *sConsoleBuffer; + static JUTConsole* sConsole; + static void* sConsoleBuffer; static size_t sConsoleBufferSize; - static JUTException *sErrorManager; + static JUTException* sErrorManager; static OSMessageQueue sMessageQueue; - static void *sMessageBuffer[1]; + static void* sMessageBuffer[1]; static JUTErrorHandler sPreUserCallback; static JUTErrorHandler sPostUserCallback; static u32 msr; static u32 fpscr; - static const char *sCpuExpName[16]; + static const char* sCpuExpName[16]; static JSUList sMapFileList; // _00 = VTBL // _00-_7C = JKRThread - JUTExternalFB *mFrameMemory; // _7C - JUTDirectPrint *mDirectPrint; // _80 - JUTGamePad *mGamePad; // _84 + JUTExternalFB* mFrameMemory; // _7C + JUTDirectPrint* mDirectPrint; // _80 + JUTGamePad* mGamePad; // _84 JUTGamePad::EPadPort mPadPort; // _88 int mPrintWaitTime0; // _8C int mPrintWaitTime1; // _90 @@ -143,4 +143,4 @@ struct JUTException : public JKRThread u32 mPrintFlags; // _9C, see ExPrintFlags enum }; -#endif \ No newline at end of file +#endif diff --git a/include/JSystem/JUtility/JUTFader.h b/include/JSystem/JUtility/JUTFader.h index 8e07a3da..985eae97 100644 --- a/include/JSystem/JUtility/JUTFader.h +++ b/include/JSystem/JUtility/JUTFader.h @@ -6,19 +6,13 @@ #include "JSystem/JUtility/JUTVideo.h" #include "types.h" -struct JUTFader -{ - enum EStatus - { - Status_Out = 0, - Status_In = 1, - Status_FadingIn = 2, - Status_FadingOut = 3 - }; +struct JUTFader { + enum EStatus { Status_Out = 0, Status_In = 1, Status_FadingIn = 2, Status_FadingOut = 3 }; JUTFader(int, int, int, int, JUtility::TColor); - virtual ~JUTFader() {} // _08 (weak) + virtual ~JUTFader() { + } // _08 (weak) virtual bool startFadeIn(int duration); // _0C virtual bool startFadeOut(int duration); // _10 virtual void draw(); // _14 @@ -29,9 +23,13 @@ struct JUTFader void start(int); void setStatus(EStatus, int); - EStatus getStatus() const { return mStatus; } + EStatus getStatus() const { + return mStatus; + } - void setColor(JUtility::TColor color) { mColor.set(color.r, color.g, color.b, mColor.a); } + void setColor(JUtility::TColor color) { + mColor.set(color.r, color.g, color.b, mColor.a); + } // _00 VTBL EStatus mStatus; // _04 - current status @@ -43,4 +41,4 @@ struct JUTFader EStatus _28; // _28 - ??? }; -#endif \ No newline at end of file +#endif diff --git a/include/JSystem/JUtility/JUTFont.h b/include/JSystem/JUtility/JUTFont.h index 9aa3946e..07a59fea 100644 --- a/include/JSystem/JUtility/JUTFont.h +++ b/include/JSystem/JUtility/JUTFont.h @@ -13,17 +13,14 @@ struct JKRHeap; struct ResFONT; -struct JUTFont -{ +struct JUTFont { typedef bool (*IsLeadByte)(int); - struct TWidth - { + struct TWidth { u8 w0; u8 w1; - const TWidth &operator=(const TWidth &other) - { + const TWidth& operator=(const TWidth& other) { w0 = other.w0; w1 = other.w1; return *this; @@ -32,41 +29,47 @@ struct JUTFont JUTFont(); - virtual ~JUTFont() {} // _08 - virtual void setGX() = 0; // _0C - virtual void setGX(JUtility::TColor, JUtility::TColor) { setGX(); }; // _10 - virtual f32 drawChar_scale(f32, f32, f32, f32, int, bool) = 0; // _14 - virtual int getLeading() const = 0; // _18 - virtual int getAscent() const = 0; // _1C - virtual int getDescent() const = 0; // _20 - virtual int getHeight() const = 0; // _24 - virtual int getWidth() const = 0; // _28 - virtual void getWidthEntry(int, JUTFont::TWidth *) const = 0; // _2C - virtual int getCellWidth() const { return getWidth(); }; // _30 - virtual int getCellHeight() const { return getHeight(); }; // _34 - virtual int getFontType() const = 0; // _38 - virtual const ResFONT *getResFont() const = 0; // _3C - virtual bool isLeadByte(int) const = 0; // _40 + virtual ~JUTFont() { + } // _08 + virtual void setGX() = 0; // _0C + virtual void setGX(JUtility::TColor, JUtility::TColor) { + setGX(); + }; // _10 + virtual f32 drawChar_scale(f32, f32, f32, f32, int, bool) = 0; // _14 + virtual int getLeading() const = 0; // _18 + virtual int getAscent() const = 0; // _1C + virtual int getDescent() const = 0; // _20 + virtual int getHeight() const = 0; // _24 + virtual int getWidth() const = 0; // _28 + virtual void getWidthEntry(int, JUTFont::TWidth*) const = 0; // _2C + virtual int getCellWidth() const { + return getWidth(); + }; // _30 + virtual int getCellHeight() const { + return getHeight(); + }; // _34 + virtual int getFontType() const = 0; // _38 + virtual const ResFONT* getResFont() const = 0; // _3C + virtual bool isLeadByte(int) const = 0; // _40 void initialize_state(); void setCharColor(JUtility::TColor); void setGradColor(JUtility::TColor, JUtility::TColor); - f32 drawString_size_scale(f32, f32, f32, f32, const char *, u32, bool); + f32 drawString_size_scale(f32, f32, f32, f32, const char*, u32, bool); - void drawString(int posX, int posY, const char *str, bool visible) { drawString_size(posX, posY, str, strlen(str), visible); } + void drawString(int posX, int posY, const char* str, bool visible) { + drawString_size(posX, posY, str, strlen(str), visible); + } - void drawString_size(int posX, int posY, const char *str, u32 len, bool visible) - { + void drawString_size(int posX, int posY, const char* str, u32 len, bool visible) { drawString_size_scale(posX, posY, getWidth(), getHeight(), str, len, visible); } - void drawString_scale(f32 posX, f32 posY, f32 width, f32 height, const char *str, bool visible) - { + void drawString_scale(f32 posX, f32 posY, f32 width, f32 height, const char* str, bool visible) { drawString_size_scale(posX, posY, width, height, str, strlen(str), visible); } - int getWidth(int i_no) const - { + int getWidth(int i_no) const { TWidth width; getWidthEntry(i_no, &width); return width.w0; @@ -77,18 +80,23 @@ struct JUTFont mFixedWidth = width; } - bool isValid() const { return mValid; } + bool isValid() const { + return mValid; + } - static bool isLeadByte_1Byte(int c) { return false; } - static bool isLeadByte_2Byte(int c) { return true; } - static bool isLeadByte_ShiftJIS(int c) - { + static bool isLeadByte_1Byte(int c) { + return false; + } + static bool isLeadByte_2Byte(int c) { + return true; + } + static bool isLeadByte_ShiftJIS(int c) { return ((c >= 0x81) && (c <= 0x9F)) || ((c >= 0xE0) && (c <= 0xFC)); } // _00 = VTBL - bool mValid; // _04 - bool mFixed; // _05 + bool mValid; // _04 + bool mFixed; // _05 int mFixedWidth; // _08 JUtility::TColor mColor1; // _0C, bottom left JUtility::TColor mColor2; // _10, bottom right @@ -96,39 +104,55 @@ struct JUTFont JUtility::TColor mColor4; // _18, top right }; -struct JUTRomFont : public JUTFont -{ +struct JUTRomFont : public JUTFont { // @fabricatedName - struct AboutEncoding - { + struct AboutEncoding { u32 mFontType; // _00 u32 mDataSize; // _04 IsLeadByte mIsLeadByteFunction; // _08 }; JUTRomFont(); - JUTRomFont(JKRHeap *); + JUTRomFont(JKRHeap*); - virtual ~JUTRomFont(); // _08 - virtual void setGX(); // _0C - virtual f32 drawChar_scale(f32, f32, f32, f32, int, bool); // _14 - virtual int getWidth() const { return spFontHeader_->width; }; // _28 - virtual int getLeading() const { return spFontHeader_->leading; }; // _18 - virtual int getAscent() const { return spFontHeader_->ascent; }; // _1C - virtual int getDescent() const { return spFontHeader_->descent; }; // _20 - virtual int getHeight() const { return getAscent() + getDescent(); }; // _24 - virtual void getWidthEntry(int, JUTFont::TWidth *) const; // _2C - virtual int getCellWidth() const { return spFontHeader_->cellWidth; }; // _30 - virtual int getCellHeight() const { return spFontHeader_->cellHeight; }; // _34 - virtual ResFONT *getResFont() const { return nullptr; }; // _3C - virtual int getFontType() const { return spAboutEncoding_->mFontType; }; // _38 - virtual bool isLeadByte(int) const; // _40 + virtual ~JUTRomFont(); // _08 + virtual void setGX(); // _0C + virtual f32 drawChar_scale(f32, f32, f32, f32, int, bool); // _14 + virtual int getWidth() const { + return spFontHeader_->width; + }; // _28 + virtual int getLeading() const { + return spFontHeader_->leading; + }; // _18 + virtual int getAscent() const { + return spFontHeader_->ascent; + }; // _1C + virtual int getDescent() const { + return spFontHeader_->descent; + }; // _20 + virtual int getHeight() const { + return getAscent() + getDescent(); + }; // _24 + virtual void getWidthEntry(int, JUTFont::TWidth*) const; // _2C + virtual int getCellWidth() const { + return spFontHeader_->cellWidth; + }; // _30 + virtual int getCellHeight() const { + return spFontHeader_->cellHeight; + }; // _34 + virtual ResFONT* getResFont() const { + return nullptr; + }; // _3C + virtual int getFontType() const { + return spAboutEncoding_->mFontType; + }; // _38 + virtual bool isLeadByte(int) const; // _40 - void initiate(JKRHeap *); - void loadImage(JKRHeap *); + void initiate(JKRHeap*); + void loadImage(JKRHeap*); - static AboutEncoding *spAboutEncoding_; - static OSFontHeader *spFontHeader_; + static AboutEncoding* spAboutEncoding_; + static OSFontHeader* spFontHeader_; static u32 suFontHeaderRefered_; // they misspelled referred static AboutEncoding saoAboutEncoding_[2]; @@ -136,23 +160,21 @@ struct JUTRomFont : public JUTFont // _00-_1C = JUTFont }; -struct BlockHeader -{ - const BlockHeader *getNext() const { return reinterpret_cast(reinterpret_cast(this) + this->mSize); } - inline static void advance(const BlockHeader **iterator) - { - *iterator = reinterpret_cast(reinterpret_cast(*iterator) + (*iterator)->mSize); +struct BlockHeader { + const BlockHeader* getNext() const { + return reinterpret_cast(reinterpret_cast(this) + this->mSize); + } + inline static void advance(const BlockHeader** iterator) { + *iterator = reinterpret_cast(reinterpret_cast(*iterator) + (*iterator)->mSize); } u32 mMagic; // _00 u32 mSize; // _04 }; -struct ResFONT -{ +struct ResFONT { // INF1, size: 0x14 - struct InfoBlock : public BlockHeader - { + struct InfoBlock : public BlockHeader { // _00 = BlockHeader u16 mFontType; // _08 u16 mAscent; // _0A @@ -163,8 +185,7 @@ struct ResFONT }; // WID1, size: 0x10 - struct WidthBlock : public BlockHeader - { + struct WidthBlock : public BlockHeader { // _00 = BlockHeader u16 mStartCode; // _08 u16 mEndCode; // _0A @@ -172,8 +193,7 @@ struct ResFONT }; // MAP1, size: 0x14 - struct MapBlock : public BlockHeader - { + struct MapBlock : public BlockHeader { // _00 = BlockHeader u16 mMappingMethod; // _08 u16 mStartCode; // _0A @@ -183,8 +203,7 @@ struct ResFONT }; // GLY1, size: 0x20 - struct GlyphBlock : public BlockHeader - { + struct GlyphBlock : public BlockHeader { // _00 = BlockHeader u16 mStartCode; // _08 u16 mEndCode; // _0A @@ -210,40 +229,52 @@ struct ResFONT /** * @size{0x70} */ -struct JUTResFont : public JUTFont -{ +struct JUTResFont : public JUTFont { JUTResFont(); - JUTResFont(const ResFONT *, JKRHeap *); + JUTResFont(const ResFONT*, JKRHeap*); - virtual ~JUTResFont(); // _08 - virtual void setGX(); // _0C - virtual void setGX(JUtility::TColor, JUtility::TColor); // _10 - virtual f32 drawChar_scale(f32, f32, f32, f32, int, bool); // _14 - virtual int getDescent() const { return mInfoBlock->mDescent; }; // _20 - virtual int getHeight() const { return getAscent() + getDescent(); }; // _24 - virtual int getAscent() const { return mInfoBlock->mAscent; }; // _1C - virtual int getWidth() const { return mInfoBlock->mWidth; }; // _28 - virtual void getWidthEntry(int, JUTFont::TWidth *) const; // _2C - virtual int getCellWidth() const; // _30 - virtual int getCellHeight() const; // _34 - virtual int getFontType() const { return mInfoBlock->mFontType; }; // _38 - virtual const ResFONT *getResFont() const { return mResource; }; // _3C - virtual int getLeading() const { return mInfoBlock->mLeading; }; // _18 - virtual bool isLeadByte(int) const; // _40 - virtual void loadImage(int, GXTexMapID); // _44 - virtual void setBlock(); // _48 + virtual ~JUTResFont(); // _08 + virtual void setGX(); // _0C + virtual void setGX(JUtility::TColor, JUtility::TColor); // _10 + virtual f32 drawChar_scale(f32, f32, f32, f32, int, bool); // _14 + virtual int getDescent() const { + return mInfoBlock->mDescent; + }; // _20 + virtual int getHeight() const { + return getAscent() + getDescent(); + }; // _24 + virtual int getAscent() const { + return mInfoBlock->mAscent; + }; // _1C + virtual int getWidth() const { + return mInfoBlock->mWidth; + }; // _28 + virtual void getWidthEntry(int, JUTFont::TWidth*) const; // _2C + virtual int getCellWidth() const; // _30 + virtual int getCellHeight() const; // _34 + virtual int getFontType() const { + return mInfoBlock->mFontType; + }; // _38 + virtual const ResFONT* getResFont() const { + return mResource; + }; // _3C + virtual int getLeading() const { + return mInfoBlock->mLeading; + }; // _18 + virtual bool isLeadByte(int) const; // _40 + virtual void loadImage(int, GXTexMapID); // _44 + virtual void setBlock(); // _48 - int convertSjis(int, u16 *) const; + int convertSjis(int, u16*) const; void countBlock(); void deleteMemBlocks_ResFont(); int getFontCode(int) const; void initialize_state(); - bool initiate(const ResFONT *, JKRHeap *); - void loadFont(int, GXTexMapID, TWidth *); - bool protected_initiate(const ResFONT *, JKRHeap *); + bool initiate(const ResFONT*, JKRHeap*); + void loadFont(int, GXTexMapID, TWidth*); + bool protected_initiate(const ResFONT*, JKRHeap*); - inline void delete_and_initialize() - { + inline void delete_and_initialize() { deleteMemBlocks_ResFont(); initialize_state(); } @@ -256,33 +287,30 @@ struct JUTResFont : public JUTFont int mHeight; // _20 GXTexObj _24; // _24 int _44; // _44 - const ResFONT *mResource; // _48 - ResFONT::InfoBlock *mInfoBlock; // _4C, INF1 - void **mMemBlocks; // _50 - ResFONT::WidthBlock **mWidthBlocks; // _54, WID1 - ResFONT::GlyphBlock **mGlyphBlocks; // _58, GLY1 - ResFONT::MapBlock **mMapBlocks; // _5C, MAP1 + const ResFONT* mResource; // _48 + ResFONT::InfoBlock* mInfoBlock; // _4C, INF1 + void** mMemBlocks; // _50 + ResFONT::WidthBlock** mWidthBlocks; // _54, WID1 + ResFONT::GlyphBlock** mGlyphBlocks; // _58, GLY1 + ResFONT::MapBlock** mMapBlocks; // _5C, MAP1 u16 mWidthBlockCount; // _60 u16 mGlyphBlockCount; // _62 u16 mMapBlockCount; // _64 u16 _66; // _66 u16 mMaxCode; // _68 - IsLeadByte *mIsLeadByte; // _6C + IsLeadByte* mIsLeadByte; // _6C }; -struct JUTCacheFont : public JUTResFont -{ - enum EPagingType - { +struct JUTCacheFont : public JUTResFont { + enum EPagingType { CFPAGETYPE_Unk0 = 0, CFPAGETYPE_Unk1 = 1, }; - struct TGlyphCacheInfo - { + struct TGlyphCacheInfo { // TODO: the rest of the data members - TGlyphCacheInfo *mPrev; // _00 - TGlyphCacheInfo *mNext; // _04 + TGlyphCacheInfo* mPrev; // _00 + TGlyphCacheInfo* mNext; // _04 u8 _08[4]; // _08 u16 _0C; // _0C u16 _0E; // _0E @@ -293,13 +321,12 @@ struct JUTCacheFont : public JUTResFont GXTexObj mGxTexObj; // _20 }; - struct TCachePage - { + struct TCachePage { u8 _00[0x8]; // _00, unknown s16 _08; // _08 u16 _0A; // _0A u8 _0C[0x4]; // _0C, unknown - u8 *_10; // _10 + u8* _10; // _10 u16 _14; // _14 u16 _18; // _18 u16 _1C; // _1C @@ -309,58 +336,62 @@ struct JUTCacheFont : public JUTResFont }; JUTCacheFont(); - JUTCacheFont(const ResFONT *, void *, u32, JKRHeap *); - JUTCacheFont(const ResFONT *, u32, JKRHeap *); + JUTCacheFont(const ResFONT*, void*, u32, JKRHeap*); + JUTCacheFont(const ResFONT*, u32, JKRHeap*); virtual ~JUTCacheFont(); // _08 virtual void loadImage(int, _GXTexMapID); // _44 virtual void setBlock(); // _48 - bool allocArea(void *, u32, JKRHeap *); - bool allocArray(JKRHeap *); + bool allocArea(void*, u32, JKRHeap*); + bool allocArray(JKRHeap*); void deleteMemBlocks_CacheFont(); - bool getMemorySize(const ResFONT *, u16 *, u32 *, u16 *, u32 *, u16 *, u32 *, u32 *); + bool getMemorySize(const ResFONT*, u16*, u32*, u16*, u32*, u16*, u32*, u32*); void initialize_state(); - bool initiate(const ResFONT *, void *, u32, JKRHeap *); - bool internal_initiate(const ResFONT *, void *, u32, JKRHeap *); + bool initiate(const ResFONT*, void*, u32, JKRHeap*); + bool internal_initiate(const ResFONT*, void*, u32, JKRHeap*); void invalidiateAllCache(); - TGlyphCacheInfo *loadCache_char_subroutine(int *, bool); - void loadCache_string(const char *, bool); - void prepend(TGlyphCacheInfo *); - void unlink(TGlyphCacheInfo *); + TGlyphCacheInfo* loadCache_char_subroutine(int*, bool); + void loadCache_string(const char*, bool); + void prepend(TGlyphCacheInfo*); + void unlink(TGlyphCacheInfo*); // Unused/inlined: void determineBlankPage(); - void getGlyphFromAram(TGlyphCacheInfo *, TCachePage *, int *, int *); + void getGlyphFromAram(TGlyphCacheInfo*, TCachePage*, int*, int*); void loadCache_char(int, bool); - void loadCache_string_size(const char *, u32, bool); + void loadCache_string_size(const char*, u32, bool); void unlockCache_all(); void unlockCache_char(int); - void unlockCache_string(const char *); - void unlockCache_string_size(const char *, u32); + void unlockCache_string(const char*); + void unlockCache_string_size(const char*, u32); - void setPagingType(EPagingType type) { mPagingType = type; } + void setPagingType(EPagingType type) { + mPagingType = type; + } - static u32 calcCacheSize(u32 param_0, int param_1) { return (ALIGN_NEXT(param_0, 0x20) + 0x40) * param_1; } + static u32 calcCacheSize(u32 param_0, int param_1) { + return (ALIGN_NEXT(param_0, 0x20) + 0x40) * param_1; + } // _00 = VTBL // _00-_70 = JUTResFont u32 mWidthBlocksSize; // _70 u32 mGlyphBlocksSize; // _74 u32 mMapBlocksSize; // _78 - void *_7C; // _7C - void *_80; // _80 - void *_84; // _84 + void* _7C; // _7C + void* _80; // _80 + void* _84; // _84 u32 mMaxSheetSize; // _88 EPagingType mPagingType; // _8C - void *mCacheBuffer; // _90 + void* mCacheBuffer; // _90 u32 _94; // _94 u32 mCachePage; // _98 - TGlyphCacheInfo *_9C; // _9C - TGlyphCacheInfo *_A0; // _A0 - void *_A4; // _A4 + TGlyphCacheInfo* _9C; // _9C + TGlyphCacheInfo* _A0; // _A0 + void* _A4; // _A4 u32 _A8; // _A8 - JKRAramBlock *mAramBlock; // _AC + JKRAramBlock* mAramBlock; // _AC u8 _B0; // _B0 int _B4; // _B4 }; diff --git a/include/JSystem/JUtility/JUTGamePad.h b/include/JSystem/JUtility/JUTGamePad.h index 8540bd92..2385a6c4 100644 --- a/include/JSystem/JUtility/JUTGamePad.h +++ b/include/JSystem/JUtility/JUTGamePad.h @@ -10,9 +10,8 @@ #ifdef __cplusplus extern "C" { -class JUTGamePadRecordBase -{ -public: +class JUTGamePadRecordBase { + public: JUTGamePadRecordBase(); virtual ~JUTGamePadRecordBase(); virtual void read(PADStatus* status) = 0; @@ -27,22 +26,11 @@ public: }; typedef void (*JUTResetBtnCb)(int, void*); -class JUTGamePad : public JKRDisposer -{ -public: - enum EPadPort - { - Port_unknown = -999, - Port_Invalid = -1, - Port1 = 0, - Port2, - Port3, - Port4, - PortRecorder - }; +class JUTGamePad : public JKRDisposer { + public: + enum EPadPort { Port_unknown = -999, Port_Invalid = -1, Port1 = 0, Port2, Port3, Port4, PortRecorder }; - enum EButtons - { + enum EButtons { MAINSTICK_UP = 0x8000000, MAINSTICK_DOWN = 0x4000000, MAINSTICK_RIGHT = 0x2000000, @@ -65,24 +53,11 @@ public: DPAD_LEFT = 0x1 }; - enum EStickMode - { - NonClamped, - Clamped - }; + enum EStickMode { NonClamped, Clamped }; - enum EClampMode - { - NoClamp, - Clamp, - ClampCircle - }; + enum EClampMode { NoClamp, Clamp, ClampCircle }; - enum EWhichStick - { - WhichStick_MainStick, - WhichStick_SubStick - }; + enum EWhichStick { WhichStick_MainStick, WhichStick_SubStick }; JUTGamePad(); JUTGamePad(EPadPort port); @@ -235,38 +210,40 @@ public: JUTGamePadRecordBase* getPadReplay() const { return this->mPadReplay; - } + } - class CButton - { - public: - CButton() { this->clear(); }; + class CButton { + public: + CButton() { + this->clear(); + }; void clear(); void update(const PADStatus* padStatus, u32 buttons); void setRepeat(u32 mask, u32 delay, u32 frequency); - u32 mButton; // buttons held down - u32 mTrigger; // buttons newly pressed this frame - u32 mRelease; // buttons released this frame - u8 mAnalogA; // - u8 mAnalogB; // - u8 mAnalogL; // left trigger percent - u8 mAnalogR; // right trigger percent - f32 mAnalogLf; // left trigger analog percent - f32 mAnalogRf; // right trigger analog percent - u32 mRepeat; // buttons currently marked as "repeated" triggers when held - u32 mRepeatTimer; // frames since current button combo has been held - u32 mRepeatLastButton; // last buttons pressed - u32 mRepeatMask; // button mask to allow repeating trigger inputs - u32 mRepeatDelay; // delay before beginning repeated input - u32 mRepeatFrequency; // repeat input every X frames + u32 mButton; // buttons held down + u32 mTrigger; // buttons newly pressed this frame + u32 mRelease; // buttons released this frame + u8 mAnalogA; // + u8 mAnalogB; // + u8 mAnalogL; // left trigger percent + u8 mAnalogR; // right trigger percent + f32 mAnalogLf; // left trigger analog percent + f32 mAnalogRf; // right trigger analog percent + u32 mRepeat; // buttons currently marked as "repeated" triggers when held + u32 mRepeatTimer; // frames since current button combo has been held + u32 mRepeatLastButton; // last buttons pressed + u32 mRepeatMask; // button mask to allow repeating trigger inputs + u32 mRepeatDelay; // delay before beginning repeated input + u32 mRepeatFrequency; // repeat input every X frames }; - class CStick - { - public: - CStick() { this->clear(); } + class CStick { + public: + CStick() { + this->clear(); + } void clear(); u32 update(s8 x, s8 y, JUTGamePad::EStickMode, JUTGamePad::EWhichStick); @@ -278,16 +255,13 @@ public: s16 mAngle; }; - class CRumble - { - public: - enum ERumble { - Rumble0, - Rumble1, - Rumble2 - }; + class CRumble { + public: + enum ERumble { Rumble0, Rumble1, Rumble2 }; - CRumble(JUTGamePad* gamePad) { this->clear(gamePad); } + CRumble(JUTGamePad* gamePad) { + this->clear(gamePad); + } static u8 mStatus[PAD_MAX_CONTROLLERS]; static u32 mEnabled; @@ -299,7 +273,7 @@ public: static bool isEnabled(u32 channel) { return (JUTGamePad::CRumble::mEnabled & channel) != 0; } - + void clear(); void clear(JUTGamePad* gamePad); void update(s16); @@ -312,8 +286,10 @@ public: }; class C3ButtonReset { - public: - C3ButtonReset() { mReset = false; } + public: + C3ButtonReset() { + mReset = false; + } static u32 sResetPattern; static u32 sResetMaskPattern; @@ -328,7 +304,9 @@ public: bool mReset; }; - static PADStatus *getPadStatus(int idx) { return &mPadStatus[idx]; } + static PADStatus* getPadStatus(int idx) { + return &mPadStatus[idx]; + } static JSUList mPadList; static CButton mPadButton[PAD_MAX_CONTROLLERS]; @@ -340,21 +318,19 @@ public: static f32 sReleasePoint; static PADStatus mPadStatus[PAD_MAX_CONTROLLERS]; - - CButton mButtons; // _18 - CStick mMainStick; // _48 - CStick mSubStick; // _58 - CRumble mRumble; // _68 - s16 mPortNum; // _78 - s8 mErrorStatus; // _7A - JSULink mLink; // _7C + CButton mButtons; // _18 + CStick mMainStick; // _48 + CStick mSubStick; // _58 + CRumble mRumble; // _68 + s16 mPortNum; // _78 + s8 mErrorStatus; // _7A + JSULink mLink; // _7C JUTGamePadRecordBase* mPadRecord; JUTGamePadRecordBase* mPadReplay; u32 _94; - C3ButtonReset mButtonReset; // _98 - OSTime mResetTime; // _A0 + C3ButtonReset mButtonReset; // _98 + OSTime mResetTime; // _A0 }; - } #endif diff --git a/include/JSystem/JUtility/JUTGraphFifo.h b/include/JSystem/JUtility/JUTGraphFifo.h index c52f58c4..fe261316 100644 --- a/include/JSystem/JUtility/JUTGraphFifo.h +++ b/include/JSystem/JUtility/JUTGraphFifo.h @@ -4,8 +4,7 @@ #include "types.h" #include -struct JUTGraphFifo -{ +struct JUTGraphFifo { JUTGraphFifo(u32); virtual ~JUTGraphFifo(); // _08 @@ -13,21 +12,21 @@ struct JUTGraphFifo void becomeCurrent(); void setBreakPt(); - void getGpStatus() - { + void getGpStatus() { GXGetGPStatus((GXBool*)&mGpStatus[0], (GXBool*)&mGpStatus[1], (GXBool*)&mGpStatus[2], (GXBool*)&mGpStatus[3], (GXBool*)&mGpStatus[4]); } - bool isGPActive() - { + bool isGPActive() { getGpStatus(); return mGpStatus[2] == false; } - void save() { GXSaveCPUFifo(this->mFifo); } + void save() { + GXSaveCPUFifo(this->mFifo); + } - static JUTGraphFifo *sCurrentFifo; + static JUTGraphFifo* sCurrentFifo; static GXBool mGpStatus[5]; static bool sInitiated; @@ -38,6 +37,8 @@ struct JUTGraphFifo u8 _10[0xC]; // _10 }; -inline void JUTCreateFifo(u32 bufSize) { new JUTGraphFifo(bufSize); } +inline void JUTCreateFifo(u32 bufSize) { + new JUTGraphFifo(bufSize); +} -#endif \ No newline at end of file +#endif diff --git a/include/JSystem/JUtility/JUTProcBar.h b/include/JSystem/JUtility/JUTProcBar.h index 42e04a31..b5668011 100644 --- a/include/JSystem/JUtility/JUTProcBar.h +++ b/include/JSystem/JUtility/JUTProcBar.h @@ -9,46 +9,43 @@ #include "types.h" #ifdef __cplusplus -class JUTProcBar -{ -public: - struct CTime - { - CTime() { clear(); } +class JUTProcBar { + public: + struct CTime { + CTime() { + clear(); + } - void clear() - { + void clear() { mCost = 0; _08 = 0; _0C = 0; } - void start(u8 red, u8 green, u8 blue) - { + void start(u8 red, u8 green, u8 blue) { mR = red; mG = green; mB = blue; mStartTick = OSGetTick(); } - void end() - { + void end() { mCost = OSTicksToMicroseconds(OSDiffTick(OSGetTick(), mStartTick)); if (mCost == 0) mCost = 1; } - void accumePeek() - { - //u32 prev = ++_0C; - if (++_0C >= 0x10 || mCost >= _08) - { + void accumePeek() { + // u32 prev = ++_0C; + if (++_0C >= 0x10 || mCost >= _08) { _08 = mCost; _0C = 0; } } - int calcBarSize(int p1, int p2) { return mCost * p1 / p2; } + int calcBarSize(int p1, int p2) { + return mCost * p1 / p2; + } u32 mStartTick; // _00 u32 mCost; // _04 @@ -59,12 +56,17 @@ public: u8 mB; // _12 }; - struct CParamSet { - void setBarWidth(int w) { mBarWidth = w; }; - void setWidth(int w) { mWidth = w; } - void setUserPosition(int pos) { mUserPosition = pos; } - void setPosition(int x, int y) - { + struct CParamSet { + void setBarWidth(int w) { + mBarWidth = w; + }; + void setWidth(int w) { + mWidth = w; + } + void setUserPosition(int pos) { + mUserPosition = pos; + } + void setPosition(int x, int y) { mPosX = x; mPosY = y; } @@ -76,7 +78,7 @@ public: /* 0x10 */ int mUserPosition; }; - JUTProcBar(); // unused / inlined + JUTProcBar(); // unused / inlined ~JUTProcBar(); // unused / inlined static JUTProcBar* create(); @@ -89,7 +91,7 @@ public: // Unused Functions / Inlines void bar_subroutine(int, int, int, int, int, int, int, JUtility::TColor, JUtility::TColor); - void adjustMeterLength(u32, f32 *, f32, f32, int *); + void adjustMeterLength(u32, f32*, f32, f32, int*); void getUnuseUserBar(); u32 getGpCost() const { @@ -108,21 +110,49 @@ public: return sManager; } - void idleStart() { mIdle.start(255, 129, 30); } - void idleEnd() { mIdle.end(); } - void gpStart() { mGp.start(255, 129, 30); } - void gpEnd() { mGp.end(); } - void cpuStart() { mCpu.start(255, 129, 30); } - void cpuEnd() { mCpu.end(); } - void gpWaitStart() { mGpWait.start(255, 129, 30); } - void gpWaitEnd() { mGpWait.end(); } - void wholeLoopStart() { mWholeLoop.start(255, 129, 30); } - void wholeLoopEnd() { mWholeLoop.end(); } + void idleStart() { + mIdle.start(255, 129, 30); + } + void idleEnd() { + mIdle.end(); + } + void gpStart() { + mGp.start(255, 129, 30); + } + void gpEnd() { + mGp.end(); + } + void cpuStart() { + mCpu.start(255, 129, 30); + } + void cpuEnd() { + mCpu.end(); + } + void gpWaitStart() { + mGpWait.start(255, 129, 30); + } + void gpWaitEnd() { + mGpWait.end(); + } + void wholeLoopStart() { + mWholeLoop.start(255, 129, 30); + } + void wholeLoopEnd() { + mWholeLoop.end(); + } - void setCostFrame(int frame) { mCostFrame = frame; } - void setVisible(bool visible) { mVisible = visible; } - bool isVisible() { return mVisible; } - void setHeapBarVisible(bool visible) { mHeapBarVisible = visible; } + void setCostFrame(int frame) { + mCostFrame = frame; + } + void setVisible(bool visible) { + mVisible = visible; + } + bool isVisible() { + return mVisible; + } + void setHeapBarVisible(bool visible) { + mHeapBarVisible = visible; + } void userStart(int idx, u8 p2, u8 p3, u8 p4) { sManager->mUsers[idx].start(p2, p3, p4); sManager->_108 |= 1 << idx; @@ -136,22 +166,22 @@ public: return mParams.mBarWidth * 2; } - static JUTProcBar* sManager; // might be private too -private: - CTime mIdle; // _00 - CTime mGp; // _14 - CTime mCpu; // _28 - CTime mGpWait; // _3C - CTime mWholeLoop; // _50 - CTime mUsers[8]; // _64 - int mCostFrame; // _104 - u32 _108; // _108, active users? - bool mVisible; // _10C - int _110; // _110 - CParamSet mParams; // _114 - int _128; // _128 - JKRHeap* mWatchHeap; // _12C - bool mHeapBarVisible; // _130 + static JUTProcBar* sManager; // might be private too + private: + CTime mIdle; // _00 + CTime mGp; // _14 + CTime mCpu; // _28 + CTime mGpWait; // _3C + CTime mWholeLoop; // _50 + CTime mUsers[8]; // _64 + int mCostFrame; // _104 + u32 _108; // _108, active users? + bool mVisible; // _10C + int _110; // _110 + CParamSet mParams; // _114 + int _128; // _128 + JKRHeap* mWatchHeap; // _12C + bool mHeapBarVisible; // _130 }; // 0x134 size #endif diff --git a/include/JSystem/JUtility/JUTVideo.h b/include/JSystem/JUtility/JUTVideo.h index 6c62f6cd..e9d5f87d 100644 --- a/include/JSystem/JUtility/JUTVideo.h +++ b/include/JSystem/JUtility/JUTVideo.h @@ -11,30 +11,45 @@ typedef u8 (*Pattern)[2]; -struct JUTVideo -{ +struct JUTVideo { JUTVideo(const GXRenderModeObj*); virtual ~JUTVideo(); // _08 - static JUTVideo *createManager(const GXRenderModeObj*); + static JUTVideo* createManager(const GXRenderModeObj*); static void destroyManager(); static void preRetraceProc(unsigned long); static void postRetraceProc(unsigned long); static void drawDoneCallback(); - u32 getEfbHeight() const { return mRenderModeObj->efbHeight; } - u32 getXfbHeight() const { return mRenderModeObj->xfbHeight & 0xffff; } - u32 getFbWidth() const { return (u16)mRenderModeObj->fbWidth; } + u32 getEfbHeight() const { + return mRenderModeObj->efbHeight; + } + u32 getXfbHeight() const { + return mRenderModeObj->xfbHeight & 0xffff; + } + u32 getFbWidth() const { + return (u16)mRenderModeObj->fbWidth; + } void getBounds(u16& width, u16& height) const { width = getFbWidth(); height = getEfbHeight(); } - GXRenderModeObj *getRenderMode() const { return mRenderModeObj; } - u32 isAntiAliasing() const { return mRenderModeObj->aa; } - Pattern getSamplePattern() const { return mRenderModeObj->sample_pattern; } - u8 *getVFilter() const { return mRenderModeObj->vfilter; } - OSMessageQueue *getMessageQueue() { return &mMessageQueue; }; + GXRenderModeObj* getRenderMode() const { + return mRenderModeObj; + } + u32 isAntiAliasing() const { + return mRenderModeObj->aa; + } + Pattern getSamplePattern() const { + return mRenderModeObj->sample_pattern; + } + u8* getVFilter() const { + return mRenderModeObj->vfilter; + } + OSMessageQueue* getMessageQueue() { + return &mMessageQueue; + }; static void drawDoneStart(); static void dummyNoDrawWait(); void setRenderMode(const GXRenderModeObj*); @@ -48,12 +63,18 @@ struct JUTVideo void getPixelAspect() const; // Static inline gets - static JUTVideo *getManager() { return sManager; } - static OSTick getVideoInterval() { return sVideoInterval; } - static OSTick getVideoLastTick() { return sVideoLastTick; } + static JUTVideo* getManager() { + return sManager; + } + static OSTick getVideoInterval() { + return sVideoInterval; + } + static OSTick getVideoLastTick() { + return sVideoLastTick; + } // _00 VTBL - GXRenderModeObj *mRenderModeObj; // _04 + GXRenderModeObj* mRenderModeObj; // _04 u32 _08; // _08 u32 mRetraceCount; // _0C int _10; // _10 @@ -68,12 +89,12 @@ struct JUTVideo OSMessage mMessage; // _34 OSMessageQueue mMessageQueue; // _38 - static JUTVideo *sManager; + static JUTVideo* sManager; static OSTick sVideoLastTick; static OSTick sVideoInterval; }; -inline JUTVideo *JUTGetVideoManager() { +inline JUTVideo* JUTGetVideoManager() { return JUTVideo::getManager(); } diff --git a/include/JSystem/JUtility/JUTXfb.h b/include/JSystem/JUtility/JUTXfb.h index 2016c719..7c731447 100644 --- a/include/JSystem/JUtility/JUTXfb.h +++ b/include/JSystem/JUtility/JUTXfb.h @@ -5,11 +5,10 @@ #include #include "types.h" -struct JUTExternalFB -{ - JUTExternalFB(GXRenderModeObj *, GXGamma, void *, u32); +struct JUTExternalFB { + JUTExternalFB(GXRenderModeObj*, GXGamma, void*, u32); - GXRenderModeObj *mRenderModeObj; // _00 + GXRenderModeObj* mRenderModeObj; // _00 u32 mSize; // _04 u8 _08[4]; // _08 u16 _0C; // _0C @@ -17,62 +16,77 @@ struct JUTExternalFB bool _10; // _10 }; -class JUTXfb -{ -public: - enum EXfbNumber - { - Unset = 0, - SingleBuffer = 1, - DoubleBuffer = 2, - TripleBuffer = 3 - }; +class JUTXfb { + public: + enum EXfbNumber { Unset = 0, SingleBuffer = 1, DoubleBuffer = 2, TripleBuffer = 3 }; void clearIndex(); void common_init(int); JUTXfb(const GXRenderModeObj*, JKRHeap*, JUTXfb::EXfbNumber); ~JUTXfb(); void delXfb(int); - static JUTXfb *createManager(const GXRenderModeObj* rmode, JKRHeap*, JUTXfb::EXfbNumber); + static JUTXfb* createManager(const GXRenderModeObj* rmode, JKRHeap*, JUTXfb::EXfbNumber); static void destroyManager(); void initiate(u16, u16, JKRHeap*, JUTXfb::EXfbNumber); u32 accumeXfbSize(); - int getBufferNum() const { return mBufferNum; } - int getDrawnXfbIndex() const { return mDrawnXfbIndex; } - s16 getDrawingXfbIndex() const { return mDrawingXfbIndex; } - s16 getDisplayingXfbIndex() const { return mDisplayingXfbIndex; } - int getSDrawingFlag() const { return mSDrawingFlag; } + int getBufferNum() const { + return mBufferNum; + } + int getDrawnXfbIndex() const { + return mDrawnXfbIndex; + } + s16 getDrawingXfbIndex() const { + return mDrawingXfbIndex; + } + s16 getDisplayingXfbIndex() const { + return mDisplayingXfbIndex; + } + int getSDrawingFlag() const { + return mSDrawingFlag; + } - void *getXfb(int index) const { + void* getXfb(int index) const { return mBuffer[index]; } - void *getDrawnXfb() const { + void* getDrawnXfb() const { return (mDrawnXfbIndex >= 0) ? mBuffer[mDrawnXfbIndex] : nullptr; } - void *getDrawingXfb() const { + void* getDrawingXfb() const { return (mDrawingXfbIndex >= 0) ? mBuffer[mDrawingXfbIndex] : nullptr; } - void *getDisplayingXfb() const { + void* getDisplayingXfb() const { return (mDisplayingXfbIndex >= 0) ? mBuffer[mDisplayingXfbIndex] : nullptr; } - void setBufferNum(int num) { mBufferNum = num; } - void setDisplayingXfbIndex(s16 index) { mDisplayingXfbIndex = index; } - void setSDrawingFlag(s32 flag) { mSDrawingFlag = flag; } - void setDrawnXfbIndex(s16 index) { mDrawnXfbIndex = index; } - void setDrawingXfbIndex(s16 index) { mDrawingXfbIndex = index; } + void setBufferNum(int num) { + mBufferNum = num; + } + void setDisplayingXfbIndex(s16 index) { + mDisplayingXfbIndex = index; + } + void setSDrawingFlag(s32 flag) { + mSDrawingFlag = flag; + } + void setDrawnXfbIndex(s16 index) { + mDrawnXfbIndex = index; + } + void setDrawingXfbIndex(s16 index) { + mDrawingXfbIndex = index; + } - static JUTXfb *getManager() { return sManager; } + static JUTXfb* getManager() { + return sManager; + } -private: - static JUTXfb *sManager; + private: + static JUTXfb* sManager; -private: - void *mBuffer[3]; // 00 + private: + void* mBuffer[3]; // 00 bool mXfbAllocated[3]; // 0c int mBufferNum; // 10 s16 mDrawingXfbIndex; // 14 diff --git a/include/JSystem/JUtility/TColor.h b/include/JSystem/JUtility/TColor.h index 3e6d334a..ae7172e0 100644 --- a/include/JSystem/JUtility/TColor.h +++ b/include/JSystem/JUtility/TColor.h @@ -11,63 +11,82 @@ extern "C" { #define TCOLOR_BLACK JUtility::TColor(0, 0, 0, 0) namespace JUtility { - struct TColor : public GXColor { - TColor() { set(0xFFFFFFFF); } +struct TColor : public GXColor { + TColor() { + set(0xFFFFFFFF); + } - TColor(u8 _r, u8 _g, u8 _b, u8 _a) { set(_r, _g, _b, _a); } + TColor(u8 _r, u8 _g, u8 _b, u8 _a) { + set(_r, _g, _b, _a); + } - TColor(u32 u32Color) { set(u32Color); } + TColor(u32 u32Color) { + set(u32Color); + } - TColor(GXColor color) { set(color); } + TColor(GXColor color) { + set(color); + } - TColor &operator=(const TColor &other) { - ((GXColor *)this)->operator=(other); - return *this; + TColor& operator=(const TColor& other) { + ((GXColor*)this)->operator=(other); + return *this; } /** @fabricated */ - TColor &operator=(const GXColorS10 &other) { - r = other.r; - g = other.g; - b = other.b; - a = other.a; - return *this; + TColor& operator=(const GXColorS10& other) { + r = other.r; + g = other.g; + b = other.b; + a = other.a; + return *this; } - operator u32() const { return toUInt32(); } - u32 toUInt32() const { return *(u32 *)&r; } + operator u32() const { + return toUInt32(); + } + u32 toUInt32() const { + return *(u32*)&r; + } void set(u8 cR, u8 cG, u8 cB, u8 cA) { - r = cR; - g = cG; - b = cB; - a = cA; + r = cR; + g = cG; + b = cB; + a = cA; } - void set(u32 u32Color) { *(u32 *)&r = u32Color; } + void set(u32 u32Color) { + *(u32*)&r = u32Color; + } - void set(GXColor gxColor) { *(GXColor *)&r = gxColor; } - void set(TColor color) { *this = color; } + void set(GXColor gxColor) { + *(GXColor*)&r = gxColor; + } + void set(TColor color) { + *this = color; + } void setRGB(u8 cR, u8 cG, u8 cB) { - r = cR; - g = cG; - b = cB; + r = cR; + g = cG; + b = cB; } - void setRGB(const TColor &other) { setRGB(other.r, other.g, other.b); } + void setRGB(const TColor& other) { + setRGB(other.r, other.g, other.b); + } - void setRGBA(const TColor &other) { - r = other.r; - g = other.g; - b = other.b; - a = other.a; + void setRGBA(const TColor& other) { + r = other.r; + g = other.g; + b = other.b; + a = other.a; } // _00 = GXColor (_00 = r, _01 = g, _02 = b, _03 = a) - }; +}; } // namespace JUtility - } #endif diff --git a/include/JSystem/ResTIMG.h b/include/JSystem/ResTIMG.h index 407c1e74..aae52405 100644 --- a/include/JSystem/ResTIMG.h +++ b/include/JSystem/ResTIMG.h @@ -11,48 +11,51 @@ typedef u8 _JUTTransparency; #endif enum { - ResTIMG_FORMAT_C8 = 9 - // TODO: others + ResTIMG_FORMAT_C8 = 9 + // TODO: others }; -enum { - ResTIMG_NO_PALETTE, - ResTIMG_PALETTE -}; +enum { ResTIMG_NO_PALETTE, ResTIMG_PALETTE }; struct ResTIMG { - inline BOOL isMIPmapEnabled() const { return (mIsMIPmapEnabled > 0); } + inline BOOL isMIPmapEnabled() const { + return (mIsMIPmapEnabled > 0); + } - inline u16 getWidth() const { return mSizeX; } - inline u16 getHeight() const { return mSizeY; } + inline u16 getWidth() const { + return mSizeX; + } + inline u16 getHeight() const { + return mSizeY; + } - u8 mTextureFormat; // _00 - _JUTTransparency mTransparency; // _01 - u16 mSizeX; // _02 - u16 mSizeY; // _04 - u8 mWrapS; // _06 - u8 mWrapT; // _07 - u8 mPaletteFormat; // _08 - u8 mColorFormat; // _09 - u16 mPaletteEntryCount; // _0A - u32 mPaletteOffset; // _0C - GXBool mIsMIPmapEnabled; // _10 - GXBool mDoEdgeLOD; // _11 - GXBool mIsBiasClamp; // _12 - GXBool mIsMaxAnisotropy; // _13 - u8 mMinFilterType; // _14 - u8 mMagFilterType; // _15 - s8 mMinLOD; // _16 - s8 mMaxLOD; // _17 - u8 mTotalImageCount; // _18 - u8 _19; // _19, unknown - s16 mLODBias; // _1A - u32 mImageDataOffset; // _1C + u8 mTextureFormat; // _00 + _JUTTransparency mTransparency; // _01 + u16 mSizeX; // _02 + u16 mSizeY; // _04 + u8 mWrapS; // _06 + u8 mWrapT; // _07 + u8 mPaletteFormat; // _08 + u8 mColorFormat; // _09 + u16 mPaletteEntryCount; // _0A + u32 mPaletteOffset; // _0C + GXBool mIsMIPmapEnabled; // _10 + GXBool mDoEdgeLOD; // _11 + GXBool mIsBiasClamp; // _12 + GXBool mIsMaxAnisotropy; // _13 + u8 mMinFilterType; // _14 + u8 mMagFilterType; // _15 + s8 mMinLOD; // _16 + s8 mMaxLOD; // _17 + u8 mTotalImageCount; // _18 + u8 _19; // _19, unknown + s16 mLODBias; // _1A + u32 mImageDataOffset; // _1C }; struct ResTIMGPair { - ResTIMG _00; - ResTIMG _20; + ResTIMG _00; + ResTIMG _20; }; #endif -#endif \ No newline at end of file +#endif diff --git a/src/static/JSystem/J2DGraph/J2DGrafContext.cpp b/src/static/JSystem/J2DGraph/J2DGrafContext.cpp index a672729b..96d934af 100644 --- a/src/static/JSystem/J2DGraph/J2DGrafContext.cpp +++ b/src/static/JSystem/J2DGraph/J2DGrafContext.cpp @@ -2,24 +2,20 @@ #include "MSL_C/math.h" J2DGrafContext::J2DGrafContext(f32 left, f32 top, f32 right, f32 bottom) - : mBounds(left, top, left + right, top + bottom) - , mScissorBounds(left, top, left + right, top + bottom) -{ + : mBounds(left, top, left + right, top + bottom), mScissorBounds(left, top, left + right, top + bottom) { JUtility::TColor color(-1); setColor(color); setLineWidth(6); } -void J2DGrafContext::setPort() -{ +void J2DGrafContext::setPort() { setScissor(); setup2D(); GXSetViewport(mBounds.i.x, mBounds.i.y, mBounds.f.x - mBounds.i.x, mBounds.f.y - mBounds.i.y, 0.0f, 1.0f); } -void J2DGrafContext::setup2D() -{ +void J2DGrafContext::setup2D() { GXSetNumIndStages(0); for (int i = 0; i < 8; i++) { GXSetTevDirect((GXTevStageID)i); @@ -59,8 +55,7 @@ void J2DGrafContext::setup2D() GXSetVtxDesc(GX_VA_TEX0, GX_NONE); } -void J2DGrafContext::setScissor() -{ +void J2DGrafContext::setScissor() { JGeometry::TBox2f hardBounds(0, 0, 1024, 1000); JGeometry::TBox2f newBounds(mScissorBounds); @@ -75,47 +70,48 @@ void J2DGrafContext::setScissor() } } -void J2DGrafContext::scissor(const JGeometry::TBox2f& bounds) { mScissorBounds = bounds; } - -void J2DGrafContext::place(const JGeometry::TBox2f& bounds) -{ - mBounds = bounds; +void J2DGrafContext::scissor(const JGeometry::TBox2f& bounds) { mScissorBounds = bounds; } -void J2DGrafContext::setColor(JUtility::TColor colorTL, JUtility::TColor colorTR, JUtility::TColor colorBR, JUtility::TColor colorBL) -{ +void J2DGrafContext::place(const JGeometry::TBox2f& bounds) { + mBounds = bounds; + mScissorBounds = bounds; +} + +void J2DGrafContext::setColor(JUtility::TColor colorTL, JUtility::TColor colorTR, JUtility::TColor colorBR, + JUtility::TColor colorBL) { mColorTL = colorTL; mColorTR = colorTR; mColorBR = colorBR; mColorBL = colorBL; - _B0.mType = 1; - _B0.mSrcFactor = 4; + _B0.mType = 1; + _B0.mSrcFactor = 4; _B0.mDestFactor = 5; - mLinePart.mType = 1; - mLinePart.mSrcFactor = 4; + mLinePart.mType = 1; + mLinePart.mSrcFactor = 4; mLinePart.mDestFactor = 5; - mBoxPart.mType = 1; - mBoxPart.mSrcFactor = 4; + mBoxPart.mType = 1; + mBoxPart.mSrcFactor = 4; mBoxPart.mDestFactor = 5; if ((u8)u32(mColorTL) != 0xFF) { return; } - _B0.mType = 0; - _B0.mSrcFactor = 1; + _B0.mType = 0; + _B0.mSrcFactor = 1; _B0.mDestFactor = 0; if ((u8)u32(mColorBR) != 0xFF) { return; } - mLinePart.mType = 0; - mLinePart.mSrcFactor = 1; + mLinePart.mType = 0; + mLinePart.mSrcFactor = 1; mLinePart.mDestFactor = 0; if ((u8)u32(mColorTR) != 0xFF) { @@ -125,20 +121,19 @@ void J2DGrafContext::setColor(JUtility::TColor colorTL, JUtility::TColor colorTR return; } - mBoxPart.mType = 0; - mBoxPart.mSrcFactor = 1; + mBoxPart.mType = 0; + mBoxPart.mSrcFactor = 1; mBoxPart.mDestFactor = 0; } -void J2DGrafContext::setLineWidth(u8 width) -{ +void J2DGrafContext::setLineWidth(u8 width) { mLineWidth = width; GXSetLineWidth(mLineWidth, GX_TO_ZERO); } -void J2DGrafContext::fillBox(const JGeometry::TBox2f& box) -{ - GXSetBlendMode((GXBlendMode)mBoxPart.mType, (GXBlendFactor)mBoxPart.mSrcFactor, (GXBlendFactor)mBoxPart.mDestFactor, GX_LO_SET); +void J2DGrafContext::fillBox(const JGeometry::TBox2f& box) { + GXSetBlendMode((GXBlendMode)mBoxPart.mType, (GXBlendFactor)mBoxPart.mSrcFactor, (GXBlendFactor)mBoxPart.mDestFactor, + GX_LO_SET); GXLoadPosMtxImm(mPosMtx, 0); GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_CLR_RGBA, GX_F32, 0); @@ -156,9 +151,9 @@ void J2DGrafContext::fillBox(const JGeometry::TBox2f& box) GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_CLR_RGBA, GX_RGBA4, 0); } -void J2DGrafContext::drawFrame(const JGeometry::TBox2f& box) -{ - GXSetBlendMode((GXBlendMode)mBoxPart.mType, (GXBlendFactor)mBoxPart.mSrcFactor, (GXBlendFactor)mBoxPart.mDestFactor, GX_LO_SET); +void J2DGrafContext::drawFrame(const JGeometry::TBox2f& box) { + GXSetBlendMode((GXBlendMode)mBoxPart.mType, (GXBlendFactor)mBoxPart.mSrcFactor, (GXBlendFactor)mBoxPart.mDestFactor, + GX_LO_SET); GXLoadPosMtxImm(mPosMtx, 0); GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_CLR_RGBA, GX_F32, 0); @@ -178,9 +173,9 @@ void J2DGrafContext::drawFrame(const JGeometry::TBox2f& box) GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_CLR_RGBA, GX_RGBA4, 0); } -void J2DGrafContext::line(JGeometry::TVec2f start, JGeometry::TVec2f end) -{ - GXSetBlendMode((GXBlendMode)mLinePart.mType, (GXBlendFactor)mLinePart.mSrcFactor, (GXBlendFactor)mLinePart.mDestFactor, GX_LO_SET); +void J2DGrafContext::line(JGeometry::TVec2f start, JGeometry::TVec2f end) { + GXSetBlendMode((GXBlendMode)mLinePart.mType, (GXBlendFactor)mLinePart.mSrcFactor, + (GXBlendFactor)mLinePart.mDestFactor, GX_LO_SET); GXLoadPosMtxImm(mPosMtx, 0); GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_CLR_RGBA, GX_F32, 0); @@ -194,8 +189,7 @@ void J2DGrafContext::line(JGeometry::TVec2f start, JGeometry::TVec2f end) GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_CLR_RGBA, GX_RGBA4, 0); } -void J2DGrafContext::lineTo(JGeometry::TVec2f pos) -{ +void J2DGrafContext::lineTo(JGeometry::TVec2f pos) { line(mPrevPos, pos); mPrevPos = pos; -} \ No newline at end of file +} diff --git a/src/static/JSystem/J2DGraph/J2DOrthoGraph.cpp b/src/static/JSystem/J2DGraph/J2DOrthoGraph.cpp index c9befb4d..af0456bf 100644 --- a/src/static/JSystem/J2DGraph/J2DOrthoGraph.cpp +++ b/src/static/JSystem/J2DGraph/J2DOrthoGraph.cpp @@ -1,43 +1,35 @@ #include "JSystem/J2D/J2DGrafContext.h" -J2DOrthoGraph::J2DOrthoGraph() - : J2DGrafContext(0.0f, 0.0f, 0.0f, 0.0f) -{ +J2DOrthoGraph::J2DOrthoGraph() : J2DGrafContext(0.0f, 0.0f, 0.0f, 0.0f) { setLookat(); } J2DOrthoGraph::J2DOrthoGraph(f32 left, f32 top, f32 right, f32 bottom, f32 near, f32 far) - : J2DGrafContext(left, top, right, bottom) -{ + : J2DGrafContext(left, top, right, bottom) { mOrtho = JGeometry::TBox2f(0, 0, right, bottom); mNear = near; mFar = far; setLookat(); } -void J2DOrthoGraph::setPort() -{ +void J2DOrthoGraph::setPort() { J2DGrafContext::setPort(); C_MTXOrtho(mMtx44, mOrtho.i.y, 0.5f + mOrtho.f.y, mOrtho.i.x, mOrtho.f.x, mNear, mFar); GXSetProjection(mMtx44, GX_ORTHOGRAPHIC); } - -void J2DOrthoGraph::setOrtho(const JGeometry::TBox2f& bounds, f32 far, f32 near) -{ +void J2DOrthoGraph::setOrtho(const JGeometry::TBox2f& bounds, f32 far, f32 near) { mOrtho = bounds; mNear = -near; mFar = -far; } -void J2DOrthoGraph::setLookat() -{ +void J2DOrthoGraph::setLookat() { PSMTXIdentity(mPosMtx); GXLoadPosMtxImm(mPosMtx, 0); } -void J2DOrthoGraph::scissorBounds(JGeometry::TBox2f* out, const JGeometry::TBox2f* src) -{ +void J2DOrthoGraph::scissorBounds(JGeometry::TBox2f* out, const JGeometry::TBox2f* src) { f32 widthPower = this->getWidthPower(); f32 heightPower = this->getHeightPower(); f32 ix = mBounds.i.x >= 0 ? mBounds.i.x : 0; @@ -50,8 +42,7 @@ void J2DOrthoGraph::scissorBounds(JGeometry::TBox2f* out, const JGeometry::TBox2 out->intersect(mScissorBounds); } -void J2DDrawLine(f32 x1, f32 y1, f32 x2, f32 y2, JUtility::TColor color, int line_width) -{ +void J2DDrawLine(f32 x1, f32 y1, f32 x2, f32 y2, JUtility::TColor color, int line_width) { J2DOrthoGraph oGrph; oGrph.setLineWidth(line_width); oGrph.setColor(color); @@ -59,37 +50,33 @@ void J2DDrawLine(f32 x1, f32 y1, f32 x2, f32 y2, JUtility::TColor color, int lin oGrph.lineTo(x2, y2); } -void J2DFillBox(f32 l, f32 t, f32 x, f32 y, JUtility::TColor color) -{ +void J2DFillBox(f32 l, f32 t, f32 x, f32 y, JUtility::TColor color) { J2DFillBox(JGeometry::TBox2f(l, t, l + x, t + y), color); } -void J2DFillBox(const JGeometry::TBox2f& box, JUtility::TColor color) -{ +void J2DFillBox(const JGeometry::TBox2f& box, JUtility::TColor color) { J2DOrthoGraph oGrph; oGrph.setColor(color); oGrph.fillBox(box); } -void J2DFillBox(f32 l, f32 t, f32 x, f32 y, JUtility::TColor c1, JUtility::TColor c2, JUtility::TColor c3, JUtility::TColor c4) -{ +void J2DFillBox(f32 l, f32 t, f32 x, f32 y, JUtility::TColor c1, JUtility::TColor c2, JUtility::TColor c3, + JUtility::TColor c4) { J2DFillBox(JGeometry::TBox2f(l, t, l + x, t + y), c1, c2, c3, c4); } -void J2DFillBox(const JGeometry::TBox2f &box, JUtility::TColor c1, JUtility::TColor c2, JUtility::TColor c3, JUtility::TColor c4) -{ +void J2DFillBox(const JGeometry::TBox2f& box, JUtility::TColor c1, JUtility::TColor c2, JUtility::TColor c3, + JUtility::TColor c4) { J2DOrthoGraph oGrph; oGrph.setColor(c1, c2, c3, c4); oGrph.fillBox(box); } -void J2DDrawFrame(f32 l, f32 t, f32 x, f32 y, JUtility::TColor color, u8 line_width) -{ +void J2DDrawFrame(f32 l, f32 t, f32 x, f32 y, JUtility::TColor color, u8 line_width) { J2DDrawFrame(JGeometry::TBox2f(l, t, l + x, t + y), color, line_width); } -void J2DDrawFrame(const JGeometry::TBox2f& box, JUtility::TColor color, u8 line_width) -{ +void J2DDrawFrame(const JGeometry::TBox2f& box, JUtility::TColor color, u8 line_width) { J2DOrthoGraph oGrph; oGrph.setColor(color); oGrph.setLineWidth(line_width); diff --git a/src/static/JSystem/JFramework/JFWDisplay.cpp b/src/static/JSystem/JFramework/JFWDisplay.cpp index b35b2b56..8847d6e2 100644 --- a/src/static/JSystem/JFramework/JFWDisplay.cpp +++ b/src/static/JSystem/JFramework/JFWDisplay.cpp @@ -12,7 +12,7 @@ // https://github.com/kiwi515/ogws/blob/master/src/egg/core/eggAsyncDisplay.cpp // gpHang: https://github.com/valentinaslover/paper-mar/blob/master/source/sdk/DEMOInit.c#L280 -GC_Mtx e_mtx = {{1.0f, 0.0f, 0.0f, 0.0f}, {0.0f, 1.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 1.0f, 0.0f}}; +GC_Mtx e_mtx = { { 1.0f, 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, 1.0f, 0.0f } }; JFWDisplay* JFWDisplay::sManager; @@ -35,14 +35,14 @@ void JFWDisplay::ctor_subroutine(const GXRenderModeObj* rmode, bool enableAlpha) mClearColor.set(0, 0, 0, 0); mZClear = 0xFFFFFF; - mRMode = (rmode) ? rmode : JUTVideo::sManager->getRenderMode(); - + mRMode = (rmode) ? rmode : JUTVideo::sManager->getRenderMode(); + mGamma = 0; mFader = nullptr; mFrameRate = 1; mTickRate = 0; mCombinationRatio = 0.0f; - + mFrameTime = 0; mStartTick = OSGetTick(); mVideoFrameTime = 0; @@ -65,7 +65,8 @@ JFWDisplay::~JFWDisplay() { JUTXfb::destroyManager(); } -JFWDisplay *JFWDisplay::createManager(const GXRenderModeObj* rmode, JKRHeap* heap, JUTXfb::EXfbNumber bufferCount, bool p4) { +JFWDisplay* JFWDisplay::createManager(const GXRenderModeObj* rmode, JKRHeap* heap, JUTXfb::EXfbNumber bufferCount, + bool p4) { JUT_CONFIRM_MESSAGE(sManager == 0); if (sManager == nullptr) @@ -81,8 +82,7 @@ void JFWDisplay::destroyManager() { } void callDirectDraw() { - JUTChangeFrameBuffer(JUTXfb::getManager()->getDrawingXfb(), - JUTVideo::getManager()->getEfbHeight(), + JUTChangeFrameBuffer(JUTXfb::getManager()->getDrawingXfb(), JUTVideo::getManager()->getEfbHeight(), JUTVideo::getManager()->getFbWidth()); JUTAssertion::flushMessage(); } @@ -92,7 +92,7 @@ void JFWDisplay::prepareCopyDisp() { u16 width = (u16)JUTVideo::getManager()->getFbWidth(); u16 height = (u16)JUTVideo::getManager()->getEfbHeight(); u16 xfbHeight = (u16)JUTVideo::getManager()->getXfbHeight(); - + GXSetCopyClear(mClearColor, mZClear); GXSetDispCopySrc(0, 0, width, height); GXSetDispCopyDst(width, xfbHeight); @@ -108,7 +108,7 @@ void JFWDisplay::prepareCopyDisp() { } void JFWDisplay::drawendXfb_single() { - JUTXfb *manager = JUTXfb::getManager(); + JUTXfb* manager = JUTXfb::getManager(); if (manager->getDrawingXfbIndex() >= 0) { prepareCopyDisp(); JFWDrawDoneAlarm(); @@ -118,18 +118,16 @@ void JFWDisplay::drawendXfb_single() { } void JFWDisplay::exchangeXfb_double() { - JUTXfb *xfbMng = JUTXfb::getManager(); + JUTXfb* xfbMng = JUTXfb::getManager(); if (xfbMng->getDrawnXfbIndex() == xfbMng->getDisplayingXfbIndex()) { - if (xfbMng->getDrawingXfbIndex() >= 0) - { + if (xfbMng->getDrawingXfbIndex() >= 0) { prepareCopyDisp(); GXCopyDisp(xfbMng->getDrawingXfb(), GX_TRUE); if (mDrawDoneMethod == UNK_METHOD_0) { GXDrawDone(); JUTVideo::dummyNoDrawWait(); - } - else { + } else { JUTVideo::drawDoneStart(); } @@ -140,8 +138,7 @@ void JFWDisplay::exchangeXfb_double() { int cur_xfb_index = xfbMng->getDrawingXfbIndex(); xfbMng->setDrawnXfbIndex(cur_xfb_index); xfbMng->setDrawingXfbIndex(cur_xfb_index >= 0 ? cur_xfb_index ^ 1 : 0); - } - else { + } else { clearEfb(JUtility::TColor(0, 0, 0, 0xff)); if (xfbMng->getDrawingXfbIndex() < 0) { xfbMng->setDrawingXfbIndex(0); @@ -150,7 +147,7 @@ void JFWDisplay::exchangeXfb_double() { } void JFWDisplay::exchangeXfb_triple() { - JUTXfb *xfbMng = JUTXfb::getManager(); + JUTXfb* xfbMng = JUTXfb::getManager(); if (xfbMng->getDrawingXfbIndex() >= 0) { callDirectDraw(); @@ -168,7 +165,7 @@ void JFWDisplay::exchangeXfb_triple() { } void JFWDisplay::copyXfb_triple() { - JUTXfb *xfbMng = JUTXfb::getManager(); + JUTXfb* xfbMng = JUTXfb::getManager(); if (xfbMng->getDrawingXfbIndex() >= 0) { prepareCopyDisp(); @@ -181,16 +178,14 @@ void JFWDisplay::preGX() { GXInvalidateTexAll(); GXInvalidateVtxCache(); - if (mRMode->aa) { + if (mRMode->aa) { GXSetPixelFmt(GX_PF_RGB565_Z16, GX_ZC_LINEAR); GXSetDither(GX_ENABLE); - } - else { + } else { if (mEnableAlpha) { GXSetPixelFmt(GX_PF_RGBA6_Z24, GX_ZC_LINEAR); GXSetDither(GX_ENABLE); - } - else { + } else { GXSetPixelFmt(GX_PF_RGB8_Z24, GX_ZC_LINEAR); GXSetDither(GX_DISABLE); } @@ -223,8 +218,8 @@ void JFWDisplay::endGX() { GXFlush(); } -void JFWDisplay::beginRender() { - JUTProcBar::getManager()->wholeLoopEnd(); +void JFWDisplay::beginRender() { + JUTProcBar::getManager()->wholeLoopEnd(); JUTProcBar::getManager()->wholeLoopStart(); JUTProcBar::getManager()->idleStart(); @@ -238,45 +233,43 @@ void JFWDisplay::beginRender() { JUTProcBar::getManager()->idleEnd(); JUTProcBar::getManager()->gpStart(); - - JUTXfb * xfbMgr = JUTXfb::getManager(); + + JUTXfb* xfbMgr = JUTXfb::getManager(); switch (xfbMgr->getBufferNum()) { - case 1: - if (xfbMgr->getSDrawingFlag() != 2) { - xfbMgr->setSDrawingFlag(1); - clearEfb(JUtility::TColor(0, 0, 0, 0xff)); - } - else { - xfbMgr->setSDrawingFlag(1); - } - xfbMgr->setDrawingXfbIndex(mDrawingXfbNo); - break; - case 2: - exchangeXfb_double(); - break; - case 3: - exchangeXfb_triple(); - break; - default: - break; + case 1: + if (xfbMgr->getSDrawingFlag() != 2) { + xfbMgr->setSDrawingFlag(1); + clearEfb(JUtility::TColor(0, 0, 0, 0xff)); + } else { + xfbMgr->setSDrawingFlag(1); + } + xfbMgr->setDrawingXfbIndex(mDrawingXfbNo); + break; + case 2: + exchangeXfb_double(); + break; + case 3: + exchangeXfb_triple(); + break; + default: + break; } - + preGX(); } void JFWDisplay::endRender() { endGX(); - switch (JUTXfb::getManager()->getBufferNum()) - { - case 1: - drawendXfb_single(); - case 2: - break; - case 3: - copyXfb_triple(); - default: - break; + switch (JUTXfb::getManager()->getBufferNum()) { + case 1: + drawendXfb_single(); + case 2: + break; + case 3: + copyXfb_triple(); + default: + break; } JUTProcBar::getManager()->cpuStart(); @@ -286,31 +279,29 @@ void JFWDisplay::endRender() { void JFWDisplay::endFrame() { JUTProcBar::getManager()->cpuEnd(); JUTProcBar::getManager()->gpWaitStart(); - + switch (JUTXfb::getManager()->getBufferNum()) { - case 1: - break; - case 2: - JFWDrawDoneAlarm(); - GXFlush(); - break; - case 3: - JFWDrawDoneAlarm(); - GXFlush(); - break; - default: - break; + case 1: + break; + case 2: + JFWDrawDoneAlarm(); + GXFlush(); + break; + case 3: + JFWDrawDoneAlarm(); + GXFlush(); + break; + default: + break; } JUTProcBar::getManager()->gpWaitEnd(); JUTProcBar::getManager()->gpEnd(); - static u32 prevFrame = VIGetRetraceCount(); u32 retrace_cnt = VIGetRetraceCount(); JUTProcBar::getManager()->setCostFrame(retrace_cnt - prevFrame); prevFrame = retrace_cnt; - } void JFWDisplay::waitBlanking(int p1) { @@ -328,8 +319,7 @@ void waitForTick(u32 p1, u16 p2) { time = OSGetTime(); } nextTick = time + p1; - } - else { + } else { static u32 nextCount = VIGetRetraceCount(); u32 uVar1 = (p2 == 0) ? 1 : p2; OSMessage msg; @@ -343,7 +333,7 @@ void waitForTick(u32 p1, u16 p2) { } void JFWThreadAlarmHandler(OSAlarm* p_alarm, OSContext* p_ctx) { - JFWAlarm *alarm = static_cast(p_alarm); + JFWAlarm* alarm = static_cast(p_alarm); OSResumeThread(alarm->getThread()); } @@ -359,16 +349,12 @@ void JFWDisplay::threadSleep(s64 time) { } static GXTexObj clear_z_tobj; -static u8 clear_z_TX[] __attribute__((aligned(32))) = { - 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, - 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, - 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, - 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff -}; +static u8 clear_z_TX[] + __attribute__((aligned(32))) = { 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, + 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, + 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; void* JFWDisplay::changeToSingleXfb(int index) { JUTXfb* xfb = JUTXfb::getManager(); @@ -384,7 +370,7 @@ void* JFWDisplay::changeToSingleXfb(int index) { } VIWaitForRetrace(); - + if (xfbNo != xfb->getDisplayingXfbIndex()) { u32 xfbSize = xfb->accumeXfbSize(); DCInvalidateRange(xfb->getDrawingXfb(), xfbSize); @@ -427,15 +413,14 @@ void* JFWDisplay::changeToDoubleXfb() { void JFWDisplay::clearEfb_init() { GXInitTexObj(&clear_z_tobj, &clear_z_TX, 4, 4, GX_TF_Z24X8, GX_REPEAT, GX_REPEAT, GX_FALSE); - GXInitTexObjLOD(&clear_z_tobj, GX_NEAR, GX_NEAR, 0.0f, 0.0f, 0.0f, GX_FALSE, GX_FALSE, - GX_ANISO_1); + GXInitTexObjLOD(&clear_z_tobj, GX_NEAR, GX_NEAR, 0.0f, 0.0f, 0.0f, GX_FALSE, GX_FALSE, GX_ANISO_1); } void JFWDisplay::clearEfb(GXColor color) { Mtx44 mtx; u16 height = mRMode->efbHeight; u16 width = mRMode->fbWidth; - + C_MTXOrtho(mtx, 0.0f, height, 0.0f, width, 0.0f, 1.0f); GXSetProjection(mtx, GX_ORTHOGRAPHIC); GXSetViewport(0.0f, 0.0f, width, height, 0.0f, 1.0f); @@ -499,8 +484,7 @@ void JFWDisplay::calcCombinationRatio() { s32 unk30 = mFrameTime * 2; s32 i = vidInterval; - for (; i < unk30; i += vidInterval) { - } + for (; i < unk30; i += vidInterval) {} s32 tmp = (i - unk30) - mVideoFrameTime; if (tmp < 0) { @@ -512,34 +496,34 @@ void JFWDisplay::calcCombinationRatio() { } } -void JFWGXAbortAlarmHandler(OSAlarm *param_0, OSContext *param_1) { +void JFWGXAbortAlarmHandler(OSAlarm* param_0, OSContext* param_1) { diagnoseGpHang(); GXAbortFrame(); GXSetDrawDone(); } void diagnoseGpHang() { - u32 xfTop0, xfBot0, suRdy0, r0Rdy0; - u32 xfTop1, xfBot1, suRdy1, r0Rdy1; - u32 xfTopD, xfBotD, suRdyD, r0RdyD; - GXBool readIdle, cmdIdle, junk; + u32 xfTop0, xfBot0, suRdy0, r0Rdy0; + u32 xfTop1, xfBot1, suRdy1, r0Rdy1; + u32 xfTopD, xfBotD, suRdyD, r0RdyD; + GXBool readIdle, cmdIdle, junk; - GXReadXfRasMetric(&xfBot0, &xfTop0, &r0Rdy0, &suRdy0); - GXReadXfRasMetric(&xfBot1, &xfTop1, &r0Rdy1, &suRdy1); + GXReadXfRasMetric(&xfBot0, &xfTop0, &r0Rdy0, &suRdy0); + GXReadXfRasMetric(&xfBot1, &xfTop1, &r0Rdy1, &suRdy1); - xfTopD = (xfTop1 - xfTop0) == 0; - xfBotD = (xfBot1 - xfBot0) == 0; - suRdyD = (suRdy1 - suRdy0) > 0; - r0RdyD = (r0Rdy1 - r0Rdy0) > 0; + xfTopD = (xfTop1 - xfTop0) == 0; + xfBotD = (xfBot1 - xfBot0) == 0; + suRdyD = (suRdy1 - suRdy0) > 0; + r0RdyD = (r0Rdy1 - r0Rdy0) > 0; - GXGetGPStatus(&junk, &junk, &readIdle, &cmdIdle, &junk); + GXGetGPStatus(&junk, &junk, &readIdle, &cmdIdle, &junk); OSReport("GP status %d%d%d%d%d%d --> ", readIdle, cmdIdle, xfTopD, xfBotD, suRdyD, r0RdyD); if (!xfBotD && suRdyD) OSReport("GP hang due to XF stall bug.\n"); else if (!xfTopD && xfBotD && suRdyD) OSReport("GP hang due to unterminated primitive.\n"); - else if (!cmdIdle && xfTopD && xfBotD && suRdyD) + else if (!cmdIdle && xfTopD && xfBotD && suRdyD) OSReport("GP hang due to illegal instruction.\n"); else if (readIdle && cmdIdle && xfTopD && xfBotD && suRdyD && r0RdyD) OSReport("GP appears to be not hung (waiting for input).\n"); diff --git a/src/static/JSystem/JFramework/JFWSystem.cpp b/src/static/JSystem/JFramework/JFWSystem.cpp index 34b33d48..b4d33517 100644 --- a/src/static/JSystem/JFramework/JFWSystem.cpp +++ b/src/static/JSystem/JFramework/JFWSystem.cpp @@ -24,22 +24,20 @@ u32 JFWSystem::CSetUpParam::aramGraphBufSize = 0x600000; s32 JFWSystem::CSetUpParam::streamPriority = 8; s32 JFWSystem::CSetUpParam::decompPriority = 7; s32 JFWSystem::CSetUpParam::aPiecePriority = 6; -const ResFONT *JFWSystem::CSetUpParam::systemFontRes = &JUTResFONT_Ascfont_fix12; -const _GXRenderModeObj *JFWSystem::CSetUpParam::renderMode = &GXNtsc480IntDf; +const ResFONT* JFWSystem::CSetUpParam::systemFontRes = &JUTResFONT_Ascfont_fix12; +const _GXRenderModeObj* JFWSystem::CSetUpParam::renderMode = &GXNtsc480IntDf; u32 JFWSystem::CSetUpParam::exConsoleBufferSize = 0x24F8; -JKRHeap *JFWSystem::rootHeap; -JKRHeap *JFWSystem::systemHeap; -JKRThread *JFWSystem::mainThread; -JUTDbPrint *JFWSystem::debugPrint; -JUTFont *JFWSystem::systemFont; -JUTConsoleManager *JFWSystem::systemConsoleManager; -JUTConsole *JFWSystem::systemConsole; +JKRHeap* JFWSystem::rootHeap; +JKRHeap* JFWSystem::systemHeap; +JKRThread* JFWSystem::mainThread; +JUTDbPrint* JFWSystem::debugPrint; +JUTFont* JFWSystem::systemFont; +JUTConsoleManager* JFWSystem::systemConsoleManager; +JUTConsole* JFWSystem::systemConsole; bool JFWSystem::sInitCalled; -void JFWSystem::firstInit() -{ -#line 80 +void JFWSystem::firstInit() { JUT_ASSERT(rootHeap == 0); OSInit(); DVDInit(); @@ -47,23 +45,21 @@ void JFWSystem::firstInit() systemHeap = JKRExpHeap::create(CSetUpParam::sysHeapSize, rootHeap, false); } -void JFWSystem::init() -{ -#line 101 +void JFWSystem::init() { JUT_ASSERT(sInitCalled == false); if (rootHeap == 0) firstInit(); sInitCalled = true; - JKRAram::create(CSetUpParam::aramAudioBufSize, CSetUpParam::aramGraphBufSize, CSetUpParam::streamPriority, CSetUpParam::decompPriority, - CSetUpParam::aPiecePriority); + JKRAram::create(CSetUpParam::aramAudioBufSize, CSetUpParam::aramGraphBufSize, CSetUpParam::streamPriority, + CSetUpParam::decompPriority, CSetUpParam::aPiecePriority); - mainThread = new JKRThread(OSGetCurrentThread(), 4); + mainThread = new JKRThread(OSGetCurrentThread(), 4); JUTVideo::createManager(CSetUpParam::renderMode); JUTCreateFifo(CSetUpParam::fifoBufSize); JUTGamePad::init(); - JUTDirectPrint *directPrint = JUTDirectPrint::start(); + JUTDirectPrint* directPrint = JUTDirectPrint::start(); JUTAssertion::create(); JUTException::create(directPrint); systemFont = new JUTResFont(CSetUpParam::systemFontRes, nullptr); @@ -73,13 +69,10 @@ void JFWSystem::init() systemConsole = JUTConsole::create(60, 200, nullptr); systemConsole->setFont(systemFont); - if (CSetUpParam::renderMode->efbHeight < 300) - { + if (CSetUpParam::renderMode->efbHeight < 300) { systemConsole->setFontSize(systemFont->getWidth() * 0.85f, systemFont->getHeight() * 0.5f); systemConsole->setPosition(20, 25); - } - else - { + } else { systemConsole->setFontSize(systemFont->getWidth() * 0.85f, systemFont->getHeight()); systemConsole->setPosition(20, 50); } @@ -88,6 +81,6 @@ void JFWSystem::init() systemConsole->setOutput(JUTConsole::OUTPUT_OSREPORT | JUTConsole::OUTPUT_CONSOLE); JUTSetReportConsole(systemConsole); JUTSetWarningConsole(systemConsole); - void *mem = systemHeap->alloc(CSetUpParam::exConsoleBufferSize, 4); + void* mem = systemHeap->alloc(CSetUpParam::exConsoleBufferSize, 4); JUTException::createConsole(mem, CSetUpParam::exConsoleBufferSize); -} \ No newline at end of file +} diff --git a/src/static/JSystem/JGadget/linklist.cpp b/src/static/JSystem/JGadget/linklist.cpp index fd25a7d7..d3cc27bc 100644 --- a/src/static/JSystem/JGadget/linklist.cpp +++ b/src/static/JSystem/JGadget/linklist.cpp @@ -28,7 +28,6 @@ TNodeLinkList::iterator TNodeLinkList::erase(iterator it, iterator itEnd) { } TNodeLinkList::iterator TNodeLinkList::erase(TNodeLinkList::iterator it) { - #line 102 JUT_ASSERT(it.p_!=&oNode_); iterator itNext = it; @@ -90,7 +89,6 @@ void TNodeLinkList::splice(TNodeLinkList::iterator it, TNodeLinkList& rSrc, TNod } void TNodeLinkList::splice(iterator it, TNodeLinkList& rSrc) { - #line 146 JUT_ASSERT(this!=&rSrc); this->splice(it, rSrc, rSrc.begin(), rSrc.end()); JUT_ASSERT(rSrc.empty()); @@ -104,7 +102,6 @@ TNodeLinkList::iterator TNodeLinkList::Find(const TLinkListNode* node) { #define NULL 0 TNodeLinkList::iterator TNodeLinkList::Insert(iterator it, TLinkListNode* p) { - #line 300 JUT_ASSERT(p!=0); TLinkListNode* pIt = it.p_; JUT_ASSERT(pIt!=0); @@ -128,7 +125,6 @@ TNodeLinkList::iterator TNodeLinkList::Insert(iterator it, TLinkListNode* p) { #define NULL (void*)0; TNodeLinkList::iterator TNodeLinkList::Erase(TLinkListNode* p) { - #line 325 JUT_ASSERT(!empty()); JUT_ASSERT(p!=0); JUT_ASSERT(p!=&oNode_); @@ -151,21 +147,18 @@ bool TNodeLinkList::Confirm() const { u32 u = 0; const_iterator itEnd = this->end(); - #line 357 JGADGET_EXITWARN(itEnd.p_==&oNode_); const_iterator it = this->begin(); - JGADGET_EXITWARN(it.p_==oNode_.pNext_); // #line 359 + JGADGET_EXITWARN(it.p_==oNode_.pNext_); for (; it != itEnd; ++it, ++u) { - JGADGET_EXITWARN(upNext_->pPrev_==pIt); - JGADGET_EXITWARN(pIt->pPrev_->pNext_==pIt); // #line 366 + JGADGET_EXITWARN(pIt->pPrev_->pNext_==pIt); } - #line 368 JGADGET_EXITWARN(it.p_==&oNode_); JGADGET_EXITWARN(u==size()); return true; @@ -183,7 +176,6 @@ bool TNodeLinkList::Confirm_iterator(const_iterator it) const { ++itBegin; } - #line 383 JGADGET_EXITWARN(it==itEnd); return true; diff --git a/src/static/JSystem/JKernel/JKRAram.cpp b/src/static/JSystem/JKernel/JKRAram.cpp index fb313391..5111c107 100644 --- a/src/static/JSystem/JKernel/JKRAram.cpp +++ b/src/static/JSystem/JKernel/JKRAram.cpp @@ -11,18 +11,17 @@ JSUList JKRAram::sAramCommandList; JKRAram* JKRAram::sAramObject; u32 JKRAram::sSZSBufferSize = 0x400; -JKRAram* JKRAram::create(u32 aram_audio_buffer_size, u32 aram_audio_graph_size, - s32 streamPriority, s32 decomp_priority, - s32 piece_priority) { - if (!sAramObject) { - sAramObject = new (JKRGetSystemHeap(), 0) - JKRAram(aram_audio_buffer_size, aram_audio_graph_size, piece_priority); - } +JKRAram* JKRAram::create(u32 aram_audio_buffer_size, u32 aram_audio_graph_size, s32 streamPriority, s32 decomp_priority, + s32 piece_priority) { + if (!sAramObject) { + sAramObject = + new (JKRGetSystemHeap(), 0) JKRAram(aram_audio_buffer_size, aram_audio_graph_size, piece_priority); + } - JKRCreateAramStreamManager(streamPriority); - JKRCreateDecompManager(decomp_priority); - sAramObject->resume(); - return sAramObject; + JKRCreateAramStreamManager(streamPriority); + JKRCreateDecompManager(decomp_priority); + sAramObject->resume(); + return sAramObject; } OSMessage JKRAram::sMessageBuffer[4] = { @@ -34,269 +33,257 @@ OSMessage JKRAram::sMessageBuffer[4] = { OSMessageQueue JKRAram::sMessageQueue = { 0 }; -JKRAram::JKRAram(u32 bufSize, u32 graphSize, s32 priority) - : JKRThread(0x4000, 0x10, priority) { - u32 aramBase = ARInit(mStackArray, ARRAY_COUNT(mStackArray)); - ARQInit(); +JKRAram::JKRAram(u32 bufSize, u32 graphSize, s32 priority) : JKRThread(0x4000, 0x10, priority) { + u32 aramBase = ARInit(mStackArray, ARRAY_COUNT(mStackArray)); + ARQInit(); - u32 aramSize = ARGetSize(); - mAudioMemorySize = bufSize; - if (graphSize == 0xffffffff) { - mGraphMemorySize = aramSize - bufSize - aramBase; - mUserMemorySize = 0; - } - else { - mGraphMemorySize = graphSize; - mUserMemorySize = (aramSize - (bufSize + graphSize) - aramBase); - } + u32 aramSize = ARGetSize(); + mAudioMemorySize = bufSize; + if (graphSize == 0xffffffff) { + mGraphMemorySize = aramSize - bufSize - aramBase; + mUserMemorySize = 0; + } else { + mGraphMemorySize = graphSize; + mUserMemorySize = (aramSize - (bufSize + graphSize) - aramBase); + } - mAudioMemoryPtr = ARAlloc(mAudioMemorySize); - mGraphMemoryPtr = ARAlloc(mGraphMemorySize); + mAudioMemoryPtr = ARAlloc(mAudioMemorySize); + mGraphMemoryPtr = ARAlloc(mGraphMemorySize); - if (mUserMemorySize != 0) { // ternary? - mUserMemoryPtr = ARAlloc(mUserMemorySize); - } - else { - mUserMemoryPtr = nullptr; - } + if (mUserMemorySize != 0) { // ternary? + mUserMemoryPtr = ARAlloc(mUserMemorySize); + } else { + mUserMemoryPtr = nullptr; + } - mAramHeap = new (JKRHeap::getSystemHeap(), 0) - JKRAramHeap(mGraphMemoryPtr, mGraphMemorySize); + mAramHeap = new (JKRHeap::getSystemHeap(), 0) JKRAramHeap(mGraphMemoryPtr, mGraphMemorySize); } JKRAram::~JKRAram() { - sAramObject = nullptr; - if (mAramHeap) delete mAramHeap; + sAramObject = nullptr; + if (mAramHeap) + delete mAramHeap; } void* JKRAram::run() { - int result; - JKRAMCommand* command; - JKRAramCommand* message; - OSInitMessageQueue(&sMessageQueue, sMessageBuffer, 4); - do { - OSReceiveMessage(&sMessageQueue, (OSMessage*)&message, OS_MESSAGE_BLOCK); - result = message->mActive; - command = (JKRAMCommand*)message->mArg; - delete message; + int result; + JKRAMCommand* command; + JKRAramCommand* message; + OSInitMessageQueue(&sMessageQueue, sMessageBuffer, 4); + do { + OSReceiveMessage(&sMessageQueue, (OSMessage*)&message, OS_MESSAGE_BLOCK); + result = message->mActive; + command = (JKRAMCommand*)message->mArg; + delete message; - switch (result) { - case 1: - JKRAramPiece::startDMA(command); - break; - } - } while (true); + switch (result) { + case 1: + JKRAramPiece::startDMA(command); + break; + } + } while (true); } -bool JKRAram::checkOkAddress(u8* addr, u32 size, JKRAramBlock* block, - u32 blockSize) { - if (!IS_ALIGNED((u32)addr, 0x20) && !IS_ALIGNED(size, 0x20)) { - JPANIC(225, ":::address not 32Byte aligned."); - return false; - } - - if (block) { - if (!IS_ALIGNED(block->getAddress() + blockSize, 0x20)) { - JPANIC(234, ":::address not 32Byte aligned."); - return false; +bool JKRAram::checkOkAddress(u8* addr, u32 size, JKRAramBlock* block, u32 blockSize) { + if (!IS_ALIGNED((u32)addr, 0x20) && !IS_ALIGNED(size, 0x20)) { + JPANIC(225, ":::address not 32Byte aligned."); + return false; } - } - return true; + + if (block) { + if (!IS_ALIGNED(block->getAddress() + blockSize, 0x20)) { + JPANIC(234, ":::address not 32Byte aligned."); + return false; + } + } + return true; } void JKRAram::changeGroupIdIfNeed(u8* data, int groupId) { - JKRHeap* currentHeap = JKRGetCurrentHeap(); - if (currentHeap->getHeapType() == 'EXPH' && groupId >= 0) { - JKRExpHeap::CMemBlock* block = (JKRExpHeap::CMemBlock*)(data + -0x10); - block->newGroupId(groupId); - } + JKRHeap* currentHeap = JKRGetCurrentHeap(); + if (currentHeap->getHeapType() == 'EXPH' && groupId >= 0) { + JKRExpHeap::CMemBlock* block = (JKRExpHeap::CMemBlock*)(data + -0x10); + block->newGroupId(groupId); + } } -JKRAramBlock* JKRAram::mainRamToAram(u8* buf, u32 address, u32 alignedSize, - JKRExpandSwitch expandSwitch, u32 fileSize, - JKRHeap* heap, int id) { - JKRAramBlock* block = nullptr; - checkOkAddress(buf, address, nullptr, 0); - if (expandSwitch == EXPAND_SWITCH_DECOMPRESS) { - expandSwitch = (JKRCheckCompressed(buf) == JKRCOMPRESSION_NONE) - ? EXPAND_SWITCH_DEFAULT - : EXPAND_SWITCH_DECOMPRESS; - } - if (expandSwitch == EXPAND_SWITCH_DECOMPRESS) { - u32 expandSize = JKRCheckCompressed(buf) != JKRCOMPRESSION_NONE - ? JKRDecompExpandSize(buf) - : 0; - if (fileSize == 0 || fileSize > expandSize) { - fileSize = expandSize; +JKRAramBlock* JKRAram::mainRamToAram(u8* buf, u32 address, u32 alignedSize, JKRExpandSwitch expandSwitch, u32 fileSize, + JKRHeap* heap, int id) { + JKRAramBlock* block = nullptr; + checkOkAddress(buf, address, nullptr, 0); + if (expandSwitch == EXPAND_SWITCH_DECOMPRESS) { + expandSwitch = + (JKRCheckCompressed(buf) == JKRCOMPRESSION_NONE) ? EXPAND_SWITCH_DEFAULT : EXPAND_SWITCH_DECOMPRESS; } - if (address == 0) { - block = JKRAllocFromAram(fileSize, JKRAramHeap::Head); - if (block == nullptr) return nullptr; + if (expandSwitch == EXPAND_SWITCH_DECOMPRESS) { + u32 expandSize = JKRCheckCompressed(buf) != JKRCOMPRESSION_NONE ? JKRDecompExpandSize(buf) : 0; + if (fileSize == 0 || fileSize > expandSize) { + fileSize = expandSize; + } + if (address == 0) { + block = JKRAllocFromAram(fileSize, JKRAramHeap::Head); + if (block == nullptr) + return nullptr; - block->newGroupID(decideAramGroupId(id)); - address = block->getAddress(); + block->newGroupID(decideAramGroupId(id)); + address = block->getAddress(); + } + if (alignedSize == 0 || alignedSize > expandSize) + alignedSize = expandSize; + + if (fileSize > alignedSize) + fileSize = alignedSize; + + void* allocatedMem = JKRAllocFromHeap(heap, fileSize, -32); + if (allocatedMem == nullptr) { + if (block != nullptr) { + delete block; + } + block = nullptr; + } else { + JKRDecompress(buf, (u8*)allocatedMem, fileSize, 0); + JKRAramPcs(0, (u32)allocatedMem, address, alignedSize, block); + JKRFreeToHeap(heap, allocatedMem); + block = block == nullptr ? (JKRAramBlock*)-1 : block; + } + } else { + if (address == 0) { + block = JKRAllocFromAram(alignedSize, JKRAramHeap::Head); + block->newGroupID(decideAramGroupId(id)); + if (block == nullptr) + return nullptr; + + address = block->getAddress(); + } + + JKRAramPcs(0, (u32)buf, address, alignedSize, block); + block = block == nullptr ? (JKRAramBlock*)-1 : block; } - if (alignedSize == 0 || alignedSize > expandSize) alignedSize = expandSize; - - if (fileSize > alignedSize) fileSize = alignedSize; - - void* allocatedMem = JKRAllocFromHeap(heap, fileSize, -32); - if (allocatedMem == nullptr) { - if (block != nullptr) { - delete block; - } - block = nullptr; - } - else { - JKRDecompress(buf, (u8*)allocatedMem, fileSize, 0); - JKRAramPcs(0, (u32)allocatedMem, address, alignedSize, block); - JKRFreeToHeap(heap, allocatedMem); - block = block == nullptr ? (JKRAramBlock*)-1 : block; - } - } - else { - if (address == 0) { - block = JKRAllocFromAram(alignedSize, JKRAramHeap::Head); - block->newGroupID(decideAramGroupId(id)); - if (block == nullptr) return nullptr; - - address = block->getAddress(); - } - - JKRAramPcs(0, (u32)buf, address, alignedSize, block); - block = block == nullptr ? (JKRAramBlock*)-1 : block; - } - return block; + return block; } -JKRAramBlock* JKRAram::mainRamToAram(u8* buf, JKRAramBlock* block, - u32 alignedSize, - JKRExpandSwitch expandSwitch, u32 fileSize, - JKRHeap* heap, int id) { - checkOkAddress(buf, 0, block, 0); +JKRAramBlock* JKRAram::mainRamToAram(u8* buf, JKRAramBlock* block, u32 alignedSize, JKRExpandSwitch expandSwitch, + u32 fileSize, JKRHeap* heap, int id) { + checkOkAddress(buf, 0, block, 0); - if (block == nullptr) { - return mainRamToAram(buf, (u32)0, alignedSize, expandSwitch, fileSize, heap, - id); - } + if (block == nullptr) { + return mainRamToAram(buf, (u32)0, alignedSize, expandSwitch, fileSize, heap, id); + } - u32 blockSize = block->getSize(); + u32 blockSize = block->getSize(); - if (expandSwitch == EXPAND_SWITCH_DECOMPRESS) { - fileSize = fileSize >= blockSize ? blockSize : fileSize; - } + if (expandSwitch == EXPAND_SWITCH_DECOMPRESS) { + fileSize = fileSize >= blockSize ? blockSize : fileSize; + } - alignedSize = alignedSize > blockSize ? blockSize : alignedSize; + alignedSize = alignedSize > blockSize ? blockSize : alignedSize; - return mainRamToAram(buf, block->getAddress(), alignedSize, expandSwitch, - fileSize, heap, id); + return mainRamToAram(buf, block->getAddress(), alignedSize, expandSwitch, fileSize, heap, id); } // TODO: figure out name of parameter 5 -u8* JKRAram::aramToMainRam(u32 address, u8* buf, u32 srcSize, - JKRExpandSwitch expandSwitch, u32 p5, JKRHeap* heap, - int id, u32* pSize) { - int compression = JKRCOMPRESSION_NONE; - if (pSize) *pSize = 0; +u8* JKRAram::aramToMainRam(u32 address, u8* buf, u32 srcSize, JKRExpandSwitch expandSwitch, u32 p5, JKRHeap* heap, + int id, u32* pSize) { + int compression = JKRCOMPRESSION_NONE; + if (pSize) + *pSize = 0; - checkOkAddress(buf, address, nullptr, 0); + checkOkAddress(buf, address, nullptr, 0); - u32 expandSize; - if (expandSwitch == EXPAND_SWITCH_DECOMPRESS) { - u8 buffer[64]; - u8* bufPtr = (u8*)ALIGN_NEXT((u32)buffer, 32); - JKRAramPcs(1, address, (u32)bufPtr, sizeof(buffer) / 2, - nullptr); // probably change sizeof(buffer) / 2 to 32 - compression = JKRCheckCompressed(bufPtr); - expandSize = JKRDecompExpandSize(bufPtr); - } - - if (compression == JKRCOMPRESSION_YAZ0) // SZS - { - if (p5 != 0 && p5 < expandSize) expandSize = p5; - - if (buf == nullptr) buf = (u8*)JKRAllocFromHeap(heap, expandSize, 32); - if (buf == nullptr) - return nullptr; - else { - changeGroupIdIfNeed(buf, id); - JKRDecompressFromAramToMainRam(address, buf, srcSize, expandSize, 0); - if (pSize) { - *pSize = expandSize; - } - return buf; + u32 expandSize; + if (expandSwitch == EXPAND_SWITCH_DECOMPRESS) { + u8 buffer[64]; + u8* bufPtr = (u8*)ALIGN_NEXT((u32)buffer, 32); + JKRAramPcs(1, address, (u32)bufPtr, sizeof(buffer) / 2, + nullptr); // probably change sizeof(buffer) / 2 to 32 + compression = JKRCheckCompressed(bufPtr); + expandSize = JKRDecompExpandSize(bufPtr); } - } - else if (compression == JKRCOMPRESSION_YAY0) // SZP - { - u8* szpSpace = (u8*)JKRAllocFromHeap(heap, srcSize, -32); - if (szpSpace == nullptr) { - return nullptr; - } - else { - JKRAramPcs(1, address, (u32)szpSpace, srcSize, nullptr); - if (p5 != 0 && p5 < expandSize) expandSize = p5; - u8* szpBuffer = - buf == nullptr ? (u8*)JKRAllocFromHeap(heap, expandSize, 32) : buf; + if (compression == JKRCOMPRESSION_YAZ0) // SZS + { + if (p5 != 0 && p5 < expandSize) + expandSize = p5; - if (szpBuffer == nullptr) { - JKRFree(szpSpace); - return nullptr; - } - else { - changeGroupIdIfNeed(szpBuffer, id); - JKRDecompress(szpSpace, szpBuffer, expandSize, 0); - JKRFreeToHeap(heap, szpSpace); - if (pSize) { - *pSize = expandSize; + if (buf == nullptr) + buf = (u8*)JKRAllocFromHeap(heap, expandSize, 32); + if (buf == nullptr) + return nullptr; + else { + changeGroupIdIfNeed(buf, id); + JKRDecompressFromAramToMainRam(address, buf, srcSize, expandSize, 0); + if (pSize) { + *pSize = expandSize; + } + return buf; + } + } else if (compression == JKRCOMPRESSION_YAY0) // SZP + { + u8* szpSpace = (u8*)JKRAllocFromHeap(heap, srcSize, -32); + if (szpSpace == nullptr) { + return nullptr; + } else { + JKRAramPcs(1, address, (u32)szpSpace, srcSize, nullptr); + if (p5 != 0 && p5 < expandSize) + expandSize = p5; + + u8* szpBuffer = buf == nullptr ? (u8*)JKRAllocFromHeap(heap, expandSize, 32) : buf; + + if (szpBuffer == nullptr) { + JKRFree(szpSpace); + return nullptr; + } else { + changeGroupIdIfNeed(szpBuffer, id); + JKRDecompress(szpSpace, szpBuffer, expandSize, 0); + JKRFreeToHeap(heap, szpSpace); + if (pSize) { + *pSize = expandSize; + } + return szpBuffer; + } + } + } else // Not compressed or ASR + { + if (buf == nullptr) + buf = (u8*)JKRAllocFromHeap(heap, srcSize, 32); + if (buf == nullptr) { + return nullptr; + } else { + changeGroupIdIfNeed(buf, id); + JKRAramPcs(1, address, (u32)buf, srcSize, nullptr); + if (pSize != nullptr) { + *pSize = srcSize; + } + return buf; } - return szpBuffer; - } } - } - else // Not compressed or ASR - { - if (buf == nullptr) buf = (u8*)JKRAllocFromHeap(heap, srcSize, 32); - if (buf == nullptr) { - return nullptr; - } - else { - changeGroupIdIfNeed(buf, id); - JKRAramPcs(1, address, (u32)buf, srcSize, nullptr); - if (pSize != nullptr) { - *pSize = srcSize; - } - return buf; - } - } } // TODO: figure out what p6 does -u8* JKRAram::aramToMainRam(JKRAramBlock* block, u8* buf, u32 bufSize, - u32 alignedBlockSize, JKRExpandSwitch expandSwitch, - u32 p6, JKRHeap* heap, int id, u32* pSize) { - int compression = JKRCOMPRESSION_NONE; - if (pSize) *pSize = 0; +u8* JKRAram::aramToMainRam(JKRAramBlock* block, u8* buf, u32 bufSize, u32 alignedBlockSize, + JKRExpandSwitch expandSwitch, u32 p6, JKRHeap* heap, int id, u32* pSize) { + int compression = JKRCOMPRESSION_NONE; + if (pSize) + *pSize = 0; - checkOkAddress(buf, 0, block, alignedBlockSize); + checkOkAddress(buf, 0, block, alignedBlockSize); - if (block == nullptr) { - JPANIC(667, ":::Bad Aram Block specified.\n"); - } + if (block == nullptr) { + JPANIC(667, ":::Bad Aram Block specified.\n"); + } - u32 freeSize = block->getSize(); + u32 freeSize = block->getSize(); - if (alignedBlockSize >= freeSize) return nullptr; + if (alignedBlockSize >= freeSize) + return nullptr; - bufSize = bufSize == 0 ? freeSize : bufSize; + bufSize = bufSize == 0 ? freeSize : bufSize; - if (alignedBlockSize + bufSize > freeSize) { - bufSize = freeSize - alignedBlockSize; - } + if (alignedBlockSize + bufSize > freeSize) { + bufSize = freeSize - alignedBlockSize; + } - return aramToMainRam(alignedBlockSize + block->getAddress(), buf, bufSize, - expandSwitch, p6, heap, id, pSize); + return aramToMainRam(alignedBlockSize + block->getAddress(), buf, bufSize, expandSwitch, p6, heap, id, pSize); } static OSMutex decompMutex; @@ -322,188 +309,181 @@ static u8* nextSrcData(u8* current); static int decompSZS_subroutine(u8* src, u8* dest); void JKRAram::aramSync(JKRAMCommand*, int) { - // JUT_REPORT_MSG("bad aramSync\n"); + // JUT_REPORT_MSG("bad aramSync\n"); } -int JKRDecompressFromAramToMainRam(u32 src, void* dst, u32 srcLength, - u32 dstLength, u32 offset) { - szpBuf = (u8*)JKRAllocFromSysHeap(SZP_BUFFERSIZE, 32); +int JKRDecompressFromAramToMainRam(u32 src, void* dst, u32 srcLength, u32 dstLength, u32 offset) { + szpBuf = (u8*)JKRAllocFromSysHeap(SZP_BUFFERSIZE, 32); - // JUT_ASSERT(szpBuf != 0); + JUT_ASSERT(szpBuf != 0); - szpEnd = szpBuf + SZP_BUFFERSIZE; - if (offset != 0) { - refBuf = (u8*)JKRAllocFromSysHeap(0x1120, 0); - // JUT_ASSERT(refBuf != 0); - refEnd = refBuf + 0x1120; - refCurrent = refBuf; - } - else { - refBuf = nullptr; - } + szpEnd = szpBuf + SZP_BUFFERSIZE; + if (offset != 0) { + refBuf = (u8*)JKRAllocFromSysHeap(0x1120, 0); + JUT_ASSERT(refBuf != 0); + refEnd = refBuf + 0x1120; + refCurrent = refBuf; + } else { + refBuf = nullptr; + } - srcAddress = src; - srcOffset = 0; - transLeft = (srcLength != 0) ? srcLength : -1; - fileOffset = offset; - readCount = 0; - maxDest = dstLength; + srcAddress = src; + srcOffset = 0; + transLeft = (srcLength != 0) ? srcLength : -1; + fileOffset = offset; + readCount = 0; + maxDest = dstLength; - decompSZS_subroutine(firstSrcData(), (u8*)dst); - JKRFree(szpBuf); + decompSZS_subroutine(firstSrcData(), (u8*)dst); + JKRFree(szpBuf); - if (refBuf) { - JKRFree(refBuf); - } + if (refBuf) { + JKRFree(refBuf); + } - return 0; + return 0; } int decompSZS_subroutine(u8* src, u8* dest) { - u8* endPtr; - s32 validBitCount = 0; - s32 currCodeByte = 0; + u8* endPtr; + s32 validBitCount = 0; + s32 currCodeByte = 0; - if (src[0] != 'Y' || src[1] != 'a' || src[2] != 'z' || src[3] != '0') { - return -1; - } - - SYaz0Header* header = (SYaz0Header*)src; - endPtr = dest + (header->length - fileOffset); - if (endPtr > dest + maxDest) { - endPtr = dest + maxDest; - } - - src += 0x10; - do { - if (validBitCount == 0) { - if ((src > srcLimit) && transLeft) { - src = nextSrcData(src); - } - currCodeByte = *src; - validBitCount = 8; - src++; + if (src[0] != 'Y' || src[1] != 'a' || src[2] != 'z' || src[3] != '0') { + return -1; } - if (currCodeByte & 0x80) { - if (fileOffset != 0) { - if (readCount >= fileOffset) { - *dest = *src; - dest++; - if (dest == endPtr) { - break; - } - } - *(refCurrent++) = *src; - if (refCurrent == refEnd) { - refCurrent = refBuf; - } - src++; - } - else { - *dest = *src; - dest++; - src++; - if (dest == endPtr) { - break; - } - } - readCount++; + + SYaz0Header* header = (SYaz0Header*)src; + endPtr = dest + (header->length - fileOffset); + if (endPtr > dest + maxDest) { + endPtr = dest + maxDest; } - else { - u32 dist = src[1] | (src[0] & 0x0f) << 8; - s32 numBytes = src[0] >> 4; - src += 2; - u8* copySource; - if (fileOffset != 0) { - copySource = refCurrent - dist - 1; - if (copySource < refBuf) { - copySource += refEnd - refBuf; - } - } - else { - copySource = dest - dist - 1; - } - if (numBytes == 0) { - numBytes = *src + 0x12; - src += 1; - } - else { - numBytes += 2; - } - if (fileOffset != 0) { - do { - if (readCount >= fileOffset) { - *dest = *copySource; - dest++; - if (dest == endPtr) { - break; + + src += 0x10; + do { + if (validBitCount == 0) { + if ((src > srcLimit) && transLeft) { + src = nextSrcData(src); } - } - *(refCurrent++) = *copySource; - if (refCurrent == refEnd) { - refCurrent = refBuf; - } - copySource++; - if (copySource == refEnd) { - copySource = refBuf; - } - readCount++; - numBytes--; - } while (numBytes != 0); - } - else { - do { - *dest = *copySource; - dest++; - if (dest == endPtr) { - break; - } - readCount++; - numBytes--; - copySource++; - } while (numBytes != 0); - } - } - currCodeByte <<= 1; - validBitCount--; - } while (dest < endPtr); - return 0; + currCodeByte = *src; + validBitCount = 8; + src++; + } + if (currCodeByte & 0x80) { + if (fileOffset != 0) { + if (readCount >= fileOffset) { + *dest = *src; + dest++; + if (dest == endPtr) { + break; + } + } + *(refCurrent++) = *src; + if (refCurrent == refEnd) { + refCurrent = refBuf; + } + src++; + } else { + *dest = *src; + dest++; + src++; + if (dest == endPtr) { + break; + } + } + readCount++; + } else { + u32 dist = src[1] | (src[0] & 0x0f) << 8; + s32 numBytes = src[0] >> 4; + src += 2; + u8* copySource; + if (fileOffset != 0) { + copySource = refCurrent - dist - 1; + if (copySource < refBuf) { + copySource += refEnd - refBuf; + } + } else { + copySource = dest - dist - 1; + } + if (numBytes == 0) { + numBytes = *src + 0x12; + src += 1; + } else { + numBytes += 2; + } + if (fileOffset != 0) { + do { + if (readCount >= fileOffset) { + *dest = *copySource; + dest++; + if (dest == endPtr) { + break; + } + } + *(refCurrent++) = *copySource; + if (refCurrent == refEnd) { + refCurrent = refBuf; + } + copySource++; + if (copySource == refEnd) { + copySource = refBuf; + } + readCount++; + numBytes--; + } while (numBytes != 0); + } else { + do { + *dest = *copySource; + dest++; + if (dest == endPtr) { + break; + } + readCount++; + numBytes--; + copySource++; + } while (numBytes != 0); + } + } + currCodeByte <<= 1; + validBitCount--; + } while (dest < endPtr); + return 0; } static u8* firstSrcData() { - srcLimit = szpEnd - 0x19; - u8* buf = szpBuf; - u32 maxSize = (szpEnd - szpBuf); - u32 transSize = MIN(transLeft, maxSize); + srcLimit = szpEnd - 0x19; + u8* buf = szpBuf; + u32 maxSize = (szpEnd - szpBuf); + u32 transSize = MIN(transLeft, maxSize); - JKRAramPcs(1, srcAddress + srcOffset, (u32)buf, ALIGN_NEXT(transSize, 32), - nullptr); + JKRAramPcs(1, srcAddress + srcOffset, (u32)buf, ALIGN_NEXT(transSize, 32), nullptr); - srcOffset += transSize; - transLeft -= transSize; + srcOffset += transSize; + transLeft -= transSize; - return buf; + return buf; } u8* nextSrcData(u8* current) { - u8* dest; - u32 left = (u32)(szpEnd - current); - if (IS_NOT_ALIGNED(left, 0x20)) - dest = szpBuf + 0x20 - (left & (0x20 - 1)); - else - dest = szpBuf; + u8* dest; + u32 left = (u32)(szpEnd - current); + if (IS_NOT_ALIGNED(left, 0x20)) + dest = szpBuf + 0x20 - (left & (0x20 - 1)); + else + dest = szpBuf; - memcpy(dest, current, left); - u32 transSize = (u32)(szpEnd - (dest + left)); - if (transSize > transLeft) transSize = transLeft; - // JUT_ASSERT(transSize > 0); + memcpy(dest, current, left); + u32 transSize = (u32)(szpEnd - (dest + left)); + if (transSize > transLeft) + transSize = transLeft; + JUT_ASSERT(transSize > 0); - JKRAramPcs(1, (u32)(srcAddress + srcOffset), ((u32)dest + left), - ALIGN_NEXT(transSize, 0x20), nullptr); - srcOffset += transSize; - transLeft -= transSize; + JKRAramPcs(1, (u32)(srcAddress + srcOffset), ((u32)dest + left), ALIGN_NEXT(transSize, 0x20), nullptr); + srcOffset += transSize; + transLeft -= transSize; - if (transLeft == 0) srcLimit = (dest + left) + transSize; + if (transLeft == 0) + srcLimit = (dest + left) + transSize; - return dest; + return dest; } diff --git a/src/static/JSystem/JKernel/JKRAramArchive.cpp b/src/static/JSystem/JKernel/JKRAramArchive.cpp index 3308fb37..835409d2 100644 --- a/src/static/JSystem/JKernel/JKRAramArchive.cpp +++ b/src/static/JSystem/JKernel/JKRAramArchive.cpp @@ -9,303 +9,286 @@ #include "JSystem/JSystem.h" #include "JSystem/JUtility/JUTAssertion.h" -JKRAramArchive::JKRAramArchive() : JKRArchive() {} +JKRAramArchive::JKRAramArchive() : JKRArchive() { +} + +JKRAramArchive::JKRAramArchive(s32 entryNum, EMountDirection mountDirection) : JKRArchive(entryNum, MOUNT_ARAM) { + mMountDirection = mountDirection; + if (!open(entryNum)) { + return; + } else { + mVolumeType = 'RARC'; + mVolumeName = &mStrTable[mDirectories->mOffset]; + sVolumeList.prepend(&mFileLoaderLink); + mIsMounted = true; + } +} + +JKRAramArchive::~JKRAramArchive() { + if (mIsMounted == true) { + if (mArcInfoBlock) { + SDIFileEntry* fileEntries = mFileEntries; + for (int i = 0; i < mArcInfoBlock->num_file_entries; i++) { + if (fileEntries->mData != nullptr) { + JKRFreeToHeap(mHeap, fileEntries->mData); + } + fileEntries++; + } + JKRFreeToHeap(mHeap, mArcInfoBlock); + mArcInfoBlock = nullptr; + } + + if (mDvdFile) { + delete mDvdFile; + } + if (mBlock) { + delete mBlock; + } + + sVolumeList.remove(&mFileLoaderLink); + mIsMounted = false; + } +} + +void JKRAramArchive::fixedInit(s32 entryNum, EMountDirection direction) { + mIsMounted = false; + mMountDirection = direction; + mMountMode = 2; + mMountCount = 1; + _54 = 2; + mHeap = JKRGetCurrentHeap(); + mEntryNum = entryNum; + + if (sCurrentVolume) + return; + sCurrentVolume = this; + sCurrentDirID = 0; +} + +bool JKRAramArchive::mountFixed(s32 entryNum, EMountDirection direction) { + if (entryNum < 0) + return false; + + if (check_mount_already(entryNum)) + return false; + + fixedInit(entryNum, direction); + if (open(entryNum) == false) { + return false; + } -JKRAramArchive::JKRAramArchive(s32 entryNum, EMountDirection mountDirection) - : JKRArchive(entryNum, MOUNT_ARAM) { - mMountDirection = mountDirection; - if (!open(entryNum)) { - return; - } - else { mVolumeType = 'RARC'; mVolumeName = &mStrTable[mDirectories->mOffset]; sVolumeList.prepend(&mFileLoaderLink); mIsMounted = true; - } -} - -JKRAramArchive::~JKRAramArchive() { - if (mIsMounted == true) { - if (mArcInfoBlock) { - SDIFileEntry* fileEntries = mFileEntries; - for (int i = 0; i < mArcInfoBlock->num_file_entries; i++) { - if (fileEntries->mData != nullptr) { - JKRFreeToHeap(mHeap, fileEntries->mData); - } - fileEntries++; - } - JKRFreeToHeap(mHeap, mArcInfoBlock); - mArcInfoBlock = nullptr; - } - - if (mDvdFile) { - delete mDvdFile; - } - if (mBlock) { - delete mBlock; - } - - sVolumeList.remove(&mFileLoaderLink); - mIsMounted = false; - } -} - -void JKRAramArchive::fixedInit(s32 entryNum, EMountDirection direction) { - mIsMounted = false; - mMountDirection = direction; - mMountMode = 2; - mMountCount = 1; - _54 = 2; - mHeap = JKRGetCurrentHeap(); - mEntryNum = entryNum; - - if (sCurrentVolume) return; - sCurrentVolume = this; - sCurrentDirID = 0; -} - -bool JKRAramArchive::mountFixed(s32 entryNum, EMountDirection direction) { - if (entryNum < 0) return false; - - if (check_mount_already(entryNum)) return false; - - fixedInit(entryNum, direction); - if (open(entryNum) == false) { - return false; - } - - mVolumeType = 'RARC'; - mVolumeName = &mStrTable[mDirectories->mOffset]; - sVolumeList.prepend(&mFileLoaderLink); - mIsMounted = true; - return true; + return true; } bool JKRAramArchive::mountFixed(const char* path, EMountDirection direction) { - s32 entrynum = DVDConvertPathToEntrynum((char*)path); - return mountFixed(entrynum, direction); + s32 entrynum = DVDConvertPathToEntrynum((char*)path); + return mountFixed(entrynum, direction); } void JKRAramArchive::unmountFixed() { - if (sCurrentVolume == this) sCurrentVolume = nullptr; + if (sCurrentVolume == this) + sCurrentVolume = nullptr; - if (mArcInfoBlock) { - SDIFileEntry* fileEntries = mFileEntries; - for (int i = 0; i < mArcInfoBlock->num_file_entries; i++) { - if (fileEntries->mData != nullptr) { - JKRFreeToHeap(mHeap, fileEntries->mData); - } - fileEntries++; + if (mArcInfoBlock) { + SDIFileEntry* fileEntries = mFileEntries; + for (int i = 0; i < mArcInfoBlock->num_file_entries; i++) { + if (fileEntries->mData != nullptr) { + JKRFreeToHeap(mHeap, fileEntries->mData); + } + fileEntries++; + } + JKRFreeToHeap(mHeap, mArcInfoBlock); + mArcInfoBlock = nullptr; } - JKRFreeToHeap(mHeap, mArcInfoBlock); - mArcInfoBlock = nullptr; - } - if (mDvdFile) delete mDvdFile; + if (mDvdFile) + delete mDvdFile; - if (mBlock) delete mBlock; + if (mBlock) + delete mBlock; - sVolumeList.remove(&mFileLoaderLink); - mIsMounted = false; + sVolumeList.remove(&mFileLoaderLink); + mIsMounted = false; } #if DEBUG -CW_FORCE_STRINGS(JKRAramArchive_cpp, __FILE__, "isMounted()", - "mMountCount == 1") +CW_FORCE_STRINGS(JKRAramArchive_cpp, __FILE__, "isMounted()", "mMountCount == 1") #endif - bool JKRAramArchive::open(long entryNum) { - mArcInfoBlock = nullptr; - mDirectories = nullptr; - mFileEntries = nullptr; - mStrTable = nullptr; - mBlock = nullptr; +bool JKRAramArchive::open(long entryNum) { + mArcInfoBlock = nullptr; + mDirectories = nullptr; + mFileEntries = nullptr; + mStrTable = nullptr; + mBlock = nullptr; - mDvdFile = - new (JKRGetSystemHeap(), mMountDirection == MOUNT_DIRECTION_HEAD ? 4 : -4) - JKRDvdFile(entryNum); - if (mDvdFile == nullptr) { - mMountMode = 0; - return 0; - } - - // NOTE: a different struct is used here for sure, unfortunately i can't get - // any hits on this address, so gonna leave it like this for now - SArcHeader* mem = (SArcHeader*)JKRAllocFromSysHeap(32, -32); - if (mem == nullptr) { - mMountMode = 0; - } - else { - JKRDvdToMainRam(entryNum, (u8*)mem, EXPAND_SWITCH_DECOMPRESS, 32, nullptr, - JKRDvdRipper::ALLOC_DIR_TOP, 0, &mCompression); - int alignment = mMountDirection == MOUNT_DIRECTION_HEAD ? 32 : -32; - u32 alignedSize = ALIGN_NEXT(mem->file_data_offset, 32); - mArcInfoBlock = - (SArcDataInfo*)JKRAllocFromHeap(mHeap, alignedSize, alignment); - if (mArcInfoBlock == nullptr) { - mMountMode = 0; - } - else { - JKRDvdToMainRam(entryNum, (u8*)mArcInfoBlock, EXPAND_SWITCH_DECOMPRESS, - alignedSize, nullptr, JKRDvdRipper::ALLOC_DIR_TOP, 32, - nullptr); - - mDirectories = - (SDIDirEntry*)((u8*)mArcInfoBlock + mArcInfoBlock->node_offset); - mFileEntries = (SDIFileEntry*)((u8*)mArcInfoBlock + - mArcInfoBlock->file_entry_offset); - mStrTable = (const char*)((u8*)mArcInfoBlock + - mArcInfoBlock->string_table_offset); - - u32 aramSize = ALIGN_NEXT(mem->file_data_length, 32); - mBlock = - JKRAllocFromAram(aramSize, mMountDirection == MOUNT_DIRECTION_HEAD - ? JKRAramHeap::Head - : JKRAramHeap::Tail); - if (mBlock == nullptr) { + mDvdFile = new (JKRGetSystemHeap(), mMountDirection == MOUNT_DIRECTION_HEAD ? 4 : -4) JKRDvdFile(entryNum); + if (mDvdFile == nullptr) { mMountMode = 0; - } - else { - JKRDvdToAram(entryNum, mBlock->getAddress(), EXPAND_SWITCH_DECOMPRESS, - mem->header_length + mem->file_data_offset, 0); - } + return 0; + } + + // NOTE: a different struct is used here for sure, unfortunately i can't get + // any hits on this address, so gonna leave it like this for now + SArcHeader* mem = (SArcHeader*)JKRAllocFromSysHeap(32, -32); + if (mem == nullptr) { + mMountMode = 0; + } else { + JKRDvdToMainRam(entryNum, (u8*)mem, EXPAND_SWITCH_DECOMPRESS, 32, nullptr, JKRDvdRipper::ALLOC_DIR_TOP, 0, + &mCompression); + int alignment = mMountDirection == MOUNT_DIRECTION_HEAD ? 32 : -32; + u32 alignedSize = ALIGN_NEXT(mem->file_data_offset, 32); + mArcInfoBlock = (SArcDataInfo*)JKRAllocFromHeap(mHeap, alignedSize, alignment); + if (mArcInfoBlock == nullptr) { + mMountMode = 0; + } else { + JKRDvdToMainRam(entryNum, (u8*)mArcInfoBlock, EXPAND_SWITCH_DECOMPRESS, alignedSize, nullptr, + JKRDvdRipper::ALLOC_DIR_TOP, 32, nullptr); + + mDirectories = (SDIDirEntry*)((u8*)mArcInfoBlock + mArcInfoBlock->node_offset); + mFileEntries = (SDIFileEntry*)((u8*)mArcInfoBlock + mArcInfoBlock->file_entry_offset); + mStrTable = (const char*)((u8*)mArcInfoBlock + mArcInfoBlock->string_table_offset); + + u32 aramSize = ALIGN_NEXT(mem->file_data_length, 32); + mBlock = JKRAllocFromAram(aramSize, + mMountDirection == MOUNT_DIRECTION_HEAD ? JKRAramHeap::Head : JKRAramHeap::Tail); + if (mBlock == nullptr) { + mMountMode = 0; + } else { + JKRDvdToAram(entryNum, mBlock->getAddress(), EXPAND_SWITCH_DECOMPRESS, + mem->header_length + mem->file_data_offset, 0); + } + } } - } cleanup: - if (mem != nullptr) { - JKRFreeToSysHeap(mem); - } - if (mMountMode == 0) { - JREPORTF(":::[%s: %d] Cannot alloc memory\n", __FILE__, - 415); // TODO: macro - } - return mMountMode != 0; + if (mem != nullptr) { + JKRFreeToSysHeap(mem); + } + if (mMountMode == 0) { + JREPORTF(":::[%s: %d] Cannot alloc memory\n", __FILE__, + 415); // TODO: macro + } + return mMountMode != 0; } void* JKRAramArchive::fetchResource(SDIFileEntry* fileEntry, u32* pSize) { - JUT_ASSERT(isMounted()); + JUT_ASSERT(isMounted()); - u32 sizeRef; - u8* data; + u32 sizeRef; + u8* data; - if (fileEntry->mData) { - if (pSize) *pSize = fileEntry->mSize; - } - else { - u32 addres = mBlock->getAddress(); - int compression = JKRConvertAttrToCompressionType(fileEntry->mFlag >> 0x18); - u32 size = - fetchResource_subroutine(fileEntry->mDataOffset + addres, - fileEntry->mSize, mHeap, compression, &data); - if (pSize) *pSize = size; - fileEntry->mData = (void*)data; - } + if (fileEntry->mData) { + if (pSize) + *pSize = fileEntry->mSize; + } else { + u32 addres = mBlock->getAddress(); + int compression = JKRConvertAttrToCompressionType(fileEntry->mFlag >> 0x18); + u32 size = + fetchResource_subroutine(fileEntry->mDataOffset + addres, fileEntry->mSize, mHeap, compression, &data); + if (pSize) + *pSize = size; + fileEntry->mData = (void*)data; + } - return fileEntry->mData; + return fileEntry->mData; } -void* JKRAramArchive::fetchResource(void* data, u32 compressedSize, - SDIFileEntry* fileEntry, u32* pSize, - JKRExpandSwitch expandSwitch) { - JUT_ASSERT(isMounted()); - u32 fileSize = fileEntry->mSize; - if (fileSize > compressedSize) { - fileSize = compressedSize; - } - if (fileEntry->mData) { - JKRHeap::copyMemory(data, fileEntry->mData, fileSize); - } - else { - int compression = JKRConvertAttrToCompressionType(fileEntry->mFlag >> 0x18); - if (expandSwitch != EXPAND_SWITCH_DECOMPRESS) compression = 0; +void* JKRAramArchive::fetchResource(void* data, u32 compressedSize, SDIFileEntry* fileEntry, u32* pSize, + JKRExpandSwitch expandSwitch) { + JUT_ASSERT(isMounted()); + u32 fileSize = fileEntry->mSize; + if (fileSize > compressedSize) { + fileSize = compressedSize; + } + if (fileEntry->mData) { + JKRHeap::copyMemory(data, fileEntry->mData, fileSize); + } else { + int compression = JKRConvertAttrToCompressionType(fileEntry->mFlag >> 0x18); + if (expandSwitch != EXPAND_SWITCH_DECOMPRESS) + compression = 0; - fileSize = fetchResource_subroutine( - fileEntry->mDataOffset + mBlock->getAddress(), fileSize, (u8*)data, - compressedSize, compression); - } + fileSize = fetchResource_subroutine(fileEntry->mDataOffset + mBlock->getAddress(), fileSize, (u8*)data, + compressedSize, compression); + } - if (pSize != nullptr) { - *pSize = fileSize; - } - return data; + if (pSize != nullptr) { + *pSize = fileSize; + } + return data; } u32 JKRAramArchive::getAramAddress_Entry(SDIFileEntry* fileEntry) { - JUT_ASSERT(isMounted()); + JUT_ASSERT(isMounted()); - if (fileEntry == nullptr) { - return 0; - } - return fileEntry->mDataOffset + mBlock->getAddress(); + if (fileEntry == nullptr) { + return 0; + } + return fileEntry->mDataOffset + mBlock->getAddress(); } u32 JKRAramArchive::getAramAddress(u32 type, const char* file) { - SDIFileEntry* entry = findTypeResource(type, file); - return getAramAddress_Entry(entry); + SDIFileEntry* entry = findTypeResource(type, file); + return getAramAddress_Entry(entry); } -u32 JKRAramArchive::fetchResource_subroutine(u32 srcAram, u32 size, u8* data, - u32 expandSize, int compression) { - JUT_ASSERT((srcAram & 0x1f) == 0); +u32 JKRAramArchive::fetchResource_subroutine(u32 srcAram, u32 size, u8* data, u32 expandSize, int compression) { + JUT_ASSERT((srcAram & 0x1f) == 0); - u32 sizeRef; + u32 sizeRef; - u32 alignedSize = ALIGN_NEXT(size, 32); - u32 prevAlignedSize = ALIGN_PREV(expandSize, 32); - switch (compression) { - case JKRCOMPRESSION_NONE: - if (alignedSize > prevAlignedSize) { - alignedSize = prevAlignedSize; + u32 alignedSize = ALIGN_NEXT(size, 32); + u32 prevAlignedSize = ALIGN_PREV(expandSize, 32); + switch (compression) { + case JKRCOMPRESSION_NONE: + if (alignedSize > prevAlignedSize) { + alignedSize = prevAlignedSize; + } + JKRAramToMainRam(srcAram, data, alignedSize, EXPAND_SWITCH_DEFAULT, prevAlignedSize, nullptr, -1, &sizeRef); + return sizeRef; + case JKRCOMPRESSION_YAY0: + case JKRCOMPRESSION_YAZ0: + JKRAramToMainRam(srcAram, data, alignedSize, EXPAND_SWITCH_DECOMPRESS, prevAlignedSize, nullptr, -1, + &sizeRef); + return sizeRef; + default: + JPANIC(550, ":::??? bad sequence\n"); + return 0; } - JKRAramToMainRam(srcAram, data, alignedSize, EXPAND_SWITCH_DEFAULT, - prevAlignedSize, nullptr, -1, &sizeRef); - return sizeRef; - case JKRCOMPRESSION_YAY0: - case JKRCOMPRESSION_YAZ0: - JKRAramToMainRam(srcAram, data, alignedSize, EXPAND_SWITCH_DECOMPRESS, - prevAlignedSize, nullptr, -1, &sizeRef); - return sizeRef; - default: - JPANIC(550, ":::??? bad sequence\n"); - return 0; - } } -u32 JKRAramArchive::fetchResource_subroutine(u32 srcAram, u32 size, - JKRHeap* heap, int compression, - u8** pBuf) { - u32 resSize; - u32 alignedSize = ALIGN_NEXT(size, 32); +u32 JKRAramArchive::fetchResource_subroutine(u32 srcAram, u32 size, JKRHeap* heap, int compression, u8** pBuf) { + u32 resSize; + u32 alignedSize = ALIGN_NEXT(size, 32); - u8* buffer; - switch (compression) { - case JKRCOMPRESSION_NONE: - buffer = (u8*)JKRAllocFromHeap(heap, alignedSize, 32); - JUT_ASSERT(buffer != 0); + u8* buffer; + switch (compression) { + case JKRCOMPRESSION_NONE: + buffer = (u8*)JKRAllocFromHeap(heap, alignedSize, 32); + JUT_ASSERT(buffer != 0); - JKRAramToMainRam(srcAram, buffer, alignedSize, EXPAND_SWITCH_DEFAULT, - alignedSize, nullptr, -1, nullptr); - *pBuf = buffer; + JKRAramToMainRam(srcAram, buffer, alignedSize, EXPAND_SWITCH_DEFAULT, alignedSize, nullptr, -1, nullptr); + *pBuf = buffer; - return size; - case JKRCOMPRESSION_YAY0: - case JKRCOMPRESSION_YAZ0: - u8* header = (u8*)JKRAllocFromHeap(heap, 0x20, 0x20); - JKRAramToMainRam(srcAram, header, 0x20, EXPAND_SWITCH_DEFAULT, 0, nullptr, - -1, nullptr); - u32 expandSize = JKRDecompExpandSize(header); - JKRFreeToHeap(heap, header); - expandSize = ALIGN_NEXT(expandSize, 32); - buffer = (u8*)JKRAllocFromHeap(heap, expandSize, 0x20); - JUT_ASSERT(buffer); + return size; + case JKRCOMPRESSION_YAY0: + case JKRCOMPRESSION_YAZ0: + u8* header = (u8*)JKRAllocFromHeap(heap, 0x20, 0x20); + JKRAramToMainRam(srcAram, header, 0x20, EXPAND_SWITCH_DEFAULT, 0, nullptr, -1, nullptr); + u32 expandSize = JKRDecompExpandSize(header); + JKRFreeToHeap(heap, header); + expandSize = ALIGN_NEXT(expandSize, 32); + buffer = (u8*)JKRAllocFromHeap(heap, expandSize, 0x20); + JUT_ASSERT(buffer); - JKRAramToMainRam(srcAram, buffer, alignedSize, EXPAND_SWITCH_DECOMPRESS, - expandSize, heap, -1, &resSize); - *pBuf = buffer; - return resSize; - default: - JPANIC(605, ":::??? bad sequence\n"); - return 0; - } + JKRAramToMainRam(srcAram, buffer, alignedSize, EXPAND_SWITCH_DECOMPRESS, expandSize, heap, -1, &resSize); + *pBuf = buffer; + return resSize; + default: + JPANIC(605, ":::??? bad sequence\n"); + return 0; + } } diff --git a/src/static/JSystem/JKernel/JKRAramBlock.cpp b/src/static/JSystem/JKernel/JKRAramBlock.cpp index b035869d..53b715d2 100644 --- a/src/static/JSystem/JKernel/JKRAramBlock.cpp +++ b/src/static/JSystem/JKernel/JKRAramBlock.cpp @@ -1,45 +1,37 @@ #include "JSystem/JKernel/JKRAram.h" -JKRAramBlock::JKRAramBlock(u32 address, u32 size, u32 freeSize, u8 groupID, - bool tempMemory) - : mLink(this), - mAddress(address), - mSize(size), - mFreeSize(freeSize), - mGroupID(groupID), - mIsTempMemory(tempMemory) {} +JKRAramBlock::JKRAramBlock(u32 address, u32 size, u32 freeSize, u8 groupID, bool tempMemory) + : mLink(this), mAddress(address), mSize(size), mFreeSize(freeSize), mGroupID(groupID), mIsTempMemory(tempMemory) { +} JKRAramBlock::~JKRAramBlock() { - JSULink* prev = this->mLink.getPrev(); - JSUList* list = this->mLink.getList(); + JSULink* prev = this->mLink.getPrev(); + JSUList* list = this->mLink.getList(); - if (prev) { - prev->getObject()->mFreeSize += this->mSize + this->mFreeSize; - list->remove(&this->mLink); - } - else { - this->mFreeSize += this->mSize; - this->mSize = 0; - } + if (prev) { + prev->getObject()->mFreeSize += this->mSize + this->mFreeSize; + list->remove(&this->mLink); + } else { + this->mFreeSize += this->mSize; + this->mSize = 0; + } } JKRAramBlock* JKRAramBlock::allocHead(u32 size, u8 groupID, JKRAramHeap* heap) { - u32 address = this->mAddress + this->mSize; - u32 freeSize = this->mFreeSize - size; + u32 address = this->mAddress + this->mSize; + u32 freeSize = this->mFreeSize - size; - JKRAramBlock* block = new (heap->mHeap, nullptr) - JKRAramBlock(address, size, freeSize, groupID, false); - this->mFreeSize = 0; - this->mLink.mPtrList->insert(this->mLink.mNext, &block->mLink); - return block; + JKRAramBlock* block = new (heap->mHeap, nullptr) JKRAramBlock(address, size, freeSize, groupID, false); + this->mFreeSize = 0; + this->mLink.mPtrList->insert(this->mLink.mNext, &block->mLink); + return block; } JKRAramBlock* JKRAramBlock::allocTail(u32 size, u8 groupID, JKRAramHeap* heap) { - u32 address = this->mAddress + this->mSize + this->mFreeSize - size; + u32 address = this->mAddress + this->mSize + this->mFreeSize - size; - JKRAramBlock* block = - new (heap->mHeap, nullptr) JKRAramBlock(address, size, 0, groupID, true); - this->mFreeSize -= size; - this->mLink.mPtrList->insert(this->mLink.mNext, &block->mLink); - return block; + JKRAramBlock* block = new (heap->mHeap, nullptr) JKRAramBlock(address, size, 0, groupID, true); + this->mFreeSize -= size; + this->mLink.mPtrList->insert(this->mLink.mNext, &block->mLink); + return block; } diff --git a/src/static/JSystem/JKernel/JKRAramHeap.cpp b/src/static/JSystem/JKernel/JKRAramHeap.cpp index 85fe39cf..81520305 100644 --- a/src/static/JSystem/JKernel/JKRAramHeap.cpp +++ b/src/static/JSystem/JKernel/JKRAramHeap.cpp @@ -5,165 +5,154 @@ JSUList JKRAramHeap::sAramList; JKRAramHeap::JKRAramHeap(u32 baseAddress, u32 size) : JKRDisposer() { - OSInitMutex(&this->mMutex); - this->mHeap = JKRHeap::findFromRoot(this); - this->mSize = ALIGN_PREV(size, 0x20); - this->mHeadAddress = ALIGN_NEXT(baseAddress, 0x20); - this->mTailAddress = this->mHeadAddress + this->mSize; - this->mGroupID = 0xFF; - JKRAramBlock* block = new (this->mHeap, nullptr) - JKRAramBlock(this->mHeadAddress, 0, this->mSize, 0xFF, false); - sAramList.append(&block->mLink); + OSInitMutex(&this->mMutex); + this->mHeap = JKRHeap::findFromRoot(this); + this->mSize = ALIGN_PREV(size, 0x20); + this->mHeadAddress = ALIGN_NEXT(baseAddress, 0x20); + this->mTailAddress = this->mHeadAddress + this->mSize; + this->mGroupID = 0xFF; + JKRAramBlock* block = new (this->mHeap, nullptr) JKRAramBlock(this->mHeadAddress, 0, this->mSize, 0xFF, false); + sAramList.append(&block->mLink); } JKRAramHeap::~JKRAramHeap() { - for (JSUListIterator it = sAramList.getFirst(); - it != sAramList.getEnd();) { - delete (it++).getObject(); - } + for (JSUListIterator it = sAramList.getFirst(); it != sAramList.getEnd();) { + delete (it++).getObject(); + } } JKRAramBlock* JKRAramHeap::alloc(u32 size, JKRAramHeap::EAllocMode mode) { - JKRAramBlock* block; - this->lock(); + JKRAramBlock* block; + this->lock(); - if (mode == Head) { - block = this->allocFromHead(size); - } - else { - block = this->allocFromTail(size); - } + if (mode == Head) { + block = this->allocFromHead(size); + } else { + block = this->allocFromTail(size); + } - this->unlock(); - return block; + this->unlock(); + return block; } /* Code retrieved from Twilight Princess Debug version & matched. Unused in AC. */ -void JKRAramHeap::free(JKRAramBlock* block) { delete block; } +void JKRAramHeap::free(JKRAramBlock* block) { + delete block; +} JKRAramBlock* JKRAramHeap::allocFromHead(u32 size) { - size = ALIGN_NEXT(size, 32); - u32 min_size = 0xFFFFFFFFUL; - JKRAramBlock* block = nullptr; + size = ALIGN_NEXT(size, 32); + u32 min_size = 0xFFFFFFFFUL; + JKRAramBlock* block = nullptr; - for (JSUListIterator it = sAramList.getFirst(); - it != sAramList.getEnd(); it++) { - JKRAramBlock* n_block = it.getObject(); - if (n_block->mFreeSize >= size && min_size > n_block->mFreeSize) { - min_size = n_block->mFreeSize; - block = n_block; - if (block->mFreeSize == size) { - break; - } + for (JSUListIterator it = sAramList.getFirst(); it != sAramList.getEnd(); it++) { + JKRAramBlock* n_block = it.getObject(); + if (n_block->mFreeSize >= size && min_size > n_block->mFreeSize) { + min_size = n_block->mFreeSize; + block = n_block; + if (block->mFreeSize == size) { + break; + } + } } - } - if (block != nullptr) { - return block->allocHead(size, this->mGroupID, this); - } + if (block != nullptr) { + return block->allocHead(size, this->mGroupID, this); + } - return nullptr; + return nullptr; } JKRAramBlock* JKRAramHeap::allocFromTail(u32 size) { - JKRAramBlock* block = nullptr; - size = ALIGN_NEXT(size, 32); + JKRAramBlock* block = nullptr; + size = ALIGN_NEXT(size, 32); - for (JSUListIterator it = sAramList.getLast(); - it != sAramList.getEnd(); it--) { - JKRAramBlock* n_block = it.getObject(); + for (JSUListIterator it = sAramList.getLast(); it != sAramList.getEnd(); it--) { + JKRAramBlock* n_block = it.getObject(); - if (n_block->mFreeSize >= size) { - block = n_block; - break; + if (n_block->mFreeSize >= size) { + block = n_block; + break; + } } - } - if (block != nullptr) { - return block->allocTail(size, this->mGroupID, this); - } + if (block != nullptr) { + return block->allocTail(size, this->mGroupID, this); + } - return nullptr; + return nullptr; } /* Debug code retrieved from Twilight Princess Debug version */ void JKRAramHeap::dump() { - this->lock(); + this->lock(); - int total_used = 0; - JREPORT("\nJKRAramHeap dump\n"); - JREPORT(" attr address: size gid\n"); + int total_used = 0; + JREPORT("\nJKRAramHeap dump\n"); + JREPORT(" attr address: size gid\n"); - for (JSUListIterator listItr = sAramList.getFirst(); - listItr != sAramList.getEnd(); listItr++) { - if (listItr->mSize != 0) { - JREPORTF("%s %08x: %08x %3d\n", - listItr->isTempMemory() ? " temp" : "alloc", listItr->mAddress, - listItr->mSize, listItr->mGroupID); + for (JSUListIterator listItr = sAramList.getFirst(); listItr != sAramList.getEnd(); listItr++) { + if (listItr->mSize != 0) { + JREPORTF("%s %08x: %08x %3d\n", listItr->isTempMemory() ? " temp" : "alloc", listItr->mAddress, + listItr->mSize, listItr->mGroupID); + } + + if (listItr->mFreeSize != 0) { + JREPORTF(" free %08x: %08x 0\n", listItr->mAddress + listItr->mSize, listItr->mFreeSize); + } + + total_used += listItr->mSize; } - if (listItr->mFreeSize != 0) { - JREPORTF(" free %08x: %08x 0\n", listItr->mAddress + listItr->mSize, - listItr->mFreeSize); - } + JREPORTF("%d / %d bytes (%6.2f%%) used\n", total_used, this->mSize, (f32)total_used / (f32)this->mSize); - total_used += listItr->mSize; - } - - JREPORTF("%d / %d bytes (%6.2f%%) used\n", total_used, this->mSize, - (f32)total_used / (f32)this->mSize); - - this->unlock(); + this->unlock(); } /* Not present in AC, recreated from TP debug. TODO: Check for matching. */ u32 JKRAramHeap::getFreeSize() { - u32 max_free = 0; - this->lock(); + u32 max_free = 0; + this->lock(); - for (JSUListIterator it = sAramList.getFirst(); - it != sAramList.getEnd(); it++) { - if (it->mFreeSize > max_free) { - max_free = it->mFreeSize; + for (JSUListIterator it = sAramList.getFirst(); it != sAramList.getEnd(); it++) { + if (it->mFreeSize > max_free) { + max_free = it->mFreeSize; + } } - } - this->unlock(); - return max_free; + this->unlock(); + return max_free; } /* Not present in AC, recreated from TP debug. TODO: Check for matching. */ u32 JKRAramHeap::getTotalFreeSize() { - u32 total_free = 0; - this->lock(); + u32 total_free = 0; + this->lock(); - for (JSUListIterator it = sAramList.getFirst(); - it != sAramList.getEnd(); it++) { - total_free += it->mFreeSize; - } + for (JSUListIterator it = sAramList.getFirst(); it != sAramList.getEnd(); it++) { + total_free += it->mFreeSize; + } - this->unlock(); - return total_free; + this->unlock(); + return total_free; } /* Not present in AC, recreated from TP debug. TODO: Check for matching. */ u32 JKRAramHeap::getUsedSize(u8 groupID) { - u32 total_used = 0; - this->lock(); + u32 total_used = 0; + this->lock(); - if (groupID == ARAM_GROUP_ID_ALL) { - total_used = this->mSize - this->getTotalFreeSize(); - } - else { - for (JSUListIterator it = sAramList.getFirst(); - it != sAramList.getEnd(); it++) { - if (groupID == it->mGroupID) { - total_used += it->mSize; - } + if (groupID == ARAM_GROUP_ID_ALL) { + total_used = this->mSize - this->getTotalFreeSize(); + } else { + for (JSUListIterator it = sAramList.getFirst(); it != sAramList.getEnd(); it++) { + if (groupID == it->mGroupID) { + total_used += it->mSize; + } + } } - } - this->unlock(); - return total_used; + this->unlock(); + return total_used; } diff --git a/src/static/JSystem/JKernel/JKRAramPiece.cpp b/src/static/JSystem/JKernel/JKRAramPiece.cpp index 31acd78b..30f64675 100644 --- a/src/static/JSystem/JKernel/JKRAramPiece.cpp +++ b/src/static/JSystem/JKernel/JKRAramPiece.cpp @@ -12,146 +12,132 @@ JSUList JKRAramPiece::sAramPieceCommandList; OSMutex JKRAramPiece::mMutex; -JKRAMCommand* JKRAramPiece::prepareCommand( - int direction, u32 source, u32 destination, u32 length, - JKRAramBlock* aramBlock, JKRAMCommand::AMCommandCallback callback) { - JKRAMCommand* cmd = new (JKRGetSystemHeap(), -4) JKRAMCommand(); - cmd->mDirection = direction; - cmd->mSource = source; - cmd->mDestination = destination; - cmd->mAramBlock = aramBlock; - cmd->mLength = length; - cmd->mCallback = callback; +JKRAMCommand* JKRAramPiece::prepareCommand(int direction, u32 source, u32 destination, u32 length, + JKRAramBlock* aramBlock, JKRAMCommand::AMCommandCallback callback) { + JKRAMCommand* cmd = new (JKRGetSystemHeap(), -4) JKRAMCommand(); + cmd->mDirection = direction; + cmd->mSource = source; + cmd->mDestination = destination; + cmd->mAramBlock = aramBlock; + cmd->mLength = length; + cmd->mCallback = callback; - return cmd; + return cmd; } void JKRAramPiece::sendCommand(JKRAMCommand* cmd) { - JKRAramPiece::startDMA(cmd); + JKRAramPiece::startDMA(cmd); } -JKRAMCommand* JKRAramPiece::orderAsync( - int direction, u32 source, u32 destination, u32 length, - JKRAramBlock* aramBlock, JKRAMCommand::AMCommandCallback callback) { - JKRAramPiece::lock(); +JKRAMCommand* JKRAramPiece::orderAsync(int direction, u32 source, u32 destination, u32 length, JKRAramBlock* aramBlock, + JKRAMCommand::AMCommandCallback callback) { + JKRAramPiece::lock(); - if (!JKR_ISALIGNED32(source) || !JKR_ISALIGNED32(destination)) { - JLOGF("direction = %x\n", direction); - JLOGF("source = %x\n", source); - JLOGF("destination = %x\n", destination); - JLOGF("length = %x\n", length); - JPANICLINE(102); - } + if (!JKR_ISALIGNED32(source) || !JKR_ISALIGNED32(destination)) { + JLOGF("direction = %x\n", direction); + JLOGF("source = %x\n", source); + JLOGF("destination = %x\n", destination); + JLOGF("length = %x\n", length); + JPANICLINE(102); + } - JKRAramCommand* aramCmd = new (JKRGetSystemHeap(), -4) JKRAramCommand(); - JKRAMCommand* cmd = JKRAramPiece::prepareCommand( - direction, source, destination, length, aramBlock, callback); - aramCmd->setting(TRUE, cmd); - OSSendMessage((OSMessageQueue*)&JKRAram::sMessageQueue, (OSMessage)aramCmd, - OS_MESSAGE_BLOCK); - if (cmd->mCallback != nullptr) { - JKRAramPiece::sAramPieceCommandList.append(&cmd->mAramPieceCommandLink); - } + JKRAramCommand* aramCmd = new (JKRGetSystemHeap(), -4) JKRAramCommand(); + JKRAMCommand* cmd = JKRAramPiece::prepareCommand(direction, source, destination, length, aramBlock, callback); + aramCmd->setting(TRUE, cmd); + OSSendMessage((OSMessageQueue*)&JKRAram::sMessageQueue, (OSMessage)aramCmd, OS_MESSAGE_BLOCK); + if (cmd->mCallback != nullptr) { + JKRAramPiece::sAramPieceCommandList.append(&cmd->mAramPieceCommandLink); + } - JKRAramPiece::unlock(); - return cmd; + JKRAramPiece::unlock(); + return cmd; } bool JKRAramPiece::sync(JKRAMCommand* cmd, BOOL noBlock) { - OSMessage msg[1]; + OSMessage msg[1]; - JKRAramPiece::lock(); + JKRAramPiece::lock(); - if (!noBlock) { - OSReceiveMessage(&cmd->mMesgQueue, msg, OS_MESSAGE_BLOCK); - JKRAramPiece::sAramPieceCommandList.remove(&cmd->mAramPieceCommandLink); - JKRAramPiece::unlock(); - return true; - } - else { - if (!OSReceiveMessage(&cmd->mMesgQueue, msg, OS_MESSAGE_NOBLOCK)) { - JKRAramPiece::unlock(); - return false; + if (!noBlock) { + OSReceiveMessage(&cmd->mMesgQueue, msg, OS_MESSAGE_BLOCK); + JKRAramPiece::sAramPieceCommandList.remove(&cmd->mAramPieceCommandLink); + JKRAramPiece::unlock(); + return true; + } else { + if (!OSReceiveMessage(&cmd->mMesgQueue, msg, OS_MESSAGE_NOBLOCK)) { + JKRAramPiece::unlock(); + return false; + } else { + JKRAramPiece::sAramPieceCommandList.remove(&cmd->mAramPieceCommandLink); + JKRAramPiece::unlock(); + return true; + } } - else { - JKRAramPiece::sAramPieceCommandList.remove(&cmd->mAramPieceCommandLink); - JKRAramPiece::unlock(); - return true; - } - } } -bool JKRAramPiece::orderSync(int direction, u32 source, u32 destination, - u32 length, JKRAramBlock* aramBlock) { - JKRAramPiece::lock(); +bool JKRAramPiece::orderSync(int direction, u32 source, u32 destination, u32 length, JKRAramBlock* aramBlock) { + JKRAramPiece::lock(); - JKRAMCommand* cmd = JKRAramPiece::orderAsync(direction, source, destination, - length, aramBlock, nullptr); - bool res = JKRAramPiece::sync(cmd, FALSE); - delete cmd; + JKRAMCommand* cmd = JKRAramPiece::orderAsync(direction, source, destination, length, aramBlock, nullptr); + bool res = JKRAramPiece::sync(cmd, FALSE); + delete cmd; - JKRAramPiece::unlock(); - return res; + JKRAramPiece::unlock(); + return res; } void JKRAramPiece::startDMA(JKRAMCommand* cmd) { - if (cmd->mDirection == ARAM_DIR_ARAM_TO_MRAM) { - DCInvalidateRange((u8*)cmd->mDestination, cmd->mLength); - } - else { /* cmd->mDirection == ARAM_DIR_MRAM_TO_ARAM */ - DCStoreRange((u8*)cmd->mSource, cmd->mLength); - } + if (cmd->mDirection == ARAM_DIR_ARAM_TO_MRAM) { + DCInvalidateRange((u8*)cmd->mDestination, cmd->mLength); + } else { /* cmd->mDirection == ARAM_DIR_MRAM_TO_ARAM */ + DCStoreRange((u8*)cmd->mSource, cmd->mLength); + } - ARQPostRequest(cmd, 0, cmd->mDirection, 0, cmd->mSource, cmd->mDestination, - cmd->mLength, JKRAramPiece::doneDMA); + ARQPostRequest(cmd, 0, cmd->mDirection, 0, cmd->mSource, cmd->mDestination, cmd->mLength, JKRAramPiece::doneDMA); } void JKRAramPiece::doneDMA(u32 param) { - JKRAMCommand* cmd = (JKRAMCommand*)param; - if (cmd->mDirection == ARAM_DIR_ARAM_TO_MRAM) { - DCInvalidateRange((u8*)cmd->mDestination, cmd->mLength); - } - if (cmd->mCallbackType != ARAMPIECE_DONE_CALLBACK) { - if (cmd->mCallbackType == ARAMPIECE_DONE_DECOMPRESS) { - JKRDecomp::sendCommand(cmd->mDecompCommand); + JKRAMCommand* cmd = (JKRAMCommand*)param; + if (cmd->mDirection == ARAM_DIR_ARAM_TO_MRAM) { + DCInvalidateRange((u8*)cmd->mDestination, cmd->mLength); } - } - else { - if (cmd->mCallback != nullptr) { - (*cmd->mCallback)(param); + if (cmd->mCallbackType != ARAMPIECE_DONE_CALLBACK) { + if (cmd->mCallbackType == ARAMPIECE_DONE_DECOMPRESS) { + JKRDecomp::sendCommand(cmd->mDecompCommand); + } + } else { + if (cmd->mCallback != nullptr) { + (*cmd->mCallback)(param); + } else { + if (cmd->mCompletedMesgQueue != nullptr) { + OSSendMessage(cmd->mCompletedMesgQueue, (OSMessage)cmd, OS_MESSAGE_NOBLOCK); + } else { + OSSendMessage(&cmd->mMesgQueue, (OSMessage)cmd, OS_MESSAGE_NOBLOCK); + } + } } - else { - if (cmd->mCompletedMesgQueue != nullptr) { - OSSendMessage(cmd->mCompletedMesgQueue, (OSMessage)cmd, - OS_MESSAGE_NOBLOCK); - } - else { - OSSendMessage(&cmd->mMesgQueue, (OSMessage)cmd, OS_MESSAGE_NOBLOCK); - } - } - } } JKRAMCommand::JKRAMCommand() : mAramPieceCommandLink(this), mLink30(this) { - OSInitMessageQueue(&this->mMesgQueue, this->mMesgBuffer, 1); - this->mCallback = nullptr; - this->mCompletedMesgQueue = nullptr; - this->mCallbackType = ARAMPIECE_DONE_CALLBACK; - this->_8C = nullptr; - this->_90 = nullptr; - this->_94 = nullptr; + OSInitMessageQueue(&this->mMesgQueue, this->mMesgBuffer, 1); + this->mCallback = nullptr; + this->mCompletedMesgQueue = nullptr; + this->mCallbackType = ARAMPIECE_DONE_CALLBACK; + this->_8C = nullptr; + this->_90 = nullptr; + this->_94 = nullptr; } JKRAMCommand::~JKRAMCommand() { - if (this->_8C != nullptr) { - delete this->_8C; - } + if (this->_8C != nullptr) { + delete this->_8C; + } - if (this->_90 != nullptr) { - delete this->_90; - } + if (this->_90 != nullptr) { + delete this->_90; + } - if (this->_94 != nullptr) { - JKRFree(this->_94); - } + if (this->_94 != nullptr) { + JKRFree(this->_94); + } } diff --git a/src/static/JSystem/JKernel/JKRAramStream.cpp b/src/static/JSystem/JKernel/JKRAramStream.cpp index 77a4295e..b5356e53 100644 --- a/src/static/JSystem/JKernel/JKRAramStream.cpp +++ b/src/static/JSystem/JKernel/JKRAramStream.cpp @@ -17,105 +17,99 @@ u32 JKRAramStream::transSize = nullptr; JKRHeap* JKRAramStream::transHeap = nullptr; JKRAramStream* JKRAramStream::create(s32 param) { - if (JKRAramStream::sAramStreamObject == nullptr) { - JKRAramStream::sAramStreamObject = - new (JKRGetSystemHeap(), 0) JKRAramStream(param); - setTransBuffer(nullptr, 0, nullptr); - } - return JKRAramStream::sAramStreamObject; + if (JKRAramStream::sAramStreamObject == nullptr) { + JKRAramStream::sAramStreamObject = new (JKRGetSystemHeap(), 0) JKRAramStream(param); + setTransBuffer(nullptr, 0, nullptr); + } + return JKRAramStream::sAramStreamObject; } JKRAramStream::JKRAramStream(s32 priority) : JKRThread(0x4000, 0x10, priority) { - OSResumeThread(mThreadRecord); + OSResumeThread(mThreadRecord); } JKRAramStream::~JKRAramStream() {}; void* JKRAramStream::run() { - OSMessage result; - OSInitMessageQueue( - &JKRAramStream::sMessageQueue, JKRAramStream::sMessageBuffer, - ARRAY_COUNT(sMessageBuffer)); // jank cast to void** to satisfy prototype - while (true) { - OSReceiveMessage(&JKRAramStream::sMessageQueue, &result, OS_MESSAGE_BLOCK); - JKRAramStreamCommand* command = static_cast(result); - switch (command->type) { - case JKRAramStreamCommand::ECT_READ: - readFromAram(); - break; - case JKRAramStreamCommand::ECT_WRITE: - writeToAram(command); - break; + OSMessage result; + OSInitMessageQueue(&JKRAramStream::sMessageQueue, JKRAramStream::sMessageBuffer, + ARRAY_COUNT(sMessageBuffer)); // jank cast to void** to satisfy prototype + while (true) { + OSReceiveMessage(&JKRAramStream::sMessageQueue, &result, OS_MESSAGE_BLOCK); + JKRAramStreamCommand* command = static_cast(result); + switch (command->type) { + case JKRAramStreamCommand::ECT_READ: + readFromAram(); + break; + case JKRAramStreamCommand::ECT_WRITE: + writeToAram(command); + break; + } } - } } u32 JKRAramStream::readFromAram() { - return 1; -} // probably a define evaluating to 1 + return 1; +} // probably a define evaluating to 1 s32 JKRAramStream::writeToAram(JKRAramStreamCommand* command) { - u32 dstSize = command->mSize; - u32 offset = command->mOffset; - u32 writtenLength = 0; - u32 destination = command->mAddress; - u8* buffer = command->mTransferBuffer; - u32 bufferSize = command->mTransferBufferSize; - JKRHeap* heap = command->mHeap; - if (buffer) { - bufferSize = (bufferSize == nullptr) ? 0x8000 : bufferSize; + u32 dstSize = command->mSize; + u32 offset = command->mOffset; + u32 writtenLength = 0; + u32 destination = command->mAddress; + u8* buffer = command->mTransferBuffer; + u32 bufferSize = command->mTransferBufferSize; + JKRHeap* heap = command->mHeap; + if (buffer) { + bufferSize = (bufferSize == nullptr) ? 0x8000 : bufferSize; - command->mTransferBufferSize = bufferSize; - command->mAllocatedTransferBuffer = false; - } - else { - bufferSize = (bufferSize == nullptr) ? 0x8000 : bufferSize; + command->mTransferBufferSize = bufferSize; + command->mAllocatedTransferBuffer = false; + } else { + bufferSize = (bufferSize == nullptr) ? 0x8000 : bufferSize; - if (heap) { - buffer = (u8*)JKRAllocFromHeap(heap, bufferSize, -0x20); - command->mTransferBuffer = buffer; - } - else { - buffer = (u8*)JKRAllocFromHeap(nullptr, bufferSize, -0x20); - command->mTransferBuffer = buffer; + if (heap) { + buffer = (u8*)JKRAllocFromHeap(heap, bufferSize, -0x20); + command->mTransferBuffer = buffer; + } else { + buffer = (u8*)JKRAllocFromHeap(nullptr, bufferSize, -0x20); + command->mTransferBuffer = buffer; + } + + command->mTransferBufferSize = bufferSize; + command->mAllocatedTransferBuffer = true; } - command->mTransferBufferSize = bufferSize; - command->mAllocatedTransferBuffer = true; - } - - if (!buffer) { - if (!heap) { - JKRGetCurrentHeap()->dump(); - } - else { - heap->dump(); - } - JPANIC(169, "abort\n"); - } - - if (buffer) { - command->mStream->seek(offset, SEEK_SET); - while (dstSize != 0) { - u32 length = (dstSize > bufferSize) ? bufferSize : dstSize; - - s32 readLength = command->mStream->read(buffer, length); - - JKRAramPcs(0, (u32)buffer, destination, length, nullptr); - dstSize -= length; - writtenLength += length; - destination += length; + if (!buffer) { + if (!heap) { + JKRGetCurrentHeap()->dump(); + } else { + heap->dump(); + } + JPANIC(169, "abort\n"); } - if (command->mAllocatedTransferBuffer) { - JKRFree(buffer); - command->mAllocatedTransferBuffer = false; - } - } + if (buffer) { + command->mStream->seek(offset, SEEK_SET); + while (dstSize != 0) { + u32 length = (dstSize > bufferSize) ? bufferSize : dstSize; - OSSendMessage(&command->mMessageQueue, (OSMessage)writtenLength, - OS_MESSAGE_NOBLOCK); - return writtenLength; + s32 readLength = command->mStream->read(buffer, length); + + JKRAramPcs(0, (u32)buffer, destination, length, nullptr); + dstSize -= length; + writtenLength += length; + destination += length; + } + + if (command->mAllocatedTransferBuffer) { + JKRFree(buffer); + command->mAllocatedTransferBuffer = false; + } + } + + OSSendMessage(&command->mMessageQueue, (OSMessage)writtenLength, OS_MESSAGE_NOBLOCK); + return writtenLength; }; /* @@ -124,92 +118,84 @@ s32 JKRAramStream::writeToAram(JKRAramStreamCommand* command) { * Should exist to generate JSURandomInputStream::getAvailable() const * afterwards. */ -JKRAramStreamCommand* JKRAramStream::write_StreamToAram_Async( - JSUFileInputStream* stream, JKRAramBlock* addr, u32 size, u32 offset) { - JKRAramStreamCommand* command = - new (JKRGetSystemHeap(), -4) JKRAramStreamCommand(); - command->type = JKRAramStreamCommand::ECT_WRITE; - command->mAddress = (u32)addr; - command->mSize = size; - command->mStream = stream; - command->_28 = stream->getAvailable(); - command->mOffset = offset; - command->mTransferBuffer = transBuffer; - command->mHeap = transHeap; - command->mTransferBufferSize = transSize; +JKRAramStreamCommand* JKRAramStream::write_StreamToAram_Async(JSUFileInputStream* stream, JKRAramBlock* addr, u32 size, + u32 offset) { + JKRAramStreamCommand* command = new (JKRGetSystemHeap(), -4) JKRAramStreamCommand(); + command->type = JKRAramStreamCommand::ECT_WRITE; + command->mAddress = (u32)addr; + command->mSize = size; + command->mStream = stream; + command->_28 = stream->getAvailable(); + command->mOffset = offset; + command->mTransferBuffer = transBuffer; + command->mHeap = transHeap; + command->mTransferBufferSize = transSize; - OSInitMessageQueue(&command->mMessageQueue, &command->mMessage, 1); - OSSendMessage(&sMessageQueue, command, OS_MESSAGE_BLOCK); - return command; + OSInitMessageQueue(&command->mMessageQueue, &command->mMessage, 1); + OSSendMessage(&sMessageQueue, command, OS_MESSAGE_BLOCK); + return command; } -JKRAramStreamCommand* JKRAramStream::write_StreamToAram_Async( - JSUFileInputStream* stream, u32 addr, u32 size, u32 offset) { - JKRAramStreamCommand* command = - new (JKRGetSystemHeap(), -4) JKRAramStreamCommand(); - command->type = JKRAramStreamCommand::ECT_WRITE; - command->mAddress = addr; - command->mSize = size; - command->mStream = stream; - command->_28 = 0; - command->mOffset = offset; - command->mTransferBuffer = transBuffer; - command->mHeap = transHeap; - command->mTransferBufferSize = transSize; +JKRAramStreamCommand* JKRAramStream::write_StreamToAram_Async(JSUFileInputStream* stream, u32 addr, u32 size, + u32 offset) { + JKRAramStreamCommand* command = new (JKRGetSystemHeap(), -4) JKRAramStreamCommand(); + command->type = JKRAramStreamCommand::ECT_WRITE; + command->mAddress = addr; + command->mSize = size; + command->mStream = stream; + command->_28 = 0; + command->mOffset = offset; + command->mTransferBuffer = transBuffer; + command->mHeap = transHeap; + command->mTransferBufferSize = transSize; - OSInitMessageQueue(&command->mMessageQueue, &command->mMessage, 1); - OSSendMessage(&sMessageQueue, command, OS_MESSAGE_BLOCK); - return command; + OSInitMessageQueue(&command->mMessageQueue, &command->mMessage, 1); + OSSendMessage(&sMessageQueue, command, OS_MESSAGE_BLOCK); + return command; } -JKRAramStreamCommand* JKRAramStream::sync(JKRAramStreamCommand* command, - BOOL isNonBlocking) { - OSMessage msg; - if (isNonBlocking == FALSE) { - OSReceiveMessage(&command->mMessageQueue, &msg, OS_MESSAGE_BLOCK); - if (msg == nullptr) { - command = nullptr; - return command; +JKRAramStreamCommand* JKRAramStream::sync(JKRAramStreamCommand* command, BOOL isNonBlocking) { + OSMessage msg; + if (isNonBlocking == FALSE) { + OSReceiveMessage(&command->mMessageQueue, &msg, OS_MESSAGE_BLOCK); + if (msg == nullptr) { + command = nullptr; + return command; + } else { + return command; + } + } else { + BOOL receiveResult = OSReceiveMessage(&command->mMessageQueue, &msg, OS_MESSAGE_NOBLOCK); + if (receiveResult == FALSE) { + command = nullptr; + return command; + } else if (msg == nullptr) { + command = nullptr; + return command; + } else { + return command; + } } - else { - return command; - } - } - else { - BOOL receiveResult = - OSReceiveMessage(&command->mMessageQueue, &msg, OS_MESSAGE_NOBLOCK); - if (receiveResult == FALSE) { - command = nullptr; - return command; - } - else if (msg == nullptr) { - command = nullptr; - return command; - } - else { - return command; - } - } } void JKRAramStream::setTransBuffer(u8* buffer, u32 bufferSize, JKRHeap* heap) { - transBuffer = nullptr; - transSize = 0x8000; - transHeap = nullptr; + transBuffer = nullptr; + transSize = 0x8000; + transHeap = nullptr; - if (buffer) { - transBuffer = (u8*)ALIGN_NEXT((u32)buffer, 0x20); - } + if (buffer) { + transBuffer = (u8*)ALIGN_NEXT((u32)buffer, 0x20); + } - if (bufferSize) { - transSize = ALIGN_PREV(bufferSize, 0x20); - } + if (bufferSize) { + transSize = ALIGN_PREV(bufferSize, 0x20); + } - if (heap && !buffer) { - transHeap = heap; - } + if (heap && !buffer) { + transHeap = heap; + } } JKRAramStreamCommand::JKRAramStreamCommand() { - mAllocatedTransferBuffer = false; + mAllocatedTransferBuffer = false; } diff --git a/src/static/JSystem/JKernel/JKRArchivePri.cpp b/src/static/JSystem/JKernel/JKRArchivePri.cpp index e695b4eb..591f1883 100644 --- a/src/static/JSystem/JKernel/JKRArchivePri.cpp +++ b/src/static/JSystem/JKernel/JKRArchivePri.cpp @@ -7,37 +7,31 @@ u32 JKRArchive::sCurrentDirID; -JKRArchive::JKRArchive() -{ +JKRArchive::JKRArchive() { mIsMounted = false; mMountDirection = MOUNT_DIRECTION_HEAD; } -JKRArchive::JKRArchive(s32 entryNum, JKRArchive::EMountMode mountMode) - : JKRFileLoader() -{ +JKRArchive::JKRArchive(s32 entryNum, JKRArchive::EMountMode mountMode) : JKRFileLoader() { mIsMounted = false; mMountMode = mountMode; mMountCount = 1; _54 = 1; mHeap = JKRHeap::findFromRoot(this); - if (!mHeap) - { + if (!mHeap) { mHeap = JKRHeap::sCurrentHeap; } mEntryNum = entryNum; - if (sCurrentVolume == nullptr) - { + if (sCurrentVolume == nullptr) { sCurrentDirID = 0; sCurrentVolume = this; } } -JKRArchive::~JKRArchive() {} +JKRArchive::~JKRArchive() { +} -bool JKRArchive::isSameName(JKRArchive::CArcName& archiveName, - u32 nameTableOffset, u16 hash) const -{ +bool JKRArchive::isSameName(JKRArchive::CArcName& archiveName, u32 nameTableOffset, u16 hash) const { u16 arcHash = archiveName.getHash(); if (arcHash != hash) return false; @@ -45,24 +39,18 @@ bool JKRArchive::isSameName(JKRArchive::CArcName& archiveName, return strcmp(&mStrTable[nameTableOffset], archiveName.getString()) == 0; } -JKRArchive::SDIDirEntry* JKRArchive::findResType(u32 type) const -{ +JKRArchive::SDIDirEntry* JKRArchive::findResType(u32 type) const { SDIDirEntry* dirEntry = mDirectories; - for (u32 i = 0; i < mArcInfoBlock->num_nodes; i++, dirEntry++) - { - if (dirEntry->mType == type) - { + for (u32 i = 0; i < mArcInfoBlock->num_nodes; i++, dirEntry++) { + if (dirEntry->mType == type) { return dirEntry; } } return nullptr; } -JKRArchive::SDIDirEntry* JKRArchive::findDirectory(const char* path, - u32 index) const -{ - if (path == nullptr) - { +JKRArchive::SDIDirEntry* JKRArchive::findDirectory(const char* path, u32 index) const { + if (path == nullptr) { return &mDirectories[index]; } @@ -70,12 +58,9 @@ JKRArchive::SDIDirEntry* JKRArchive::findDirectory(const char* path, SDIDirEntry* dirEntry = &mDirectories[index]; SDIFileEntry* entry = &mFileEntries[dirEntry->mFirstIdx]; - for (int i = 0; i < dirEntry->mNum; entry++, i++) - { - if (isSameName(arcName, entry->mFlag & 0xFFFFFF, entry->mHash)) - { - if ((entry->mFlag >> 24) & 0x02) - { + for (int i = 0; i < dirEntry->mNum; entry++, i++) { + if (isSameName(arcName, entry->mFlag & 0xFFFFFF, entry->mHash)) { + if ((entry->mFlag >> 24) & 0x02) { return findDirectory(path, entry->mDataOffset); } break; @@ -85,22 +70,15 @@ JKRArchive::SDIDirEntry* JKRArchive::findDirectory(const char* path, return nullptr; } -JKRArchive::SDIFileEntry* JKRArchive::findTypeResource(u32 type, - const char* name) const -{ - if (type != 0) - { +JKRArchive::SDIFileEntry* JKRArchive::findTypeResource(u32 type, const char* name) const { + if (type != 0) { CArcName arcName; arcName.store(name); SDIDirEntry* dirEntry = findResType(type); - if (dirEntry != nullptr) - { + if (dirEntry != nullptr) { SDIFileEntry* fileEntry = mFileEntries + dirEntry->mFirstIdx; - for (int i = 0; i < dirEntry->mNum; fileEntry++, i++) - { - if (isSameName(arcName, fileEntry->mFlag & 0xFFFFFF, - fileEntry->mHash)) - { + for (int i = 0; i < dirEntry->mNum; fileEntry++, i++) { + if (isSameName(arcName, fileEntry->mFlag & 0xFFFFFF, fileEntry->mHash)) { return fileEntry; } } @@ -109,24 +87,17 @@ JKRArchive::SDIFileEntry* JKRArchive::findTypeResource(u32 type, return nullptr; } -JKRArchive::SDIFileEntry* JKRArchive::findFsResource(const char* path, - u32 index) const -{ - if (path) - { +JKRArchive::SDIFileEntry* JKRArchive::findFsResource(const char* path, u32 index) const { + if (path) { CArcName arcName(&path, '/'); SDIDirEntry* dirEntry = &mDirectories[index]; SDIFileEntry* entry = &mFileEntries[dirEntry->mFirstIdx]; - for (int i = 0; i < dirEntry->mNum; entry++, i++) - { - if (isSameName(arcName, entry->mFlag & 0xFFFFFF, entry->mHash)) - { - if (((entry->mFlag >> 0x18) & 2)) - { + for (int i = 0; i < dirEntry->mNum; entry++, i++) { + if (isSameName(arcName, entry->mFlag & 0xFFFFFF, entry->mHash)) { + if (((entry->mFlag >> 0x18) & 2)) { return findFsResource(path, entry->mDataOffset); } - if (path == 0) - { + if (path == 0) { return entry; } return nullptr; @@ -136,24 +107,19 @@ JKRArchive::SDIFileEntry* JKRArchive::findFsResource(const char* path, return nullptr; } -JKRArchive::SDIFileEntry* JKRArchive::findIdxResource(u32 idx) const -{ - if (idx < mArcInfoBlock->num_file_entries) - { +JKRArchive::SDIFileEntry* JKRArchive::findIdxResource(u32 idx) const { + if (idx < mArcInfoBlock->num_file_entries) { return mFileEntries + idx; } return nullptr; } -JKRArchive::SDIFileEntry* JKRArchive::findNameResource(const char* name) const -{ +JKRArchive::SDIFileEntry* JKRArchive::findNameResource(const char* name) const { SDIFileEntry* fileEntry = mFileEntries; CArcName arcName(name); - for (int i = 0; i < mArcInfoBlock->num_file_entries; fileEntry++, i++) - { - if (isSameName(arcName, fileEntry->mFlag & 0xFFFFFF, fileEntry->mHash)) - { + for (int i = 0; i < mArcInfoBlock->num_file_entries; fileEntry++, i++) { + if (isSameName(arcName, fileEntry->mFlag & 0xFFFFFF, fileEntry->mHash)) { return fileEntry; } } @@ -161,35 +127,27 @@ JKRArchive::SDIFileEntry* JKRArchive::findNameResource(const char* name) const return nullptr; } -JKRArchive::SDIFileEntry* JKRArchive::findPtrResource(const void* ptr) const -{ +JKRArchive::SDIFileEntry* JKRArchive::findPtrResource(const void* ptr) const { SDIFileEntry* entry = mFileEntries; - for (u32 i = 0; i < mArcInfoBlock->num_file_entries; entry++, i++) - { - if (entry->mData == ptr) - { + for (u32 i = 0; i < mArcInfoBlock->num_file_entries; entry++, i++) { + if (entry->mData == ptr) { return entry; } } return nullptr; } -JKRArchive::SDIFileEntry* JKRArchive::findIdResource(u16 id) const -{ +JKRArchive::SDIFileEntry* JKRArchive::findIdResource(u16 id) const { SDIFileEntry* entry; - if (id != 0xFFFF) - { + if (id != 0xFFFF) { entry = &mFileEntries[id]; - if (entry->mFileID == id && (entry->getFlag01())) - { + if (entry->mFileID == id && (entry->getFlag01())) { return entry; } entry = mFileEntries; - for (int i = 0; i < mArcInfoBlock->num_file_entries; entry++, i++) - { - if (entry->mFileID == id && (entry->getFlag01())) - { + for (int i = 0; i < mArcInfoBlock->num_file_entries; entry++, i++) { + if (entry->mFileID == id && (entry->getFlag01())) { return entry; } } @@ -197,16 +155,13 @@ JKRArchive::SDIFileEntry* JKRArchive::findIdResource(u16 id) const return nullptr; } -void JKRArchive::CArcName::store(const char* name) -{ +void JKRArchive::CArcName::store(const char* name) { mHash = 0; int count = 0; - while (*name) - { + while (*name) { int lower = tolower(*name); mHash = lower + mHash * 3; - if (count < 0x100) - { + if (count < 0x100) { mString[count++] = lower; } name++; @@ -215,16 +170,13 @@ void JKRArchive::CArcName::store(const char* name) mString[count] = '\0'; } -const char* JKRArchive::CArcName::store(const char* name, char endChar) -{ +const char* JKRArchive::CArcName::store(const char* name, char endChar) { mHash = 0; int count = 0; - for (; *name && *name != endChar; name++) - { + for (; *name && *name != endChar; name++) { int lower = tolower(*name); mHash = lower + mHash * 3; - if (count < 0x100) - { + if (count < 0x100) { mString[count++] = lower; } } diff --git a/src/static/JSystem/JKernel/JKRArchivePub.cpp b/src/static/JSystem/JKernel/JKRArchivePub.cpp index c3fffbd0..d49287a2 100644 --- a/src/static/JSystem/JKernel/JKRArchivePub.cpp +++ b/src/static/JSystem/JKernel/JKRArchivePub.cpp @@ -12,326 +12,298 @@ // does that and it doesn't cause any issues JKRArchive* JKRArchive::check_mount_already(s32 entryNum, JKRHeap* pHeap) { - // UNUSED FUNCTION - JKRHeap* heap = pHeap; - if (heap == nullptr) { - heap = JKRGetCurrentHeap(); - } - - JSUListIterator iterator; - for (iterator = sVolumeList.getFirst(); iterator != sVolumeList.getEnd(); - ++iterator) { - if (iterator->getVolumeType() == 'RARC') { - JKRArchive* archive = - (JKRArchive*) - iterator.getObject(); // in TP debug it calls operator-> ? - if (archive->mEntryNum == entryNum && archive->mHeap == heap) { - archive->mMountCount++; - return archive; - } + // UNUSED FUNCTION + JKRHeap* heap = pHeap; + if (heap == nullptr) { + heap = JKRGetCurrentHeap(); } - } - return nullptr; + + JSUListIterator iterator; + for (iterator = sVolumeList.getFirst(); iterator != sVolumeList.getEnd(); ++iterator) { + if (iterator->getVolumeType() == 'RARC') { + JKRArchive* archive = (JKRArchive*)iterator.getObject(); // in TP debug it calls operator-> ? + if (archive->mEntryNum == entryNum && archive->mHeap == heap) { + archive->mMountCount++; + return archive; + } + } + } + return nullptr; } JKRArchive* JKRArchive::check_mount_already(s32 entryNum) { - for (JSUListIterator iterator = sVolumeList.getFirst(); iterator != sVolumeList.getEnd(); - ++iterator) { - if (iterator->getVolumeType() == 'RARC') { - JKRArchive* archive = - (JKRArchive*) - iterator.getObject(); // in TP debug it calls operator-> ? - if (archive->mEntryNum == entryNum) { - archive->mMountCount++; - return archive; - } + for (JSUListIterator iterator = sVolumeList.getFirst(); iterator != sVolumeList.getEnd(); + ++iterator) { + if (iterator->getVolumeType() == 'RARC') { + JKRArchive* archive = (JKRArchive*)iterator.getObject(); // in TP debug it calls operator-> ? + if (archive->mEntryNum == entryNum) { + archive->mMountCount++; + return archive; + } + } } - } - return nullptr; + return nullptr; } -JKRArchive* JKRArchive::mount(const char* path, EMountMode mode, JKRHeap* heap, - EMountDirection direction) { - int entryNum = DVDConvertPathToEntrynum((char*)path); - if (entryNum < 0) return nullptr; +JKRArchive* JKRArchive::mount(const char* path, EMountMode mode, JKRHeap* heap, EMountDirection direction) { + int entryNum = DVDConvertPathToEntrynum((char*)path); + if (entryNum < 0) + return nullptr; - JKRArchive* mountedArchive = check_mount_already(entryNum); - if (mountedArchive != nullptr) { - return mountedArchive; - } + JKRArchive* mountedArchive = check_mount_already(entryNum); + if (mountedArchive != nullptr) { + return mountedArchive; + } - int alignment = (direction == MOUNT_DIRECTION_HEAD) ? 4 : -4; - JKRArchive* archive; - switch (mode) { - case MOUNT_MEM: - if (entryNum == -1) - archive = nullptr; - else - archive = new (heap, alignment) JKRMemArchive(entryNum, direction); - break; - case MOUNT_ARAM: - archive = new (heap, alignment) JKRAramArchive(entryNum, direction); - break; - case MOUNT_DVD: - archive = new (heap, alignment) JKRDvdArchive(entryNum, direction); - break; - case MOUNT_COMP: - archive = new (heap, alignment) JKRCompArchive(entryNum, direction); - break; - } - if (archive != nullptr && archive->getMountMode() == UNKNOWN_MOUNT_MODE) { - delete archive; - archive = nullptr; - } - return archive; -} - -JKRArchive* JKRArchive::mount(void* p1, JKRHeap* heap, - EMountDirection mountDirection) { - JKRArchive* archive = check_mount_already((s32)p1, heap); - if (archive != nullptr) { - return archive; - } - return new (heap, (mountDirection == MOUNT_DIRECTION_HEAD) ? 4 : -4) - JKRMemArchive(p1, 0xFFFF, MBF_0); -} - -JKRArchive* JKRArchive::mount(s32 entryNum, EMountMode mountMode, JKRHeap* heap, - EMountDirection mountDirection) { - JKRArchive* archive = check_mount_already(entryNum, heap); - if (archive) { - return archive; - } - else { - int i = (mountDirection == MOUNT_DIRECTION_HEAD) ? 4 : -4; + int alignment = (direction == MOUNT_DIRECTION_HEAD) ? 4 : -4; JKRArchive* archive; - switch (mountMode) { - case MOUNT_MEM: - archive = new (heap, i) JKRMemArchive(entryNum, mountDirection); - break; - case MOUNT_ARAM: - archive = new (heap, i) JKRAramArchive(entryNum, mountDirection); - break; - case MOUNT_DVD: - archive = new (heap, i) JKRDvdArchive(entryNum, mountDirection); - break; - case MOUNT_COMP: - archive = new (heap, i) JKRCompArchive(entryNum, mountDirection); - break; + switch (mode) { + case MOUNT_MEM: + if (entryNum == -1) + archive = nullptr; + else + archive = new (heap, alignment) JKRMemArchive(entryNum, direction); + break; + case MOUNT_ARAM: + archive = new (heap, alignment) JKRAramArchive(entryNum, direction); + break; + case MOUNT_DVD: + archive = new (heap, alignment) JKRDvdArchive(entryNum, direction); + break; + case MOUNT_COMP: + archive = new (heap, alignment) JKRCompArchive(entryNum, direction); + break; } if (archive != nullptr && archive->getMountMode() == UNKNOWN_MOUNT_MODE) { - delete archive; - archive = nullptr; + delete archive; + archive = nullptr; } return archive; - } +} + +JKRArchive* JKRArchive::mount(void* p1, JKRHeap* heap, EMountDirection mountDirection) { + JKRArchive* archive = check_mount_already((s32)p1, heap); + if (archive != nullptr) { + return archive; + } + return new (heap, (mountDirection == MOUNT_DIRECTION_HEAD) ? 4 : -4) JKRMemArchive(p1, 0xFFFF, MBF_0); +} + +JKRArchive* JKRArchive::mount(s32 entryNum, EMountMode mountMode, JKRHeap* heap, EMountDirection mountDirection) { + JKRArchive* archive = check_mount_already(entryNum, heap); + if (archive) { + return archive; + } else { + int i = (mountDirection == MOUNT_DIRECTION_HEAD) ? 4 : -4; + JKRArchive* archive; + switch (mountMode) { + case MOUNT_MEM: + archive = new (heap, i) JKRMemArchive(entryNum, mountDirection); + break; + case MOUNT_ARAM: + archive = new (heap, i) JKRAramArchive(entryNum, mountDirection); + break; + case MOUNT_DVD: + archive = new (heap, i) JKRDvdArchive(entryNum, mountDirection); + break; + case MOUNT_COMP: + archive = new (heap, i) JKRCompArchive(entryNum, mountDirection); + break; + } + if (archive != nullptr && archive->getMountMode() == UNKNOWN_MOUNT_MODE) { + delete archive; + archive = nullptr; + } + return archive; + } } bool JKRArchive::becomeCurrent(const char* path) { - SDIDirEntry* entry; - if (*path == '/') { - const char* directoryName = path + 1; - if (*directoryName == '\0') { - directoryName = nullptr; + SDIDirEntry* entry; + if (*path == '/') { + const char* directoryName = path + 1; + if (*directoryName == '\0') { + directoryName = nullptr; + } + entry = findDirectory(directoryName, 0); + } else { + entry = findDirectory(path, sCurrentDirID); } - entry = findDirectory(directoryName, 0); - } - else { - entry = findDirectory(path, sCurrentDirID); - } - bool result = (entry != nullptr); - if (result) { - sCurrentVolume = this; - sCurrentDirID = (entry - mDirectories); - } - return result; + bool result = (entry != nullptr); + if (result) { + sCurrentVolume = this; + sCurrentDirID = (entry - mDirectories); + } + return result; } bool JKRArchive::getDirEntry(JKRArchive::SDirEntry* dirEntry, u32 p2) const { - SDIFileEntry* fileEntry = findIdxResource(p2); - if (!fileEntry) { - return false; - } + SDIFileEntry* fileEntry = findIdxResource(p2); + if (!fileEntry) { + return false; + } - dirEntry->mFlags = fileEntry->mFlag >> 0x18; - dirEntry->mID = fileEntry->mFileID; - dirEntry->mName = (char*)mStrTable + (fileEntry->mFlag & 0xFFFFFF); - return true; + dirEntry->mFlags = fileEntry->mFlag >> 0x18; + dirEntry->mID = fileEntry->mFileID; + dirEntry->mName = (char*)mStrTable + (fileEntry->mFlag & 0xFFFFFF); + return true; } -void* JKRArchive::getGlbResource(u32 type, const char* name, - JKRArchive* archive) { - void* resource = nullptr; - if (archive) { - return archive->getResource(type, name); - } - for (JSULink* link = sVolumeList.getFirst(); link != nullptr; - link = link->getNext()) { - if (link->getObject()->getVolumeType() == 'RARC' && - (resource = link->getObject()->getResource(type, name))) { - break; +void* JKRArchive::getGlbResource(u32 type, const char* name, JKRArchive* archive) { + void* resource = nullptr; + if (archive) { + return archive->getResource(type, name); } - } - return resource; + for (JSULink* link = sVolumeList.getFirst(); link != nullptr; link = link->getNext()) { + if (link->getObject()->getVolumeType() == 'RARC' && (resource = link->getObject()->getResource(type, name))) { + break; + } + } + return resource; } void* JKRArchive::getResource(const char* path) { - JUT_ASSERT(isMounted()); - SDIFileEntry* fileEntry; - if (*path == '/') { - fileEntry = findFsResource(path + 1, 0); - } - else { - fileEntry = findFsResource(path, sCurrentDirID); - } - return (fileEntry != nullptr) ? (void*)fetchResource(fileEntry, nullptr) - : nullptr; + JUT_ASSERT(isMounted()); + SDIFileEntry* fileEntry; + if (*path == '/') { + fileEntry = findFsResource(path + 1, 0); + } else { + fileEntry = findFsResource(path, sCurrentDirID); + } + return (fileEntry != nullptr) ? (void*)fetchResource(fileEntry, nullptr) : nullptr; } void* JKRArchive::getResource(u32 type, const char* name) { - JUT_ASSERT(isMounted()); - SDIFileEntry* fileEntry; - if (type == 0 || type == '????') { - fileEntry = findNameResource(name); - } - else { - fileEntry = findTypeResource(type, name); - } - return (fileEntry != nullptr) ? (void*)fetchResource(fileEntry, nullptr) - : nullptr; + JUT_ASSERT(isMounted()); + SDIFileEntry* fileEntry; + if (type == 0 || type == '????') { + fileEntry = findNameResource(name); + } else { + fileEntry = findTypeResource(type, name); + } + return (fileEntry != nullptr) ? (void*)fetchResource(fileEntry, nullptr) : nullptr; } void* JKRArchive::getIdxResource(u32 index) { - SDIFileEntry* fileEntry = findIdxResource(index); - return (fileEntry != nullptr) ? (void*)fetchResource(fileEntry, nullptr) - : nullptr; + SDIFileEntry* fileEntry = findIdxResource(index); + return (fileEntry != nullptr) ? (void*)fetchResource(fileEntry, nullptr) : nullptr; } -size_t JKRArchive::readResource(void* resourceBuffer, u32 bufferSize, u32 type, - const char* name) { - JUT_ASSERT(isMounted()); - SDIFileEntry* fileEntry; - if (type == 0 || type == '????') { - fileEntry = findNameResource(name); - } - else { - fileEntry = findTypeResource(type, name); - } - if (fileEntry) { - u32 resourceSize; - fetchResource(resourceBuffer, bufferSize, fileEntry, &resourceSize, - EXPAND_SWITCH_DECOMPRESS); - return resourceSize; - } - return 0; +size_t JKRArchive::readResource(void* resourceBuffer, u32 bufferSize, u32 type, const char* name) { + JUT_ASSERT(isMounted()); + SDIFileEntry* fileEntry; + if (type == 0 || type == '????') { + fileEntry = findNameResource(name); + } else { + fileEntry = findTypeResource(type, name); + } + if (fileEntry) { + u32 resourceSize; + fetchResource(resourceBuffer, bufferSize, fileEntry, &resourceSize, EXPAND_SWITCH_DECOMPRESS); + return resourceSize; + } + return 0; } // Returns the size of the resource at the given path, or 0 if not found. -size_t JKRArchive::readResource(void* resourceBuffer, u32 bufferSize, - const char* path, - JKRExpandSwitch expandSwitch) { - JUT_ASSERT(isMounted()); - SDIFileEntry* fileEntry; - if (*path == '/') { - fileEntry = findFsResource(path + 1, 0); - } - else { - fileEntry = findFsResource(path, sCurrentDirID); - } - if (fileEntry) { - u32 resourceSize; - fetchResource(resourceBuffer, bufferSize, fileEntry, &resourceSize, - expandSwitch); - return resourceSize; - } - return 0; +size_t JKRArchive::readResource(void* resourceBuffer, u32 bufferSize, const char* path, JKRExpandSwitch expandSwitch) { + JUT_ASSERT(isMounted()); + SDIFileEntry* fileEntry; + if (*path == '/') { + fileEntry = findFsResource(path + 1, 0); + } else { + fileEntry = findFsResource(path, sCurrentDirID); + } + if (fileEntry) { + u32 resourceSize; + fetchResource(resourceBuffer, bufferSize, fileEntry, &resourceSize, expandSwitch); + return resourceSize; + } + return 0; } // Returns the size of the resource with the given ID, or 0 if not found. size_t JKRArchive::readResource(void* resourceBuffer, u32 bufferSize, u16 id) { - JUT_ASSERT(isMounted()); - SDIFileEntry* fileEntry = findIdResource(id); - if (fileEntry) { - u32 resSize; - fetchResource(resourceBuffer, bufferSize, fileEntry, &resSize, - EXPAND_SWITCH_DEFAULT); - return resSize; - } - return 0; + JUT_ASSERT(isMounted()); + SDIFileEntry* fileEntry = findIdResource(id); + if (fileEntry) { + u32 resSize; + fetchResource(resourceBuffer, bufferSize, fileEntry, &resSize, EXPAND_SWITCH_DEFAULT); + return resSize; + } + return 0; } // This function is currently full off bugs, it doesn't increase the pointer to // the file entries, and sets the pointer of mData to null before it's sent to // free void JKRArchive::removeResourceAll() { - if (mArcInfoBlock && mMountMode != MOUNT_MEM) { - SDIFileEntry* entry = mFileEntries; - for (int i = 0; i < mArcInfoBlock->num_file_entries; i++) { - if (entry->mData) { - entry->mData = nullptr; - JKRFreeToHeap(mHeap, entry->mData); - } + if (mArcInfoBlock && mMountMode != MOUNT_MEM) { + SDIFileEntry* entry = mFileEntries; + for (int i = 0; i < mArcInfoBlock->num_file_entries; i++) { + if (entry->mData) { + entry->mData = nullptr; + JKRFreeToHeap(mHeap, entry->mData); + } + } } - } } bool JKRArchive::removeResource(void* resource) { - JUT_ASSERT(resource != 0); - SDIFileEntry* entry = findPtrResource(resource); - if (entry == nullptr) { - return false; - } - entry->mData = nullptr; - JKRHeap::free(resource, mHeap); - return true; + JUT_ASSERT(resource != 0); + SDIFileEntry* entry = findPtrResource(resource); + if (entry == nullptr) { + return false; + } + entry->mData = nullptr; + JKRHeap::free(resource, mHeap); + return true; } bool JKRArchive::detachResource(void* resource) { - JUT_ASSERT(resource != 0); - SDIFileEntry* entry = findPtrResource(resource); - if (entry == nullptr) { - return false; - } - entry->mData = nullptr; - return true; + JUT_ASSERT(resource != 0); + SDIFileEntry* entry = findPtrResource(resource); + if (entry == nullptr) { + return false; + } + entry->mData = nullptr; + return true; } s32 JKRArchive::getResSize(const void* resource) const { - JUT_ASSERT(resource != 0); - SDIFileEntry* entry = findPtrResource(resource); - return (entry == nullptr) ? -1 : entry->getSize(); + JUT_ASSERT(resource != 0); + SDIFileEntry* entry = findPtrResource(resource); + return (entry == nullptr) ? -1 : entry->getSize(); } u32 JKRArchive::countFile(const char* path) const { - SDIDirEntry* dirEntry; - if (*path == '/') { - const char* pathPtr = path + 1; - if (*pathPtr == '\0') { - pathPtr = nullptr; + SDIDirEntry* dirEntry; + if (*path == '/') { + const char* pathPtr = path + 1; + if (*pathPtr == '\0') { + pathPtr = nullptr; + } + dirEntry = findDirectory(pathPtr, 0); + } else { + dirEntry = findDirectory(path, sCurrentDirID); } - dirEntry = findDirectory(pathPtr, 0); - } - else { - dirEntry = findDirectory(path, sCurrentDirID); - } - return (dirEntry) ? dirEntry->mNum : 0; + return (dirEntry) ? dirEntry->mNum : 0; } JKRFileFinder* JKRArchive::getFirstFile(const char* path) const { - SDIDirEntry* dirEntry; - if (*path == '/') { - const char* pathPtr = path + 1; - if (*pathPtr == '\0') { - pathPtr = nullptr; + SDIDirEntry* dirEntry; + if (*path == '/') { + const char* pathPtr = path + 1; + if (*pathPtr == '\0') { + pathPtr = nullptr; + } + dirEntry = findDirectory(pathPtr, 0); + } else { + dirEntry = findDirectory(path, sCurrentDirID); } - dirEntry = findDirectory(pathPtr, 0); - } - else { - dirEntry = findDirectory(path, sCurrentDirID); - } - if (dirEntry) { - return new (JKRGetSystemHeap(), 0) JKRArcFinder( - const_cast(this), dirEntry->mFirstIdx, dirEntry->mNum); - } - return nullptr; + if (dirEntry) { + return new (JKRGetSystemHeap(), 0) + JKRArcFinder(const_cast(this), dirEntry->mFirstIdx, dirEntry->mNum); + } + return nullptr; } diff --git a/src/static/JSystem/JKernel/JKRCompArchive.cpp b/src/static/JSystem/JKernel/JKRCompArchive.cpp index c46000e1..09a800f4 100644 --- a/src/static/JSystem/JKernel/JKRCompArchive.cpp +++ b/src/static/JSystem/JKernel/JKRCompArchive.cpp @@ -8,335 +8,303 @@ #include "JSystem/JSystem.h" #include "JSystem/JUtility/JUTAssertion.h" -JKRCompArchive::JKRCompArchive(long entryNum, EMountDirection mountDirection) - : JKRArchive(entryNum, MOUNT_COMP) { - mMountDirection = mountDirection; - if (!open(entryNum)) { - return; - } - else { - mVolumeType = 'RARC'; - mVolumeName = &mStrTable[mDirectories->mOffset]; - sVolumeList.prepend(&mFileLoaderLink); - mIsMounted = true; - } +JKRCompArchive::JKRCompArchive(long entryNum, EMountDirection mountDirection) : JKRArchive(entryNum, MOUNT_COMP) { + mMountDirection = mountDirection; + if (!open(entryNum)) { + return; + } else { + mVolumeType = 'RARC'; + mVolumeName = &mStrTable[mDirectories->mOffset]; + sVolumeList.prepend(&mFileLoaderLink); + mIsMounted = true; + } } #if DEBUG void stringGen() { - JUT_PANIC("isMounted()"); - JUT_PANIC("mMountCount == 1"); + JUT_PANIC("isMounted()"); + JUT_PANIC("mMountCount == 1"); } #endif JKRCompArchive::~JKRCompArchive() { - if (mArcInfoBlock) { - SDIFileEntry* fileEntries = mFileEntries; - for (int i = 0; i < mArcInfoBlock->num_file_entries; i++) { - u32 flag = (fileEntries->mFlag >> 24); - if ((flag & 16) == 0 && fileEntries->mData) { - JKRFreeToHeap(mHeap, fileEntries->mData); - } - fileEntries++; + if (mArcInfoBlock) { + SDIFileEntry* fileEntries = mFileEntries; + for (int i = 0; i < mArcInfoBlock->num_file_entries; i++) { + u32 flag = (fileEntries->mFlag >> 24); + if ((flag & 16) == 0 && fileEntries->mData) { + JKRFreeToHeap(mHeap, fileEntries->mData); + } + fileEntries++; + } + JKRFreeToHeap(mHeap, mArcInfoBlock); + mArcInfoBlock = nullptr; + } + if (mAramPart) { + delete mAramPart; + } + if (mDvdFile) { + delete mDvdFile; } - JKRFreeToHeap(mHeap, mArcInfoBlock); - mArcInfoBlock = nullptr; - } - if (mAramPart) { - delete mAramPart; - } - if (mDvdFile) { - delete mDvdFile; - } - sVolumeList.remove(&mFileLoaderLink); - mIsMounted = false; + sVolumeList.remove(&mFileLoaderLink); + mIsMounted = false; } bool JKRCompArchive::open(long entryNum) { - mArcInfoBlock = nullptr; - _60 = 0; - mAramPart = nullptr; - _68 = 0; - mSizeOfMemPart = 0; - mSizeOfAramPart = 0; - _78 = 0; - mDirectories = nullptr; - mFileEntries = nullptr; - mStrTable = nullptr; + mArcInfoBlock = nullptr; + _60 = 0; + mAramPart = nullptr; + _68 = 0; + mSizeOfMemPart = 0; + mSizeOfAramPart = 0; + _78 = 0; + mDirectories = nullptr; + mFileEntries = nullptr; + mStrTable = nullptr; - mDvdFile = new (JKRGetSystemHeap(), 0) JKRDvdFile(entryNum); - if (mDvdFile == nullptr) { - mMountMode = 0; - return 0; - } - SArcHeader* arcHeader = (SArcHeader*)JKRAllocFromSysHeap( - sizeof(SArcHeader), -32); // NOTE: unconfirmed if this struct is used - if (arcHeader == nullptr) { - mMountMode = 0; - } - else { - int alignment; - - JKRDvdToMainRam(entryNum, (u8*)arcHeader, EXPAND_SWITCH_DECOMPRESS, 32, - nullptr, JKRDvdRipper::ALLOC_DIR_TOP, 0, &mCompression); - - mSizeOfMemPart = arcHeader->_14; - mSizeOfAramPart = arcHeader->_18; - JUT_ASSERT((mSizeOfMemPart & 0x1f) == 0); - JUT_ASSERT((mSizeOfAramPart & 0x1f) == 0); - - switch (mCompression) { - case JKRCOMPRESSION_NONE: - case JKRCOMPRESSION_YAZ0: - alignment = mMountDirection == 1 ? 32 : -32; - mArcInfoBlock = (SArcDataInfo*)JKRAllocFromHeap( - mHeap, arcHeader->file_data_offset + mSizeOfMemPart, alignment); - if (mArcInfoBlock == nullptr) { + mDvdFile = new (JKRGetSystemHeap(), 0) JKRDvdFile(entryNum); + if (mDvdFile == nullptr) { mMountMode = 0; - } - else { - JKRDvdToMainRam(entryNum, (u8*)mArcInfoBlock, - EXPAND_SWITCH_DECOMPRESS, - (u32)arcHeader->file_data_offset + mSizeOfMemPart, - nullptr, JKRDvdRipper::ALLOC_DIR_TOP, 0x20, nullptr); - _60 = (u32)mArcInfoBlock + arcHeader->file_data_offset; - - if (mSizeOfAramPart != 0) { - mAramPart = JKRAllocFromAram(mSizeOfAramPart, JKRAramHeap::Head); - if (mAramPart == nullptr) { - mMountMode = 0; - break; - } - - JKRDvdToAram(entryNum, mAramPart->getAddress(), - EXPAND_SWITCH_DECOMPRESS, - arcHeader->header_length + - arcHeader->file_data_offset + mSizeOfMemPart, - 0); - } - - mDirectories = - (SDIDirEntry*)((u32)mArcInfoBlock + mArcInfoBlock->node_offset); - mFileEntries = (SDIFileEntry*)((u32)mArcInfoBlock + - mArcInfoBlock->file_entry_offset); - mStrTable = (const char*)((u32)mArcInfoBlock + - mArcInfoBlock->string_table_offset); - _68 = arcHeader->header_length + arcHeader->file_data_offset; - } - break; - - case JKRCOMPRESSION_YAY0: - u32 alignedSize = ALIGN_NEXT(mDvdFile->getFileSize(), 32); - alignment = ((mMountDirection == 1) ? 32 : -32); - u8* buf = (u8*)JKRAllocFromSysHeap(alignedSize, -alignment); - - if (buf == nullptr) { + return 0; + } + SArcHeader* arcHeader = + (SArcHeader*)JKRAllocFromSysHeap(sizeof(SArcHeader), -32); // NOTE: unconfirmed if this struct is used + if (arcHeader == nullptr) { mMountMode = 0; - } - else { - JKRDvdToMainRam(entryNum, buf, EXPAND_SWITCH_NONE, alignedSize, - nullptr, JKRDvdRipper::ALLOC_DIR_TOP, 0, nullptr); - u32 expandSize = ALIGN_NEXT(JKRDecompExpandSize(buf), 32); - u8* mem = (u8*)JKRAllocFromHeap(mHeap, expandSize, -alignment); + } else { + int alignment; - if (mem == nullptr) { - mMountMode = 0; + JKRDvdToMainRam(entryNum, (u8*)arcHeader, EXPAND_SWITCH_DECOMPRESS, 32, nullptr, JKRDvdRipper::ALLOC_DIR_TOP, 0, + &mCompression); + + mSizeOfMemPart = arcHeader->_14; + mSizeOfAramPart = arcHeader->_18; + JUT_ASSERT((mSizeOfMemPart & 0x1f) == 0); + JUT_ASSERT((mSizeOfAramPart & 0x1f) == 0); + + switch (mCompression) { + case JKRCOMPRESSION_NONE: + case JKRCOMPRESSION_YAZ0: + alignment = mMountDirection == 1 ? 32 : -32; + mArcInfoBlock = + (SArcDataInfo*)JKRAllocFromHeap(mHeap, arcHeader->file_data_offset + mSizeOfMemPart, alignment); + if (mArcInfoBlock == nullptr) { + mMountMode = 0; + } else { + JKRDvdToMainRam(entryNum, (u8*)mArcInfoBlock, EXPAND_SWITCH_DECOMPRESS, + (u32)arcHeader->file_data_offset + mSizeOfMemPart, nullptr, + JKRDvdRipper::ALLOC_DIR_TOP, 0x20, nullptr); + _60 = (u32)mArcInfoBlock + arcHeader->file_data_offset; + + if (mSizeOfAramPart != 0) { + mAramPart = JKRAllocFromAram(mSizeOfAramPart, JKRAramHeap::Head); + if (mAramPart == nullptr) { + mMountMode = 0; + break; + } + + JKRDvdToAram(entryNum, mAramPart->getAddress(), EXPAND_SWITCH_DECOMPRESS, + arcHeader->header_length + arcHeader->file_data_offset + mSizeOfMemPart, 0); + } + + mDirectories = (SDIDirEntry*)((u32)mArcInfoBlock + mArcInfoBlock->node_offset); + mFileEntries = (SDIFileEntry*)((u32)mArcInfoBlock + mArcInfoBlock->file_entry_offset); + mStrTable = (const char*)((u32)mArcInfoBlock + mArcInfoBlock->string_table_offset); + _68 = arcHeader->header_length + arcHeader->file_data_offset; + } + break; + + case JKRCOMPRESSION_YAY0: + u32 alignedSize = ALIGN_NEXT(mDvdFile->getFileSize(), 32); + alignment = ((mMountDirection == 1) ? 32 : -32); + u8* buf = (u8*)JKRAllocFromSysHeap(alignedSize, -alignment); + + if (buf == nullptr) { + mMountMode = 0; + } else { + JKRDvdToMainRam(entryNum, buf, EXPAND_SWITCH_NONE, alignedSize, nullptr, + JKRDvdRipper::ALLOC_DIR_TOP, 0, nullptr); + u32 expandSize = ALIGN_NEXT(JKRDecompExpandSize(buf), 32); + u8* mem = (u8*)JKRAllocFromHeap(mHeap, expandSize, -alignment); + + if (mem == nullptr) { + mMountMode = 0; + } else { + arcHeader = (SArcHeader*)mem; + JKRDecompress((u8*)buf, (u8*)mem, expandSize, 0); + JKRFreeToSysHeap(buf); + + mArcInfoBlock = (SArcDataInfo*)JKRAllocFromHeap( + mHeap, arcHeader->file_data_offset + mSizeOfMemPart, alignment); + if (mArcInfoBlock == nullptr) { + mMountMode = 0; + } else { + // arcHeader + 1 should lead to 0x20, which is the data after the + // header + JKRHeap::copyMemory((u8*)mArcInfoBlock, arcHeader + 1, + (arcHeader->file_data_offset + mSizeOfMemPart)); + _60 = (u32)mArcInfoBlock + arcHeader->file_data_offset; + if (mSizeOfAramPart != 0) { + mAramPart = JKRAllocFromAram(mSizeOfAramPart, JKRAramHeap::Head); + if (mAramPart == nullptr) { + mMountMode = 0; + } else { + JKRMainRamToAram((u8*)mem + arcHeader->header_length + arcHeader->file_data_offset + + mSizeOfMemPart, + mAramPart->getAddress(), mSizeOfAramPart, EXPAND_SWITCH_DEFAULT, 0, + nullptr, -1, nullptr); + } + } + } + } + } + mDirectories = (SDIDirEntry*)((u32)mArcInfoBlock + mArcInfoBlock->node_offset); + mFileEntries = (SDIFileEntry*)((u32)mArcInfoBlock + mArcInfoBlock->file_entry_offset); + mStrTable = (const char*)((u32)mArcInfoBlock + mArcInfoBlock->string_table_offset); + _68 = arcHeader->header_length + arcHeader->file_data_offset; + break; } - else { - arcHeader = (SArcHeader*)mem; - JKRDecompress((u8*)buf, (u8*)mem, expandSize, 0); - JKRFreeToSysHeap(buf); + } - mArcInfoBlock = (SArcDataInfo*)JKRAllocFromHeap( - mHeap, arcHeader->file_data_offset + mSizeOfMemPart, alignment); - if (mArcInfoBlock == nullptr) { - mMountMode = 0; - } - else { - // arcHeader + 1 should lead to 0x20, which is the data after the - // header - JKRHeap::copyMemory( - (u8*)mArcInfoBlock, arcHeader + 1, - (arcHeader->file_data_offset + mSizeOfMemPart)); - _60 = (u32)mArcInfoBlock + arcHeader->file_data_offset; - if (mSizeOfAramPart != 0) { - mAramPart = - JKRAllocFromAram(mSizeOfAramPart, JKRAramHeap::Head); - if (mAramPart == nullptr) { - mMountMode = 0; - } - else { - JKRMainRamToAram( - (u8*)mem + arcHeader->header_length + - arcHeader->file_data_offset + mSizeOfMemPart, - mAramPart->getAddress(), mSizeOfAramPart, - EXPAND_SWITCH_DEFAULT, 0, nullptr, -1, nullptr); - } - } - } + if (arcHeader) { + JKRFreeToHeap(mHeap, arcHeader); + } + if (mMountMode == 0) { + JREPORTF(0, ":::[%s: %d] Cannot alloc memory in mounting CompArchive\n", __FILE__, 567); // Macro? + if (mDvdFile) { + delete mDvdFile; + mDvdFile = nullptr; } - } - mDirectories = - (SDIDirEntry*)((u32)mArcInfoBlock + mArcInfoBlock->node_offset); - mFileEntries = (SDIFileEntry*)((u32)mArcInfoBlock + - mArcInfoBlock->file_entry_offset); - mStrTable = (const char*)((u32)mArcInfoBlock + - mArcInfoBlock->string_table_offset); - _68 = arcHeader->header_length + arcHeader->file_data_offset; - break; } - } - - if (arcHeader) { - JKRFreeToHeap(mHeap, arcHeader); - } - if (mMountMode == 0) { - JREPORTF(0, ":::[%s: %d] Cannot alloc memory in mounting CompArchive\n", - __FILE__, 567); // Macro? - if (mDvdFile) { - delete mDvdFile; - mDvdFile = nullptr; - } - } - return mMountMode != 0; + return mMountMode != 0; } void* JKRCompArchive::fetchResource(SDIFileEntry* fileEntry, u32* pSize) { - JUT_ASSERT(isMounted()); + JUT_ASSERT(isMounted()); - u32 ptrSize; + u32 ptrSize; - if (fileEntry->mData == nullptr) { - u32 flag = fileEntry->mFlag >> 0x18; - if (flag & 0x10) { - fileEntry->mData = (void*)(_60 + fileEntry->mDataOffset); - if (pSize) *pSize = fileEntry->mSize; + if (fileEntry->mData == nullptr) { + u32 flag = fileEntry->mFlag >> 0x18; + if (flag & 0x10) { + fileEntry->mData = (void*)(_60 + fileEntry->mDataOffset); + if (pSize) + *pSize = fileEntry->mSize; + } else if (flag & 0x20) { + u32 address = mAramPart->getAddress(); + int compression = JKRConvertAttrToCompressionType(fileEntry->mFlag >> 0x18); + + u8* data; + u32 size = JKRAramArchive::fetchResource_subroutine(fileEntry->mDataOffset + address - mSizeOfMemPart, + fileEntry->mSize, mHeap, compression, &data); + + if (pSize) + *pSize = size; + + fileEntry->mData = data; + + } else if (flag & 0x40) { + int compression = JKRConvertAttrToCompressionType(fileEntry->mFlag >> 0x18); + + u8* data; + u32 size = JKRDvdArchive::fetchResource_subroutine( + mEntryNum, _68 + fileEntry->mDataOffset, fileEntry->mSize, mHeap, compression, mCompression, &data); + + if (pSize) + *pSize = size; + + fileEntry->mData = data; + } + } else if (pSize) { + *pSize = fileEntry->mSize; } - else if (flag & 0x20) { - u32 address = mAramPart->getAddress(); - int compression = - JKRConvertAttrToCompressionType(fileEntry->mFlag >> 0x18); - - u8* data; - u32 size = JKRAramArchive::fetchResource_subroutine( - fileEntry->mDataOffset + address - mSizeOfMemPart, fileEntry->mSize, - mHeap, compression, &data); - - if (pSize) *pSize = size; - - fileEntry->mData = data; - - } - else if (flag & 0x40) { - int compression = - JKRConvertAttrToCompressionType(fileEntry->mFlag >> 0x18); - - u8* data; - u32 size = JKRDvdArchive::fetchResource_subroutine( - mEntryNum, _68 + fileEntry->mDataOffset, fileEntry->mSize, mHeap, - compression, mCompression, &data); - - if (pSize) *pSize = size; - - fileEntry->mData = data; - } - } - else if (pSize) { - *pSize = fileEntry->mSize; - } - return fileEntry->mData; + return fileEntry->mData; } -void* JKRCompArchive::fetchResource(void* data, u32 compressedSize, - SDIFileEntry* fileEntry, u32* pSize, - JKRExpandSwitch expandSwitch) { -// u32 size = 0; - JUT_ASSERT(isMounted()); +void* JKRCompArchive::fetchResource(void* data, u32 compressedSize, SDIFileEntry* fileEntry, u32* pSize, + JKRExpandSwitch expandSwitch) { + // u32 size = 0; + JUT_ASSERT(isMounted()); - u32 size = ALIGN_NEXT(fileEntry->mSize, 32); - u32 expandSize = 0; + u32 size = ALIGN_NEXT(fileEntry->mSize, 32); + u32 expandSize = 0; - if (size == 0) JPANIC(651, ":::bad resource size. size = 0\n"); + if (size == 0) + JPANIC(651, ":::bad resource size. size = 0\n"); - if (fileEntry->mData) { - if (size > (compressedSize & ~31)) { - size = (compressedSize & ~31); + if (fileEntry->mData) { + if (size > (compressedSize & ~31)) { + size = (compressedSize & ~31); + } + + JKRHeap::copyMemory(data, fileEntry->mData, size); + expandSize = size; + } else { + u32 fileFlag = fileEntry->mFlag >> 0x18; + int compression = JKRConvertAttrToCompressionType(fileFlag); + if (expandSwitch != EXPAND_SWITCH_DECOMPRESS) + compression = 0; + + if (fileFlag & 0x10) { + if (size > (compressedSize & ~31)) { + size = (compressedSize & ~31); + } + + if (FLAG_ON(fileFlag, 4)) { + JKRHeap::copyMemory(data, (void*)(_60 + fileEntry->mDataOffset), size); + } else { + u8* header = (u8*)(_60 + fileEntry->mDataOffset); + expandSize = JKRDecompExpandSize(header); + expandSize = (expandSize > compressedSize) ? compressedSize : expandSize; + JKRDecompress(header, (u8*)data, expandSize, 0); + } + + expandSize = JKRMemArchive::fetchResource_subroutine((u8*)(_60 + fileEntry->mDataOffset), size, (u8*)data, + compressedSize, compression); + } else if (fileFlag & 0x20) { + expandSize = JKRAramArchive::fetchResource_subroutine(fileEntry->mDataOffset + mAramPart->getAddress() - + mSizeOfMemPart, + size, (u8*)data, compressedSize, compression); + } else if (fileFlag & 0x40) { + expandSize = JKRDvdArchive::fetchResource_subroutine(mEntryNum, _68 + fileEntry->mDataOffset, size, + (u8*)data, compressedSize, compression, mCompression); + } else { + JPANIC(731, ":::CompArchive: bad mode."); + } } - JKRHeap::copyMemory(data, fileEntry->mData, size); - expandSize = size; - } - else { - u32 fileFlag = fileEntry->mFlag >> 0x18; - int compression = JKRConvertAttrToCompressionType(fileFlag); - if (expandSwitch != EXPAND_SWITCH_DECOMPRESS) compression = 0; - - if (fileFlag & 0x10) { - if (size > (compressedSize & ~31)) { - size = (compressedSize & ~31); - } - - if (FLAG_ON(fileFlag, 4)) { - JKRHeap::copyMemory(data, (void*)(_60 + fileEntry->mDataOffset), size); - } - else { - u8* header = (u8*)(_60 + fileEntry->mDataOffset); - expandSize = JKRDecompExpandSize(header); - expandSize = - (expandSize > compressedSize) ? compressedSize : expandSize; - JKRDecompress(header, (u8*)data, expandSize, 0); - } - - expandSize = JKRMemArchive::fetchResource_subroutine( - (u8*)(_60 + fileEntry->mDataOffset), size, (u8*)data, - compressedSize, compression); + if (pSize) { + *pSize = expandSize; } - else if (fileFlag & 0x20) { - expandSize = JKRAramArchive::fetchResource_subroutine( - fileEntry->mDataOffset + mAramPart->getAddress() - mSizeOfMemPart, - size, (u8*)data, compressedSize, compression); - } - else if (fileFlag & 0x40) { - expandSize = JKRDvdArchive::fetchResource_subroutine( - mEntryNum, _68 + fileEntry->mDataOffset, size, (u8*)data, - compressedSize, compression, mCompression); - } - else { - JPANIC(731, ":::CompArchive: bad mode."); - } - } - - if (pSize) { - *pSize = expandSize; - } - return data; + return data; } void JKRCompArchive::removeResourceAll() { - if (mArcInfoBlock && mMountMode != MOUNT_MEM) { - SDIFileEntry* fileEntry = mFileEntries; - for (int i = 0; i < mArcInfoBlock->num_file_entries; i++) { - u32 flag = fileEntry->mFlag >> 0x18; - if (fileEntry->mData) { - if ((flag & 0x10) == 0) { - JKRFreeToHeap(mHeap, fileEntry->mData); - } + if (mArcInfoBlock && mMountMode != MOUNT_MEM) { + SDIFileEntry* fileEntry = mFileEntries; + for (int i = 0; i < mArcInfoBlock->num_file_entries; i++) { + u32 flag = fileEntry->mFlag >> 0x18; + if (fileEntry->mData) { + if ((flag & 0x10) == 0) { + JKRFreeToHeap(mHeap, fileEntry->mData); + } - fileEntry->mData = nullptr; - } + fileEntry->mData = nullptr; + } + } } - } } bool JKRCompArchive::removeResource(void* resource) { - SDIFileEntry* fileEntry = findPtrResource(resource); - if (!fileEntry) return false; + SDIFileEntry* fileEntry = findPtrResource(resource); + if (!fileEntry) + return false; - if (((fileEntry->mFlag >> 0x18) & 0x10) == 0) { - JKRFreeToHeap(mHeap, resource); - } + if (((fileEntry->mFlag >> 0x18) & 0x10) == 0) { + JKRFreeToHeap(mHeap, resource); + } - fileEntry->mData = nullptr; - return true; + fileEntry->mData = nullptr; + return true; } diff --git a/src/static/JSystem/JKernel/JKRDecomp.cpp b/src/static/JSystem/JKernel/JKRDecomp.cpp index 9f645815..ae17d9b3 100644 --- a/src/static/JSystem/JKernel/JKRDecomp.cpp +++ b/src/static/JSystem/JKernel/JKRDecomp.cpp @@ -11,281 +11,266 @@ OSMessageQueue JKRDecomp::sMessageQueue = { 0 }; JKRDecomp* JKRDecomp::sDecompObject; JKRDecomp* JKRDecomp::create(s32 decompPriority) { - if (JKRDecomp::sDecompObject == nullptr) { - JKRDecomp::sDecompObject = - new (JKRGetSystemHeap(), 0) JKRDecomp(decompPriority); - } + if (JKRDecomp::sDecompObject == nullptr) { + JKRDecomp::sDecompObject = new (JKRGetSystemHeap(), 0) JKRDecomp(decompPriority); + } - return JKRDecomp::sDecompObject; + return JKRDecomp::sDecompObject; } -JKRDecomp::JKRDecomp(s32 priority) - : JKRThread(JKRDECOMP_STACK_SIZE, JKRDECOMP_THREAD_MSG_BUF_COUNT, - priority) { - OSResumeThread(this->mThreadRecord); +JKRDecomp::JKRDecomp(s32 priority) : JKRThread(JKRDECOMP_STACK_SIZE, JKRDECOMP_THREAD_MSG_BUF_COUNT, priority) { + OSResumeThread(this->mThreadRecord); } -JKRDecomp::~JKRDecomp() {} +JKRDecomp::~JKRDecomp() { +} void* JKRDecomp::run() { - OSMessage recMesg; - JKRDecompCommand* cmd; - OSInitMessageQueue(&JKRDecomp::sMessageQueue, JKRDecomp::sMessageBuffer, - JKRDECOMP_MSG_BUF_COUNT); + OSMessage recMesg; + JKRDecompCommand* cmd; + OSInitMessageQueue(&JKRDecomp::sMessageQueue, JKRDecomp::sMessageBuffer, JKRDECOMP_MSG_BUF_COUNT); - while (true) { while (true) { - while (true) { - OSReceiveMessage(&JKRDecomp::sMessageQueue, &recMesg, OS_MESSAGE_BLOCK); - cmd = static_cast(recMesg); - JKRDecomp::decode(cmd->mSrcBuffer, cmd->mDstBuffer, cmd->mSrcLength, - cmd->mSkipCount); + while (true) { + while (true) { + OSReceiveMessage(&JKRDecomp::sMessageQueue, &recMesg, OS_MESSAGE_BLOCK); + cmd = static_cast(recMesg); + JKRDecomp::decode(cmd->mSrcBuffer, cmd->mDstBuffer, cmd->mSrcLength, cmd->mSkipCount); - if (cmd->transferType == JKRDecompCommand::MRAM) { - break; + if (cmd->transferType == JKRDecompCommand::MRAM) { + break; + } + + if (cmd->transferType == JKRDecompCommand::ARAM) { + JKRAramPcs_SendCommand(cmd->mAMCommand); + } + } + + if (cmd->mCallback == nullptr) { + break; + } + + cmd->mCallback((u32)cmd); } - if (cmd->transferType == JKRDecompCommand::ARAM) { - JKRAramPcs_SendCommand(cmd->mAMCommand); + if (cmd->pMesgQueue1C != nullptr) { + OSSendMessage(cmd->pMesgQueue1C, (OSMessage)1, OS_MESSAGE_NOBLOCK); + } else { + OSSendMessage(&cmd->mMesgQueue, (OSMessage)1, OS_MESSAGE_NOBLOCK); } - } - - if (cmd->mCallback == nullptr) { - break; - } - - cmd->mCallback((u32)cmd); } - - if (cmd->pMesgQueue1C != nullptr) { - OSSendMessage(cmd->pMesgQueue1C, (OSMessage)1, OS_MESSAGE_NOBLOCK); - } - else { - OSSendMessage(&cmd->mMesgQueue, (OSMessage)1, OS_MESSAGE_NOBLOCK); - } - } } -JKRDecompCommand* JKRDecomp::prepareCommand(u8* srcBuffer, u8* dstBuffer, - u32 srcLength, u32 skipCount, - DecompCallback* callback) { - JKRDecompCommand* cmd = new (JKRGetSystemHeap(), -4) JKRDecompCommand(); +JKRDecompCommand* JKRDecomp::prepareCommand(u8* srcBuffer, u8* dstBuffer, u32 srcLength, u32 skipCount, + DecompCallback* callback) { + JKRDecompCommand* cmd = new (JKRGetSystemHeap(), -4) JKRDecompCommand(); - cmd->mSrcBuffer = srcBuffer; - cmd->mDstBuffer = dstBuffer; - cmd->mSrcLength = srcLength; - cmd->mSkipCount = skipCount; - cmd->mCallback = callback; + cmd->mSrcBuffer = srcBuffer; + cmd->mDstBuffer = dstBuffer; + cmd->mSrcLength = srcLength; + cmd->mSkipCount = skipCount; + cmd->mCallback = callback; - return cmd; + return cmd; } BOOL JKRDecomp::sendCommand(JKRDecompCommand* cmd) { - BOOL res = OSSendMessage(&JKRDecomp::sMessageQueue, (OSMessage)cmd, - OS_MESSAGE_BLOCK); + BOOL res = OSSendMessage(&JKRDecomp::sMessageQueue, (OSMessage)cmd, OS_MESSAGE_BLOCK); #ifdef JSYSTEM_DEBUG - if (res == FALSE) { - JPANIC(142, "Decomp MesgBuf FULL!"); - } + if (res == FALSE) { + JPANIC(142, "Decomp MesgBuf FULL!"); + } #endif - return res; + return res; } -JKRDecompCommand* JKRDecomp::orderAsync(u8* srcBuffer, u8* dstBuffer, - u32 srcLength, u32 skipCount, - DecompCallback* callback) { - JKRDecompCommand* cmd = JKRDecomp::prepareCommand( - srcBuffer, dstBuffer, srcLength, skipCount, callback); - JKRDecomp::sendCommand(cmd); - return cmd; +JKRDecompCommand* JKRDecomp::orderAsync(u8* srcBuffer, u8* dstBuffer, u32 srcLength, u32 skipCount, + DecompCallback* callback) { + JKRDecompCommand* cmd = JKRDecomp::prepareCommand(srcBuffer, dstBuffer, srcLength, skipCount, callback); + JKRDecomp::sendCommand(cmd); + return cmd; } bool JKRDecomp::sync(JKRDecompCommand* cmd, BOOL noBlock) { - OSMessage msg; + OSMessage msg; - if (!noBlock) { - OSReceiveMessage(&cmd->mMesgQueue, &msg, OS_MESSAGE_BLOCK); - return true; - } - else { - return OSReceiveMessage(&cmd->mMesgQueue, &msg, OS_MESSAGE_NOBLOCK) != - FALSE; - } + if (!noBlock) { + OSReceiveMessage(&cmd->mMesgQueue, &msg, OS_MESSAGE_BLOCK); + return true; + } else { + return OSReceiveMessage(&cmd->mMesgQueue, &msg, OS_MESSAGE_NOBLOCK) != FALSE; + } } -bool JKRDecomp::orderSync(u8* srcBuffer, u8* dstBuffer, u32 srcLength, - u32 skipCount) { - JKRDecompCommand* cmd = JKRDecomp::orderAsync(srcBuffer, dstBuffer, srcLength, - skipCount, nullptr); - bool res = JKRDecomp::sync(cmd, FALSE); - delete cmd; - return res; +bool JKRDecomp::orderSync(u8* srcBuffer, u8* dstBuffer, u32 srcLength, u32 skipCount) { + JKRDecompCommand* cmd = JKRDecomp::orderAsync(srcBuffer, dstBuffer, srcLength, skipCount, nullptr); + bool res = JKRDecomp::sync(cmd, FALSE); + delete cmd; + return res; } -void JKRDecomp::decode(u8* srcBuffer, u8* dstBuffer, u32 srcLength, - u32 skipCount) { - CompressionMode mode = JKRDecomp::checkCompressed(srcBuffer); - if (mode == SZP) { - JKRDecomp::decodeSZP(srcBuffer, dstBuffer, srcLength, skipCount); - } - else if (mode == SZS) { - JKRDecomp::decodeSZS(srcBuffer, dstBuffer, srcLength, skipCount); - } +void JKRDecomp::decode(u8* srcBuffer, u8* dstBuffer, u32 srcLength, u32 skipCount) { + CompressionMode mode = JKRDecomp::checkCompressed(srcBuffer); + if (mode == SZP) { + JKRDecomp::decodeSZP(srcBuffer, dstBuffer, srcLength, skipCount); + } else if (mode == SZS) { + JKRDecomp::decodeSZS(srcBuffer, dstBuffer, srcLength, skipCount); + } } void JKRDecomp::decodeSZP(u8* src, u8* dst, u32 srcLength, u32 skipCount) { - int srcChunkOffset; - int count; - int dstOffset; - u32 length; - int linkInfo; - int offset; - int i; + int srcChunkOffset; + int count; + int dstOffset; + u32 length; + int linkInfo; + int offset; + int i; - int decodedSize = JKRDECOMP_READU32BE(src, 4); - int linkTableOffset = JKRDECOMP_READU32BE(src, 8); - int srcDataOffset = JKRDECOMP_READU32BE(src, 12); + int decodedSize = JKRDECOMP_READU32BE(src, 4); + int linkTableOffset = JKRDECOMP_READU32BE(src, 8); + int srcDataOffset = JKRDECOMP_READU32BE(src, 12); - dstOffset = 0; - u32 counter = - 0; // curently counter gets assembled before the READ_U32 operations - srcChunkOffset = 16; + dstOffset = 0; + u32 counter = 0; // curently counter gets assembled before the READ_U32 operations + srcChunkOffset = 16; - u32 chunkBits; - if (srcLength == 0) return; - if (skipCount > decodedSize) return; + u32 chunkBits; + if (srcLength == 0) + return; + if (skipCount > decodedSize) + return; - length = srcLength; - do { - if (counter == 0) { - chunkBits = JKRDECOMP_READU32BE(src, srcChunkOffset); - srcChunkOffset += sizeof(u32); - counter = sizeof(u32) * 8; - } - - if (chunkBits & 0x80000000) { - if (skipCount == 0) { - dst[dstOffset] = src[srcDataOffset]; - length--; - if (length == 0) return; - } - else { - skipCount--; - } - dstOffset++; - srcDataOffset++; - } - else { - linkInfo = src[linkTableOffset] << 8 | src[linkTableOffset + 1]; - linkTableOffset += sizeof(u16); - - offset = dstOffset - (linkInfo & 0xFFF); - count = (linkInfo >> 12); - if (count == 0) { - count = (u32)src[srcDataOffset++] + 0x12; - } - else - count += 2; - - if ((int)count > decodedSize - dstOffset) count = decodedSize - dstOffset; - - for (i = 0; i < (int)count; i++, dstOffset++, offset++) { - if (skipCount == 0) { - dst[dstOffset] = dst[offset - 1]; - length--; - if (length == 0) return; + length = srcLength; + do { + if (counter == 0) { + chunkBits = JKRDECOMP_READU32BE(src, srcChunkOffset); + srcChunkOffset += sizeof(u32); + counter = sizeof(u32) * 8; } - else - skipCount--; - } - } - chunkBits <<= 1; - counter--; - } while (dstOffset < decodedSize); + if (chunkBits & 0x80000000) { + if (skipCount == 0) { + dst[dstOffset] = src[srcDataOffset]; + length--; + if (length == 0) + return; + } else { + skipCount--; + } + dstOffset++; + srcDataOffset++; + } else { + linkInfo = src[linkTableOffset] << 8 | src[linkTableOffset + 1]; + linkTableOffset += sizeof(u16); + + offset = dstOffset - (linkInfo & 0xFFF); + count = (linkInfo >> 12); + if (count == 0) { + count = (u32)src[srcDataOffset++] + 0x12; + } else + count += 2; + + if ((int)count > decodedSize - dstOffset) + count = decodedSize - dstOffset; + + for (i = 0; i < (int)count; i++, dstOffset++, offset++) { + if (skipCount == 0) { + dst[dstOffset] = dst[offset - 1]; + length--; + if (length == 0) + return; + } else + skipCount--; + } + } + + chunkBits <<= 1; + counter--; + } while (dstOffset < decodedSize); } -void JKRDecomp::decodeSZS(u8* src_buffer, u8* dst_buffer, u32 srcSize, - u32 skipCount) { - u8* decompEnd = dst_buffer + *(u32*)(src_buffer + 4) - skipCount; - u8* copyStart; - s32 copyByteCount; - s32 chunkBitsLeft = 0; - s32 chunkBits; +void JKRDecomp::decodeSZS(u8* src_buffer, u8* dst_buffer, u32 srcSize, u32 skipCount) { + u8* decompEnd = dst_buffer + *(u32*)(src_buffer + 4) - skipCount; + u8* copyStart; + s32 copyByteCount; + s32 chunkBitsLeft = 0; + s32 chunkBits; - if (srcSize == 0) return; - if (skipCount > *(u32*)src_buffer) return; + if (srcSize == 0) + return; + if (skipCount > *(u32*)src_buffer) + return; - u8* curSrcPos = src_buffer + 0x10; - do { - if (chunkBitsLeft == 0) { - chunkBits = *curSrcPos++; - chunkBitsLeft = 8; - } - if ((chunkBits & 0x80) != 0) { - if (skipCount == 0) { - *dst_buffer = *curSrcPos; - srcSize--; - dst_buffer++; - if (srcSize == 0) return; - } - else { - skipCount--; - } - curSrcPos++; - } - else { - u8 curVal = *curSrcPos; - copyStart = dst_buffer - (curSrcPos[1] | (curVal & 0xF) << 8); - curSrcPos += 2; - if (curVal >> 4 == 0) { - copyByteCount = *curSrcPos + 0x12; - curSrcPos++; - } - else { - copyByteCount = (curVal >> 4) + 2; - } - do { - if (skipCount == 0) { - *dst_buffer = *(copyStart - 1); - srcSize--; - dst_buffer++; - if (srcSize == 0) return; + u8* curSrcPos = src_buffer + 0x10; + do { + if (chunkBitsLeft == 0) { + chunkBits = *curSrcPos++; + chunkBitsLeft = 8; } - else { - skipCount--; + if ((chunkBits & 0x80) != 0) { + if (skipCount == 0) { + *dst_buffer = *curSrcPos; + srcSize--; + dst_buffer++; + if (srcSize == 0) + return; + } else { + skipCount--; + } + curSrcPos++; + } else { + u8 curVal = *curSrcPos; + copyStart = dst_buffer - (curSrcPos[1] | (curVal & 0xF) << 8); + curSrcPos += 2; + if (curVal >> 4 == 0) { + copyByteCount = *curSrcPos + 0x12; + curSrcPos++; + } else { + copyByteCount = (curVal >> 4) + 2; + } + do { + if (skipCount == 0) { + *dst_buffer = *(copyStart - 1); + srcSize--; + dst_buffer++; + if (srcSize == 0) + return; + } else { + skipCount--; + } + copyByteCount--; + copyStart++; + } while (copyByteCount != 0); } - copyByteCount--; - copyStart++; - } while (copyByteCount != 0); - } - chunkBits <<= 1; - chunkBitsLeft--; - } while (dst_buffer != decompEnd); + chunkBits <<= 1; + chunkBitsLeft--; + } while (dst_buffer != decompEnd); } JKRDecomp::CompressionMode JKRDecomp::checkCompressed(u8* buf) { - if (buf[0] == 'Y' && buf[1] == 'a' && buf[3] == '0') { - if (buf[2] == 'y') { - return SZP; + if (buf[0] == 'Y' && buf[1] == 'a' && buf[3] == '0') { + if (buf[2] == 'y') { + return SZP; + } + + if (buf[2] == 'z') { + return SZS; + } } - if (buf[2] == 'z') { - return SZS; - } - } - - return NONE; + return NONE; } JKRDecompCommand::JKRDecompCommand() { - OSInitMessageQueue(&this->mMesgQueue, this->mMesgBuffer, 1); - this->mCallback = nullptr; - this->pMesgQueue1C = nullptr; - this->mCmd = this; - this->transferType = MRAM; + OSInitMessageQueue(&this->mMesgQueue, this->mMesgBuffer, 1); + this->mCallback = nullptr; + this->pMesgQueue1C = nullptr; + this->mCmd = this; + this->transferType = MRAM; } -JKRDecompCommand::~JKRDecompCommand() {} +JKRDecompCommand::~JKRDecompCommand() { +} diff --git a/src/static/JSystem/JKernel/JKRDisposer.cpp b/src/static/JSystem/JKernel/JKRDisposer.cpp index 970a1167..daf2739d 100644 --- a/src/static/JSystem/JKernel/JKRDisposer.cpp +++ b/src/static/JSystem/JKernel/JKRDisposer.cpp @@ -3,14 +3,14 @@ #include "JSystem/JKernel/JKRHeap.h" JKRDisposer::JKRDisposer() : mPointerLinks(this) { - this->mRootHeap = JKRHeap::findFromRoot(this); - if (this->mRootHeap != nullptr) { - this->mRootHeap->appendDisposer(this); - } + this->mRootHeap = JKRHeap::findFromRoot(this); + if (this->mRootHeap != nullptr) { + this->mRootHeap->appendDisposer(this); + } } JKRDisposer::~JKRDisposer() { - if (this->mRootHeap != nullptr) { - this->mRootHeap->removeDisposer(this); - } + if (this->mRootHeap != nullptr) { + this->mRootHeap->removeDisposer(this); + } } diff --git a/src/static/JSystem/JKernel/JKRDvdAramRipper.cpp b/src/static/JSystem/JKernel/JKRDvdAramRipper.cpp index 327d96b9..999e4cb9 100644 --- a/src/static/JSystem/JKernel/JKRDvdAramRipper.cpp +++ b/src/static/JSystem/JKernel/JKRDvdAramRipper.cpp @@ -14,193 +14,181 @@ JSUList JKRDvdAramRipper::sDvdAramAsyncList; bool JKRDvdAramRipper::errorRetry = true; int JKRDvdAramRipper::sSZSBufferSize = 0x400; -JKRAramBlock* JKRDvdAramRipper::loadToAram(s32 entrynum, u32 p2, - JKRExpandSwitch expSwitch, u32 p6, - u32 p7) { - JKRDvdFile dvdFile; - if (!dvdFile.open(entrynum)) - return nullptr; - else - return loadToAram(&dvdFile, p2, expSwitch, p6, p7); +JKRAramBlock* JKRDvdAramRipper::loadToAram(s32 entrynum, u32 p2, JKRExpandSwitch expSwitch, u32 p6, u32 p7) { + JKRDvdFile dvdFile; + if (!dvdFile.open(entrynum)) + return nullptr; + else + return loadToAram(&dvdFile, p2, expSwitch, p6, p7); } -JKRAramBlock* JKRDvdAramRipper::loadToAram(JKRDvdFile* dvdFile, u32 p1, - JKRExpandSwitch p2, u32 p3, u32 p4) { - JKRADCommand* command = loadToAram_Async(dvdFile, p1, p2, nullptr, p3, p4); - syncAram(command, 0); +JKRAramBlock* JKRDvdAramRipper::loadToAram(JKRDvdFile* dvdFile, u32 p1, JKRExpandSwitch p2, u32 p3, u32 p4) { + JKRADCommand* command = loadToAram_Async(dvdFile, p1, p2, nullptr, p3, p4); + syncAram(command, 0); - if (p1) { + if (p1) { + delete command; + return (JKRAramBlock*)-1; + } + + JKRAramBlock* result = command->mBlock; delete command; - return (JKRAramBlock*)-1; - } - - JKRAramBlock* result = command->mBlock; - delete command; - return result; + return result; } -JKRADCommand* JKRDvdAramRipper::loadToAram_Async(JKRDvdFile* dvdFile, u32 p1, - JKRExpandSwitch expSwitch, - JKRADCommand::LoadCallback cb, - u32 p4, u32 p5) { - JKRADCommand* command = new (JKRGetSystemHeap(), -4) JKRADCommand(); - command->mDvdFile = dvdFile; - command->_1C = p1; - command->mBlock = nullptr; - command->mExpandSwitch = expSwitch; - command->mCallBack = cb; +JKRADCommand* JKRDvdAramRipper::loadToAram_Async(JKRDvdFile* dvdFile, u32 p1, JKRExpandSwitch expSwitch, + JKRADCommand::LoadCallback cb, u32 p4, u32 p5) { + JKRADCommand* command = new (JKRGetSystemHeap(), -4) JKRADCommand(); + command->mDvdFile = dvdFile; + command->_1C = p1; + command->mBlock = nullptr; + command->mExpandSwitch = expSwitch; + command->mCallBack = cb; - command->_14 = p4; - command->_18 = p5; + command->_14 = p4; + command->_18 = p5; - if (!callCommand_Async(command)) { - delete command; - return nullptr; - } + if (!callCommand_Async(command)) { + delete command; + return nullptr; + } - return command; + return command; } JKRADCommand* JKRDvdAramRipper::callCommand_Async(JKRADCommand* command) { - bool isCmdTrdNull = true; - JKRDvdFile* dvdFile = command->mDvdFile; - int compression = JKRCOMPRESSION_NONE; - OSLockMutex(&dvdFile->mAramMutex); + bool isCmdTrdNull = true; + JKRDvdFile* dvdFile = command->mDvdFile; + int compression = JKRCOMPRESSION_NONE; + OSLockMutex(&dvdFile->mAramMutex); - s32 uncompressedSize; + s32 uncompressedSize; - if (dvdFile->mAramThread) { - isCmdTrdNull = false; - } - else { - dvdFile->mAramThread = OSGetCurrentThread(); - JSUFileInputStream* stream = - new (JKRGetSystemHeap(), -4) JSUFileInputStream(dvdFile); - dvdFile->mInputStream = stream; - u32 fileSize = dvdFile->getFileSize(); - if (command->_18 && fileSize > command->_18) { - fileSize = command->_18; - } - fileSize = ALIGN_NEXT(fileSize, 0x20); - if (command->mExpandSwitch == EXPAND_SWITCH_DECOMPRESS) { - u8 buffer[0x40]; - u8* bufPtr = (u8*)ALIGN_NEXT((u32)buffer, 0x20); - while (true) { - if (DVDReadPrio(dvdFile->getFileInfo(), bufPtr, 0x20, 0, 2) >= 0) { - break; + if (dvdFile->mAramThread) { + isCmdTrdNull = false; + } else { + dvdFile->mAramThread = OSGetCurrentThread(); + JSUFileInputStream* stream = new (JKRGetSystemHeap(), -4) JSUFileInputStream(dvdFile); + dvdFile->mInputStream = stream; + u32 fileSize = dvdFile->getFileSize(); + if (command->_18 && fileSize > command->_18) { + fileSize = command->_18; + } + fileSize = ALIGN_NEXT(fileSize, 0x20); + if (command->mExpandSwitch == EXPAND_SWITCH_DECOMPRESS) { + u8 buffer[0x40]; + u8* bufPtr = (u8*)ALIGN_NEXT((u32)buffer, 0x20); + while (true) { + if (DVDReadPrio(dvdFile->getFileInfo(), bufPtr, 0x20, 0, 2) >= 0) { + break; + } + + if (errorRetry == false) { + delete stream; + return nullptr; + } + + VIWaitForRetrace(); + } + + compression = JKRCheckCompressed(bufPtr); + u32 expSize = JKRDecompExpandSize(bufPtr); + uncompressedSize = expSize; + + if ((command->_18 != 0) && expSize > command->_18) { + uncompressedSize = command->_18; + } } - if (errorRetry == false) { - delete stream; - return nullptr; + if (compression == JKRCOMPRESSION_NONE) { + command->mExpandSwitch = EXPAND_SWITCH_DEFAULT; } - VIWaitForRetrace(); - } + if (command->mExpandSwitch == EXPAND_SWITCH_DECOMPRESS) { + if (command->_1C == 0 && command->mBlock == nullptr) { + command->mBlock = JKRAram::getAramHeap()->alloc(uncompressedSize, JKRAramHeap::Head); + if (command->mBlock) { + command->_1C = command->mBlock->mAddress; + } + dvdFile->mAramBlock = command->mBlock; + } - compression = JKRCheckCompressed(bufPtr); - u32 expSize = JKRDecompExpandSize(bufPtr); - uncompressedSize = expSize; + if (command->mBlock) { + command->_1C = command->mBlock->mAddress; + } - if ((command->_18 != 0) && expSize > command->_18) { - uncompressedSize = command->_18; - } - } + if (command->_1C == 0) { + dvdFile->mAramThread = nullptr; + return nullptr; + } + } else { + if (command->_1C == 0 && !command->mBlock) { + command->mBlock = JKRAram::getAramHeap()->alloc(fileSize, JKRAramHeap::Head); + } - if (compression == JKRCOMPRESSION_NONE) { - command->mExpandSwitch = EXPAND_SWITCH_DEFAULT; - } + if (command->mBlock) { + command->_1C = command->mBlock->mAddress; + } - if (command->mExpandSwitch == EXPAND_SWITCH_DECOMPRESS) { - if (command->_1C == 0 && command->mBlock == nullptr) { - command->mBlock = - JKRAram::getAramHeap()->alloc(uncompressedSize, JKRAramHeap::Head); - if (command->mBlock) { - command->_1C = command->mBlock->mAddress; + if (command->_1C == 0) { + dvdFile->mAramThread = nullptr; + return nullptr; + } } - dvdFile->mAramBlock = command->mBlock; - } - if (command->mBlock) { - command->_1C = command->mBlock->mAddress; - } + if (compression == 0) { + command->mStreamCommand = + JKRAramStream::write_StreamToAram_Async(stream, command->_1C, fileSize - command->_14, command->_14); + } else if (compression == JKRCOMPRESSION_YAY0) { + command->mStreamCommand = + JKRAramStream::write_StreamToAram_Async(stream, command->_1C, fileSize - command->_14, command->_14); + } else if (compression == JKRCOMPRESSION_YAZ0) { + command->mStreamCommand = nullptr; + JKRDecompressFromDVDToAram(command->mDvdFile, command->_1C, fileSize, uncompressedSize, command->_14, 0); + } - if (command->_1C == 0) { - dvdFile->mAramThread = nullptr; - return nullptr; - } - } - else { - if (command->_1C == 0 && !command->mBlock) { - command->mBlock = - JKRAram::getAramHeap()->alloc(fileSize, JKRAramHeap::Head); - } - - if (command->mBlock) { - command->_1C = command->mBlock->mAddress; - } - - if (command->_1C == 0) { - dvdFile->mAramThread = nullptr; - return nullptr; - } + if (!command->mCallBack) { + sDvdAramAsyncList.append(&command->mLink); + } else { + command->mCallBack((u32)command); + } } - if (compression == 0) { - command->mStreamCommand = JKRAramStream::write_StreamToAram_Async( - stream, command->_1C, fileSize - command->_14, command->_14); - } - else if (compression == JKRCOMPRESSION_YAY0) { - command->mStreamCommand = JKRAramStream::write_StreamToAram_Async( - stream, command->_1C, fileSize - command->_14, command->_14); - } - else if (compression == JKRCOMPRESSION_YAZ0) { - command->mStreamCommand = nullptr; - JKRDecompressFromDVDToAram(command->mDvdFile, command->_1C, fileSize, - uncompressedSize, command->_14, 0); - } - - if (!command->mCallBack) { - sDvdAramAsyncList.append(&command->mLink); - } - else { - command->mCallBack((u32)command); - } - } - - OSUnlockMutex(&dvdFile->mAramMutex); - return isCmdTrdNull == true ? command : nullptr; + OSUnlockMutex(&dvdFile->mAramMutex); + return isCmdTrdNull == true ? command : nullptr; } bool JKRDvdAramRipper::syncAram(JKRADCommand* command, int p1) { - JKRDvdFile* dvdFile = command->mDvdFile; - OSLockMutex(&dvdFile->mAramMutex); + JKRDvdFile* dvdFile = command->mDvdFile; + OSLockMutex(&dvdFile->mAramMutex); - if (command->mStreamCommand) { - JKRAramStreamCommand* var1 = - JKRAramStream::sync(command->mStreamCommand, p1); + if (command->mStreamCommand) { + JKRAramStreamCommand* var1 = JKRAramStream::sync(command->mStreamCommand, p1); - if (p1 != 0 && var1 == nullptr) { - OSUnlockMutex(&dvdFile->mAramMutex); - return false; + if (p1 != 0 && var1 == nullptr) { + OSUnlockMutex(&dvdFile->mAramMutex); + return false; + } } - } - sDvdAramAsyncList.remove(&command->mLink); - if (command->mStreamCommand) { - delete command->mStreamCommand; - } + sDvdAramAsyncList.remove(&command->mLink); + if (command->mStreamCommand) { + delete command->mStreamCommand; + } - delete dvdFile->mInputStream; - dvdFile->mAramThread = nullptr; - OSUnlockMutex(&dvdFile->mAramMutex); - return true; + delete dvdFile->mInputStream; + dvdFile->mAramThread = nullptr; + OSUnlockMutex(&dvdFile->mAramMutex); + return true; } -JKRADCommand::JKRADCommand() : mLink(this) { _44 = 0; } +JKRADCommand::JKRADCommand() : mLink(this) { + _44 = 0; +} JKRADCommand::~JKRADCommand() { - if (_44 == 1) delete mDvdFile; + if (_44 == 1) + delete mDvdFile; } static OSMutex decompMutex; @@ -228,175 +216,189 @@ static u8* firstSrcData(); static u8* nextSrcData(u8*); static u32 dmaBufferFlush(u32); -int JKRDecompressFromDVDToAram(JKRDvdFile* dvdFile, u32 address, u32 fileSize, - u32 _maxDest, u32 _fileOffset, u32 _srcOffset) { - int result = 0; - szpBuf = (u8*)JKRAllocFromSysHeap(SZP_BUFFERSIZE, 32); - JUT_ASSERT(szpBuf != 0); - szpEnd = szpBuf + SZP_BUFFERSIZE; +int JKRDecompressFromDVDToAram(JKRDvdFile* dvdFile, u32 address, u32 fileSize, u32 _maxDest, u32 _fileOffset, + u32 _srcOffset) { + int result = 0; + szpBuf = (u8*)JKRAllocFromSysHeap(SZP_BUFFERSIZE, 32); + JUT_ASSERT(szpBuf != 0); + szpEnd = szpBuf + SZP_BUFFERSIZE; - refBuf = (u8*)JKRAllocFromSysHeap(REF_BUFFERSIZE, 0); - JUT_ASSERT(refBuf != 0); - refEnd = refBuf + REF_BUFFERSIZE; - refCurrent = refBuf; + refBuf = (u8*)JKRAllocFromSysHeap(REF_BUFFERSIZE, 0); + JUT_ASSERT(refBuf != 0); + refEnd = refBuf + REF_BUFFERSIZE; + refCurrent = refBuf; - dmaBuf = (u8*)JKRAllocFromSysHeap(DMA_BUFFERSIZE, 32); - JUT_ASSERT(dmaBuf != 0); - dmaEnd = dmaBuf + DMA_BUFFERSIZE; - dmaCurrent = dmaBuf; + dmaBuf = (u8*)JKRAllocFromSysHeap(DMA_BUFFERSIZE, 32); + JUT_ASSERT(dmaBuf != 0); + dmaEnd = dmaBuf + DMA_BUFFERSIZE; + dmaCurrent = dmaBuf; - srcFile = dvdFile; - srcOffset = _srcOffset; - transLeft = fileSize - _srcOffset; - fileOffset = _fileOffset; - readCount = 0; - maxDest = _maxDest; + srcFile = dvdFile; + srcOffset = _srcOffset; + transLeft = fileSize - _srcOffset; + fileOffset = _fileOffset; + readCount = 0; + maxDest = _maxDest; - u8* first = firstSrcData(); - if (first) result = decompSZS_subroutine(first, address); + u8* first = firstSrcData(); + if (first) + result = decompSZS_subroutine(first, address); - JKRFree(szpBuf); - JKRFree(refBuf); - JKRFree(dmaBuf); + JKRFree(szpBuf); + JKRFree(refBuf); + JKRFree(dmaBuf); - return result; + return result; } int decompSZS_subroutine(u8* src, u32 dmaAddr) { - u32 endPtr; - u8* copySource; - s32 validBitCount = 0; - s32 currCodeByte = 0; - s32 numBytes; + u32 endPtr; + u8* copySource; + s32 validBitCount = 0; + s32 currCodeByte = 0; + s32 numBytes; - u32 dmaStart = dmaAddr; + u32 dmaStart = dmaAddr; - if (src[0] != 'Y' || src[1] != 'a' || src[2] != 'z' || src[3] != '0') - return -1; + if (src[0] != 'Y' || src[1] != 'a' || src[2] != 'z' || src[3] != '0') + return -1; - SYaz0Header* header = (SYaz0Header*)src; - endPtr = dmaAddr + (header->length - fileOffset); - if (endPtr > dmaAddr + maxDest) endPtr = dmaAddr + maxDest; + SYaz0Header* header = (SYaz0Header*)src; + endPtr = dmaAddr + (header->length - fileOffset); + if (endPtr > dmaAddr + maxDest) + endPtr = dmaAddr + maxDest; - src += 0x10; + src += 0x10; - do { - if (validBitCount == 0) { - if ((src > srcLimit) && transLeft) src = nextSrcData(src); + do { + if (validBitCount == 0) { + if ((src > srcLimit) && transLeft) + src = nextSrcData(src); - currCodeByte = *src++; - validBitCount = 8; - } - if (currCodeByte & 0x80) { - if (readCount >= fileOffset) { - dmaAddr++; - *dmaCurrent++ = *src; - if (dmaCurrent == dmaEnd) dmaStart += dmaBufferFlush(dmaStart); - - if (dmaAddr == endPtr) break; - } - *(refCurrent++) = *src; - if (refCurrent == refEnd) refCurrent = refBuf; - - src++; - - readCount++; - } - else { - int t0 = src[0]; - int t1 = src[1]; - copySource = refCurrent - (t1 | (t0 & 0x0f) << 8) - 1; - numBytes = t0 >> 4; - src += 2; - if (copySource < refBuf) copySource = copySource + (refEnd - refBuf); - - if (numBytes == 0) - numBytes = *src++ + 0x12; - else - numBytes += 2; - - do { - if (readCount >= fileOffset) { - dmaAddr++; - *(dmaCurrent++) = *copySource; - if (dmaCurrent == dmaEnd) dmaStart += dmaBufferFlush(dmaStart); - - if (dmaAddr == endPtr) break; + currCodeByte = *src++; + validBitCount = 8; } - *(refCurrent++) = *copySource; - if (refCurrent == refEnd) refCurrent = refBuf; + if (currCodeByte & 0x80) { + if (readCount >= fileOffset) { + dmaAddr++; + *dmaCurrent++ = *src; + if (dmaCurrent == dmaEnd) + dmaStart += dmaBufferFlush(dmaStart); - copySource++; + if (dmaAddr == endPtr) + break; + } + *(refCurrent++) = *src; + if (refCurrent == refEnd) + refCurrent = refBuf; - if (copySource == refEnd) copySource = refBuf; + src++; - readCount++; - numBytes--; - } while (numBytes != 0); - } - currCodeByte <<= 1; - validBitCount--; - } while (dmaAddr < endPtr); + readCount++; + } else { + int t0 = src[0]; + int t1 = src[1]; + copySource = refCurrent - (t1 | (t0 & 0x0f) << 8) - 1; + numBytes = t0 >> 4; + src += 2; + if (copySource < refBuf) + copySource = copySource + (refEnd - refBuf); - dmaBufferFlush(dmaStart); + if (numBytes == 0) + numBytes = *src++ + 0x12; + else + numBytes += 2; - return 0; + do { + if (readCount >= fileOffset) { + dmaAddr++; + *(dmaCurrent++) = *copySource; + if (dmaCurrent == dmaEnd) + dmaStart += dmaBufferFlush(dmaStart); + + if (dmaAddr == endPtr) + break; + } + *(refCurrent++) = *copySource; + if (refCurrent == refEnd) + refCurrent = refBuf; + + copySource++; + + if (copySource == refEnd) + copySource = refBuf; + + readCount++; + numBytes--; + } while (numBytes != 0); + } + currCodeByte <<= 1; + validBitCount--; + } while (dmaAddr < endPtr); + + dmaBufferFlush(dmaStart); + + return 0; } u8* firstSrcData() { - srcLimit = szpEnd - 0x19; - u8* buf = szpBuf; - u32 max = (szpEnd - szpBuf); - u32 transSize = MIN(transLeft, max); + srcLimit = szpEnd - 0x19; + u8* buf = szpBuf; + u32 max = (szpEnd - szpBuf); + u32 transSize = MIN(transLeft, max); - while (true) { - if (0 <= DVDReadPrio(srcFile->getFileInfo(), buf, transSize, 0, 2)) break; - if (!JKRDvdAramRipper::isErrorRetry()) return nullptr; - VIWaitForRetrace(); - } - srcOffset += transSize; - transLeft -= transSize; - return buf; + while (true) { + if (0 <= DVDReadPrio(srcFile->getFileInfo(), buf, transSize, 0, 2)) + break; + if (!JKRDvdAramRipper::isErrorRetry()) + return nullptr; + VIWaitForRetrace(); + } + srcOffset += transSize; + transLeft -= transSize; + return buf; } u8* nextSrcData(u8* src) { - u32 limit = szpEnd - src; - u8* buf; - if (IS_NOT_ALIGNED(limit, 0x20)) - buf = szpBuf + 0x20 - (limit & (0x20 - 1)); - else - buf = szpBuf; + u32 limit = szpEnd - src; + u8* buf; + if (IS_NOT_ALIGNED(limit, 0x20)) + buf = szpBuf + 0x20 - (limit & (0x20 - 1)); + else + buf = szpBuf; - memcpy(buf, src, limit); - u32 transSize = (u32)(szpEnd - (buf + limit)); - if (transSize > transLeft) transSize = transLeft; + memcpy(buf, src, limit); + u32 transSize = (u32)(szpEnd - (buf + limit)); + if (transSize > transLeft) + transSize = transLeft; - JUT_ASSERT(transSize > 0); - while (true) { - int result = DVDReadPrio(srcFile->getFileInfo(), (buf + limit), transSize, - srcOffset, 2); - if (result >= 0) break; + JUT_ASSERT(transSize > 0); + while (true) { + int result = DVDReadPrio(srcFile->getFileInfo(), (buf + limit), transSize, srcOffset, 2); + if (result >= 0) + break; - if (!JKRDvdAramRipper::isErrorRetry()) return nullptr; + if (!JKRDvdAramRipper::isErrorRetry()) + return nullptr; - VIWaitForRetrace(); - } + VIWaitForRetrace(); + } - srcOffset += transSize; - transLeft -= transSize; - if (transLeft == 0) srcLimit = transSize + (buf + limit); + srcOffset += transSize; + transLeft -= transSize; + if (transLeft == 0) + srcLimit = transSize + (buf + limit); - return buf; + return buf; } u32 dmaBufferFlush(u32 src) { - if (dmaCurrent == dmaBuf) { - return 0; - } - else { - u32 length = ALIGN_NEXT((u32)(dmaCurrent - dmaBuf), 32); - JKRAramPiece::orderSync(0, (u32)dmaBuf, src, length, nullptr); - dmaCurrent = dmaBuf; - return length; - } + if (dmaCurrent == dmaBuf) { + return 0; + } else { + u32 length = ALIGN_NEXT((u32)(dmaCurrent - dmaBuf), 32); + JKRAramPiece::orderSync(0, (u32)dmaBuf, src, length, nullptr); + dmaCurrent = dmaBuf; + return length; + } } diff --git a/src/static/JSystem/JKernel/JKRDvdArchive.cpp b/src/static/JSystem/JKernel/JKRDvdArchive.cpp index 86c67571..b825b394 100644 --- a/src/static/JSystem/JKernel/JKRDvdArchive.cpp +++ b/src/static/JSystem/JKernel/JKRDvdArchive.cpp @@ -8,18 +8,14 @@ #include "JSystem/JSystem.h" #include "JSystem/JUtility/JUTAssertion.h" -JKRDvdArchive::JKRDvdArchive() : JKRArchive() {} +JKRDvdArchive::JKRDvdArchive() : JKRArchive() { +} -JKRDvdArchive::JKRDvdArchive(s32 entryNum, EMountDirection mountDirection) - : JKRArchive(entryNum, MOUNT_DVD) -{ +JKRDvdArchive::JKRDvdArchive(s32 entryNum, EMountDirection mountDirection) : JKRArchive(entryNum, MOUNT_DVD) { mMountDirection = mountDirection; - if (!open(entryNum)) - { + if (!open(entryNum)) { return; - } - else - { + } else { mVolumeType = 'RARC'; mVolumeName = &mStrTable[mDirectories->mOffset]; sVolumeList.prepend(&mFileLoaderLink); @@ -27,17 +23,12 @@ JKRDvdArchive::JKRDvdArchive(s32 entryNum, EMountDirection mountDirection) } } -JKRDvdArchive::~JKRDvdArchive() -{ - if (mIsMounted == true) - { - if (mArcInfoBlock) - { +JKRDvdArchive::~JKRDvdArchive() { + if (mIsMounted == true) { + if (mArcInfoBlock) { SDIFileEntry* fileEntries = mFileEntries; - for (int i = 0; i < mArcInfoBlock->num_file_entries; i++) - { - if (fileEntries->mData != nullptr) - { + for (int i = 0; i < mArcInfoBlock->num_file_entries; i++) { + if (fileEntries->mData != nullptr) { JKRFreeToHeap(mHeap, fileEntries->mData); } fileEntries++; @@ -45,8 +36,7 @@ JKRDvdArchive::~JKRDvdArchive() JKRFreeToHeap(mHeap, mArcInfoBlock); } - if (mDvdFile) - { + if (mDvdFile) { delete mDvdFile; } @@ -59,8 +49,7 @@ JKRDvdArchive::~JKRDvdArchive() CW_FORCE_STRINGS(JKRDvdArchive_cpp, __FILE__, "isMounted()", "mMountCount == 1") #endif -bool JKRDvdArchive::open(long entryNum) -{ +bool JKRDvdArchive::open(long entryNum) { mArcInfoBlock = nullptr; _60 = 0; mDirectories = nullptr; @@ -68,254 +57,199 @@ bool JKRDvdArchive::open(long entryNum) mStrTable = nullptr; mDvdFile = new (JKRGetSystemHeap(), 0) JKRDvdFile(entryNum); - if (mDvdFile == nullptr) - { + if (mDvdFile == nullptr) { mMountMode = 0; return 0; } - SDIFileEntry* mem = (SDIFileEntry*)JKRAllocFromSysHeap( - 32, 32); // NOTE: unconfirmed if this struct was used here - if (mem == nullptr) - { + SDIFileEntry* mem = (SDIFileEntry*)JKRAllocFromSysHeap(32, 32); // NOTE: unconfirmed if this struct was used here + if (mem == nullptr) { mMountMode = 0; - } - else - { - JKRDvdToMainRam(entryNum, (u8*)mem, EXPAND_SWITCH_DECOMPRESS, 32, nullptr, - JKRDvdRipper::ALLOC_DIR_TOP, 0, &mCompression); + } else { + JKRDvdToMainRam(entryNum, (u8*)mem, EXPAND_SWITCH_DECOMPRESS, 32, nullptr, JKRDvdRipper::ALLOC_DIR_TOP, 0, + &mCompression); int alignment = mMountDirection == MOUNT_DIRECTION_HEAD ? 32 : -32; - mArcInfoBlock = - (SArcDataInfo*)JKRAllocFromHeap(mHeap, mem->mSize, alignment); - if (mArcInfoBlock == nullptr) - { + mArcInfoBlock = (SArcDataInfo*)JKRAllocFromHeap(mHeap, mem->mSize, alignment); + if (mArcInfoBlock == nullptr) { mMountMode = 0; - } - else - { - JKRDvdToMainRam(entryNum, (u8*)mArcInfoBlock, EXPAND_SWITCH_DECOMPRESS, - mem->mSize, nullptr, JKRDvdRipper::ALLOC_DIR_TOP, 32, - nullptr); + } else { + JKRDvdToMainRam(entryNum, (u8*)mArcInfoBlock, EXPAND_SWITCH_DECOMPRESS, mem->mSize, nullptr, + JKRDvdRipper::ALLOC_DIR_TOP, 32, nullptr); - mDirectories = - (SDIDirEntry*)((u8*)mArcInfoBlock + mArcInfoBlock->node_offset); - mFileEntries = (SDIFileEntry*)((u8*)mArcInfoBlock + - mArcInfoBlock->file_entry_offset); - mStrTable = (const char*)((u8*)mArcInfoBlock + - mArcInfoBlock->string_table_offset); + mDirectories = (SDIDirEntry*)((u8*)mArcInfoBlock + mArcInfoBlock->node_offset); + mFileEntries = (SDIFileEntry*)((u8*)mArcInfoBlock + mArcInfoBlock->file_entry_offset); + mStrTable = (const char*)((u8*)mArcInfoBlock + mArcInfoBlock->string_table_offset); _60 = mem->mDataOffset + mem->mSize; // End of data offset? } } cleanup: - if (mem != nullptr) - { + if (mem != nullptr) { JKRFreeToSysHeap(mem); } - if (mMountMode == 0) - { + if (mMountMode == 0) { JREPORTF(":::Cannot alloc memory [%s][%d]\n", __FILE__, 397); // Macro? - if (mDvdFile != nullptr) - { + if (mDvdFile != nullptr) { delete mDvdFile; } } return mMountMode != 0; } -void* JKRDvdArchive::fetchResource(SDIFileEntry* fileEntry, u32* pSize) -{ +void* JKRDvdArchive::fetchResource(SDIFileEntry* fileEntry, u32* pSize) { JUT_ASSERT(isMounted()); u32 sizeRef; u8* data; - if (fileEntry->mData == nullptr) - { + if (fileEntry->mData == nullptr) { int compression = JKRConvertAttrToCompressionType(fileEntry->mFlag >> 0x18); - u32 size = fetchResource_subroutine(mEntryNum, _60 + fileEntry->mDataOffset, - fileEntry->mSize, mHeap, - (int)compression, mCompression, &data); + u32 size = fetchResource_subroutine(mEntryNum, _60 + fileEntry->mDataOffset, fileEntry->mSize, mHeap, + (int)compression, mCompression, &data); if (pSize) *pSize = size; fileEntry->mData = data; - } - else if (pSize) - { + } else if (pSize) { *pSize = fileEntry->mSize; } return fileEntry->mData; } -void* JKRDvdArchive::fetchResource(void* data, u32 compressedSize, - SDIFileEntry* fileEntry, u32* pSize, - JKRExpandSwitch expandSwitch) -{ +void* JKRDvdArchive::fetchResource(void* data, u32 compressedSize, SDIFileEntry* fileEntry, u32* pSize, + JKRExpandSwitch expandSwitch) { JUT_ASSERT(isMounted()); u32 fileSize = compressedSize & -32; u32 alignedSize = ALIGN_NEXT(fileEntry->mSize, 32); - if (alignedSize > fileSize) - { + if (alignedSize > fileSize) { alignedSize = fileSize; } - if (fileEntry->mData == nullptr) - { + if (fileEntry->mData == nullptr) { int compression = JKRConvertAttrToCompressionType(fileEntry->mFlag >> 0x18); if (expandSwitch != EXPAND_SWITCH_DECOMPRESS) compression = 0; - alignedSize = fetchResource_subroutine( - mEntryNum, _60 + fileEntry->mDataOffset, fileEntry->mSize, (u8*)data, - fileSize, compression, mCompression); - } - else - { + alignedSize = fetchResource_subroutine(mEntryNum, _60 + fileEntry->mDataOffset, fileEntry->mSize, (u8*)data, + fileSize, compression, mCompression); + } else { JKRHeap::copyMemory(data, fileEntry->mData, alignedSize); } - if (pSize) - { + if (pSize) { *pSize = alignedSize; } return data; } -u32 JKRDvdArchive::fetchResource_subroutine(long entryNum, u32 offset, u32 size, - u8* data, u32 expandSize, - int fileCompression, - int archiveCompression) -{ +u32 JKRDvdArchive::fetchResource_subroutine(long entryNum, u32 offset, u32 size, u8* data, u32 expandSize, + int fileCompression, int archiveCompression) { u32 prevAlignedSize, alignedSize; alignedSize = ALIGN_NEXT(size, 32); prevAlignedSize = ALIGN_PREV(expandSize, 32); - switch (archiveCompression) - { - case JKRCOMPRESSION_NONE: - { - switch (fileCompression) - { - case JKRCOMPRESSION_NONE: + switch (archiveCompression) { + case JKRCOMPRESSION_NONE: { + switch (fileCompression) { + case JKRCOMPRESSION_NONE: - if (alignedSize > prevAlignedSize) - { - alignedSize = prevAlignedSize; + if (alignedSize > prevAlignedSize) { + alignedSize = prevAlignedSize; + } + JKRDvdRipper::loadToMainRAM(entryNum, data, EXPAND_SWITCH_DEFAULT, alignedSize, nullptr, + JKRDvdRipper::ALLOC_DIR_TOP, offset, nullptr); + return alignedSize; + + case JKRCOMPRESSION_YAY0: + case JKRCOMPRESSION_YAZ0: + u8* header = (u8*)JKRAllocFromSysHeap(0x20, 0x20); + JKRDvdRipper::loadToMainRAM(entryNum, header, EXPAND_SWITCH_NONE, 0x20, nullptr, + JKRDvdRipper::ALLOC_DIR_TOP, offset, nullptr); + u32 expandFileSize = JKRDecompExpandSize(header); + JKRFreeToSysHeap(header); + alignedSize = ALIGN_NEXT(expandFileSize, 32); + if (alignedSize > prevAlignedSize) { + alignedSize = prevAlignedSize; + } + JKRDvdRipper::loadToMainRAM(entryNum, data, EXPAND_SWITCH_DECOMPRESS, alignedSize, nullptr, + JKRDvdRipper::ALLOC_DIR_TOP, offset, nullptr); + return expandFileSize; } - JKRDvdRipper::loadToMainRAM( - entryNum, data, EXPAND_SWITCH_DEFAULT, alignedSize, nullptr, - JKRDvdRipper::ALLOC_DIR_TOP, offset, nullptr); - return alignedSize; - - case JKRCOMPRESSION_YAY0: - case JKRCOMPRESSION_YAZ0: - u8* header = (u8*)JKRAllocFromSysHeap(0x20, 0x20); - JKRDvdRipper::loadToMainRAM( - entryNum, header, EXPAND_SWITCH_NONE, 0x20, nullptr, - JKRDvdRipper::ALLOC_DIR_TOP, offset, nullptr); - u32 expandFileSize = JKRDecompExpandSize(header); - JKRFreeToSysHeap(header); - alignedSize = ALIGN_NEXT(expandFileSize, 32); - if (alignedSize > prevAlignedSize) - { - alignedSize = prevAlignedSize; + } + case JKRCOMPRESSION_YAZ0: { + if (size > prevAlignedSize) { + size = prevAlignedSize; } - JKRDvdRipper::loadToMainRAM( - entryNum, data, EXPAND_SWITCH_DECOMPRESS, alignedSize, nullptr, - JKRDvdRipper::ALLOC_DIR_TOP, offset, nullptr); - return expandFileSize; + JKRDvdRipper::loadToMainRAM(entryNum, data, EXPAND_SWITCH_DECOMPRESS, size, nullptr, + JKRDvdRipper::ALLOC_DIR_TOP, offset, nullptr); + return size; } - } - case JKRCOMPRESSION_YAZ0: - { - if (size > prevAlignedSize) - { - size = prevAlignedSize; + + case JKRCOMPRESSION_YAY0: { + JPANIC(537, "Sorry, not prepared for SZP archive.\n"); + return 0; } - JKRDvdRipper::loadToMainRAM(entryNum, data, EXPAND_SWITCH_DECOMPRESS, - size, nullptr, JKRDvdRipper::ALLOC_DIR_TOP, - offset, nullptr); - return size; - } - case JKRCOMPRESSION_YAY0: - { - JPANIC(537, "Sorry, not prepared for SZP archive.\n"); - return 0; - } - - default: - { - JPANIC(546, ":::??? bad sequence\n"); - } + default: { + JPANIC(546, ":::??? bad sequence\n"); + } } return 0; } -u32 JKRDvdArchive::fetchResource_subroutine(long entryNum, u32 offset, u32 size, - JKRHeap* heap, int fileCompression, - int archiveCompression, u8** pBuf) -{ +u32 JKRDvdArchive::fetchResource_subroutine(long entryNum, u32 offset, u32 size, JKRHeap* heap, int fileCompression, + int archiveCompression, u8** pBuf) { u32 alignedSize = ALIGN_NEXT(size, 32); u8* buffer; - switch (archiveCompression) - { - case JKRCOMPRESSION_NONE: - { - switch (fileCompression) - { - case JKRCOMPRESSION_NONE: + switch (archiveCompression) { + case JKRCOMPRESSION_NONE: { + switch (fileCompression) { + case JKRCOMPRESSION_NONE: + buffer = (u8*)JKRAllocFromHeap(heap, alignedSize, 32); + JUT_ASSERT(buffer != 0); + + JKRDvdToMainRam(entryNum, buffer, EXPAND_SWITCH_DEFAULT, alignedSize, nullptr, + JKRDvdRipper::ALLOC_DIR_TOP, offset, nullptr); + *pBuf = buffer; + return alignedSize; + + case JKRCOMPRESSION_YAY0: + case JKRCOMPRESSION_YAZ0: + u8* header = (u8*)JKRAllocFromHeap(heap, 0x20, 0x20); + JKRDvdToMainRam(entryNum, header, EXPAND_SWITCH_NONE, 0x20, nullptr, JKRDvdRipper::ALLOC_DIR_TOP, + offset, nullptr); + + alignedSize = JKRDecompExpandSize(header); + JKRFreeToHeap(heap, header); + buffer = (u8*)JKRAllocFromHeap(heap, alignedSize, 0x20); + JUT_ASSERT(buffer); + + JKRDvdToMainRam(entryNum, buffer, EXPAND_SWITCH_DECOMPRESS, alignedSize, nullptr, + JKRDvdRipper::ALLOC_DIR_TOP, offset, nullptr); + *pBuf = buffer; + return alignedSize; + } + } + case JKRCOMPRESSION_YAZ0: { buffer = (u8*)JKRAllocFromHeap(heap, alignedSize, 32); - JUT_ASSERT(buffer != 0); - - JKRDvdToMainRam(entryNum, buffer, EXPAND_SWITCH_DEFAULT, alignedSize, - nullptr, JKRDvdRipper::ALLOC_DIR_TOP, offset, - nullptr); - *pBuf = buffer; - return alignedSize; - - case JKRCOMPRESSION_YAY0: - case JKRCOMPRESSION_YAZ0: - u8* header = (u8*)JKRAllocFromHeap(heap, 0x20, 0x20); - JKRDvdToMainRam(entryNum, header, EXPAND_SWITCH_NONE, 0x20, nullptr, - JKRDvdRipper::ALLOC_DIR_TOP, offset, nullptr); - - alignedSize = JKRDecompExpandSize(header); - JKRFreeToHeap(heap, header); - buffer = (u8*)JKRAllocFromHeap(heap, alignedSize, 0x20); JUT_ASSERT(buffer); - - JKRDvdToMainRam(entryNum, buffer, EXPAND_SWITCH_DECOMPRESS, - alignedSize, nullptr, JKRDvdRipper::ALLOC_DIR_TOP, - offset, nullptr); + JKRDvdToMainRam(entryNum, buffer, EXPAND_SWITCH_DECOMPRESS, size, nullptr, JKRDvdRipper::ALLOC_DIR_TOP, + offset, nullptr); *pBuf = buffer; return alignedSize; } - } - case JKRCOMPRESSION_YAZ0: - { - buffer = (u8*)JKRAllocFromHeap(heap, alignedSize, 32); - JUT_ASSERT(buffer); - JKRDvdToMainRam(entryNum, buffer, EXPAND_SWITCH_DECOMPRESS, size, nullptr, - JKRDvdRipper::ALLOC_DIR_TOP, offset, nullptr); - *pBuf = buffer; - return alignedSize; - } - case JKRCOMPRESSION_YAY0: - { - JPANIC(612, "Sorry, not prepared for SZP archive.\n"); - return 0; - } + case JKRCOMPRESSION_YAY0: { + JPANIC(612, "Sorry, not prepared for SZP archive.\n"); + return 0; + } - default: - { - JPANIC(617, ":::??? bad sequence\n"); - } + default: { + JPANIC(617, ":::??? bad sequence\n"); + } } return 0; } diff --git a/src/static/JSystem/JKernel/JKRDvdFile.cpp b/src/static/JSystem/JKernel/JKRDvdFile.cpp index bfa4372e..1803fb24 100644 --- a/src/static/JSystem/JKernel/JKRDvdFile.cpp +++ b/src/static/JSystem/JKernel/JKRDvdFile.cpp @@ -2,115 +2,117 @@ JSUList JKRDvdFile::sDvdList; -JKRDvdFile::JKRDvdFile() : JKRFile(), mLink(this) { this->initiate(); } +JKRDvdFile::JKRDvdFile() : JKRFile(), mLink(this) { + this->initiate(); +} /* This method is confirmed to exist, but goes unused in AC. Retrieved from TP debug. */ JKRDvdFile::JKRDvdFile(const char* filename) : JKRFile(), mLink(this) { - this->initiate(); - this->mFileOpen = this->open(filename); + this->initiate(); + this->mFileOpen = this->open(filename); - if (this->isAvailable()) { - return; - } + if (this->isAvailable()) { + return; + } } JKRDvdFile::JKRDvdFile(s32 entrynum) : JKRFile(), mLink(this) { - this->initiate(); - this->mFileOpen = this->open(entrynum); + this->initiate(); + this->mFileOpen = this->open(entrynum); - if (this->isAvailable()) { - return; - } + if (this->isAvailable()) { + return; + } } -JKRDvdFile::~JKRDvdFile() { this->close(); } +JKRDvdFile::~JKRDvdFile() { + this->close(); +} void JKRDvdFile::initiate() { - /* Reference to self. Used to retrieve reference in the DVDReadAsync - * DVDCallback func. */ - this->mDvdFileInfo.mFile = this; - OSInitMutex(&this->mDvdMutex); - OSInitMutex(&this->mAramMutex); - OSInitMessageQueue(&this->mDvdMessageQueue, &this->mDvdMessage, 1); - OSInitMessageQueue(&this->mAramMessageQueue, &this->mAramMessage, 1); - this->mDvdThread = nullptr; - this->mAramThread = nullptr; - this->_58 = 0; + /* Reference to self. Used to retrieve reference in the DVDReadAsync + * DVDCallback func. */ + this->mDvdFileInfo.mFile = this; + OSInitMutex(&this->mDvdMutex); + OSInitMutex(&this->mAramMutex); + OSInitMessageQueue(&this->mDvdMessageQueue, &this->mDvdMessage, 1); + OSInitMessageQueue(&this->mAramMessageQueue, &this->mAramMessage, 1); + this->mDvdThread = nullptr; + this->mAramThread = nullptr; + this->_58 = 0; } /* This method is confirmed to exist, but goes unused in AC. Retrieved from TP debug. */ bool JKRDvdFile::open(const char* filename) { - if (this->mFileOpen == false) { - this->mFileOpen = DVDOpen((char*)filename, &this->mDvdFileInfo); - if (this->mFileOpen) { - sDvdList.append(&this->mLink); - DVDGetFileInfoStatus(&this->mDvdFileInfo); + if (this->mFileOpen == false) { + this->mFileOpen = DVDOpen((char*)filename, &this->mDvdFileInfo); + if (this->mFileOpen) { + sDvdList.append(&this->mLink); + DVDGetFileInfoStatus(&this->mDvdFileInfo); + } } - } - return this->mFileOpen; + return this->mFileOpen; } bool JKRDvdFile::open(s32 entrynum) { - if (this->mFileOpen == false) { - this->mFileOpen = DVDFastOpen(entrynum, &this->mDvdFileInfo); - if (this->mFileOpen) { - sDvdList.append(&this->mLink); - DVDGetFileInfoStatus(&this->mDvdFileInfo); + if (this->mFileOpen == false) { + this->mFileOpen = DVDFastOpen(entrynum, &this->mDvdFileInfo); + if (this->mFileOpen) { + sDvdList.append(&this->mLink); + DVDGetFileInfoStatus(&this->mDvdFileInfo); + } } - } - return this->mFileOpen; + return this->mFileOpen; } bool JKRDvdFile::close() { - if (this->mFileOpen) { - if (DVDClose(&this->mDvdFileInfo)) { - this->mFileOpen = false; - return sDvdList.remove(&this->mLink); + if (this->mFileOpen) { + if (DVDClose(&this->mDvdFileInfo)) { + this->mFileOpen = false; + return sDvdList.remove(&this->mLink); + } else { + OSErrorLine(212, "cannot close DVD file\n"); /* JKRDvdFile.cpp line 212 */ + } } - else { - OSErrorLine(212, "cannot close DVD file\n"); /* JKRDvdFile.cpp line 212 */ - } - } } int JKRDvdFile::readData(void* data, s32 length, s32 ofs) { - OSLockMutex(&this->mDvdMutex); - s32 retAddr; + OSLockMutex(&this->mDvdMutex); + s32 retAddr; - if (this->mDvdThread != nullptr) { - OSUnlockMutex(&this->mDvdMutex); - return -1; - } - else { - this->mDvdThread = OSGetCurrentThread(); - retAddr = -1; - if (DVDReadAsync(&this->mDvdFileInfo, data, length, ofs, - JKRDvdFile::doneProcess)) { - retAddr = this->sync(); + if (this->mDvdThread != nullptr) { + OSUnlockMutex(&this->mDvdMutex); + return -1; + } else { + this->mDvdThread = OSGetCurrentThread(); + retAddr = -1; + if (DVDReadAsync(&this->mDvdFileInfo, data, length, ofs, JKRDvdFile::doneProcess)) { + retAddr = this->sync(); + } + + this->mDvdThread = nullptr; + OSUnlockMutex(&this->mDvdMutex); } - this->mDvdThread = nullptr; - OSUnlockMutex(&this->mDvdMutex); - } - - return retAddr; + return retAddr; } -int JKRDvdFile::writeData(const void* data, s32 length, s32 ofs) { return -1; } +int JKRDvdFile::writeData(const void* data, s32 length, s32 ofs) { + return -1; +} s32 JKRDvdFile::sync() { - OSMessage m; + OSMessage m; - OSLockMutex(&this->mDvdMutex); - OSReceiveMessage(&this->mDvdMessageQueue, &m, OS_MESSAGE_BLOCK); - this->mDvdThread = nullptr; - OSUnlockMutex(&this->mDvdMutex); - return (s32)m; + OSLockMutex(&this->mDvdMutex); + OSReceiveMessage(&this->mDvdMessageQueue, &m, OS_MESSAGE_BLOCK); + this->mDvdThread = nullptr; + OSUnlockMutex(&this->mDvdMutex); + return (s32)m; } void JKRDvdFile::doneProcess(s32 result, DVDFileInfo* info) { - OSSendMessage(&static_cast(info)->mFile->mDvdMessageQueue, - (OSMessage)result, OS_MESSAGE_NOBLOCK); + OSSendMessage(&static_cast(info)->mFile->mDvdMessageQueue, (OSMessage)result, OS_MESSAGE_NOBLOCK); } diff --git a/src/static/JSystem/JKernel/JKRDvdRipper.cpp b/src/static/JSystem/JKernel/JKRDvdRipper.cpp index 5a698305..27de91b2 100644 --- a/src/static/JSystem/JKernel/JKRDvdRipper.cpp +++ b/src/static/JSystem/JKernel/JKRDvdRipper.cpp @@ -15,190 +15,187 @@ static int decompSZS_subroutine(u8* src, u8* dest); static u8* firstSrcData(); static u8* nextSrcData(u8* nowData); -void* JKRDvdRipper::loadToMainRAM(const char* file, u8* buf, JKRExpandSwitch expandSwitch, u32 maxDest, JKRHeap* heap, EAllocDirection allocDir, u32 offset, int* compressMode) { - JKRDvdFile dvdFile; +void* JKRDvdRipper::loadToMainRAM(const char* file, u8* buf, JKRExpandSwitch expandSwitch, u32 maxDest, JKRHeap* heap, + EAllocDirection allocDir, u32 offset, int* compressMode) { + JKRDvdFile dvdFile; - if (!dvdFile.open(file)) { - return nullptr; - } - else { - return JKRDvdRipper::loadToMainRAM(&dvdFile, buf, expandSwitch, maxDest, heap, allocDir, offset, compressMode); - } -} - -void* JKRDvdRipper::loadToMainRAM(s32 entrynum, u8* buf, JKRExpandSwitch expandSwitch, u32 maxDest, JKRHeap* heap, EAllocDirection allocDir, u32 offset, int* compressMode) { - JKRDvdFile dvdFile; - - if (!dvdFile.open(entrynum)) { - return nullptr; - } - else { - return JKRDvdRipper::loadToMainRAM(&dvdFile, buf, expandSwitch, maxDest, heap, allocDir, offset, compressMode); - } -} - -void* JKRDvdRipper::loadToMainRAM(JKRDvdFile* file, u8* buf, JKRExpandSwitch expandSwitch, u32 maxDest, JKRHeap* heap, EAllocDirection allocDir, u32 offset, int* compressMode) { - u32 finalSize; - - bool allocated = false; - JKRDecomp::CompressionMode fileCompressMode = JKRDecomp::NONE; - u8* mem = nullptr; - u32 fileSize = ALIGN_NEXT(file->getFileSize(), 32); - - if (expandSwitch == EXPAND_SWITCH_DECOMPRESS) { - u8 buffer[64]; - u8* aligned_buf = (u8*)ALIGN_NEXT((u32)buffer, 32); - while (true) { - if (DVDReadPrio(file->getFileInfo(), aligned_buf, 32, 0, 2) >= 0) { - break; - } - if (JKRDvdRipper::errorRetry == false) { + if (!dvdFile.open(file)) { return nullptr; - } + } else { + return JKRDvdRipper::loadToMainRAM(&dvdFile, buf, expandSwitch, maxDest, heap, allocDir, offset, compressMode); + } +} - VIWaitForRetrace(); +void* JKRDvdRipper::loadToMainRAM(s32 entrynum, u8* buf, JKRExpandSwitch expandSwitch, u32 maxDest, JKRHeap* heap, + EAllocDirection allocDir, u32 offset, int* compressMode) { + JKRDvdFile dvdFile; + + if (!dvdFile.open(entrynum)) { + return nullptr; + } else { + return JKRDvdRipper::loadToMainRAM(&dvdFile, buf, expandSwitch, maxDest, heap, allocDir, offset, compressMode); + } +} + +void* JKRDvdRipper::loadToMainRAM(JKRDvdFile* file, u8* buf, JKRExpandSwitch expandSwitch, u32 maxDest, JKRHeap* heap, + EAllocDirection allocDir, u32 offset, int* compressMode) { + u32 finalSize; + + bool allocated = false; + JKRDecomp::CompressionMode fileCompressMode = JKRDecomp::NONE; + u8* mem = nullptr; + u32 fileSize = ALIGN_NEXT(file->getFileSize(), 32); + + if (expandSwitch == EXPAND_SWITCH_DECOMPRESS) { + u8 buffer[64]; + u8* aligned_buf = (u8*)ALIGN_NEXT((u32)buffer, 32); + while (true) { + if (DVDReadPrio(file->getFileInfo(), aligned_buf, 32, 0, 2) >= 0) { + break; + } + if (JKRDvdRipper::errorRetry == false) { + return nullptr; + } + + VIWaitForRetrace(); + } + + fileCompressMode = JKRCheckCompressed(aligned_buf); + finalSize = JKRDecompExpandSize(aligned_buf); } - fileCompressMode = JKRCheckCompressed(aligned_buf); - finalSize = JKRDecompExpandSize(aligned_buf); - } - - if (compressMode != nullptr) { - *compressMode = fileCompressMode; - } - - if (expandSwitch == EXPAND_SWITCH_DECOMPRESS && fileCompressMode != JKRDecomp::NONE) { - if (maxDest != 0 && finalSize > maxDest) { - finalSize = maxDest; + if (compressMode != nullptr) { + *compressMode = fileCompressMode; } - if (buf == nullptr) { - buf = (u8*)JKRAllocFromHeap(heap, finalSize, allocDir == ALLOC_DIR_TOP ? 32 : -32); - allocated = true; + if (expandSwitch == EXPAND_SWITCH_DECOMPRESS && fileCompressMode != JKRDecomp::NONE) { + if (maxDest != 0 && finalSize > maxDest) { + finalSize = maxDest; + } + + if (buf == nullptr) { + buf = (u8*)JKRAllocFromHeap(heap, finalSize, allocDir == ALLOC_DIR_TOP ? 32 : -32); + allocated = true; + } + + if (buf == nullptr) { + return nullptr; + } + + if (fileCompressMode == JKRDecomp::SZP) { + mem = (u8*)JKRAllocFromHeap(heap, fileSize, 32); + if (mem == nullptr && allocated == true) { + JKRFree(buf); + return nullptr; + } + } + } else { + if (buf == nullptr) { + buf = (u8*)JKRAllocFromHeap(heap, fileSize - offset, allocDir == ALLOC_DIR_TOP ? 32 : -32); + allocated = true; + } + + if (buf == nullptr) { + return nullptr; + } } - if (buf == nullptr) { - return nullptr; + if (fileCompressMode == JKRDecomp::NONE) { + JKRDecomp::CompressionMode subCompressMode = JKRDecomp::NONE; + + if (offset != 0) { + u8 buffer[64]; + u8* aligned_buf = (u8*)ALIGN_NEXT((u32)buffer, 32); + while (true) { + if (DVDReadPrio(file->getFileInfo(), aligned_buf, 32, offset, 2) >= 0) { + break; + } + + if (JKRDvdRipper::errorRetry == false) { + return nullptr; + } + + VIWaitForRetrace(); + } + + subCompressMode = JKRCheckCompressed(aligned_buf); + } + + if (subCompressMode == JKRDecomp::NONE || expandSwitch == EXPAND_SWITCH_NONE || + expandSwitch == EXPAND_SWITCH_DEFAULT) { + s32 readSize = fileSize - offset; + if (maxDest != 0 && maxDest < readSize) { + readSize = maxDest; + } + + while (true) { + if (DVDReadPrio(file->getFileInfo(), buf, readSize, offset, 2) >= 0) { + break; + } + + if (JKRDvdRipper::errorRetry == false) { + return nullptr; + } + + VIWaitForRetrace(); + } + return buf; + } + + if (subCompressMode == JKRDecomp::SZS) { + JKRDecompressFromDVD(file, buf, fileSize, maxDest, 0, offset); + } else { + JPANIC(297, "Sorry, not prepared for SZP resource\n"); + } } if (fileCompressMode == JKRDecomp::SZP) { - mem = (u8*)JKRAllocFromHeap(heap, fileSize, 32); - if (mem == nullptr && allocated == true) { - JKRFree(buf); - return nullptr; - } - } - } - else { - if (buf == nullptr) { - buf = (u8*)JKRAllocFromHeap(heap, fileSize - offset, allocDir == ALLOC_DIR_TOP ? 32 : -32); - allocated = true; - } - - if (buf == nullptr) { - return nullptr; - } - } - - if (fileCompressMode == JKRDecomp::NONE) { - JKRDecomp::CompressionMode subCompressMode = JKRDecomp::NONE; - - if (offset != 0) { - u8 buffer[64]; - u8* aligned_buf = (u8*)ALIGN_NEXT((u32)buffer, 32); - while (true) { - if (DVDReadPrio(file->getFileInfo(), aligned_buf, 32, offset, 2) >= 0) { - break; + if (offset != 0) { + JPANIC(306, ":::Not support SZP with offset read"); } - if (JKRDvdRipper::errorRetry == false) { - return nullptr; - } - - VIWaitForRetrace(); - } - - subCompressMode = JKRCheckCompressed(aligned_buf); - } - - if (subCompressMode == JKRDecomp::NONE || expandSwitch == EXPAND_SWITCH_NONE || expandSwitch == EXPAND_SWITCH_DEFAULT) { - s32 readSize = fileSize - offset; - if (maxDest != 0 && maxDest < readSize) { - readSize = maxDest; - } - - while (true) { - if (DVDReadPrio(file->getFileInfo(), buf, readSize, offset, 2) >= 0) { - break; - } - - if (JKRDvdRipper::errorRetry == false) { - return nullptr; - } - - VIWaitForRetrace(); - } - return buf; - } - - if (subCompressMode == JKRDecomp::SZS) { - JKRDecompressFromDVD(file, buf, fileSize, maxDest, 0, offset); - } - else { - JPANIC(297, "Sorry, not prepared for SZP resource\n"); - } - } - - if (fileCompressMode == JKRDecomp::SZP) { - if (offset != 0) { - JPANIC(306, ":::Not support SZP with offset read"); - } - - /* Looks like a bug here */ + /* Looks like a bug here */ #ifndef FIXES - if (DVDReadPrio(file->getFileInfo(), mem, fileSize, 0, 2) < 0) { - if (JKRDvdRipper::errorRetry == false) { - VIWaitForRetrace(); - } + if (DVDReadPrio(file->getFileInfo(), mem, fileSize, 0, 2) < 0) { + if (JKRDvdRipper::errorRetry == false) { + VIWaitForRetrace(); + } - JKRFree(mem); - return nullptr; - } - else { - JKRDecompress(mem, buf, finalSize, offset); - JKRFree(mem); - return buf; - } + JKRFree(mem); + return nullptr; + } else { + JKRDecompress(mem, buf, finalSize, offset); + JKRFree(mem); + return buf; + } #else - while (DVDReadPrio(file->getFileInfo(), mem, fileSize, 0, 2) < 0) { - if (JKRDvdRipper::errorRetry == false) { - if (allocated) { - JKRFree(buf); + while (DVDReadPrio(file->getFileInfo(), mem, fileSize, 0, 2) < 0) { + if (JKRDvdRipper::errorRetry == false) { + if (allocated) { + JKRFree(buf); + } + + JKRFree(mem); + return nullptr; + } + + VIWaitForRetrace(); } + JKRDecompress(mem, buf, finalSize, 0); JKRFree(mem); - return nullptr; - } - - VIWaitForRetrace(); - } - - JKRDecompress(mem, buf, finalSize, 0); - JKRFree(mem); #endif - } - else if (fileCompressMode == JKRDecomp::SZS) { - JKRDecompressFromDVD(file, buf, fileSize, finalSize, offset, 0); - return buf; - } - else { - if (allocated) { - JKRFree(buf); + } else if (fileCompressMode == JKRDecomp::SZS) { + JKRDecompressFromDVD(file, buf, fileSize, finalSize, offset, 0); + return buf; + } else { + if (allocated) { + JKRFree(buf); + } + return nullptr; } - return nullptr; - } - return buf; + return buf; } static u8* szpBuf; @@ -216,251 +213,215 @@ static u32 readCount; static u32 maxDest; int JKRDecompressFromDVD(JKRDvdFile* _srcFile, void* buf, u32 size, u32 _maxDest, u32 _fileOffset, u32 _srcOffset) { - int res = 0; + int res = 0; - szpBuf = (u8*)JKRAllocFromSysHeap(SZP_BUFFERSIZE, -32); - szpEnd = szpBuf + SZP_BUFFERSIZE; + szpBuf = (u8*)JKRAllocFromSysHeap(SZP_BUFFERSIZE, -32); + szpEnd = szpBuf + SZP_BUFFERSIZE; - if (_fileOffset != 0) { - refBuf = (u8*)JKRAllocFromSysHeap(REF_BUFFERSIZE, -4); - refEnd = refBuf + REF_BUFFERSIZE; - refCurrent = refBuf; - } - else { - refBuf = nullptr; - } + if (_fileOffset != 0) { + refBuf = (u8*)JKRAllocFromSysHeap(REF_BUFFERSIZE, -4); + refEnd = refBuf + REF_BUFFERSIZE; + refCurrent = refBuf; + } else { + refBuf = nullptr; + } - srcFile = _srcFile; - srcOffset = _srcOffset; - transLeft = size - _srcOffset; - fileOffset = _fileOffset; - readCount = 0; - maxDest = _maxDest; + srcFile = _srcFile; + srcOffset = _srcOffset; + transLeft = size - _srcOffset; + fileOffset = _fileOffset; + readCount = 0; + maxDest = _maxDest; - u8* src = firstSrcData(); - if (src != nullptr) { - res = decompSZS_subroutine(src, (u8*)buf); - } + u8* src = firstSrcData(); + if (src != nullptr) { + res = decompSZS_subroutine(src, (u8*)buf); + } - JKRFree(szpBuf); + JKRFree(szpBuf); - if (refBuf != nullptr) { - JKRFree(refBuf); - } + if (refBuf != nullptr) { + JKRFree(refBuf); + } - return res; + return res; } static int decompSZS_subroutine(u8* src, u8* dest) { - u8* endPtr; - s32 validBitCount = 0; - s32 currCodeByte = 0; - u32 ts = 0; + u8* endPtr; + s32 validBitCount = 0; + s32 currCodeByte = 0; + u32 ts = 0; - if ((s32)src[0] != 'Y' || (s32)src[1] != 'a' || (s32)src[2] != 'z' || (s32)src[3] != '0') - { - return -1; - } - - SZPHeader* header = (SZPHeader*)src; - endPtr = dest + (header->decompSize - fileOffset); - if (endPtr > dest + maxDest) - { - endPtr = dest + maxDest; - } - - src += 0x10; - do - { - if (validBitCount == 0) - { - if ((src > srcLimit) && transLeft) - { - src = nextSrcData(src); - if (!src) - { - return -1; - } - } - currCodeByte = *src; - validBitCount = 8; - src++; + if ((s32)src[0] != 'Y' || (s32)src[1] != 'a' || (s32)src[2] != 'z' || (s32)src[3] != '0') { + return -1; } - if (currCodeByte & 0x80) - { - if (fileOffset != 0) - { - if (readCount >= fileOffset) - { - *dest = *src; - dest++; - ts++; - if (dest == endPtr) - { - break; - } - } - *(refCurrent++) = *src; - if (refCurrent == refEnd) - { - refCurrent = refBuf; - } - src++; - } - else - { - *dest = *src; - dest++; - src++; - ts++; - if (dest == endPtr) - { - break; - } - } - readCount++; + + SZPHeader* header = (SZPHeader*)src; + endPtr = dest + (header->decompSize - fileOffset); + if (endPtr > dest + maxDest) { + endPtr = dest + maxDest; } - else - { - u32 dist = src[1] | (src[0] & 0x0f) << 8; - s32 numBytes = src[0] >> 4; - src += 2; - u8* copySource; - if (fileOffset != 0) - { - copySource = refCurrent - dist - 1; - if (copySource < refBuf) - { - copySource += refEnd - refBuf; - } - } - else - { - copySource = dest - dist - 1; - } - if (numBytes == 0) - { - numBytes = *src + 0x12; - src += 1; - } - else - { - numBytes += 2; - } - if (fileOffset != 0) - { - do - { - if (readCount >= fileOffset) - { - *dest = *copySource; - dest++; - ts++; - if (dest == endPtr) - { - break; + + src += 0x10; + do { + if (validBitCount == 0) { + if ((src > srcLimit) && transLeft) { + src = nextSrcData(src); + if (!src) { + return -1; + } } - } - *(refCurrent++) = *copySource; - if (refCurrent == refEnd) - { - refCurrent = refBuf; - } - copySource++; - if (copySource == refEnd) - { - copySource = refBuf; - } - readCount++; - numBytes--; - } while (numBytes != 0); - } - else - { - do - { - *dest = *copySource; - dest++; - ts++; - if (dest == endPtr) - { - break; - } - readCount++; - numBytes--; - copySource++; - } while (numBytes != 0); - } - } - currCodeByte <<= 1; - validBitCount--; - } while (dest < endPtr); + currCodeByte = *src; + validBitCount = 8; + src++; + } + if (currCodeByte & 0x80) { + if (fileOffset != 0) { + if (readCount >= fileOffset) { + *dest = *src; + dest++; + ts++; + if (dest == endPtr) { + break; + } + } + *(refCurrent++) = *src; + if (refCurrent == refEnd) { + refCurrent = refBuf; + } + src++; + } else { + *dest = *src; + dest++; + src++; + ts++; + if (dest == endPtr) { + break; + } + } + readCount++; + } else { + u32 dist = src[1] | (src[0] & 0x0f) << 8; + s32 numBytes = src[0] >> 4; + src += 2; + u8* copySource; + if (fileOffset != 0) { + copySource = refCurrent - dist - 1; + if (copySource < refBuf) { + copySource += refEnd - refBuf; + } + } else { + copySource = dest - dist - 1; + } + if (numBytes == 0) { + numBytes = *src + 0x12; + src += 1; + } else { + numBytes += 2; + } + if (fileOffset != 0) { + do { + if (readCount >= fileOffset) { + *dest = *copySource; + dest++; + ts++; + if (dest == endPtr) { + break; + } + } + *(refCurrent++) = *copySource; + if (refCurrent == refEnd) { + refCurrent = refBuf; + } + copySource++; + if (copySource == refEnd) { + copySource = refBuf; + } + readCount++; + numBytes--; + } while (numBytes != 0); + } else { + do { + *dest = *copySource; + dest++; + ts++; + if (dest == endPtr) { + break; + } + readCount++; + numBytes--; + copySource++; + } while (numBytes != 0); + } + } + currCodeByte <<= 1; + validBitCount--; + } while (dest < endPtr); - return 0; + return 0; } static u8* firstSrcData() { - srcLimit = szpEnd - 0x19; - u8* buf = szpBuf; - u32 size = (szpEnd - szpBuf); - u32 transSize = MIN(transLeft, size); + srcLimit = szpEnd - 0x19; + u8* buf = szpBuf; + u32 size = (szpEnd - szpBuf); + u32 transSize = MIN(transLeft, size); - while (true) { - if (DVDReadPrio(srcFile->getFileInfo(), buf, transSize, srcOffset, 2) < 0) { - if (JKRDvdRipper::errorRetry == false) { - return nullptr; - } - VIWaitForRetrace(); + while (true) { + if (DVDReadPrio(srcFile->getFileInfo(), buf, transSize, srcOffset, 2) < 0) { + if (JKRDvdRipper::errorRetry == false) { + return nullptr; + } + VIWaitForRetrace(); + } else { + srcOffset += transSize; + transLeft -= transSize; + return buf; + } } - else { - srcOffset += transSize; - transLeft -= transSize; - return buf; - } - } } static u8* nextSrcData(u8* nowData) { - u32 size = (szpEnd - nowData); - u8* dst; - if (JKR_ISNOTALIGNED32(size)) { - dst = szpBuf + 32 - (size & 31); - } - else { - dst = szpBuf; - } - - memcpy(dst, nowData, size); - - u32 n_size = (szpEnd - (dst + size)); - if (n_size > transLeft) { - n_size = transLeft; - } - - while (true) { - if (DVDReadPrio(srcFile->getFileInfo(), (dst + size), n_size, srcOffset, 2) >= 0) { - break; + u32 size = (szpEnd - nowData); + u8* dst; + if (JKR_ISNOTALIGNED32(size)) { + dst = szpBuf + 32 - (size & 31); + } else { + dst = szpBuf; } - // Oopsies, forgot to call the function + + memcpy(dst, nowData, size); + + u32 n_size = (szpEnd - (dst + size)); + if (n_size > transLeft) { + n_size = transLeft; + } + + while (true) { + if (DVDReadPrio(srcFile->getFileInfo(), (dst + size), n_size, srcOffset, 2) >= 0) { + break; + } + // Oopsies, forgot to call the function #ifndef FIXES - if (JKRDvdRipper::isErrorRetry == false) { - return nullptr; - } + if (JKRDvdRipper::isErrorRetry == false) { + return nullptr; + } #else - if (JKRDvdRipper::isErrorRetry() == false) { - return nullptr; - } + if (JKRDvdRipper::isErrorRetry() == false) { + return nullptr; + } #endif - VIWaitForRetrace(); - } + VIWaitForRetrace(); + } - srcOffset += n_size; - transLeft -= n_size; + srcOffset += n_size; + transLeft -= n_size; - if (transLeft == 0) { - srcLimit = (dst + size) + n_size; - } + if (transLeft == 0) { + srcLimit = (dst + size) + n_size; + } - return dst; + return dst; } diff --git a/src/static/JSystem/JKernel/JKRExpHeap.cpp b/src/static/JSystem/JKernel/JKRExpHeap.cpp index 9eb0e3bf..90649bde 100644 --- a/src/static/JSystem/JKernel/JKRExpHeap.cpp +++ b/src/static/JSystem/JKernel/JKRExpHeap.cpp @@ -12,11 +12,9 @@ static JKRExpHeap::CMemBlock* DBfoundBlock; static JKRExpHeap::CMemBlock* DBnewFreeBlock; static JKRExpHeap::CMemBlock* DBnewUsedBlock; -JKRExpHeap* JKRExpHeap::createRoot(int maxHeaps, bool errorFlag) -{ +JKRExpHeap* JKRExpHeap::createRoot(int maxHeaps, bool errorFlag) { JKRExpHeap* heap = nullptr; - if (!sRootHeap) - { + if (!sRootHeap) { void* memory; u32 memorySize; initArena((char**)&memory, &memorySize, maxHeaps); @@ -29,11 +27,9 @@ JKRExpHeap* JKRExpHeap::createRoot(int maxHeaps, bool errorFlag) return heap; } -JKRExpHeap* JKRExpHeap::create(u32 size, JKRHeap* parent, bool errorFlag) -{ +JKRExpHeap* JKRExpHeap::create(u32 size, JKRHeap* parent, bool errorFlag) { JKRExpHeap* newHeap; - if (!parent) - { + if (!parent) { parent = sRootHeap; } @@ -44,8 +40,7 @@ JKRExpHeap* JKRExpHeap::create(u32 size, JKRHeap* parent, bool errorFlag) u8* memory = (u8*)JKRAllocFromHeap(parent, alignedSize, 0x10); u8* dataPtr = memory + expHeapSize; - if (!memory) - { + if (!memory) { return nullptr; } if ((int)(alignedSize - expHeapSize) < 0x10) { @@ -54,8 +49,7 @@ JKRExpHeap* JKRExpHeap::create(u32 size, JKRHeap* parent, bool errorFlag) } newHeap = new (memory) JKRExpHeap(dataPtr, alignedSize - expHeapSize, parent, errorFlag); - if (newHeap == nullptr) - { + if (newHeap == nullptr) { JKRFree(memory); return nullptr; }; @@ -63,17 +57,13 @@ JKRExpHeap* JKRExpHeap::create(u32 size, JKRHeap* parent, bool errorFlag) return newHeap; } -JKRExpHeap* JKRExpHeap::create(void* ptr, u32 size, JKRHeap* parent, bool errorFlag) -{ +JKRExpHeap* JKRExpHeap::create(void* ptr, u32 size, JKRHeap* parent, bool errorFlag) { JKRHeap* parent2; - if (parent == nullptr) - { + if (parent == nullptr) { parent2 = sRootHeap->find(ptr); if (!parent2) return nullptr; - } - else - { + } else { parent2 = parent; } @@ -95,9 +85,7 @@ JKRExpHeap* JKRExpHeap::create(void* ptr, u32 size, JKRHeap* parent, bool errorF return newHeap; } -JKRExpHeap::JKRExpHeap(void* p1, u32 p2, JKRHeap* p3, bool p4) - : JKRHeap(p1, p2, p3, p4) -{ +JKRExpHeap::JKRExpHeap(void* p1, u32 p2, JKRHeap* p3, bool p4) : JKRHeap(p1, p2, p3, p4) { mCurrentAllocMode = 0; mCurrentGroupID = 0xFF; mHead = static_cast(p1); @@ -107,10 +95,11 @@ JKRExpHeap::JKRExpHeap(void* p1, u32 p2, JKRHeap* p3, bool p4) mTailUsedList = nullptr; } -JKRExpHeap::~JKRExpHeap() { dispose(); } +JKRExpHeap::~JKRExpHeap() { + dispose(); +} -s32 JKRExpHeap::do_changeGroupID(unsigned char groupID) -{ +s32 JKRExpHeap::do_changeGroupID(unsigned char groupID) { lock(); u8 oldGroupID = mCurrentGroupID; mCurrentGroupID = groupID; @@ -118,8 +107,7 @@ s32 JKRExpHeap::do_changeGroupID(unsigned char groupID) return oldGroupID; } -void* JKRExpHeap::do_alloc(u32 size, int alignment) -{ +void* JKRExpHeap::do_alloc(u32 size, int alignment) { lock(); if (size < 4) { @@ -129,8 +117,7 @@ void* JKRExpHeap::do_alloc(u32 size, int alignment) whatdo = 0; void* ptr; - if (alignment >= 0) - { + if (alignment >= 0) { if (alignment <= 4) { whatdo = 1; @@ -141,21 +128,16 @@ void* JKRExpHeap::do_alloc(u32 size, int alignment) whatdo = 2; ptr = allocFromHead(size, alignment); } - } - else - { + } else { if (-alignment <= 4) { whatdo = 3; ptr = allocFromTail(size); - } - else { + } else { whatdo = 4; ptr = allocFromTail(size, -alignment); } - } - if (ptr == nullptr) - { + if (ptr == nullptr) { JUTWarningConsole_f(":::cannot alloc memory (0x%x byte).\n", size); if (mErrorFlag == true) callErrorHandler(this, size, alignment); @@ -165,8 +147,7 @@ void* JKRExpHeap::do_alloc(u32 size, int alignment) return ptr; } -void* JKRExpHeap::allocFromHead(u32 size, int align) -{ +void* JKRExpHeap::allocFromHead(u32 size, int align) { CMemBlock* newFreeBlock; CMemBlock* newUsedBlock; @@ -175,27 +156,22 @@ void* JKRExpHeap::allocFromHead(u32 size, int align) u32 foundOffset = 0; CMemBlock* foundBlock = nullptr; - for (CMemBlock* block = mHead; block; block = block->mNext) - { + for (CMemBlock* block = mHead; block; block = block->mNext) { u32 offset = ALIGN_PREV(align - 1 + (u32)block->getContent(), align) - (u32)block->getContent(); - if (block->mAllocatedSpace < size + offset) - { + if (block->mAllocatedSpace < size + offset) { continue; } - if (foundSize <= (u32)block->mAllocatedSpace) - { + if (foundSize <= (u32)block->mAllocatedSpace) { continue; } foundSize = block->mAllocatedSpace; foundBlock = block; foundOffset = offset; - if (mCurrentAllocMode != 0) - { + if (mCurrentAllocMode != 0) { break; } u32 blockSize = block->mAllocatedSpace; - if (blockSize == size) - { + if (blockSize == size) { break; } } @@ -204,34 +180,25 @@ void* JKRExpHeap::allocFromHead(u32 size, int align) DBfoundOffset = foundOffset; DBfoundBlock = foundBlock; - if (foundBlock) - { - if (foundOffset >= sizeof(CMemBlock)) - { + if (foundBlock) { + if (foundOffset >= sizeof(CMemBlock)) { whatdo2++; CMemBlock* prev = foundBlock->mPrev; CMemBlock* next = foundBlock->mNext; newUsedBlock = foundBlock->allocFore(foundOffset - sizeof(CMemBlock), 0, 0, 0, 0); - if (newUsedBlock) - { + if (newUsedBlock) { whatdo2 += 2; newFreeBlock = newUsedBlock->allocFore(size, mCurrentGroupID, 0, 0, 0); - } - else - { + } else { newFreeBlock = nullptr; } - if (newFreeBlock) - { + if (newFreeBlock) { setFreeBlock(foundBlock, prev, newFreeBlock); - } - else - { + } else { setFreeBlock(foundBlock, prev, next); } - if (newFreeBlock) - { + if (newFreeBlock) { whatdo2 += 4; setFreeBlock(newFreeBlock, foundBlock, next); } @@ -245,8 +212,7 @@ void* JKRExpHeap::allocFromHead(u32 size, int align) return newUsedBlock->getContent(); } - if (foundOffset != 0) - { + if (foundOffset != 0) { whatdo2 += 0x10; CMemBlock* prev = foundBlock->mPrev; CMemBlock* next = foundBlock->mNext; @@ -254,24 +220,20 @@ void* JKRExpHeap::allocFromHead(u32 size, int align) newUsedBlock = (CMemBlock*)((u32)foundBlock + foundOffset); newUsedBlock->mAllocatedSpace = foundBlock->mAllocatedSpace - foundOffset; newFreeBlock = newUsedBlock->allocFore(size, mCurrentGroupID, (u8)foundOffset, 0, 0); - if (newFreeBlock) - { + if (newFreeBlock) { whatdo2 += 0x20; setFreeBlock(newFreeBlock, prev, next); } appendUsedList(newUsedBlock); whatdo2 += 0x40; return newUsedBlock->getContent(); - } - else - { + } else { whatdo2 += 0x80; CMemBlock* prev = foundBlock->mPrev; CMemBlock* next = foundBlock->mNext; newFreeBlock = foundBlock->allocFore(size, mCurrentGroupID, 0, 0, 0); removeFreeBlock(foundBlock); - if (newFreeBlock) - { + if (newFreeBlock) { whatdo2 += 0x100; setFreeBlock(newFreeBlock, prev, next); } @@ -285,48 +247,38 @@ void* JKRExpHeap::allocFromHead(u32 size, int align) return nullptr; } -void* JKRExpHeap::allocFromHead(u32 size) -{ +void* JKRExpHeap::allocFromHead(u32 size) { size = ALIGN_NEXT(size, 4); int foundSize = -1; CMemBlock* foundBlock = nullptr; - for (CMemBlock* block = mHead; block; block = block->mNext) - { - if (block->mAllocatedSpace < size) - { + for (CMemBlock* block = mHead; block; block = block->mNext) { + if (block->mAllocatedSpace < size) { continue; } - if (foundSize <= (u32)block->mAllocatedSpace) - { // TODO: figure out if mAllocatedSpace is u32 or not + if (foundSize <= (u32)block->mAllocatedSpace) { // TODO: figure out if mAllocatedSpace is u32 or not continue; } foundSize = block->mAllocatedSpace; foundBlock = block; - if (mCurrentAllocMode != 0) - { + if (mCurrentAllocMode != 0) { break; } - if (foundSize == size) - { + if (foundSize == size) { break; } } whatdo2++; - if (foundBlock) - { + if (foundBlock) { CMemBlock* newblock = foundBlock->allocFore(size, mCurrentGroupID, 0, 0, 0); whatdo2 += 2; - if (newblock) - { + if (newblock) { whatdo2 += 4; setFreeBlock(newblock, foundBlock->mPrev, foundBlock->mNext); - } - else - { + } else { whatdo2 += 8; removeFreeBlock(foundBlock); } @@ -339,46 +291,36 @@ void* JKRExpHeap::allocFromHead(u32 size) return nullptr; } -void* JKRExpHeap::allocFromTail(u32 size, int align) -{ +void* JKRExpHeap::allocFromTail(u32 size, int align) { u32 offset = 0; CMemBlock* foundBlock = nullptr; CMemBlock* newBlock = nullptr; u32 usedSize; u32 start; - for (CMemBlock* block = mTail; block; block = block->mPrev) - { + for (CMemBlock* block = mTail; block; block = block->mPrev) { start = ALIGN_PREV((u32)block->getContent() + block->mAllocatedSpace - size, align); usedSize = (u32)block->getContent() + block->mAllocatedSpace - start; - if (block->mAllocatedSpace >= usedSize) - { + if (block->mAllocatedSpace >= usedSize) { foundBlock = block; offset = block->mAllocatedSpace - usedSize; newBlock = (CMemBlock*)start - 1; break; } } - if (foundBlock != nullptr) - { - if (offset >= sizeof(CMemBlock)) - { + if (foundBlock != nullptr) { + if (offset >= sizeof(CMemBlock)) { newBlock->initiate(nullptr, nullptr, usedSize, mCurrentGroupID, -0x80); foundBlock->mAllocatedSpace = foundBlock->mAllocatedSpace - usedSize - sizeof(CMemBlock); appendUsedList(newBlock); return newBlock->getContent(); - } - else - { - if (offset != 0) - { + } else { + if (offset != 0) { removeFreeBlock(foundBlock); newBlock->initiate(nullptr, nullptr, usedSize, mCurrentGroupID, offset | 0x80); appendUsedList(newBlock); return newBlock->getContent(); - } - else - { + } else { removeFreeBlock(foundBlock); newBlock->initiate(nullptr, nullptr, usedSize, mCurrentGroupID, -0x80); appendUsedList(newBlock); @@ -389,34 +331,26 @@ void* JKRExpHeap::allocFromTail(u32 size, int align) return nullptr; } -void* JKRExpHeap::allocFromTail(u32 size) -{ +void* JKRExpHeap::allocFromTail(u32 size) { u32 size2 = ALIGN_NEXT(size, 4); CMemBlock* foundBlock = nullptr; - for (CMemBlock* block = mTail; block; block = block->mPrev) - { - if (block->mAllocatedSpace >= size2) - { + for (CMemBlock* block = mTail; block; block = block->mPrev) { + if (block->mAllocatedSpace >= size2) { foundBlock = block; break; } } - if (foundBlock != nullptr) - { + if (foundBlock != nullptr) { CMemBlock* usedBlock = foundBlock->allocBack(size2, 0, 0, mCurrentGroupID, 0); CMemBlock* freeBlock; - if (usedBlock) - { + if (usedBlock) { freeBlock = foundBlock; - } - else - { + } else { removeFreeBlock(foundBlock); usedBlock = foundBlock; freeBlock = nullptr; } - if (freeBlock) - { + if (freeBlock) { setFreeBlock(freeBlock, foundBlock->mPrev, foundBlock->mNext); } appendUsedList(usedBlock); @@ -425,41 +359,31 @@ void* JKRExpHeap::allocFromTail(u32 size) return nullptr; } -void JKRExpHeap::do_free(void* memblock) -{ +void JKRExpHeap::do_free(void* memblock) { lock(); - if (mStart <= memblock && memblock <= mEnd) - { + if (mStart <= memblock && memblock <= mEnd) { CMemBlock* block = CMemBlock::getHeapBlock(memblock); - if (block != nullptr) - { + if (block != nullptr) { block->free(this); } - } - else - { + } else { JUT_WARNING_F("free: memblock %x not in heap %x", memblock, this); } unlock(); } -int JKRExpHeap::freeGroup(u8 groupID) -{ +int JKRExpHeap::freeGroup(u8 groupID) { lock(); CMemBlock* block = mHeadUsedList; int count = 0; - while (block != nullptr) - { - if (block->mGroupID == groupID) - { + while (block != nullptr) { + if (block->mGroupID == groupID) { dispose(block + 1, block->mAllocatedSpace); CMemBlock* temp = block->mNext; block->free(this); count++; block = temp; - } - else - { + } else { block = block->mNext; } } @@ -467,8 +391,7 @@ int JKRExpHeap::freeGroup(u8 groupID) return count; } -void JKRExpHeap::do_freeAll() -{ +void JKRExpHeap::do_freeAll() { lock(); JKRHeap::callAllDisposer(); mHead = (CMemBlock*)mStart; @@ -479,80 +402,61 @@ void JKRExpHeap::do_freeAll() unlock(); } -void JKRExpHeap::do_freeTail() -{ +void JKRExpHeap::do_freeTail() { lock(); - for (CMemBlock* block = mHeadUsedList; block != nullptr;) - { - if ((block->mFlags & 0x80) != 0) - { + for (CMemBlock* block = mHeadUsedList; block != nullptr;) { + if ((block->mFlags & 0x80) != 0) { dispose(block + 1, block->mAllocatedSpace); CMemBlock* temp = block->mNext; block->free(this); block = temp; - } - else - { + } else { block = block->mNext; } } unlock(); } -s32 JKRExpHeap::do_resize(void* ptr, u32 size) -{ +s32 JKRExpHeap::do_resize(void* ptr, u32 size) { lock(); CMemBlock* block = CMemBlock::getHeapBlock(ptr); - if (block == nullptr || ptr < mStart || mEnd < ptr) - { + if (block == nullptr || ptr < mStart || mEnd < ptr) { unlock(); return -1; } size = ALIGN_NEXT(size, 4); - if (size == block->mAllocatedSpace) - { + if (size == block->mAllocatedSpace) { unlock(); return size; } - if (size > block->mAllocatedSpace) - { + if (size > block->mAllocatedSpace) { CMemBlock* foundBlock = nullptr; - for (CMemBlock* freeBlock = mHead; freeBlock; freeBlock = freeBlock->mNext) - { - if (freeBlock == (CMemBlock*)((u32)(block + 1) + block->mAllocatedSpace)) - { + for (CMemBlock* freeBlock = mHead; freeBlock; freeBlock = freeBlock->mNext) { + if (freeBlock == (CMemBlock*)((u32)(block + 1) + block->mAllocatedSpace)) { foundBlock = freeBlock; break; } } - if (foundBlock == nullptr) - { + if (foundBlock == nullptr) { unlock(); return -1; } - if (size > block->mAllocatedSpace + sizeof(CMemBlock) + foundBlock->mAllocatedSpace) - { + if (size > block->mAllocatedSpace + sizeof(CMemBlock) + foundBlock->mAllocatedSpace) { unlock(); return -1; } removeFreeBlock(foundBlock); block->mAllocatedSpace += foundBlock->mAllocatedSpace + sizeof(CMemBlock); - if (block->mAllocatedSpace - size > sizeof(CMemBlock)) - { + if (block->mAllocatedSpace - size > sizeof(CMemBlock)) { CMemBlock* newBlock = block->allocFore(size, block->mGroupID, block->mFlags, 0, 0); - if (newBlock) - { + if (newBlock) { recycleFreeBlock(newBlock); } } - } - else - { - if (block->mAllocatedSpace - size > sizeof(CMemBlock)) - { + } else { + if (block->mAllocatedSpace - size > sizeof(CMemBlock)) { CMemBlock* freeBlock = block->allocFore(size, block->mGroupID, block->mFlags, 0, 0); - if (freeBlock) - { + if (freeBlock) { recycleFreeBlock(freeBlock); } } @@ -561,12 +465,10 @@ s32 JKRExpHeap::do_resize(void* ptr, u32 size) return block->mAllocatedSpace; } -s32 JKRExpHeap::do_getSize(void* ptr) -{ +s32 JKRExpHeap::do_getSize(void* ptr) { lock(); CMemBlock* block = CMemBlock::getHeapBlock(ptr); - if (block == nullptr || ptr < mStart || mEnd < ptr) - { + if (block == nullptr || ptr < mStart || mEnd < ptr) { unlock(); return -1; } @@ -574,12 +476,10 @@ s32 JKRExpHeap::do_getSize(void* ptr) return block->mAllocatedSpace; } -s32 JKRExpHeap::do_getFreeSize() -{ +s32 JKRExpHeap::do_getFreeSize() { lock(); int maxFreeSize = 0; - for (CMemBlock* block = mHead; block != nullptr; block = block->mNext) - { + for (CMemBlock* block = mHead; block != nullptr; block = block->mNext) { if (maxFreeSize < block->mAllocatedSpace) maxFreeSize = block->mAllocatedSpace; } @@ -587,28 +487,23 @@ s32 JKRExpHeap::do_getFreeSize() return maxFreeSize; } -s32 JKRExpHeap::do_getTotalFreeSize() -{ +s32 JKRExpHeap::do_getTotalFreeSize() { int freeSize = 0; lock(); - for (CMemBlock* block = mHead; block != nullptr; block = block->mNext) - { + for (CMemBlock* block = mHead; block != nullptr; block = block->mNext) { freeSize += block->mAllocatedSpace; } unlock(); return freeSize; } -s32 JKRExpHeap::getUsedSize(u8 groupId) const -{ +s32 JKRExpHeap::getUsedSize(u8 groupId) const { JKRExpHeap* this2 = const_cast(this); this2->lock(); u32 size = 0; - for (CMemBlock* block = mHeadUsedList; block; block = block->mNext) - { + for (CMemBlock* block = mHeadUsedList; block; block = block->mNext) { u8 blockGroupId = block->mGroupID; - if (blockGroupId == groupId) - { + if (blockGroupId == groupId) { size += block->mAllocatedSpace + sizeof(CMemBlock); } } @@ -616,84 +511,64 @@ s32 JKRExpHeap::getUsedSize(u8 groupId) const return size; } -bool JKRExpHeap::isEmpty() -{ +bool JKRExpHeap::isEmpty() { u32 newSize; - #line 1269 JUT_ASSERT(newSize > 0); return true; } -bool JKRExpHeap::check() -{ +bool JKRExpHeap::check() { lock(); int totalBytes = 0; bool ok = true; - for (CMemBlock* block = mHeadUsedList; block; block = block->mNext) - { - if (!block->isValid()) - { + for (CMemBlock* block = mHeadUsedList; block; block = block->mNext) { + if (!block->isValid()) { ok = false; JUTWarningConsole_f(":::addr %08x: bad heap signature. (%c%c)\n", block, JSUHiByte(block->mUsageHeader), - JSULoByte(block->mUsageHeader)); + JSULoByte(block->mUsageHeader)); } - if (block->mNext) - { - if (!block->mNext->isValid()) - { + if (block->mNext) { + if (!block->mNext->isValid()) { ok = false; JUTWarningConsole_f(":::addr %08x: bad next pointer (%08x)\nabort\n", block, block->mNext); break; } - if (block->mNext->mPrev != block) - { + if (block->mNext->mPrev != block) { ok = false; JUTWarningConsole_f(":::addr %08x: bad previous pointer (%08x)\n", block->mNext, block->mNext->mPrev); } - } - else - { - if (mTailUsedList != block) - { + } else { + if (mTailUsedList != block) { ok = false; JUTWarningConsole_f(":::addr %08x: bad used list(REV) (%08x)\n", block, mTailUsedList); } } totalBytes += sizeof(CMemBlock) + block->mAllocatedSpace + block->getAlignment(); } - for (CMemBlock* block = mHead; block; block = block->mNext) - { + for (CMemBlock* block = mHead; block; block = block->mNext) { totalBytes += block->mAllocatedSpace + sizeof(CMemBlock); - if (block->mNext) - { - if (block->mNext->mPrev != block) - { + if (block->mNext) { + if (block->mNext->mPrev != block) { ok = false; JUTWarningConsole_f(":::addr %08x: bad previous pointer (%08x)\n", block->mNext, block->mNext->mPrev); } - if ((u32)block + block->mAllocatedSpace + sizeof(CMemBlock) > (u32)block->mNext) - { + if ((u32)block + block->mAllocatedSpace + sizeof(CMemBlock) > (u32)block->mNext) { ok = false; JUTWarningConsole_f(":::addr %08x: bad block size (%08x)\n", block, block->mAllocatedSpace); } - } - else - { - if (mTail != block) - { + } else { + if (mTail != block) { ok = false; JUTWarningConsole_f(":::addr %08x: bad used list(REV) (%08x)\n", block, mTail); } } } - if (totalBytes != mSize) - { + if (totalBytes != mSize) { ok = false; JUTWarningConsole_f(":::bad total memory block size (%08X, %08X)\n", mSize, totalBytes); } - if (!ok) - { + if (!ok) { JUTWarningConsole(":::there is some error in this heap!\n"); } @@ -701,59 +576,45 @@ bool JKRExpHeap::check() return ok; } -void JKRExpHeap::appendUsedList(JKRExpHeap::CMemBlock* blockToAppend) -{ - if (!blockToAppend) - { +void JKRExpHeap::appendUsedList(JKRExpHeap::CMemBlock* blockToAppend) { + if (!blockToAppend) { JPANIC(1543, ":::ERROR! appendUsedList\n"); } CMemBlock* block = mTailUsedList; CMemBlock* tail = mTailUsedList; blockToAppend->mUsageHeader = 'HM'; - if (tail) - { + if (tail) { tail->mNext = blockToAppend; blockToAppend->mPrev = tail; - } - else - { + } else { blockToAppend->mPrev = nullptr; } mTailUsedList = blockToAppend; - if (!mHeadUsedList) - { + if (!mHeadUsedList) { mHeadUsedList = blockToAppend; } blockToAppend->mNext = nullptr; } -void JKRExpHeap::setFreeBlock(JKRExpHeap::CMemBlock* p1, JKRExpHeap::CMemBlock* p2, JKRExpHeap::CMemBlock* p3) -{ - if (p2 == nullptr) - { +void JKRExpHeap::setFreeBlock(JKRExpHeap::CMemBlock* p1, JKRExpHeap::CMemBlock* p2, JKRExpHeap::CMemBlock* p3) { + if (p2 == nullptr) { mHead = p1; p1->mPrev = nullptr; - } - else - { + } else { p2->mNext = p1; p1->mPrev = p2; } - if (p3 == nullptr) - { + if (p3 == nullptr) { mTail = p1; p1->mNext = nullptr; - } - else - { + } else { p3->mPrev = p1; p1->mNext = p3; } p1->mUsageHeader = 0; } -void JKRExpHeap::removeFreeBlock(JKRExpHeap::CMemBlock* blockToRemove) -{ +void JKRExpHeap::removeFreeBlock(JKRExpHeap::CMemBlock* blockToRemove) { CMemBlock* prev = blockToRemove->mPrev; CMemBlock* next = blockToRemove->mNext; if (prev == nullptr) @@ -766,8 +627,7 @@ void JKRExpHeap::removeFreeBlock(JKRExpHeap::CMemBlock* blockToRemove) next->mPrev = prev; } -void JKRExpHeap::removeUsedBlock(JKRExpHeap::CMemBlock* blockToRemove) -{ +void JKRExpHeap::removeUsedBlock(JKRExpHeap::CMemBlock* blockToRemove) { // UNUSED FUNCTION CMemBlock* prev = blockToRemove->mPrev; CMemBlock* next = blockToRemove->mNext; @@ -781,16 +641,14 @@ void JKRExpHeap::removeUsedBlock(JKRExpHeap::CMemBlock* blockToRemove) next->mPrev = prev; } -void JKRExpHeap::recycleFreeBlock(JKRExpHeap::CMemBlock* block) -{ +void JKRExpHeap::recycleFreeBlock(JKRExpHeap::CMemBlock* block) { JKRExpHeap::CMemBlock* newBlock = block; int size = block->mAllocatedSpace; void* blockEnd = (u8*)block + size; block->mUsageHeader = 0; // int offset = block->mFlags & 0x7f; - if ((u32)(block->mFlags & 0x7f) != 0) - { + if ((u32)(block->mFlags & 0x7f) != 0) { newBlock = (CMemBlock*)((u8*)block - (block->mFlags & 0x7f)); size += (block->mFlags & 0x7f); blockEnd = (u8*)newBlock + size; @@ -799,32 +657,27 @@ void JKRExpHeap::recycleFreeBlock(JKRExpHeap::CMemBlock* block) newBlock->mAllocatedSpace = size; } - if (!mHead) - { + if (!mHead) { newBlock->initiate(nullptr, nullptr, size, 0, 0); mHead = newBlock; mTail = newBlock; setFreeBlock(newBlock, nullptr, nullptr); return; } - if (mHead >= blockEnd) - { + if (mHead >= blockEnd) { newBlock->initiate(nullptr, nullptr, size, 0, 0); setFreeBlock(newBlock, nullptr, mHead); joinTwoBlocks(newBlock); return; } - if (mTail <= newBlock) - { + if (mTail <= newBlock) { newBlock->initiate(nullptr, nullptr, size, 0, 0); setFreeBlock(newBlock, mTail, nullptr); joinTwoBlocks(newBlock->mPrev); return; } - for (CMemBlock* freeBlock = mHead; freeBlock; freeBlock = freeBlock->mNext) - { - if (freeBlock >= newBlock || newBlock >= freeBlock->mNext) - { + for (CMemBlock* freeBlock = mHead; freeBlock; freeBlock = freeBlock->mNext) { + if (freeBlock >= newBlock || newBlock >= freeBlock->mNext) { continue; } newBlock->mNext = freeBlock->mNext; @@ -840,8 +693,7 @@ void JKRExpHeap::recycleFreeBlock(JKRExpHeap::CMemBlock* block) // This functions doesn't match for the debug build, however functionality wise it's the same // https://decomp.me/scratch/UOwNi -void JKRExpHeap::joinTwoBlocks(CMemBlock* block) -{ +void JKRExpHeap::joinTwoBlocks(CMemBlock* block) { // for some reason this gets rid of regswaps for the debug version, however is most likely incorrect // u32 endAddr; // u32 nextAddr; @@ -850,25 +702,24 @@ void JKRExpHeap::joinTwoBlocks(CMemBlock* block) u32 endAddr = (u32)(block + 1) + block->mAllocatedSpace; CMemBlock* next = block->mNext; u32 nextAddr = (u32)next - (next->mFlags & 0x7f); - if (endAddr > nextAddr) - { + if (endAddr > nextAddr) { JUTWarningConsole_f(":::Heap may be broken. (block = %x)", block); JREPORTF(":::block = %x\n", block); - JREPORTF(":::joinTwoBlocks [%x %x %x][%x %x %x]\n", block, block->mFlags, block->mAllocatedSpace, block->mNext, block->mNext->mFlags, block->mNext->mAllocatedSpace); + JREPORTF(":::joinTwoBlocks [%x %x %x][%x %x %x]\n", block, block->mFlags, block->mAllocatedSpace, block->mNext, + block->mNext->mFlags, block->mNext->mAllocatedSpace); JREPORTF(":::: endAddr = %x\n", endAddr); JREPORTF(":::: nextAddr = %x\n", nextAddr); JKRGetCurrentHeap()->dump(); JPANIC(1824, ":::: Bad Block\n"); } - if (endAddr == nextAddr) - { - block->mAllocatedSpace = next->mAllocatedSpace + sizeof(CMemBlock) + (next->mFlags & 0x7f) + block->mAllocatedSpace; + if (endAddr == nextAddr) { + block->mAllocatedSpace = + next->mAllocatedSpace + sizeof(CMemBlock) + (next->mFlags & 0x7f) + block->mAllocatedSpace; setFreeBlock(block, block->mPrev, next->mNext); } } -bool JKRExpHeap::dump() -{ +bool JKRExpHeap::dump() { lock(); bool result = check(); u32 usedBytes = 0; @@ -876,32 +727,28 @@ bool JKRExpHeap::dump() u32 freeCount = 0; JUTReportConsole(" attr address: size gid aln prev_ptr next_ptr\n"); JUTReportConsole("(Used Blocks)\n"); - if (!mHeadUsedList) - { + if (!mHeadUsedList) { JUTReportConsole(" NONE\n"); } - for (CMemBlock* block = mHeadUsedList; block; block = block->mNext) - { - if (!block->isValid()) - { + for (CMemBlock* block = mHeadUsedList; block; block = block->mNext) { + if (!block->isValid()) { JUTReportConsole_f("xxxxx %08x: -------- --- --- (-------- --------)\nabort\n", block); break; } - JUTReportConsole_f("%s %08x: %08x %3d %3d (%08x %08x)\n", block->_isTempMemBlock() ? " temp" : "alloc", block->getContent(), - block->mAllocatedSpace, block->mGroupID, block->getAlignment(), block->mPrev, block->mNext); + JUTReportConsole_f("%s %08x: %08x %3d %3d (%08x %08x)\n", block->_isTempMemBlock() ? " temp" : "alloc", + block->getContent(), block->mAllocatedSpace, block->mGroupID, block->getAlignment(), + block->mPrev, block->mNext); usedBytes += sizeof(CMemBlock) + block->mAllocatedSpace + block->getAlignment(); usedCount++; } JUTReportConsole("(Free Blocks)\n"); - if (!mHead) - { + if (!mHead) { JUTReportConsole(" NONE\n"); } - for (CMemBlock* block = mHead; block; block = block->mNext) - { - JUTReportConsole_f("%s %08x: %08x %3d %3d (%08x %08x)\n", " free", block->getContent(), block->mAllocatedSpace, block->mGroupID, - block->getAlignment(), block->mPrev, block->mNext); + for (CMemBlock* block = mHead; block; block = block->mNext) { + JUTReportConsole_f("%s %08x: %08x %3d %3d (%08x %08x)\n", " free", block->getContent(), + block->mAllocatedSpace, block->mGroupID, block->getAlignment(), block->mPrev, block->mNext); freeCount++; } float percent = ((float)usedBytes / (float)mSize) * 100.0f; @@ -910,8 +757,7 @@ bool JKRExpHeap::dump() return result; } -bool JKRExpHeap::dump_sort() -{ +bool JKRExpHeap::dump_sort() { lock(); bool result = check(); u32 usedBytes = 0; @@ -919,51 +765,41 @@ bool JKRExpHeap::dump_sort() u32 freeCount = 0; JUTReportConsole(" attr address: size gid aln prev_ptr next_ptr\n"); JUTReportConsole("(Used Blocks)\n"); - if (mHeadUsedList == nullptr) - { + if (mHeadUsedList == nullptr) { JUTReportConsole(" NONE\n"); - } - else - { + } else { CMemBlock* var1 = nullptr; - while (true) - { + while (true) { CMemBlock* block = (CMemBlock*)0xffffffff; - for (CMemBlock* iterBlock = mHeadUsedList; iterBlock; iterBlock = iterBlock->mNext) - { - if (var1 < iterBlock && iterBlock < block) - { + for (CMemBlock* iterBlock = mHeadUsedList; iterBlock; iterBlock = iterBlock->mNext) { + if (var1 < iterBlock && iterBlock < block) { block = iterBlock; } } - if (block == (CMemBlock*)0xffffffff) - { + if (block == (CMemBlock*)0xffffffff) { break; } - if (!block->isValid()) - { + if (!block->isValid()) { JUTReportConsole_f("xxxxx %08x: -------- --- --- (-------- --------)\nabort\n"); break; } int offset = block->getAlignment(); void* content = block->getContent(); const char* type = block->_isTempMemBlock() ? " temp" : "alloc"; - JUTReportConsole_f("%s %08x: %08x %3d %3d (%08x %08x)\n", type, content, block->mAllocatedSpace, block->mGroupID, offset, - block->mPrev, block->mNext); + JUTReportConsole_f("%s %08x: %08x %3d %3d (%08x %08x)\n", type, content, block->mAllocatedSpace, + block->mGroupID, offset, block->mPrev, block->mNext); usedBytes += sizeof(CMemBlock) + block->mAllocatedSpace + block->getAlignment(); usedCount++; var1 = block; } } JUTReportConsole("(Free Blocks)\n"); - if (mHead == nullptr) - { + if (mHead == nullptr) { JUTReportConsole(" NONE\n"); } - for (CMemBlock* block = mHead; block; block = block->mNext) - { - JUTReportConsole_f("%s %08x: %08x %3d %3d (%08x %08x)\n", " free", block->getContent(), block->mAllocatedSpace, block->mGroupID, - block->getAlignment(), block->mPrev, block->mNext); + for (CMemBlock* block = mHead; block; block = block->mNext) { + JUTReportConsole_f("%s %08x: %08x %3d %3d (%08x %08x)\n", " free", block->getContent(), + block->mAllocatedSpace, block->mGroupID, block->getAlignment(), block->mPrev, block->mNext); freeCount++; } float percent = ((float)usedBytes / (float)mSize) * 100.0f; @@ -973,8 +809,7 @@ bool JKRExpHeap::dump_sort() } // these didn't get deadstripped, workaround to generate it -static void genData() -{ +static void genData() { JUTWarningConsole_f("+---------------JKRExpHeap\n"); JUTWarningConsole_f("| Align Group size ( prev , next )\n"); JUTWarningConsole_f("| ---- FreeFirst\n"); @@ -986,8 +821,8 @@ static void genData() JUTWarningConsole_f("+---------------End\n"); } -void JKRExpHeap::CMemBlock::initiate(JKRExpHeap::CMemBlock* prev, JKRExpHeap::CMemBlock* next, u32 size, u8 groupID, u8 alignment) -{ +void JKRExpHeap::CMemBlock::initiate(JKRExpHeap::CMemBlock* prev, JKRExpHeap::CMemBlock* next, u32 size, u8 groupID, + u8 alignment) { mUsageHeader = 'HM'; mFlags = alignment; mGroupID = groupID; @@ -996,13 +831,12 @@ void JKRExpHeap::CMemBlock::initiate(JKRExpHeap::CMemBlock* prev, JKRExpHeap::CM mNext = next; } -JKRExpHeap::CMemBlock* JKRExpHeap::CMemBlock::allocFore(u32 size, u8 groupId1, u8 alignment1, u8 groupId2, u8 alignment2) -{ +JKRExpHeap::CMemBlock* JKRExpHeap::CMemBlock::allocFore(u32 size, u8 groupId1, u8 alignment1, u8 groupId2, + u8 alignment2) { CMemBlock* block = nullptr; mGroupID = groupId1; mFlags = alignment1; - if (mAllocatedSpace >= size + sizeof(CMemBlock)) - { + if (mAllocatedSpace >= size + sizeof(CMemBlock)) { block = (CMemBlock*)(size + (u32)this); block = block + 1; block->mGroupID = groupId2; @@ -1014,11 +848,9 @@ JKRExpHeap::CMemBlock* JKRExpHeap::CMemBlock::allocFore(u32 size, u8 groupId1, u } JKRExpHeap::CMemBlock* JKRExpHeap::CMemBlock::allocBack(unsigned long size, unsigned char groupID, unsigned char p3, - unsigned char allocGroupID, unsigned char p5) -{ + unsigned char allocGroupID, unsigned char p5) { CMemBlock* newBlock = nullptr; - if (mAllocatedSpace >= size + sizeof(CMemBlock)) - { + if (mAllocatedSpace >= size + sizeof(CMemBlock)) { newBlock = reinterpret_cast(mAllocatedSpace + reinterpret_cast(this) - size); newBlock->mGroupID = allocGroupID; newBlock->mFlags = p5 | 0x80; @@ -1026,74 +858,57 @@ JKRExpHeap::CMemBlock* JKRExpHeap::CMemBlock::allocBack(unsigned long size, unsi mGroupID = groupID; mFlags = p3; mAllocatedSpace -= (size + sizeof(CMemBlock)); - } - else - { + } else { mGroupID = allocGroupID; mFlags = 0x80; } return newBlock; } -void* JKRExpHeap::CMemBlock::free(JKRExpHeap* heap) -{ +void* JKRExpHeap::CMemBlock::free(JKRExpHeap* heap) { heap->removeUsedBlock(this); heap->recycleFreeBlock(this); return nullptr; } -JKRExpHeap::CMemBlock* JKRExpHeap::CMemBlock::getHeapBlock(void* mem) -{ - if (mem != nullptr && (static_cast(mem) - 1)->mUsageHeader == 0x484D) - { +JKRExpHeap::CMemBlock* JKRExpHeap::CMemBlock::getHeapBlock(void* mem) { + if (mem != nullptr && (static_cast(mem) - 1)->mUsageHeader == 0x484D) { return static_cast(mem) - 1; } return nullptr; } -void JKRExpHeap::state_register(JKRHeap::TState* p, u32 param_1) const -{ +void JKRExpHeap::state_register(JKRHeap::TState* p, u32 param_1) const { JUT_ASSERT(p != 0); JUT_ASSERT(p->getHeap() == this); getState_(p); // not needed, however TP debug has it setState_u32ID_(p, param_1); - if (param_1 <= 0xff) - { + if (param_1 <= 0xff) { setState_uUsedSize_(p, getUsedSize(param_1)); - } - else - { + } else { setState_uUsedSize_(p, getUsedSize_((JKRExpHeap*)this)); } u32 checkCode = 0; - for (CMemBlock* block = mHeadUsedList; block; block = block->mNext) - { - if (param_1 <= 0xff) - { + for (CMemBlock* block = mHeadUsedList; block; block = block->mNext) { + if (param_1 <= 0xff) { u8 groupId = block->mGroupID; - if (groupId == param_1) - { + if (groupId == param_1) { checkCode += (u32)block * 3; } - } - else - { + } else { checkCode += (u32)block * 3; } } setState_u32CheckCode_(p, checkCode); } -bool JKRExpHeap::state_compare(const JKRHeap::TState& r1, const JKRHeap::TState& r2) const -{ +bool JKRExpHeap::state_compare(const JKRHeap::TState& r1, const JKRHeap::TState& r2) const { JUT_ASSERT(r1.getHeap() == r2.getHeap()); bool result = true; - if (r1.mCheckCode != r2.mCheckCode) - { + if (r1.mCheckCode != r2.mCheckCode) { result = false; } - if (r1.mUsedSize != r2.mUsedSize) - { + if (r1.mUsedSize != r2.mUsedSize) { result = false; } return result; diff --git a/src/static/JSystem/JKernel/JKRFile.cpp b/src/static/JSystem/JKernel/JKRFile.cpp index cb06f045..8fb0fae7 100644 --- a/src/static/JSystem/JKernel/JKRFile.cpp +++ b/src/static/JSystem/JKernel/JKRFile.cpp @@ -28,16 +28,16 @@ */ void JKRFile::read(void* data, s32 length, s32 ofs) { #ifdef JSYSTEM_DEBUG - if (!JKR_ISALIGNED(length, 32)) { - JUTAssertion::showAssert(JUTAssertion::getSDevice(), __FILE__, __LINE__, "( length & 0x1f ) == 0"); - } + if (!JKR_ISALIGNED(length, 32)) { + JUTAssertion::showAssert(JUTAssertion::getSDevice(), __FILE__, __LINE__, "( length & 0x1f ) == 0"); + } #endif - while (true) { - if (this->readData(data, length, ofs) == length) { - return; - } + while (true) { + if (this->readData(data, length, ofs) == length) { + return; + } - VIWaitForRetrace(); - } + VIWaitForRetrace(); + } } diff --git a/src/static/JSystem/JKernel/JKRFileFinder.cpp b/src/static/JSystem/JKernel/JKRFileFinder.cpp index 71683dc1..bae5f0b2 100644 --- a/src/static/JSystem/JKernel/JKRFileFinder.cpp +++ b/src/static/JSystem/JKernel/JKRFileFinder.cpp @@ -2,8 +2,7 @@ #include "JSystem/JKernel/JKRFileFinder.h" #include "JSystem/JKernel/JKRArchive.h" -JKRArcFinder::JKRArcFinder(JKRArchive* archive, long startindex, long entries) : JKRFileFinder() -{ +JKRArcFinder::JKRArcFinder(JKRArchive* archive, long startindex, long entries) : JKRFileFinder() { mArchive = archive; mIsAvailable = entries > 0; @@ -14,13 +13,10 @@ JKRArcFinder::JKRArcFinder(JKRArchive* archive, long startindex, long entries) : findNextFile(); } -bool JKRArcFinder::findNextFile() -{ - if (mIsAvailable) - { +bool JKRArcFinder::findNextFile() { + if (mIsAvailable) { mIsAvailable = (mNextIndex <= mEndIndex); - if (mIsAvailable) - { + if (mIsAvailable) { JKRArchive::SDirEntry dirEntry; mIsAvailable = mArchive->getDirEntry(&dirEntry, mNextIndex); mBase.mFileName = dirEntry.mName; @@ -35,22 +31,18 @@ bool JKRArcFinder::findNextFile() } // UNUSED -JKRDvdFinder::JKRDvdFinder(const char* path) : JKRFileFinder() -{ +JKRDvdFinder::JKRDvdFinder(const char* path) : JKRFileFinder() { mIsDvdOpen = DVDOpenDir(const_cast(path), &mDir); mIsAvailable = mIsDvdOpen; findNextFile(); } // UNUSED, not sure if it matches -bool JKRDvdFinder::findNextFile() -{ - if (mIsAvailable) - { +bool JKRDvdFinder::findNextFile() { + if (mIsAvailable) { DVDDirEntry entry; mIsAvailable = DVDReadDir(&mDir, &entry); - if (mIsAvailable) - { + if (mIsAvailable) { mIsDir = (bool)entry.isDir; mBase.mFileName = entry.name; mBase.mFileIndex = entry.entryNum; diff --git a/src/static/JSystem/JKernel/JKRFileLoader.cpp b/src/static/JSystem/JKernel/JKRFileLoader.cpp index 98b52ca6..d6400e0d 100644 --- a/src/static/JSystem/JKernel/JKRFileLoader.cpp +++ b/src/static/JSystem/JKernel/JKRFileLoader.cpp @@ -5,55 +5,46 @@ JSUList JKRFileLoader::sVolumeList; JKRFileLoader* JKRFileLoader::sCurrentVolume; -JKRFileLoader::JKRFileLoader() : JKRDisposer(), mFileLoaderLink(this) -{ +JKRFileLoader::JKRFileLoader() : JKRDisposer(), mFileLoaderLink(this) { mVolumeName = nullptr; mVolumeType = 0; mMountCount = 0; } -JKRFileLoader::~JKRFileLoader() -{ +JKRFileLoader::~JKRFileLoader() { if (sCurrentVolume == this) sCurrentVolume = nullptr; } -void JKRFileLoader::unmount() -{ - if (mMountCount != 0) - { +void JKRFileLoader::unmount() { + if (mMountCount != 0) { if (--mMountCount == 0) delete this; } } -void JKRFileLoader::changeDirectory(const char* dir) -{ +void JKRFileLoader::changeDirectory(const char* dir) { JKRFileLoader* vol = findVolume(&dir); if (vol) vol->becomeCurrent(dir); } -void* JKRFileLoader::getGlbResource(const char* path) -{ +void* JKRFileLoader::getGlbResource(const char* path) { const char* components[2]; components[0] = path; JKRFileLoader* loader = findVolume(components); return (loader == nullptr) ? nullptr : loader->getResource(components[0]); } -void* JKRFileLoader::getGlbResource(const char* name, JKRFileLoader* fileLoader) -{ +void* JKRFileLoader::getGlbResource(const char* name, JKRFileLoader* fileLoader) { void* resource = nullptr; - if (fileLoader) - { + if (fileLoader) { return fileLoader->getResource(0, name); } JSUList& volumeList = getVolumeList(); JSUListIterator iterator; - for (iterator = volumeList.getFirst(); iterator != volumeList.getEnd(); ++iterator) - { + for (iterator = volumeList.getFirst(); iterator != volumeList.getEnd(); ++iterator) { resource = iterator->getResource(0, name); if (resource) break; @@ -61,24 +52,20 @@ void* JKRFileLoader::getGlbResource(const char* name, JKRFileLoader* fileLoader) return resource; } -size_t JKRFileLoader::readGlbResource(void* resBuf, u32 bufSize, const char* volumeName, JKRExpandSwitch expandSwitch) -{ +size_t JKRFileLoader::readGlbResource(void* resBuf, u32 bufSize, const char* volumeName, JKRExpandSwitch expandSwitch) { JKRFileLoader* vol = findVolume(&volumeName); return vol == nullptr ? 0 : vol->readResource(resBuf, bufSize, volumeName, expandSwitch); } -bool JKRFileLoader::removeResource(void* resourceBuffer, JKRFileLoader* fileLoader) -{ - if (fileLoader) - { +bool JKRFileLoader::removeResource(void* resourceBuffer, JKRFileLoader* fileLoader) { + if (fileLoader) { return fileLoader->removeResource(resourceBuffer); } JSUList& volumeList = getVolumeList(); JSUListIterator iterator; - for (iterator = volumeList.getFirst(); iterator != volumeList.getEnd(); ++iterator) - { + for (iterator = volumeList.getFirst(); iterator != volumeList.getEnd(); ++iterator) { if (iterator->removeResource(resourceBuffer)) return true; } @@ -86,17 +73,14 @@ bool JKRFileLoader::removeResource(void* resourceBuffer, JKRFileLoader* fileLoad return false; } -bool JKRFileLoader::detachResource(void* resourceBuffer, JKRFileLoader* fileLoader) -{ - if (fileLoader) - { +bool JKRFileLoader::detachResource(void* resourceBuffer, JKRFileLoader* fileLoader) { + if (fileLoader) { return fileLoader->detachResource(resourceBuffer); } JSUList& volumeList = getVolumeList(); JSUListIterator iterator; - for (iterator = volumeList.getFirst(); iterator != volumeList.getEnd(); ++iterator) - { + for (iterator = volumeList.getFirst(); iterator != volumeList.getEnd(); ++iterator) { if (iterator->detachResource(resourceBuffer)) return true; } @@ -104,10 +88,8 @@ bool JKRFileLoader::detachResource(void* resourceBuffer, JKRFileLoader* fileLoad return false; } -JKRFileLoader* JKRFileLoader::findVolume(const char** volumeName) -{ - if (*volumeName[0] != '/') - { +JKRFileLoader* JKRFileLoader::findVolume(const char** volumeName) { + if (*volumeName[0] != '/') { return sCurrentVolume; } @@ -116,16 +98,14 @@ JKRFileLoader* JKRFileLoader::findVolume(const char** volumeName) JSUList& volumeList = sVolumeList; JSUListIterator iterator; - for (iterator = volumeList.getFirst(); iterator != volumeList.getEnd(); ++iterator) - { + for (iterator = volumeList.getFirst(); iterator != volumeList.getEnd(); ++iterator) { if (strcmp(volumeNameBuffer, iterator->mVolumeName) == 0) return iterator.getObject(); } return nullptr; } -JKRFileFinder* JKRFileLoader::findFirstFile(const char* volumeName) -{ +JKRFileFinder* JKRFileLoader::findFirstFile(const char* volumeName) { JKRFileFinder* ret = nullptr; JKRFileLoader* vol = findVolume(&volumeName); @@ -135,21 +115,15 @@ JKRFileFinder* JKRFileLoader::findFirstFile(const char* volumeName) return ret; } -const char* JKRFileLoader::fetchVolumeName(char* buffer, long bufferSize, const char* path) -{ +const char* JKRFileLoader::fetchVolumeName(char* buffer, long bufferSize, const char* path) { static char rootPath[] = "/"; - if (strcmp(path, "/") == 0) - { + if (strcmp(path, "/") == 0) { strcpy(buffer, rootPath); return rootPath; - } - else - { + } else { path++; - while (*path != 0 && *path != '/') - { - if (1 < bufferSize) - { + while (*path != 0 && *path != '/') { + if (1 < bufferSize) { *buffer = _tolower(*path); buffer++; bufferSize--; diff --git a/src/static/JSystem/JKernel/JKRHeap.cpp b/src/static/JSystem/JKernel/JKRHeap.cpp index 811773bb..49efe192 100644 --- a/src/static/JSystem/JKernel/JKRHeap.cpp +++ b/src/static/JSystem/JKernel/JKRHeap.cpp @@ -19,21 +19,16 @@ u32 JKRHeap::mMemorySize; bool JKRHeap::sDefaultFillFlag = true; -JKRHeap::JKRHeap(void* data, u32 size, JKRHeap* heap, bool errorFlag) : JKRDisposer(), -mChildTree(this), -mDisposerList() -{ +JKRHeap::JKRHeap(void* data, u32 size, JKRHeap* heap, bool errorFlag) + : JKRDisposer(), mChildTree(this), mDisposerList() { OSInitMutex(&mMutex); mSize = size; mStart = (u8*)data; mEnd = ((u8*)data + size); - if (heap == nullptr) - { + if (heap == nullptr) { becomeSystemHeap(); becomeCurrentHeap(); - } - else - { + } else { heap->mChildTree.appendChild(&mChildTree); if (sSystemHeap == sRootHeap) becomeSystemHeap(); @@ -47,8 +42,7 @@ mDisposerList() mInitFlag = false; } -JKRHeap::~JKRHeap() -{ +JKRHeap::~JKRHeap() { mChildTree.getParent()->removeChild(&mChildTree); JSUTree* nextRootHeap = sRootHeap->mChildTree.getFirstChild(); if (sCurrentHeap == this) @@ -58,12 +52,10 @@ JKRHeap::~JKRHeap() sSystemHeap = !nextRootHeap ? sRootHeap : nextRootHeap->getObject(); } -bool JKRHeap::initArena(char** outUserRamStart, u32* outUserRamSize, int numHeaps) -{ +bool JKRHeap::initArena(char** outUserRamStart, u32* outUserRamSize, int numHeaps) { void* arenaLo = OSGetArenaLo(); void* arenaHi = OSGetArenaHi(); - if (arenaLo == arenaHi) - { + if (arenaLo == arenaHi) { return false; } void* arenaStart = OSInitAlloc(arenaLo, arenaHi, numHeaps); @@ -82,129 +74,111 @@ bool JKRHeap::initArena(char** outUserRamStart, u32* outUserRamSize, int numHeap return true; } -JKRHeap* JKRHeap::becomeSystemHeap() -{ +JKRHeap* JKRHeap::becomeSystemHeap() { JKRHeap* old = sSystemHeap; sSystemHeap = this; return old; } -JKRHeap* JKRHeap::becomeCurrentHeap() -{ +JKRHeap* JKRHeap::becomeCurrentHeap() { JKRHeap* old = sCurrentHeap; sCurrentHeap = this; return old; } -void JKRHeap::destroy(JKRHeap* heap) -{ - #line 200 +void JKRHeap::destroy(JKRHeap* heap) { JUT_ASSERT(heap != 0); heap->destroy(); } -void* JKRHeap::alloc(u32 byteCount, int padding, JKRHeap* heap) -{ +void* JKRHeap::alloc(u32 byteCount, int padding, JKRHeap* heap) { void* memory = nullptr; - if (heap) - { + if (heap) { memory = heap->do_alloc(byteCount, padding); - } - else if (sCurrentHeap) - { + } else if (sCurrentHeap) { memory = sCurrentHeap->do_alloc(byteCount, padding); } return memory; } -void* JKRHeap::alloc(u32 byteCount, int padding) -{ - JUT_WARNING_F(317, !mInitFlag, "alloc %x byte in heap %x", byteCount, this); +void* JKRHeap::alloc(u32 byteCount, int padding) { + JUT_WARNING_F(!mInitFlag, "alloc %x byte in heap %x", byteCount, this); return do_alloc(byteCount, padding); } -void JKRHeap::free(void* memory, JKRHeap* heap) -{ - if ((heap) || (heap = findFromRoot(memory), heap)) - { +void JKRHeap::free(void* memory, JKRHeap* heap) { + if ((heap) || (heap = findFromRoot(memory), heap)) { heap->free(memory); } } -void JKRHeap::free(void* memory) -{ - JUT_WARNING_F(365, !mInitFlag, "free %x in heap %x", memory, this); +void JKRHeap::free(void* memory) { + JUT_WARNING_F(!mInitFlag, "free %x in heap %x", memory, this); do_free(memory); } -void JKRHeap::callAllDisposer() -{ +void JKRHeap::callAllDisposer() { JSUListIterator iterator; - while (iterator = mDisposerList.getFirst(), iterator != mDisposerList.getEnd()) - { + while (iterator = mDisposerList.getFirst(), iterator != mDisposerList.getEnd()) { iterator->~JKRDisposer(); } } -void JKRHeap::freeAll() -{ - JUT_WARNING_F(417, !mInitFlag, "freeAll in heap %x", this); +void JKRHeap::freeAll() { + JUT_WARNING_F(!mInitFlag, "freeAll in heap %x", this); do_freeAll(); } -void JKRHeap::freeTail() -{ - JUT_WARNING_F(431, !mInitFlag, "freeTail in heap %x", this); +void JKRHeap::freeTail() { + JUT_WARNING_F(!mInitFlag, "freeTail in heap %x", this); do_freeTail(); } -void JKRHeap::resize(void* memoryBlock, u32 newSize) -{ - JUT_WARNING_F(491, !mInitFlag, "resize block %x into %x in heap %x", memoryBlock, newSize, this); +void JKRHeap::resize(void* memoryBlock, u32 newSize) { + JUT_WARNING_F(!mInitFlag, "resize block %x into %x in heap %x", memoryBlock, newSize, this); do_resize(memoryBlock, newSize); } -s32 JKRHeap::getSize(void* memoryBlock, JKRHeap* heap) -{ - if (heap == nullptr && (heap = findFromRoot(memoryBlock), heap == nullptr)) - { +s32 JKRHeap::getSize(void* memoryBlock, JKRHeap* heap) { + if (heap == nullptr && (heap = findFromRoot(memoryBlock), heap == nullptr)) { return -1; - } - else + } else return heap->getSize(memoryBlock); } -s32 JKRHeap::getSize(void* memoryBlock) { return do_getSize(memoryBlock); } -s32 JKRHeap::getFreeSize() { return do_getFreeSize(); } -s32 JKRHeap::getTotalFreeSize() { return do_getTotalFreeSize(); } +s32 JKRHeap::getSize(void* memoryBlock) { + return do_getSize(memoryBlock); +} +s32 JKRHeap::getFreeSize() { + return do_getFreeSize(); +} +s32 JKRHeap::getTotalFreeSize() { + return do_getTotalFreeSize(); +} -s32 JKRHeap::changeGroupID(u8 newGroupID) -{ - JUT_WARNING_F(570, !mInitFlag, "change heap ID into %x in heap %x", newGroupID, this); +s32 JKRHeap::changeGroupID(u8 newGroupID) { + JUT_WARNING_F(!mInitFlag, "change heap ID into %x in heap %x", newGroupID, this); return do_changeGroupID(newGroupID); } -u8 JKRHeap::getCurrentGroupId() { return do_getCurrentGroupId(); } +u8 JKRHeap::getCurrentGroupId() { + return do_getCurrentGroupId(); +} -JKRHeap* JKRHeap::findFromRoot(void* ptr) -{ +JKRHeap* JKRHeap::findFromRoot(void* ptr) { if (sRootHeap != nullptr) return sRootHeap->find(ptr); return nullptr; } -JKRHeap* JKRHeap::find(void* memory) const -{ - if ((mStart <= memory) && (memory <= mEnd)) - { - if (mChildTree.getNumChildren() != 0) - { - for (JSUTreeIterator iterator(mChildTree.getFirstChild()); iterator != mChildTree.getEndChild(); ++iterator) - { +JKRHeap* JKRHeap::find(void* memory) const { + if ((mStart <= memory) && (memory <= mEnd)) { + if (mChildTree.getNumChildren() != 0) { + for (JSUTreeIterator iterator(mChildTree.getFirstChild()); iterator != mChildTree.getEndChild(); + ++iterator) { JKRHeap* result = iterator->find(memory); - if (result) - { + if (result) { return result; } } @@ -214,22 +188,18 @@ JKRHeap* JKRHeap::find(void* memory) const return nullptr; } -JKRHeap* JKRHeap::findAllHeap(void* memory) const -{ - if (mChildTree.getNumChildren() != 0) - { - for (JSUTreeIterator iterator(mChildTree.getFirstChild()); iterator != mChildTree.getEndChild(); ++iterator) - { +JKRHeap* JKRHeap::findAllHeap(void* memory) const { + if (mChildTree.getNumChildren() != 0) { + for (JSUTreeIterator iterator(mChildTree.getFirstChild()); iterator != mChildTree.getEndChild(); + ++iterator) { JKRHeap* result = iterator->findAllHeap(memory); - if (result) - { + if (result) { return result; } } } - if (mStart <= memory && memory < mEnd) - { + if (mStart <= memory && memory < mEnd) { return const_cast(this); } @@ -237,31 +207,22 @@ JKRHeap* JKRHeap::findAllHeap(void* memory) const } // generates __as__25JSUTreeIterator<7JKRHeap>FP17JSUTree<7JKRHeap> and __ct__25JSUTreeIterator<7JKRHeap>Fv, remove this -void JKRHeap::dispose_subroutine(u32 begin, u32 end) -{ +void JKRHeap::dispose_subroutine(u32 begin, u32 end) { JSUListIterator last_iterator; JSUListIterator next_iterator; JSUListIterator iterator; - for (iterator = mDisposerList.getFirst(); iterator != mDisposerList.getEnd(); - iterator = next_iterator) - { + for (iterator = mDisposerList.getFirst(); iterator != mDisposerList.getEnd(); iterator = next_iterator) { JKRDisposer* disposer = iterator.getObject(); - if ((void*)begin <= disposer && disposer < (void*)end) - { + if ((void*)begin <= disposer && disposer < (void*)end) { disposer->~JKRDisposer(); - if (last_iterator == nullptr) - { + if (last_iterator == nullptr) { next_iterator = mDisposerList.getFirst(); - } - else - { + } else { next_iterator = last_iterator; next_iterator++; } - } - else - { + } else { last_iterator = iterator; next_iterator = iterator; next_iterator++; @@ -269,36 +230,30 @@ void JKRHeap::dispose_subroutine(u32 begin, u32 end) } } -bool JKRHeap::dispose(void* memory, u32 size) -{ +bool JKRHeap::dispose(void* memory, u32 size) { u32 begin = (u32)memory; u32 end = (u32)memory + size; dispose_subroutine(begin, end); return false; } -void JKRHeap::dispose(void* begin, void* end) -{ +void JKRHeap::dispose(void* begin, void* end) { dispose_subroutine((u32)begin, (u32)end); } -void JKRHeap::dispose() -{ +void JKRHeap::dispose() { JSUListIterator iterator; - while (iterator = mDisposerList.getFirst(), iterator != mDisposerList.getEnd()) - { + while (iterator = mDisposerList.getFirst(), iterator != mDisposerList.getEnd()) { iterator->~JKRDisposer(); } } -void JKRHeap::copyMemory(void* dst, void* src, u32 size) -{ +void JKRHeap::copyMemory(void* dst, void* src, u32 size) { u32 count = (size + 3) / 4; u32* dst_32 = (u32*)dst; u32* src_32 = (u32*)src; - while (count > 0) - { + while (count > 0) { *dst_32 = *src_32; dst_32++; src_32++; @@ -306,40 +261,33 @@ void JKRHeap::copyMemory(void* dst, void* src, u32 size) } } -void JKRDefaultMemoryErrorRoutine(void* heap, u32 size, int alignment) -{ - // OSReport("Error: Cannot allocate memory %d(0x%x)byte in %d byte alignment from %08x\n", size, size, alignment, heap); +void JKRDefaultMemoryErrorRoutine(void* heap, u32 size, int alignment) { + // OSReport("Error: Cannot allocate memory %d(0x%x)byte in %d byte alignment from %08x\n", size, size, alignment, + // heap); OSErrorLine(710, "abort\n"); } -JKRHeapErrorHandler* JKRHeap::setErrorHandler(JKRHeapErrorHandler* newHandler) -{ +JKRHeapErrorHandler* JKRHeap::setErrorHandler(JKRHeapErrorHandler* newHandler) { JKRHeapErrorHandler* oldHandler = mErrorHandler; - if (!newHandler) - { + if (!newHandler) { newHandler = JKRDefaultMemoryErrorRoutine; } mErrorHandler = newHandler; return oldHandler; } -bool JKRHeap::isSubHeap(JKRHeap* heap) const -{ +bool JKRHeap::isSubHeap(JKRHeap* heap) const { if (!heap) return false; - if (mChildTree.getNumChildren() != 0) - { + if (mChildTree.getNumChildren() != 0) { JSUTreeIterator iterator; - for (iterator = mChildTree.getFirstChild(); iterator != mChildTree.getEndChild(); ++iterator) - { - if (iterator.getObject() == heap) - { + for (iterator = mChildTree.getFirstChild(); iterator != mChildTree.getEndChild(); ++iterator) { + if (iterator.getObject() == heap) { return true; } - if (iterator.getObject()->isSubHeap(heap)) - { + if (iterator.getObject()->isSubHeap(heap)) { return true; } } @@ -348,35 +296,33 @@ bool JKRHeap::isSubHeap(JKRHeap* heap) const return false; } -void* operator new(u32 byteCount) -{ +void* operator new(u32 byteCount) { return JKRHeap::alloc(byteCount, 4, nullptr); } -void* operator new(u32 byteCount, int alignment) -{ +void* operator new(u32 byteCount, int alignment) { return JKRHeap::alloc(byteCount, alignment, nullptr); } -void* operator new(u32 byteCount, JKRHeap* heap, int alignment) -{ +void* operator new(u32 byteCount, JKRHeap* heap, int alignment) { return JKRHeap::alloc(byteCount, alignment, heap); } -void* operator new[](u32 byteCount) -{ +void* operator new[](u32 byteCount) { return JKRHeap::alloc(byteCount, 4, nullptr); } -void* operator new[](u32 byteCount, int alignment) -{ +void* operator new[](u32 byteCount, int alignment) { return JKRHeap::alloc(byteCount, alignment, nullptr); } -void* operator new[](u32 byteCount, JKRHeap* heap, int alignment) -{ +void* operator new[](u32 byteCount, JKRHeap* heap, int alignment) { return JKRHeap::alloc(byteCount, alignment, heap); } - // this is not needed without the other pragma and asm bs -void operator delete(void* memory) { JKRHeap::free(memory, nullptr); } -void operator delete[](void* memory) { JKRHeap::free(memory, nullptr); } +// this is not needed without the other pragma and asm bs +void operator delete(void* memory) { + JKRHeap::free(memory, nullptr); +} +void operator delete[](void* memory) { + JKRHeap::free(memory, nullptr); +} /*JKRHeap::TState::TState(const JKRHeap::TState::TArgument &arg, const JKRHeap::TState::TLocation &location) { @@ -393,37 +339,30 @@ JKRHeap::TState::TState(const JKRHeap::TState &other, const JKRHeap::TState::TLo // UNUSED FUNCTION }*/ - JKRHeap::TState::~TState() -{ +JKRHeap::TState::~TState() { // Unused, however might need it } -void JKRHeap::state_register(JKRHeap::TState* p, u32) const -{ - #line 1132 +void JKRHeap::state_register(JKRHeap::TState* p, u32) const { JUT_ASSERT(p != 0); JUT_ASSERT(p->getHeap() == this); } -bool JKRHeap::state_compare(const JKRHeap::TState& r1, const JKRHeap::TState& r2) const -{ - #line 1141 +bool JKRHeap::state_compare(const JKRHeap::TState& r1, const JKRHeap::TState& r2) const { JUT_ASSERT(r1.getHeap() == r2.getHeap()); return (r1.getCheckCode() == r2.getCheckCode()); } // fabricated, but probably matches(except for line numbers) -void JKRHeap::state_dumpDifference(const JKRHeap::TState& r1, const JKRHeap::TState& r2) -{ - JUT_LOG_F(1157, "heap : %p / %p", r1.getHeap(), r2.getHeap()); - JUT_LOG_F(1158, "check-code : 0x%08x / 0x%08x", r1.getCheckCode(), r2.getCheckCode()); - JUT_LOG_F(1159, "id : 0x%08x / 0x%08x", r1.getId(), r2.getId()); - JUT_LOG_F(1160, "used size : %10u / %10u", r1.getUsedSize(), r2.getUsedSize()); +void JKRHeap::state_dumpDifference(const JKRHeap::TState& r1, const JKRHeap::TState& r2) { + JUT_LOG_F("heap : %p / %p", r1.getHeap(), r2.getHeap()); + JUT_LOG_F("check-code : 0x%08x / 0x%08x", r1.getCheckCode(), r2.getCheckCode()); + JUT_LOG_F("id : 0x%08x / 0x%08x", r1.getId(), r2.getId()); + JUT_LOG_F("used size : %10u / %10u", r1.getUsedSize(), r2.getUsedSize()); } -void JKRHeap::state_dump(const TState& state) const -{ - JUT_LOG_F(1165, "check-code : 0x%08x", state.getCheckCode()); - JUT_LOG_F(1166, "id : 0x%08x", state.getId()); - JUT_LOG_F(1167, "used size : %u", state.getUsedSize()); +void JKRHeap::state_dump(const TState& state) const { + JUT_LOG_F("check-code : 0x%08x", state.getCheckCode()); + JUT_LOG_F("id : 0x%08x", state.getId()); + JUT_LOG_F("used size : %u", state.getUsedSize()); } diff --git a/src/static/JSystem/JKernel/JKRMemArchive.cpp b/src/static/JSystem/JKernel/JKRMemArchive.cpp index c71c23bb..74519a48 100644 --- a/src/static/JSystem/JKernel/JKRMemArchive.cpp +++ b/src/static/JSystem/JKernel/JKRMemArchive.cpp @@ -7,18 +7,15 @@ #include "JSystem/JKernel/JKRDvdRipper.h" #include "JSystem/JUtility/JUTAssertion.h" -JKRMemArchive::JKRMemArchive() : JKRArchive() {} +JKRMemArchive::JKRMemArchive() : JKRArchive() { +} -JKRMemArchive::JKRMemArchive(s32 entryNum, EMountDirection mountDirection) : JKRArchive(entryNum, MOUNT_MEM) -{ +JKRMemArchive::JKRMemArchive(s32 entryNum, EMountDirection mountDirection) : JKRArchive(entryNum, MOUNT_MEM) { mIsMounted = false; mMountDirection = mountDirection; - if (!open(entryNum, mMountDirection)) - { + if (!open(entryNum, mMountDirection)) { return; - } - else - { + } else { mVolumeType = 'RARC'; mVolumeName = &mStrTable[mDirectories->mOffset]; sVolumeList.prepend(&mFileLoaderLink); @@ -26,15 +23,11 @@ JKRMemArchive::JKRMemArchive(s32 entryNum, EMountDirection mountDirection) : JKR } } -JKRMemArchive::JKRMemArchive(void* mem, u32 size, JKRMemBreakFlag breakFlag) : JKRArchive((s32)mem, MOUNT_MEM) -{ +JKRMemArchive::JKRMemArchive(void* mem, u32 size, JKRMemBreakFlag breakFlag) : JKRArchive((s32)mem, MOUNT_MEM) { mIsMounted = false; - if (!open(mem, size, breakFlag)) - { + if (!open(mem, size, breakFlag)) { return; - } - else - { + } else { mVolumeType = 'RARC'; mVolumeName = &mStrTable[mDirectories->mOffset]; sVolumeList.prepend(&mFileLoaderLink); @@ -42,10 +35,8 @@ JKRMemArchive::JKRMemArchive(void* mem, u32 size, JKRMemBreakFlag breakFlag) : J } } -JKRMemArchive::~JKRMemArchive() -{ - if (mIsMounted == true) - { +JKRMemArchive::~JKRMemArchive() { + if (mIsMounted == true) { if (mIsOpen && mArcHeader) JKRFreeToHeap(mHeap, mArcHeader); @@ -54,17 +45,16 @@ JKRMemArchive::~JKRMemArchive() } } -#if DEBUG // function is needed to generate certain strings first, however this is not what the original function looks like -void JKRMemArchive::fixedInit(s32) -{ +#if DEBUG // function is needed to generate certain strings first, however this is not what the original function looks + // like +void JKRMemArchive::fixedInit(s32) { JUT_ASSERT(isMounted()); JUT_PANIC("mMountCount == 1"); // some member is called mMountCount, if there's a game with this assert, fix JUT_ASSERT(mArcHeader->signature == 'RARC'); } #endif -bool JKRMemArchive::open(s32 entryNum, JKRArchive::EMountDirection mountDirection) -{ +bool JKRMemArchive::open(s32 entryNum, JKRArchive::EMountDirection mountDirection) { mArcHeader = nullptr; mArcInfoBlock = nullptr; mArchiveData = nullptr; @@ -74,50 +64,39 @@ bool JKRMemArchive::open(s32 entryNum, JKRArchive::EMountDirection mountDirectio mIsOpen = false; mMountDirection = mountDirection; - if (mMountDirection == JKRArchive::MOUNT_DIRECTION_HEAD) - { + if (mMountDirection == JKRArchive::MOUNT_DIRECTION_HEAD) { u32 loadedSize; - mArcHeader = (SArcHeader*)JKRDvdRipper::loadToMainRAM( - entryNum, nullptr, EXPAND_SWITCH_DECOMPRESS, 0, mHeap, JKRDvdRipper::ALLOC_DIR_TOP, - 0, (int*)&mCompression); + mArcHeader = (SArcHeader*)JKRDvdRipper::loadToMainRAM(entryNum, nullptr, EXPAND_SWITCH_DECOMPRESS, 0, mHeap, + JKRDvdRipper::ALLOC_DIR_TOP, 0, (int*)&mCompression); - } - else - { + } else { u32 loadedSize; - mArcHeader = (SArcHeader*)JKRDvdRipper::loadToMainRAM( - entryNum, nullptr, EXPAND_SWITCH_DECOMPRESS, 0, mHeap, - JKRDvdRipper::ALLOC_DIR_BOTTOM, 0, (int*)&mCompression); + mArcHeader = (SArcHeader*)JKRDvdRipper::loadToMainRAM(entryNum, nullptr, EXPAND_SWITCH_DECOMPRESS, 0, mHeap, + JKRDvdRipper::ALLOC_DIR_BOTTOM, 0, (int*)&mCompression); } - if (!mArcHeader) - { + if (!mArcHeader) { mMountMode = UNKNOWN_MOUNT_MODE; - } - else - { + } else { JUT_ASSERT(mArcHeader->signature == 'RARC'); mArcInfoBlock = (SArcDataInfo*)((u8*)mArcHeader + mArcHeader->header_length); mDirectories = (SDIDirEntry*)((u8*)&mArcInfoBlock->num_nodes + mArcInfoBlock->node_offset); mFileEntries = (SDIFileEntry*)((u8*)&mArcInfoBlock->num_nodes + mArcInfoBlock->file_entry_offset); mStrTable = (char*)((u8*)&mArcInfoBlock->num_nodes + mArcInfoBlock->string_table_offset); - mArchiveData = - (u8*)((u32)mArcHeader + mArcHeader->header_length + mArcHeader->file_data_offset); + mArchiveData = (u8*)((u32)mArcHeader + mArcHeader->header_length + mArcHeader->file_data_offset); mIsOpen = true; } #if DEBUG // OS Assert? - if (mMountMode == UNKNOWN_MOUNT_MODE) - { + if (mMountMode == UNKNOWN_MOUNT_MODE) { OSReport(":::Cannot alloc memory [%s][%d]\n", __FILE__, 460); } #endif return (mMountMode == UNKNOWN_MOUNT_MODE) ? false : true; } -bool JKRMemArchive::open(void* buffer, u32 bufferSize, JKRMemBreakFlag flag) -{ +bool JKRMemArchive::open(void* buffer, u32 bufferSize, JKRMemBreakFlag flag) { mArcHeader = (SArcHeader*)buffer; JUT_ASSERT(mArcHeader->signature == 'RARC'); mArcInfoBlock = (SArcDataInfo*)((u8*)mArcHeader + mArcHeader->header_length); @@ -131,12 +110,11 @@ bool JKRMemArchive::open(void* buffer, u32 bufferSize, JKRMemBreakFlag flag) return true; } -void* JKRMemArchive::fetchResource(SDIFileEntry* fileEntry, u32* resourceSize) -{ +void* JKRMemArchive::fetchResource(SDIFileEntry* fileEntry, u32* resourceSize) { JUT_ASSERT(isMounted()) - if (!fileEntry->mData) - fileEntry->mData = mArchiveData + fileEntry->mDataOffset; + if (!fileEntry->mData) + fileEntry->mData = mArchiveData + fileEntry->mDataOffset; if (resourceSize) *resourceSize = fileEntry->mSize; @@ -144,43 +122,35 @@ void* JKRMemArchive::fetchResource(SDIFileEntry* fileEntry, u32* resourceSize) return fileEntry->mData; } -void* JKRMemArchive::fetchResource(void* buffer, u32 bufferSize, SDIFileEntry* fileEntry, - u32* resourceSize, JKRExpandSwitch expandSwitch) -{ +void* JKRMemArchive::fetchResource(void* buffer, u32 bufferSize, SDIFileEntry* fileEntry, u32* resourceSize, + JKRExpandSwitch expandSwitch) { JUT_ASSERT(isMounted()) - bufferSize = (bufferSize & -32); + bufferSize = (bufferSize & -32); u32 srcLength = ALIGN_NEXT(fileEntry->mSize, 32); - if (srcLength > bufferSize) - { + if (srcLength > bufferSize) { srcLength = bufferSize; } - if (fileEntry->mData != nullptr) - { + if (fileEntry->mData != nullptr) { JKRHeap::copyMemory(buffer, fileEntry->mData, srcLength); - } - else - { + } else { int compression = JKRConvertAttrToCompressionType(fileEntry->getAttr()); if (expandSwitch != EXPAND_SWITCH_DECOMPRESS) compression = JKRCOMPRESSION_NONE; void* data = mArchiveData + fileEntry->mDataOffset; - srcLength = - fetchResource_subroutine((u8*)data, srcLength, (u8*)buffer, bufferSize, compression); + srcLength = fetchResource_subroutine((u8*)data, srcLength, (u8*)buffer, bufferSize, compression); } - if (resourceSize) - { + if (resourceSize) { *resourceSize = srcLength; } return buffer; } -void JKRMemArchive::removeResourceAll(void) -{ +void JKRMemArchive::removeResourceAll(void) { JUT_ASSERT(isMounted()); if (mArcInfoBlock == nullptr) @@ -191,17 +161,14 @@ void JKRMemArchive::removeResourceAll(void) // !@bug: looping over file entries without incrementing the fileEntry pointer. Thus, only the // first fileEntry will clear/remove the resource data. SDIFileEntry* fileEntry = mFileEntries; - for (int i = 0; i < mArcInfoBlock->num_file_entries; i++) - { - if (fileEntry->mData) - { + for (int i = 0; i < mArcInfoBlock->num_file_entries; i++) { + if (fileEntry->mData) { fileEntry->mData = nullptr; } } } -bool JKRMemArchive::removeResource(void* resource) -{ +bool JKRMemArchive::removeResource(void* resource) { JUT_ASSERT(isMounted()); SDIFileEntry* fileEntry = findPtrResource(resource); @@ -212,35 +179,32 @@ bool JKRMemArchive::removeResource(void* resource) return true; } -u32 JKRMemArchive::fetchResource_subroutine(u8* src, u32 srcLength, u8* dst, u32 dstLength, int compression) -{ +u32 JKRMemArchive::fetchResource_subroutine(u8* src, u32 srcLength, u8* dst, u32 dstLength, int compression) { u32 alignedDst = dstLength & -32; u32 alignedSrc = ALIGN_NEXT(srcLength, 32); - switch (compression) - { - case JKRCOMPRESSION_NONE: - if (alignedSrc > alignedDst) - alignedSrc = alignedDst; + switch (compression) { + case JKRCOMPRESSION_NONE: + if (alignedSrc > alignedDst) + alignedSrc = alignedDst; - JKRHeap::copyMemory(dst, src, alignedSrc); - return alignedSrc; + JKRHeap::copyMemory(dst, src, alignedSrc); + return alignedSrc; - case JKRCOMPRESSION_YAY0: - case JKRCOMPRESSION_YAZ0: - u32 expandSize = JKRDecompExpandSize(src); + case JKRCOMPRESSION_YAY0: + case JKRCOMPRESSION_YAZ0: + u32 expandSize = JKRDecompExpandSize(src); - if (expandSize > alignedDst) { - expandSize = alignedDst; + if (expandSize > alignedDst) { + expandSize = alignedDst; + } + + JKRDecompress(src, dst, expandSize, 0); + return expandSize; + + default: { + JPANIC(709, ":::??? bad sequence\n"); + return 0; } - - JKRDecompress(src, dst, expandSize, 0); - return expandSize; - - default: - { - JPANIC(709, ":::??? bad sequence\n"); - return 0; - } } return alignedSrc; diff --git a/src/static/JSystem/JKernel/JKRThread.cpp b/src/static/JSystem/JKernel/JKRThread.cpp index 0006186e..27d3310a 100644 --- a/src/static/JSystem/JKernel/JKRThread.cpp +++ b/src/static/JSystem/JKernel/JKRThread.cpp @@ -5,110 +5,95 @@ JSUList JKRThread::sThreadList; -JKRThread::JKRThread(u32 stackSize, int msgCount, int threadPrio) - : mLink(this) { - this->mHeap = JKRHeap::findFromRoot(this); - if (this->mHeap == nullptr) { - this->mHeap = JKRHeap::sSystemHeap; - } +JKRThread::JKRThread(u32 stackSize, int msgCount, int threadPrio) : mLink(this) { + this->mHeap = JKRHeap::findFromRoot(this); + if (this->mHeap == nullptr) { + this->mHeap = JKRHeap::sSystemHeap; + } - this->mStackSize = JKR_ALIGN32(stackSize); - this->mStackMemory = JKRHeap::alloc(this->mStackSize, 32, this->mHeap); - this->mThreadRecord = - (OSThread*)JKRHeap::alloc(sizeof(OSThread), 32, this->mHeap); - OSCreateThread(this->mThreadRecord, &JKRThread::start, this, - (void*)((u32)this->mStackMemory + this->mStackSize), - this->mStackSize, threadPrio, OS_THREAD_ATTR_DETACH); - this->mMesgCount = msgCount; - this->mMesgBuffer = (OSMessage*)JKRHeap::alloc( - mMesgCount * sizeof(OSMessage), 0, this->mHeap); - OSInitMessageQueue(&this->mMesgQueue, this->mMesgBuffer, this->mMesgCount); - JKRThread::sThreadList.append(&this->mLink); + this->mStackSize = JKR_ALIGN32(stackSize); + this->mStackMemory = JKRHeap::alloc(this->mStackSize, 32, this->mHeap); + this->mThreadRecord = (OSThread*)JKRHeap::alloc(sizeof(OSThread), 32, this->mHeap); + OSCreateThread(this->mThreadRecord, &JKRThread::start, this, (void*)((u32)this->mStackMemory + this->mStackSize), + this->mStackSize, threadPrio, OS_THREAD_ATTR_DETACH); + this->mMesgCount = msgCount; + this->mMesgBuffer = (OSMessage*)JKRHeap::alloc(mMesgCount * sizeof(OSMessage), 0, this->mHeap); + OSInitMessageQueue(&this->mMesgQueue, this->mMesgBuffer, this->mMesgCount); + JKRThread::sThreadList.append(&this->mLink); } -JKRThread::JKRThread(OSThread* threadRecord, int msgCount) - : mLink(this) { - this->mHeap = nullptr; - this->mThreadRecord = threadRecord; - this->mStackSize = (u32)threadRecord->stackEnd - (u32)threadRecord->stackBase; - this->mStackMemory = threadRecord->stackBase; - this->mMesgCount = msgCount; - this->mMesgBuffer = (OSMessage*)JKRHeap::sSystemHeap->alloc( - mMesgCount * sizeof(OSMessage), 4); - OSInitMessageQueue(&this->mMesgQueue, this->mMesgBuffer, this->mMesgCount); - JKRThread::sThreadList.append(&this->mLink); +JKRThread::JKRThread(OSThread* threadRecord, int msgCount) : mLink(this) { + this->mHeap = nullptr; + this->mThreadRecord = threadRecord; + this->mStackSize = (u32)threadRecord->stackEnd - (u32)threadRecord->stackBase; + this->mStackMemory = threadRecord->stackBase; + this->mMesgCount = msgCount; + this->mMesgBuffer = (OSMessage*)JKRHeap::sSystemHeap->alloc(mMesgCount * sizeof(OSMessage), 4); + OSInitMessageQueue(&this->mMesgQueue, this->mMesgBuffer, this->mMesgCount); + JKRThread::sThreadList.append(&this->mLink); } JKRThread::~JKRThread() { - JKRThread::sThreadList.remove(&this->mLink); + JKRThread::sThreadList.remove(&this->mLink); - if (this->mHeap != nullptr) { - if (!OSIsThreadTerminated(this->mThreadRecord)) { - OSDetachThread(this->mThreadRecord); - OSCancelThread(this->mThreadRecord); + if (this->mHeap != nullptr) { + if (!OSIsThreadTerminated(this->mThreadRecord)) { + OSDetachThread(this->mThreadRecord); + OSCancelThread(this->mThreadRecord); + } + + JKRHeap::free(this->mStackMemory, this->mHeap); + JKRHeap::free(this->mThreadRecord, this->mHeap); } - JKRHeap::free(this->mStackMemory, this->mHeap); - JKRHeap::free(this->mThreadRecord, this->mHeap); - } - - JKRHeap::free(this->mMesgBuffer, nullptr); + JKRHeap::free(this->mMesgBuffer, nullptr); } void* JKRThread::start(void* thread) { - return static_cast(thread)->run(); + return static_cast(thread)->run(); } // UNUSED FUNCTIONS, REQUIRED FOR RTTI -JKRTask::JKRTask() : JKRThread(0x4000, 4, 31) -{ - +JKRTask::JKRTask() : JKRThread(0x4000, 4, 31) { } -JKRTask::~JKRTask() { } +JKRTask::~JKRTask() { +} -JKRTask* JKRTask::create() -{ - return new JKRTask(); +JKRTask* JKRTask::create() { + return new JKRTask(); } void JKRTask::destroy() { - delete this; + delete this; } -void* JKRTask::run() -{ - Request* req; - //OSInitFastCast(); - while (true) - { - req = (Request*)waitMessageBlock(); - if (req->mCb) - { - req->mCb(req->mArg); - if (mTaskMsgQueue) - { - OSSendMessage(mTaskMsgQueue, req->mMsg, OS_MESSAGE_NOBLOCK); - } +void* JKRTask::run() { + Request* req; + // OSInitFastCast(); + while (true) { + req = (Request*)waitMessageBlock(); + if (req->mCb) { + req->mCb(req->mArg); + if (mTaskMsgQueue) { + OSSendMessage(mTaskMsgQueue, req->mMsg, OS_MESSAGE_NOBLOCK); + } + } + req->mCb = nullptr; } - req->mCb = nullptr; - } } -bool JKRTask::request(RequestCallback callback, void* arg, void* msg) -{ - Request* req = searchBlank(); - if (req == nullptr) - { - return false; - } - req->mCb = callback; - req->mArg = arg; - req->mMsg = msg; - bool sendResult = OSSendMessage(&mMesgQueue, req, OS_MESSAGE_NOBLOCK); - if (!sendResult) - { - req->mCb = nullptr; - } - return sendResult; +bool JKRTask::request(RequestCallback callback, void* arg, void* msg) { + Request* req = searchBlank(); + if (req == nullptr) { + return false; + } + req->mCb = callback; + req->mArg = arg; + req->mMsg = msg; + bool sendResult = OSSendMessage(&mMesgQueue, req, OS_MESSAGE_NOBLOCK); + if (!sendResult) { + req->mCb = nullptr; + } + return sendResult; } diff --git a/src/static/JSystem/JSupport/JSUFileStream.cpp b/src/static/JSystem/JSupport/JSUFileStream.cpp index ae299a09..d79417a6 100644 --- a/src/static/JSystem/JSupport/JSUFileStream.cpp +++ b/src/static/JSystem/JSupport/JSUFileStream.cpp @@ -1,55 +1,53 @@ #include "JSystem/JSupport/JSUStream.h" -JSUFileInputStream::JSUFileInputStream(JKRFile* file) - : mObject(file), mPosition(0) {} +JSUFileInputStream::JSUFileInputStream(JKRFile* file) : mObject(file), mPosition(0) { +} int JSUFileInputStream::readData(void* buf, s32 len) { - int read = 0; + int read = 0; - if (((JKRFile*)this->mObject)->isAvailable()) { - /* Check if need to clamp length to EOF */ - if ((u32)(this->mPosition + len) > - ((JKRFile*)this->mObject)->getFileSize()) { - len = ((JKRFile*)this->mObject)->getFileSize() - this->mPosition; + if (((JKRFile*)this->mObject)->isAvailable()) { + /* Check if need to clamp length to EOF */ + if ((u32)(this->mPosition + len) > ((JKRFile*)this->mObject)->getFileSize()) { + len = ((JKRFile*)this->mObject)->getFileSize() - this->mPosition; + } + + if (len > 0) { + read = ((JKRFile*)this->mObject)->readData(buf, len, this->mPosition); + this->mPosition += read; + } } - if (len > 0) { - read = ((JKRFile*)this->mObject)->readData(buf, len, this->mPosition); - this->mPosition += read; - } - } - - return read; + return read; } int JSUFileInputStream::seekPos(s32 offset, JSUStreamSeekFrom from) { - int pos = this->mPosition; + int pos = this->mPosition; - switch (from) { - case SEEK_SET: - this->mPosition = offset; - break; + switch (from) { + case SEEK_SET: + this->mPosition = offset; + break; - case SEEK_END: - this->mPosition = ((JKRFile*)this->mObject)->getFileSize() - offset; - break; + case SEEK_END: + this->mPosition = ((JKRFile*)this->mObject)->getFileSize() - offset; + break; - case SEEK_CUR: - this->mPosition = pos + offset; - break; - } + case SEEK_CUR: + this->mPosition = pos + offset; + break; + } - if (this->mPosition < 0) { - this->mPosition = 0; - } + if (this->mPosition < 0) { + this->mPosition = 0; + } - if (this->mPosition > (s32)((JKRFile*)this->mObject)->getFileSize()) { - this->mPosition = ((JKRFile*)this->mObject)->getFileSize(); - } + if (this->mPosition > (s32)((JKRFile*)this->mObject)->getFileSize()) { + this->mPosition = ((JKRFile*)this->mObject)->getFileSize(); + } - return this->mPosition - pos; + return this->mPosition - pos; } -JSUFileOutputStream::JSUFileOutputStream(JKRFile *file) { - -} \ No newline at end of file +JSUFileOutputStream::JSUFileOutputStream(JKRFile* file) { +} diff --git a/src/static/JSystem/JSupport/JSUInputStream.cpp b/src/static/JSystem/JSupport/JSUInputStream.cpp index 170385ab..eec8ff36 100644 --- a/src/static/JSystem/JSupport/JSUInputStream.cpp +++ b/src/static/JSystem/JSupport/JSUInputStream.cpp @@ -1,120 +1,120 @@ #include "JSystem/JSupport/JSUStream.h" - -JSUInputStream::~JSUInputStream() { } + +JSUInputStream::~JSUInputStream() { +} int JSUInputStream::read(void* buf, s32 size) { - int len = this->readData(buf, size); - if (len != size) { - this->setState(EOF); - } - return len; + int len = this->readData(buf, size); + if (len != size) { + this->setState(EOF); + } + return len; } char* JSUInputStream::read(char* str) { - u16 size; - int len = this->readData(&size, sizeof(size)); - if (len != sizeof(size)) { - str[0] = '\0'; - this->setState(EOF); - str = nullptr; - } - else { - int strRead = this->readData(str, size); - str[strRead] = '\0'; - if (strRead != size) { - this->setState(EOF); + u16 size; + int len = this->readData(&size, sizeof(size)); + if (len != sizeof(size)) { + str[0] = '\0'; + this->setState(EOF); + str = nullptr; + } else { + int strRead = this->readData(str, size); + str[strRead] = '\0'; + if (strRead != size) { + this->setState(EOF); + } } - } - return str; + return str; } /* @fabricated -- this method is confirmed to exist, but goes unused in AC */ char* JSUInputStream::readString() { - u16 len; - int r = this->readData(&len, sizeof(len)); - if (r != sizeof(len)) { - this->setState(EOF); - return nullptr; - } + u16 len; + int r = this->readData(&len, sizeof(len)); + if (r != sizeof(len)) { + this->setState(EOF); + return nullptr; + } - char* buf = new char[len+1]; - r = this->readData(buf, len); - if (r != len) { - delete[] buf; - this->setState(EOF); - return nullptr; - } + char* buf = new char[len + 1]; + r = this->readData(buf, len); + if (r != len) { + delete[] buf; + this->setState(EOF); + return nullptr; + } - buf[len] = '\0'; - return buf; + buf[len] = '\0'; + return buf; } /* @fabricated -- this method is confirmed to exist, but goes unused in AC */ char* JSUInputStream::readString(char* buf, u16 len) { - int r = this->readData(buf, len); - if (r != len) { - this->setState(EOF); - return nullptr; - } + int r = this->readData(buf, len); + if (r != len) { + this->setState(EOF); + return nullptr; + } - buf[len] = '\0'; - return buf; + buf[len] = '\0'; + return buf; } int JSUInputStream::skip(s32 amount) { - u8 _p; - int i; + u8 _p; + int i; - for (i = 0; i < amount; i++) { - if (this->readData(&_p, sizeof(_p)) != sizeof(_p)) { - this->setState(EOF); - break; + for (i = 0; i < amount; i++) { + if (this->readData(&_p, sizeof(_p)) != sizeof(_p)) { + this->setState(EOF); + break; + } } - } - return i; + return i; } /* JSURandomInputStream */ int JSURandomInputStream::skip(s32 amount) { - int s = this->seekPos(amount, SEEK_CUR); - if (s != amount) { - this->setState(EOF); - } - return s; + int s = this->seekPos(amount, SEEK_CUR); + if (s != amount) { + this->setState(EOF); + } + return s; } /* This method is confirmed to exist, but goes unused in AC. Retrieved from TP debug. */ int JSURandomInputStream::align(s32 alignment) { - int pos = this->getPosition(); - int aligned = ((alignment-1) + pos) & ~(alignment-1); - int change = aligned - pos; + int pos = this->getPosition(); + int aligned = ((alignment - 1) + pos) & ~(alignment - 1); + int change = aligned - pos; - if (change != 0) { - int s = this->seekPos(aligned, SEEK_SET); - if (s != change) { - this->setState(EOF); + if (change != 0) { + int s = this->seekPos(aligned, SEEK_SET); + if (s != change) { + this->setState(EOF); + } } - } - return change; + return change; } /* This method is confirmed to exist, but goes unused in AC. Retrieved from TP debug. */ int JSURandomInputStream::peek(void* buf, s32 len) { - int pos = this->getPosition(); - int r = this->read(buf, len); - if (r != 0) { - this->seekPos(pos, SEEK_SET); - } + int pos = this->getPosition(); + int r = this->read(buf, len); + if (r != 0) { + this->seekPos(pos, SEEK_SET); + } - return r; -} + return r; +} int JSURandomInputStream::seek(s32 offset, JSUStreamSeekFrom from) { - int s = this->seekPos(offset, from); - this->clrState(EOF); - return s; + int s = this->seekPos(offset, from); + this->clrState(EOF); + return s; } diff --git a/src/static/JSystem/JSupport/JSUList.cpp b/src/static/JSystem/JSupport/JSUList.cpp index c1a8cf26..827de1d4 100644 --- a/src/static/JSystem/JSupport/JSUList.cpp +++ b/src/static/JSystem/JSupport/JSUList.cpp @@ -1,6 +1,6 @@ #include "JSystem/JSupport/JSUList.h" -JSUPtrLink::JSUPtrLink(void *pData) { +JSUPtrLink::JSUPtrLink(void* pData) { mPtrList = 0; mData = pData; mPrev = 0; @@ -34,7 +34,7 @@ void JSUPtrList::initiate() { mLinkCount = 0; } -void JSUPtrList::setFirst(JSUPtrLink *pLink) { +void JSUPtrList::setFirst(JSUPtrLink* pLink) { pLink->mPtrList = this; pLink->mPrev = 0; pLink->mNext = 0; @@ -43,7 +43,7 @@ void JSUPtrList::setFirst(JSUPtrLink *pLink) { mLinkCount = 1; } -bool JSUPtrList::append(JSUPtrLink *pLink) { +bool JSUPtrList::append(JSUPtrLink* pLink) { bool validity = (pLink->mPtrList == 0); if (!validity) { @@ -53,8 +53,7 @@ bool JSUPtrList::append(JSUPtrLink *pLink) { if (validity) { if (!mLinkCount) { setFirst(pLink); - } - else { + } else { pLink->mPtrList = this; pLink->mPrev = mTail; pLink->mNext = 0; @@ -67,7 +66,7 @@ bool JSUPtrList::append(JSUPtrLink *pLink) { return validity; } -bool JSUPtrList::prepend(JSUPtrLink *pLink) { +bool JSUPtrList::prepend(JSUPtrLink* pLink) { bool validity = (pLink->mPtrList == 0); if (!validity) { @@ -77,8 +76,7 @@ bool JSUPtrList::prepend(JSUPtrLink *pLink) { if (validity) { if (!mLinkCount) { setFirst(pLink); - } - else { + } else { pLink->mPtrList = this; pLink->mPrev = 0; pLink->mNext = mHead; @@ -91,7 +89,7 @@ bool JSUPtrList::prepend(JSUPtrLink *pLink) { return validity; } -bool JSUPtrList::insert(JSUPtrLink *pLink_1, JSUPtrLink *pLink_2) { +bool JSUPtrList::insert(JSUPtrLink* pLink_1, JSUPtrLink* pLink_2) { if (pLink_1 == mHead) { return prepend(pLink_2); } @@ -123,23 +121,20 @@ bool JSUPtrList::insert(JSUPtrLink *pLink_1, JSUPtrLink *pLink_2) { return validity; } -bool JSUPtrList::remove(JSUPtrLink *pLink) { +bool JSUPtrList::remove(JSUPtrLink* pLink) { bool isSameList = (pLink->mPtrList == this); if (isSameList) { if (mLinkCount == 1) { mHead = 0; mTail = 0; - } - else if (pLink == mHead) { + } else if (pLink == mHead) { pLink->mNext->mPrev = 0; mHead = pLink->mNext; - } - else if (pLink == mTail) { + } else if (pLink == mTail) { pLink->mPrev->mNext = 0; mTail = pLink->mPrev; - } - else { + } else { pLink->mPrev->mNext = pLink->mNext; pLink->mNext->mPrev = pLink->mPrev; } @@ -151,16 +146,13 @@ bool JSUPtrList::remove(JSUPtrLink *pLink) { return isSameList; } -JSUPtrLink *JSUPtrList::getNthLink(u32 n) const -{ - if (n >= mLinkCount) - { +JSUPtrLink* JSUPtrList::getNthLink(u32 n) const { + if (n >= mLinkCount) { return nullptr; } - JSUPtrLink *curHead = mHead; - for (int i = 0; i < n; i++) - { + JSUPtrLink* curHead = mHead; + for (int i = 0; i < n; i++) { curHead = curHead->mNext; } return curHead; -} \ No newline at end of file +} diff --git a/src/static/JSystem/JUtility/JUTAssert.cpp b/src/static/JSystem/JUtility/JUTAssert.cpp index bea09b5b..7cebc2e9 100644 --- a/src/static/JSystem/JUtility/JUTAssert.cpp +++ b/src/static/JSystem/JUtility/JUTAssert.cpp @@ -5,67 +5,60 @@ #include "JSystem/JUtility/JUTDbPrint.h" #include "JSystem/JUtility/JUTDirectPrint.h" -namespace JUTAssertion -{ - namespace - { - static u32 sMessageLife; - static u32 sMessageOwner; - static bool mSynchro; - static char sMessageFileLine[64]; - static char sMessageString[96]; +namespace JUTAssertion { +namespace { +static u32 sMessageLife; +static u32 sMessageOwner; +static bool mSynchro; +static char sMessageFileLine[64]; +static char sMessageString[96]; - static u32 sDisplayTime = -1; - static u32 sDevice = 3; - static bool sVisible = true; +static u32 sDisplayTime = -1; +static u32 sDevice = 3; +static bool sVisible = true; +} // namespace + +void create() { +} + +u32 flush_subroutine() { + if (sMessageLife == 0) { + return 0; } - - void create() {} - - u32 flush_subroutine() - { - if (sMessageLife == 0) { - return 0; - } - if (sMessageLife != -1) { - sMessageLife--; - } - if (sMessageLife < 5) { - return 0; - } - return sMessageLife; + if (sMessageLife != -1) { + sMessageLife--; } + if (sMessageLife < 5) { + return 0; + } + return sMessageLife; +} - void flushMessage() - { - if (flush_subroutine() && sVisible == true) - { - JUTDirectPrint::getManager()->drawString(16, 16, sMessageFileLine); - JUTDirectPrint::getManager()->drawString(16, 24, sMessageString); +void flushMessage() { + if (flush_subroutine() && sVisible == true) { + JUTDirectPrint::getManager()->drawString(16, 16, sMessageFileLine); + JUTDirectPrint::getManager()->drawString(16, 24, sMessageString); + } +} + +void flushMessage_dbPrint() { + if (flush_subroutine() && sVisible == true && JUTDbPrint::getManager()) { + JUTFont* font = JUTDbPrint::getManager()->getFont(); + if (font) { + u8 tmp = ((VIGetRetraceCount() & 60) << 2) | 0xF; + font->setGX(); + font->setCharColor(JUtility::TColor(255, tmp, tmp, 255)); + font->drawString(30, 36, sMessageFileLine, true); + font->drawString(30, 54, sMessageString, true); } } +} - void flushMessage_dbPrint() - { - if (flush_subroutine() && sVisible == true && JUTDbPrint::getManager()) - { - JUTFont *font = JUTDbPrint::getManager()->getFont(); - if (font) - { - u8 tmp = ((VIGetRetraceCount() & 60) << 2) | 0xF; - font->setGX(); - font->setCharColor(JUtility::TColor(255, tmp, tmp, 255)); - font->drawString(30, 36, sMessageFileLine, true); - font->drawString(30, 54, sMessageString, true); - } - } - } +void changeDisplayTime(u32 time) { + sDisplayTime = time; +} - void changeDisplayTime(u32 time) { - sDisplayTime = time; - } - - void changeDevice(u32 device) { - sDevice = device; - } -} \ No newline at end of file +void changeDevice(u32 device) { + sDevice = device; +} +} // namespace JUTAssertion diff --git a/src/static/JSystem/JUtility/JUTConsole.cpp b/src/static/JSystem/JUtility/JUTConsole.cpp index ddcda5eb..34fea4f2 100644 --- a/src/static/JSystem/JUtility/JUTConsole.cpp +++ b/src/static/JSystem/JUtility/JUTConsole.cpp @@ -13,16 +13,15 @@ #define OUTPUT_OSREPORT 2 #define OUTPUT_ALL (OUTPUT_OSREPORT | OUTPUT_CONSOLE) -JUTConsoleManager *JUTConsoleManager::sManager; +JUTConsoleManager* JUTConsoleManager::sManager; -JUTConsole *JUTConsole::create(uint param_0, uint maxLines, JKRHeap *pHeap) -{ - JUTConsoleManager *const pManager = JUTConsoleManager::getManager(); +JUTConsole* JUTConsole::create(uint param_0, uint maxLines, JKRHeap* pHeap) { + JUTConsoleManager* const pManager = JUTConsoleManager::getManager(); JUT_ASSERT(pManager != 0); - u8 *buffer = (u8*)JKRAllocFromHeap(pHeap, getObjectSizeFromBufferSize(param_0, maxLines), 0); + u8* buffer = (u8*)JKRAllocFromHeap(pHeap, getObjectSizeFromBufferSize(param_0, maxLines), 0); - JUTConsole *newConsole = new (buffer) JUTConsole(param_0, maxLines, true); + JUTConsole* newConsole = new (buffer) JUTConsole(param_0, maxLines, true); newConsole->mBuf = buffer + sizeof(JUTConsole); newConsole->clear(); @@ -30,15 +29,14 @@ JUTConsole *JUTConsole::create(uint param_0, uint maxLines, JKRHeap *pHeap) return newConsole; } -JUTConsole *JUTConsole::create(uint param_0, void *buffer, u32 bufferSize) -{ - JUTConsoleManager *const pManager = JUTConsoleManager::getManager(); +JUTConsole* JUTConsole::create(uint param_0, void* buffer, u32 bufferSize) { + JUTConsoleManager* const pManager = JUTConsoleManager::getManager(); JUT_ASSERT(pManager != 0); JUT_ASSERT(( (u32)buffer & 0x3 ) == 0); u32 maxLines = getLineFromObjectSize(bufferSize, param_0); - JUTConsole *newConsole = new (buffer) JUTConsole(param_0, maxLines, false); - newConsole->mBuf = (u8 *)buffer + sizeof(JUTConsole); + JUTConsole* newConsole = new (buffer) JUTConsole(param_0, maxLines, false); + newConsole->mBuf = (u8*)buffer + sizeof(JUTConsole); newConsole->clear(); pManager->appendConsole(newConsole); @@ -46,13 +44,12 @@ JUTConsole *JUTConsole::create(uint param_0, void *buffer, u32 bufferSize) } // unused -void JUTConsole::destroy(JUTConsole *console) { +void JUTConsole::destroy(JUTConsole* console) { JUT_ASSERT(console != 0); delete console; } -JUTConsole::JUTConsole(uint p1, uint maxLines, bool p3) -{ +JUTConsole::JUTConsole(uint p1, uint maxLines, bool p3) { _2C = p3; _20 = p1; mMaxLines = maxLines; @@ -61,8 +58,7 @@ JUTConsole::JUTConsole(uint p1, uint maxLines, bool p3) mPositionY = 50; mHeight = 20; - if (mHeight > mMaxLines) - { + if (mHeight > mMaxLines) { mHeight = mMaxLines; } @@ -81,133 +77,100 @@ JUTConsole::~JUTConsole() { JUTConsoleManager::getManager()->removeConsole(this); } -size_t JUTConsole::getObjectSizeFromBufferSize(unsigned int p1, unsigned int maxLines) -{ +size_t JUTConsole::getObjectSizeFromBufferSize(unsigned int p1, unsigned int maxLines) { int objSize = (p1 + 2) * maxLines + sizeof(JUTConsole); return objSize; } -size_t JUTConsole::getLineFromObjectSize(u32 bufferSize, unsigned int param_1) -{ +size_t JUTConsole::getLineFromObjectSize(u32 bufferSize, unsigned int param_1) { bufferSize -= sizeof(JUTConsole); int line = (bufferSize) / (param_1 + 2); return line; } -void JUTConsole::clear() -{ +void JUTConsole::clear() { _30 = 0; _34 = 0; _38 = 0; _3C = 0; - for (int i = 0; i < mMaxLines; i++) - { + for (int i = 0; i < mMaxLines; i++) { setLineAttr(i, 0); } setLineAttr(0, -1); *getLinePtr(0) = 0; } -void JUTConsole::doDraw(JUTConsole::EConsoleType consoleType) const -{ +void JUTConsole::doDraw(JUTConsole::EConsoleType consoleType) const { f32 font_yOffset; s32 changeLine_1; s32 changeLine_2; - if (mIsVisible && (mFont || consoleType == CONSOLE_TYPE_2)) - { - if (mHeight != 0) - { + if (mIsVisible && (mFont || consoleType == CONSOLE_TYPE_2)) { + if (mHeight != 0) { bool isConsoleType0 = consoleType == CONSOLE_TYPE_0 ? true : false; font_yOffset = 2.0f + mFontSizeY; - if (consoleType != CONSOLE_TYPE_2) - { - if (!JUTVideo::getManager()) - { + if (consoleType != CONSOLE_TYPE_2) { + if (!JUTVideo::getManager()) { J2DOrthoGraph ortho(0.0f, 0.0f, 640.0f, 480.0f, -1.0f, 1.0f); ortho.setPort(); - } - else - { + } else { f32 w = JUTVideo::getManager()->getFbWidth(); f32 h = JUTVideo::getManager()->getEfbHeight(); J2DOrthoGraph ortho(0.0f, 0.0f, w, h, -1.0f, 1.0f); ortho.setPort(); } - const JUtility::TColor *color; - if (isConsoleType0) - { + const JUtility::TColor* color; + if (isConsoleType0) { color = &_60; - } - else - { + } else { color = &_5C; } - J2DFillBox(mPositionX - 2, (int)(mPositionY - font_yOffset), - (int)((mFontSizeX * _20) + 4.0f), (int)(font_yOffset * mHeight), - *color); + J2DFillBox(mPositionX - 2, (int)(mPositionY - font_yOffset), (int)((mFontSizeX * _20) + 4.0f), + (int)(font_yOffset * mHeight), *color); mFont->setGX(); - if (isConsoleType0) - { + if (isConsoleType0) { s32 s = (diffIndex(_30, _38) - mHeight) + 1; - if (s <= 0) - { + if (s <= 0) { mFont->setCharColor(JUtility::TColor(255, 255, 255, 255)); - } - else if (_30 == _34) - { + } else if (_30 == _34) { mFont->setCharColor(JUtility::TColor(255, 230, 230, 255)); - } - else - { + } else { mFont->setCharColor(JUtility::TColor(230, 230, 255, 255)); } - } - else - { + } else { mFont->setCharColor(JUtility::TColor(230, 230, 230, 255)); } - } - else - { - JUTDirectPrint::getManager()->erase(mPositionX - 3, mPositionY - 2, - (_20 * 6) + 6, + } else { + JUTDirectPrint::getManager()->erase(mPositionX - 3, mPositionY - 2, (_20 * 6) + 6, (int)(font_yOffset * mHeight) + 4); } - char *linePtr; + char* linePtr; s32 curLine = _30; s32 yFactor = 0; - do - { - linePtr = (char *)getLinePtr(curLine); + do { + linePtr = (char*)getLinePtr(curLine); - if ((u8)linePtr[-1] != 0) - { - if (consoleType != CONSOLE_TYPE_2) - { - mFont->drawString_scale(mPositionX, ((yFactor * font_yOffset) + mPositionY), - mFontSizeX, mFontSizeY, linePtr, true); - } - else - { - JUTDirectPrint::getManager()->drawString( - mPositionX, ((yFactor * font_yOffset) + mPositionY), linePtr); + if ((u8)linePtr[-1] != 0) { + if (consoleType != CONSOLE_TYPE_2) { + mFont->drawString_scale(mPositionX, ((yFactor * font_yOffset) + mPositionY), mFontSizeX, + mFontSizeY, linePtr, true); + } else { + JUTDirectPrint::getManager()->drawString(mPositionX, ((yFactor * font_yOffset) + mPositionY), + linePtr); } changeLine_1 = curLine + 1; - changeLine_2 = ((((s32)changeLine_1 )>= (s32)mMaxLines)) ? 0 : changeLine_1; + changeLine_2 = ((((s32)changeLine_1) >= (s32)mMaxLines)) ? 0 : changeLine_1; yFactor += 1; curLine = changeLine_2; - } - else - { + } else { break; } } while (yFactor < mHeight && changeLine_2 != _34); @@ -215,70 +178,51 @@ void JUTConsole::doDraw(JUTConsole::EConsoleType consoleType) const } } -void JUTConsole::print_f(char const *text, ...) -{ +void JUTConsole::print_f(char const* text, ...) { va_list args; va_start(args, text); JUTConsole_print_f_va_(this, text, args); va_end(args); } -void JUTConsole::print(char const *param_0) -{ - if (mOutput & OUTPUT_OSREPORT) - { - //JUT_REPORT_MSG("%s", param_0); +void JUTConsole::print(char const* param_0) { + if (mOutput & OUTPUT_OSREPORT) { + // JUT_REPORT_MSG("%s", param_0); } - if (mOutput & OUTPUT_CONSOLE) - { - const u8 *r29 = (const u8 *)param_0; - u8 *r28 = getLinePtr(_38) + _3C; - while (*r29 != 0) - { - if (_66 && _34 == nextIndex(_38)) - { + if (mOutput & OUTPUT_CONSOLE) { + const u8* r29 = (const u8*)param_0; + u8* r28 = getLinePtr(_38) + _3C; + while (*r29 != 0) { + if (_66 && _34 == nextIndex(_38)) { break; } - if (*r29 == '\n') - { + if (*r29 == '\n') { r29++; _3C = _20; - } - else if (*r29 == '\t') - { + } else if (*r29 == '\t') { r29++; - while (_3C < _20) - { + while (_3C < _20) { *(r28++) = ' '; _3C++; - if (_3C % 8 == 0) - { + if (_3C % 8 == 0) { break; } } - } - else if (mFont && mFont->isLeadByte(*r29)) - { - if (_3C + 1 < _20) - { + } else if (mFont && mFont->isLeadByte(*r29)) { + if (_3C + 1 < _20) { *(r28++) = *(r29++); *(r28++) = *(r29++); _3C++; _3C++; - } - else - { + } else { *(r28++) = 0; _3C++; } - } - else - { + } else { *(r28++) = *(r29++); _3C++; } - if (_3C < _20) - { + if (_3C < _20) { continue; } *r28 = 0; @@ -288,26 +232,21 @@ void JUTConsole::print(char const *param_0) r28 = getLinePtr(_38); *r28 = 0; int local_28 = diffIndex(_30, _38); - if (local_28 == mHeight) - { + if (local_28 == mHeight) { _30 = nextIndex(_30); } - if (_38 == _34) - { + if (_38 == _34) { _34 = nextIndex(_34); } - if (_38 == _30) - { + if (_38 == _30) { _30 = nextIndex(_30); } - } *r28 = 0; } } -void JUTConsole_print_f_va_(JUTConsole *console, const char *text, va_list args) -{ +void JUTConsole_print_f_va_(JUTConsole* console, const char* text, va_list args) { char buf[1024]; JUT_ASSERT(console!=0); vsnprintf(buf, sizeof(buf), text, args); @@ -333,7 +272,7 @@ void JUTConsole::dumpToTerminal(unsigned int n) { } } } - //OSReport("\n:::dump of console[%x]--------------------------------\n", this); + // OSReport("\n:::dump of console[%x]--------------------------------\n", this); int i = 0; do { u8* line = getLinePtr(lineNo); @@ -341,41 +280,30 @@ void JUTConsole::dumpToTerminal(unsigned int n) { break; } if (_65) { - OSReport("[%03d] %s\n",i, line); - } - else { + OSReport("[%03d] %s\n", i, line); + } else { OSReport("%s\n", line); } lineNo = nextIndex(lineNo); i++; } while (lineNo != _34); - //OSReport(":::dump of console[%x] END----------------------------\n", this); + // OSReport(":::dump of console[%x] END----------------------------\n", this); } -void JUTConsole::scroll(int scrollAmnt) -{ - if (scrollAmnt < 0) - { +void JUTConsole::scroll(int scrollAmnt) { + if (scrollAmnt < 0) { int diff = diffIndex(_34, _30); - if (scrollAmnt < -diff) - { + if (scrollAmnt < -diff) { scrollAmnt = -diff; } - } - else - { - if (scrollAmnt > 0) - { - if (diffIndex(_34, _38) + 1 <= mHeight) - { + } else { + if (scrollAmnt > 0) { + if (diffIndex(_34, _38) + 1 <= mHeight) { scrollAmnt = 0; - } - else - { + } else { int diff = diffIndex(_30, _38) - mHeight + 1; - if (scrollAmnt > diff) - { + if (scrollAmnt > diff) { scrollAmnt = diff; } } @@ -383,92 +311,77 @@ void JUTConsole::scroll(int scrollAmnt) } _30 += scrollAmnt; - if (_30 < 0) - { + if (_30 < 0) { _30 += mMaxLines; } - if (_30 >= mMaxLines) - { + if (_30 >= mMaxLines) { _30 -= mMaxLines; } } -int JUTConsole::getUsedLine() const -{ +int JUTConsole::getUsedLine() const { int usedLine = diffIndex(_34, _38); return usedLine; } -int JUTConsole::getLineOffset() const -{ +int JUTConsole::getLineOffset() const { int offset = diffIndex(_34, _30); return offset; } -JUTConsoleManager::JUTConsoleManager() -{ +JUTConsoleManager::JUTConsoleManager() { mActiveConsole = nullptr; mDirectConsole = nullptr; } -JUTConsoleManager *JUTConsoleManager::createManager(JKRHeap *pHeap) -{ +JUTConsoleManager* JUTConsoleManager::createManager(JKRHeap* pHeap) { JUT_ASSERT(sManager == 0); - if (pHeap == nullptr) - { + if (pHeap == nullptr) { pHeap = JKRGetCurrentHeap(); } sManager = new (pHeap, 0) JUTConsoleManager(); return sManager; } -void JUTConsoleManager::appendConsole(JUTConsole *const console) -{ +void JUTConsoleManager::appendConsole(JUTConsole* const console) { JUT_ASSERT(sManager != 0 && console != 0); - - // not sure why this assert was 3 lines later JUT_ASSERT(soLink_.Find( console ) == soLink_.end()); soLink_.Push_back(console); - if (mActiveConsole == nullptr) - { + if (mActiveConsole == nullptr) { mActiveConsole = console; } } -void JUTConsoleManager::removeConsole(JUTConsole *const console) -{ +void JUTConsoleManager::removeConsole(JUTConsole* const console) { JUT_ASSERT(sManager != 0 && console != 0); JUT_ASSERT(soLink_.Find( console ) != soLink_.end()); - - if (mActiveConsole == console) - { - if(soLink_.size() <= 1) { + + if (mActiveConsole == console) { + if (soLink_.size() <= 1) { mActiveConsole = nullptr; - } - else { - mActiveConsole = console != &soLink_.back() ? soLink_.Element_toValue(console->mNode.getNext()) : &soLink_.front(); + } else { + mActiveConsole = + console != &soLink_.back() ? soLink_.Element_toValue(console->mNode.getNext()) : &soLink_.front(); } } if (JUTGetWarningConsole() == console) JUTSetWarningConsole(nullptr); if (JUTGetReportConsole() == console) JUTSetReportConsole(nullptr); - + soLink_.Remove(console); } -void JUTConsoleManager::draw() const -{ - // this cast is needed to match release, luckily doesn't affect tp debug either, so maybe there's another temp or cast somewhere? - JGadget::TLinkList::const_iterator it = ((const JUTConsoleManager *)this)->soLink_.begin(); +void JUTConsoleManager::draw() const { + // this cast is needed to match release, luckily doesn't affect tp debug either, so maybe there's another temp or + // cast somewhere? + JGadget::TLinkList::const_iterator it = ((const JUTConsoleManager*)this)->soLink_.begin(); JGadget::TLinkList::const_iterator itEnd = soLink_.end(); - for (; it != itEnd; ++it) - { - const JUTConsole &console = *it; - if (&console != mActiveConsole) - { + for (; it != itEnd; ++it) { + const JUTConsole& console = *it; + if (&console != mActiveConsole) { console.doDraw(JUTConsole::CONSOLE_TYPE_1); } } @@ -477,14 +390,12 @@ void JUTConsoleManager::draw() const mActiveConsole->doDraw(JUTConsole::CONSOLE_TYPE_0); } - void JUTConsoleManager::drawDirect(bool waitRetrace) const { - if(mDirectConsole) { - if(waitRetrace) { + if (mDirectConsole) { + if (waitRetrace) { BOOL interrupt = OSEnableInterrupts(); u32 retrace_count = VIGetRetraceCount(); - do - { + do { } while (retrace_count == VIGetRetraceCount()); OSRestoreInterrupts(interrupt); } @@ -492,83 +403,76 @@ void JUTConsoleManager::drawDirect(bool waitRetrace) const { } } -void JUTConsoleManager::setDirectConsole(JUTConsole *console) { +void JUTConsoleManager::setDirectConsole(JUTConsole* console) { if (mDirectConsole != nullptr) { appendConsole(mDirectConsole); } - if(console != nullptr) { + if (console != nullptr) { removeConsole(console); } mDirectConsole = console; } -static JUTConsole *sReportConsole; -static JUTConsole *sWarningConsole; +static JUTConsole* sReportConsole; +static JUTConsole* sWarningConsole; // C Functions -void JUTSetReportConsole(JUTConsole *console) { +void JUTSetReportConsole(JUTConsole* console) { sReportConsole = console; } -JUTConsole *JUTGetReportConsole() { +JUTConsole* JUTGetReportConsole() { return sReportConsole; } -void JUTSetWarningConsole(JUTConsole *console) { +void JUTSetWarningConsole(JUTConsole* console) { sWarningConsole = console; } -JUTConsole *JUTGetWarningConsole() { +JUTConsole* JUTGetWarningConsole() { return sWarningConsole; } -void JUTReportConsole_f_va(const char *text, va_list args) { +void JUTReportConsole_f_va(const char* text, va_list args) { char buf[256]; - if(!JUTGetReportConsole()) { + if (!JUTGetReportConsole()) { vsnprintf(buf, sizeof(buf), text, args); - //JUT_REPORT_MSG("%s", buf); - } - else if (JUTGetReportConsole()->getOutput() & OUTPUT_ALL) { + // JUT_REPORT_MSG("%s", buf); + } else if (JUTGetReportConsole()->getOutput() & OUTPUT_ALL) { vsnprintf(buf, sizeof(buf), text, args); JUTGetReportConsole()->print(buf); } } -void JUTReportConsole_f(const char *text, ...) -{ +void JUTReportConsole_f(const char* text, ...) { va_list vl; va_start(vl, text); JUTReportConsole_f_va(text, vl); va_end(vl); } -void JUTReportConsole(const char *text) { +void JUTReportConsole(const char* text) { JUTReportConsole_f("%s", text); } -void JUTWarningConsole_f_va(const char *text, va_list args) -{ +void JUTWarningConsole_f_va(const char* text, va_list args) { char buf[256]; - if (!JUTGetWarningConsole()) - { + if (!JUTGetWarningConsole()) { vsnprintf(buf, sizeof(buf), text, args); OSReport("%s", buf); - } - else if (JUTGetWarningConsole()->getOutput() & OUTPUT_ALL) - { + } else if (JUTGetWarningConsole()->getOutput() & OUTPUT_ALL) { vsnprintf(buf, sizeof(buf), text, args); JUTGetWarningConsole()->print(buf); } } -void JUTWarningConsole_f(const char *text, ...) -{ +void JUTWarningConsole_f(const char* text, ...) { va_list vl; va_start(vl, text); JUTReportConsole_f_va(text, vl); va_end(vl); } -void JUTWarningConsole(const char *text) { +void JUTWarningConsole(const char* text) { JUTReportConsole_f("%s", text); -} \ No newline at end of file +} diff --git a/src/static/JSystem/JUtility/JUTDbPrint.cpp b/src/static/JSystem/JUtility/JUTDbPrint.cpp index cd63fdd9..f0f264a6 100644 --- a/src/static/JSystem/JUtility/JUTDbPrint.cpp +++ b/src/static/JSystem/JUtility/JUTDbPrint.cpp @@ -6,11 +6,9 @@ #include "JSystem/JUtility/JUTVideo.h" #include "types.h" -JUTDbPrint *JUTDbPrint::sDebugPrint; +JUTDbPrint* JUTDbPrint::sDebugPrint; -JUTDbPrint::JUTDbPrint(JUTFont *font, JKRHeap *heap) - : mColor() -{ +JUTDbPrint::JUTDbPrint(JUTFont* font, JKRHeap* heap) : mColor() { mFont = font; mList = nullptr; mHeap = (heap) ? heap : JKRHeap::getCurrentHeap(); @@ -18,14 +16,12 @@ JUTDbPrint::JUTDbPrint(JUTFont *font, JKRHeap *heap) mVisible = true; } -JUTDbPrint::~JUTDbPrint() {} +JUTDbPrint::~JUTDbPrint() { +} -JUTDbPrint *JUTDbPrint::start(JUTFont *font, JKRHeap *heap) -{ - if (!sDebugPrint) - { - if (!heap) - { +JUTDbPrint* JUTDbPrint::start(JUTFont* font, JKRHeap* heap) { + if (!sDebugPrint) { + if (!heap) { heap = JKRHeap::getCurrentHeap(); } sDebugPrint = new JUTDbPrint(font, heap); @@ -33,98 +29,83 @@ JUTDbPrint *JUTDbPrint::start(JUTFont *font, JKRHeap *heap) return sDebugPrint; } -JUTFont *JUTDbPrint::changeFont(JUTFont *newFont) -{ - JUTFont *oldFont = mFont; - if (newFont) - { +JUTFont* JUTDbPrint::changeFont(JUTFont* newFont) { + JUTFont* oldFont = mFont; + if (newFont) { mFont = newFont; } return oldFont; } -void JUTDbPrint::enter(int x, int y, int duration, const char *txt, int len) -{ - if(len > 0) { - JUTDbPrintList *pList = (JUTDbPrintList *)JKRAllocFromHeap(mHeap, sizeof(JUTDbPrintList) + len, -4); - if (pList) - { +void JUTDbPrint::enter(int x, int y, int duration, const char* txt, int len) { + if (len > 0) { + JUTDbPrintList* pList = (JUTDbPrintList*)JKRAllocFromHeap(mHeap, sizeof(JUTDbPrintList) + len, -4); + if (pList) { pList->mX = x; pList->mY = y; pList->mDuration = duration; pList->mLen = len; - strcpy((char *)&pList->mStr, txt); + strcpy((char*)&pList->mStr, txt); pList->mNext = mList; mList = pList; } } } -void JUTDbPrint::flush() { +void JUTDbPrint::flush() { // eyebrow raise emoji - JUTDbPrintList *pList = (JUTDbPrintList *)&mList; - JUTDbPrintList *currList = mList; + JUTDbPrintList* pList = (JUTDbPrintList*)&mList; + JUTDbPrintList* currList = mList; - if (mFont) - { - if (currList) - { + if (mFont) { + if (currList) { J2DOrthoGraph orthograph(0.0f, 0.0f, 640.0f, 480.0f, -1.0f, 1.0f); orthograph.setPort(); mFont->setGX(); mFont->setCharColor(mColor); - while (currList) - { - if (mVisible) - { + while (currList) { + if (mVisible) { drawString(currList->mX, currList->mY, currList->mLen, &currList->mStr); } - if (--currList->mDuration <= 0) - { - JUTDbPrintList *next = currList->mNext; + if (--currList->mDuration <= 0) { + JUTDbPrintList* next = currList->mNext; JKRFreeToHeap(mHeap, currList); pList->mNext = next; currList = next; - } - else - { + } else { pList = currList; currList = currList->mNext; } } } - } } - -void JUTDbPrint::flush(int left, int top, int right, int bottom) -{ - + } } -void JUTDbPrint::drawString(int x, int y, int len, const unsigned char *str) -{ - mFont->drawString_size(x, y, reinterpret_cast(str), len, true); +void JUTDbPrint::flush(int left, int top, int right, int bottom) { } -void JUTReport(int x, int y, const char *fmt, ...) -{ +void JUTDbPrint::drawString(int x, int y, int len, const unsigned char* str) { + mFont->drawString_size(x, y, reinterpret_cast(str), len, true); +} + +void JUTReport(int x, int y, const char* fmt, ...) { va_list vl; va_start(vl, fmt); char buf[128]; s32 n = vsnprintf(buf, sizeof(buf), fmt, vl); if (n >= 0) { - JUTDbPrint::getManager()->enter(x, y, 1, buf, n < 256 ? n : 255); + JUTDbPrint::getManager()->enter(x, y, 1, buf, n < 256 ? n : 255); } va_end(); } -void JUTReport(int x, int y, int duration, const char *fmt, ...) -{ +void JUTReport(int x, int y, int duration, const char* fmt, ...) { va_list vl; va_start(vl, fmt); char buf[256]; s32 n = vsnprintf(buf, sizeof(buf), fmt, vl); if (n >= 0) { - JUTDbPrint::getManager()->enter(x, y, duration, buf, n < 256 ? n : 255); + JUTDbPrint::getManager()->enter(x, y, duration, buf, n < 256 ? n : 255); } va_end(vl); } diff --git a/src/static/JSystem/JUtility/JUTDirectFile.cpp b/src/static/JSystem/JUtility/JUTDirectFile.cpp index f78d5828..6466041a 100644 --- a/src/static/JSystem/JUtility/JUTDirectFile.cpp +++ b/src/static/JSystem/JUtility/JUTDirectFile.cpp @@ -1,27 +1,21 @@ #include #include "JSystem/JUtility/JUTDirectFile.h" -int JUTDirectFile::fetch32byte() -{ +int JUTDirectFile::fetch32byte() { mToRead = mLength - ALIGN_PREV(mPos, DVD_MIN_TRANSFER_SIZE); - if (mToRead > JUTDF_BUFSIZE) - { + if (mToRead > JUTDF_BUFSIZE) { mToRead = JUTDF_BUFSIZE; } int interrupts = OSEnableInterrupts(); int readRes = DVDReadAsync(&mFileInfo, mSectorStart, ALIGN_NEXT(mToRead, DVD_MIN_TRANSFER_SIZE), ALIGN_PREV(mPos, DVD_MIN_TRANSFER_SIZE), nullptr); OSRestoreInterrupts(interrupts); - if (!readRes) - { + if (!readRes) { return -1; - } - else - { + } else { interrupts = OSEnableInterrupts(); - while (DVDGetCommandBlockStatus(&mFileInfo.cb)) - { + while (DVDGetCommandBlockStatus(&mFileInfo.cb)) { ; } OSRestoreInterrupts(interrupts); @@ -29,30 +23,28 @@ int JUTDirectFile::fetch32byte() } } -JUTDirectFile::JUTDirectFile() -{ +JUTDirectFile::JUTDirectFile() { mLength = 0; mPos = 0; mToRead = 0; - mSectorStart = (u8 *)ALIGN_NEXT((u32)mBuffer, DVD_MIN_TRANSFER_SIZE); + mSectorStart = (u8*)ALIGN_NEXT((u32)mBuffer, DVD_MIN_TRANSFER_SIZE); mIsOpen = false; } -JUTDirectFile::~JUTDirectFile() { mIsOpen = false; } +JUTDirectFile::~JUTDirectFile() { + mIsOpen = false; +} -bool JUTDirectFile::fopen(const char *filename) -{ - if (!filename) - { +bool JUTDirectFile::fopen(const char* filename) { + if (!filename) { return false; } int interrupts = OSEnableInterrupts(); - int dvdRes = DVDOpen(const_cast(filename), &mFileInfo); + int dvdRes = DVDOpen(const_cast(filename), &mFileInfo); OSRestoreInterrupts(interrupts); - if (!dvdRes) - { + if (!dvdRes) { mIsOpen = false; return false; } @@ -66,10 +58,8 @@ bool JUTDirectFile::fopen(const char *filename) return true; } -void JUTDirectFile::fclose() -{ - if (mIsOpen) - { +void JUTDirectFile::fclose() { + if (mIsOpen) { int interrupts = OSEnableInterrupts(); DVDClose(&mFileInfo); OSRestoreInterrupts(interrupts); @@ -80,69 +70,58 @@ void JUTDirectFile::fclose() * Gets data of length 'len' and stores in 'buf'. * Returns actual length gotten in bytes, or -1 if error. */ -int JUTDirectFile::fgets(void *buf, int len) -{ +int JUTDirectFile::fgets(void* buf, int len) { // if file isn't open, return error (-1). - if (!mIsOpen) - { + if (!mIsOpen) { return -1; } // if desired length to get is 0, get... 0 bytes. - if (len == 0) - { + if (len == 0) { return 0; } // if desired length to get is 1, return 1. // (final byte gotten is always 0, so len 1 is pointless). - if (len == 1) - { + if (len == 1) { return 1; } // if buffer to read into doesn't exist, return error. - if (!buf) - { + if (!buf) { return -1; } // if we're already beyond the file length, return error. - if (mPos >= mLength) - { + if (mPos >= mLength) { return -1; } int readMax; - u8 *byteBuf = (u8 *)buf; + u8* byteBuf = (u8*)buf; readMax = len - 1; // desired bytes of data to get (last value is then 0). int readCount = 0; - while (mPos < mLength) - { + while (mPos < mLength) { // if there's nothing left to read, return error. - if (mToRead == 0 && fetch32byte() < 0) - { + if (mToRead == 0 && fetch32byte() < 0) { return -1; } // read in each chunk. u32 currPos = mPos & (JUTDF_BUFSIZE - 1); u32 chunkSize = (mToRead - currPos); - if (readCount + chunkSize > readMax) - { + if (readCount + chunkSize > readMax) { chunkSize = len - readCount - 1; } BOOL isAtEnd = FALSE; - for (int i = 0; i < chunkSize; i++) - { + for (int i = 0; i < chunkSize; i++) { u8 byte = mSectorStart[currPos++]; *byteBuf++ = byte; // if we hit the end of a line, stop reading. - if (byte == '\n') - { + if (byte == '\n') { chunkSize = i + 1; isAtEnd = TRUE; break; @@ -150,14 +129,12 @@ int JUTDirectFile::fgets(void *buf, int len) } // if we exceed the buffer size, stop reading. - if (currPos >= JUTDF_BUFSIZE) - { + if (currPos >= JUTDF_BUFSIZE) { mToRead = 0; } // if we hit the end of a line, set final byte to 0 and stop reading. - if (isAtEnd == TRUE) - { + if (isAtEnd == TRUE) { readCount += chunkSize; *byteBuf = 0; mPos += chunkSize; @@ -169,18 +146,16 @@ int JUTDirectFile::fgets(void *buf, int len) mPos += chunkSize; // if we're at (or beyond) our desired length, set final byte to 0 and stop reading. - if (readCount >= readMax) - { + if (readCount >= readMax) { *byteBuf = 0; break; } } // if got to the end of the data, set final byte to 0. - if (mPos >= mLength) - { + if (mPos >= mLength) { *byteBuf = 0; } return readCount; -} \ No newline at end of file +} diff --git a/src/static/JSystem/JUtility/JUTDirectPrint.cpp b/src/static/JSystem/JUtility/JUTDirectPrint.cpp index 32aa8d59..5ad86db3 100644 --- a/src/static/JSystem/JUtility/JUTDirectPrint.cpp +++ b/src/static/JSystem/JUtility/JUTDirectPrint.cpp @@ -3,15 +3,13 @@ #include "MSL_C/printf.h" #include "JSystem/JUtility/JUTDirectPrint.h" -JUTDirectPrint *JUTDirectPrint::sDirectPrint; +JUTDirectPrint* JUTDirectPrint::sDirectPrint; -JUTDirectPrint::JUTDirectPrint() -{ +JUTDirectPrint::JUTDirectPrint() { changeFrameBuffer(nullptr, 0, 0); } -JUTDirectPrint *JUTDirectPrint::start() -{ +JUTDirectPrint* JUTDirectPrint::start() { if (!sDirectPrint) { sDirectPrint = new JUTDirectPrint(); } @@ -19,29 +17,24 @@ JUTDirectPrint *JUTDirectPrint::start() return sDirectPrint; } -void JUTDirectPrint::erase(int x, int y, int width, int height) -{ +void JUTDirectPrint::erase(int x, int y, int width, int height) { if (!mFramebuffer) { return; } - if (400 < mFbWidth) - { + if (400 < mFbWidth) { x = x << 1; width = width << 1; } - if (300 < mFbHeight) - { + if (300 < mFbHeight) { y = y << 1; height = height << 1; } - u16 *pixel = mFrameMemory + mStride * y + x; - for (int i = 0; i < height; i++) - { - for (int j = 0; j < width; j++) - { + u16* pixel = mFrameMemory + mStride * y + x; + for (int i = 0; i < height; i++) { + for (int j = 0; j < width; j++) { *pixel = 0x1080; pixel = pixel + 1; } @@ -51,14 +44,13 @@ void JUTDirectPrint::erase(int x, int y, int width, int height) } u8 JUTDirectPrint::sAsciiTable[128] = { - 0x7A, 0x7A, 0x7A, 0x7A, 0x7A, 0x7A, 0x7A, 0x7A, 0x7A, 0xFD, 0xFE, 0x7A, 0x7A, 0x7A, 0x7A, 0x7A, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0x29, 0x64, 0x65, 0x66, 0x2B, 0x67, 0x68, 0x25, 0x26, 0x69, 0x2A, 0x6A, 0x27, 0x2C, 0x6B, - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x24, 0x6C, 0x6D, 0x6E, 0x6F, 0x28, - 0x70, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, - 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x71, 0x72, 0x73, 0x74, 0x75, - 0xFF, 0x7D, 0x7E, 0x7F, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x8B, - 0x8C, 0x8D, 0x8E, 0x8F, 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x76, 0x77, 0x78, 0x79, 0x7A, + 0x7A, 0x7A, 0x7A, 0x7A, 0x7A, 0x7A, 0x7A, 0x7A, 0x7A, 0xFD, 0xFE, 0x7A, 0x7A, 0x7A, 0x7A, 0x7A, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x29, 0x64, 0x65, 0x66, 0x2B, + 0x67, 0x68, 0x25, 0x26, 0x69, 0x2A, 0x6A, 0x27, 0x2C, 0x6B, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, + 0x09, 0x24, 0x6C, 0x6D, 0x6E, 0x6F, 0x28, 0x70, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, + 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x71, 0x72, 0x73, 0x74, + 0x75, 0xFF, 0x7D, 0x7E, 0x7F, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, + 0x8E, 0x8F, 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x76, 0x77, 0x78, 0x79, 0x7A, }; u32 JUTDirectPrint::sFontData[64] = { @@ -73,15 +65,14 @@ u32 JUTDirectPrint::sFontData[64] = { }; u32 JUTDirectPrint::sFontData2[77] = { - 0x51421820, 0x53E7A420, 0x014A2C40, 0x01471000, 0x0142AA00, 0x03EAA400, 0x01471A78, 0x00000000, - 0x50008010, 0x20010820, 0xF8020040, 0x20420820, 0x50441010, 0x00880000, 0x00070E00, 0x01088840, - 0x78898820, 0x004A8810, 0x788A8810, 0x01098808, 0x00040E04, 0x70800620, 0x11400820, 0x12200820, - 0x10001020, 0x10000820, 0x100F8820, 0x70000620, 0x60070000, 0x110F82A0, 0x12AA8AE0, 0x084F92A0, - 0x100FBE1C, 0x10089008, 0x60070808, 0x00000000, 0x02000200, 0x7A078270, 0x8BC81E88, 0x8A2822F8, - 0x9A282280, 0x6BC79E78, 0x30000000, 0x48080810, 0x41E80000, 0x422F1830, 0xFBE88810, 0x40288890, - 0x43C89C60, 0x81000000, 0x81000000, 0x990F3C70, 0xA10AA288, 0xE10AA288, 0xA10AA288, 0x98CAA270, - 0x00000000, 0x00000020, 0xF1EF1E20, 0x8A28A0F8, 0x8A281C20, 0xF1E80220, 0x80283C38, 0x00000000, - 0x00000000, 0x8A28B688, 0x8A2A8888, 0x8A2A8878, 0x894A8808, 0x788536F0, 0x00000000, 0x00000000, + 0x51421820, 0x53E7A420, 0x014A2C40, 0x01471000, 0x0142AA00, 0x03EAA400, 0x01471A78, 0x00000000, 0x50008010, + 0x20010820, 0xF8020040, 0x20420820, 0x50441010, 0x00880000, 0x00070E00, 0x01088840, 0x78898820, 0x004A8810, + 0x788A8810, 0x01098808, 0x00040E04, 0x70800620, 0x11400820, 0x12200820, 0x10001020, 0x10000820, 0x100F8820, + 0x70000620, 0x60070000, 0x110F82A0, 0x12AA8AE0, 0x084F92A0, 0x100FBE1C, 0x10089008, 0x60070808, 0x00000000, + 0x02000200, 0x7A078270, 0x8BC81E88, 0x8A2822F8, 0x9A282280, 0x6BC79E78, 0x30000000, 0x48080810, 0x41E80000, + 0x422F1830, 0xFBE88810, 0x40288890, 0x43C89C60, 0x81000000, 0x81000000, 0x990F3C70, 0xA10AA288, 0xE10AA288, + 0xA10AA288, 0x98CAA270, 0x00000000, 0x00000020, 0xF1EF1E20, 0x8A28A0F8, 0x8A281C20, 0xF1E80220, 0x80283C38, + 0x00000000, 0x00000000, 0x8A28B688, 0x8A2A8888, 0x8A2A8878, 0x894A8808, 0x788536F0, 0x00000000, 0x00000000, 0xF8000000, 0x10000000, 0x20000000, 0x40000000, 0xF8000000, }; @@ -90,12 +81,12 @@ void JUTDirectPrint::drawChar(int position_x, int position_y, int ch) { int col_index = (codepoint % 5) * 6; int row_index = (codepoint / 5) * 7; - const u32 *font_data = (100 > ch) ? sFontData + row_index : sFontData2 + row_index; + const u32* font_data = (100 > ch) ? sFontData + row_index : sFontData2 + row_index; int scale_x = (mFbWidth < 400) ? 1 : 2; int scale_y = (mFbHeight < 300) ? 1 : 2; - u16 *pixel = mFrameMemory + mStride * position_y * scale_y + position_x * scale_x; + u16* pixel = mFrameMemory + mStride * position_y * scale_y + position_x * scale_x; for (int y = 0; y < 7; y++) { u32 data = *font_data << col_index; font_data += 1; @@ -119,52 +110,40 @@ void JUTDirectPrint::drawChar(int position_x, int position_y, int ch) { } } -void JUTDirectPrint::changeFrameBuffer(void *fb, u16 width, u16 height) -{ +void JUTDirectPrint::changeFrameBuffer(void* fb, u16 width, u16 height) { mFramebuffer = fb; - mFrameMemory = (u16 *)fb; + mFrameMemory = (u16*)fb; mFbWidth = width; mFbHeight = height; mStride = ALIGN_NEXT((u16)width, 16); mFbSize = (u32)mStride * (u32)mFbHeight * 2; } -void JUTDirectPrint::printSub(u16 position_x, u16 position_y, const char *format, va_list args, bool clear) -{ +void JUTDirectPrint::printSub(u16 position_x, u16 position_y, const char* format, va_list args, bool clear) { char buffer[256]; - if (!mFrameMemory) - { + if (!mFrameMemory) { return; } int buffer_length = vsnprintf(buffer, sizeof(buffer), format, args); u16 x = position_x; - if (buffer_length > 0) - { - if (clear) - { + if (buffer_length > 0) { + if (clear) { erase(position_x - 6, position_y - 3, (buffer_length + 2) * 6, 0xd); } - char *ptr = buffer; - for (; 0 < buffer_length; buffer_length--, ptr++) - { + char* ptr = buffer; + for (; 0 < buffer_length; buffer_length--, ptr++) { int codepoint = sAsciiTable[*ptr & 0x7f]; - if (codepoint == 0xfe) - { + if (codepoint == 0xfe) { position_x = x; position_y += 7; - } - else if (codepoint == 0xfd) - { + } else if (codepoint == 0xfd) { s32 current_position = (int)position_x; s32 tab = (current_position - x + 0x2f) % 0x30; position_x = current_position + 0x30 - tab; - } - else - { - if (codepoint != 0xff) - { + } else { + if (codepoint != 0xff) { drawChar(position_x, position_y, codepoint); } position_x += 6; @@ -175,10 +154,8 @@ void JUTDirectPrint::printSub(u16 position_x, u16 position_y, const char *format DCFlushRange(mFrameMemory, mFbSize); } -void JUTDirectPrint::print(u16 position_x, u16 position_y, char const *format, ...) -{ - if (mFrameMemory) - { +void JUTDirectPrint::print(u16 position_x, u16 position_y, char const* format, ...) { + if (mFrameMemory) { va_list args; va_start(args, format); printSub(position_x, position_y, format, args, true); @@ -186,18 +163,15 @@ void JUTDirectPrint::print(u16 position_x, u16 position_y, char const *format, . } } -void JUTDirectPrint::drawString(u16 position_x, u16 position_y, char *text) -{ +void JUTDirectPrint::drawString(u16 position_x, u16 position_y, char* text) { drawString_f(position_x, position_y, "%s", text); } -void JUTDirectPrint::drawString_f(u16 position_x, u16 position_y, char const *format, ...) -{ - if (mFrameMemory) - { +void JUTDirectPrint::drawString_f(u16 position_x, u16 position_y, char const* format, ...) { + if (mFrameMemory) { va_list args; va_start(args, format); printSub(position_x, position_y, format, args, false); va_end(args); } -} \ No newline at end of file +} diff --git a/src/static/JSystem/JUtility/JUTException.cpp b/src/static/JSystem/JUtility/JUTException.cpp index c3b04d85..6086c10b 100644 --- a/src/static/JSystem/JUtility/JUTException.cpp +++ b/src/static/JSystem/JUtility/JUTException.cpp @@ -11,9 +11,7 @@ #include "JSystem/JUtility/JUTDirectPrint.h" #include "JSystem/JUtility/JUTDirectFile.h" - -struct CallbackObject -{ +struct CallbackObject { JUTErrorHandler callback; u16 error; OSContext* context; @@ -21,63 +19,58 @@ struct CallbackObject u32 dar; }; -void search_name_part(u8 *, u8 *, int); +void search_name_part(u8*, u8*, int); -void *JUTException::sMessageBuffer[1] = { nullptr}; +void* JUTException::sMessageBuffer[1] = { nullptr }; OSMessageQueue JUTException::sMessageQueue = {}; -static OSTime c3bcnt[4] = {0, 0, 0, 0}; -const char *JUTException::sCpuExpName[] = { - "SYSTEM RESET", - "MACHINE CHECK", - "DSI", - "ISI", - "EXTERNAL INTERRUPT", - "ALIGNMENT", - "PROGRAM", - "FLOATING POINT", - "DECREMENTER", - "SYSTEM CALL", - "TRACE", - "PERFORMACE MONITOR", - "BREAK POINT", - "SYSTEM INTERRUPT", - "THERMAL INTERRUPT", - "PROTECTION" -}; +static OSTime c3bcnt[4] = { 0, 0, 0, 0 }; +const char* JUTException::sCpuExpName[] = { "SYSTEM RESET", + "MACHINE CHECK", + "DSI", + "ISI", + "EXTERNAL INTERRUPT", + "ALIGNMENT", + "PROGRAM", + "FLOATING POINT", + "DECREMENTER", + "SYSTEM CALL", + "TRACE", + "PERFORMACE MONITOR", + "BREAK POINT", + "SYSTEM INTERRUPT", + "THERMAL INTERRUPT", + "PROTECTION" }; -JUTException *JUTException::sErrorManager; +JUTException* JUTException::sErrorManager; JUTErrorHandler JUTException::sPreUserCallback; JUTErrorHandler JUTException::sPostUserCallback; static CallbackObject exCallbackObject; -void *JUTException::sConsoleBuffer; +void* JUTException::sConsoleBuffer; u32 JUTException::sConsoleBufferSize; -JUTConsole *JUTException::sConsole; +JUTConsole* JUTException::sConsole; u32 JUTException::msr; u32 JUTException::fpscr; - JSUList JUTException::sMapFileList(false); -JUTException *JUTException::create(JUTDirectPrint *directPrint) { - if(sErrorManager == nullptr) { +JUTException* JUTException::create(JUTDirectPrint* directPrint) { + if (sErrorManager == nullptr) { sErrorManager = new (JKRGetSystemHeap(), 0) JUTException(directPrint); sErrorManager->resume(); } return sErrorManager; } -void *JUTException::run() -{ +void* JUTException::run() { PPCMtmsr(PPCMfmsr() & ~0x0900); OSInitMessageQueue(&sMessageQueue, sMessageBuffer, 1); OSMessage message; - while (true) - { + while (true) { OSReceiveMessage(&sMessageQueue, &message, OS_MESSAGE_BLOCK); - CallbackObject *cb = (CallbackObject *)message; + CallbackObject* cb = (CallbackObject*)message; JUTErrorHandler callback = cb->callback; u16 error = cb->error; - OSContext *context = cb->context; + OSContext* context = cb->context; u32 dsisr = cb->dsisr; u32 dar = cb->dar; @@ -94,7 +87,7 @@ void *JUTException::run() } } -JUTException::JUTException(JUTDirectPrint *directPrint) : JKRThread(0x4000, 0x10, 0) { +JUTException::JUTException(JUTDirectPrint* directPrint) : JKRThread(0x4000, 0x10, 0) { mDirectPrint = directPrint; OSSetErrorHandler(OS_ERROR_DSI, (OSErrorHandler)errorHandler); @@ -114,14 +107,12 @@ JUTException::JUTException(JUTDirectPrint *directPrint) : JKRThread(0x4000, 0x10 mPrintFlags = EXPRINTFLAG_All; } -void JUTException::errorHandler(OSError error, OSContext *context, u32 dsisr, u32 dar) -{ +void JUTException::errorHandler(OSError error, OSContext* context, u32 dsisr, u32 dar) { msr = PPCMfmsr(); fpscr = getFpscr(); OSFillFPUContext(context); OSSetErrorHandler(error, nullptr); - if (error == OS_ERROR_PROTECTION) - { + if (error == OS_ERROR_PROTECTION) { OSProtectRange(0, nullptr, 0, 3); OSProtectRange(1, nullptr, 0, 3); OSProtectRange(2, nullptr, 0, 3); @@ -139,43 +130,30 @@ void JUTException::errorHandler(OSError error, OSContext *context, u32 dsisr, u3 OSYieldThread(); } -void JUTException::showFloatSub(int index, f32 value) -{ - if (isnan(value)) - { +void JUTException::showFloatSub(int index, f32 value) { + if (isnan(value)) { sConsole->print_f("F%02d: Nan ", index); - } - else if (isinf(value)) - { + } else if (isinf(value)) { if ((*(u8*)(&value)) & 0x80) // signed { sConsole->print_f("F%02d:+Inf ", index); - } - else - { + } else { sConsole->print_f("F%02d:-Inf ", index); } - } - else if (value == 0.0f) - { + } else if (value == 0.0f) { sConsole->print_f("F%02d: 0.0 ", index); - } - else - { + } else { sConsole->print_f("F%02d:%+.3E", index, value); } } -void JUTException::showFloat(OSContext *context) -{ - if (!sConsole) - { +void JUTException::showFloat(OSContext* context) { + if (!sConsole) { return; } sConsole->print("-------------------------------- FPR\n"); - for (int i = 0; i < 10; i++) - { + for (int i = 0; i < 10; i++) { showFloatSub(i, context->fpr[i]); sConsole->print(" "); showFloatSub(i + 11, context->fpr[i + 11]); @@ -189,24 +167,19 @@ void JUTException::showFloat(OSContext *context) sConsole->print("\n"); } -bool JUTException::searchPartialModule(u32 address, u32 *module_id, u32 *section_id, u32 *section_offset, u32 *name_offset) -{ - if (!address) - { +bool JUTException::searchPartialModule(u32 address, u32* module_id, u32* section_id, u32* section_offset, + u32* name_offset) { + if (!address) { return false; } - OSModuleInfo *module = *(OSModuleInfo **)0x800030C8; - for (; module != nullptr; module = module->link.next) - { - OSSectionInfo *section = OSGetSectionInfo(module); - for (u32 i = 0; i < module->numSections; section++, i++) - { - if (section->size != 0) - { + OSModuleInfo* module = *(OSModuleInfo**)0x800030C8; + for (; module != nullptr; module = module->link.next) { + OSSectionInfo* section = OSGetSectionInfo(module); + for (u32 i = 0; i < module->numSections; section++, i++) { + if (section->size != 0) { u32 addr = section->offset & ~0x01; - if ((addr <= address) && (address < addr + section->size)) - { + if ((addr <= address) && (address < addr + section->size)) { if (module_id) *module_id = module->id; if (section_id) @@ -224,23 +197,18 @@ bool JUTException::searchPartialModule(u32 address, u32 *module_id, u32 *section return false; } -void search_name_part(u8 *src, u8 *dst, int dst_length) -{ - for (u8 *p = src; *p; p++) - { - if (*p == '\\') - { +void search_name_part(u8* src, u8* dst, int dst_length) { + for (u8* p = src; *p; p++) { + if (*p == '\\') { src = p; } } - if (*src == '\\') - { + if (*src == '\\') { src++; } - for (int i = 0; (*src != 0) && (i < dst_length);) - { + for (int i = 0; (*src != 0) && (i < dst_length);) { if (*src == '.') break; *dst++ = *src++; @@ -250,10 +218,8 @@ void search_name_part(u8 *src, u8 *dst, int dst_length) *dst = '\0'; } -void JUTException::showStack(OSContext *context) -{ - if (!sConsole) - { +void JUTException::showStack(OSContext* context) { + if (!sConsole) { return; } @@ -263,27 +229,23 @@ void JUTException::showStack(OSContext *context) sConsole->print_f("Address: BackChain LR save\n"); for (i = 0, stackPointer = (u32*)context->gpr[1]; - (stackPointer != nullptr) && (stackPointer != (u32*)0xFFFFFFFF) - && (i++ < 0x10);) { - if (i > mTraceSuppress) { - sConsole->print("Suppress trace.\n"); - return; - } + (stackPointer != nullptr) && (stackPointer != (u32*)0xFFFFFFFF) && (i++ < 0x10);) { + if (i > mTraceSuppress) { + sConsole->print("Suppress trace.\n"); + return; + } - sConsole->print_f("%08X: %08X %08X\n", stackPointer, - stackPointer[0], stackPointer[1]); - showMapInfo_subroutine(stackPointer[1], false); - JUTConsoleManager* manager = JUTConsoleManager::sManager; - manager->drawDirect(true); - waitTime(mPrintWaitTime1); - stackPointer = (u32*)stackPointer[0]; - } + sConsole->print_f("%08X: %08X %08X\n", stackPointer, stackPointer[0], stackPointer[1]); + showMapInfo_subroutine(stackPointer[1], false); + JUTConsoleManager* manager = JUTConsoleManager::sManager; + manager->drawDirect(true); + waitTime(mPrintWaitTime1); + stackPointer = (u32*)stackPointer[0]; + } } -void JUTException::showMainInfo(u16 error, OSContext *context, u32 dsisr, u32 dar) -{ - if (!sConsole) - { +void JUTException::showMainInfo(u16 error, OSContext* context, u32 dsisr, u32 dar) { + if (!sConsole) { return; } @@ -292,26 +254,21 @@ void JUTException::showMainInfo(u16 error, OSContext *context, u32 dsisr, u32 da sConsole->print_f("DSISR: %08XH DAR: %08XH\n", dsisr, dar); } -void JUTException::showGPR(OSContext *context) -{ - if (!sConsole) - { +void JUTException::showGPR(OSContext* context) { + if (!sConsole) { return; } sConsole->print("-------------------------------- GPR\n"); - for (int i = 0; i < 10; i++) - { - sConsole->print_f("R%02d:%08XH R%02d:%08XH R%02d:%08XH\n", i, context->gpr[i], i + 11, - context->gpr[i + 11], i + 22, context->gpr[i + 22]); + for (int i = 0; i < 10; i++) { + sConsole->print_f("R%02d:%08XH R%02d:%08XH R%02d:%08XH\n", i, context->gpr[i], i + 11, context->gpr[i + 11], + i + 22, context->gpr[i + 22]); } sConsole->print_f("R%02d:%08XH R%02d:%08XH\n", 10, context->gpr[10], 21, context->gpr[21]); } -bool JUTException::showMapInfo_subroutine(u32 address, bool begin_with_newline) -{ - if ((address < 0x80000000) || (0x82ffffff < address)) - { +bool JUTException::showMapInfo_subroutine(u32 address, bool begin_with_newline) { + if ((address < 0x80000000) || (0x82ffffff < address)) { return false; } @@ -321,43 +278,34 @@ bool JUTException::showMapInfo_subroutine(u32 address, bool begin_with_newline) u32 section_offset; u8 name_part[36]; - const char *new_line = "\n"; - if (begin_with_newline == false) - { + const char* new_line = "\n"; + if (begin_with_newline == false) { new_line = ""; } - bool result = - searchPartialModule(address, &module_id, §ion_id, §ion_offset, &name_offset); - if (result == true) - { - search_name_part((u8 *)name_offset, name_part, 32); + bool result = searchPartialModule(address, &module_id, §ion_id, §ion_offset, &name_offset); + if (result == true) { + search_name_part((u8*)name_offset, name_part, 32); sConsole->print_f("%s %s:%x section:%d\n", new_line, name_part, section_offset, section_id); begin_with_newline = false; } JSUListIterator last = sMapFileList.getEnd(); JSUListIterator first = sMapFileList.getFirst(); - if (first != last) - { + if (first != last) { u32 out_addr; u32 out_size; char out_line[256]; - if (result == true) - { - result = - queryMapAddress((char *)name_part, section_offset, section_id, &out_addr, &out_size, - out_line, sizeof(out_line), true, begin_with_newline); - } - else - { - result = queryMapAddress(nullptr, address, -1, &out_addr, &out_size, out_line, + if (result == true) { + result = queryMapAddress((char*)name_part, section_offset, section_id, &out_addr, &out_size, out_line, sizeof(out_line), true, begin_with_newline); + } else { + result = queryMapAddress(nullptr, address, -1, &out_addr, &out_size, out_line, sizeof(out_line), true, + begin_with_newline); } - if (result == true) - { + if (result == true) { return true; } } @@ -365,27 +313,22 @@ bool JUTException::showMapInfo_subroutine(u32 address, bool begin_with_newline) return false; } -void JUTException::showGPRMap(OSContext *context) -{ - if (!sConsole) - { +void JUTException::showGPRMap(OSContext* context) { + if (!sConsole) { return; } bool found_address_register = false; sConsole->print("-------------------------------- GPRMAP\n"); - for (int i = 0; i < 31; i++) - { + for (int i = 0; i < 31; i++) { u32 address = context->gpr[i]; - if (address >= 0x80000000 && 0x83000000 - 1 >= address) - { + if (address >= 0x80000000 && 0x83000000 - 1 >= address) { found_address_register = true; sConsole->print_f("R%02d: %08XH", i, address); - if (!showMapInfo_subroutine(address, true)) - { + if (!showMapInfo_subroutine(address, true)) { sConsole->print(" no information\n"); } JUTConsoleManager::sManager->drawDirect(true); @@ -393,74 +336,63 @@ void JUTException::showGPRMap(OSContext *context) } } - if (!found_address_register) - { + if (!found_address_register) { sConsole->print(" no register which seem to address.\n"); } } -void JUTException::printDebugInfo(JUTException::EInfoPage page, OSError error, OSContext *context, u32 param_3, u32 param_4) -{ - switch (page) - { - case INFOPAGE_GPR: - return showGPR(context); - case INFOPAGE_Float: - showFloat(context); - if (sConsole) - { - sConsole->print_f(" MSR:%08XH\t FPSCR:%08XH\n", msr, fpscr); - } - break; - case INFOPAGE_Stack: - return showStack(context); - case INFOPAGE_GPRMap: - return showGPRMap(context); +void JUTException::printDebugInfo(JUTException::EInfoPage page, OSError error, OSContext* context, u32 param_3, + u32 param_4) { + switch (page) { + case INFOPAGE_GPR: + return showGPR(context); + case INFOPAGE_Float: + showFloat(context); + if (sConsole) { + sConsole->print_f(" MSR:%08XH\t FPSCR:%08XH\n", msr, fpscr); + } + break; + case INFOPAGE_Stack: + return showStack(context); + case INFOPAGE_GPRMap: + return showGPRMap(context); } } -bool JUTException::isEnablePad() const -{ - if (mGamePad == (JUTGamePad *)0xFFFFFFFF) +bool JUTException::isEnablePad() const { + if (mGamePad == (JUTGamePad*)0xFFFFFFFF) return true; if (mPadPort >= JUTGamePad::Port1) return true; - if(mGamePad) { + if (mGamePad) { return true; } return false; } -bool JUTException::readPad(u32 *out_trigger, u32 *out_button) -{ +bool JUTException::readPad(u32* out_trigger, u32* out_button) { bool result = false; OSTime start_time = OSGetTime(); OSTime ms; - do - { + do { OSTime end_time = OSGetTime(); OSTime ticks = end_time - start_time; ms = ticks / (OS_TIMER_CLOCK / 1000); } while (ms < 0x32); - if (mGamePad == (JUTGamePad *)0xffffffff) - { + if (mGamePad == (JUTGamePad*)0xffffffff) { JUTGamePad gamePad0(JUTGamePad::Port1); JUTGamePad gamePad1(JUTGamePad::Port2); JUTGamePad gamePad2(JUTGamePad::Port3); JUTGamePad gamePad3(JUTGamePad::Port4); JUTGamePad::read(); - c3bcnt[0] = - (gamePad0.isPushing3ButtonReset() ? (c3bcnt[0] != 0 ? c3bcnt[0] : OSGetTime()) : 0); - c3bcnt[1] = - (gamePad1.isPushing3ButtonReset() ? (c3bcnt[1] != 0 ? c3bcnt[1] : OSGetTime()) : 0); - c3bcnt[2] = - (gamePad2.isPushing3ButtonReset() ? (c3bcnt[2] != 0 ? c3bcnt[2] : OSGetTime()) : 0); - c3bcnt[3] = - (gamePad3.isPushing3ButtonReset() ? (c3bcnt[3] != 0 ? c3bcnt[3] : OSGetTime()) : 0); + c3bcnt[0] = (gamePad0.isPushing3ButtonReset() ? (c3bcnt[0] != 0 ? c3bcnt[0] : OSGetTime()) : 0); + c3bcnt[1] = (gamePad1.isPushing3ButtonReset() ? (c3bcnt[1] != 0 ? c3bcnt[1] : OSGetTime()) : 0); + c3bcnt[2] = (gamePad2.isPushing3ButtonReset() ? (c3bcnt[2] != 0 ? c3bcnt[2] : OSGetTime()) : 0); + c3bcnt[3] = (gamePad3.isPushing3ButtonReset() ? (c3bcnt[3] != 0 ? c3bcnt[3] : OSGetTime()) : 0); OSTime resetTime0 = (c3bcnt[0] != 0) ? (OSGetTime() - c3bcnt[0]) : 0; OSTime resetTime1 = (c3bcnt[1] != 0) ? (OSGetTime() - c3bcnt[1]) : 0; @@ -472,50 +404,38 @@ bool JUTException::readPad(u32 *out_trigger, u32 *out_button) gamePad2.checkResetCallback(resetTime2); gamePad3.checkResetCallback(resetTime3); - if (out_trigger) - { - *out_trigger = gamePad0.getTrigger() | gamePad1.getTrigger() | gamePad2.getTrigger() | - gamePad3.getTrigger(); + if (out_trigger) { + *out_trigger = + gamePad0.getTrigger() | gamePad1.getTrigger() | gamePad2.getTrigger() | gamePad3.getTrigger(); } - if (out_button) - { - *out_button = gamePad0.getButton() | gamePad1.getButton() | gamePad2.getButton() | - gamePad3.getButton(); + if (out_button) { + *out_button = gamePad0.getButton() | gamePad1.getButton() | gamePad2.getButton() | gamePad3.getButton(); } result = true; - } - else if (mPadPort >= JUTGamePad::Port1) - { + } else if (mPadPort >= JUTGamePad::Port1) { JUTGamePad gamePad(mPadPort); - OSTime &gamePadTime = c3bcnt[0]; - gamePadTime = - (gamePad.isPushing3ButtonReset() ? (gamePadTime != 0 ? gamePadTime : OSGetTime()) : 0); + OSTime& gamePadTime = c3bcnt[0]; + gamePadTime = (gamePad.isPushing3ButtonReset() ? (gamePadTime != 0 ? gamePadTime : OSGetTime()) : 0); OSTime resetTime = (gamePadTime != 0) ? (OSGetTime() - gamePadTime) : 0; gamePad.checkResetCallback(resetTime); JUTGamePad::read(); - if (out_trigger) - { + if (out_trigger) { *out_trigger = gamePad.getTrigger(); } - if (out_button) - { + if (out_button) { *out_button = gamePad.getButton(); } result = true; - } - else if (mGamePad) - { + } else if (mGamePad) { JUTGamePad::read(); - if (out_trigger) - { + if (out_trigger) { *out_trigger = mGamePad->getTrigger(); } - if (out_button) - { + if (out_button) { *out_button = mGamePad->getButton(); } @@ -525,50 +445,41 @@ bool JUTException::readPad(u32 *out_trigger, u32 *out_button) return result; } -void JUTException::printContext(OSError error, OSContext *context, u32 dsisr, u32 dar) -{ +void JUTException::printContext(OSError error, OSContext* context, u32 dsisr, u32 dar) { bool is_pad_enabled = isEnablePad() ? false : true; - if (!sErrorManager->mDirectPrint->isActive()) - { + if (!sErrorManager->mDirectPrint->isActive()) { return; } - if (!sConsole) - { + if (!sConsole) { return; } - sConsole->print_f("******** EXCEPTION OCCURRED! ********\nFrameMemory:%XH\n", - getFrameMemory()); + sConsole->print_f("******** EXCEPTION OCCURRED! ********\nFrameMemory:%XH\n", getFrameMemory()); int post_callback_executed = false; - while (true) - { + while (true) { showMainInfo(error, context, dsisr, dar); JUTConsoleManager::sManager->drawDirect(true); waitTime(mPrintWaitTime0); - if ((mPrintFlags & EXPRINTFLAG_GPR) != 0) - { + if ((mPrintFlags & EXPRINTFLAG_GPR) != 0) { printDebugInfo(INFOPAGE_GPR, error, context, dsisr, dar); JUTConsoleManager::sManager->drawDirect(true); waitTime(mPrintWaitTime0); } - if ((mPrintFlags & EXPRINTFLAG_GPRMap) != 0) - { + if ((mPrintFlags & EXPRINTFLAG_GPRMap) != 0) { printDebugInfo(INFOPAGE_GPRMap, error, context, dsisr, dar); JUTConsoleManager::sManager->drawDirect(true); waitTime(mPrintWaitTime0); } - if ((mPrintFlags & EXPRINTFLAG_Float) != 0) - { + if ((mPrintFlags & EXPRINTFLAG_Float) != 0) { printDebugInfo(INFOPAGE_Float, error, context, dsisr, dar); JUTConsoleManager::sManager->drawDirect(true); waitTime(mPrintWaitTime0); } - if ((mPrintFlags & EXPRINTFLAG_Stack) != 0) - { + if ((mPrintFlags & EXPRINTFLAG_Stack) != 0) { printDebugInfo(INFOPAGE_Stack, error, context, dsisr, dar); JUTConsoleManager::sManager->drawDirect(true); waitTime(mPrintWaitTime1); @@ -577,24 +488,21 @@ void JUTException::printContext(OSError error, OSContext *context, u32 dsisr, u3 sConsole->print("--------------------------------\n"); JUTConsoleManager::sManager->drawDirect(true); - if (post_callback_executed == 0 && sPostUserCallback) - { + if (post_callback_executed == 0 && sPostUserCallback) { BOOL enable = OSEnableInterrupts(); post_callback_executed = true; (*sPostUserCallback)(error, context, dsisr, dar); OSRestoreInterrupts(enable); } - if (_98 == 0 || !is_pad_enabled) - { + if (_98 == 0 || !is_pad_enabled) { break; } sConsole->setOutput(sConsole->getOutput() & 1); } - if (!is_pad_enabled) - { + if (!is_pad_enabled) { OSEnableInterrupts(); u32 button; @@ -602,51 +510,42 @@ void JUTException::printContext(OSError error, OSContext *context, u32 dsisr, u3 int down = 0; int up = 0; - do - { + do { readPad(&trigger, &button); bool draw = false; - if (trigger == 0x100) - { + if (trigger == 0x100) { sConsole->scrollToLastLine(); draw = true; } - if (trigger == 0x200) - { + if (trigger == 0x200) { sConsole->scrollToFirstLine(); draw = true; } - if (button == 8) - { - JUTConsole *console = sConsole; + if (button == 8) { + JUTConsole* console = sConsole; up = (down < 3) ? -1 : ((down < 5) ? -2 : ((down < 7) ? -4 : -8)); console->scroll(up); draw = true; up = 0; down++; - } - else if (button == 4) - { - JUTConsole *console = sConsole; + } else if (button == 4) { + JUTConsole* console = sConsole; down = (up < 3) ? 1 : ((up < 5) ? 2 : ((up < 7) ? 4 : 8)); console->scroll(down); draw = true; down = 0; up++; - } - else - { + } else { down = 0; up = 0; } - if (draw == true) - { + if (draw == true) { u32 start = VIGetRetraceCount(); while (start == VIGetRetraceCount()) ; @@ -657,8 +556,7 @@ void JUTException::printContext(OSError error, OSContext *context, u32 dsisr, u3 } while (true); } - while (true) - { + while (true) { sConsole->scrollToFirstLine(); JUTConsoleManager::sManager->drawDirect(true); waitTime(2000); @@ -667,13 +565,12 @@ void JUTException::printContext(OSError error, OSContext *context, u32 dsisr, u3 int used_line; u32 height; next: - for (u32 i = sConsole->getHeight(); i > 0; i--) - { + for (u32 i = sConsole->getHeight(); i > 0; i--) { sConsole->scroll(1); JUTConsoleManager::sManager->drawDirect(true); height = sConsole->getHeight(); - JUTConsole *console = sConsole; + JUTConsole* console = sConsole; line_offset = console->getLineOffset(); used_line = console->getUsedLine(); if ((used_line - height) + 1U <= line_offset) @@ -683,25 +580,21 @@ void JUTException::printContext(OSError error, OSContext *context, u32 dsisr, u3 waitTime(3000); height = sConsole->getHeight(); - JUTConsole *console = sConsole; + JUTConsole* console = sConsole; line_offset = console->getLineOffset(); used_line = console->getUsedLine(); - if ((used_line - height) + 1U <= line_offset) - { + if ((used_line - height) + 1U <= line_offset) { continue; } goto next; } } -void JUTException::waitTime(s32 timeout_ms) -{ - if (timeout_ms) - { +void JUTException::waitTime(s32 timeout_ms) { + if (timeout_ms) { OSTime start_time = OSGetTime(); OSTime ms; - do - { + do { OSTime end_time = OSGetTime(); OSTime ticks = end_time - start_time; ms = ticks / (OS_TIMER_CLOCK / 1000); @@ -709,18 +602,17 @@ void JUTException::waitTime(s32 timeout_ms) } } -void JUTException::createFB() -{ - GXRenderModeObj *renderMode = &GXNtsc480Int; - void *end = (void *)OSGetArenaHi(); +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; - void *begin = (void *)ALIGN_PREV((u32)end - size, 32); - void *object = (void *)ALIGN_PREV((s32)begin - sizeof(JUTExternalFB), 32); - JUTExternalFB *fb = new (object) JUTExternalFB(renderMode, GX_GM_1_7, begin, size); + void* begin = (void*)ALIGN_PREV((u32)end - size, 32); + void* object = (void*)ALIGN_PREV((s32)begin - sizeof(JUTExternalFB), 32); + JUTExternalFB* fb = new (object) JUTExternalFB(renderMode, GX_GM_1_7, begin, size); mDirectPrint->changeFrameBuffer(object); VIConfigure(renderMode); @@ -728,12 +620,10 @@ void JUTException::createFB() VISetBlack(FALSE); VIFlush(); - mFrameMemory = (JUTExternalFB *)object; + mFrameMemory = (JUTExternalFB*)object; } - +// clang-format off asm u32 JUTException::getFpscr() { // TODO: figure out if this is possible with asm - - // clang-format off fralloc mfmsr r5 ori r5, r5, 0x2000 @@ -744,62 +634,50 @@ asm u32 JUTException::getFpscr() { // TODO: figure out if this is possible with lwz r3, 12(r1) frfree blr - // clang-format on } +// clang-format on -JUTErrorHandler JUTException::setPreUserCallback(JUTErrorHandler callback) -{ +JUTErrorHandler JUTException::setPreUserCallback(JUTErrorHandler callback) { JUTErrorHandler previous = sPreUserCallback; sPreUserCallback = callback; return previous; } -JUTErrorHandler JUTException::setPostUserCallback(JUTErrorHandler callback) -{ +JUTErrorHandler JUTException::setPostUserCallback(JUTErrorHandler callback) { JUTErrorHandler previous = sPostUserCallback; sPostUserCallback = callback; return previous; } -void JUTException::appendMapFile(const char *path) -{ - if (!path) - { +void JUTException::appendMapFile(const char* path) { + if (!path) { return; } JSUListIterator iterator; - for (iterator = sMapFileList.getFirst(); iterator != sMapFileList.getEnd(); ++iterator) - { - if (strcmp(path, iterator->mFileName) == 0) - { + for (iterator = sMapFileList.getFirst(); iterator != sMapFileList.getEnd(); ++iterator) { + if (strcmp(path, iterator->mFileName) == 0) { return; } } - JUTExMapFile *mapFile = new JUTExMapFile((char *)path); + JUTExMapFile* mapFile = new JUTExMapFile((char*)path); sMapFileList.append(&mapFile->mLink); } -bool JUTException::queryMapAddress(char *mapPath, u32 address, s32 section_id, u32 *out_addr, u32 *out_size, char *out_line, u32 line_length, bool print, bool begin_with_newline) -{ - if (mapPath) - { +bool JUTException::queryMapAddress(char* mapPath, u32 address, s32 section_id, u32* out_addr, u32* out_size, + char* out_line, u32 line_length, bool print, bool begin_with_newline) { + if (mapPath) { char buffer[80]; strcpy(buffer, mapPath); strcat(buffer, ".map"); - if (queryMapAddress_single(buffer, address, section_id, out_addr, out_size, out_line, - line_length, print, begin_with_newline) == true) - { + if (queryMapAddress_single(buffer, address, section_id, out_addr, out_size, out_line, line_length, print, + begin_with_newline) == true) { return true; } - } - else if (sMapFileList.getFirst() != sMapFileList.getEnd()) - { - if (queryMapAddress_single(sMapFileList.getFirst()->getObject()->mFileName, address, -1, - out_addr, out_size, out_line, line_length, print, - begin_with_newline) == true) - { + } else if (sMapFileList.getFirst() != sMapFileList.getEnd()) { + if (queryMapAddress_single(sMapFileList.getFirst()->getObject()->mFileName, address, -1, out_addr, out_size, + out_line, line_length, print, begin_with_newline) == true) { return true; } } @@ -807,11 +685,10 @@ bool JUTException::queryMapAddress(char *mapPath, u32 address, s32 section_id, u return false; } -bool JUTException::queryMapAddress_single(char *mapPath, u32 address, s32 section_id, u32 *out_addr, u32 *out_size, char *out_line, u32 line_length, bool print, bool begin_with_newline) -{ +bool JUTException::queryMapAddress_single(char* mapPath, u32 address, s32 section_id, u32* out_addr, u32* out_size, + char* out_line, u32 line_length, bool print, bool begin_with_newline) { /* fake match on TP debug? */ - if (!mapPath) - { + if (!mapPath) { return false; } @@ -819,22 +696,19 @@ bool JUTException::queryMapAddress_single(char *mapPath, u32 address, s32 sectio char buffer[0x200]; JUTDirectFile file; int section_idx = 0; - if (!file.fopen(mapPath)) - { + if (!file.fopen(mapPath)) { return false; } bool result = false; bool found_section; - while (true) - { + while (true) { section_idx++; found_section = false; - while (true) - { - char *src; - char *dst; + while (true) { + char* src; + char* dst; if (file.fgets(buffer, sizeof(buffer)) < 0) break; @@ -843,8 +717,7 @@ bool JUTException::queryMapAddress_single(char *mapPath, u32 address, s32 sectio int i = 0; src = buffer + 1; - while (*src != '\0') - { + while (*src != '\0') { section_name[i] = *src; if (*src == ' ' || i == 0xf) break; @@ -856,8 +729,7 @@ bool JUTException::queryMapAddress_single(char *mapPath, u32 address, s32 sectio if (*src == 0) break; - if (src[1] == 's' && src[2] == 'e' && src[3] == 'c' && src[4] == 't') - { + if (src[1] == 's' && src[2] == 'e' && src[3] == 'c' && src[4] == 't') { found_section = true; break; } @@ -869,66 +741,55 @@ bool JUTException::queryMapAddress_single(char *mapPath, u32 address, s32 sectio if (section_id >= 0 && section_id != section_idx) continue; - int length; + int length; - while (true) - { + while (true) { if ((length = file.fgets(buffer, sizeof(buffer))) <= 4) break; if ((length < 28)) continue; - if ((buffer[28] == '4')) - { + if ((buffer[28] == '4')) { u32 addr = ((buffer[18] - '0') << 28) | strtol(buffer + 19, nullptr, 16); int size = strtol(buffer + 11, nullptr, 16); - if ((addr <= address && address < addr + size)) - { + if ((addr <= address && address < addr + size)) { if (out_addr) *out_addr = addr; if (out_size) *out_size = size; - if (out_line) - { - const u8 *src = (const u8 *)&buffer[0x1e]; - u8 *dst = (u8 *)out_line; + if (out_line) { + const u8* src = (const u8*)&buffer[0x1e]; + u8* dst = (u8*)out_line; u32 i = 0; - for (i = 0; i < line_length - 1; ++src) - { + for (i = 0; i < line_length - 1; ++src) { if ((u32)(*src) < ' ' && (u32)*src != '\t') break; - if ((*src == ' ' || (u32)*src == '\t') && (i != 0)) - { - if (dst[-1] != ' ') - { + if ((*src == ' ' || (u32)*src == '\t') && (i != 0)) { + if (dst[-1] != ' ') { *dst = ' '; dst++; ++i; } - } - else - { + } else { *dst++ = *src; i++; } } - if (i != 0 && dst[-1] == ' ') - { + if (i != 0 && dst[-1] == ' ') { dst--; i--; } *dst = 0; - - if (print) - { - if (begin_with_newline) - { + + if (print) { + if (begin_with_newline) { sConsole->print("\n"); } - sConsole->print_f(" [%08X]: .%s [%08X: %XH]\n %s\n", address, section_name, addr, size, out_line); + sConsole->print_f(" [%08X]: .%s [%08X: %XH]\n %s\n", address, section_name, addr, size, + out_line); begin_with_newline = false; } } @@ -939,15 +800,13 @@ bool JUTException::queryMapAddress_single(char *mapPath, u32 address, s32 sectio (void)0; // memes } - //if (!result) + // if (!result) //{ - if ((section_id < 0 || section_id != section_idx)) - { + if ((section_id < 0 || section_id != section_idx)) { goto cont; } //} - if (print && begin_with_newline) - { + if (print && begin_with_newline) { sConsole->print("\n"); } break; @@ -958,21 +817,18 @@ bool JUTException::queryMapAddress_single(char *mapPath, u32 address, s32 sectio return result ? true : false; } -void JUTException::createConsole(void *console_buffer, u32 console_buffer_size) -{ - if (!console_buffer || !console_buffer_size) - { +void JUTException::createConsole(void* console_buffer, u32 console_buffer_size) { + if (!console_buffer || !console_buffer_size) { return; } u32 lines = JUTConsole::getLineFromObjectSize(console_buffer_size, 0x32); - if (lines != 0) - { + if (lines != 0) { sConsoleBuffer = console_buffer; sConsoleBufferSize = console_buffer_size; sConsole = JUTConsole::create(0x32, console_buffer, console_buffer_size); - JUTConsoleManager *manager = JUTConsoleManager::sManager; + JUTConsoleManager* manager = JUTConsoleManager::sManager; manager->setDirectConsole(sConsole); sConsole->setFontSize(10.0, 6.0); @@ -983,11 +839,10 @@ void JUTException::createConsole(void *console_buffer, u32 console_buffer_size) } } -JUTExternalFB::JUTExternalFB(GXRenderModeObj *renderMode, GXGamma gamma, void *buffer, u32 size) -{ +JUTExternalFB::JUTExternalFB(GXRenderModeObj* renderMode, GXGamma gamma, void* buffer, u32 size) { mRenderModeObj = renderMode; mSize = size; _0C = 1; mGamma = gamma; _10 = false; -} \ No newline at end of file +} diff --git a/src/static/JSystem/JUtility/JUTFader.cpp b/src/static/JSystem/JUtility/JUTFader.cpp index 465aaa70..d9e0281d 100644 --- a/src/static/JSystem/JUtility/JUTFader.cpp +++ b/src/static/JSystem/JUtility/JUTFader.cpp @@ -4,8 +4,7 @@ #include "JSystem/J2D/J2DGrafContext.h" JUTFader::JUTFader(int p1, int p2, int p3, int p4, JUtility::TColor color) - : mColor(color), mViewBox(p1, p2, p1 + p3, p2 + p4) -{ + : mColor(color), mViewBox(p1, p2, p1 + p3, p2 + p4) { mStatus = Status_Out; mTicksTarget = 0; mTicksRun = 0; @@ -13,39 +12,34 @@ JUTFader::JUTFader(int p1, int p2, int p3, int p4, JUtility::TColor color) mEStatus = -1; } -void JUTFader::control() -{ +void JUTFader::control() { if (0 <= mEStatus && mEStatus-- == 0) mStatus = _28; if (mStatus == Status_In) return; - switch (mStatus) - { - case Status_Out: - mColor.a = 0xFF; - break; - case Status_FadingIn: - mColor.a = 0xFF - ((++mTicksRun * 0xFF) / mTicksTarget); - if (mTicksRun >= mTicksTarget) - { - mStatus = Status_In; - } - break; - case Status_FadingOut: - mColor.a = ((++mTicksRun * 0xFF) / mTicksTarget); - if (mTicksRun >= mTicksTarget) - { - mStatus = Status_Out; - } - break; + switch (mStatus) { + case Status_Out: + mColor.a = 0xFF; + break; + case Status_FadingIn: + mColor.a = 0xFF - ((++mTicksRun * 0xFF) / mTicksTarget); + if (mTicksRun >= mTicksTarget) { + mStatus = Status_In; + } + break; + case Status_FadingOut: + mColor.a = ((++mTicksRun * 0xFF) / mTicksTarget); + if (mTicksRun >= mTicksTarget) { + mStatus = Status_Out; + } + break; } draw(); } -void JUTFader::draw() -{ +void JUTFader::draw() { if (mColor.a == 0) return; @@ -54,13 +48,11 @@ void JUTFader::draw() orthograph.fillBox(mViewBox); } -void JUTFader::start(int) -{ +void JUTFader::start(int) { // UNUSED FUNCTION } -bool JUTFader::startFadeIn(int duration) -{ +bool JUTFader::startFadeIn(int duration) { bool fadingOut = mStatus == Status_Out; if (fadingOut) { @@ -72,8 +64,7 @@ bool JUTFader::startFadeIn(int duration) return fadingOut; } -bool JUTFader::startFadeOut(int duration) -{ +bool JUTFader::startFadeOut(int duration) { bool fadingIn = mStatus == Status_In; if (fadingIn) { @@ -85,33 +76,29 @@ bool JUTFader::startFadeOut(int duration) return fadingIn; } -void JUTFader::setStatus(JUTFader::EStatus i_status, int param_1) -{ - switch (i_status) - { - case Status_Out: - if (param_1 != 0) - { +void JUTFader::setStatus(JUTFader::EStatus i_status, int param_1) { + switch (i_status) { + case Status_Out: + if (param_1 != 0) { + _28 = Status_Out; + mEStatus = (u16)param_1; + break; + } + + mStatus = Status_Out; _28 = Status_Out; - mEStatus = (u16)param_1; + mEStatus = 0; break; - } + case Status_In: + if (param_1 != 0) { + _28 = Status_In; + mEStatus = (u16)param_1; + break; + } - mStatus = Status_Out; - _28 = Status_Out; - mEStatus = 0; - break; - case Status_In: - if (param_1 != 0) - { + mStatus = Status_In; _28 = Status_In; - mEStatus = (u16)param_1; + mEStatus = 0; break; - } - - mStatus = Status_In; - _28 = Status_In; - mEStatus = 0; - break; } -} \ No newline at end of file +} diff --git a/src/static/JSystem/JUtility/JUTFont.cpp b/src/static/JSystem/JUtility/JUTFont.cpp index a990eb2b..f354d3a9 100644 --- a/src/static/JSystem/JUtility/JUTFont.cpp +++ b/src/static/JSystem/JUtility/JUTFont.cpp @@ -1,44 +1,37 @@ #include "JSystem/JUtility/JUTFont.h" #include "JSystem/JUtility/JUTAssertion.h" -JUTFont::JUTFont() : mColor1(), mColor2(), mColor3(), mColor4() -{ +JUTFont::JUTFont() : mColor1(), mColor2(), mColor3(), mColor4() { mValid = false; } -void JUTFont::initialize_state() -{ +void JUTFont::initialize_state() { setCharColor(JUtility::TColor()); setFixedWidth(false, 0); mValid = false; } -void JUTFont::setCharColor(JUtility::TColor color) -{ +void JUTFont::setCharColor(JUtility::TColor color) { mColor1 = color; mColor2 = color; mColor3 = color; mColor4 = color; } -void JUTFont::setGradColor(JUtility::TColor color, JUtility::TColor color2) -{ +void JUTFont::setGradColor(JUtility::TColor color, JUtility::TColor color2) { mColor1 = color; mColor2 = color; mColor3 = color2; mColor4 = color2; } -f32 JUTFont::drawString_size_scale(f32 w, f32 x, f32 y, f32 z, const char *str, u32 usz, bool flag) -{ +f32 JUTFont::drawString_size_scale(f32 w, f32 x, f32 y, f32 z, const char* str, u32 usz, bool flag) { int str_int; f32 w_old = w; - for (; usz != 0; usz--, str++) - { + for (; usz != 0; usz--, str++) { str_int = (u8)*str; - if (isLeadByte(str_int)) - { + if (isLeadByte(str_int)) { JUT_ASSERT(usz >= 2); usz--; str++; @@ -49,4 +42,4 @@ f32 JUTFont::drawString_size_scale(f32 w, f32 x, f32 y, f32 z, const char *str, flag = true; } return w - w_old; -} \ No newline at end of file +} diff --git a/src/static/JSystem/JUtility/JUTGamePad.cpp b/src/static/JSystem/JUtility/JUTGamePad.cpp index 10ee017c..dff2f418 100644 --- a/src/static/JSystem/JUtility/JUTGamePad.cpp +++ b/src/static/JSystem/JUtility/JUTGamePad.cpp @@ -4,12 +4,7 @@ #include "MSL_C/w_math.h" #include "MSL_C/math.h" -static u32 channel_mask[PAD_MAX_CONTROLLERS] = { - 0x80000000 >> 0, - 0x80000000 >> 1, - 0x80000000 >> 2, - 0x80000000 >> 3 -}; +static u32 channel_mask[PAD_MAX_CONTROLLERS] = { 0x80000000 >> 0, 0x80000000 >> 1, 0x80000000 >> 2, 0x80000000 >> 3 }; JUTGamePad::EStickMode JUTGamePad::sStickMode = Clamped; u32 JUTGamePad::C3ButtonReset::sResetPattern = START | X | B; @@ -37,444 +32,418 @@ bool JUTGamePad::C3ButtonReset::sResetOccurred = false; s32 JUTGamePad::C3ButtonReset::sResetOccurredPort = 0; JUTGamePad::JUTGamePad(EPadPort port) - : mButtons(), - mMainStick(), - mSubStick(), - mRumble(this), - mLink(this), - mButtonReset() { - this->mPortNum = port; - mPadAssign[port]++; - this->initList(); - JUTGamePad::mPadList.append(&this->mLink); - this->update(); - this->mPadRecord = nullptr; - this->mPadReplay = nullptr; + : mButtons(), mMainStick(), mSubStick(), mRumble(this), mLink(this), mButtonReset() { + this->mPortNum = port; + mPadAssign[port]++; + this->initList(); + JUTGamePad::mPadList.append(&this->mLink); + this->update(); + this->mPadRecord = nullptr; + this->mPadReplay = nullptr; } -JUTGamePad::JUTGamePad() - : mButtons(), - mMainStick(), - mSubStick(), - mRumble(this), - mLink(this), - mButtonReset() { - this->mPortNum = -1; - this->initList(); - JUTGamePad::mPadList.append(&this->mLink); - this->mPadRecord = nullptr; - this->mPadReplay = nullptr; - this->clear(); +JUTGamePad::JUTGamePad() : mButtons(), mMainStick(), mSubStick(), mRumble(this), mLink(this), mButtonReset() { + this->mPortNum = -1; + this->initList(); + JUTGamePad::mPadList.append(&this->mLink); + this->mPadRecord = nullptr; + this->mPadReplay = nullptr; + this->clear(); } JUTGamePad::~JUTGamePad() { - if (this->mPortNum != -1) { - mPadAssign[this->mPortNum]--; - this->mPortNum = -1; - } + if (this->mPortNum != -1) { + mPadAssign[this->mPortNum]--; + this->mPortNum = -1; + } - JUTGamePad::mPadList.remove(&this->mLink); + JUTGamePad::mPadList.remove(&this->mLink); } void JUTGamePad::initList() { - if (!JUTGamePad::mListInitialized) { - JUTGamePad::mPadList.initiate(); - JUTGamePad::mListInitialized = true; - } + if (!JUTGamePad::mListInitialized) { + JUTGamePad::mPadList.initiate(); + JUTGamePad::mListInitialized = true; + } } void JUTGamePad::init() { - PADSetSpec(5); - JUTGamePad::sAnalogMode = 3; - PADSetAnalogMode(3); - PADInit(); + PADSetSpec(5); + JUTGamePad::sAnalogMode = 3; + PADSetAnalogMode(3); + PADInit(); } void JUTGamePad::clear() { - this->mButtonReset.mReset = false; + this->mButtonReset.mReset = false; } void JUTGamePad::read() { - PADRead(JUTGamePad::mPadStatus); - PADClamp(JUTGamePad::mPadStatus); + PADRead(JUTGamePad::mPadStatus); + PADClamp(JUTGamePad::mPadStatus); - u32 mask; - u32 resetControllerMask = 0; - - for (s32 i = 0; i < PAD_MAX_CONTROLLERS; i++) { - mask = 0x80000000 >> i; + u32 mask; + u32 resetControllerMask = 0; - if (JUTGamePad::mPadStatus[i].err == 0) { - PADStatus* status = &JUTGamePad::mPadStatus[i]; - u32 buttons; + for (s32 i = 0; i < PAD_MAX_CONTROLLERS; i++) { + mask = 0x80000000 >> i; - buttons = (JUTGamePad::mPadMStick[i].update(status->stickX, status->stickY, JUTGamePad::sStickMode, WhichStick_MainStick) << 24); - buttons |= (JUTGamePad::mPadSStick[i].update(status->substickX, status->substickY, JUTGamePad::sStickMode, WhichStick_SubStick) << 16); - JUTGamePad::mPadButton[i].update(status, buttons); - } - else if (JUTGamePad::mPadStatus[i].err == -1) { - JUTGamePad::mPadMStick[i].update(0, 0, JUTGamePad::sStickMode, WhichStick_MainStick); - JUTGamePad::mPadSStick[i].update(0, 0, JUTGamePad::sStickMode, WhichStick_SubStick); - JUTGamePad::mPadButton[i].update(nullptr, 0); + if (JUTGamePad::mPadStatus[i].err == 0) { + PADStatus* status = &JUTGamePad::mPadStatus[i]; + u32 buttons; - if ((JUTGamePad::mSuppressPadReset & mask) == 0) { - resetControllerMask |= mask; - } - } - else { - JUTGamePad::mPadButton[i].mTrigger = 0; - JUTGamePad::mPadButton[i].mRelease = 0; - JUTGamePad::mPadButton[i].mRepeat = 0; - } - } + buttons = (JUTGamePad::mPadMStick[i].update(status->stickX, status->stickY, JUTGamePad::sStickMode, + WhichStick_MainStick) + << 24); + buttons |= (JUTGamePad::mPadSStick[i].update(status->substickX, status->substickY, JUTGamePad::sStickMode, + WhichStick_SubStick) + << 16); + JUTGamePad::mPadButton[i].update(status, buttons); + } else if (JUTGamePad::mPadStatus[i].err == -1) { + JUTGamePad::mPadMStick[i].update(0, 0, JUTGamePad::sStickMode, WhichStick_MainStick); + JUTGamePad::mPadSStick[i].update(0, 0, JUTGamePad::sStickMode, WhichStick_SubStick); + JUTGamePad::mPadButton[i].update(nullptr, 0); - JSUListIterator it; - for (it = JUTGamePad::mPadList.getFirst(); it != JUTGamePad::mPadList.getEnd(); it++) { - if (it->getPadReplay() != nullptr) { - PADStatus status; - u32 buttons; - - it->getPadReplay()->read(&status); - buttons = it->mMainStick.update(status.stickX, status.stickY, JUTGamePad::sStickMode, WhichStick_MainStick) << 24; - buttons |= it->mSubStick.update(status.substickX, status.substickY, JUTGamePad::sStickMode, WhichStick_SubStick) << 16; - it->mButtons.update(&status, buttons); - } - else { - if (it->mPortNum == -1) { - it->assign(); - } - - it->update(); + if ((JUTGamePad::mSuppressPadReset & mask) == 0) { + resetControllerMask |= mask; + } + } else { + JUTGamePad::mPadButton[i].mTrigger = 0; + JUTGamePad::mPadButton[i].mRelease = 0; + JUTGamePad::mPadButton[i].mRepeat = 0; + } } - if (it->getPadRecord() != nullptr && it->mPortNum != -1) { - int port = it->mPortNum; + JSUListIterator it; + for (it = JUTGamePad::mPadList.getFirst(); it != JUTGamePad::mPadList.getEnd(); it++) { + if (it->getPadReplay() != nullptr) { + PADStatus status; + u32 buttons; - if (JUTGamePad::mPadStatus[port].err == 0) { - it->getPadRecord()->write(&JUTGamePad::mPadStatus[port]); - } + it->getPadReplay()->read(&status); + buttons = it->mMainStick.update(status.stickX, status.stickY, JUTGamePad::sStickMode, WhichStick_MainStick) + << 24; + buttons |= + it->mSubStick.update(status.substickX, status.substickY, JUTGamePad::sStickMode, WhichStick_SubStick) + << 16; + it->mButtons.update(&status, buttons); + } else { + if (it->mPortNum == -1) { + it->assign(); + } + + it->update(); + } + + if (it->getPadRecord() != nullptr && it->mPortNum != -1) { + int port = it->mPortNum; + + if (JUTGamePad::mPadStatus[port].err == 0) { + it->getPadRecord()->write(&JUTGamePad::mPadStatus[port]); + } + } } - } - if (resetControllerMask != 0) { - PADReset(resetControllerMask); - } + if (resetControllerMask != 0) { + PADReset(resetControllerMask); + } - JUTGamePad::checkResetSwitch(); + JUTGamePad::checkResetSwitch(); } void JUTGamePad::assign() { - for (s32 i = 0; i < PAD_MAX_CONTROLLERS; i++) { - if (JUTGamePad::mPadStatus[i].err == 0 && JUTGamePad::mPadAssign[i] == 0) { - this->mPortNum = i; - JUTGamePad::mPadAssign[i] = 1; - JUTGamePad::mPadButton[i].setRepeat(this->mButtons.mRepeatMask, this->mButtons.mRepeatDelay, this->mButtons.mRepeatFrequency); - this->mRumble.clear(this); - break; + for (s32 i = 0; i < PAD_MAX_CONTROLLERS; i++) { + if (JUTGamePad::mPadStatus[i].err == 0 && JUTGamePad::mPadAssign[i] == 0) { + this->mPortNum = i; + JUTGamePad::mPadAssign[i] = 1; + JUTGamePad::mPadButton[i].setRepeat(this->mButtons.mRepeatMask, this->mButtons.mRepeatDelay, + this->mButtons.mRepeatFrequency); + this->mRumble.clear(this); + break; + } } - } } void JUTGamePad::checkResetCallback(OSTime time) { - if (this->mPortNum != -1 && time >= JUTGamePad::C3ButtonReset::sThreshold) { - JUTGamePad::C3ButtonReset::sResetOccurred = true; - JUTGamePad::C3ButtonReset::sResetOccurredPort = this->mPortNum; + if (this->mPortNum != -1 && time >= JUTGamePad::C3ButtonReset::sThreshold) { + JUTGamePad::C3ButtonReset::sResetOccurred = true; + JUTGamePad::C3ButtonReset::sResetOccurredPort = this->mPortNum; - if (JUTGamePad::C3ButtonReset::sCallback != NULL) { - (*JUTGamePad::C3ButtonReset::sCallback)(this->mPortNum, JUTGamePad::C3ButtonReset::sCallbackArg); + if (JUTGamePad::C3ButtonReset::sCallback != NULL) { + (*JUTGamePad::C3ButtonReset::sCallback)(this->mPortNum, JUTGamePad::C3ButtonReset::sCallbackArg); + } } - } } void JUTGamePad::update() { - if (this->mPortNum != -1) { - this->mButtons = JUTGamePad::mPadButton[this->mPortNum]; - this->mMainStick = JUTGamePad::mPadMStick[this->mPortNum]; - this->mSubStick = JUTGamePad::mPadSStick[this->mPortNum]; - this->mErrorStatus = JUTGamePad::mPadStatus[this->mPortNum].err; + if (this->mPortNum != -1) { + this->mButtons = JUTGamePad::mPadButton[this->mPortNum]; + this->mMainStick = JUTGamePad::mPadMStick[this->mPortNum]; + this->mSubStick = JUTGamePad::mPadSStick[this->mPortNum]; + this->mErrorStatus = JUTGamePad::mPadStatus[this->mPortNum].err; - if (JUTGamePad::C3ButtonReset::sResetOccurred == false) { - if (JUTGamePad::C3ButtonReset::sResetPattern == (JUTGamePad::C3ButtonReset::sResetPattern & this->mButtons.mButton)) { - if (this->mButtonReset.mReset == true) { - this->checkResetCallback(OSGetTime() - this->mResetTime); + if (JUTGamePad::C3ButtonReset::sResetOccurred == false) { + if (JUTGamePad::C3ButtonReset::sResetPattern == + (JUTGamePad::C3ButtonReset::sResetPattern & this->mButtons.mButton)) { + if (this->mButtonReset.mReset == true) { + this->checkResetCallback(OSGetTime() - this->mResetTime); + } else { + this->mButtonReset.mReset = true; + this->mResetTime = OSGetTime(); + } + } else { + this->mButtonReset.mReset = false; + } } - else { - this->mButtonReset.mReset = true; - this->mResetTime = OSGetTime(); - } - } - else { - this->mButtonReset.mReset = false; - } + + this->mRumble.update(this->mPortNum); } - - this->mRumble.update(this->mPortNum); - } } void JUTGamePad::checkResetSwitch() { - if (!JUTGamePad::C3ButtonReset::sResetOccurred) { - if (OSGetResetSwitchState() != 0) { - JUTGamePad::C3ButtonReset::sResetSwitchPushing = true; - } - else { - if (JUTGamePad::C3ButtonReset::sResetSwitchPushing == true) { - JUTGamePad::C3ButtonReset::sResetOccurred = true; - JUTGamePad::C3ButtonReset::sResetOccurredPort = -1; + if (!JUTGamePad::C3ButtonReset::sResetOccurred) { + if (OSGetResetSwitchState() != 0) { + JUTGamePad::C3ButtonReset::sResetSwitchPushing = true; + } else { + if (JUTGamePad::C3ButtonReset::sResetSwitchPushing == true) { + JUTGamePad::C3ButtonReset::sResetOccurred = true; + JUTGamePad::C3ButtonReset::sResetOccurredPort = -1; - if (*JUTGamePad::C3ButtonReset::sCallback != nullptr) { - (*JUTGamePad::C3ButtonReset::sCallback)(-1, JUTGamePad::C3ButtonReset::sCallbackArg); + if (*JUTGamePad::C3ButtonReset::sCallback != nullptr) { + (*JUTGamePad::C3ButtonReset::sCallback)(-1, JUTGamePad::C3ButtonReset::sCallbackArg); + } + } + + JUTGamePad::C3ButtonReset::sResetSwitchPushing = false; } - } - - JUTGamePad::C3ButtonReset::sResetSwitchPushing = false; } - } } void JUTGamePad::CButton::clear() { - this->mButton = 0; - this->mTrigger = 0; - this->mRelease = 0; - this->mRepeat = 0; - this->mAnalogA = 0; - this->mAnalogB = 0; - this->mAnalogL = 0; - this->mAnalogR = 0; - this->mRepeatTimer = 0; - this->mRepeatLastButton = 0; - this->mRepeatMask = 0; - this->mRepeatDelay = 0; - this->mRepeatFrequency = 0; -} - -void JUTGamePad::CButton::update(const PADStatus* padStatus, u32 stick_buttons) { - u32 tempButtons; - u32 buttons; - - if (padStatus != nullptr) { - tempButtons = padStatus->button; - } - else { - tempButtons = 0; - } - - buttons = stick_buttons | tempButtons; - this->mRepeat = 0; - - if (this->mRepeatDelay != 0) { - if (this->mRepeatMask != 0) { - u32 repeatButtons = buttons & this->mRepeatMask; - this->mRepeat = 0; - - if (repeatButtons == 0) { - this->mRepeatLastButton = 0; - this->mRepeatTimer = 0; - } - else if (this->mRepeatLastButton == repeatButtons) { - this->mRepeatTimer++; - if ( - this->mRepeatTimer == this->mRepeatDelay || - (this->mRepeatTimer > this->mRepeatDelay && ((this->mRepeatTimer - this->mRepeatDelay) % this->mRepeatFrequency) == 0) - ) { - this->mRepeat = repeatButtons; - } - } - else { - this->mRepeat = repeatButtons & (this->mRepeatLastButton ^ 0xFFFFFFFF); - this->mRepeatLastButton = repeatButtons; - this->mRepeatTimer = 0; - } - } - } - - this->mTrigger = buttons & (buttons ^ this->mButton); - this->mRelease = this->mButton & (buttons ^ this->mButton); - this->mButton = buttons; - this->mRepeat |= (this->mRepeatMask ^ 0xFFFFFFFF) & this->mTrigger; - - if (padStatus != nullptr) { - this->mAnalogA = padStatus->analogA; - this->mAnalogB = padStatus->analogB; - this->mAnalogL = padStatus->triggerLeft; - this->mAnalogR = padStatus->triggerRight; - } - else { + this->mButton = 0; + this->mTrigger = 0; + this->mRelease = 0; + this->mRepeat = 0; this->mAnalogA = 0; this->mAnalogB = 0; this->mAnalogL = 0; this->mAnalogR = 0; - } + this->mRepeatTimer = 0; + this->mRepeatLastButton = 0; + this->mRepeatMask = 0; + this->mRepeatDelay = 0; + this->mRepeatFrequency = 0; +} - this->mAnalogLf = (f32)(int)this->mAnalogL / 150.0f; - this->mAnalogRf = (f32)(int)this->mAnalogR / 150.0f; +void JUTGamePad::CButton::update(const PADStatus* padStatus, u32 stick_buttons) { + u32 tempButtons; + u32 buttons; + + if (padStatus != nullptr) { + tempButtons = padStatus->button; + } else { + tempButtons = 0; + } + + buttons = stick_buttons | tempButtons; + this->mRepeat = 0; + + if (this->mRepeatDelay != 0) { + if (this->mRepeatMask != 0) { + u32 repeatButtons = buttons & this->mRepeatMask; + this->mRepeat = 0; + + if (repeatButtons == 0) { + this->mRepeatLastButton = 0; + this->mRepeatTimer = 0; + } else if (this->mRepeatLastButton == repeatButtons) { + this->mRepeatTimer++; + if (this->mRepeatTimer == this->mRepeatDelay || + (this->mRepeatTimer > this->mRepeatDelay && + ((this->mRepeatTimer - this->mRepeatDelay) % this->mRepeatFrequency) == 0)) { + this->mRepeat = repeatButtons; + } + } else { + this->mRepeat = repeatButtons & (this->mRepeatLastButton ^ 0xFFFFFFFF); + this->mRepeatLastButton = repeatButtons; + this->mRepeatTimer = 0; + } + } + } + + this->mTrigger = buttons & (buttons ^ this->mButton); + this->mRelease = this->mButton & (buttons ^ this->mButton); + this->mButton = buttons; + this->mRepeat |= (this->mRepeatMask ^ 0xFFFFFFFF) & this->mTrigger; + + if (padStatus != nullptr) { + this->mAnalogA = padStatus->analogA; + this->mAnalogB = padStatus->analogB; + this->mAnalogL = padStatus->triggerLeft; + this->mAnalogR = padStatus->triggerRight; + } else { + this->mAnalogA = 0; + this->mAnalogB = 0; + this->mAnalogL = 0; + this->mAnalogR = 0; + } + + this->mAnalogLf = (f32)(int)this->mAnalogL / 150.0f; + this->mAnalogRf = (f32)(int)this->mAnalogR / 150.0f; } void JUTGamePad::CStick::clear() { - this->mX = 0.0f; - this->mY = 0.0f; - this->mValue = 0.0f; - this->mAngle = 0; + this->mX = 0.0f; + this->mY = 0.0f; + this->mValue = 0.0f; + this->mAngle = 0; } u32 JUTGamePad::CStick::update(s8 x, s8 y, EStickMode stickMode, EWhichStick whichStick) { - int stickMax = whichStick == WhichStick_MainStick ? 54 : 42; - - this->mX = (f32)x / (f32)stickMax; - this->mY = (f32)y / (f32)stickMax; - this->mValue = sqrtf(this->mX * this->mX + this->mY * this->mY); + int stickMax = whichStick == WhichStick_MainStick ? 54 : 42; - if (this->mValue > 1.0f) { - if (stickMode == Clamped) { - this->mX /= this->mValue; - this->mY /= this->mValue; + this->mX = (f32)x / (f32)stickMax; + this->mY = (f32)y / (f32)stickMax; + this->mValue = sqrtf(this->mX * this->mX + this->mY * this->mY); + + if (this->mValue > 1.0f) { + if (stickMode == Clamped) { + this->mX /= this->mValue; + this->mY /= this->mValue; + } + + this->mValue = 1.0f; } - this->mValue = 1.0f; - } - - if (this->mValue > 0.0f) { - if (this->mY == 0.0f) { - if (this->mX > 0.0f) { - this->mAngle = 0x4000; - } - else { - this->mAngle = -0x4000; - } + if (this->mValue > 0.0f) { + if (this->mY == 0.0f) { + if (this->mX > 0.0f) { + this->mAngle = 0x4000; + } else { + this->mAngle = -0x4000; + } + } else { + f32 angle = atan2(this->mX, -this->mY); + this->mAngle = angle * 10430.379f; //((f32)0x8000 / F_PI); + } } - else { - f32 angle = atan2(this->mX, -this->mY); - this->mAngle = angle * 10430.379f; //((f32)0x8000 / F_PI); - } - } - return this->getButton(); + return this->getButton(); } u32 JUTGamePad::CStick::getButton() { - u32 button = 0; + u32 button = 0; - if (-0.25f < this->mX && this->mX < 0.25f) { - button &= ~(DPAD_LEFT | DPAD_RIGHT); - } - else if (this->mX <= -0.5f) { - button |= DPAD_LEFT; - } - else if (this->mX >= 0.5f) { - button |= DPAD_RIGHT; - } + if (-0.25f < this->mX && this->mX < 0.25f) { + button &= ~(DPAD_LEFT | DPAD_RIGHT); + } else if (this->mX <= -0.5f) { + button |= DPAD_LEFT; + } else if (this->mX >= 0.5f) { + button |= DPAD_RIGHT; + } - if (-0.25f < this->mY && this->mY < 0.25f) { - button &= ~(DPAD_DOWN | DPAD_UP); - } - else if (this->mY <= -0.5f) { - button |= DPAD_DOWN; - } - else if (this->mY >= 0.5f) { - button |= DPAD_UP; - } + if (-0.25f < this->mY && this->mY < 0.25f) { + button &= ~(DPAD_DOWN | DPAD_UP); + } else if (this->mY <= -0.5f) { + button |= DPAD_DOWN; + } else if (this->mY >= 0.5f) { + button |= DPAD_UP; + } - return button; + return button; } void JUTGamePad::CRumble::clear() { - this->mFrame = 0; - this->mLength = 0; - this->mData = nullptr; - this->mFrameCount = 0; - JUTGamePad::CRumble::mEnabled = 0xF0000000; -} - -void JUTGamePad::CRumble::clear(JUTGamePad* gamePad) { - if (0 <= gamePad->getPortNum() && gamePad->getPortNum() < PAD_MAX_CONTROLLERS) { - JUTGamePad::CRumble::mStatus[gamePad->getPortNum()] = 0; - this->stopMotorHard(gamePad->getPortNum()); - } - - this->clear(); -} - -void JUTGamePad::CRumble::startMotor(int port) { - if (JUTGamePad::CRumble::isEnabled(channel_mask[port])) { - PADControlMotor(port, PAD_MOTOR_RUMBLE); - JUTGamePad::CRumble::mStatus[port] = 1; - } -} - -void JUTGamePad::CRumble::stopMotor(int port) { - if (JUTGamePad::CRumble::isEnabled(channel_mask[port])) { - PADControlMotor(port, PAD_MOTOR_STOP); - JUTGamePad::CRumble::mStatus[port] = 0; - } -} - -void JUTGamePad::CRumble::stopMotorHard(int port) { - if (JUTGamePad::CRumble::isEnabled(channel_mask[port])) { - PADControlMotor(port, PAD_MOTOR_STOP_HARD); - JUTGamePad::CRumble::mStatus[port] = 0; - } -} - -static inline u8 getNumBit(const u8* data, int bit) { - return (((0x80 >> (bit & 7)) & data[(u32)bit >> 3]) & 0xFF); -} - -void JUTGamePad::CRumble::update(s16 port) { - if (!JUTGamePad::CRumble::isEnabled(channel_mask[port])) { this->mFrame = 0; this->mLength = 0; this->mData = nullptr; this->mFrameCount = 0; - } + JUTGamePad::CRumble::mEnabled = 0xF0000000; +} - if (this->mLength != 0) { - if (this->mFrame >= this->mLength) { - JUTGamePad::CRumble::stopMotorHard(port); - this->mLength = 0; +void JUTGamePad::CRumble::clear(JUTGamePad* gamePad) { + if (0 <= gamePad->getPortNum() && gamePad->getPortNum() < PAD_MAX_CONTROLLERS) { + JUTGamePad::CRumble::mStatus[gamePad->getPortNum()] = 0; + this->stopMotorHard(gamePad->getPortNum()); } - else { - if (this->mFrameCount == 0) { - if (JUTGamePad::CRumble::mStatus[port] == 0) { - JUTGamePad::CRumble::startMotor(port); + + this->clear(); +} + +void JUTGamePad::CRumble::startMotor(int port) { + if (JUTGamePad::CRumble::isEnabled(channel_mask[port])) { + PADControlMotor(port, PAD_MOTOR_RUMBLE); + JUTGamePad::CRumble::mStatus[port] = 1; + } +} + +void JUTGamePad::CRumble::stopMotor(int port) { + if (JUTGamePad::CRumble::isEnabled(channel_mask[port])) { + PADControlMotor(port, PAD_MOTOR_STOP); + JUTGamePad::CRumble::mStatus[port] = 0; + } +} + +void JUTGamePad::CRumble::stopMotorHard(int port) { + if (JUTGamePad::CRumble::isEnabled(channel_mask[port])) { + PADControlMotor(port, PAD_MOTOR_STOP_HARD); + JUTGamePad::CRumble::mStatus[port] = 0; + } +} + +static inline u8 getNumBit(const u8* data, int bit) { + return (((0x80 >> (bit & 7)) & data[(u32)bit >> 3]) & 0xFF); +} + +void JUTGamePad::CRumble::update(s16 port) { + if (!JUTGamePad::CRumble::isEnabled(channel_mask[port])) { + this->mFrame = 0; + this->mLength = 0; + this->mData = nullptr; + this->mFrameCount = 0; + } + + if (this->mLength != 0) { + if (this->mFrame >= this->mLength) { + JUTGamePad::CRumble::stopMotorHard(port); + this->mLength = 0; + } else { + if (this->mFrameCount == 0) { + if (JUTGamePad::CRumble::mStatus[port] == 0) { + JUTGamePad::CRumble::startMotor(port); + } + + return; + } + + u8 bit = getNumBit(this->mData, this->mFrame % this->mFrameCount); + if (bit != 0 && JUTGamePad::CRumble::mStatus[port] == 0) { + JUTGamePad::CRumble::startMotor(port); + } else if (bit == 0 && JUTGamePad::CRumble::mStatus[port] != 0) { + JUTGamePad::CRumble::stopMotorHard(port); + } } - return; - } - - u8 bit = getNumBit(this->mData, this->mFrame % this->mFrameCount); - if (bit != 0 && JUTGamePad::CRumble::mStatus[port] == 0) { - JUTGamePad::CRumble::startMotor(port); - } - else if (bit == 0 && JUTGamePad::CRumble::mStatus[port] != 0) { - JUTGamePad::CRumble::stopMotorHard(port); - } + this->mFrame++; } - - this->mFrame++; - } } void JUTGamePad::CButton::setRepeat(u32 repeatMask, u32 repeatDelay, u32 repeatFreq) { - this->mRepeatLastButton = 0; - this->mRepeatTimer = 0; - this->mRepeatMask = repeatMask; - this->mRepeatDelay = repeatDelay; - this->mRepeatFrequency = repeatFreq; + this->mRepeatLastButton = 0; + this->mRepeatTimer = 0; + this->mRepeatMask = repeatMask; + this->mRepeatDelay = repeatDelay; + this->mRepeatFrequency = repeatFreq; } bool JUTGamePad::recalibrate(u32 channels) { - u32 channelMasks[PAD_MAX_CONTROLLERS] = { - 0x80000000 >> 0, - 0x80000000 >> 1, - 0x80000000 >> 2, - 0x80000000 >> 3 - }; + u32 channelMasks[PAD_MAX_CONTROLLERS] = { 0x80000000 >> 0, 0x80000000 >> 1, 0x80000000 >> 2, 0x80000000 >> 3 }; - for (int i = 0; i < PAD_MAX_CONTROLLERS; i++) { - if ((JUTGamePad::mSuppressPadReset & channelMasks[i]) != 0) { - channels &= channelMasks[i] ^ 0xFFFFFFFF; + for (int i = 0; i < PAD_MAX_CONTROLLERS; i++) { + if ((JUTGamePad::mSuppressPadReset & channelMasks[i]) != 0) { + channels &= channelMasks[i] ^ 0xFFFFFFFF; + } } - } - return PADRecalibrate(channels); + return PADRecalibrate(channels); } diff --git a/src/static/JSystem/JUtility/JUTGraphFifo.cpp b/src/static/JSystem/JUtility/JUTGraphFifo.cpp index 86a328f5..c53fd938 100644 --- a/src/static/JSystem/JUtility/JUTGraphFifo.cpp +++ b/src/static/JSystem/JUtility/JUTGraphFifo.cpp @@ -3,43 +3,36 @@ #include "JSystem/JUtility/JUTGraphFifo.h" bool JUTGraphFifo::sInitiated; -JUTGraphFifo *JUTGraphFifo::sCurrentFifo; +JUTGraphFifo* JUTGraphFifo::sCurrentFifo; GXBool JUTGraphFifo::mGpStatus[5]; -JUTGraphFifo::JUTGraphFifo(u32 size) -{ +JUTGraphFifo::JUTGraphFifo(u32 size) { mSize = ALIGN_NEXT(size, 32); - if (sInitiated) - { - mFifo = (GXFifoObj *)JKRAllocFromSysHeap(mSize + sizeof(GXFifoObj), 32); + if (sInitiated) { + mFifo = (GXFifoObj*)JKRAllocFromSysHeap(mSize + sizeof(GXFifoObj), 32); mBase = mFifo + 1; GXInitFifoBase(mFifo, mBase, mSize); GXInitFifoPtrs(mFifo, mBase, mBase); - } - else - { + } else { /** TODO: Figure out what has sizeof 0xA0. */ mBase = JKRAllocFromSysHeap(mSize + 0xA0, 32); - mBase = (void *)ALIGN_NEXT((u32)mBase, 32); + mBase = (void*)ALIGN_NEXT((u32)mBase, 32); mFifo = GXInit(mBase, mSize); sInitiated = true; sCurrentFifo = this; } } -JUTGraphFifo::~JUTGraphFifo() -{ +JUTGraphFifo::~JUTGraphFifo() { sCurrentFifo->save(); - while (isGPActive()) - { + while (isGPActive()) { ; } - if (sCurrentFifo == this) - { + if (sCurrentFifo == this) { sCurrentFifo = nullptr; } JKRFreeToSysHeap(mBase); -} \ No newline at end of file +} diff --git a/src/static/JSystem/JUtility/JUTProcBar.cpp b/src/static/JSystem/JUtility/JUTProcBar.cpp index 804609a6..fe20e2ff 100644 --- a/src/static/JSystem/JUtility/JUTProcBar.cpp +++ b/src/static/JSystem/JUtility/JUTProcBar.cpp @@ -2,8 +2,7 @@ #include "JSystem/JUtility/JUTVideo.h" #include "JSystem/JUtility/JUTProcBar.h" - -JUTProcBar *JUTProcBar::sManager; +JUTProcBar* JUTProcBar::sManager; f32 oneFrameRate = 8.0f; f32 oneFrameRateUser = 10.0f; @@ -12,16 +11,15 @@ JUTProcBar::JUTProcBar() { mVisible = true; mHeapBarVisible = true; _108 = 0; - + u16 height = JUTVideo::getManager()->getXfbHeight(); if (JUTVideo::getManager()->getXfbHeight() > 400) { - + mParams.setBarWidth(2); mParams.setPosition(39, height - 40); mParams.setWidth(562); mParams.setUserPosition(height - 70); - } - else { + } else { mParams.setBarWidth(1); mParams.setPosition(39, height - 20); mParams.setWidth(562); @@ -36,7 +34,7 @@ JUTProcBar::~JUTProcBar() { sManager = nullptr; } -JUTProcBar *JUTProcBar::create() { +JUTProcBar* JUTProcBar::create() { if (!sManager) { sManager = new JUTProcBar(); } @@ -61,15 +59,13 @@ void JUTProcBar::clear() { } // Matches -void JUTProcBar::bar_subroutine(int param_0, int param_1, int param_2, int param_3, int param_4, - int param_5, int param_6, JUtility::TColor param_7, - JUtility::TColor param_8) { +void JUTProcBar::bar_subroutine(int param_0, int param_1, int param_2, int param_3, int param_4, int param_5, + int param_6, JUtility::TColor param_7, JUtility::TColor param_8) { int var2 = param_5 * param_3 / param_4; int var1 = param_6 * param_3 / param_4; J2DFillBox(param_0, param_1, var2, param_2, param_7); - if (var1 >= 0) - { + if (var1 >= 0) { if (var1 < 6) J2DFillBox(param_0, param_1, var1, param_2, param_8); else @@ -77,14 +73,12 @@ void JUTProcBar::bar_subroutine(int param_0, int param_1, int param_2, int param } } -// Matched +// Matched // perhaps rewrite this function, kinda annoying to read -void JUTProcBar::adjustMeterLength(u32 param_0, f32 *param_1, f32 param_2, f32 param_3, - int *param_4) { +void JUTProcBar::adjustMeterLength(u32 param_0, f32* param_1, f32 param_2, f32 param_3, int* param_4) { BOOL var2 = false; float var1 = *param_1; - while (var1 > param_2) - { + while (var1 > param_2) { if (param_0 * var1 * 20.0f / 16666.0f <= mParams.mWidth - 30.0f) break; @@ -97,8 +91,7 @@ void JUTProcBar::adjustMeterLength(u32 param_0, f32 *param_1, f32 param_2, f32 p if (var1 > param_3 - 0.2f) var1 = param_3; - while (!var2 && var1 < param_3) - { + while (!var2 && var1 < param_3) { (*param_4)++; if (*param_4 < 0x1e) break; @@ -119,11 +112,11 @@ MKDD: https://decomp.me/scratch/1Q2Ke TP: https://decomp.me/scratch/YKjcF */ void JUTProcBar::drawProcessBar() { - if (mVisible) - { + if (mVisible) { int frameDuration = 16666; // duration in miliseconds? for how long a frame takes, - if (JUTVideo::getManager() && ((JUTVideo::getManager()->getRenderMode()->viTVmode >> 2) & 0x0f) == VI_PAL) // possibly a define - frameDuration = 20000; // duration for PAL + if (JUTVideo::getManager() && + ((JUTVideo::getManager()->getRenderMode()->viTVmode >> 2) & 0x0f) == VI_PAL) // possibly a define + frameDuration = 20000; // duration for PAL static int cnt = 0; adjustMeterLength(mWholeLoop.mCost, &oneFrameRate, 1.0f, 10.0f, &cnt); @@ -144,7 +137,8 @@ void JUTProcBar::drawProcessBar() { if (mCostFrame > r24) J2DFillBox(mParams.mPosX, mParams.mPosY + r27 + 1, mParams.mWidth, 1.0f, JUtility::TColor(250, 0, 0, 200)); else - J2DFillBox(mParams.mPosX, mParams.mPosY + r27 + 1, mCostFrame * r28 + 2, 1.0f, JUtility::TColor(0, 250, 250, 200)); + J2DFillBox(mParams.mPosX, mParams.mPosY + r27 + 1, mCostFrame * r28 + 2, 1.0f, + JUtility::TColor(0, 250, 250, 200)); int stack92 = mWholeLoop.mCost * r28 / frameDuration; if (stack92 > mParams.mWidth) @@ -152,38 +146,40 @@ void JUTProcBar::drawProcessBar() { else J2DFillBox(mParams.mPosX, mParams.mPosY, stack92, 1.0f, JUtility::TColor(50, 255, 0, 255)); - if (_110 == 0) - { + if (_110 == 0) { int r23 = mParams.mPosY + mParams.mBarWidth; - bar_subroutine(mParams.mPosX + 1, r23, r26, r28, frameDuration, mGp.mCost, mGp._08, JUtility::TColor(80, 255, 80, 255), JUtility::TColor(100, 255, 120, 255)); + bar_subroutine(mParams.mPosX + 1, r23, r26, r28, frameDuration, mGp.mCost, mGp._08, + JUtility::TColor(80, 255, 80, 255), JUtility::TColor(100, 255, 120, 255)); r23 += mParams.mBarWidth * 2; - bar_subroutine(mParams.mPosX + 1, r23, r26, r28, frameDuration, mCpu.mCost, mCpu._08, JUtility::TColor(255, 80, 80, 255), JUtility::TColor(255, 100, 100, 255)); + bar_subroutine(mParams.mPosX + 1, r23, r26, r28, frameDuration, mCpu.mCost, mCpu._08, + JUtility::TColor(255, 80, 80, 255), JUtility::TColor(255, 100, 100, 255)); r23 += mParams.mBarWidth * 2; - bar_subroutine(mParams.mPosX + 1, r23, r26, r28, frameDuration, mIdle.mCost, mIdle._08, JUtility::TColor(180, 180, 160, 255), JUtility::TColor(200, 200, 200, 255)); - } - else - { + bar_subroutine(mParams.mPosX + 1, r23, r26, r28, frameDuration, mIdle.mCost, mIdle._08, + JUtility::TColor(180, 180, 160, 255), JUtility::TColor(200, 200, 200, 255)); + } else { int r22 = mParams.mPosY + mParams.mBarWidth; int r21 = mParams.mPosX + 1; - bar_subroutine(r21, r22, r26, r28, frameDuration, gpuTime, -1, JUtility::TColor(80, 255, 80, 255), JUtility::TColor(80, 255, 80, 255)); + bar_subroutine(r21, r22, r26, r28, frameDuration, gpuTime, -1, JUtility::TColor(80, 255, 80, 255), + JUtility::TColor(80, 255, 80, 255)); int thingy1 = gpuTime * r28 / frameDuration + r21; J2DFillBox(thingy1, r22, mGpWait.calcBarSize(r28, frameDuration), r26, JUtility::TColor(0, 255, 0, 255)); int r30 = mGp.calcBarSize(r28, frameDuration) + r21; r21 += totalTime * r28 / frameDuration; r22 += mParams.mBarWidth * 2; - bar_subroutine(r21, r22, r26, r28, frameDuration, mCpu.mCost, -1, JUtility::TColor(255, 80, 80, 255), JUtility::TColor(255, 80, 80, 255)); + bar_subroutine(r21, r22, r26, r28, frameDuration, mCpu.mCost, -1, JUtility::TColor(255, 80, 80, 255), + JUtility::TColor(255, 80, 80, 255)); r22 += mParams.mBarWidth * 2; - bar_subroutine(r30, r22, r26, r28, frameDuration, mIdle.mCost, -1, JUtility::TColor(180, 180, 160, 255), JUtility::TColor(180, 180, 160, 255)); + bar_subroutine(r30, r22, r26, r28, frameDuration, mIdle.mCost, -1, JUtility::TColor(180, 180, 160, 255), + JUtility::TColor(180, 180, 160, 255)); } - for (int i = 1; i < r24; i++) - { + for (int i = 1; i < r24; i++) { int temp2 = mParams.mPosX + i * r28 + 1; - J2DDrawLine(temp2, mParams.mPosY + mParams.mBarWidth, temp2, mParams.mPosY + r27 - mParams.mBarWidth, (i % 5) != 0 ? JUtility::TColor(100, 100, 255, 255) : JUtility::TColor(180, 255, 255, 255), 12); + J2DDrawLine(temp2, mParams.mPosY + mParams.mBarWidth, temp2, mParams.mPosY + r27 - mParams.mBarWidth, + (i % 5) != 0 ? JUtility::TColor(100, 100, 255, 255) : JUtility::TColor(180, 255, 255, 255), 12); } u32 temp3 = 0; - for (int i = 0; i < 8; i++) - { - CTime *time = &mUsers[i]; + for (int i = 0; i < 8; i++) { + CTime* time = &mUsers[i]; if (++time->_0C >= 0x10 || time->mCost > time->_08) { time->_08 = time->mCost; time->_0C = 0; @@ -191,47 +187,51 @@ void JUTProcBar::drawProcessBar() { if (time->_08 > temp3) temp3 = time->_08; } - if ((temp3 ? true : false) == true) - { + if ((temp3 ? true : false) == true) { static int cntUser = 0; adjustMeterLength(temp3, &oneFrameRateUser, 1.0f, 10.0f, &cntUser); int r21 = oneFrameRateUser * 20.0f; J2DFillBox(mParams.mPosX, mParams.mUserPosition, mParams.mWidth, r25, JUtility::TColor(0, 0, 50, 200)); - J2DDrawFrame(mParams.mPosX, mParams.mUserPosition, mParams.mWidth, r25, JUtility::TColor(50, 50, 150, 255), 6); - for (int i = 0; i < 8; i++) - { - CTime *time = &mUsers[i]; + J2DDrawFrame(mParams.mPosX, mParams.mUserPosition, mParams.mWidth, r25, JUtility::TColor(50, 50, 150, 255), + 6); + for (int i = 0; i < 8; i++) { + CTime* time = &mUsers[i]; if (++time->_0C >= 0x10 || time->mCost > time->_08) { time->_08 = time->mCost; time->_0C = 0; } - if (time->mCost != 0 || time->_08 != 0) - { + if (time->mCost != 0 || time->_08 != 0) { int temp4 = time->mCost * r21 / frameDuration; int temp5 = time->_08 * r21 / frameDuration; time->mCost = 0; - J2DFillBox(mParams.mPosX + 1, mParams.mUserPosition + mParams.mBarWidth + i * mParams.mBarWidth, temp4, mParams.mBarWidth, JUtility::TColor(time->mR, time->mG, time->mB, 255)); + J2DFillBox(mParams.mPosX + 1, mParams.mUserPosition + mParams.mBarWidth + i * mParams.mBarWidth, + temp4, mParams.mBarWidth, JUtility::TColor(time->mR, time->mG, time->mB, 255)); if (temp5 < 3u) - J2DFillBox(mParams.mPosX, mParams.mUserPosition + mParams.mBarWidth + i * mParams.mBarWidth, temp5, mParams.mBarWidth, JUtility::TColor(255, 200, 50, 255)); + J2DFillBox(mParams.mPosX, mParams.mUserPosition + mParams.mBarWidth + i * mParams.mBarWidth, + temp5, mParams.mBarWidth, JUtility::TColor(255, 200, 50, 255)); else - J2DFillBox(mParams.mPosX + temp5 - 3, mParams.mUserPosition + mParams.mBarWidth + i * mParams.mBarWidth, 3.0f, mParams.mBarWidth, JUtility::TColor(255, 200, 50, 255)); + J2DFillBox(mParams.mPosX + temp5 - 3, + mParams.mUserPosition + mParams.mBarWidth + i * mParams.mBarWidth, 3.0f, + mParams.mBarWidth, JUtility::TColor(255, 200, 50, 255)); } } int r22 = (mParams.mWidth - 4 + r21) / r21; - for (int i = 1; i < r22; i++) - { + for (int i = 1; i < r22; i++) { int temp6 = mParams.mPosX + i * r21 + 1; - J2DDrawLine(temp6, mParams.mUserPosition + mParams.mBarWidth, temp6, mParams.mUserPosition + r25 - mParams.mBarWidth, (i % 5) != 0 ? JUtility::TColor(100, 100, 255, 255) : JUtility::TColor(180, 255, 255, 255), 12); + J2DDrawLine(temp6, mParams.mUserPosition + mParams.mBarWidth, temp6, + mParams.mUserPosition + r25 - mParams.mBarWidth, + (i % 5) != 0 ? JUtility::TColor(100, 100, 255, 255) : JUtility::TColor(180, 255, 255, 255), + 12); } } _108 = 0; } } -int addrToXPos(void *param_0, int param_1) { +int addrToXPos(void* param_0, int param_1) { return param_1 * (((u32)param_0 - 0x80000000) / (float)JKRHeap::getMemorySize()); } @@ -239,9 +239,7 @@ int byteToXLen(int param_0, int param_1) { return param_1 * (param_0 / (float)JKRHeap::getMemorySize()); } -static void heapBar(JKRHeap *param_0, int param_1, int param_2, int param_3, int param_4, - int param_5) -{ +static void heapBar(JKRHeap* param_0, int param_1, int param_2, int param_3, int param_4, int param_5) { int stack52 = param_1 + addrToXPos(param_0->getStartAddr(), param_4); int var1 = param_1 + addrToXPos(param_0->getEndAddr(), param_4); int stack36 = byteToXLen(param_0->getTotalFreeSize(), param_4); @@ -257,11 +255,10 @@ MKDD(Debug): https://decomp.me/scratch/BUM6J MKDD(Releae) https://decomp.me/scratch/bxY1q TP(O3): https://decomp.me/scratch/Mi52V */ -void JUTProcBar::drawHeapBar() -{ - if (mHeapBarVisible) - { - int start; // required/workaround for regswaps, end might be a shared variable too, however doesn't seem to be needed? +void JUTProcBar::drawHeapBar() { + if (mHeapBarVisible) { + int start; // required/workaround for regswaps, end might be a shared variable too, however doesn't seem to be + // needed? int posX = mParams.mPosX; int posY = mParams.mPosY; int barHeight = mParams.mBarWidth * 2; @@ -271,28 +268,27 @@ void JUTProcBar::drawHeapBar() // draw main box in opaque bordeaux red and main frame in purple? J2DFillBox(posX, posY - (height * 2), width, height, JUtility::TColor(100, 0, 50, 200)); J2DDrawFrame(posX, posY - (height * 2), width, height, JUtility::TColor(100, 50, 150, 255), 6); - + // Draws a pink line that shows the size of the memstart to start of arenalow? start = posX + addrToXPos(JKRHeap::getCodeStart(), width); int codeEnd = posX + addrToXPos(JKRHeap::getCodeEnd(), width); J2DFillBox(start, posY - (height * 2), codeEnd - start, height, JUtility::TColor(255, 50, 150, 255)); - + // draws a dark blue line that shows how much memory is free? start = posX + addrToXPos(JKRHeap::getUserRamStart(), width); int userEnd = posX + addrToXPos(JKRHeap::getUserRamEnd(), width); J2DFillBox(start, posY - (height * 2), userEnd - start, height, JUtility::TColor(0, 50, 150, 255)); - - // draws a light blue line that shows how much memory is free in the root heap(blends to light pink, not sure how this works) + + // draws a light blue line that shows how much memory is free in the root heap(blends to light pink, not sure + // how this works) int size = byteToXLen(JKRHeap::getRootHeap()->getTotalFreeSize(), width); J2DFillBox(start, posY - (height * 2), size, height / 2, JUtility::TColor(0, 250, 250, 255)); - if (_128 == 0) - { + if (_128 == 0) { // draws a line of either the watch heap(if available), otherwise draw the current heap - JKRHeap *heap = mWatchHeap ? mWatchHeap : JKRGetCurrentHeap(); - if (heap != JKRHeap::getSystemHeap()) { + JKRHeap* heap = mWatchHeap ? mWatchHeap : JKRGetCurrentHeap(); + if (heap != JKRHeap::getSystemHeap()) { heapBar(heap, posX, posY, barHeight, width, height); } - } } } diff --git a/src/static/JSystem/JUtility/JUTResFont.cpp b/src/static/JSystem/JUtility/JUTResFont.cpp index d82e6d1e..ffbd72ea 100644 --- a/src/static/JSystem/JUtility/JUTResFont.cpp +++ b/src/static/JSystem/JUtility/JUTResFont.cpp @@ -6,34 +6,32 @@ #include "JSystem/JUtility/JUTFont.h" #include "types.h" -JUTFont::IsLeadByte const JUTResFont::saoAboutEncoding_[3] = {JUTFont::isLeadByte_1Byte, JUTFont::isLeadByte_2Byte, JUTFont::isLeadByte_ShiftJIS}; +JUTFont::IsLeadByte const JUTResFont::saoAboutEncoding_[3] = { JUTFont::isLeadByte_1Byte, JUTFont::isLeadByte_2Byte, + JUTFont::isLeadByte_ShiftJIS }; const u32 suAboutEncoding_ = 3; -JUTResFont::JUTResFont() -{ +JUTResFont::JUTResFont() { initialize_state(); } -JUTResFont::JUTResFont(const ResFONT *resource, JKRHeap *heap) -{ +JUTResFont::JUTResFont(const ResFONT* resource, JKRHeap* heap) { initialize_state(); JUTResFont::initiate(resource, heap); } -JUTResFont::~JUTResFont() -{ - if (mValid) - { +JUTResFont::~JUTResFont() { + if (mValid) { deleteMemBlocks_ResFont(); initialize_state(); JUTFont::initialize_state(); } } -void JUTResFont::deleteMemBlocks_ResFont() { delete[] mMemBlocks; } +void JUTResFont::deleteMemBlocks_ResFont() { + delete[] mMemBlocks; +} -void JUTResFont::initialize_state() -{ +void JUTResFont::initialize_state() { mResource = nullptr; mMemBlocks = nullptr; mWidthBlocks = nullptr; @@ -44,10 +42,8 @@ void JUTResFont::initialize_state() _44 = -1; } -bool JUTResFont::initiate(const ResFONT *resource, JKRHeap *heap) -{ - if (!protected_initiate(resource, heap)) - { +bool JUTResFont::initiate(const ResFONT* resource, JKRHeap* heap) { + if (!protected_initiate(resource, heap)) { deleteMemBlocks_ResFont(); initialize_state(); JUTFont::initialize_state(); @@ -57,16 +53,14 @@ bool JUTResFont::initiate(const ResFONT *resource, JKRHeap *heap) return true; } -bool JUTResFont::protected_initiate(const ResFONT *resource, JKRHeap *heap) -{ - void **blocks; +bool JUTResFont::protected_initiate(const ResFONT* resource, JKRHeap* heap) { + void** blocks; deleteMemBlocks_ResFont(); initialize_state(); JUTFont::initialize_state(); - if (!resource) - { + if (!resource) { return false; } @@ -76,29 +70,23 @@ bool JUTResFont::protected_initiate(const ResFONT *resource, JKRHeap *heap) countBlock(); u32 blockNum = mWidthBlockCount + mGlyphBlockCount + mMapBlockCount; - mMemBlocks = new (heap, 0) void *[blockNum]; + mMemBlocks = new (heap, 0) void*[blockNum]; blocks = mMemBlocks; - if (mMemBlocks == nullptr) - { + if (mMemBlocks == nullptr) { return false; - } - else - { - if (mWidthBlockCount != 0) - { - mWidthBlocks = (ResFONT::WidthBlock **)blocks; + } else { + if (mWidthBlockCount != 0) { + mWidthBlocks = (ResFONT::WidthBlock**)blocks; blocks += mWidthBlockCount; } - if (mGlyphBlockCount != 0) - { - mGlyphBlocks = (ResFONT::GlyphBlock **)blocks; + if (mGlyphBlockCount != 0) { + mGlyphBlocks = (ResFONT::GlyphBlock**)blocks; blocks += mGlyphBlockCount; } - if (mMapBlockCount != 0) - { - mMapBlocks = (ResFONT::MapBlock **)blocks; + if (mMapBlockCount != 0) { + mMapBlocks = (ResFONT::MapBlock**)blocks; } } @@ -106,89 +94,80 @@ bool JUTResFont::protected_initiate(const ResFONT *resource, JKRHeap *heap) return true; } -void JUTResFont::countBlock() -{ +void JUTResFont::countBlock() { mWidthBlockCount = 0; mGlyphBlockCount = 0; mMapBlockCount = 0; - BlockHeader *data = (BlockHeader *)mResource->mData; - for (u32 i = 0; i < mResource->mNumBlocks; i++, data = (BlockHeader *)data->getNext()) - { + BlockHeader* data = (BlockHeader*)mResource->mData; + for (u32 i = 0; i < mResource->mNumBlocks; i++, data = (BlockHeader*)data->getNext()) { int magic = data->mMagic; - switch (magic) - { - case 'WID1': - mWidthBlockCount++; - break; + switch (magic) { + case 'WID1': + mWidthBlockCount++; + break; - case 'GLY1': - mGlyphBlockCount++; - break; + case 'GLY1': + mGlyphBlockCount++; + break; - case 'MAP1': - mMapBlockCount++; - break; + case 'MAP1': + mMapBlockCount++; + break; - case 'INF1': - // mInfoBlock; - break; + case 'INF1': + // mInfoBlock; + break; - default: - JUTReportConsole("JUTResFont: Unknown data block\n"); + default: + JUTReportConsole("JUTResFont: Unknown data block\n"); } }; } -void JUTResFont::setBlock() -{ +void JUTResFont::setBlock() { int widthNum = 0; int glyphNum = 0; - int mapNum = 0; + int mapNum = 0; mMaxCode = -1; - BlockHeader *data = (BlockHeader *)mResource->mData; - for (u32 i = 0; i < mResource->mNumBlocks; i++, data = (BlockHeader *)data->getNext()) - { + BlockHeader* data = (BlockHeader*)mResource->mData; + for (u32 i = 0; i < mResource->mNumBlocks; i++, data = (BlockHeader*)data->getNext()) { int magic = data->mMagic; - switch (magic) - { - case 'INF1': - mInfoBlock = (ResFONT::InfoBlock *)data; - u32 u = mInfoBlock->mFontType; -#line 244 - JUT_ASSERT(u < suAboutEncoding_); - mIsLeadByte = (IsLeadByte *)&saoAboutEncoding_[u]; - break; + switch (magic) { + case 'INF1': + mInfoBlock = (ResFONT::InfoBlock*)data; + u32 u = mInfoBlock->mFontType; + JUT_ASSERT(u < suAboutEncoding_); + mIsLeadByte = (IsLeadByte*)&saoAboutEncoding_[u]; + break; - case 'WID1': - mWidthBlocks[widthNum] = (ResFONT::WidthBlock *)data; - widthNum++; - break; + case 'WID1': + mWidthBlocks[widthNum] = (ResFONT::WidthBlock*)data; + widthNum++; + break; - case 'GLY1': - mGlyphBlocks[glyphNum] = (ResFONT::GlyphBlock *)data; - glyphNum++; - break; + case 'GLY1': + mGlyphBlocks[glyphNum] = (ResFONT::GlyphBlock*)data; + glyphNum++; + break; - case 'MAP1': - mMapBlocks[mapNum] = (ResFONT::MapBlock *)data; - if (mMaxCode > mMapBlocks[mapNum]->mStartCode) - { - mMaxCode = mMapBlocks[mapNum]->mStartCode; - } - mapNum++; - break; + case 'MAP1': + mMapBlocks[mapNum] = (ResFONT::MapBlock*)data; + if (mMaxCode > mMapBlocks[mapNum]->mStartCode) { + mMaxCode = mMapBlocks[mapNum]->mStartCode; + } + mapNum++; + break; - default: - JUTReportConsole("Unknown data block\n"); - break; + default: + JUTReportConsole("Unknown data block\n"); + break; } } } -void JUTResFont::setGX() -{ +void JUTResFont::setGX() { GXSetNumChans(1); GXSetNumTevStages(1); GXSetNumTexGens(1); @@ -209,14 +188,10 @@ void JUTResFont::setGX() GXSetVtxDesc(GX_VA_TEX0, GX_DIRECT); } -void JUTResFont::setGX(JUtility::TColor color0, JUtility::TColor color1) -{ - if (u32(color0) == 0 && u32(color1) == -1) - { +void JUTResFont::setGX(JUtility::TColor color0, JUtility::TColor color1) { + if (u32(color0) == 0 && u32(color1) == -1) { setGX(); - } - else - { + } else { GXSetNumChans(1); GXSetNumTevStages(2); GXSetNumTexGens(1); @@ -250,37 +225,27 @@ void JUTResFont::setGX(JUtility::TColor color0, JUtility::TColor color1) } } -f32 JUTResFont::drawChar_scale(f32 pos_x, f32 pos_y, f32 scale_x, f32 scale_y, int chr, bool flag) -{ +f32 JUTResFont::drawChar_scale(f32 pos_x, f32 pos_y, f32 scale_x, f32 scale_y, int chr, bool flag) { JUTFont::TWidth width; f32 posMinX; // declaration order matters! f32 posMinY, scaled_height; f32 posMaxX; -#line 378 JUT_ASSERT(mValid); - loadFont(chr, GX_TEXMAP0, &width); - if ((mFixed) || (!flag)) - { + if ((mFixed) || (!flag)) { posMinX = pos_x; - } - else - { + } else { posMinX = (pos_x - width.w0 * (scale_x / getCellWidth())); } f32 retval = mFixedWidth * (scale_x / getCellWidth()); - if (!mFixed) - { - if (!flag) - { + if (!mFixed) { + if (!flag) { retval = (width.w1 + width.w0) * (scale_x / getCellWidth()); - } - else - { + } else { retval = width.w1 * (scale_x / getCellWidth()); } } @@ -292,7 +257,7 @@ f32 JUTResFont::drawChar_scale(f32 pos_x, f32 pos_y, f32 scale_x, f32 scale_y, i f32 posMaxY = descent * scaled_height + pos_y; // glyph section - ResFONT::GlyphBlock *used_glyphs = mGlyphBlocks[_66]; + ResFONT::GlyphBlock* used_glyphs = mGlyphBlocks[_66]; u16 tex_width = used_glyphs->mTextureWidth; u16 tex_height = used_glyphs->mTextureHeight; int t_width = mWidth; @@ -333,26 +298,21 @@ f32 JUTResFont::drawChar_scale(f32 pos_x, f32 pos_y, f32 scale_x, f32 scale_y, i return retval; } -void JUTResFont::loadFont(int chr, GXTexMapID id, JUTFont::TWidth *width) -{ - if (width) - { +void JUTResFont::loadFont(int chr, GXTexMapID id, JUTFont::TWidth* width) { + if (width) { getWidthEntry(chr, width); } int fontcode = getFontCode(chr); loadImage(fontcode, id); } -void JUTResFont::getWidthEntry(int chr, JUTFont::TWidth *width) const -{ +void JUTResFont::getWidthEntry(int chr, JUTFont::TWidth* width) const { int fontcode = getFontCode(chr); width->w0 = 0; width->w1 = mInfoBlock->mWidth; - for (int i = 0; i < mWidthBlockCount; i++) - { - if (mWidthBlocks[i]->mStartCode <= fontcode && fontcode <= mWidthBlocks[i]->mEndCode) - { + for (int i = 0; i < mWidthBlockCount; i++) { + if (mWidthBlocks[i]->mStartCode <= fontcode && fontcode <= mWidthBlocks[i]->mEndCode) { *width = mWidthBlocks[i]->mChunkNum[(fontcode - mWidthBlocks[i]->mStartCode)]; break; } @@ -360,95 +320,78 @@ void JUTResFont::getWidthEntry(int chr, JUTFont::TWidth *width) const return; } -int JUTResFont::getCellWidth() const -{ - ResFONT::GlyphBlock *glyph; - ResFONT::GlyphBlock **glyphs; +int JUTResFont::getCellWidth() const { + ResFONT::GlyphBlock* glyph; + ResFONT::GlyphBlock** glyphs; glyphs = mGlyphBlocks; - if (glyphs) - { + if (glyphs) { glyph = *glyphs; - if (glyph) - { + if (glyph) { return glyph->mCellWidth; } } return getWidth(); } -int JUTResFont::getCellHeight() const -{ - ResFONT::GlyphBlock *glyph; - ResFONT::GlyphBlock **glyphs; +int JUTResFont::getCellHeight() const { + ResFONT::GlyphBlock* glyph; + ResFONT::GlyphBlock** glyphs; glyphs = mGlyphBlocks; - if (glyphs) - { + if (glyphs) { glyph = *glyphs; - if (glyph) - { + if (glyph) { return glyph->mCellHeight; } } return getHeight(); } -bool JUTResFont::isLeadByte(int chr) const { return (*mIsLeadByte)(chr); } +bool JUTResFont::isLeadByte(int chr) const { + return (*mIsLeadByte)(chr); +} // regswaps -int JUTResFont::getFontCode(int chr) const -{ +int JUTResFont::getFontCode(int chr) const { static const u16 halftofull[95] = { - 0x8140, 0x8149, 0x8168, 0x8194, 0x8190, 0x8193, 0x8195, 0x8166, 0x8169, 0x816A, 0x8196, 0x817B, - 0x8143, 0x817C, 0x8144, 0x815E, 0x824F, 0x8250, 0x8251, 0x8252, 0x8253, 0x8254, 0x8255, 0x8256, - 0x8257, 0x8258, 0x8146, 0x8147, 0x8183, 0x8181, 0x8184, 0x8148, 0x8197, 0x8260, 0x8261, 0x8262, - 0x8263, 0x8264, 0x8265, 0x8266, 0x8267, 0x8268, 0x8269, 0x826A, 0x826B, 0x826C, 0x826D, 0x826E, - 0x826F, 0x8270, 0x8271, 0x8272, 0x8273, 0x8274, 0x8275, 0x8276, 0x8277, 0x8278, 0x8279, 0x816D, - 0x818F, 0x816E, 0x814F, 0x8151, 0x8165, 0x8281, 0x8282, 0x8283, 0x8284, 0x8285, 0x8286, 0x8287, - 0x8288, 0x8289, 0x828A, 0x828B, 0x828C, 0x828D, 0x828E, 0x828F, 0x8290, 0x8291, 0x8292, 0x8293, + 0x8140, 0x8149, 0x8168, 0x8194, 0x8190, 0x8193, 0x8195, 0x8166, 0x8169, 0x816A, 0x8196, 0x817B, 0x8143, 0x817C, + 0x8144, 0x815E, 0x824F, 0x8250, 0x8251, 0x8252, 0x8253, 0x8254, 0x8255, 0x8256, 0x8257, 0x8258, 0x8146, 0x8147, + 0x8183, 0x8181, 0x8184, 0x8148, 0x8197, 0x8260, 0x8261, 0x8262, 0x8263, 0x8264, 0x8265, 0x8266, 0x8267, 0x8268, + 0x8269, 0x826A, 0x826B, 0x826C, 0x826D, 0x826E, 0x826F, 0x8270, 0x8271, 0x8272, 0x8273, 0x8274, 0x8275, 0x8276, + 0x8277, 0x8278, 0x8279, 0x816D, 0x818F, 0x816E, 0x814F, 0x8151, 0x8165, 0x8281, 0x8282, 0x8283, 0x8284, 0x8285, + 0x8286, 0x8287, 0x8288, 0x8289, 0x828A, 0x828B, 0x828C, 0x828D, 0x828E, 0x828F, 0x8290, 0x8291, 0x8292, 0x8293, 0x8294, 0x8295, 0x8296, 0x8297, 0x8298, 0x8299, 0x829A, 0x816F, 0x8162, 0x8170, 0x8160, }; - + int ret = mInfoBlock->mDefaultCode; - if ((getFontType() == 2) && (mMaxCode >= 0x8000U) && (chr >= 0x20) && (chr < 0x7FU)) - { + if ((getFontType() == 2) && (mMaxCode >= 0x8000U) && (chr >= 0x20) && (chr < 0x7FU)) { chr = halftofull[chr - 32]; } - for (int i = 0; i < mMapBlockCount; i++) - { - if ((mMapBlocks[i]->mStartCode <= chr) && (chr <= mMapBlocks[i]->mEndCode)) - { - if (mMapBlocks[i]->mMappingMethod == 0) - { + for (int i = 0; i < mMapBlockCount; i++) { + if ((mMapBlocks[i]->mStartCode <= chr) && (chr <= mMapBlocks[i]->mEndCode)) { + if (mMapBlocks[i]->mMappingMethod == 0) { ret = chr - mMapBlocks[i]->mStartCode; break; - } - else if (mMapBlocks[i]->mMappingMethod == 2) - { + } else if (mMapBlocks[i]->mMappingMethod == 2) { ret = *(&mMapBlocks[i]->mLeading + ((chr - mMapBlocks[i]->mStartCode))); // type punning sin break; - } - else if (mMapBlocks[i]->mMappingMethod == 3) - { - - u16 *leading_temp = &mMapBlocks[i]->mLeading; + } else if (mMapBlocks[i]->mMappingMethod == 3) { + + u16* leading_temp = &mMapBlocks[i]->mLeading; int phi_r5 = 0; int phi_r6_2 = mMapBlocks[i]->mNumEntries - 1; - while (phi_r6_2 >= phi_r5) - { + while (phi_r6_2 >= phi_r5) { int temp_r7 = (phi_r6_2 + phi_r5) / 2; - if (chr < leading_temp[temp_r7 * 2]) - { + if (chr < leading_temp[temp_r7 * 2]) { phi_r6_2 = temp_r7 - 1; continue; } - if (chr > leading_temp[temp_r7 * 2]) - { + if (chr > leading_temp[temp_r7 * 2]) { phi_r5 = temp_r7 + 1; continue; } @@ -456,12 +399,9 @@ int JUTResFont::getFontCode(int chr) const ret = leading_temp[temp_r7 * 2 + 1]; // jank? possibly type punning fuckery break; } // loop closes here - } - else if (mMapBlocks[i]->mMappingMethod == 1) - { - u16 *phi_r5_2 = nullptr; - if (mMapBlocks[i]->mNumEntries == 1) - { + } else if (mMapBlocks[i]->mMappingMethod == 1) { + u16* phi_r5_2 = nullptr; + if (mMapBlocks[i]->mNumEntries == 1) { phi_r5_2 = &mMapBlocks[i]->mLeading; } ret = JUTResFont::convertSjis(chr, phi_r5_2); @@ -473,14 +413,11 @@ int JUTResFont::getFontCode(int chr) const return ret; } -void JUTResFont::loadImage(int code, GXTexMapID id) -{ +void JUTResFont::loadImage(int code, GXTexMapID id) { int i = 0; - for (; i < mGlyphBlockCount; i++) - { - if (mGlyphBlocks[i]->mStartCode <= code && code <= mGlyphBlocks[i]->mEndCode) - { + for (; i < mGlyphBlockCount; i++) { + if (mGlyphBlocks[i]->mStartCode <= code && code <= mGlyphBlocks[i]->mEndCode) { code -= mGlyphBlocks[i]->mStartCode; break; } @@ -497,10 +434,10 @@ void JUTResFont::loadImage(int code, GXTexMapID id) mWidth = cellCol * mGlyphBlocks[i]->mCellWidth; mHeight = cellRow * mGlyphBlocks[i]->mCellHeight; - if (pageIdx != _44 || i != _66) - { - GXInitTexObj(&_24, &mGlyphBlocks[i]->mData[pageIdx * mGlyphBlocks[i]->mTextureSize], mGlyphBlocks[i]->mTextureWidth, - mGlyphBlocks[i]->mTextureHeight, (GXTexFmt)mGlyphBlocks[i]->mTextureFormat, GX_CLAMP, GX_CLAMP, 0); + if (pageIdx != _44 || i != _66) { + GXInitTexObj(&_24, &mGlyphBlocks[i]->mData[pageIdx * mGlyphBlocks[i]->mTextureSize], + mGlyphBlocks[i]->mTextureWidth, mGlyphBlocks[i]->mTextureHeight, + (GXTexFmt)mGlyphBlocks[i]->mTextureFormat, GX_CLAMP, GX_CLAMP, 0); GXInitTexObjLOD(&_24, GX_LINEAR, GX_LINEAR, 0.0f, 0.0f, 0.0f, 0U, 0U, GX_ANISO_1); _44 = pageIdx; @@ -511,17 +448,15 @@ void JUTResFont::loadImage(int code, GXTexMapID id) } // probably needs some work to match TP(debug) -int JUTResFont::convertSjis(int inChr, u16 *inLead) const -{ +int JUTResFont::convertSjis(int inChr, u16* inLead) const { u8 hi = JSUHiByte(inChr); u16 lead = JSULoByte(inChr); int out = lead - 0x40; - if (0x40 <= out) - { + if (0x40 <= out) { out--; } lead = 0x31c; - if(inLead) { + if (inLead) { lead = *inLead; } return out + (hi - 0x88) * 0xbc + -0x5e + lead; diff --git a/src/static/JSystem/JUtility/JUTVideo.cpp b/src/static/JSystem/JUtility/JUTVideo.cpp index b3a85747..448b1b09 100644 --- a/src/static/JSystem/JUtility/JUTVideo.cpp +++ b/src/static/JSystem/JUtility/JUTVideo.cpp @@ -3,37 +3,32 @@ #include "JSystem/JUtility/JUTVideo.h" #include "JSystem/JUtility/JUTXfb.h" -JUTVideo *JUTVideo::sManager; +JUTVideo* JUTVideo::sManager; OSTick JUTVideo::sVideoLastTick; OSTick JUTVideo::sVideoInterval; bool sDrawWaiting; -JUTVideo *JUTVideo::createManager(const GXRenderModeObj *renderModeObj) -{ - if (sManager == nullptr) - { +JUTVideo* JUTVideo::createManager(const GXRenderModeObj* renderModeObj) { + if (sManager == nullptr) { sManager = new JUTVideo(renderModeObj); } return sManager; } -void JUTVideo::destroyManager() -{ - if (sManager != nullptr) - { +void JUTVideo::destroyManager() { + if (sManager != nullptr) { delete sManager; sManager = nullptr; } } -JUTVideo::JUTVideo(const GXRenderModeObj *renderModeObj) -{ +JUTVideo::JUTVideo(const GXRenderModeObj* renderModeObj) { mRenderModeObj = nullptr; VIInit(); setRenderMode(renderModeObj); mIsSetBlack = true; - mSetBlackFrameCount = 2; + mSetBlackFrameCount = 2; VISetBlack(TRUE); VIFlush(); _08 = 0; @@ -50,16 +45,13 @@ JUTVideo::JUTVideo(const GXRenderModeObj *renderModeObj) GXSetDrawDoneCallback(drawDoneCallback); } -JUTVideo::~JUTVideo() -{ +JUTVideo::~JUTVideo() { VISetPreRetraceCallback(mPreviousPreRetraceCallback); VISetPostRetraceCallback(mPreviousPostRetraceCallback); } -void JUTVideo::preRetraceProc(u32 retrace_count) -{ - if (sManager->mPreRetraceCallback) - { +void JUTVideo::preRetraceProc(u32 retrace_count) { + if (sManager->mPreRetraceCallback) { (*sManager->mPreRetraceCallback)(retrace_count); } @@ -67,29 +59,25 @@ void JUTVideo::preRetraceProc(u32 retrace_count) sVideoInterval = OSDiffTick(tick, sVideoLastTick); sVideoLastTick = tick; - JUTXfb *xfb = JUTXfb::getManager(); - if (!xfb) - { + JUTXfb* xfb = JUTXfb::getManager(); + if (!xfb) { VISetBlack(TRUE); VIFlush(); return; } - static void *frameBuffer = nullptr; + static void* frameBuffer = nullptr; - if (frameBuffer) - { - JUTVideo *videoManager = JUTGetVideoManager(); - const GXRenderModeObj *renderMode = videoManager->getRenderMode(); - JUTDirectPrint *directPrint = JUTDirectPrint::getManager(); + if (frameBuffer) { + JUTVideo* videoManager = JUTGetVideoManager(); + const GXRenderModeObj* renderMode = videoManager->getRenderMode(); + JUTDirectPrint* directPrint = JUTDirectPrint::getManager(); directPrint->changeFrameBuffer(frameBuffer, renderMode->fbWidth, renderMode->efbHeight); } - if (sManager->mIsSetBlack == 1) - { + if (sManager->mIsSetBlack == 1) { s32 frame_count = sManager->mSetBlackFrameCount; - if (frame_count > 0) - { + if (frame_count > 0) { frame_count--; } @@ -100,50 +88,38 @@ void JUTVideo::preRetraceProc(u32 retrace_count) return; } - if (!xfb) - { + if (!xfb) { VISetBlack(TRUE); VIFlush(); return; } - if (xfb->getBufferNum() == 3 || xfb->getBufferNum() == 2) - { - if (!sDrawWaiting) - { + if (xfb->getBufferNum() == 3 || xfb->getBufferNum() == 2) { + if (!sDrawWaiting) { s16 index = xfb->getDrawnXfbIndex(); xfb->setDisplayingXfbIndex(index); - if (index < 0) - { + if (index < 0) { VISetBlack(TRUE); VIFlush(); - } - else - { + } else { VISetBlack(FALSE); VISetNextFrameBuffer(xfb->getDisplayingXfb()); - VIFlush(); + VIFlush(); frameBuffer = xfb->getDisplayingXfb(); } } - } - else if (xfb->getBufferNum() == 1) - { - if (xfb->getSDrawingFlag() == 0) - { + } else if (xfb->getBufferNum() == 1) { + if (xfb->getSDrawingFlag() == 0) { s16 index = xfb->getDrawnXfbIndex(); - if (index >= 0) - { + if (index >= 0) { xfb->setDisplayingXfbIndex(index); GXCopyDisp(xfb->getDisplayingXfb(), GX_TRUE); GXFlush(); xfb->setSDrawingFlag(2); frameBuffer = xfb->getDisplayingXfb(); VISetBlack(FALSE); - - } - else - { + + } else { VISetBlack(TRUE); } } @@ -151,76 +127,67 @@ void JUTVideo::preRetraceProc(u32 retrace_count) } } -void JUTVideo::drawDoneStart() -{ +void JUTVideo::drawDoneStart() { sDrawWaiting = true; GXSetDrawDone(); } -void JUTVideo::dummyNoDrawWait() { sDrawWaiting = false; } +void JUTVideo::dummyNoDrawWait() { + sDrawWaiting = false; +} -void JUTVideo::drawDoneCallback() -{ - JUTXfb *xfb = JUTXfb::getManager(); - if (!xfb) - { +void JUTVideo::drawDoneCallback() { + JUTXfb* xfb = JUTXfb::getManager(); + if (!xfb) { return; } sDrawWaiting = false; - if (xfb->getBufferNum() == JUTXfb::SingleBuffer && xfb->getSDrawingFlag() == 1) - { + if (xfb->getBufferNum() == JUTXfb::SingleBuffer && xfb->getSDrawingFlag() == 1) { xfb->setSDrawingFlag(0); - if (xfb->getDrawnXfb()) - { + if (xfb->getDrawnXfb()) { VISetNextFrameBuffer(xfb->getDrawnXfb()); VIFlush(); } } } -void JUTVideo::postRetraceProc(u32 p1) -{ - if (sManager->mPostRetraceCallback != nullptr) - { +void JUTVideo::postRetraceProc(u32 p1) { + if (sManager->mPostRetraceCallback != nullptr) { sManager->mPostRetraceCallback(p1); } u32 retraceCount = VIGetRetraceCount(); - OSSendMessage(&sManager->mMessageQueue, (void *)retraceCount, OS_MESSAGE_NOBLOCK); + OSSendMessage(&sManager->mMessageQueue, (void*)retraceCount, OS_MESSAGE_NOBLOCK); } -void JUTVideo::setRenderMode(const GXRenderModeObj *newRenderModeObj) -{ - if (mRenderModeObj && newRenderModeObj->viTVmode != mRenderModeObj->viTVmode) - { +void JUTVideo::setRenderMode(const GXRenderModeObj* newRenderModeObj) { + if (mRenderModeObj && newRenderModeObj->viTVmode != mRenderModeObj->viTVmode) { mIsSetBlack = true; mSetBlackFrameCount = 4; } - mRenderModeObj = (GXRenderModeObj *)newRenderModeObj; + mRenderModeObj = (GXRenderModeObj*)newRenderModeObj; VIConfigure(mRenderModeObj); VIFlush(); - if (mIsSetBlack) - { + if (mIsSetBlack) { VIWaitForRetrace(); VIWaitForRetrace(); } } -void JUTVideo::waitRetraceIfNeed() {} +void JUTVideo::waitRetraceIfNeed() { +} -VIRetraceCallback JUTVideo::setPreRetraceCallback(VIRetraceCallback newCB) -{ +VIRetraceCallback JUTVideo::setPreRetraceCallback(VIRetraceCallback newCB) { VIRetraceCallback oldCB = mPreRetraceCallback; mPreRetraceCallback = newCB; return oldCB; } -VIRetraceCallback JUTVideo::setPostRetraceCallback(VIRetraceCallback newCB) -{ +VIRetraceCallback JUTVideo::setPostRetraceCallback(VIRetraceCallback newCB) { VIRetraceCallback oldCB = mPostRetraceCallback; mPostRetraceCallback = newCB; return oldCB; -} \ No newline at end of file +} diff --git a/src/static/JSystem/JUtility/JUTXfb.cpp b/src/static/JSystem/JUtility/JUTXfb.cpp index 521ed13b..2006cddf 100644 --- a/src/static/JSystem/JUtility/JUTXfb.cpp +++ b/src/static/JSystem/JUtility/JUTXfb.cpp @@ -5,10 +5,9 @@ #include "JSystem/JUtility/JUTVideo.h" #include "JSystem/JUtility/JUTXfb.h" -JUTXfb *JUTXfb::sManager; +JUTXfb* JUTXfb::sManager; -void JUTXfb::clearIndex() -{ +void JUTXfb::clearIndex() { mDrawingXfbIndex = -1; mDrawnXfbIndex = -1; mDisplayingXfbIndex = -1; @@ -20,16 +19,12 @@ void JUTXfb::common_init(int xfbNum) { mSDrawingFlag = 99; } -JUTXfb::JUTXfb(const GXRenderModeObj *rmode, JKRHeap *heap, JUTXfb::EXfbNumber number) -{ +JUTXfb::JUTXfb(const GXRenderModeObj* rmode, JKRHeap* heap, JUTXfb::EXfbNumber number) { common_init(number); - if (rmode) - { + if (rmode) { initiate(rmode->fbWidth, rmode->xfbHeight, heap, number); - } - else - { + } else { u16 efbWidth = JUTVideo::getManager()->getRenderMode()->fbWidth; u16 xfbHeight = JUTVideo::getManager()->getRenderMode()->xfbHeight; u16 efbHeight = JUTVideo::getManager()->getRenderMode()->efbHeight; @@ -38,44 +33,35 @@ JUTXfb::JUTXfb(const GXRenderModeObj *rmode, JKRHeap *heap, JUTXfb::EXfbNumber n } } -JUTXfb::~JUTXfb() -{ - for (int i = 0; i < 3; i++) - { +JUTXfb::~JUTXfb() { + for (int i = 0; i < 3; i++) { delXfb(i); } sManager = nullptr; } -void JUTXfb::delXfb(int xfbIdx) -{ - if (mXfbAllocated[xfbIdx] && mBuffer[xfbIdx]) - { +void JUTXfb::delXfb(int xfbIdx) { + if (mXfbAllocated[xfbIdx] && mBuffer[xfbIdx]) { delete mBuffer[xfbIdx]; } } -JUTXfb *JUTXfb::createManager(const GXRenderModeObj* rmode, JKRHeap *heap, JUTXfb::EXfbNumber number) -{ +JUTXfb* JUTXfb::createManager(const GXRenderModeObj* rmode, JKRHeap* heap, JUTXfb::EXfbNumber number) { JUT_CONFIRM_MESSAGE(sManager == 0); - if (sManager == nullptr) - { + if (sManager == nullptr) { sManager = new JUTXfb(rmode, heap, number); } return sManager; } -void JUTXfb::destroyManager() -{ +void JUTXfb::destroyManager() { JUT_CONFIRM_MESSAGE(sManager); delete sManager; sManager = nullptr; } -void JUTXfb::initiate(u16 w, u16 h, JKRHeap *heap, JUTXfb::EXfbNumber number) -{ - if (heap == nullptr) - { +void JUTXfb::initiate(u16 w, u16 h, JKRHeap* heap, JUTXfb::EXfbNumber number) { + if (heap == nullptr) { heap = JKRGetSystemHeap(); } @@ -83,32 +69,25 @@ void JUTXfb::initiate(u16 w, u16 h, JKRHeap *heap, JUTXfb::EXfbNumber number) mBuffer[0] = new (heap, 32) u16[size]; mXfbAllocated[0] = true; - if (number >= DoubleBuffer) - { + if (number >= DoubleBuffer) { mBuffer[1] = new (heap, 32) u16[size]; mXfbAllocated[1] = true; - } - else - { + } else { mBuffer[1] = nullptr; mXfbAllocated[1] = false; } - if (number >= TripleBuffer) - { + if (number >= TripleBuffer) { mBuffer[2] = new (heap, 32) u16[size]; mXfbAllocated[2] = true; - } - else - { + } else { mBuffer[2] = nullptr; mXfbAllocated[2] = false; } } -u32 JUTXfb::accumeXfbSize() -{ - JUTVideo *video = JUTVideo::getManager(); +u32 JUTXfb::accumeXfbSize() { + JUTVideo* video = JUTVideo::getManager(); u16 height = video->getXfbHeight(); u16 width = video->getFbWidth(); return (u16)ALIGN_NEXT(width, 16) * height * 2; From 1960e9693d552e70544a808f5636a1bee69b1cab Mon Sep 17 00:00:00 2001 From: SwareJonge <41187958+SwareJonge@users.noreply.github.com> Date: Tue, 17 Jun 2025 23:56:14 +0200 Subject: [PATCH 9/9] correct minor issue in OSError --- include/dolphin/os/OSError.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/include/dolphin/os/OSError.h b/include/dolphin/os/OSError.h index 487c159f..27831723 100644 --- a/include/dolphin/os/OSError.h +++ b/include/dolphin/os/OSError.h @@ -26,8 +26,7 @@ typedef void (*OSErrorHandler)(OSError error, OSContext *context, ...); #define OS_ERROR_SYSTEM_INTERRUPT 13 #define OS_ERROR_THERMAL_INTERRUPT 14 #define OS_ERROR_PROTECTION 15 -#define OS_ERROR_FPE 16 -#define OS_ERROR_MAX (OS_ERROR_FPE + 1) +#define OS_ERROR_MAX (OS_ERROR_PROTECTION + 1) OSErrorHandler OSSetErrorHandler(OSError error, OSErrorHandler handler);