2 ; Ullrich von Bassewitz, 11.06.1998
4 ; char* ltoa (long value, char* s, int radix);
5 ; char* ultoa (unsigned long value, char* s, int radix);
11 .importzp sreg, ptr1, ptr2, ptr3, tmp1
17 .byte '-', '2', '1', '4', '7', '4', '8', '3', '6', '4', '8', 0
21 ; Common subroutine to pop the parameters and put them into core
24 dopop: sta tmp1 ; will loose high byte
28 sta sreg ; save for return
30 jsr popax ; get low word of value
33 jsr popax ; get high word of value
42 _ltoa: jsr dopop ; pop the arguments
44 ; We must handle $80000000 in a special way, since it is the only negative
45 ; number that has no positive 32-bit counterpart
47 ldx ptr3+1 ; get high byte
59 L1: lda specval,y ; copy -2147483648
65 ; Check if the value is negative. If so, write a - sign and negate the
68 L2: txa ; get high byte
72 sta (ptr1),y ; store sign
77 L3: lda ptr2 ; negate val
100 _ultoa: jsr dopop ; pop the arguments
102 ; Convert to string by dividing and push the result onto the stack
107 ; Divide val/tmp1 -> val, remainder in a
123 tay ; get remainder into y
124 lda __hextab,y ; get hex character
125 pha ; save char value on stack
133 ; Get the characters from the stack into the string
138 beq L10 ; jump if sentinel
142 ; Done! Return the target string