From f1bf0a483e917b67cf9db6483072db261f7688c3 Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Tue, 17 Feb 2026 03:45:41 -0500 Subject: Start welding the new UI code to the client. Compiles but doesn't work yet... --- src/cmd.c | 8 +++- src/conio.c | 37 ---------------- src/conio.c.old | 37 ++++++++++++++++ src/conio.h | 14 ------ src/conio.h.old | 14 ++++++ src/err.c | 37 ---------------- src/err.c.old | 37 ++++++++++++++++ src/err.h | 22 ---------- src/err.h.old | 22 ++++++++++ src/irc.c | 131 +++++++++++++++++++++++++++++++++++++------------------- src/irc.h | 9 +--- src/main.c | 99 +++++++++++++++++++----------------------- src/screen.h | 2 + src/ui.c | 73 ------------------------------- src/ui.c.old | 73 +++++++++++++++++++++++++++++++ 15 files changed, 325 insertions(+), 290 deletions(-) delete mode 100644 src/conio.c create mode 100644 src/conio.c.old delete mode 100644 src/conio.h create mode 100644 src/conio.h.old delete mode 100644 src/err.c create mode 100644 src/err.c.old delete mode 100644 src/err.h create mode 100644 src/err.h.old delete mode 100644 src/ui.c create mode 100644 src/ui.c.old (limited to 'src') diff --git a/src/cmd.c b/src/cmd.c index 3c7f482..1eccdf5 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -1,6 +1,8 @@ #include #include #include "irc.h" +#include "addrs.h" +#include "screen.h" void cmd_chan_text(const char *cmd) { txbuf_set_str("PRIVMSG "); @@ -15,5 +17,9 @@ void cmd_command(const char *cmd) { txbuf_send_str(cmd + 1); else if(channel[0]) cmd_chan_text(cmd); - else ui_print("*** You are not on a channel\n"); + else scr_print(SCR_CURR, "*** You are not on a channel\n"); +} + +void cmd_execute(void) { + cmd_command(edit_box); } diff --git a/src/conio.c b/src/conio.c deleted file mode 100644 index 2742ab6..0000000 --- a/src/conio.c +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Simple conio for E: - */ - -#include -#include -#include "cio.h" - -void printl(const char* c, int l) -{ - OS.iocb[0].buffer=c; - OS.iocb[0].buflen=l; - OS.iocb[0].command=IOCB_PUTCHR; - ciov(); -} - -void printc(char* c) -{ - OS.iocb[0].buffer=c; - OS.iocb[0].buflen=1; - OS.iocb[0].command=IOCB_PUTCHR; - ciov(); -} - -void print(const char* c) -{ - int l=strlen(c); - printl(c,l); -} - -void get_line(char* buf, unsigned char len) -{ - OS.iocb[0].buffer=buf; - OS.iocb[0].buflen=len; - OS.iocb[0].command=IOCB_GETREC; - ciov(); -} diff --git a/src/conio.c.old b/src/conio.c.old new file mode 100644 index 0000000..2742ab6 --- /dev/null +++ b/src/conio.c.old @@ -0,0 +1,37 @@ +/** + * Simple conio for E: + */ + +#include +#include +#include "cio.h" + +void printl(const char* c, int l) +{ + OS.iocb[0].buffer=c; + OS.iocb[0].buflen=l; + OS.iocb[0].command=IOCB_PUTCHR; + ciov(); +} + +void printc(char* c) +{ + OS.iocb[0].buffer=c; + OS.iocb[0].buflen=1; + OS.iocb[0].command=IOCB_PUTCHR; + ciov(); +} + +void print(const char* c) +{ + int l=strlen(c); + printl(c,l); +} + +void get_line(char* buf, unsigned char len) +{ + OS.iocb[0].buffer=buf; + OS.iocb[0].buflen=len; + OS.iocb[0].command=IOCB_GETREC; + ciov(); +} diff --git a/src/conio.h b/src/conio.h deleted file mode 100644 index 25ca6c2..0000000 --- a/src/conio.h +++ /dev/null @@ -1,14 +0,0 @@ -/** - * conio - */ - -#ifndef CONIO_H -#define CONIO_H - -void print(const char* c); -void printc(char* c); -void printl(const char* c, unsigned short l); -void get_line(char* buf, unsigned char len); -char get_char(void); - -#endif /* CONIO_H */ diff --git a/src/conio.h.old b/src/conio.h.old new file mode 100644 index 0000000..25ca6c2 --- /dev/null +++ b/src/conio.h.old @@ -0,0 +1,14 @@ +/** + * conio + */ + +#ifndef CONIO_H +#define CONIO_H + +void print(const char* c); +void printc(char* c); +void printl(const char* c, unsigned short l); +void get_line(char* buf, unsigned char len); +char get_char(void); + +#endif /* CONIO_H */ diff --git a/src/err.c b/src/err.c deleted file mode 100644 index 8d58670..0000000 --- a/src/err.c +++ /dev/null @@ -1,37 +0,0 @@ -/** - * FujiNet Tools for CLI - * - * Error output - * - * Author: Thomas Cherryhomes - * - * - * Released under GPL, see COPYING - * for details - */ - -#include -#include "conio.h" - -const char error_138[]="FUJINET NOT RESPONDING\x9B"; -const char error_139[]="FUJINET NAK\x9b"; -const char error[]="SIO ERROR\x9b"; - -/** - * Show error - */ -void err_sio(void) -{ - switch (OS.dcb.dstats) - { - case 138: - print(error_138); - break; - case 139: - print(error_139); - break; - default: - print(error); - break; - } -} diff --git a/src/err.c.old b/src/err.c.old new file mode 100644 index 0000000..8d58670 --- /dev/null +++ b/src/err.c.old @@ -0,0 +1,37 @@ +/** + * FujiNet Tools for CLI + * + * Error output + * + * Author: Thomas Cherryhomes + * + * + * Released under GPL, see COPYING + * for details + */ + +#include +#include "conio.h" + +const char error_138[]="FUJINET NOT RESPONDING\x9B"; +const char error_139[]="FUJINET NAK\x9b"; +const char error[]="SIO ERROR\x9b"; + +/** + * Show error + */ +void err_sio(void) +{ + switch (OS.dcb.dstats) + { + case 138: + print(error_138); + break; + case 139: + print(error_139); + break; + default: + print(error); + break; + } +} diff --git a/src/err.h b/src/err.h deleted file mode 100644 index d3bf3d7..0000000 --- a/src/err.h +++ /dev/null @@ -1,22 +0,0 @@ -/** - * FujiNet Tools for CLI - * - * Error output - * - * Author: Thomas Cherryhomes - * - * - * Released under GPL, see COPYING - * for details - */ - - -#ifndef ERR_H -#define ERR_H - -/** - * Show error - */ -void err_sio(void); - -#endif /* ERR_H */ diff --git a/src/err.h.old b/src/err.h.old new file mode 100644 index 0000000..d3bf3d7 --- /dev/null +++ b/src/err.h.old @@ -0,0 +1,22 @@ +/** + * FujiNet Tools for CLI + * + * Error output + * + * Author: Thomas Cherryhomes + * + * + * Released under GPL, see COPYING + * for details + */ + + +#ifndef ERR_H +#define ERR_H + +/** + * Show error + */ +void err_sio(void); + +#endif /* ERR_H */ diff --git a/src/irc.c b/src/irc.c index 28ce527..db86b12 100644 --- a/src/irc.c +++ b/src/irc.c @@ -4,12 +4,13 @@ #include #include "irc.h" +#include "screen.h" +#include "edbox.h" #include "numerics.h" #ifdef __ATARI__ #include #include -#include "conio.h" #include "nio.h" #else #define CH_EOL '|' @@ -31,7 +32,7 @@ static int joined = 0; #ifdef __ATARI__ static void join_channel(void) { - ui_print("Joining channel...\n"); + scr_create(channel, 1); txbuf_set_str("JOIN "); txbuf_append_str(channel); txbuf_append_str("\n"); @@ -40,34 +41,44 @@ static void join_channel(void) { } static void do_pong(void) { - ui_putchar(CH_EOL); - ui_print("PING/PONG\n"); /* make hiding this a preference, or just ditch it */ + scr_print(SCR_SERVER, "PING/PONG\n"); /* make hiding this a preference, or just ditch it */ txbuf_set_str("PONG "); txbuf_append_str(msg_args[0]); txbuf_send(); } -static void do_privmsg(void) { - static char chan; - - chan = (*msg_dest == '#'); +static char do_chantext(void) { + char s; - if(chan) { - ui_putchar('<'); - } else { - ui_putchar('*'); + s = scr_getbyname(msg_dest); + scr_putc(s, '<'); + scr_print(s, msg_src); + if(!s) { /* if we don't have a window for it */ + scr_putc(s, '/'); + scr_print(s, msg_dest); } + scr_putc(s, '>'); + return s; +} - ui_print(msg_src); +static char do_private(void) { + char s; - if(chan) { - ui_putchar('>'); - } else { - ui_putchar('*'); - } + scr_putc(SCR_PRIV, '*'); + scr_print(SCR_PRIV, msg_src); + scr_putc(SCR_PRIV, '*'); + return s; +} + +static void do_privmsg(void) { + char s; + + if(*msg_dest == '#') + s = do_chantext(); + else + s = do_private(); - ui_putchar(' '); - ui_print(msg_text); + scr_print(s, msg_text); /* text ends with an EOL, don't print another */ } /* numerics call this with arg==1, since arg 0 is always our nick. @@ -75,24 +86,25 @@ static void do_privmsg(void) { */ static void do_catchall(int arg) { if(msg_src) { - ui_print(msg_src); - ui_putchar(' '); + scr_print(SCR_SERVER, msg_src); + scr_putc(SCR_SERVER, ' '); } - ui_print(msg_cmd); + scr_print(SCR_SERVER, msg_cmd); for(; arg < msg_argcount; arg++) { - ui_putchar(' '); - ui_print(msg_args[arg]); + scr_putc(SCR_SERVER, ' '); + scr_print(SCR_SERVER, msg_args[arg]); } if(msg_text) { - ui_putchar(' '); - ui_print(msg_text); + scr_putc(SCR_SERVER, ' '); + scr_print(SCR_SERVER, msg_text); } } static void do_numeric(void) { + char s; unsigned int num = atoi(msg_cmd); switch(num) { @@ -103,16 +115,18 @@ static void do_numeric(void) { break; case RPL_TOPIC: - ui_print("Topic for "); - ui_print(msg_args[1]); - ui_print(": "); - ui_print(msg_text); + s = scr_getbyname(msg_args[1]); + scr_print(s, "Topic for "); + scr_print(s, msg_args[1]); + scr_print(s, ": "); + scr_print(s, msg_text); break; case RPL_TOPICWHOTIME: - ui_print("Topic set by: "); - ui_print(msg_args[1]); - ui_putchar('\n'); + s = scr_getbyname(msg_args[1]); + scr_print(s, "Topic set by: "); + scr_print(s, msg_args[1]); + scr_putc(s, '\n'); break; default: @@ -122,9 +136,9 @@ static void do_numeric(void) { } static void invalid_msg(char type) { - ui_print("??? unknown, type "); - ui_putchar(type); - ui_putchar('\n'); + scr_print(SCR_SERVER, "??? unknown, type "); + scr_putc(SCR_SERVER, type); + scr_putc(SCR_SERVER, '\n'); } #else static void do_pong(void) { } @@ -210,7 +224,7 @@ static void parse_msg(void) { #ifdef __ATARI__ OS.crsinh = 1; - ui_start_msg(); + // ui_start_msg(); if(streq_i(msg_cmd, "PRIVMSG")) { do_privmsg(); } else if(isdigit(msg_cmd[0])) { @@ -218,7 +232,7 @@ static void parse_msg(void) { } else { do_catchall(0); } - ui_end_msg(); + // ui_end_msg(); #else { int i; @@ -253,6 +267,16 @@ static void irc_parse(void) { } } +/* TODO: there needs to be a scr_printnum() */ +void print_errnum(void) { + extern unsigned char err; + char tmp[10]; + scr_print(SCR_CURR, "Error #"); + itoa(err, tmp, 10); + scr_print(SCR_CURR, tmp); + scr_print(SCR_CURR, ", press any key...\n"); +} + #ifdef __ATARI__ int irc_read(void) { if(!trip) return 1; @@ -260,11 +284,11 @@ int irc_read(void) { err = nstatus(url); if(err == 136) { - ui_print("Disconnected, press any key...\n"); + scr_print(SCR_CURR, "Disconnected, press any key...\n"); cgetc(); return 0; } else if(err != 1) { - print_error(err); + print_errnum(); return 0; } @@ -277,8 +301,8 @@ int irc_read(void) { if(bw > 0) { err = nread(url, rx_buf, bw); if(err != 1) { - ui_print("READ ERROR: "); - print_error(err); + scr_print(SCR_CURR, "READ ERROR: "); + print_errnum(); return 0; } @@ -307,6 +331,25 @@ void irc_register(void) { txbuf_send(); } +static void start_keystroke(void) { + char i, s; + + i = cgetc(); + if(i >= '1' && i <= '7') { + s = i - '1'; + if(scr_active[s] != SCR_UNUSED) + scr_display(s); + } +} + +static void keystroke(void) { + if(GTIA_READ.consol == 6) { /* start pressed */ + start_keystroke(); + } else { + edbox_keystroke(); + } +} + /* only exits on error (e.g. connection closed, which might be via /QUIT). */ void irc_loop(void) { while(1) { @@ -314,7 +357,7 @@ void irc_loop(void) { if(kbhit()) if(joined) - ui_keystroke(); + keystroke(); else join_channel(); } } diff --git a/src/irc.h b/src/irc.h index 77510d1..5b9e81e 100644 --- a/src/irc.h +++ b/src/irc.h @@ -47,13 +47,8 @@ void irc_register(void); the IRC server (via /quit or error). */ void irc_loop(void); -/**** ui.c */ -void ui_init(void); -void ui_start_msg(void); -void ui_end_msg(void); -void ui_keystroke(void); -void ui_print(const char *str); -void ui_putchar(char c); +void print_errnum(void); /**** cmd.c */ void cmd_command(const char *cmd); +void cmd_execute(void); diff --git a/src/main.c b/src/main.c index 2b9db34..d15a7be 100644 --- a/src/main.c +++ b/src/main.c @@ -15,9 +15,11 @@ #include #include #include // for kbhit() and cgetc() -#include "conio.h" // our local one. +// #include "conio.h" // our local one. #include "nio.h" #include "irc.h" +#include "screen.h" +#include "edbox.h" char url[256] = DEF_URL; // URL char usernick[32] = DEF_NICK; @@ -31,6 +33,7 @@ unsigned char rx_buf[MAX_IRC_MSG_LEN]; // RX buffer. unsigned char tx_buf[MAX_IRC_MSG_LEN]; // TX buffer. unsigned int txbuflen; // TX buffer length char channel[32] = DEF_CHANNEL; +static char got_line; /* TODO: user modes (default +iw), fg/bg color... */ @@ -43,58 +46,43 @@ static void strcpy_to_eol(char *dst, const char *src) { *dst = '\0'; } -/** - * Get URL from user. - */ -void get_config(void) { - OS.crsinh = 0; +static void return_pressed(void) { + got_line = 1; +} - putchar(CH_CLR); - print(BANNER); +static void get_line(void) { + got_line = 0; + edbox_callback = return_pressed; + while(!got_line) + edbox_keystroke(); + scr_print(SCR_SERVER, edit_box); +} + +void get_config(void) { + scr_print(SCR_SERVER, BANNER); while(1) { - print("\nURL ["); - print(url); - print("]?\n"); - get_line(tx_buf, sizeof(url) - 1); - if(tx_buf[0] != CH_EOL) strcpy_to_eol(url, tx_buf); - - print("Nick ["); - print(usernick); - print("]? "); - get_line(tx_buf, sizeof(usernick) - 1); - if(tx_buf[0] != CH_EOL) strcpy_to_eol(usernick, tx_buf); - - print("Channel ["); - print(channel); - print("]? "); - get_line(tx_buf, sizeof(channel) - 1); - if(tx_buf[0] != CH_EOL) strcpy_to_eol(channel, tx_buf); - - /* - print("\n\nURL: "); - print(url); - print("\nNick: "); - print(usernick); - print("\nChannel: "); - print(channel); - */ - - print("\n\nAre these settings OK [Y/n]? "); + scr_print(SCR_SERVER, "\nURL ["); + scr_print(SCR_SERVER, url); + scr_print(SCR_SERVER, "]?\n"); + get_line(); + if(edit_box[0] != CH_EOL) strcpy_to_eol(url, edit_box); + + scr_print(SCR_SERVER, "Nick ["); + scr_print(SCR_SERVER, usernick); + scr_print(SCR_SERVER, "]?\n"); + get_line(); + if(edit_box[0] != CH_EOL) strcpy_to_eol(usernick, edit_box); + + scr_print(SCR_SERVER, "Channel ["); + scr_print(SCR_SERVER, channel); + scr_print(SCR_SERVER, "]?\n"); + get_line(); + if(edit_box[0] != CH_EOL) strcpy_to_eol(channel, edit_box); + + scr_print(SCR_SERVER, "\n\nAre these settings OK [Y/n]?\n"); if(tolower(cgetc()) != 'n') break; } - - // print("Press Return to connect\n"); - // cgetc(); -} - -/** - * Print error - */ -void print_error(unsigned char err) { - itoa(err, tmp, 10); - print(tmp); - print("\n"); } void txbuf_init(void) { @@ -125,15 +113,15 @@ void txbuf_send_str(const char *str) { } int fn_connect(void) { - print("\n" "Connecting to: "); - print(url); - print("\n"); + scr_print(SCR_SERVER, "Connecting to: "); + scr_print(SCR_SERVER, url); + scr_print(SCR_SERVER, "\n"); err = nopen(url, FNET_TRANSLATION); if(err != SUCCESS) { - print("Connection failed: "); - print_error(err); + scr_print(SCR_SERVER, "Connection failed: "); + print_errnum(); return 0; } @@ -155,13 +143,14 @@ void fn_disconnect(void) { } int main(void) { - OS.lmargn = 0; // Set left margin to 0 OS.shflok = 0; // turn off shift-lock. OS.soundr = 0; // Turn off SIO beeping sound - cursor(1); // Keep cursor on + + scr_init(); while(1) { get_config(); + edbox_callback = cmd_execute; if(fn_connect()) { irc_register(); irc_loop(); diff --git a/src/screen.h b/src/screen.h index 5762009..849133c 100644 --- a/src/screen.h +++ b/src/screen.h @@ -9,6 +9,8 @@ #define SCR_INACTIVE 1 #define SCR_ACTIVE 2 +#define SCR_SERVER 0 +#define SCR_PRIV 1 #define SCR_CURR 0xff /**** public API ****/ diff --git a/src/ui.c b/src/ui.c deleted file mode 100644 index 68f32a0..0000000 --- a/src/ui.c +++ /dev/null @@ -1,73 +0,0 @@ -#include -#include -#include "irc.h" -#include -#include "conio.h" - -#define MAX_INPUT_LEN 119 - -static char input_buffer[MAX_INPUT_LEN + 1]; -static short inbuf_len = 0; - -void ui_init(void) { - OS.escflg = 0; - inbuf_len = input_buffer[0] = 0; -} - -void ui_start_msg() { - /* TODO: use msg_src and msg_dest to decide which window to - print to (when we have multi-window support) */ - OS.crsinh = 1; - putchar(CH_DELLINE); -} - -void ui_end_msg(void) { - OS.crsinh = 0; - // putchar(CH_EOL); // NO! - if(inbuf_len) print(input_buffer); -} - -void ui_print(const char *str) { - OS.escflg = 0x80; - print(str); - OS.escflg = 0; -} - -void ui_putchar(char c) { - putchar(c); -} - -void ui_keystroke(void) { - char c; - - OS.escflg = 0x80; - - /* pressing ctrl-3 (aka EOF) crashes cc65-compiled binaries *hard*, - so don't allow it. */ - if(OS.ch == (KEY_3 | KEY_CTRL)) { - OS.ch = KEY_NONE; - return; - } - - c = cgetc(); - - if(c == CH_EOL && !inbuf_len) - return; /* ignore empty message */ - - if(c == CH_DEL && inbuf_len) { - OS.escflg = 0; - putchar(c); - OS.escflg = 0x80; - input_buffer[inbuf_len--] = 0; - } else if(inbuf_len == MAX_INPUT_LEN) { - return; /* ignore */ - } else { - putchar(c); - input_buffer[inbuf_len++] = c; - input_buffer[inbuf_len] = 0; - if(c == CH_EOL) { - cmd_command(input_buffer); - ui_init(); - } - } -} diff --git a/src/ui.c.old b/src/ui.c.old new file mode 100644 index 0000000..68f32a0 --- /dev/null +++ b/src/ui.c.old @@ -0,0 +1,73 @@ +#include +#include +#include "irc.h" +#include +#include "conio.h" + +#define MAX_INPUT_LEN 119 + +static char input_buffer[MAX_INPUT_LEN + 1]; +static short inbuf_len = 0; + +void ui_init(void) { + OS.escflg = 0; + inbuf_len = input_buffer[0] = 0; +} + +void ui_start_msg() { + /* TODO: use msg_src and msg_dest to decide which window to + print to (when we have multi-window support) */ + OS.crsinh = 1; + putchar(CH_DELLINE); +} + +void ui_end_msg(void) { + OS.crsinh = 0; + // putchar(CH_EOL); // NO! + if(inbuf_len) print(input_buffer); +} + +void ui_print(const char *str) { + OS.escflg = 0x80; + print(str); + OS.escflg = 0; +} + +void ui_putchar(char c) { + putchar(c); +} + +void ui_keystroke(void) { + char c; + + OS.escflg = 0x80; + + /* pressing ctrl-3 (aka EOF) crashes cc65-compiled binaries *hard*, + so don't allow it. */ + if(OS.ch == (KEY_3 | KEY_CTRL)) { + OS.ch = KEY_NONE; + return; + } + + c = cgetc(); + + if(c == CH_EOL && !inbuf_len) + return; /* ignore empty message */ + + if(c == CH_DEL && inbuf_len) { + OS.escflg = 0; + putchar(c); + OS.escflg = 0x80; + input_buffer[inbuf_len--] = 0; + } else if(inbuf_len == MAX_INPUT_LEN) { + return; /* ignore */ + } else { + putchar(c); + input_buffer[inbuf_len++] = c; + input_buffer[inbuf_len] = 0; + if(c == CH_EOL) { + cmd_command(input_buffer); + ui_init(); + } + } +} -- cgit v1.2.3