mirror of
https://github.com/ACreTeam/ac-decomp
synced 2026-06-16 05:55:39 -04:00
Merge pull request #502 from SwareJonge/JSystem
Implement all of JSystem
This commit is contained in:
+21
-21
@@ -611,15 +611,15 @@ 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(
|
||||
"JFramework",
|
||||
[
|
||||
Object(NonMatching, "JSystem/JFramework/JFWDisplay.cpp"),
|
||||
Object(NonMatching, "JSystem/JFramework/JFWSystem.cpp"),
|
||||
Object(Matching, "JSystem/JFramework/JFWDisplay.cpp"),
|
||||
Object(Matching, "JSystem/JFramework/JFWSystem.cpp"),
|
||||
],
|
||||
),
|
||||
JSystemLib(
|
||||
@@ -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"),
|
||||
@@ -657,29 +657,29 @@ 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(
|
||||
"JUtility",
|
||||
[
|
||||
Object(NonMatching, "JSystem/JUtility/JUTAssert.cpp"),
|
||||
Object(NonMatching, "JSystem/JUtility/JUTConsole.cpp"),
|
||||
Object(NonMatching, "JSystem/JUtility/JUTDbPrint.cpp"),
|
||||
Object(NonMatching, "JSystem/JUtility/JUTDirectFile.cpp"),
|
||||
Object(NonMatching, "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/JUTAssert.cpp"),
|
||||
Object(Matching, "JSystem/JUtility/JUTConsole.cpp"),
|
||||
Object(Matching, "JSystem/JUtility/JUTDbPrint.cpp"),
|
||||
Object(Matching, "JSystem/JUtility/JUTDirectFile.cpp"),
|
||||
Object(Matching, "JSystem/JUtility/JUTDirectPrint.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"),
|
||||
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"),
|
||||
],
|
||||
),
|
||||
# {
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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<f32> 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<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
|
||||
// _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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 <dolphin/mtx.h>
|
||||
#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,
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -0,0 +1,176 @@
|
||||
#ifndef _JSYSTEM_JFW_JFWDISPLAY_H
|
||||
#define _JSYSTEM_JFW_JFWDISPLAY_H
|
||||
|
||||
#include <dolphin/gx.h>
|
||||
#include <dolphin/mtx.h>
|
||||
#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<JFWAlarm> 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
|
||||
@@ -0,0 +1,67 @@
|
||||
#ifndef _JSYSTEM_JFW_JFWSYSTEM_H
|
||||
#define _JSYSTEM_JFW_JFWSYSTEM_H
|
||||
|
||||
#include <dolphin/gx.h>
|
||||
#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;
|
||||
|
||||
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;
|
||||
}
|
||||
static void setAramAudioBufSize(u32 bufSize) {
|
||||
JUT_ASSERT(sInitCalled == 0);
|
||||
CSetUpParam::aramAudioBufSize = bufSize;
|
||||
}
|
||||
static void setAramGraphBufSize(u32 bufSize) {
|
||||
JUT_ASSERT(sInitCalled == 0);
|
||||
CSetUpParam::aramGraphBufSize = bufSize;
|
||||
}
|
||||
static void setRenderMode(const _GXRenderModeObj* rmode) {
|
||||
JUT_ASSERT(sInitCalled == 0);
|
||||
CSetUpParam::renderMode = rmode;
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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_;
|
||||
};
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
+220
-225
@@ -1,235 +1,227 @@
|
||||
#ifndef _JSYSTEM_JGEOMETRY_H
|
||||
#define _JSYSTEM_JGEOMETRY_H
|
||||
|
||||
#include <dolphin/mtx.h>
|
||||
#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 <typename T>
|
||||
struct TVec2 {
|
||||
TVec2() { }
|
||||
TVec2(T v) { set(v); }
|
||||
TVec2(T x, T y) { set(x, y); }
|
||||
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 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<f32>& min)
|
||||
{
|
||||
if (x >= min.x)
|
||||
x = min.x;
|
||||
if (y >= min.y)
|
||||
y = min.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 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;
|
||||
}
|
||||
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(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 */
|
||||
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;
|
||||
}
|
||||
/** @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;
|
||||
}
|
||||
|
||||
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; }
|
||||
bool isAbove(const TVec2<T>& other) const {
|
||||
return (x >= other.x) && (y >= other.y) ? true : false;
|
||||
}
|
||||
|
||||
T x;
|
||||
T y;
|
||||
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) {};
|
||||
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(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;
|
||||
}
|
||||
// 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<f32>& 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<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;
|
||||
}
|
||||
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 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<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;
|
||||
}
|
||||
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); }
|
||||
bool isAbove(const TVec3<T>& 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 <class T>
|
||||
struct TBox {
|
||||
TBox()
|
||||
: i()
|
||||
, f()
|
||||
{
|
||||
}
|
||||
TBox(const TBox& other)
|
||||
: i(other.f)
|
||||
, f(other.y)
|
||||
{
|
||||
}
|
||||
template <class T> struct TBox {
|
||||
TBox() : i(), f() {
|
||||
}
|
||||
TBox(const TBox& other) : i(other.f), f(other.y) {
|
||||
}
|
||||
|
||||
T i, f;
|
||||
T i, f;
|
||||
};
|
||||
|
||||
// clang-format off
|
||||
@@ -314,44 +306,47 @@ struct TBox2 : TBox<TVec2<T> > {
|
||||
};
|
||||
// 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;
|
||||
// }
|
||||
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); }
|
||||
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 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);
|
||||
}
|
||||
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
|
||||
TVec3<T> mMin; // _00
|
||||
TVec3<T> mMax; // _0C
|
||||
};
|
||||
|
||||
typedef TVec2<f32> TVec2f;
|
||||
@@ -362,4 +357,4 @@ typedef TBox3<f32> TBox3f;
|
||||
} // namespace JGeometry
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
+217
-218
@@ -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<JKRAramBlock> mLink;
|
||||
u32 mAddress;
|
||||
u32 mSize;
|
||||
u32 mFreeSize;
|
||||
u8 mGroupID;
|
||||
bool mIsTempMemory;
|
||||
JSULink<JKRAramBlock> 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<JKRAramBlock> sAramList;
|
||||
static JSUList<JKRAramBlock> 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<JKRAMCommand> sAramCommandList;
|
||||
static JKRAram* sAramObject;
|
||||
static OSMessage sMessageBuffer[4];
|
||||
static OSMessageQueue sMessageQueue;
|
||||
static JSUList<JKRAMCommand> 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<JKRAMCommand> mAramPieceCommandLink;
|
||||
JSULink<JKRAMCommand> 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<JKRAMCommand> mAramPieceCommandLink;
|
||||
JSULink<JKRAMCommand> 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<JKRAMCommand> sAramPieceCommandList;
|
||||
static OSMutex mMutex;
|
||||
static JSUList<JKRAMCommand> 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
|
||||
|
||||
@@ -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,22 +154,27 @@ public:
|
||||
u32 _1C; // _1C
|
||||
};
|
||||
|
||||
JKRArchive(s32, EMountMode);
|
||||
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
|
||||
|
||||
virtual ~JKRArchive(); // _08
|
||||
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;
|
||||
@@ -161,17 +193,13 @@ 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*);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -9,17 +9,15 @@ extern "C" {
|
||||
|
||||
class JKRHeap;
|
||||
|
||||
class JKRDisposer
|
||||
{
|
||||
public:
|
||||
class JKRDisposer {
|
||||
public:
|
||||
JKRDisposer();
|
||||
virtual ~JKRDisposer();
|
||||
|
||||
public:
|
||||
public:
|
||||
JKRHeap* mRootHeap; // _4
|
||||
JSULink<JKRDisposer> mPointerLinks; // _8
|
||||
};
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -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<JKRADCommand> 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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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<JKRDvdFile> 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<JKRDvdFile> mLink;
|
||||
OSThread* mDvdThread;
|
||||
void initiate();
|
||||
s32 sync();
|
||||
|
||||
static void doneProcess(s32 result, DVDFileInfo* info);
|
||||
|
||||
static JSUList<JKRDvdFile> 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<JKRDvdFile> mLink;
|
||||
OSThread* mDvdThread;
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
@@ -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<JKRDMCommand> sDvdAsyncList;
|
||||
static JSUList<JKRDMCommand> 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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,21 +46,26 @@ 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<JKRFileLoader>& getVolumeList() { return sVolumeList; }
|
||||
static JKRFileLoader* getCurrentVolume() {
|
||||
return sCurrentVolume;
|
||||
}
|
||||
static void setCurrentVolume(JKRFileLoader* fileLoader) {
|
||||
sCurrentVolume = fileLoader;
|
||||
}
|
||||
static JSUList<JKRFileLoader>& getVolumeList() {
|
||||
return sVolumeList;
|
||||
}
|
||||
|
||||
static JKRFileLoader* sCurrentVolume;
|
||||
static JSUList<JKRFileLoader> sVolumeList;
|
||||
|
||||
protected:
|
||||
protected:
|
||||
/* 0x00 */ // vtable
|
||||
/* 0x04 */ // JKRDisposer
|
||||
JSULink<JKRFileLoader> mFileLoaderLink; // 0x18
|
||||
const char* mVolumeName; // 0x28
|
||||
u32 mVolumeType; // 0x2C
|
||||
bool mIsMounted; // 0x30
|
||||
u8 field_0x31[3]; // 0x31
|
||||
u32 mMountCount; // 0x34
|
||||
};
|
||||
|
||||
|
||||
@@ -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<OSMutex*>(&mMutex)); }
|
||||
void unlock() const { OSUnlockMutex(const_cast<OSMutex*>(&mMutex)); }
|
||||
void lock() const {
|
||||
OSLockMutex(const_cast<OSMutex*>(&mMutex));
|
||||
}
|
||||
void unlock() const {
|
||||
OSUnlockMutex(const_cast<OSMutex*>(&mMutex));
|
||||
}
|
||||
|
||||
JKRHeap* getParent()
|
||||
{
|
||||
JKRHeap* getParent() {
|
||||
return mChildTree.getParent()->getObject();
|
||||
}
|
||||
|
||||
const JSUTree<JKRHeap>& getHeapTree()
|
||||
{
|
||||
const JSUTree<JKRHeap>& 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);
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
+133
-124
@@ -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<JKRThread>* 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<JKRThread>* getList() {
|
||||
return &JKRThread::sThreadList;
|
||||
}
|
||||
|
||||
static JSUList<JKRThread> sThreadList;
|
||||
OSThread* getThreadRecord() const {
|
||||
return this->mThreadRecord;
|
||||
}
|
||||
void* getStack() const {
|
||||
return this->mStackMemory;
|
||||
}
|
||||
|
||||
protected:
|
||||
JSULink<JKRThread> 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<JKRThread> sThreadList;
|
||||
|
||||
protected:
|
||||
JSULink<JKRThread> 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<JKRTask> 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<JKRTask> 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<JKRTask> sTaskList;
|
||||
static u8 sEndMesgQueue[32]; // Unused
|
||||
static JSUList<JKRTask> 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
|
||||
|
||||
@@ -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."))
|
||||
|
||||
@@ -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
|
||||
#endif
|
||||
|
||||
@@ -7,22 +7,32 @@
|
||||
|
||||
#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*);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -6,107 +6,134 @@
|
||||
|
||||
#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;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
+184
-125
@@ -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 T>
|
||||
class JSULink; // friend class? i'm C++ noob
|
||||
template <class T> class JSULink; // friend class? i'm C++ noob
|
||||
|
||||
template <class T>
|
||||
class JSUList : public JSUPtrList
|
||||
{
|
||||
public:
|
||||
JSUList(bool thing) : JSUPtrList(thing)
|
||||
{
|
||||
template <class T> class JSUList : public JSUPtrList {
|
||||
public:
|
||||
JSUList(bool thing) : JSUPtrList(thing) {
|
||||
}
|
||||
JSUList() : JSUPtrList()
|
||||
{
|
||||
JSUList() : JSUPtrList() {
|
||||
}
|
||||
|
||||
bool append(JSULink<T> *link) { return JSUPtrList::append((JSUPtrLink *)link); }
|
||||
bool prepend(JSULink<T> *link) { return JSUPtrList::prepend((JSUPtrLink *)link); }
|
||||
bool insert(JSULink<T> *before, JSULink<T> *link) { return JSUPtrList::insert((JSUPtrLink *)before, (JSUPtrLink *)link); }
|
||||
bool remove(JSULink<T> *link) { return JSUPtrList::remove((JSUPtrLink *)link); }
|
||||
bool append(JSULink<T>* link) {
|
||||
return JSUPtrList::append((JSUPtrLink*)link);
|
||||
}
|
||||
bool prepend(JSULink<T>* link) {
|
||||
return JSUPtrList::prepend((JSUPtrLink*)link);
|
||||
}
|
||||
bool insert(JSULink<T>* before, JSULink<T>* link) {
|
||||
return JSUPtrList::insert((JSUPtrLink*)before, (JSUPtrLink*)link);
|
||||
}
|
||||
bool remove(JSULink<T>* link) {
|
||||
return JSUPtrList::remove((JSUPtrLink*)link);
|
||||
}
|
||||
|
||||
JSULink<T> *getFirst() const { return (JSULink<T> *)getFirstLink(); }
|
||||
JSULink<T> *getLast() const { return (JSULink<T> *)getLastLink(); }
|
||||
JSULink<T> *getEnd() const { return nullptr; }
|
||||
JSULink<T>* getFirst() const {
|
||||
return (JSULink<T>*)getFirstLink();
|
||||
}
|
||||
JSULink<T>* getLast() const {
|
||||
return (JSULink<T>*)getLastLink();
|
||||
}
|
||||
JSULink<T>* getEnd() const {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
u32 getNumLinks() const { return mLinkCount; }
|
||||
u32 getNumLinks() const {
|
||||
return mLinkCount;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class JSUListIterator
|
||||
{
|
||||
public:
|
||||
JSUListIterator()
|
||||
: mLink(nullptr)
|
||||
{
|
||||
template <typename T> class JSUListIterator {
|
||||
public:
|
||||
JSUListIterator() : mLink(nullptr) {
|
||||
}
|
||||
JSUListIterator(JSULink<T> *link)
|
||||
: mLink(link)
|
||||
{
|
||||
JSUListIterator(JSULink<T>* link) : mLink(link) {
|
||||
}
|
||||
JSUListIterator(JSUList<T> *list)
|
||||
: mLink(list->getFirst())
|
||||
{
|
||||
JSUListIterator(JSUList<T>* list) : mLink(list->getFirst()) {
|
||||
}
|
||||
|
||||
JSUListIterator<T> &operator=(JSULink<T> *link)
|
||||
{
|
||||
JSUListIterator<T>& operator=(JSULink<T>* link) {
|
||||
this->mLink = link;
|
||||
return *this;
|
||||
}
|
||||
|
||||
T *getObject() { return this->mLink->getObject(); }
|
||||
T* getObject() {
|
||||
return this->mLink->getObject();
|
||||
}
|
||||
|
||||
bool operator==(JSULink<T> const *other) const { return this->mLink == other; }
|
||||
bool operator!=(JSULink<T> const *other) const { return this->mLink != other; }
|
||||
bool operator==(JSUListIterator<T> const &other) const { return this->mLink == other.mLink; }
|
||||
bool operator!=(JSUListIterator<T> const &other) const { return this->mLink != other.mLink; }
|
||||
bool operator==(JSULink<T> const* other) const {
|
||||
return this->mLink == other;
|
||||
}
|
||||
bool operator!=(JSULink<T> const* other) const {
|
||||
return this->mLink != other;
|
||||
}
|
||||
bool operator==(JSUListIterator<T> const& other) const {
|
||||
return this->mLink == other.mLink;
|
||||
}
|
||||
bool operator!=(JSUListIterator<T> const& other) const {
|
||||
return this->mLink != other.mLink;
|
||||
}
|
||||
|
||||
JSUListIterator<T> operator++(int)
|
||||
{
|
||||
JSUListIterator<T> operator++(int) {
|
||||
JSUListIterator<T> prev = *this;
|
||||
this->mLink = this->mLink->getNext();
|
||||
return prev;
|
||||
}
|
||||
|
||||
JSUListIterator<T> &operator++()
|
||||
{
|
||||
JSUListIterator<T>& operator++() {
|
||||
this->mLink = this->mLink->getNext();
|
||||
return *this;
|
||||
}
|
||||
|
||||
JSUListIterator<T> operator--(int)
|
||||
{
|
||||
JSUListIterator<T> operator--(int) {
|
||||
JSUListIterator<T> prev = *this;
|
||||
this->mLink = this->mLink->getPrev();
|
||||
return prev;
|
||||
}
|
||||
|
||||
JSUListIterator<T> &operator--()
|
||||
{
|
||||
JSUListIterator<T>& 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<T> *mLink;
|
||||
JSULink<T>* mLink;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class JSULink : public JSUPtrLink
|
||||
{
|
||||
public:
|
||||
JSULink(void *pData) : JSUPtrLink(pData)
|
||||
{
|
||||
template <class T> class JSULink : public JSUPtrLink {
|
||||
public:
|
||||
JSULink(void* pData) : JSUPtrLink(pData) {
|
||||
}
|
||||
|
||||
T *getObject() const { return (T *)mData; }
|
||||
JSUList<T> *getList() const { return (JSUList<T> *)JSUPtrLink::getList(); } // fabricated, offcial name: getSupervisor
|
||||
JSULink<T> *getNext() const { return (JSULink<T> *)JSUPtrLink::getNext(); }
|
||||
JSULink<T> *getPrev() const { return (JSULink<T> *)JSUPtrLink::getPrev(); }
|
||||
T* getObject() const {
|
||||
return (T*)mData;
|
||||
}
|
||||
JSUList<T>* getList() const {
|
||||
return (JSUList<T>*)JSUPtrLink::getList();
|
||||
} // fabricated, offcial name: getSupervisor
|
||||
JSULink<T>* getNext() const {
|
||||
return (JSULink<T>*)JSUPtrLink::getNext();
|
||||
}
|
||||
JSULink<T>* getPrev() const {
|
||||
return (JSULink<T>*)JSUPtrLink::getPrev();
|
||||
}
|
||||
|
||||
~JSULink()
|
||||
{
|
||||
~JSULink() {
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T> // TODO: most of these inlines are probably wrong: rework
|
||||
class JSUTree : public JSUList<T>, public JSULink<T>
|
||||
{
|
||||
public:
|
||||
JSUTree(T *owner) : JSUList<T>(), JSULink<T>(owner) {}
|
||||
~JSUTree() {}
|
||||
class JSUTree : public JSUList<T>, public JSULink<T> {
|
||||
public:
|
||||
JSUTree(T* owner) : JSUList<T>(), JSULink<T>(owner) {
|
||||
}
|
||||
~JSUTree() {
|
||||
}
|
||||
|
||||
bool appendChild(JSUTree<T> *child) { return this->append(child); }
|
||||
bool prependChild(JSUTree<T> *child) { return this->prepend(child); }
|
||||
bool removeChild(JSUTree<T> *child) { return this->remove(child); }
|
||||
bool insertChild(JSUTree<T> *before, JSUTree<T> *child) { return this->insert(before, child); }
|
||||
bool appendChild(JSUTree<T>* child) {
|
||||
return this->append(child);
|
||||
}
|
||||
bool prependChild(JSUTree<T>* child) {
|
||||
return this->prepend(child);
|
||||
}
|
||||
bool removeChild(JSUTree<T>* child) {
|
||||
return this->remove(child);
|
||||
}
|
||||
bool insertChild(JSUTree<T>* before, JSUTree<T>* child) {
|
||||
return this->insert(before, child);
|
||||
}
|
||||
|
||||
JSUTree<T> *getEndChild() const { return nullptr; }
|
||||
JSUTree<T> *getFirstChild() const { return (JSUTree<T> *)this->getFirstLink(); }
|
||||
JSUTree<T> *getLastChild() const { return (JSUTree<T> *)this->getLast(); }
|
||||
JSUTree<T> *getNextChild() const { return (JSUTree<T> *)this->mNext; }
|
||||
JSUTree<T> *getPrevChild() const { return (JSUTree<T> *)this->getPrev(); }
|
||||
u32 getNumChildren() const { return this->mLinkCount; }
|
||||
T *getObject() const { return (T *)this->mData; }
|
||||
JSUTree<T> *getParent() const { return (JSUTree<T> *)this->mPtrList; }
|
||||
JSUTree<T>* getEndChild() const {
|
||||
return nullptr;
|
||||
}
|
||||
JSUTree<T>* getFirstChild() const {
|
||||
return (JSUTree<T>*)this->getFirstLink();
|
||||
}
|
||||
JSUTree<T>* getLastChild() const {
|
||||
return (JSUTree<T>*)this->getLast();
|
||||
}
|
||||
JSUTree<T>* getNextChild() const {
|
||||
return (JSUTree<T>*)this->mNext;
|
||||
}
|
||||
JSUTree<T>* getPrevChild() const {
|
||||
return (JSUTree<T>*)this->getPrev();
|
||||
}
|
||||
u32 getNumChildren() const {
|
||||
return this->mLinkCount;
|
||||
}
|
||||
T* getObject() const {
|
||||
return (T*)this->mData;
|
||||
}
|
||||
JSUTree<T>* getParent() const {
|
||||
return (JSUTree<T>*)this->mPtrList;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class JSUTreeIterator
|
||||
{
|
||||
public:
|
||||
JSUTreeIterator() : mTree(nullptr) {}
|
||||
JSUTreeIterator(JSUTree<T> *tree) : mTree(tree) {}
|
||||
template <typename T> class JSUTreeIterator {
|
||||
public:
|
||||
JSUTreeIterator() : mTree(nullptr) {
|
||||
}
|
||||
JSUTreeIterator(JSUTree<T>* tree) : mTree(tree) {
|
||||
}
|
||||
|
||||
JSUTreeIterator<T> &operator=(JSUTree<T> *tree)
|
||||
{
|
||||
JSUTreeIterator<T>& operator=(JSUTree<T>* tree) {
|
||||
this->mTree = tree;
|
||||
return *this;
|
||||
}
|
||||
|
||||
T *getObject() const { return mTree->getObject(); }
|
||||
T* getObject() const {
|
||||
return mTree->getObject();
|
||||
}
|
||||
|
||||
bool operator==(JSUTree<T> *other) { return this->mTree == other; }
|
||||
bool operator==(JSUTree<T>* other) {
|
||||
return this->mTree == other;
|
||||
}
|
||||
|
||||
bool operator!=(const JSUTree<T> *other) const { return this->mTree != other; }
|
||||
bool operator!=(const JSUTree<T>* other) const {
|
||||
return this->mTree != other;
|
||||
}
|
||||
|
||||
JSUTreeIterator<T> operator++(int)
|
||||
{
|
||||
JSUTreeIterator<T> operator++(int) {
|
||||
JSUTreeIterator<T> prev = *this;
|
||||
this->mTree = this->mTree->getNextChild();
|
||||
return prev;
|
||||
}
|
||||
|
||||
JSUTreeIterator<T> &operator++()
|
||||
{
|
||||
JSUTreeIterator<T>& 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<T> *mTree;
|
||||
private:
|
||||
JSUTree<T>* mTree;
|
||||
};
|
||||
|
||||
#endif /* JSULIST_H */
|
||||
|
||||
@@ -7,20 +7,41 @@
|
||||
|
||||
#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() {
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -3,6 +3,6 @@
|
||||
|
||||
#include "JSystem/JKernel/JKRAram.h"
|
||||
#include "JSystem/JMacro.h"
|
||||
//#include "JSystem/JUtility/JUTException.h"
|
||||
#include "JSystem/JUtility/JUTException.h"
|
||||
|
||||
#endif
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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 : public 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,122 +31,143 @@ 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;
|
||||
}
|
||||
|
||||
void scrollToLastLine() { scroll(mMaxLines); }
|
||||
void scrollToFirstLine() { scroll(-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
|
||||
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
|
||||
int _64; // _64
|
||||
bool mIsVisible; // _68
|
||||
bool _69; // _69
|
||||
bool _6A; // _6A
|
||||
bool _6B; // _6B
|
||||
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<JUTConsole, -24> 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);
|
||||
|
||||
@@ -2,13 +2,68 @@
|
||||
#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
|
||||
};
|
||||
|
||||
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, ...);
|
||||
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
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
#ifndef _JSYSTEM_JUT_JUTDIRECTFILE_H
|
||||
#define _JSYSTEM_JUT_JUTDIRECTFILE_H
|
||||
|
||||
#include <dolphin/dvd.h>
|
||||
#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
|
||||
@@ -2,61 +2,55 @@
|
||||
#define JUTDIRECTPRINT_H
|
||||
|
||||
#include "types.h"
|
||||
// #include "va_args.h"
|
||||
#include "JSystem/JUtility/TColor.h"
|
||||
#include "libc/stdarg.h"
|
||||
|
||||
#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 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 );
|
||||
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*, ...);
|
||||
|
||||
// Inline/Unused
|
||||
void printSub(u16, u16, const char *, va_list *, bool);
|
||||
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; }
|
||||
JUtility::TColor getCharColor() const { return mCharColor; }
|
||||
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, aligned width?
|
||||
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
|
||||
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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -0,0 +1,146 @@
|
||||
#ifndef _JSYSTEM_JUT_JUTEXCEPTION_H
|
||||
#define _JSYSTEM_JUT_JUTEXCEPTION_H
|
||||
|
||||
#include <dolphin/os.h>
|
||||
#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)(OSError error, OSContext* context, u32 dsisr, u32 dar);
|
||||
|
||||
enum ExPrintFlags {
|
||||
EXPRINTFLAG_GPR = 0x1,
|
||||
EXPRINTFLAG_GPRMap = 0x2,
|
||||
EXPRINTFLAG_Float = 0x4,
|
||||
EXPRINTFLAG_Stack = 0x8,
|
||||
EXPRINTFLAG_All = 0xFF,
|
||||
};
|
||||
|
||||
/**
|
||||
* @size{0xA4}
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
char* mFileName; // _00
|
||||
JSULink<JUTExMapFile> 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;
|
||||
static 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[16];
|
||||
static JSUList<JUTExMapFile> 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
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,44 @@
|
||||
#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);
|
||||
|
||||
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
|
||||
JUtility::TColor mColor; // _10 - color of fade
|
||||
JGeometry::TBox2f mViewBox; // _14 - ortho box to render within
|
||||
int mEStatus; // _24 - ???
|
||||
EStatus _28; // _28 - ???
|
||||
};
|
||||
|
||||
#endif
|
||||
+175
-144
@@ -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<const BlockHeader *>(reinterpret_cast<const u8 *>(this) + this->mSize); }
|
||||
inline static void advance(const BlockHeader **iterator)
|
||||
{
|
||||
*iterator = reinterpret_cast<const BlockHeader *>(reinterpret_cast<const u8 *>(*iterator) + (*iterator)->mSize);
|
||||
struct BlockHeader {
|
||||
const BlockHeader* getNext() const {
|
||||
return reinterpret_cast<const BlockHeader*>(reinterpret_cast<const u8*>(this) + this->mSize);
|
||||
}
|
||||
inline static void advance(const BlockHeader** iterator) {
|
||||
*iterator = reinterpret_cast<const BlockHeader*>(reinterpret_cast<const u8*>(*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
|
||||
};
|
||||
|
||||
@@ -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);
|
||||
@@ -93,7 +68,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();
|
||||
@@ -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<JUTGamePad> 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<JUTGamePad> mLink; // _7C
|
||||
CButton mButtons; // _18
|
||||
CStick mMainStick; // _48
|
||||
CStick mSubStick; // _58
|
||||
CRumble mRumble; // _68
|
||||
s16 mPortNum; // _78
|
||||
s8 mErrorStatus; // _7A
|
||||
JSULink<JUTGamePad> mLink; // _7C
|
||||
JUTGamePadRecordBase* mPadRecord;
|
||||
JUTGamePadRecordBase* mPadReplay;
|
||||
u32 _94;
|
||||
C3ButtonReset mButtonReset; // _98
|
||||
OSTime mResetTime; // _A0
|
||||
C3ButtonReset mButtonReset; // _98
|
||||
OSTime mResetTime; // _A0
|
||||
};
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
#ifndef _JSYSTEM_JUT_JUTGRAPHFIFO_H
|
||||
#define _JSYSTEM_JUT_JUTGRAPHFIFO_H
|
||||
|
||||
#include "types.h"
|
||||
#include <dolphin/gx.h>
|
||||
|
||||
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
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -8,55 +8,73 @@
|
||||
#include "dolphin/vi.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
/**
|
||||
* @size{0x58}
|
||||
*/
|
||||
|
||||
typedef u8 (*Pattern)[2];
|
||||
|
||||
struct JUTVideo
|
||||
{
|
||||
JUTVideo(const _GXRenderModeObj *);
|
||||
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();
|
||||
|
||||
u16 getEfbHeight() const { return mRenderModeObj->efbHeight; }
|
||||
u16 getFbWidth() const { return 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; }
|
||||
u16 getXfbHeight() const { return mRenderModeObj->xfbHeight; }
|
||||
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 *);
|
||||
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
|
||||
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
|
||||
@@ -71,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();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
#ifndef _JSYSTEM_JUT_JUTXFB_H
|
||||
#define _JSYSTEM_JUT_JUTXFB_H
|
||||
|
||||
#include <dolphin/gx.h>
|
||||
#include <JSystem/JKernel/JKRHeap.h>
|
||||
#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
|
||||
@@ -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
|
||||
|
||||
|
||||
+37
-34
@@ -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
|
||||
#endif
|
||||
|
||||
@@ -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 */
|
||||
@@ -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 <values.h>
|
||||
* (one may replace the following line by "#include <values.h>")
|
||||
*/
|
||||
|
||||
#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
|
||||
@@ -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
|
||||
|
||||
@@ -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, ...);
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -26,10 +26,13 @@ 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_MAX (OS_ERROR_PROTECTION + 1)
|
||||
|
||||
OSErrorHandler OSSetErrorHandler(OSError error, OSErrorHandler handler);
|
||||
|
||||
extern OSErrorHandler __OSErrorTable[OS_ERROR_MAX];
|
||||
extern u32 __OSFpscrEnableBits;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -69,11 +69,21 @@ 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();
|
||||
|
||||
VIRetraceCallback VISetPreRetraceCallback(VIRetraceCallback callback);
|
||||
VIRetraceCallback VISetPostRetraceCallback(VIRetraceCallback callback);
|
||||
void* VIGetNextFrameBuffer();
|
||||
void* VIGetCurrentFrameBuffer();
|
||||
void VISetNextFrameBuffer(void* fb);
|
||||
|
||||
void VIInit();
|
||||
void VIFlush();
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -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_
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -0,0 +1,195 @@
|
||||
#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;
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
#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 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) {
|
||||
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) {
|
||||
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) {
|
||||
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) {
|
||||
J2DDrawFrame(JGeometry::TBox2f(l, t, l + x, t + 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);
|
||||
}
|
||||
@@ -0,0 +1,532 @@
|
||||
#include <libc/string.h>
|
||||
#include <dolphin/vi.h>
|
||||
#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<JFWAlarm*>(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");
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
#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 = 0x24F8;
|
||||
|
||||
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() {
|
||||
JUT_ASSERT(rootHeap == 0);
|
||||
OSInit();
|
||||
DVDInit();
|
||||
rootHeap = JKRExpHeap::createRoot(CSetUpParam::maxStdHeaps, false);
|
||||
systemHeap = JKRExpHeap::create(CSetUpParam::sysHeapSize, rootHeap, false);
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
}
|
||||
@@ -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(u<size()); // #line 362
|
||||
JGADGET_EXITWARN(u<size());
|
||||
const TLinkListNode* pIt = it.p_;
|
||||
JUT_ASSERT(pIt!=0); // #line 364
|
||||
#line 365
|
||||
JUT_ASSERT(pIt!=0);
|
||||
JGADGET_EXITWARN(pIt->pNext_->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;
|
||||
|
||||
@@ -11,18 +11,17 @@ JSUList<JKRAMCommand> 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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<JKRAramBlock>* prev = this->mLink.getPrev();
|
||||
JSUList<JKRAramBlock>* list = this->mLink.getList();
|
||||
JSULink<JKRAramBlock>* prev = this->mLink.getPrev();
|
||||
JSUList<JKRAramBlock>* 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;
|
||||
}
|
||||
|
||||
@@ -5,165 +5,154 @@
|
||||
JSUList<JKRAramBlock> 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<JKRAramBlock> it = sAramList.getFirst();
|
||||
it != sAramList.getEnd();) {
|
||||
delete (it++).getObject();
|
||||
}
|
||||
for (JSUListIterator<JKRAramBlock> 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<JKRAramBlock> 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<JKRAramBlock> 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<JKRAramBlock> it = sAramList.getLast();
|
||||
it != sAramList.getEnd(); it--) {
|
||||
JKRAramBlock* n_block = it.getObject();
|
||||
for (JSUListIterator<JKRAramBlock> 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<JKRAramBlock> 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<JKRAramBlock> 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<JKRAramBlock> it = sAramList.getFirst();
|
||||
it != sAramList.getEnd(); it++) {
|
||||
if (it->mFreeSize > max_free) {
|
||||
max_free = it->mFreeSize;
|
||||
for (JSUListIterator<JKRAramBlock> 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<JKRAramBlock> it = sAramList.getFirst();
|
||||
it != sAramList.getEnd(); it++) {
|
||||
total_free += it->mFreeSize;
|
||||
}
|
||||
for (JSUListIterator<JKRAramBlock> 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<JKRAramBlock> 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<JKRAramBlock> 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;
|
||||
}
|
||||
|
||||
@@ -12,146 +12,132 @@
|
||||
JSUList<JKRAMCommand> 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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<JKRAramStreamCommand*>(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<JKRAramStreamCommand*>(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;
|
||||
}
|
||||
|
||||
@@ -7,42 +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(const char* p1, JKRArchive::EMountMode mountMode)
|
||||
{
|
||||
// UNUSED FUNCTION
|
||||
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;
|
||||
@@ -50,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];
|
||||
}
|
||||
|
||||
@@ -75,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;
|
||||
@@ -90,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;
|
||||
}
|
||||
}
|
||||
@@ -114,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;
|
||||
@@ -141,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;
|
||||
}
|
||||
}
|
||||
@@ -166,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;
|
||||
}
|
||||
}
|
||||
@@ -202,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++;
|
||||
@@ -220,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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,329 +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();
|
||||
}
|
||||
|
||||
JSUList<JKRFileLoader>& volumeList = JKRArchive::sVolumeList;
|
||||
JSUListIterator<JKRFileLoader> iterator;
|
||||
for (iterator = volumeList.getFirst(); iterator != volumeList.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<JKRFileLoader> 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) {
|
||||
JSUList<JKRFileLoader>& volumeList = JKRArchive::sVolumeList;
|
||||
JSUListIterator<JKRFileLoader> iterator;
|
||||
for (iterator = volumeList.getFirst(); iterator != volumeList.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<JKRFileLoader> 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<JKRFileLoader>* 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<JKRFileLoader>* 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<JKRArchive*>(this), dirEntry->mFirstIdx, dirEntry->mNum);
|
||||
}
|
||||
return nullptr;
|
||||
if (dirEntry) {
|
||||
return new (JKRGetSystemHeap(), 0)
|
||||
JKRArcFinder(const_cast<JKRArchive*>(this), dirEntry->mFirstIdx, dirEntry->mNum);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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<JKRDecompCommand*>(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<JKRDecompCommand*>(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() {
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,193 +14,181 @@ JSUList<JKRADCommand> 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -2,115 +2,117 @@
|
||||
|
||||
JSUList<JKRDvdFile> 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<JKRDvdFileInfo*>(info)->mFile->mDvdMessageQueue,
|
||||
(OSMessage)result, OS_MESSAGE_NOBLOCK);
|
||||
OSSendMessage(&static_cast<JKRDvdFileInfo*>(info)->mFile->mDvdMessageQueue, (OSMessage)result, OS_MESSAGE_NOBLOCK);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<char*>(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;
|
||||
|
||||
@@ -5,55 +5,46 @@
|
||||
JSUList<JKRFileLoader> 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<JKRFileLoader>& volumeList = getVolumeList();
|
||||
JSUListIterator<JKRFileLoader> 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<JKRFileLoader>& volumeList = getVolumeList();
|
||||
JSUListIterator<JKRFileLoader> 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<JKRFileLoader>& volumeList = getVolumeList();
|
||||
JSUListIterator<JKRFileLoader> 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<JKRFileLoader>& volumeList = sVolumeList;
|
||||
JSUListIterator<JKRFileLoader> 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--;
|
||||
|
||||
@@ -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<JKRHeap>* 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<JKRDisposer> 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<JKRHeap> iterator(mChildTree.getFirstChild()); iterator != mChildTree.getEndChild(); ++iterator)
|
||||
{
|
||||
JKRHeap* JKRHeap::find(void* memory) const {
|
||||
if ((mStart <= memory) && (memory <= mEnd)) {
|
||||
if (mChildTree.getNumChildren() != 0) {
|
||||
for (JSUTreeIterator<JKRHeap> 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<JKRHeap> iterator(mChildTree.getFirstChild()); iterator != mChildTree.getEndChild(); ++iterator)
|
||||
{
|
||||
JKRHeap* JKRHeap::findAllHeap(void* memory) const {
|
||||
if (mChildTree.getNumChildren() != 0) {
|
||||
for (JSUTreeIterator<JKRHeap> 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<JKRHeap*>(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<JKRDisposer> last_iterator;
|
||||
JSUListIterator<JKRDisposer> next_iterator;
|
||||
JSUListIterator<JKRDisposer> 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<JKRDisposer> 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<JKRHeap> 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());
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -5,110 +5,95 @@
|
||||
|
||||
JSUList<JKRThread> 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<JKRThread*>(thread)->run();
|
||||
return static_cast<JKRThread*>(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;
|
||||
}
|
||||
|
||||
@@ -1,51 +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) {
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,158 @@
|
||||
#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;
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
#include <dolphin/pad.h>
|
||||
#include <dolphin/vi.h>
|
||||
#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;
|
||||
} // namespace
|
||||
|
||||
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;
|
||||
}
|
||||
} // namespace JUTAssertion
|
||||
@@ -0,0 +1,478 @@
|
||||
#include <MSL_C/printf.h>
|
||||
|
||||
#include <dolphin/os.h>
|
||||
#include <dolphin/vi.h>
|
||||
#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);
|
||||
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<JUTConsole, -24>::const_iterator it = ((const JUTConsoleManager*)this)->soLink_.begin();
|
||||
JGadget::TLinkList<JUTConsole, -24>::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);
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
#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<const char*>(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);
|
||||
}
|
||||
@@ -0,0 +1,161 @@
|
||||
#include <dolphin/os.h>
|
||||
#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<char*>(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;
|
||||
}
|
||||
@@ -0,0 +1,177 @@
|
||||
#include <dolphin/os.h>
|
||||
|
||||
#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);
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user