more bigendian support and other wiiu specific fixes

This commit is contained in:
GaryOderNichts 2020-10-27 19:06:13 +01:00
parent 8cccd45af3
commit b5bf3d60e9
16 changed files with 577 additions and 65 deletions

View File

@ -792,10 +792,17 @@ CAnimManager::LoadAnimFile(int fd, bool compress)
float *fbuf = (float*)buf;
CFileMgr::Read(fd, (char*)&anpk, sizeof(IfpHeader));
#ifdef BIGENDIAN
anpk.size = BSWAP32(anpk.size);
#endif
if(strncmp(anpk.ident, "ANLF", 4) == 0){
ROUNDSIZE(anpk.size);
CFileMgr::Read(fd, buf, anpk.size);
#ifndef BIGENDIAN
numANPK = *(int*)buf;
#else
numANPK = BSWAP32(*(int*)buf);
#endif
}else if(strncmp(anpk.ident, "ANPK", 4) == 0){
CFileMgr::Seek(fd, -8, 1);
numANPK = 1;
@ -804,13 +811,23 @@ CAnimManager::LoadAnimFile(int fd, bool compress)
for(i = 0; i < numANPK; i++){
// block name
CFileMgr::Read(fd, (char*)&anpk, sizeof(IfpHeader));
#ifdef BIGENDIAN
anpk.size = BSWAP32(anpk.size);
#endif
ROUNDSIZE(anpk.size);
CFileMgr::Read(fd, (char*)&info, sizeof(IfpHeader));
#ifdef BIGENDIAN
info.size = BSWAP32(info.size);
#endif
ROUNDSIZE(info.size);
CFileMgr::Read(fd, buf, info.size);
CAnimBlock *animBlock = &ms_aAnimBlocks[ms_numAnimBlocks++];
strncpy(animBlock->name, buf+4, 24);
#ifndef BIGENDIAN
animBlock->numAnims = *(int*)buf;
#else
animBlock->numAnims = BSWAP32(*(int*)buf);
#endif
animBlock->firstIndex = ms_numAnimations;
@ -819,53 +836,92 @@ CAnimManager::LoadAnimFile(int fd, bool compress)
// animation name
CFileMgr::Read(fd, (char*)&name, sizeof(IfpHeader));
#ifdef BIGENDIAN
name.size = BSWAP32(name.size);
#endif
ROUNDSIZE(name.size);
CFileMgr::Read(fd, buf, name.size);
hier->SetName(buf);
// DG info has number of nodes/sequences
CFileMgr::Read(fd, (char*)&dgan, sizeof(IfpHeader));
#ifdef BIGENDIAN
dgan.size = BSWAP32(dgan.size);
#endif
ROUNDSIZE(dgan.size);
CFileMgr::Read(fd, (char*)&info, sizeof(IfpHeader));
#ifdef BIGENDIAN
info.size = BSWAP32(info.size);
#endif
ROUNDSIZE(info.size);
CFileMgr::Read(fd, buf, info.size);
#ifndef BIGENDIAN
hier->numSequences = *(int*)buf;
#else
hier->numSequences = BSWAP32(*(int*)buf);
#endif
hier->sequences = new CAnimBlendSequence[hier->numSequences];
CAnimBlendSequence *seq = hier->sequences;
for(k = 0; k < hier->numSequences; k++, seq++){
// Each node has a name and key frames
CFileMgr::Read(fd, (char*)&cpan, sizeof(IfpHeader));
#ifdef BIGENDIAN
cpan.size = BSWAP32(cpan.size);
#endif
ROUNDSIZE(dgan.size);
CFileMgr::Read(fd, (char*)&anim, sizeof(IfpHeader));
#ifdef BIGENDIAN
anim.size = BSWAP32(anim.size);
#endif
ROUNDSIZE(anim.size);
CFileMgr::Read(fd, buf, anim.size);
#ifndef BIGENDIAN
int numFrames = *(int*)(buf+28);
#else
int numFrames = BSWAP32(*(int*)(buf+28));
#endif
#ifdef PED_SKIN
if(anim.size == 44)
#ifndef BIGENDIAN
seq->SetBoneTag(*(int*)(buf+40));
#else
seq->SetBoneTag(BSWAP32(*(int*)(buf+40)));
#endif
#endif
seq->SetName(buf);
if(numFrames == 0)
continue;
CFileMgr::Read(fd, (char*)&info, sizeof(info));
#ifdef BIGENDIAN
info.size = BSWAP32(info.size);
#endif
if(strncmp(info.ident, "KR00", 4) == 0){
seq->SetNumFrames(numFrames, false);
KeyFrame *kf = seq->GetKeyFrame(0);
for(l = 0; l < numFrames; l++, kf++){
CFileMgr::Read(fd, buf, 0x14);
#ifndef BIGENDIAN
kf->rotation.x = -fbuf[0];
kf->rotation.y = -fbuf[1];
kf->rotation.z = -fbuf[2];
kf->rotation.w = fbuf[3];
kf->deltaTime = fbuf[4]; // absolute time here
#else
kf->rotation.x = -FLOATSWAP32(fbuf[0]);
kf->rotation.y = -FLOATSWAP32(fbuf[1]);
kf->rotation.z = -FLOATSWAP32(fbuf[2]);
kf->rotation.w = FLOATSWAP32(fbuf[3]);
kf->deltaTime = FLOATSWAP32(fbuf[4]); // absolute time here
#endif
}
}else if(strncmp(info.ident, "KRT0", 4) == 0){
seq->SetNumFrames(numFrames, true);
KeyFrameTrans *kf = (KeyFrameTrans*)seq->GetKeyFrame(0);
for(l = 0; l < numFrames; l++, kf++){
CFileMgr::Read(fd, buf, 0x20);
#ifndef BIGENDIAN
kf->rotation.x = -fbuf[0];
kf->rotation.y = -fbuf[1];
kf->rotation.z = -fbuf[2];
@ -874,12 +930,23 @@ CAnimManager::LoadAnimFile(int fd, bool compress)
kf->translation.y = fbuf[5];
kf->translation.z = fbuf[6];
kf->deltaTime = fbuf[7]; // absolute time here
#else
kf->rotation.x = -FLOATSWAP32(fbuf[0]);
kf->rotation.y = -FLOATSWAP32(fbuf[1]);
kf->rotation.z = -FLOATSWAP32(fbuf[2]);
kf->rotation.w = FLOATSWAP32(fbuf[3]);
kf->translation.x = FLOATSWAP32(fbuf[4]);
kf->translation.y = FLOATSWAP32(fbuf[5]);
kf->translation.z = FLOATSWAP32(fbuf[6]);
kf->deltaTime = FLOATSWAP32(fbuf[7]); // absolute time here
#endif
}
}else if(strncmp(info.ident, "KRTS", 4) == 0){
seq->SetNumFrames(numFrames, true);
KeyFrameTrans *kf = (KeyFrameTrans*)seq->GetKeyFrame(0);
for(l = 0; l < numFrames; l++, kf++){
CFileMgr::Read(fd, buf, 0x2C);
#ifndef BIGENDIAN
kf->rotation.x = -fbuf[0];
kf->rotation.y = -fbuf[1];
kf->rotation.z = -fbuf[2];
@ -889,6 +956,17 @@ CAnimManager::LoadAnimFile(int fd, bool compress)
kf->translation.z = fbuf[6];
// scaling ignored
kf->deltaTime = fbuf[10]; // absolute time here
#else
kf->rotation.x = -FLOATSWAP32(fbuf[0]);
kf->rotation.y = -FLOATSWAP32(fbuf[1]);
kf->rotation.z = -FLOATSWAP32(fbuf[2]);
kf->rotation.w = FLOATSWAP32(fbuf[3]);
kf->translation.x = FLOATSWAP32(fbuf[4]);
kf->translation.y = FLOATSWAP32(fbuf[5]);
kf->translation.z = FLOATSWAP32(fbuf[6]);
// scaling ignored
kf->deltaTime = FLOATSWAP32(fbuf[10]); // absolute time here
#endif
}
}

View File

@ -1049,6 +1049,11 @@ cSampleManager::InitialiseChannel(uint32 nChannel, uint32 nSfx, uint8 nBank)
uintptr addr = nSampleBankMemoryStartAddress[nBank] + m_aSamples[nSfx].nOffset - m_aSamples[BankStartOffset[nBank]].nOffset;
#ifdef BIGENDIAN
for (int i = 0; i < m_aSamples[nSfx].nSize / sizeof(uint16); i++)
((uint16*)addr)[i] = BSWAP16(((uint16*)addr)[i]);
#endif
if ( ALBuffers[nSfx].IsEmpty() )
{
ALuint buf;

View File

@ -107,7 +107,11 @@ void COnscreenTimerEntry::Process() {
}
int32* timerPtr = CTheScripts::GetPointerToScriptVariable(m_nTimerOffset);
#ifndef BIGENDIAN
int32 oldTime = *timerPtr;
#else
int32 oldTime = BSWAP32(*timerPtr);
#endif
int32 newTime = oldTime - int32(CTimer::GetTimeStepInSeconds() * 1000);
if(newTime < 0) {
*timerPtr = 0;
@ -115,7 +119,11 @@ void COnscreenTimerEntry::Process() {
m_nTimerOffset = 0;
m_aTimerText[0] = 0;
} else {
#ifndef BIGENDIAN
*timerPtr = newTime;
#else
*timerPtr = BSWAP32(newTime);
#endif
int32 oldTimeSeconds = oldTime / 1000;
if(oldTimeSeconds < 12 && newTime / 1000 != oldTimeSeconds) {
DMAudio.PlayFrontEndSound(SOUND_CLOCK_TICK, newTime / 1000);
@ -144,12 +152,20 @@ bool COnscreenTimerEntry::ProcessForDisplay() {
}
void COnscreenTimerEntry::ProcessForDisplayClock() {
#ifndef BIGENDIAN
uint32 time = *CTheScripts::GetPointerToScriptVariable(m_nTimerOffset);
#else
uint32 time = BSWAP32(*CTheScripts::GetPointerToScriptVariable(m_nTimerOffset));
#endif
sprintf(m_bTimerBuffer, "%02d:%02d", time / 1000 / 60,
time / 1000 % 60);
}
void COnscreenTimerEntry::ProcessForDisplayCounter() {
#ifndef BIGENDIAN
uint32 counter = *CTheScripts::GetPointerToScriptVariable(m_nCounterOffset);
#else
uint32 counter = BSWAP32(*CTheScripts::GetPointerToScriptVariable(m_nCounterOffset));
#endif
sprintf(m_bCounterBuffer, "%d", counter);
}

File diff suppressed because it is too large Load Diff

View File

@ -309,12 +309,20 @@ public:
static int32 Read4BytesFromScript(uint32* pIp) {
int32 retval = ScriptSpace[*pIp + 3] << 24 | ScriptSpace[*pIp + 2] << 16 | ScriptSpace[*pIp + 1] << 8 | ScriptSpace[*pIp];
*pIp += 4;
#ifndef BIGENDIANa
return retval;
#else
return BSWAP32(retval);
#endif
}
static int16 Read2BytesFromScript(uint32* pIp) {
int16 retval = ScriptSpace[*pIp + 1] << 8 | ScriptSpace[*pIp];
*pIp += 2;
#ifndef BIGENDIANa
return retval;
#else
return BSWAP32(retval);
#endif
}
static int8 Read1ByteFromScript(uint32* pIp) {
int8 retval = ScriptSpace[*pIp];

View File

@ -23,7 +23,13 @@ CDirectory::ReadDirFile(const char *filename)
fd = CFileMgr::OpenFile(filename, "rb");
while(CFileMgr::Read(fd, (char*)&dirinfo, sizeof(dirinfo)))
{
#ifdef BIGENDIAN
dirinfo.offset = BSWAP32(dirinfo.offset);
dirinfo.size = BSWAP32(dirinfo.size);
#endif
AddItem(dirinfo);
}
CFileMgr::CloseFile(fd);
}

View File

@ -234,8 +234,6 @@ CFileLoader::LoadCollisionModel(uint8 *buf, CColModel &model, char *modelname)
model.boundingBox.max.z = *(float*)(buf+36);
model.numSpheres = *(int16*)(buf+40);
#else
// TODO make a macro for those buf to float bswaps
// wtf is 0 | 128?
model.boundingSphere.radius = FLOATSWAP32(*(float*)(buf));
model.boundingSphere.center.x = FLOATSWAP32(*(float*)(buf+4));
model.boundingSphere.center.y = FLOATSWAP32(*(float*)(buf+8));

View File

@ -88,6 +88,48 @@ CCullZones::ResolveVisibilities(void)
CFileMgr::Read(fd, (char*)aPointersToBigBuildingsForBuildings, sizeof(aPointersToBigBuildingsForBuildings));
CFileMgr::Read(fd, (char*)aPointersToBigBuildingsForTreadables, sizeof(aPointersToBigBuildingsForTreadables));
CFileMgr::CloseFile(fd);
#ifdef BIGENDIAN
NumCullZones = BSWAP32(NumCullZones);
for (int i = 0; i < NUMCULLZONES; i++)
{
CCullZone* z = &aZones[i];
z->position.x = FLOATSWAP32(z->position.x);
z->position.y = FLOATSWAP32(z->position.y);
z->position.z = FLOATSWAP32(z->position.z);
z->minx = FLOATSWAP32(z->minx);
z->maxx = FLOATSWAP32(z->maxx);
z->miny = FLOATSWAP32(z->miny);
z->maxy = FLOATSWAP32(z->maxy);
z->minz = FLOATSWAP32(z->minz);
z->maxz = FLOATSWAP32(z->maxz);
z->m_indexStart = BSWAP32(z->m_indexStart);
z->m_groupIndexCount[0] = BSWAP16(z->m_groupIndexCount[0]);
z->m_groupIndexCount[1] = BSWAP16(z->m_groupIndexCount[1]);
z->m_groupIndexCount[2] = BSWAP16(z->m_groupIndexCount[2]);
z->m_numBuildings = BSWAP16(z->m_numBuildings);
z->m_numTreadablesPlus10m = BSWAP16(z->m_numTreadablesPlus10m);
z->m_numTreadables = BSWAP16(z->m_numTreadables);
}
NumAttributeZones = BSWAP32(NumAttributeZones);
for (int i = 0; i < NUMATTRIBZONES; i++)
{
CAttributeZone* a = &aAttributeZones[i];
a->minx = FLOATSWAP32(a->minx);
a->maxx = FLOATSWAP32(a->maxx);
a->miny = FLOATSWAP32(a->miny);
a->maxy = FLOATSWAP32(a->maxy);
a->minz = FLOATSWAP32(a->minz);
a->maxz = FLOATSWAP32(a->maxz);
a->attributes = BSWAP16(a->attributes);
a->wantedLevel = BSWAP16(a->wantedLevel);
}
for (int i = 0; i < NUMZONEINDICES; i++)
aIndices[i] = BSWAP16(aIndices[i]);
for (int i = 0; i < NUMBUILDINGS; i++)
aPointersToBigBuildingsForBuildings[i] = BSWAP16(aPointersToBigBuildingsForBuildings[i]);
for (int i = 0; i < NUMTREADABLES; i++)
aPointersToBigBuildingsForTreadables[i] = BSWAP16(aPointersToBigBuildingsForTreadables[i]);
#endif
}else{
#if 0
// TODO: implement code from mobile to generate data here

View File

@ -88,6 +88,10 @@ inline float _floatswap32(float f)
#define BSWAP32(x) __builtin_bswap32(x)
#define BSWAP16(x) __builtin_bswap16(x)
#define FLOATSWAP32(x) _floatswap32(x)
#else
#define BSWAP32(x) (x)
#define BSWAP16(x) (x)
#define FLOATSWAP32(x) (x)
#endif
#ifndef nil

View File

@ -31,6 +31,10 @@ FindPlayerDff(uint32 &offset, uint32 &size)
do {
if (!CFileMgr::Read(file, (char*)&info, sizeof(CDirectory::DirectoryInfo)))
return;
#ifdef BIGENDIAN
info.offset = BSWAP32(info.offset);
info.size = BSWAP32(info.size);
#endif
} while (strcasecmp("player.dff", info.name) != 0);
offset = info.offset;

View File

@ -35,7 +35,7 @@ bool CWaterLevel::WavesCalculatedThisFrame;
RpAtomic *CWaterLevel::ms_pWavyAtomic;
RpGeometry *CWaterLevel::apGeomArray[8];
int16 CWaterLevel::nGeomUsed;
//"Custom" Don´t Render Water Toggle
//"Custom" Don<EFBFBD>t Render Water Toggle
bool gbDontRenderWater;
//RwTexture *gpWaterTex;
@ -75,6 +75,19 @@ CWaterLevel::Initialise(Const char *pWaterDat)
CFileMgr::Read(hFile, (char *)ms_aWaterRects, sizeof(ms_aWaterRects));
CFileMgr::Read(hFile, (char *)aWaterBlockList, sizeof(aWaterBlockList));
CFileMgr::Read(hFile, (char *)aWaterFineBlockList, sizeof(aWaterFineBlockList));
#ifdef BIGENDIAN
ms_nNoOfWaterLevels = BSWAP32(ms_nNoOfWaterLevels);
for (int i = 0; i < 48; i++)
ms_aWaterZs[i] = FLOATSWAP32(ms_aWaterZs[i]);
for (int i = 0; i < 48; i++)
{
CRect* r = &ms_aWaterRects[i];
r->left = FLOATSWAP32(r->left);
r->bottom = FLOATSWAP32(r->bottom);
r->right = FLOATSWAP32(r->right);
r->top = FLOATSWAP32(r->top);
}
#endif
}
CFileMgr::CloseFile(hFile);
@ -334,7 +347,7 @@ SectorRadius(float fSize)
void
CWaterLevel::RenderWater()
{
//"Custom" Don´t Render Water Toggle
//"Custom" Don<EFBFBD>t Render Water Toggle
#ifndef MASTER
if (gbDontRenderWater)
return;

View File

@ -35,6 +35,10 @@ GeometryListStreamRead1(RwStream *stream, rpGeometryList *geomlist)
if(RwStreamRead(stream, &numGeoms, 4) != 4)
return nil;
#ifdef BIGENDIAN
numGeoms = BSWAP32(numGeoms);
#endif
numberGeometrys = numGeoms/2;
geomlist->numGeoms = numGeoms;
if(geomlist->numGeoms > 0){
@ -102,6 +106,13 @@ ClumpAtomicStreamRead(RwStream *stream, rwFrameList *frmList, rpGeometryList *ge
if(RwStreamRead(stream, &a, size) != size)
return nil;
#ifdef BIGENDIAN
a.frameIndex = BSWAP32(a.frameIndex);
a.geomIndex = BSWAP32(a.geomIndex);
a.flags = BSWAP32(a.flags);
a.unused = BSWAP32(a.unused);
#endif
atomic = RpAtomicCreate();
if(atomic == nil)
return nil;
@ -151,6 +162,12 @@ RpClumpGtaStreamRead1(RwStream *stream)
return false;
}
#ifdef BIGENDIAN
gClumpInfo.numAtomics = BSWAP32(gClumpInfo.numAtomics);
gClumpInfo.numCameras = BSWAP32(gClumpInfo.numCameras);
gClumpInfo.numLights = BSWAP32(gClumpInfo.numLights);
#endif
if(!RwStreamFindChunk(stream, rwID_FRAMELIST, nil, &version))
return false;
if(rwFrameListStreamRead(stream, &gFrameList) == nil)

View File

@ -109,6 +109,10 @@ RwTexDictionaryGtaStreamRead1(RwStream *stream)
if(RwStreamRead(stream, &numTextures, size) != size)
return nil;
#ifdef BIGENDIAN
numTextures = BSWAP32(numTextures);
#endif
texDict = RwTexDictionaryCreate();
if(texDict == nil)
return nil;
@ -325,8 +329,14 @@ CreateTxdImageForVideoCard()
RwStreamWrite(img, buf, num);
}
#ifndef BIGENDIAN
dirInfo.offset = pos / CDSTREAM_SECTOR_SIZE;
dirInfo.size = size;
#else
// Save as little endian for consistancy
dirInfo.offset = BSWAP32(pos / CDSTREAM_SECTOR_SIZE);
dirInfo.size = BSWAP32(size);
#endif
strncpy(dirInfo.name, filename, sizeof(dirInfo.name));
pDir->AddItem(dirInfo);
CStreaming::RemoveTxd(i);

View File

@ -139,7 +139,13 @@ char* casepath(char const* path, bool checkPathFirst)
}
size_t l = strlen(path);
#ifdef __WIIU__
// alloca seems to cause issues here, so just use the stack
char _p[l+1];
char* p = _p;
#else
char* p = (char*)alloca(l + 1);
#endif
char* out = (char*)malloc(l + 3); // for extra ./
strcpy(p, path);
@ -174,7 +180,6 @@ char* casepath(char const* path, bool checkPathFirst)
char* c;
while (c = strsep(&p, "/\\"))
{
debug("sep string from %s is %s", p, c);
// May be trailing slash(allow), slash at the start(avoid), or multiple slashes(avoid)
if (*c == '\0')
{

View File

@ -10,6 +10,8 @@
#include <vpad/input.h>
#include <coreinit/time.h>
#include <stdio.h>
#include "rwcore.h"
#include "skeleton.h"
@ -141,9 +143,7 @@ psGrabScreen(RwCamera *pCamera)
double
psTimer(void)
{
struct timespec start;
clock_gettime(CLOCK_MONOTONIC, &start);
return start.tv_sec * 1000.0 + start.tv_nsec/1000000.0;
return OSTicksToMilliseconds(OSGetSystemTime());
}
@ -834,6 +834,37 @@ _InputTranslateShiftKeyUpDown(RsKeyCodes *rs) {
RsKeyboardEventHandler(rshiftStatus ? rsKEYDOWN : rsKEYUP, &(*rs = rsRSHIFT));
}
#include <coreinit/memory.h>
#include <coreinit/memheap.h>
#include <coreinit/memexpheap.h>
#include <coreinit/memdefaultheap.h>
void memInfo()
{
for(int32_t i = 0; i<2; i++) {
MEMHeapHandle defaultHeap = MEMGetBaseHeapHandle((MEMBaseHeapType) i);
if(defaultHeap != 0) {
uint32_t start = 0;
uint32_t size_bytes = 0;
OSGetMemBound((OSMemoryType) (i+1),&start,&size_bytes);
WHBLogPrintf("Memory Bound MEM%d: startAddress 0x%08X size 0x%08X\n",i+1,start,size_bytes);
int32_t size = MEMGetAllocatableSizeForExpHeapEx(defaultHeap, 4);
int32_t totalSize = MEMGetTotalFreeSizeForExpHeap(defaultHeap);
WHBLogPrintf("BaseHandle address 0x%08X: MEM%d with %07d kb memory free in one block, %07d kb in total.\n",defaultHeap,i+1,size/1024,totalSize/1024);
MEMHeapHandle parent = MEMFindParentHeap(defaultHeap);
if(parent != 0) {
size = MEMGetAllocatableSizeForExpHeapEx(parent, 4);
int32_t totalSize = MEMGetTotalFreeSizeForExpHeap(parent);
WHBLogPrintf("It's parent heap is 0x%08X: With %07d kb memory free in one block, %07d kb in total.\n",parent,size/1024,totalSize/1024);
} else {
WHBLogPrintf("No parent found =(\n");
}
}
}
}
/*
*****************************************************************************
*/
@ -851,6 +882,8 @@ main(int argc, char *argv[])
WHBLogPrintf("RE3 Wii U started");
memInfo();
// Set out working dir to the path where the assets are
chdir("/vol/external01/wiiu/apps/re3");

View File

@ -70,9 +70,7 @@ CText::Load(void)
type[3] = filedata[offset++];
sectlen = (int)filedata[offset+3]<<24 | (int)filedata[offset+2]<<16 |
(int)filedata[offset+1]<<8 | (int)filedata[offset+0];
#ifdef BIGENDIAN
sectlen = BSWAP32(sectlen);
#endif
offset += 4;
if(sectlen != 0){
if(strncmp(type, "TKEY", 4) == 0)
@ -191,6 +189,11 @@ CKeyArray::Load(size_t length, uint8 *data, intptr_t *offset)
for(i = 0; i < length; i++)
rawbytes[i] = data[(*offset)++];
#ifdef BIGENDIAN
for (i = 0; i < numEntries; i++)
entries[i].valueOffset = BSWAP32(entries[i].valueOffset);
#endif
}
void
@ -271,6 +274,11 @@ CData::Load(size_t length, uint8 *data, intptr_t *offset)
for(i = 0; i < length; i++)
rawbytes[i] = data[(*offset)++];
#ifdef BIGENDIAN
for (i = 0; i < numChars; i++)
chars[i] = BSWAP16(chars[i]);
#endif
}
void