diff options
| -rw-r--r-- | engines/prince/debugger.cpp | 178 | ||||
| -rw-r--r-- | engines/prince/debugger.h | 3 | ||||
| -rw-r--r-- | engines/prince/prince.cpp | 2 | ||||
| -rw-r--r-- | engines/prince/script.cpp | 136 | ||||
| -rw-r--r-- | engines/prince/script.h | 13 | 
5 files changed, 158 insertions, 174 deletions
diff --git a/engines/prince/debugger.cpp b/engines/prince/debugger.cpp index be9677b99f..449ba5001a 100644 --- a/engines/prince/debugger.cpp +++ b/engines/prince/debugger.cpp @@ -26,130 +26,132 @@  namespace Prince {  Debugger::Debugger(PrinceEngine *vm) : GUI::Debugger(), _vm(vm) { -    DCmd_Register("continue",       WRAP_METHOD(Debugger, Cmd_Exit)); -    DCmd_Register("level",          WRAP_METHOD(Debugger, Cmd_DebugLevel)); -    DCmd_Register("setflag",        WRAP_METHOD(Debugger, Cmd_SetFlag)); -    DCmd_Register("getflag",        WRAP_METHOD(Debugger, Cmd_GetFlag)); -    DCmd_Register("clearflag",      WRAP_METHOD(Debugger, Cmd_ClearFlag)); -    DCmd_Register("viewflc",        WRAP_METHOD(Debugger, Cmd_ViewFlc)); -    DCmd_Register("initroom",       WRAP_METHOD(Debugger, Cmd_InitRoom)); -    DCmd_Register("changecursor",   WRAP_METHOD(Debugger, Cmd_ChangeCursor)); +	DCmd_Register("continue",		WRAP_METHOD(Debugger, Cmd_Exit)); +	DCmd_Register("level",			WRAP_METHOD(Debugger, Cmd_DebugLevel)); +	DCmd_Register("setflag",		WRAP_METHOD(Debugger, Cmd_SetFlag)); +	DCmd_Register("getflag",		WRAP_METHOD(Debugger, Cmd_GetFlag)); +	DCmd_Register("clearflag",		WRAP_METHOD(Debugger, Cmd_ClearFlag)); +	DCmd_Register("viewflc",		WRAP_METHOD(Debugger, Cmd_ViewFlc)); +	DCmd_Register("initroom",		WRAP_METHOD(Debugger, Cmd_InitRoom)); +	DCmd_Register("changecursor",	WRAP_METHOD(Debugger, Cmd_ChangeCursor));  }  static int strToInt(const char *s) { -    if (!*s) -        // No string at all -        return 0; -    else if (toupper(s[strlen(s) - 1]) != 'H') -        // Standard decimal string -        return atoi(s); - -    // Hexadecimal string -    uint tmp = 0; -    int read = sscanf(s, "%xh", &tmp); -    if (read < 1) -        error("strToInt failed on string \"%s\"", s); -    return (int)tmp; +	if (!*s) +		// No string at all +		return 0; +	else if (toupper(s[strlen(s) - 1]) != 'H') +		// Standard decimal string +		return atoi(s); + +	// Hexadecimal string +	uint tmp = 0; +	int read = sscanf(s, "%xh", &tmp); +	if (read < 1) +		error("strToInt failed on string \"%s\"", s); +	return (int)tmp;  }  bool Debugger::Cmd_DebugLevel(int argc, const char **argv) { -    if (argc == 1) { -            DebugPrintf("Debugging is currently set at level %d\n", gDebugLevel); -    } else { // set level -        gDebugLevel = atoi(argv[1]); -        if (0 <= gDebugLevel && gDebugLevel < 11) { -            DebugPrintf("Debug level set to level %d\n", gDebugLevel); -        } else if (gDebugLevel < 0) { -            DebugPrintf("Debugging is now disabled\n"); -        } else -            DebugPrintf("Not a valid debug level (0 - 10)\n"); -    } - -    return true; +	if (argc == 1) { +			DebugPrintf("Debugging is currently set at level %d\n", gDebugLevel); +	} else { // set level +		gDebugLevel = atoi(argv[1]); +		if (0 <= gDebugLevel && gDebugLevel < 11) { +			DebugPrintf("Debug level set to level %d\n", gDebugLevel); +		} else if (gDebugLevel < 0) { +			DebugPrintf("Debugging is now disabled\n"); +		} else +			DebugPrintf("Not a valid debug level (0 - 10)\n"); +	} + +	return true;  }  /*   * This command sets a flag   */  bool Debugger::Cmd_SetFlag(int argc, const char **argv) { -    // Check for a flag to set -    if (argc != 2) { -        DebugPrintf("Usage: %s <flag number>\n", argv[0]); -        return true; -    } - -    int flagNum = strToInt(argv[1]); -    //g_globals->setFlag(flagNum); -    return true; +	// Check for a flag to set +	if (argc != 2) { +		DebugPrintf("Usage: %s <flag number>\n", argv[0]); +		return true; +	} + +	int flagNum = strToInt(argv[1]); +	//g_globals->setFlag(flagNum); +	return true;  }  /*   * This command gets the value of a flag   */  bool Debugger::Cmd_GetFlag(int argc, const char **argv) { -    // Check for an flag to display -    if (argc != 2) { -        DebugPrintf("Usage: %s <flag number>\n", argv[0]); -        return true; -    } - -    int flagNum = strToInt(argv[1]); -    //DebugPrintf("Value: %d\n", g_globals->getFlag(flagNum)); -    return true; +	// Check for an flag to display +	if (argc != 2) { +		DebugPrintf("Usage: %s <flag number>\n", argv[0]); +		return true; +	} + +	int flagNum = strToInt(argv[1]); +	//DebugPrintf("Value: %d\n", g_globals->getFlag(flagNum)); +	return true;  }  /*   * This command clears a flag   */  bool Debugger::Cmd_ClearFlag(int argc, const char **argv) { -    // Check for a flag to clear -    if (argc != 2) { -        DebugPrintf("Usage: %s <flag number>\n", argv[0]); -        return true; -    } - -    int flagNum = strToInt(argv[1]); -    //g_globals->clearFlag(flagNum); -    return true; +	// Check for a flag to clear +	if (argc != 2) { +		DebugPrintf("Usage: %s <flag number>\n", argv[0]); +		return true; +	} + +	int flagNum = strToInt(argv[1]); +	//g_globals->clearFlag(flagNum); +	return true;  }  /*   * This command starts new flc anim   */  bool Debugger::Cmd_ViewFlc(int argc, const char **argv) { -    // Check for a flag to clear -    if (argc != 2) { -        DebugPrintf("Usage: %s <anim number>\n", argv[0]); -        return true; -    } - -    int flagNum = strToInt(argv[1]); -    _vm->loadAnim(flagNum, false); -    return true; +	// Check for a flag to clear +	if (argc != 2) { +		DebugPrintf("Usage: %s <anim number>\n", argv[0]); +		return true; +	} + +	int flagNum = strToInt(argv[1]); +	_vm->loadAnim(flagNum, false); +	return true;  }  bool Debugger::Cmd_InitRoom(int argc, const char **argv) { -    // Check for a flag to clear -    if (argc != 2) { -        DebugPrintf("Usage: %s <anim number>\n", argv[0]); -        return true; -    } - -    int flagNum = strToInt(argv[1]); -    _vm->loadLocation(flagNum); -    return true; +	// Check for a flag to clear +	if (argc != 2) { +		DebugPrintf("Usage: %s <anim number>\n", argv[0]); +		return true; +	} + +	int flagNum = strToInt(argv[1]); +	_vm->loadLocation(flagNum); +	return true;  }  bool Debugger::Cmd_ChangeCursor(int argc, const char **argv) { -    // Check for a flag to clear -    if (argc != 2) { -        DebugPrintf("Usage: %s <curId>\n", argv[0]); -        return true; -    } - -    int flagNum = strToInt(argv[1]); -    _vm->changeCursor(flagNum); -    return true; +	// Check for a flag to clear +	if (argc != 2) { +		DebugPrintf("Usage: %s <curId>\n", argv[0]); +		return true; +	} + +	int flagNum = strToInt(argv[1]); +	_vm->changeCursor(flagNum); +	return true;  }  }  + +/* vim: set tabstop=4 noexpandtab: */ diff --git a/engines/prince/debugger.h b/engines/prince/debugger.h index 08b1676fd7..cbb6094668 100644 --- a/engines/prince/debugger.h +++ b/engines/prince/debugger.h @@ -47,7 +47,8 @@ private:  	PrinceEngine *_vm;  }; -  }   #endif + +/* vim: set tabstop=4 noexpandtab: */ diff --git a/engines/prince/prince.cpp b/engines/prince/prince.cpp index e1d35091ed..2d1f6ce880 100644 --- a/engines/prince/prince.cpp +++ b/engines/prince/prince.cpp @@ -357,7 +357,7 @@ void PrinceEngine::keyHandler(Common::Event event) {  		scrollCameraRight(32);  		break;  	case Common::KEYCODE_ESCAPE: -		_script->setFlag(Flags::ESCAPED2, 1); +		_script->setFlagValue(Flags::ESCAPED2, 1);  		break;  	}  } diff --git a/engines/prince/script.cpp b/engines/prince/script.cpp index f32c1724b9..1c09ddb50f 100644 --- a/engines/prince/script.cpp +++ b/engines/prince/script.cpp @@ -47,8 +47,12 @@ Script::~Script() {      delete[] _code;  } -void Script::setFlag(Flags::Id flagId, uint16 value) { -	_flags[flagId - 0x8000] = value; +void Script::setFlagValue(Flags::Id flagId, uint16 value) { +	_flags[(uint16)flagId - FLAG_MASK] = value; +} + +uint16 Script::getFlagValue(Flags::Id flagId) { +	return _flags[(uint16)flagId - FLAG_MASK];  }  bool Script::loadFromStream(Common::SeekableReadStream &stream) { @@ -83,12 +87,10 @@ void Script::debugScript(const char *s, ...) {  }  void Script::step() { -#if 1  	if (_bgOpcodePC) {  		_mode = "bg";  		_bgOpcodePC = step(_bgOpcodePC);  	} -#endif  	if (_fgOpcodePC) {  		_mode = "fg";  		_fgOpcodePC = step(_fgOpcodePC); @@ -147,6 +149,14 @@ uint16 Script::readScript16bits() {      return lower | (upper << 8);  } +uint16 Script::readScriptValue() { +	uint16 value = readScript16bits(); +	if (value & FLAG_MASK) { +		value = _flags[value - FLAG_MASK]; +	} +	return value; +} +  uint32 Script::readScript32bits() {      uint16 lower = readScript16bits();      uint16 upper = readScript16bits(); @@ -359,31 +369,20 @@ void Script::O_CHANGEANIMTYPE() {  }  void Script::O__SETFLAG() { -	uint16 flagId = readScript16bits(); -	uint16 value = readScript16bits(); - -	if (value & 0x8000) { -		value = _flags[value - 0x8000]; -	} +	Flags::Id flagId = readScriptFlagId(); +	uint16 value = readScriptValue();  	debugScript("O__SETFLAG 0x%04X (%s) = %d", flagId, Flags::getFlagName(flagId), value); -	_flags[flagId - 0x8000] = value; +	setFlagValue((Flags::Id)(flagId), value);  }  void Script::O_COMPARE() { -	uint16 flagId = readScript16bits(); -	uint16 value = readScript16bits(); - -	if (value & 0x8000) { -		uint16 val = _flags[value - 0x8000]; -		debugScript("GetFlagValue 0x%04X (%s), value %d", value, Flags::getFlagName(value), val); +	Flags::Id flagId = readScriptFlagId(); +	uint16 value = readScriptValue(); -		value = val;  -	} - -	_result = !(_flags[flagId - 0x8000] == value); -	debugScript("O_COMPARE flagId 0x%04X (%s), value %d == %d (%d)", flagId, Flags::getFlagName(flagId), value, _flags[flagId - 0x8000], _result); +	_result = getFlagValue(flagId) != value; +	debugScript("O_COMPARE flagId 0x%04X (%s), value %d == %d (%d)", flagId, Flags::getFlagName(flagId), value, getFlagValue(flagId), _result);  }  void Script::O_JUMPZ() { @@ -410,15 +409,11 @@ void Script::O_EXIT() {  }  void Script::O_ADDFLAG() { -	uint16 flagId = readScript16bits(); -	uint16 value = readScript16bits(); +	Flags::Id flagId = readScriptFlagId(); +	uint16 value = readScriptValue(); -	if (value & 0x8000) { -		value = _flags[value - 0x8000]; -	} - -	_flags[flagId - 0x8000] += value; -	if (_flags[flagId - 0x8000]) +	setFlagValue(flagId, getFlagValue(flagId) + value); +	if (getFlagValue(flagId))  		_result = 1;  	else  		_result = 0; @@ -434,15 +429,11 @@ void Script::O_TALKANIM() {  }  void Script::O_SUBFLAG() { -	uint16 flagId = readScript16bits(); -	uint16 value = readScript16bits(); +	Flags::Id flagId = readScriptFlagId(); +	uint16 value = readScriptValue(); -	if (value & 0x8000) { -		value = _flags[value - 0x8000]; -	} - -	_flags[flagId - 0x8000] -= value; -	if (_flags[flagId - 0x8000]) +	setFlagValue(flagId, getFlagValue(flagId) - value); +	if (getFlagValue(flagId))  		_result = 1;  	else  		_result = 0; @@ -468,18 +459,14 @@ void Script::O_SETSTRING() {  }  void Script::O_ANDFLAG() { -	uint16 flagId = readScript16bits(); -	uint16 value = readScript16bits(); +	Flags::Id flagId = readScriptFlagId(); +	uint16 value = readScriptValue();  	debugScript("O_ANDFLAG flagId %d, value %d", flagId, value); -	if (value & 0x8000) { -		value = _flags[value - 0x8000]; -	} +	setFlagValue(flagId, getFlagValue(flagId) & value); -	_flags[flagId - 0x8000] &= value; - -	if (_flags[flagId - 0x8000]) { +	if (getFlagValue(flagId)) {  		_result = 1;  	} else {  		_result = 0; @@ -487,7 +474,7 @@ void Script::O_ANDFLAG() {  }  void Script::O_GETMOBDATA() { -	uint16 flagId = readScript16bits(); +	Flags::Id flagId = readScriptFlagId();  	uint16 mobId = readScript16bits();  	uint16 mobOffset = readScript16bits(); @@ -495,18 +482,14 @@ void Script::O_GETMOBDATA() {  }  void Script::O_ORFLAG() { -	uint16 flagId = readScript16bits(); -	uint16 value = readScript16bits(); +	Flags::Id flagId = readScriptFlagId(); +	uint16 value = readScriptValue();  	debugScript("O_ORFLAG flagId %d, value %d", flagId, value); +	 +	setFlagValue(flagId, getFlagValue(flagId) | value); -	if (value & 0x8000) { -		value = _flags[value - 0x8000]; -	} - -	_flags[flagId - 0x8000] |= value; - -	if (_flags[flagId - 0x8000]) { +	if (getFlagValue(flagId)) {  		_result = 1;  	} else {  		_result = 0; @@ -522,18 +505,14 @@ void Script::O_SETMOBDATA() {  }  void Script::O_XORFLAG() { -	uint16 flagId = readScript16bits(); -	uint16 value = readScript16bits(); +	Flags::Id flagId = readScriptFlagId(); +	uint16 value = readScriptValue();  	debugScript("O_XORFLAG flagId %d, value %d", flagId, value); -	if (value & 0x8000) { -		value = _flags[value - 0x8000]; -	} - -	_flags[flagId - 0x8000] ^= value; +	setFlagValue(flagId, getFlagValue(flagId) ^ value); -	if (_flags[flagId - 0x8000]) { +	if (getFlagValue(flagId)) {  		_result = 1;  	} else {  		_result = 0; @@ -691,10 +670,7 @@ void Script::O_TALKHERO() {  }  void Script::O_WAITTEXT() { -	uint16 slot = readScript16bits(); -	if (slot & 0x8000) { -		slot = _flags[slot - 0x8000]; -	} +	uint16 slot = readScriptValue();  	Text &text = _vm->_textSlots[slot];  	if (text._time) {  		_opcodeNF = 1; @@ -789,11 +765,11 @@ void Script::O_LOADPATH() {  }  void Script::O_GETCHAR() { -	uint16 flagId = readScript16bits(); +	Flags::Id flagId = readScriptFlagId(); -	_flags[flagId - 0x8000] = *_string; +	setFlagValue(flagId, *_string); -	debugScript("O_GETCHAR %04X (%s) %02x", flagId, Flags::getFlagName(flagId), _flags[flagId - 0x8000]); +	debugScript("O_GETCHAR %04X (%s) %02x", flagId, Flags::getFlagName(flagId), getFlagValue(flagId));  	++_string;  } @@ -816,7 +792,7 @@ void Script::O_PRINTAT() {  	debugScript("O_PRINTAT slot %d, fr1 %d, fr2 %d", slot, fr1, fr2); -	uint8 color = _flags[Flags::KOLOR - 0x8000]; +	uint8 color = getFlagValue(Flags::KOLOR);  	_vm->printAt(slot, color, (const char *)_string, fr1, fr2); @@ -923,21 +899,21 @@ void Script::O_SETPATH() {  void Script::O_GETHEROX() {  	uint16 heroId = readScript16bits(); -	uint16 flagId = readScript16bits(); +	Flags::Id flagId = readScriptFlagId();  	debugScript("O_GETHEROX heroId %d, flagId %d", heroId, flagId);  }  void Script::O_GETHEROY() {  	uint16 heroId = readScript16bits(); -	uint16 flagId = readScript16bits(); +	Flags::Id flagId = readScriptFlagId();  	debugScript("O_GETHEROY heroId %d, flagId %d", heroId, flagId);  }  void Script::O_GETHEROD() {  	uint16 heroId = readScript16bits(); -	uint16 flagId = readScript16bits(); +	Flags::Id flagId = readScriptFlagId();  	debugScript("O_GETHEROD heroId %d, flagId %d", heroId, flagId);  } @@ -1090,7 +1066,7 @@ void Script::O_SKIPTEXT() {  void Script::SetVoice(uint32 slot) { -	const uint16 VOICE_H_LINE = _flags[Flags::VOICE_H_LINE - 0x8000]; +	const uint16 VOICE_H_LINE = getFlagValue(Flags::VOICE_H_LINE);  	const Common::String streamName = Common::String::format("%03d-%02d.WAV", _currentString, VOICE_H_LINE);  	debugScript("Loading wav %s slot %d", streamName.c_str(), slot); @@ -1149,13 +1125,9 @@ void Script::O_SETVOICEC() {  }  void Script::O_VIEWFLCLOOP() { -	uint16 value = readScript16bits(); +	uint16 value = readScriptValue();  	debugScript("O_VIEWFLCLOOP animId %d", value); -	if (value & 0x8000) { -		value = _flags[value - 0x8000]; -	} -  	_vm->loadAnim(value, true);  } @@ -1178,7 +1150,7 @@ void Script::O_GETKRZYWA() {  }  void Script::O_GETMOB() { -	uint16 flagId = readScript16bits(); +	Flags::Id flagId = readScriptFlagId();  	uint16 mx = readScript16bits();  	uint16 my = readScript16bits();  	debugScript("O_GETMOB flagId %d, mx %d, my %d", flagId, mx, my); diff --git a/engines/prince/script.h b/engines/prince/script.h index 8f1ede3a83..a323c1784d 100644 --- a/engines/prince/script.h +++ b/engines/prince/script.h @@ -45,7 +45,9 @@ public:  	bool loadFromStream(Common::SeekableReadStream &stream);  	void step(); -	void setFlag(Flags::Id flag, uint16 value); + +	void setFlagValue(Flags::Id flag, uint16 value); +	uint16 getFlagValue(Flags::Id flag);  private:  	PrinceEngine *_vm; @@ -60,7 +62,9 @@ private:  	uint16 _lastOpcode;  	uint32 _lastInstruction;  	byte _result; -	int16 _flags[2000]; +	static const uint16 MAX_FLAGS = 2000; +	static const uint16 FLAG_MASK = 0x8000; +	int16 _flags[MAX_FLAGS];  	bool _opcodeNF; @@ -83,8 +87,13 @@ private:  	uint8 getCodeByte(uint32 address);  	uint8 readScript8bits();  	uint16 readScript16bits(); +  	uint32 readScript32bits();  	uint16 readScript8or16bits(); + +	uint16 readScriptValue(); +	Flags::Id readScriptFlagId() { return (Flags::Id)readScript16bits(); } +  	void debugScript(const char *s, ...);  	void SetVoice(uint32 slot);  | 
