mirror of
https://github.com/libretro/scummvm.git
synced 2025-03-06 02:10:28 +00:00
HUGO: Start using endianness-safe read/write functions
svn-id: r54389
This commit is contained in:
parent
7fb352e38a
commit
e5177eebfd
@ -40,7 +40,6 @@
|
||||
|
||||
namespace Hugo {
|
||||
|
||||
#define NUM_COLORS 16 // Num colors to save in palette
|
||||
#define DMAX 16 // Size of add/restore rect lists
|
||||
#define BMAX (DMAX * 2) // Size of dirty rect blit list
|
||||
|
||||
@ -126,15 +125,15 @@ void Screen::remapPal(uint16 oldIndex, uint16 newIndex) {
|
||||
void Screen::savePal(Common::WriteStream *f) {
|
||||
debugC(1, kDebugDisplay, "savePal");
|
||||
|
||||
warning("STUB: savePal()");
|
||||
//fwrite(bminfo.bmiColors, sizeof(bminfo.bmiColors), 1, f);
|
||||
for (int i = 0; i < _paletteSize; i++)
|
||||
f->writeByte(_palette[i]);
|
||||
}
|
||||
|
||||
void Screen::restorePal(Common::SeekableReadStream *f) {
|
||||
debugC(1, kDebugDisplay, "restorePal");
|
||||
|
||||
warning("STUB: restorePal()");
|
||||
//fread(bminfo.bmiColors, sizeof(bminfo.bmiColors), 1, f);
|
||||
for (int i = 0; i < _paletteSize; i++)
|
||||
_palette[i] = f->readByte();
|
||||
}
|
||||
|
||||
|
||||
|
@ -285,11 +285,7 @@ sound_pt FileManager::getSound(int16 sound, uint16 *size) {
|
||||
*/
|
||||
bool FileManager::fileExists(char *filename) {
|
||||
Common::File f;
|
||||
if (f.open(filename)) {
|
||||
f.close();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return(f.exists(filename));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -313,7 +309,7 @@ void FileManager::saveGame(int16 slot, const char *descrip) {
|
||||
}
|
||||
|
||||
// Write version. We can't restore from obsolete versions
|
||||
out->write(&kSavegameVersion, sizeof(kSavegameVersion));
|
||||
out->writeByte(kSavegameVersion);
|
||||
|
||||
// Save description of saved game
|
||||
out->write(descrip, DESCRIPLEN);
|
||||
@ -323,26 +319,29 @@ void FileManager::saveGame(int16 slot, const char *descrip) {
|
||||
const status_t &gameStatus = _vm->getGameStatus();
|
||||
|
||||
// Save whether hero image is swapped
|
||||
out->write(&_vm->_heroImage, sizeof(_vm->_heroImage));
|
||||
out->writeByte(_vm->_heroImage);
|
||||
|
||||
// Save score
|
||||
int score = _vm->getScore();
|
||||
out->write(&score, sizeof(score));
|
||||
out->writeSint16BE(_vm->getScore());
|
||||
|
||||
// Save story mode
|
||||
out->write(&gameStatus.storyModeFl, sizeof(gameStatus.storyModeFl));
|
||||
out->writeByte((gameStatus.storyModeFl) ? 1 : 0);
|
||||
|
||||
// Save jumpexit mode
|
||||
out->write(&gameStatus.jumpExitFl, sizeof(gameStatus.jumpExitFl));
|
||||
out->writeByte((gameStatus.jumpExitFl) ? 1 : 0);
|
||||
|
||||
// Save gameover status
|
||||
out->write(&gameStatus.gameOverFl, sizeof(gameStatus.gameOverFl));
|
||||
out->writeByte((gameStatus.gameOverFl) ? 1 : 0);
|
||||
|
||||
// Save screen states
|
||||
out->write(_vm->_screenStates, sizeof(*_vm->_screenStates) * _vm->_numScreens);
|
||||
for (int i = 0; i < _vm->_numScreens; i++)
|
||||
out->writeByte(_vm->_screenStates[i]);
|
||||
|
||||
// Save points table
|
||||
out->write(_vm->_points, sizeof(point_t) * _vm->_numBonuses);
|
||||
for (int i = 0; i < _vm->_numBonuses; i++) {
|
||||
out->writeByte(_vm->_points[i].score);
|
||||
out->writeByte((_vm->_points[i].scoredFl) ? 1 : 0);
|
||||
}
|
||||
|
||||
// Now save current time and all current events in event queue
|
||||
_vm->_scheduler->saveEvents(out);
|
||||
@ -351,7 +350,15 @@ void FileManager::saveGame(int16 slot, const char *descrip) {
|
||||
_vm->_screen->savePal(out);
|
||||
|
||||
// Save maze status
|
||||
out->write(&_maze, sizeof(maze_t));
|
||||
out->writeByte((_maze.enabledFl) ? 1 : 0);
|
||||
out->writeByte(_maze.size);
|
||||
out->writeSint16BE(_maze.x1);
|
||||
out->writeSint16BE(_maze.y1);
|
||||
out->writeSint16BE(_maze.x2);
|
||||
out->writeSint16BE(_maze.y2);
|
||||
out->writeSint16BE(_maze.x3);
|
||||
out->writeSint16BE(_maze.x4);
|
||||
out->writeByte(_maze.firstScreenIndex);
|
||||
|
||||
out->finalize();
|
||||
|
||||
@ -380,8 +387,7 @@ void FileManager::restoreGame(int16 slot) {
|
||||
return;
|
||||
|
||||
// Check version, can't restore from different versions
|
||||
int saveVersion;
|
||||
in->read(&saveVersion, sizeof(saveVersion));
|
||||
int saveVersion = in->readByte();
|
||||
if (saveVersion != kSavegameVersion) {
|
||||
error("Savegame of incompatible version");
|
||||
return;
|
||||
@ -396,27 +402,30 @@ void FileManager::restoreGame(int16 slot) {
|
||||
|
||||
_vm->_object->restoreObjects(in);
|
||||
|
||||
in->read(&_vm->_heroImage, sizeof(_vm->_heroImage));
|
||||
_vm->_heroImage = in->readByte();
|
||||
|
||||
// If hero swapped in saved game, swap it
|
||||
int heroImg = _vm->_heroImage;
|
||||
byte heroImg = _vm->_heroImage;
|
||||
if (heroImg != HERO)
|
||||
_vm->_object->swapImages(HERO, _vm->_heroImage);
|
||||
_vm->_heroImage = heroImg;
|
||||
|
||||
status_t &gameStatus = _vm->getGameStatus();
|
||||
|
||||
int score;
|
||||
in->read(&score, sizeof(score));
|
||||
int score = in->readSint16LE();
|
||||
_vm->setScore(score);
|
||||
|
||||
in->read(&gameStatus.storyModeFl, sizeof(gameStatus.storyModeFl));
|
||||
in->read(&gameStatus.jumpExitFl, sizeof(gameStatus.jumpExitFl));
|
||||
in->read(&gameStatus.gameOverFl, sizeof(gameStatus.gameOverFl));
|
||||
in->read(_vm->_screenStates, sizeof(*_vm->_screenStates) * _vm->_numScreens);
|
||||
gameStatus.storyModeFl = (in->readByte() == 1);
|
||||
gameStatus.jumpExitFl = (in->readByte() == 1);
|
||||
gameStatus.gameOverFl = (in->readByte() == 1);
|
||||
for (int i = 0; i < _vm->_numScreens; i++)
|
||||
_vm->_screenStates[i] = in->readByte();
|
||||
|
||||
// Restore points table
|
||||
in->read(_vm->_points, sizeof(point_t) * _vm->_numBonuses);
|
||||
for (int i = 0; i < _vm->_numBonuses; i++) {
|
||||
_vm->_points[i].score = in->readByte();
|
||||
_vm->_points[i].scoredFl = (in->readByte() == 1);
|
||||
}
|
||||
|
||||
_vm->_object->restoreAllSeq();
|
||||
|
||||
@ -427,7 +436,15 @@ void FileManager::restoreGame(int16 slot) {
|
||||
_vm->_screen->restorePal(in);
|
||||
|
||||
// Restore maze status
|
||||
in->read(&_maze, sizeof(maze_t));
|
||||
_maze.enabledFl = (in->readByte() == 1);
|
||||
_maze.size = in->readByte();
|
||||
_maze.x1 = in->readSint16BE();
|
||||
_maze.y1 = in->readSint16BE();
|
||||
_maze.x2 = in->readSint16BE();
|
||||
_maze.y2 = in->readSint16BE();
|
||||
_maze.x3 = in->readSint16BE();
|
||||
_maze.x4 = in->readSint16BE();
|
||||
_maze.firstScreenIndex = in->readByte();
|
||||
|
||||
delete in;
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ struct PCC_header_t { // Structure of PCX file hea
|
||||
byte mfctr, vers, enc, bpx;
|
||||
uint16 x1, y1, x2, y2; // bounding box
|
||||
uint16 xres, yres;
|
||||
byte palette[48]; // EGA color palette
|
||||
byte palette[3 * NUM_COLORS]; // EGA color palette
|
||||
byte vmode, planes;
|
||||
uint16 bytesPerLine; // Bytes per line
|
||||
byte fill2[60];
|
||||
|
@ -106,6 +106,7 @@ namespace Hugo {
|
||||
// Macros:
|
||||
#define TPS ((_config.turboFl) ? TURBO_TPS : NORMAL_TPS)
|
||||
|
||||
#define NUM_COLORS 16 // Num colors to save in palette
|
||||
#define MAX_UIFS 32 // Max possible uif items in hdr
|
||||
#define NUM_FONTS 3 // Number of dib fonts
|
||||
#define FIRST_FONT U_FONT5
|
||||
|
@ -157,10 +157,11 @@ event_t *Scheduler_v1d::doAction(event_t *curEvent) {
|
||||
break;
|
||||
case PROMPT: { // act3: Prompt user for key phrase
|
||||
response = Utils::Box(BOX_PROMPT, "%s", _vm->_file->fetchString(action->a3.promptIndex));
|
||||
strcpy(response, _vm->_file->fetchString(action->a3.promptIndex));
|
||||
if (action->a3.encodedFl)
|
||||
decodeString(response);
|
||||
|
||||
warning("STUB: doAction(act3), expecting answer %s", _vm->_file->fetchString(action->a3.responsePtr[0]));
|
||||
warning("STUB: doAction(act3), expecting answer %s", response);
|
||||
|
||||
// TODO: The answer of the player is not handled currently! Once it'll be read in the messageBox, uncomment this block
|
||||
#if 0
|
||||
@ -350,11 +351,12 @@ void Scheduler_v1d::saveEvents(Common::WriteStream *f) {
|
||||
int16 headIndex = (_headEvent == 0) ? -1 : _headEvent - _events;
|
||||
int16 tailIndex = (_tailEvent == 0) ? -1 : _tailEvent - _events;
|
||||
|
||||
f->write(&curTime, sizeof(curTime));
|
||||
f->write(&freeIndex, sizeof(freeIndex));
|
||||
f->write(&headIndex, sizeof(headIndex));
|
||||
f->write(&tailIndex, sizeof(tailIndex));
|
||||
f->writeUint32BE(curTime);
|
||||
f->writeSint16BE(freeIndex);
|
||||
f->writeSint16BE(headIndex);
|
||||
f->writeSint16BE(tailIndex);
|
||||
f->write(saveEventArr, sizeof(saveEventArr));
|
||||
warning("TODO: serialize saveEventArr");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -369,10 +371,10 @@ void Scheduler_v1d::restoreEvents(Common::SeekableReadStream *f) {
|
||||
int16 tailIndex; // Tail of list index
|
||||
event_t savedEvents[kMaxEvents]; // Convert event ptrs to indexes
|
||||
|
||||
f->read(&saveTime, sizeof(saveTime)); // time of save
|
||||
f->read(&freeIndex, sizeof(freeIndex));
|
||||
f->read(&headIndex, sizeof(headIndex));
|
||||
f->read(&tailIndex, sizeof(tailIndex));
|
||||
saveTime = f->readUint32BE(); // time of save
|
||||
freeIndex = f->readSint16BE();
|
||||
headIndex = f->readSint16BE();
|
||||
tailIndex = f->readSint16BE();
|
||||
f->read(savedEvents, sizeof(savedEvents));
|
||||
|
||||
event_t *wrkEvent;
|
||||
|
@ -377,11 +377,12 @@ void Scheduler_v1w::saveEvents(Common::WriteStream *f) {
|
||||
int16 headIndex = (_headEvent == 0) ? -1 : _headEvent - _events;
|
||||
int16 tailIndex = (_tailEvent == 0) ? -1 : _tailEvent - _events;
|
||||
|
||||
f->write(&curTime, sizeof(curTime));
|
||||
f->write(&freeIndex, sizeof(freeIndex));
|
||||
f->write(&headIndex, sizeof(headIndex));
|
||||
f->write(&tailIndex, sizeof(tailIndex));
|
||||
f->writeUint32BE(curTime);
|
||||
f->writeSint16BE(freeIndex);
|
||||
f->writeSint16BE(headIndex);
|
||||
f->writeSint16BE(tailIndex);
|
||||
f->write(saveEventArr, sizeof(saveEventArr));
|
||||
warning("TODO: serialize saveEventArr");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -396,10 +397,11 @@ void Scheduler_v1w::restoreEvents(Common::SeekableReadStream *f) {
|
||||
int16 tailIndex; // Tail of list index
|
||||
event_t savedEvents[kMaxEvents]; // Convert event ptrs to indexes
|
||||
|
||||
f->read(&saveTime, sizeof(saveTime)); // time of save
|
||||
f->read(&freeIndex, sizeof(freeIndex));
|
||||
f->read(&headIndex, sizeof(headIndex));
|
||||
f->read(&tailIndex, sizeof(tailIndex));
|
||||
saveTime = f->readUint32BE(); // time of save
|
||||
freeIndex = f->readSint16BE();
|
||||
headIndex = f->readSint16BE();
|
||||
tailIndex = f->readSint16BE();
|
||||
|
||||
f->read(savedEvents, sizeof(savedEvents));
|
||||
|
||||
event_t *wrkEvent;
|
||||
|
Loading…
x
Reference in New Issue
Block a user