From 63dc8498642b9bd088910a923ed953108f98d207 Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Fri, 8 Jan 2016 06:47:29 -0500 Subject: use custom long-to-ascii routine --- Makefile | 2 +- taipan.c | 4 ++++ ultostr.s | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 ultostr.s diff --git a/Makefile b/Makefile index 730ddc3..ebacf43 100644 --- a/Makefile +++ b/Makefile @@ -63,7 +63,7 @@ XEX=taipan.xex # All the C and asm sources for taimain.xex: TAIMAIN_HDRS=sounds.h TAIMAIN_C_SRC=taipan.c sounds.c -TAIMAIN_ASM_SRC=rand.s draw_lorcha.s timed_getch.s jsleep.s portstat.s clrtobot.s +TAIMAIN_ASM_SRC=rand.s draw_lorcha.s timed_getch.s jsleep.s portstat.s clrtobot.s ultostr.s # Default rule for plain 'make' command is to build the binary. all: $(XEX) diff --git a/taipan.c b/taipan.c index 2624842..d6892ec 100644 --- a/taipan.c +++ b/taipan.c @@ -177,6 +177,10 @@ unsigned char get_item(unsigned char allow_all) { } } +/* modified ultoa() with hardcoded radix */ +extern char *ultostr(unsigned long value, char* s); +#define ultoa(x, y, z) ultostr(x, y) + /* taipan functions (modified as little as possible) */ #define GENERIC 1 #define LI_YUEN 2 diff --git a/ultostr.s b/ultostr.s new file mode 100644 index 0000000..29420e4 --- /dev/null +++ b/ultostr.s @@ -0,0 +1,79 @@ +; +; Modified from cc65's libsrc/common/ltoa.s +; Originally by Ullrich von Bassewitz, 11.06.1998 + +; modified version by B. Watson + +; - rename ultoa => ultostr +; - got rid of ltoa (don't need it) +; - hardcode radix to 10 +; - don't need __hextab since we don't do hex (saves 16 bytes) +; - inline dopop subroutine + +; char* ultostr (unsigned long value, char* s); + + .export _ultostr + .import popax + .importzp sreg, ptr1, ptr2, ptr3 + +radix = 10 + +.code + +_ultostr: + ; pop the arguments + sta ptr1 + stx ptr1+1 + sta sreg ; save for return + stx sreg+1 + jsr popax ; get low word of value + sta ptr2 + stx ptr2+1 + jsr popax ; get high word of value + sta ptr3 + stx ptr3+1 + +; Convert to string by dividing and push the result onto the stack + +ultostr: lda #$00 + pha ; sentinel + +; Divide val/radix -> val, remainder in a + +L5: ldy #32 ; 32 bit + lda #0 ; remainder +L6: asl ptr2 + rol ptr2+1 + rol ptr3 + rol ptr3+1 + rol a + cmp #radix + bcc L7 + sbc #radix + inc ptr2 +L7: dey + bne L6 + + ora #'0' ; get ascii character + pha ; save char value on stack + + lda ptr2 + ora ptr2+1 + ora ptr3 + ora ptr3+1 + bne L5 + +; Get the characters from the stack into the string + + ldy #0 +L9: pla + sta (ptr1),y + beq L10 ; jump if sentinel + iny + bne L9 ; jump always + +; Done! Return the target string + +L10: lda sreg + ldx sreg+1 + rts -- cgit v1.2.3