diff options
author | Robert Göffringmann | 2004-11-11 10:14:35 +0000 |
---|---|---|
committer | Robert Göffringmann | 2004-11-11 10:14:35 +0000 |
commit | 7dec7b7054db8367f48d27a319c3550ec807ac27 (patch) | |
tree | 6539c8513a875eaa37c0de06208782e9d337aa4a | |
parent | c50560a48813ba237878af4f47854bd3bc8751b3 (diff) | |
download | scummvm-rg350-7dec7b7054db8367f48d27a319c3550ec807ac27.tar.gz scummvm-rg350-7dec7b7054db8367f48d27a319c3550ec807ac27.tar.bz2 scummvm-rg350-7dec7b7054db8367f48d27a319c3550ec807ac27.zip |
misc cleanup
svn-id: r15783
-rw-r--r-- | sky/control.cpp | 22 | ||||
-rw-r--r-- | sky/disk.cpp | 177 | ||||
-rw-r--r-- | sky/disk.h | 9 | ||||
-rw-r--r-- | sky/grid.cpp | 88 | ||||
-rw-r--r-- | sky/grid.h | 12 | ||||
-rw-r--r-- | sky/intro.cpp | 8 | ||||
-rw-r--r-- | sky/logic.cpp | 4 | ||||
-rw-r--r-- | sky/mouse.cpp | 13 | ||||
-rw-r--r-- | sky/music/musicbase.cpp | 2 | ||||
-rw-r--r-- | sky/screen.cpp | 8 | ||||
-rw-r--r-- | sky/sky.cpp | 30 | ||||
-rw-r--r-- | sky/sound.cpp | 4 | ||||
-rw-r--r-- | sky/text.cpp | 10 |
13 files changed, 188 insertions, 199 deletions
diff --git a/sky/control.cpp b/sky/control.cpp index e1909c079c..f800f7e27a 100644 --- a/sky/control.cpp +++ b/sky/control.cpp @@ -246,19 +246,19 @@ void Control::initPanel(void) { uint16 spdY = (SkyEngine::_systemVars.gameSpeed - 2) / SPEED_MULTIPLY; spdY += MPNL_Y + 83; // speed slider's initial position - _sprites.controlPanel = _skyDisk->loadFile(60500, NULL); - _sprites.button = _skyDisk->loadFile(60501, NULL); - _sprites.buttonDown = _skyDisk->loadFile(60502, NULL); - _sprites.savePanel = _skyDisk->loadFile(60503, NULL); - _sprites.yesNo = _skyDisk->loadFile(60504, NULL); - _sprites.slide = _skyDisk->loadFile(60505, NULL); - _sprites.slode = _skyDisk->loadFile(60506, NULL); - _sprites.slode2 = _skyDisk->loadFile(60507, NULL); - _sprites.slide2 = _skyDisk->loadFile(60508, NULL); + _sprites.controlPanel = _skyDisk->loadFile(60500); + _sprites.button = _skyDisk->loadFile(60501); + _sprites.buttonDown = _skyDisk->loadFile(60502); + _sprites.savePanel = _skyDisk->loadFile(60503); + _sprites.yesNo = _skyDisk->loadFile(60504); + _sprites.slide = _skyDisk->loadFile(60505); + _sprites.slode = _skyDisk->loadFile(60506); + _sprites.slode2 = _skyDisk->loadFile(60507); + _sprites.slide2 = _skyDisk->loadFile(60508); if (SkyEngine::_systemVars.gameVersion < 368) _sprites.musicBodge = NULL; else - _sprites.musicBodge = _skyDisk->loadFile(60509, NULL); + _sprites.musicBodge = _skyDisk->loadFile(60509); //Main control panel: X Y Text OnClick _controlPanel = createResource(_sprites.controlPanel, 1, 0, 0, 0, 0, DO_NOTHING, MAINPANEL); @@ -1538,7 +1538,7 @@ uint16 Control::restoreGameFromFile(bool autoSave) { *(uint32 *)saveData = TO_LE_32(infSize); if (inf->read(saveData+4, infSize-4) != infSize-4) { - displayMessage("Can't read from file '%s'", fName); + displayMessage(NULL, "Can't read from file '%s'", fName); free(saveData); delete inf; return RESTORE_FAILED; diff --git a/sky/disk.cpp b/sky/disk.cpp index 97e4508d2f..0f7fd50209 100644 --- a/sky/disk.cpp +++ b/sky/disk.cpp @@ -42,8 +42,8 @@ Disk::Disk(const Common::String &gameDataPath) { uint32 entriesRead; _dnrHandle->open(dinnerFilename); - if (_dnrHandle->isOpen() == false) - error("Could not open %s%s", gameDataPath.c_str(), dinnerFilename); + if (!_dnrHandle->isOpen()) + error("Could not open %s%s", gameDataPath.c_str(), dinnerFilename); if (!(_dinnerTableEntries = _dnrHandle->readUint32LE())) error("Error reading from sky.dnr"); //even though it was opened correctly?! @@ -55,7 +55,7 @@ Disk::Disk(const Common::String &gameDataPath) { warning("entriesRead != dinnerTableEntries. [%d/%d]", entriesRead, _dinnerTableEntries); _dataDiskHandle->open(dataFilename); - if (_dataDiskHandle->isOpen() == false) + if (!_dataDiskHandle->isOpen()) error("Error opening %s%s", gameDataPath.c_str(), dataFilename); printf("Found BASS version v0.0%d (%d dnr entries)\n", determineGameVersion(), _dinnerTableEntries); @@ -73,8 +73,10 @@ Disk::~Disk(void) { fEntry = fEntry->next; delete fTemp; } - if (_dnrHandle->isOpen()) _dnrHandle->close(); - if (_dataDiskHandle->isOpen()) _dataDiskHandle->close(); + if (_dnrHandle->isOpen()) + _dnrHandle->close(); + if (_dataDiskHandle->isOpen()) + _dataDiskHandle->close(); delete _dnrHandle; delete _dataDiskHandle; } @@ -96,133 +98,101 @@ bool Disk::fileExists(uint16 fileNr) { return (getFileInfo(fileNr) != NULL); } -//load in file file_nr to address dest -//if dest == NULL, then allocate memory for this file -uint8 *Disk::loadFile(uint16 fileNr, uint8 *dest) { - +// allocate memory, load the file and return a pointer +uint8 *Disk::loadFile(uint16 fileNr) { + uint8 cflag; - int32 bytesRead; - uint8 *filePtr, *inputPtr, *outputPtr; - dataFileHeader fileHeader; uint8 *prefData = givePrefetched(fileNr, &_lastLoadedFileSize); - if (prefData) { - if (dest == NULL) return prefData; - else { - memcpy(dest, prefData, _lastLoadedFileSize); - free(prefData); - return dest; - } - } + if (prefData) + return prefData; - _compFile = fileNr; debug(2, "load file %d,%d (%d)", (fileNr >> 11), (fileNr & 2047), fileNr); - filePtr = getFileInfo(fileNr); - if (filePtr == NULL) { + uint8 *fileInfoPtr = getFileInfo(fileNr); + if (fileInfoPtr == NULL) { debug(1, "File %d not found", fileNr); return NULL; } - _fileFlags = READ_LE_UINT24(filePtr + 5); - _fileSize = _fileFlags & 0x03fffff; - _lastLoadedFileSize = _fileSize; - - _fileOffset = READ_LE_UINT32(filePtr + 2) & 0x0ffffff; + uint32 fileFlags = READ_LE_UINT24(fileInfoPtr + 5); + uint32 fileSize = fileFlags & 0x03fffff; + uint32 fileOffset = READ_LE_UINT32(fileInfoPtr + 2) & 0x0ffffff; - cflag = (uint8)((_fileOffset >> 23) & 0x1); - _fileOffset &= 0x7FFFFF; + _lastLoadedFileSize = fileSize; + cflag = (uint8)((fileOffset >> 23) & 0x1); + fileOffset &= 0x7FFFFF; if (cflag) { if (SkyEngine::_systemVars.gameVersion == 331) - _fileOffset <<= 3; + fileOffset <<= 3; else - _fileOffset <<= 4; + fileOffset <<= 4; } - _fixedDest = dest; - _fileDest = dest; - _compDest = dest; - - if (dest == NULL) //we need to allocate memory for this file - _fileDest = (uint8 *)malloc(_fileSize + 4); + uint8 *fileDest = (uint8 *)malloc(fileSize + 4); // allocate memory for file - _dataDiskHandle->seek(_fileOffset, SEEK_SET); + _dataDiskHandle->seek(fileOffset, SEEK_SET); //now read in the data - bytesRead = _dataDiskHandle->read(_fileDest, 1 * _fileSize); + int32 bytesRead = _dataDiskHandle->read(fileDest, fileSize); - if (bytesRead != (int32)_fileSize) - warning("ERROR: Unable to read %d bytes from datadisk (%d bytes read)", _fileSize, bytesRead); - - cflag = (uint8)((_fileFlags >> (23)) & 0x1); + if (bytesRead != (int32)fileSize) + warning("Unable to read %d bytes from datadisk (%d bytes read)", fileSize, bytesRead); + cflag = (uint8)((fileFlags >> 23) & 0x1); //if cflag == 0 then file is compressed, 1 == uncompressed - if ((!cflag) && ((FROM_LE_16(((dataFileHeader *)_fileDest)->flag) >> 7)&1)) { - debug(2, "File is RNC compressed."); + dataFileHeader *fileHeader = (dataFileHeader*)fileDest; - memcpy(&fileHeader, _fileDest, sizeof(struct dataFileHeader)); - _decompSize = (FROM_LE_16(fileHeader.flag) & 0xFFFFFF00) << 8; - _decompSize |= FROM_LE_16((uint16)fileHeader.s_tot_size); + if ((!cflag) && ((FROM_LE_16(fileHeader->flag) >> 7) & 1)) { + debug(2, "File is RNC compressed."); - if (_fixedDest == NULL) // is this valid? - _compDest = (uint8 *)malloc(_decompSize); + uint32 decompSize = (FROM_LE_16(fileHeader->flag) & ~0xFF) << 8; + decompSize |= FROM_LE_16(fileHeader->s_tot_size); - inputPtr = _fileDest; - outputPtr = _compDest; + uint8 *uncompDest = (uint8 *)malloc(decompSize); - if ( (uint8)(_fileFlags >> (22) & 0x1) ) //do we include the header? - inputPtr += sizeof(struct dataFileHeader); - else { + RncDecoder rncDecoder; + int32 unpackLen; + if ((fileFlags >> 22) & 0x1) { //do we include the header? + // don't return the file's header + unpackLen = rncDecoder.unpackM1(fileDest + sizeof(dataFileHeader), uncompDest, 0); + } else { #ifdef SCUMM_BIG_ENDIAN // Convert dataFileHeader to BE (it only consists of 16 bit words) uint16 *headPtr = (uint16 *)_fileDest; for (uint i = 0; i < sizeof(struct dataFileHeader) / 2; i++) *(headPtr + i) = READ_LE_UINT16(headPtr + i); #endif - memcpy(outputPtr, inputPtr, sizeof(struct dataFileHeader)); - inputPtr += sizeof(struct dataFileHeader); - outputPtr += sizeof(struct dataFileHeader); + memcpy(uncompDest, fileDest, sizeof(dataFileHeader)); + unpackLen = rncDecoder.unpackM1(fileDest + sizeof(dataFileHeader), uncompDest + sizeof(dataFileHeader), 0); + unpackLen += sizeof(dataFileHeader); } - RncDecoder rncDecoder; - int32 unPackLen = rncDecoder.unpackM1(inputPtr, outputPtr, 0); - - debug(3, "UnpackM1 returned: %d", unPackLen); - - if (unPackLen == 0) { //Unpack returned 0: file was probably not packed. - if (_fixedDest == NULL) - free(_compDest); + debug(3, "UnpackM1 returned: %d", unpackLen); - return _fileDest; - } - - if (! (uint8)(_fileFlags >> (22) & 0x1) ) { // include header? - unPackLen += sizeof(struct dataFileHeader); + if (unpackLen == 0) { //Unpack returned 0: file was probably not packed. + free(uncompDest); + return fileDest; + } else { + if (unpackLen != (int32)decompSize) + debug(1, "ERROR: invalid decomp size! (was: %d, should be: %d)", unpackLen, decompSize); + _lastLoadedFileSize = decompSize; - if (unPackLen != (int32)_decompSize) { - debug(1, "ERROR: invalid decomp size! (was: %d, should be: %d)", unPackLen, _decompSize); - } + free(fileDest); + return uncompDest; } - - _lastLoadedFileSize = _decompSize; //including header - - if (_fixedDest == NULL) - free(_fileDest); } else { #ifdef SCUMM_BIG_ENDIAN if (!cflag) { - warning("patching header for uncompressed file %d", fileNr); - uint16 *headPtr = (uint16 *)_fileDest; + uint16 *headPtr = (uint16 *)fileDest; for (uint i = 0; i < sizeof(struct dataFileHeader) / 2; i++) *(headPtr + i) = READ_LE_UINT16(headPtr + i); } #endif - return _fileDest; + return fileDest; } - - return _compDest; } void Disk::prefetchFile(uint16 fileNr) { @@ -230,14 +200,15 @@ void Disk::prefetchFile(uint16 fileNr) { PrefFile **fEntry = &_prefRoot; bool found = false; while (*fEntry) { - if ((*fEntry)->fileNr == fileNr) found = true; + if ((*fEntry)->fileNr == fileNr) + found = true; fEntry = &((*fEntry)->next); } if (found) { debug(1,"Disk::prefetchFile: File %d was already prefetched",fileNr); return ; } - uint8 *temp = loadFile(fileNr, NULL); + uint8 *temp = loadFile(fileNr); *fEntry = new PrefFile; (*fEntry)->data = temp; (*fEntry)->fileSize = _lastLoadedFileSize; @@ -250,8 +221,10 @@ uint8 *Disk::givePrefetched(uint16 fileNr, uint32 *fSize) { PrefFile **fEntry = &_prefRoot; bool found = false; while ((*fEntry) && (!found)) { - if ((*fEntry)->fileNr == fileNr) found = true; - else fEntry = &((*fEntry)->next); + if ((*fEntry)->fileNr == fileNr) + found = true; + else + fEntry = &((*fEntry)->next); } if (!found) { *fSize = 0; @@ -315,8 +288,10 @@ void Disk::fnCacheFiles(void) { bCnt = 0; found = false; while (_buildList[bCnt] && (!found)) { - if ((_buildList[bCnt] & 0x7FFFU) == _loadedFilesList[lCnt]) found = true; - else bCnt++; + if ((_buildList[bCnt] & 0x7FFFU) == _loadedFilesList[lCnt]) + found = true; + else + bCnt++; } if (found) { _loadedFilesList[targCnt] = _loadedFilesList[lCnt]; @@ -338,7 +313,8 @@ void Disk::fnCacheFiles(void) { lCnt = 0; found = false; while (_loadedFilesList[lCnt] && (!found)) { - if (_loadedFilesList[lCnt] == (_buildList[bCnt] & 0x7FFFU)) found = true; + if (_loadedFilesList[lCnt] == (_buildList[bCnt] & 0x7FFFU)) + found = true; lCnt++; } if (found) { @@ -349,7 +325,7 @@ void Disk::fnCacheFiles(void) { _loadedFilesList[targCnt] = _buildList[bCnt] & 0x7FFFU; targCnt++; _loadedFilesList[targCnt] = 0; - SkyEngine::_itemList[_buildList[bCnt] & 2047] = (void**)loadFile(_buildList[bCnt] & 0x7FFF, NULL); + SkyEngine::_itemList[_buildList[bCnt] & 2047] = (void**)loadFile(_buildList[bCnt] & 0x7FFF); if (!SkyEngine::_itemList[_buildList[bCnt] & 2047]) warning("fnCacheFiles: Disk::loadFile() returned NULL for file %d",_buildList[bCnt] & 0x7FFF); bCnt++; @@ -369,7 +345,7 @@ void Disk::refreshFilesList(uint32 *list) { cnt = 0; while (list[cnt]) { _loadedFilesList[cnt] = list[cnt]; - SkyEngine::_itemList[_loadedFilesList[cnt] & 2047] = (void**)loadFile((uint16)(_loadedFilesList[cnt] & 0x7FFF), NULL); + SkyEngine::_itemList[_loadedFilesList[cnt] & 2047] = (void**)loadFile((uint16)(_loadedFilesList[cnt] & 0x7FFF)); cnt++; } _loadedFilesList[cnt] = 0; @@ -379,12 +355,13 @@ void Disk::fnMiniLoad(uint16 fileNum) { uint16 cnt = 0; while (_loadedFilesList[cnt]) { - if (_loadedFilesList[cnt] == fileNum) return ; + if (_loadedFilesList[cnt] == fileNum) + return ; cnt++; } _loadedFilesList[cnt] = fileNum & 0x7FFFU; _loadedFilesList[cnt + 1] = 0; - SkyEngine::_itemList[fileNum & 2047] = (void**)loadFile(fileNum, NULL); + SkyEngine::_itemList[fileNum & 2047] = (void**)loadFile(fileNum); } void Disk::fnFlushBuffers(void) { @@ -404,7 +381,7 @@ void Disk::dumpFile(uint16 fileNr) { File out; byte* filePtr; - filePtr = loadFile(fileNr, NULL); + filePtr = loadFile(fileNr); sprintf(buf, "dumps/file-%d.dmp", fileNr); out.open(buf, File::kFileReadMode, ""); @@ -435,8 +412,10 @@ uint32 Disk::determineGameVersion() { return 303; case 1445: //floppy (v0.0331 or v0.0348) - if (_dataDiskHandle->size() == 8830435) return 348; - else return 331; + if (_dataDiskHandle->size() == 8830435) + return 348; + else + return 331; case 1711: //cd demo (v0.0365) return 365; diff --git a/sky/disk.h b/sky/disk.h index 584a9f3b45..fe02b1eb82 100644 --- a/sky/disk.h +++ b/sky/disk.h @@ -44,7 +44,7 @@ public: Disk(const Common::String &gameDataPath); ~Disk(void); - uint8 *loadFile(uint16 fileNr, uint8 *dest); + uint8 *loadFile(uint16 fileNr); bool fileExists(uint16 fileNr); void prefetchFile(uint16 fileNr); @@ -71,13 +71,12 @@ protected: void dumpFile(uint16 fileNr); uint32 _dinnerTableEntries; + uint8 *_dinnerTableArea; + File *_dataDiskHandle; + File *_dnrHandle; - uint8 *_dinnerTableArea, *_fixedDest, *_fileDest, *_compDest; - uint32 _fileFlags, _fileOffset, _fileSize, _decompSize, _compFile; uint16 _buildList[MAX_FILES_IN_LIST]; uint32 _loadedFilesList[MAX_FILES_IN_LIST]; - File *_dataDiskHandle; - File *_dnrHandle; }; } // End of namespace Sky diff --git a/sky/grid.cpp b/sky/grid.cpp index 77dc4c82bc..8967eeabe8 100644 --- a/sky/grid.cpp +++ b/sky/grid.cpp @@ -130,21 +130,24 @@ int8 Grid::_gridConvertTable[] = { }; Grid::Grid(Disk *pDisk) { - - _gameGrids = (uint8 *)malloc(TOT_NO_GRIDS * GRID_SIZE); + for (int cnt = 0; cnt < TOT_NO_GRIDS; cnt++) + _gameGrids[cnt] = NULL; _skyDisk = pDisk; } Grid::~Grid(void) { - - free(_gameGrids); + for (uint8 cnt = 0; cnt < TOT_NO_GRIDS; cnt++) + if (_gameGrids[cnt]) + free(_gameGrids[cnt]); } void Grid::loadGrids(void) { - // no endian conversion necessary as I'm using uint8* instead of uint32* - for (uint8 cnt = 0; cnt < TOT_NO_GRIDS; cnt++) - _skyDisk->loadFile(GRID_FILE_START + cnt, _gameGrids + (cnt * GRID_SIZE)); + for (uint8 cnt = 0; cnt < TOT_NO_GRIDS; cnt++) { + if (_gameGrids[cnt]) + free(_gameGrids[cnt]); + _gameGrids[cnt] = _skyDisk->loadFile(GRID_FILE_START + cnt); + } if (!SkyEngine::isDemo()) { // single disk demos never get that far // Reloading the grids can sometimes cause problems eg when reichs door is // open the door grid bit gets replaced so you can't get back in (or out) @@ -153,25 +156,26 @@ void Grid::loadGrids(void) { } } -bool Grid::getGridValues(Compact *cpt, uint32 *resBitNum, uint32 *resWidth) { - +bool Grid::getGridValues(Compact *cpt, uint8 *resGrid, uint32 *resBitNum, uint32 *resWidth) { uint16 width = SkyCompact::getMegaSet(cpt, cpt->extCompact->megaSet)->gridWidth; - return getGridValues(cpt->xcood, cpt->ycood, width, cpt, resBitNum, resWidth); + return getGridValues(cpt->xcood, cpt->ycood, width, cpt, resGrid, resBitNum, resWidth); } -bool Grid::getGridValues(uint32 x, uint32 y, uint32 width, Compact *cpt, uint32 *resBitNum, uint32 *resWidth) { - +bool Grid::getGridValues(uint32 x, uint32 y, uint32 width, Compact *cpt, uint8 *resGrid, uint32 *resBitNum, uint32 *resWidth) { uint32 bitPos; - if (y < TOP_LEFT_Y) return false; // off screen + if (y < TOP_LEFT_Y) + return false; // off screen y -= TOP_LEFT_Y; y >>= 3; // convert to blocks - if (y >= GAME_SCREEN_HEIGHT >> 3) return false; // off screen + if (y >= GAME_SCREEN_HEIGHT >> 3) + return false; // off screen bitPos = y * 40; width++; x >>= 3; // convert to blocks if (x < (TOP_LEFT_X >> 3)) { // at least partially off screen - if (x + width < (TOP_LEFT_X >> 3)) return false; // completely off screen + if (x + width < (TOP_LEFT_X >> 3)) + return false; // completely off screen else { width -= (TOP_LEFT_X >> 3) - x; x = 0; @@ -179,13 +183,15 @@ bool Grid::getGridValues(uint32 x, uint32 y, uint32 width, Compact *cpt, uint32 } else x -= TOP_LEFT_X >> 3; - if ((GAME_SCREEN_WIDTH >> 3) <= x) return false; // off screen + if ((GAME_SCREEN_WIDTH >> 3) <= x) + return false; // off screen if ((GAME_SCREEN_WIDTH >> 3) < x + width) // partially off screen width = (GAME_SCREEN_WIDTH >> 3) - x; bitPos += x; - int32 screenGridOfs = _gridConvertTable[cpt->screen] * GRID_SIZE; - bitPos += (screenGridOfs << 3); // convert to bits + assert((_gridConvertTable[cpt->screen] >= 0) && (_gridConvertTable[cpt->screen] < TOT_NO_GRIDS)); + *resGrid = (uint8)_gridConvertTable[cpt->screen]; + uint32 tmpBits = 0x1F - (bitPos&0x1F); bitPos &= ~0x1F; // divide into dword address and bit number bitPos += tmpBits; @@ -195,56 +201,56 @@ bool Grid::getGridValues(uint32 x, uint32 y, uint32 width, Compact *cpt, uint32 } void Grid::removeObjectFromWalk(Compact *cpt) { - uint32 bitNum, width; - if (getGridValues(cpt, &bitNum, &width)) - removeObjectFromWalk(bitNum, width); + uint8 gridIdx; + if (getGridValues(cpt, &gridIdx, &bitNum, &width)) + removeObjectFromWalk(gridIdx, bitNum, width); } -void Grid::removeObjectFromWalk(uint32 bitNum, uint32 width) { - +void Grid::removeObjectFromWalk(uint8 gridIdx, uint32 bitNum, uint32 width) { for (uint32 cnt = 0; cnt < width; cnt++) { - _gameGrids[bitNum >> 3] &= ~(1 << (bitNum & 0x7)); + _gameGrids[gridIdx][bitNum >> 3] &= ~(1 << (bitNum & 0x7)); if ((bitNum & 0x1F) == 0) bitNum += 0x3F; - else bitNum--; + else + bitNum--; } } void Grid::objectToWalk(Compact *cpt) { - uint32 bitNum, width; - if (getGridValues(cpt, &bitNum, &width)) - objectToWalk(bitNum, width); + uint8 gridIdx; + if (getGridValues(cpt, &gridIdx, &bitNum, &width)) + objectToWalk(gridIdx, bitNum, width); } -void Grid::objectToWalk(uint32 bitNum, uint32 width) { - +void Grid::objectToWalk(uint8 gridIdx, uint32 bitNum, uint32 width) { for (uint32 cnt = 0; cnt < width; cnt++) { - _gameGrids[bitNum >> 3] |= (1 << (bitNum & 0x7)); + _gameGrids[gridIdx][bitNum >> 3] |= (1 << (bitNum & 0x7)); if ((bitNum & 0x1F) == 0) bitNum += 0x3F; - else bitNum--; + else + bitNum--; } } void Grid::plotGrid(uint32 x, uint32 y, uint32 width, Compact *cpt) { - uint32 resBitPos, resWidth; - if (getGridValues(x, y, width-1, cpt, &resBitPos, &resWidth)) - objectToWalk(resBitPos, resWidth); + uint8 resGridIdx; + if (getGridValues(x, y, width-1, cpt, &resGridIdx, &resBitPos, &resWidth)) + objectToWalk(resGridIdx, resBitPos, resWidth); } void Grid::removeGrid(uint32 x, uint32 y, uint32 width, Compact *cpt) { - uint32 resBitPos, resWidth; - if (getGridValues(x, y, width, cpt, &resBitPos, &resWidth)) - removeObjectFromWalk(resBitPos, resWidth); + uint8 resGridIdx; + if (getGridValues(x, y, width, cpt, &resGridIdx, &resBitPos, &resWidth)) + removeObjectFromWalk(resGridIdx, resBitPos, resWidth); } -uint8 *Grid::giveGrid(uint32 pScreen) -{ - return _gameGrids + GRID_SIZE * _gridConvertTable[pScreen]; +uint8 *Grid::giveGrid(uint32 pScreen) { + assert((_gridConvertTable[pScreen] >= 0) && (_gridConvertTable[pScreen] < TOT_NO_GRIDS)); + return _gameGrids[_gridConvertTable[pScreen]]; } } // End of namespace Sky diff --git a/sky/grid.h b/sky/grid.h index 9fd8206357..fd837c0776 100644 --- a/sky/grid.h +++ b/sky/grid.h @@ -37,12 +37,8 @@ public: // grid.asm routines void loadGrids(void); - bool getGridValues(Compact *cpt, uint32 *resBitNum, uint32 *resWidth); - bool getGridValues(uint32 x, uint32 y, uint32 width, Compact *cpt, uint32 *resBitNum, uint32 *resWidth); void removeObjectFromWalk(Compact *cpt); - void removeObjectFromWalk(uint32 bitNum, uint32 width); void objectToWalk(Compact *cpt); - void objectToWalk(uint32 bitNum, uint32 width); // function.asm // note that this routine does the same as objectToWalk, it just doesn't get @@ -50,12 +46,16 @@ public: void plotGrid(uint32 x, uint32 y, uint32 width, Compact *cpt); // same here, it's basically the same as removeObjectFromWalk void removeGrid(uint32 x, uint32 y, uint32 width, Compact *cpt); - // note that this function actually returns the byte after the end of the requested grid uint8 *giveGrid(uint32 pScreen); private: + void objectToWalk(uint8 gridIdx, uint32 bitNum, uint32 width); + void removeObjectFromWalk(uint8 gridIdx, uint32 bitNum, uint32 width); + bool getGridValues(Compact *cpt, uint8 *resGrid, uint32 *resBitNum, uint32 *resWidth); + bool getGridValues(uint32 x, uint32 y, uint32 width, Compact *cpt, uint8 *resGrid, uint32 *resBitNum, uint32 *resWidth); + static int8 _gridConvertTable[]; - uint8 *_gameGrids; + uint8 *_gameGrids[TOT_NO_GRIDS]; Disk *_skyDisk; }; diff --git a/sky/intro.cpp b/sky/intro.cpp index 8a7b0c1630..5b412a7bc0 100644 --- a/sky/intro.cpp +++ b/sky/intro.cpp @@ -725,7 +725,7 @@ bool Intro::nextPart(uint16 *&data) { case PLAYVOICE: if (!escDelay(200)) return false; - vData = _skyDisk->loadFile(*data++, NULL); + vData = _skyDisk->loadFile(*data++); // HACK: Fill the header with silence. We should // probably use _skySound instead of calling playRaw() // directly, but this will have to do for now. @@ -742,7 +742,7 @@ bool Intro::nextPart(uint16 *&data) { _mixer->stopID(SOUND_BG); if (_bgBuf) free(_bgBuf); - _bgBuf = _skyDisk->loadFile(*data++, NULL); + _bgBuf = _skyDisk->loadFile(*data++); _bgSize = _skyDisk->_lastLoadedFileSize; return true; case LOOPBG: @@ -770,8 +770,8 @@ bool Intro::floppyScrollFlirt(void) { memset(scrollScreen, 0, FRAME_SIZE); memcpy(scrollScreen + FRAME_SIZE, _skyScreen->giveCurrent(), FRAME_SIZE); uint8 *scrollPos = scrollScreen + FRAME_SIZE; - uint8 *vgaData = _skyDisk->loadFile(60100, NULL); - uint8 *diffData = _skyDisk->loadFile(60101, NULL); + uint8 *vgaData = _skyDisk->loadFile(60100); + uint8 *diffData = _skyDisk->loadFile(60101); uint16 frameNum = READ_LE_UINT16(diffData); uint8 *diffPtr = diffData + 2; uint8 *vgaPtr = vgaData; diff --git a/sky/logic.cpp b/sky/logic.cpp index e10a155ad7..c3608a142a 100644 --- a/sky/logic.cpp +++ b/sky/logic.cpp @@ -788,7 +788,7 @@ void Logic::stopAndWait() { void Logic::checkModuleLoaded(uint16 moduleNo) { if (!_moduleList[moduleNo]) - _moduleList[moduleNo] = (uint16 *)_skyDisk->loadFile((uint16)moduleNo + F_MODULE_0, NULL); + _moduleList[moduleNo] = (uint16 *)_skyDisk->loadFile((uint16)moduleNo + F_MODULE_0); } void Logic::push(uint32 a) { @@ -1191,7 +1191,7 @@ script: uint16 *scriptData = _moduleList[moduleNo]; // get module address if (!scriptData) { // The module has not been loaded - scriptData = (uint16 *)_skyDisk->loadFile(moduleNo + F_MODULE_0, NULL); + scriptData = (uint16 *)_skyDisk->loadFile(moduleNo + F_MODULE_0); _moduleList[moduleNo] = scriptData; // module has been loaded } diff --git a/sky/mouse.cpp b/sky/mouse.cpp index bc84bcc5b3..e4a8cc2c4e 100644 --- a/sky/mouse.cpp +++ b/sky/mouse.cpp @@ -94,10 +94,10 @@ Mouse::Mouse(OSystem *system, Disk *skyDisk) { _mouseX = GAME_SCREEN_WIDTH / 2; _mouseY = GAME_SCREEN_HEIGHT / 2; - _miceData = _skyDisk->loadFile(MICE_FILE, NULL); + _miceData = _skyDisk->loadFile(MICE_FILE); //load in the object mouse file - _objectMouseData = _skyDisk->loadFile(MICE_FILE + 1, NULL); + _objectMouseData = _skyDisk->loadFile(MICE_FILE + 1); } Mouse::~Mouse( ){ @@ -106,7 +106,8 @@ Mouse::~Mouse( ){ } void Mouse::replaceMouseCursors(uint16 fileNo) { - _skyDisk->loadFile(fileNo, _objectMouseData); + free(_objectMouseData); + _objectMouseData = _skyDisk->loadFile(fileNo); } bool Mouse::fnAddHuman(void) { @@ -188,8 +189,10 @@ void Mouse::spriteMouse(uint16 frameNum, uint8 mouseX, uint8 mouseY) { uint16 mouseHeight = ((struct dataFileHeader *)_miceData)->s_height; _system->setMouseCursor(newCursor, mouseWidth, mouseHeight, mouseX, mouseY, 0); - if (frameNum == MOUSE_BLANK) _system->showMouse(false); - else _system->showMouse(true); + if (frameNum == MOUSE_BLANK) + _system->showMouse(false); + else + _system->showMouse(true); } void Mouse::mouseEngine(uint16 mouseX, uint16 mouseY) { diff --git a/sky/music/musicbase.cpp b/sky/music/musicbase.cpp index da94653e88..f21f96a200 100644 --- a/sky/music/musicbase.cpp +++ b/sky/music/musicbase.cpp @@ -51,7 +51,7 @@ void MusicBase::loadSection(uint8 pSection) { if (_musicData) free(_musicData); _currentSection = pSection; - _musicData = _skyDisk->loadFile(_driverFileBase + FILES_PER_SECTION * pSection, NULL); + _musicData = _skyDisk->loadFile(_driverFileBase + FILES_PER_SECTION * pSection); _allowedCommands = 0; _musicTempo0 = 0x78; // init constants taken from idb file, area ~0x1060 _musicTempo1 = 0xC0; diff --git a/sky/screen.cpp b/sky/screen.cpp index cb1d2f9583..60274d39d2 100644 --- a/sky/screen.cpp +++ b/sky/screen.cpp @@ -133,7 +133,7 @@ void Screen::halvePalette(void) { void Screen::setPalette(uint16 fileNum) { - uint8 *tmpPal = _skyDisk->loadFile(fileNum, NULL); + uint8 *tmpPal = _skyDisk->loadFile(fileNum); if (tmpPal) { setPalette(tmpPal); free(tmpPal); @@ -143,7 +143,7 @@ void Screen::setPalette(uint16 fileNum) { void Screen::showScreen(uint16 fileNum) { if (_currentScreen) free(_currentScreen); - _currentScreen = _skyDisk->loadFile(fileNum, NULL); + _currentScreen = _skyDisk->loadFile(fileNum); if (_currentScreen) showScreen(_currentScreen); else warning("Screen::showScreen: can't load file nr. %d",fileNum); @@ -281,7 +281,7 @@ void Screen::palette_fadedown_helper(uint32 *pal, uint num) { void Screen::paletteFadeUp(uint16 fileNr) { - uint8 *pal = _skyDisk->loadFile(fileNr, NULL); + uint8 *pal = _skyDisk->loadFile(fileNr); if (pal) { paletteFadeUp(pal); free(pal); @@ -401,7 +401,7 @@ void Screen::handleTimer(void) { void Screen::startSequence(uint16 fileNum) { - _seqInfo.seqData = _skyDisk->loadFile(fileNum, NULL); + _seqInfo.seqData = _skyDisk->loadFile(fileNum); _seqInfo.framesLeft = _seqInfo.seqData[0]; _seqInfo.seqDataPos = _seqInfo.seqData + 1; _seqInfo.delay = SEQ_DELAY; diff --git a/sky/sky.cpp b/sky/sky.cpp index 0252575388..4536ac5958 100644 --- a/sky/sky.cpp +++ b/sky/sky.cpp @@ -247,8 +247,10 @@ void SkyEngine::go() { if (!_skyLogic->checkProtection()) { // don't let copy prot. screen flash up _skyScreen->recreate(); _skyScreen->spriteEngine(); - if (_debugger->showGrid()) + if (_debugger->showGrid()) { _skyScreen->showGrid(_skyLogic->_skyGrid->giveGrid(Logic::_scriptVariables[SCREEN])); + _skyScreen->forceRefresh(); + } _skyScreen->flip(); } } @@ -394,24 +396,24 @@ void SkyEngine::loadBase0(void) { void SkyEngine::loadFixedItems(void) { if (!isDemo()) - _itemList[36] = (void **)_skyDisk->loadFile(36, NULL); + _itemList[36] = (void **)_skyDisk->loadFile(36); - _itemList[49] = (void **)_skyDisk->loadFile(49, NULL); - _itemList[50] = (void **)_skyDisk->loadFile(50, NULL); - _itemList[73] = (void **)_skyDisk->loadFile(73, NULL); - _itemList[262] = (void **)_skyDisk->loadFile(262, NULL); + _itemList[49] = (void **)_skyDisk->loadFile(49); + _itemList[50] = (void **)_skyDisk->loadFile(50); + _itemList[73] = (void **)_skyDisk->loadFile(73); + _itemList[262] = (void **)_skyDisk->loadFile(262); if (isDemo()) return; - _itemList[263] = (void **)_skyDisk->loadFile(263, NULL); - _itemList[264] = (void **)_skyDisk->loadFile(264, NULL); - _itemList[265] = (void **)_skyDisk->loadFile(265, NULL); - _itemList[266] = (void **)_skyDisk->loadFile(266, NULL); - _itemList[267] = (void **)_skyDisk->loadFile(267, NULL); - _itemList[269] = (void **)_skyDisk->loadFile(269, NULL); - _itemList[271] = (void **)_skyDisk->loadFile(271, NULL); - _itemList[272] = (void **)_skyDisk->loadFile(272, NULL); + _itemList[263] = (void **)_skyDisk->loadFile(263); + _itemList[264] = (void **)_skyDisk->loadFile(264); + _itemList[265] = (void **)_skyDisk->loadFile(265); + _itemList[266] = (void **)_skyDisk->loadFile(266); + _itemList[267] = (void **)_skyDisk->loadFile(267); + _itemList[269] = (void **)_skyDisk->loadFile(269); + _itemList[271] = (void **)_skyDisk->loadFile(271); + _itemList[272] = (void **)_skyDisk->loadFile(272); } diff --git a/sky/sound.cpp b/sky/sound.cpp index da6c8ad50d..b25e4c2400 100644 --- a/sky/sound.cpp +++ b/sky/sound.cpp @@ -1049,7 +1049,7 @@ void Sound::loadSection(uint8 pSection) { _mixer->stopAll(); if (_soundData) free(_soundData); - _soundData = _skyDisk->loadFile(pSection * 4 + SOUND_FILE_BASE, NULL); + _soundData = _skyDisk->loadFile(pSection * 4 + SOUND_FILE_BASE); uint16 asmOfs; if (SkyEngine::_systemVars.gameVersion == 109) { if (pSection == 0) @@ -1219,7 +1219,7 @@ bool Sound::startSpeech(uint16 textNum) { return false; uint16 speechFileNum = _speechConvertTable[textNum >> 12] + (textNum & 0xFFF); - uint8 *speechData = _skyDisk->loadFile(speechFileNum + 50000, NULL); + uint8 *speechData = _skyDisk->loadFile(speechFileNum + 50000); if (!speechData) { debug(9,"File %d (speechFile %d from section %d) wasn't found", speechFileNum + 50000, textNum & 0xFFF, textNum >> 12); return false; diff --git a/sky/text.cpp b/sky/text.cpp index 3bbab50a5d..b916019533 100644 --- a/sky/text.cpp +++ b/sky/text.cpp @@ -41,18 +41,18 @@ Text::Text(Disk *skyDisk) { initHuffTree(); - _mainCharacterSet.addr = _skyDisk->loadFile(CHAR_SET_FILE, NULL); + _mainCharacterSet.addr = _skyDisk->loadFile(CHAR_SET_FILE); _mainCharacterSet.charHeight = MAIN_CHAR_HEIGHT; _mainCharacterSet.charSpacing = 0; fnSetFont(0); if (!SkyEngine::isDemo()) { - _controlCharacterSet.addr = _skyDisk->loadFile(60520, NULL); + _controlCharacterSet.addr = _skyDisk->loadFile(60520); _controlCharacterSet.charHeight = 12; _controlCharacterSet.charSpacing = 0; - _linkCharacterSet.addr = _skyDisk->loadFile(60521, NULL); + _linkCharacterSet.addr = _skyDisk->loadFile(60521); _linkCharacterSet.charHeight = 12; _linkCharacterSet.charSpacing = 1; @@ -63,7 +63,7 @@ Text::Text(Disk *skyDisk) { } if (SkyEngine::isCDVersion()) { - _preAfterTableArea = _skyDisk->loadFile(60522, NULL); + _preAfterTableArea = _skyDisk->loadFile(60522); } else _preAfterTableArea = NULL; } @@ -267,7 +267,7 @@ void Text::getText(uint32 textNr) { //load text #"textNr" into textBuffer debug(5, "Loading Text item(s) for Section %d", (sectionNo>>2)); uint32 fileNo = sectionNo + ((SkyEngine::_systemVars.language * NO_OF_TEXT_SECTIONS) + 60600); - SkyEngine::_itemList[FIRST_TEXT_SEC + sectionNo] = (void **)_skyDisk->loadFile((uint16)fileNo, NULL); + SkyEngine::_itemList[FIRST_TEXT_SEC + sectionNo] = (void **)_skyDisk->loadFile((uint16)fileNo); } _textItemPtr = (uint8 *)SkyEngine::_itemList[FIRST_TEXT_SEC + sectionNo]; |