Skip to content
16 changes: 16 additions & 0 deletions include/dolphin/gx/GXGeometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,22 @@ static inline void GXEnd(void) {
#endif
}

static inline void GXTexCoord2s16(int r3, int r4) // possible inline req.
{
int ptr = 0xcc010000;
*(short*)((char*)(ptr) - 0x8000) = r3;
*(short*)((char*)(ptr) - 0x8000) = r4;
}


static inline void GXPosition3s16(int r3, int r4, int r5) // possible inline req.
{
int ptr = 0xcc010000;
*(short*)((char*)(ptr) - 0x8000) = r3;
*(short*)((char*)(ptr) - 0x8000) = r4;
*(short*)((char*)(ptr) - 0x8000) = r5;
}

void GXSetLineWidth(u8 width, GXTexOffset texOffsets);
void GXSetPointSize(u8 pointSize, GXTexOffset texOffsets);
void GXEnableTexOffsets(GXTexCoordID coord, u8 line_enable, u8 point_enable);
Expand Down
2 changes: 2 additions & 0 deletions src/SB/Core/gc/iSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ void** psGetMemoryFunctions();
void iVSync();
U16 my_dsc(U16 dsc);

void iSystemInit(U32 options);
void iSystemExit();
void MemoryProtectionErrorHandler(U16 last, OSContext* ctx, U64 unk1, U64 unk2);
void TRCInit();

Expand Down
92 changes: 88 additions & 4 deletions src/SB/Core/gc/iTRC.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "iTRC.h"

#include <types.h>
#include <string.h>
#include <dolphin/gx/GXCull.h>
#include <dolphin/gx/GXFrameBuffer.h>
Expand All @@ -9,6 +8,8 @@
#include <dolphin/gx/GXPixel.h>
#include <dolphin/gx/GXTexture.h>
#include <dolphin/gx/GXTransform.h>
#include <dolphin/gx/GXLighting.h>
#include <dolphin/gx/GXTev.h>
#include <dolphin/mtx.h>
#include <dolphin/vi/vifuncs.h>

Expand All @@ -18,6 +19,12 @@
extern void GXPosition3s16(S32, S32, S32);
extern void GXTexCoord2s16(S32, S32);

// FIXME: These should be in a RW header somewhere
extern GXRenderModeObj* _RwDlRenderMode;
extern "C" {
void RwGameCubeGetXFBs(void*, void*);
}

namespace ROMFont
{
OSFontHeader* mFontData;
Expand Down Expand Up @@ -60,6 +67,40 @@ BOOL ROMFont::Init()
return OSInitFont(ROMFont::mFontData);
}

void ROMFont::InitDisplay(_GXRenderModeObj* InRenderMode)
{
GXColor clr = { 0 };
Mtx44 mtx;
Mtx idt;

mRenderMode = InRenderMode;
void** xfb = &mXFBs[1];
RwGameCubeGetXFBs(&mXFBs[0], &mXFBs[1]);
mCurrentFrameBuffer = *xfb;

ROMFont::InitGX();
ROMFont::InitVI();

GXSetCopyClear(clr, 0xffffff);
C_MTXOrtho(mtx, 0.0f, mRenderMode->efbHeight, 0.0f, mRenderMode->fbWidth, 0.0f, 10000.0f);
GXSetProjection(mtx, GX_ORTHOGRAPHIC);
PSMTXIdentity(idt);
GXLoadPosMtxImm(idt, 0);
GXSetCurrentMtx(0);
GXSetZMode(TRUE, GX_ALWAYS, TRUE);
GXSetNumChans(0);
GXSetNumTevStages(1);
GXSetTevOp(GX_TEVSTAGE0, GX_REPLACE);
GXSetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR_NULL);
GXSetBlendMode(GX_BM_BLEND, GX_BL_ONE, GX_BL_ONE, GX_LO_CLEAR);
GXClearVtxDesc();
GXSetVtxDesc(GX_VA_POS, GX_DIRECT);
GXSetVtxDesc(GX_VA_TEX0, GX_DIRECT);
GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_NRM_NBT, GX_RGBA4, 0);
GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_NRM_NBT, GX_RGBA4, 0);
return;
}

