Hacker News new | ask | show | jobs
by Someone 2996 days ago
MS-DOS isn’t alone in that. https://en.wikipedia.org/wiki/Newline#Representations_in_dif... claims ”Atari TOS, Microsoft Windows, DOS (MS-DOS, PC DOS, etc.), DEC TOPS-10, RT-11, CP/M, MP/M, OS/2, Symbian OS, Palm OS, Amstrad CPC, and most other early non-Unix and non-IBM operating systems” used it.

The real surprise is the BBC Micro, which used LF+CR.

2 comments

DOS did it because CP/M did it.

If I had to guess I'd say CP/M was developed for extra dumb teletypes that needed both to properly handle a newline. So many quirks in terminals date back to the days when everybody was just making it up as they went along. Legacy support is the root of most braindamage.

Teletypes needed it for timing. https://en.wikipedia.org/wiki/Newline#History:

”The separation of newline into two functions concealed the fact that the print head could not return from the far right to the beginning of the next line in one-character time. That is why the sequence was always sent with the CR first. A character printed after a CR would often print as a smudge, on-the-fly in the middle of the page, while it was still moving the carriage back to the first position.”

There's an entry point in the BBC Micro's OS that's routine that prints a character, or LF+CR if the character is CR (13). This routine prints the CR second, so that when it was called with 13 originally it can fall through into the main, non-translating character print routine with 13 in the accumulator, and then return to the caller that way too. (These two routines promise to preserve the accumulator.) Saves a couple of bytes in the ROM.

(There's also an entry point partway through the wrapper that just prints a newline. DRY and all that.)

The code is not exactly this, but differs from it in no relevant way:

    .osasci \ print char, translating CR to newline
        cmp #13:bne oswrch
    .osnewl \ print newline
        lda #10:jsr oswrch
        lda #13:\fall through
    .oswrch \ print char without translation
        pha
        ...
        pla
        rts
The Atom's ROM does the same thing, so they presumably just copied this for the BBC. After all, it doesn't really matter which order you print them.