Open main menu

Difference between revisions of "SCUMM/V5 opcodes"

2,972 bytes added ,  06:27, 20 March 2009
→‎SCUMM V5 opcodes: Formatting, added basic branches, arithmetic
(→‎SCUMM V5 opcodes: Formatting, added basic branches, arithmetic)
Line 8: Line 8:
|-
|-
|result||A result pointer. (A standard word pointer, always a LE word.)
|result||A result pointer. (A standard word pointer, always a LE word.)
|-
|var||A var pointer. (Same as above, but is not written to)
|-
|-
|value[8]||An 8-bit constant (a byte).
|value[8]||An 8-bit constant (a byte).
Line 20: Line 22:
|-
|-
|value[o]||The offset word for parameter value. This is only encoded if needed, but always at the position indicated. If not specified, the offset word occurs immediately after the parameter.
|value[o]||The offset word for parameter value. This is only encoded if needed, but always at the position indicated. If not specified, the offset word occurs immediately after the parameter.
|-
|target[16]||A 16-bit contstant (a word LE), relative offset after this value, measured in bytes. Used in all comparison operations, jumpRelative, etc.
|-
|-
|(term)||An optional term.
|(term)||An optional term.
|}
|}


Of course, due to the non-orthogonality of the opcodes, there are lots of exceptions.


==actorFollowCamera ($52)==
==actorFollowCamera ($52)==
Line 36: Line 41:


===Encoding===
===Encoding===
opcode result value[p16]
''opcode result value[p16]''


===Operation===
===Operation===
result := result + value
''result := result + value''


The variable pointed to by result is read, value is added to it, and the result written back.
The variable pointed to by result is read, value is added to it, and the result written back.
Line 48: Line 53:


===Encoding===
===Encoding===
opcode result value[p16]
''opcode result value[p16]''


===Operation===
===Operation===
result := result and value
''result := result and value''


The variable pointed to by result is read, logically ANDed with value, and the result written back.
The variable pointed to by result is read, logically ANDed with value, and the result written back.
Line 62: Line 67:


===Encoding===
===Encoding===
opcode $01 array[p8]
''opcode $01 array[p8]''
opcode $02 dest[p8] src[p8]
''opcode $02 dest[p8] src[p8]''
opcode $03 array[p8] index[p8] data[p8]
''opcode $03 array[p8] index[p8] data[p8]''
opcode $04 result array[p8] index[p8]
''opcode $04 result array[p8] index[p8]''
opcode $05 array[p8] size[p8]
''opcode $05 array[p8] size[p8]''


===Operation===
===Operation===
Line 91: Line 96:


===Encoding===
===Encoding===
opcode
''opcode''


===Operation===
===Operation===
Line 101: Line 106:


===Encoding===
===Encoding===
opcode script[p8] args[v16]...
''opcode script[p8] args[v16]...''


===Operation===
===Operation===
Line 115: Line 120:


===Encoding===
===Encoding===
opcode param[p16]
''opcode param[p16]''


===Operation===
===Operation===
Line 125: Line 130:


===Encoding===
===Encoding===
opcode result
''opcode result''


===Operation===
===Operation===
result := result - 1
''result := result - 1''


Reads the variable pointed to by result, decrements it, and writes it back.  
Reads the variable pointed to by result, decrements it, and writes it back.  
Line 137: Line 142:


===Encoding===
===Encoding===
opcode param[24]
''opcode param[24]''


===Operation===
===Operation===
Line 147: Line 152:


===Encoding===
===Encoding===
opcode pointer[16]
''opcode pointer[16]''


===Operation===
===Operation===
Line 157: Line 162:


===Encoding===
===Encoding===
opcode result value[p16]
''opcode result value[p16]''


===Operation===
===Operation===
result := result / value
''result := result / value''


The variable pointed to by result is read, divided by value, and the result written back. If value is zero, the result is undefined (and the interpeter may halt with an error).  
The variable pointed to by result is read, divided by value, and the result written back. If value is zero, the result is undefined (and the interpeter may halt with an error).  
Line 171: Line 176:


===Encoding===
===Encoding===
opcode left[p16] top[p16] auxopcode[8] right[p16] bottom[p16] colour[p8]
''opcode left[p16] top[p16] auxopcode[8] right[p16] bottom[p16] colour[p8]''


===Operation===
===Operation===
Line 185: Line 190:


==equalZero ($28)==
==equalZero ($28)==
jumps
===Encoding===
''opcode var target[16]''
===Operation===
''unless (var == 0) goto target''
Target is a byte offset (measured from after this instruction), which will be added to the instruction pointer.


==expression ($AC)==
==expression ($AC)==
Line 235: Line 250:


==ifClassOfIs ($1D)==
==ifClassOfIs ($1D)==
jumps
===Encoding===
''opcode value[p16] args[p16]...''
===Operation===
''unless (value.class is one of [args.class]) goto target''
Compares the value's class with all classes given in args.
Target is a byte offset (measured from after this instruction), which will be added to the instruction pointer.


==increment ($46)==
==increment ($46)==
Line 241: Line 268:


===Encoding===
===Encoding===
opcode result
''opcode result''


===Operation===
===Operation===
result := result + 1
''result := result + 1''


Reads the variable pointed to by result, increments it, and writes it back.  
Reads the variable pointed to by result, increments it, and writes it back.  
Line 251: Line 278:


