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);
10 .import __hextab, __longminstr
11 .importzp sreg, ptr1, ptr2, ptr3, tmp1
18 ; Common subroutine to pop the parameters and put them into core
21 dopop: sta tmp1 ; will loose high byte
25 sta sreg ; save for return
27 jsr popax ; get low word of value
30 jsr popax ; get high word of value
39 _ltoa: jsr dopop ; pop the arguments
41 ; We must handle $80000000 in a special way, since it is the only negative
42 ; number that has no positive 32-bit counterpart
44 ldx ptr3+1 ; get high byte
56 L1: lda __longminstr,y ; copy -2147483648
62 ; Check if the value is negative. If so, write a - sign and negate the
65 L2: txa ; get high byte
69 sta (ptr1),y ; store sign
74 L3: lda ptr2 ; negate val
97 _ultoa: jsr dopop ; pop the arguments
99 ; Convert to string by dividing and push the result onto the stack
104 ; Divide val/tmp1 -> val, remainder in a
120 tay ; get remainder into y
121 lda __hextab,y ; get hex character
122 pha ; save char value on stack
130 ; Get the characters from the stack into the string
135 beq L10 ; jump if sentinel
139 ; Done! Return the target string