6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Mon Sep 30, 2024 10:42 am

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Fri Oct 17, 2008 6:02 pm 
Offline

Joined: Fri Oct 17, 2008 5:48 pm
Posts: 4
I'm not really sure where to post this.

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:
;$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


I don't know how much more information I need to post, but as you can see, I'm having trouble making heads or tails of what precisely is going on here. Is there anybody here knowledgeable about CBM BASIC's inner workings that can shed some light on this?


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Oct 17, 2008 8:53 pm 
Offline

Joined: Fri Aug 30, 2002 2:05 pm
Posts: 347
Location: UK
Code:
;$b56e:
       lda $58     ;get pointer low byte
       ldx $59     ;get pointer high byte
;$b572:
       cpx $32     ;compare with end of arrays high byte
       bne $b57d   ;if not on same page, branch to skip this part

       cmp $31     ;else compare with end of arrays low byte
       bne $b57d   ;if not in same place, branch to skip this part

       jmp $b606   ;otherwise collect the string and leave

;$b57d:
       sta $22     ;save pointer low byte
       stx $23     ;save pointer high byte
       ldy #$00
       lda ($22),y ;get first array name byte
       tax         ;save in X, mostly to save negative flag
       iny
       lda ($22),y ;get second array name byte
       php         ;save negative flag
       iny
       lda ($22),y ;get array size low
       adc $58     ;add start of this array low, carry always clear
       sta $58     ;save start of next array low
       iny
       lda ($22),y ;get array size high
       adc $59     ;add start of this array high
       sta $59     ;save start of next array high

       plp         ;get negative flag from earlier (second name byte)
       bpl $b56e   ;if not string go do next array

; was possibly string array so ...

       txa         ;get value, and thus negative flag, from earlier (first byte)
       bmi $b56e   ;if not string go do next array

; collect string array

       iny
       lda ($22),y ;get number of dimensions
       ldy #$00    ;init Y in case we have to search
       asl         ;multiply by 2 ..
       adc #$05    ;.. add 5 gives array header size
       adc $22     ;add pointer low byte
       sta $22     ;save new pointer address low
       bcc $b5ae   ;branch if no rollover

       inc $23     ;otherwise increment pointer address high
;$b5ae:
       ldx $23     ;get pointer high
;$b5b0:
       cpx $59     ;compare pointer high byte with end of this array high byte
       bne $b5b8   ;branch if not there yet

       cmp $58     ;compare pointer low byte with end of this array low byte
       beq $b572   ;if at end of this array go check next array

;$b5b8:
       jsr $b5c7   ;otherwise do sub to find highest string in memory
       beq $b5b0   ;unconditionally loop to compare

Does that help?

Lee.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Oct 17, 2008 9:58 pm 
Offline

Joined: Fri Oct 17, 2008 5:48 pm
Posts: 4
<smacks forehead>

I had a feeling I was gonna feel stupid not having figured it out sooner or later. In my rush to understand garbage collection I had forgotten all about arrays. Thanks a lot!


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: