mirror of
https://github.com/doldecomp/sms.git
synced 2026-11-07 09:06:00 -10:00
Match gd (thx Taka)
This commit is contained in:
1 parent
dc22a283e3
commit
f981a46f57
6 files changed
+117
-102
No files matched your search
+2
-2
@@ -726,9 +726,9 @@ config.libs = [
|
||||
]),
|
||||
DolphinLib("gd", [
|
||||
Object(Matching, "dolphin/gd/GDBase.c"),
|
||||
Object(NonMatching, "dolphin/gd/GDGeometry.c"),
|
||||
Object(Matching, "dolphin/gd/GDGeometry.c"),
|
||||
Object(Matching, "dolphin/gd/GDLight.c"),
|
||||
Object(NonMatching, "dolphin/gd/GDPixel.c"),
|
||||
Object(Matching, "dolphin/gd/GDPixel.c"),
|
||||
Object(Matching, "dolphin/gd/GDTev.c"),
|
||||
Object(Matching, "dolphin/gd/GDTransform.c"),
|
||||
]),
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define _DOLPHIN_GD_BASE_H
|
||||
|
||||
#include <dolphin/types.h>
|
||||
#include <dolphin/gx/GXEnum.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -25,6 +26,77 @@ void GDOverflowed(void);
|
||||
void GDSetOverflowCallback(GDOverflowCb callback);
|
||||
void GDGetOverflowCallback();
|
||||
|
||||
// NOTE: yes, these were 100% "public" because JSystem uses them directly
|
||||
|
||||
inline static void GDOverflowCheck(u32 size)
|
||||
{
|
||||
if (__GDCurrentDL->ptr + size > __GDCurrentDL->top) {
|
||||
GDOverflowed();
|
||||
}
|
||||
}
|
||||
|
||||
inline static void __GDWrite(u8 data) { *__GDCurrentDL->ptr++ = data; }
|
||||
|
||||
inline static void GDWrite_u8(u8 data)
|
||||
{
|
||||
GDOverflowCheck(sizeof(u8));
|
||||
__GDWrite(data & 0xFF);
|
||||
}
|
||||
|
||||
inline static void GDWrite_u16(u16 data)
|
||||
{
|
||||
GDOverflowCheck(sizeof(u16));
|
||||
__GDWrite(data >> 8);
|
||||
__GDWrite(data & 0xFF);
|
||||
}
|
||||
|
||||
inline static void GDWrite_u32(u32 data)
|
||||
{
|
||||
GDOverflowCheck(sizeof(u32));
|
||||
__GDWrite(data >> 24);
|
||||
__GDWrite((data >> 16) & 0xFF);
|
||||
__GDWrite((data >> 8) & 0xFF);
|
||||
__GDWrite(data & 0xFF);
|
||||
}
|
||||
|
||||
inline static void GDWrite_f32(float data)
|
||||
{
|
||||
union {
|
||||
float f;
|
||||
u32 u;
|
||||
} fid;
|
||||
fid.f = data;
|
||||
GDWrite_u32(fid.u);
|
||||
}
|
||||
|
||||
inline static void GDWriteXFCmdHdr(u16 addr, u8 len)
|
||||
{
|
||||
GDWrite_u8(GX_CMD_LOAD_XF_REG);
|
||||
GDWrite_u16(len - 1);
|
||||
GDWrite_u16(addr);
|
||||
}
|
||||
|
||||
inline static void GDWriteXFCmd(u16 addr, u32 val)
|
||||
{
|
||||
GDWrite_u8(GX_CMD_LOAD_XF_REG);
|
||||
GDWrite_u16(0);
|
||||
GDWrite_u16(addr);
|
||||
GDWrite_u32(val);
|
||||
}
|
||||
|
||||
inline static void GDWriteCPCmd(u8 addr, u32 val)
|
||||
{
|
||||
GDWrite_u8(GX_CMD_LOAD_CP_REG);
|
||||
GDWrite_u8(addr);
|
||||
GDWrite_u32(val);
|
||||
}
|
||||
|
||||
inline static void GDWriteBPCmd(u32 regval)
|
||||
{
|
||||
GDWrite_u8(GX_CMD_LOAD_BP_REG);
|
||||
GDWrite_u32(regval);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif // ifdef __cplusplus
|
||||
|
||||
@@ -815,6 +815,17 @@ typedef enum _GXVCachePerf {
|
||||
GX_VC_ALL = 15,
|
||||
} GXVCachePerf;
|
||||
|
||||
typedef enum _GXCommand {
|
||||
GX_CMD_LOAD_INDX_A = 0x20,
|
||||
GX_CMD_LOAD_INDX_B = 0x28,
|
||||
GX_CMD_LOAD_INDX_C = 0x30,
|
||||
GX_CMD_LOAD_INDX_D = 0x38,
|
||||
|
||||
GX_CMD_LOAD_CP_REG = 0x08,
|
||||
GX_CMD_LOAD_XF_REG = 0x10,
|
||||
GX_CMD_LOAD_BP_REG = 0x61,
|
||||
} GXCommand;
|
||||
|
||||
typedef enum _GXClipMode {
|
||||
GX_CLIP_ENABLE = 0,
|
||||
GX_CLIP_DISABLE = 1,
|
||||
|
||||
@@ -350,13 +350,13 @@ void GDSetGenMode2(u8 nTexGens, u8 nChans, u8 nTevs, u8 nInds, GXCullMode cm)
|
||||
GDWriteBPCmd(0xfe07fc3f);
|
||||
// clang-format off
|
||||
GDWriteBPCmd(
|
||||
nTexGens |
|
||||
nChans << 4 |
|
||||
(nTevs - 1) << 10 |
|
||||
cm2hw[cm] << 14 |
|
||||
nInds << 16
|
||||
((u32)(nTexGens)) |
|
||||
((u32)(nChans)) << 4 |
|
||||
((u32)(nTevs - 1)) << 10 |
|
||||
((u32)(cm2hw[cm])) << 14 |
|
||||
((u32)(nInds)) << 16
|
||||
);
|
||||
// clang-format on
|
||||
GDWriteXFCmd(0x1009, (u8)(nChans & 0xff));
|
||||
GDWriteXFCmd(0x103f, (u8)(nTexGens & 0xff));
|
||||
GDWriteXFCmd(0x1009, nChans);
|
||||
GDWriteXFCmd(0x103f, nTexGens);
|
||||
}
|
||||
+25
-25
@@ -7,13 +7,13 @@ void GDSetBlendMode(GXBlendMode type, GXBlendFactor src_factor,
|
||||
GDWriteBPCmd(0xfe001fe3);
|
||||
// clang-format off
|
||||
GDWriteBPCmd(
|
||||
((type == GX_BM_BLEND) || (type == GX_BM_SUBTRACT))
|
||||
| (type == GX_BM_LOGIC) << 1
|
||||
| dst_factor << 5
|
||||
| src_factor << 8
|
||||
| (type == GX_BM_SUBTRACT) << 11
|
||||
| logic_op << 12
|
||||
| 0x41 << 24
|
||||
((u32)(type == GX_BM_BLEND || type == GX_BM_SUBTRACT)) |
|
||||
((u32)(type == GX_BM_LOGIC)) << 1 |
|
||||
((u32)dst_factor) << 5 |
|
||||
((u32)src_factor) << 8 |
|
||||
((u32)(type == GX_BM_SUBTRACT)) << 11 |
|
||||
((u32)logic_op) << 12 |
|
||||
((u32)0x41) << 24
|
||||
);
|
||||
// clang-format on
|
||||
}
|
||||
@@ -25,16 +25,16 @@ void GDSetBlendModeEtc(GXBlendMode type, GXBlendFactor src_factor,
|
||||
{
|
||||
// clang-format off
|
||||
GDWriteBPCmd(
|
||||
((type == GX_BM_BLEND) || (type == GX_BM_SUBTRACT))
|
||||
| (type == GX_BM_LOGIC) << 1
|
||||
| dither_enable << 2
|
||||
| color_update_enable << 3
|
||||
| alpha_update_enable << 4
|
||||
| dst_factor << 5
|
||||
| src_factor << 8
|
||||
| (type == GX_BM_SUBTRACT) << 11
|
||||
| logic_op << 12
|
||||
| 0x41 << 24
|
||||
((u32)(type == GX_BM_BLEND || type == GX_BM_SUBTRACT)) |
|
||||
((u32)(type == GX_BM_LOGIC)) << 1 |
|
||||
((u32)dither_enable) << 2 |
|
||||
((u32)color_update_enable) << 3 |
|
||||
((u32)alpha_update_enable) << 4 |
|
||||
((u32)dst_factor) << 5 |
|
||||
((u32)src_factor) << 8 |
|
||||
((u32)(type == GX_BM_SUBTRACT)) << 11 |
|
||||
((u32)logic_op) << 12 |
|
||||
((u32)0x41) << 24
|
||||
);
|
||||
// clang-format on
|
||||
}
|
||||
@@ -43,10 +43,10 @@ void GDSetZMode(u8 compare_enable, GXCompare func, u8 update_enable)
|
||||
{
|
||||
// clang-format off
|
||||
GDWriteBPCmd(
|
||||
compare_enable
|
||||
| func << 1
|
||||
| update_enable << 4
|
||||
| 1u << 30
|
||||
((u32)compare_enable) |
|
||||
((u32)func) << 1 |
|
||||
((u32)update_enable) << 4 |
|
||||
((u32)1) << 30
|
||||
);
|
||||
// clang-format on
|
||||
}
|
||||
@@ -55,10 +55,10 @@ void GDSetDstAlpha(u8 enable, u8 alpha)
|
||||
{
|
||||
// clang-format off
|
||||
GDWriteBPCmd(
|
||||
alpha
|
||||
| enable << 8
|
||||
| 1 << 25
|
||||
| 1 << 30
|
||||
((u32)alpha) |
|
||||
((u32)enable) << 8 |
|
||||
((u32)1) << 25 |
|
||||
((u32)1) << 30
|
||||
);
|
||||
// clang-format on
|
||||
}
|
||||
@@ -10,74 +10,6 @@
|
||||
|
||||
extern void GDOverflowed();
|
||||
|
||||
inline static void GDOverflowCheck(u32 size)
|
||||
{
|
||||
if (__GDCurrentDL->ptr + size > __GDCurrentDL->top) {
|
||||
GDOverflowed();
|
||||
}
|
||||
}
|
||||
|
||||
inline static void __GDWrite(u8 data) { *__GDCurrentDL->ptr++ = data; }
|
||||
|
||||
inline static void GDWrite_u8(u8 data)
|
||||
{
|
||||
GDOverflowCheck(sizeof(u8));
|
||||
__GDWrite(data & 0xFF);
|
||||
}
|
||||
|
||||
inline static void GDWrite_u16(u16 data)
|
||||
{
|
||||
GDOverflowCheck(sizeof(u16));
|
||||
__GDWrite(data >> 8);
|
||||
__GDWrite(data & 0xFF);
|
||||
}
|
||||
|
||||
inline static void GDWrite_u32(u32 data)
|
||||
{
|
||||
GDOverflowCheck(sizeof(u32));
|
||||
__GDWrite(data >> 24);
|
||||
__GDWrite((data >> 16) & 0xFF);
|
||||
__GDWrite((data >> 8) & 0xFF);
|
||||
__GDWrite(data & 0xFF);
|
||||
}
|
||||
|
||||
inline static void GDWrite_f32(float data)
|
||||
{
|
||||
union {
|
||||
float f;
|
||||
u32 u;
|
||||
} fid;
|
||||
fid.f = data;
|
||||
GDWrite_u32(fid.u);
|
||||
}
|
||||
|
||||
inline static void GDWriteXFCmdHdr(u16 addr, u8 len)
|
||||
{
|
||||
GDWrite_u8(16);
|
||||
GDWrite_u16(len - 1);
|
||||
GDWrite_u16(addr);
|
||||
}
|
||||
inline static void GDWriteXFCmd(u16 addr, u32 val)
|
||||
{
|
||||
GDWrite_u8(0x10);
|
||||
GDWrite_u16(0);
|
||||
GDWrite_u16(addr);
|
||||
GDWrite_u32(val);
|
||||
}
|
||||
|
||||
inline static void GDWriteCPCmd(u8 addr, u32 val)
|
||||
{
|
||||
GDWrite_u8(8);
|
||||
GDWrite_u8(addr);
|
||||
GDWrite_u32(val);
|
||||
}
|
||||
|
||||
inline static void GDWriteBPCmd(u32 regval)
|
||||
{
|
||||
GDWrite_u8(0x61);
|
||||
GDWrite_u32(regval);
|
||||
}
|
||||
|
||||
inline static u16 __GDLightID2Index(GXLightID id)
|
||||
{
|
||||
u16 idx;
|
||||
|
||||
Reference in new issue
Block a user