SCUMM: Skip endian conversion on little endian systems (instead of assigning values back to themselves)

svn-id: r53739
This commit is contained in:
Max Horn 2010-10-23 15:47:23 +00:00
parent 3534cff8ef
commit 0d54400806
7 changed files with 53 additions and 61 deletions

View File

@ -23,7 +23,6 @@
*
*/
#include "scumm/scumm.h"
#include "scumm/file.h"
#include "scumm/he/intern_he.h"
@ -40,9 +39,13 @@
namespace Scumm {
#if defined(SCUMM_LITTLE_ENDIAN)
#define LE16(x)
#define LE32(x)
#elif defined(SCUMM_BIG_ENDIAN)
#define LE16(x) ((x) = TO_LE_16(x))
#define LE32(x) ((x) = TO_LE_32(x))
#endif
ResExtractor::ResExtractor(ScummEngine_v70he *scumm)
: _vm(scumm) {
@ -207,9 +210,9 @@ int Win32ResExtractor::extractResource_(const char *resType, char *resName, byte
}
/* res_type_id_to_string:
* Translate a numeric resource type to it's corresponding string type.
* (For informative-ness.)
/**
* Translate a numeric resource type to it's corresponding string type.
* (For informative-ness.)
*/
const char *Win32ResExtractor::res_type_id_to_string(int id) {
if (id == 241)
@ -219,9 +222,9 @@ const char *Win32ResExtractor::res_type_id_to_string(int id) {
return NULL;
}
/* res_type_string_to_id:
* Translate a resource type string to integer.
* (Used to convert the --type option.)
/**
* Translate a resource type string to integer.
* (Used to convert the --type option.)
*/
const char *Win32ResExtractor::res_type_string_to_id(const char *type) {
static const char *res_type_ids[] = {
@ -242,18 +245,14 @@ const char *Win32ResExtractor::res_type_string_to_id(const char *type) {
return type;
}
/* return the resource id quoted if it's a string, otherwise just return it */
char *Win32ResExtractor::WinResource::get_resource_id_quoted() {
// FIXME: Using a static var here is EVIL and in fact, broken when
// used multiple times in a row, e.g. in a single call to printf()
// or debug()... which is in fact how we use this function... :-)
static char tmp[WINRES_ID_MAXLEN+2];
/**
* Return the resource id quoted if it is a string, otherwise (i.e. if
* it is numeric) just return it.
*/
Common::String Win32ResExtractor::WinResource::getQuotedResourceId() const {
if (numeric_id || id[0] == '\0')
return id;
sprintf(tmp, "'%s'", id);
return tmp;
return '"' + Common::String(id) + '"';
}
int Win32ResExtractor::extract_resources(WinLibrary *fi, WinResource *wr,
@ -283,16 +282,16 @@ int Win32ResExtractor::extract_resources(WinLibrary *fi, WinResource *wr,
if (lang_wr != NULL && lang_wr->id[0] != '\0') {
debugC(DEBUG_RESOURCE, "extractCursor(). Found cursor name: %s language: %s [size=%d]",
name_wr->get_resource_id_quoted(), lang_wr->get_resource_id_quoted(), size);
name_wr->getQuotedResourceId().c_str(), lang_wr->getQuotedResourceId().c_str(), size);
} else {
debugC(DEBUG_RESOURCE, "extractCursor(). Found cursor name: %s [size=%d]",
name_wr->get_resource_id_quoted(), size);
name_wr->getQuotedResourceId().c_str(), size);
}
return size;
}
/* extract_resource:
* Extract a resource, returning pointer to data.
/**
* Extract a resource, returning pointer to data.
*/
byte *Win32ResExtractor::extract_resource(WinLibrary *fi, WinResource *wr, int *size,
bool *free_it, char *type, char *lang, bool raw) {
@ -322,17 +321,17 @@ byte *Win32ResExtractor::extract_resource(WinLibrary *fi, WinResource *wr, int *
return NULL;
}
/* extract_group_icon_resource:
* Create a complete RT_GROUP_ICON resource, that can be written to
* an `.ico' file without modifications. Returns an allocated
* memory block that should be freed with free() once used.
/**
* Create a complete RT_GROUP_ICON resource, that can be written to
* an `.ico' file without modifications. Returns an allocated
* memory block that should be freed with free() once used.
*
* `root' is the offset in file that specifies the resource.
* `base' is the offset that string pointers are calculated from.
* `ressize' should point to an integer variable where the size of
* the returned memory block will be placed.
* `is_icon' indicates whether resource to be extracted is icon
* or cursor group.
* `root' is the offset in file that specifies the resource.
* `base' is the offset that string pointers are calculated from.
* `ressize' should point to an integer variable where the size of
* the returned memory block will be placed.
* `is_icon' indicates whether resource to be extracted is icon
* or cursor group.
*/
byte *Win32ResExtractor::extract_group_icon_cursor_resource(WinLibrary *fi, WinResource *wr, char *lang,
int *ressize, bool is_icon) {
@ -467,10 +466,10 @@ byte *Win32ResExtractor::extract_group_icon_cursor_resource(WinLibrary *fi, WinR
return memory;
}
/* check_offset:
* Check if a chunk of data (determined by offset and size)
* is within the bounds of the WinLibrary file.
* Usually not called directly.
/**
* Check if a chunk of data (determined by offset and size)
* is within the bounds of the WinLibrary file.
* Usually not called directly.
*/
bool Win32ResExtractor::check_offset(byte *memory, int total_size, const char *name, void *offset, int size) {
int need_size = (int)((byte *)offset - memory + size);
@ -487,8 +486,8 @@ bool Win32ResExtractor::check_offset(byte *memory, int total_size, const char *n
}
/* do_resources:
* Do something for each resource matching type, name and lang.
/**
* Do something for each resource matching type, name and lang.
*/
int Win32ResExtractor::do_resources(WinLibrary *fi, const char *type, char *name, char *lang, byte **data) {
WinResource *type_wr;
@ -496,7 +495,7 @@ int Win32ResExtractor::do_resources(WinLibrary *fi, const char *type, char *name
WinResource *lang_wr;
int size;
type_wr = (WinResource *)calloc(sizeof(WinResource)*3, 1);
type_wr = (WinResource *)calloc(3, sizeof(WinResource));
name_wr = type_wr + 1;
lang_wr = type_wr + 2;
@ -523,14 +522,11 @@ int Win32ResExtractor::do_resources_recurs(WinLibrary *fi, WinResource *base,
/* get a list of all resources at this level */
wr = list_resources(fi, base, &rescnt);
if (wr == NULL) {
if (size != 0)
return size;
else
return 0;
return size;
}
/* process each resource listed */
for (c = 0 ; c < rescnt ; c++) {
for (c = 0; c < rescnt; c++) {
/* (over)write the corresponding WinResource holder with the current */
memcpy(WINRESOURCE_BY_LEVEL(wr[c].level), wr+c, sizeof(WinResource));
@ -557,7 +553,9 @@ bool Win32ResExtractor::compare_resource_id(WinResource *wr, const char *id) {
return false;
if (id[0] == '-')
id++;
if (!(cmp1 = strtol(wr->id, 0, 10)) || !(cmp2 = strtol(id, 0, 10)) || cmp1 != cmp2)
cmp1 = strtol(wr->id, 0, 10);
cmp2 = strtol(id, 0, 10);
if (!cmp1 || !cmp2 || cmp1 != cmp2)
return false;
} else {
if (id[0] == '-')
@ -645,9 +643,9 @@ Win32ResExtractor::WinResource *Win32ResExtractor::list_pe_resources(WinLibrary
}
/* list_resources:
* Return an array of WinResource's in the current
* resource level specified by _res->
/**
* Return an array of WinResource's in the current
* resource level specified by _res->
*/
Win32ResExtractor::WinResource *Win32ResExtractor::list_resources(WinLibrary *fi, WinResource *res, int *count) {
if (res != NULL && !res->is_directory)
@ -659,10 +657,9 @@ Win32ResExtractor::WinResource *Win32ResExtractor::list_resources(WinLibrary *fi
count);
}
/* read_library:
* Read header and get resource directory offset in a Windows library
* (AKA module).
*
/**
* Read header and get resource directory offset in a Windows library
* (AKA module).
*/
bool Win32ResExtractor::read_library(WinLibrary *fi) {
/* check for DOS header signature `MZ' */
@ -743,9 +740,9 @@ bool Win32ResExtractor::read_library(WinLibrary *fi) {
return false;
}
/* calc_vma_size:
* Calculate the total amount of memory needed for a 32-bit Windows
* module. Returns -1 if file was too small.
/**
* Calculate the total amount of memory needed for a 32-bit Windows
* module. Returns -1 if file was too small.
*/
int Win32ResExtractor::calc_vma_size(WinLibrary *fi) {
Win32ImageSectionHeader *seg;

View File

@ -184,7 +184,7 @@ class Win32ResExtractor : public ResExtractor {
bool numeric_id;
bool is_directory;
char *get_resource_id_quoted();
Common::String getQuotedResourceId() const;
} PACKED_STRUCT;

View File

@ -34,7 +34,6 @@
#include "scumm/he/intern_he.h"
#include "scumm/object.h"
#include "scumm/resource.h"
#include "scumm/he/resource_he.h"
#include "scumm/scumm.h"
#include "scumm/he/sound_he.h"
#include "scumm/he/sprite_he.h"

View File

@ -31,7 +31,6 @@
#include "scumm/he/intern_he.h"
#include "scumm/object.h"
#include "scumm/resource.h"
#include "scumm/he/resource_he.h"
#include "scumm/scumm.h"
#include "scumm/he/sound_he.h"
#include "scumm/verbs.h"

View File

@ -36,7 +36,6 @@
#include "scumm/he/intern_he.h"
#include "scumm/object.h"
#include "scumm/resource.h"
#include "scumm/he/resource_he.h"
#include "scumm/scumm.h"
#include "scumm/he/sound_he.h"
#include "scumm/util.h"

View File

@ -35,7 +35,6 @@
#include "scumm/he/intern_he.h"
#include "scumm/object.h"
#include "scumm/resource.h"
#include "scumm/he/resource_he.h"
#include "scumm/scumm.h"
#include "scumm/he/sound_he.h"

View File

@ -32,7 +32,6 @@
#include "scumm/he/logic_he.h"
#include "scumm/object.h"
#include "scumm/resource.h"
#include "scumm/he/resource_he.h"
#include "scumm/scumm.h"
#include "scumm/sound.h"
#include "scumm/he/sprite_he.h"