OpCodes
Each instruction is represented by a number – opcode, which is UINT16.
By that number the game engine(.exe) identifies an action to perform. And the opcode will do what it is made for, if used correctly.
Here is how a opcode in SCM looks like:
Opcode 0001
- Code:
0100 04 00
Opcode 0002
- Code:
0200 04 @Label
- First 4 digits is the opcode number in a little-endian format.
- Second part is the data type
- Third part is a parameter(s) value
When a mission script is disassembled, the opcodes are written in a readable format, in which humans, can read better. The examples above will look something like this:
Opcode 0001
- Code:
wait 0
Opcode 0002
- Code:
jump @Label
The comment opcode words(wait, jump,) are made only so the user can understand the opcode better. The game does not know what the words mean, it knows the data number(0001: for example) and it knows the parameters and this is the only thing which is important(for example you do not need the word "wait" you can just put 0001: 0) (0001 is the data, and 0 is the parameter of that opcode for example). So when a mission script is assembled the commands are written back in raw byte form.
An opcode is UINT16 number. It means the minimum opcode is 0000 and maximum opcode is 0xFFFF. However due to a specific of the SCM language, any numbers above 0x7FFF denote negative conditional opcodes. The original un-modded game supports a way smaller amount of opcodes (maximum 0A4E for San Andreas).
Data types
Data type is a single byte written before any parameter. The purpose of it is to tell to the game how much bytes to read next and what kind of data it is, that depends on what opcode it is.
- Code:
--Data type-- --Parameter Length (bytes)--
00 0
01 4
02 2
03 2
04 1
05 2
06 4
07 6
08 6
09 8
10 2
11 2
12 6
13 6
14 1+x
15 16
16 2
17 2
18 6
19 6
Parameters
The games engine knows amount of parameters for each opcode, (and it knows the data type, as stated above as well). The parameter of a opcode, could be one of the following:
- Immediate values
- integer numbers
- floating-point numbers
- short strings (up to 7 characters and null-terminator byte)
- San Andreas long strings (up to 15 characters and length byte)
- Variables
- global variables
- local variables - Arrays
- For information on arrays see here.
Integer:
- Code:
0006: 0@ = 0
Floating-point value:
- Code:
0007: 0@ = 0.0
Short string:
- Code:
15@s
Long string:
- Code:
15@v
Global variable:
- Code:
$
Local variable:
- Code:
@
You can see this topic for information on them.
Arrays