1 /* DLOAD 16 Jan 88 Burt Mitchell */
3 /* Host software for an PC compatible to send files to a */
4 /* Color Computer using the DLOAD command. */
5 /* The Coco must be running Extended Color Basic v1.1 or OLDER */
7 /* This program uses 1200 baud as it is the default for the Coco. It is */
8 /* configured to use the PC's com1: port. To change this you will have to */
9 /* edit the procedures transmit_char() and receive_char(). */
11 /* This program has not been tested in the DLOADM mode as I have no way */
12 /* of getting a Coco machine language routine into the PC in the first */
15 /* To operate DLOAD: */
16 /* on the PC enter DLOAD filename.ext a */
17 /* the PC will inform you that it is waiting. */
18 /* on the Coco enter DLOAD */
20 /* Modified for use with unix by Bryan Clingman (bac@realtimeweb.com) */
32 /* literals for the DLOAD protocol */
35 #define block_req 0x97
44 #define block_size 127
50 unsigned char rx_char,
57 void transmit_char(unsigned char tx_char)
67 printf("transfer aborted by target. \n");
72 int main(int argc, char *argv[])
76 printf("usage: DLOAD [filename.ext] [A or B] [port]\n");
82 if ((*argv[2] == 'B') || (*argv[2] == 'b'))
86 infile = fopen(tx_name,"rb");
89 if ((*argv[2] == 'A') || (*argv[2] == 'a'))
93 infile = fopen(tx_name,"r");
97 printf("unknown file type \n");
103 printf("cant open the file to be transmitted \n");
110 /* wait for the coco to start the transfer */
112 while (rx_char != file_req)
117 /* proceed with the file transfer */
118 while (proceed == true)
120 /* get the file name from the coco. We arent using it but */
121 /* it's part of the protocol. */
123 transmit_char(file_req);
127 /* tell the coco about the file it will receive. */
131 /* now send the file */
142 printf("file not transmitted successfully \n");
149 void initiate_transfer()
151 chksum = (file_type ^ asc_flag);
153 transmit_char(file_type);
154 transmit_char(asc_flag);
155 transmit_char(chksum);
169 filename[count] = rx_char;
170 chksum = (chksum ^ rx_char);
177 printf("target requested %s \n",&filename);
181 printf("filename checksum bad. \n");
196 unsigned char file_char[130],
211 while (tx_flag == true)
213 send_new_block = true;
215 while (rx_char != block_req)
218 transmit_char(block_req);
222 /* get the MSByte of the block number */
225 chksum = (chksum ^ rx_char);
226 block_num = (rx_char << 7);
228 /* get the LSByte of the block number */
231 chksum = (chksum ^ rx_char);
232 block_num = (rx_char | block_num);
234 /* should we retransmit the previous block? */
236 if (first_time == false)
237 if (block_num == old_block_num)
238 send_new_block = false;
241 /* Get the checksum for the block number being requested. */
242 /* Does it match our calculation? */
252 if (xfer_done == true)
254 /* Send a block with a length of 0 and 128 bytes of */
255 /* anything along with a checksum for the block. */
256 /* This tells the Coco that the file is ended. */
262 while (j <= block_size)
270 /* go ahead and read in another 128 bytes. */
271 /* If there aren't 128 bytes available pad the data */
272 /* to 128 bytes. The checksum must still be correct. */
274 if (send_new_block == true)
277 while (count <= block_size)
279 file_char[count] = getc(infile);
280 /* The Coco can't handle linefeeds */
281 if (asc_flag == ASCII)
282 if (file_char[count] == '\n')
283 file_char[count] = '\r';
284 xfer_length = (count + 1);
289 while (count <= block_size)
291 file_char[count] = 0;
293 if (asc_flag != ASCII)
300 printf("Re-transmitting block #%d \n", block_num);
303 /* transmit whatever is in the buffer */
305 transmit_char(xfer_length);
308 chksum = (chksum ^ xfer_length);
310 while (count <= block_size)
312 transmit_char(file_char[count]);
313 chksum = (chksum ^ file_char[count]);
316 transmit_char(chksum);
318 total_xfer = (total_xfer + xfer_length);
319 printf("Total transmitted = %ld\r", total_xfer);
320 old_block_num = block_num;
324 printf("checksum mismatch \n");
334 printf("transfer aborted by host \n");
340 fp = fopen(port,"a+");
342 printf("Error opening port\n");