void ROMFont::InitGX()
{
U16 scaledHeight;
Expand Down Expand Up @@ -289,11 +330,20 @@ void ResetButton::SetSndKillFunction(void (*Func)())

void ResetButton::CheckResetButton()
{
// TODO

OSGetResetButtonState();
PADRecalibrate(0xf0000000);
VISetBlack(TRUE);
VIFlush();
VIWaitForRetrace();
OSEnableInterrupts();
DVDGetDriveStatus();
}

bool iTRCDisk::Init(void)
void iTRCDisk::Init()
{
return ROMFont::Init();
ROMFont::Init();
}

void iTRCDisk::SetErrorMessage(const char* message)
Expand Down Expand Up @@ -338,11 +388,45 @@ void iTRCDisk::SetMovieResumeFunction(void (*Func)())

bool iTRCDisk::IsDiskIDed()
{
return false;
S32 diskChk;
bool diskIDed;

diskIDed = false;
diskChk = DVDCheckDisk();

if ((diskChk != FALSE) && (diskChk = DVDGetDriveStatus(), diskChk == FALSE))
{
diskIDed = true;
}
return diskIDed;
}

void iTRCDisk::DisplayErrorMessage()
{
S32 tempVar;
GXCullMode* getMode = 0;
GXCullMode setMode = GX_CULL_ALL;
_GXRenderModeObj* gxRender = 0;

tempVar = strcmp(mMessage, "");

if (tempVar != 0)
{
GXGetCullMode(getMode); // (local_18)
ROMFont::InitDisplay(gxRender);
iTRCDisk::SetDVDState();
while (tempVar != 0)
{
ROMFont::DrawTextBox(0x32, 0xaa, 0x244, 100, mMessage);
if (tempVar != -1)
{
ResetButton::CheckResetButton();
}
iTRCDisk::SetDVDState();
}
iTRCDisk::ResetMessage();
GXSetCullMode(setMode);
}
}

void iTRCDisk::SetDVDState()
Expand Down
8 changes: 7 additions & 1 deletion src/SB/Core/gc/iTRC.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@

#include <types.h>
#include <dolphin/types.h>
#include <dolphin/os.h>
#include <dolphin/os/OSAlloc.h>
#include <dolphin/os/OSFont.h>
#include <dolphin/os/OSReset.h>
#include <dolphin/gx/GXStruct.h>
#include <dolphin/gx/GXGet.h>
#include <dolphin/dvd.h>
#include <dolphin/pad.h>

#include "xPad.h"

Expand All @@ -23,6 +28,7 @@ namespace ROMFont
extern bool mFirstFrame;

BOOL Init();
void InitDisplay(_GXRenderModeObj* gxRender);
void InitGX();
void InitVI();
void RenderBegin();
Expand Down Expand Up @@ -53,7 +59,7 @@ namespace iTRCDisk
void SetMovieSuspendFunction(void (*)(void));
void SetMovieResumeFunction(void (*)(void));
bool CheckDVDAndResetState();
bool Init();
void Init();
void ResetMessage();
void DisplayErrorMessage();
void SetDVDState();
Expand Down
56 changes: 3 additions & 53 deletions src/SB/Core/x/xCamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,59 +12,18 @@
#include <cmath>
#include <cstring>

struct cameraFXShake
{
F32 magnitude;
xVec3 dir;
F32 cycleTime;
F32 cycleMax;
F32 dampen;
F32 dampenRate;
F32 rotate_magnitude;
F32 radius;
xVec3* epicenterP;
xVec3 epicenter;
xVec3* player;
};

struct cameraFXZoom
{
F32 holdTime;
F32 vel;
F32 accel;
F32 distance;
U32 mode;
F32 velCur;
F32 distanceCur;
F32 holdTimeCur;
};


#define CAMERAFX_ZOOM_MODE_0 0
#define CAMERAFX_ZOOM_MODE_1 1
#define CAMERAFX_ZOOM_MODE_2 2
#define CAMERAFX_ZOOM_MODE_3 3

struct cameraFX
{
S32 type;
S32 flags;
F32 elapsedTime;
F32 maxTime;
union
{
cameraFXShake shake;
cameraFXZoom zoom;
};
};


#define CAMERAFX_TYPE_SHAKE 2

struct cameraFXTableEntry
{
S32 type;
void (*func)(cameraFX*, F32, xMat4x3*, xMat4x3*);
void (*funcKill)(cameraFX*);
};


extern F32 _764;
extern F32 _765;
Expand Down Expand Up @@ -104,15 +63,6 @@ extern F32 _1758;
extern F32 _1766;
extern F32 _1772;

extern S32 sCamCollis;
extern volatile S32 xcam_collis_owner_disable;
extern S32 xcam_do_collis;
extern F32 xcam_collis_radius;
extern F32 xcam_collis_stiffness;
extern RpAtomic* sInvisWallHack;
extern xMat4x3 sCameraFXMatOld;
extern cameraFX sCameraFX[10];
extern cameraFXTableEntry sCameraFXTable[3];

static void xCameraFXInit();
void add_camera_tweaks();
Expand Down
58 changes: 58 additions & 0 deletions src/SB/Core/x/xCamera.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,64 @@

#include <rwcore.h>

struct cameraFXShake
{
F32 magnitude;
xVec3 dir;
F32 cycleTime;
F32 cycleMax;
F32 dampen;
F32 dampenRate;
F32 rotate_magnitude;
F32 radius;
xVec3* epicenterP;
xVec3 epicenter;
xVec3* player;
};

struct cameraFXZoom
{
F32 holdTime;
F32 vel;
F32 accel;
F32 distance;
U32 mode;
F32 velCur;
F32 distanceCur;
F32 holdTimeCur;
};

struct cameraFX
{
S32 type;
S32 flags;
F32 elapsedTime;
F32 maxTime;
union
{
cameraFXShake shake;
cameraFXZoom zoom;
};
};

struct cameraFXTableEntry
{
S32 type;
void (*func)(cameraFX*, F32, xMat4x3*, xMat4x3*);
void (*funcKill)(cameraFX*);
};

extern S32 sCamCollis;
extern volatile S32 xcam_collis_owner_disable;
extern S32 xcam_do_collis;
extern F32 xcam_collis_radius;
extern F32 xcam_collis_stiffness;
extern RpAtomic* sInvisWallHack;
extern xMat4x3 sCameraFXMatOld;
extern cameraFX sCameraFX[10];
extern cameraFXTableEntry sCameraFXTable[3];


struct xScene;

enum _tagTransType
Expand Down
15 changes: 15 additions & 0 deletions src/SB/Core/x/xCollide.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,18 @@ U32 xSphereHitsSphere(const xSphere* a, const xSphere* b, xCollis* coll)
}
return uVar1;
}

