stefano wrote:What would you expect the libraries do ? I think this is a good moment to discuss it, given the Alvin's big work being done..
In the new clib this is what happens:
and I think this is what siggy is expecting.
It has to do with when the coordinates are checked for being out of bounds. I moved all checking to just before a char is printed. So in the case where '\n' is sent, the cursor is out of bounds but '\n' just moves down one line and to column zero without checking bounds (except for possible scroll of course).
The \r\n stuff is a huge headache because it varies from target to target. Most old z80 machines do not have two separate characters for text linefeed and instead send a single on - CHR$ 13. 13 maps to \r in ascii but all C programs are written using \n to advance line. What's happened is sccz80 has aligned with most of its targets so that \r\n are reversed in character code :- \r=10, \n=13. sdcc, oth, sticks to ascii and has \r=13, \n=10, sending ascii code 10 to advance to the next line which is not understood by most targets.
So what's done in the new clib is there is a clib character set where CHAR_CR ('\r') and CHAR_LF ('\n') are assigned ascii codes differently depending on which compiler is running. Under sdcc, CHAR_LF=10 and under sccz80 CHAR_LF=13. The clib treats CHAR_LF as the linefeed character in its code. The low level driver is responsible for translating native characters (like ENTER=13) to the clib char set (CHAR_LF).
Some programs only send \r (like your dangling example) or \r\n or \n to advance the line. So with a \r the new clib waits to see if a \n comes along and if not it treats an isolated \r like linefeed. If \r\n comes along, only one linefeed is generated. If \n is on its own, one linefeed is on its own. I can't remember what I did with \n\r but I think I did that case too.