diff options
author | Oliver Kiehl | 2003-09-12 18:52:53 +0000 |
---|---|---|
committer | Oliver Kiehl | 2003-09-12 18:52:53 +0000 |
commit | 9dc282f1d59c75f4aa0cbda6e85efd6ea30dc347 (patch) | |
tree | f25d78715f0ec40cf2ec5be5ead7e73ca88a22bf /sword2 | |
parent | c805e260a9a871db17866c2957ccc9042d46763c (diff) | |
download | scummvm-rg350-9dc282f1d59c75f4aa0cbda6e85efd6ea30dc347.tar.gz scummvm-rg350-9dc282f1d59c75f4aa0cbda6e85efd6ea30dc347.tar.bz2 scummvm-rg350-9dc282f1d59c75f4aa0cbda6e85efd6ea30dc347.zip |
endian fixes
svn-id: r10192
Diffstat (limited to 'sword2')
-rw-r--r-- | sword2/driver/_mouse.cpp | 2 | ||||
-rw-r--r-- | sword2/driver/d_sound.cpp | 2 | ||||
-rw-r--r-- | sword2/driver/render.cpp | 2 | ||||
-rw-r--r-- | sword2/maketext.cpp | 7 | ||||
-rw-r--r-- | sword2/mouse.cpp | 12 | ||||
-rw-r--r-- | sword2/protocol.cpp | 72 | ||||
-rw-r--r-- | sword2/resman.cpp | 140 | ||||
-rw-r--r-- | sword2/resman.h | 1 |
8 files changed, 176 insertions, 62 deletions
diff --git a/sword2/driver/_mouse.cpp b/sword2/driver/_mouse.cpp index 1bef8ae0cf..b58f016681 100644 --- a/sword2/driver/_mouse.cpp +++ b/sword2/driver/_mouse.cpp @@ -349,7 +349,7 @@ int32 AnimateMouse(void) { if (++mouseFrame == mouseAnim->noAnimFrames) mouseFrame = MOUSEFLASHFRAME; - mouseSprite = (uint8 *) mouseAnim + *(mouseOffsets + mouseFrame); + mouseSprite = (uint8 *) mouseAnim + (int32)READ_LE_UINT32(mouseOffsets + mouseFrame); if (mouseFrame != prevMouseFrame) DrawMouse(); diff --git a/sword2/driver/d_sound.cpp b/sword2/driver/d_sound.cpp index c14892385d..bcbbe3329d 100644 --- a/sword2/driver/d_sound.cpp +++ b/sword2/driver/d_sound.cpp @@ -698,7 +698,7 @@ int32 Sword2Sound::OpenFx(int32 id, uint8 *data) { while (i < 100) { if (*data == 'd') { data32 = (uint32*)data; - if (*data32 == 'atad') + if (READ_LE_UINT32(data32) == 'atad') break; } i += 1; diff --git a/sword2/driver/render.cpp b/sword2/driver/render.cpp index 80e801d837..d7983c5eda 100644 --- a/sword2/driver/render.cpp +++ b/sword2/driver/render.cpp @@ -1139,7 +1139,7 @@ int32 InitialiseBackgroundLayer(_parallax *p) { memset(memchunk, 0, p->w * p->h); for (i = 0; i < p->h; i++) { - if (p->offset[i] == 0) + if (FROM_LE_32(p->offset[i]) == 0) continue; line = (_parallaxLine *) ((uint8 *) p + FROM_LE_32(p->offset[i])); diff --git a/sword2/maketext.cpp b/sword2/maketext.cpp index 4f22632eab..392bdb9cbd 100644 --- a/sword2/maketext.cpp +++ b/sword2/maketext.cpp @@ -367,6 +367,13 @@ _frameHeader* FindChar( uint8 ch, uint8 *charSet ) if( (ch<FIRST_CHAR) ) // if 'ch' out of range // if( (ch<FIRST_CHAR) || (ch>LAST_CHAR) ) // if 'ch' out of range ch = DUD; // then print the 'dud' character (chequered flag) +// FIXME: HACK!!!! remapping ' and ! because they cause FetchFrameHeader to crash.... +#ifdef MACOSX + if (ch == '\'') + ch = ' '; + if (ch == '!') + ch = ' '; +#endif // address of char = address of charSet + offset to char //return (charSet + *(int32 *)(charSet + sizeof(_header) + 4 + 4*(ch - FIRST_CHAR))); diff --git a/sword2/mouse.cpp b/sword2/mouse.cpp index 1c66031736..ca6fa25723 100644 --- a/sword2/mouse.cpp +++ b/sword2/mouse.cpp @@ -1252,13 +1252,13 @@ int32 FN_register_mouse(int32 *params) //Tony29Oct96 Con_fatal_error("ERROR: mouse_list full [%s line %u]",__FILE__,__LINE__); #endif - mouse_list[cur_mouse].x1 = ob_mouse->x1; - mouse_list[cur_mouse].y1 = ob_mouse->y1; - mouse_list[cur_mouse].x2 = ob_mouse->x2; - mouse_list[cur_mouse].y2 = ob_mouse->y2; + mouse_list[cur_mouse].x1 = FROM_LE_32(ob_mouse->x1); + mouse_list[cur_mouse].y1 = FROM_LE_32(ob_mouse->y1); + mouse_list[cur_mouse].x2 = FROM_LE_32(ob_mouse->x2); + mouse_list[cur_mouse].y2 = FROM_LE_32(ob_mouse->y2); - mouse_list[cur_mouse].priority = ob_mouse->priority; - mouse_list[cur_mouse].pointer = ob_mouse->pointer; + mouse_list[cur_mouse].priority = FROM_LE_32(ob_mouse->priority); + mouse_list[cur_mouse].pointer = FROM_LE_32(ob_mouse->pointer); //----------------------------------------------- // (James17jun97) diff --git a/sword2/protocol.cpp b/sword2/protocol.cpp index 232113cd13..427ef04a4b 100644 --- a/sword2/protocol.cpp +++ b/sword2/protocol.cpp @@ -40,7 +40,7 @@ uint8 *FetchPalette(uint8 *screenFile) // Chris 04Oct96 _multiScreenHeader *mscreenHeader = (_multiScreenHeader *) (screenFile + sizeof(_standardHeader)); - palette = (uint8 *)mscreenHeader + FROM_LE_32(mscreenHeader->palette); + palette = (uint8 *)mscreenHeader + mscreenHeader->palette; palette[0] = 0; // always set colour 0 to black palette[1] = 0; // because most background screen palettes have a bright colour 0 @@ -57,7 +57,7 @@ uint8 *FetchPaletteMatchTable(uint8 *screenFile) // James 09dec96 { _multiScreenHeader *mscreenHeader = (_multiScreenHeader *) (screenFile + sizeof(_standardHeader)); - return (uint8 *) mscreenHeader + FROM_LE_32(mscreenHeader->paletteTable); + return (uint8 *) mscreenHeader + mscreenHeader->paletteTable; } //----------------------------------------------------------------------------------------------------------------------- @@ -67,13 +67,7 @@ _screenHeader *FetchScreenHeader(uint8 *screenFile) //Chris 04Oct96 { // Get the table _multiScreenHeader *mscreenHeader = (_multiScreenHeader *) (screenFile + sizeof(_standardHeader)); - _screenHeader *screenHeader = (_screenHeader*) ((uint8 *) mscreenHeader + FROM_LE_32(mscreenHeader->screen)); - -#if defined(SCUMM_BIG_ENDIAN) - screenHeader->width = SWAP_BYTES_16(screenHeader->width); - screenHeader->height = SWAP_BYTES_16(screenHeader->height); - screenHeader->noLayers = SWAP_BYTES_16(screenHeader->noLayers); -#endif + _screenHeader *screenHeader = (_screenHeader*) ((uint8 *) mscreenHeader + mscreenHeader->screen); return screenHeader; } @@ -92,16 +86,7 @@ _layerHeader *FetchLayerHeader(uint8 *screenFile, uint16 layerNo) //Chris 04Oct9 _multiScreenHeader *mscreenHeader = (_multiScreenHeader *) (screenFile + sizeof(_standardHeader)); - _layerHeader *layerHeader = (_layerHeader *) ((uint8 *) mscreenHeader + FROM_LE_32(mscreenHeader->layers) + (layerNo * sizeof(_layerHeader))); - -#if defined(SCUMM_BIG_ENDIAN) - layerHeader->x = SWAP_BYTES_16(layerHeader->x); - layerHeader->y = SWAP_BYTES_16(layerHeader->y); - layerHeader->width = SWAP_BYTES_16(layerHeader->width); - layerHeader->height = SWAP_BYTES_16(layerHeader->height); - layerHeader->maskSize = SWAP_BYTES_32(layerHeader->maskSize); - layerHeader->offset = SWAP_BYTES_32(layerHeader->offset); -#endif + _layerHeader *layerHeader = (_layerHeader *) ((uint8 *) mscreenHeader + mscreenHeader->layers + (layerNo * sizeof(_layerHeader))); return layerHeader; } @@ -114,7 +99,7 @@ uint8 *FetchShadingMask(uint8 *screenFile) // James 08apr97 { _multiScreenHeader *mscreenHeader = (_multiScreenHeader *) (screenFile + sizeof(_standardHeader)); - return (uint8 *) mscreenHeader + FROM_LE_32(mscreenHeader->maskOffset); + return (uint8 *) mscreenHeader + mscreenHeader->maskOffset; } //----------------------------------------------------------------------------------------------------------------------- @@ -126,15 +111,6 @@ _animHeader *FetchAnimHeader(uint8 *animFile) // (25sep96JEL) _animHeader *animHead; animHead = (_animHeader *) (animFile + sizeof(_standardHeader)); -#if defined(SCUMM_BIG_ENDIAN) - animHead->noAnimFrames = SWAP_BYTES_16(animHead->noAnimFrames); - animHead->feetStartX = SWAP_BYTES_16(animHead->feetStartX); - animHead->feetStartY = SWAP_BYTES_16(animHead->feetStartY); - animHead->feetEndX = SWAP_BYTES_16(animHead->feetEndX); - animHead->feetEndY = SWAP_BYTES_16(animHead->feetEndY); - animHead->blend = SWAP_BYTES_16(animHead->blend); -#endif - return animHead; } @@ -157,12 +133,6 @@ _cdtEntry *FetchCdtEntry(uint8 *animFile, uint16 frameNo) // Chris 09Oct96 _cdtEntry *cdtEntry; cdtEntry = (_cdtEntry *) ( (uint8 *)animHead + sizeof(_animHeader) + frameNo * sizeof(_cdtEntry) ); -#if defined(SCUMM_BIG_ENDIAN) - cdtEntry->x = (int16)SWAP_BYTES_16(cdtEntry->x); - cdtEntry->y = (int16)SWAP_BYTES_16(cdtEntry->y); - cdtEntry->frameOffset = SWAP_BYTES_32(cdtEntry->frameOffset); -#endif - return cdtEntry; } @@ -176,12 +146,6 @@ _frameHeader *FetchFrameHeader(uint8 *animFile, uint16 frameNo) // James 31oct96 // required address = (address of the start of the anim header) + frameOffset _frameHeader *frameHeader = (_frameHeader *) (animFile + sizeof(_standardHeader) + (FetchCdtEntry(animFile,frameNo)->frameOffset) ); -#if defined(SCUMM_BIG_ENDIAN) - frameHeader->compSize = SWAP_BYTES_32(frameHeader->compSize); - frameHeader->width = SWAP_BYTES_16(frameHeader->width); - frameHeader->height = SWAP_BYTES_16(frameHeader->height); -#endif - return frameHeader; } //--------------------------------------------------------------- @@ -192,12 +156,13 @@ _parallax *FetchBackgroundParallaxLayer(uint8 *screenFile, int layer) // Chris 0 _multiScreenHeader *mscreenHeader = (_multiScreenHeader *) (screenFile + sizeof(_standardHeader)); #ifdef _SWORD2_DEBUG - if (FROM_LE_32(mscreenHeader->bg_parallax[layer]) == 0) + if (mscreenHeader->bg_parallax[layer] == 0) Con_fatal_error("FetchBackgroundParallaxLayer(%d) - No parallax layer exists (%s line %u)",layer,__FILE__,__LINE__); #endif - _parallax *parallax = (_parallax *) ((uint8 *) mscreenHeader + FROM_LE_32(mscreenHeader->bg_parallax[layer])); + _parallax *parallax = (_parallax *) ((uint8 *) mscreenHeader + mscreenHeader->bg_parallax[layer]); +// FIXME: this shouldn't be here #if defined(SCUMM_BIG_ENDIAN) parallax->w = SWAP_BYTES_16(parallax->w); parallax->h = SWAP_BYTES_16(parallax->h); @@ -211,17 +176,18 @@ _parallax *FetchBackgroundLayer(uint8 *screenFile) // Chris 04Oct96 _multiScreenHeader *mscreenHeader = (_multiScreenHeader *) (screenFile + sizeof(_standardHeader)); #ifdef _SWORD2_DEBUG - if (FROM_LE_32(mscreenHeader->screen) == 0) + if (mscreenHeader->screen == 0) Con_fatal_error("FetchBackgroundLayer (%d) - No background layer exists (%s line %u)",__FILE__,__LINE__); #endif - _parallax *parallax = (_parallax *) ((uint8 *) mscreenHeader + FROM_LE_32(mscreenHeader->screen) + sizeof(_screenHeader)); + _parallax *parallax = (_parallax *) ((uint8 *) mscreenHeader + mscreenHeader->screen + sizeof(_screenHeader)); +// FIXME: this shouldn't be here #if defined(SCUMM_BIG_ENDIAN) parallax->w = SWAP_BYTES_16(parallax->w); parallax->h = SWAP_BYTES_16(parallax->h); #endif - + return parallax; } //--------------------------------------------------------------- @@ -230,12 +196,13 @@ _parallax *FetchForegroundParallaxLayer(uint8 *screenFile, int layer) // Chris 0 _multiScreenHeader *mscreenHeader = (_multiScreenHeader *) (screenFile + sizeof(_standardHeader)); #ifdef _SWORD2_DEBUG - if (FROM_LE_32(mscreenHeader->fg_parallax[layer]) == 0) + if (mscreenHeader->fg_parallax[layer] == 0) Con_fatal_error("FetchForegroundParallaxLayer(%d) - No parallax layer exists (%s line %u)",layer,__FILE__,__LINE__); #endif - _parallax *parallax = (_parallax *) ((uint8 *) mscreenHeader + FROM_LE_32(mscreenHeader->fg_parallax[layer])); + _parallax *parallax = (_parallax *) ((uint8 *) mscreenHeader + mscreenHeader->fg_parallax[layer]); +// FIXME: this shouldn't be here #if defined(SCUMM_BIG_ENDIAN) parallax->w = SWAP_BYTES_16(parallax->w); parallax->h = SWAP_BYTES_16(parallax->h); @@ -256,19 +223,18 @@ uint8 *FetchTextLine(uint8 *file, uint32 text_line) //Tony24Oct96 _textHeader *text_header = (_textHeader *) (file + sizeof(_standardHeader)); - if (text_line>=FROM_LE_32(text_header->noOfLines)) // (James08aug97) + if (text_line>=text_header->noOfLines) // (James08aug97) { fileHeader = (_standardHeader*)file; - sprintf ((char*)errorLine, "xxMissing line %d of %s (only 0..%d)", text_line, fileHeader->name, FROM_LE_32(text_header->noOfLines)-1); + sprintf ((char*)errorLine, "xxMissing line %d of %s (only 0..%d)", text_line, fileHeader->name, text_header->noOfLines-1); errorLine[0]=0; // first 2 chars are NULL so that actor-number comes out as '0' errorLine[1]=0; return(errorLine); // GOT RID OF CON_FATAL_ERROR HERE BECAUSE WE DON'T WANT IT TO CRASH OUT ANY MORE! -// Con_fatal_error("FetchTextLine cannot get %d, only 0..%d avail (%s line %u)", text_line, FROM_LE_32(text_header->noOfLines)-1,__FILE__,__LINE__); +// Con_fatal_error("FetchTextLine cannot get %d, only 0..%d avail (%s line %u)", text_line, text_header->noOfLines-1,__FILE__,__LINE__); } - point=(uint32*) text_header+1; //point to the lookup table return( (uint8*) (file + READ_LE_UINT32(point+text_line)) ); @@ -279,7 +245,7 @@ uint8 CheckTextLine(uint8 *file, uint32 text_line) // (James26jun97) { _textHeader *text_header = (_textHeader *) (file + sizeof(_standardHeader)); - if (text_line>=FROM_LE_32(text_header->noOfLines)) + if (text_line>=text_header->noOfLines) return(0); // out of range => invalid else return(1); // valid diff --git a/sword2/resman.cpp b/sword2/resman.cpp index 14f5b3acc6..7b667c2b85 100644 --- a/sword2/resman.cpp +++ b/sword2/resman.cpp @@ -368,6 +368,10 @@ uint8 *resMan::Res_open(uint32 res) { //BHTony30May96 //close the cluster file.close(); + +#ifdef SCUMM_BIG_ENDIAN + convertEndian((uint8 *) resList[res]->ad); +#endif } else { // Zdebug("RO %d, already open count=%d", res, count[res]); } @@ -386,6 +390,142 @@ uint8 *resMan::Res_open(uint32 res) { //BHTony30May96 return (uint8 *) resList[res]->ad; } +void resMan::convertEndian(uint8 *file) { + _standardHeader *hdr = (_standardHeader *)file; + + hdr->compSize = SWAP_BYTES_32(hdr->compSize); + hdr->decompSize = SWAP_BYTES_32(hdr->decompSize); + + switch(hdr->fileType) { + case ANIMATION_FILE: { + _animHeader *animHead = (_animHeader *) (file + sizeof(_standardHeader)); + + animHead->noAnimFrames = SWAP_BYTES_16(animHead->noAnimFrames); + animHead->feetStartX = SWAP_BYTES_16(animHead->feetStartX); + animHead->feetStartY = SWAP_BYTES_16(animHead->feetStartY); + animHead->feetEndX = SWAP_BYTES_16(animHead->feetEndX); + animHead->feetEndY = SWAP_BYTES_16(animHead->feetEndY); + animHead->blend = SWAP_BYTES_16(animHead->blend); + + int i; + for (i = 0; i < animHead->noAnimFrames; i++) { + _cdtEntry *cdtEntry = (_cdtEntry *) ( (uint8 *)animHead + sizeof(_animHeader) + i * sizeof(_cdtEntry) ); + cdtEntry->x = (int16)SWAP_BYTES_16(cdtEntry->x); + cdtEntry->y = (int16)SWAP_BYTES_16(cdtEntry->y); + cdtEntry->frameOffset = SWAP_BYTES_32(cdtEntry->frameOffset); + + _frameHeader *frameHeader = (_frameHeader *) (file + sizeof(_standardHeader) + cdtEntry->frameOffset); + frameHeader->compSize = SWAP_BYTES_32(frameHeader->compSize); + frameHeader->width = SWAP_BYTES_16(frameHeader->width); + frameHeader->height = SWAP_BYTES_16(frameHeader->height); + } + break; + } + case SCREEN_FILE: { + _multiScreenHeader *mscreenHeader = (_multiScreenHeader *) (file + sizeof(_standardHeader)); + + mscreenHeader->palette = SWAP_BYTES_32(mscreenHeader->palette); + mscreenHeader->bg_parallax[0] = SWAP_BYTES_32(mscreenHeader->bg_parallax[0]); + mscreenHeader->bg_parallax[1] = SWAP_BYTES_32(mscreenHeader->bg_parallax[1]); + mscreenHeader->screen = SWAP_BYTES_32(mscreenHeader->screen); + mscreenHeader->fg_parallax[0] = SWAP_BYTES_32(mscreenHeader->fg_parallax[0]); + mscreenHeader->fg_parallax[1] = SWAP_BYTES_32(mscreenHeader->fg_parallax[1]); + mscreenHeader->layers = SWAP_BYTES_32(mscreenHeader->layers); + mscreenHeader->paletteTable = SWAP_BYTES_32(mscreenHeader->paletteTable); + mscreenHeader->maskOffset = SWAP_BYTES_32(mscreenHeader->maskOffset); + + // screenHeader + _screenHeader *screenHeader = (_screenHeader*) ((uint8 *) mscreenHeader + mscreenHeader->screen); + + screenHeader->width = SWAP_BYTES_16(screenHeader->width); + screenHeader->height = SWAP_BYTES_16(screenHeader->height); + screenHeader->noLayers = SWAP_BYTES_16(screenHeader->noLayers); + + // layerHeader + _layerHeader *layerHeader; + int i; + for (i = 0; i < screenHeader->noLayers; i++) { + layerHeader = (_layerHeader *) ((uint8 *) mscreenHeader + mscreenHeader->layers + (i * sizeof(_layerHeader))); + + layerHeader->x = SWAP_BYTES_16(layerHeader->x); + layerHeader->y = SWAP_BYTES_16(layerHeader->y); + layerHeader->width = SWAP_BYTES_16(layerHeader->width); + layerHeader->height = SWAP_BYTES_16(layerHeader->height); + layerHeader->maskSize = SWAP_BYTES_32(layerHeader->maskSize); + layerHeader->offset = SWAP_BYTES_32(layerHeader->offset); + } + + // FIXME: byte swapping should be done here instead of in protocol.cpp +/* + // backgroundParallaxLayer + _parallax *parallax; + parallax = (_parallax *) ((uint8 *) mscreenHeader + mscreenHeader->bg_parallax[0]); + parallax->w = SWAP_BYTES_16(parallax->w); + parallax->h = SWAP_BYTES_16(parallax->h); + + parallax = (_parallax *) ((uint8 *) mscreenHeader + mscreenHeader->bg_parallax[1]); + parallax->w = SWAP_BYTES_16(parallax->w); + parallax->h = SWAP_BYTES_16(parallax->h); + + // backgroundLayer + parallax = (_parallax *) ((uint8 *) mscreenHeader + mscreenHeader->screen + sizeof(_screenHeader)); + parallax->w = SWAP_BYTES_16(parallax->w); + parallax->h = SWAP_BYTES_16(parallax->h); + + // foregroundParallaxLayer + parallax = (_parallax *) ((uint8 *) mscreenHeader + mscreenHeader->fg_parallax[0]); + parallax->w = SWAP_BYTES_16(parallax->w); + parallax->h = SWAP_BYTES_16(parallax->h); + + parallax = (_parallax *) ((uint8 *) mscreenHeader + mscreenHeader->fg_parallax[1]); + parallax->w = SWAP_BYTES_16(parallax->w); + parallax->h = SWAP_BYTES_16(parallax->h); +*/ + + break; + } + case GAME_OBJECT: { + _object_hub *objectHub = (_object_hub *) ((_standardHeader *)file+1); + + objectHub->type = (int)SWAP_BYTES_32(objectHub->type); + objectHub->logic_level = SWAP_BYTES_32(objectHub->logic_level); + + int i; + for (i = 0; i < TREE_SIZE; i++) { + objectHub->logic[i] = SWAP_BYTES_32(objectHub->logic[i]); + objectHub->script_id[i] = SWAP_BYTES_32(objectHub->script_id[i]); + objectHub->script_pc[i] = SWAP_BYTES_32(objectHub->script_pc[i]); + } + break; + } + case WALK_GRID_FILE: { + _walkGridHeader *walkGridHeader = (_walkGridHeader *)file; + walkGridHeader->numBars = SWAP_BYTES_32(walkGridHeader->numBars); + walkGridHeader->numNodes = SWAP_BYTES_32(walkGridHeader->numNodes); + + break; + } + case GLOBAL_VAR_FILE: + break; + case PARALLAX_FILE_null: + break; + case RUN_LIST: + break; + case TEXT_FILE: { + _textHeader *textHeader = (_textHeader *) (file + sizeof(_standardHeader)); + textHeader->noOfLines = SWAP_BYTES_32(textHeader->noOfLines); + break; + } + case SCREEN_MANAGER: + break; + case MOUSE_FILE: + break; + case ICON_FILE: + break; + } +} + + uint8 resMan::Res_check_valid(uint32 res) { // James 12mar97 // returns '1' if resource is valid, otherwise returns '0' // used in startup.cpp to ignore invalid screen-manager resources diff --git a/sword2/resman.h b/sword2/resman.h index fb7a215b1e..ec09fe639e 100644 --- a/sword2/resman.h +++ b/sword2/resman.h @@ -44,6 +44,7 @@ class resMan void Res_close(uint32 res); //decrements the count //---- + void convertEndian(uint8 *ad); uint8 Res_check_valid( uint32 res ); // returns '0' if resource out of range or null, otherwise '1' for ok |