Advertisement
ZoriaRPG

Generic GlobalSymbols Command Macros

Oct 21st, 2018
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 12.30 KB | None | 0 0
  1.  
  2. /*  Function to call a raw ZASM COMMAND with no inputs
  3.     flabel: A string literal with the function name; e.g. "MyFunction"
  4.     ocode: The opcode that this uses
  5.     Used, for example, by ClearTint()
  6.    
  7.     You can also do this with a GETTER command on one line. See below
  8. */
  9. #define SETTER_NO_INPUT_COMMAND(flabel, ocode) \
  10. { \
  11.     Function* function = getFunction(flabel); \
  12.     int label = function->getLabel(); \
  13.     vector<Opcode *> code; \
  14.     Opcode *first = new ocode(); \
  15.     first->setLabel(label); \
  16.     code.push_back(first); \
  17.     code.push_back(new OPopRegister(new VarArgument(NUL)));\
  18.     code.push_back(new OReturn()); \
  19.     function->giveCode(code);\
  20. } \
  21.  
  22. inline void _SETTER_NO_INPUT_COMMAND(const string& flabel, Opcode ocode)
  23. {
  24.     Function* function = getFunction(flabel);
  25.     int label = function->getLabel();
  26.     vector<Opcode *> code;
  27.     Opcode *first = new ocode();
  28.     first->setLabel(label);
  29.     code.push_back(first);
  30.     code.push_back(new OPopRegister(new VarArgument(NUL)));
  31.     code.push_back(new OReturn());
  32.     function->giveCode(code);
  33. }
  34.  
  35.  
  36. /* No need for a complex block to make a GETTER function with no inpuits!
  37. One line entry that acts as a GETTER, but mimics a function in syntax: */
  38.  
  39. //Returns the numer of NPCs, called as a function, NumNPCs()
  40.    //identifier     //return type               //not FUNCTION  //ZASM Variable                    //'this' type             //no inputs
  41. { "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                           } },
  42.    
  43.  
  44. //! ZASM COMMANDS with one or more inputs, and with or without returns.
  45. //! The maximum number of inputs is 16
  46.  
  47. /*  flabel: A string literal with the function name; e.g. "MyFunction"
  48.     ocode: The opcode that this uses
  49.     ARGS Number of args to pop, when we pop the stack args
  50.         These will be in reverse order on the stack:
  51.         The last arg will be SP.
  52.         Each additional arg will be SP+1, so, the third arg is SP+2
  53.     refREG: Where we pop the `this`: If we ignore it, it's NUL, otherwise, it's the ri->ref
  54. */
  55. #define SETTER_COMMAND(flabel, ocode, ARGS) \
  56. { \
  57.     Function* function = getFunction(flabel); \
  58.         int label = function->getLabel(); \
  59.         vector<Opcode *> code; \
  60.         Opcode *first = new ocode(); \
  61.         first->setLabel(label); \
  62.         code.push_back(first); \
  63.     for ( int q = 0; q < ARGS: q++ ) \
  64.     code.push_back(new OPopRegister(new VarArgument(EXP2))); \
  65.         code.push_back(new OPopRegister(new VarArgument(NUL))); \
  66.         code.push_back(new OPopRegister(new VarArgument(EXP2))); \
  67.         code.push_back(new OReturn()); \
  68.         function->giveCode(code); \
  69. } \
  70.  
  71. inline oid _SETTER_COMMAND(const str& flabel, Opcode ocode, int numARGS)
  72. {
  73.     Function* function = getFunction(flabel);
  74.         int label = function->getLabel();
  75.         vector<Opcode *> code;
  76.         Opcode *first = new ocode();
  77.         first->setLabel(label);
  78.         code.push_back(first);
  79.     for ( int q = 0; q < numARGS; q++ )
  80.     code.push_back(new OPopRegister(new VarArgument(EXP2)));
  81.         code.push_back(new OPopRegister(new VarArgument(NUL)));
  82.         code.push_back(new OPopRegister(new VarArgument(EXP2)));
  83.         code.push_back(new OReturn());
  84.         function->giveCode(code);
  85. }
  86.    
  87.  
  88. /*  Function to create a ZASM COMMAND with a return value.
  89.     flabel: A string literal with the function name
  90.     ocode: The opcode that thi uses
  91.     ARGS Number of args to pop, when we pop the stack args
  92.     refREG: Where we pop the `this`: If we ignore it, it's NUL, otherwise, it's the ri->ref
  93.     We store the return in EXP1
  94.    
  95.     Because we will directly read the stack, the opcode for this is the simplest type, returning only the ZASM Label"
  96.    
  97.     string opcide::toString()
  98.     {
  99.         return "ZASMLABEL";
  100.     }
  101. */
  102. inline void _GETTER_COMMAND(const string& flabel, Opcode ocode, int numARGS, int refREG)
  103. {
  104.     Function* function = getFunction(flabel);
  105.         int label = function->getLabel();
  106.         vector<Opcode *> code;
  107.         Opcode *first = new OPopRegister(new VarArgument(EXP1));
  108.         first->setLabel(label);
  109.         code.push_back(first);
  110.         code.push_back(new OPopRegister(new VarArgument(refREG)));
  111.         code.push_back(new ocode(new VarArgument(EXP1)));
  112.         cfor ( int q = 0; q < numARGS: q++ )
  113.     code.push_back(new OPopRegister(new VarArgument(EXP2)));
  114.         code.push_back(new OReturn());
  115.         function->giveCode(code);
  116. }
  117.  
  118. /*  Function to create a ZASM COMMAND with a return value.
  119.         The return value register is specificed by retREG
  120.     flabel: A string literal with the function name
  121.     ocode: The opcode that thi uses
  122.     ARGS Number of args to pop, when we pop the stack args
  123.     refREG: Where we pop the `this`: If we ignore it, it's NUL, otherwise, it's the ri->ref
  124.     c store the return in EXP1
  125.    
  126.     Because we will directly read the stack, the opcode for this is the simplest type, returning only the ZASM Label"
  127.    
  128.     string opcide::toString()
  129.     {
  130.         return "ZASMLABEL";
  131.     }
  132. */
  133. #define GETTER_COMMAND(flabel, ocode, ARGS, refREG, retREG) \
  134. { \
  135.     Function* function = getFunction(flabel); \
  136.         int label = function->getLabel(); \
  137.         vector<Opcode *> code; \
  138.         Opcode *first = new OPopRegister(new VarArgument(EXP1)); \
  139.         first->setLabel(label); \
  140.         code.push_back(first); \
  141.         code.push_back(new OPopRegister(new VarArgument(refREG))); \
  142.         code.push_back(new ocode(new VarArgument(retREG))); \
  143.         cfor ( int q = 0; q < ARGS: q++ ) \
  144.     code.push_back(new OPopRegister(new VarArgument(EXP2))); \
  145.         code.push_back(new OReturn()); \
  146.         function->giveCode(code); \
  147. } \
  148.  
  149. inline void _GETTER_COMMAND(const string& flabel, Opcode ocode, int numARGS, int refREG, int retREG)
  150. {
  151.     Function* function = getFunction(flabel);
  152.         int label = function->getLabel();
  153.         vector<Opcode *> code;
  154.         Opcode *first = new OPopRegister(new VarArgument(EXP1));
  155.         first->setLabel(label);
  156.         code.push_back(first);
  157.         code.push_back(new OPopRegister(new VarArgument(refREG))); //The refInfo register, for the 'this'.
  158.         code.push_back(new ocode(new VarArgument(retREG))); //The return register.
  159.         cfor ( int q = 0; q < ARGS: q++ )
  160.     code.push_back(new OPopRegister(new VarArgument(EXP2)));
  161.         code.push_back(new OReturn());
  162.         function->giveCode(code);
  163. } \
  164.  
  165. /*  Standard function to load a ri->ref and return its pointer.
  166.     Takes one arg. Used by MOST refloaders.
  167.     flabel is a string literal with the function name; e.g. "LoadThingData"
  168.     ocode is the opcode in bytehode.h
  169.     refID is the inforef register (e.g., REFFFC for ri->ffcref).
  170.         The ri->ref is defined in zdefs.h in struct refInfo.
  171.         The REGISTER is defined in bytecode.h and ffscript.h
  172.        
  173.     Because we will directly read the stack, the opcode for this is the simplest type, returning only the ZASM Label"
  174.    
  175.     string opcide::toString()
  176.     {
  177.         return "ZASMLABEL";
  178.     }
  179. */
  180. #define LOAD_REFINFO_ONE_INPUT(flabel,ocode,refID) \
  181. { \
  182.     Function* function = getFunction(flabel); \
  183.         int label = function->getLabel(); \
  184.         vector<Opcode *> code; \
  185.         Opcode *first = new OPopRegister(new VarArgument(EXP1)); \
  186.         first->setLabel(label); \
  187.         code.push_back(first); \
  188.         code.push_back(new OPopRegister(new VarArgument(NUL))); \
  189.         code.push_back(new ocode(new VarArgument(EXP1))); \
  190.         code.push_back(new OSetRegister(new VarArgument(EXP1), new VarArgument(refID))); \
  191.         code.push_back(new OPopRegister(new VarArgument(EXP2))); \
  192.         code.push_back(new OReturn()); \
  193.         function->giveCode(code); \
  194. } \
  195.  
  196. inline void _LOAD_REFINFO_ONE_INPUT(const string& flabel, Opcode ocode, dword refID)
  197. {
  198.     Function* function = getFunction(flabel);
  199.         int label = function->getLabel();
  200.         vector<Opcode *> code;
  201.         Opcode *first = new OPopRegister(new VarArgument(EXP1));
  202.         first->setLabel(label);
  203.         code.push_back(first);
  204.         code.push_back(new OPopRegister(new VarArgument(NUL)));
  205.         code.push_back(new ocode(new VarArgument(EXP1)));
  206.         code.push_back(new OSetRegister(new VarArgument(EXP1), new VarArgument(refID)));
  207.         code.push_back(new OPopRegister(new VarArgument(EXP2)));
  208.         code.push_back(new OReturn());
  209.         function->giveCode(code);
  210. } \
  211.  
  212. /*  Standard function to load a ri->ref and return its pointer.
  213.     Takes two args. Used by LoadMapData(int,int).
  214.     flabel is a string literal with the function name; e.g. "LoadThingData"
  215.     ocode is the opcode in bytehode.h
  216.     refID is the inforef register (e.g., REFFFC for ri->ffcref).
  217.     The ri->ref is defined in zdefs.h in struct refInfo.
  218.     The REGISTER is defined in bytecode.h and ffscript.h
  219.    
  220.     OPCODE for this:
  221.     One inout uses a UnaryOpcode
  222.     //Replace 'ocode' with your opcode identifier.
  223.     //Replace ZASMLABEL with the ZASM label for the command.
  224.  
  225.     string ocode::toString()
  226.     {
  227.         return "ZASMLABEL " + getArgument()->toString();
  228.     }
  229. */
  230.  
  231. //This uses a ZASM label, set as a ZASM VARIABLE, rather than a COMMAND LABEL and Opcode.
  232. #define LOAD_REFINFO_TWO_INPUTS(flabel,ocode,refID) \
  233. { \
  234.         Function* function = getFunction(flabel); \
  235.         int label = function->getLabel(); \
  236.         vector<Opcode *> code; \
  237.         Opcode *first = new OPopRegister(new VarArgument(INDEX2)); \
  238.         first->setLabel(label); \
  239.         code.push_back(first); \
  240.         code.push_back(new OPopRegister(new VarArgument(INDEX))); \
  241.         code.push_back(new OPopRegister(new VarArgument(NUL))); \
  242.         code.push_back(new OSetRegister(new VarArgument(EXP1), new VarArgument(ZASMLABEL))); \
  243.         code.push_back(new OPopRegister(new VarArgument(EXP2))); \
  244.          code.push_back(new OReturn()); \
  245.         function->giveCode(code); \
  246. } \
  247.  
  248. inline void LOAD_REFINFO_TWO_INPUTS(const string& flabel, int ZASMLABEL, dword refID)
  249. {
  250.         Function* function = getFunction(flabel);
  251.         int label = function->getLabel();
  252.         vector<Opcode *> code;
  253.         Opcode *first = new OPopRegister(new VarArgument(INDEX2));
  254.         first->setLabel(label);
  255.         code.push_back(first);
  256.         code.push_back(new OPopRegister(new VarArgument(INDEX)));
  257.         code.push_back(new OPopRegister(new VarArgument(NUL)));
  258.         code.push_back(new OSetRegister(new VarArgument(EXP1), new VarArgument(ZASMLABEL)));
  259.         code.push_back(new OPopRegister(new VarArgument(EXP2)));
  260.          code.push_back(new OReturn());
  261.         function->giveCode(code);
  262. }
  263.    
  264.  
  265.  
  266. /*
  267.     Opcode for this:
  268.  
  269.     This particular block does not use an opcode. it uses OSetRegister and a ZASM label to operate via
  270.     ffscript.cpp getter variables as a pseudo-function!
  271.  
  272. //! When adding these types of functions, the entry is different:
  273. // Function identifier   //return type           //type is FUNCTION  //'this' type         //Args, listed by type. -1 for NONE
  274. { "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 } },
  275. { "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 } },
  276.    
  277. ///////////////
  278. /// OPCODES ///
  279. ///////////////
  280. /* ZASM COMMAND functions use opcodes:
  281.  
  282. Once you establish a function, you will want to add an opcode for it to bytecode.cpp.
  283.  
  284. For basic
  285. */
  286.  
  287.  
  288. //For direct stack read calls:
  289. string OClearTint::toString()
  290. {
  291.     return "CLEARTINT";
  292. }
  293.  
  294. //For Unary Opcodes:
  295. string OTrace6Register::toString()
  296. {
  297.     return "TRACE6 " + getArgument()->toString();
  298. }
  299.  
  300. //For Binary Opcodes:
  301.  
  302. string OModuloRegister::toString()
  303. {
  304.     return "MODR " + getFirstArgument()->toString() + "," + getSecondArgument()->toString();
  305. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement