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);
9 .import popax, popptr1, negeax
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
22 jsr popax ; get s to ptr2
25 sta ptr3 ; save for return
27 jsr popptr1 ; get low word of value to ptr1
28 jsr popax ; get high word of value to sreg
37 _ltoa: jsr dopop ; pop the arguments
39 ; We must handle $80000000 in a special way, since it is the only negative
40 ; number that has no positive 32-bit counterpart
42 ldx sreg+1 ; get high byte
54 L1: lda __longminstr,y ; copy -2147483648
60 ; Check if the value is negative. If so, write a - sign and negate the
63 L2: txa ; get high byte
67 .if (.cpu .bitand CPU_ISET_65SC02)
71 sta (ptr2),y ; store sign
78 L3: lda ptr1 ; negate val
91 _ultoa: jsr dopop ; pop the arguments
93 ; Convert to string by dividing and push the result onto the stack
98 ; Divide val/tmp1 -> val, remainder in a
114 tay ; get remainder into y
115 lda __hextab,y ; get hex character
116 pha ; save char value on stack
124 ; Get the characters from the stack into the string
129 beq L10 ; jump if sentinel
133 ; Done! Return the target string