Advertisement
RyDeR_

DynamicParams.inc

Mar 6th, 2012
1,305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.78 KB | None | 0 0
  1. /*
  2.  *  Copyright © 2012-2013 RyDeR`
  3.  *  DynamicParams.inc
  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.  
  19. #if defined _Included_DynamicParams
  20.     #endinput
  21. #else
  22.     #define _Included_DynamicParams
  23. #endif
  24.  
  25. #if !defined MAX_DYNAMIC_PARAMS
  26.     #define MAX_DYNAMIC_PARAMS (16)
  27. #endif
  28.  
  29. enum e_ParamTypes {
  30.     e_TYPE_MIXED,
  31.     e_TYPE_STRING,
  32.     e_TYPE_BYREF
  33. };
  34.  
  35. stock
  36.     g_aiStack[MAX_DYNAMIC_PARAMS],
  37.     g_iIdx
  38. ;
  39.  
  40. stock pushParam(const e_ParamTypes: iParamType, { Float, _ }: ...) {
  41.     if(numargs() == 2) {
  42.         if(g_iIdx < MAX_DYNAMIC_PARAMS) {
  43.             new
  44.                 iAddr
  45.             ;
  46.             #emit CONST.PRI g_aiStack
  47.             #emit LOAD.ALT g_iIdx
  48.             #emit SHL.C.ALT 2
  49.             #emit ADD
  50.             #emit STOR.S.PRI iAddr
  51.            
  52.             switch(iParamType) {
  53.                 case e_TYPE_MIXED: {
  54.                     #emit LOAD.S.ALT iAddr
  55.                     #emit LOAD.S.PRI 16
  56.                     #emit LOAD.I
  57.                     #emit STOR.I
  58.                 }
  59.                 case e_TYPE_STRING, e_TYPE_BYREF: {
  60.                     #emit LOAD.S.ALT iAddr
  61.                     #emit LOAD.S.PRI 16
  62.                     #emit STOR.I
  63.                 }
  64.             }
  65.             g_iIdx++;
  66.            
  67.             return (g_iIdx - 1);
  68.         }
  69.     }
  70.     return -1;
  71. }
  72.  
  73. stock setParam(const e_ParamTypes: iParamType, const iIdx, { Float, _ }: ...) {
  74.     if(numargs() == 3) {
  75.         if(iIdx < MAX_DYNAMIC_PARAMS) {
  76.             new
  77.                 iAddr
  78.             ;
  79.             #emit CONST.PRI g_aiStack
  80.             #emit LOAD.S.ALT iIdx
  81.             #emit SHL.C.ALT 2
  82.             #emit ADD
  83.             #emit STOR.S.PRI iAddr
  84.                
  85.             switch(iParamType) {
  86.                 case e_TYPE_MIXED: {
  87.                     #emit LOAD.S.ALT iAddr
  88.                     #emit LOAD.S.PRI 20
  89.                     #emit LOAD.I
  90.                     #emit STOR.I
  91.                 }
  92.                 case e_TYPE_STRING, e_TYPE_BYREF: {
  93.                     #emit LOAD.S.ALT iAddr
  94.                     #emit LOAD.S.PRI 20
  95.                     #emit STOR.I
  96.                 }
  97.             }
  98.             return iIdx;
  99.         }
  100.     }
  101.     return -1;
  102. }
  103.  
  104. stock popParam() {
  105.     if(g_iIdx > 0) {
  106.         return --g_iIdx;
  107.     }
  108.     return 0;
  109. }
  110.  
  111. stock clearParams() {
  112.     g_iIdx = 0;
  113.    
  114.     return 1;
  115. }
  116.  
  117. stock callFunction(const szName[], const bool: bClear = true) {
  118.     new
  119.         iParam,
  120.         iAddr,
  121.         iIdx = funcidx(szName)
  122.     ;
  123.     // Credits to Slice
  124.     #emit LCTRL 1
  125.     #emit NEG
  126.     #emit MOVE.ALT
  127.     #emit ADD.C 32
  128.     #emit STOR.S.PRI iParam
  129.     #emit LREF.S.PRI iParam
  130.     #emit ADD
  131.     #emit LOAD.S.ALT iIdx
  132.     #emit SHL.C.ALT 3
  133.     #emit ADD
  134.     #emit STOR.S.PRI iParam
  135.     #emit LREF.S.PRI iParam
  136.     #emit STOR.S.PRI iAddr
  137.    
  138.     iIdx = g_iIdx;
  139.    
  140.     while (iIdx--) {
  141.         iParam = g_aiStack[iIdx];
  142.         #emit PUSH.S iParam
  143.     }
  144.     #emit LOAD.PRI g_iIdx
  145.     #emit SHL.C.PRI 2
  146.     #emit PUSH.PRI
  147.    
  148.     if(bClear) {
  149.         clearParams();
  150.     }
  151.     #emit LCTRL 6
  152.     #emit ADD.C 28
  153.     #emit PUSH.PRI
  154.    
  155.     #emit LOAD.S.PRI iAddr
  156.     #emit SCTRL 6
  157.     #emit STACK 12
  158.     #emit RETN
  159.        
  160.     return 0;
  161. }
  162.  
  163. stock callNative(const iNativeIdx, const bool: bClear = true) { // Credits to ZeeX
  164.     new
  165.         iParam,
  166.         iIdx
  167.     ;
  168.     iIdx = g_iIdx;
  169.    
  170.     while(iIdx--) {
  171.         iParam = g_aiStack[iIdx];
  172.         #emit PUSH.S iParam
  173.     }
  174.     #emit LOAD.PRI g_iIdx
  175.     #emit SHL.C.PRI 2
  176.     #emit PUSH.PRI
  177.    
  178.     #emit LCTRL 0
  179.     #emit MOVE.ALT
  180.     #emit LCTRL 6
  181.     #emit ADD
  182.     #emit MOVE.ALT
  183.     #emit LCTRL 1
  184.     #emit SUB.ALT
  185.     #emit ADD.C 56
  186.     #emit STOR.S.PRI iParam
  187.    
  188.     #emit LOAD.S.PRI iNativeIdx
  189.     #emit SREF.S.PRI iParam
  190.    
  191.     #emit SYSREQ.C 0xFFFFFFFF
  192.     #emit STOR.S.PRI iParam
  193.    
  194.     #emit LCTRL 4
  195.     #emit LOAD.ALT g_iIdx
  196.     #emit SHL.C.ALT 2
  197.     #emit ADD
  198.     #emit ADD.C 4
  199.     #emit SCTRL 4
  200.    
  201.     if(bClear) {
  202.         clearParams();
  203.     }
  204.     return iParam;
  205. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement