Implement & link famicom.cpp

This commit is contained in:
Cuyler36
2024-01-29 20:31:47 -05:00
parent 7788f50a59
commit d08076381b
39 changed files with 4048 additions and 119 deletions
+134
View File
@@ -0,0 +1,134 @@
#ifndef _JSYSTEM_J2D_J2DGRAFCONTEXT_H
#define _JSYSTEM_J2D_J2DGRAFCONTEXT_H
#include "types.h"
#include "JSystem/JGeometry.h"
#include "JSystem/J2D/J2DTypes.h"
#include "JSystem/JUtility/TColor.h"
#include "dolphin/mtx.h"
/**
* @fabricated
*/
enum J2DGrafType {
J2DGraf_Base = 0,
J2DGraf_Ortho = 1,
J2DGraf_Persp = 2,
};
struct J2DGrafBlend {
u8 mType; // _00
u8 mSrcFactor; // _01
u8 mDestFactor; // _02
};
struct J2DGrafContext {
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)
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 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);
// 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
};
struct J2DPerspGraph : public J2DGrafContext {
J2DPerspGraph();
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);
inline f32 getFovY() const { return mFovY; }
// _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);
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*);
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<f32> 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
};
void J2DFillBox(f32 param_0, f32 param_1, f32 param_2, f32 param_3, JUtility::TColor color);
void J2DFillBox(JGeometry::TBox2f const& param_0, JUtility::TColor param_1);
void J2DFillBox(f32, f32, f32, f32, JUtility::TColor, JUtility::TColor, JUtility::TColor, JUtility::TColor);
void J2DFillBox(const JGeometry::TBox2f&, JUtility::TColor, JUtility::TColor, JUtility::TColor, JUtility::TColor);
void J2DDrawFrame(f32 param_0, f32 param_1, f32 param_2, f32 param_3, JUtility::TColor param_4, u8 param_5);
void J2DDrawFrame(JGeometry::TBox2f const& param_0, JUtility::TColor param_1, u8 param_2);
void J2DDrawLine(f32, f32, f32, f32, JUtility::TColor, int);
#endif
+361 -7
View File
@@ -1,9 +1,363 @@
#ifndef JGEOMETRY_H
#define JGEOMETRY_H
#ifndef _JSYSTEM_JGEOMETRY_H
#define _JSYSTEM_JGEOMETRY_H
#include "JSystem/JGeometry/Vec.h"
#include "JSystem/JGeometry/Box.h"
#include "JSystem/JGeometry/Util.h"
#endif
#include "types.h"
#endif
inline f32 fsqrt_step(f32 mag)
{
f32 root = __frsqrte(mag);
return 0.5f * root * (3.0f - mag * (root * root));
}
namespace JGeometry {
template <typename T>
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 x, T y)
{
this->x = x;
this->y = y;
}
void set(const TVec2& other)
{
x = other.x;
y = other.y;
}
void setMin(const TVec2<f32>& min)
{
if (x >= min.x)
x = min.x;
if (y >= min.y)
y = min.y;
}
void setMax(const TVec2<f32>& max)
{
if (x <= max.x)
x = max.x;
if (y <= max.y)
y = max.y;
}
void add(const TVec2<T>& other)
{
x += other.x;
y += other.y;
}
/** @fabricated */
// TVec2<T> adding(const TVec2<T>& other) { return TVec2<T>(x + other.x, y + other.y); }
/** @fabricated */
TVec2<T> adding(T xDelta, T yDelta) { return TVec2<T>(x + xDelta, y + yDelta); }
/** @fabricated */
void add(T xDelta, T yDelta)
{
x += xDelta;
y += yDelta;
}
TVec2<T>& operator+=(const TVec2<T>& other)
{
x += other.x;
y += other.y;
return *this;
}
TVec2<T>& operator*=(const TVec2<T>& other)
{
x *= other.x;
y *= other.y;
return *this;
}
bool isAbove(const TVec2<T>& other) const { return (x >= other.x) && (y >= other.y) ? true : false; }
T x;
T y;
};
template <typename T>
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<T>& 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;
}
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 setMin(const TVec3<f32>& 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<f32>& 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 TVec3(Vec& vec)
// {
// x = vec.x;
// y = vec.y;
// z = vec.z;
// }
void zero() { x = y = z = 0.0f; }
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(const TVec3<f32>& 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<T>& other) const { return (x >= other.x) && (y >= other.y) && (z >= other.z); }
T x;
T y;
T z;
};
// Size: 0x10
template <class T>
struct TBox {
TBox()
: i()
, f()
{
}
TBox(const TBox& other)
: i(other.f)
, f(other.y)
{
}
T i, f;
};
// clang-format off
template<> struct TBox<TVec2<f32> > {
inline f32 getWidth() const { return f.x - i.x; }
inline f32 getHeight() const { return f.y - i.y; }
bool isValid() const { return f.isAbove(i); }
void addPos(f32 x, f32 y) {
addPos(TVec2<f32>(x, y));
}
void addPos(const TVec2<f32>& pos) {
i.add(pos);
f.add(pos);
}
bool intersect(const TBox<TVec2<f32> >& other) {
i.setMax(other.i);
f.setMin(other.f);
return isValid();
}
TVec2<f32> i, f;
};
template <typename T>
struct TBox2 : TBox<TVec2<T> > {
TBox2() {}
// TBox2(const TBox2& other) { set(other); }
TBox2(const TVec2<T>& i, const TVec2<T> f) { set(i, f); }
// TBox2(const TVec2<T>& i, T x1, T y1) { set(i, x1, y1); }
// TBox2(T x0, T y0, const TVec2<T>& f) { set(x0, y0, f); }
TBox2(f32 x0, f32 y0, f32 x1, f32 y1) { set(x0, y0, x1, y1); }
TBox2(f32 x0, f32 y0, TVec2<f32>& f) { set(x0, y0, x0 + f.x, y0 + f.y); }
TBox2(f32 val)
{
f.y = val;
f.x = val;
i.y = val;
i.x = val;
}
// inline TBox2& operator=(const TBox2& other)
// {
// set(other);
// return *this;
// }
void absolute() {
if (!this->isValid()) {
TBox2<T> box(*this);
this->i.setMin(box.i);
this->i.setMin(box.f);
this->f.setMax(box.i);
this->f.setMax(box.f);
}
}
inline void setX(const T& x) {
this->f.x = this->i.x = x;
}
inline void setY(const T& y) {
this->f.y = this->i.y = y;
}
// /** @fabricated */
// TBox2<T>& addingPos(TBox2<T>& result, const TVec2<T>& pos) {
// return TBox2<T>(i.adding(pos), f.adding(pos));
// }
void set(const TBox2& other) { set(other.i, other.f); }
void set(const TVec2<T>& i, const TVec2<T>& f) { this->i.set(i), this->f.set(f); }
// void set(const TVec2<T>& i, T x1, T y1) { this->i.set(i), this->f.set(x1, y1); }
// void set(T x0, T y0, const TVec2<T>& f) { this->i.set(x0, y0), this->f.set(f); }
void set(T x0, T y0, T x1, T y1) { this->i.set(x0, y0); this->f.set(x1, y1); }
// void setOrigin(const TVec2<T>& other) { this->i.set(other); }
// void setSize(T width, T height) { this->f.x = this->i.x + width; this->f.y = this->i.y + height; }
};
// clang-format on
template <typename T>
struct TBox3 {
// TBox3() {}
// TBox2(const TBox2& other) { set(other); }
// TBox3(const TVec3<T>& i, const TVec3<T> f) { set(i, f); }
// // TBox2(const TVec2<T>& i, T x1, T y1) { set(i, x1, y1); }
// // TBox2(T x0, T y0, const TVec2<T>& 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<T>& 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); }
void absolute()
{
if (!this->isValid()) {
TBox3<T> 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<T>& i, const TVec3<T>& 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<T> mMin; // _00
TVec3<T> mMax; // _0C
};
typedef TVec2<f32> TVec2f;
typedef TVec3<f32> TVec3f;
typedef TBox2<f32> TBox2f;
typedef TBox3<f32> TBox3f;
} // namespace JGeometry
#endif
+1
View File
@@ -6,6 +6,7 @@
#include "JSystem/JKernel/JKRDvdFile.h"
#include "JSystem/JKernel/JKRThread.h"
#include "JSystem/JKernel/JKRAram.h"
#include "JSystem/JKernel/JKREnum.h"
#define JKRDECOMP_MSG_BUF_COUNT 4
#define JKRDECOMP_STACK_SIZE 0x4000
+2 -2
View File
@@ -19,7 +19,7 @@ class JKRFileFinder
{
public:
JKRFileFinder()
: mIsAvailable(false), mIsFileOrDir(false)
: mIsAvailable(false), mIsDir(false)
{
}
@@ -36,7 +36,7 @@ public:
// _00 = VTBL
bool mIsAvailable; // _10
bool mIsFileOrDir; // _11
bool mIsDir; // _11
};
class JKRArcFinder : public JKRFileFinder
+1 -1
View File
@@ -46,7 +46,7 @@ namespace JUTAssertion
#define JUT_MAX_ASSERT(...)
#define JUT_LOG_F(...)
#ifndef DEBUG
#if defined(DEBUG) || 1
#define JUT_ASSERT(...)
#define JUT_ASSERT_F(...)
#else
+1 -1
View File
@@ -4,6 +4,6 @@
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, ...);
#endif
+4 -2
View File
@@ -126,10 +126,12 @@ public:
return JUTGamePad::sClampMode;
}
static s8 getPortStatus(EPadPort port) {
/* @HACK - This gets inlined when defined -- JSystem might have precompiled headers */
static s8 getPortStatus(EPadPort port);
/*{
JUT_ASSERT(0 <= port && port < 4);
return mPadStatus[port].err;
}
}*/
bool isPushing3ButtonReset() const {
bool pushing = false;
+156
View File
@@ -0,0 +1,156 @@
#ifndef _JUTPROCBAR_H
#define _JUTPROCBAR_H
#include "dolphin/os.h"
#include "dolphin/os/OSTime.h"
#include "JSystem/JUtility/TColor.h"
#include "JSystem/JKernel/JKRHeap.h"
#include "types.h"
class JUTProcBar
{
public:
struct CTime
{
CTime() { clear(); }
void clear()
{
mCost = 0;
_08 = 0;
_0C = 0;
}
void start(u8 red, u8 green, u8 blue)
{
mR = red;
mG = green;
mB = blue;
mStartTick = OSGetTick();
}
void end()
{
mCost = OSTicksToMicroseconds(OSDiffTick(OSGetTick(), mStartTick));
if (mCost == 0)
mCost = 1;
}
void accumePeek()
{
//u32 prev = ++_0C;
if (++_0C >= 0x10 || mCost >= _08)
{
_08 = mCost;
_0C = 0;
}
}
int calcBarSize(int p1, int p2) { return mCost * p1 / p2; }
u32 mStartTick; // _00
u32 mCost; // _04
u32 _08; // _08
u32 _0C; // _0C
u8 mR; // _10
u8 mG; // _11
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)
{
mPosX = x;
mPosY = y;
}
/* 0x00 */ int mBarWidth;
/* 0x04 */ int mPosX;
/* 0x08 */ int mPosY;
/* 0x0C */ int mWidth;
/* 0x10 */ int mUserPosition;
};
JUTProcBar(); // unused / inlined
~JUTProcBar(); // unused / inlined
static JUTProcBar* create();
static void destroy();
static void clear();
void draw();
void drawProcessBar();
void drawHeapBar();
// 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 getUnuseUserBar();
u32 getGpCost() const {
return mGp.mCost;
}
u32 getCpuCost() const {
return mCpu.mCost;
}
u32 getUserCost(int idx) {
return sManager->mUsers[idx].mCost;
}
static JUTProcBar* getManager() {
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 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;
}
inline u32 calcGPUTime() { // fabricated
return mGp.mCost - mGpWait.mCost;
}
int calcBarHeight() { // fabricated
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
}; // 0x134 size
#endif
+56
View File
@@ -0,0 +1,56 @@
#ifndef _JSYSTEM_RESTIMG_H
#define _JSYSTEM_RESTIMG_H
#include "dolphin/gx.h"
#include "types.h"
#ifndef _JUTTransparency
typedef u8 _JUTTransparency;
#endif
enum {
ResTIMG_FORMAT_C8 = 9
// TODO: others
};
enum {
ResTIMG_NO_PALETTE,
ResTIMG_PALETTE
};
struct ResTIMG {
inline BOOL isMIPmapEnabled() const { return (mIsMIPmapEnabled > 0); }
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
};
struct ResTIMGPair {
ResTIMG _00;
ResTIMG _20;
};
#endif