1 /* This program sends an td8e Dectape image out the serial port to the PDP8
2 restore 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
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]))
45 unsigned short block_buf
[BLKSIZE
];
47 unsigned int chksum
= 0;
51 setup_config(&baud
,&two_stop
,serial_dev
);
54 strcpy(filename
,argv
[1]);
56 printf("Enter file name to send\n");
62 in
= fopen(filename
,"rb");
64 in
= fopen(filename
,"r");
67 fprintf(stderr
,"On file %s ",filename
);
68 perror("open failed");
73 /* For testing write to file, only works in unix version */
74 fd
= open("dat",O_RDWR
| O_CREAT
| O_TRUNC
,0666);
76 perror("Open failed on dat");
80 fd
= init_comm(serial_dev
,baud
,two_stop
);
87 /* If start of new block */
88 if (count
== BLKSIZE
) {
90 /* If sent all blocks pdp8 asked for wait for it to ask for more */
92 while (ser_read(fd
,(char *)buf
,1) < 1 && !terminate
);
95 printf("Got readsize %d\n",readsz);
98 if ((rc
= fread(block_buf
,2,BLKSIZE
,in
)) < BLKSIZE
) {
101 perror("\nfile read failed\n");
104 /* Must be at start of block when data done */
106 printf("\nEarly end of file %d, %d\n",count
,rc
);
109 /* Send end of data flag */
111 ser_write(fd
,(char *)buf
,1);
112 /* Wait for PDP to ask for checksum */
113 while (ser_read(fd
,(char *)buf
,1) < 1 && !terminate
);
116 buf
[1] = (chksum
& 0xfff) >> 8;
117 ser_write(fd
,(char *)buf
,2);
121 ser_write(fd
,(char *)buf
,1);
123 if (block
% 5 == 0) {
124 printf("Block %d\r",block
);
128 /* Send 2 words as 3 bytes */
129 chksum
+= block_buf
[count
];
130 buf
[0] = block_buf
[count
];
131 if (count
+ 1 == BLKSIZE
) {
132 buf
[1] = (block_buf
[count
] >> 8);
134 ser_write(fd
,(char *)buf
,2);
136 chksum
+= block_buf
[count
+1];
137 buf
[1] = (block_buf
[count
] >> 8) | (block_buf
[count
+1] << 4);
138 buf
[2] = (block_buf
[count
+1] >> 4);
140 ser_write(fd
,(char *)buf
,3);