diff options
| -rw-r--r-- | sky/disk.cpp | 81 | ||||
| -rw-r--r-- | sky/disk.h | 19 | ||||
| -rw-r--r-- | sky/intro.cpp | 3 | ||||
| -rw-r--r-- | sky/logic.cpp | 47 | 
4 files changed, 34 insertions, 116 deletions
| diff --git a/sky/disk.cpp b/sky/disk.cpp index ba5930a959..a14b94b341 100644 --- a/sky/disk.cpp +++ b/sky/disk.cpp @@ -34,13 +34,9 @@ static const char *dataFilename = "sky.dsk";  static const char *dinnerFilename = "sky.dnr";  Disk::Disk(const Common::String &gameDataPath) { -	_prefRoot = NULL; -  	_dataDiskHandle = new Common::File();  	_dnrHandle = new Common::File(); -	uint32 entriesRead; -  	_dnrHandle->open(dinnerFilename);  	if (!_dnrHandle->isOpen())  		error("Could not open %s%s", gameDataPath.c_str(), dinnerFilename); @@ -49,10 +45,10 @@ Disk::Disk(const Common::String &gameDataPath) {  		error("Error reading from sky.dnr"); //even though it was opened correctly?!  	_dinnerTableArea = (uint8 *)malloc(_dinnerTableEntries * 8); -	entriesRead = _dnrHandle->read(_dinnerTableArea, 8 * _dinnerTableEntries) / 8; +	uint32 entriesRead = _dnrHandle->read(_dinnerTableArea, 8 * _dinnerTableEntries) / 8;  	if (entriesRead != _dinnerTableEntries) -		warning("entriesRead != dinnerTableEntries. [%d/%d]", entriesRead, _dinnerTableEntries); +		error("entriesRead != dinnerTableEntries. [%d/%d]", entriesRead, _dinnerTableEntries);  	_dataDiskHandle->open(dataFilename);  	if (!_dataDiskHandle->isOpen()) @@ -65,14 +61,6 @@ Disk::Disk(const Common::String &gameDataPath) {  }  Disk::~Disk(void) { - -	PrefFile *fEntry = _prefRoot; -	while (fEntry) { -		free(fEntry->data); -		PrefFile *fTemp = fEntry; -		fEntry = fEntry->next; -		delete fTemp; -	}  	if (_dnrHandle->isOpen())  		_dnrHandle->close();  	if (_dataDiskHandle->isOpen()) @@ -83,20 +71,7 @@ Disk::~Disk(void) {  	delete _dataDiskHandle;  } -void Disk::flushPrefetched(void) { - -	PrefFile *fEntry = _prefRoot; -	while (fEntry) { -		free(fEntry->data); -		PrefFile *fTemp = fEntry; -		fEntry = fEntry->next; -		delete fTemp; -	} -	_prefRoot = NULL; -} -  bool Disk::fileExists(uint16 fileNr) { -  	return (getFileInfo(fileNr) != NULL);  } @@ -105,10 +80,6 @@ uint8 *Disk::loadFile(uint16 fileNr) {  	uint8 cflag; -	uint8 *prefData = givePrefetched(fileNr, &_lastLoadedFileSize); -	if (prefData) -		return prefData; -  	debug(2, "load file %d,%d (%d)", (fileNr >> 11), (fileNr & 2047), fileNr);  	uint8 *fileInfoPtr = getFileInfo(fileNr); @@ -202,47 +173,13 @@ uint8 *Disk::loadFile(uint16 fileNr) {  	}  } -void Disk::prefetchFile(uint16 fileNr) { - -	PrefFile **fEntry = &_prefRoot; -	bool found = false; -	while (*fEntry) { -		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); -	*fEntry = new PrefFile; -	(*fEntry)->data = temp; -	(*fEntry)->fileSize = _lastLoadedFileSize; -	(*fEntry)->fileNr = fileNr; -	(*fEntry)->next = NULL; -} - -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 (!found) { -		*fSize = 0; -		return NULL; -	} -	uint8 *retPtr = (*fEntry)->data; -	PrefFile *retStr = *fEntry; -	*fEntry = (*fEntry)->next; -	*fSize = retStr->fileSize; -	delete retStr; -	return retPtr; +uint16 *Disk::loadScriptFile(uint16 fileNr) { +	uint16 *buf = (uint16*)loadFile(fileNr); +#ifdef SCUMM_BIG_ENDIAN +	for (int i = 0; i < _lastLoadedFileSize / 2; i++) +		buf[i] = FROM_LE_16(buf[i]); +#endif +	return buf;  }  uint8 *Disk::getFileInfo(uint16 fileNr) { diff --git a/sky/disk.h b/sky/disk.h index b8b0d74d1b..b132080bca 100644 --- a/sky/disk.h +++ b/sky/disk.h @@ -27,32 +27,23 @@  #include "common/str.h"  #include "sky/rnc_deco.h" +#define MAX_FILES_IN_LIST 60 +  namespace Common {  	class File;  }  namespace Sky { -#define MAX_FILES_IN_LIST 60 - -struct PrefFile { -	uint8 *data; -	uint16 fileNr; -	uint32 fileSize; -	PrefFile *next; -}; -  class Disk {  public:  	Disk(const Common::String &gameDataPath);  	~Disk(void);  	uint8 *loadFile(uint16 fileNr); +	uint16 *loadScriptFile(uint16 fileNr);  	bool fileExists(uint16 fileNr); -	void prefetchFile(uint16 fileNr); -	void flushPrefetched(void); -  	uint32 determineGameVersion();  	uint32 _lastLoadedFileSize; @@ -66,10 +57,6 @@ public:  	void refreshFilesList(uint32 *list);  protected: - -	PrefFile *_prefRoot; -	uint8 *givePrefetched(uint16 fileNr, uint32 *fSize); -  	uint8 *getFileInfo(uint16 fileNr);  	void dumpFile(uint16 fileNr); diff --git a/sky/intro.cpp b/sky/intro.cpp index f271545933..02b3050fc0 100644 --- a/sky/intro.cpp +++ b/sky/intro.cpp @@ -639,7 +639,6 @@ Intro::Intro(Disk *disk, Screen *screen, MusicBase *music, Sound *sound, Text *t  Intro::~Intro(void) {  	_mixer->stopAll(); -	_skyDisk->flushPrefetched();  	_skyScreen->stopSequence();  	if (_textBuf)  		free(_textBuf); @@ -654,8 +653,6 @@ bool Intro::doIntro(bool floppyIntro) {  	if (!SkyEngine::isCDVersion())  		floppyIntro = true; -	_skyDisk->prefetchFile(60112); -	_skyDisk->prefetchFile(60113);  	_skyMusic->loadSection(0);  	_skySound->loadSection(0); diff --git a/sky/logic.cpp b/sky/logic.cpp index f8ae36e1d1..f88e5d233d 100644 --- a/sky/logic.cpp +++ b/sky/logic.cpp @@ -1217,13 +1217,13 @@ script:  	/// process a script  	/// low level interface to interpreter -	uint16 moduleNo = (uint16)((scriptNo & 0xff00) >> 12); +	uint16 moduleNo = scriptNo >> 12;  	debug(3, "Doing Script %x", (offset << 16) | scriptNo);  	uint16 *scriptData = _moduleList[moduleNo]; // get module address -	if (!scriptData) { // The module has not been loaded -		scriptData = (uint16 *)_skyDisk->loadFile(moduleNo + F_MODULE_0); -		_moduleList[moduleNo] = scriptData; // module has been loaded +	if (!scriptData) { // We need to load the script module +		_moduleList[moduleNo] = _skyDisk->loadScriptFile(moduleNo + F_MODULE_0); +		 scriptData = _moduleList[moduleNo]; // module has been loaded  	}  	uint16 *moduleStart = scriptData; @@ -1232,18 +1232,18 @@ script:  	if (offset)  		scriptData = moduleStart + offset;  	else -		scriptData += READ_LE_UINT16(scriptData + (scriptNo & 0x0fff)); +		scriptData += scriptData[scriptNo & 0x0fff];  	uint32 a = 0, b = 0, c = 0;  	uint16 command, s;  	for (;;) { -		command = READ_LE_UINT16(scriptData++); // get a command +		command = *scriptData++; // get a command  		Debug::script(command, scriptData);  		switch (command) {  		case 0: // push_variable -			push( _scriptVariables[READ_LE_UINT16(scriptData++) / 4] ); +			push( _scriptVariables[*scriptData++ / 4] );  			break;  		case 1: // less_than  			a = pop(); @@ -1254,7 +1254,7 @@ script:  				push(0);  			break;  		case 2: // push_number -			push(READ_LE_UINT16(scriptData++)); +			push(*scriptData++);  			break;  		case 3: // not_equal  			a = pop(); @@ -1273,14 +1273,14 @@ script:  				push(0);  			break;  		case 5: // skip_zero -			s = READ_LE_UINT16(scriptData++); +			s = *scriptData++;  			a = pop();  			if (!a)  				scriptData += s / 2;  			break;  		case 6: // pop_var -			b = _scriptVariables[READ_LE_UINT16(scriptData++) / 4] = pop(); +			b = _scriptVariables[*scriptData++ / 4] = pop();  			break;  		case 7: // minus  			a = pop(); @@ -1293,7 +1293,7 @@ script:  			push(b+a);  			break;  		case 9: // skip_always -			s = READ_LE_UINT16(scriptData++); +			s = *scriptData++;  			scriptData += s / 2;  			break;  		case 10: // if_or @@ -1306,7 +1306,7 @@ script:  			break;  		case 11: // call_mcode  			{ -				a = READ_LE_UINT16(scriptData++); +				a = *scriptData++;  				assert(a <= 3);  				// No, I did not forget the "break"s  				switch (a) { @@ -1318,7 +1318,7 @@ script:  					a = pop();  				} -				uint16 mcode = READ_LE_UINT16(scriptData++)/4; // get mcode number +				uint16 mcode = *scriptData++ / 4; // get mcode number  				Debug::mcode(mcode, a, b, c);  				Compact *saveCpt = _compact; @@ -1338,13 +1338,13 @@ script:  				push(0);  			break;  		case 14: // switch -			c = s = READ_LE_UINT16(scriptData++); // get number of cases +			c = s = *scriptData++; // get number of cases  			a = pop(); // and value to switch on  			do { -				if (a == READ_LE_UINT16(scriptData)) { -					scriptData += READ_LE_UINT16(scriptData + 1) / 2; +				if (a == *scriptData) { +					scriptData += scriptData[1] / 2;  					scriptData++;  					break;  				} @@ -1352,14 +1352,14 @@ script:  			} while (--s);  			if (s == 0) -				scriptData += READ_LE_UINT16(scriptData)/2; // use the default +				scriptData += *scriptData / 2; // use the default  			break;  		case 15: // push_offset -			push( *(uint16 *)_skyCompact->getCompactElem(_compact, READ_LE_UINT16(scriptData++)) ); +			push( *(uint16 *)_skyCompact->getCompactElem(_compact, *scriptData++) );  			break;  		case 16: // pop_offset  			// pop a value into a compact -			*(uint16 *)_skyCompact->getCompactElem(_compact, READ_LE_UINT16(scriptData++)) = (uint16)pop(); +			*(uint16 *)_skyCompact->getCompactElem(_compact, *scriptData++) = (uint16)pop();  			break;  		case 17: // is_equal  			a = pop(); @@ -1370,7 +1370,7 @@ script:  				push(0);  			break;  		case 18: { // skip_nz -				int16 t = READ_LE_UINT16(scriptData++); +				int16 t = *scriptData++;  				a = pop();  				if (a)  					scriptData += t / 2; @@ -1668,7 +1668,6 @@ bool Logic::fnClearStop(uint32 a, uint32 b, uint32 c) {  }  bool Logic::fnPointerText(uint32 a, uint32 b, uint32 c) { -  	_skyText->fnPointerText(a, _skyMouse->giveMouseX(), _skyMouse->giveMouseY());  	return true;  } @@ -2028,11 +2027,11 @@ bool Logic::fnResetId(uint32 id, uint32 resetBlock, uint32 c) {  	uint16 *rst = (uint16 *)_skyCompact->fetchCpt(resetBlock);  	if (!cpt) { -		warning("fnResetId(): Compact %d (id) == NULL",id); +		warning("fnResetId(): Compact %d (id) == NULL", id);  		return true;  	}  	if (!rst) { -		warning("fnResetId(): Compact %d (resetBlock) == NULL",resetBlock); +		warning("fnResetId(): Compact %d (resetBlock) == NULL", resetBlock);  		return true;  	} @@ -2318,13 +2317,11 @@ bool Logic::fnEnterSection(uint32 sectionNo, uint32 b, uint32 c) {  }  bool Logic::fnRestoreGame(uint32 a, uint32 b, uint32 c) { -  	_skyControl->doLoadSavePanel();  	return false;  }  bool Logic::fnRestartGame(uint32 a, uint32 b, uint32 c) { -  	_skyControl->restartGame();  	return false;  } | 
