TOLTECS: Cleanup

This commit is contained in:
Filippos Karapetis 2013-01-02 15:04:48 +02:00
parent 3eae0e61e7
commit 765578effe
4 changed files with 65 additions and 120 deletions

View file

@ -138,30 +138,7 @@ void Palette::clearFragments() {
_fragments.clear();
}
void Palette::buildColorTransTable(byte limit, int8 deltaValue, byte mask) {
byte r = 0, g = 0, b = 0;
mask &= 7;
for (int i = 0; i < 256; i++) {
if (deltaValue < 0) {
// TODO (probably unused)
warning("Palette::buildColorTransTable(%d, %d, %02X) not yet implemented!", limit, deltaValue, mask);
} else {
r = _mainPalette[i * 3 + 0];
g = _mainPalette[i * 3 + 1];
b = _mainPalette[i * 3 + 2];
if (MAX(r, MAX(b, g)) >= limit) {
if ((mask & 1) && r >= deltaValue)
r -= deltaValue;
if ((mask & 2) && g >= deltaValue)
g -= deltaValue;
if ((mask & 4) && b >= deltaValue)
b -= deltaValue;
}
}
byte Palette::getMatchingColor(byte r, byte g, byte b) {
int bestIndex = 0;
uint16 bestMatch = 0xFFFF;
@ -175,13 +152,32 @@ void Palette::buildColorTransTable(byte limit, int8 deltaValue, byte mask) {
}
}
_colorTransTable[i] = bestIndex;
}
return bestIndex;
}
void Palette::buildColorTransTable2(byte limit, int8 deltaValue, byte mask) {
// TODO
void Palette::buildColorTransTable(byte limit, int8 deltaValue, byte mask) {
byte r = 0, g = 0, b = 0;
mask &= 7;
if (deltaValue < 0) // unused
error("buildColorTransTable called with a negative delta value(limit %d, delta %d, mask %02X)", limit, deltaValue, mask);
for (int i = 0; i < 256; i++) {
r = _mainPalette[i * 3 + 0];
g = _mainPalette[i * 3 + 1];
b = _mainPalette[i * 3 + 2];
if (MAX(r, MAX(b, g)) >= limit) {
if ((mask & 1) && r >= deltaValue)
r -= deltaValue;
if ((mask & 2) && g >= deltaValue)
g -= deltaValue;
if ((mask & 4) && b >= deltaValue)
b -= deltaValue;
}
_colorTransTable[i] = getMatchingColor(r, g, b);
}
}
void Palette::saveState(Common::WriteStream *out) {

View file

@ -50,8 +50,8 @@ public:
uint16 findFragment(int16 id);
void clearFragments();
byte getMatchingColor(byte r, byte g, byte b);
void buildColorTransTable(byte limit, int8 deltaValue, byte mask);
void buildColorTransTable2(byte limit, int8 deltaValue, byte mask);
byte getColorTransPixel(byte pixel) const { return _colorTransTable[pixel]; }
byte *getMainPalette() { return _mainPalette; }

View file

@ -40,6 +40,22 @@
namespace Toltecs {
static const VarType varTypes[] = {
vtByte, vtWord, vtWord, vtByte, vtWord, // 0 - 4
vtWord, vtWord, vtWord, vtWord, vtWord, // 5 - 9
vtWord, vtWord, vtByte, vtWord, vtWord, // 10 - 14
vtWord, vtWord, vtWord, vtWord, vtWord, // 15 - 19
vtWord, vtWord // 20 - 21
};
static const char *varNames[] = {
"mouseDisabled", "mouseY", "mouseX", "mouseButton", "verbLineY", // 0 - 4
"verbLineX", "verbLineWidth", "verbLineCount", "verbLineNum", "talkTextItemNum", // 5 - 9
"talkTextY", "talkTextX", "talkTextFontColor", "cameraY", "cameraX", // 10 - 14
"walkSpeedY", "walkSpeedX", "flag01", "sceneResIndex", "guiHeight", // 15 - 19
"sceneHeight", "sceneWidth" // 20 - 21
};
ScriptInterpreter::ScriptInterpreter(ToltecsEngine *vm) : _vm(vm) {
_stack = new byte[kScriptStackSize];
@ -247,27 +263,21 @@ void ScriptInterpreter::execOpcode(byte opcode) {
break;
}
case 1:
// ok
_regs.reg0 = readInt16();
break;
case 2:
// ok
_regs.reg1 = readInt16();
break;
case 3:
// ok
_regs.reg3 = readInt16();
break;
case 4:
// ok
_regs.reg5 = _regs.reg0;
break;
case 5:
// ok
_regs.reg3 = _regs.reg0;
break;
case 6:
// ok
_regs.reg1 = _regs.reg0;
break;
case 7:
@ -475,65 +485,8 @@ void ScriptInterpreter::execScriptFunction(uint16 index) {
(*_scriptFuncs[index])();
}
VarType ScriptInterpreter::getGameVarType(uint variable) {
switch (variable) {
case 0: return vtByte;
case 1: return vtWord;
case 2: return vtWord;
case 3: return vtByte;
case 4: return vtWord;
case 5: return vtWord;
case 6: return vtWord;
case 7: return vtWord;
case 8: return vtWord;
case 9: return vtWord;
case 10: return vtWord;
case 11: return vtWord;
case 12: return vtByte;
case 13: return vtWord;
case 14: return vtWord;
case 15: return vtWord;
case 16: return vtWord;
case 17: return vtWord;
case 18: return vtWord;
case 19: return vtWord;
case 20: return vtWord;
case 21: return vtWord;
default:
error("Invalid game variable");
}
}
const char *getVarName(uint variable) {
switch (variable) {
case 0: return "mouseDisabled";
case 1: return "mouseY";
case 2: return "mouseX";
case 3: return "mouseButton";
case 4: return "verbLineY";
case 5: return "verbLineX";
case 6: return "verbLineWidth";
case 7: return "verbLineCount";
case 8: return "verbLineNum";
case 9: return "talkTextItemNum";
case 10: return "talkTextY";
case 11: return "talkTextX";
case 12: return "talkTextFontColor";
case 13: return "cameraY";
case 14: return "cameraX";
case 15: return "walkSpeedY";
case 16: return "walkSpeedX";
case 17: return "flag01";
case 18: return "sceneResIndex";
case 19: return "guiHeight";
case 20: return "sceneHeight";
case 21: return "sceneWidth";
}
return "(invalid)";
}
int16 ScriptInterpreter::getGameVar(uint variable) {
debug(0, "ScriptInterpreter::getGameVar(%d{%s})", variable, getVarName(variable));
debug(0, "ScriptInterpreter::getGameVar(%d{%s})", variable, varNames[variable]);
switch (variable) {
case 0: return _vm->_mouseDisabled;
@ -559,13 +512,13 @@ int16 ScriptInterpreter::getGameVar(uint variable) {
case 20: return _vm->_sceneHeight;
case 21: return _vm->_sceneWidth;
default:
warning("Getting unimplemented game variable %s (%d)", getVarName(variable), variable);
warning("Getting unimplemented game variable %s (%d)", varNames[variable], variable);
return 0;
}
}
void ScriptInterpreter::setGameVar(uint variable, int16 value) {
debug(0, "ScriptInterpreter::setGameVar(%d{%s}, %d)", variable, getVarName(variable), value);
debug(0, "ScriptInterpreter::setGameVar(%d{%s}, %d)", variable, varNames[variable], value);
switch (variable) {
case 0:
@ -632,10 +585,9 @@ void ScriptInterpreter::setGameVar(uint variable, int16 value) {
case 1:
case 2:
default:
warning("Setting unimplemented game variable %s (%d) to %d", getVarName(variable), variable, value);
warning("Setting unimplemented game variable %s (%d) to %d", varNames[variable], variable, value);
break;
}
}
byte ScriptInterpreter::arg8(int16 offset) {
@ -682,7 +634,6 @@ byte *ScriptInterpreter::localPtr(int16 offset) {
}
void ScriptInterpreter::saveState(Common::WriteStream *out) {
// Save registers
out->writeUint16LE(_regs.reg0);
out->writeUint16LE(_regs.reg1);
@ -708,11 +659,9 @@ void ScriptInterpreter::saveState(Common::WriteStream *out) {
// Save IP
out->writeUint16LE((int16)(_code - getSlotData(_regs.reg4)));
}
void ScriptInterpreter::loadState(Common::ReadStream *in) {
// Load registers
_regs.reg0 = in->readUint16LE();
_regs.reg1 = in->readUint16LE();
@ -741,7 +690,6 @@ void ScriptInterpreter::loadState(Common::ReadStream *in) {
// Load IP
_code = getSlotData(_regs.reg4) + in->readUint16LE();
}
void ScriptInterpreter::sfNop() {
@ -755,7 +703,9 @@ void ScriptInterpreter::sfGetGameVar() {
void ScriptInterpreter::sfSetGameVar() {
int16 varIndex = arg16(3);
VarType varType = getGameVarType(varIndex);
assert(varIndex <= 21);
VarType varType = varTypes[varIndex];
int16 value = 0;
if (varType == vtByte)
value = arg8(5);
@ -810,8 +760,7 @@ void ScriptInterpreter::sfSetDeltaAnimPalette() {
}
void ScriptInterpreter::sfSetUnkPaletteEffect() {
// TODO
debug("ScriptInterpreter::sfSetUnkPaletteEffect");
error("ScriptInterpreter::sfSetUnkPaletteEffect called"); // unused
}
void ScriptInterpreter::sfBuildColorTransTable() {
@ -1029,9 +978,8 @@ void ScriptInterpreter::sfHandleInput() {
if (_vm->_rightButtonDown) {
keyCode = 1;
} else {
/* Convert keyboard scancode to IBM PC scancode
Only scancodes known to be used (so far) are converted
*/
// Convert keyboard scancode to IBM PC scancode.
// Only scancodes known to be used (so far) are converted.
switch (_vm->_keyState.keycode) {
case Common::KEYCODE_ESCAPE:
keyCode = 1;
@ -1050,11 +998,13 @@ void ScriptInterpreter::sfRunOptionsScreen() {
_vm->showMenu(kMenuIdMain);
}
/* NOTE: The opcodes sfPrecacheSprites, sfPrecacheSounds1, sfPrecacheSounds2 and
sfDeletePrecachedFiles were used by the original engine to handle precaching
of data so the game doesn't stall while playing (due to the slow speed of
CD-Drives back then). This is not needed in ScummVM since all supported
systems are fast enough to load data in-game. */
/**
* NOTE: The opcodes sfPrecacheSprites, sfPrecacheSounds1, sfPrecacheSounds2 and
* sfDeletePrecachedFiles were used by the original engine to handle precaching
* of data so the game doesn't stall while playing (due to the slow speed of
* CD-Drives back then). This is not needed in ScummVM since all supported
* systems are fast enough to load data in-game.
*/
void ScriptInterpreter::sfPrecacheSprites() {
// See note above

View file

@ -49,7 +49,6 @@ public:
byte *getSlotData(int slotIndex) const { return _slots[slotIndex].data; }
VarType getGameVarType(uint variable);
int16 getGameVar(uint variable);
void setGameVar(uint variable, int16 value);