More CGX matches

This commit is contained in:
Luke Street 2022-08-30 01:12:32 -04:00
parent b28e24862b
commit 6fbaa00f07
5 changed files with 75 additions and 23 deletions

View File

@ -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;

View File

@ -1,9 +1,8 @@
#ifndef DOLPHIN_GX_H
#define DOLPHIN_GX_H
#ifdef __cplusplus
extern "C" {
#endif
#include <dolphin/gx/GXEnum.h>
#include <dolphin/gx/GXStruct.h>
#include <dolphin/gx/GXBump.h>
#include <dolphin/gx/GXCommandList.h>
@ -19,14 +18,9 @@ extern "C" {
#include <dolphin/gx/GXManage.h>
#include <dolphin/gx/GXPerf.h>
#include <dolphin/gx/GXPixel.h>
#include <dolphin/gx/GXStruct.h>
#include <dolphin/gx/GXTev.h>
#include <dolphin/gx/GXTexture.h>
#include <dolphin/gx/GXTransform.h>
#include <dolphin/gx/GXVert.h>
#ifdef __cplusplus
}
#endif
#endif

View File

@ -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);
}
}
}
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
}

View File

@ -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)

22
tools/dol_diff.py Normal file
View File

@ -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))