Advertisement
Shiska

wait

Jun 24th, 2012
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 5.46 KB | None | 0 0
  1. // Nero_3D
  2.  
  3. /*
  4. native wait(time);
  5. */
  6.  
  7. // With SetTimerEx
  8. // Some variables gets changed while passing the stack to SetTimerEx
  9. // Reason unknown !
  10.  
  11. forward WakeEx(stack[], count, offset, address);
  12. public WakeEx(stack[], count, offset, address) {
  13.     // storing current frame
  14.     new
  15.         frame
  16.     ;
  17.     // recreating stack
  18.     while(count-- != 1) {
  19.         #emit load.s.alt stack
  20.         #emit load.s.pri count
  21.         #emit shl.c.pri 2
  22.         #emit add
  23.         #emit stor.s.pri frame
  24.         #emit lref.s.pri frame
  25.         #emit push.pri
  26.     }
  27.     // getting first frame
  28.     #emit lctrl 4 // stack
  29.     #emit load.s.alt offset
  30.     #emit add
  31.     #emit stor.s.pri frame
  32.     #emit stor.s.pri count
  33.     // setting the frame pointer to the new stack
  34.     for( ; ; ) {
  35.         #emit lref.s.pri count
  36.         #emit stor.s.pri offset
  37.  
  38.         if(offset == 0) {
  39.             break;
  40.         } else {
  41.             #emit load.s.pri offset
  42.             #emit load.s.alt count
  43.             #emit add
  44.             #emit stor.i
  45.             #emit stor.s.pri count
  46.         }
  47.     }
  48.     // setting the pointers
  49.     #emit load.s.alt count
  50.     #emit lctrl 5 // frame
  51.     #emit stor.i
  52.     #emit const.pri 4
  53.     #emit add
  54.     #emit move.alt
  55.     #emit lctrl 6 // cip
  56.     #emit add.c 48 // 12
  57.     #emit stor.i
  58.     // setting new frame and jumping back into the code
  59.     #emit load.s.pri frame
  60.     #emit load.s.alt address
  61.     #emit sctrl 5 // frame
  62.     #emit move.pri
  63.     #emit sctrl 6 // cip
  64.     // code will return here
  65. }
  66.  
  67. stock wait(time) {
  68.     new
  69.         current,
  70.         offset,
  71.         count,
  72.         end
  73.     ;
  74.     // getting the stack value before this function
  75.     #emit lctrl 4 // stack
  76.     #emit add.c 32 // 4 vars + 2 pointers + byte + 1 parameter
  77.     #emit stor.s.pri current
  78.     // getting the frame offset
  79.     #emit load.s.alt 0
  80.     #emit sub.alt
  81.     #emit stor.s.pri offset
  82.     // prepare loop
  83.     #emit load.s.pri 0
  84.     #emit stor.s.pri count
  85.     // looping through the frames
  86.     for( ; ; ) {
  87.         // saving the byte offset
  88.         #emit load.s.pri count
  89.         #emit stor.s.pri end
  90.         #emit load.i
  91.         #emit stor.s.pri count
  92.  
  93.         if(count == 0) {
  94.             break;
  95.         } else {
  96.             #emit load.s.pri count
  97.             #emit load.s.alt end
  98.             #emit sub
  99.             #emit stor.i
  100.         }
  101.     }
  102.     // getting last value to save
  103.     #emit load.s.pri end
  104.     #emit add.c 8
  105.     #emit move.alt
  106.     #emit load.i
  107.     #emit add
  108.     #emit add.c 4
  109.     #emit stor.s.pri end
  110.     // getting count
  111.     #emit load.s.alt current
  112.     #emit sub
  113.     #emit shr.c.pri 2
  114.     #emit stor.s.pri count
  115.     // static
  116.     static const
  117.         func[] = "WakeEx",
  118.         form[] = "aiii"
  119.     ;
  120.     // pushing one more cell
  121.     // because the first cell always gets changed to 1000
  122.     // but it doesnt happen within this function, checked
  123.     count += 1;
  124.     current -= 4;
  125.     // calling the timer
  126.     #emit push.adr 4
  127.     #emit push.adr offset
  128.     #emit push.adr count
  129.     #emit push.s current
  130.     #emit push.c form
  131.     #emit push.c 0
  132.     #emit push.s time
  133.     #emit push.c func
  134.     #emit push.c 32
  135.     #emit sysreq.c SetTimerEx
  136.     // resetting stack
  137.     #emit load.s.pri end
  138.     #emit sctrl 4 // stack
  139.     // change to pointers to zero
  140.     #emit zero.pri
  141.     #emit sctrl 5 // frame
  142.     #emit sctrl 6 // cip
  143.     // end
  144. }
  145.  
  146. // This one works with a global variable
  147. // Therefore its limited to it
  148. // But this works flawless
  149.  
  150. /*
  151. new
  152.     gStack[64]
  153. ;
  154.  
  155. forward WakeEx(count, offset, address);
  156. public WakeEx(count, offset, address) {
  157.     // storing current frame
  158.     new
  159.         frame
  160.     ;
  161.     // recreating stack
  162.     while(count--) {
  163.         #emit const.alt gStack
  164.         #emit load.s.pri count
  165.         #emit lidx
  166.         #emit push.pri
  167.     }
  168.     // getting first frame
  169.     #emit lctrl 4 // stack
  170.     #emit load.s.alt offset
  171.     #emit add
  172.     #emit stor.s.pri frame
  173.     #emit stor.s.pri count
  174.     // setting the frame pointer to the new stack
  175.     for( ; ; ) {
  176.         #emit lref.s.pri count
  177.         #emit stor.s.pri offset
  178.  
  179.         if(offset == 0) {
  180.             break;
  181.         } else {
  182.             #emit load.s.pri offset
  183.             #emit load.s.alt count
  184.             #emit add
  185.             #emit stor.i
  186.             #emit stor.s.pri count
  187.         }
  188.     }
  189.     // setting the pointers
  190.     #emit load.s.alt count
  191.     #emit lctrl 5 // frame
  192.     #emit stor.i
  193.     #emit const.pri 4
  194.     #emit add
  195.     #emit move.alt
  196.     #emit lctrl 6 // cip
  197.     #emit add.c 48 // 12
  198.     #emit stor.i
  199.     // setting new frame and jumping back into the code
  200.     #emit load.s.pri frame
  201.     #emit load.s.alt address
  202.     #emit sctrl 5 // frame
  203.     #emit move.pri
  204.     #emit sctrl 6 // cip
  205.     // code will return here
  206. }
  207.  
  208. stock wait(time) {
  209.     new
  210.         current,
  211.         offset,
  212.         count,
  213.         end
  214.     ;
  215.     // getting the stack value before this function
  216.     #emit lctrl 4 // stack
  217.     #emit add.c 32 // 4 vars + 2 pointers + byte + 1 parameter
  218.     #emit stor.s.pri current
  219.     // getting the frame offset
  220.     #emit load.s.alt 0
  221.     #emit sub.alt
  222.     #emit stor.s.pri offset
  223.     // prepare loop
  224.     #emit load.s.pri 0
  225.     #emit stor.s.pri count
  226.     // looping through the frames
  227.     for( ; ; ) {
  228.         // saving the byte offset
  229.         #emit load.s.pri count
  230.         #emit stor.s.pri end
  231.         #emit load.i
  232.         #emit stor.s.pri count
  233.  
  234.         if(count == 0) {
  235.             break;
  236.         } else {
  237.             #emit load.s.pri count
  238.             #emit load.s.alt end
  239.             #emit sub
  240.             #emit stor.i
  241.         }
  242.     }
  243.     // adding the parameters
  244.     #emit load.s.pri end
  245.     #emit add.c 8
  246.     #emit move.alt
  247.     #emit load.i
  248.     #emit add
  249.     #emit add.c 4
  250.     #emit stor.s.pri end
  251.     // storing the whole stack into the heap
  252.     while(current < end) {
  253.         #emit const.pri gStack
  254.         #emit load.s.alt count
  255.         #emit shl.c.alt 2
  256.         #emit add
  257.         #emit move.alt
  258.         #emit lref.s.pri current
  259.         #emit stor.i
  260.  
  261.         current += 4;
  262.         count++;
  263.     }
  264.     // getting the return
  265.     #emit load.s.pri 4
  266.     #emit stor.s.pri current
  267.     // resetting stack
  268.     #emit load.s.pri end
  269.     #emit sctrl 4 // stack
  270.     // calling the timer
  271.     SetTimerEx("WakeEx", time, false, "iii", count, offset, current);
  272.     // change to pointers to zero
  273.     #emit zero.pri
  274.     #emit sctrl 5 // frame
  275.     #emit sctrl 6 // cip
  276.     // end
  277. }
  278. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement