Decompile some PSX SDK functions (#1002)

This commit is contained in:
Luciano Ciccariello 2024-01-21 17:58:32 +00:00 committed by GitHub
parent beb89d55a6
commit 8eb7795b4f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
13 changed files with 320 additions and 106 deletions

View File

@ -40,6 +40,7 @@ endif()
set(SOURCE_FILES_PSX_SDK
src/main/psxsdk/libgpu/ext.c
src/main/psxsdk/libgpu/prim.c
)
set(SOURCE_FILES_MOCK_SDK

View File

@ -17,7 +17,7 @@ OBJCOPY := $(CROSS)objcopy
AS_FLAGS += -Iinclude -march=r3000 -mtune=r3000 -no-pad-sections -O1 -G0
PSXCC_FLAGS := -quiet -mcpu=3000 -fgnu-linker -mgas -gcoff
CC_FLAGS += -G0 -w -O2 -funsigned-char -fpeephole -ffunction-cse -fpcc-struct-return -fcommon -fverbose-asm -msoft-float -g
CPP_FLAGS += -Iinclude -undef -Wall -fno-builtin
CPP_FLAGS += -Iinclude -Iinclude/psxsdk -undef -Wall -fno-builtin
CPP_FLAGS += -Dmips -D__GNUC__=2 -D__OPTIMIZE__ -D__mips__ -D__mips -Dpsx -D__psx__ -D__psx -D_PSYQ -D__EXTENSIONS__ -D_MIPSEL -D_LANGUAGE_C -DLANGUAGE_C -DNO_LOGS -DHACKS -DUSE_INCLUDE_ASM
CPP_FLAGS += -D_internal_version_$(VERSION) -DSOTN_STR
LD_FLAGS := -nostdlib --no-check-sections

View File

@ -30,7 +30,8 @@ segments:
subsegments:
- [0x800, rodata]
- [0x874, rodata] # jpt_80011B20
- [0x8F8, rodata]
- [0x8F8, .rodata, psxsdk/libgpu/prim]
- [0x9C8, rodata]
- [0xA10, .rodata, psxsdk/libgpu/sys]
- [0xB60, rodata]
- [0xC94, rodata] # jpt_800163F4

View File

@ -2,6 +2,7 @@
// _card_load
extern void InitCARD(long val);
extern long StartCARD(void);
// _card_clear
long _card_clear(long chan);
// _card_write
// _new_card

View File

@ -11,7 +11,7 @@ struct Callbacks {
int (*RestartCallback)(void);
};
extern u16 D_8002C2BA;
extern unsigned short D_8002C2BA;
extern struct Callbacks* D_8002D340;
int VSync(int mode);
@ -22,7 +22,7 @@ void* DMACallback(int dma, void (*func)());
int ResetCallback(void);
int StopCallback(void);
int RestartCallback(void);
u16 CheckCallback(void);
int CheckCallback(void);
long SetVideoMode(long mode);

View File

@ -74,7 +74,7 @@
#define getcode(p) (u_char)(((P_TAG*)(p))->code)
#define getaddr(p) (u_long)(((P_TAG*)(p))->addr)
#define nextPrim(p) (void*)((((P_TAG*)(p))->addr) | 0x80000000)
#define nextPrim(p) (void*)((u_long)(((P_TAG*)(p))->addr) | 0x80000000)
#define isendprim(p) ((((P_TAG*)(p))->addr) == 0xffffff)
#define addPrim(ot, p) setaddr(p, getaddr(ot)), setaddr(ot, p)
@ -83,14 +83,29 @@
#define catPrim(p0, p1) setaddr(p0, p1)
#define termPrim(p) setaddr(p, 0xffffffff)
#define setLineG2(p) setlen(p, 4), setcode(p, 0x50)
#define setPolyF3(p) setlen(p, 4), setcode(p, 0x20)
#define setPolyFT3(p) setlen(p, 7), setcode(p, 0x24)
#define setPolyG3(p) setlen(p, 6), setcode(p, 0x30)
#define setPolyGT3(p) setlen(p, 9), setcode(p, 0x34)
#define setPolyF4(p) setlen(p, 5), setcode(p, 0x28)
#define setPolyFT4(p) setlen(p, 9), setcode(p, 0x2c)
#define setPolyG4(p) setlen(p, 8), setcode(p, 0x38)
#define setPolyGT4(p) setlen(p, 12), setcode(p, 0x3c)
#define setSprt(p) setlen(p, 4), setcode(p, 0x64)
#define setSprt16(p) setlen(p, 3), setcode(p, 0x7c)
#define setSprt8(p) setlen(p, 3), setcode(p, 0x74)
#define setSprt16(p) setlen(p, 3), setcode(p, 0x7c)
#define setSprt(p) setlen(p, 4), setcode(p, 0x64)
#define setTile1(p) setlen(p, 2), setcode(p, 0x68)
#define setTile8(p) setlen(p, 2), setcode(p, 0x70)
#define setTile16(p) setlen(p, 2), setcode(p, 0x78)
#define setTile(p) setlen(p, 3), setcode(p, 0x60)
#define setLineF2(p) setlen(p, 3), setcode(p, 0x40)
#define setLineG2(p) setlen(p, 4), setcode(p, 0x50)
#define setLineF3(p) setlen(p, 5), setcode(p, 0x48), (p)->pad = 0x55555555
#define setLineG3(p) setlen(p, 7), setcode(p, 0x58), (p)->pad = 0x55555555
#define setLineF4(p) setlen(p, 6), setcode(p, 0x4c), (p)->pad = 0x55555555
#define setLineG4(p) setlen(p, 9), setcode(p, 0x5c), (p)->pad = 0x55555555
#define setSemiTrans(p, abe) \
((abe) ? setcode(p, getcode(p) | 0x02) : setcode(p, getcode(p) & ~0x02))
@ -138,12 +153,62 @@ typedef struct {
} P_CODE;
typedef struct {
/* 0x00 */ u_long tag;
/* 0x04 */ u_char r0, g0, b0, code;
/* 0x08 */ short x0, y0;
/* 0x0C */ u_char r1, g1, b1, p1;
/* 0x10 */ short x1, y1;
} LINE_G2; /* size = 0x14 */
u_long tag;
u_char r0, g0, b0, code;
short x0, y0;
short x1, y1;
short x2, y2;
} POLY_F3;
typedef struct {
u_long tag;
u_char r0, g0, b0, code;
short x0, y0;
short x1, y1;
short x2, y2;
short x3, y3;
} POLY_F4;
typedef struct {
u_long tag;
u_char r0, g0, b0, code;
short x0, y0;
u_char u0, v0;
u_short clut;
short x1, y1;
u_char u1, v1;
u_short tpage;
short x2, y2;
u_char u2, v2;
u_short pad1;
} POLY_FT3;
typedef struct {
u_long tag;
u_char r0, g0, b0, code;
short x0, y0;
u_char u0, v0;
u_short clut;
short x1, y1;
u_char u1, v1;
u_short tpage;
short x2, y2;
u_char u2, v2;
u_short pad1;
short x3, y3;
u_char u3, v3;
u_short pad2;
} POLY_FT4;
typedef struct {
u_long tag;
u_char r0, g0, b0, code;
short x0, y0;
u_char r1, g1, b1, pad1;
short x1, y1;
u_char r2, g2, b2, pad2;
short x2, y2;
} POLY_G3;
typedef struct {
/* 0x00 */ u_long tag;
@ -244,6 +309,64 @@ typedef struct {
/* 0x32 */ u_short pad3;
} POLY_GT4; /* Gouraud Textured Quadrangle, size = 0x34*/
typedef struct {
u_long tag;
u_char r0, g0, b0, code;
short x0, y0;
short x1, y1;
} LINE_F2;
typedef struct {
u_long tag;
u_char r0, g0, b0, code;
short x0, y0;
u_char r1, g1, b1, p1;
short x1, y1;
} LINE_G2;
typedef struct {
u_long tag;
u_char r0, g0, b0, code;
short x0, y0;
short x1, y1;
short x2, y2;
u_long pad;
} LINE_F3;
typedef struct {
u_long tag;
u_char r0, g0, b0, code;
short x0, y0;
u_char r1, g1, b1, p1;
short x1, y1;
u_char r2, g2, b2, p2;
short x2, y2;
u_long pad;
} LINE_G3;
typedef struct {
u_long tag;
u_char r0, g0, b0, code;
short x0, y0;
short x1, y1;
short x2, y2;
short x3, y3;
u_long pad;
} LINE_F4;
typedef struct {
u_long tag;
u_char r0, g0, b0, code;
short x0, y0;
u_char r1, g1, b1, p1;
short x1, y1;
u_char r2, g2, b2, p2;
short x2, y2;
u_char r3, g3, b3, p3;
short x3, y3;
u_long pad;
} LINE_G4;
typedef struct {
/* 0x00 */ u_long tag;
/* 0x04 */ u_char r0;
@ -286,11 +409,29 @@ typedef struct {
} SPRT_8; /* 8x8 Sprite, size = 0x10 */
typedef struct {
/* 0x00 */ u_long tag;
/* 0x04 */ u_char r0, g0, b0, code;
/* 0x08 */ short x0, y0;
/* 0x0C */ short w, h;
} TILE; /* free size Tile, size = 0x10 */
u_long tag;
u_char r0, g0, b0, code;
short x0, y0;
short w, h;
} TILE;
typedef struct {
u_long tag;
u_char r0, g0, b0, code;
short x0, y0;
} TILE_16;
typedef struct {
u_long tag;
u_char r0, g0, b0, code;
short x0, y0;
} TILE_8;
typedef struct {
u_long tag;
u_char r0, g0, b0, code;
short x0, y0;
} TILE_1;
typedef struct {
/* 0x00 */ RECT clip; /* clip area */
@ -366,6 +507,9 @@ u_short GetClut(int x, // Horizontal frame buffer address of CLUT
);
u_short GetTPage(int tp, int abr, int x, int y);
void DumpTPage(u_short tpage);
void DumpClut(u_short clut);
extern void AddPrim(void* ot, void* p);
extern void SetShadeTex(void* p, int tge);
extern void SetLineG2(LINE_G2* p);

View File

@ -22,7 +22,7 @@ int StopCallback(void) { return D_8002D340->StopCallback(); }
int RestartCallback(void) { return D_8002D340->RestartCallback(); }
u16 CheckCallback(void) { return D_8002C2BA; }
int CheckCallback(void) { return D_8002C2BA; }
INCLUDE_ASM("main/nonmatchings/psxsdk/libapi/l10", GetIntrMask);

View File

@ -1,3 +1,7 @@
#include "common.h"
#include <libcard.h>
INCLUDE_ASM("main/nonmatchings/psxsdk/libcard/card", _card_clear);
long _card_clear(long chan) {
_new_card();
return _card_write(chan, 0x3F, 0);
}

View File

@ -1,14 +1,20 @@
#include "common.h"
#include <libetc.h>
INCLUDE_ASM("main/nonmatchings/psxsdk/libetc/pad", PadInit);
// void PadInit(s32 arg0) {
// D_80073080 = arg0;
// D_8003925C = -1;
// ResetCallback();
// PAD_init(0x20000001, &D_8003925C);
// ChangeClearPAD(0);
// }
extern int PadIdentifier;
extern int pad_buf;
INCLUDE_ASM("main/nonmatchings/psxsdk/libetc/pad", PadRead);
void PadInit(int mode) {
PadIdentifier = mode;
pad_buf = -1;
ResetCallback();
PAD_init(0x20000001, &pad_buf);
ChangeClearPAD(0);
}
INCLUDE_ASM("main/nonmatchings/psxsdk/libetc/pad", PadStop);
u_long PadRead(int id) {
PAD_dr();
return ~pad_buf;
}
void PadStop(void) { StopPAD(); }

View File

@ -1,5 +1,14 @@
#include "common.h"
#include <libetc.h>
INCLUDE_ASM("main/nonmatchings/psxsdk/libetc/vmode", SetVideoMode);
extern long D_8002D3A4;
INCLUDE_ASM("main/nonmatchings/psxsdk/libetc/vmode", GetVideoMode);
long SetVideoMode(long mode) {
long prev;
prev = D_8002D3A4;
D_8002D3A4 = mode;
return prev;
}
long GetVideoMode(void) { return D_8002D3A4; }

View File

@ -1,8 +1,44 @@
#include "common.h"
#include <libgpu.h>
INCLUDE_ASM("main/nonmatchings/psxsdk/libgpu/font", SetDumpFnt);
typedef struct {
u32 unk00;
u32 unk04;
s16 x;
s16 y;
s16 w;
s16 h;
u32 unk10;
u32 unk14;
u32 unk18;
u32 unk1C;
u32 unk20;
u32 unk24;
u32 unk28;
} FntStream;
INCLUDE_ASM("main/nonmatchings/psxsdk/libgpu/font", FntLoad);
extern s32 D_8002B810;
extern s32 D_8002B814;
extern int (*GPU_printf)(const char*, ...);
void SetDumpFnt(int id) {
if (id >= 0 && D_8002B810 >= id) {
D_8002B814 = id;
GPU_printf = FntPrint;
}
}
extern u_long D_8002B818[];
extern FntStream Font[4];
extern u16 clut;
extern u16 tpage;
void FntLoad(s32 tx, s32 ty) {
clut = LoadClut2(D_8002B818, tx, ty + 0x80);
tpage = LoadTPage(D_8002B818 + 0x80, 0, 0, tx, ty, 0x80, 0x20);
D_8002B810 = 0;
memset(Font, 0, sizeof(Font));
}
INCLUDE_ASM("main/nonmatchings/psxsdk/libgpu/font", FntOpen);

View File

@ -1,75 +1,98 @@
#include "common.h"
#include <psxsdk/libgpu.h>
INCLUDE_ASM("main/nonmatchings/psxsdk/libgpu/prim", GetTPage);
extern void (*GPU_printf)(const char* fmt, ...);
INCLUDE_ASM("main/nonmatchings/psxsdk/libgpu/prim", GetClut);
u_short GetTPage(int tp, int abr, int x, int y) {
return GetGraphType() ? (tp & 3) << 9 | (abr & 3) << 7 | (y & 0x300) >> 3 |
(x & 0x3FF) >> 6
: (tp & 3) << 7 | (abr & 3) << 5 | (y & 0x100) >> 4 |
(x & 0x3FF) >> 6;
}
INCLUDE_ASM("main/nonmatchings/psxsdk/libgpu/prim", DumpTPage);
u16 GetClut(s32 x, s32 y) { return getClut(x, y); }
INCLUDE_ASM("main/nonmatchings/psxsdk/libgpu/prim", DumpClut);
void DumpTPage(u_short tpage) {
if (GetGraphType()) {
GPU_printf("tpage: (%d,%d,%d,%d)\n", (tpage >> 9) & 3, (tpage >> 7) & 3,
(tpage << 6) & 0x7C0, (tpage * 8) & 0x300);
} else {
GPU_printf("tpage: (%d,%d,%d,%d)\n", (tpage >> 7) & 3, (tpage >> 5) & 3,
(tpage << 6) & 0x7C0, (tpage * 0x10) & 0x100);
}
}
INCLUDE_ASM("main/nonmatchings/psxsdk/libgpu/prim", NextPrim);
void DumpClut(u_short clut) {
GPU_printf("clut: (%d,%d)\n", (clut & 0x3F) * 0x10, clut >> 6);
}
INCLUDE_ASM("main/nonmatchings/psxsdk/libgpu/prim", IsEndPrim);
void* NextPrim(void* p) { return nextPrim(p); }
INCLUDE_ASM("main/nonmatchings/psxsdk/libgpu/prim", AddPrim);
int IsEndPrim(void* p) { return isendprim(p); }
INCLUDE_ASM("main/nonmatchings/psxsdk/libgpu/prim", AddPrims);
void AddPrim(void* ot, void* p) { addPrim(ot, p); }
INCLUDE_ASM("main/nonmatchings/psxsdk/libgpu/prim", CatPrim);
void AddPrims(void* ot, void* p0, void* p1) { addPrims(ot, p0, p1); }
INCLUDE_ASM("main/nonmatchings/psxsdk/libgpu/prim", TermPrim);
void CatPrim(void* p0, void* p1) { catPrim(p0, p1); }
INCLUDE_ASM("main/nonmatchings/psxsdk/libgpu/prim", SetSemiTrans);
void TermPrim(void* p) { return termPrim(p); }
INCLUDE_ASM("main/nonmatchings/psxsdk/libgpu/prim", SetShadeTex);
void SetSemiTrans(void* p, int abe) { return setSemiTrans(p, abe); }
INCLUDE_ASM("main/nonmatchings/psxsdk/libgpu/prim", SetPolyF3);
void SetShadeTex(void* p, int tge) { return setShadeTex(p, tge); }
INCLUDE_ASM("main/nonmatchings/psxsdk/libgpu/prim", SetPolyFT3);
INCLUDE_ASM("main/nonmatchings/psxsdk/libgpu/prim", SetPolyG3);
INCLUDE_ASM("main/nonmatchings/psxsdk/libgpu/prim", SetPolyGT3);
INCLUDE_ASM("main/nonmatchings/psxsdk/libgpu/prim", SetPolyF4);
INCLUDE_ASM("main/nonmatchings/psxsdk/libgpu/prim", SetPolyFT4);
INCLUDE_ASM("main/nonmatchings/psxsdk/libgpu/prim", SetPolyG4);
INCLUDE_ASM("main/nonmatchings/psxsdk/libgpu/prim", SetPolyGT4);
INCLUDE_ASM("main/nonmatchings/psxsdk/libgpu/prim", SetSprt8);
INCLUDE_ASM("main/nonmatchings/psxsdk/libgpu/prim", SetSprt16);
INCLUDE_ASM("main/nonmatchings/psxsdk/libgpu/prim", SetSprt);
INCLUDE_ASM("main/nonmatchings/psxsdk/libgpu/prim", SetTile1);
INCLUDE_ASM("main/nonmatchings/psxsdk/libgpu/prim", SetTile8);
INCLUDE_ASM("main/nonmatchings/psxsdk/libgpu/prim", SetTile16);
INCLUDE_ASM("main/nonmatchings/psxsdk/libgpu/prim", SetTile);
void SetPolyF3(POLY_F3* p) { setPolyF3(p); }
void SetPolyFT3(POLY_FT3* p) { setPolyFT3(p); }
void SetPolyG3(POLY_G3* p) { setPolyG3(p); }
void SetPolyGT3(POLY_GT3* p) { setPolyGT3(p); }
void SetPolyF4(POLY_F4* p) { setPolyF4(p); }
void SetPolyFT4(POLY_FT4* p) { setPolyFT4(p); }
void SetPolyG4(POLY_G4* p) { setPolyG4(p); }
void SetPolyGT4(POLY_GT4* p) { setPolyGT4(p); }
void SetSprt8(SPRT_8* p) { setSprt8(p); }
void SetSprt16(SPRT_16* p) { setSprt16(p); }
void SetSprt(SPRT* p) { setSprt(p); }
void SetTile1(TILE_1* p) { setTile1(p); }
void SetTile8(TILE_8* p) { setTile8(p); }
void SetTile16(TILE_16* p) { setTile16(p); }
void SetTile(TILE* p) { setTile(p); }
INCLUDE_ASM("main/nonmatchings/psxsdk/libgpu/prim", SetBlockFill);
INCLUDE_ASM("main/nonmatchings/psxsdk/libgpu/prim", SetLineF2);
INCLUDE_ASM("main/nonmatchings/psxsdk/libgpu/prim", SetLineG2);
INCLUDE_ASM("main/nonmatchings/psxsdk/libgpu/prim", SetLineF3);
INCLUDE_ASM("main/nonmatchings/psxsdk/libgpu/prim", SetLineG3);
INCLUDE_ASM("main/nonmatchings/psxsdk/libgpu/prim", SetLineF4);
INCLUDE_ASM("main/nonmatchings/psxsdk/libgpu/prim", SetLineG4);
void SetLineF2(LINE_F2* p) { setLineF2(p); }
void SetLineG2(LINE_G2* p) { setLineG2(p); }
void SetLineF3(LINE_F3* p) { setLineF3(p); }
void SetLineG3(LINE_G3* p) { setLineG3(p); }
void SetLineF4(LINE_F4* p) { setLineF4(p); }
void SetLineG4(LINE_G4* p) { setLineG4(p); }
INCLUDE_ASM("main/nonmatchings/psxsdk/libgpu/prim", MargePrim);
INCLUDE_ASM("main/nonmatchings/psxsdk/libgpu/prim", DumpDrawEnv);
void DumpDrawEnv(DRAWENV* env) {
GPU_printf("clip (%3d,%3d)-(%d,%d)\n", env->clip.x, env->clip.y,
env->clip.w, env->clip.h);
GPU_printf("ofs (%3d,%3d)\n", env->ofs[0], env->ofs[1]);
GPU_printf(
"tw (%d,%d)-(%d,%d)\n", env->tw.x, env->tw.y, env->tw.w, env->tw.h);
GPU_printf("dtd %d\n", env->dtd);
GPU_printf("dfe %d\n", env->dfe);
if (GetGraphType()) {
GPU_printf("tpage: (%d,%d,%d,%d)\n", (env->tpage >> 9) & 3,
(env->tpage >> 7) & 3, (env->tpage << 6) & 0x7C0,
(env->tpage * 8) & 0x300);
} else {
GPU_printf("tpage: (%d,%d,%d,%d)\n", (env->tpage >> 7) & 3,
(env->tpage >> 5) & 3, (env->tpage << 6) & 0x7C0,
(env->tpage * 0x10) & 0x100);
}
}
INCLUDE_ASM("main/nonmatchings/psxsdk/libgpu/prim", DumpDispEnv);
void DumpDispEnv(DISPENV* env) {
GPU_printf("disp (%3d,%3d)-(%d,%d)\n", env->disp.x, env->disp.y,
env->disp.w, (s32)env->disp.h);
GPU_printf("screen (%3d,%3d)-(%d,%d)\n", env->screen.x, env->screen.y,
env->screen.w, (s32)env->screen.h);
GPU_printf("isinter %d\n", env->isinter);
GPU_printf("isrgb24 %d\n", env->isrgb24);
}

View File

@ -4,6 +4,8 @@
#include <stdio.h>
#include <log.h>
int (*GPU_printf)(const char*, ...) = FntPrint;
int FntOpen(int x, int y, int w, int h, int isbg, int n) { NOT_IMPLEMENTED; }
void FntLoad(int tx, int ty) { NOT_IMPLEMENTED; }
@ -60,22 +62,9 @@ int SetGraphDebug(int level) { NOT_IMPLEMENTED; }
u_long* ClearOTag(u_long* ot, int n) { NOT_IMPLEMENTED; }
u_short GetTPage(int tp, int abr, int x, int y) {
NOT_IMPLEMENTED;
return 0;
}
void SetDrawEnv(DR_ENV* dr_env, DRAWENV* env) { NOT_IMPLEMENTED; }
u_short GetClut(int x, int y) { return getClut(x, y); }
void AddPrim(void* ot, void* p) { addPrim(ot, p); }
void SetShadeTex(void* p, int tge) { setShadeTex(p, tge); }
void SetLineG2(LINE_G2* p) { setLineG2(p); }
void SetPolyGT3(POLY_GT3* p) { setPolyGT3(p); }
void SetPolyG4(POLY_G4* p) { setPolyG4(p); }
void SetPolyGT4(POLY_GT4* p) { setPolyGT4(p); }
void SetSemiTrans(void* p, int abe) { setSemiTrans(p, abe); }
void SetSprt(SPRT* p) { setSprt(p); }
void SetSprt16(SPRT_16* p) { setSprt16(p); }
void SetSprt8(SPRT_8* p) { setSprt8(p); }
void SetTile(TILE* p) { setTile(p); }
int GetGraphType(void) {
// always 0 in SOTN
return 0;
}