-
Notifications
You must be signed in to change notification settings - Fork 5
/
notes.txt
222 lines (201 loc) · 6.86 KB
/
notes.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
######################################
####### AGS disassembler notes #######
######################################
// disassembles script and dumps instructions in a file
//public void Disassemble(string targetpath)
//{
/*
* Instructions are stored as Int32 where highest byte stores instance id:
* (memory) (register)
* [ AA BB CC 01 ] [ 01 CC BB AA ]
* [ opcode ][id] [id][ opcode ]
*
* If script compiled in debug mode, it contains "linenumber" instructions
* with a line number as an argument.
*
* For 3.4 opcode is 0..74 inclusive.
*
* Each instruction can have multiple arguments represented as Int32.
* For 3.4 maximum arguments count is 3.
* Argument may be either a numeric value or an offset\pointer.
* Fixups table is used to determine the type of an argument.
*
* Fixups types:
* 0x0 : numerical literal
* GLOBAL_DATA = 0x1 : offset into globaldata (in bytes)
* FUNCTION = 0x2 : offset from a start of code section (pc value ???)
* STRING = 0x3 : offset to strings null-terminated sequence (in bytes)
* IMPORT = 0x4 : index for imports array
* DATADATA = 0x5 : relative offset into globaldata stored in globaldata (in bytes)
* STACK = 0x6 : offset on the stack (in bytes)
*/
/*for (int i = 0; i < Fixups.Length; ++i)
{
AGSScriptFixup fixup = Fixups[i];
switch (fixup.Type)
{
case AGSFixupType.Literal:
{
int value = Code[fixup.Value];
}
break;
case AGSFixupType.GlobalData:
{
int offset = Code[fixup.Value];
int value = GlobalData[offset];
}
break;
case AGSFixupType.Function:
{
int offset = Code[fixup.Value];
int value = Code[offset];
}
break;
case AGSFixupType.String:
{
int offset = Code[fixup.Value];
string value = ReadCString(StringsBlob[offset]);
}
break;
case AGSFixupType.Import:
{
int index = Code[fixup.Value];
string value = Imports[index];
}
break;
case AGSFixupType.DataData:
{
int offset = GlobalData[fixup.Value];
int value = GlobalData[offset];
}
break;
case AGSFixupType.Stack:
{
int offset = Code[fixup.Value];
int value = Stack[offset];
}
break;
default:
throw new InvalidDataException();
}
}*/
//}
########### Literal types ############
"number":
"int": 12
"float": 3.1415
"string": "Ouch!"
A sequence of characters enclosed in '"' symbols.
"identifier": player, oLever, gInventory
A simple symbolic name of an object.
"function": IsTimerExpired
Simple symbolic name of a function that does not have a "this" pointer.
Looks like it's NOT mangled, so we cannot tell a difference between
a function name and an identifier without looking at how this value is used.
Also, we have no information is it imported or exported function.
"method": Character::ChangeRoom^3, hToRoom_Interact$0
A member function name, that requires to set a "this" pointer.
Looks like it is always mangled, so we CAN tell a difference between
imported and exported method (imported methods use '^' symbol instead of a '$').
We also know the object name (goes before '::' symbol).
Because it's mangled we always know a number of parameters that are passed.
"property": DynamicSprite::get_Height, DynamicSprite::set_Height
A member function that has 'get' and\or 'set' variants.
It's not mangled, but a function name has a prefix of 'set_' or 'get_'.
There's no information if this is an imported or exported method,
but I don't remember if you can declare your own properties in AGS (probably not).
######### Instruction layout #########
TODO: A column based layout???
############# Registers ##############
0x00, null
0x01, sp - stack pointer
0x02, mar - memory address register
0x03, ax - general purpose
0x04, bx - general purpose
0x05, cx - general purpose
0x06, op - object pointer (for member func calls)
0x07, dx - general purpose
########## Instructions set ##########
[opcode], [mnemonic], [args count]
0x00, "null", 0
0x01, "add", 2
0x02, "sub", 2
0x03, "mov", 2
0x04, "memwritelit", 2
0x05, "ret", 0
0x06, "mov", 2
0x07, "memread", 1
0x08, "memwrite", 1
0x09, "mul", 2
0x0A, "div", 2
0x0B, "add", 2
0x0C, "sub", 2
0x0D, "bit_and", 2
0x0E, "bit_or", 2
0x0F, "cmp", 2
0x10, "ncmp", 2
0x11, "gt", 2
0x12, "lt", 2
0x13, "gte", 2
0x14, "lte", 2
0x15, "and", 2
0x16, "or", 2
0x17, "call", 1
0x18, "memread.b", 1
0x19, "memread.w", 1
0x1A, "memwrite.b", 1
0x1B, "memwrite.w", 1
0x1C, "jz", 1
0x1D, "push", 1
0x1E, "pop", 1
0x1F, "jmp", 1
0x20, "mul", 2
0x21, "farcall", 1
0x22, "farpush", 1
0x23, "farsubsp", 1
0x24, "sourceline", 1
0x25, "callscr", 1
0x26, "thisaddr", 1
0x27, "setfuncargs", 1
0x28, "mod", 2
0x29, "xor", 2
0x2A, "not", 1
0x2B, "shl", 2
0x2C, "shr", 2
0x2D, "callobj", 1
0x2E, "checkbounds", 2
0x2F, "memwrite.ptr", 1
0x30, "memread.ptr", 1
0x31, "memwrite.ptr.0", 0
0x32, "meminit.ptr", 1
0x33, "load.sp.offs", 1
0x34, "checknull.ptr", 0
0x35, "f.add", 2
0x36, "f.sub", 2
0x37, "f.mul", 2
0x38, "f.div", 2
0x39, "f.add", 2
0x3A, "f.sub", 2
0x3B, "f.gt", 2
0x3C, "f.lt" , 2
0x3D, "f.gte", 2
0x3E, "f.lte", 2
0x3F, "zeromem", 1
0x40, "newstring", 1
0x41, "strcmp", 2
0x42, "strnotcmp", 2
0x43, "checknull", 1
0x44, "loopcheckoff", 0
0x45, "memwrite.ptr.0.nd", 0
0x46, "jnz", 1
0x47, "dynamicbounds", 1
0x48, "newarray", 3
0x49, "newuserobject", 2
###### Instruction description #######
"null" - not used
"add" - reg[arg1] += arg2
"sub" - reg[arg1] += arg2
"mov" - reg[arg2] = reg[arg1]
reg[arg2] = arg1
"memwritelit" - m[MAR] = arg2 (copy arg1 bytes)
"ret" - return from a subroutine