ZX81: Inconsisent handling of "NEWLINE"

Bug reports (if you don't/won't have a Github account)
Post Reply
siggi
Well known member
Posts: 343
Joined: Thu Jul 26, 2007 9:06 am

ZX81: Inconsisent handling of "NEWLINE"

Post by siggi »

Different input functions give different results when pressing "NEWLINE" on ZX81 keyboard.
Older compiler versions returned "\n" (char 10)

Now the state is:
in_Inkey() gives result 13 (CR, \r)
fgets gives restult 10 (LF, \n)

Code example:

Code: Select all

        printk("enter smtp config:\n(<ret> for default)\n");
        printk("smtp-server: (%s)\n", server);
        fgets(buf, sizeof(server), stdin);
        if (*buf)
            strcpy(server, buf);
printf("serverchar = %u\n", (unsigned int) *buf);
printf("in_inKey = %u\n", in_Inkey());
Is this an intended behavior?
Siggi
User avatar
dom
Well known member
Posts: 1194
Joined: Sun Jul 15, 2007 10:01 pm

Post by dom »

It's a good question!

It's right that fgets() gives LF - we've switched all ports over so that \n -> 10 - this makes interop with sdcc work nicely.

The in_Inkey() are z88dk specific APIs, it looks like I've made all the new implementations of that API also return 13 for the "Return/Enter/NewLine" key. It also looks like newlib using code 13 as well.

Given that this also affects newlib, I'll let Alvin comment as well and decide if we want to harmonise it.

To step around this problem (and have the same functionality), just call getk_inkey() - that will return code 10.
Post Reply