| 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_Hcxx . . $ `lib/d3x_op.h:93:9`! |
| 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_BREAKcxx . . $ `lib/d3x_op.h:165:9`! 0 |
| 166 | #define OP_LOAD_ABScxx . . $ `lib/d3x_op.h:166:9`! 1 |
| 167 | #define OP_LOAD_ADIcxx . . $ `lib/d3x_op.h:167:9`! 2 |
| 168 | #define OP_LOAD_IMMcxx . . $ `lib/d3x_op.h:168:9`! 3 |
| 169 | #define OP_LOAD_PARMcxx . . $ `lib/d3x_op.h:169:9`! 4 |
| 170 | #define OP_STORE_ABScxx . . $ `lib/d3x_op.h:170:9`! 5 |
| 171 | #define OP_STORE_ADIcxx . . $ `lib/d3x_op.h:171:9`! 6 |
| 172 | #define OP_STORE_PARMcxx . . $ `lib/d3x_op.h:172:9`! 7 |
| 173 | #define OP_ADDcxx . . $ `lib/d3x_op.h:173:9`! 10 |
| 174 | #define OP_SUBcxx . . $ `lib/d3x_op.h:174:9`! 11 |
| 175 | #define OP_MULcxx . . $ `lib/d3x_op.h:175:9`! 12 |
| 176 | #define OP_DIVcxx . . $ `lib/d3x_op.h:176:9`! 13 |
| 177 | #define OP_MODcxx . . $ `lib/d3x_op.h:177:9`! 14 |
| 178 | #define OP_ANDcxx . . $ `lib/d3x_op.h:178:9`! 15 |
| 179 | #define OP_ORcxx . . $ `lib/d3x_op.h:179:9`! 16 |
| 180 | #define OP_NEGcxx . . $ `lib/d3x_op.h:180:9`! 17 |
| 181 | #define OP_NOTcxx . . $ `lib/d3x_op.h:181:9`! 18 |
| 182 | #define OP_ABScxx . . $ `lib/d3x_op.h:182:9`! 19 |
| 183 | #define OP_EQUcxx . . $ `lib/d3x_op.h:183:9`! 20 |
| 184 | #define OP_NEQcxx . . $ `lib/d3x_op.h:184:9`! 21 |
| 185 | #define OP_LTcxx . . $ `lib/d3x_op.h:185:9`! 22 |
| 186 | #define OP_LTEcxx . . $ `lib/d3x_op.h:186:9`! 23 |
| 187 | #define OP_GTcxx . . $ `lib/d3x_op.h:187:9`! 24 |
| 188 | #define OP_GTEcxx . . $ `lib/d3x_op.h:188:9`! 25 |
| 189 | #define OP_BORcxx . . $ `lib/d3x_op.h:189:9`! 26 |
| 190 | #define OP_BANDcxx . . $ `lib/d3x_op.h:190:9`! 27 |
| 191 | #define OP_VEXcxx . . $ `lib/d3x_op.h:191:9`! 28 |
| 192 | #define OP_VEYcxx . . $ `lib/d3x_op.h:192:9`! 29 |
| 193 | #define OP_VEZcxx . . $ `lib/d3x_op.h:193:9`! 30 |
| 194 | #define OP_XEVcxx . . $ `lib/d3x_op.h:194:9`! 31 |
| 195 | #define OP_YEVcxx . . $ `lib/d3x_op.h:195:9`! 32 |
| 196 | #define OP_ZEVcxx . . $ `lib/d3x_op.h:196:9`! 33 |
| 197 | #define OP_ADDIcxx . . $ `lib/d3x_op.h:197:9`! 34 |
| 198 | #define OP_BANDIcxx . . $ `lib/d3x_op.h:198:9`! 35 |
| 199 | #define OP_BORIcxx . . $ `lib/d3x_op.h:199:9`! 36 |
| 200 | #define OP_EPUSHcxx . . $ `lib/d3x_op.h:200:9`! 40 |
| 201 | #define OP_EPOPcxx . . $ `lib/d3x_op.h:201:9`! 41 |
| 202 | #define OP_PCALLcxx . . $ `lib/d3x_op.h:202:9`! 42 |
| 203 | #define OP_CALLcxx . . $ `lib/d3x_op.h:203:9`! 43 |
| 204 | #define OP_CPUSHcxx . . $ `lib/d3x_op.h:204:9`! 44 |
| 205 | #define OP_CPOPcxx . . $ `lib/d3x_op.h:205:9`! 45 |
| 206 | #define OP_TOCSPcxx . . $ `lib/d3x_op.h:206:9`! 46 |
| 207 | #define OP_FROMCSPcxx . . $ `lib/d3x_op.h:207:9`! 47 |
| 208 | #define OP_RETcxx . . $ `lib/d3x_op.h:208:9`! 48 |
| 209 | #define OP_DEFERcxx . . $ `lib/d3x_op.h:209:9`! 49 |
| 210 | #define OP_JUMP_ABScxx . . $ `lib/d3x_op.h:210:9`! 50 |
| 211 | #define OP_JUMP_NCONDcxx . . $ `lib/d3x_op.h:211:9`! 51 |
| 212 | |
| 213 | #define VFREG_STARTcxx . . $ `lib/d3x_op.h:213:9`! 0 |
| 214 | #define VFREG_NUMcxx . . $ `lib/d3x_op.h:214:9`! 16 |
| 215 | #define REG_VF0cxx . . $ `lib/d3x_op.h:215:9`! 0 |
| 216 | #define REG_VF1cxx . . $ `lib/d3x_op.h:216:9`! 1 |
| 217 | #define REG_VF2cxx . . $ `lib/d3x_op.h:217:9`! 2 |
| 218 | #define REG_VF3cxx . . $ `lib/d3x_op.h:218:9`! 3 |
| 219 | #define REG_VF4cxx . . $ `lib/d3x_op.h:219:9`! 4 |
| 220 | #define REG_VF5cxx . . $ `lib/d3x_op.h:220:9`! 5 |
| 221 | #define REG_VF6cxx . . $ `lib/d3x_op.h:221:9`! 6 |
| 222 | #define REG_VF7cxx . . $ `lib/d3x_op.h:222:9`! 7 |
| 223 | |
| 224 | /* Address registers allow indirect addressing. |
| 225 | Ad0 typically accesses local variables from the stack. |
| 226 | */ |
| 227 | #define AREG_STARTcxx . . $ `lib/d3x_op.h:227:9`! VFREG_START + VFREG_NUM |
| 228 | #define AREG_NUMcxx . . $ `lib/d3x_op.h:228:9`! 2 |
| 229 | #define REG_AD0cxx . . $ `lib/d3x_op.h:229:9`! 0 |
| 230 | #define REG_AD1cxx . . $ `lib/d3x_op.h:230:9`! 1 |
| 231 | |
| 232 | #define MAX_D3X_REGScxx . . $ `lib/d3x_op.h:232:9`! 32 |
| 233 | |
| 234 | struct tD3XInstructioncxx . . $ tD3XInstruction# { |
| 235 | uint8_tcxx . . $ uint8_t# opccxx . . $ tD3XInstruction#opc.; /* Opcode */ |
| 236 | unioncxx . . $ tD3XInstruction#$anonymous_type_0# { |
| 237 | structcxx . . $ tD3XInstruction#$anonymous_type_0#$anonymous_type_1# /* Register and or immediate */ |
| 238 | { |
| 239 | uint8_tcxx . . $ uint8_t# dcxx . . $ tD3XInstruction#$anonymous_type_0#$anonymous_type_1#d.; |
| 240 | unioncxx . . $ tD3XInstruction#$anonymous_type_0#$anonymous_type_1#$anonymous_type_2# { |
| 241 | int icxx . . $ tD3XInstruction#$anonymous_type_0#$anonymous_type_1#$anonymous_type_2#i.; |
| 242 | float fcxx . . $ tD3XInstruction#$anonymous_type_0#$anonymous_type_1#$anonymous_type_2#f.; |
| 243 | } immcxx . . $ tD3XInstruction#$anonymous_type_0#$anonymous_type_1#imm.; |
| 244 | } ricxx . . $ tD3XInstruction#$anonymous_type_0#ri.; |
| 245 | structcxx . . $ tD3XInstruction#$anonymous_type_0#$anonymous_type_3# /* register <- Address-Immediate indirect addressing */ |
| 246 | { |
| 247 | uint8_tcxx . . $ uint8_t# dcxx . . $ tD3XInstruction#$anonymous_type_0#$anonymous_type_3#d., acxx . . $ tD3XInstruction#$anonymous_type_0#$anonymous_type_3#a.; |
| 248 | uint16_tcxx . . $ uint16_t# immcxx . . $ tD3XInstruction#$anonymous_type_0#$anonymous_type_3#imm.; |
| 249 | } aiicxx . . $ tD3XInstruction#$anonymous_type_0#aii.; |
| 250 | structcxx . . $ tD3XInstruction#$anonymous_type_0#$anonymous_type_4# /* jump absolute <- register or jump/call absolute (r = 0xff) */ |
| 251 | { |
| 252 | uint16_tcxx . . $ uint16_t# abscxx . . $ tD3XInstruction#$anonymous_type_0#$anonymous_type_4#abs.; |
| 253 | uint8_tcxx . . $ uint8_t# rcxx . . $ tD3XInstruction#$anonymous_type_0#$anonymous_type_4#r.; |
| 254 | } racxx . . $ tD3XInstruction#$anonymous_type_0#ra.; |
| 255 | structcxx . . $ tD3XInstruction#$anonymous_type_0#$anonymous_type_5# /* register <- Address-Immediate indirect addressing */ |
| 256 | { |
| 257 | uint8_tcxx . . $ uint8_t# dcxx . . $ tD3XInstruction#$anonymous_type_0#$anonymous_type_5#d., scxx . . $ tD3XInstruction#$anonymous_type_0#$anonymous_type_5#s.; |
| 258 | } rrcxx . . $ tD3XInstruction#$anonymous_type_0#rr.; |
| 259 | } oprcxx . . $ tD3XInstruction#opr.; /* Operand depends on Opcode */ |
| 260 | }; |
| 261 | |
| 262 | /* Values used for defer opcode */ |
| 263 | #define DEFER_ENDcxx . . $ `lib/d3x_op.h:263:9`! 0 |
| 264 | #define DEFER_DEFAULTcxx . . $ `lib/d3x_op.h:264:9`! 1 |
| 265 | |
| 266 | /* Values defined for type of object the 'me' or 'it' variable will be */ |
| 267 | #define REF_OBJTYPEcxx . . $ `lib/d3x_op.h:267:9`! 0 |
| 268 | #define REF_TRIGTYPEcxx . . $ `lib/d3x_op.h:268:9`! 1 |
| 269 | #define REF_LEVELTYPEcxx . . $ `lib/d3x_op.h:269:9`! 2 |
| 270 | #define REF_GAMEMODEcxx . . $ `lib/d3x_op.h:270:9`! 3 |
| 271 | |
| 272 | /* parameter types for scripts */ |
| 273 | #define PARMTYPE_NUMBERcxx . . $ `lib/d3x_op.h:273:9`! 0 |
| 274 | #define PARMTYPE_VECTORcxx . . $ `lib/d3x_op.h:274:9`! 1 |
| 275 | #define PARMTYPE_REFcxx . . $ `lib/d3x_op.h:275:9`! 2 |
| 276 | #define PARMTYPE_STRREFcxx . . $ `lib/d3x_op.h:276:9`! 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_NUMcxx . . $ `lib/d3x_op.h:281:9`! 4 |
| 282 | #define SCRARG_EVENTcxx . . $ `lib/d3x_op.h:282:9`! 0 |
| 283 | #define SCRARG_MEcxx . . $ `lib/d3x_op.h:283:9`! 1 |
| 284 | #define SCRARG_ITTYPEcxx . . $ `lib/d3x_op.h:284:9`! 2 |
| 285 | #define SCRARG_ITcxx . . $ `lib/d3x_op.h:285:9`! 3 |
| 286 | #define EVTARG_NUMcxx . . $ `lib/d3x_op.h:286:9`! 8 |
| 287 | #define SCRSTACK_STARTcxx . . $ `lib/d3x_op.h:287:9`! SCRARG_NUM + EVTARG_NUM |
| 288 | |
| 289 | /* Program map entry */ |
| 290 | #define MAX_D3XID_NAMEcxx . . $ `lib/d3x_op.h:290:9`! 32 |
| 291 | |
| 292 | struct tD3XPMapcxx . . $ tD3XPMap# { |
| 293 | char namecxx . . $ tD3XPMap#name.[MAX_D3XID_NAMEcxx . . $ `lib/d3x_op.h:290:9`!]; |
| 294 | uint16_tcxx . . $ uint16_t# ipcxx . . $ tD3XPMap#ip.; |
| 295 | uint16_tcxx . . $ uint16_t# memcxx . . $ tD3XPMap#mem.; |
| 296 | uint16_tcxx . . $ uint16_t# typecxx . . $ tD3XPMap#type.; |
| 297 | uint16_tcxx . . $ uint16_t# parmscxx . . $ tD3XPMap#parms.; |
| 298 | }; |
| 299 | |
| 300 | #define D3X_TAGcxx . . $ `lib/d3x_op.h:300:9`! "D3X5" |
| 301 | |
| 302 | #endif |