.org util_data
hex_char:
.byte "0123456789ABCDEF"
ptok_tab:
.byte ".@:=+-><(),xy\"\'#;$%"
dtab:
.byte "\n,\"\' "
dtab2:
.byte "),.+<>-=;\n"
.org utils
print_hi:
and
sta idx3
lda
jsr charcpy
lda.q idx0
ldx
jsr print_hex
lda.q hex_str
sta.q strbuf+1
lda.q hex_str+8
sta.q strbuf+9
ldx
stx idx3
lda
jsr charcpy
lda
jsr charcpy
rts
print_lo:
lda
sta idx3
@loop:
ldx
pha
jsr print_hex
lda.w (ptr3)
jsr charcpy
lsr
jsr charcpy
pla
inc
cmp
bcs @end
@loop1:
pha
lda
jsr charcpy
pla
bra @loop
@end:
inx
lda
sta strbuf, x
tax
lda.d
jsr print_str
rts
print_chunk:
ldx
phy.w
txy
@loop:
and
ldx
lda (idx0), y
jsr print_hex
lda.w (ptr3)
jsr charcpy
lsr
jsr charcpy
iny
cpy
beq @end
lda
jsr charcpy
bra @loop
@end:
ply.w
inx
and
sta strbuf, x
tax
sta idx3
rts
print_hex:
pha.q
and
ldb
lda.w
jsr set_ptr
inb
lda.d
clc
adc
jsr set_ptr
ldb
pla.q
@loop:
pha.q
and
phy.w
tay
lda (ptr2), y
dec ptr3
sta (ptr3)
ply.w
pla.q
@isauto:
cpx
bcc @auto
dex
beq @end
bra @next
@auto:
ldb
@next:
lsr
beq @isauto1
bra @loop
@isauto1:
cpb
beq @end
bra @loop
@end:
rts
strtoull:
phy.w
sta f
and
tay
sta.q valbuf
@loop:
lda (ptr3), y
pha
jsr isdigit
pla
bne @digit
jsr tolower
pha
jsr islower
pla
beq @end
@alpha:
sec
sbc
bra @chkbase
@digit:
sec
sbc
@chkbase:
cmp f
bcs @end
@addval:
tab
lda.q valbuf
mul f
clc
aab
sta.q valbuf
iny
bra @loop
@end:
ply.w
ldb
rts
charcpy:
ldx idx3
sta strbuf, x
inc idx3
rts
strlen:
ldb
jsr set_ptr
deb
tba
tax
phy.w
txy
@loop:
lda (ptr2), y
beq @end
iny
bra @loop
@end:
tyx
ply.w
rts
strcmp:
ldb
jsr set_ptr
deb
tba
phy.w
tay
@loop:
ldb
lda (ptr), y
beq cmpr
ldb
cmp (ptr2), y
bne cmpr
iny
bra @loop
strcasecmp:
ldb
jsr set_ptr
deb
tba
phy.w
tay
@loop:
ldb
lda (ptr), y
beq cmpr
ldb
jsr tolower
phb
pha
lda (ptr2), y
jsr tolower
tab
pla
cab
plb
bne cmpr
iny
bra @loop
cmpr:
lda (ptr2), y
beq @islong
@isshort:
lda (ptr), y
beq @short
@islong:
cpb
bne @equ
@long:
lda
bra @end
@equ:
lda
bra @end
@short:
lda
@end:
ply.w
rts
isdigit:
sec
sbc
and
cmp
bcs @false
@true:
lda
bra @end
@false:
lda
@end:
rts
isxdigit:
pha
jsr isdigit
pla
bne @true
@alpha:
sec
ora
sbc
and
cmp
bcs @false
@true:
lda
bra @end
@false:
lda
@end:
rts
isupper:
sec
sbc
bra isletter
islower:
sec
sbc
isletter:
and
cmp
bcs @false
@true:
lda
bra @end
@false:
lda
@end:
rts
tolower:
pha
jsr isupper
pla
beq @end
@lower:
ora
@end:
rts
toupper:
pha
jsr islower
pla
beq @end
@upper:
and
@end:
rts
isdelm2:
ldx
@loop:
ldb dtab2, x
beq @other
cab
beq @r1
inx
bra @loop
@other:
ldx
cmp
beq @r1
cmp
beq @r2
cmp
beq @r2
@r0:
lda
rts
@r1:
ldx
lda
rts
@r2:
lda
rts
isdelm:
ldx
stx a
@loop:
ldb dtab, x
beq @other
cab
beq @rshft
inx
bra @loop
@other:
ldx
cmp
beq @rshft
ldx
cmp
beq @rshft
ldx
@r0:
lda
rts
@rshft:
stx a
ldx
lda
lsl a
rts
get_ptok:
ldx
jsr tolower
@loop:
ldb ptok_tab, x
beq @other
cab
beq @rtab
inx
bra @loop
@rtab:
txa
rts
@other:
tab
jsr isdigit
bne @rnum
tba
jsr islower
bne @ralph
lda
rts
@rnum:
lda
rts
@ralph:
lda
rts