Debian Codegraph @

lib/d3x_op.h

raw symbols SCIP
1 /*
2 * Descent 3
3 * Copyright (C) 2024 Parallax Software
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 --- HISTORICAL COMMENTS FOLLOW ---
19
20 * $Logfile: /DescentIII/Main/lib/d3x_op.h $
21 * $Revision: 20 $
22 * $Date: 4/03/98 5:15p $
23 * $Author: Samir $
24 *
25 * D3X Opcodes.
26 *
27 * $Log: /DescentIII/Main/lib/d3x_op.h $
28 *
29 * 20 4/03/98 5:15p Samir
30 * Added event parameters and upped registers.
31 *
32 * 19 3/26/98 12:18p Samir
33 * Updated D3X version.
34 *
35 * 18 3/19/98 9:41p Samir
36 * updated script file to now store length of script names. this wasn't
37 * happening before, and was a major bug that seemed to go unnoticed.
38 *
39 * 17 3/11/98 11:22a Samir
40 * Added new integer opcodes.
41 *
42 * 16 2/10/98 10:44a Samir
43 * Added gamemode script type.
44 *
45 * 15 2/05/98 2:44p Samir
46 * Added dynamic strings.
47 *
48 * 14 1/22/98 6:22p Samir
49 * Moved script parameter info to d3x.h.
50 *
51 * 13 1/20/98 4:12p Samir
52 * New script housekeeping system.
53 *
54 * 12 1/19/98 3:48p Samir
55 * Added script parameter support.
56 *
57 * 11 1/19/98 2:44p Samir
58 * Use one script per object and started parameter passing support.
59 *
60 * 10 9/22/97 5:59p Samir
61 * Added a name field to scripts, so we create threads using name instead
62 * of number
63 *
64 * 9 9/10/97 2:01p Samir
65 * Added level type for scripts.
66 *
67 * 8 9/08/97 4:28p Samir
68 * Added script type object support, for specialized trigger/object
69 * scripts. Needed to add type to map file.
70 *
71 * 7 9/02/97 6:11p Samir
72 * Added constant for number of arguments to a script.
73 *
74 * 6 8/21/97 5:55p Samir
75 * Updated map file to store memory usage per script.
76 *
77 * 5 8/12/97 3:27p Samir
78 * Renamed registers to VF (Vector-float)
79 *
80 * 4 8/05/97 6:42p Samir
81 * D3X Script map structure.
82 *
83 * 3 8/05/97 10:47a Samir
84 * Added endscript processing.
85 *
86 * 2 8/04/97 4:21p Samir
87 * Finalized opcodes for D3X processor.
88 *
89 * $NoKeywords: $
90 */
91
92 #ifndef OPCODES_H
93 #define OPCODES_H
94
95 /* This is a list of macro-opcodes */
96
97 /*
98 Memory operations
99 LOAD rx, (ABSOLUTE)
100 LOAD rx, (ADx+IMM)
101 LOAD rx, IMM
102 STORE rx, (ABSOLUTE)
103 STORE rx, (ADx+IMM)
104
105 Math functions
106 ADD rx, rx
107 ADDI rx, rx
108 SUB rx, rx
109 MUL rx, rx
110 DIV rx, rx
111 AND rx, rx
112 MOD rx, rx
113 BAND rx, rx
114 BANDI rx, rx
115 OR rx, rx
116 BOR rx, rx
117 BORI rx, rx
118 EQU rx, rx
119 NEQ rx, rx
120 LT rx, rx
121 LTE rx, rx
122 GT rx, rx
123 GTE rx, rx
124 NEG rx
125 NOT rx
126 ABS rx
127
128 Math vector functions (Vector element extraction)
129 VEX rx, vx
130 VEY rx, vx
131 VEY rx, vx
132 XEV vx, rx
133 YEV vx, rx
134 ZEV vx, rx
135 SCALEV vx, i/fx
136
137 Execution Buffer
138 EPUSH rx
139 EPOP rx
140 PCALL FN
141 CALL ABSOLUTE
142
143 Call Stack Data Operations
144 CPUSH rx
145 CPOP rx
146 TOCSP ADx Transfer ADx reg to CSP reg
147 FROMCSP ADx Transger CSP reg to ADx reg
148 RETURN grabs address from current CSP
149 (return from CALL)
150
151 BRANCHING
152
153 JUMP ABSOLUTE Branch uncoditonally
154 JUMPN ABSOLUTE, rx Jump if rx == 0
155 */
156
157 /*
158 registers
159 ad0, ad1 Address registers
160 i0, i1 Integer registers
161 f0, f1 Float registers
162 v0, v1 Vector registers
163 */
164
165 #define OP_BREAK 0
166 #define OP_LOAD_ABS 1
167 #define OP_LOAD_ADI 2
168 #define OP_LOAD_IMM 3
169 #define OP_LOAD_PARM 4
170 #define OP_STORE_ABS 5
171 #define OP_STORE_ADI 6
172 #define OP_STORE_PARM 7
173 #define OP_ADD 10
174 #define OP_SUB 11
175 #define OP_MUL 12
176 #define OP_DIV 13
177 #define OP_MOD 14
178 #define OP_AND 15
179 #define OP_OR 16
180 #define OP_NEG 17
181 #define OP_NOT 18
182 #define OP_ABS 19
183 #define OP_EQU 20
184 #define OP_NEQ 21
185 #define OP_LT 22
186 #define OP_LTE 23
187 #define OP_GT 24
188 #define OP_GTE 25
189 #define OP_BOR 26
190 #define OP_BAND 27
191 #define OP_VEX 28
192 #define OP_VEY 29
193 #define OP_VEZ 30
194 #define OP_XEV 31
195 #define OP_YEV 32
196 #define OP_ZEV 33
197 #define OP_ADDI 34
198 #define OP_BANDI 35
199 #define OP_BORI 36
200 #define OP_EPUSH 40
201 #define OP_EPOP 41
202 #define OP_PCALL 42
203 #define OP_CALL 43
204 #define OP_CPUSH 44
205 #define OP_CPOP 45
206 #define OP_TOCSP 46
207 #define OP_FROMCSP 47
208 #define OP_RET 48
209 #define OP_DEFER 49
210 #define OP_JUMP_ABS 50
211 #define OP_JUMP_NCOND 51
212
213 #define VFREG_START 0
214 #define VFREG_NUM 16
215 #define REG_VF0 0
216 #define REG_VF1 1
217 #define REG_VF2 2
218 #define REG_VF3 3
219 #define REG_VF4 4
220 #define REG_VF5 5
221 #define REG_VF6 6
222 #define REG_VF7 7
223
224 /* Address registers allow indirect addressing.
225 Ad0 typically accesses local variables from the stack.
226 */
227 #define AREG_START VFREG_START + VFREG_NUM
228 #define AREG_NUM 2
229 #define REG_AD0 0
230 #define REG_AD1 1
231
232 #define MAX_D3X_REGS 32
233
234 struct tD3XInstruction {
235 uint8_t opc; /* Opcode */
236 union {
237 struct /* Register and or immediate */
238 {
239 uint8_t d;
240 union {
241 int i;
242 float f;
243 } imm;
244 } ri;
245 struct /* register <- Address-Immediate indirect addressing */
246 {
247 uint8_t d, a;
248 uint16_t imm;
249 } aii;
250 struct /* jump absolute <- register or jump/call absolute (r = 0xff) */
251 {
252 uint16_t abs;
253 uint8_t r;
254 } ra;
255 struct /* register <- Address-Immediate indirect addressing */
256 {
257 uint8_t d, s;
258 } rr;
259 } opr; /* Operand depends on Opcode */
260 };
261
262 /* Values used for defer opcode */
263 #define DEFER_END 0
264 #define DEFER_DEFAULT 1
265
266 /* Values defined for type of object the 'me' or 'it' variable will be */
267 #define REF_OBJTYPE 0
268 #define REF_TRIGTYPE 1
269 #define REF_LEVELTYPE 2
270 #define REF_GAMEMODE 3
271
272 /* parameter types for scripts */
273 #define PARMTYPE_NUMBER 0
274 #define PARMTYPE_VECTOR 1
275 #define PARMTYPE_REF 2
276 #define PARMTYPE_STRREF 3
277
278 /* Offsets into call stack which contain the passed arguments to a script
279 SCRARG_NUM = number of arguments of script (including event arguments)
280 */
281 #define SCRARG_NUM 4
282 #define SCRARG_EVENT 0
283 #define SCRARG_ME 1
284 #define SCRARG_ITTYPE 2
285 #define SCRARG_IT 3
286 #define EVTARG_NUM 8
287 #define SCRSTACK_START SCRARG_NUM + EVTARG_NUM
288
289 /* Program map entry */
290 #define MAX_D3XID_NAME 32
291
292 struct tD3XPMap {
293 char name[MAX_D3XID_NAME];
294 uint16_t ip;
295 uint16_t mem;
296 uint16_t type;
297 uint16_t parms;
298 };
299
300 #define D3X_TAG "D3X5"
301
302 #endif