Skip to content

Commit

Permalink
GX work
Browse files Browse the repository at this point in the history
  • Loading branch information
LagoLunatic committed Nov 7, 2024
1 parent 0492ca2 commit 04a5b59
Show file tree
Hide file tree
Showing 15 changed files with 184 additions and 93 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"search.exclude": {
"build/*/config.json": true,
"build/**/*.MAP": true,
"build/*/include/assets/**": true,
"build.ninja": true,
".ninja_*": true,
"objdiff.json": true,
Expand Down
6 changes: 3 additions & 3 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -1143,20 +1143,20 @@ def MatchingFor(*versions):
DolphinLib(
"gx",
[
Object(NonMatching, "dolphin/gx/GXInit.c"),
Object(NonMatching, "dolphin/gx/GXInit.c", extra_cflags=["-opt nopeephole"]),
Object(NonMatching, "dolphin/gx/GXFifo.c"),
Object(NonMatching, "dolphin/gx/GXAttr.c"),
Object(NonMatching, "dolphin/gx/GXMisc.c"),
Object(NonMatching, "dolphin/gx/GXGeometry.c"),
Object(NonMatching, "dolphin/gx/GXFrameBuf.c"),
Object(NonMatching, "dolphin/gx/GXLight.c"),
Object(NonMatching, "dolphin/gx/GXLight.c", extra_cflags=["-fp_contract off"]),
Object(NonMatching, "dolphin/gx/GXTexture.c"),
Object(NonMatching, "dolphin/gx/GXBump.c"),
Object(NonMatching, "dolphin/gx/GXTev.c"),
Object(NonMatching, "dolphin/gx/GXPixel.c"),
Object(NonMatching, "dolphin/gx/GXStubs.c"),
Object(NonMatching, "dolphin/gx/GXDisplayList.c"),
Object(NonMatching, "dolphin/gx/GXTransform.c"),
Object(NonMatching, "dolphin/gx/GXTransform.c", extra_cflags=["-fp_contract off"]),
Object(NonMatching, "dolphin/gx/GXPerf.c"),
],
),
Expand Down
3 changes: 2 additions & 1 deletion include/JSystem/JMath/JMath.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#ifndef JMATH_H
#define JMATH_H

#include "dolphin/mtx/mtx.h"
#include "dolphin/mtx/quat.h"
#include "math.h"

bool JMANewSinTable(u8 numBits);
void JMAEulerToQuat(s16 x, s16 y, s16 z, Quaternion* out);
Expand Down
82 changes: 82 additions & 0 deletions include/dolphin/gx/GX.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,88 @@ inline void GFWriteBPCmd(u32 x) {

inline void GXEnd() {}

#define GX_WRITE_U8(ub) \
GXFIFO.u8 = (u8)(ub)

#define GX_WRITE_U16(us) \
GXFIFO.u16 = (u16)(us)

#define GX_WRITE_U32(ui) \
GXFIFO.u32 = (u32)(ui)

#define GX_WRITE_F32(f) \
GXFIFO.f32 = (f32)(f);

#define GX_WRITE_XF_REG(addr, value) \
do { \
GX_WRITE_U8(0x10); \
GX_WRITE_U32(0x1000 + (addr)); \
GX_WRITE_U32(value); \
VERIF_XF_REG(addr, value); \
} while (0)

#if DEBUG
#define GX_WRITE_XF_REG_2(addr, value) \
do { \
u32 xfData = (value); &xfData; \
GX_WRITE_U32(value); \
VERIF_XF_REG_alt(addr, xfData); \
} while (0)
#define GX_WRITE_XF_REG_F(addr, value) \
do { \
f32 xfData = (value); \
GX_WRITE_F32(value); \
VERIF_XF_REG_alt(addr, *(u32 *)&xfData); \
} while (0)
#else
#define GX_WRITE_XF_REG_2(addr, value) \
do { \
GX_WRITE_U32(value); \
} while (0)
#define GX_WRITE_XF_REG_F(addr, value) \
do { \
GX_WRITE_F32(value); \
} while (0)
#endif

#define GX_WRITE_RAS_REG(value) \
do { \
GX_WRITE_U8(0x61); \
GX_WRITE_U32(value); \
VERIF_RAS_REG(value); \
} while (0)

#define GX_WRITE_SOME_REG2(a, b, c, addr) \
do { \
long regAddr; \
GX_WRITE_U8(a); \
GX_WRITE_U8(b); \
GX_WRITE_U32(c); \
regAddr = addr; \
if (regAddr >= 0 && regAddr < 4) { \
gx->indexBase[regAddr] = c; \
} \
} while (0)
#define GX_WRITE_SOME_REG3(a, b, c, addr) \
do { \
long regAddr; \
GX_WRITE_U8(a); \
GX_WRITE_U8(b); \
GX_WRITE_U32(c); \
regAddr = addr; \
if (regAddr >= 0 && regAddr < 4) { \
gx->indexStride[regAddr] = c; \
} \
} while (0)
#define GX_WRITE_SOME_REG4(a, b, c, addr) \
do { \
long regAddr; \
GX_WRITE_U8(a); \
GX_WRITE_U8(b); \
GX_WRITE_U32(c); \
regAddr = addr; \
} while (0)

#ifdef __cplusplus
};
#endif
Expand Down
2 changes: 1 addition & 1 deletion include/dolphin/gx/GXEnum.h
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ typedef enum _GXAnisotropy {

typedef enum _GXCITexFmt {
/* 0x8 */ GX_TF_C4 = 8,
/* 0x8 */ GX_TF_C8,
/* 0x9 */ GX_TF_C8,
/* 0xA */ GX_TF_C14X2
} GXCITexFmt;

Expand Down
14 changes: 12 additions & 2 deletions include/dolphin/gx/GXInit.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ typedef struct _GXData {
// Texture regions
/* 0x208 */ GXTexRegion TexRegions0[GX_MAX_TEXMAP];
/* 0x288 */ GXTexRegion TexRegions1[4];
/* 0x2C8 */ u32 m2C8;
/* 0x2C8 */ u32 m2CC;
/* 0x2C8 */ u32 nextTexRgn;
/* 0x2C8 */ u32 nextTexRgnCI;

// Texture lookup table regions
/* 0x2D0 */ GXTlutRegion TlutRegions[GX_MAX_TLUT_ALL];
Expand Down Expand Up @@ -140,6 +140,16 @@ extern u16* __cpReg;
extern u16* __peReg;
extern vu16* __memReg;

#define GX_GET_MEM_REG(offset) (*(vu16*)((vu16*)(__memReg) + (offset)))
#define GX_GET_CP_REG(offset) (*(vu16*)((vu16*)(__cpReg) + (offset)))
#define GX_GET_PE_REG(offset) (*(vu16*)((vu16*)(__peReg) + (offset)))
#define GX_GET_PI_REG(offset) (*(vu32*)((vu32*)(__piReg) + (offset)))

#define GX_SET_MEM_REG(offset, val) (*(vu16*)((vu16*)(__memReg) + (offset)) = val)
#define GX_SET_CP_REG(offset, val) (*(vu16*)((vu16*)(__cpReg) + (offset)) = val)
#define GX_SET_PE_REG(offset, val) (*(vu16*)((vu16*)(__peReg) + (offset)) = val)
#define GX_SET_PI_REG(offset, val) (*(vu32*)((vu32*)(__piReg) + (offset)) = val)

inline void GXSetWasteFlags() {
GXData* data = __GXData;
data->dirtyState |= GX_DIRTY_SU_TEX | GX_DIRTY_BP_MASK;
Expand Down
2 changes: 1 addition & 1 deletion include/dolphin/gx/GXTexture.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void GXSetTexCoordBias(GXTexCoordID coord, GXBool s_enable, GXBool t_enable);

void __SetSURegs();
void __GXSetSUTexRegs();
void __GXSetTmemConfig();
void __GXSetTmemConfig(u32);

#ifdef __cplusplus
};
Expand Down
2 changes: 2 additions & 0 deletions include/dolphin/gx/GXTransform.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ void GXGetScissor(u32* left, u32* top, u32* width, u32* height);
void GXSetScissorBoxOffset(s32 x, s32 y);
void GXSetClipMode(GXClipMode mode);

void __GXSetMatrixIndex(GXAttr index);

#ifdef __cplusplus
};
#endif
Expand Down
1 change: 1 addition & 0 deletions include/global.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#endif

extern int __cntlzw(uint);
extern int __rlwimi(int, int, int, int, int);
extern void __dcbz(void*, int);

#define VERSION_JPN 0
Expand Down
2 changes: 1 addition & 1 deletion src/JSystem/JParticle/JPAMath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "JSystem/JParticle/JPAMath.h"
#include "JSystem/JMath/JMath.h"
#include "JSystem/JMath/JMATrigonometric.h"
#include "dolphin/types.h"
#include "dolphin/mtx/mtx.h"

static f32 dummy() {
return 1.0f;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "abort_exit.h"
#include "critical_regions.h"
#include "stddef.h"
#include "NMWException.h"

void _ExitProcess();

extern void (*_dtors[])(void);

Expand Down
13 changes: 10 additions & 3 deletions src/d/actor/d_a_title.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
//

#include "d/actor/d_a_title.h"
#include "d/res/res_tlogo.h"
#include "d/res/res_tlogoe.h"
#include "d/res/res_tlogoe0.h"
#include "d/d_procname.h"
#include "f_op/f_op_overlap_mng.h"
#include "f_op/f_op_scene_mng.h"
Expand All @@ -18,6 +15,16 @@
#include "JSystem/JKernel/JKRExpHeap.h"
#include "stdio.h"

#if VERSION == VERSION_JPN
#include "d/res/res_tlogo.h"
#endif
#if VERSION == VERSION_USA
#include "d/res/res_tlogoe.h"
#endif
#if VERSION == VERSION_PAL
#include "d/res/res_tlogoe0.h"
#endif

// Note: For VERSION_PAL the "TlogoE0" string literal is modified at runtime.
#define ARCNAME VERSION_SELECT("Tlogo", "TlogoE", "TlogoE0")

Expand Down
30 changes: 8 additions & 22 deletions src/dolphin/gx/GXBump.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,36 +127,22 @@ void GXSetIndTexCoordScale(GXIndTexStageID texStage, GXIndTexScale scaleS, GXInd
}

void GXSetIndTexOrder(GXIndTexStageID stage, GXTexCoordID coord, GXTexMapID map) {
GXData* data;

if (map == 0xFF) {
map = GX_TEXMAP0;
}

if (coord == 0xFF) {
coord = GX_TEXCOORD0;
}

switch (stage) {
case GX_INDTEXSTAGE0:
data = __GXData;
GX_BITFIELD_SET(data->iref, 29, 3, map);
GX_BITFIELD_SET(data->iref, 26, 3, coord);
GX_BITFIELD_SET(__GXData->iref, 29, 3, map);
GX_BITFIELD_SET(__GXData->iref, 26, 3, coord);
break;
case GX_INDTEXSTAGE1:
data = __GXData;
GX_BITFIELD_SET(data->iref, 23, 3, map);
GX_BITFIELD_SET(data->iref, 20, 3, coord);
GX_BITFIELD_SET(__GXData->iref, 23, 3, map);
GX_BITFIELD_SET(__GXData->iref, 20, 3, coord);
break;
case GX_INDTEXSTAGE2:
data = __GXData;
GX_BITFIELD_SET(data->iref, 17, 3, map);
GX_BITFIELD_SET(data->iref, 14, 3, coord);
GX_BITFIELD_SET(__GXData->iref, 17, 3, map);
GX_BITFIELD_SET(__GXData->iref, 14, 3, coord);
break;
case GX_INDTEXSTAGE3:
data = __GXData;
GX_BITFIELD_SET(data->iref, 11, 3, map);
GX_BITFIELD_SET(data->iref, 8, 3, coord);
GX_BITFIELD_SET(__GXData->iref, 11, 3, map);
GX_BITFIELD_SET(__GXData->iref, 8, 3, coord);
break;
}

Expand Down
49 changes: 9 additions & 40 deletions src/dolphin/gx/GXInit.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,21 @@

char* __GXVersion = "<< Dolphin SDK - GX release build: Nov 10 2004 06:27:12 (0x2301) >>";

static GXFifoObj FifoObj;

static GXData gxData;

static GXFifoObj FifoObj;

GXData* const __GXData = &gxData;

GXTexRegion* __GXDefaultTexRegionCallback(const GXTexObj* obj, GXTexMapID id) {
GXTexFmt format; // r31
GXBool isMipMap; // r3
GXTexFmt format;

format = GXGetTexObjFmt(obj);
isMipMap = GXGetTexObjMipMap(obj);
id = (GXTexMapID)(id % GX_MAX_TEXMAP);

switch (format) {
case GX_TF_RGBA8:
// if (isMipMap) {
// return &__GXData->TexRegions2[id];
// }
return &__GXData->TexRegions1[id];

case GX_TF_C4:
case GX_TF_C8:
case GX_TF_C14X2:
return &__GXData->TexRegions0[id];

default:
if (isMipMap) {
return &__GXData->TexRegions1[id];
}
return &__GXData->TexRegions0[id];
if (format != GX_TF_C4 && format != GX_TF_C8 && format != GX_TF_C14X2) {
return &__GXData->TexRegions0[__GXData->nextTexRgn++ % GX_MAX_TEXMAP];
} else {
return &__GXData->TexRegions1[__GXData->nextTexRgnCI++ % 4];
}
}

Expand Down Expand Up @@ -168,11 +152,6 @@ GXFifoObj* GXInit(void* base, u32 size) {
GXSetCPUFifo(&FifoObj);
GXSetGPFifo(&FifoObj);

if (!resetFuncRegistered) {
// OSRegisterResetFunction(&GXResetFuncInfo);
resetFuncRegistered = 1;
}

__GXPEInit();
EnableWriteGatherPipe();

Expand Down Expand Up @@ -280,7 +259,6 @@ GXFifoObj* GXInit(void* base, u32 size) {

GFWriteBPCmd(0x67000000);

__GXSetIndirectMask(0);
__GXSetTmemConfig(2);
__GXInitGX();

Expand All @@ -289,7 +267,6 @@ GXFifoObj* GXInit(void* base, u32 size) {

void __GXInitGX(void) {
GXRenderModeObj* renderObj;
GXTexObj texObj;
Mtx ident;
GXColor clearColor = {64, 64, 64, 255};
GXColor ambColor = {0, 0, 0, 0};
Expand Down Expand Up @@ -395,19 +372,11 @@ void __GXInitGX(void) {
GXSetChanMatColor(GX_COLOR1A1, matColor);

GXInvalidateTexAll();
__GXData->nextTexRgn = 0;
__GXData->nextTexRgnCI = 0;
GXSetTexRegionCallback(__GXDefaultTexRegionCallback);
GXSetTlutRegionCallback(__GXDefaultTlutRegionCallback);

GXInitTexObj(&texObj, DefaultTexData, 4, 4, GX_TF_IA8, GX_CLAMP, GX_CLAMP, GX_FALSE);
GXLoadTexObj(&texObj, GX_TEXMAP0);
GXLoadTexObj(&texObj, GX_TEXMAP1);
GXLoadTexObj(&texObj, GX_TEXMAP2);
GXLoadTexObj(&texObj, GX_TEXMAP3);
GXLoadTexObj(&texObj, GX_TEXMAP4);
GXLoadTexObj(&texObj, GX_TEXMAP5);
GXLoadTexObj(&texObj, GX_TEXMAP6);
GXLoadTexObj(&texObj, GX_TEXMAP7);

GXSetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR0A0);
GXSetTevOrder(GX_TEVSTAGE1, GX_TEXCOORD1, GX_TEXMAP1, GX_COLOR0A0);
GXSetTevOrder(GX_TEVSTAGE2, GX_TEXCOORD2, GX_TEXMAP2, GX_COLOR0A0);
Expand Down
Loading

0 comments on commit 04a5b59

Please sign in to comment.