void xParabolaRecenter(xParabola* p, F32 newZeroT)
{
xVec3 newPos;
xVec3 newVel;

xParabolaEvalPos(p, &newPos, newZeroT);
xParabolaEvalVel(p, &newVel, newZeroT);

xVec3Copy(&p->initPos, &newPos);
xVec3Copy(&p->initVel, &newVel);

p->maxTime -= newZeroT;
p->minTime -= newZeroT;
}
1 change: 1 addition & 0 deletions src/SB/Core/x/xCollide.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ U32 xSphereHitsModel(const xSphere* b, const xModelInstance* m, xCollis* coll);
S32 xParabolaHitsEnv(xParabola* p, const xEnv* env, xCollis* colls);
void xParabolaEvalPos(const xParabola*, xVec3*, F32);
void xParabolaEvalVel(const xParabola*, xVec3*, F32);
void xParabolaRecenter(xParabola* p, F32 newZeroT);

void xVec3AddScaled(xVec3*, const xVec3*, F32);
xVec3 xCollisTriHit(const xCollis::tri_data& tri, const xModelInstance& model);
Expand Down
2 changes: 2 additions & 0 deletions src/SB/Core/x/xFX.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ struct xFXRibbon

extern xFXRing ringlist[RING_COUNT];

void xFXStartup();
void xFXShutdown();
void xFXInit();
xFXRing* xFXRingCreate(const xVec3* pos, const xFXRing* params);
void xFXRingRender();
Expand Down
2 changes: 1 addition & 1 deletion src/SB/Core/x/xGlobals.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct xGlobals
_tagxPad* pad1;
_tagxPad* pad2;
_tagxPad* pad3;
S32 profile;
S32 profile; //0x32c

// 0x330 in globals
char profFunc[6][128];
Expand Down
Loading