Skip to content

Commit

Permalink
Some fixes for Big Endian systems
Browse files Browse the repository at this point in the history
  • Loading branch information
MBeijer authored and AJenbo committed Oct 6, 2019
1 parent ca05b2e commit d641c65
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 52 deletions.
19 changes: 11 additions & 8 deletions Source/drlg_l1.cpp
Expand Up @@ -207,13 +207,15 @@ void DRLG_L1Pass3()
{
int i, j, xx, yy;
long v1, v2, v3, v4, lv;
WORD *MegaTiles;

lv = 22 - 1;

v1 = *((WORD *)&pMegaTiles[lv * 8]) + 1;
v2 = *((WORD *)&pMegaTiles[lv * 8] + 1) + 1;
v3 = *((WORD *)&pMegaTiles[lv * 8] + 2) + 1;
v4 = *((WORD *)&pMegaTiles[lv * 8] + 3) + 1;
MegaTiles = (WORD *)&pMegaTiles[lv * 8];
v1 = SDL_SwapLE16(*(MegaTiles + 0)) + 1;
v2 = SDL_SwapLE16(*(MegaTiles + 1)) + 1;
v3 = SDL_SwapLE16(*(MegaTiles + 2)) + 1;
v4 = SDL_SwapLE16(*(MegaTiles + 3)) + 1;

for (j = 0; j < MAXDUNY; j += 2)
{
Expand All @@ -231,10 +233,11 @@ void DRLG_L1Pass3()
for (i = 0; i < DMAXX; i++) {
lv = dungeon[i][j] - 1;
/// ASSERT: assert(lv >= 0);
v1 = *((WORD *)&pMegaTiles[lv * 8]) + 1;
v2 = *((WORD *)&pMegaTiles[lv * 8] + 1) + 1;
v3 = *((WORD *)&pMegaTiles[lv * 8] + 2) + 1;
v4 = *((WORD *)&pMegaTiles[lv * 8] + 3) + 1;
MegaTiles = (WORD *)&pMegaTiles[lv * 8];
v1 = SDL_SwapLE16(*(MegaTiles + 0)) + 1;
v2 = SDL_SwapLE16(*(MegaTiles + 1)) + 1;
v3 = SDL_SwapLE16(*(MegaTiles + 2)) + 1;
v4 = SDL_SwapLE16(*(MegaTiles + 3)) + 1;
dPiece[xx][yy] = v1;
dPiece[xx + 1][yy] = v2;
dPiece[xx][yy + 1] = v3;
Expand Down
19 changes: 11 additions & 8 deletions Source/drlg_l2.cpp
Expand Up @@ -424,13 +424,15 @@ void DRLG_L2Pass3()
{
int i, j, xx, yy;
long v1, v2, v3, v4, lv;
WORD *MegaTiles;

lv = 12 - 1;

v1 = *((WORD *)&pMegaTiles[lv * 8]) + 1;
v2 = *((WORD *)&pMegaTiles[lv * 8] + 1) + 1;
v3 = *((WORD *)&pMegaTiles[lv * 8] + 2) + 1;
v4 = *((WORD *)&pMegaTiles[lv * 8] + 3) + 1;
MegaTiles = (WORD *)&pMegaTiles[lv * 8];
v1 = SDL_SwapLE16(*(MegaTiles + 0)) + 1;
v2 = SDL_SwapLE16(*(MegaTiles + 1)) + 1;
v3 = SDL_SwapLE16(*(MegaTiles + 2)) + 1;
v4 = SDL_SwapLE16(*(MegaTiles + 3)) + 1;

for (j = 0; j < MAXDUNY; j += 2)
{
Expand All @@ -447,10 +449,11 @@ void DRLG_L2Pass3()
xx = 16;
for (i = 0; i < DMAXX; i++) {
lv = dungeon[i][j] - 1;
v1 = *((WORD *)&pMegaTiles[lv * 8]) + 1;
v2 = *((WORD *)&pMegaTiles[lv * 8] + 1) + 1;
v3 = *((WORD *)&pMegaTiles[lv * 8] + 2) + 1;
v4 = *((WORD *)&pMegaTiles[lv * 8] + 3) + 1;
MegaTiles = (WORD *)&pMegaTiles[lv * 8];
v1 = SDL_SwapLE16(*(MegaTiles + 0)) + 1;
v2 = SDL_SwapLE16(*(MegaTiles + 1)) + 1;
v3 = SDL_SwapLE16(*(MegaTiles + 2)) + 1;
v4 = SDL_SwapLE16(*(MegaTiles + 3)) + 1;
dPiece[xx][yy] = v1;
dPiece[xx + 1][yy] = v2;
dPiece[xx][yy + 1] = v3;
Expand Down
19 changes: 11 additions & 8 deletions Source/drlg_l3.cpp
Expand Up @@ -1640,13 +1640,15 @@ void DRLG_L3Pass3()
{
int i, j, xx, yy;
long v1, v2, v3, v4, lv;
WORD *MegaTiles;

lv = 8 - 1;

v1 = *((WORD *)&pMegaTiles[lv * 8]) + 1;
v2 = *((WORD *)&pMegaTiles[lv * 8] + 1) + 1;
v3 = *((WORD *)&pMegaTiles[lv * 8] + 2) + 1;
v4 = *((WORD *)&pMegaTiles[lv * 8] + 3) + 1;
MegaTiles = (WORD *)&pMegaTiles[lv * 8];
v1 = SDL_SwapLE16(*(MegaTiles + 0)) + 1;
v2 = SDL_SwapLE16(*(MegaTiles + 1)) + 1;
v3 = SDL_SwapLE16(*(MegaTiles + 2)) + 1;
v4 = SDL_SwapLE16(*(MegaTiles + 3)) + 1;

for (j = 0; j < MAXDUNY; j += 2)
{
Expand All @@ -1664,10 +1666,11 @@ void DRLG_L3Pass3()
for (i = 0; i < DMAXX; i++) {
lv = dungeon[i][j] - 1;
if (lv >= 0) {
v1 = *((WORD *)&pMegaTiles[lv * 8]) + 1;
v2 = *((WORD *)&pMegaTiles[lv * 8] + 1) + 1;
v3 = *((WORD *)&pMegaTiles[lv * 8] + 2) + 1;
v4 = *((WORD *)&pMegaTiles[lv * 8] + 3) + 1;
MegaTiles = (WORD *)&pMegaTiles[lv * 8];
v1 = SDL_SwapLE16(*(MegaTiles + 0)) + 1;
v2 = SDL_SwapLE16(*(MegaTiles + 1)) + 1;
v3 = SDL_SwapLE16(*(MegaTiles + 2)) + 1;
v4 = SDL_SwapLE16(*(MegaTiles + 3)) + 1;
} else {
v1 = 0;
v2 = 0;
Expand Down
19 changes: 11 additions & 8 deletions Source/drlg_l4.cpp
Expand Up @@ -1900,13 +1900,15 @@ void DRLG_L4Pass3()
{
int i, j, xx, yy;
long v1, v2, v3, v4, lv;
WORD *MegaTiles;

lv = 30 - 1;

v1 = *((WORD *)&pMegaTiles[lv * 8]) + 1;
v2 = *((WORD *)&pMegaTiles[lv * 8] + 1) + 1;
v3 = *((WORD *)&pMegaTiles[lv * 8] + 2) + 1;
v4 = *((WORD *)&pMegaTiles[lv * 8] + 3) + 1;
MegaTiles = (WORD *)&pMegaTiles[lv * 8];
v1 = SDL_SwapLE16(*(MegaTiles + 0)) + 1;
v2 = SDL_SwapLE16(*(MegaTiles + 1)) + 1;
v3 = SDL_SwapLE16(*(MegaTiles + 2)) + 1;
v4 = SDL_SwapLE16(*(MegaTiles + 3)) + 1;

for (j = 0; j < MAXDUNY; j += 2)
{
Expand All @@ -1924,10 +1926,11 @@ void DRLG_L4Pass3()
for (i = 0; i < DMAXX; i++) {
lv = dungeon[i][j] - 1;
if (lv >= 0) {
v1 = *((WORD *)&pMegaTiles[lv * 8]) + 1;
v2 = *((WORD *)&pMegaTiles[lv * 8] + 1) + 1;
v3 = *((WORD *)&pMegaTiles[lv * 8] + 2) + 1;
v4 = *((WORD *)&pMegaTiles[lv * 8] + 3) + 1;
MegaTiles = (WORD *)&pMegaTiles[lv * 8];
v1 = SDL_SwapLE16(*(MegaTiles + 0)) + 1;
v2 = SDL_SwapLE16(*(MegaTiles + 1)) + 1;
v3 = SDL_SwapLE16(*(MegaTiles + 2)) + 1;
v4 = SDL_SwapLE16(*(MegaTiles + 3)) + 1;
} else {
v1 = 0;
v2 = 0;
Expand Down
18 changes: 9 additions & 9 deletions Source/mpqapi.cpp
Expand Up @@ -584,15 +584,15 @@ BOOL WriteMPQHeader()
DWORD NumberOfBytesWritten;

memset(&fhdr, 0, sizeof(fhdr));
fhdr.signature = '\x1AQPM';
fhdr.headersize = 32;
fhdr.filesize = GetFileSize(sghArchive, 0);
fhdr.version = 0;
fhdr.sectorsizeid = 3;
fhdr.hashoffset = 32872;
fhdr.blockoffset = 104;
fhdr.hashcount = 2048;
fhdr.blockcount = 2048;
fhdr.signature = SDL_SwapLE32('\x1AQPM');
fhdr.headersize = SDL_SwapLE32(32);
fhdr.filesize = SDL_SwapLE32(GetFileSize(sghArchive, 0));
fhdr.version = SDL_SwapLE16(0);
fhdr.sectorsizeid = SDL_SwapLE16(3);
fhdr.hashoffset = SDL_SwapLE32(32872);
fhdr.blockoffset = SDL_SwapLE32(104);
fhdr.hashcount = SDL_SwapLE32(2048);
fhdr.blockcount = SDL_SwapLE32(2048);

if (SetFilePointer(sghArchive, 0, NULL, FILE_BEGIN) == -1)
return 0;
Expand Down
28 changes: 17 additions & 11 deletions Source/town.cpp
Expand Up @@ -1007,7 +1007,7 @@ void SetTownMicros()
lv--;
pPiece = (WORD *)&pLevelPieces[32 * lv];
for (i = 0; i < 16; i++) {
pMap->mt[i] = pPiece[(i & 1) + 14 - (i & 0xE)];
pMap->mt[i] = SDL_SwapLE16(pPiece[(i & 1) + 14 - (i & 0xE)]);
}
} else {
for (i = 0; i < 16; i++) {
Expand All @@ -1032,8 +1032,9 @@ void SetTownMicros()

void T_FillSector(BYTE *P3Tiles, BYTE *pSector, int xi, int yi, int w, int h)
{
int i, j, xx, yy;
int i, j, xx, yy, nMap;
long v1, v2, v3, v4, ii;
WORD *Sector;

ii = 4;
yy = yi;
Expand All @@ -1043,11 +1044,14 @@ void T_FillSector(BYTE *P3Tiles, BYTE *pSector, int xi, int yi, int w, int h)
WORD *Map;

Map = (WORD *)&pSector[ii];
if (*Map) {
v1 = *((WORD *)&P3Tiles[(*Map - 1) * 8]) + 1;
v2 = *((WORD *)&P3Tiles[(*Map - 1) * 8] + 1) + 1;
v3 = *((WORD *)&P3Tiles[(*Map - 1) * 8] + 2) + 1;
v4 = *((WORD *)&P3Tiles[(*Map - 1) * 8] + 3) + 1;
nMap = SDL_SwapLE16(*Map);
if (nMap) {
Sector = (((WORD *)&P3Tiles[(nMap - 1) * 8]));
v1 = SDL_SwapLE16(*(Sector + 0)) + 1;
v2 = SDL_SwapLE16(*(Sector + 1)) + 1;
v3 = SDL_SwapLE16(*(Sector + 2)) + 1;
v4 = SDL_SwapLE16(*(Sector + 3)) + 1;

} else {
v1 = 0;
v2 = 0;
Expand All @@ -1068,11 +1072,13 @@ void T_FillSector(BYTE *P3Tiles, BYTE *pSector, int xi, int yi, int w, int h)
void T_FillTile(BYTE *P3Tiles, int xx, int yy, int t)
{
long v1, v2, v3, v4;
WORD *Tiles;

v1 = *((WORD *)&P3Tiles[(t - 1) * 8]) + 1;
v2 = *((WORD *)&P3Tiles[(t - 1) * 8] + 1) + 1;
v3 = *((WORD *)&P3Tiles[(t - 1) * 8] + 2) + 1;
v4 = *((WORD *)&P3Tiles[(t - 1) * 8] + 3) + 1;
Tiles = ((WORD *)&P3Tiles[(t - 1) * 8]);
v1 = SDL_SwapLE16(*(Tiles + 0)) + 1;
v2 = SDL_SwapLE16(*(Tiles + 1)) + 1;
v3 = SDL_SwapLE16(*(Tiles + 2)) + 1;
v4 = SDL_SwapLE16(*(Tiles + 3)) + 1;

dPiece[xx][yy] = v1;
dPiece[xx + 1][yy] = v2;
Expand Down

10 comments on commit d641c65

@arczi84
Copy link
Contributor

@arczi84 arczi84 commented on d641c65 Oct 7, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Except Source/mpqapi.cpp I'm the author of those byte swaps.

@AJenbo
Copy link
Member

@AJenbo AJenbo commented on d641c65 Oct 7, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry if I got it mixed up when going over the commits they appeared to me as originating from MBeijer. The remaining swaps are in your name and I'm about 2/3 done verifying them. It's unfortunately to late for me to change this commit since it has been merged to master, but let me know if there are any other issues with the rebase I did :

#306

@MBeijer
Copy link
Contributor Author

@MBeijer MBeijer commented on d641c65 Oct 7, 2019 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AJenbo
Copy link
Member

@AJenbo AJenbo commented on d641c65 Oct 7, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually MBeijer was the original author of all the changes here as can be seen in this commit AmigaPorts@d968a97

But I understand tre confusion since a later merge removed them by mistake and @arczi then added them again.

@arczi84
Copy link
Contributor

@arczi84 arczi84 commented on d641c65 Oct 7, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean I made corrections to these swaps because they were not working.

@arczi84
Copy link
Contributor

@arczi84 arczi84 commented on d641c65 Oct 7, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AJenbo
Copy link
Member

@AJenbo AJenbo commented on d641c65 Oct 7, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have simplified the commit history since there where more commits then lines of change, I have assigned the change to the person that did the initial bulk change. If you look at the full history you will see that both MBeijer and I made additional changes to this code, this is also true for the commits attributed to you, so I think it works out reasonably fair in the end.

@arczi84
Copy link
Contributor

@arczi84 arczi84 commented on d641c65 Oct 7, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Meh, it took me hours to fix this, I'm not at all in history :P

@MBeijer
Copy link
Contributor Author

@MBeijer MBeijer commented on d641c65 Oct 7, 2019 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AJenbo
Copy link
Member

@AJenbo AJenbo commented on d641c65 Oct 7, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arczi84 as mentioned I'm still in the process of reviewing your changes, I expect them to be in at the end of the day.

Please sign in to comment.