-
-
Save tschak909/2d28e65ef77532f8c7b246114e2857b7 to your computer and use it in GitHub Desktop.
Snippets to implement flow control using c64 user port modems in C
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** In io_base.c - io_recv_serial is called as part of main loop */ | |
/** | |
* io_recv_serial() - Receive and interpret serial data. | |
*/ | |
void io_recv_serial(void) | |
{ | |
recv_buffer_size=io_serial_buffer_size(); | |
if (recv_buffer_size>XOFF_THRESHOLD && xoff_enabled==false) | |
{ | |
// Ask modem to stop receiving | |
io_recv_serial_flow_off(); | |
} | |
else if (recv_buffer_size<XON_THRESHOLD && xoff_enabled==true) | |
{ | |
// Ask modem to start receiving | |
io_recv_serial_flow_on(); | |
} | |
if (ser_get(&ch)==SER_ERR_OK) | |
{ | |
// Detect and strip IAC escapes (two consecutive bytes of 0xFF) | |
if (ch==0xFF && lastch == 0xFF) | |
{ | |
lastch=0x00; | |
} | |
else | |
{ | |
lastch=ch; | |
ShowPLATO(&ch,1); | |
} | |
} | |
} | |
/** in c64/io.c */ | |
extern uint8_t xoff_enabled; | |
/** | |
* Return the serial buffer size | |
*/ | |
uint8_t io_serial_buffer_size(void) | |
{ | |
return PEEK(0x29B)-PEEK(0x29C)&0xff; | |
} | |
/** | |
* io_recv_serial_flow_off() - Tell modem to stop receiving. | |
*/ | |
void io_recv_serial_flow_off(void) | |
{ | |
// for now, assume user port. | |
POKE(0xD020,0); | |
POKE(0xDD01,0); | |
} | |
/** | |
* io_recv_serial_flow_on() - Tell modem to stop receiving. | |
*/ | |
void io_recv_serial_flow_on(void) | |
{ | |
// For now, assume user port. | |
POKE(0xD020,14); | |
POKE(0xDD01,1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment