mirror of https://github.com/peterferrie/0boot.git
v3 with multi-region support and DOS ordering
This commit is contained in:
parent
de713c17dd
commit
8f980ac031
151
0BOOT.S
151
0BOOT.S
|
@ -1,33 +1,43 @@
|
|||
;license:BSD-3-Clause
|
||||
;bootable zpage seek/read
|
||||
;copyright (c) Peter Ferrie 2015-16
|
||||
;copyright (c) Peter Ferrie 2015-16, 2018
|
||||
;thanks to 4am for inspiration and testing
|
||||
;assemble using ACME
|
||||
!cpu 6502
|
||||
!to "0boot",plain
|
||||
*=$800
|
||||
tracks = $d1 ;user-defined
|
||||
address = $d1 ;user-defined
|
||||
first_trk = $01 ;user-defined
|
||||
address = $d1 ;user-defined, high byte of first page
|
||||
entry = $d1d1 ;user-defined
|
||||
sectors = $00 ;user-defined, sectors to load from partial track (increase tracks first)
|
||||
version = 2
|
||||
sectors = $00 ;user-defined, sectors to load from partial track (increase tracks count first)
|
||||
interleave= 0 ;user-defined, to retain .dsk sector ordering
|
||||
multi_regn= 0 ;user-defined, load to non-sequential addresses
|
||||
!if multi_regn=1 {
|
||||
!macro region {region !byte $d1,0,$d1,0,$d1,0,$d1,0,$d1,0,$d1,0,$d1,0,$d1,0,$d1,0,$d1,0,$d1,0,$d1,0}
|
||||
;user-defined
|
||||
;assign every '$d1' from left
|
||||
;for track with alternative address
|
||||
;or zero to continue from last address
|
||||
;beginning with second track
|
||||
;array size = tracks*2
|
||||
}
|
||||
version = 3
|
||||
|
||||
;memory usage:
|
||||
;256 bytes ($200-2FF) static table
|
||||
grouped = $200
|
||||
;106 bytes ($300-369) static table
|
||||
preshift = $300
|
||||
;86 bytes ($36A-3BF) dynamic table (2-bit array)
|
||||
bit2tbl = $36a
|
||||
;106 bytes ($36C-3D5) static table
|
||||
preshift = $36C
|
||||
;86 bytes ($300-355) dynamic table (2-bit array)
|
||||
bit2tbl = $300
|
||||
|
||||
!byte 1 ;we'll read the other one ourselves
|
||||
lsr ;check sector number
|
||||
bne + ;branch if not 1
|
||||
inc $3d ;increment sector (faster to find)
|
||||
txa
|
||||
lsr
|
||||
lsr
|
||||
lsr
|
||||
lsr
|
||||
jsr $f87b
|
||||
ora #$c0 ;slot to PROM base
|
||||
pha
|
||||
lda #$5b ;read-1
|
||||
|
@ -54,39 +64,51 @@
|
|||
sta <(slotpatch6+1)
|
||||
ora #8 ;MOTOROFF
|
||||
sta <(slotpatch8+1)
|
||||
!if interleave=1 {
|
||||
ldx #$0f
|
||||
txs
|
||||
- lda sectbl, x
|
||||
pha
|
||||
dex
|
||||
bpl -
|
||||
}
|
||||
lda #>(entry-1)
|
||||
pha
|
||||
lda #<(entry-1)
|
||||
pha
|
||||
ldx #(stackend-addrtbl)
|
||||
- lda <(addrtbl-1), x
|
||||
pha ;copy stack frame
|
||||
dex
|
||||
bne -
|
||||
ldy #<(tracks*2)
|
||||
bne + ;branch always
|
||||
*=$839
|
||||
jsr preread
|
||||
lda #>(entry-1)
|
||||
pha
|
||||
lda #<(entry-1)
|
||||
pha
|
||||
ldx #<((tracks*16)+sectors)
|
||||
lda #address
|
||||
jmp $bf00 ;DOS 3.3 launcher entrypoint
|
||||
|
||||
;build read/seek call-sequence per track
|
||||
+
|
||||
!if sectors>0 {
|
||||
txa
|
||||
pha
|
||||
lda #<initsec
|
||||
pha
|
||||
txa
|
||||
clc
|
||||
bcc ++
|
||||
}
|
||||
|
||||
- txa
|
||||
bcc + ;set initially by LSR above
|
||||
!if multi_regn=1 {
|
||||
lda region-2, y
|
||||
beq no_region
|
||||
pha
|
||||
txa
|
||||
pha
|
||||
lda #<(set_address-1)
|
||||
pha
|
||||
txa
|
||||
|
||||
no_region
|
||||
}
|
||||
pha
|
||||
pha
|
||||
|
||||
!byte $c9 ;CMP masks SEC, clears carry on even rounds
|
||||
+ sec ;SEC is reached on odd rounds
|
||||
!if sectors>0 {
|
||||
|
@ -98,31 +120,28 @@
|
|||
dey
|
||||
bne -
|
||||
|
||||
!if first_trk>1 {
|
||||
ldy #((first_trk-1)*2)
|
||||
- txa
|
||||
pha
|
||||
lda #<(seek-1)
|
||||
pha ;push seek twice for two phases
|
||||
dey
|
||||
bne -
|
||||
}
|
||||
|
||||
;construct denibbilisation table
|
||||
;pre-shifted for interleave read
|
||||
|
||||
ldx #$40
|
||||
-- ldy <(tmpval+1)
|
||||
tya
|
||||
asl
|
||||
bit <(tmpval+1)
|
||||
beq +
|
||||
ora <(tmpval+1)
|
||||
eor #$ff
|
||||
and #$7e
|
||||
- bcs +
|
||||
lsr
|
||||
bne -
|
||||
ldx #$6a
|
||||
- asl preshift-1,x
|
||||
asl preshift-1,x
|
||||
dex
|
||||
txa
|
||||
asl
|
||||
asl
|
||||
sta preshift-$16, y
|
||||
+ dec <(tmpval+1)
|
||||
bne --
|
||||
bne -
|
||||
|
||||
;construct 2-bit group table
|
||||
|
||||
iny
|
||||
-- lsr <(curtrk+1)
|
||||
lsr <(curtrk+1)
|
||||
- lda <indextbl, x
|
||||
|
@ -148,8 +167,14 @@
|
|||
preread ;must exit with carry set!
|
||||
rts
|
||||
|
||||
*=$8fe
|
||||
!byte $be, 1
|
||||
!if interleave=1 {
|
||||
sectbl !byte 0,7,$e,6,$d,5,$c,4,$b,3,$a,2,9,1,8,$f
|
||||
}
|
||||
!if multi_regn=1 {
|
||||
+region
|
||||
}
|
||||
|
||||
*=$900
|
||||
|
||||
;the following lives on sector $0E
|
||||
!pseudopc 0 {
|
||||
|
@ -174,7 +199,6 @@ rdpage
|
|||
inc <(rdpage+1)
|
||||
inx
|
||||
bne rdpage
|
||||
|
||||
read
|
||||
-- jsr readnib
|
||||
- cmp #$d5
|
||||
|
@ -197,8 +221,11 @@ read
|
|||
and <(sector+1)
|
||||
dey
|
||||
bpl -
|
||||
sta <(sector+1) ;store index for later
|
||||
tay
|
||||
!if interleave=1 {
|
||||
tax
|
||||
ldy $100, x
|
||||
}
|
||||
sty <(sector+1) ;store index for later
|
||||
ldx <addrtbl, y ;fetch corresponding address
|
||||
stx <(adrpatch6+2)
|
||||
dex
|
||||
|
@ -218,7 +245,7 @@ slotpatch1
|
|||
lda preshift-$96, x
|
||||
sta bit2tbl-$aa, y ;store 2-bit array
|
||||
tmpval
|
||||
eor #$7f ;constant used in table init, self-mod later
|
||||
eor #0
|
||||
iny
|
||||
bne --
|
||||
ldy #$aa
|
||||
|
@ -289,21 +316,26 @@ setdelay
|
|||
lda #$d1
|
||||
jmp wait
|
||||
|
||||
driveoff
|
||||
;place post-read routine here
|
||||
|
||||
slotpatch8
|
||||
lda $c0d1
|
||||
|
||||
;fall through
|
||||
|
||||
readnib
|
||||
slotpatch7
|
||||
- lda $c0d1
|
||||
bpl -
|
||||
rts
|
||||
|
||||
driveoff
|
||||
slotpatch8
|
||||
lda $c0d1
|
||||
|
||||
;place post-read routine here
|
||||
;must end before $ed
|
||||
|
||||
seekret ;shhhh
|
||||
jmp entry
|
||||
!if multi_regn=1 {
|
||||
set_address
|
||||
pla
|
||||
sta rdpage+1
|
||||
rts
|
||||
}
|
||||
|
||||
addrtbl
|
||||
!word $fe89-1, $fe93-1, driveoff-1
|
||||
|
@ -312,4 +344,7 @@ patchtbl
|
|||
!byte <(slotpatch1+1), <(slotpatch2+1), <(slotpatch3+1), <(slotpatch4+1), <(slotpatch5+1), <(slotpatch7+1)
|
||||
indextbl ;the 0 also terminates the patchtbl list!
|
||||
!byte 0, 2, 1, 3
|
||||
!if (addrtbl+$10)>$ff {
|
||||
!serious "code is too large, ends at *"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,315 @@
|
|||
;bootable zpage seek/read
|
||||
;copyright (c) Peter Ferrie 2015-16
|
||||
;thanks to 4am for inspiration and testing
|
||||
;assemble using ACME
|
||||
!cpu 6502
|
||||
!to "0boot",plain
|
||||
*=$800
|
||||
tracks = $d1 ;user-defined
|
||||
address = $d1 ;user-defined
|
||||
entry = $d1d1 ;user-defined
|
||||
sectors = $00 ;user-defined, sectors to load from partial track (increase tracks first)
|
||||
version = 2
|
||||
|
||||
;memory usage:
|
||||
;256 bytes ($200-2FF) static table
|
||||
grouped = $200
|
||||
;106 bytes ($300-369) static table
|
||||
preshift = $300
|
||||
;86 bytes ($36A-3BF) dynamic table (2-bit array)
|
||||
bit2tbl = $36a
|
||||
|
||||
!byte 1 ;we'll read the other one ourselves
|
||||
lsr ;check sector number
|
||||
bne + ;branch if not 1
|
||||
inc $3d ;increment sector (faster to find)
|
||||
txa
|
||||
lsr
|
||||
lsr
|
||||
lsr
|
||||
lsr
|
||||
ora #$c0 ;slot to PROM base
|
||||
pha
|
||||
lda #$5b ;read-1
|
||||
pha
|
||||
rts
|
||||
|
||||
;the following TAY is a workaround for a CFFA bug
|
||||
;the bug is that Y isn't zero on entry
|
||||
;the workaround sets it to one instead
|
||||
;it's not zero, but it's better than #$10
|
||||
|
||||
+ tay
|
||||
txa
|
||||
ora #$8c ;slot to Q6L
|
||||
- ldx $900, y
|
||||
stx $0, y ;copy RTS to zpage
|
||||
iny
|
||||
bne -
|
||||
- iny
|
||||
ldx <(patchtbl-1), y
|
||||
sta $0, x ;replace placeholders with Q6L
|
||||
bne -
|
||||
and #$f0 ;PHASEOFF
|
||||
sta <(slotpatch6+1)
|
||||
ora #8 ;MOTOROFF
|
||||
sta <(slotpatch8+1)
|
||||
ldx #(stackend-addrtbl)
|
||||
- lda <(addrtbl-1), x
|
||||
pha ;copy stack frame
|
||||
dex
|
||||
bne -
|
||||
ldy #<(tracks*2)
|
||||
bne + ;branch always
|
||||
*=$839
|
||||
jsr preread
|
||||
lda #>(entry-1)
|
||||
pha
|
||||
lda #<(entry-1)
|
||||
pha
|
||||
ldx #<((tracks*16)+sectors)
|
||||
lda #address
|
||||
jmp $bf00 ;DOS 3.3 launcher entrypoint
|
||||
|
||||
;build read/seek call-sequence per track
|
||||
+
|
||||
!if sectors>0 {
|
||||
txa
|
||||
pha
|
||||
lda #<initsec
|
||||
pha
|
||||
txa
|
||||
clc
|
||||
bcc ++
|
||||
}
|
||||
|
||||
- txa
|
||||
bcc + ;set initially by LSR above
|
||||
pha
|
||||
pha
|
||||
!byte $c9 ;CMP masks SEC, clears carry on even rounds
|
||||
+ sec ;SEC is reached on odd rounds
|
||||
!if sectors>0 {
|
||||
++
|
||||
}
|
||||
pha
|
||||
lda #<(seek-1)
|
||||
pha ;push seek twice for two phases
|
||||
dey
|
||||
bne -
|
||||
|
||||
;construct denibbilisation table
|
||||
;pre-shifted for interleave read
|
||||
|
||||
ldx #$40
|
||||
-- ldy <(tmpval+1)
|
||||
tya
|
||||
asl
|
||||
bit <(tmpval+1)
|
||||
beq +
|
||||
ora <(tmpval+1)
|
||||
eor #$ff
|
||||
and #$7e
|
||||
- bcs +
|
||||
lsr
|
||||
bne -
|
||||
dex
|
||||
txa
|
||||
asl
|
||||
asl
|
||||
sta preshift-$16, y
|
||||
+ dec <(tmpval+1)
|
||||
bne --
|
||||
|
||||
;construct 2-bit group table
|
||||
|
||||
-- lsr <(curtrk+1)
|
||||
lsr <(curtrk+1)
|
||||
- lda <indextbl, x
|
||||
sta grouped-1, y
|
||||
inc <(sector+1)
|
||||
lda <(sector+1)
|
||||
and <(curtrk+1)
|
||||
bne +
|
||||
inx
|
||||
txa
|
||||
and #3
|
||||
tax
|
||||
+ iny
|
||||
iny
|
||||
iny
|
||||
iny
|
||||
cpy #4
|
||||
bcs -
|
||||
iny
|
||||
cpy #4
|
||||
bcc --
|
||||
|
||||
preread ;must exit with carry set!
|
||||
rts
|
||||
|
||||
*=$8fe
|
||||
!byte $be, 1
|
||||
|
||||
;the following lives on sector $0E
|
||||
!pseudopc 0 {
|
||||
wait = $fca8
|
||||
|
||||
count
|
||||
!byte version ;not copied!
|
||||
|
||||
;fill address array for one track
|
||||
|
||||
inittrk
|
||||
ldx #$f0
|
||||
initsec
|
||||
!if sectors>0 {
|
||||
!byte $2c
|
||||
ldx #<(-sectors)
|
||||
}
|
||||
stx <count
|
||||
rdpage
|
||||
lda #address
|
||||
sta <(addrtbl-$f0), x
|
||||
inc <(rdpage+1)
|
||||
inx
|
||||
bne rdpage
|
||||
|
||||
read
|
||||
-- jsr readnib
|
||||
- cmp #$d5
|
||||
bne --
|
||||
jsr readnib
|
||||
cmp #$aa
|
||||
bne -
|
||||
tay ;we need Y=#$AA later
|
||||
jsr readnib
|
||||
eor #$ad ;zero A if match
|
||||
beq check_mode
|
||||
|
||||
;if not #$AD, then #$96 is assumed
|
||||
|
||||
ldy #2 ;volume, track, sector
|
||||
- jsr readnib
|
||||
rol ;set carry
|
||||
sta <(sector+1)
|
||||
jsr readnib
|
||||
and <(sector+1)
|
||||
dey
|
||||
bpl -
|
||||
sta <(sector+1) ;store index for later
|
||||
tay
|
||||
ldx <addrtbl, y ;fetch corresponding address
|
||||
stx <(adrpatch6+2)
|
||||
dex
|
||||
stx <(adrpatch3+2)
|
||||
stx <(adrpatch5+2)
|
||||
inx ;restore value in case it was zero
|
||||
branch_read
|
||||
bcs read ;branch always
|
||||
check_mode
|
||||
cpx #0
|
||||
beq read ;loop if not expecting #$AD
|
||||
|
||||
-- sta <(tmpval+1) ;zero rolling checksum
|
||||
slotpatch1
|
||||
- ldx $c0d1
|
||||
bpl -
|
||||
lda preshift-$96, x
|
||||
sta bit2tbl-$aa, y ;store 2-bit array
|
||||
tmpval
|
||||
eor #$7f ;constant used in table init, self-mod later
|
||||
iny
|
||||
bne --
|
||||
ldy #$aa
|
||||
slotpatch2
|
||||
- ldx $c0d1
|
||||
bpl -
|
||||
eor preshift-$96, x
|
||||
ldx bit2tbl-$aa, y
|
||||
eor grouped+2, x ;first 86 nibbles use group bits 0-1
|
||||
adrpatch3
|
||||
sta $d156, y
|
||||
iny
|
||||
bne -
|
||||
and #$fc
|
||||
ldy #$aa
|
||||
slotpatch3
|
||||
- ldx $c0d1
|
||||
bpl -
|
||||
eor preshift-$96, x
|
||||
ldx bit2tbl-$aa, y
|
||||
eor grouped+1, x ;second 86 nibbles use group bits 2-3
|
||||
adrpatch5
|
||||
sta $d1ac, y
|
||||
iny
|
||||
bne -
|
||||
and #$fc
|
||||
ldx #$ac
|
||||
slotpatch4
|
||||
- ldy $c0d1
|
||||
bpl -
|
||||
eor preshift-$96, y
|
||||
ldy bit2tbl-$ac, x
|
||||
eor grouped, y ;last 84 nibbles use group bits 4-5
|
||||
adrpatch6
|
||||
sta $d100, x
|
||||
inx
|
||||
bne -
|
||||
and #$fc
|
||||
slotpatch5
|
||||
- ldy $c0d1
|
||||
bpl -
|
||||
eor preshift-$96, y
|
||||
bne branch_read ;branch if checksum failure
|
||||
sector
|
||||
ldy #0 ;constant used in table init, self-mod later
|
||||
stx addrtbl, y ;zero corresponding address
|
||||
inc <count ;adjust remaining count (faster than looping over array)
|
||||
bne branch_read ;read all requested sectors in one track
|
||||
rts
|
||||
|
||||
seek ;requires carry set on entry
|
||||
inc <(curtrk+1) ;phase on
|
||||
curtrk
|
||||
ldy #$3f ;constant used in table init, self-mod later
|
||||
lda #4
|
||||
jsr delay
|
||||
dey ;phase off
|
||||
adc #$41 ;clear carry while setting #$42
|
||||
delay
|
||||
sta <(setdelay+1)
|
||||
tya
|
||||
and #3
|
||||
rol
|
||||
tax
|
||||
slotpatch6
|
||||
lda $c0d1, x
|
||||
setdelay
|
||||
lda #$d1
|
||||
jmp wait
|
||||
|
||||
readnib
|
||||
slotpatch7
|
||||
- lda $c0d1
|
||||
bpl -
|
||||
rts
|
||||
|
||||
driveoff
|
||||
slotpatch8
|
||||
lda $c0d1
|
||||
|
||||
;place post-read routine here
|
||||
;must end before $ed
|
||||
|
||||
seekret ;shhhh
|
||||
jmp entry
|
||||
|
||||
addrtbl
|
||||
!word $fe89-1, $fe93-1, driveoff-1
|
||||
stackend
|
||||
patchtbl
|
||||
!byte <(slotpatch1+1), <(slotpatch2+1), <(slotpatch3+1), <(slotpatch4+1), <(slotpatch5+1), <(slotpatch7+1)
|
||||
indextbl ;the 0 also terminates the patchtbl list!
|
||||
!byte 0, 2, 1, 3
|
||||
}
|
|
@ -1,10 +1,12 @@
|
|||
fast bootable Read Track/Sector routine.
|
||||
- targets single-loaders in ProDOS order
|
||||
- targets single-loaders in either ProDOS or DOS (v3 only) order
|
||||
- load from any slot
|
||||
- scatter-reads sectors
|
||||
- full-track read in one revolution
|
||||
- can read tracks to non-sequential addresses (v3 only)
|
||||
- runs entirely from zpage
|
||||
- can load up to 11 complete tracks
|
||||
- can load up to 12 additional sectors ($0400-bfff)
|
||||
- DOS 3.3 Launcher compatible
|
||||
- DOS 3.3 Launcher compatible (v2 only)
|
||||
- supports pre- and post-read routines
|
||||
- requires only 3 pages in memory
|
||||
|
|
Loading…
Reference in New Issue