I'm trying to figure out how the garbage collection works on the commodore 64 CBM BASIC ROM, and I'm officially stuck on a snippet of code. I can't seem to figure out what it's trying to accomplish.
Code: Select all
;$b56e:
lda $58
ldx $59 ;get current highest string address
;$b572:
cpx $32 ;check against start of free memory high
bne $b57d ;if not on same page, branch to skip this part
cmp $31 ;otherwise check string addr low against free memory low
bne $b57d ;if not in same place, branch to skip this part
jmp $b606 ;otherwise collect the string and leave
;$b57d:
sta $22 ;save temp address here
stx $23
ldy #$00
lda ($22),y ;get first variable name byte
tax ;save in X, mostly to save negative flag
iny
lda ($22),y ;get second variable name byte
php ;save negative flag
iny
lda ($22),y ;get string length or defaddr low
adc $58 ;add to highest address low (plus carry???)
sta $58
iny
lda ($22),y ;get string addr low(???) or defaddr high
adc $59 ;add to highest address high(???)
sta $59
plp ;get negative flag from earlier (second name byte)
bpl $b56e ;if not set, def'd function or floating point, branch
txa ;get value, and thus negative flag, from earlier (first byte)
bmi $b56e ;if set, integer, thus branch, otherwise continue with string
iny
lda ($22),y ;get string addr high
ldy #$00 ;init Y in case we have to search
asl ;multiply by 2, add 5 pages and old temp address low (???)
adc #$05
adc $22
sta $22 ;save as new temp address low
bcc $b5ae
inc $23 ;otherwise increment temp address high
;$b5ae:
ldx $23 ;get temp address high
;$b5b0:
cpx $59 ;compare with highest address high
bne $b5b8 ;if not on same page, branch
cmp $58 ;otherwise compare temp addr low with highest addr low
beq $b572 ;if not in same place, branch to check against start bottom
;$b5b8:
jsr $b5c7 ;otherwise do sub to find highest string in memory
beq $b5b0 ;unconditionally loop to compare