From 41a17b9da6ed1f4345bb0d492ac617862d0602f2 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Sat, 13 Sep 2003 12:03:29 +0000 Subject: let the interpreter use native endianess for variables -> this allows us to get rid of various endian conversions, and also fixs lots of other problems on BE systems. Beware, though, this may impair save game exchange between LE/BE: we'll have to adjust save_rest.cpp to convert to/from LE upon save/load svn-id: r10216 --- sword2/icons.cpp | 2 -- sword2/interpreter.cpp | 18 +++++++++--------- sword2/mouse.cpp | 34 +++++++++++++++++----------------- sword2/router.cpp | 21 +++++---------------- 4 files changed, 31 insertions(+), 44 deletions(-) (limited to 'sword2') diff --git a/sword2/icons.cpp b/sword2/icons.cpp index e747feace1..7df435ac1c 100644 --- a/sword2/icons.cpp +++ b/sword2/icons.cpp @@ -51,8 +51,6 @@ int32 FN_add_menu_object(int32 *params) //Tony1Oct96 // copy the structure to our in-the-engine list memcpy( &temp_list[total_temp], (uint8*) *params, sizeof(menu_object)); // - temp_list[total_temp].icon_resource = FROM_LE_32(temp_list[total_temp].icon_resource); - temp_list[total_temp].luggage_resource = FROM_LE_32(temp_list[total_temp].luggage_resource); total_temp++; return(IR_CONT); // script continue diff --git a/sword2/interpreter.cpp b/sword2/interpreter.cpp index f6fc161578..9958260584 100644 --- a/sword2/interpreter.cpp +++ b/sword2/interpreter.cpp @@ -396,8 +396,8 @@ int RunScript ( char * scriptData , char * objectData , uint32 *offset ) case CP_PUSH_LOCAL_VAR32: // 1 Push the contents of a local variable Read16ip(parameter) - DEBUG2("Push local var %d (%d)",parameter,(int32)READ_LE_UINT32(variables+parameter)); - PUSHONSTACK ( (int32)READ_LE_UINT32(variables+parameter) ); + DEBUG2("Push local var %d (%d)",parameter,*(int32 *)(variables+parameter)); + PUSHONSTACK ( *(int32 *)(variables+parameter) ); break; @@ -417,7 +417,7 @@ int RunScript ( char * scriptData , char * objectData , uint32 *offset ) Read16ip(parameter) POPOFFSTACK ( value ); DEBUG2("Pop %d into var %d",value,parameter); - *((int *)(variables+parameter)) = TO_LE_32(value); + *((int *)(variables+parameter)) = value; break; case CP_CALL_MCODE: // 4 Call an mcode routine @@ -518,15 +518,15 @@ int RunScript ( char * scriptData , char * objectData , uint32 *offset ) case CP_ADDNPOP_LOCAL_VAR32: // 10 Read16ip(parameter) POPOFFSTACK ( value ); - *((int *)(variables+parameter)) = TO_LE_32((int32)READ_LE_UINT32(variables+parameter) + value); - DEBUG3("+= %d into var %d->%d",value,parameter,(int32)READ_LE_UINT32(variables+parameter)); + *((int *)(variables+parameter)) = *(int32 *)(variables+parameter) + value; + DEBUG3("+= %d into var %d->%d",value,parameter,*(int32 *)(variables+parameter)); break; case CP_SUBNPOP_LOCAL_VAR32: // 11 Read16ip(parameter) POPOFFSTACK ( value ); - *((int *)(variables+parameter)) = TO_LE_32((int32)READ_LE_UINT32(variables+parameter) - value); - DEBUG3("-= %d into var %d->%d",value,parameter,(int32)READ_LE_UINT32(variables+parameter)); + *((int *)(variables+parameter)) = *(int32 *)(variables+parameter) - value; + DEBUG3("-= %d into var %d->%d",value,parameter,*(int32 *)(variables+parameter)); break; case CP_SKIPONTRUE: // 12 Skip if the value on the stack is TRUE @@ -574,7 +574,7 @@ int RunScript ( char * scriptData , char * objectData , uint32 *offset ) VS_COL_GREY); #else globalInterpreterVariables2[parameter] += value; - DEBUG3("+= %d into global var %d->%d",value,parameter,(int32)READ_LE_UINT32(variables+parameter)); + DEBUG3("+= %d into global var %d->%d",value,parameter,*(int32 *)(variables+parameter)); #endif break; } @@ -593,7 +593,7 @@ int RunScript ( char * scriptData , char * objectData , uint32 *offset ) VS_COL_GREY); #else globalInterpreterVariables2[parameter] -= value; - DEBUG3("-= %d into global var %d->%d",value,parameter,(int32)READ_LE_UINT32(variables+parameter)); + DEBUG3("-= %d into global var %d->%d",value,parameter,*(int32 *)(variables+parameter)); #endif break; } diff --git a/sword2/mouse.cpp b/sword2/mouse.cpp index 9dd116591f..938017a6ca 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 = 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].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].priority = FROM_LE_32(ob_mouse->priority); - mouse_list[cur_mouse].pointer = FROM_LE_32(ob_mouse->pointer); + mouse_list[cur_mouse].priority = ob_mouse->priority; + mouse_list[cur_mouse].pointer = ob_mouse->pointer; //----------------------------------------------- // (James17jun97) @@ -1321,10 +1321,10 @@ int32 FN_init_floor_mouse(int32 *params) // James29nov96 ob_mouse->x1 = 0; ob_mouse->y1 = 0; - ob_mouse->x2 = TO_LE_32(this_screen.screen_wide-1); - ob_mouse->y2 = TO_LE_32(this_screen.screen_deep-1); - ob_mouse->priority = TO_LE_32(9); // floor is always lowest priority - ob_mouse->pointer = TO_LE_32(NORMAL_MOUSE_ID); // normal pointer + ob_mouse->x2 = this_screen.screen_wide-1; + ob_mouse->y2 = this_screen.screen_deep-1; + ob_mouse->priority = 9; // floor is always lowest priority + ob_mouse->pointer = NORMAL_MOUSE_ID; // normal pointer return(IR_CONT); // continue script @@ -1342,12 +1342,12 @@ int32 FN_set_scroll_left_mouse(int32 *params) // James13feb97 ob_mouse->x1 = 0; ob_mouse->y1 = 0; - ob_mouse->x2 = TO_LE_32(this_screen.scroll_offset_x + SCROLL_MOUSE_WIDTH); - ob_mouse->y2 = TO_LE_32(this_screen.screen_deep-1); + ob_mouse->x2 = this_screen.scroll_offset_x + SCROLL_MOUSE_WIDTH; + ob_mouse->y2 = this_screen.screen_deep-1; ob_mouse->priority = 0; // highest priority if (this_screen.scroll_offset_x > 0) // if not fully scrolled to the left - ob_mouse->pointer = TO_LE_32(SCROLL_LEFT_MOUSE_ID); + ob_mouse->pointer = SCROLL_LEFT_MOUSE_ID; else ob_mouse->pointer = 0; // so the mouse area doesn't get registered @@ -1362,14 +1362,14 @@ int32 FN_set_scroll_right_mouse(int32 *params) // James13feb97 Object_mouse *ob_mouse = (Object_mouse *) params[0]; - ob_mouse->x1 = TO_LE_32(this_screen.scroll_offset_x + screenWide - SCROLL_MOUSE_WIDTH); + ob_mouse->x1 = this_screen.scroll_offset_x + screenWide - SCROLL_MOUSE_WIDTH; ob_mouse->y1 = 0; - ob_mouse->x2 = TO_LE_32(this_screen.screen_wide-1); - ob_mouse->y2 = TO_LE_32(this_screen.screen_deep-1); + ob_mouse->x2 = this_screen.screen_wide-1; + ob_mouse->y2 = this_screen.screen_deep-1; ob_mouse->priority = 0; // highest priority if (this_screen.scroll_offset_x < this_screen.max_scroll_offset_x) // if not fully scrolled to the right - ob_mouse->pointer = TO_LE_32(SCROLL_RIGHT_MOUSE_ID); + ob_mouse->pointer = SCROLL_RIGHT_MOUSE_ID; else ob_mouse->pointer = 0; // so the mouse area doesn't get registered diff --git a/sword2/router.cpp b/sword2/router.cpp index eb86964a65..06229dc29b 100644 --- a/sword2/router.cpp +++ b/sword2/router.cpp @@ -2645,11 +2645,11 @@ void LoadWalkData(Object_walkdata *ob_walkdata) uint32 frameCounter = 0; // starts at frame 0 of mega set (16sep96 JEL) - nWalkFrames = FROM_LE_32(ob_walkdata->nWalkFrames); - usingStandingTurnFrames = FROM_LE_32(ob_walkdata->usingStandingTurnFrames); - usingWalkingTurnFrames = FROM_LE_32(ob_walkdata->usingWalkingTurnFrames); - usingSlowInFrames = FROM_LE_32(ob_walkdata->usingSlowInFrames); - usingSlowOutFrames = FROM_LE_32(ob_walkdata->usingSlowOutFrames); + nWalkFrames = ob_walkdata->nWalkFrames; + usingStandingTurnFrames = ob_walkdata->usingStandingTurnFrames; + usingWalkingTurnFrames = ob_walkdata->usingWalkingTurnFrames; + usingSlowInFrames = ob_walkdata->usingSlowInFrames; + usingSlowOutFrames = ob_walkdata->usingSlowOutFrames; numberOfSlowOutFrames = usingSlowOutFrames; // 0 = not using slow out frames; non-zero = using that many frames for each leading leg for each direction memcpy(&numberOfSlowInFrames[0],ob_walkdata->nSlowInFrames,NO_DIRECTIONS*sizeof(numberOfSlowInFrames[0])); @@ -2657,17 +2657,6 @@ void LoadWalkData(Object_walkdata *ob_walkdata) memcpy(&dx[0],ob_walkdata->dx,NO_DIRECTIONS*(nWalkFrames+1)*sizeof(dx[0])); memcpy(&dy[0],ob_walkdata->dy,NO_DIRECTIONS*(nWalkFrames+1)*sizeof(dy[0])); -#ifdef SCUMM_BIG_ENDIAN - for (direction=0; direction