.area text
; n -> 12,SP
; tmp -> 14,SP
; t -> 15,SP
; j -> 17,SP
; s -> 19,SP
; base -> 27,SP
; i -> 25,SP
; buf -> 21,SP
_itoa::
pshd
leas -21,S
leax 25,S
leay 17,S
movw 0,x,0,y
L2:
ldx 27,S
ldd 17,S
idiv
std 12,S
cpd #9
bgt L5
ldd 12,S
leay 19,S
movw 0,y,10,S
ldy 10,S
iny
sty 19,S
addd #48
tfr D,Y
ldx 10,S
tfr Y,D
stab 0,X
bra L6
L5:
leay 19,S
movw 0,y,8,S
ldy 8,S
iny
sty 19,S
ldd 12,S
addd #87
ldx 8,S
stab 0,X
L6:
ldx 27,S
ldd 17,S
idiv
stx 17,S
L3:
ldy 17,S
cpy #0
bne L2
ldab 14,S
clra
cpd #0
beq L7
leay 19,S
movw 0,y,6,S
ldy 6,S
iny
sty 19,S
ldy #45
ldx 6,S
tfr Y,D
stab 0,X
L7:
leax 19,S
movw 0,x,4,S
ldd 4,S
addd #65535
std 19,S
ldd #0
ldx 4,S
stab 0,X
leax 21,S
movw 0,x,15,S
bra L12
L9:
ldy 15,S
movb 0,Y,14,S
ldy 2,S
iny
sty 15,S
movw 15,S,2,S
ldab [19,S]
tfr B,D
ldx 2,S
stab 0,X
ldd 0,S
addd #65535
tfr D,Y
ldx 0,S
leax 19,S
movw 0,x,0,S
sty 19,S
ldab 14,S
tfr B,D
stab 0,X
L10:
L12:
ldy 15,S
cpy 19,S
blo L9
ldd 21,S
leas 23,S
rts
L1:
leas 23,S
rts