diff options
author | Scott Percival | 2019-11-30 11:57:37 +0800 |
---|---|---|
committer | Scott Percival | 2019-12-02 21:57:09 +0800 |
commit | 29be7c0fa6af06fed0965348e880e908273e05f1 (patch) | |
tree | abf75112ce444690f3bf8dd8418ed383692316d7 /engines/director | |
parent | f7fee0145b755782c190203c3aa9a2cd54ee95a1 (diff) | |
download | scummvm-rg350-29be7c0fa6af06fed0965348e880e908273e05f1.tar.gz scummvm-rg350-29be7c0fa6af06fed0965348e880e908273e05f1.tar.bz2 scummvm-rg350-29be7c0fa6af06fed0965348e880e908273e05f1.zip |
DIRECTOR: Implement c_jump and c_jumpif
Diffstat (limited to 'engines/director')
-rw-r--r-- | engines/director/lingo/lingo-bytecode.cpp | 29 | ||||
-rw-r--r-- | engines/director/lingo/lingo-code.cpp | 11 |
2 files changed, 31 insertions, 9 deletions
diff --git a/engines/director/lingo/lingo-bytecode.cpp b/engines/director/lingo/lingo-bytecode.cpp index 131a18211d..f606d729a1 100644 --- a/engines/director/lingo/lingo-bytecode.cpp +++ b/engines/director/lingo/lingo-bytecode.cpp @@ -58,17 +58,18 @@ static LingoV4Bytecode lingoV4[] = { { 0x43, Lingo::c_arraypush, "b" }, { 0x44, Lingo::c_constpush, "bv" }, { 0x45, Lingo::c_symbolpush, "b" }, - { 0x53, Lingo::c_jump, "bj" }, - { 0x54, Lingo::c_jump, "bnj" }, - { 0x55, Lingo::c_jumpif, "bj" }, + { 0x53, Lingo::c_jump, "jb" }, + { 0x54, Lingo::c_jump, "jbn" }, + { 0x55, Lingo::c_jumpif, "jb" }, { 0x5c, Lingo::c_v4theentitypush, "b" }, { 0x5d, Lingo::c_v4theentityassign, "b" }, { 0x81, Lingo::c_intpush, "w" }, { 0x82, Lingo::c_argspush, "w" }, { 0x83, Lingo::c_arraypush, "w" }, { 0x84, Lingo::c_constpush, "wv" }, - { 0x93, Lingo::c_jump, "wj" }, - { 0x95, Lingo::c_jumpif, "wj" }, + { 0x93, Lingo::c_jump, "jw" }, + { 0x94, Lingo::c_jump, "jwn" }, + { 0x95, Lingo::c_jumpif, "jw" }, { 0, 0, 0 } }; @@ -501,7 +502,7 @@ void Lingo::addCodeV4(Common::SeekableSubReadStreamEndian &stream, ScriptType ty case 'w': offsetList.push_back(_currentScript->size()); offsetList.push_back(_currentScript->size()); - arg = (int16)READ_UINT16(&codeStore[pointer]); + arg = (int16)READ_BE_UINT16(&codeStore[pointer]); pointer += 2; break; case 'v': @@ -550,6 +551,22 @@ void Lingo::addCodeV4(Common::SeekableSubReadStreamEndian &stream, ScriptType ty } } } + + // Rewrite every offset flagged as a jump based on the new code alignment. + // This converts the relative offset from the bytecode to an absolute one. + for (uint j = 0; j < jumpList.size(); j++) { + int originalJumpAddressLoc = jumpList[j]; + int originalJumpInstructionLoc = originalJumpAddressLoc-1; + int jumpAddressPc = offsetList[originalJumpAddressLoc]; + int jump = getInt(jumpAddressPc); + int oldTarget = originalJumpInstructionLoc + jump; + if ((oldTarget >= 0) && (oldTarget < (int)offsetList.size())) { + int newJump = offsetList[oldTarget]; + WRITE_UINT32(&((*_currentScript)[jumpAddressPc]), newJump); + } else { + warning("Jump of %d from position %d is outside the function!", jump, originalJumpAddressLoc); + } + } } free(codeStore); } diff --git a/engines/director/lingo/lingo-code.cpp b/engines/director/lingo/lingo-code.cpp index 7c05385a2e..9e11480b53 100644 --- a/engines/director/lingo/lingo-code.cpp +++ b/engines/director/lingo/lingo-code.cpp @@ -881,12 +881,17 @@ void Lingo::c_le() { } void Lingo::c_jump() { - warning("STUB: c_jump()"); + uint jump = g_lingo->readInt(); + g_lingo->_pc = jump; } void Lingo::c_jumpif() { - g_lingo->pop(); - warning("STUB: c_jumpif()"); + uint jump = g_lingo->readInt(); + Datum test = g_lingo->pop(); + test.toInt(); + if (test.u.i) { + g_lingo->_pc = jump; + } } void Lingo::c_repeatwhilecode(void) { |