From 5b401215d9e0a31687c27b8b56ba3d651b89e000 Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Fri, 30 Jul 2010 14:56:38 +0000 Subject: SCI: Added handling of negative numbers to op_mod for SCI01 and newer games. Fixes the battlecruiser mini-game in SQ5. Many thanks to lskovlun, wjp and m_kiewitz for their joined effort on this issue svn-id: r51508 --- engines/sci/engine/vm.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'engines/sci') diff --git a/engines/sci/engine/vm.cpp b/engines/sci/engine/vm.cpp index b7f6896a48..0ab66419c0 100644 --- a/engines/sci/engine/vm.cpp +++ b/engines/sci/engine/vm.cpp @@ -1069,11 +1069,17 @@ void run_vm(EngineState *s) { case op_mod: { // 0x05 (05) r_temp = POP32(); - int16 modulo, value; - if (validate_signedInteger(s->r_acc, modulo) && validate_signedInteger(r_temp, value)) - s->r_acc = make_reg(0, (modulo != 0 ? value % modulo : 0)); - else + int16 modulo, value, result; + if (validate_signedInteger(s->r_acc, modulo) && validate_signedInteger(r_temp, value)) { + modulo = ABS(modulo); + result = (modulo != 0 ? value % modulo : 0); + // In SCI01, handling for negative numbers was added + if (getSciVersion() >= SCI_VERSION_01 && result < 0) + result += modulo; + s->r_acc = make_reg(0, result); + } else { s->r_acc = arithmetic_lookForWorkaround(opcode, NULL, s->r_acc, r_temp); + } break; } -- cgit v1.2.3