by satiated_grue · 1mo ago · 0 comments
\r\n was how lines were terminated on the wire for many early devices (for example, the Teletype ASR-33 seen in the famous photograph of Thompson and Ritchie at Bell Labs).
If the carriage is very far to the right, and an LF is sent followed by the CR, then the carriage will still be returning when the next character arrives, which will print at some random location along the return path.
CR followed by the mechanically much faster LF operation gives enough time for the carriage to be fully homed and in proper position for the printable character to be struck.
I wondered what the thought process was at Acorn when they decided on the opposite. It looks like they did this on their 8-bit micros as well. I found this explanation: https://retrocomputing.stackexchange.com/questions/29929/why...
I've only looked briefly but it seems there is a snippet of code in the ASCII output routine that expands just CR to LF+CR which is shorter when the bytes are output in that order. If they did CR first and fell through to the output routine for LF it would clobber the A register and you'd need additional code to restore it after outputting it with OSWRCH, which would also preven the fallthrough. So it saves five bytes three bytes of ROM :)
Still leaves out why they didn't expand LF to CR+LF, but I suppose the specific order was a non-consideration at the time.