Skip to content

Commit

Permalink
Merge pull request #5 from SuperDude88/main
Browse files Browse the repository at this point in the history
JFramework Mostly Matching
  • Loading branch information
magcius authored Sep 10, 2023
2 parents ef45f47 + 37e0ee5 commit 7a5484f
Show file tree
Hide file tree
Showing 12 changed files with 834 additions and 68 deletions.
2 changes: 2 additions & 0 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ def ActorRel(rel_name, status):
"cflags": CFLAGS_FRAMEWORK,
"host": True,
"objects": [
NonMatching("JSystem/JFramework/JFWDisplay.cpp"),
NonMatching("JSystem/JFramework/JFWSystem.cpp"),
Matching ("JSystem/JKernel/JKRFile.cpp"),
Matching ("JSystem/JSupport/JSUList.cpp"),
NonMatching("JSystem/JSupport/JSUInputStream.cpp"),
Expand Down
61 changes: 61 additions & 0 deletions include/JSystem/J2DGraph/J2DGrafContext.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#ifndef J2DGRAFCONTEXT_H
#define J2DGRAFCONTEXT_H

#include "JSystem/JGeometry.h"
#include "JSystem/JUtility/TColor.h"
#include "dolphin/mtx/mtx.h"
#include "dolphin/types.h"

class J2DGrafContext {
public:
struct Blend {
/* 0x0 */ u8 mType;
/* 0x1 */ u8 mSrcFactor;
/* 0x2 */ u8 mDstFactor;
};


/* 802E8B08 */ J2DGrafContext(f32 x, f32 y, f32 width, f32 height);
/* 802E90C0 */ void scissor(JGeometry::TBox2<f32> const& bounds);
void setColor(JUtility::TColor c) { this->setColor(c, c, c, c); }
/* 802E9118 */ void setColor(JUtility::TColor colorTL, JUtility::TColor colorTR,
JUtility::TColor colorBR, JUtility::TColor colorBL);
/* 802E9234 */ void setLineWidth(u8);
/* 802E9260 */ void fillBox(JGeometry::TBox2<f32> const& box);
/* 802E9368 */ void drawFrame(JGeometry::TBox2<f32> const& box);
/* 802E9488 */ void line(JGeometry::TVec2<f32> start, JGeometry::TVec2<f32> end);
/* 802E9564 */ void lineTo(JGeometry::TVec2<f32> pos);
void lineTo(f32 x, f32 y) { this->lineTo(JGeometry::TVec2<f32>(x, y)); }
void moveTo(f32 x, f32 y) { this->moveTo(JGeometry::TVec2<f32>(x, y)); }

void moveTo(JGeometry::TVec2<f32> pos) { mPrevPos = pos; }

/* 802E95D4 */ virtual ~J2DGrafContext() {}
/* 802E90E4 */ virtual void place(JGeometry::TBox2<f32> const& bounds);
/* 802E961C */ virtual void place(f32 x, f32 y, f32 width, f32 height) {
JGeometry::TBox2<f32> box(x, y, x + width, y + height);
this->place(box);
}
/* 802E8BB4 */ virtual void setPort();
/* 802E8C44 */ virtual void setup2D();
/* 802E8E20 */ virtual void setScissor();
/* 802E9664 */ virtual s32 getGrafType() const { return 0; }
/* 802E966C */ virtual void setLookat() {}

public:
/* 0x04 */ JGeometry::TBox2<f32> mBounds;
/* 0x14 */ JGeometry::TBox2<f32> mScissorBounds;
/* 0x24 */ JUtility::TColor mColorTL;
/* 0x28 */ JUtility::TColor mColorTR;
/* 0x2C */ JUtility::TColor mColorBR;
/* 0x30 */ JUtility::TColor mColorBL;
/* 0x34 */ u8 mLineWidth;
/* 0x38 */ JGeometry::TVec2<f32> mPrevPos;
/* 0x40 */ Mtx44 mMtx44;
/* 0x80 */ Mtx mPosMtx;
/* 0xB0 */ Blend field_0xb0;
/* 0xB3 */ Blend mLinePart;
/* 0xB6 */ Blend mBoxPart;
};

#endif /* J2DGRAFCONTEXT_H */
39 changes: 39 additions & 0 deletions include/JSystem/J2DGraph/J2DOrthoGraph.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#ifndef J2DORTHOGRAPH_H
#define J2DORTHOGRAPH_H

#include "JSystem/J2DGraph/J2DGrafContext.h"

class J2DOrthoGraph : public J2DGrafContext {
public:
J2DOrthoGraph();
J2DOrthoGraph(f32 x, f32 y, f32 width, f32 height, f32 far, f32 near);
void setOrtho(JGeometry::TBox2<f32> const& bounds, f32 far, f32 near);
void scissorBounds(JGeometry::TBox2<f32>*, JGeometry::TBox2<f32> const*);

virtual ~J2DOrthoGraph() {}
virtual void setPort();
virtual s32 getGrafType() const { return 1; }
virtual void setLookat();

f32 getWidthPower() const { return mBounds.getWidth() / mOrtho.getWidth(); }
f32 getHeightPower() const { return mBounds.getHeight() / mOrtho.getHeight(); }

void setOrtho(f32 x, f32 y, f32 width, f32 height, f32 far, f32 near) {
JGeometry::TBox2<f32> ortho(x, y, x + width, y + height);
setOrtho(ortho, far, near);
}

private:
/* 0xBC */ JGeometry::TBox2<f32> mOrtho;
/* 0xCC */ f32 mNear;
/* 0xD0 */ f32 mFar;
};

void J2DDrawLine(f32 x1, f32 y1, f32 x2, f32 y2, JUtility::TColor color,
int line_width);
void J2DFillBox(f32 x, f32 y, f32 width, f32 height, JUtility::TColor color);
void J2DFillBox(JGeometry::TBox2<f32> const& box, JUtility::TColor color);
void J2DDrawFrame(f32 x, f32 y, f32 width, f32 height, JUtility::TColor color, u8 line_width);
void J2DDrawFrame(JGeometry::TBox2<f32> const& box, JUtility::TColor color, u8 line_width);

#endif /* J2DORTHOGRAPH_H */
123 changes: 123 additions & 0 deletions include/JSystem/JFramework/JFWDisplay.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
#ifndef JFWDISPLAY_H
#define JFWDISPLAY_H

#include "JSystem/JSupport/JSUList.h"
#include "JSystem/JUtility/JUTDirectPrint.h"
#include "JSystem/JUtility/JUTFader.h"
#include "JSystem/JUtility/JUTXfb.h"
#include "dolphin/os/OSAlarm.h"
#include "dolphin/types.h"

typedef struct _GXColor GXColor;
typedef struct _GXRenderModeObj GXRenderModeObj;
class JKRHeap;

typedef void (*JFWDisplayUnkFunc)(void);

extern bool JFWAutoAbortGfx;

class JFWAlarm : public OSAlarm {
public:
JFWAlarm() /* : mLink(this) */ {}
~JFWAlarm() {}
void createAlarm() { OSCreateAlarm(this); }
void cancelAlarm() { OSCancelAlarm(this); }
//void removeLink() { sList.remove(&mLink); }
//void appendLink() { sList.append(&mLink); }
OSThread* getThread() const { return mThread; }
void setThread(OSThread* thread) { mThread = thread; }

static JSUList<JFWAlarm> sList;

public:
/* 0x30 */ OSThread* mThread;
};

class JFWDisplay {
public:
enum EDrawDone {
/* 0x0 */ UNK_METHOD_0 = 0,
/* 0x1 */ UNK_METHOD_1 = 1
};

/* 80272040 */ void ctor_subroutine(const _GXRenderModeObj*, bool enableAlpha);
/* 802720F8 */ JFWDisplay(const _GXRenderModeObj*, JKRHeap*, JUTXfb::EXfbNumber, bool);
/* 802721DC */ static JFWDisplay* createManager(JKRHeap*, JUTXfb::EXfbNumber, bool);
/* 802722B8 */ void prepareCopyDisp();
/* 802723AC */ void drawendXfb_single();
/* 802723F4 */ void exchangeXfb_double();
/* 802724FC */ void exchangeXfb_triple();
/* 80272574 */ void copyXfb_triple();
/* 802725F8 */ void preGX();
/* 8027268C */ void endGX();
/* 80272C60 */ void waitBlanking(int);
/* 80272E10 */ void threadSleep(s64);
/* 80272EB8 */ void clearEfb_init();
/* 80272F9C */ void clearEfb(int param_0, int param_1, int param_2, int param_3, GXColor color);
/* 80272F2C */ void clearEfb();
/* 80272F58 */ void clearEfb(_GXColor color);
/* 8027331C */ void calcCombinationRatio();

/* 80272798 */ virtual void beginRender();
/* 80272A04 */ virtual void endRender();
/* 80272AB0 */ virtual void endFrame();
/* 80272160 */ virtual ~JFWDisplay();

static JFWDisplay* getManager() { return sManager; }

int startFadeOut(int param_0) {
if (mpFader != NULL) {
return mpFader->startFadeOut(param_0);
}
return 1;
}

int startFadeIn(int param_0) {
if (mpFader != NULL) {
return mpFader->startFadeIn(param_0);
}
return 1;
}

void setTickRate(u32 rate) {
mTickRate = rate;
mFrameRate = 0;
}

void setDrawDoneMethod(EDrawDone drawDone) { mDrawDoneMethod = drawDone; }
void setFader(JUTFader* fader) { mpFader = fader; }
void setClearColor(JUtility::TColor color) { mClearColor = color; }

static JFWDisplay* sManager;

private:
/* 0x04 */ JUTFader* mpFader;
/* 0x08 */ const _GXRenderModeObj* mpRenderMode;
/* 0x0C */ JUtility::TColor mClearColor;
/* 0x10 */ u32 mZClear;
/* 0x14 */ JUTXfb* mXfbManager;
/* 0x18 */ u16 mGamma;
/* 0x1C */ EDrawDone mDrawDoneMethod;
/* 0x20 */ u16 mFrameRate;
/* 0x24 */ u32 mTickRate;
/* 0x28 */ bool mEnableAlpha;
/* 0x2A */ u16 mClamp;
/* 0x2C */ f32 mCombinationRatio;
/* 0x30 */ u32 field_0x30;
/* 0x34 */ u32 field_0x34;
/* 0x38 */ u32 field_0x38;
/* 0x3C */ s16 field_0x3C;
/* 0x3E */ u8 field_0x3E;
};

inline void JUTChangeFrameBuffer(void* buffer, u16 height, u16 width) {
JUTDirectPrint::getManager()->changeFrameBuffer(buffer, width, height);
}

static void JFWDrawDoneAlarm();
static void JFWGXDrawDoneAutoAbort();
static void JFWGXAbortAlarmHandler(OSAlarm* p_alarm, OSContext* p_ctx);
static void waitForTick(u32 p1, u16 p2);
static void diagnoseGpHang();

#endif /* JFWDISPLAY_H */
46 changes: 46 additions & 0 deletions include/JSystem/JFramework/JFWSystem.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#ifndef JFWSYSTEM_H
#define JFWSYSTEM_H

#include "dolphin/types.h"

typedef struct _GXRenderModeObj GXRenderModeObj;
class JKRExpHeap;
class JKRThread;
class JUTConsole;
class JUTConsoleManager;
class JUTDbPrint;
class JUTResFont;
struct ResFONT;

struct JFWSystem {
struct CSetUpParam {
static s32 maxStdHeaps;
static u32 sysHeapSize;
static u32 fifoBufSize;
static u32 aramAudioBufSize;
static u32 aramGraphBufSize;
static u32 streamPriority;
static u32 decompPriority;
static u32 aPiecePriority;
static ResFONT* systemFontRes;
static GXRenderModeObj* renderMode;
static u32 exConsoleBufferSize;
};

static void firstInit();
static void init();

static JUTConsole* getSystemConsole() { return systemConsole; }
static JKRExpHeap* getSystemHeap() { return systemHeap; }

static JKRExpHeap* rootHeap;
static JKRExpHeap* systemHeap;
static JKRThread* mainThread;
static JUTDbPrint* debugPrint;
static JUTResFont* systemFont;
static JUTConsoleManager* systemConsoleManager;
static JUTConsole* systemConsole;
static bool sInitCalled;
};

#endif /* JFWSYSTEM_H */
16 changes: 8 additions & 8 deletions include/JSystem/JKernel/JKRAram.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ class JKRAram : public JKRThread {
//private:
/* 0x00 */ // vtable
/* 0x04 */ // JKRThread
/* 0x7C */ u32 mAudioMemoryPtr;
/* 0x80 */ u32 mAudioMemorySize;
/* 0x84 */ u32 mGraphMemoryPtr;
/* 0x88 */ u32 mGraphMemorySize;
/* 0x8C */ u32 mAramMemoryPtr;
/* 0x90 */ u32 mAramMemorySize;
/* 0x94 */ JKRAramHeap* mAramHeap;
/* 0x98 */ u32 mStackArray[3];
/* 0x68 */ u32 mAudioMemoryPtr;
/* 0x6C */ u32 mAudioMemorySize;
/* 0x70 */ u32 mGraphMemoryPtr;
/* 0x74 */ u32 mGraphMemorySize;
/* 0x78 */ u32 mAramMemoryPtr;
/* 0x7C */ u32 mAramMemorySize;
/* 0x80 */ JKRAramHeap* mAramHeap;
/* 0x84 */ u32 mStackArray[3];

public:
static JKRAram* create(u32, u32, long, long, long);
Expand Down
6 changes: 2 additions & 4 deletions include/JSystem/JKernel/JKRThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ class JKRThread : JKRDisposer {

OSThread* getThreadRecord() const { return mThreadRecord; }
void* getStack() const { return mStackMemory; }
TLoad* getLoadInfo() { return &mLoadInfo; }
JKRHeap* getCurrentHeap() const { return mCurrentHeap; }
s32 getCurrentHeapError() const { return mCurrentHeapError; }

Expand Down Expand Up @@ -105,9 +104,8 @@ class JKRThread : JKRDisposer {
/* 0x54 */ s32 mMessageCount;
/* 0x58 */ void* mStackMemory;
/* 0x5C */ u32 mStackSize;
/* 0x60 */ TLoad mLoadInfo;
/* 0x74 */ JKRHeap* mCurrentHeap;
/* 0x78 */ s32 mCurrentHeapError;
/* 0x60 */ JKRHeap* mCurrentHeap;
/* 0x64 */ s32 mCurrentHeapError;

public:
static void* start(void* param_1);
Expand Down
11 changes: 5 additions & 6 deletions include/JSystem/JUtility/JUTConsole.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,11 @@ class JUTConsole : public JKRDisposer {
/* 0x58 */ int mOutput;
/* 0x5C */ JUtility::TColor field_0x5c;
/* 0x60 */ JUtility::TColor field_0x60;
/* 0x64 */ int field_0x64;
/* 0x68 */ bool mVisible;
/* 0x69 */ bool field_0x69;
/* 0x6A */ bool field_0x6a;
/* 0x6B */ bool field_0x6b;
}; // Size: 0x6C
/* 0x64 */ bool mVisible;
/* 0x65 */ bool field_0x65;
/* 0x66 */ bool field_0x66;
/* 0x67 */ bool field_0x67;
}; // Size: 0x68

class JUTConsoleManager {
public:
Expand Down
22 changes: 11 additions & 11 deletions include/JSystem/JUtility/JUTException.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,19 +119,19 @@ class JUTException : public JKRThread {
static u32 fpscr;

private:
/* 0x7C */ JUTExternalFB* mFrameMemory;
/* 0x80 */ JUTDirectPrint* mDirectPrint;
/* 0x84 */ JUTGamePad* mGamePad;
/* 0x88 */ JUTGamePad::EPadPort mGamePadPort;
/* 0x8C */ s32 mPrintWaitTime0;
/* 0x90 */ s32 mPrintWaitTime1;
/* 0x94 */ u32 mTraceSuppress;
/* 0x98 */ u32 field_0x98;
/* 0x9C */ u32 mPrintFlags;
/* 0xA0 */ u32 mStackPointer;
/* 0x68 */ JUTExternalFB* mFrameMemory;
/* 0x6C */ JUTDirectPrint* mDirectPrint;
/* 0x70 */ JUTGamePad* mGamePad;
/* 0x74 */ JUTGamePad::EPadPort mGamePadPort;
/* 0x78 */ s32 mPrintWaitTime0;
/* 0x7C */ s32 mPrintWaitTime1;
/* 0x80 */ u32 mTraceSuppress;
/* 0x84 */ u32 field_0x98;
/* 0x88 */ u32 mPrintFlags;
/* 0x8C */ u32 mStackPointer;
};

STATIC_ASSERT(sizeof(JUTException) == 0xA4);
STATIC_ASSERT(sizeof(JUTException) == 0x90);

struct JUTWarn {
JUTWarn& operator<<(const char*) { return *this; }
Expand Down
2 changes: 1 addition & 1 deletion include/JSystem/JUtility/JUTXfb.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class JUTXfb {
/* 802E5260 */ JUTXfb(_GXRenderModeObj const*, JKRHeap*, JUTXfb::EXfbNumber);
/* 802E5308 */ ~JUTXfb();
/* 802E5378 */ void delXfb(int);
/* 802E53B8 */ static JUTXfb* createManager(JKRHeap*, JUTXfb::EXfbNumber);
/* 802E53B8 */ static JUTXfb* createManager(const _GXRenderModeObj*, JKRHeap*, JUTXfb::EXfbNumber);
/* 802E5424 */ static void destroyManager();
/* 802E5454 */ void initiate(u16, u16, JKRHeap*, JUTXfb::EXfbNumber);

Expand Down
Loading

0 comments on commit 7a5484f

Please sign in to comment.