Skip to content

Commit

Permalink
Match some S2DEX functions (#193)
Browse files Browse the repository at this point in the history
* Match some s2dex functions

* Rename s2dex structs

* Remove stray comment

* Decode scissorX1/scissorY1
  • Loading branch information
cadmic authored Oct 14, 2024
1 parent d8556e1 commit f1382ed
Show file tree
Hide file tree
Showing 4 changed files with 795 additions and 39 deletions.
74 changes: 59 additions & 15 deletions include/emulator/rsp.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
#define AUDIO_SEGMENT_ADDRESS(pRSP, nOffsetRDRAM) \
(pRSP->anAudioBaseSegment[((nOffsetRDRAM) >> 24) & 0xF] + ((nOffsetRDRAM) & 0xFFFFFF))

#define G_OBJLT_TXTRBLOCK 0x00001033
#define G_OBJLT_TXTRTILE 0x00FC1034
#define G_OBJLT_TLUT 0x00000030

typedef enum RspAudioUCodeType {
RUT_NOCODE = -1,
RUT_ABI1 = 0,
Expand Down Expand Up @@ -264,7 +268,7 @@ typedef struct Rsp {
/* 0x39C8 */ int* dctBuf;
} Rsp; // size = 0x39CC

typedef struct __anon_0x5ED4F {
typedef struct uObjBg_t {
/* 0x00 */ u16 imageX;
/* 0x02 */ u16 imageW;
/* 0x04 */ s16 frameX;
Expand All @@ -285,9 +289,9 @@ typedef struct __anon_0x5ED4F {
/* 0x22 */ u16 tmemLoadTH;
/* 0x24 */ u16 tmemSizeW;
/* 0x26 */ u16 tmemSize;
} __anon_0x5ED4F; // size = 0x28
} uObjBg_t; // size = 0x28

typedef struct __anon_0x5F05A {
typedef struct uObjScaleBg_t {
/* 0x00 */ u16 imageX;
/* 0x02 */ u16 imageW;
/* 0x04 */ s16 frameX;
Expand All @@ -306,15 +310,15 @@ typedef struct __anon_0x5F05A {
/* 0x1E */ u16 scaleH;
/* 0x20 */ s32 imageYorig;
/* 0x24 */ u8 padding[4];
} __anon_0x5F05A; // size = 0x28
} uObjScaleBg_t; // size = 0x28

typedef union __anon_0x5F2FB {
__anon_0x5ED4F b;
__anon_0x5F05A s;
typedef union uObjBg {
uObjBg_t b;
uObjScaleBg_t s;
s64 force_structure_alignment;
} __anon_0x5F2FB;
} uObjBg;

typedef struct __anon_0x5F429 {
typedef struct uObjSprite_t {
/* 0x00 */ s16 objX;
/* 0x02 */ u16 scaleW;
/* 0x04 */ u16 imageW;
Expand All @@ -329,16 +333,56 @@ typedef struct __anon_0x5F429 {
/* 0x15 */ u8 imageSiz;
/* 0x16 */ u8 imagePal;
/* 0x17 */ u8 imageFlags;
} __anon_0x5F429; // size = 0x18
} uObjSprite_t; // size = 0x18

typedef union __anon_0x5F63B {
__anon_0x5F429 s;
typedef union uObjSprite {
uObjSprite_t s;
s64 force_structure_alignment;
} uObjSprite;

typedef struct uObjTxtrBlock_t {
/* 0x00 */ u32 type;
/* 0x04 */ u32 image;
/* 0x08 */ u16 tmem;
/* 0x0A */ u16 tsize;
/* 0x0C */ u16 tline;
/* 0x0E */ u16 sid;
/* 0x10 */ u32 flag;
/* 0x14 */ u32 mask;
} uObjTxtrBlock_t; // size = 0x18

typedef struct uObjTxtrTile_t {
/* 0x00 */ u32 type;
/* 0x04 */ u32 image;
/* 0x08 */ u16 tmem;
/* 0x0A */ u16 twidth;
/* 0x0C */ u16 theight;
/* 0x0E */ u16 sid;
/* 0x10 */ u32 flag;
/* 0x14 */ u32 mask;
} uObjTxtrTile_t; // size = 0x18

typedef struct uObjTxtrTLUT_t {
/* 0x00 */ u32 type;
/* 0x04 */ u32 image;
/* 0x08 */ u16 phead;
/* 0x0A */ u16 pnum;
/* 0x0C */ u16 zero;
/* 0x0E */ u16 sid;
/* 0x10 */ u32 flag;
/* 0x14 */ u32 mask;
} uObjTxtrTLUT_t; // size = 0x18

typedef union uObjTxtr {
uObjTxtrBlock_t block;
uObjTxtrTile_t tile;
uObjTxtrTLUT_t tlut;
s64 force_structure_alignment;
} __anon_0x5F63B;
} uObjTxtr;

bool rspFillObjBg(Rsp* pRSP, s32 nAddress, __anon_0x5F2FB* pBg);
bool rspFillObjBg(Rsp* pRSP, s32 nAddress, uObjBg* pBg);
bool rspSetImage(struct Frame* pFrame, Rsp* pRSP, s32 nFormat, s32 nWidth, s32 nSize, s32 nImage);
bool rspFillObjBgScale(Rsp* pRSP, s32 nAddress, __anon_0x5F2FB* pBg);
bool rspFillObjBgScale(Rsp* pRSP, s32 nAddress, uObjBg* pBg);
bool rspPut32(Rsp* pRSP, u32 nAddress, s32* pData);
bool rspGet32(Rsp* pRSP, u32 nAddress, s32* pData);
bool rspInvalidateCache(Rsp* pRSP, s32 nOffset0, s32 nOffset1);
Expand Down
2 changes: 1 addition & 1 deletion src/emulator/frame.c
Original file line number Diff line number Diff line change
Expand Up @@ -3247,7 +3247,7 @@ bool frameHackCIMG_Zelda2_Shrink(Rdp* pRDP, Frame* pFrame, u64** ppnGBI) {
u32 nCommandHi;
Rsp* pRSP;
s32 done;
union __anon_0x5F2FB bg;
uObjBg bg;

pnGBI = *ppnGBI;
for (count = 0; count < ARRAY_COUNT(GBIcode); count++) {
Expand Down
4 changes: 2 additions & 2 deletions src/emulator/rdp.c
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ bool rdpParseGBI(Rdp* pRDP, u64** ppnGBI, RspUCodeType eTypeUCode) {
pFrame->aTile[iTile].nX1 = (nCommandLo >> 12) & 0xFFF;
pFrame->aTile[iTile].nY1 = nCommandLo & 0xFFF;

pFrame->n2dLoadTexType = 0xFC1034;
pFrame->n2dLoadTexType = G_OBJLT_TXTRTILE;
pFrame->nLastX0 = pFrame->aTile[iTile].nX0;
pFrame->nLastY0 = pFrame->aTile[iTile].nY0;
pFrame->nLastX1 = pFrame->aTile[iTile].nX1;
Expand All @@ -379,7 +379,7 @@ bool rdpParseGBI(Rdp* pRDP, u64** ppnGBI, RspUCodeType eTypeUCode) {
pFrame->aTile[iTile].nY0 = nCommandHi & 0xFFF;
pFrame->aTile[iTile].nX1 = (nCommandLo >> 12) & 0xFFF;
pFrame->aTile[iTile].nY1 = nCommandLo & 0xFFF;
pFrame->n2dLoadTexType = 0x1033;
pFrame->n2dLoadTexType = G_OBJLT_TXTRBLOCK;
if (!frameLoadTMEM(pFrame, FLT_BLOCK, iTile)) {
return false;
}
Expand Down
Loading

0 comments on commit f1382ed

Please sign in to comment.