| 1 | /* This program sends an rx01 image out the serial port to the PDP8 restore |
| 2 | program. It will prompt for the file to send or use first command |
| 3 | line argument. It needs a config file dumprest.cfg or $HOME/.dumprest.cfg |
| 4 | with the format defined in config.c |
| 5 | |
| 6 | The PDP8 end should be running before this program is started |
| 7 | |
| 8 | On the PC ctrl-break will terminate the program |
| 9 | */ |
| 10 | #ifdef PC |
| 11 | #include "encom.h" |
| 12 | #else |
| 13 | #include <termios.h> |
| 14 | #include <unistd.h> |
| 15 | #include <memory.h> |
| 16 | #endif |
| 17 | |
| 18 | #include <stdio.h> |
| 19 | #include <fcntl.h> |
| 20 | #include <time.h> |
| 21 | #include <signal.h> |
| 22 | #include <stdlib.h> |
| 23 | #include <string.h> |
| 24 | |
| 25 | #define ARRAYSIZE(a) (sizeof(a) / sizeof(a[0])) |
| 26 | |
| 27 | int terminate = 0; |
| 28 | |
| 29 | #include "config.c" |
| 30 | #include "comm.c" |
| 31 | |
| 32 | main(argc,argv) |
| 33 | int argc; |
| 34 | char *argv[]; |
| 35 | { |
| 36 | int fd; |
| 37 | FILE *in; |
| 38 | char filename[256]; |
| 39 | char serial_dev[256]; |
| 40 | long baud; |
| 41 | int two_stop; |
| 42 | unsigned char buf[3]; |
| 43 | unsigned char temp[256]; |
| 44 | int sect,scnt,track; |
| 45 | unsigned int chksum = 0; |
| 46 | int cntr; |
| 47 | int interleave = 2; |
| 48 | int size_flag; |
| 49 | int sector_size; |
| 50 | |
| 51 | setup_config(&baud,&two_stop,serial_dev); |
| 52 | |
| 53 | if (argc > 1) { |
| 54 | strcpy(filename,argv[1]); |
| 55 | } else { |
| 56 | printf("Enter file name to send\n"); |
| 57 | fflush(stdout); |
| 58 | scanf("%s",filename); |
| 59 | } |
| 60 | |
| 61 | #ifdef PC |
| 62 | in = fopen(filename,"rb"); |
| 63 | #else |
| 64 | in = fopen(filename,"r"); |
| 65 | #endif |
| 66 | if (in == NULL) { |
| 67 | fprintf(stderr,"On file %s ",filename); |
| 68 | perror("open failed"); |
| 69 | exit(1); |
| 70 | } |
| 71 | |
| 72 | fseek(in, 512511L, SEEK_SET); |
| 73 | if (fread(temp,1,1,in) == 1) { |
| 74 | interleave = 3; |
| 75 | printf("Sending double density disk image (RX02)\n"); |
| 76 | size_flag = 044; |
| 77 | sector_size = 256; |
| 78 | } else { |
| 79 | interleave = 2; |
| 80 | printf("Sending single density disk image (RX01)\n"); |
| 81 | size_flag = 022; |
| 82 | sector_size = 128; |
| 83 | } |
| 84 | |
| 85 | |
| 86 | #if 0 |
| 87 | /* For testing write to file, only works in unix version */ |
| 88 | fd = open("dat",O_RDWR | O_CREAT | O_TRUNC,0666); |
| 89 | if (fd < 0) { |
| 90 | perror("Open failed on dat"); |
| 91 | exit(1); |
| 92 | } |
| 93 | #else |
| 94 | fd = init_comm(serial_dev,baud,two_stop); |
| 95 | #endif |
| 96 | |
| 97 | buf[0] = size_flag; |
| 98 | ser_write(fd,(char *)buf,1); |
| 99 | chksum = buf[0]; |
| 100 | |
| 101 | sect = 1; |
| 102 | track = 0; |
| 103 | scnt = 0; |
| 104 | while(!terminate) { |
| 105 | if (track > 76) { |
| 106 | buf[0] = 0xfe; |
| 107 | chksum += buf[0]; |
| 108 | chksum = -chksum; |
| 109 | buf[1] = chksum; |
| 110 | ser_write(fd,(char *)buf,2); |
| 111 | printf("\nDone\n"); |
| 112 | exit(0); |
| 113 | } else { |
| 114 | buf[0] = 0xff; |
| 115 | chksum += buf[0]; |
| 116 | ser_write(fd,(char *)buf,1); |
| 117 | } |
| 118 | fseek(in, (track*26L + sect - 1) * sector_size, SEEK_SET); |
| 119 | if (fread(temp,sector_size,1,in) != 1) { |
| 120 | perror("Fread failed"); |
| 121 | exit(1); |
| 122 | } |
| 123 | for (cntr = 0; cntr < sector_size; cntr++) |
| 124 | chksum += temp[cntr]; |
| 125 | buf[0] = track; |
| 126 | buf[1] = sect; |
| 127 | chksum += buf[0]; |
| 128 | chksum += buf[1]; |
| 129 | ser_write(fd,(char *)buf,2); |
| 130 | ser_write(fd,(char *)temp,sector_size); |
| 131 | |
| 132 | sect += interleave; |
| 133 | if (sect > 26) |
| 134 | sect -= 26; |
| 135 | if (sect == 1) |
| 136 | sect++; |
| 137 | |
| 138 | scnt++; |
| 139 | if (scnt >= 26) { |
| 140 | printf("Track %d\r",track); |
| 141 | fflush(stdout); |
| 142 | track++; |
| 143 | sect = 1; |
| 144 | scnt = 0; |
| 145 | } |
| 146 | } |
| 147 | return 1; |
| 148 | } |