aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engines/hugo/file.cpp51
-rw-r--r--engines/hugo/file_v1d.cpp4
-rw-r--r--engines/hugo/file_v1w.cpp2
-rw-r--r--engines/hugo/file_v2d.cpp16
-rw-r--r--engines/hugo/file_v3d.cpp12
-rw-r--r--engines/hugo/global.h1
-rw-r--r--engines/hugo/schedule.cpp2
-rw-r--r--engines/hugo/schedule_v1d.cpp2
-rw-r--r--engines/hugo/schedule_v1w.cpp2
-rw-r--r--engines/hugo/schedule_v2d.cpp2
-rw-r--r--engines/hugo/schedule_v3d.cpp2
-rw-r--r--engines/hugo/util.cpp45
-rw-r--r--engines/hugo/util.h1
13 files changed, 45 insertions, 97 deletions
diff --git a/engines/hugo/file.cpp b/engines/hugo/file.cpp
index 48e68a7099..2979271bc5 100644
--- a/engines/hugo/file.cpp
+++ b/engines/hugo/file.cpp
@@ -94,12 +94,12 @@ seq_t *FileManager::readPCX(Common::File &f, seq_t *seqPtr, byte *imagePtr, bool
f.read(PCC_header.fill2, sizeof(PCC_header.fill2));
if (PCC_header.mfctr != 10)
- Utils::Error(PCCH_ERR, "%s", name);
+ error("Bad data file format: %s", name);
// Allocate memory for seq_t if 0
if (seqPtr == 0) {
if ((seqPtr = (seq_t *)malloc(sizeof(seq_t))) == 0)
- Utils::Error(HEAP_ERR, "%s", name);
+ error("Insufficient memory to run game.");
}
// Find size of image data in 8-bit DIB format
@@ -113,9 +113,9 @@ seq_t *FileManager::readPCX(Common::File &f, seq_t *seqPtr, byte *imagePtr, bool
// Allocate memory for image data if NULL
if (imagePtr == 0) {
- if ((imagePtr = (byte *)malloc((size_t) size)) == 0)
- Utils::Error(HEAP_ERR, "%s", name);
+ imagePtr = (byte *)malloc((size_t) size);
}
+ assert(imagePtr);
seqPtr->imagePtr = imagePtr;
@@ -165,7 +165,7 @@ void FileManager::readImage(int objNum, object_t *objPtr) {
warning("File %s not found, trying again with %s%s", buf, _vm->_arrayNouns[objPtr->nounIndex][0], OBJEXT);
strcat(strcpy(buf, _vm->_arrayNouns[objPtr->nounIndex][0]), OBJEXT);
if (!_objectsArchive.open(buf))
- Utils::Error(FILE_ERR, "%s", buf);
+ error("File not found: %s", buf);
}
free(buf);
}
@@ -258,25 +258,22 @@ sound_pt FileManager::getSound(int16 sound, uint16 *size) {
if (!has_read_header) {
if (fp.read(s_hdr, sizeof(s_hdr)) != sizeof(s_hdr))
- Utils::Error(FILE_ERR, "%s", SOUND_FILE);
+ error("Wrong sound file format: %s", SOUND_FILE);
has_read_header = true;
}
*size = s_hdr[sound].size;
if (*size == 0)
- Utils::Error(SOUND_ERR, "%s", SOUND_FILE);
+ error("Wrong sound file format or missing sound %d: %s", sound, SOUND_FILE);
// Allocate memory for sound or music, if possible
sound_pt soundPtr = (byte *)malloc(s_hdr[sound].size); // Ptr to sound data
- if (soundPtr == 0) {
- warning("Low on memory");
- return 0;
- }
+ assert(soundPtr);
// Seek to data and read it
fp.seek(s_hdr[sound].offset, SEEK_SET);
if (fp.read(soundPtr, s_hdr[sound].size) != s_hdr[sound].size)
- Utils::Error(FILE_ERR, "%s", SOUND_FILE);
+ error("File not found: %s", SOUND_FILE);
fp.close();
@@ -391,7 +388,7 @@ void FileManager::restoreGame(int16 slot) {
int saveVersion;
in->read(&saveVersion, sizeof(saveVersion));
if (saveVersion != kSavegameVersion) {
- Utils::Error(GEN_ERR, "%s", "Savegame of incompatible version");
+ error("Savegame of incompatible version");
return;
}
@@ -473,7 +470,7 @@ void FileManager::initSavedGame() {
saveGame(-1, "");
in = _vm->getSaveFileManager()->openForLoading(_vm->_initFilename);
if (!in) {
- Utils::Error(WRITE_ERR, "%s", _vm->_initFilename.c_str());
+ warning("Unable to write file: %s", _vm->_initFilename.c_str());
return;
}
}
@@ -483,8 +480,8 @@ void FileManager::initSavedGame() {
delete in;
// Check sanity - maybe disk full or path set to read-only drive?
- if (_vm->getGameStatus().saveSize == -1)
- Utils::Error(WRITE_ERR, "%s", _vm->_initFilename.c_str());
+ if (_vm->getGameStatus().saveSize <= 0)
+ warning("Unable to write file: %s", _vm->_initFilename.c_str());
}
/**
@@ -500,7 +497,7 @@ void FileManager::printBootText() {
warning("printBootText - Skipping as H1 Dos may be a freeware");
return;
} else {
- Utils::Error(FILE_ERR, "%s", BOOTFILE);
+ error("Missing startup file");
}
}
@@ -510,7 +507,7 @@ void FileManager::printBootText() {
// Skip over the boot structure (already read) and read exit text
ofp.seek((long)sizeof(_boot), SEEK_SET);
if (ofp.read(buf, _boot.exit_len) != (size_t)_boot.exit_len)
- Utils::Error(FILE_ERR, "%s", BOOTFILE);
+ error("Error while reading startup file");
// Decrypt the exit text, using CRYPT substring
int i;
@@ -518,9 +515,7 @@ void FileManager::printBootText() {
buf[i] ^= CRYPT[i % strlen(CRYPT)];
buf[i] = '\0';
- //Box(BOX_OK, "%s", buf_p);
- //MessageBox(hwnd, buf_p, "License", MB_ICONINFORMATION);
- warning("printBootText(): License: %s", buf);
+ Utils::Box(BOX_OK, "%s", buf);
}
free(buf);
@@ -541,12 +536,12 @@ void FileManager::readBootFile() {
warning("readBootFile - Skipping as H1 Dos may be a freeware");
return;
} else {
- Utils::Error(FILE_ERR, "%s", BOOTFILE);
+ error("Missing startup file");
}
}
if (ofp.size() < (int32)sizeof(_boot))
- Utils::Error(FILE_ERR, "%s", BOOTFILE);
+ error("Corrupted startup file");
_boot.checksum = ofp.readByte();
_boot.registered = ofp.readByte();
@@ -564,7 +559,7 @@ void FileManager::readBootFile() {
ofp.close();
if (checksum)
- Utils::Error(GEN_ERR, "%s", "Program startup file invalid");
+ error("Corrupted startup file");
}
/**
@@ -582,10 +577,10 @@ uif_hdr_t *FileManager::getUIFHeader(uif_t id) {
// Open unbuffered to do far read
Common::File ip; // Image data file
if (!ip.open(UIF_FILE))
- Utils::Error(FILE_ERR, "%s", UIF_FILE);
+ error("File not found: %s", UIF_FILE);
if (ip.size() < (int32)sizeof(UIFHeader))
- Utils::Error(FILE_ERR, "%s", UIF_FILE);
+ error("Wrong file format: %s", UIF_FILE);
for (int i = 0; i < MAX_UIFS; ++i) {
UIFHeader[i].size = ip.readUint16LE();
@@ -606,7 +601,7 @@ void FileManager::readUIFItem(int16 id, byte *buf) {
// Open uif file to read data
Common::File ip; // UIF_FILE handle
if (!ip.open(UIF_FILE))
- Utils::Error(FILE_ERR, "%s", UIF_FILE);
+ error("File not found: %s", UIF_FILE);
// Seek to data
uif_hdr_t *UIFHeaderPtr = getUIFHeader((uif_t)id);
@@ -621,7 +616,7 @@ void FileManager::readUIFItem(int16 id, byte *buf) {
break;
default: // Read file data into supplied array
if (ip.read(buf, UIFHeaderPtr->size) != UIFHeaderPtr->size)
- Utils::Error(FILE_ERR, "%s", UIF_FILE);
+ error("Wrong file format: %s", UIF_FILE);
break;
}
diff --git a/engines/hugo/file_v1d.cpp b/engines/hugo/file_v1d.cpp
index a62d0f39e6..a85794b4e5 100644
--- a/engines/hugo/file_v1d.cpp
+++ b/engines/hugo/file_v1d.cpp
@@ -70,7 +70,7 @@ void FileManager_v1d::readOverlay(int screenNum, image_pt image, ovl_t overlayTy
}
if (!_sceneryArchive1.open(buf))
- Utils::Error(FILE_ERR, "%s", buf);
+ error("File not found: %s", buf);
image_pt tmpImage = image; // temp ptr to overlay file
@@ -88,7 +88,7 @@ void FileManager_v1d::readBackground(int screenIndex) {
char *buf = (char *) malloc(2048 + 1); // Buffer for file access
strcat(strcpy(buf, _vm->_screenNames[screenIndex]), ".ART");
if (!_sceneryArchive1.open(buf))
- Utils::Error(FILE_ERR, "%s", buf);
+ error("File not found: %s", buf);
// Read the image into dummy seq and static dib_a
seq_t *dummySeq; // Image sequence structure for Read_pcx
dummySeq = readPCX(_sceneryArchive1, 0, _vm->_screen->getFrontBuffer(), true, _vm->_screenNames[screenIndex]);
diff --git a/engines/hugo/file_v1w.cpp b/engines/hugo/file_v1w.cpp
index 9e9d380200..e4f97a917d 100644
--- a/engines/hugo/file_v1w.cpp
+++ b/engines/hugo/file_v1w.cpp
@@ -77,7 +77,7 @@ void FileManager_v1w::readOverlay(int screenNum, image_pt image, ovl_t overlayTy
i = sceneBlock.ob_len;
break;
default:
- Utils::Error(FILE_ERR, "%s", "Bad ovl_type");
+ error("Bad overlayType: %d", overlayType);
break;
}
if (i == 0) {
diff --git a/engines/hugo/file_v2d.cpp b/engines/hugo/file_v2d.cpp
index c8e94cb8ef..baf7f4c97f 100644
--- a/engines/hugo/file_v2d.cpp
+++ b/engines/hugo/file_v2d.cpp
@@ -53,11 +53,11 @@ void FileManager_v2d::openDatabaseFiles() {
debugC(1, kDebugFile, "openDatabaseFiles");
if (!_stringArchive.open(STRING_FILE))
- Utils::Error(FILE_ERR, "%s", STRING_FILE);
+ error("File not found: %s", STRING_FILE);
if (!_sceneryArchive1.open("scenery.dat"))
- Utils::Error(FILE_ERR, "%s", "scenery.dat");
+ error("File not found: scenery.dat");
if (!_objectsArchive.open(OBJECTS_FILE))
- Utils::Error(FILE_ERR, "%s", OBJECTS_FILE);
+ error("File not found: %s", OBJECTS_FILE);
}
/**
@@ -131,7 +131,7 @@ void FileManager_v2d::readOverlay(int screenNum, image_pt image, ovl_t overlayTy
i = sceneBlock.ob_len;
break;
default:
- Utils::Error(FILE_ERR, "%s", "Bad ovl_type");
+ error("Bad overlayType: %d", overlayType);
break;
}
if (i == 0) {
@@ -168,18 +168,18 @@ char *FileManager_v2d::fetchString(int index) {
_stringArchive.seek((uint32)index * sizeof(uint32), SEEK_SET);
uint32 off1, off2;
if (_stringArchive.read((char *)&off1, sizeof(uint32)) == 0)
- Utils::Error(FILE_ERR, "%s", "String offset");
+ error("An error has occurred: bad String offset");
if (_stringArchive.read((char *)&off2, sizeof(uint32)) == 0)
- Utils::Error(FILE_ERR, "%s", "String offset");
+ error("An error has occurred: bad String offset");
// Check size of string
if ((off2 - off1) >= MAX_BOX)
- Utils::Error(FILE_ERR, "%s", "Fetched string too long!");
+ error("Fetched string too long!");
// Position to string and read it into gen purpose _textBoxBuffer
_stringArchive.seek(off1, SEEK_SET);
if (_stringArchive.read(_textBoxBuffer, (uint16)(off2 - off1)) == 0)
- Utils::Error(FILE_ERR, "%s", "Fetch_string");
+ error("An error has occurred: fetchString");
// Null terminate, decode and return it
_textBoxBuffer[off2-off1] = '\0';
diff --git a/engines/hugo/file_v3d.cpp b/engines/hugo/file_v3d.cpp
index 312e2f7bc2..e98b4cc013 100644
--- a/engines/hugo/file_v3d.cpp
+++ b/engines/hugo/file_v3d.cpp
@@ -83,13 +83,13 @@ void FileManager_v3d::openDatabaseFiles() {
debugC(1, kDebugFile, "openDatabaseFiles");
if (!_stringArchive.open(STRING_FILE))
- Utils::Error(FILE_ERR, "%s", STRING_FILE);
+ error("File not found: %s", STRING_FILE);
if (!_sceneryArchive1.open("scenery1.dat"))
- Utils::Error(FILE_ERR, "%s", "scenery1.dat");
+ error("File not found: scenery1.dat");
if (!_sceneryArchive2.open("scenery2.dat"))
- Utils::Error(FILE_ERR, "%s", "scenery2.dat");
+ error("File not found: scenery2.dat");
if (!_objectsArchive.open(OBJECTS_FILE))
- Utils::Error(FILE_ERR, "%s", OBJECTS_FILE);
+ error("File not found: %s", OBJECTS_FILE);
}
/**
@@ -140,7 +140,7 @@ void FileManager_v3d::readOverlay(int screenNum, image_pt image, ovl_t overlayTy
i = sceneBlock.ob_len;
break;
default:
- Utils::Error(FILE_ERR, "%s", "Bad ovl_type");
+ error("Bad overlayType: %d", overlayType);
break;
}
if (i == 0) {
@@ -180,7 +180,7 @@ void FileManager_v3d::readOverlay(int screenNum, image_pt image, ovl_t overlayTy
i = sceneBlock.ob_len;
break;
default:
- Utils::Error(FILE_ERR, "%s", "Bad ovl_type");
+ error("Bad overlayType: %d", overlayType);
break;
}
if (i == 0) {
diff --git a/engines/hugo/global.h b/engines/hugo/global.h
index 0ab21ddb9c..43a1e39b8f 100644
--- a/engines/hugo/global.h
+++ b/engines/hugo/global.h
@@ -38,7 +38,6 @@ namespace Hugo {
#define MAX_SOUNDS 64 // Max number of sounds
#define BOOTFILE "HUGO.BSF" // Name of boot structure file
#define LEN_MASK 0x3F // Lower 6 bits are length
-#define PBFILE "playback.dat"
// Name scenery and objects picture databases
#define OBJECTS_FILE "objects.dat"
diff --git a/engines/hugo/schedule.cpp b/engines/hugo/schedule.cpp
index c368a1982d..837034a445 100644
--- a/engines/hugo/schedule.cpp
+++ b/engines/hugo/schedule.cpp
@@ -75,7 +75,7 @@ event_t *Scheduler::getQueue() {
debugC(4, kDebugSchedule, "getQueue");
if (!_freeEvent) // Error: no more events available
- Utils::Error(EVNT_ERR, "%s", "getQueue");
+ error("An error has occurred: %s", "getQueue");
event_t *resEvent = _freeEvent;
_freeEvent = _freeEvent->nextEvent;
resEvent->nextEvent = 0;
diff --git a/engines/hugo/schedule_v1d.cpp b/engines/hugo/schedule_v1d.cpp
index b7ce263a27..1b8dbd0300 100644
--- a/engines/hugo/schedule_v1d.cpp
+++ b/engines/hugo/schedule_v1d.cpp
@@ -313,7 +313,7 @@ event_t *Scheduler_v1d::doAction(event_t *curEvent) {
warning("STUB: doAction(act49)");
break;
default:
- Utils::Error(EVNT_ERR, "%s", "doAction");
+ error("An error has occurred: %s", "doAction");
break;
}
diff --git a/engines/hugo/schedule_v1w.cpp b/engines/hugo/schedule_v1w.cpp
index 128d0687a7..b2a495fcfa 100644
--- a/engines/hugo/schedule_v1w.cpp
+++ b/engines/hugo/schedule_v1w.cpp
@@ -340,7 +340,7 @@ event_t *Scheduler_v1w::doAction(event_t *curEvent) {
_vm->_object->_objects[action->a48.objNumb].currImagePtr = _vm->_object->_objects[action->a48.objNumb].currImagePtr->nextSeqPtr;
break;
default:
- Utils::Error(EVNT_ERR, "%s", "doAction");
+ error("An error has occurred: %s", "doAction");
break;
}
diff --git a/engines/hugo/schedule_v2d.cpp b/engines/hugo/schedule_v2d.cpp
index 22a79356bf..f1611fca4d 100644
--- a/engines/hugo/schedule_v2d.cpp
+++ b/engines/hugo/schedule_v2d.cpp
@@ -380,7 +380,7 @@ event_t *Scheduler_v2d::doAction(event_t *curEvent) {
warning("STUB: doAction(act49)");
break;
default:
- Utils::Error(EVNT_ERR, "%s", "doAction");
+ error("An error has occurred: %s", "doAction");
break;
}
diff --git a/engines/hugo/schedule_v3d.cpp b/engines/hugo/schedule_v3d.cpp
index fc37bd8b83..f710ccbc7d 100644
--- a/engines/hugo/schedule_v3d.cpp
+++ b/engines/hugo/schedule_v3d.cpp
@@ -313,7 +313,7 @@ event_t *Scheduler_v3d::doAction(event_t *curEvent) {
warning("STUB: doAction(act49)");
break;
default:
- Utils::Error(EVNT_ERR, "%s", "doAction");
+ error("An error has occurred: %s", "doAction");
break;
}
diff --git a/engines/hugo/util.cpp b/engines/hugo/util.cpp
index a3e778e228..bad97d80c5 100644
--- a/engines/hugo/util.cpp
+++ b/engines/hugo/util.cpp
@@ -136,51 +136,6 @@ char *Utils::Box(box_t dismiss, const char *s, ...) {
}
/**
- * Fatal error handler. Reset environment, print error and exit
- * Arguments are same as printf
- */
-void Utils::Error(int error_type, const char *format, ...) {
- char buffer[ERRLEN + 1];
- bool fatal = true; // Fatal error, else continue
-
- switch (error_type) {
- case FILE_ERR:
- strcpy(buffer, HugoEngine::get()._textUtil[kErr1]);
- break;
- case WRITE_ERR:
- strcpy(buffer, HugoEngine::get()._textUtil[kErr2]);
- fatal = false; // Allow continuation
- break;
- case PCCH_ERR:
- strcpy(buffer, HugoEngine::get()._textUtil[kErr3]);
- break;
- case HEAP_ERR:
- strcpy(buffer, HugoEngine::get()._textUtil[kErr4]);
- break;
- case SOUND_ERR:
- strcpy(buffer, HugoEngine::get()._textUtil[kErr5]);
- break;
- default:
- strcpy(buffer, HugoEngine::get()._textUtil[kErr6]);
- break;
- }
-
- if (fatal)
- HugoEngine::get().shutdown(); // Restore any devices before exit
-
- va_list marker;
- va_start(marker, format);
- vsnprintf(&buffer[strlen(buffer)], ERRLEN - strlen(buffer), format, marker);
- va_end(marker);
- //MessageBeep(MB_ICONEXCLAMATION);
- //MessageBox(hwnd, buffer, "HugoWin Error", MB_OK | MB_ICONEXCLAMATION);
- warning("Hugo Error: %s", buffer);
-
- if (fatal)
- exit(1);
-}
-
-/**
* Print options for user when dead
*/
void Utils::gameOverMsg(void) {
diff --git a/engines/hugo/util.h b/engines/hugo/util.h
index a3e206dba9..7120ebf771 100644
--- a/engines/hugo/util.h
+++ b/engines/hugo/util.h
@@ -54,7 +54,6 @@ int lastBit(byte data);
void gameOverMsg();
void reverseByte(byte *data);
-void Error(int code, const char *format, ...) GCC_PRINTF(2, 3);
char *Box(box_t, const char *, ...) GCC_PRINTF(2, 3);
char *strlwr(char *buffer);