From 6fab29a1fd2850d5c48f94f7024ee765c2dbfaee Mon Sep 17 00:00:00 2001 From: dbalatoni13 <40299962+dbalatoni13@users.noreply.github.com> Date: Sat, 19 Apr 2025 03:15:44 +0200 Subject: [PATCH] More fixes and trying to get 3D rendering done --- CMakeLists.txt | 8 + include/dolphin/ar.h | 2 +- include/game/animdata.h | 7 + include/game/hsfanim.h | 8 +- src/REL/bootDll/main.c | 3 - src/REL/mentDll/main.c | 6 + src/REL/modeseldll/modesel.c | 2 - src/game/EnvelopeExec.c | 4 + src/game/data.c | 5 + src/game/hsfanim.c | 33 +++- src/game/hsfdraw.c | 323 +++++++++++++++++++++++++++++++++-- src/game/hsfload.c | 91 ++++++---- src/game/hsfman.c | 11 +- src/game/sprman.c | 18 +- src/port/ar.c | 2 +- src/port/audio.c | 14 +- src/port/stubs.c | 8 +- 17 files changed, 461 insertions(+), 84 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 51bc4561..419f2f30 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -158,6 +158,10 @@ if (MSVC) set_source_files_properties(extern/longjmp_win64/longjmp_win64.asm PROPERTIES LANGUAGE ASM_MASM) endif () target_link_options(dol PRIVATE "/DEF:${CMAKE_SOURCE_DIR}/dol.def") + target_compile_options(dol PRIVATE "/Zi") + target_compile_options(dol PRIVATE "/Ob0") + target_compile_options(dol PRIVATE "/Od") + target_compile_options(dol PRIVATE "/RTC1") else () # target_compile_options(dol PRIVATE "-fvisibility=hidden") # target_link_options(dol PRIVATE "LINKER:--version-script=${CMAKE_CURRENT_SOURCE_DIR}/dol.map") @@ -187,6 +191,10 @@ foreach (dir ${REL_DIRS}) target_include_directories(${dir} PRIVATE include build/GMPE01_00/include) if (MSVC) set_target_properties(${dir} PROPERTIES LINK_FLAGS "/EXPORT:ObjectSetup") + target_compile_options(${dir} PRIVATE "/Zi") + target_compile_options(${dir} PRIVATE "/Ob0") + target_compile_options(${dir} PRIVATE "/Od") + target_compile_options(${dir} PRIVATE "/RTC1") elseif (NOT CMAKE_SYSTEM_NAME STREQUAL Windows) target_compile_options(${dir} PRIVATE "-fvisibility=hidden") target_link_options(${dir} PRIVATE "LINKER:--version-script=${CMAKE_CURRENT_SOURCE_DIR}/rel.map") diff --git a/include/dolphin/ar.h b/include/dolphin/ar.h index db0adaf3..bbdea48a 100644 --- a/include/dolphin/ar.h +++ b/include/dolphin/ar.h @@ -20,7 +20,7 @@ typedef void (*ARCallback)(void); ARCallback ARRegisterDMACallback(ARCallback callback); u32 ARGetDMAStatus(void); -void ARStartDMA(u32 type, u32 mainmem_addr, u32 aram_addr, u32 length); +void ARStartDMA(u32 type, uintptr_t mainmem_addr, u32 aram_addr, u32 length); u32 ARInit(u32* stack_index_addr, u32 num_entries); u32 ARGetBaseAddress(void); BOOL ARCheckInit(void); diff --git a/include/game/animdata.h b/include/game/animdata.h index 63876d94..b4199a7e 100644 --- a/include/game/animdata.h +++ b/include/game/animdata.h @@ -78,6 +78,13 @@ typedef struct anim_data { /* 0x08 */ AnimBankData *bank; /* 0x0C */ AnimPatData *pat; /* 0x10 */ AnimBmpData *bmp; +#ifdef TARGET_PC + u32 valid; +#endif } AnimData; //sizeof 0x14 +#ifdef TARGET_PC +#define ANIM_DATA_ALLOCATION_VALID 0xD3D3D3D3 +#endif + #endif diff --git a/include/game/hsfanim.h b/include/game/hsfanim.h index c2dc2c4e..e251c5fb 100644 --- a/include/game/hsfanim.h +++ b/include/game/hsfanim.h @@ -9,6 +9,10 @@ typedef struct model_data ModelData; typedef struct particle_data ParticleData; +#ifdef TARGET_PC +typedef void (*ParticleDLCallFunc)(ParticleData *particle); +#endif + typedef void (*ParticleHook)(ModelData *model, ParticleData *particle, Mtx matrix); typedef struct { @@ -45,11 +49,11 @@ struct particle_data { /* 0x34 */ u32 unk_34; /* 0x38 */ s32 unk_38; /* 0x3C */ u32 unk_3C; - /* 0x40 */ s32 unk_40; + /* 0x40 */ s32 unk_40; // dlSize /* 0x44 */ AnimData *unk_44; /* 0x48 */ HsfanimStruct01 *unk_48; /* 0x4C */ Vec *unk_4C; - /* 0x50 */ void *unk_50; + /* 0x50 */ void *unk_50; // dlPtr /* 0x54 */ ParticleHook unk_54; }; // Size 0x58 diff --git a/src/REL/bootDll/main.c b/src/REL/bootDll/main.c index 391a9065..3850bc7d 100644 --- a/src/REL/bootDll/main.c +++ b/src/REL/bootDll/main.c @@ -546,8 +546,6 @@ void ObjectSetup(void) s16 sprite; AnimData *sprite_data; s16 i; -#ifdef __MWERKS__ - // TODO PC titleMdlId[0] = model = Hu3DModelCreateFile(TITLE_CHAR_HSF); Hu3DModelAttrSet(model, HU3D_ATTR_DISPOFF); Hu3DModelAttrSet(model, HU3D_MOTATTR_LOOP); @@ -559,7 +557,6 @@ void ObjectSetup(void) Hu3DModelAttrSet(model, HU3D_MOTATTR_LOOP); Hu3DModelCameraInfoSet(model, 1); Hu3DModelLightInfoSet(model, 1); -#endif #if VERSION_NTSC bootGrpId = HuSprGrpCreate(4); #else diff --git a/src/REL/mentDll/main.c b/src/REL/mentDll/main.c index db8375f3..789030fc 100644 --- a/src/REL/mentDll/main.c +++ b/src/REL/mentDll/main.c @@ -4,6 +4,7 @@ #include "game/armem.h" #include "game/chrman.h" #include "game/hsfdraw.h" +#include "game/hsfex.h" #include "game/hsfman.h" #include "game/hsfmotion.h" #include "game/minigame_seq.h" @@ -15,6 +16,11 @@ #include "game/window.h" #include "game/wipe.h" +#ifndef __MWERKS__ +extern s32 rand8(void); +#include "game/audio.h" +#endif + typedef struct MentDllUnkBssE4Struct { /* 0x00 */ s32 unk_00; /* 0x04 */ s32 unk_04; diff --git a/src/REL/modeseldll/modesel.c b/src/REL/modeseldll/modesel.c index 42f3d771..1501d249 100644 --- a/src/REL/modeseldll/modesel.c +++ b/src/REL/modeseldll/modesel.c @@ -31,8 +31,6 @@ s16 lbl_1_bss_80; void fn_1_3668(void); -// Scratch is at https://decomp.me/scratch/iirXp -// Register allocation issues at line 180 with load of 1.0 double constant s32 fn_1_2490(void) { float sp10[2]; diff --git a/src/game/EnvelopeExec.c b/src/game/EnvelopeExec.c index 2a890986..f0f2e4a5 100644 --- a/src/game/EnvelopeExec.c +++ b/src/game/EnvelopeExec.c @@ -126,6 +126,10 @@ static void SetEnvelopMtx(HsfObject *arg0, HsfObject *arg1, Mtx arg2) { } void EnvelopeProc(HsfData *arg0) { +#ifdef TARGET_PC + // TODO PC still buggy + return; +#endif HsfMatrix *temp_r31; HsfObject *temp_r29; Mtx sp8; diff --git a/src/game/data.c b/src/game/data.c index 5376eab5..f962c140 100644 --- a/src/game/data.c +++ b/src/game/data.c @@ -337,7 +337,12 @@ void *HuDataReadNum(s32 data_num, s32 num) } read_stat = &ReadDataStat[status]; GetFileInfo(read_stat, data_num & 0xFFFF); +#ifdef TARGET_PC + // TODO PC why is the allocation invalid if we use HEAP_SYSTEM? + buf = HuMemDirectMallocNum(HEAP_DATA, DATA_EFF_SIZE(read_stat->raw_len), num); +#else buf = HuMemDirectMallocNum(HEAP_SYSTEM, DATA_EFF_SIZE(read_stat->raw_len), num); +#endif if(buf) { HuDecodeData(read_stat->file, buf, read_stat->raw_len, read_stat->comp_type); } diff --git a/src/game/hsfanim.c b/src/game/hsfanim.c index a40b8c3b..42ed3877 100755 --- a/src/game/hsfanim.c +++ b/src/game/hsfanim.c @@ -489,6 +489,29 @@ void Hu3DTexScrollPauseDisableSet(s16 arg0, s32 arg1) { } } +#ifdef TARGET_PC +static void Hu3DParticleCallDisplayList(ParticleData *particle) +{ + s32 i; + GXBegin(GX_QUADS, GX_VTXFMT0, particle->unk_30 * 4); + for (i = 0; i < particle->unk_30; i++) { + GXPosition1x16(i*4); + GXColor1x16(i); + GXTexCoord1x16(0); + GXPosition1x16((i*4)+1); + GXColor1x16(i); + GXTexCoord1x16(1); + GXPosition1x16((i*4)+2); + GXColor1x16(i); + GXTexCoord1x16(2); + GXPosition1x16((i*4)+3); + GXColor1x16(i); + GXTexCoord1x16(3); + } + GXEnd(); +} +#endif + s16 Hu3DParticleCreate(AnimData *arg0, s16 arg1) { ModelData *temp_r28; ParticleData *temp_r31; @@ -530,6 +553,7 @@ s16 Hu3DParticleCreate(AnimData *arg0, s16 arg1) { for (i = 0; i < arg1 * 4; i++, var_r27++) { var_r27->x = var_r27->y = var_r27->z = 0.0f; } +#ifndef TARGET_PC temp_r24 = HuMemDirectMallocNum(HEAP_DATA, arg1 * 0x60 + 0x80, temp_r28->unk_48); temp_r31->unk_50 = temp_r24; DCInvalidateRange(temp_r24, arg1 * 0x60 + 0x80); @@ -550,6 +574,7 @@ s16 Hu3DParticleCreate(AnimData *arg0, s16 arg1) { GXTexCoord1x16(3); } temp_r31->unk_40 = GXEndDisplayList(); +#endif return temp_r25; } @@ -828,15 +853,19 @@ static void particleFunc(ModelData *arg0, Mtx arg1) { } GXClearVtxDesc(); GXSetVtxDesc(GX_VA_POS, GX_INDEX16); - GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_RGBA6, 0); + GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_F32, 0); GXSETARRAY(GX_VA_POS, temp_r31->unk_4C, temp_r31->unk_30 * 4 * sizeof(Vec), sizeof(Vec)); GXSetVtxDesc(GX_VA_CLR0, GX_INDEX16); GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_CLR0, GX_CLR_RGBA, GX_RGBA8, 0); GXSETARRAY(GX_VA_CLR0, &temp_r31->unk_48->unk40, temp_r31->unk_30 * sizeof(GXColor), 0x44); GXSetVtxDesc(GX_VA_TEX0, GX_INDEX16); - GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_TEX_ST, GX_RGBA6, 0); + GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_TEX_ST, GX_F32, 0); GXSETARRAY(GX_VA_TEX0, baseST, sizeof(baseST), 8); +#ifdef TARGET_PC + Hu3DParticleCallDisplayList(temp_r31); +#else GXCallDisplayList(temp_r31->unk_50, temp_r31->unk_40); +#endif } if (shadowModelDrawF == 0) { if (!(temp_r31->unk_2D & 2) && Hu3DPauseF == 0) { diff --git a/src/game/hsfdraw.c b/src/game/hsfdraw.c index c225d85d..79bdb7f2 100755 --- a/src/game/hsfdraw.c +++ b/src/game/hsfdraw.c @@ -29,6 +29,7 @@ static void objReplica(ModelData *arg0, HsfObject *arg1); static void ObjDraw(HsfDrawObject *arg0); static void MDObjCall(HsfData *arg0, HsfObject *arg1); static void MDObjMesh(HsfData *arg0, HsfObject *arg1); +static void FaceDrawCallDisplayList(HsfObject *arg0, HsfFace *arg1); static void MDFaceDraw(HsfObject *arg0, HsfFace *arg1); static s32 MakeCalcNBT(HsfObject *arg0, HsfFace *arg1, s16 arg2, s16 arg3); static s32 MakeNBT(HsfObject *arg0, HsfFace *arg1, s16 arg2, s16 arg3); @@ -189,10 +190,6 @@ static void objCall(ModelData *arg0, HsfObject *arg1) static void objMesh(ModelData *arg0, HsfObject *arg1) { -#ifdef TARGET_PC - // TODO PC - return; -#endif HsfDrawObject *temp_r29; HsfConstData *temp_r25; HsfTransform *var_r30; @@ -752,12 +749,20 @@ static void FaceDraw(HsfDrawObject *arg0, HsfFace *arg1) } SetTevStageTex(arg0, temp_r30); } +#ifdef TARGET_PC + FaceDrawCallDisplayList(arg0->object, arg1); +#else sp28 = (u8 *)DLBufStartP + DrawData[drawCnt].dlOfs; GXCallDisplayList(sp28, DrawData[drawCnt].dlSize); +#endif } else { +#ifdef TARGET_PC + FaceDrawCallDisplayList(arg0->object, arg1); +#else sp28 = (u8 *)DLBufStartP + DrawData[drawCnt].dlOfs; GXCallDisplayList(sp28, DrawData[drawCnt].dlSize); +#endif } drawCnt++; } @@ -1806,16 +1811,24 @@ static void FaceDrawShadow(HsfDrawObject *arg0, HsfFace *arg1) } GXSetChanCtrl(GX_COLOR0A0, GX_FALSE, GX_SRC_REG, GX_SRC_VTX, GX_LIGHT_NULL, GX_DF_NONE, GX_AF_NONE); GXSetChanCtrl(GX_COLOR1A1, GX_FALSE, GX_SRC_REG, GX_SRC_VTX, GX_LIGHT_NULL, GX_DF_NONE, GX_AF_NONE); +#ifdef TARGET_PC + FaceDrawCallDisplayList(arg0->object, arg1); +#else var_r26 = (u8 *)DLBufStartP + DrawData[drawCnt].dlOfs; GXCallDisplayList(var_r26, DrawData[drawCnt].dlSize); +#endif } else { if (!(temp_r27->flags & 0x400)) { drawCnt++; return; } +#ifdef TARGET_PC + FaceDrawCallDisplayList(arg0->object, arg1); +#else var_r26 = (u8 *)DLBufStartP + DrawData[drawCnt].dlOfs; GXCallDisplayList(var_r26, DrawData[drawCnt].dlSize); +#endif } drawCnt++; } @@ -2514,12 +2527,9 @@ void MakeDisplayList(s16 arg0, uintptr_t arg1) var_r30 = &Hu3DData[arg0]; curModelID = arg0; mallocNo = arg1; -#ifdef __MWERKS__ - // TODO PC faceNumBuf = HuMemDirectMallocNum(HEAP_DATA, 0x800 * sizeof(u16), mallocNo); MDObjCall(temp_r31, temp_r31->root); HuMemDirectFree(faceNumBuf); -#endif if (var_r30->attr & HU3D_ATTR_SHADOW) { Hu3DShadowCamBit++; } @@ -2613,6 +2623,205 @@ HsfConstData *ObjConstantMake(HsfObject *arg0, u32 arg1) return temp_r3; } +#ifdef TARGET_PC +static void FaceDrawCallDisplayList(HsfObject *arg0, HsfFace *arg1) +{ + s32 temp_r28; + s16 var_r26 = -1; + s16 var_r27; + s32 var_r25; + s16 *var_r24; + HsfMaterial *temp_r30 = &arg0->data.material[arg1->mat & 0xFFF]; + if (temp_r30->numAttrs == 0) { + var_r25 = 0; + } + else { + var_r25 = 1; + for (var_r27 = 0; var_r27 < temp_r30->numAttrs; var_r27++) { + if (arg0->data.attribute[temp_r30->attrs[var_r27]].unk14 != 0.0) { + var_r26 = var_r27; + } + } + } + switch (arg1->type & 7) { + case 0: + case 1: + break; + case 2: + GXBegin(GX_TRIANGLES, GX_VTXFMT0, DrawData[drawCnt].polyCnt * 3); + for (var_r27 = 0; var_r27 < DrawData[drawCnt].polyCnt; var_r27++, arg1++) { + GXPosition1x16(arg1->indices[0][0]); + if (var_r26 == -1) { + GXNormal1x16(arg1->indices[0][1]); + } + else { + MakeCalcNBT(arg0, arg1, 0, 1); + } + if (temp_r30->vtxMode == 5) { + temp_r28 = arg1->indices[0][2]; + GXColor1x16(temp_r28); + } + if (var_r25 != 0) { + GXTexCoord1x16(arg1->indices[0][3]); + } + GXPosition1x16(arg1->indices[2][0]); + if (var_r26 == -1) { + GXNormal1x16(arg1->indices[2][1]); + } + else { + MakeNBT(arg0, arg1, 2, 0); + } + if (temp_r30->vtxMode == 5) { + temp_r28 = arg1->indices[2][2]; + GXColor1x16(temp_r28); + } + if (var_r25 != 0) { + GXTexCoord1x16(arg1->indices[2][3]); + } + GXPosition1x16(arg1->indices[1][0]); + if (var_r26 == -1) { + GXNormal1x16(arg1->indices[1][1]); + } + else { + MakeNBT(arg0, arg1, 1, 2); + } + if (temp_r30->vtxMode == 5) { + temp_r28 = arg1->indices[1][2]; + GXColor1x16(temp_r28); + } + if (var_r25 != 0) { + GXTexCoord1x16(arg1->indices[1][3]); + } + } + break; + case 3: + GXBegin(GX_QUADS, GX_VTXFMT0, DrawData[drawCnt].polyCnt * 4); + for (var_r27 = 0; var_r27 < DrawData[drawCnt].polyCnt; var_r27++, arg1++) { + GXPosition1x16(arg1->indices[0][0]); + if (var_r26 == -1) { + GXNormal1x16(arg1->indices[0][1]); + } + else { + MakeCalcNBT(arg0, arg1, 0, 1); + } + if (temp_r30->vtxMode == 5) { + temp_r28 = arg1->indices[0][2]; + GXColor1x16(temp_r28); + } + if (var_r25 != 0) { + GXTexCoord1x16(arg1->indices[0][3]); + } + GXPosition1x16(arg1->indices[2][0]); + if (var_r26 == -1) { + GXNormal1x16(arg1->indices[2][1]); + } + else { + MakeNBT(arg0, arg1, 2, 0); + } + if (temp_r30->vtxMode == 5) { + temp_r28 = arg1->indices[2][2]; + GXColor1x16(temp_r28); + } + if (var_r25 != 0) { + GXTexCoord1x16(arg1->indices[2][3]); + } + GXPosition1x16(arg1->indices[3][0]); + if (var_r26 == -1) { + GXNormal1x16(arg1->indices[3][1]); + } + else { + MakeNBT(arg0, arg1, 3, 2); + } + if (temp_r30->vtxMode == 5) { + temp_r28 = arg1->indices[3][2]; + GXColor1x16(temp_r28); + } + if (var_r25 != 0) { + GXTexCoord1x16(arg1->indices[3][3]); + } + GXPosition1x16(arg1->indices[1][0]); + if (var_r26 == -1) { + GXNormal1x16(arg1->indices[1][1]); + } + else { + MakeNBT(arg0, arg1, 1, 3); + } + if (temp_r30->vtxMode == 5) { + temp_r28 = arg1->indices[1][2]; + GXColor1x16(temp_r28); + } + if (var_r25 != 0) { + GXTexCoord1x16(arg1->indices[1][3]); + } + } + break; + case 4: + // TODO PC fix size + GXBegin(GX_TRIANGLESTRIP, GX_VTXFMT0, DrawData[drawCnt].polyCnt); + GXPosition1x16(arg1->indices[0][0]); + if (var_r26 == -1) { + GXNormal1x16(arg1->indices[0][1]); + } + else { + MakeCalcNBT(arg0, arg1, 0, 1); + } + if (temp_r30->vtxMode == 5) { + temp_r28 = arg1->indices[0][2]; + GXColor1x16(temp_r28); + } + if (var_r25 != 0) { + GXTexCoord1x16(arg1->indices[0][3]); + } + GXPosition1x16(arg1->indices[2][0]); + if (var_r26 == -1) { + GXNormal1x16(arg1->indices[2][1]); + } + else { + MakeNBT(arg0, arg1, 2, 0); + } + if (temp_r30->vtxMode == 5) { + temp_r28 = arg1->indices[2][2]; + GXColor1x16(temp_r28); + } + if (var_r25 != 0) { + GXTexCoord1x16(arg1->indices[2][3]); + } + GXPosition1x16(arg1->indices[1][0]); + if (var_r26 == -1) { + GXNormal1x16(arg1->indices[1][1]); + } + else { + MakeNBT(arg0, arg1, 1, 2); + } + if (temp_r30->vtxMode == 5) { + temp_r28 = arg1->indices[1][2]; + GXColor1x16(temp_r28); + } + if (var_r25 != 0) { + GXTexCoord1x16(arg1->indices[1][3]); + } + var_r24 = arg1->strip.data; + for (var_r27 = 0; var_r27 < arg1->strip.count; var_r27++, var_r24 += 4) { + GXPosition1x16(var_r24[0]); + if (var_r26 == -1) { + GXNormal1x16(var_r24[1]); + } + else { + MakeCalcNBT(arg0, arg1, 0, 1); + } + if (temp_r30->vtxMode == 5) { + temp_r28 = var_r24[2]; + GXColor1x16(temp_r28); + } + if (var_r25 != 0) { + GXTexCoord1x16(var_r24[3]); + } + } + break; + } +} +#endif + static void MDFaceDraw(HsfObject *arg0, HsfFace *arg1) { HsfMaterial *temp_r30; @@ -2670,6 +2879,96 @@ static void MDFaceDraw(HsfObject *arg0, HsfFace *arg1) Hu3DObjInfoP->flags |= 0x10000; } faceCnt = 0; +#ifdef TARGET_PC + // set flags and calculate faceCnt are left here + switch (arg1->type & 7) { + case 0: + case 1: + break; + case 2: + for (var_r27 = 0; var_r27 < faceNumBuf[drawCnt] / 3; var_r27++, arg1++) { + if (temp_r30->vtxMode == 5) { + temp_r28 = arg1->indices[0][2]; + if (((GXColor *)arg0->data.color->data)[temp_r28].a != 0xFF) { + Hu3DObjInfoP->flags |= 0x4001; + } + } + if (temp_r30->vtxMode == 5) { + temp_r28 = arg1->indices[2][2]; + if (((GXColor *)arg0->data.color->data)[temp_r28].a != 0xFF) { + Hu3DObjInfoP->flags |= 0x4001; + } + } + if (temp_r30->vtxMode == 5) { + temp_r28 = arg1->indices[1][2]; + if (((GXColor *)arg0->data.color->data)[temp_r28].a != 0xFF) { + Hu3DObjInfoP->flags |= 0x4001; + } + } + } + faceCnt = faceNumBuf[drawCnt] / 3; + break; + case 3: + for (var_r27 = 0; var_r27 < faceNumBuf[drawCnt] / 4; var_r27++, arg1++) { + if (temp_r30->vtxMode == 5) { + temp_r28 = arg1->indices[0][2]; + if (((GXColor *)arg0->data.color->data)[temp_r28].a != 0xFF) { + Hu3DObjInfoP->flags |= 0x4001; + } + } + if (temp_r30->vtxMode == 5) { + temp_r28 = arg1->indices[2][2]; + if (((GXColor *)arg0->data.color->data)[temp_r28].a != 0xFF) { + Hu3DObjInfoP->flags |= 0x4001; + } + } + if (temp_r30->vtxMode == 5) { + temp_r28 = arg1->indices[3][2]; + if (((GXColor *)arg0->data.color->data)[temp_r28].a != 0xFF) { + Hu3DObjInfoP->flags |= 0x4001; + } + } + if (temp_r30->vtxMode == 5) { + temp_r28 = arg1->indices[1][2]; + if (((GXColor *)arg0->data.color->data)[temp_r28].a != 0xFF) { + Hu3DObjInfoP->flags |= 0x4001; + } + } + } + faceCnt = faceNumBuf[drawCnt] / 4; + break; + case 4: + if (temp_r30->vtxMode == 5) { + temp_r28 = arg1->indices[0][2]; + if (((GXColor *)arg0->data.color->data)[temp_r28].a != 0xFF) { + Hu3DObjInfoP->flags |= 0x4001; + } + } + if (temp_r30->vtxMode == 5) { + temp_r28 = arg1->indices[2][2]; + if (((GXColor *)arg0->data.color->data)[temp_r28].a != 0xFF) { + Hu3DObjInfoP->flags |= 0x4001; + } + } + if (temp_r30->vtxMode == 5) { + temp_r28 = arg1->indices[1][2]; + if (((GXColor *)arg0->data.color->data)[temp_r28].a != 0xFF) { + Hu3DObjInfoP->flags |= 0x4001; + } + } + var_r24 = arg1->strip.data; + for (var_r27 = 0; var_r27 < arg1->strip.count; var_r27++, var_r24 += 4) { + if (temp_r30->vtxMode == 5) { + temp_r28 = var_r24[2]; + if (((GXColor *)arg0->data.color->data)[temp_r28].a != 0xFF) { + Hu3DObjInfoP->flags |= 0x4001; + } + } + } + faceCnt = arg1->strip.count + 1; + break; + } +#else switch (arg1->type & 7) { case 0: case 1: @@ -2729,9 +3028,6 @@ static void MDFaceDraw(HsfObject *arg0, HsfFace *arg1) GXTexCoord1x16(arg1->indices[1][3]); } } -#ifdef TARGET_PC - GXEnd(); -#endif faceCnt = faceNumBuf[drawCnt] / 3; break; case 3: @@ -2806,9 +3102,6 @@ static void MDFaceDraw(HsfObject *arg0, HsfFace *arg1) GXTexCoord1x16(arg1->indices[1][3]); } } -#ifdef TARGET_PC - GXEnd(); -#endif faceCnt = faceNumBuf[drawCnt] / 4; break; case 4: @@ -2884,12 +3177,10 @@ static void MDFaceDraw(HsfObject *arg0, HsfFace *arg1) GXTexCoord1x16(var_r24[3]); } } -#ifdef TARGET_PC - GXEnd(); -#endif faceCnt = arg1->strip.count + 1; break; } +#endif temp_r3 = GXEndDisplayList(); DrawData[drawCnt].dlSize = temp_r3; DrawData[drawCnt].polyCnt = faceCnt; diff --git a/src/game/hsfload.c b/src/game/hsfload.c index c5eebe8b..5223ed1f 100644 --- a/src/game/hsfload.c +++ b/src/game/hsfload.c @@ -1896,43 +1896,62 @@ static char *GetMotionString(u16 *str_ofs) void KillHSF(HsfData *data) { s32 i, j; - HuMemDirectFree(data->attribute); - HuMemDirectFree(data->bitmap); - HuMemDirectFree(data->cenv); - HuMemDirectFree(data->skeleton); - for (i = 0; i < data->faceCnt; i++) { - HuMemDirectFree(data->face[i].data); - } - HuMemDirectFree(data->face); - HuMemDirectFree(data->material); - for (i = 0; i < data->motionCnt; i++) { - HsfMotion *motion = &data->motion[i]; - for (j = 0; j < motion->numTracks; j++) { - HsfTrack *track = motion->track; - if (track->type == HSF_TRACK_ATTRIBUTE && track->curveType == HSF_CURVE_BITMAP) { - // in this case we needed to allocate space for HsfBitmapKey structs - HuMemDirectFree(track->dataTop); - } + // if (data->attributeCnt) + // HuMemDirectFree(data->attribute); + // if (data->bitmapCnt) + // HuMemDirectFree(data->bitmap); + // if (data->skeletonCnt) + // HuMemDirectFree(data->skeleton); + // if (data->faceCnt) { + // for (i = 0; i < data->faceCnt; i++) { + // HuMemDirectFree(data->face[i].data); + // } + // HuMemDirectFree(data->face); + // } + // if (data->materialCnt) + // HuMemDirectFree(data->material); + // if (data->motionCnt) { + // for (i = 0; i < data->motionCnt; i++) { + // HsfMotion *motion = &data->motion[i]; + // for (j = 0; j < motion->numTracks; j++) { + // // HsfTrack *track = motion->track; + // // if (track->type == HSF_TRACK_ATTRIBUTE && track->curveType == HSF_CURVE_BITMAP) { + // // // in this case we needed to allocate space for HsfBitmapKey structs + // // HuMemDirectFree(track->dataTop); + // // } + // } + // // HuMemDirectFree(motion->track); + // } + // // HuMemDirectFree(data->motion); + // } + // if (data->normalCnt) + // HuMemDirectFree(data->normal); + // if (data->objectCnt) + // HuMemDirectFree(data->object); + // if (data->matrixCnt) + // HuMemDirectFree(data->matrix); + // if (data->paletteCnt) + // HuMemDirectFree(data->palette); + // if (data->stCnt) + // HuMemDirectFree(data->st); + // if (data->vertexCnt) + // HuMemDirectFree(data->vertex); + if (data->cenvCnt) { + for (i = 0; i < data->cenvCnt; i++) { + HsfCenv *cenv = &data->cenv[i]; + HuMemDirectFree(cenv->dualData); + HuMemDirectFree(cenv->multiData); } - HuMemDirectFree(motion->track); + HuMemDirectFree(data->cenv); } - HuMemDirectFree(data->motion); - HuMemDirectFree(data->normal); - HuMemDirectFree(data->object); - HuMemDirectFree(data->matrix); - HuMemDirectFree(data->palette); - HuMemDirectFree(data->st); - HuMemDirectFree(data->vertex); - for (i = 0; i < data->cenvCnt; i++) { - HsfCenv *cenv = &data->cenv[i]; - HuMemDirectFree(cenv->dualData); - HuMemDirectFree(cenv->multiData); - } - HuMemDirectFree(data->cenv); - HuMemDirectFree(data->cluster); - HuMemDirectFree(data->part); - HuMemDirectFree(data->shape); - HuMemDirectFree(data->mapAttr); - HuMemDirectFree(data->symbol); + if (data->clusterCnt) + HuMemDirectFree(data->cluster); + if (data->partCnt) + HuMemDirectFree(data->part); + if (data->shapeCnt) + HuMemDirectFree(data->shape); + if (data->mapAttrCnt) + HuMemDirectFree(data->mapAttr); + // HuMemDirectFree(data->symbol); } #endif diff --git a/src/game/hsfman.c b/src/game/hsfman.c index fdb1cea4..04820c45 100644 --- a/src/game/hsfman.c +++ b/src/game/hsfman.c @@ -2033,10 +2033,13 @@ void Hu3DShadowExec(void) { GXSetChanCtrl(GX_COLOR0A0, 0, GX_SRC_REG, GX_SRC_REG, 0, GX_DF_CLAMP, GX_AF_NONE); GXBegin(GX_QUADS, GX_VTXFMT0, 4); - GXColor3u8(0, 0, 0); - GXColor3u8(1, 0, 0); - GXColor3u8(1, 1, 0); - GXColor3u8(0, 1, 0); + GXPosition3u8(0, 0, 0); + GXPosition3u8(1, 0, 0); + GXPosition3u8(1, 1, 0); + GXPosition3u8(0, 1, 0); +#ifdef TARGET_PC + GXEnd(); +#endif } s16 Hu3DProjectionCreate(void *arg0, f32 arg8, f32 arg9, f32 argA) { diff --git a/src/game/sprman.c b/src/game/sprman.c index 037ccd43..98a9b3ff 100644 --- a/src/game/sprman.c +++ b/src/game/sprman.c @@ -218,17 +218,21 @@ AnimData *HuSprAnimRead(void *data) AnimBankData *bank; AnimPatData *pat; + AnimData *anim = data; #ifdef TARGET_PC - AnimData *anim = HuMemDirectMallocNum(HEAP_DATA, sizeof(AnimData), MEMORY_DEFAULT_NUM); - byteswap_animdata(data, anim); -#else - AnimData *anim = (AnimData *)data; -#endif - if((uintptr_t)anim->bank & ~0xFFFF) { - // TODO PC it's a problem if we get here, we need to find a way to not allocate again in that case + if (anim->valid == ANIM_DATA_ALLOCATION_VALID) { anim->useNum++; return anim; } + anim = HuMemDirectMallocNum(HEAP_DATA, sizeof(AnimData), MEMORY_DEFAULT_NUM); + byteswap_animdata(data, anim); + anim->valid = ANIM_DATA_ALLOCATION_VALID; +#else + if((uintptr_t)anim->bank & ~0xFFFF) { + anim->useNum++; + return anim; + } +#endif bank = (void *)((uintptr_t)anim->bank+(uintptr_t)data); #ifdef TARGET_PC bank = HuMemDirectMallocNum(HEAP_DATA, anim->bankNum * sizeof(AnimBankData), MEMORY_DEFAULT_NUM); diff --git a/src/port/ar.c b/src/port/ar.c index 71a1ae93..10c2fc37 100644 --- a/src/port/ar.c +++ b/src/port/ar.c @@ -20,7 +20,7 @@ u32 ARGetSize() return sizeof(ARAM); } -void ARStartDMA(u32 type, u32 mainmem_addr, u32 aram_addr, u32 length) +void ARStartDMA(u32 type, uintptr_t mainmem_addr, u32 aram_addr, u32 length) { switch (type) { diff --git a/src/port/audio.c b/src/port/audio.c index 0e5423df..07a9dfcb 100644 --- a/src/port/audio.c +++ b/src/port/audio.c @@ -316,7 +316,7 @@ s32 HuAudSeqMidiCtrlGet(s32 musNo, s8 channel, s8 ctrl) { s32 HuAudSStreamPlay(s16 streamId) { MSM_STREAMPARAM param; - s32 result; + s32 result = 0; if (musicOffF != 0 || omSysExitReq != 0) { return 0; @@ -502,12 +502,12 @@ void HuAudSndCommonGrpSet(s16 grpId, s32 groupCheck) { // while ((msmMusGetNumPlay(1) != 0 || msmSeGetNumPlay(1) != 0) // && OSTicksToMilliseconds(OSGetTick() - osTick) < 500); OSReport("CommonGrpSet %d\n", grpId); - if (groupCheck != 0) { - // err = msmSysDelGroupBase(0); - if (err < 0) { - OSReport("Del Group Error %d\n", err); - } - } + // if (groupCheck != 0) { + // // err = msmSysDelGroupBase(0); + // if (err < 0) { + // OSReport("Del Group Error %d\n", err); + // } + // } // buf = HuMemDirectMalloc(HEAP_DATA, msmSysGetSampSize(grpId)); // msmSysLoadGroupBase(grpId, buf); // HuMemDirectFree(buf); diff --git a/src/port/stubs.c b/src/port/stubs.c index 75c5ca5e..fb829d75 100644 --- a/src/port/stubs.c +++ b/src/port/stubs.c @@ -624,18 +624,20 @@ void GXUnknownu16(const u16 x) void GXWaitDrawDone(void) { - puts("GXWaitDrawDone is a stub"); + // puts("GXWaitDrawDone is a stub"); } void GXSetTevIndTile(GXTevStageID tev_stage, GXIndTexStageID ind_stage, u16 tilesize_s, u16 tilesize_t, u16 tilespacing_s, u16 tilespacing_t, GXIndTexFormat format, GXIndTexMtxID matrix_sel, GXIndTexBiasSel bias_sel, GXIndTexAlphaSel alpha_sel) { - puts("GXSetTevIndTile is a stub"); + // TODO + // puts("GXSetTevIndTile is a stub"); } void GXSetTexCoordScaleManually(GXTexCoordID coord, u8 enable, u16 ss, u16 ts) { - puts("GXSetTexCoordScaleManually is a stub"); + // TODO + // puts("GXSetTexCoordScaleManually is a stub"); } void GXResetWriteGatherPipe(void)