Programming Examples
Appendix B
B-34
/* If user did not request direct download to dual port, go through
the iterations of downloading through the already download loadpcl.bin */
if (file_into_dp == FALSE) {
while(!eof(loadfile)) { /* loop until end of file */
/* read up to 0x780 bytes into dual port offset 0x80, which is where
the loadpcl.bin program expects to find the binary */
length = read(loadfile, &base[LOADPCL_DATA_WINDOW], 0x780);
/* Put the length (number of bytes just read) into appropriate location
in dual port */
* (int *) (&base[LOADPCL_SIZE]) = length;
/* On first pass through LOADPCL.BIN, need to release the KTX from
reset, subsequent passes through LOADPCL.BIN the procedure is
different */
if (firstpass) {
base[KTX_RELEASE] = 1; /* Release the KTX from reset */
firstpass = 0; /* set flag so next pass through is different */
}
else base[LOADPCL_HANDSHAKE] = 0; /* Not the first pass through, so set byte to */
/* zero to tell loadpcl.bin that another chunk*/
/* of data is ready to be transferred. */
/* Wait for loadpcl.bin to indicate it is done with this chunk, or user */
/* presses a key. */
while(base[LOADPCL_HANDSHAKE] == 0) if (kbhit()) exit(1);
/* Check status byte for errors */
switch(base[LOADPCL_STATUS]) {
case 0: /* OK – no error */
break;
case 1:
printf(”\nDownload error: Block too large.\n”);
exit(2);
break;
case 2:
printf(”\nDownload error: RAM full.\n”);
exit(2);
break;
default:
printf(”\nDownload error: Unknown – %02x.\n”, base[LOADPCL_STATUS]);
exit(2);
break;
}
}
printf(”\nTotal bytes downloaded: %04x\n”, *(int *) (&base[LOADPCL_LENGTH]));
base[KTX_RESET] = 1;
return(0);
}
else { /* user requested a direct load into dual port */
/* do the read directly from the file into dual port */
length = read(loadfile, base, 0x800);
/* Check to see if user requested a file which was too long to fit in
dual port. */
if (length == 0x800) {
printf(”\nFile is too long to fit in dual port.\n”);
exit(1);
}