<html><head></head><body><div style="font-family:Helvetica Neue, Helvetica, Arial, sans-serif;font-size:small;"><div><div>Hi Paul,</div></div><div><br></div><div><br></div><div>It works (although the code could now benefit from some cleanup, but.. does the job). Even zero-sized files work now.</div><div><br></div><div><br></div><div>Thanks!</div><div><br></div><div><br></div><div>Andreas</div><div><br></div><div><br></div><hr><div id="ydpbb0b7907yahoo_quoted_9080714868" class="ydpbb0b7907yahoo_quoted"><div style="font-family:'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:13px;color:#26282a;"><div>On Friday, June 30, 2017, 1:25:36 PM GMT+2, Paul Reed <paulreed@paddedcell.com> wrote:</div><div><br></div><div><br></div><div><div dir="ltr">Hi Andreas,<br clear="none"><br clear="none">> I do not really understand 100% the part starting with<br clear="none">> "int pos = (rxcount - fnlen -1) % 256, followed by two cascaded if<br clear="none">> statements, one with condition pos == 0 and one with condition flen ><br clear="none">> 255".<br clear="none"><br clear="none">Nor did I, even though I wrote it :( However, after sitting down with my<br clear="none">former self and getting him to explain himself, I have tested the<br clear="none">following patch (on macOS, at least; the latter diff just gets rid of a<br clear="none">warning).<br clear="none"><br clear="none">The rxcount variable tracks how many characters have been "received" by<br clear="none">the *virtual* machine, which is why it's % 256 not % 255 (took me a<br clear="none">while...).<br clear="none"><br clear="none">So a packet header byte is "received" every 256 bytes, or (now) when the<br clear="none">remaining file length (flen) is zero, otherwise it's a data byte. That's<br clear="none">what the if statement *should* have said. Apologies!<br clear="none"><br clear="none">Thanks again,<br clear="none">Paul<br clear="none"><br clear="none"><br clear="none">diff --git a/src/pclink.c b/src/pclink.c<br clear="none">index 5c4aa81..fa9ce3d 100644<br clear="none">--- a/src/pclink.c<br clear="none">+++ b/src/pclink.c<br clear="none">@@ -101,18 +101,18 @@ static uint32_t PCLink_RData(const struct<br clear="none">RISC_Serial *serial) {<br clear="none"> }<br clear="none"> } else {<br clear="none"> int pos = (rxcount - fnlen - 1) % 256;<br clear="none">- if (pos == 0) {<br clear="none">+ if (pos == 0 || flen == 0) {<br clear="none"> if (flen > 255) {<br clear="none"> ch = 255;<br clear="none"> } else {<br clear="none"> ch = (uint8_t)flen;<br clear="none">+ if (flen == 0) {<br clear="none">+ mode = 0; unlink(RecName);<br clear="none">+ }<br clear="none"> }<br clear="none"> } else {<br clear="none"> read(fd, &ch, 1);<div class="ydpbb0b7907yqt9056023538" id="ydpbb0b7907yqtfd97519"><br clear="none"> flen--;</div><br clear="none">- if (flen == 0) {<br clear="none">- mode = 0; unlink(RecName);<br clear="none">- }<br clear="none"> }<br clear="none"> }<br clear="none"> }<br clear="none">diff --git a/src/sdl-main.c b/src/sdl-main.c<br clear="none">index 892f9e9..8510f2a 100644<br clear="none">--- a/src/sdl-main.c<br clear="none">+++ b/src/sdl-main.c<br clear="none">@@ -66,7 +66,7 @@ static struct option long_options[] = {<br clear="none"> { "leds", no_argument, NULL, 'L' },<br clear="none"> { "size", required_argument, NULL, 's' },<br clear="none"> { "serial-fd", required_argument, NULL, 'F' },<br clear="none">- { NULL }<br clear="none">+ { NULL, no_argument, NULL, '\0' }<br clear="none"> };<br clear="none"><br clear="none"> static void fail(int code, const char *fmt, ...) {<div class="ydpbb0b7907yqt9056023538" id="ydpbb0b7907yqtfd01416"><br clear="none"><br clear="none"><br clear="none"></div></div></div></div></div></div></body></html>