1
0
mirror of https://github.com/hsoft/collapseos.git synced 2024-11-23 18:08:05 +11:00

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...
This commit is contained in:
Virgil Dupras 2020-12-16 12:44:29 -05:00
parent 63d2c97386
commit f0087cd48e

View File

@ -2,7 +2,6 @@
#include <stdio.h> #include <stdio.h>
#include <fcntl.h> #include <fcntl.h>
#include <unistd.h> #include <unistd.h>
#include <stdint.h>
#include "common.h" #include "common.h"
@ -41,11 +40,9 @@ int main(int argc, char **argv)
fprintf(stderr, "Could not open %s\n", argv[1]); fprintf(stderr, "Could not open %s\n", argv[1]);
return 1; return 1;
} }
uint16_t checksum = 0;
char s[0x40]; char s[0x40];
// Write all received bytes, keeping a checksum, then print that checksum
sprintf(s, 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); memptr+bytecount, memptr);
sendcmd(fd, s); sendcmd(fd, s);
@ -54,22 +51,23 @@ int main(int argc, char **argv)
putc('.', stderr); putc('.', stderr);
fflush(stderr); fflush(stderr);
unsigned char c = s[0]; unsigned char c = s[0];
checksum += c;
write(fd, &c, 1); write(fd, &c, 1);
usleep(1000); // let it breathe usleep(1000); // let it breathe
} mread(fd, s, 2); // read hex pair
fprintf(stderr, "\nBytes sent, checksum...\n"); s[2] = 0; // null terminate
mread(fd, s, 4); // read hex string unsigned char c2 = strtol(s, NULL, 16);
s[4] = 0; // null terminate if (c != c2) {
uint16_t checksum2 = strtol(s, NULL, 16); // mismatch!
if (checksum == checksum2) { unsigned int pos = ftell(fp);
fprintf(stderr, "OK\n"); fprintf(stderr, "Mismatch at byte %d! %d != %d.\n", pos, c, c2);
} else { // we don't exit now because we need to "consume" our whole program.
fprintf(stderr, "Mismatch! Expected %04x and got %04x.\n", checksum, checksum2);
returncode = 1; returncode = 1;
} }
usleep(1000); // let it breathe
}
readprompt(fd); readprompt(fd);
sendcmdp(fd, "FORGET _"); sendcmdp(fd, "FORGET _");
fprintf(stderr, "Done!\n");
fclose(fp); fclose(fp);
if (fd > 0) { if (fd > 0) {
close(fd); close(fd);