From 15488c9cb3c7200efc3c863b505959a07e96e89a Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Mon, 9 Mar 2026 21:41:56 -0400 Subject: use 16-bit ints for ping times (saves 778 bytes). --- src/cmd.c | 15 ++++----------- src/irc.c | 33 ++++++++++++++++++++++----------- src/irc.h | 2 +- 3 files changed, 27 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/cmd.c b/src/cmd.c index 770d879..2f5b59e 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -229,20 +229,13 @@ static void send_ctcp(void) { txbuf_send(); } -long read_rtclok(void) { - long r; - - r = ((long)OS.rtclok[0] << 16); - r |= (OS.rtclok[1] << 8); - r |= OS.rtclok[2]; - - return r; +/* only the bottom 15 bits! */ +unsigned int read_rtclok(void) { + return ((OS.rtclok[1] << 8) | (OS.rtclok[2])) & 0x7fff; } static void rtclok_to_numbuf(void) { - long r; - r = read_rtclok(); - ltoa(r, numbuf, 10); + itoa(read_rtclok(), numbuf, 10); } static void do_ctcp_ping(void) { diff --git a/src/irc.c b/src/irc.c index f5c0149..8740e15 100644 --- a/src/irc.c +++ b/src/irc.c @@ -81,21 +81,31 @@ static void do_chan_nick(void) { } static void do_priv_nick(void) { - scr_print_active("*"); - scr_print_active(msg_src); - scr_print_active("* "); - bell(); + if(msg_src) { + scr_print_active("*"); + scr_print_active(msg_src); + scr_print_active("* "); + bell(); + } } +/* this ping calculation relies on the assumption that + nobody's ping time will ever be more than 9 minutes. anyone + that lagged will have been disconnected from the server already. + if this assumption turns out to be false, the ping time displayed + will be wrong (module ~9 mins). I don't think it's ever going to be + a real problem. + Why do it this way? Because using longs instead of ints bloats the + code by 778 bytes! */ static void print_ping_time(char *p) { - static long now, pingtime; - static int sec, frac; + static unsigned int now, pingtime; + static unsigned int sec, frac; now = read_rtclok(); - pingtime = atol(p); + pingtime = (unsigned int)atoi(p); - /* correct for rtclock rollover (every 77 hours) */ - if(now < pingtime) now |= 0x01000000L; + /* correct for rtclock rollover (every ~9 mins) */ + if(now < pingtime) now |= 0x8000; pingtime = now - pingtime; @@ -114,9 +124,10 @@ static void print_ping_time(char *p) { scr_print_active(numbuf); scr_print_active(" sec"); - /* for debugging: + /* + // for debugging: scr_print_active(" "); - ltoa(pingtime, numbuf, 10); + itoa(pingtime, numbuf, 10); scr_print_active(numbuf); */ } diff --git a/src/irc.h b/src/irc.h index b6791ad..2525120 100644 --- a/src/irc.h +++ b/src/irc.h @@ -61,4 +61,4 @@ void print_errnum(void); /**** cmd.c */ void cmd_command(char *cmd); void cmd_execute(void); -long read_rtclok(void); /* irc.c needs this one so it's not static */ +unsigned int read_rtclok(void); /* irc.c needs this one so it's not static */ -- cgit v1.2.3