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 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 src/a2uint.s (limited to 'src/a2uint.s') 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 -- cgit v1.2.3