home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / commercial-software / programming / AZTEC302.ZIP / TERM.ARC < prev   
Text File  |  1998-09-16  |  6KB  |  283 lines

  1. term.c
  2. #define XOFF    0x13
  3. #define XON        0x11
  4.  
  5. main(argc, argv)
  6. char **argv;
  7. {
  8.     register int speed;
  9.  
  10.     speed = 9600;
  11.     if (argc > 1)
  12.         speed = atoi(argv[1]);
  13.     term(speed);
  14.     comrest();
  15. }
  16.  
  17. #undef putchar
  18.  
  19. putchar(c)
  20. {
  21.     scr_putc(c);
  22.     if (c == '\n')
  23.         scr_putc('\r');
  24.     return c;
  25. }
  26.  
  27. #define INQSIZ    256        /* these sizes must be powers of two */
  28. #define OUTQSIZ    16
  29.  
  30. unsigned char  inqh, inqt, outqh, outqt;
  31. unsigned char inpq[INQSIZ], outq[OUTQSIZ];
  32. int inqcnt;
  33. char mode, stopped, xoffsent;
  34.  
  35. term(speed)
  36. {
  37.     /*
  38.      * Inpq is the queue of characters from the com line, waiting to go to
  39.      * the console.  Outq is from the console, waiting to go to the com line
  40.      */
  41.     register int c, row;
  42.  
  43.     printf("Manx term 3.20A (Use F1 to exit)\n");
  44.     cominit(speed);
  45.     for (;;) {
  46.         if (scr_poll() != -1) {
  47.             c = scr_getc();
  48.             if (c == (59|0x80))        /* check for F1 to exit */
  49.                 return c;
  50.             if (c == (83|0x80))
  51.                 c = 0x7f;        /* map DEL key to ascii DEL */
  52.             outq[outqh] = c;
  53.             outqh = outqh+1 & OUTQSIZ-1;
  54.         }
  55.  
  56.         if (inqh != inqt) {
  57.             c = inpq[inqt] & 0x7f;            /* strip parity */
  58.             ++inqt;
  59.             --inqcnt;
  60.             switch (mode) {
  61.             case 1:
  62.                 mode = 0;
  63.                 switch (c) {
  64. #ifdef DOWNLOAD
  65.                 case 02: case 03:    /* initiate upload/download sequence */
  66.                     download();
  67.                     continue;
  68. #endif
  69.                 case 'Q':            /* insert a blank @ cursor pos */
  70.                     scr_cinsert();
  71.                     continue;
  72.                 case 'W':            /* delete the char @ cursor pos */
  73.                     scr_cdelete();
  74.                     continue;
  75.                 case 'E':            /* insert a blank line @ cursor pos */
  76.                     scr_linsert();
  77.                     continue;
  78.                 case 'R':            /* delete the line @ cursor pos */
  79.                     scr_ldelete();
  80.                     continue;
  81.                 case 'T':            /* clear to end of line */
  82.                     scr_eol();
  83.                     continue;
  84.                 case '*':            /* home cursor & clear screen */
  85.                     scr_clear();
  86.                     continue;
  87.                 case '=':            /* cursor move sequence */
  88.                     mode = 2;
  89.                     continue;
  90.                 }
  91.                 /* fall thru into normal character processing */
  92.  
  93.             case 0:
  94.                 if (c == 0x1b)
  95.                     mode = 1;
  96.                 else if (c == 032)
  97.                     scr_clear();
  98.                 else
  99.                     scr_putc(c);
  100.                 break;
  101.  
  102.             case 2:        /* row character for cursor move */
  103.                 row = c - 32;
  104.                 mode = 3;
  105.                 continue;
  106.  
  107.             case 3:        /* column character for cursor move */
  108.                 c -= 32;
  109.                 scr_curs(row, c);
  110.                 mode = 0;
  111.                 continue;
  112.             }
  113.         }
  114.          
  115.         if (inqcnt > 200 && !stopped) {
  116.             if (comput(XOFF) == 0)
  117.                 stopped = xoffsent = 1;
  118.         } else if (xoffsent && inqcnt < 30) {
  119.             if (comput(XON) == 0)
  120.                 stopped = xoffsent = 0;
  121.         } else if (outqt != outqh && comput(outq[outqt]) == 0) {
  122.             stopped = 0;
  123.             outqt = outqt+1 & OUTQSIZ-1;
  124.         }
  125.     }
  126. }
  127. pcio.asm
  128. ;:ts=8
  129. ;
  130. ;    IBM PC Support routines
  131. ;
  132.  
  133. BASE    equ    3f8H
  134. DATA    equ    BASE+0        ;data register
  135. INTENAB    equ    BASE+1        ;interrupt enable
  136. DIVLAT0    equ    BASE+0        ;divisor latch (least sig. byte)
  137. DIVLAT1    equ    BASE+1        ;divisor latch (most sig. byte)
  138. INTID    equ    BASE+2        ;interrupt identification
  139. LINECTL    equ    BASE+3        ;line control
  140. MODCTL    equ    BASE+4        ;modem control
  141. LINSTAT    equ    BASE+5        ;line status
  142. MODSTAT    equ    BASE+6        ;modem status
  143. INTVEC  equ    30H        ;location of interrupt vector
  144. INTCTL    equ    20h        ;8259 control register
  145. INTCHIP equ    21h        ;8259 mask register
  146.  
  147.  
  148. codeseg    segment    para public 'code'
  149.     assume    cs:codeseg, ds:dataseg
  150. dataseg    segment    para public 'data'
  151. extrn    inqh_:byte, inqt_:byte, inqcnt_:word
  152. extrn    inpq_:byte
  153.  
  154. port    dw    0200H
  155. vec_low dw    ?
  156. vec_high dw    ?
  157. intr_reg db    ?
  158. intr_chp db    ?
  159. dataseg ends
  160.  
  161. data_add dw        ?    ;codesegment variable for location of dataseg in 'C'
  162.  
  163.     public    comput_
  164. comput_    proc    near
  165.     mov    dx,LINSTAT
  166.     in    al,dx
  167.     and    ax,20H            ;is the transmitter ready?
  168.     jz    notready        ;not yet
  169.     mov    bx,sp
  170.     mov    al,2[bx]
  171.     mov    dx,DATA
  172.     out    dx,al            ;output the data
  173.     sub    ax,ax
  174.     ret
  175. notready:
  176.     mov    ax,-1
  177.     ret
  178. comput_    endp
  179.  
  180.     public    cominit_
  181. cominit_ proc    near
  182.     mov    bx,sp
  183.     push    es
  184.     sub    ax,ax
  185.     mov    es,ax
  186.     mov     ax, es:[INTVEC]  ;save contents of interupt table
  187.     mov     vec_low, ax
  188.     mov    ax,es:[INTVEC+2]  ;ditto
  189.     mov    vec_high,ax
  190.     cli
  191.     mov    es:[INTVEC],offset intsr  ;insert the address of int. handler
  192.     mov    es:[INTVEC+2],cs
  193.     mov    data_add,ds        ;mov 'C' dataseg address to var.
  194.     sti
  195.     mov    dx,INTENAB        ;get contents of interupt enable reg.
  196.     in    al,dx
  197.     mov    intr_reg,al         ;sav contents of interupt enable reg.
  198.     mov    al,01H            ;enable data ready intr.
  199.     out    dx,al
  200.     mov    dx,INTCHIP        ;get contents of interupt chip
  201.     in    al,dx
  202.     mov    intr_chp,al        ;sav contents of interupt chip
  203.     and    al,0efH
  204.     out    dx,al            ;turn on interupt chip
  205.     mov    al,80H
  206.     mov    dx,LINECTL
  207.     out    dx,al
  208.     mov    ax,0c200H
  209.     mov    dx,1        ;dividend = 0x1c200
  210.     div    word ptr 2[bx]    ;compute baud rate divisor
  211.     mov    dx,DIVLAT0
  212.     out    dx,al        ;setup com port to given baud rate
  213.     mov    al,ah
  214.     inc    dx        ;second byte of divisor latch
  215.     out    dx,al
  216.     mov    al,03H        ;set 8 data, 1 stop, no parity
  217.     mov    dx,LINECTL
  218.     out    dx,al
  219.     inc    dx
  220.     mov    al,0bh        ;turn on DTR, RTS and enable ints 
  221.     out    dx,al
  222.     mov    al,020h        ;send EOI to 8259
  223.     out    INTCTL,al
  224.     pop     es
  225.     ret
  226. cominit_ endp
  227.  
  228.     public  comrest_
  229. comrest_ proc    near
  230.     push    es
  231.     mov    al,intr_reg
  232.     mov    dx,INTENAB
  233.     out    dx,al
  234.     mov    al,intr_chp
  235.     mov    dx,INTCHIP
  236.     out    dx,al
  237. ;
  238.     sub    ax,ax
  239.     mov    es,ax
  240.     mov    ax, vec_low              ;restore interupt vec. table
  241.     cli
  242.     mov    es:[INTVEC], ax
  243.     mov    ax, vec_high              ;restore interupt vec. table
  244.     mov    es:[INTVEC+2],ax
  245.     sti
  246.     pop    es
  247.     ret
  248. comrest_ endp
  249.  
  250.     public    intsr
  251. intsr    proc    far
  252.     push     ds
  253.     push    ax
  254.     push    dx
  255.     push    bx
  256.     mov    ds,data_add
  257.     mov    dx,DATA
  258.     in    al,dx            ;yes, get the byte
  259.     and    ax,255
  260.     sub    bx,bx
  261.     mov    bl,inqh_
  262.     mov    byte ptr inpq_[bx],al    ;mov char. into cue
  263. ;    inc    inqh_            ;increment cue head will wrap at 255
  264.     inc    bl
  265.     cmp    bl,inqt_
  266.     je    no_overflow
  267.     mov    inqh_,bl
  268.     inc    inqcnt_
  269. no_overflow:
  270. ;
  271.     mov    al,020h        ;send EOI to 8259
  272.     out    INTCTL,al
  273.     pop    bx
  274.     pop    dx
  275.     pop    ax
  276.     pop    ds
  277.     iret
  278. intsr    endp
  279.  
  280. codeseg    ends
  281.     end
  282. ndmarker = &first, *restart = &first;
  283. static