Skip to content

Commit

Permalink
Finish matching zConditional and mark xFog as matching (#294)
Browse files Browse the repository at this point in the history
* Finish matching zConditional

* Mark xFog as matching

Matches on the new patched compiler, no changes required.
  • Loading branch information
tgsm authored Jul 7, 2024
1 parent 40402ea commit c69187d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 35 deletions.
4 changes: 2 additions & 2 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ def Rel(lib_name: str, objects: List[Object]) -> Dict[str, Any]:
Object(Matching, "SB/Core/x/xEnv.cpp"),
Object(Matching, "SB/Core/x/xEvent.cpp"),
Object(NonMatching, "SB/Core/x/xFFX.cpp"),
Object(Equivalent, "SB/Core/x/xFog.cpp"),
Object(Matching, "SB/Core/x/xFog.cpp"),
Object(NonMatching, "SB/Core/x/xFont.cpp"),
Object(NonMatching, "SB/Core/x/xFX.cpp"),
Object(Matching, "SB/Core/x/xGroup.cpp"),
Expand Down Expand Up @@ -340,7 +340,7 @@ def Rel(lib_name: str, objects: List[Object]) -> Dict[str, Any]:
Object(Equivalent, "SB/Game/zAnimList.cpp"),
Object(NonMatching, "SB/Game/zAssetTypes.cpp"),
Object(NonMatching, "SB/Game/zCamera.cpp"),
Object(NonMatching, "SB/Game/zConditional.cpp"),
Object(Matching, "SB/Game/zConditional.cpp"),
Object(NonMatching, "SB/Game/zCutsceneMgr.cpp"),
Object(NonMatching, "SB/Game/zDispatcher.cpp"),
Object(NonMatching, "SB/Game/zEGenerator.cpp"),
Expand Down
2 changes: 0 additions & 2 deletions src/SB/Core/x/xFog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

#include <types.h>

// NON_MATCHING:
// function parameter loading order is swapped
void xFogClearFog()
{
iCameraSetFogParams(NULL, 0.0f);
Expand Down
48 changes: 18 additions & 30 deletions src/SB/Game/zConditional.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,21 @@ void zConditionalInit(void* b, void* asset)
zVarInit(zVarEntryTable);
}

struct UnknownTypeInheritingBase : xBase
{
int8* unknownPtr;
};

void zConditionalInit(xBase* b, zCondAsset* asset)
{
xBaseInit(b, asset);
b->eventFunc = (xBaseEventCB)zConditionalEventCB;
_zConditional* cond = (_zConditional*)b;

// ?? I think that they must have cast asset to some other type, and
// accessed a field of that other type, but I don't know what type it is.
UnknownTypeInheritingBase* object = (UnknownTypeInheritingBase*)b;
object->unknownPtr = (int8*)asset;
xBaseInit((xBase*)cond, asset);
cond->eventFunc = (xBaseEventCB)zConditionalEventCB;
cond->asset = asset;

if (b->linkCount != 0)
if (cond->linkCount != 0)
{
b->link = (xLinkAsset*)(object->unknownPtr + 24);
cond->link = (xLinkAsset*)(cond->asset + 1);
}
else
{
b->link = NULL;
cond->link = NULL;
}
}

Expand All @@ -54,7 +47,7 @@ void zConditionalLoad(_zConditional* ent, xSerial* s)
xBaseLoad(ent, s);
}

bool zConditional_Evaluate(_zConditional* c)
uint32 zConditional_Evaluate(_zConditional* c)
{
zVarEntry* v = NULL;
void* context = NULL;
Expand All @@ -81,40 +74,33 @@ bool zConditional_Evaluate(_zConditional* c)
switch (c->asset->op)
{
case CONDITION_EQ:
return temp == c->asset->constNum;
return temp == c->asset->constNum ? 1 : 0;

case CONDITION_GT:
return temp > c->asset->constNum;
return temp > c->asset->constNum ? 1 : 0;

case CONDITION_LT:
return temp < c->asset->constNum;
return temp < c->asset->constNum ? 1 : 0;

case CONDITION_GE:
return temp >= c->asset->constNum;
return temp >= c->asset->constNum ? 1 : 0;

case CONDITION_LE:
return temp <= c->asset->constNum;
return temp <= c->asset->constNum ? 1 : 0;

case CONDITION_NE:
return temp != c->asset->constNum;
return temp != c->asset->constNum ? 1 : 0;

default:
return 0;
}
}

#if 0
// This doesn't work because it's missing a single branch instruction
// The original assembly has a redundant branch instruction:
// /* 80052814 0004F614 48 00 00 48 */ b lbl_8005285C
// /* 80052818 0004F618 48 00 00 44 */ b lbl_8005285C
// But this code only generates a single one of those branch instructions,
// otherwise, it is identical.
int32 zConditionalEventCB(xBase* arg1, xBase* arg2, uint32 toEvent, const float32* fp, xBase* other)
{
switch (toEvent)
{
case eEventTrue:
case eEventEvaluate:
if (zConditional_Evaluate((_zConditional*)arg2))
{
zEntEvent(arg2, arg2, eEventTrue);
Expand All @@ -125,11 +111,13 @@ int32 zConditionalEventCB(xBase* arg1, xBase* arg2, uint32 toEvent, const float3
}
break;

case eEventTrue:
break;

case eEventReset:
zConditionalReset((_zConditional*)arg2);
break;
}

return eEventEnable;
}
#endif
2 changes: 1 addition & 1 deletion src/SB/Game/zConditional.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ void zConditionalInit(xBase* base, zCondAsset* asset);
void zConditionalInit(void* b, void* asset);
void zConditionalLoad(_zConditional* ent, xSerial* s);
void zConditionalSave(_zConditional* ent, xSerial* s);
bool zConditional_Evaluate(_zConditional* c);
uint32 zConditional_Evaluate(_zConditional* c);

#endif

0 comments on commit c69187d

Please sign in to comment.