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 / HM6.CZ / HM6.C
Text File  |  2000-06-30  |  9KB  |  394 lines

  1. /***************************** Module 6 ************************************/
  2.  
  3. #define C80
  4. #include "hmodem80.h"
  5.  
  6. title()
  7. {
  8.    static char line1[] = "H M O D E M   II";
  9.    static char line3[] = "For H/Z89 and H8/H19 Z80 Systems";
  10.    static char line4[] = "Copyright (c) 1988 by Hal Maney";
  11.    static char line5[] = "510 Barrack Hill Road";
  12.    static char line6[] = "Ridgefield, CT 06877";
  13.    static char line7[] = "Press any key";
  14.  
  15.    cls();
  16.    locate(7,ctr(line1));
  17.    printf(line1);
  18.    locate(9,ctr(Version));
  19.    printf(Version);
  20.    locate(10,ctr(line3));
  21.    printf(line3);
  22.    locate(11,ctr(line4));
  23.    printf(line4);
  24.    locate(12,ctr(line5));
  25.    printf(line5);
  26.    locate(13,ctr(line6));
  27.    printf(line6);
  28.    putlabel(line7);
  29.    hidecurs();
  30.    flush();
  31.    kbwait(10);
  32. }
  33.  
  34. ctr(p)
  35. char *p;
  36. {
  37.    return max((80 - strlen(p))/2,0);
  38. }
  39.  
  40. getconfig()
  41. {
  42.    static int fd;
  43.    static unsigned size, sectors;
  44.    static char *p;
  45.  
  46.    fd = fopen(Cfgfile,"rb");
  47.    if (fd) {
  48.       p = Waste;
  49.       size = (unsigned)p - (unsigned)&BFlag;
  50.       sectors = roundup(size,128);
  51. #ifdef   DEBUG
  52.       printf("\nsize=%d\nsectors=%d",size,sectors);
  53.       printf("\nwaste=%x\n&bflag=%x\n",Waste,&BFlag);
  54. #endif
  55.       read(fd,&BFlag,sectors*128);
  56.       fclose(fd);
  57.    }
  58.    Mdmport = Line.port;
  59.    Mdmstat = Line.mstatus;
  60.    Linestat = Line.lstatus;
  61. }
  62.  
  63. mstrout(string,echo)
  64. char *string;
  65. int echo;             /* echo flag means send to screen also */
  66. {
  67.    static char c;
  68.  
  69.    while (c = *string++) {
  70.       if ((c == RET) || (c == '\n')) {      /* RET is a ! */
  71.          mcharout(CR);
  72.          mcharout(LF);
  73.          c = '\n';
  74.       }
  75.       else if (c == WAITASEC)
  76.          wait(1);
  77.       else
  78.          mcharout(c);
  79.       if (echo)
  80.          putchar(c);
  81.    }
  82.    mswait(100);      /* wait 100 ms */
  83.    purgeline();
  84. }
  85.  
  86. capturetog(filename)
  87. char *filename;
  88. {
  89.    if (!BFlag) {
  90.       strcpy(Lastlog,filename);
  91.       BFlag = TRUE;
  92.       startcapture();
  93.       if (allocerror(MainBuffer))
  94.          BFlag = FALSE;
  95.    }
  96.    else {
  97.       keep(Lastlog);
  98.       BFlag = FALSE;
  99.    }      
  100. }
  101.  
  102. tlabel() /*print level 1 labels on the 25th line*/
  103. {
  104.    killlabel();
  105.    printf(
  106.    "%s1> \033pReceive%s  Log  %s Dir  %sPrScr%s Send%sHangup%s Level %s Help %s",
  107.       Stline,Vl,Vl,Vl,Vl,Vl,Vl,Vl,Vl);
  108.    printf(
  109.    "Quit%s%02d%c%d%d%s%s%s%s%s%s\033q%s",Vl,Baudtable[Current.cbaudindex]/100,
  110.     Current.cparity,Current.cdatabits,Current.cstopbits,Vl,BFlag?"LG":"--",Vl,
  111.     PFlag?"PR":"--",Vl,FDx?"FDX":"HDX",Endline);
  112. }
  113.  
  114. comlabel() /*print level 2 labels*/
  115. {
  116.    killlabel();
  117.    printf(
  118.    "%s2> \033p   Dial%sHost%sConfigure%sPrint%sDisk%sHangup%s Level %s",
  119.     Stline,Vl,Vl,Vl,Vl,Vl,Vl,Vl);
  120.    printf("Help%sQuit%s   %02d%c%d%d%s%s%s%s%s%s\033q%s",Vl,Vl,
  121.     Baudtable[Current.cbaudindex]/100,Current.cparity,Current.cdatabits,
  122.     Current.cstopbits,Vl,BFlag?"LG":"--",Vl,PFlag?"PR":"--",Vl,
  123.     FDx?"FDX":"HDX",Endline);
  124. }
  125.  
  126. scplabel()
  127. {
  128.    putlabel("READING THE SCREEN -> Please wait...");
  129. }
  130.  
  131. slabel() /*print send mode labels on the 25th line*/
  132. {
  133.    putlabel("SEND FILE Mode:  Press ESC to Abort...");
  134. }
  135.  
  136. rlabel() /*print receive mode labels on the 25th line*/
  137. {
  138.    putlabel("RECEIVE FILE Mode:  Press ESC to Abort...");
  139. }
  140.  
  141. hlabel() /* host mode label */
  142. {
  143.    putlabel("HOST MODE:  Press ESC to Exit...");   
  144. }
  145.  
  146. chlabel()  /* chat mode label */
  147. {
  148.    putlabel("CHAT MODE:  Press ESC to Return to Host");   
  149. }
  150.  
  151. putlabel(string)
  152. char string[];
  153. {
  154.    static char bar[] = 
  155. "                                                                                ";
  156.  
  157.    killlabel();
  158.    printf("%s\033p%s",Stline,bar);
  159.    locate(24,ctr(string));
  160.    printf("%s%s%s%s","\033p",string,"\033q",Endline);
  161. }
  162.  
  163. killlabel() /*disable 25th line*/
  164. {
  165.    printf("\033y1");
  166. }
  167.  
  168. getfunct(c)  /*see if function key was pressed*/
  169. unsigned c;
  170. {
  171.    static unsigned m;
  172.  
  173.    if (c == ESC) {
  174.       mswait(50);                    /* wait 50 ms */
  175.       if ((m=getch()) == '?') {
  176.          mswait(50);
  177.          m = getch();
  178.       }
  179.       return m;
  180.    }
  181.    else
  182.       return 0;
  183. }
  184.  
  185. asciisend(file)  /* send ascii file with xon/xoff protocol */
  186. char *file;
  187. {
  188.    char *grabmem();
  189.    static int fd, status, bytes, c;
  190.    static char *inbuf;
  191.    static unsigned j, bufsize;
  192.  
  193.    status = NERROR;
  194.    inbuf = grabmem(&bufsize);
  195.    if (allocerror(inbuf))
  196.       return NERROR;
  197.    fd = fopen(file,"rb");
  198.    if (openerror(fd,file)) {
  199.       free(inbuf);
  200.       return NERROR;
  201.    }
  202. #ifdef   DEBUG
  203.    printf("\nbufsize = %d\n",bufsize);
  204. #endif
  205.    sprintf(Buf,"Sending %s, ASCII Transfer",file);
  206.    putlabel(Buf);
  207.    j = 0;
  208.    QuitFlag = FALSE;
  209.    while (bytes = read(fd,inbuf,bufsize)) {
  210.       c = inbuf[0];
  211.       for (j = 0; (j < bytes) && (c != CTRLZ); c = inbuf[++j]) {
  212.          if (XonXoff && minprdy() && (mcharinp() == CTRLS)) {
  213.             putlabel("\007XOFF Received, waiting for XON");
  214.             while (readline(10) != CTRLQ) {
  215.                if (QuitFlag == TRUE)
  216.                   goto cleanup;
  217.             }
  218.             putlabel(Buf);
  219.          }
  220.          mcharout(c);
  221.          putchar(c);
  222.       }
  223.    }
  224.    status = OK;
  225.  
  226. cleanup:
  227.    fclose(fd);
  228.    free(inbuf);
  229.    return status;
  230. }
  231.  
  232. /***************** directory functions *************************************/
  233.  
  234. struct direntry {
  235.    char userno;
  236.    char flname[8];
  237.    char ftype[3];
  238.    char fextent;
  239.    char reserved[2];
  240.    char record;
  241.    char map[16];
  242. };
  243.  
  244. struct fcb {
  245.    char drive;
  246.    char filename[8];
  247.    char filetype[3];
  248.    char extent;
  249.    int freserved;
  250.    char recused;
  251.    unsigned abused[8];
  252.    char seqrec;
  253.    unsigned ranrec;
  254.    char ranreco;
  255. } Thefcb;
  256.  
  257. struct dpb {
  258.    unsigned spt;
  259.    char bsh;
  260.    char blm;
  261.    char exm;
  262.    unsigned dsm;
  263.    unsigned drm;
  264.    char al0;
  265.    char al1;
  266.    unsigned cks;
  267.    unsigned off;
  268. };
  269.  
  270. directory()
  271. {
  272.    static int j, factor, dircode;
  273.    static unsigned i, dtotal, atotal, allen, remaining, bls;
  274.    static char *alloca;
  275.    static struct stat *statp;
  276.    static struct dpb *thedpb;
  277.    static struct direntry *dp;
  278.  
  279.    cls();
  280.    statp = alloc(sizeof(struct stat));
  281.    if (allocerror(statp))
  282.       return;
  283.    sprintf(Buf,"Directory for Drive %c:",Currdrive);
  284.    putlabel(Buf);
  285.    bdos(SETDMA,CPMBUF);         /* set dma address */
  286.    dircode = getfirst("????????.???");
  287.    for (j=1; dircode != 0xff; j++) {
  288.       dp = CPMBUF + dircode*32;
  289.       memcpy(statp->fname,dp->flname,8);
  290.       memcpy(statp->fext,dp->ftype,3);
  291.       statp->fname[8] = statp->fext[3] = '\0';
  292.       strcpy(Pathname,statp->fname);
  293.       strcat(Pathname,".");
  294.       strcat(Pathname,statp->fext);
  295.       fstat(Pathname,statp);
  296.       sprintf(Buf,"%8s.%3s%3dk",statp->fname,statp->fext,
  297.          roundup(statp->records,8));
  298.       strcat(Buf,(j % COLUMNS) ? "  " : "\n");
  299.       if (Inhost)
  300.          mstrout(Buf,TRUE);
  301.       else
  302.          printf(Buf);
  303.       dircode = getnext();
  304.    }
  305.    thedpb = nbdos(GETDPB,NULL);
  306.    alloca = nbdos(GETALL,NULL);
  307.    bls = 0x0001;
  308.    bls <<= thedpb->bsh + 7;
  309.    factor = bls/1024;
  310.    dtotal = factor * (thedpb->dsm+1);
  311.    allen = (thedpb->dsm/8) + 1;
  312.    for (atotal=i=0; i<allen; i++)
  313.       atotal += cntbits(*(alloca+i));
  314.    atotal *= factor;
  315.    remaining = dtotal - atotal;
  316.    sprintf(Buf,"\n\nSpace remaining on %c:  %dk\n",Currdrive,remaining);
  317.    if (Inhost)
  318.       mstrout(Buf,TRUE);
  319.    else
  320.       printf(Buf);
  321.    free(statp);
  322. }
  323.  
  324. fstat(fname,status)
  325. char *fname;
  326. struct stat *status;
  327. {
  328.    unsigned filelength();
  329.  
  330.    makfcb(fname,&Thefcb);
  331.    status->records = filelength(&Thefcb);
  332.    getfirst(fname);
  333.    makfcb("????????.???",&Thefcb);
  334. }
  335.  
  336. unsigned
  337. filelength(fcbp)
  338. struct fcb *fcbp;
  339. {
  340.    bdos(0x23,fcbp);
  341.    return fcbp->ranrec;
  342. }
  343.  
  344. roundup(dividend,divisor)
  345. int dividend, divisor;
  346. {
  347.    return (dividend/divisor + ((dividend%divisor) ? 1 : 0));
  348. }
  349.  
  350. getfirst(aname)      /* ambiguous file name */
  351. char *aname;
  352. {
  353.    makfcb(aname,&Thefcb);
  354.    return bdos(SFF,&Thefcb) & 0xff;
  355. }
  356.  
  357. getnext()
  358. {
  359.    return bdos(SFN,NULL) & 0xff;
  360. }
  361.  
  362. nbdos()
  363. {
  364. #ifdef C80
  365. #asm
  366.    POP H
  367.    POP D
  368.    POP B
  369.    PUSH B
  370.    PUSH D
  371.    PUSH H
  372.    CALL 5
  373. #endasm
  374. #endif
  375. }
  376.  
  377. memcpy(dest,source,count)
  378. char *dest, *source;
  379. int count;
  380. {
  381.    while (count--)
  382.       *dest++ = *source++;
  383. }
  384.  
  385. memset(dest,byte,count)
  386. char *dest, byte;
  387. int count;
  388. {
  389.    while (count--)
  390.       *dest++ = byte;
  391. }
  392.    
  393. /************************** END OF MODULE 6 *********************************/
  394.