[comp.sys.atari.st] Reading the upper byte of typed chars

jpexg@mit-hermes.UUCP (04/01/87)

This is in reply to the person who was having trouble reading the full 16-bit
character with Crawcin() calls, etc.

You'd think that since the character-reading calls get a 16-bit word, the extra
byte would be packed into the top byte. Not so, but Megamax is wrong when
they say that Crawcin(), Cnecin(), Cconin() etc read 1 word: they can
just as easily read a longword, and if you do this you will find the extra byte
in the low half of the top word. See below for an example, which types low and
high byte for any key and pings the bell if you hit the "help" key. 


include <stdio.h>
include <osbind.h>

#define HELPLOW 0
#define HELPHIGH 98
#define BELL 7

main(){
	long z;

	while (1)				/* Loop till you droop */
	{	while (!Cconis()) ; 		/* Wait for it..... */
		z = Cnecin();
		if (z == ((long)HELPLOW | (long)(HELPHIGH << 16)))
		  Cconout(BELL);		/* Ping */

		printf("16-bit character <%c>, value 0x%lx, ", (char)z, z);
		printf("low byte 0x%lx, high byte 0x%lx\n", 
		       z&0xFFFF, (z >> 16)&0xFFFF);
		if ((char)z == 3) break;	/* Control-c exits */
	}
}