aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engines/sci/scicore/resource.cpp219
-rw-r--r--engines/sci/scicore/resource_map.cpp90
-rw-r--r--engines/sci/scicore/resource_patch.cpp30
-rw-r--r--engines/sci/scicore/sci_memory.cpp69
4 files changed, 142 insertions, 266 deletions
diff --git a/engines/sci/scicore/resource.cpp b/engines/sci/scicore/resource.cpp
index fc8a59336b..0a40d0f6a0 100644
--- a/engines/sci/scicore/resource.cpp
+++ b/engines/sci/scicore/resource.cpp
@@ -23,7 +23,7 @@
*
*/
-/* Resource library */
+// Resource library
#include "common/archive.h"
#include "common/file.h"
@@ -31,12 +31,12 @@
#include "sci/include/sci_memory.h"
#include "sci/include/sciresource.h"
-#include "sci/include/vocabulary.h" /* For SCI version auto-detection */
+#include "sci/include/vocabulary.h"
namespace Sci {
#undef SCI_REQUIRE_RESOURCE_FILES
-/* #define SCI_VERBOSE_RESMGR 1 */
+//#define SCI_VERBOSE_RESMGR 1
// FIXME: Get rid of G_DIR_SEPARATOR / G_DIR_SEPARATOR_S
#if _MSC_VER
@@ -80,7 +80,7 @@ const char* sci_resource_types[] = {"view", "pic", "script", "text", "sound",
"patch", "bitmap", "palette", "cdaudio",
"audio", "sync", "message", "map", "heap"
};
-/* These are the 18 resource types supported by SCI1 */
+// These are the 18 resource types supported by SCI1
const char *sci_resource_type_suffixes[] = {"v56", "p56", "scr", "tex", "snd",
" ", "voc", "fon", "cur", "pat",
@@ -91,7 +91,6 @@ const char *sci_resource_type_suffixes[] = {"v56", "p56", "scr", "tex", "snd",
int resourcecmp(const void *first, const void *second);
-
typedef int decomp_funct(resource_t *result, Common::ReadStream &stream, int sci_version);
typedef void patch_sprintf_funct(char *string, resource_t *res);
@@ -133,15 +132,10 @@ int resourcecmp(const void *first, const void *second) {
}
-
-
-
-/*-----------------------------*/
-/*-- Resmgr helper functions --*/
-/*-----------------------------*/
+//-- Resmgr helper functions --
void _scir_add_altsource(resource_t *res, ResourceSource *source, unsigned int file_offset) {
- resource_altsource_t *rsrc = (resource_altsource_t*)sci_malloc(sizeof(resource_altsource_t));
+ resource_altsource_t *rsrc = (resource_altsource_t *)sci_malloc(sizeof(resource_altsource_t));
rsrc->next = res->alt_sources;
rsrc->source = source;
@@ -157,14 +151,12 @@ resource_t *_scir_find_resource_unsorted(resource_t *res, int res_nr, int type,
return NULL;
}
-/*-----------------------------------*/
-/** Resource source list management **/
-/*-----------------------------------*/
+// Resource source list management
ResourceSource *scir_add_external_map(ResourceManager *mgr, const char *file_name) {
ResourceSource *newsrc = new ResourceSource();
- /* Add the new source to the SLL of sources */
+ // Add the new source to the SLL of sources
newsrc->next = mgr->_sources;
mgr->_sources = newsrc;
@@ -176,11 +168,10 @@ ResourceSource *scir_add_external_map(ResourceManager *mgr, const char *file_nam
return newsrc;
}
-ResourceSource *scir_add_volume(ResourceManager *mgr, ResourceSource *map, const char *filename,
- int number, int extended_addressing) {
+ResourceSource *scir_add_volume(ResourceManager *mgr, ResourceSource *map, const char *filename, int number, int extended_addressing) {
ResourceSource *newsrc = new ResourceSource();
- /* Add the new source to the SLL of sources */
+ // Add the new source to the SLL of sources
newsrc->next = mgr->_sources;
mgr->_sources = newsrc;
@@ -189,19 +180,21 @@ ResourceSource *scir_add_volume(ResourceManager *mgr, ResourceSource *map, const
newsrc->location_name = filename;
newsrc->volume_number = number;
newsrc->associated_map = map;
+
return 0;
}
ResourceSource *scir_add_patch_dir(ResourceManager *mgr, const char *dirname) {
ResourceSource *newsrc = new ResourceSource();
- /* Add the new source to the SLL of sources */
+ // Add the new source to the SLL of sources
newsrc->next = mgr->_sources;
mgr->_sources = newsrc;
newsrc->source_type = RESSOURCE_TYPE_DIRECTORY;
newsrc->scanned = false;
newsrc->location_name = dirname;
+
return 0;
}
@@ -209,8 +202,7 @@ ResourceSource *scir_get_volume(ResourceManager *mgr, ResourceSource *map, int v
ResourceSource *seeker = mgr->_sources;
while (seeker) {
- if (seeker->source_type == RESSOURCE_TYPE_VOLUME &&
- seeker->associated_map == map &&
+ if (seeker->source_type == RESSOURCE_TYPE_VOLUME && seeker->associated_map == map &&
seeker->volume_number == volume_nr)
return seeker;
seeker = seeker->next;
@@ -219,42 +211,35 @@ ResourceSource *scir_get_volume(ResourceManager *mgr, ResourceSource *map, int v
return NULL;
}
-/*------------------------------------------------*/
-/** Resource manager constructors and operations **/
-/*------------------------------------------------*/
+// Resource manager constructors and operations
-static void
-_scir_load_from_patch_file(Common::File &file, resource_t *res, char *filename) {
+static void _scir_load_from_patch_file(Common::File &file, resource_t *res, char *filename) {
unsigned int really_read;
- res->data = (unsigned char*)sci_malloc(res->size);
+ res->data = (unsigned char *)sci_malloc(res->size);
really_read = file.read(res->data, res->size);
if (really_read < res->size) {
- error("Read %d bytes from %s but expected %d!",
- really_read, filename, res->size);
+ error("Read %d bytes from %s but expected %d!", really_read, filename, res->size);
}
res->status = SCI_STATUS_ALLOCATED;
}
-static void
-_scir_load_resource(ResourceManager *mgr, resource_t *res, bool protect) {
+static void _scir_load_resource(ResourceManager *mgr, resource_t *res, bool protect) {
char filename[MAXPATHLEN];
Common::File file;
resource_t backup;
memcpy(&backup, res, sizeof(resource_t));
- /* First try lower-case name */
+ // First try lower-case name
if (res->source->source_type == RESSOURCE_TYPE_DIRECTORY) {
-
if (!patch_sprintfers[mgr->sci_version]) {
- error("Resource manager's SCI version (%d) has no patch file name printers",
- mgr->sci_version);
+ error("Resource manager's SCI version (%d) has no patch file name printers", mgr->sci_version);
}
- /* Get patch file name */
+ // Get patch file name
patch_sprintfers[mgr->sci_version](filename, res);
// FIXME: Instead of using SearchMan, maybe we should only search
@@ -270,23 +255,20 @@ _scir_load_resource(ResourceManager *mgr, resource_t *res, bool protect) {
return;
}
-
file.seek(res->file_offset, SEEK_SET);
if (res->source->source_type == RESSOURCE_TYPE_DIRECTORY)
_scir_load_from_patch_file(file, res, filename);
else if (!decompressors[mgr->sci_version]) {
- /* Check whether we support this at all */
+ // Check whether we support this at all
error("Resource manager's SCI version (%d) is invalid", mgr->sci_version);
} else {
- int error = /* Decompress from regular resource file */
+ int error = // Decompress from regular resource file
decompressors[mgr->sci_version](res, file, mgr->sci_version);
if (error) {
- sciprintf("Error %d occured while reading %s.%03d"
- " from resource file: %s\n",
- error, sci_resource_types[res->type], res->number,
- sci_error_types[error]);
+ sciprintf("Error %d occured while reading %s.%03d from resource file: %s\n",
+ error, sci_resource_types[res->type], res->number, sci_error_types[error]);
if (protect)
memcpy(res, &backup, sizeof(resource_t));
@@ -303,9 +285,7 @@ resource_t *scir_test_resource(ResourceManager *mgr, int type, int number) {
resource_t binseeker;
binseeker.type = type;
binseeker.number = number;
- return (resource_t *)
- bsearch(&binseeker, mgr->_resources, mgr->_resourcesNr,
- sizeof(resource_t), resourcecmp);
+ return (resource_t *)bsearch(&binseeker, mgr->_resources, mgr->_resourcesNr, sizeof(resource_t), resourcecmp);
}
int sci0_get_compression_method(Common::ReadStream &stream);
@@ -341,7 +321,7 @@ int sci_test_view_type(ResourceManager *mgr) {
return (mgr->sci_version = SCI_VERSION_01_VGA);
}
- /* Try the same thing with pics */
+ // Try the same thing with pics
for (i = 0; i < 1000; i++) {
res = scir_test_resource(mgr, sci_pic, i);
@@ -367,8 +347,6 @@ int sci_test_view_type(ResourceManager *mgr) {
return mgr->sci_version;
}
-
-
int scir_add_appropriate_sources(ResourceManager *mgr) {
//char path_separator;
ResourceSource *map;
@@ -396,7 +374,7 @@ static int _scir_scan_new_sources(ResourceManager *mgr, int *detected_version, R
int preset_version = mgr->sci_version;
int resource_error = 0;
int dummy = mgr->sci_version;
-// resource_t **concat_ptr = &(mgr->_resources[mgr->_resourcesNr-1].next);
+ //resource_t **concat_ptr = &(mgr->_resources[mgr->_resourcesNr - 1].next);
if (detected_version == NULL)
detected_version = &dummy;
@@ -410,40 +388,28 @@ static int _scir_scan_new_sources(ResourceManager *mgr, int *detected_version, R
switch (source->source_type) {
case RESSOURCE_TYPE_DIRECTORY:
if (mgr->sci_version <= SCI_VERSION_01)
- sci0_read_resource_patches(source,
- &mgr->_resources,
- &mgr->_resourcesNr);
+ sci0_read_resource_patches(source, &mgr->_resources, &mgr->_resourcesNr);
else
- sci1_read_resource_patches(source,
- &mgr->_resources,
- &mgr->_resourcesNr);
+ sci1_read_resource_patches(source, &mgr->_resources, &mgr->_resourcesNr);
break;
case RESSOURCE_TYPE_EXTERNAL_MAP:
- if (preset_version <= SCI_VERSION_01_VGA_ODD
- /* || preset_version == SCI_VERSION_AUTODETECT -- subsumed by the above line */) {
- resource_error =
- sci0_read_resource_map(mgr,
- source,
- &mgr->_resources,
- &mgr->_resourcesNr,
- detected_version);
-
+ if (preset_version <= SCI_VERSION_01_VGA_ODD /* || preset_version == SCI_VERSION_AUTODETECT -- subsumed by the above line */) {
+ resource_error = sci0_read_resource_map(mgr, source, &mgr->_resources, &mgr->_resourcesNr, detected_version);
#if 0
if (resource_error >= SCI_ERROR_CRITICAL) {
- sciprintf("Resmgr: Error while loading resource map: %s\n",
- sci_error_types[resource_error]);
+ sciprintf("Resmgr: Error while loading resource map: %s\n", sci_error_types[resource_error]);
if (resource_error == SCI_ERROR_RESMAP_NOT_FOUND)
sciprintf("Running SCI games without a resource map is not supported ATM\n");
sci_free(mgr);
return NULL;
}
if (resource_error == SCI_ERROR_RESMAP_NOT_FOUND) {
- /* fixme: Try reading w/o resource.map */
+ // fixme: Try reading w/o resource.map
resource_error = SCI_ERROR_NO_RESOURCE_FILES_FOUND;
}
if (resource_error == SCI_ERROR_NO_RESOURCE_FILES_FOUND) {
- /* Initialize empty resource manager */
+ // Initialize empty resource manager
mgr->_resourcesNr = 0;
mgr->_resources = 0; // FIXME: Was = (resource_t*)sci_malloc(1);
resource_error = 0;
@@ -451,25 +417,17 @@ static int _scir_scan_new_sources(ResourceManager *mgr, int *detected_version, R
#endif
}
- if ((preset_version == SCI_VERSION_1_EARLY) ||
- (preset_version == SCI_VERSION_1_LATE) ||
- (preset_version == SCI_VERSION_1_1) ||
+ if ((preset_version == SCI_VERSION_1_EARLY) || (preset_version == SCI_VERSION_1_LATE) || (preset_version == SCI_VERSION_1_1) ||
((*detected_version == SCI_VERSION_AUTODETECT) && (preset_version == SCI_VERSION_AUTODETECT))) {
- resource_error =
- sci1_read_resource_map(mgr,
- source,
- scir_get_volume(mgr, source, 0),
- &mgr->_resources,
- &mgr->_resourcesNr,
- detected_version);
-
+ resource_error = sci1_read_resource_map(mgr, source, scir_get_volume(mgr, source, 0),
+ &mgr->_resources, &mgr->_resourcesNr, detected_version);
if (resource_error == SCI_ERROR_RESMAP_NOT_FOUND) {
- /* fixme: Try reading w/o resource.map */
+ // fixme: Try reading w/o resource.map
resource_error = SCI_ERROR_NO_RESOURCE_FILES_FOUND;
}
if (resource_error == SCI_ERROR_NO_RESOURCE_FILES_FOUND) {
- /* Initialize empty resource manager */
+ // Initialize empty resource manager
mgr->_resourcesNr = 0;
mgr->_resources = 0; // FIXME: Was = (resource_t*)sci_malloc(1);
resource_error = 0;
@@ -479,15 +437,14 @@ static int _scir_scan_new_sources(ResourceManager *mgr, int *detected_version, R
mgr->sci_version = *detected_version;
break;
}
- qsort(mgr->_resources, mgr->_resourcesNr, sizeof(resource_t),
- resourcecmp); /* Sort resources */
+ qsort(mgr->_resources, mgr->_resourcesNr, sizeof(resource_t), resourcecmp); // Sort resources
}
return resource_error;
}
-int
-scir_scan_new_sources(ResourceManager *mgr, int *detected_version) {
+int scir_scan_new_sources(ResourceManager *mgr, int *detected_version) {
_scir_scan_new_sources(mgr, detected_version, mgr->_sources);
+
return 0;
}
@@ -530,14 +487,12 @@ ResourceManager::ResourceManager(int version, int maxMemory) {
// return NULL;
}
- qsort(_resources, _resourcesNr, sizeof(resource_t),
- resourcecmp); /* Sort resources */
+ qsort(_resources, _resourcesNr, sizeof(resource_t), resourcecmp); // Sort resources
if (version == SCI_VERSION_AUTODETECT)
switch (resmap_version) {
case SCI_VERSION_0:
- if (scir_test_resource(mgr, sci_vocab,
- VOCAB_RESOURCE_SCI0_MAIN_VOCAB)) {
+ if (scir_test_resource(mgr, sci_vocab, VOCAB_RESOURCE_SCI0_MAIN_VOCAB)) {
version = sci_test_view_type(mgr);
if (version == SCI_VERSION_01_VGA) {
sciprintf("Resmgr: Detected KQ5 or similar\n");
@@ -545,8 +500,7 @@ ResourceManager::ResourceManager(int version, int maxMemory) {
sciprintf("Resmgr: Detected SCI0\n");
version = SCI_VERSION_0;
}
- } else if (scir_test_resource(mgr, sci_vocab,
- VOCAB_RESOURCE_SCI1_MAIN_VOCAB)) {
+ } else if (scir_test_resource(mgr, sci_vocab, VOCAB_RESOURCE_SCI1_MAIN_VOCAB)) {
version = sci_test_view_type(mgr);
if (version == SCI_VERSION_01_VGA) {
sciprintf("Resmgr: Detected KQ5 or similar\n");
@@ -584,32 +538,28 @@ ResourceManager::ResourceManager(int version, int maxMemory) {
break;
}
case SCI_VERSION_1_1:
- /* No need to handle SCI 1.1 here - it was done in resource_map.c */
+ // No need to handle SCI 1.1 here - it was done in resource_map.cpp
version = SCI_VERSION_1_1;
break;
default:
- sciprintf("Resmgr: Warning: While autodetecting: Couldn't"
- " determine SCI version");
+ sciprintf("Resmgr: Warning: While autodetecting: Couldn't determine SCI version");
}
if (!resource_error) {
- qsort(_resources, _resourcesNr, sizeof(resource_t),
- resourcecmp); /* Sort resources */
+ qsort(_resources, _resourcesNr, sizeof(resource_t), resourcecmp); // Sort resources
}
mgr->sci_version = version;
}
-static void
-_scir_free_altsources(resource_altsource_t *dynressrc) {
+static void _scir_free_altsources(resource_altsource_t *dynressrc) {
if (dynressrc) {
_scir_free_altsources(dynressrc->next);
free(dynressrc);
}
}
-void
-_scir_free_resources(resource_t *resources, int _resourcesNr) {
+void _scir_free_resources(resource_t *resources, int _resourcesNr) {
int i;
for (i = 0; i < _resourcesNr; i++) {
@@ -631,20 +581,15 @@ ResourceManager::~ResourceManager() {
_resources = NULL;
}
-
-static void
-_scir_unalloc(resource_t *res) {
+static void _scir_unalloc(resource_t *res) {
free(res->data);
res->data = NULL;
res->status = SCI_STATUS_NOMALLOC;
}
-
-static void
-_scir_remove_from_lru(ResourceManager *mgr, resource_t *res) {
+static void _scir_remove_from_lru(ResourceManager *mgr, resource_t *res) {
if (res->status != SCI_STATUS_ENQUEUED) {
- sciprintf("Resmgr: Oops: trying to remove resource that isn't"
- " enqueued\n");
+ sciprintf("Resmgr: Oops: trying to remove resource that isn't enqueued\n");
return;
}
@@ -662,11 +607,9 @@ _scir_remove_from_lru(ResourceManager *mgr, resource_t *res) {
res->status = SCI_STATUS_ALLOCATED;
}
-static void
-_scir_add_to_lru(ResourceManager *mgr, resource_t *res) {
+static void _scir_add_to_lru(ResourceManager *mgr, resource_t *res) {
if (res->status != SCI_STATUS_ALLOCATED) {
- sciprintf("Resmgr: Oops: trying to enqueue resource with state"
- " %d\n", res->status);
+ sciprintf("Resmgr: Oops: trying to enqueue resource with state %d\n", res->status);
return;
}
@@ -680,38 +623,31 @@ _scir_add_to_lru(ResourceManager *mgr, resource_t *res) {
mgr->memory_lru += res->size;
#if (SCI_VERBOSE_RESMGR > 1)
- error("Adding %s.%03d (%d bytes) to lru control: %d bytes total\n",
- sci_resource_types[res->type], res->number, res->size,
- mgr->memory_lru);
+ error("Adding %s.%03d (%d bytes) to lru control: %d bytes total\n", sci_resource_types[res->type],
+ res->number, res->size, mgr->memory_lru);
#endif
res->status = SCI_STATUS_ENQUEUED;
}
-static void
-_scir_print_lru_list(ResourceManager *mgr) {
+static void _scir_print_lru_list(ResourceManager *mgr) {
int mem = 0;
int entries = 0;
resource_t *res = mgr->lru_first;
while (res) {
- error("\t%s.%03d: %d bytes\n",
- sci_resource_types[res->type], res->number,
- res->size);
+ error("\t%s.%03d: %d bytes\n", sci_resource_types[res->type], res->number, res->size);
mem += res->size;
++entries;
res = res->next;
}
- error("Total: %d entries, %d bytes (mgr says %d)\n",
- entries, mem, mgr->memory_lru);
+ error("Total: %d entries, %d bytes (mgr says %d)\n", entries, mem, mgr->memory_lru);
}
-static void
-_scir_free_old_resources(ResourceManager *mgr, int last_invulnerable) {
- while (mgr->_maxMemory < mgr->memory_lru
- && (!last_invulnerable || mgr->lru_first != mgr->lru_last)) {
+static void _scir_free_old_resources(ResourceManager *mgr, int last_invulnerable) {
+ while (mgr->_maxMemory < mgr->memory_lru && (!last_invulnerable || mgr->lru_first != mgr->lru_last)) {
resource_t *goner = mgr->lru_last;
if (!goner) {
error("Internal error: mgr->lru_last is NULL");
@@ -723,22 +659,18 @@ _scir_free_old_resources(ResourceManager *mgr, int last_invulnerable) {
_scir_remove_from_lru(mgr, goner);
_scir_unalloc(goner);
#ifdef SCI_VERBOSE_RESMGR
- sciprintf("Resmgr-debug: LRU: Freeing %s.%03d (%d bytes)\n",
- sci_resource_types[goner->type], goner->number,
- goner->size);
+ sciprintf("Resmgr-debug: LRU: Freeing %s.%03d (%d bytes)\n", sci_resource_types[goner->type], goner->number, goner->size);
#endif
}
}
-resource_t *
-scir_find_resource(ResourceManager *mgr, int type, int number, int lock) {
+resource_t * scir_find_resource(ResourceManager *mgr, int type, int number, int lock) {
resource_t *retval;
if (number >= sci_max_resource_nr[mgr->sci_version]) {
int modded_number = number % sci_max_resource_nr[mgr->sci_version];
sciprintf("[resmgr] Requested invalid resource %s.%d, mapped to %s.%d\n",
- sci_resource_types[type], number,
- sci_resource_types[type], modded_number);
+ sci_resource_types[type], number, sci_resource_types[type], modded_number);
number = modded_number;
}
@@ -752,8 +684,8 @@ scir_find_resource(ResourceManager *mgr, int type, int number, int lock) {
else if (retval->status == SCI_STATUS_ENQUEUED)
_scir_remove_from_lru(mgr, retval);
- /* Unless an error occured, the resource is now either
- ** locked or allocated, but never queued or freed. */
+ // Unless an error occured, the resource is now either
+ // locked or allocated, but never queued or freed.
if (lock) {
if (retval->status == SCI_STATUS_ALLOCATED) {
@@ -764,7 +696,7 @@ scir_find_resource(ResourceManager *mgr, int type, int number, int lock) {
++retval->lockers;
- } else if (retval->status != SCI_STATUS_LOCKED) { /* Don't lock it */
+ } else if (retval->status != SCI_STATUS_LOCKED) { // Don't lock it
if (retval->status == SCI_STATUS_ALLOCATED)
_scir_add_to_lru(mgr, retval);
}
@@ -774,14 +706,12 @@ scir_find_resource(ResourceManager *mgr, int type, int number, int lock) {
if (retval->data)
return retval;
else {
- sciprintf("Resmgr: Failed to read %s.%03d\n",
- sci_resource_types[retval->type], retval->number);
+ sciprintf("Resmgr: Failed to read %s.%03d\n", sci_resource_types[retval->type], retval->number);
return NULL;
}
}
-void
-scir_unlock_resource(ResourceManager *mgr, resource_t *res, int resnum, int restype) {
+void scir_unlock_resource(ResourceManager *mgr, resource_t *res, int resnum, int restype) {
if (!res) {
if (restype >= ARRAYSIZE(sci_resource_types))
sciprintf("Resmgr: Warning: Attempt to unlock non-existant resource %03d.%03d", restype, resnum);
@@ -791,13 +721,12 @@ scir_unlock_resource(ResourceManager *mgr, resource_t *res, int resnum, int rest
}
if (res->status != SCI_STATUS_LOCKED) {
- sciprintf("Resmgr: Warning: Attempt to unlock unlocked"
- " resource %s.%03d\n",
+ sciprintf("Resmgr: Warning: Attempt to unlock unlocked resource %s.%03d\n",
sci_resource_types[res->type], res->number);
return;
}
- if (!--res->lockers) { /* No more lockers? */
+ if (!--res->lockers) { // No more lockers?
res->status = SCI_STATUS_ALLOCATED;
mgr->memory_locked -= res->size;
_scir_add_to_lru(mgr, res);
diff --git a/engines/sci/scicore/resource_map.cpp b/engines/sci/scicore/resource_map.cpp
index fef1aafd04..f0e418facd 100644
--- a/engines/sci/scicore/resource_map.cpp
+++ b/engines/sci/scicore/resource_map.cpp
@@ -37,7 +37,7 @@ namespace Sci {
#define SCI1_RESMAP_ENTRIES_SIZE 6
#define SCI11_RESMAP_ENTRIES_SIZE 5
-/* Resource type encoding */
+// Resource type encoding
#define SCI0_B1_RESTYPE_MASK 0xf8
#define SCI0_B1_RESTYPE_SHIFT 3
#define SCI0_B3_RESFILE_MASK 0xfc
@@ -121,8 +121,7 @@ static int detect_odd_sci01(Common::File &file) {
return files_ok;
}
-static int
-sci_res_read_entry(ResourceManager *mgr, ResourceSource *map,
+static int sci_res_read_entry(ResourceManager *mgr, ResourceSource *map,
byte *buf, resource_t *res, int sci_version) {
res->id = buf[0] | (buf[1] << 8);
res->type = SCI0_RESID_GET_TYPE(buf);
@@ -148,13 +147,13 @@ sci_res_read_entry(ResourceManager *mgr, ResourceSource *map,
}
#if 0
- error("Read [%04x] %6d.%s\tresource.%03d, %08x\n",
- res->id, res->number,
- sci_resource_type_suffixes[res->type],
- res->file, res->file_offset);
+ error("Read [%04x] %6d.%s\tresource.%03d, %08x\n", res->id, res->number,
+ sci_resource_type_suffixes[res->type], res->file, res->file_offset);
#endif
- if (res->source == NULL) return 1;
+ if (res->source == NULL)
+ return 1;
+
return 0;
}
@@ -232,24 +231,22 @@ int sci0_read_resource_map(ResourceManager *mgr, ResourceSource *map, resource_t
*/
- if ((buf[0] == 0x80) &&
- (buf[1] % 3 == 0) &&
- (buf[3] == 0x81)) {
+ if ((buf[0] == 0x80) && (buf[1] % 3 == 0) && (buf[3] == 0x81)) {
return SCI_ERROR_INVALID_RESMAP_ENTRY;
}
file.seek(0, SEEK_SET);
switch (detect_odd_sci01(file)) {
- case 0 : /* Odd SCI01 */
+ case 0 : // Odd SCI01
if (*sci_version == SCI_VERSION_AUTODETECT)
*sci_version = SCI_VERSION_01_VGA_ODD;
break;
- case 1 : /* SCI0 or normal SCI01 */
+ case 1 : // SCI0 or normal SCI01
if (*sci_version == SCI_VERSION_AUTODETECT)
*sci_version = SCI_VERSION_0;
break;
- default : /* Neither, or error occurred */
+ default : // Neither, or error occurred
return SCI_ERROR_RESMAP_NOT_FOUND;
}
@@ -261,8 +258,8 @@ int sci0_read_resource_map(ResourceManager *mgr, ResourceSource *map, resource_t
resource_nr = fsize / SCI0_RESMAP_ENTRIES_SIZE;
- resources = (resource_t*)sci_calloc(resource_nr, sizeof(resource_t));
- /* Sets valid default values for most entries */
+ resources = (resource_t *)sci_calloc(resource_nr, sizeof(resource_t));
+ // Sets valid default values for most entries
do {
int read_ok = file.read(&buf, SCI0_RESMAP_ENTRIES_SIZE);
@@ -274,7 +271,7 @@ int sci0_read_resource_map(ResourceManager *mgr, ResourceSource *map, resource_t
next_entry = 0;
} else if (read_ok != SCI0_RESMAP_ENTRIES_SIZE) {
next_entry = 0;
- } else if (buf[5] == 0xff) /* Most significant offset byte */
+ } else if (buf[5] == 0xff) // Most significant offset byte
next_entry = 0;
if (next_entry) {
@@ -288,22 +285,18 @@ int sci0_read_resource_map(ResourceManager *mgr, ResourceSource *map, resource_t
}
for (i = 0; i < resource_index; i++)
- if (resources[resource_index].id ==
- resources[i].id) {
+ if (resources[resource_index].id == resources[i].id) {
addto = i;
fresh = 0;
}
- _scir_add_altsource(resources + addto,
- resources[resource_index].source,
- resources[resource_index].file_offset);
+ _scir_add_altsource(resources + addto, resources[resource_index].source, resources[resource_index].file_offset);
if (fresh)
++resource_index;
if (++resources_total_read >= resource_nr) {
- sciprintf("Warning: After %d entries, resource.map"
- " is not terminated", resource_index);
+ sciprintf("Warning: After %d entries, resource.map is not terminated", resource_index);
next_entry = 0;
}
@@ -324,8 +317,8 @@ int sci0_read_resource_map(ResourceManager *mgr, ResourceSource *map, resource_t
return SCI_ERROR_INVALID_RESMAP_ENTRY;
} else {
#if 0
- /* Check disabled, Mac SQ3 thinks it has resource.004 but doesn't need it -- CR */
- /* Check whether the highest resfile used exists */
+ // Check disabled, Mac SQ3 thinks it has resource.004 but doesn't need it -- CR
+ // Check whether the highest resfile used exists
char filename_buf[14];
sprintf(filename_buf, "resource.%03d", max_resfile_nr);
@@ -338,7 +331,7 @@ int sci0_read_resource_map(ResourceManager *mgr, ResourceSource *map, resource_t
}
if (resource_index < resource_nr)
- resources = (resource_t*)sci_realloc(resources, sizeof(resource_t) * resource_index);
+ resources = (resource_t *)sci_realloc(resources, sizeof(resource_t) * resource_index);
*resource_p = resources;
*resource_nr_p = resource_index;
@@ -364,13 +357,13 @@ static int sci10_or_11(int *types) {
while (types[next_restype] == 0)
next_restype++;
- could_be_10 = ((types[next_restype] - types[this_restype])
- % SCI1_RESMAP_ENTRIES_SIZE) == 0;
- could_be_11 = ((types[next_restype] - types[this_restype])
- % SCI11_RESMAP_ENTRIES_SIZE) == 0;
+ could_be_10 = ((types[next_restype] - types[this_restype]) % SCI1_RESMAP_ENTRIES_SIZE) == 0;
+ could_be_11 = ((types[next_restype] - types[this_restype]) % SCI11_RESMAP_ENTRIES_SIZE) == 0;
- if (could_be_10 && !could_be_11) return SCI_VERSION_1;
- if (could_be_11 && !could_be_10) return SCI_VERSION_1_1;
+ if (could_be_10 && !could_be_11)
+ return SCI_VERSION_1;
+ if (could_be_11 && !could_be_10)
+ return SCI_VERSION_1_1;
this_restype++;
next_restype++;
@@ -379,8 +372,7 @@ static int sci10_or_11(int *types) {
return SCI_VERSION_AUTODETECT;
}
-int
-sci1_read_resource_map(ResourceManager *mgr, ResourceSource *map, ResourceSource *vol,
+int sci1_read_resource_map(ResourceManager *mgr, ResourceSource *map, ResourceSource *vol,
resource_t **resource_p, int *resource_nr_p, int *sci_version) {
int fsize;
Common::File file;
@@ -388,7 +380,7 @@ sci1_read_resource_map(ResourceManager *mgr, ResourceSource *map, ResourceSource
int resource_nr;
int resource_index = 0;
int ofs, header_size;
- int *types = (int*)sci_malloc(sizeof(int) * (sci1_last_resource + 1));
+ int *types = (int *)sci_malloc(sizeof(int) * (sci1_last_resource + 1));
int i;
byte buf[SCI1_RESMAP_ENTRIES_SIZE];
int lastrt;
@@ -408,14 +400,12 @@ sci1_read_resource_map(ResourceManager *mgr, ResourceSource *map, ResourceSource
if (*sci_version == SCI_VERSION_AUTODETECT)
*sci_version = entry_size_selector;
- if (*sci_version == SCI_VERSION_AUTODETECT) { /* That didn't help */
+ if (*sci_version == SCI_VERSION_AUTODETECT) { // That didn't help
sciprintf("Unable to detect resource map version\n");
return SCI_ERROR_NO_RESOURCE_FILES_FOUND;
}
- entrysize = entry_size_selector == SCI_VERSION_1_1
- ? SCI11_RESMAP_ENTRIES_SIZE
- : SCI1_RESMAP_ENTRIES_SIZE;
+ entrysize = entry_size_selector == SCI_VERSION_1_1 ? SCI11_RESMAP_ENTRIES_SIZE : SCI1_RESMAP_ENTRIES_SIZE;
fsize = file.size();
if (fsize < 0) {
@@ -468,22 +458,17 @@ sci1_read_resource_map(ResourceManager *mgr, ResourceSource *map, ResourceSource
res->id = res->number | (res->type << 16);
for (j = 0; i < resource_index; i++)
- if (resources[resource_index].id ==
- resources[i].id) {
+ if (resources[resource_index].id == resources[i].id) {
addto = i;
fresh = 0;
}
#if 0
- error("Read [%04x] %6d.%s\tresource.%03d, %08x ==> %d\n",
- res->id, res->number,
- sci_resource_type_suffixes[res->type],
+ error("Read [%04x] %6d.%s\tresource.%03d, %08x ==> %d\n", res->id, res->number, sci_resource_type_suffixes[res->type],
res->file, res->file_offset, addto);
#endif
- _scir_add_altsource(resources + addto,
- resources[resource_index].source,
- resources[resource_index].file_offset);
+ _scir_add_altsource(resources + addto, resources[resource_index].source, resources[resource_index].file_offset);
if (fresh)
++resource_index;
@@ -500,8 +485,7 @@ sci1_read_resource_map(ResourceManager *mgr, ResourceSource *map, ResourceSource
}
#ifdef TEST_RESOURCE_MAP
-int
-main(int argc, char **argv) {
+int main(int argc, char **argv) {
int resource_nr;
resource_t *resources;
int notok = sci0_read_resource_map(".", &resources, &resource_nr);
@@ -519,10 +503,8 @@ main(int argc, char **argv) {
for (i = 0; i < resource_nr; i++) {
resource_t *res = resources + i;
- printf("#%04d:\tRESOURCE.%03d:%8d\t%s.%03d\n",
- i, res->file, res->file_offset,
- sci_resource_types[res->type],
- res->number);
+ printf("#%04d:\tRESOURCE.%03d:%8d\t%s.%03d\n", i, res->file, res->file_offset,
+ sci_resource_types[res->type], res->number);
}
} else
error("Found no resources.\n");
diff --git a/engines/sci/scicore/resource_patch.cpp b/engines/sci/scicore/resource_patch.cpp
index b4fc6dd2c0..783dda4845 100644
--- a/engines/sci/scicore/resource_patch.cpp
+++ b/engines/sci/scicore/resource_patch.cpp
@@ -39,7 +39,7 @@ void sci1_sprintf_patch_file_name(char *string, resource_t *res) {
sprintf(string, "%d.%s", res->number, sci_resource_type_suffixes[res->type]);
}
-/* version-agnostic patch application */
+// version-agnostic patch application
static void process_patch(ResourceSource *source,
Common::ArchiveMember &member, int restype, int resnumber, resource_t **resource_p, int *resource_nr_p) {
Common::File file;
@@ -52,10 +52,7 @@ static void process_patch(ResourceSource *source,
perror("""__FILE__"": (""__LINE__""): failed to open");
else {
guint8 filehdr[2];
- resource_t *newrsc = _scir_find_resource_unsorted(*resource_p,
- *resource_nr_p,
- restype,
- resnumber);
+ resource_t *newrsc = _scir_find_resource_unsorted(*resource_p, *resource_nr_p, restype, resnumber);
int fsize = file.size();
if (fsize < 3) {
printf("File too small\n");
@@ -73,21 +70,19 @@ static void process_patch(ResourceSource *source,
} else if (patch_data_offset + 2 >= fsize) {
printf("Failed; patch starting at offset %d can't be in file of size %d\n", filehdr[1] + 2, fsize);
} else {
- /* Adjust for file offset */
+ // Adjust for file offset
fsize -= patch_data_offset;
- /* Prepare destination, if neccessary */
+ // Prepare destination, if neccessary
if (!newrsc) {
- /* Completely new resource! */
+ // Completely new resource!
++(*resource_nr_p);
- *resource_p = (resource_t*)sci_realloc(*resource_p,
- *resource_nr_p
- * sizeof(resource_t));
+ *resource_p = (resource_t *)sci_realloc(*resource_p, *resource_nr_p * sizeof(resource_t));
newrsc = (*resource_p - 1) + *resource_nr_p;
newrsc->alt_sources = NULL;
}
- /* Overwrite everything, because we're patching */
+ // Overwrite everything, because we're patching
newrsc->size = fsize - 2;
newrsc->id = restype << 11 | resnumber;
newrsc->number = resnumber;
@@ -99,7 +94,6 @@ static void process_patch(ResourceSource *source,
_scir_add_altsource(newrsc, source, 2);
printf("OK\n");
-
}
}
}
@@ -118,8 +112,7 @@ int sci0_read_resource_patches(ResourceSource *source, resource_t **resource_p,
char *endptr;
for (i = sci_view; i < sci_invalid_resource; i++)
- if (scumm_strnicmp(sci_resource_types[i], name.c_str(),
- strlen(sci_resource_types[i])) == 0)
+ if (scumm_strnicmp(sci_resource_types[i], name.c_str(), strlen(sci_resource_types[i])) == 0)
restype = i;
if (restype != sci_invalid_resource) {
@@ -128,8 +121,7 @@ int sci0_read_resource_patches(ResourceSource *source, resource_t **resource_p,
if (name[resname_len] != '.')
restype = sci_invalid_resource;
else {
- resnumber = strtol(name.c_str() + 1 + resname_len,
- &endptr, 10); /* Get resource number */
+ resnumber = strtol(name.c_str() + 1 + resname_len, &endptr, 10); // Get resource number
if ((*endptr != '\0') || (resname_len + 1 == name.size()))
restype = sci_invalid_resource;
@@ -165,9 +157,7 @@ int sci1_read_resource_patches(ResourceSource *source, resource_t **resource_p,
}
if (restype != sci_invalid_resource) {
-
- resnumber = strtol(name.c_str(),
- &endptr, 10); /* Get resource number */
+ resnumber = strtol(name.c_str(), &endptr, 10); // Get resource number
if (endptr != dot)
restype = sci_invalid_resource;
diff --git a/engines/sci/scicore/sci_memory.cpp b/engines/sci/scicore/sci_memory.cpp
index 539879568d..4b2b56d696 100644
--- a/engines/sci/scicore/sci_memory.cpp
+++ b/engines/sci/scicore/sci_memory.cpp
@@ -28,99 +28,76 @@
namespace Sci {
-/* set optimisations for Win32: */
-/* g on: enable global optimizations */
-/* t on: use fast code */
-/* y on: suppress creation of frame pointers on stack */
-/* s off: disable minimize size code */
-
-#ifdef _MSC_VER
-# include <crtdbg.h>
-# ifndef SATISFY_PURIFY
-# pragma optimize( "s", off )
-# pragma optimize( "gty", on )
-# pragma intrinsic( memcpy, strlen )
-# endif
-#endif
-
-
-void *
-sci_malloc(size_t size) {
+void * sci_malloc(size_t size) {
void *res;
+
ALLOC_MEM((res = malloc(size)), size, __FILE__, __LINE__, "")
return res;
}
-void *
-sci_calloc(size_t num, size_t size) {
+void * sci_calloc(size_t num, size_t size) {
void *res;
+
ALLOC_MEM((res = calloc(num, size)), num * size, __FILE__, __LINE__, "")
return res;
}
-
-void *
-sci_realloc(void *ptr, size_t size) {
+void *sci_realloc(void *ptr, size_t size) {
void *res;
+
ALLOC_MEM((res = realloc(ptr, size)), size, __FILE__, __LINE__, "")
return res;
}
-
-char *
-sci_strdup(const char *src) {
+char *sci_strdup(const char *src) {
void *res;
+
if (!src) {
- error("_SCI_STRDUP() [%s (%s) : %u]\n",
- __FILE__, "", __LINE__);
+ error("_SCI_STRDUP() [%s (%s) : %u]\n", __FILE__, "", __LINE__);
error(" attempt to strdup NULL pointer\n");
BREAKPOINT();
}
ALLOC_MEM((res = strdup(src)), strlen(src), __FILE__, __LINE__, "")
+
return (char*)res;
}
-
-char *
-sci_strndup(const char *src, size_t length) {
+char *sci_strndup(const char *src, size_t length) {
void *res;
char *strres;
size_t rlen = (int)MIN(strlen(src), length) + 1;
+
if (!src) {
- error("_SCI_STRNDUP() [%s (%s) : %u]\n",
- __FILE__, "", __LINE__);
+ error("_SCI_STRNDUP() [%s (%s) : %u]\n", __FILE__, "", __LINE__);
error(" attempt to strndup NULL pointer\n");
BREAKPOINT();
}
ALLOC_MEM((res = malloc(rlen)), rlen, __FILE__, __LINE__, "")
- strres = (char*)res;
+ strres = (char *)res;
strncpy(strres, src, rlen);
strres[rlen - 1] = 0;
return strres;
}
-/*-------- Refcounting ----------*/
+//-------- Refcounting ----------
-#define REFCOUNT_OVERHEAD (sizeof(guint32)*3)
+#define REFCOUNT_OVERHEAD (sizeof(guint32) * 3)
#define REFCOUNT_MAGIC_LIVE_1 0xebdc1741
#define REFCOUNT_MAGIC_LIVE_2 0x17015ac9
#define REFCOUNT_MAGIC_DEAD_1 0x11dead11
#define REFCOUNT_MAGIC_DEAD_2 0x22dead22
-#define REFCOUNT_CHECK(p) ((((guint32 *)(p))[-3] == REFCOUNT_MAGIC_LIVE_2) \
- && (((guint32 *)(p))[-1] == REFCOUNT_MAGIC_LIVE_1))
+#define REFCOUNT_CHECK(p) ((((guint32 *)(p))[-3] == REFCOUNT_MAGIC_LIVE_2) && (((guint32 *)(p))[-1] == REFCOUNT_MAGIC_LIVE_1))
#define REFCOUNT(p) (((guint32 *)p)[-2])
#undef TRACE_REFCOUNT
-
-extern void *
- sci_refcount_alloc(size_t length) {
- guint32 *data = (guint32*)sci_malloc(REFCOUNT_OVERHEAD + length);
+extern void *sci_refcount_alloc(size_t length) {
+ guint32 *data = (guint32 *)sci_malloc(REFCOUNT_OVERHEAD + length);
#ifdef TRACE_REFCOUNT
error("[] REF: Real-alloc at %p\n", data);
#endif
@@ -130,8 +107,7 @@ extern void *
data[-3] = REFCOUNT_MAGIC_LIVE_2;
REFCOUNT(data) = 1;
#ifdef TRACE_REFCOUNT
- error("[] REF: Alloc'd %p (ref=%d) OK=%d\n", data, REFCOUNT(data),
- REFCOUNT_CHECK(data));
+ error("[] REF: Alloc'd %p (ref=%d) OK=%d\n", data, REFCOUNT(data), REFCOUNT_CHECK(data));
#endif
return data;
}
@@ -150,13 +126,12 @@ extern void *sci_refcount_incref(void *data) {
extern void sci_refcount_decref(void *data) {
#ifdef TRACE_REFCOUNT
- error("[] REF: Dec'ing %p (prev ref=%d) OK=%d\n", data, REFCOUNT(data),
- REFCOUNT_CHECK(data));
+ error("[] REF: Dec'ing %p (prev ref=%d) OK=%d\n", data, REFCOUNT(data), REFCOUNT_CHECK(data));
#endif
if (!REFCOUNT_CHECK(data)) {
BREAKPOINT();
} else if (--REFCOUNT(data) == 0) {
- guint32 *fdata = (guint32*)data;
+ guint32 *fdata = (guint32 *)data;
fdata[-1] = REFCOUNT_MAGIC_DEAD_1;
fdata[-3] = REFCOUNT_MAGIC_DEAD_2;