Difference between revisions of "III/VC SCM"

From GTAMods Wiki
Jump to navigation Jump to search
m (Mysterious data have been already known but were never revealed in the article.)
Line 2: Line 2:
 
== Overall Format ==
 
== Overall Format ==
 
  (02 00 01)h + 32 bit int    Jump to second segment
 
  (02 00 01)h + 32 bit int    Jump to second segment
  byte                        Padding
+
  byte                        Padding (always 0)
 
   (Global vars)              Space for variable saving
 
   (Global vars)              Space for variable saving
 
  (02 00 01)h + 32 bit int    Jump to third segment
 
  (02 00 01)h + 32 bit int    Jump to third segment
  byte                        Segment id
+
  byte                        Padding (always 0)
 
   32 bit int                Number of models
 
   32 bit int                Number of models
   (model names)              24 byte model names * number of models(model 0 not used)
+
   (model names)              24 byte model names * number of models (model 0 name is empty and therefore unused)
 
  (02 00 01)h + 32 bit int    Jump to fourth segment
 
  (02 00 01)h + 32 bit int    Jump to fourth segment
  byte                        Segment id
+
  byte                        Padding (always 0)
8 bytes                      Padding/mysterious, unused data
+
  32 bit int                MAIN size
32 bit int                   Number of missions
+
  32 bit int                Largest mission size
 +
  32 bit int                 Number of missions
 
   (mission addresses)        32 bit addresses * number of missions
 
   (mission addresses)        32 bit addresses * number of missions
 
  (MAIN code)                  MAIN section, equal to size defined earlier
 
  (MAIN code)                  MAIN section, equal to size defined earlier
Line 44: Line 45:
 
0051: return</source>
 
0051: return</source>
 
   
 
   
compiles as:
+
...compiles as:
 
  01 00 04 08 //wait opcode (First 2 bytes = opcode, next byte = 04 the parameter type for 8-bit int, and 08 is the actual value)
 
  01 00 04 08 //wait opcode (First 2 bytes = opcode, next byte = 04 the parameter type for 8-bit int, and 08 is the actual value)
 
  02 00 02 18 00 // jump opcode. The 18 00 would mean that the global var is stored at address 0x0018
 
  02 00 02 18 00 // jump opcode. The 18 00 would mean that the global var is stored at address 0x0018

Revision as of 10:36, 30 August 2012

40px-Ambox rewrite orange.svg.png This article may need to be rewritten.
Please help improve this article. The discussion page may contain suggestions.

Overall Format

(02 00 01)h + 32 bit int     Jump to second segment
byte                         Padding (always 0)
  (Global vars)              Space for variable saving
(02 00 01)h + 32 bit int     Jump to third segment
byte                         Padding (always 0)
  32 bit int                 Number of models
  (model names)              24 byte model names * number of models (model 0 name is empty and therefore unused)
(02 00 01)h + 32 bit int     Jump to fourth segment
byte                         Padding (always 0)
  32 bit int                 MAIN size
  32 bit int                 Largest mission size
  32 bit int                 Number of missions
  (mission addresses)        32 bit addresses * number of missions
(MAIN code)                  MAIN section, equal to size defined earlier
(mission code)               The mission data, missions stored at offsets defined earlier

Main Section

Made up of many opcodes one after the other. Opcodes are of the format:

TOpcode {
  Opcode[2]: Word; //Opocode number in word format
  Parameters: Array Of TParameter;
}

The number of parameters is specific for each opcode. The opcode database has all of the opcodes in VC, with their parameter numbers, and for most, a description of what they do. Parameters are of the format:

TParameter {
  ParameterType[1]: Byte; //Says which type of parameter will follow
  ActualParameter: varies; //The actual parameter
}

The parameter types are as follows (but there are more in SA):

01: 32-bit int   (DWord)
02: global var   (Word)
03: local var    (Word)
04: 8-bit int    (Byte)
05: 16-bit int   (Word)
06: 4-byte float (Single)

Labels use the type 01 (although if they address is small enough using data types 04 and 05 will also work). Global and local vars can also be used for labels. Global vars reference a position in the file much like a label. There is a space at the top of the scm file filled with 00's which is space reserved for global vars. This is divided into blocks of 4 bytes, each var taking up one of these blocks. In compiled form, the global vars each point to somewhere in that block (or should do as otherwise writing to it will modify the actual code).

Example

This code:

0001: wait 8 ms
0002: jump $var1
0050: gosub 1@
0051: return

...compiles as:

01 00 04 08 //wait opcode (First 2 bytes = opcode, next byte = 04 the parameter type for 8-bit int, and 08 is the actual value)
02 00 02 18 00 // jump opcode. The 18 00 would mean that the global var is stored at address 0x0018
50 00 03 01 00 //the gosub opcode
51 00 //the return opcode (it has no parameters)