From 900eb9bca18f57531bc74d3a5f5b5e87870cd1ae Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Sun, 5 Apr 2026 19:59:30 -0400 Subject: Replace cc65 lib isdigit() and atoi() with less bloated isnum() and a2uint(). --- src/a2uint.s | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/cmd.c | 4 ++-- src/complete.c | 1 - src/irc.c | 7 +++---- src/irc.h | 6 ++++++ src/isnum.s | 18 +++++++++++++++++ src/main.c | 1 - 7 files changed, 92 insertions(+), 8 deletions(-) create mode 100644 src/a2uint.s create mode 100644 src/isnum.s (limited to 'src') diff --git a/src/a2uint.s b/src/a2uint.s new file mode 100644 index 0000000..c296181 --- /dev/null +++ b/src/a2uint.s @@ -0,0 +1,63 @@ + + ; replacement for atoi() that doesn't use cc65's bloated ctype. + ; also, doesn't handle signed results (not needed). + + .export _a2uint + .import _isnum + .importzp ptr1, sreg + + result = sreg + temp16 = sreg+2 + +_a2uint: + sta ptr1 + stx ptr1+1 + + lda #0 + sta result + sta result+1 + tay + +@chrloop: + lda (ptr1),y ; get next character + jsr _isnum ; is is a digit? + beq @done ; Z set = non-digit + + ; multiply result by 10 + lda result + asl + sta temp16 + lda result+1 + rol + sta temp16+1 ; temp16 now result * 2 + + ldx #3 +@x8loop: + asl result + rol result+1 + dex + bne @x8loop + + ; result now result * 8 + clc + lda result + adc temp16 + sta result + lda result+1 + adc temp16+1 + sta result+1 ; result now original result * 10 + + lda (ptr1),y ; get character again + iny ; point to next char + and #$0f ; de-ASCIIfy + clc + adc result + sta result + bcc @chrloop + inc result+1 + bne @chrloop + +@done: + lda result + ldx result+1 + rts diff --git a/src/cmd.c b/src/cmd.c index 03a6a26..f0a6d8a 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -356,9 +356,9 @@ static void do_ver(void) { static void do_color(void) { arg2 = nextarg(arg1); - OS.color2 = atoi(arg1); + OS.color2 = a2uint(arg1); if(arg2) - OS.color1 = atoi(arg2); + OS.color1 = a2uint(arg2); } static void do_query(void) { diff --git a/src/complete.c b/src/complete.c index 46073c4..e76def1 100644 --- a/src/complete.c +++ b/src/complete.c @@ -1,6 +1,5 @@ #include #include -#include #include "addrs.h" #include "edbox.h" #include "screen.h" diff --git a/src/irc.c b/src/irc.c index e518205..e581e94 100644 --- a/src/irc.c +++ b/src/irc.c @@ -1,7 +1,6 @@ #include #include #include -#include #include "irc.h" #include "screen.h" @@ -123,7 +122,7 @@ static void print_ping_time(char *p) { static unsigned int sec, frac; now = read_rtclok(); - pingtime = (unsigned int)atoi(p); + pingtime = (unsigned int)a2uint(p); /* correct for rtclock rollover (every ~9 mins) */ if(now < pingtime) now |= 0x8000; @@ -384,7 +383,7 @@ static void do_forward_chan(void) { static void do_numeric(void) { static unsigned int num; - num = atoi(msg_cmd); + num = a2uint(msg_cmd); switch(num) { /* use the server's idea of what our nick is, in case it got @@ -559,7 +558,7 @@ static void dispatch_msg(void) { } else { do_server_pong(); } - } else if(isdigit(msg_cmd[0])) { + } else if(isnum(msg_cmd[0])) { do_numeric(); } else { do_catchall(0); diff --git a/src/irc.h b/src/irc.h index 91ffd00..3171033 100644 --- a/src/irc.h +++ b/src/irc.h @@ -75,3 +75,9 @@ void cmd_send_pm(char *args); void cmd_ctcp_ping(char *nick); void cmd_server_ping(void); unsigned int read_rtclok(void); /* irc.c needs this one so it's not static */ + +/* see isnum.s */ +extern char __fastcall__ isnum(char c); + +/* see a2uint.s */ +extern unsigned int __fastcall__ a2uint(char *str); diff --git a/src/isnum.s b/src/isnum.s new file mode 100644 index 0000000..7aa3251 --- /dev/null +++ b/src/isnum.s @@ -0,0 +1,18 @@ + + .export _isnum + + ; isdigit() replacement that avoids cc65's ctype bloat. + ; returns 0 in A/X for non-digit, non-zero for digit. + ; *also* when calling from asm, the Z flag is set for + ; non-digit, clear for digit. +_isnum: + cmp #'0' + bcc ret0 + cmp #'9'+1 + bcs ret0 + lda #1 + .byte $2c +ret0: + lda #0 + tax + rts diff --git a/src/main.c b/src/main.c index c19cff9..ebce0bb 100644 --- a/src/main.c +++ b/src/main.c @@ -10,7 +10,6 @@ #include #include #include -#include #include "nio.h" #include "irc.h" #include "screen.h" -- cgit v1.2.3