Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.58 KB | None | 0 0
  1. #include "common.h"
  2. #include "event.h"
  3.  
  4. void CheckAlloc(void *n)
  5. /* Check if an allocation completed successfully */
  6. {
  7.     if(n == NULL)
  8.     /* Failed! */
  9.     {
  10.         exit(1);
  11.         /* Exit with err num 1 */
  12.     }
  13. }
  14.  
  15. void DoNothing(void *n)
  16. /* Just an ugly wordaround to remove some warnings */
  17. {
  18.     State *s;
  19.     s = (State *)n;
  20.     s -> nothing = 0;
  21. }
  22.  
  23. /*int returnmode()
  24. {
  25.     return 3;
  26. }*/
  27.  
  28. void InitGraph(void *n)
  29. /* Function to init graphics driver */
  30. {
  31.     int gd = VGA, gm = VGAMED;
  32.     /* Use VGAMED for setvisualpage & setactivepage */
  33.     //installuserdriver("svga256", returnmode);
  34.     initgraph(&gd, &gm, "");
  35.     cleardevice();
  36.     DoNothing(n);
  37. }
  38.  
  39. void ClearGraph(void *n)
  40. /* Function to clear screen */
  41. {
  42.     DoNothing(n);
  43.     cleardevice();
  44. }
  45.  
  46. void FREEMEMRow(Row *row)
  47. /* Release all the memory that used by a row */
  48. {
  49.     Row *next;
  50.     next = row;
  51.     while(next != NULL)
  52.     /* While not completed */
  53.     {
  54.         next = row -> next;
  55.         /* Save the next node first */
  56.        
  57.         FREEMEMChar(row -> ch);
  58.         /* Then free Chars of the Row  */
  59.        
  60.         FREEMEM(row);
  61.         /* Then free the Row node itself */
  62.        
  63.         row = next;
  64.         /* Move to next row */
  65.     }
  66. }
  67.  
  68. void FREEMEMChar(Char *ch)
  69. /* Free link table struct Char */
  70. {
  71.     Char *next;
  72.     next = ch;
  73.     while(next != NULL)
  74.     /* While not completed */
  75.     {
  76.         next = ch -> next;
  77.         /* Save the next node first */
  78.        
  79.         FREEMEM(ch);
  80.         /* Then free this node */
  81.        
  82.         ch = next;
  83.         /* Move to next node */
  84.     }
  85. }
  86.  
  87. void Exit(void *n)
  88. /* Flag an exit event */
  89. {
  90.     State *s;
  91.     s = (State *)n;
  92.     if(s -> ischildwindow)
  93.     /* Only exit the child window */
  94.         CloseChildWindow(n);
  95.     else
  96.     /* Change the whole exit flag */
  97.         s -> isexit = 1;
  98. }
  99.  
  100. void CalcDelay(void *n)
  101. /* Use biostime to adjust delay() */
  102. {
  103.     long bios_time, bios_time_start;
  104.     long i;
  105.     State *s;
  106.     s = (State *)n;
  107.    
  108.     bios_time_start = biostime(0, 0);
  109.     /* Save the current time */
  110.    
  111.     delay(200);
  112.     /* Do a 200ms delay */
  113.    
  114.     bios_time = biostime(0, 0);
  115.     /* Get current time after the 200ms delay */
  116.    
  117.     s -> delaytime = bios_time - bios_time_start;
  118.     /* Then save the true timestamp for adjusting */
  119. }
  120.  
  121. void Delay(void *n, long t)
  122. /* The fixed delay function */
  123. {
  124.     State *s;
  125.     int i;
  126.     s = (State *)n;
  127.    
  128.     delay((int)(200 * t / s -> delaytime / CLK_TCK));
  129.     /* Use the true timestamp to adjust the buggy delay */
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement