Well, this is nothing new and its certainly only one of many converters, but I made one that is hopefully small (but not so fast):
Code:
; Convert 32-bit number to petscii/ascii
; "printsize" is a pointer to the 32-bit number (e.g. 4 bytes)
; Uses two ZP locations for temporary storage ($2 & $3)
; "printtxt" is the null-terminated output string
long2petscii
ldy #3
pfsl2
ldx #3
lda #0
sta $2
sec
php
pfsl3
plp
pfsl3b
lda printsize,x
sta printsize+4,x
sbc subtable,y
sta printsize,x ; store remaining value
php
dey
dex
bpl pfsl3
inc $2
iny
iny
iny
iny ; reset y
ldx #3
plp ; get carry
bcs pfsl3b ; still positive
lda printsize+4 ; now negative, so recall last value
sta printsize
lda printsize+5
sta printsize+1
lda printsize+6
sta printsize+2
lda printsize+7
sta printsize+3
iny ; next stage
iny
iny
iny
sty $3 ;save
tya
lsr ;/2
lsr ;/4
tay
dey
lda $2
clc
adc #$2F ;($2)+$30-1 get petscii code
sta printtxt,y ;put number into text string
ldy $3
cpy #$2B
bne pfsl2
lda #0
sta printtxt+10
lda #<printtxt
ldy #>printtxt
;A and Y points to a null terminated string which is the number in Ascii.
rts
subtable
byte $3b,$9a,$ca,$00 ;1000000000 (=1G)
byte $05,$f5,$e1,$00 ;100000000
byte $00,$98,$96,$80 ;10000000
byte $00,$0f,$42,$40 ;1000000
byte $00,$01,$86,$a0 ;100000
byte $00,$00,$27,$10 ;10000
byte $00,$00,$03,$e8 ;1000
byte $00,$00,$00,$64 ;100
byte $00,$00,$00,$0a ;10
byte $00,$00,$00,$01 ;1
printsize
bytes 8,0
printtxt
bytes 11,0
If you want something fast, this is not it. But I hope it takes less space than some of the other converters out there (which was the reason I made it). I haven't optimized it (yet), so you can probably shave off some bytes here and there to get it even more compact.
Edit: Ok, some testing shows that it uses 2600 cpu cycles for the number "1" and about 14600 cycles for the number "3999999999" (absolutely worst case). Still only 14ms at 1MHz or 1ms at 14Mhz.. Total code size is 123 bytes.