home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Black Box 4
/
BlackBox.cdr
/
progc
/
xdev_118.arj
/
XEDIT.LZH
/
XEDIT4.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-04-01
|
6KB
|
339 lines
/* Low-level functions addressing BIOS & PC Hardware */
#include <dos.h>
#include <stdlib.h>
#include "keys.h"
#pragma inline
static union REGS rg;
static int mtask=0;
#define DVID 1
#define DDOSID 2
#define MOSID 3
#define TVID 4
void pascal set_mtask (void);
int pascal is_dv (void);
int pascal is_ddos (void);
int pascal is_mos (void);
int pascal is_tv (void);
void pascal pause_dv (void);
void pascal pause_ddos (void);
void pascal pause_tv (void);
void pascal pause_mos (void);
#ifdef USECLOCK
extern void pascal print_clock(void);
#endif
/* Position cursor */
void pascal cursor (int x, int y) {
_AX = 0x0200;
_BX = 0;
_DX = ((y << 8) & 0xff00) + x;
geninterrupt(16);
/*
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) {
_AX = 0x0300;
_BX = 0;
geninterrupt(16);
*x = _DL;
*y = _DH;
}
/* Set cursor type */
void pascal set_cursor_type (int t) {
_AX = 0x0100;
_BX = 0;
_CX = t;
geninterrupt(16);
}
char attrib = 7;
/* Clear screen */
void pascal clear_screen () {
cursor (0,0);
_AL = ' ';
_AH = 9;
_BX = attrib;
_CX = 2000;
geninterrupt(16);
}
/* Return video mode */
int pascal vmode () {
_AH = 15;
geninterrupt(16);
return _AL;
}
/* Test for scroll lock */
int pascal scroll_lock () {
_AX = 0x0200;
geninterrupt(0x16);
return _AL & 0x10;
}
void (*helpfunc)();
int helpkey=0;
int helping=0;
/* check for keyboard press */
int pascal kb_hit () {
_AH = 0x0b;
geninterrupt(0x21);
if(!_AL) {
#ifdef USECLOCK
print_clock();
#endif
switch(mtask) {
case DVID: pause_dv();
break;
case DDOSID: pause_ddos();
break;
case TVID: pause_tv();
break;
case MOSID: pause_mos();
break;
}
geninterrupt(0x28); /* scheduler interrupt */
return 0;
}
return 1;
}
/* Get a keyboard character */
int pascal get_char () {
int c;
while(1) {
_AH = 0x0b;
geninterrupt(0x21);
if (!_AL) {
#ifdef USECLOCK
print_clock();
#endif
switch(mtask) {
case DVID: pause_dv();
break;
case DDOSID: pause_ddos();
break;
case TVID: pause_tv();
break;
case MOSID: pause_mos();
break;
}
geninterrupt(0x28); /* scheduler interrupt */
continue;
}
rg.h.ah=0;
int86(0x16,&rg,&rg);
if (rg.h.al == 0) c=rg.h.ah | 128;
else c=rg.h.al;
/* handle special keys */
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 == 45056U)
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) {
if (vseg == 45056U)
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;
}
void pascal set_mtask (void) {
if(is_dv()) mtask=DVID;
else if(is_ddos()) mtask=DDOSID;
else if(is_mos()) mtask=MOSID;
else if(is_tv()) mtask=TVID;
}
int pascal is_dv (void) {
rg.x.cx=0x4445;
rg.x.dx=0x5351;
rg.x.ax=0x2b01;
int86(0x21,&rg,&rg);
if(rg.h.al==0xff) return 0;
return rg.x.bx;
}
int pascal is_ddos (void) {
rg.h.ah=0xe4;
int86(0x21,&rg,&rg);
if(rg.h.al==1 || rg.h.al==2) return 1;
return 0;
}
int pascal is_mos (void) {
int temp;
rg.h.ah=0x30;
int86(0x21,&rg,&rg);
temp=rg.x.ax;
rg.x.ax=0x3000;
rg.x.bx=0x3000;
rg.x.cx=0x3000;
rg.x.dx=0x3000;
int86(0x21,&rg,&rg);
if(rg.x.ax==temp) return temp;
return 0;
}
int pascal is_tv (void) {
rg.x.ax=0x1022;
rg.x.bx=0;
int86(0x15,&rg,&rg);
if(!rg.x.bx) return 0;
return rg.x.bx;
}
void pascal pause_dv (void) {
_AX = 0x0101a;
geninterrupt(0x15);
_AX = 0x1000;
geninterrupt(0x15);
_AX = 0x1025;
geninterrupt(0x15);
}
void pascal pause_ddos (void) {
geninterrupt(0xf4);
}
void pascal pause_tv (void) {
_AX = 0x1000;
geninterrupt(0x15);
}
void pascal pause_mos (void) {
_AX = 0x0703;
_BX = 0x03;
_CX = 0;
_DX = 0;
geninterrupt(0x38);
}