home *** CD-ROM | disk | FTP | other *** search
-
- /* Low-level functions addressing BIOS & PC Hardware used by local
- window routines */
-
- #include "dos.h"
- #include "keys.h"
- #pragma inline
- static union REGS rg;
- #ifdef USEMOUSE
- char mouse=0;
- int hcount=7;
- int vcount=7;
- int lastcount=150;
- int mouselast=0;
- int hysterisis=7;
- char button[8]={0,'\r',ESC,PGUP,PGDN,F1,CTRL_PGDN,CTRL_PGUP};
- #endif
- #ifdef USECLOCK
- extern void pascal print_clock(void);
- #endif
- extern cdecl printf(char *,...);
-
- /* Position cursor */
-
- void pascal cursor (int x, int y) {
-
- rg.x.ax=0x0200;
- rg.x.bx=0;
- rg.x.dx=((y<<8)&0xff00)+x;
- int86 (16,&rg,&rg);
- }
-
- /* Return cursor position */
-
- void pascal curr_cursor (int *x,int *y) {
-
- rg.x.ax=0x0300;
- rg.x.bx=0;
- int86(16,&rg,&rg);
- *x=rg.h.dl;
- *y=rg.h.dh;
- }
-
- /* Set cursor type */
-
- void pascal set_cursor_type(int t) {
-
- rg.x.ax=0x0100;
- rg.x.bx=0;
- rg.x.cx=t;
- int86(16,&rg,&rg);
- }
-
- char attrib = 7;
-
- /* Clear screen */
-
- void pascal clear_screen() {
-
- cursor (0,0);
- rg.h.al=' ';
- rg.h.ah=9;
- rg.x.bx=attrib;
- rg.x.cx=2000;
- int86(16,&rg,&rg);
- }
-
- /* Return video mode */
-
- int pascal vmode() {
-
- rg.h.ah=15;
- int86(16,&rg,&rg);
- return rg.h.al;
- }
-
- /* Test for scroll lock */
-
- int pascal scroll_lock() {
-
- rg.x.ax=0x0200;
- int86(0x16,&rg,&rg);
- return rg.h.al & 0x10;
- }
-
- void (*helpfunc)();
- int helpkey=0;
- int helping=0;
-
- /*Get a keyboard character */
-
- int pascal get_char () {
-
- int c;
- #ifdef USEMOUSE
- static int mousex=0;
- static int mousey=0;
- static int lastbutton=0;
- int mx;
- int my;
- register int x;
- #endif
-
- while(1) {
- rg.h.ah=1;
- int86(0x16,&rg,&rg);
- if (rg.x.flags & 0x40) {
- #ifdef USEMOUSE
- if(mouse) {
- rg.x.ax=3;
- int86(0x33,&rg,&rg);
- if(rg.x.bx) {
- if(mouselast>0 && rg.x.bx==lastbutton) {
- mouselast--;
- goto SkipButtons;
- }
- c=button[rg.x.bx];
- lastbutton=rg.x.bx;
- if(c) {
- mouselast=lastcount;
- mousex=mousey=0;
- goto MouseBreakIn;
- }
- }
- else mouselast=0;
- if(mouselast>0)mouselast--;
- SkipButtons:
- c=0;
-
- mx=my=0;
- for(x=0;x<5;x++) {
- rg.x.ax=11;
- int86(0x33,&rg,&rg);
- mx+=(int)rg.x.cx;
- my+=(int)rg.x.dx;
- }
- mx/=5;
- my/=5;
- mousex+=mx;
- mousey+=my;
- if(hcount > -1) {
- if(mousex > hcount) {
- c=FWD;
- }
- else if(mousex < (-hcount)) {
- c=BS;
- }
- }
- if(vcount > -1) {
- if(mousey > vcount) {
- c=DN;
- }
- else if(mousey < (-vcount)) {
- c=UP;
- }
- }
- if(c) {
- mousex=mousey=0;
- goto MouseBreakIn;
- }
- }
- #endif
- #ifdef USECLOCK
- print_clock();
- #endif
- continue;
- }
- rg.h.ah=0;
- int86(0x16,&rg,&rg);
- if (rg.h.al == 0) c=rg.h.ah | 128;
- else c=rg.h.al;
- MouseBreakIn:
- if (c==helpkey && helpfunc) {
- if (!helping) {
- helping=1;
- (*helpfunc)();
- helping=0;
- continue;
- }
- }
- break;
- }
- return c;
- }
-
-
- void pascal vpoke (unsigned vseg, unsigned adr, unsigned chr) {
-
- if (vseg == 45056)
- poke(vseg,adr,chr);
- else {
- _DI=adr;
- _ES=vseg;
- asm cld;
- _BX=chr;
- _DX=986;
-
- do
- asm in al,dx;
- while (_AL & 1);
-
- do
- asm in al,dx;
- while (!(_AL & 1));
- _AL = _BL;
- asm stosb;
-
- do
- asm in al,dx;
- while (_AL & 1);
-
- do
- asm in al,dx;
- while(!(_AL & 1));
- _AL = _BH;
- asm stosb;
- }
- }
-
- int pascal vpeek(unsigned vseg, unsigned adr) {
-
- int ch,at;
-
- if (vseg == 45056)
- return peek(vseg,adr);
- asm push ds;
- _DX=986;
- _DS=vseg;
- _SI=adr;
- asm cld;
-
- do
- asm in al,dx;
- while(_AL & 1);
-
- do
- asm in al,dx;
- while(!(_AL & 1));
- asm lodsb;
- _BL = _AL;
-
- do
- asm in al,dx;
- while(_AL & 1);
-
- do
- asm in al,dx;
- while(!(_AL & 1));
- asm lodsb;
- _BH=_AL;
- _AX=_BX;
- asm pop ds;
- return _AX;
- }
-
- /* End of IBMPC.C File */
-