diff options
| author | B. Watson <urchlay@slackware.uk> | 2026-04-05 19:59:30 -0400 |
|---|---|---|
| committer | B. Watson <urchlay@slackware.uk> | 2026-04-05 19:59:30 -0400 |
| commit | 900eb9bca18f57531bc74d3a5f5b5e87870cd1ae (patch) | |
| tree | 5ee6d1047444e9e2473945e2df6025897a89d16a /src/a2uint.s | |
| parent | 06bdd272adb09ae5b55a068dfa879ce005cf4748 (diff) | |
| download | fujinet-chat-900eb9bca18f57531bc74d3a5f5b5e87870cd1ae.tar.gz | |
Replace cc65 lib isdigit() and atoi() with less bloated isnum() and a2uint().
Diffstat (limited to 'src/a2uint.s')
| -rw-r--r-- | src/a2uint.s | 63 |
1 files changed, 63 insertions, 0 deletions
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 |
