diff --git a/include/Kyoto/Graphics/CGX.hpp b/include/Kyoto/Graphics/CGX.hpp index 1aed0ba5..43d2c74a 100644 --- a/include/Kyoto/Graphics/CGX.hpp +++ b/include/Kyoto/Graphics/CGX.hpp @@ -14,8 +14,8 @@ public: u32 xc_alphaOps; u32 x10_indFlags; u32 x14_tevOrderFlags; - u32 x18_kColorSel; - u32 x19_kAlphaSel; + u8 x18_kColorSel; + u8 x19_kAlphaSel; STevState(); }; @@ -83,6 +83,11 @@ public: GXAttnFn attnFn); static void SetTevKColor(GXTevKColorID id, const GXColor& color); static void SetTevColorIn(GXTevStageID stageId, GXTevColorArg a, GXTevColorArg b, GXTevColorArg c, GXTevColorArg d); + static void SetTevAlphaIn(GXTevStageID stageId, GXTevAlphaArg a, GXTevAlphaArg b, GXTevAlphaArg c, GXTevAlphaArg d); + static void SetTevColorOp(GXTevStageID stageId, GXTevOp op, GXTevBias bias, GXTevScale scale, GXBool clamp, GXTevRegID outReg); + static void SetTevColorOp_Compressed(GXTevStageID stageId, u32 flags); + static void SetTevAlphaOp(GXTevStageID stageId, GXTevOp op, GXTevBias bias, GXTevScale scale, GXBool clamp, GXTevRegID outReg); + static void SetTevAlphaOp_Compressed(GXTevStageID stageId, u32 flags); static GXColor GetChanAmbColor(EChannelId channel); @@ -92,9 +97,7 @@ public: static inline void CopyGXColor(GXColor& dst, const GXColor& src) { *reinterpret_cast< u32* >(&dst) = *reinterpret_cast< const u32* >(&src); } - static inline u32 MaskAndShiftLeft(u32 a, u32 b, u32 s) { - return (a & b) << s; - } + static inline u32 MaskAndShiftLeft(u32 a, u32 b, u32 s) { return (a & b) << s; } private: static SGXState sGXState; diff --git a/include/dolphin/gx.h b/include/dolphin/gx.h index 91838c20..f3ab630a 100644 --- a/include/dolphin/gx.h +++ b/include/dolphin/gx.h @@ -1,9 +1,8 @@ #ifndef DOLPHIN_GX_H #define DOLPHIN_GX_H -#ifdef __cplusplus -extern "C" { -#endif +#include +#include #include #include @@ -19,14 +18,9 @@ extern "C" { #include #include #include -#include #include #include #include #include -#ifdef __cplusplus -} -#endif - #endif diff --git a/src/Kyoto/Graphics/CGX.cpp b/src/Kyoto/Graphics/CGX.cpp index 21c8e586..adddd605 100644 --- a/src/Kyoto/Graphics/CGX.cpp +++ b/src/Kyoto/Graphics/CGX.cpp @@ -59,15 +59,48 @@ void CGX::SetTevKColor(GXTevKColorID id, const GXColor& color) { } } -// TODO non-matching void CGX::SetTevColorIn(GXTevStageID stageId, GXTevColorArg a, GXTevColorArg b, GXTevColorArg c, GXTevColorArg d) { - u32 ma = MaskAndShiftLeft(a, 0x1F, 0); - u32 mb = MaskAndShiftLeft(b, 0x1F, 5); - u32 mc = MaskAndShiftLeft(c, 0x1F, 10); - u32 md = MaskAndShiftLeft(d, 0x1F, 15); - u32 flags = ma | mb | mc | md; - if (flags != sGXState.x68_tevStates[stageId].x0_colorInArgs) { - sGXState.x68_tevStates[stageId].x0_colorInArgs = flags; + u32 flags = MaskAndShiftLeft(a, 0x1F, 0) | MaskAndShiftLeft(b, 0x1F, 5) | MaskAndShiftLeft(c, 0x1F, 10) | MaskAndShiftLeft(d, 0x1F, 15); + STevState& state = sGXState.x68_tevStates[stageId]; + if (flags != state.x0_colorInArgs) { + state.x0_colorInArgs = flags; GXSetTevColorIn(stageId, a, b, c, d); } -} \ No newline at end of file +} + +void CGX::SetTevAlphaIn(GXTevStageID stageId, GXTevAlphaArg a, GXTevAlphaArg b, GXTevAlphaArg c, GXTevAlphaArg d) { + u32 flags = MaskAndShiftLeft(a, 0x1F, 0) | MaskAndShiftLeft(b, 0x1F, 5) | MaskAndShiftLeft(c, 0x1F, 10) | MaskAndShiftLeft(d, 0x1F, 15); + STevState& state = sGXState.x68_tevStates[stageId]; + if (flags != state.x4_alphaInArgs) { + state.x4_alphaInArgs = flags; + GXSetTevAlphaIn(stageId, a, b, c, d); + } +} + +void CGX::SetTevColorOp(GXTevStageID stageId, GXTevOp op, GXTevBias bias, GXTevScale scale, GXBool clamp, GXTevRegID outReg) { + u32 flags = MaskAndShiftLeft(op, 0xF, 0) | MaskAndShiftLeft(bias, 3, 4) | MaskAndShiftLeft(scale, 3, 6) | MaskAndShiftLeft(clamp, 1, 8) | + MaskAndShiftLeft(outReg, 3, 9); + STevState& state = sGXState.x68_tevStates[stageId]; + if (flags != state.x8_colorOps) { + state.x8_colorOps = flags; + GXSetTevColorOp(stageId, op, bias, scale, clamp, outReg); + } +} + +void CGX::SetTevColorOp_Compressed(GXTevStageID stageId, u32 flags) { + // TODO +} + +void CGX::SetTevAlphaOp(GXTevStageID stageId, GXTevOp op, GXTevBias bias, GXTevScale scale, GXBool clamp, GXTevRegID outReg) { + u32 flags = MaskAndShiftLeft(op, 0xF, 0) | MaskAndShiftLeft(bias, 3, 4) | MaskAndShiftLeft(scale, 3, 6) | MaskAndShiftLeft(clamp, 1, 8) | + MaskAndShiftLeft(outReg, 3, 9); + STevState& state = sGXState.x68_tevStates[stageId]; + if (flags != state.xc_alphaOps) { + state.xc_alphaOps = flags; + GXSetTevAlphaOp(stageId, op, bias, scale, clamp, outReg); + } +} + +void CGX::SetTevAlphaOp_Compressed(GXTevStageID stageId, u32 flags) { + // TODO +} diff --git a/tools/decompctx.py b/tools/decompctx.py index b127e4f9..e043a79c 100755 --- a/tools/decompctx.py +++ b/tools/decompctx.py @@ -27,7 +27,7 @@ def import_h_file(in_file, r_path) -> str: return import_c_file(inc_path) else: print("Failed to locate", in_file) - exit(1) + return "" def import_c_file(in_file) -> str: in_file = os.path.relpath(in_file, root_dir) diff --git a/tools/dol_diff.py b/tools/dol_diff.py new file mode 100644 index 00000000..3322e1df --- /dev/null +++ b/tools/dol_diff.py @@ -0,0 +1,22 @@ +from sys import argv + +def nextU32(f): + dat = f.read(4) + return int.from_bytes(dat, 'big') + +with open(argv[1], 'rb') as dol: + offsets = [nextU32(dol) for i in range(18)] + addresses = [nextU32(dol) for i in range(18)] + sizes = [nextU32(dol) for i in range(18)] + + target = int(argv[2], 16) + + for i in range(0, 0x18): + offset = offsets[i] + size = sizes[i] + if offset <= target < offset + size: + section = i + delta = target - offset + break + + print(hex(addresses[section] + delta))