avoid redundant seek on aligned read

This commit is contained in:
Peter Ferrie 2016-11-29 16:53:44 -08:00
parent b527d41d26
commit a5b839d7d0

82
fstbt.s
View File

@ -6,26 +6,40 @@
!to "fstbt",plain
*=$800
enable_stack = 0 ;set to 1 to enable reading into stack (mutually exclusive with enable_banked)
enable_banked = 0 ;set to bank number (1 or 2) to enable reading into banked RAM
!if (enable_stack+enable_banked)=2 {
!error can't enable both options
}
!byte 1
tay ;A is last read sector+1 on entry
!if enable_banked=1 {
lda $C089 ;bank in ROM while leaving RAM write-enabled if it was before
} else {
!if enable_banked=2 {
lda $C081 ;bank in ROM while leaving RAM write-enabled if it was before
}
}
;check array before checking sector number
;allows us to avoid a redundant seek if all slots are full in a track,
;and then the list ends
incindex
inc adrindex + 1 ;select next address
adrindex
lda adrtable - 1 ;15 entries in first row, 16 entries thereafter
cmp #$C0
beq jmpoep ;#$C0 means end of data
sta $27 ;set high part of address
;2, 4, 6, 8, $0A, $0C, $0E
;because PROM increments by one itself
;and is too slow to read sectors in purely incremental order
;so we offer every other sector for read candidates
incsector
iny
cpy #$10 ;set carry, needed for seek
bcc incindex ;cases 1-$0F
cpy #$10
bcc setsector ;cases 1-$0F
beq sector1 ;finished with $0E
;next should be 1 for 1, 3, 5, 7... sequence
@ -40,26 +54,11 @@ incsector
sector1
ldy #1
incindex
sty $3d ;set sector
setsector
sty $3D ;set sector
iny ;prepare to be next sector in case of unallocated sector
inc adrindex + 1 ;select next address
!if enable_banked=1 {
lda $C08B
lda $C08B
} else {
!if enable_banked=2 {
lda $C083
lda $C083
}
}
adrindex
lda adrtable - 1 ;15 entries in first row, 16 entries thereafter
beq incsector ;skip empty slots to allow sparse tracks
sta $27 ;set high part of address
cmp #$C0 ;detect end of data
beq jmpoep ;end of data
lda $27
beq incindex ;empty slot, back to the top
;convert slot to PROM address
@ -72,17 +71,26 @@ adrindex
pha
lda #$5B ;read-1
pha
!if enable_banked=1 {
lda $C08B
lda $C08B ;write-enable RAM and bank it in so read can decode
} else {
!if enable_banked=2 {
lda $C083
lda $C083 ;write-enable RAM and bank it in so read can decode
}
}
rts ;return to PROM
seek
inc $41 ;next track
asl $40 ;carry clear, phase off
jsr seek1
jsr seek1 ;returns carry set, not useful
clc ;carry clear, phase off
seek1
jsr delay ;returns with carry set, phase on
inc $40
inc $40 ;next phase
delay
lda $40
@ -91,21 +99,21 @@ delay
ora $2B ;merge in slot
tay
lda $C080, y
!if enable_banked = 1 {
lda $C089
} else {
!if enable_banked = 2 {
lda $C081
}
}
lda #$30
jmp $FCA8 ;common delay for all phases
jmpoep
!if enable_banked = 1 {
lda $C08B ;bank in our RAM, write-enabled
} else {
!if enable_banked = 2 {
lda $C083 ;bank in our RAM, write-enabled
}
}
jmp $1234 ;arbitrary entry-point to use after read completes
;set to the value that you need
adrtable
;15 slots for track 0 (track 0 sector 0 is not addressable)
;16 slots for all other tracks, fill with addresses, 0 to skip any sector
!byte $C0 ;end of list, can't load to stack
!byte $C0 ;end of list