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:
sec
sbc
bra @chkbase
@digit:
sec
sbc
@chkbase:
cmp sp+25
bcs @end
@addval:
tab
lda.q sp+1
mul sp+25
clc
adc b
sta.q sp+1
iny
and
bra @loop
@end:
pla.q
ply.q
ldb
rts
strlen:
phy.q
pha.q
and
tay
@loop:
lda (sp+1), y
beq @end
iny
bra @loop
@end:
pla.q
tya
ply.q
rts
strcmp:
ldb
tba
phy.q
tay
@loop:
ldb
lda (sp+25), y
beq cmpr
ldb
cmp (sp+19), y
bne cmpr
iny
bra @loop
strccmp:
strcasecmp:
ldb
tba
phy.q
tay
@loop:
ldb
lda (sp+25), y
beq cmpr
ldb
jsr tolower
phb
pha
lda (sp+19), y
jsr tolower
tab
pla
cmp b
plb
bne cmpr
iny
bra @loop
cmpr:
lda (sp+17), y
beq @islong
@isshort:
lda (sp+25), y
beq @short
@islong:
cpb
bne @equ
@long:
lda
bra @end
@equ:
lda
bra @end
@short:
lda
@end:
ply.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:
phy.q
pha.q
and
tay
sbs
lda.q sp+17
ora.d sp+21
beq @end
lda.q sp+17
clc
adc
sta.q sp+17
lda.q heapf
sta.q sp+9
bra @checkblk
@findfblk:
ldy
lda.q (sp+9), y
sec
sbc.q sp+17
bcs @blkfound
ldy
lda.q (sp+9), y
sta.q sp+9
@checkblk:
ora.d sp+13
bne @findfblk
lda.q heapptr
clc
adc.q sp+17
bcs @outofspace
cmp.q heapend
bcc @inctop
beq @inctop
@outofspace:
and
bra @end
@inctop:
pha.q
lda.q heapptr
sta.q sp+17
pla.q
sta.q heapptr
bra @setsize
@blkfound:
bne @sliceblk
cmp
bcs @sliceblk
ldy
lda.q (sp+9), y
sta.q sp+1
ora.d sp+5
beq @setheapf
ldy
lda.q (sp+9), y
sta.q (sp+1), y
bra @chknxtblk
@setheapf:
lda.q (sp+9), y
sta.q heapf
@chknxtblk:
lda.q (sp+9), y
sta.q sp+1
ora.d sp+5
beq @setheapl
ldy
lda.q (sp+9), y
sta.q (sp+1), y
bra @retptr
@setheapl:
ldy
lda.q (sp+9), y
sta.q heapl
bra @retptr
@sliceblk:
ldy
lda.q (sp+9), y
sec
sbc.q sp+17
sta.q (sp+9), y
clc
adc.q sp+9
sta.q sp+9
@setsize:
ldy
lda.q sp+17
sta.q (sp+9), y
@retptr:
ldy
lda.q sp+9
sta.q (sp+9), y
clc
adc
@end:
ads
ply.q
rts
free:
pha.q
phb.q
phy.q
pha.q
and
tay
sbs
lda.q sp+25
ora.d sp+29
bne @getrealblk
bra @end
@getrealblk:
lda.q sp+25
sec
sbc
sta.q sp+25
lda.q (sp+25)
sta.q sp+25
ldy
lda.q (sp+25), y
sta.q sp+17
clc
adc.q sp+25
cmp.q heapptr
bne @heapadd
@dectop:
lda.q sp+25
sta.q heapptr
@chklastblk:
lda.q heapl
sta.q sp+17
ora.d sp+21
beq @end
lda.q sp+17
ldy
lda.q (sp+17), y
clc
adc.q sp+17
cmp.q heapptr
bne @end
@delblk:
lda.q sp+17
sta.q heapptr
@correctblk:
ldy
lda.q (sp+17), y
sta.q sp+25
sta.q heapl
ora.d sp+29
bne @delnxtblk
sta.q heapf
bra @end
@delnxtblk:
and
ldy
sta.q (sp+25), y
@end:
ads
ply.q
plb.q
pla.q
rts
@heapadd:
lda.q heapf
sta.q sp+9
ora.d sp+13
bne @srchflst
@empty:
ldy
sta.q (sp+25), y
ldy
sta.q (sp+25), y
lda.q sp+25
sta.q heapf
sta.q heapf
bra @end
@srchflst:
and
sta.q sp+1
ldy
@loop:
lda.q sp+9
cmp.q sp+25
beq @nextright
bcs @chkrmerge
@nextright:
sta.q sp+1
lda.q (sp+9), y
sta.q sp+9
ora.d sp+13
bne @loop
@st_lmerge2:
sta.q (sp+25), y
lda.q sp+25
sta.q heapl
bra @chklmerge2
@chkrmerge:
lda.q sp+25
clc
adc.q sp+17
cmp.q sp+9
bne @normerge
@rmerge:
ldy
lda.q sp+17
clc
adc.q (sp+9), y
sta.q (sp+25), y
@rmerge2:
ldy
lda.q (sp+9), y
sta.q (sp+25), y
sta.q sp+17
ora.d sp+21
beq @setheapl
@setprev:
lda.q sp+25
ldy
sta.q (sp+17), y
bra @chklmerge
@setheapl:
lda.q sp+25
sta.q heapl
bra @chklmerge
@normerge:
lda.q sp+9
ldy
sta.q (sp+25), y
lda.q sp+25
ldy
lda.q (sp+9), y
@chklmerge:
lda.q sp+1
ora.d sp+5
bne @chklmerge2
@newstart:
ldy
sta.q (sp+25), y
lda.q sp+25
sta.q heapf
bra @end2
@chklmerge2:
ldy
lda.q (sp+1), y
clc
adc.q sp+1
cmp.q sp+25
bne @nolmerge
@lmerge:
lda.q (sp+1), y
clc
ldb.q (sp+25), y
adc b
sta.q (sp+1), y
@lmerge2:
ldy
lda.q (sp+25), y
sta.q (sp+1), y
sta.q sp+17
ora.d sp+21
beq @newlast
@lprev:
lda.q sp+1
ldy
sta.q (sp+17), y
bra @end2
@newlast:
lda.q sp+1
sta.q heapl
bra @end2
@nolmerge:
lda.q sp+25
ldy
sta.q (sp+1), y
@nolmerge2:
lda.q sp+1
ldy
sta.q (sp+25), y
@end2:
ads
ply.q
plb.q
pla.q
rts
memcpy:
pha.q
pha.q
phb.q
phy.q
and
tab
cpy
beq @end
@loop:
lda (sp+9)
sta (sp+17)
inc.q sp+9
inc.q sp+17
dey
beq @end
bra @loop
@end:
ads
pla.q
rts