home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / c64cross / c64boot.c < prev    next >
C/C++ Source or Header  |  2020-01-01  |  2KB  |  55 lines

  1. /* "c64boot.c"  initial download program for Unix systems
  2.  * program to download files to C64, modelled on C64BOOT.CLU
  3.  * sends lines, one at a time, each followed by a checksum.
  4.  * the C64 validates cksum and returns "OK" or "NG".
  5.  * last line cksum sent with leading "-" to signify eof.
  6.  * Although written on a Unix system, the C code contains
  7.  * no kernal calls and should be fairly portable.
  8.  * Written by:  Alastair Mayer, U. of Guelph, 2-Apr-85
  9.  *               ( ACDMAYER at UOGUELPH.BITNET )
  10.  * Changes and fixes by Matt Sorrels, August 1992
  11.  */
  12. #include <stdio.h>
  13. #define BUFFMAX 256
  14. #define EOS '\0'
  15.  
  16. main(argc,argv)
  17. int argc;
  18. char *argv[];
  19. {
  20.  
  21.    char received[BUFFMAX],
  22.         line[BUFFMAX];
  23.    char *c;
  24.    int  checksum = 0;
  25.    int eof = 0;
  26.    FILE *fd;
  27.  
  28.    if (argc>1)
  29.       fd = fopen(argv[1],"r");
  30.    if (fd == NULL) {
  31.       fprintf(stderr,"%s: can't open '%s'\n",argv[0],argv[1]);
  32.       exit(-1);
  33.       }
  34.    while (strcmp(received,"OK"))
  35.        scanf("%[^\n]%*c",received);
  36.       /* wait for starting "OK" */
  37.  
  38.    while ( (! eof) || (strcmp(received,"NG")==0)) {
  39.        if (strcmp(received,"OK")==0) {
  40.           line[0] = EOS;  /* clear it first */
  41.           eof = (fscanf(fd,"%[^\n]%*c",line) < 0);
  42.           }
  43.        checksum = 0;
  44.        for (c=line; *c ; c++) {
  45.           putchar(*c);
  46.           checksum += *c;
  47.           }
  48.        putchar('\n');
  49.        if (eof) putchar('-');
  50.        printf("%d\n",checksum);
  51.        received[0] = EOS;  /* clear it in case we don't read anything */
  52.        scanf("%[^\n]%*c",received);
  53.        }
  54. }
  55.