1 /* This program receives an td8e Dectape image from the serial port from the
2 PDP8 dump program. It will prompt for the file to receive or use first
3 command line argument. It needs a config file dumprest.cfg or
4 $HOME/.dumprest.cfg with the format defined in config.c
6 This program should be running before the PDP8 end is started.
8 On the PC ctrl-break will terminate the program
25 #define ARRAYSIZE(a) (sizeof(a) / sizeof(a[0]))
42 unsigned char buf
[200];
47 setup_config(&baud
,&two_stop
,serial_dev
);
50 strcpy(filename
,argv
[1]);
52 printf("Enter file name to receive\n");
58 out
= fopen(filename
,"wb");
60 out
= fopen(filename
,"w");
63 fprintf(stderr
,"On file %s ",filename
);
64 perror("open failed");
69 /* For testing read from file, only works in unix version */
70 fd
= open("dat",O_RDONLY
,0666);
72 perror("Open failed on dat");
76 fd
= init_comm(serial_dev
,baud
,two_stop
);
82 c
= ser_read(fd
,(char *)buf
,sizeof(buf
));
84 perror("Serial read failed");
87 for (i
= 0; i
< c
; i
++) {
89 /* -2 = waiting for checksum */
96 temp
= temp
| (buf
[i
] << 8);
97 if (((temp
+ chksum
) & 0xfff) != 0) {
98 printf("\nChecksum mismatch %x %x\n",temp
,chksum
);
101 printf("\nDone, wait for program to exit\n");
105 /* -1 = waiting for block flag */
106 if (buf
[i
] != 0xff && buf
[i
] != 0xfd) {
107 /* End of data flag */
108 if (buf
[i
] == 0xfe) {
112 printf("\nMissing start of block flag\n");
118 printf("\nblock %d bad\n", block
);
122 /* Count >= 0 is word count in block */
123 /* Byte is byte in 3 byte sequence for 2 words */
129 temp
= (temp
| (buf
[i
] << 8)) & 0xfff;
130 fwrite(&temp
,2,1,out
);
131 chksum
= chksum
+ temp
;
137 temp
= (temp
| (buf
[i
] << 4)) & 0xfff;
138 fwrite(&temp
,2,1,out
);
139 chksum
= chksum
+ temp
;
143 /* If at end of block setup for next */
148 if (block
% 5 == 0) {
149 printf("Block %d\r",block
);