home *** CD-ROM | disk | FTP | other *** search
/ APDL Public Domain 1 / APDL_PD1A.iso / program / language / icon / Source / Iconx / C / Fxmsdos < prev    next >
Encoding:
Text File  |  1990-07-19  |  6.1 KB  |  329 lines

  1.  
  2. /*
  3.  * Prototype.
  4.  */
  5.  
  6. int    getlist    Params((struct b_lelem *bp,unsigned int *vals, int limit));
  7.  
  8. /*
  9.  * Int86(a)
  10.  */
  11. #if LATTICE
  12. FncDcl(Int86,1)
  13.    {
  14.    RunErr(121,0);
  15.    }
  16. #endif                    /* LATTICE */
  17.  
  18. #if MICROSOFT || TURBO
  19. FncDcl(Int86,1)
  20.    {
  21.  
  22.     union  REGS inreg,outreg;
  23.     struct SREGS insreg,outsreg;
  24.  
  25.     unsigned int vals[9];
  26.     unsigned int flag;
  27.     word nslots;
  28.  
  29.     struct b_list *hp;
  30.     struct b_lelem *bp;
  31.  
  32. /*
  33.  * Make sure that Arg1 is a list, that it only has 9 values, and all
  34.  * are ints.
  35.  */
  36.  
  37.     if (Type(Arg1) != T_List) {
  38.     RunErr(118, &Arg1);
  39.     }
  40.  
  41.     hp = (struct b_list *) BlkLoc(Arg1);
  42.     if (hp->size != 9) {
  43.     RunErr(205, &Arg1);
  44.     }
  45.  
  46.     bp = (struct b_lelem *) hp->listhead;
  47.     if (getlist(bp, vals, 9) == Failure)
  48.        Fail;
  49.     flag = vals[0];
  50.  
  51.     inreg.x.ax = vals[1];
  52.     inreg.x.bx = vals[2];
  53.     inreg.x.cx = vals[3];
  54.     inreg.x.dx = vals[4];
  55.     inreg.x.si = vals[5];
  56.     inreg.x.di = vals[6];
  57.     insreg.es = vals[7];
  58.     insreg.ds = vals[8];
  59.     segread(&insreg);
  60.     insreg.es = vals[7];
  61.     insreg.ds = vals[8];
  62.  
  63. /*** FIX CCW 01/21/89 ****/
  64. /*  flag = int86x(flag,&inreg,&outreg,&insreg); */
  65.  
  66.     int86x(flag,&inreg,&outreg,&insreg);    /* ... this should work for */
  67.     flag = outreg.x.cflag;            /* ... both MSC and Turbo C */
  68.  
  69.  
  70. /*
  71.  * Return the values.
  72.  */
  73.    nslots = 9;
  74.    if (blkreq((word)sizeof(struct b_list) + sizeof(struct b_lelem) +
  75.     nslots * sizeof(struct descrip)) == Error) {
  76.       RunErr(0, NULL);
  77.       }
  78.  
  79.    hp = alclist((word)9);
  80.    bp = alclstb(nslots,(word)0,(word)9);
  81.    hp->listhead = hp->listtail = (union block *) bp;
  82.  
  83. /* returns [flags,ax,bx,cx,dx,si,di,es,ds] */
  84.  
  85.    MakeInt((uword)flag,&(bp->lslots[0]));
  86.    MakeInt((uword)outreg.x.ax,&(bp->lslots[1]));
  87.    MakeInt((uword)outreg.x.bx,&(bp->lslots[2]));
  88.    MakeInt((uword)outreg.x.cx,&(bp->lslots[3]));
  89.    MakeInt((uword)outreg.x.dx,&(bp->lslots[4]));
  90.    MakeInt((uword)outreg.x.si,&(bp->lslots[5]));
  91.    MakeInt((uword)outreg.x.di,&(bp->lslots[6]));
  92.    MakeInt((uword)insreg.es,&(bp->lslots[7]));
  93.    MakeInt((uword)insreg.ds,&(bp->lslots[8]));
  94.  
  95.    ArgType(0) = D_List;
  96.    Arg(0).vword.bptr = (union block *) hp;
  97.    Return;
  98.    }
  99. #endif                    /* MICROSOFT || TURBO */
  100.  
  101. static char *zptr = NULL;
  102. #if MICROSOFT || TURBO
  103. #define ptr2word(x) ((uword)((char huge *)x - (char huge *)zptr))
  104. #define word2ptr(x) ((char huge *)((char huge *)zptr + (uword)x))
  105. #else                    /* MICROSOFT || TURBO */
  106. #define ptr2word(x) (uword)x
  107. #define word2ptr(x) ((char *)x)
  108. #endif                    /* MICROSOFT || TURBO */
  109.  
  110. /*
  111.  * peek(addr,len)
  112.  */
  113.  
  114. FncDcl(Peek,2)
  115.    {
  116.    unsigned int vals[2];
  117.    struct b_list *hp;
  118.    struct b_lelem *bp;
  119.    union {
  120.        char *cptr;
  121.        struct {
  122.        unsigned int o;
  123.        unsigned int s;
  124.        } Word;
  125.        } addr;
  126.  
  127.       if (defshort(&Arg2,1) == Error) {
  128.       RunErr(0, NULL);
  129.       }
  130.    switch (Type(Arg1)) {
  131.  
  132.     case T_Integer:
  133.         StrLoc(Arg0) = (char *) word2ptr(Arg1.vword.integr);
  134.         break;
  135.     case T_List:
  136.         hp = (struct b_list *) BlkLoc(Arg1);
  137.         if (hp->size != 2) {
  138.             RunErr(205, &Arg1);
  139.             }
  140.         bp = (struct b_lelem *) hp->listhead;
  141.         if (getlist(bp, vals, 2) == Failure) Fail;
  142.         addr.Word.s = vals[0];
  143.         addr.Word.o = vals[1];
  144.         Arg0.vword.sptr = addr.cptr;
  145.         break;
  146.     default:
  147.         RunErr(101,&Arg1);
  148.    }
  149.    switch (Type(Arg2)) {
  150.  
  151.     case T_Integer:
  152.         StrLen(Arg0) = Arg2.vword.integr;
  153.         break;
  154.     default:
  155.         RunErr(101, &Arg2);
  156.    }
  157.    Return;
  158.    }
  159.  
  160. /*
  161.  * poke(addr,s)
  162.  */
  163.  
  164. FncDcl(Poke,2)
  165.    {
  166.    unsigned int vals[2];
  167.    register char *s1,*s2;
  168.    register word l;
  169.    union {
  170.     char *cptr;
  171.     struct {
  172.         unsigned int o;
  173.         unsigned int s;
  174.         } Word;
  175.     } addr;
  176.    struct b_list *hp;
  177.    struct b_lelem *bp;
  178.  
  179.    switch (Type(Arg1)) {
  180.  
  181.     case T_Integer:
  182.         addr.cptr = (char *)word2ptr(Arg1.vword.integr);
  183.         break;
  184.     case T_List:
  185.         hp = (struct b_list *) BlkLoc(Arg1);
  186.         if (hp->size != 2) {
  187.             RunErr(205,&Arg1);
  188.             }
  189.         bp = (struct b_lelem *) hp->listhead;
  190.         if (getlist(bp, vals, 2) == Failure) Fail;
  191.         addr.Word.s = vals[0];
  192.         addr.Word.o = vals[1];
  193.         break;
  194.     default:
  195.         RunErr(101,&Arg1);
  196.    }
  197.    if (!Qual(Arg2)) {
  198.       RunErr(103, &Arg2);
  199.       }
  200.    l = StrLen(Arg2);
  201.    s1 = StrLoc(Arg2);
  202.    s2 = addr.cptr;
  203.  
  204.    memcopy(s2,s1,l);     /* Copy... */
  205.  
  206.    Return;
  207.    }
  208.  
  209. /*
  210.  * Getspace(i)
  211.  */
  212.  
  213. FncDcl(GetSpace,1)
  214.    {
  215.        char *addr;
  216.        uword u;
  217.        int size;
  218.  
  219.       if (Arg1.dword != D_Integer) {    /* should convert & check for small */
  220.        RunErr(101, &Arg1);
  221.        }
  222.  
  223.       size = (int)Arg1.vword.integr;
  224.       addr = (char *)calloc(size,sizeof(char));
  225.       if (addr==NULL) Fail;
  226.       u = ptr2word(addr);
  227.       MakeInt(u,&Arg0);
  228.       Return;
  229.    }
  230.  
  231. /*
  232.  * FreeSpace(a)
  233.  */
  234.  
  235. FncDcl(FreeSpace,1)
  236.    {
  237.    uword u;
  238.    char *addr;
  239.  
  240.    switch (Type(Arg1)) {
  241.     case T_Integer:
  242.        u = Arg1.vword.integr;
  243.         break;
  244.     default:
  245.         RunErr(102, &Arg1);
  246.    }
  247.    addr = word2ptr(u);
  248.    free((pointer)addr);
  249.    Return;
  250.    }
  251.  
  252. static int getlist(bp,vals,limit)
  253. unsigned int *vals;
  254. int limit;
  255. struct b_lelem *bp;
  256. {
  257.     int i;
  258.     int count;
  259.  
  260.     i = 0;
  261.     for(count = 0 ;count <limit;count++) {
  262.     int j;
  263.     if( ++i > bp->nused) {
  264.         i = 1;
  265.         bp = (struct b_lelem *) bp->listnext;
  266.     }
  267.     j = bp->first + i - 1;    /* Get slot index */
  268.     if( j >= bp->nslots)
  269.         j -= bp->nslots;
  270.     switch(Type(bp->lslots[j])) {
  271.         case T_Integer:    /* should check for small */
  272.         vals[count] = (int)IntVal(bp->lslots[j]);
  273.         break;
  274.         default:
  275.         RunErr(101,&bp->lslots[j]);
  276.     }
  277.     }
  278.    return 0;
  279. }
  280.  
  281. /*
  282.  * InPort(i) - Return a value from port i
  283.  */
  284.  
  285. FncDcl(InPort,1)
  286. {
  287.    unsigned int value;
  288.    int port;
  289.  
  290.    switch (cvint(&Arg1)) {    /* should check for small */
  291.        case T_Integer:
  292.        port = (int)IntVal(Arg1);
  293.        break;
  294.        default:
  295.       RunErr(101, &Arg1);
  296.    }
  297.    value = inp(port);
  298.    MakeInt(value, &Arg0);
  299. }
  300.  
  301. /*
  302.  * OutPort(i1,i2) - Write i2 to port i1
  303.  */
  304.  
  305. FncDcl(OutPort,2)
  306.    {
  307.    int value;
  308.    unsigned int port;
  309.  
  310.    switch (cvint(&Arg1)) {
  311.        case T_Integer:        /* should check for small */
  312.        port = (int)IntVal(Arg1);
  313.        break;
  314.        default:
  315.        RunErr(101, &Arg1);
  316.    }
  317.    switch (cvint(&Arg2)) {    /* should check for small */
  318.        case T_Integer:
  319.        if (IntVal(Arg2) > 255) {
  320.           RunErr(205, &Arg2);
  321.           }
  322.        value = (int)IntVal(Arg2);
  323.        break;
  324.        default:
  325.        RunErr(101, &Arg2);
  326.    }
  327.    outp(port,value);
  328. }
  329.