aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cmd.c8
-rw-r--r--src/conio.c.old (renamed from src/conio.c)0
-rw-r--r--src/conio.h.old (renamed from src/conio.h)0
-rw-r--r--src/err.c.old (renamed from src/err.c)0
-rw-r--r--src/err.h.old (renamed from src/err.h)0
-rw-r--r--src/irc.c131
-rw-r--r--src/irc.h9
-rw-r--r--src/main.c99
-rw-r--r--src/screen.h2
-rw-r--r--src/ui.c.old (renamed from src/ui.c)0
10 files changed, 142 insertions, 107 deletions
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 <atari.h>
#include <stdio.h>
#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.old
index 2742ab6..2742ab6 100644
--- a/src/conio.c
+++ b/src/conio.c.old
diff --git a/src/conio.h b/src/conio.h.old
index 25ca6c2..25ca6c2 100644
--- a/src/conio.h
+++ b/src/conio.h.old
diff --git a/src/err.c b/src/err.c.old
index 8d58670..8d58670 100644
--- a/src/err.c
+++ b/src/err.c.old
diff --git a/src/err.h b/src/err.h.old
index d3bf3d7..d3bf3d7 100644
--- a/src/err.h
+++ b/src/err.h.old
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 <ctype.h>
#include "irc.h"
+#include "screen.h"
+#include "edbox.h"
#include "numerics.h"
#ifdef __ATARI__
#include <atari.h>
#include <conio.h>
-#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 <string.h>
#include <ctype.h>
#include <conio.h> // 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.old
index 68f32a0..68f32a0 100644
--- a/src/ui.c
+++ b/src/ui.c.old