diff options
Diffstat (limited to 'sky/disk.cpp')
-rw-r--r-- | sky/disk.cpp | 192 |
1 files changed, 81 insertions, 111 deletions
diff --git a/sky/disk.cpp b/sky/disk.cpp index 233709cd52..b7b50e1da9 100644 --- a/sky/disk.cpp +++ b/sky/disk.cpp @@ -22,52 +22,45 @@ #include "stdafx.h" #include "common/scummsys.h" #include "common/engine.h" -#include "common/file.h" +#include "sky/disk.h" #include "sky/skydefs.h" #include "sky/sky.h" #include "sky/rnc_deco.h" -#define MAX_FILES_IN_LIST 60 +static const char *dataFilename = "sky.dsk"; +static const char *dinnerFilename = "sky.dnr"; -const char *dataFilename = "sky.dsk"; -const char *dinnerFilename = "sky.dnr"; -uint8 *dinnerTableArea, *fixedDest, *fileDest, *compDest; -uint32 dinnerTableEntries, fileFlags, fileOffset, fileSize, decompSize, compFile; -uint16 buildList[MAX_FILES_IN_LIST]; -uint32 loadedFileList[MAX_FILES_IN_LIST]; +SkyDisk::SkyDisk(char *gameDataPath) { + _gameDataPath = gameDataPath; -File *dataDiskHandle = new File(); -File *dnrHandle = new File(); - -void SkyState::initialiseDisk() { + _dataDiskHandle = new File(); + _dnrHandle = new File(); uint32 entriesRead; - dnrHandle->open(dinnerFilename, _gameDataPath); - if (dnrHandle->isOpen() == false) + _dnrHandle->open(dinnerFilename, _gameDataPath); + if (_dnrHandle->isOpen() == false) error("Could not open %s%s!\n", _gameDataPath, dinnerFilename); - if (!(dinnerTableEntries = dnrHandle->readUint32LE())) + if (!(_dinnerTableEntries = _dnrHandle->readUint32LE())) error("Error reading from sky.dnr!\n"); //even though it was opened correctly?! - debug(1, "Entries in dinner table: %d", dinnerTableEntries); + debug(1, "Entries in dinner table: %d", _dinnerTableEntries); - determineGameVersion(dinnerTableEntries); - - dinnerTableArea = (uint8 *)malloc(dinnerTableEntries * 8); - entriesRead = dnrHandle->read(dinnerTableArea, 8 * dinnerTableEntries) / 8; + _dinnerTableArea = (uint8 *)malloc(_dinnerTableEntries * 8); + entriesRead = _dnrHandle->read(_dinnerTableArea, 8 * _dinnerTableEntries) / 8; - if (entriesRead != dinnerTableEntries) - warning("entriesRead != dinnerTableEntries. [%d/%d]\n", entriesRead, dinnerTableEntries); + if (entriesRead != _dinnerTableEntries) + warning("entriesRead != dinnerTableEntries. [%d/%d]\n", entriesRead, _dinnerTableEntries); - dataDiskHandle->open(dataFilename, _gameDataPath); - if (dataDiskHandle->isOpen() == false) + _dataDiskHandle->open(dataFilename, _gameDataPath); + if (_dataDiskHandle->isOpen() == false) error("Error opening %s%s!\n", _gameDataPath, dataFilename); } //load in file file_nr to address dest //if dest == NULL, then allocate memory for this file -uint8 *SkyState::loadFile(uint16 fileNr, uint8 *dest) { +uint8 *SkyDisk::loadFile(uint16 fileNr, uint8 *dest) { uint8 cflag; int32 bytesRead; @@ -78,7 +71,7 @@ uint8 *SkyState::loadFile(uint16 fileNr, uint8 *dest) { warning("File order checking not implemented yet!\n"); #endif - compFile = fileNr; + _compFile = fileNr; debug(2, "load file %d,%d (%d)", (fileNr >> 11), (fileNr & 2047), fileNr); filePtr = getFileInfo(fileNr); @@ -87,58 +80,58 @@ uint8 *SkyState::loadFile(uint16 fileNr, uint8 *dest) { return NULL; } - fileFlags = READ_LE_UINT32((filePtr + 5)); - fileSize = fileFlags & 0x03fffff; - _lastLoadedFileSize = fileSize; + _fileFlags = READ_LE_UINT32((filePtr + 5)); + _fileSize = _fileFlags & 0x03fffff; + _lastLoadedFileSize = _fileSize; - fileOffset = READ_LE_UINT32((filePtr + 2)) & 0x0ffffff; + _fileOffset = READ_LE_UINT32((filePtr + 2)) & 0x0ffffff; - cflag = (uint8)((fileOffset >> (23)) & 0x1); - fileOffset = (((1 << (23)) ^ 0xFFFFFFFF) & fileOffset); + cflag = (uint8)((_fileOffset >> (23)) & 0x1); + _fileOffset = (((1 << (23)) ^ 0xFFFFFFFF) & _fileOffset); if (cflag) - fileOffset <<= 4; + _fileOffset <<= 4; - fixedDest = dest; - fileDest = dest; - compDest = dest; + _fixedDest = dest; + _fileDest = dest; + _compDest = dest; if (dest == NULL) //we need to allocate memory for this file - fileDest = (uint8 *)malloc(fileSize); + _fileDest = (uint8 *)malloc(_fileSize); - dataDiskHandle->seek(fileOffset, SEEK_SET); + _dataDiskHandle->seek(_fileOffset, SEEK_SET); #ifdef file_order_chk warning("File order checking not implemented yet!\n"); #endif //now read in the data - bytesRead = dataDiskHandle->read(fileDest, 1 * fileSize); + bytesRead = _dataDiskHandle->read(_fileDest, 1 * _fileSize); - if (bytesRead != (int32)fileSize) - printf("ERROR: Unable to read %d bytes from datadisk (%d bytes read)\n", fileSize, bytesRead); + if (bytesRead != (int32)_fileSize) + printf("ERROR: Unable to read %d bytes from datadisk (%d bytes read)\n", _fileSize, bytesRead); - cflag = (uint8)((fileFlags >> (23)) & 0x1); + cflag = (uint8)((_fileFlags >> (23)) & 0x1); //if cflag == 0 then file is compressed, 1 == uncompressed if (!cflag) { debug(2, "File is compressed..."); - memcpy(&fileHeader, fileDest, sizeof(struct dataFileHeader)); + memcpy(&fileHeader, _fileDest, sizeof(struct dataFileHeader)); if ( (uint8)((FROM_LE_16(fileHeader.flag) >> 7) & 0x1) ) { debug(2, "with RNC!"); - decompSize = (FROM_LE_16(fileHeader.flag) & 0xFFFFFF00) << 8; - decompSize |= FROM_LE_16((uint16)fileHeader.s_tot_size); + _decompSize = (FROM_LE_16(fileHeader.flag) & 0xFFFFFF00) << 8; + _decompSize |= FROM_LE_16((uint16)fileHeader.s_tot_size); - if (fixedDest == NULL) // is this valid? - compDest = (uint8 *)malloc(decompSize); + if (_fixedDest == NULL) // is this valid? + _compDest = (uint8 *)malloc(_decompSize); - inputPtr = fileDest; - outputPtr = compDest; + inputPtr = _fileDest; + outputPtr = _compDest; - if ( (uint8)(fileFlags >> (22) & 0x1) ) //do we include the header? + if ( (uint8)(_fileFlags >> (22) & 0x1) ) //do we include the header? inputPtr += sizeof(struct dataFileHeader); else { memcpy(outputPtr, inputPtr, sizeof(struct dataFileHeader)); @@ -152,39 +145,39 @@ uint8 *SkyState::loadFile(uint16 fileNr, uint8 *dest) { debug(3, "UnpackM1 returned: %d", unPackLen); if (unPackLen == 0) { //Unpack returned 0: file was probably not packed. - if (fixedDest == NULL) - free(compDest); + if (_fixedDest == NULL) + free(_compDest); - return fileDest; + return _fileDest; } - if (! (uint8)(fileFlags >> (22) & 0x1) ) { // include header? + if (! (uint8)(_fileFlags >> (22) & 0x1) ) { // include header? unPackLen += sizeof(struct dataFileHeader); - if (unPackLen != (int32)decompSize) { - debug(1, "ERROR: invalid decomp size! (was: %d, should be: %d)", unPackLen, decompSize); + if (unPackLen != (int32)_decompSize) { + debug(1, "ERROR: invalid decomp size! (was: %d, should be: %d)", unPackLen, _decompSize); } } - _lastLoadedFileSize = decompSize; //including header + _lastLoadedFileSize = _decompSize; //including header - if (fixedDest == NULL) - free(fileDest); + if (_fixedDest == NULL) + free(_fileDest); } else debug(2, "but not with RNC! (?!)"); } else - return fileDest; + return _fileDest; - return compDest; + return _compDest; } -uint8 *SkyState::getFileInfo(uint16 fileNr) { +uint8 *SkyDisk::getFileInfo(uint16 fileNr) { uint16 i; - uint16 *dnrTbl16Ptr = (uint16 *)dinnerTableArea; + uint16 *dnrTbl16Ptr = (uint16 *)_dinnerTableArea; - for (i = 0; i < dinnerTableEntries; i++) { + for (i = 0; i < _dinnerTableEntries; i++) { if (READ_LE_UINT16(dnrTbl16Ptr + (i * 4)) == fileNr) { debug(2, "file %d found!", fileNr); return (uint8 *)(dnrTbl16Ptr + (i * 4)); @@ -195,70 +188,47 @@ uint8 *SkyState::getFileInfo(uint16 fileNr) { return (uint8 *)NULL; } -void SkyState::determineGameVersion(uint32 dnrEntries) { +void SkyDisk::dumpFile(uint16 fileNr) { + char buf[128]; + File out; + byte* filePtr; - //determine game version based on number of entries in dinner table + filePtr = loadFile(fileNr, NULL); + sprintf(buf, "dumps/file-%d.dmp", fileNr); - switch (dnrEntries) { + out.open(buf, "", 1); + if (out.isOpen() == false) { + out.open(buf, "", 2); + if (out.isOpen() == false) + return; + out.write(filePtr, _lastLoadedFileSize); + } + out.close(); + free(filePtr); +} +uint32 SkyDisk::determineGameVersion() { + //determine game version based on number of entries in dinner table + switch (_dinnerTableEntries) { case 247: //floppy demo (v0.0267) - _isDemo = true; - _isCDVersion = false; - _gameVersion = 267; - break; - + return 267; case 1404: //floppy (v0.0288) - _isDemo = false; - _isCDVersion = false; - _gameVersion = 288; - break; - + return 288; case 1445: //floppy (v0.0331) - _isDemo = false; - _isCDVersion = false; - _gameVersion = 331; - break; - + return 331; case 1711: //cd demo (v0.0365) - _isDemo = true; - _isCDVersion = true; - _gameVersion = 365; - break; - + return 365; case 5099: //cd (v0.0368) - _isDemo = false; - _isCDVersion = true; - _gameVersion = 368; - break; - + return 368; default: //unknown version error("Unknown game version!"); break; } - } -void SkyState::dumpFile(uint16 fileNr) { - char buf[128]; - File out; - byte* filePtr; - - filePtr = loadFile(fileNr, NULL); - sprintf(buf, "dumps/file-%d.dmp", fileNr); - - out.open(buf, "", 1); - if (out.isOpen() == false) { - out.open(buf, "", 2); - if (out.isOpen() == false) - return; - out.write(filePtr, _lastLoadedFileSize); - } - out.close(); - free(filePtr); -} |