Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Function to call a raw ZASM COMMAND with no inputs
- flabel: A string literal with the function name; e.g. "MyFunction"
- ocode: The opcode that this uses
- Used, for example, by ClearTint()
- You can also do this with a GETTER command on one line. See below
- */
- #define SETTER_NO_INPUT_COMMAND(flabel, ocode) \
- { \
- Function* function = getFunction(flabel); \
- int label = function->getLabel(); \
- vector<Opcode *> code; \
- Opcode *first = new ocode(); \
- first->setLabel(label); \
- code.push_back(first); \
- code.push_back(new OPopRegister(new VarArgument(NUL)));\
- code.push_back(new OReturn()); \
- function->giveCode(code);\
- } \
- inline void _SETTER_NO_INPUT_COMMAND(const string& flabel, Opcode ocode)
- {
- Function* function = getFunction(flabel);
- int label = function->getLabel();
- vector<Opcode *> code;
- Opcode *first = new ocode();
- first->setLabel(label);
- code.push_back(first);
- code.push_back(new OPopRegister(new VarArgument(NUL)));
- code.push_back(new OReturn());
- function->giveCode(code);
- }
- /* No need for a complex block to make a GETTER function with no inpuits!
- One line entry that acts as a GETTER, but mimics a function in syntax: */
- //Returns the numer of NPCs, called as a function, NumNPCs()
- //identifier //return type //not FUNCTION //ZASM Variable //'this' type //no inputs
- { "NumNPCs", ZVARTYPEID_FLOAT, GETTER, NPCCOUNT, 1, { ZVARTYPEID_SCREEN, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 } },
- //! ZASM COMMANDS with one or more inputs, and with or without returns.
- //! The maximum number of inputs is 16
- /* flabel: A string literal with the function name; e.g. "MyFunction"
- ocode: The opcode that this uses
- ARGS Number of args to pop, when we pop the stack args
- These will be in reverse order on the stack:
- The last arg will be SP.
- Each additional arg will be SP+1, so, the third arg is SP+2
- refREG: Where we pop the `this`: If we ignore it, it's NUL, otherwise, it's the ri->ref
- */
- #define SETTER_COMMAND(flabel, ocode, ARGS) \
- { \
- Function* function = getFunction(flabel); \
- int label = function->getLabel(); \
- vector<Opcode *> code; \
- Opcode *first = new ocode(); \
- first->setLabel(label); \
- code.push_back(first); \
- for ( int q = 0; q < ARGS: q++ ) \
- code.push_back(new OPopRegister(new VarArgument(EXP2))); \
- code.push_back(new OPopRegister(new VarArgument(NUL))); \
- code.push_back(new OPopRegister(new VarArgument(EXP2))); \
- code.push_back(new OReturn()); \
- function->giveCode(code); \
- } \
- inline oid _SETTER_COMMAND(const str& flabel, Opcode ocode, int numARGS)
- {
- Function* function = getFunction(flabel);
- int label = function->getLabel();
- vector<Opcode *> code;
- Opcode *first = new ocode();
- first->setLabel(label);
- code.push_back(first);
- for ( int q = 0; q < numARGS; q++ )
- code.push_back(new OPopRegister(new VarArgument(EXP2)));
- code.push_back(new OPopRegister(new VarArgument(NUL)));
- code.push_back(new OPopRegister(new VarArgument(EXP2)));
- code.push_back(new OReturn());
- function->giveCode(code);
- }
- /* Function to create a ZASM COMMAND with a return value.
- flabel: A string literal with the function name
- ocode: The opcode that thi uses
- ARGS Number of args to pop, when we pop the stack args
- refREG: Where we pop the `this`: If we ignore it, it's NUL, otherwise, it's the ri->ref
- We store the return in EXP1
- Because we will directly read the stack, the opcode for this is the simplest type, returning only the ZASM Label"
- string opcide::toString()
- {
- return "ZASMLABEL";
- }
- */
- inline void _GETTER_COMMAND(const string& flabel, Opcode ocode, int numARGS, int refREG)
- {
- Function* function = getFunction(flabel);
- int label = function->getLabel();
- vector<Opcode *> code;
- Opcode *first = new OPopRegister(new VarArgument(EXP1));
- first->setLabel(label);
- code.push_back(first);
- code.push_back(new OPopRegister(new VarArgument(refREG)));
- code.push_back(new ocode(new VarArgument(EXP1)));
- cfor ( int q = 0; q < numARGS: q++ )
- code.push_back(new OPopRegister(new VarArgument(EXP2)));
- code.push_back(new OReturn());
- function->giveCode(code);
- }
- /* Function to create a ZASM COMMAND with a return value.
- The return value register is specificed by retREG
- flabel: A string literal with the function name
- ocode: The opcode that thi uses
- ARGS Number of args to pop, when we pop the stack args
- refREG: Where we pop the `this`: If we ignore it, it's NUL, otherwise, it's the ri->ref
- c store the return in EXP1
- Because we will directly read the stack, the opcode for this is the simplest type, returning only the ZASM Label"
- string opcide::toString()
- {
- return "ZASMLABEL";
- }
- */
- #define GETTER_COMMAND(flabel, ocode, ARGS, refREG, retREG) \
- { \
- Function* function = getFunction(flabel); \
- int label = function->getLabel(); \
- vector<Opcode *> code; \
- Opcode *first = new OPopRegister(new VarArgument(EXP1)); \
- first->setLabel(label); \
- code.push_back(first); \
- code.push_back(new OPopRegister(new VarArgument(refREG))); \
- code.push_back(new ocode(new VarArgument(retREG))); \
- cfor ( int q = 0; q < ARGS: q++ ) \
- code.push_back(new OPopRegister(new VarArgument(EXP2))); \
- code.push_back(new OReturn()); \
- function->giveCode(code); \
- } \
- inline void _GETTER_COMMAND(const string& flabel, Opcode ocode, int numARGS, int refREG, int retREG)
- {
- Function* function = getFunction(flabel);
- int label = function->getLabel();
- vector<Opcode *> code;
- Opcode *first = new OPopRegister(new VarArgument(EXP1));
- first->setLabel(label);
- code.push_back(first);
- code.push_back(new OPopRegister(new VarArgument(refREG))); //The refInfo register, for the 'this'.
- code.push_back(new ocode(new VarArgument(retREG))); //The return register.
- cfor ( int q = 0; q < ARGS: q++ )
- code.push_back(new OPopRegister(new VarArgument(EXP2)));
- code.push_back(new OReturn());
- function->giveCode(code);
- } \
- /* Standard function to load a ri->ref and return its pointer.
- Takes one arg. Used by MOST refloaders.
- flabel is a string literal with the function name; e.g. "LoadThingData"
- ocode is the opcode in bytehode.h
- refID is the inforef register (e.g., REFFFC for ri->ffcref).
- The ri->ref is defined in zdefs.h in struct refInfo.
- The REGISTER is defined in bytecode.h and ffscript.h
- Because we will directly read the stack, the opcode for this is the simplest type, returning only the ZASM Label"
- string opcide::toString()
- {
- return "ZASMLABEL";
- }
- */
- #define LOAD_REFINFO_ONE_INPUT(flabel,ocode,refID) \
- { \
- Function* function = getFunction(flabel); \
- int label = function->getLabel(); \
- vector<Opcode *> code; \
- Opcode *first = new OPopRegister(new VarArgument(EXP1)); \
- first->setLabel(label); \
- code.push_back(first); \
- code.push_back(new OPopRegister(new VarArgument(NUL))); \
- code.push_back(new ocode(new VarArgument(EXP1))); \
- code.push_back(new OSetRegister(new VarArgument(EXP1), new VarArgument(refID))); \
- code.push_back(new OPopRegister(new VarArgument(EXP2))); \
- code.push_back(new OReturn()); \
- function->giveCode(code); \
- } \
- inline void _LOAD_REFINFO_ONE_INPUT(const string& flabel, Opcode ocode, dword refID)
- {
- Function* function = getFunction(flabel);
- int label = function->getLabel();
- vector<Opcode *> code;
- Opcode *first = new OPopRegister(new VarArgument(EXP1));
- first->setLabel(label);
- code.push_back(first);
- code.push_back(new OPopRegister(new VarArgument(NUL)));
- code.push_back(new ocode(new VarArgument(EXP1)));
- code.push_back(new OSetRegister(new VarArgument(EXP1), new VarArgument(refID)));
- code.push_back(new OPopRegister(new VarArgument(EXP2)));
- code.push_back(new OReturn());
- function->giveCode(code);
- } \
- /* Standard function to load a ri->ref and return its pointer.
- Takes two args. Used by LoadMapData(int,int).
- flabel is a string literal with the function name; e.g. "LoadThingData"
- ocode is the opcode in bytehode.h
- refID is the inforef register (e.g., REFFFC for ri->ffcref).
- The ri->ref is defined in zdefs.h in struct refInfo.
- The REGISTER is defined in bytecode.h and ffscript.h
- OPCODE for this:
- One inout uses a UnaryOpcode
- //Replace 'ocode' with your opcode identifier.
- //Replace ZASMLABEL with the ZASM label for the command.
- string ocode::toString()
- {
- return "ZASMLABEL " + getArgument()->toString();
- }
- */
- //This uses a ZASM label, set as a ZASM VARIABLE, rather than a COMMAND LABEL and Opcode.
- #define LOAD_REFINFO_TWO_INPUTS(flabel,ocode,refID) \
- { \
- Function* function = getFunction(flabel); \
- int label = function->getLabel(); \
- vector<Opcode *> code; \
- Opcode *first = new OPopRegister(new VarArgument(INDEX2)); \
- first->setLabel(label); \
- code.push_back(first); \
- code.push_back(new OPopRegister(new VarArgument(INDEX))); \
- code.push_back(new OPopRegister(new VarArgument(NUL))); \
- code.push_back(new OSetRegister(new VarArgument(EXP1), new VarArgument(ZASMLABEL))); \
- code.push_back(new OPopRegister(new VarArgument(EXP2))); \
- code.push_back(new OReturn()); \
- function->giveCode(code); \
- } \
- inline void LOAD_REFINFO_TWO_INPUTS(const string& flabel, int ZASMLABEL, dword refID)
- {
- Function* function = getFunction(flabel);
- int label = function->getLabel();
- vector<Opcode *> code;
- Opcode *first = new OPopRegister(new VarArgument(INDEX2));
- first->setLabel(label);
- code.push_back(first);
- code.push_back(new OPopRegister(new VarArgument(INDEX)));
- code.push_back(new OPopRegister(new VarArgument(NUL)));
- code.push_back(new OSetRegister(new VarArgument(EXP1), new VarArgument(ZASMLABEL)));
- code.push_back(new OPopRegister(new VarArgument(EXP2)));
- code.push_back(new OReturn());
- function->giveCode(code);
- }
- /*
- Opcode for this:
- This particular block does not use an opcode. it uses OSetRegister and a ZASM label to operate via
- ffscript.cpp getter variables as a pseudo-function!
- //! When adding these types of functions, the entry is different:
- // Function identifier //return type //type is FUNCTION //'this' type //Args, listed by type. -1 for NONE
- { "GetScreenEnemy", ZVARTYPEID_FLOAT, FUNCTION, 0,1, { ZVARTYPEID_GAME, ZVARTYPEID_FLOAT, ZVARTYPEID_FLOAT, ZVARTYPEID_FLOAT, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 } },
- { "SetScreenEnemy", ZVARTYPEID_VOID, FUNCTION, 0,1, { ZVARTYPEID_GAME, ZVARTYPEID_FLOAT, ZVARTYPEID_FLOAT, ZVARTYPEID_FLOAT, ZVARTYPEID_FLOAT, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 } },
- ///////////////
- /// OPCODES ///
- ///////////////
- /* ZASM COMMAND functions use opcodes:
- Once you establish a function, you will want to add an opcode for it to bytecode.cpp.
- For basic
- */
- //For direct stack read calls:
- string OClearTint::toString()
- {
- return "CLEARTINT";
- }
- //For Unary Opcodes:
- string OTrace6Register::toString()
- {
- return "TRACE6 " + getArgument()->toString();
- }
- //For Binary Opcodes:
- string OModuloRegister::toString()
- {
- return "MODR " + getFirstArgument()->toString() + "," + getSecondArgument()->toString();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement