From f0087cd48eb85fb00d851c9dd02730aa1b2d6e8c Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Wed, 16 Dec 2020 12:44:29 -0500 Subject: [PATCH] Revert "tools: make upload a bit faster" This optimisation appears to make the upload process unreliable in some cases. I can't appear to reliably upload to my TRS-80 with this version. I prefer reliability than speed... --- tools/upload.c | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/tools/upload.c b/tools/upload.c index 43cbda9..23ac2cb 100644 --- a/tools/upload.c +++ b/tools/upload.c @@ -2,7 +2,6 @@ #include #include #include -#include #include "common.h" @@ -41,11 +40,9 @@ int main(int argc, char **argv) fprintf(stderr, "Could not open %s\n", argv[1]); return 1; } - uint16_t checksum = 0; char s[0x40]; - // Write all received bytes, keeping a checksum, then print that checksum sprintf(s, - ": _ 0 %d %d DO KEY DUP I C! + LOOP .X ; _", + ": _ 0x%04x 0x%04x DO KEY DUP .x I C! LOOP ; _", memptr+bytecount, memptr); sendcmd(fd, s); @@ -54,22 +51,23 @@ int main(int argc, char **argv) putc('.', stderr); fflush(stderr); unsigned char c = s[0]; - checksum += c; write(fd, &c, 1); usleep(1000); // let it breathe - } - fprintf(stderr, "\nBytes sent, checksum...\n"); - mread(fd, s, 4); // read hex string - s[4] = 0; // null terminate - uint16_t checksum2 = strtol(s, NULL, 16); - if (checksum == checksum2) { - fprintf(stderr, "OK\n"); - } else { - fprintf(stderr, "Mismatch! Expected %04x and got %04x.\n", checksum, checksum2); - returncode = 1; + mread(fd, s, 2); // read hex pair + s[2] = 0; // null terminate + unsigned char c2 = strtol(s, NULL, 16); + if (c != c2) { + // mismatch! + unsigned int pos = ftell(fp); + fprintf(stderr, "Mismatch at byte %d! %d != %d.\n", pos, c, c2); + // we don't exit now because we need to "consume" our whole program. + returncode = 1; + } + usleep(1000); // let it breathe } readprompt(fd); sendcmdp(fd, "FORGET _"); + fprintf(stderr, "Done!\n"); fclose(fp); if (fd > 0) { close(fd);