- changed the byte order swappers to use ZDoom's versions

This is to reduce redundancy, plus, these are native on Windows and macOS.
This commit is contained in:
Christoph Oelckers 2020-08-03 19:09:57 +02:00
parent 3c8da8c421
commit 5704c57fe0
7 changed files with 88 additions and 97 deletions

View file

@ -644,20 +644,18 @@ int dbLoadMap(const char *pPath, int *pX, int *pY, int *pZ, short *pAngle, short
byte_1A76C7 = 1; byte_1A76C7 = 1;
} }
#if B_BIG_ENDIAN == 1 mapHeader.at0 = LittleLong(mapHeader.at0);
mapHeader.at0 = B_LITTLE32(mapHeader.at0); mapHeader.at4 = LittleLong(mapHeader.at4);
mapHeader.at4 = B_LITTLE32(mapHeader.at4); mapHeader.at8 = LittleLong(mapHeader.at8);
mapHeader.at8 = B_LITTLE32(mapHeader.at8); mapHeader.atc = LittleShort(mapHeader.atc);
mapHeader.atc = B_LITTLE16(mapHeader.atc); mapHeader.ate = LittleShort(mapHeader.ate);
mapHeader.ate = B_LITTLE16(mapHeader.ate); mapHeader.at10 = LittleShort(mapHeader.at10);
mapHeader.at10 = B_LITTLE16(mapHeader.at10); mapHeader.at12 = LittleLong(mapHeader.at12);
mapHeader.at12 = B_LITTLE32(mapHeader.at12); mapHeader.at16 = LittleLong(mapHeader.at16);
mapHeader.at16 = B_LITTLE32(mapHeader.at16); mapHeader.at1b = LittleLong(mapHeader.at1b);
mapHeader.at1b = B_LITTLE32(mapHeader.at1b); mapHeader.at1f = LittleShort(mapHeader.at1f);
mapHeader.at1f = B_LITTLE16(mapHeader.at1f); mapHeader.at21 = LittleShort(mapHeader.at21);
mapHeader.at21 = B_LITTLE16(mapHeader.at21); mapHeader.at23 = LittleShort(mapHeader.at23);
mapHeader.at23 = B_LITTLE16(mapHeader.at23);
#endif
*pX = mapHeader.at0; *pX = mapHeader.at0;
*pY = mapHeader.at4; *pY = mapHeader.at4;
@ -696,11 +694,10 @@ int dbLoadMap(const char *pPath, int *pX, int *pY, int *pZ, short *pAngle, short
{ {
fr.Read(&byte_19AE44, 128); fr.Read(&byte_19AE44, 128);
dbCrypt((char*)&byte_19AE44, 128, numwalls); dbCrypt((char*)&byte_19AE44, 128, numwalls);
#if B_BIG_ENDIAN == 1
byte_19AE44.at40 = B_LITTLE32(byte_19AE44.at40); byte_19AE44.at40 = LittleLong(byte_19AE44.at40);
byte_19AE44.at44 = B_LITTLE32(byte_19AE44.at44); byte_19AE44.at44 = LittleLong(byte_19AE44.at44);
byte_19AE44.at48 = B_LITTLE32(byte_19AE44.at48); byte_19AE44.at48 = LittleLong(byte_19AE44.at48);
#endif
} }
else else
{ {
@ -718,7 +715,7 @@ int dbLoadMap(const char *pPath, int *pX, int *pY, int *pZ, short *pAngle, short
pSky->lognumtiles = mapHeader.at10; pSky->lognumtiles = mapHeader.at10;
for (int i = 0; i < ClipHigh(gSkyCount, MAXPSKYTILES); i++) for (int i = 0; i < ClipHigh(gSkyCount, MAXPSKYTILES); i++)
{ {
pSky->tileofs[i] = B_LITTLE16(tpskyoff[i]); pSky->tileofs[i] = LittleShort(tpskyoff[i]);
} }
for (int i = 0; i < numsectors; i++) for (int i = 0; i < numsectors; i++)
@ -729,21 +726,20 @@ int dbLoadMap(const char *pPath, int *pX, int *pY, int *pZ, short *pAngle, short
{ {
dbCrypt((char*)pSector, sizeof(sectortype), gMapRev*sizeof(sectortype)); dbCrypt((char*)pSector, sizeof(sectortype), gMapRev*sizeof(sectortype));
} }
#if B_BIG_ENDIAN == 1 pSector->wallptr = LittleShort(pSector->wallptr);
pSector->wallptr = B_LITTLE16(pSector->wallptr); pSector->wallnum = LittleShort(pSector->wallnum);
pSector->wallnum = B_LITTLE16(pSector->wallnum); pSector->ceilingz = LittleLong(pSector->ceilingz);
pSector->ceilingz = B_LITTLE32(pSector->ceilingz); pSector->floorz = LittleLong(pSector->floorz);
pSector->floorz = B_LITTLE32(pSector->floorz); pSector->ceilingstat = LittleShort(pSector->ceilingstat);
pSector->ceilingstat = B_LITTLE16(pSector->ceilingstat); pSector->floorstat = LittleShort(pSector->floorstat);
pSector->floorstat = B_LITTLE16(pSector->floorstat); pSector->ceilingpicnum = LittleShort(pSector->ceilingpicnum);
pSector->ceilingpicnum = B_LITTLE16(pSector->ceilingpicnum); pSector->ceilingheinum = LittleShort(pSector->ceilingheinum);
pSector->ceilingheinum = B_LITTLE16(pSector->ceilingheinum); pSector->floorpicnum = LittleShort(pSector->floorpicnum);
pSector->floorpicnum = B_LITTLE16(pSector->floorpicnum); pSector->floorheinum = LittleShort(pSector->floorheinum);
pSector->floorheinum = B_LITTLE16(pSector->floorheinum); pSector->type = LittleShort(pSector->type);
pSector->type = B_LITTLE16(pSector->type); pSector->hitag = LittleShort(pSector->hitag);
pSector->hitag = B_LITTLE16(pSector->hitag); pSector->extra = LittleShort(pSector->extra);
pSector->extra = B_LITTLE16(pSector->extra);
#endif
qsector_filler[i] = pSector->fogpal; qsector_filler[i] = pSector->fogpal;
pSector->fogpal = 0; pSector->fogpal = 0;
if (sector[i].extra > 0) if (sector[i].extra > 0)
@ -854,19 +850,17 @@ int dbLoadMap(const char *pPath, int *pX, int *pY, int *pZ, short *pAngle, short
{ {
dbCrypt((char*)pWall, sizeof(walltype), (gMapRev*sizeof(sectortype)) | 0x7474614d); dbCrypt((char*)pWall, sizeof(walltype), (gMapRev*sizeof(sectortype)) | 0x7474614d);
} }
#if B_BIG_ENDIAN == 1 pWall->x = LittleLong(pWall->x);
pWall->x = B_LITTLE32(pWall->x); pWall->y = LittleLong(pWall->y);
pWall->y = B_LITTLE32(pWall->y); pWall->point2 = LittleShort(pWall->point2);
pWall->point2 = B_LITTLE16(pWall->point2); pWall->nextwall = LittleShort(pWall->nextwall);
pWall->nextwall = B_LITTLE16(pWall->nextwall); pWall->nextsector = LittleShort(pWall->nextsector);
pWall->nextsector = B_LITTLE16(pWall->nextsector); pWall->cstat = LittleShort(pWall->cstat);
pWall->cstat = B_LITTLE16(pWall->cstat); pWall->picnum = LittleShort(pWall->picnum);
pWall->picnum = B_LITTLE16(pWall->picnum); pWall->overpicnum = LittleShort(pWall->overpicnum);
pWall->overpicnum = B_LITTLE16(pWall->overpicnum); pWall->type = LittleShort(pWall->type);
pWall->type = B_LITTLE16(pWall->type); pWall->hitag = LittleShort(pWall->hitag);
pWall->hitag = B_LITTLE16(pWall->hitag); pWall->extra = LittleShort(pWall->extra);
pWall->extra = B_LITTLE16(pWall->extra);
#endif
if (wall[i].extra > 0) if (wall[i].extra > 0)
{ {
char pBuffer[nXWallSize]; char pBuffer[nXWallSize];
@ -931,23 +925,23 @@ int dbLoadMap(const char *pPath, int *pX, int *pY, int *pZ, short *pAngle, short
{ {
dbCrypt((char*)pSprite, sizeof(spritetype), (gMapRev*sizeof(spritetype)) | 0x7474614d); dbCrypt((char*)pSprite, sizeof(spritetype), (gMapRev*sizeof(spritetype)) | 0x7474614d);
} }
#if B_BIG_ENDIAN == 1
pSprite->x = B_LITTLE32(pSprite->x); pSprite->x = LittleLong(pSprite->x);
pSprite->y = B_LITTLE32(pSprite->y); pSprite->y = LittleLong(pSprite->y);
pSprite->z = B_LITTLE32(pSprite->z); pSprite->z = LittleLong(pSprite->z);
pSprite->cstat = B_LITTLE16(pSprite->cstat); pSprite->cstat = LittleShort(pSprite->cstat);
pSprite->picnum = B_LITTLE16(pSprite->picnum); pSprite->picnum = LittleShort(pSprite->picnum);
pSprite->sectnum = B_LITTLE16(pSprite->sectnum); pSprite->sectnum = LittleShort(pSprite->sectnum);
pSprite->statnum = B_LITTLE16(pSprite->statnum); pSprite->statnum = LittleShort(pSprite->statnum);
pSprite->ang = B_LITTLE16(pSprite->ang); pSprite->ang = LittleShort(pSprite->ang);
pSprite->owner = B_LITTLE16(pSprite->owner); pSprite->owner = LittleShort(pSprite->owner);
pSprite->index = B_LITTLE16(pSprite->index); pSprite->index = LittleShort(pSprite->index);
pSprite->yvel = B_LITTLE16(pSprite->yvel); pSprite->yvel = LittleShort(pSprite->yvel);
pSprite->inittype = B_LITTLE16(pSprite->inittype); pSprite->inittype = LittleShort(pSprite->inittype);
pSprite->type = B_LITTLE16(pSprite->type); pSprite->type = LittleShort(pSprite->type);
pSprite->flags = B_LITTLE16(pSprite->hitag); pSprite->flags = LittleShort(pSprite->hitag);
pSprite->extra = B_LITTLE16(pSprite->extra); pSprite->extra = LittleShort(pSprite->extra);
#endif
InsertSpriteSect(i, sprite[i].sectnum); InsertSpriteSect(i, sprite[i].sectnum);
InsertSpriteStat(i, sprite[i].statnum); InsertSpriteStat(i, sprite[i].statnum);
Numsprites++; Numsprites++;
@ -1051,11 +1045,8 @@ int dbLoadMap(const char *pPath, int *pX, int *pY, int *pZ, short *pAngle, short
sprite[i].cstat &= ~0x30; sprite[i].cstat &= ~0x30;
} }
} }
unsigned int nCRC; unsigned int nCRC = fr.ReadUInt32();
fr.Read(&nCRC, 4);
#if B_BIG_ENDIAN == 1
nCRC = B_LITTLE32(nCRC);
#endif
fr.Seek(0, FileReader::SeekSet); fr.Seek(0, FileReader::SeekSet);
auto buffer = fr.Read(); auto buffer = fr.Read();
md4once(buffer.Data(), buffer.Size(), g_loadedMapHack.md4); md4once(buffer.Data(), buffer.Size(), g_loadedMapHack.md4);

View file

@ -179,27 +179,27 @@ void ByteSwapQAV(void* p)
{ {
#if B_BIG_ENDIAN == 1 #if B_BIG_ENDIAN == 1
QAV* qav = (QAV*)p; QAV* qav = (QAV*)p;
qav->nFrames = B_LITTLE32(qav->nFrames); qav->nFrames = LittleLong(qav->nFrames);
qav->ticksPerFrame = B_LITTLE32(qav->ticksPerFrame); qav->ticksPerFrame = LittleLong(qav->ticksPerFrame);
qav->at10 = B_LITTLE32(qav->at10); qav->at10 = LittleLong(qav->at10);
qav->x = B_LITTLE32(qav->x); qav->x = LittleLong(qav->x);
qav->y = B_LITTLE32(qav->y); qav->y = LittleLong(qav->y);
qav->nSprite = B_LITTLE32(qav->nSprite); qav->nSprite = LittleLong(qav->nSprite);
for (int i = 0; i < qav->nFrames; i++) for (int i = 0; i < qav->nFrames; i++)
{ {
FRAMEINFO* pFrame = &qav->frames[i]; FRAMEINFO* pFrame = &qav->frames[i];
SOUNDINFO* pSound = &pFrame->sound; SOUNDINFO* pSound = &pFrame->sound;
pFrame->nCallbackId = B_LITTLE32(pFrame->nCallbackId); pFrame->nCallbackId = LittleLong(pFrame->nCallbackId);
pSound->sound = B_LITTLE32(pSound->sound); pSound->sound = LittleLong(pSound->sound);
for (int j = 0; j < 8; j++) for (int j = 0; j < 8; j++)
{ {
TILE_FRAME* pTile = &pFrame->tiles[j]; TILE_FRAME* pTile = &pFrame->tiles[j];
pTile->picnum = B_LITTLE32(pTile->picnum); pTile->picnum = LittleLong(pTile->picnum);
pTile->x = B_LITTLE32(pTile->x); pTile->x = LittleLong(pTile->x);
pTile->y = B_LITTLE32(pTile->y); pTile->y = LittleLong(pTile->y);
pTile->z = B_LITTLE32(pTile->z); pTile->z = LittleLong(pTile->z);
pTile->stat = B_LITTLE32(pTile->stat); pTile->stat = LittleLong(pTile->stat);
pTile->angle = B_LITTLE16(pTile->angle); pTile->angle = LittleShort(pTile->angle);
} }
} }
#endif #endif

View file

@ -603,11 +603,11 @@ void SeqLoadSaveConstruct(void)
static void ByteSwapSEQ(Seq* pSeq) static void ByteSwapSEQ(Seq* pSeq)
{ {
#if B_BIG_ENDIAN == 1 #if B_BIG_ENDIAN == 1
pSeq->version = B_LITTLE16(pSeq->version); pSeq->version = LittleShort(pSeq->version);
pSeq->nFrames = B_LITTLE16(pSeq->nFrames); pSeq->nFrames = LittleShort(pSeq->nFrames);
pSeq->at8 = B_LITTLE16(pSeq->at8); pSeq->at8 = LittleShort(pSeq->at8);
pSeq->ata = B_LITTLE16(pSeq->ata); pSeq->ata = LittleShort(pSeq->ata);
pSeq->atc = B_LITTLE32(pSeq->atc); pSeq->atc = LittleLong(pSeq->atc);
for (int i = 0; i < pSeq->nFrames; i++) for (int i = 0; i < pSeq->nFrames; i++)
{ {
SEQFRAME* pFrame = &pSeq->frames[i]; SEQFRAME* pFrame = &pSeq->frames[i];

View file

@ -55,11 +55,11 @@ int soundRates[13] = {
void ByteSwapSFX(SFX* pSFX) void ByteSwapSFX(SFX* pSFX)
{ {
#if B_BIG_ENDIAN == 1 #if B_BIG_ENDIAN == 1
pSFX->relVol = B_LITTLE32(pSFX->relVol); pSFX->relVol = LittleLong(pSFX->relVol);
pSFX->pitch = B_LITTLE32(pSFX->pitch); pSFX->pitch = LittleLong(pSFX->pitch);
pSFX->pitchRange = B_LITTLE32(pSFX->pitchRange); pSFX->pitchRange = LittleLong(pSFX->pitchRange);
pSFX->format = B_LITTLE32(pSFX->format); pSFX->format = LittleLong(pSFX->format);
pSFX->loopStart = B_LITTLE32(pSFX->loopStart); pSFX->loopStart = LittleLong(pSFX->loopStart);
#endif #endif
} }

View file

@ -70,7 +70,7 @@ int tileInit(char a1, const char *a2)
hFile.Read(voxelIndex, sizeof(voxelIndex)); hFile.Read(voxelIndex, sizeof(voxelIndex));
#if B_BIG_ENDIAN == 1 #if B_BIG_ENDIAN == 1
for (int i = 0; i < kMaxTiles; i++) for (int i = 0; i < kMaxTiles; i++)
voxelIndex[i] = B_LITTLE16(voxelIndex[i]); voxelIndex[i] = LittleShort(voxelIndex[i]);
#endif #endif
} }
hFile = fileSystem.OpenFileReader("SHADE.DAT"); hFile = fileSystem.OpenFileReader("SHADE.DAT");

View file

@ -66,7 +66,7 @@ void trigInit()
#if B_BIG_ENDIAN == 1 #if B_BIG_ENDIAN == 1
for (int i = 0; i < 512; i++) for (int i = 0; i < 512; i++)
{ {
costable[i] = B_LITTLE32(costable[i]); costable[i] = LittleLong(costable[i]);
} }
#endif #endif
costable[512] = 0; costable[512] = 0;

View file

@ -348,7 +348,7 @@ void viewInit(void)
#if B_BIG_ENDIAN == 1 #if B_BIG_ENDIAN == 1
for (int i = 0; i < kLensSize*kLensSize; i++) for (int i = 0; i < kLensSize*kLensSize; i++)
{ {
lensTable[i] = B_LITTLE32(lensTable[i]); lensTable[i] = LittleLong(lensTable[i]);
} }
#endif #endif
uint8_t *data = tileAllocTile(4077, kLensSize, kLensSize); uint8_t *data = tileAllocTile(4077, kLensSize, kLensSize);