home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / CPM / HEATH / HMSRC20.LBR / HM3.CZ / HM3.C
Text File  |  2000-06-30  |  11KB  |  516 lines

  1. /************************ Module 3 ***************************************/
  2. /*                                                                       */
  3. /*      The following functions are hardware dependent.  These are       */
  4. /*  set up to use a Hayes modem running through the H8-4 board           */
  5. /*  on the HEATH H8, or the serial board on the H89.  The modem port     */
  6. /*  is driven at interrupt level 5 and must be configured for interrupt  */
  7. /*  5 on the serial board.  This can be changed to another level if      */
  8. /*  needed.                                                              */
  9. /*                                                                       */
  10. /*************************************************************************/
  11.  
  12. #define  C80
  13.  
  14. /* box characters for H-19 */
  15.  
  16. #define     LC       38
  17. #define     TR       2
  18. #define     HT       12
  19. #define     WD       41
  20. #define     HORIZ    'a'
  21. #define     VERT     '`'
  22. #define     UL       'f'
  23. #define     UR       'c'
  24. #define     LL       'e'
  25. #define     LR       'd'     
  26. #define     RC       LC+WD-1
  27. #define     BR       TR+HT-1
  28.  
  29. /***************************/
  30.  
  31. #include "hmodem80.h"
  32.  
  33. prtservice()    /*printer service routine*/
  34. {
  35.    if (pready()) {
  36.       if (Prthead != Prttail) {
  37.          bdos(5,*Prttail++);        /* write list byte */
  38.          if (Prttail > Prttop)
  39.             Prttail = Prtbottom;
  40.       }
  41.    }
  42. }
  43.  
  44. pready()   /*get printer status using bios call*/
  45. {
  46. #ifdef   C80
  47. #asm
  48.          LXI     H,prdy1
  49.          PUSH    H               ;SAVE RETURN ADDRESS
  50.          LHLD    BIOSADDR        ;start of bios
  51.          LXI     D,LISTST        ;offset of list status call
  52.          DAD     D
  53.          PCHL                    ;BIOS CALL TO LISTST
  54. prdy1:   MOV     L,A             ;RESULT IN A
  55.          MVI     H,0
  56. #endasm
  57. #endif
  58. }
  59.  
  60. screenprint()
  61. {  
  62.    static int c, pos;
  63.  
  64.    scplabel();
  65.    flush();
  66.    if (!PFlag)
  67.       if (getprtbuf() != OK)
  68.          return;
  69.    pos = 0;
  70.    outp(0xe9,0);             /* disable console interrupt */
  71.    outp(0xe8,ESC);           /* send ESC # to transmit screen */
  72.    mswait(6);
  73.    outp(0xe8,'#');
  74.    while ((c=dio()) != CR) {
  75.       if (c == ESC)
  76.          dio();
  77.       else {
  78.          *Prthead++ = c;
  79.          adjustprthead();
  80.          pos++;
  81.          if (pos == 80) {
  82.             *Prthead++ = CR;
  83.             adjustprthead();
  84.             *Prthead++ = LF;
  85.             adjustprthead();
  86.             pos = 0;
  87.          }
  88.       }
  89.    }
  90.    outp(0xe9,1);             /* enable console interrupt */
  91.    flush();
  92.    if (!PFlag)
  93.       free(Prtbuf);
  94. }
  95.  
  96. adjustprthead()
  97. {
  98.    if (Prthead > Prttop)
  99.       Prthead = Prtbottom;
  100. }
  101.  
  102. dio()          /* direct console port inp when bdos is too slow */
  103. {
  104. #asm
  105. INLP:       IN       0EDH     ;check port status
  106.           ANI    1           ;char ready?
  107.           JZ       INLP        ;wait for char
  108.           IN       0E8H
  109.           ANI    177Q        ;strip parity
  110.           MOV    L,A
  111.           MVI   H,0
  112.           RET
  113. #endasm
  114. }
  115.  
  116. initializemodem()
  117. {
  118.    resetace();
  119.    mstrout("\n\n",FALSE);
  120.    mstrout(Modem.init,FALSE);
  121.    while (readline(10) != TIMEOUT);   /*gobble echoed characters*/
  122. }
  123.  
  124. getch()
  125. {
  126.    return bdos(DIRCTIO,INPUT);
  127. }
  128.  
  129. flush()
  130. {
  131.    while(bdos(GCS,NULL))          /*clear type-ahead buffer*/
  132.       bdos(CONIN,NULL);
  133.    getch();           /*and anything else*/
  134. }
  135.  
  136. purgeline()
  137. {
  138.    while (minprdy())              /*while there are characters...*/
  139.      mcharinp();             /*gobble them*/
  140. }
  141.  
  142. mread(buffer,count,timeout)      /* time in tenths of seconds */
  143. char *buffer;
  144. int count, timeout;
  145. {
  146.    static int i, t;
  147.  
  148.    timeout *= 50;   /* 2 ms ticks */
  149.  
  150.    i = 0;
  151.    t = timeout + *Ticptr;
  152.    while (!minprdy() && (t != *Ticptr) && !opabort());  /*wait until ready*/
  153.    while (count--) {
  154.       if (minprdy())
  155.          buffer[i++] = mcharinp();           /*get it*/
  156.       else
  157.          break;
  158.    }
  159.    return i;
  160. }
  161.  
  162. mcharinp()
  163. {
  164.    static unsigned c;
  165.  
  166.    c = *Mdmtail++;
  167.    if (Mdmtail > Mdmtop) {
  168.       Tlap++;
  169.       Mdmtail = Mdmbottom;
  170.    }
  171.    if (Stopped) {
  172.       if ((Hlap == Tlap) || ((Mdmtail-Mdmhead) > 256)) {
  173.          outp(Mdmport,CTRLQ);
  174.          Stopped = FALSE;
  175.       }
  176.    }
  177.    return c;
  178. }
  179.  
  180. mcharout(c)
  181. char c;
  182. {
  183.    while (!moutrdy())
  184.       opabort();         /* do nothing until ready except check for abort */
  185.    outp(Mdmport,c);
  186. }
  187.  
  188. moutrdy()
  189. {
  190.    return inp(Linestat) & OUTSTAT;
  191. }
  192.  
  193. minprdy()
  194. {
  195.    return (Mdmtail != Mdmhead) || Stopped;
  196. }
  197.  
  198. cls() /*clear the screen*/
  199. {
  200.    printf("\n\033E\b\b\b\b\b");
  201. }
  202.  
  203. locate(r,c)
  204. int r, c;
  205. {
  206.    printf("\033Y%c%c",r+32,c+32);
  207. }
  208.  
  209. box()          /* put box on screen for file transfer */
  210. {
  211.    register int i;
  212.    static char *headings[] = { "","PROTOCOL:","FILE NAME:","FILE SIZE:",
  213.                                "BLOCK CHECK:","TRANSFER TIME:",
  214.                                "BYTES TRANSFERRED:","BLOCKS TRANSFERRED:",
  215.                                "SECTORS IN FILE:","ERROR COUNT:",
  216.                                "LAST MESSAGE:  NONE" };
  217.    static int start[] = { 0,13+LC,12+LC,12+LC,10+LC,8+LC,4+LC,3+LC,6+LC,
  218.                           10+LC,9+LC };
  219.       
  220.    printf("\033F");
  221.    locate(TR,LC);
  222.    putchar(UL);
  223.    for (i=1; i<WD-1; i++)
  224.       putchar(HORIZ);
  225.    putchar(UR);
  226.    locate(BR,LC);
  227.    putchar(LL);
  228.    for (i=1; i<WD-1; i++)
  229.       putchar(HORIZ);
  230.    putchar(LR);
  231.    for (i=1; i<HT-1; i++) {
  232.       locate(TR+i,LC);
  233.       putchar(VERT);
  234.       locate(TR+i,RC);
  235.       putchar(VERT);
  236.    }
  237.    printf("\033G");
  238.    clrbox();
  239.    for (i=1; i<11; i++) {
  240.       locate(TR+i,start[i]);
  241.       printf(headings[i]);
  242.    }   
  243. }
  244.  
  245. clrbox()
  246. {
  247.    register int i;
  248.  
  249.    for (i=TR+1; i < BR; i++) {
  250.       locate(i,LC+1);
  251.       printf("                                       ");
  252.    }
  253. }
  254.  
  255. hidecurs()
  256. {
  257.    printf("\033x5");
  258. }
  259.  
  260. showcurs()
  261. {
  262.    printf("\033y5");
  263. }
  264.  
  265. savecurs()
  266. {
  267.    printf("\033j");    /* save cursor position */
  268. }
  269.  
  270. restcurs()
  271. {
  272.    printf("\033k");    /* return cursor to previously saved position */
  273. }
  274.  
  275. minterrupt()    /*modem input interrupt service routine*/
  276. {
  277. #ifdef   C80
  278. #asm
  279.    PUSH    PSW
  280.    PUSH    B
  281.    PUSH    D
  282.    PUSH    H
  283. #endasm
  284.    if (inp(Linestat) & INSTAT) {
  285.       *Mdmhead++ = inp(Mdmport);
  286.       if (Mdmhead > Mdmtop) {
  287.          Hlap++;
  288.          Mdmhead = Mdmbottom;
  289.       }
  290.       if (  !Stopped 
  291.          && XonXoff
  292.          && (Hlap != Tlap) 
  293.          && ((Mdmtail-Mdmhead) < 128)) {
  294.             outp(Mdmport,CTRLS);
  295.             Stopped = TRUE;
  296.       }
  297.    }
  298. #asm
  299.    POP     H
  300.    POP     D
  301.    POP     B
  302.    POP     PSW
  303.    EI
  304. #endasm
  305. #endif
  306. }
  307.  
  308. initvector()
  309. {
  310.    static char *p;
  311.    static unsigned *q;
  312.  
  313.    p = Intlevel * 8;
  314.    q = p + 1;
  315.    *p = JUMP;
  316.    *q = minterrupt;
  317.    Mdmhead = Mdmtail = Mdmbottom = MdmInBuffer = alloc(MBUFSIZ);
  318.    Mdmtop = MdmInBuffer + MBUFSIZ - 1;
  319.    if (allocerror(MdmInBuffer))
  320.       deinitvector();
  321. }
  322.  
  323. deinitvector()
  324. {
  325.    static char *p;
  326.  
  327.    outp(Mdmport+1,0);   /*disable modem interrupts*/
  328.    p = Intlevel * 8;
  329.    *p = ENABLE;
  330.    p++;
  331.    *p = RTN;
  332. }
  333.  
  334. openerror(chan,fname)
  335. int chan;
  336. char *fname;
  337. {
  338.    if (!chan) {
  339.       printf("\n\nERROR - Cannot open %s\n\n",fname);
  340.       wait(3);
  341.    }
  342.    return !chan;
  343. }
  344.  
  345. wrerror(fname)
  346. char *fname;
  347. {
  348.    printf("\n\nERROR - Cannot write to %s\n\n",fname);
  349.    wait(3);
  350. }
  351.  
  352. allocerror(p)
  353. char *p;
  354. {
  355.    static int status;
  356.  
  357.    if (status=(p == -1))
  358.       perror("Memory allocation failure");
  359.    return status;   
  360. }
  361.  
  362. perror(string)
  363. char *string;
  364. {
  365.    printf("\007\nERROR - %s\n\n",string);
  366.    wait(3);
  367. }
  368.  
  369. mdmerror()
  370. {  
  371.    return inp(Linestat) & 0x0e;
  372. }
  373.  
  374. hangup()
  375. {
  376.    printf("\nHanging up...");
  377.    outp(Mdmport+4,02);             /*kill DTR momentarily*/
  378.    mswait(200);
  379.    outp(Mdmport+4,03);
  380.    mstrout(Modem.hangup,FALSE);
  381.    printf("\033p Line Disconnected \033q\n");
  382.    resetace();
  383. }
  384.  
  385. kbwait(seconds)
  386. unsigned seconds;
  387. {
  388.    static unsigned t;
  389.    static int c;
  390.  
  391.    t = seconds * 500;
  392.    t += *Ticptr;
  393.    while(!(c=getch()) && (t != *Ticptr));
  394.    return ((c & 0xff) == ESC);
  395. }
  396.  
  397. wait(seconds)
  398. unsigned seconds;
  399. {
  400.    mswait(seconds*1000);
  401. }
  402.  
  403. mswait(milliseconds)
  404. unsigned milliseconds;
  405. {
  406.    static unsigned t;
  407.  
  408.    t = milliseconds >> 1;         /* 2-ms ticks */
  409.    t += *Ticptr;
  410.    while (t != *Ticptr);  /*wait until ready*/
  411. }
  412.  
  413. setace(n)   /* for a particular phone call */
  414. int n;
  415. {
  416.    Current.cbaudindex = Book[n].pbaudindex;
  417.    Current.cparity = Book[n].pparity;
  418.    Current.cdatabits = Book[n].pdatabits;
  419.    Current.cstopbits = Book[n].pstopbits;
  420.    updateace();
  421. }
  422.  
  423. resetace()  /* to default values */
  424. {
  425.    Current.cbaudindex = Line.baudindex;
  426.    Current.cparity = Line.parity;
  427.    Current.cdatabits = Line.databits;
  428.    Current.cstopbits = Line.stopbits;
  429.    updateace();
  430. }
  431.  
  432. updateace()
  433. {
  434.    initace(Mdmport,Current.cbaudindex,Current.cparity,
  435.       Current.cdatabits,Current.cstopbits);
  436. }
  437.  
  438.  
  439. initace(port,b,p,d,s)                               /*for 8250 ace*/
  440. int port,b,p,d,s;
  441. {
  442.    static int parity, databits, stopbits;
  443.  
  444.    switch (p) {
  445.    case 'E':
  446.       parity = EVENPARITY;
  447.       break;
  448.    case 'O':
  449.       parity = ODDPARITY;
  450.       break;
  451. /* case 'N': */
  452.    default:
  453.       parity = NOPARITY;
  454.       break;
  455.    }
  456.    switch (d) {
  457.    case 7:
  458.       databits = SEVENBITS;
  459.       break;
  460. /* case 8:  */
  461.    default:
  462.       databits = EIGHTBITS;
  463.       break;
  464.    }
  465.    switch (s) {
  466.    case 1:
  467.       stopbits = ONEBIT;
  468.       break;
  469. /* case 2:   */
  470.    default:
  471.       stopbits = TWOBITS;
  472.       break;
  473.    }
  474.    outp(port+3,0x80);           /*set baud rate access bit*/
  475.    outp(port,Divtable[b] & 0xff);   /*set baud rate lsb*/
  476.    outp(port+1,Divtable[b]>>8);    /*then set msb*/
  477.    outp(port+3,parity | databits | stopbits);
  478.    outp(port+4,03);             /*set DTR and RTS high*/
  479.    outp(port+1,01);             /*enable received data interrupt*/
  480. }
  481.  
  482. outp(port,c)
  483. {
  484. #ifdef   C80
  485. #asm
  486.             POP     H               ;RETURN ADDRESS
  487.             POP     D               ;CHARACTER TO OUTPUT
  488.             POP     B               ;PORT TO OUTPUT
  489.             PUSH    B
  490.             PUSH    D
  491.             PUSH    H
  492. .Z80  
  493.             OUT    (C),E            ;NEED Z80 TO DO THIS
  494. .8080
  495. #endasm
  496. #endif
  497. }
  498.  
  499. inp(port)
  500. {
  501. #ifdef   C80
  502. #asm
  503.             POP     H               ;RETURN ADDRESS
  504.             POP     B               ;PORT TO INPUT
  505.             PUSH    B
  506.             PUSH    H
  507. .Z80
  508.             IN      L,(C)           ;Z80 ONLY
  509. .8080
  510.             MVI     H,0
  511. #endasm
  512. #endif
  513. }
  514.  
  515. /************************ end of module 3 **********************************/
  516.