home *** CD-ROM | disk | FTP | other *** search
-
- /*
- * Prototype.
- */
-
- int getlist Params((struct b_lelem *bp,unsigned int *vals, int limit));
-
- /*
- * Int86(a)
- */
- #if LATTICE
- FncDcl(Int86,1)
- {
- RunErr(121,0);
- }
- #endif /* LATTICE */
-
- #if MICROSOFT || TURBO
- FncDcl(Int86,1)
- {
-
- union REGS inreg,outreg;
- struct SREGS insreg,outsreg;
-
- unsigned int vals[9];
- unsigned int flag;
- word nslots;
-
- struct b_list *hp;
- struct b_lelem *bp;
-
- /*
- * Make sure that Arg1 is a list, that it only has 9 values, and all
- * are ints.
- */
-
- if (Type(Arg1) != T_List) {
- RunErr(118, &Arg1);
- }
-
- hp = (struct b_list *) BlkLoc(Arg1);
- if (hp->size != 9) {
- RunErr(205, &Arg1);
- }
-
- bp = (struct b_lelem *) hp->listhead;
- if (getlist(bp, vals, 9) == Failure)
- Fail;
- flag = vals[0];
-
- inreg.x.ax = vals[1];
- inreg.x.bx = vals[2];
- inreg.x.cx = vals[3];
- inreg.x.dx = vals[4];
- inreg.x.si = vals[5];
- inreg.x.di = vals[6];
- insreg.es = vals[7];
- insreg.ds = vals[8];
- segread(&insreg);
- insreg.es = vals[7];
- insreg.ds = vals[8];
-
- /*** FIX CCW 01/21/89 ****/
- /* flag = int86x(flag,&inreg,&outreg,&insreg); */
-
- int86x(flag,&inreg,&outreg,&insreg); /* ... this should work for */
- flag = outreg.x.cflag; /* ... both MSC and Turbo C */
-
-
- /*
- * Return the values.
- */
- nslots = 9;
- if (blkreq((word)sizeof(struct b_list) + sizeof(struct b_lelem) +
- nslots * sizeof(struct descrip)) == Error) {
- RunErr(0, NULL);
- }
-
- hp = alclist((word)9);
- bp = alclstb(nslots,(word)0,(word)9);
- hp->listhead = hp->listtail = (union block *) bp;
-
- /* returns [flags,ax,bx,cx,dx,si,di,es,ds] */
-
- MakeInt((uword)flag,&(bp->lslots[0]));
- MakeInt((uword)outreg.x.ax,&(bp->lslots[1]));
- MakeInt((uword)outreg.x.bx,&(bp->lslots[2]));
- MakeInt((uword)outreg.x.cx,&(bp->lslots[3]));
- MakeInt((uword)outreg.x.dx,&(bp->lslots[4]));
- MakeInt((uword)outreg.x.si,&(bp->lslots[5]));
- MakeInt((uword)outreg.x.di,&(bp->lslots[6]));
- MakeInt((uword)insreg.es,&(bp->lslots[7]));
- MakeInt((uword)insreg.ds,&(bp->lslots[8]));
-
- ArgType(0) = D_List;
- Arg(0).vword.bptr = (union block *) hp;
- Return;
- }
- #endif /* MICROSOFT || TURBO */
-
- static char *zptr = NULL;
- #if MICROSOFT || TURBO
- #define ptr2word(x) ((uword)((char huge *)x - (char huge *)zptr))
- #define word2ptr(x) ((char huge *)((char huge *)zptr + (uword)x))
- #else /* MICROSOFT || TURBO */
- #define ptr2word(x) (uword)x
- #define word2ptr(x) ((char *)x)
- #endif /* MICROSOFT || TURBO */
-
- /*
- * peek(addr,len)
- */
-
- FncDcl(Peek,2)
- {
- unsigned int vals[2];
- struct b_list *hp;
- struct b_lelem *bp;
- union {
- char *cptr;
- struct {
- unsigned int o;
- unsigned int s;
- } Word;
- } addr;
-
- if (defshort(&Arg2,1) == Error) {
- RunErr(0, NULL);
- }
- switch (Type(Arg1)) {
-
- case T_Integer:
- StrLoc(Arg0) = (char *) word2ptr(Arg1.vword.integr);
- break;
- case T_List:
- hp = (struct b_list *) BlkLoc(Arg1);
- if (hp->size != 2) {
- RunErr(205, &Arg1);
- }
- bp = (struct b_lelem *) hp->listhead;
- if (getlist(bp, vals, 2) == Failure) Fail;
- addr.Word.s = vals[0];
- addr.Word.o = vals[1];
- Arg0.vword.sptr = addr.cptr;
- break;
- default:
- RunErr(101,&Arg1);
- }
- switch (Type(Arg2)) {
-
- case T_Integer:
- StrLen(Arg0) = Arg2.vword.integr;
- break;
- default:
- RunErr(101, &Arg2);
- }
- Return;
- }
-
- /*
- * poke(addr,s)
- */
-
- FncDcl(Poke,2)
- {
- unsigned int vals[2];
- register char *s1,*s2;
- register word l;
- union {
- char *cptr;
- struct {
- unsigned int o;
- unsigned int s;
- } Word;
- } addr;
- struct b_list *hp;
- struct b_lelem *bp;
-
- switch (Type(Arg1)) {
-
- case T_Integer:
- addr.cptr = (char *)word2ptr(Arg1.vword.integr);
- break;
- case T_List:
- hp = (struct b_list *) BlkLoc(Arg1);
- if (hp->size != 2) {
- RunErr(205,&Arg1);
- }
- bp = (struct b_lelem *) hp->listhead;
- if (getlist(bp, vals, 2) == Failure) Fail;
- addr.Word.s = vals[0];
- addr.Word.o = vals[1];
- break;
- default:
- RunErr(101,&Arg1);
- }
- if (!Qual(Arg2)) {
- RunErr(103, &Arg2);
- }
- l = StrLen(Arg2);
- s1 = StrLoc(Arg2);
- s2 = addr.cptr;
-
- memcopy(s2,s1,l); /* Copy... */
-
- Return;
- }
-
- /*
- * Getspace(i)
- */
-
- FncDcl(GetSpace,1)
- {
- char *addr;
- uword u;
- int size;
-
- if (Arg1.dword != D_Integer) { /* should convert & check for small */
- RunErr(101, &Arg1);
- }
-
- size = (int)Arg1.vword.integr;
- addr = (char *)calloc(size,sizeof(char));
- if (addr==NULL) Fail;
- u = ptr2word(addr);
- MakeInt(u,&Arg0);
- Return;
- }
-
- /*
- * FreeSpace(a)
- */
-
- FncDcl(FreeSpace,1)
- {
- uword u;
- char *addr;
-
- switch (Type(Arg1)) {
- case T_Integer:
- u = Arg1.vword.integr;
- break;
- default:
- RunErr(102, &Arg1);
- }
- addr = word2ptr(u);
- free((pointer)addr);
- Return;
- }
-
- static int getlist(bp,vals,limit)
- unsigned int *vals;
- int limit;
- struct b_lelem *bp;
- {
- int i;
- int count;
-
- i = 0;
- for(count = 0 ;count <limit;count++) {
- int j;
- if( ++i > bp->nused) {
- i = 1;
- bp = (struct b_lelem *) bp->listnext;
- }
- j = bp->first + i - 1; /* Get slot index */
- if( j >= bp->nslots)
- j -= bp->nslots;
- switch(Type(bp->lslots[j])) {
- case T_Integer: /* should check for small */
- vals[count] = (int)IntVal(bp->lslots[j]);
- break;
- default:
- RunErr(101,&bp->lslots[j]);
- }
- }
- return 0;
- }
-
- /*
- * InPort(i) - Return a value from port i
- */
-
- FncDcl(InPort,1)
- {
- unsigned int value;
- int port;
-
- switch (cvint(&Arg1)) { /* should check for small */
- case T_Integer:
- port = (int)IntVal(Arg1);
- break;
- default:
- RunErr(101, &Arg1);
- }
- value = inp(port);
- MakeInt(value, &Arg0);
- }
-
- /*
- * OutPort(i1,i2) - Write i2 to port i1
- */
-
- FncDcl(OutPort,2)
- {
- int value;
- unsigned int port;
-
- switch (cvint(&Arg1)) {
- case T_Integer: /* should check for small */
- port = (int)IntVal(Arg1);
- break;
- default:
- RunErr(101, &Arg1);
- }
- switch (cvint(&Arg2)) { /* should check for small */
- case T_Integer:
- if (IntVal(Arg2) > 255) {
- RunErr(205, &Arg2);
- }
- value = (int)IntVal(Arg2);
- break;
- default:
- RunErr(101, &Arg2);
- }
- outp(port,value);
- }
-