Big endian fixes - part 2 (#405)
* Big endian fix for S3LoadSample and Win32SetPaletteEntries * Add the missing BR_ENDIAN_BIG guard to S3LoadSample Co-authored-by: Anonymous Maarten <madebr@users.noreply.github.com> * DRPixelmapDoubledCopy big endian fix * big endian fix for the KEYBOARD.COK loading * CalcLSChecksum big endian fix * PrintScreenFile big endian fix --------- Co-authored-by: Anonymous Maarten <madebr@users.noreply.github.com>
This commit is contained in:
parent
78ef3c27f2
commit
22369744bb
|
@ -3147,8 +3147,13 @@ void DRPixelmapDoubledCopy(br_pixelmap* pDestn, br_pixelmap* pSource, int pSourc
|
|||
for (j = 0; j < width_over_2; j++) {
|
||||
--sptr;
|
||||
pixels = *sptr;
|
||||
#if BR_ENDIAN_BIG
|
||||
pixel_1 = pixels >> 0;
|
||||
pixel_2 = pixels >> 8;
|
||||
#else
|
||||
pixel_1 = pixels >> 8;
|
||||
pixel_2 = pixels >> 0;
|
||||
#endif
|
||||
dptr[-1] = pixel_1;
|
||||
dptr2[-1] = pixel_1;
|
||||
dptr[-2] = pixel_1;
|
||||
|
|
|
@ -33,6 +33,11 @@ int gSave_allowed;
|
|||
(V) = BrHtoNL(V); \
|
||||
} while (0)
|
||||
|
||||
#define SWAP32_LE(V) \
|
||||
do { \
|
||||
(V) = BrHtoLL(V); \
|
||||
} while (0)
|
||||
|
||||
// IDA: void __usercall CorrectLoadByteOrdering(int pIndex@<EAX>)
|
||||
void CorrectLoadByteOrdering(int pIndex) {
|
||||
int i;
|
||||
|
@ -56,6 +61,29 @@ void CorrectLoadByteOrdering(int pIndex) {
|
|||
}
|
||||
}
|
||||
|
||||
#if BR_ENDIAN_BIG
|
||||
static void CorrectChecksumByteOrdering(tSave_game* pSaved_game) {
|
||||
int i;
|
||||
|
||||
SWAP32_LE(pSaved_game->version);
|
||||
SWAP32_LE(pSaved_game->rank);
|
||||
SWAP32_LE(pSaved_game->credits);
|
||||
SWAP32_LE(pSaved_game->skill_level);
|
||||
SWAP32_LE(pSaved_game->frank_or_annitude);
|
||||
SWAP32_LE(pSaved_game->game_completed);
|
||||
SWAP32_LE(pSaved_game->current_race_index);
|
||||
SWAP32_LE(pSaved_game->number_of_cars);
|
||||
for (i = 0; i < COUNT_OF(pSaved_game->cars_available); i++) {
|
||||
SWAP32_LE(pSaved_game->cars_available[i]);
|
||||
}
|
||||
SWAP32_LE(pSaved_game->current_car_index);
|
||||
SWAP32_LE(pSaved_game->redo_race_index);
|
||||
for (i = 0; i < COUNT_OF(pSaved_game->power_up_levels); i++) {
|
||||
SWAP32_LE(pSaved_game->power_up_levels[i]);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// IDA: tU32 __usercall CalcLSChecksum@<EAX>(tSave_game *pSaved_game@<EAX>)
|
||||
tU32 CalcLSChecksum(tSave_game* pSaved_game) {
|
||||
tU32 checksum;
|
||||
|
@ -70,12 +98,20 @@ tU32 CalcLSChecksum(tSave_game* pSaved_game) {
|
|||
}
|
||||
#endif
|
||||
|
||||
#if BR_ENDIAN_BIG
|
||||
CorrectChecksumByteOrdering(pSaved_game);
|
||||
#endif
|
||||
checksum = 0;
|
||||
for (i = 0, ptr = (tU8*)pSaved_game; i < (sizeof(tSave_game) - sizeof(tU32)); i++, ptr++) {
|
||||
checksum2 = (*ptr ^ 0xbd) + checksum;
|
||||
checksum = checksum ^ checksum2 << 25 ^ checksum2 >> 7;
|
||||
}
|
||||
#if BR_ENDIAN_BIG
|
||||
CorrectChecksumByteOrdering(pSaved_game);
|
||||
return BrHtoLL(checksum);
|
||||
#else
|
||||
return checksum;
|
||||
#endif
|
||||
}
|
||||
|
||||
// IDA: void __cdecl LoadSavedGames()
|
||||
|
|
|
@ -678,9 +678,15 @@ void PrintScreenFile(FILE* pF) {
|
|||
// 3. Color table (=palette)
|
||||
for (i = 0; i < 256; i++) {
|
||||
// red, green, blue, unused
|
||||
#if BR_ENDIAN_BIG
|
||||
WriteU8L(pF, ((tU8*)gCurrent_palette->pixels)[4 * i + 3]);
|
||||
WriteU8L(pF, ((tU8*)gCurrent_palette->pixels)[4 * i + 2]);
|
||||
WriteU8L(pF, ((tU8*)gCurrent_palette->pixels)[4 * i + 1]);
|
||||
#else
|
||||
WriteU8L(pF, ((tU8*)gCurrent_palette->pixels)[4 * i]);
|
||||
WriteU8L(pF, ((tU8*)gCurrent_palette->pixels)[4 * i + 1]);
|
||||
WriteU8L(pF, ((tU8*)gCurrent_palette->pixels)[4 * i + 2]);
|
||||
#endif
|
||||
WriteU8L(pF, 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -130,6 +130,12 @@ void PDInitialiseSystem(void) {
|
|||
fread(gASCII_table, len / 2, 1, f);
|
||||
fread(gASCII_shift_table, len / 2, 1, f);
|
||||
fclose(f);
|
||||
#if BR_ENDIAN_BIG
|
||||
for (int i = 0; i < 128; i++) {
|
||||
gASCII_table[i] = BrSwap32(gASCII_table[i]);
|
||||
gASCII_shift_table[i] = BrSwap32(gASCII_shift_table[i]);
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
memcpy(gASCII_table, harness_game_info.defines.ascii_table, sizeof(gASCII_table));
|
||||
memcpy(gASCII_shift_table, harness_game_info.defines.ascii_shift_table, sizeof(gASCII_shift_table));
|
||||
|
|
|
@ -391,6 +391,12 @@ void PDInitialiseSystem(void) {
|
|||
fread(gASCII_table, len, 1u, f);
|
||||
fread(gASCII_shift_table, len, 1u, f);
|
||||
fclose(f);
|
||||
#if BR_ENDIAN_BIG
|
||||
for (int i = 0; i < 128; i++) {
|
||||
gASCII_table[i] = BrSwap32(gASCII_table[i]);
|
||||
gASCII_shift_table[i] = BrSwap32(gASCII_shift_table[i]);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
Win32InitInputDevice();
|
||||
}
|
||||
|
@ -719,9 +725,15 @@ void Win32SetPaletteEntries(uint8_t* entries, int pFirst_colour, int pCount) {
|
|||
}
|
||||
for (i = pFirst_colour; i <= last_colour; i++) {
|
||||
gWin32_palette[i].peFlags = 0;
|
||||
#if BR_ENDIAN_BIG
|
||||
gWin32_palette[i].peRed = entries[i * 4 + 1];
|
||||
gWin32_palette[i].peGreen = entries[i * 4 + 2];
|
||||
gWin32_palette[i].peBlue = entries[i * 4 + 3];
|
||||
#else
|
||||
gWin32_palette[i].peRed = entries[i * 4 + 2];
|
||||
gWin32_palette[i].peGreen = entries[i * 4 + 1];
|
||||
gWin32_palette[i].peBlue = entries[i * 4];
|
||||
#endif
|
||||
}
|
||||
SSDXSetPaleeteEntries(gWin32_palette, 0, 256);
|
||||
}
|
||||
|
|
|
@ -55,10 +55,17 @@ int S3LoadSample(tS3_sound_id id) {
|
|||
if (memcmp(buf, "RIFF", 4) == 0) {
|
||||
wav_header* hdr = (wav_header*)buf;
|
||||
sample->dataptr = &buf[sizeof(wav_header)];
|
||||
#if BR_ENDIAN_BIG
|
||||
sample->size = BrSwap32(hdr->data_bytes);
|
||||
sample->rate = BrSwap32(hdr->sample_rate);
|
||||
sample->resolution = BrSwap16(hdr->bit_depth);
|
||||
sample->channels = BrSwap16(hdr->num_channels);
|
||||
#else
|
||||
sample->size = hdr->data_bytes;
|
||||
sample->rate = hdr->sample_rate;
|
||||
sample->resolution = hdr->bit_depth;
|
||||
sample->channels = hdr->num_channels;
|
||||
#endif
|
||||
} else {
|
||||
sample->rate = 16000;
|
||||
sample->resolution = 8;
|
||||
|
|
Loading…
Reference in New Issue