==isEqual ($48)==
==isEqual ($48)==
===Encoding===
''opcode var value[p16] target[16]''
===Operation===
''unless (value == var) goto target''
Target is a byte offset (measured from after this instruction), which will be added to the instruction pointer.


==isGreater ($78)==
==isGreater ($78)==
===Encoding===
''opcode var value[p16] target[16]''
===Operation===
''unless (value > var) goto target''
Target is a byte offset (measured from after this instruction), which will be added to the instruction pointer.


==isGreaterEqual ($04)==
==isGreaterEqual ($04)==
===Encoding===
''opcode var value[p16] target[16]''
===Operation===
''unless (value >= var) goto target''
Target is a byte offset (measured from after this instruction), which will be added to the instruction pointer.


==isLess ($44)==
==isLess ($44)==
===Encoding===
''opcode var value[p16] target[16]''
===Operation===
''unless (value < var) goto target''
Target is a byte offset (measured from after this instruction), which will be added to the instruction pointer.


==isNotEqual ($08)==
==isNotEqual ($08)==
===Encoding===
''opcode var value[p16] target[16]''
===Operation===
''unless (value != var) goto target''
Target is a byte offset (measured from after this instruction), which will be added to the instruction pointer.


==isSoundRunning ($7C)==
==isSoundRunning ($7C)==
Line 264: Line 331:
==jumpRelative ($18)==
==jumpRelative ($18)==


non-standard encoding
jumps


===Encoding===
===Encoding===
opcode target[16]
''opcode target[16]''


===Operation===
===Operation===
PC := PC + target
''PC := PC + target''


The inline constant target is read as a signed word and added to the program counter after the instruction has been read. Therefore, if target is zero, the instruction will do nothing; if target is -3, an infinite loop will result.  
The inline constant target is read as a signed word and added to the program counter after the instruction has been read. Therefore, if target is zero, the instruction will do nothing; if target is -3, an infinite loop will result.  


==lessOrEqual ($38)==
==lessOrEqual ($38)==
jumps
===Encoding===
''opcode var value[p16] target[16]''
===Operation===
''unless (value <= var) goto target''
Target is a byte offset (measured from after this instruction), which will be added to the instruction pointer.


==lights ($70)==
==lights ($70)==
Line 285: Line 362:


==move ($1A)==
==move ($1A)==
===Encoding===
''opcode result value[p16]''
===Operation===
''result := value''
Value is moved into result.


==multiply ($1B)==
==multiply ($1B)==
===Encoding===
''opcode result value[p16]''
===Operation===
''result := result * value''
The variable pointed to by result is read, multiplied by value, and written back.


==notEqualZero ($A8)==
==notEqualZero ($A8)==
===Encoding===
''opcode var target[16]''
===Operation===
''unless (var != 0) goto target''
Target is a byte offset (measured from after this instruction), which will be added to the instruction pointer.


==or ($57)==
==or ($57)==
Line 295: Line 396:


===Encoding===
===Encoding===
opcode result value[p16]
''opcode result value[p16]''


===Operation===
===Operation===
result := result or value
''result := result or value''


The variable pointed to by result is read, logically ORed with value, and the result written back.
The variable pointed to by result is read, logically ORed with value, and the result written back.
Line 337: Line 438:


==setVarRange ($26)==
==setVarRange ($26)==
non-standard encoding
===Encoding===
===Encoding===
opcode result value[8] (value[8] or value[16])...
''opcode result number[8] values[8]...''
or
''opcode result number[8] values[16]...''


===Operation===
===Operation===
This sets a number of variables to the given parameters. The starting variable is given as "result", and the number of variables to modify is given as "value[8]". This is followed by the same number of values. The values are constants, and can be either 16-bit, if the highest bit of the opcode is set, i.e. $A6; or 8-bit, if the highest bit of the opcode is not set, i.e. $26. Note that all values are affected by this high bit; you can't mix 8 and 16-bit values.
This sets a number of variables to the given parameters. The starting variable is given as "result", and the number of variables to modify is given as "number". This is followed by the same number of values, which will be put into the variable locations. The values are constants, and can be either 16-bit, if the highest bit of the opcode is set, i.e. $A6; or 8-bit, if the highest bit of the opcode is not set, i.e. $26. Note that all values are affected by the opcode's high bit; you can't mix 8 and 16-bit values.


===Descumm example===
===descumm example===
setVarRange(Var[178],9,[0,0,0,0,0,0,0,0,0]);
''setVarRange(Var[178],9,[0,0,0,0,0,0,0,0,0]);''


This sets variables 178 to 186 (inclusive) to 0.
This sets variables 178 to 186 (inclusive) to 0.
Line 359: Line 465:


===Encoding===
===Encoding===
opcode script[p8] args[v16]...
''opcode script[p8] args[v16]...''


===Operation===
===Operation===
Line 386: Line 492:


==subtract ($3A)==
==subtract ($3A)==
===Encoding===
''opcode result value[p16]''
===Operation===
''result := result - value''
The variable pointed to by result is read, value is subtracted from it, and the result written back.


==animateActor ($11)==
==animateActor ($11)==
Line 396: Line 510:


==walkActorToObject ($36)==
==walkActorToObject ($36)==
All material © 2000-2002 David Given, unless where stated otherwise.


=Table of Parameters=
=Table of Parameters=
125

edits