home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / BBS / MISC / XSRC_117.ZIP / LAXOWLVL.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-10-28  |  4.2 KB  |  257 lines

  1.  
  2. /* Low-level functions addressing BIOS & PC Hardware used by local
  3.    window routines */
  4.  
  5. #include "dos.h"
  6. #include "keys.h"
  7. #pragma inline
  8. static union REGS rg;
  9. #ifdef USEMOUSE
  10.     char mouse=0;
  11.     int  hcount=7;
  12.     int  vcount=7;
  13.     int  lastcount=150;
  14.     int  mouselast=0;
  15.     int  hysterisis=7;
  16.     char button[8]={0,'\r',ESC,PGUP,PGDN,F1,CTRL_PGDN,CTRL_PGUP};
  17. #endif
  18. #ifdef USECLOCK
  19.     extern void pascal print_clock(void);
  20. #endif
  21. extern cdecl printf(char *,...);
  22.  
  23. /* Position cursor */
  24.  
  25. void pascal cursor (int x, int y) {
  26.  
  27.   rg.x.ax=0x0200;
  28.   rg.x.bx=0;
  29.   rg.x.dx=((y<<8)&0xff00)+x;
  30.   int86 (16,&rg,&rg);
  31. }
  32.  
  33. /* Return cursor position */
  34.  
  35. void pascal curr_cursor (int *x,int *y) {
  36.  
  37.   rg.x.ax=0x0300;
  38.   rg.x.bx=0;
  39.   int86(16,&rg,&rg);
  40.   *x=rg.h.dl;
  41.   *y=rg.h.dh;
  42. }
  43.  
  44. /* Set cursor type */
  45.  
  46. void pascal set_cursor_type(int t) {
  47.  
  48.   rg.x.ax=0x0100;
  49.   rg.x.bx=0;
  50.   rg.x.cx=t;
  51.   int86(16,&rg,&rg);
  52. }
  53.  
  54. char attrib = 7;
  55.  
  56. /* Clear screen */
  57.  
  58. void pascal clear_screen() {
  59.  
  60.   cursor (0,0);
  61.   rg.h.al=' ';
  62.   rg.h.ah=9;
  63.   rg.x.bx=attrib;
  64.   rg.x.cx=2000;
  65.   int86(16,&rg,&rg);
  66. }
  67.  
  68. /* Return video mode */
  69.  
  70. int pascal vmode() {
  71.  
  72.   rg.h.ah=15;
  73.   int86(16,&rg,&rg);
  74.   return rg.h.al;
  75. }
  76.  
  77. /* Test for scroll lock */
  78.  
  79. int pascal scroll_lock() {
  80.  
  81.   rg.x.ax=0x0200;
  82.   int86(0x16,&rg,&rg);
  83.   return rg.h.al & 0x10;
  84. }
  85.  
  86. void (*helpfunc)();
  87. int helpkey=0;
  88. int helping=0;
  89.  
  90. /*Get a keyboard character */
  91.  
  92. int pascal get_char () {
  93.  
  94.   int c;
  95. #ifdef USEMOUSE
  96.   static int mousex=0;
  97.   static int mousey=0;
  98.   static int lastbutton=0;
  99.   int mx;
  100.   int my;
  101.   register int x;
  102. #endif
  103.  
  104.   while(1) {
  105.     rg.h.ah=1;
  106.     int86(0x16,&rg,&rg);
  107.     if (rg.x.flags & 0x40) {
  108. #ifdef USEMOUSE
  109.       if(mouse) {
  110.           rg.x.ax=3;
  111.           int86(0x33,&rg,&rg);
  112.           if(rg.x.bx) {
  113.             if(mouselast>0 && rg.x.bx==lastbutton) {
  114.               mouselast--;
  115.               goto SkipButtons;
  116.             }
  117.             c=button[rg.x.bx];
  118.             lastbutton=rg.x.bx;
  119.             if(c) {
  120.                 mouselast=lastcount;
  121.                 mousex=mousey=0;
  122.                 goto MouseBreakIn;
  123.             }
  124.           }
  125.           else mouselast=0;
  126.           if(mouselast>0)mouselast--;
  127. SkipButtons:
  128.           c=0;
  129.  
  130.           mx=my=0;
  131.           for(x=0;x<5;x++) {
  132.               rg.x.ax=11;
  133.               int86(0x33,&rg,&rg);
  134.               mx+=(int)rg.x.cx;
  135.               my+=(int)rg.x.dx;
  136.           }
  137.           mx/=5;
  138.           my/=5;
  139.           mousex+=mx;
  140.           mousey+=my;
  141.           if(hcount > -1) {
  142.               if(mousex > hcount) {
  143.                 c=FWD;
  144.               }
  145.               else if(mousex < (-hcount)) {
  146.                 c=BS;
  147.               }
  148.           }
  149.           if(vcount > -1) {
  150.               if(mousey > vcount) {
  151.                 c=DN;
  152.               }
  153.               else if(mousey < (-vcount)) {
  154.                 c=UP;
  155.               }
  156.           }
  157.           if(c) {
  158.             mousex=mousey=0;
  159.             goto MouseBreakIn;
  160.           }
  161.       }
  162. #endif
  163. #ifdef USECLOCK
  164.       print_clock();
  165. #endif
  166.       continue;
  167.     }
  168.     rg.h.ah=0;
  169.     int86(0x16,&rg,&rg);
  170.     if (rg.h.al == 0) c=rg.h.ah | 128;
  171.     else c=rg.h.al;
  172. MouseBreakIn:
  173.     if (c==helpkey && helpfunc) {
  174.        if (!helping) {
  175.          helping=1;
  176.          (*helpfunc)();
  177.          helping=0;
  178.          continue;
  179.        }
  180.      }
  181.      break;
  182.    }
  183.    return c;
  184. }
  185.  
  186.  
  187. void pascal vpoke (unsigned vseg, unsigned adr, unsigned chr) {
  188.  
  189.     if (vseg == 45056)
  190.         poke(vseg,adr,chr);
  191.     else {
  192.         _DI=adr;
  193.         _ES=vseg;
  194.         asm cld;
  195.         _BX=chr;
  196.         _DX=986;
  197.  
  198.         do
  199.             asm in al,dx;
  200.         while (_AL & 1);
  201.  
  202.         do
  203.             asm in al,dx;
  204.         while (!(_AL & 1));
  205.         _AL = _BL;
  206.         asm stosb;
  207.  
  208.         do
  209.             asm in al,dx;
  210.         while (_AL & 1);
  211.  
  212.         do
  213.             asm in al,dx;
  214.         while(!(_AL & 1));
  215.         _AL = _BH;
  216.         asm stosb;
  217.     }
  218. }
  219.  
  220. int pascal vpeek(unsigned vseg, unsigned adr) {
  221.  
  222.     int ch,at;
  223.  
  224.     if (vseg == 45056)
  225.         return peek(vseg,adr);
  226.     asm push ds;
  227.     _DX=986;
  228.     _DS=vseg;
  229.     _SI=adr;
  230.     asm cld;
  231.  
  232.     do
  233.         asm in al,dx;
  234.     while(_AL & 1);
  235.  
  236.     do
  237.         asm in al,dx;
  238.     while(!(_AL & 1));
  239.     asm lodsb;
  240.     _BL = _AL;
  241.  
  242.     do
  243.         asm in al,dx;
  244.     while(_AL & 1);
  245.  
  246.     do
  247.         asm in al,dx;
  248.     while(!(_AL & 1));
  249.     asm lodsb;
  250.     _BH=_AL;
  251.     _AX=_BX;
  252.     asm pop ds;
  253.     return _AX;
  254. }
  255.  
  256. /* End of IBMPC.C File */
  257.