|
| 1 | +/*====================================================================================================================== |
| 2 | + * Copyright © 2023 PeriBooty and Contributors |
| 3 | + * |
| 4 | + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated |
| 5 | + * documentation files (the “Software”), to deal in the Software without restriction, including without limitation the |
| 6 | + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to |
| 7 | + * permit persons to whom the Software is furnished to do so, subject to the following conditions: |
| 8 | + * |
| 9 | + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the |
| 10 | + * Software. |
| 11 | + * |
| 12 | + * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE |
| 13 | + * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS |
| 14 | + * OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
| 15 | + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 16 | + *====================================================================================================================*/ |
| 17 | +#ifndef LIBDIANNEX_DXINSTRUCTIONS_HPP |
| 18 | +#define LIBDIANNEX_DXINSTRUCTIONS_HPP |
| 19 | + |
| 20 | +namespace diannex |
| 21 | +{ |
| 22 | + enum class [[maybe_unused]] DxOpcode : unsigned char |
| 23 | + { |
| 24 | + nop = 0x00, // No-op |
| 25 | + |
| 26 | + freeloc = 0x0A, // Frees a local variable from the stack frame (IF IT EXISTS!): [ID] |
| 27 | + |
| 28 | + // Special register instructions |
| 29 | + save = 0x0B, // Copy the value on the top of the stack into the save register |
| 30 | + load = 0x0C, // Push the value from the save register onto the top of the stack |
| 31 | + |
| 32 | + // Stack instructions |
| 33 | + pushu = 0x0F, // Push undefined value to stack |
| 34 | + pushi = 0x10, // Push 32-bit int: [int value] |
| 35 | + pushd = 0x11, // Push 64-bit floating point: [double value] |
| 36 | + |
| 37 | + pushs = 0x12, // Push external string: [index] |
| 38 | + pushints = 0x13, // Push external interpolated string: [index, expr count] |
| 39 | + pushbs = 0x14, // Push internal binary string: [ID] |
| 40 | + pushbints = 0x15, // Push internal binary interpolated string: [ID, expr count] |
| 41 | + |
| 42 | + makearr = 0x16, // Construct an array based off of stack: [size] |
| 43 | + pusharrind = 0x17, // Extract a single value out of an array, removing the array as well (uses stack for index) |
| 44 | + setarrind = 0x18, // Sets a value in an array on the top of the stack (uses stack for index and value) |
| 45 | + |
| 46 | + setvarglb = 0x19, // Set a global variable from the stack: [string name] |
| 47 | + setvarloc = 0x1A, // Set a local variable from the stack: [ID] |
| 48 | + pushvarglb = 0x1B, // Pushes a global variable to the stack: [string name] |
| 49 | + pushvarloc = 0x1C, // Pushes a local variable to the stack: [ID] |
| 50 | + |
| 51 | + pop = 0x1D, // Discards the value on the top of the stack |
| 52 | + dup = 0x1E, // Duplicates the value on the top of the stack |
| 53 | + dup2 = 0x1F, // Duplicates the values on the top two slots of the stack |
| 54 | + |
| 55 | + // Operators |
| 56 | + add = 0x20, // Adds the two values on the top of the stack, popping them, pushing the result |
| 57 | + sub = 0x21, // ditto, subtracts |
| 58 | + mul = 0x22, // ditto, multiplies |
| 59 | + div = 0x23, // ditto, divides |
| 60 | + mod = 0x24, // ditto, modulo |
| 61 | + neg = 0x25, // Negates the value on the top of the stack, popping it, pushing the result |
| 62 | + inv = 0x26, // ditto, but inverts a boolean |
| 63 | + |
| 64 | + bitls = 0x27, // Peforms bitwise left-shift using the top two values of stack, popping them, pushing the result |
| 65 | + bitrs = 0x28, // ditto, right-shift |
| 66 | + _bitand = 0x29, // ditto, and |
| 67 | + _bitor = 0x2A, // ditto, or |
| 68 | + bitxor = 0x2B, // ditto, xor |
| 69 | + bitneg = 0x2C, // ditto, negate (~) |
| 70 | + |
| 71 | + pow = 0x2D, // Power binary operation using top two values of stack |
| 72 | + |
| 73 | + cmpeq = 0x30, // Compares the top two values of stack to check if they are equal, popping them, pushing the result |
| 74 | + cmpgt = 0x31, // ditto, greater than |
| 75 | + cmplt = 0x32, // ditto, less than |
| 76 | + cmpgte = 0x33, // ditto, greater than or equal |
| 77 | + cmplte = 0x34, // ditto, less than or equal |
| 78 | + cmpneq = 0x35, // ditto, not equal |
| 79 | + |
| 80 | + // Control flow |
| 81 | + j = 0x40, // Jumps to an instruction [int relative address] |
| 82 | + jt = 0x41, // ditto, but if the value on the top of the stack is truthy (which it pops off) |
| 83 | + jf = 0x42, // ditto, but if the value on the top of the stack is NOT truthy (which it pops off) |
| 84 | + exit = 0x43, // Exits the current stack frame |
| 85 | + ret = 0x44, // Exits the current stack frame, returning a value (from the stack, popping it off) |
| 86 | + call = 0x45, // Calls a function defined in the code [ID, int parameter count] |
| 87 | + callext = 0x46, // Calls a function defined by a game [string name, int parameter count] |
| 88 | + |
| 89 | + choicebeg = 0x47, // Switches to the choice state in the interpreter- no other choices can run and |
| 90 | + // only one textrun can execute until after choicesel is executed |
| 91 | + choiceadd = 0x48, // Adds a choice, using the stack for the text and the % chance of appearing [int relative jump address] |
| 92 | + choiceaddt = 0x49, // ditto, but also if an additional stack value is truthy [int relative jump address] |
| 93 | + choicesel = 0x4A, // Pauses the interpreter, waiting for user input to select one of the choices, then jumps to one of them, resuming |
| 94 | + |
| 95 | + chooseadd = 0x4B, // Adds a new address to one of the possible next statements, using stack for chances [int relative jump address] (to the current stack frame) |
| 96 | + chooseaddt = 0x4C, // ditto, but also if an additional stack value is truthy [int relative jump address] |
| 97 | + choosesel = 0x4D, // Jumps to one of the choices, using the addresses and chances/requirement values on the stack |
| 98 | + |
| 99 | + textrun = 0x4E, // Pauses the interpreter, running a line of text from the stack |
| 100 | + }; |
| 101 | +} |
| 102 | + |
| 103 | +#endif //LIBDIANNEX_DXINSTRUCTIONS_HPP |
0 commit comments