/* descriptor of the master's end of the pty for TX> and RX<? */
static int rxtxfd;
/* if >= 0x100, val there is a value waiting in LSB */
static int rxval = 0;
/* To read a byte, we need to poll twice. The first time, it returns 0 or 1.
* 0 means there's nothing, 1 means there's something. If 1 was returned,
* the next read of the port will be the value. If 0 was returned, the next
* read of the port will be another poll.
*/
static byte iord_rxtx() {
byte b;
if (rxval) {
b = rxval & 0xff;
rxval = 0;
return b;
} else {
if (read(rxtxfd, &b, 1) == 1) {
rxval = b | 0x100;
return 1;
} else {
return 0;
}
}
}