Skip to content
Snippets Groups Projects
Commit fa5ba5a6 authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Move input translation (e.g. for PETSCII) to its own sbbs_t methods

Move kbincom() to an sbbs_t method.

No functional change here, just getting ready to support input translation for stdio
external programs as an option.
parent 56b07155
No related branches found
No related tags found
1 merge request!463MRC mods by Codefenix (2024-10-20)
Pipeline #3719 passed
...@@ -22,23 +22,32 @@ ...@@ -22,23 +22,32 @@
#include "sbbs.h" #include "sbbs.h"
#include "petdefs.h" #include "petdefs.h"
int kbincom(sbbs_t* sbbs, unsigned long timeout) int sbbs_t::kbincom(unsigned long timeout)
{ {
int ch; int ch;
if(sbbs->keybuftop!=sbbs->keybufbot) { if(keybuftop!=keybufbot) {
ch=sbbs->keybuf[sbbs->keybufbot++]; ch=keybuf[keybufbot++];
if(sbbs->keybufbot==KEY_BUFSIZE) if(keybufbot==KEY_BUFSIZE)
sbbs->keybufbot=0; keybufbot=0;
#if 0 #if 0
char* p = c_escape_char(ch); char* p = c_escape_char(ch);
if(p == NULL) if(p == NULL)
p = (char*)&ch; p = (char*)&ch;
lprintf(LOG_DEBUG, "kbincom read %02X '%s'", ch, p); lprintf(LOG_DEBUG, "kbincom read %02X '%s'", ch, p);
#endif #endif
} else { return ch;
ch=sbbs->incom(timeout); }
long term = sbbs->term_supports(); ch = incom(timeout);
if(ch != NOINP)
ch = translate_input(ch);
return ch;
}
int sbbs_t::translate_input(int ch)
{
long term = term_supports();
if(term&PETSCII) { if(term&PETSCII) {
switch(ch) { switch(ch) {
case PETSCII_HOME: case PETSCII_HOME:
...@@ -73,11 +82,16 @@ int kbincom(sbbs_t* sbbs, unsigned long timeout) ...@@ -73,11 +82,16 @@ int kbincom(sbbs_t* sbbs, unsigned long timeout)
break; break;
} }
} }
}
return ch; return ch;
} }
void sbbs_t::translate_input(char* buf, size_t len)
{
for(size_t i =0; i < len; i++)
buf[i] = translate_input(buf[i]);
}
/****************************************************************************/ /****************************************************************************/
/* Returns character if a key has been hit remotely and responds */ /* Returns character if a key has been hit remotely and responds */
/* May return NOINP on timeout instead of '\0' when K_NUL mode is used. */ /* May return NOINP on timeout instead of '\0' when K_NUL mode is used. */
...@@ -86,7 +100,7 @@ int sbbs_t::inkey(long mode, unsigned long timeout) ...@@ -86,7 +100,7 @@ int sbbs_t::inkey(long mode, unsigned long timeout)
{ {
int ch=0; int ch=0;
ch=kbincom(this,timeout); ch=kbincom(timeout);
if(sys_status&SS_SYSPAGE) if(sys_status&SS_SYSPAGE)
sbbs_beep(400 + sbbs_random(800), ch == NOINP ? 100 : 10); sbbs_beep(400 + sbbs_random(800), ch == NOINP ? 100 : 10);
...@@ -295,7 +309,7 @@ char sbbs_t::handle_ctrlkey(char ch, long mode) ...@@ -295,7 +309,7 @@ char sbbs_t::handle_ctrlkey(char ch, long mode)
hotkey_inside &= ~(1<<ch); hotkey_inside &= ~(1<<ch);
return(0); return(0);
case ESC: case ESC:
i=kbincom(this, (mode&K_GETSTR) ? 3000:1000); i=kbincom((mode&K_GETSTR) ? 3000:1000);
if(i==NOINP) // timed-out waiting for '[' if(i==NOINP) // timed-out waiting for '['
return(ESC); return(ESC);
ch=i; ch=i;
...@@ -313,20 +327,20 @@ char sbbs_t::handle_ctrlkey(char ch, long mode) ...@@ -313,20 +327,20 @@ char sbbs_t::handle_ctrlkey(char ch, long mode)
} }
#endif #endif
while(i<10 && j<30) { /* up to 3 seconds */ while(i<10 && j<30) { /* up to 3 seconds */
ch=kbincom(this, 100); ch=kbincom(100);
if(ch==(NOINP&0xff)) { if(ch==(NOINP&0xff)) {
j++; j++;
continue; continue;
} }
if(i == 0 && ch == 'M' && mouse_mode != MOUSE_MODE_OFF) { if(i == 0 && ch == 'M' && mouse_mode != MOUSE_MODE_OFF) {
str[i++] = ch; str[i++] = ch;
int button = kbincom(this, 100); int button = kbincom(100);
if(button == NOINP) { if(button == NOINP) {
lprintf(LOG_DEBUG, "Timeout waiting for mouse button value"); lprintf(LOG_DEBUG, "Timeout waiting for mouse button value");
continue; continue;
} }
str[i++] = button; str[i++] = button;
ch = kbincom(this, 100); ch = kbincom(100);
if(ch < '!') { if(ch < '!') {
lprintf(LOG_DEBUG, "Unexpected mouse-button (0x%02X) tracking char: 0x%02X < '!'" lprintf(LOG_DEBUG, "Unexpected mouse-button (0x%02X) tracking char: 0x%02X < '!'"
, button, ch); , button, ch);
...@@ -334,7 +348,7 @@ char sbbs_t::handle_ctrlkey(char ch, long mode) ...@@ -334,7 +348,7 @@ char sbbs_t::handle_ctrlkey(char ch, long mode)
} }
str[i++] = ch; str[i++] = ch;
int x = ch - '!'; int x = ch - '!';
ch = kbincom(this, 100); ch = kbincom(100);
if(ch < '!') { if(ch < '!') {
lprintf(LOG_DEBUG, "Unexpected mouse-button (0x%02X) tracking char: 0x%02X < '!'" lprintf(LOG_DEBUG, "Unexpected mouse-button (0x%02X) tracking char: 0x%02X < '!'"
, button, ch); , button, ch);
...@@ -398,7 +412,7 @@ char sbbs_t::handle_ctrlkey(char ch, long mode) ...@@ -398,7 +412,7 @@ char sbbs_t::handle_ctrlkey(char ch, long mode)
} }
if(i == 0 && ch == '<' && mouse_mode != MOUSE_MODE_OFF) { if(i == 0 && ch == '<' && mouse_mode != MOUSE_MODE_OFF) {
while(i < sizeof(str) - 1) { while(i < sizeof(str) - 1) {
int byte = kbincom(this, 100); int byte = kbincom(100);
if(byte == NOINP) { if(byte == NOINP) {
lprintf(LOG_DEBUG, "Timeout waiting for mouse report character (%d)", i); lprintf(LOG_DEBUG, "Timeout waiting for mouse report character (%d)", i);
return 0; return 0;
......
...@@ -447,6 +447,9 @@ public: ...@@ -447,6 +447,9 @@ public:
int _outcom(uchar ch); // send character, without retry (on buffer flow condition) int _outcom(uchar ch); // send character, without retry (on buffer flow condition)
int outcom(uchar ch, int max_attempts = OUTCOM_RETRY_ATTEMPTS); // send character, with retry int outcom(uchar ch, int max_attempts = OUTCOM_RETRY_ATTEMPTS); // send character, with retry
int incom(unsigned long timeout=0); // receive character int incom(unsigned long timeout=0); // receive character
int kbincom(unsigned long timeout=0); // " " or return keyboard buffer
int translate_input(int ch);
void translate_input(char* buf, size_t);
void spymsg(const char *msg); // send message to active spies void spymsg(const char *msg); // send message to active spies
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment