x64 and hsfload improvements, build every REL (#582)

* Port some of hsfload.c

* More byteswaps in hsfload.c

* Finish hsfload besides cenv

* hsfload fixes

* Some x64 improvements

* More x64 improvements

* 64 bit improvements

* Link in lots of files

* Fix armem bug

* Fix dll killing, load modeseldll

* Fixes, clearing TODOs

* Tons of warning/error fixes

* Linux build fixes

* Add -fPIC flag to fix build on x64 linux

* GXSETARRAY sizes and misc fixes

* More fixes

* Build all RELs

* Implement C_Quat functions

* Fix PAL build
This commit is contained in:
Dávid Balatoni 2025-04-14 18:02:42 +02:00 committed by GitHub
parent bc19d2263b
commit 34cf507e3f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
186 changed files with 3256 additions and 1540 deletions

View file

@ -77,10 +77,10 @@ static void __DEMOInitMem()
void *arenaHi = OSGetArenaHi();
unsigned long fbSize = ((u16)(rmode->fbWidth + 15) & 0xFFF0) * rmode->xfbHeight * 2;
DemoFrameBuffer1 = (void *)(((u32)arenaLo + 0x1F) & 0xFFFFFFE0);
DemoFrameBuffer2 = (void *)(((u32)DemoFrameBuffer1 + fbSize + 0x1F) & 0xFFFFFFE0);
DemoFrameBuffer1 = (void *)(((uintptr_t)arenaLo + 0x1F) & ~0x1F);
DemoFrameBuffer2 = (void *)(((uintptr_t)DemoFrameBuffer1 + fbSize + 0x1F) & ~0x1F);
DemoCurrentBuffer = DemoFrameBuffer2;
arenaLo = (void *)(((u32)DemoFrameBuffer2 + fbSize + 0x1F) & 0xFFFFFFE0);
arenaLo = (void *)(((uintptr_t)DemoFrameBuffer2 + fbSize + 0x1F) & ~0x1F);
OSSetArenaLo(arenaLo);
if (((OSGetConsoleType() + 0xF0000000) == 4U) && ((OSGetPhysicalMemSize() + 0xFFC00000) != 0U)
&& (OSGetConsoleSimulatedMemSize() < 0x01800000U)) {
@ -91,9 +91,9 @@ static void __DEMOInitMem()
arenaHi = OSGetArenaHi();
arenaLo = OSInitAlloc(arenaLo, arenaHi, 1);
OSSetArenaLo(arenaLo);
arenaLo = (void *)(((u32)arenaLo + 0x1F) & 0xFFFFFFE0);
arenaHi = (void *)((u32)arenaHi & 0xFFFFFFE0);
OSSetCurrentHeap(OSCreateHeap((void *)(((u32)arenaLo)), arenaHi));
arenaLo = (void *)(((uintptr_t)arenaLo + 0x1F) & ~0x1F);
arenaHi = (void *)((uintptr_t)arenaHi & ~0x1F);
OSSetCurrentHeap(OSCreateHeap((void *)(((uintptr_t)arenaLo)), arenaHi));
OSSetArenaLo((arenaLo = arenaHi));
}
@ -210,13 +210,13 @@ static void LoadMemInfo()
arenaHi = OSGetArenaHi();
arenaLo = OSInitAlloc(arenaLo, arenaHi, 1);
OSSetArenaLo(arenaLo);
arenaLo = (void *)(((u32)arenaLo + 0x1F) & 0xFFFFFFE0);
arenaHi = (void *)((u32)arenaHi & 0xFFFFFFE0);
arenaLo = (void *)(((uintptr_t)arenaLo + 0x1F) & ~0x1F);
arenaHi = (void *)((uintptr_t)arenaHi & ~0x1F);
OSSetCurrentHeap(OSCreateHeap((void *)(((u32)arenaLo)), arenaHi));
OSSetArenaLo((arenaLo = arenaHi));
return;
}
memEntry = (void *)((u32)buf + 0x1F & 0xFFFFFFE0);
memEntry = (void *)((uintptr_t)buf + 0x1F & ~0x1F);
arenaHiOld = OSGetArenaHi();
simMemEnd = OSPhysicalToCached(OSGetConsoleSimulatedMemSize());
OSSetArenaHi(OSPhysicalToCached(OSGetPhysicalMemSize()));
@ -224,8 +224,8 @@ static void LoadMemInfo()
arenaHi = OSGetArenaHi();
arenaLo = OSInitAlloc(arenaLo, arenaHi, 1);
OSSetArenaLo(arenaLo);
arenaLo = (void *)(((u32)arenaLo + 0x1F) & 0xFFFFFFE0);
arenaHi = (void *)((u32)arenaHi & 0xFFFFFFE0);
arenaLo = (void *)(((uintptr_t)arenaLo + 0x1F) & ~0x1F);
arenaHi = (void *)((uintptr_t)arenaHi & ~0x1F);
OSSetCurrentHeap(OSCreateHeap((void *)(arenaLo), arenaHi));
OSSetArenaLo((arenaLo = arenaHi));
OSAllocFixed(&arenaHiOld, &simMemEnd);
@ -234,7 +234,7 @@ static void LoadMemInfo()
while (length) {
OSReport("loop\n");
transferLength = (length < 0x20) ? length : 0x20;
if (DVDReadPrio(&fileInfo, memEntry, (transferLength + 0x1F) & 0xFFFFFFE0, offset, 2) < 0) {
if (DVDReadPrio(&fileInfo, memEntry, (transferLength + 0x1F) & ~0x1F, offset, 2) < 0) {
OSPanic(__FILE__, 0x49F, "An error occurred when issuing read to /meminfo.bin\n");
}
indexMax = (transferLength / 8);

View file

@ -1367,7 +1367,6 @@ void C_MTXMultVecArray(const Mtx m, const Vec* srcBase, Vec* dstBase, u32 count)
void C_MTXROMultVecArray(const ROMtx m, const Vec *srcBase, Vec *dstBase, u32 count)
{
u32 i;
for (u32 i = 0; i < count; ++i) {
Vec* src = &srcBase[i];
Vec* dst = &dstBase[i];

View file

@ -14,6 +14,7 @@ void C_QUATAdd(const Quaternion *p, const Quaternion *q, Qtrn *r)
r->w = p->w + q->w;
}
#ifdef GEKKO
void PSQUATAdd(register const Quaternion *p, register const Quaternion *q, register Quaternion *r)
{
asm {
@ -27,7 +28,19 @@ void PSQUATAdd(register const Quaternion *p, register const Quaternion *q, regis
psq_st f0, 0x8(r5), 0, 0
}
}
#endif
#ifdef TARGET_PC
void C_QUATMultiply(const Quaternion *a, const Quaternion *b, Quaternion *ab)
{
ab->x = a->w * b->x + a->x * b->w + a->y * b->z - a->z * b->y;
ab->y = a->w * b->y - a->x * b->z + a->y * b->w + a->z * b->x;
ab->z = a->w * b->z + a->x * b->y - a->y * b->x + a->z * b->w;
ab->w = a->w * b->w - a->x * b->x - a->y * b->y - a->z * b->z;
}
#endif
#ifdef GEKKO
void PSQUATMultiply(register const Quaternion *a, register const Quaternion *b, register Quaternion *ab)
{
asm {
@ -55,7 +68,26 @@ void PSQUATMultiply(register const Quaternion *a, register const Quaternion *b,
psq_st f5, 8(ab), 0, 0
}
}
#endif
#ifdef TARGET_PC
void C_QUATNormalize(const Quaternion *src, Quaternion *unit)
{
float len = sqrtf(src->x * src->x + src->y * src->y + src->z * src->z + src->w * src->w);
if (len > 0.0f) {
float inv_len = 1.0f / len;
unit->x = src->x * inv_len;
unit->y = src->y * inv_len;
unit->z = src->z * inv_len;
unit->w = src->w * inv_len;
} else {
unit->x = unit->y = unit->z = 0.0f;
unit->w = 1.0f;
}
}
#endif
#ifdef GEKKO
void PSQUATNormalize(const register Quaternion *src, register Quaternion *unit)
{
// sdata2
@ -95,7 +127,27 @@ void PSQUATNormalize(const register Quaternion *src, register Quaternion *unit)
}
}
}
#endif
#ifdef TARGET_PC
void C_QUATInverse(const Quaternion *src, Quaternion *inv)
{
float len_squared = src->x * src->x + src->y * src->y + src->z * src->z + src->w * src->w;
if (len_squared > 0.0f) {
float inv_len_squared = 1.0f / len_squared;
inv->x = -src->x * inv_len_squared;
inv->y = -src->y * inv_len_squared;
inv->z = -src->z * inv_len_squared;
inv->w = src->w * inv_len_squared;
} else {
inv->x = inv->y = inv->z = 0.0f;
inv->w = 1.0f;
}
}
#endif
#ifdef GEKKO
void PSQUATInverse(const register Quaternion *src, register Quaternion *inv)
{
register f32 vv1, vv2, vv3, vv4;
@ -126,6 +178,7 @@ void PSQUATInverse(const register Quaternion *src, register Quaternion *inv)
psq_st vv3, 8(inv), 1, 0;
}
}
#endif
void C_QUATRotAxisRad(Quaternion *q, const Vec *axis, f32 rad)
{
@ -133,7 +186,7 @@ void C_QUATRotAxisRad(Quaternion *q, const Vec *axis, f32 rad)
Vec dst;
tmp = rad;
PSVECNormalize(axis, &dst);
VECNormalize(axis, &dst);
tmp2 = tmp * 0.5f;
tmp3 = sinf(tmp * 0.5f);

View file

@ -155,7 +155,7 @@ void *OSAllocFromHeap(int heap, unsigned long size)
hd = &HeapArray[heap];
size += 0x20;
size = (size + 0x1F) & 0xFFFFFFE0;
size = (size + 0x1F) & ~0x1F;
for (cell = hd->free; cell != NULL; cell = cell->next) {
if ((signed)size <= (signed)cell->size) {

View file

@ -34,7 +34,7 @@ void OSStopStopwatch(struct OSStopwatch *sw)
}
}
long long OSCheckStopwatch(struct OSStopwatch *sw)
OSTime OSCheckStopwatch(OSStopwatch *sw)
{
long long currTotal;