home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / xbase / library / clipper / timer / ontick / ontickc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-05-12  |  3.6 KB  |  133 lines

  1. /*
  2. **    Program...: ontickC.c
  3. **    Author....: Brenton Farmer
  4. **    Date......: 10/10/91
  5. **    Purpose...: C code to support Clipper ontick() function.
  6. **
  7. **    Revision..:    1.1 02/15/92 Changed code to support indos flag checking    
  8. **                    1.2 03/29/92 Changed operation to use hotkey to invoke udf
  9. **                    1.3 03/30/92 Added non int 21 keyboard stuff routine
  10. */
  11.  
  12. #include "extend.h"
  13.  
  14. typedef struct {
  15.     unsigned es, ds, di, si, bp, sp, bx, dx, cx, ax, ip, cs, flags;
  16. } INTERRUPT_REGS;
  17.  
  18. void ( interrupt far *old_int8)();
  19. void interrupt far C10ckISR( INTERRUPT_REGS);
  20. int StuffScanCode( int);
  21.  
  22. extern void ( interrupt far *_getvector( unsigned int))();
  23. extern void _setvector( unsigned int, void( interrupt far *)());
  24. extern char * _getindosAddress();
  25.  
  26.  
  27. /*
  28. **    Declare Global Variables
  29. */
  30. int gTicks = 0;            // Call Clipper routine every Ticks
  31. int gTickerCount = 0;    // How many ticks have elapsed
  32. int gHotKey = 0;            // ScanCode to put on keyboard buffer
  33.  
  34. char far *indos = 0;        // Address of DOS safe flag
  35.  
  36.  
  37. /*
  38. **    Logical C10ckSet( int TickTime, int ScanCode)
  39. **
  40. **    Note: C10ckSet( 0, 0); to turns off ticker
  41. */
  42. CLIPPER C10ckSet()
  43. {
  44.     static int TickerIsActive = 0;             // 1 if Ticker active, 0 if not
  45.     int ReturnValue = 0;                             // 0 if invalid parameters passed
  46.     int TickValue = 0;                             // Hotkey stuff interval
  47.  
  48.     if ( PCOUNT == 2 && ISNUM(1) && ISNUM(2))
  49.     {
  50.         ReturnValue = 1;
  51.         if ( ( TickValue = _parni( 1)) != 0) // If TickValue != 0 Setup Timer
  52.         {
  53.             gTicks = TickValue;                     // Stuff Hotkey from isr every (Ticks)
  54.             gTickerCount = 0;                         // Time elapsed in ticks
  55.             gHotKey = _parni(2);                     // Hotkey Scancode
  56.  
  57.             if ( indos == 0)
  58.                 indos = _getindosAddress();     // Get indos address
  59.  
  60.             if (!TickerIsActive) {                 // Don't allow double install
  61.                 old_int8 = _getvector( 0x08);     // Get current int 8 isr
  62.                 _setvector( 0x08, C10ckISR);     // Set int 8 to my isr
  63.             }
  64.             TickerIsActive = 1;                     // Ticker is now installed
  65.         }
  66.         else {
  67.             if ( TickerIsActive)
  68.                 _setvector( 0x08, old_int8);     // Restore the original isr
  69.  
  70.             TickerIsActive = 0;
  71.             gHotKey = 0;
  72.             gTicks = 0;          
  73.             gTickerCount = 0;
  74.         }
  75.     }
  76.  
  77.     _retl( ReturnValue);
  78. }
  79.  
  80.  
  81. /*
  82. **
  83. **
  84. */
  85. void interrupt far C10ckISR( INTERRUPT_REGS r)
  86. {
  87.     static int Busy = 0;
  88.  
  89.     (*old_int8)();                                    // Execute old handler
  90.  
  91.     if ( !Busy)    {                                    // Busy must be 0 (Prevents recursion)
  92.         ++Busy;                                        // Increment Busy flag
  93.         if ( ++gTickerCount >= gTicks)         // Has the appropriate time passed
  94.             if (! *indos) 
  95.                 if ( StuffScanCode( gHotKey))    // Stuff keyboard with hot-key
  96.                     gTickerCount = 0;                // Reset ticker Timer
  97.         --Busy;                                        // Decrement Busy Flag
  98.     }
  99. }
  100.  
  101.  
  102. /*
  103. **    Stuff Scancode into keyboard buffer.
  104. **
  105. ** NOTE: Since this routine is called from within my int8 handler
  106. **       it is entered with interrupts disabled. In order to keep
  107. **       this routine to a minimum -- NO checking is done to ensure
  108. **            a valid scancode.  I based this code on an assembly language
  109. **            fragment from Ted Mean's putkey.asm routine in the
  110. **            nanforum lib.
  111. */
  112. int StuffScanCode( int ScanCode)
  113. {
  114.     static int *Tail = (int *) 0x0000041C;
  115.  
  116.     int NewKeyBuff;
  117.  
  118.     if (! ScanCode)                                    // Don't allow 0 scancode
  119.         return ( FALSE);
  120.  
  121.     NewKeyBuff = *Tail + 2;
  122.     if ( NewKeyBuff == 0x003E)                        // If NewKeyBuff== Buff maxbyte
  123.         NewKeyBuff = 0x001E;                              // Set NewKeyBuff= Buff minbyte
  124.  
  125.     if ( NewKeyBuff == *((int *) 0x0000041A))    // If NewKeyBuff== Buffer Head
  126.         return ( FALSE);                                // then keyboard Buffer is full
  127.  
  128.     *((int *) ((unsigned long)( *Tail + 0x0400))) = ScanCode;
  129.     *Tail = NewKeyBuff;
  130.  
  131.     return ( TRUE);
  132. }
  133.