strtoull:
phy.q
and
tay
pha.q
@loop:
lda (sp+26), y
pha
jsr isdigit
pla
bne @digit
jsr tolower
pha
jsr islower
pla
beq @end
@alpha:
sub
bra @chkbase
@digit:
sub
@chkbase:
cmp sp+25
bcs @end
@addval:
tab
lda.q sp+1
mul sp+25
add a, b
sta.q sp+1
iny
and
bra @loop
@end:
pla.q
ply.q
ldb
rts
strlen:
and
@loop:
inc
cmp (d+a-1),
bne @loop
@end:
dec
rts
strcmp:
phb.q
phx.q
phy.q
and
tab
tax
tay
@loop:
ldx
mov a, (d+y)
beq cmpr
ldx
cmp a, (s+y)
bne cmpr
iny
bra @loop
strcasecmp:
phb.q
phx.q
phy.q
and
tab
tax
inx
tay
@loop:
dex
mov a, (d+y)
beq cmpr
inx
jsr tolower
tab
mov a, (s+y)
jsr tolower
cmp b
bne cmpr
iny
bra @loop
cmpr:
mov a, (s+y)
beq @islong
@isshort:
mov a, (d+y)
bne @islong
lda
bra @end
@islong:
cpx
set a, eq
@end:
ply.q
plx.q
plb.q
rts
isdigit:
sec
sbc
and
cmp
lcc
lcs
rts
isxdigit:
pha
jsr isdigit
pla
bne @end
@alpha:
ora
sub
and
cmp
lcc
lcs
@end:
rts
isupper:
sub
bra isletter
islower:
sub
isletter:
and
cmp
lcc
lcs
rts
tolower:
pha
jsr isupper
pla
beq @end
@lower:
ora
@end:
rts
toupper:
pha
jsr islower
pla
beq @end
@upper:
and
@end:
rts
malloc:
phb.q
phx.q
phy.q
xor b, b
mov x, b
txy
mov a, d
beq @end
add
cmp
bcs @getheapf
@toosmall:
lda
@getheapf:
mov d, a
ldb.q heapf
bra @checkblk
@findfblk:
mov.q a, (b+fblk.size)
sub a, d
bcs @blkfound
mov.q b, (b+fblk.next)
@checkblk:
bne @findfblk
mov a, d
add.q heapptr
bcs @outofspace
cmp.q heapend
bcc @inctop
beq @inctop
@outofspace:
and
bra @end
@inctop:
ldb.q heapptr
sta.q heapptr
bra @setsize
@blkfound:
bne @sliceblk
cmp
bcs @sliceblk
mov.q x, (b+fblk.prev)
beq @setheapf
ldy
mov.q (x+y), (b+y)
bra @chknxtblk
@setheapf:
ldy
mov.q heapf, (b+y)
@chknxtblk:
mov.q x, (b+y)
beq @setheapl
ldy
mov.q (x+y), (b+y)
bra @retptr
@setheapl:
ldy
mov.q heapl, (b+y)
bra @retptr
@sliceblk:
ldy
sub.q (b+y), d
add.q b, (b+y)
@setsize:
mov.q (b+ublk.size), d
@retptr:
mov.q (b+ublk.start), b
add b,
tba
@end:
ply.q
plx.q
plb.q
rts
free:
pha.q
phb.q
phx.q
phy.q
phe.q
and
tab
tax
tay
mov a, d
bne @getrealblk
bra @end
@getrealblk:
sub
mov.q a, (a)
mov.q b, (a+ublk.size)
lea e, (a+b)
cpe.q heapptr
bne @heapadd
@dectop:
sta.q heapptr
@chklastblk:
ldb.q heapl
beq @end
ldy
mov.q a, (b+fblk.size)
lea e, (a+b)
cpe.q heapptr
bne @end
@delblk:
stb.q heapptr
@correctblk:
mov.q a, (b+fblk.prev)
sta.q heapl
bne @delnxtblk
sta.q heapf
bra @end
@delnxtblk:
lea e, (a+fblk.next)
stz.q (e)
@end:
ple.q
ply.q
plx.q
plb.q
pla.q
rts
@heapadd:
ldy.q heapf
bne @srchflst
@empty:
mov.q (a+fblk.next), y
mov.q (a+fblk.prev), y
sta.q heapf
sta.q heapl
bra @end
@srchflst:
@loop:
cmp y, a
beq @nextright
bcs @chkrmerge
@nextright:
tyx
mov.q y, (y+fblk.next)
bne @loop
@st_lmerge2:
mov.q (a+fblk.next), y
sta.q heapl
bra @chklmerge2
@chkrmerge:
lea e, (a+b)
cmp e, y
bne @normerge
@rmerge:
mov e, b
add.q e, (y+fblk.size)
mov.q (a+fblk.size), e
@rmerge2:
lea fblk.next
mov.q (a+e), (y+e)
mov.q b, (y+e)
beq @setheapl
@setprev:
mov.q (b+fblk.prev), a
bra @chklmerge
@setheapl:
sta.q heapl
bra @chklmerge
@normerge:
mov.q (a+fblk.next), y
mov.q (y+fblk.prev), a
@chklmerge:
and x, x
bne @chklmerge2
@newstart:
mov.q (a+fblk.prev), x
sta.q heapf
bra @end2
@chklmerge2:
mov.q e, (x+fblk.size)
add e, x
cmp e, a
bne @nolmerge
@lmerge:
lea fblk.size
add.q (x+e), (a+e)
@lmerge2:
lea fblk.next
mov.q (x+e), (a+e)
mov.q b, (a+e)
beq @newlast
@lprev:
mov.q (b+fblk.prev), x
bra @end2
@newlast:
stx.q heapl
bra @end2
@nolmerge:
mov.q (x+fblk.next), a
@nolmerge2:
mov.q (a+fblk.prev), x
@end2:
ple.q
ply.q
plb.q
pla.q
rts
memcpy:
phb.q
mov a, d
and f, f
beq @end
xor b, b
@loop:
mov (d+b), (s+b)
inb
cmp b, f
bne @loop
@end:
plb.q
rts
memcpy_back:
phb.q
mov a, d
mov b, f
@loop:
cpb
beq @end
deb
mov (d+b), (s+b)
bra @loop
@end:
plb.q
rts
memcpy_dir:
and c, c
bne @back
@forward:
jsr memcpy
bra @end
@back:
jsr memcpy_back
@end:
rts
memset:
phb.q
xor b, b
mov a, d
cmp f,
beq @end
@loop:
mov (d+b), s
inb
cmp b, f
bne @loop
@end:
plb.q
rts
max:
mov a, s
cmp d, s
beq @end
mcs a, d
@end:
rts
min:
mov a, s
cmp d, s
mcc a, d
@end:
rts