home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / communic / sercom / downl2.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-09-04  |  2.1 KB  |  97 lines

  1.  
  2. #include "dos.h";
  3. #include "stdio.h";
  4.  
  5. #define PORT 0                         /* For COM1. 1 for COM2 */
  6. #define _DATAREADY 1
  7.  
  8. unsigned char calcparm();
  9. unsigned int setparms();
  10. unsigned char charin();
  11. unsigned int getstat();
  12. FILE *fstart();
  13.  
  14. main(argc, argv)
  15. int argc;
  16. char *argv[];
  17. {
  18. FILE *f;
  19. unsigned char ch, parmbyte;
  20.  
  21.    f = fstart(argc, argv);
  22.    if (f == NULL) 
  23.       exit();
  24.  
  25. /* Calculate and set the parameter byte */
  26.  
  27.    parmbyte = calcparm(300, 0, 1, 8);            /* Program 16.5           */
  28.    setparms(PORT, parmbyte);                     /* Program 16.1           */
  29.  
  30. /*
  31. * First we have to call charin because only that sets up the outgoing
  32. * handshaking lines. It will return after a time-out.
  33. */
  34.    charin(PORT, &ch);
  35.  
  36.    printf("%s \n", "Press any key to start download");
  37.    getch();
  38.  
  39.    downl2(f);
  40.  
  41.    fclose(f);                                    /* Close the File         */
  42.  
  43.    printf("%s \n", "Finished");
  44.       
  45. }
  46.  
  47. downl2(f)
  48. FILE *f;
  49. {
  50. unsigned char ch, ah, al;
  51. unsigned int status, timeout;
  52.  
  53.    printf("%s \n", "Press 'ESC' to stop download");
  54.  
  55.    for (;;) {
  56.  
  57.       if (kbhit()) {
  58.          if (getch() == 27) 
  59.                                 return;          /* Hit ESC                */
  60.       }
  61.  
  62.       if (timeout == 4000) {                     /* Warning Message        */
  63.          printf("%s \n", "Waiting");
  64.          timeout = 0;
  65.       }
  66.  
  67.       status = getstat(PORT);                    /* Program 16.4           */
  68.  
  69.       ah = status >> 8;
  70.  
  71.       al = status;
  72. /*
  73. * We could test the other status bits for errors here
  74. */
  75.       if (! (ah & _DATAREADY)) {                 /* Nothing received       */
  76.          ++timeout;
  77.          continue;
  78.       }
  79.  
  80.       timeout = 0;
  81.  
  82. /* We know a character has been received so we will read it       */
  83.  
  84.       charin(PORT, &ch);                         /* Program 16.3           */
  85.  
  86.       fputc(ch, f);                              /* record it to the file  */
  87.  
  88.       putchar(ch);                               /* Display it             */
  89.    }
  90. }
  91.  
  92.  
  93.  
  94. /* Figure 16.9: DOWNL2: Read a File, ROM-BIOS version */
  95.  
  96.  
  97.