home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 2 / ctrom_ii_b.zip / ctrom_ii_b / PROGRAM / C / CBGRX102 / EVENT32.C < prev    next >
Text File  |  1992-08-12  |  4KB  |  119 lines

  1. /** 
  2.  ** EVENT32.C 
  3.  **
  4.  **  Copyright (C) 1992, Csaba Biegl
  5.  **    820 Stirrup Dr, Nashville, TN, 37221
  6.  **    csaba@vuse.vanderbilt.edu
  7.  **
  8.  **  This file is distributed under the terms listed in the document
  9.  **  "copying.cb", available from the author at the address above.
  10.  **  A copy of "copying.cb" should accompany this file; if not, a copy
  11.  **  should be available from where this file was obtained.  This file
  12.  **  may not be distributed without a verbatim copy of "copying.cb".
  13.  **  You should also have received a copy of the GNU General Public
  14.  **  License along with this program (it is in the file "copying");
  15.  **  if not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  16.  **  Cambridge, MA 02139, USA.
  17.  **
  18.  **  This program is distributed in the hope that it will be useful,
  19.  **  but WITHOUT ANY WARRANTY; without even the implied warranty of
  20.  **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21.  **  GNU General Public License for more details.
  22.  **/
  23.  
  24. #ifndef __GNUC__
  25. #error  This file is only for the DJGPP 32-bit version!!!!
  26. #endif
  27.  
  28. #include <stdlib.h>
  29. #include "eventque.h"
  30.  
  31. asm(                                       "\n\
  32.     .data                                \n\
  33.     .align  4                            \n\
  34. _mousedraw_painter:        /* pointer to the function */        \n\
  35.     .long    0        /* to draw mouse */            \n\
  36. _mousedraw_active_p:        /* pointer to flag to zero */        \n\
  37.     .long    0        /* when drawing is done */        \n\
  38. _mousedraw_contaddr_p:        /* pointer to dword containing */    \n\
  39.     .long    0        /* return address from mouse draw */    \n\
  40.     .text                                \n\
  41.     .align  2,144                            \n\
  42. _mousedraw_func:                            \n\
  43.     pushl    %eax           /* place for return address */        \n\
  44.     pushl    %eax           /* save EAX */                \n\
  45.     movl    _mousedraw_contaddr_p,%eax                \n\
  46.     movl    (%eax),%eax   /* fix up return address */        \n\
  47.     movl    %eax,4(%esp)                        \n\
  48.     pushf                                \n\
  49.     pushl    %ebx                            \n\
  50.     pushl    %ecx                            \n\
  51.     pushl    %edx                            \n\
  52.     movl    _mousedraw_painter,%eax                    \n\
  53.     call    *%eax                            \n\
  54.     popl    %edx                            \n\
  55.     popl    %ecx                            \n\
  56.     popl    %ebx                            \n\
  57.     movl    _mousedraw_active_p,%eax                \n\
  58.     movb    $0,(%eax)      /* clear active flag */            \n\
  59.     popf                                \n\
  60.     popl    %eax                            \n\
  61.     ret            /* back to program */              "
  62. );
  63.  
  64. static int  have_queue = 0;
  65.  
  66. /*
  67.  * These are actually local symbols at the link level, we just have to
  68.  * trick the C compiler
  69.  */
  70. extern void mousedraw_func(void);
  71. extern void (*mousedraw_painter)(void);
  72. extern char *mousedraw_active_p;
  73. extern long *mousedraw_contaddr_p;
  74.  
  75.  
  76. void EventQueueDeInit(void)
  77. {
  78.     if(have_queue) {
  79.         asm volatile(                           "\n\
  80.         movl   $0x00ff,%%eax                    \n\
  81.         xorl   %%ebx,%%ebx                    \n\
  82.         int    $0x33                          "
  83.         : /* nothing */
  84.         : /* nothing */
  85.         : "ax", "bx", "cx", "dx"
  86.         );
  87.         have_queue = 0;
  88.     }
  89. }
  90.  
  91. EventQueue *EventQueueInit(int qsize,int ms_stksize,void (*msdraw)(void))
  92. {
  93.     EventQueue *queue;
  94.     int ack;
  95.  
  96.     if(qsize < 20) qsize = 20;
  97.     if(msdraw != NULL) {
  98.         mousedraw_painter = msdraw;
  99.         msdraw = mousedraw_func;
  100.     }
  101.     asm volatile(                               "\n\
  102.         movl   $0x00ff,%%eax                    \n\
  103.         movl   %2,%%ebx                        \n\
  104.         movl   %3,%%ecx                        \n\
  105.         int       $0x33                        \n\
  106.         movl   %%eax,%0                        \n\
  107.         movl   %%ebx,%1                        \n\
  108.         movl   %%ecx,_mousedraw_contaddr_p                \n\
  109.         movl   %%edx,_mousedraw_active_p                  "
  110.         : "=g" (ack),   "=g" (queue)
  111.         : "g"  (qsize), "g"  (msdraw)
  112.         : "ax", "bx", "cx", "dx"
  113.     );
  114.     if(ack != 0x0ff0) queue = NULL;
  115.     have_queue = (queue != NULL) ? 1 : 0;
  116.     return(queue);
  117. }
  118.  
  119.