uint8 Script::readScriptChar(bool allow7C, bool limitVal, bool limitVar) { uint8 result; uint8 data = readScript8bits(); if (limitVal) { data &= 0x7F; } if (allow7C && (data == 0x7C)) { // Index a bidimensional array uint8 parta, partb; parta = readScriptChar(false, false, false); partb = readScriptChar(false, true, true); result = _variables[0x0A * parta + partb + 0x19]; } else if (data == 0x23) { // Index an array data = readScript8bits(); if (limitVar) { data &= 0x7F; } result = _variables[data - 0x61]; } else { // Immediate value result = data - 0x30; } return result; }
void Script::o_strcmpnejmp() { // 0x1A uint16 varnum = readScript8or16bits(); uint8 val; uint8 result = 1; debugScript(1, false, "STRCMP-NEJMP: var[0x%04X..],", varnum); do { val = readScriptChar(true, true, true); if (_variables[varnum] != val) { result = 0; } varnum++; debugScript(1, false, " 0x%02X", val); } while (!(getCodeByte(_currentInstruction - 1) & 0x80)); uint16 address = readScript16bits(); if (!result) { debugScript(1, true, " jumping to @0x%04X", address); _currentInstruction = address; } else { debugScript(1, true, " not jumping"); } }
void Script::o_printstring() { char stringstorage[15], newchar; uint8 counter = 0; debugScript(1, true, "PRINTSTRING"); memset(stringstorage, 0, 15); do { newchar = readScriptChar(true, true, true) + 0x30; if (newchar < 0x30 || newchar > 0x39) { // If character is invalid, chuck a space in if (newchar < 0x41 || newchar > 0x7A) { newchar = 0x20; } } stringstorage[counter] = newchar; counter++; } while (!(getCodeByte(_currentInstruction - 1) & 0x80)); stringstorage[counter] = 0; // Load the font if required if (!_font) { _font = new Font(_vm->_system); } _font->printstring(stringstorage); }
void Script::o_printstring() { char stringstorage[15]; uint8 counter = 0; debugScript(1, true, "PRINTSTRING"); memset(stringstorage, 0, 15); do { char newchar = readScriptChar(true, true, true) + 0x30; if (newchar < 0x30 || newchar > 0x39) { // If character is invalid, chuck a space in if (newchar < 0x41 || newchar > 0x7A) { newchar = 0x20; } } stringstorage[counter] = newchar; counter++; } while (!(getCodeByte(_currentInstruction - 1) & 0x80)); stringstorage[counter] = 0; Common::Rect topbar(640, 80); Graphics::Surface *gamescreen = _vm->_system->lockScreen(); // Clear the top bar gamescreen->fillRect(topbar, 0); // Draw the string printString(gamescreen, stringstorage); _vm->_system->unlockScreen(); }
void Script::o_obscureswap() { uint16 var1, var2, tmp; debugScript(1, true, "OBSCSWAP"); // Read the first variable var1 = readScriptChar(false, true, true) * 10; var1 += readScriptChar(false, true, true) + 0x19; // Read the second variable var2 = readScriptChar(false, true, true) * 10; var2 += readScriptChar(false, true, true) + 0x19; // Swap the values tmp = _variables[var1]; setVariable(var1, _variables[var2]); setVariable(var2, tmp); }
void Script::o_loadstring() { uint16 varnum = readScript8or16bits(); debugScript(1, false, "LOADSTRING var[0x%04X..] =", varnum); do { setVariable(varnum++, readScriptChar(true, true, true)); debugScript(1, false, " 0x%02X", _variables[varnum - 1]); } while (!(getCodeByte(_currentInstruction - 1) & 0x80)); debugScript(1, false, "\n"); }
uint16 Script::getVideoRefString() { Common::String str; byte c; while ((c = readScript8bits())) { switch (c) { case 0x23: c = readScript8bits(); c = _variables[c - 0x61] + 0x30; if (c >= 0x41 && c <= 0x5A) { c += 0x20; } break; case 0x7C: uint8 parta, partb; parta = readScriptChar(false, false, false); partb = readScriptChar(false, false, false); c = _variables[0x0A * parta + partb + 0x19] + 0x30; break; default: if (c >= 0x41 && c <= 0x5A) { c += 0x20; } } // Append the current character at the end of the string str += c; } // Add a trailing dot str += 0x2E; debugScript(0, false, "%s", str.c_str()); // Extract the script name. Common::String scriptname(_scriptFile.c_str(), _scriptFile.size() - 4); // Get the fileref of the resource return _vm->_resMan->getRef(str, scriptname); }
void Script::o_strcmpnejmp_var() { // 0x21 uint16 data = readScriptVar(); if (data > 9) { data -= 7; } data = _variables[data + 0x19]; bool stringsmatch = 1; do { if (_variables[data++] != readScriptChar(true, true, true)) { stringsmatch = 0; } } while (!(getCodeByte(_currentInstruction - 1) & 0x80)); uint16 offset = readScript16bits(); if (!stringsmatch) { _currentInstruction = offset; } }
void Script::o_charlessjmp() { uint16 varnum = readScript8or16bits(); uint8 result = 0; debugScript(1, false, "CHARLESS-JMP: var[0x%04X..],", varnum); do { uint8 val = readScriptChar(true, true, true); if (val > _variables[varnum]) { result = 1; } varnum++; debugScript(1, false, " 0x%02X", val); } while (!(getCodeByte(_currentInstruction - 1) & 0x80)); uint16 address = readScript16bits(); if (result) { debugScript(1, true, " jumping to @0x%04X", address); _currentInstruction = address; } else { debugScript(1, true, " not jumping"); } }