Use old offset calculation, save ptr3

Looks like cprintf modifies ptr3, so make sure to save it if you are
calling that.

There also may have been an issue with how the previous sector address
was calculated, the one which does not account for carries seems to
work.
This commit is contained in:
Byron Lathi
2023-08-23 20:48:57 -07:00
parent 8273e01ad8
commit eb72e83629

View File

@@ -101,6 +101,11 @@ _start:
ldx #>word_str ldx #>word_str
jsr pushax jsr pushax
lda ptr3
pha
lda ptr3 + 1
pha
ldy #$1d ; load file size (256) ldy #$1d ; load file size (256)
lda (ptr3),y lda (ptr3),y
lsr ; divide by 2 to get file size (512) lsr ; divide by 2 to get file size (512)
@@ -108,26 +113,29 @@ _start:
ldy #$4 ldy #$4
jsr _cprintf jsr _cprintf
pla
sta ptr3 + 1
pla
sta ptr3
ldy #$1b ; load high byte of low first cluster ldy #$1b ; load high byte of low first cluster
lda (ptr3),y lda (ptr3),y
tax tax
dey dey
lda (ptr3),y ; load low byte of low first cluster lda (ptr3),y ; load low byte of low first cluster
ldx data_start + 1
sec sec
sbc #$02 sbc #$02 ; don't handle carry, assume low byte is not 0 or 1
bcs @3 ldx data_start + 1 ; load x as high data start
dex asl ; multiply cluster num (minus 2) by 8
@3: asl
asl asl
asl asl
clc clc
adc data_start adc data_start ; add that to low data start
bcc @5 bcc @5 ; handle carry
inx inx
@5: stz sreg ; data start is not going to be > 2^16 @5: stz sreg
stz sreg + 1 ; (I hope) stz sreg+1
phx phx
pha pha