allow LC residency, direct aux loading, second drive, smaller code

This commit is contained in:
Peter Ferrie 2016-06-15 07:23:43 -07:00
parent 470f30b6ef
commit 912f6446d4
1 changed files with 210 additions and 156 deletions

366
PRORWTS.S
View File

@ -9,9 +9,11 @@
enable_write = 0 ;set to 1 to enable write support enable_write = 0 ;set to 1 to enable write support
;file must exist already and its size cannot be altered ;file must exist already and its size cannot be altered
;writes occur in multiples of block size (256 bytes for floppy, 512 bytes for HDD) ;writes occur in multiples of block size (256 bytes for floppy, 512 bytes for HDD)
allow_multi = 1 ;set to 1 to allow multiple floppies
allow_subdir = 0 ;set to 1 to allow opening subdirectories to access files allow_subdir = 0 ;set to 1 to allow opening subdirectories to access files
might_exist = 0 ;set to 1 if file is not known to always exist already might_exist = 0 ;set to 1 if file is not known to always exist already
;makes use of status to indicate success or failure ;makes use of status to indicate success or failure
allow_aux = 0 ;set to 1 to allow read/write directly to/from aux memory
load_high = 0 ;load into banked RAM instead of main RAM load_high = 0 ;load into banked RAM instead of main RAM
lc_bank = 1 ;load into specified bank (1 or 2) if load_high=1 lc_bank = 1 ;load into specified bank (1 or 2) if load_high=1
@ -43,14 +45,15 @@
secsize2 = $48 secsize2 = $48
!if might_exist=1 { !if might_exist=1 {
status = $f4 ;returns non-zero on error status = $f3 ;returns non-zero on error
}
!if allow_aux=1 {
auxreq = $f4 ;set to 1 to read/write aux memory, else main memory is used
} }
sizelo = $f5 ;must set if writing sizelo = $f5 ;must set if writing
sizehi = $f6 ;must set if writing sizehi = $f6 ;must set if writing
!if might_exist=1 {
entries = $f7 ;total number of entries entries = $f7 ;total number of entries
} reqcmd = $f8 ;used if enable_write=1, 1=read, 2=write; if allow_multi=1, bit 7 selects drive
reqcmd = $f8 ;used if enable_write=1, 1=read, 2=write
ldrlo = $f9 ;used if override_adr=1 ldrlo = $f9 ;used if override_adr=1
ldrhi = $fa ;used if override_adr=1 ldrhi = $fa ;used if override_adr=1
namlo = $fb namlo = $fb
@ -103,22 +106,25 @@ init jsr $fe93
tax tax
inx inx
stx unrdrvon+1 stx unrdrvon+1
eor #4 inx
sta unrread1+1 !if allow_multi=1 {
sta unrread2+1 stx unrdrvsel+1
sta unrread3+1 } ;allow_multi
inx
inx
stx unrread1+1
stx unrread2+1
stx unrread3+1
!if enable_write=1 { !if enable_write=1 {
sta unrread4+1 stx unrread4+1
sta unrread5+1 stx unrread5+1
sta unrread6+1 stx unrread6+1
sta unrread7+1 stx unrread7+1
sta unrread8+1 stx unrread8+1
tax
inx inx
stx unrlatch1+1 stx unrlatch1+1
stx unrlatch2+1 stx unrlatch2+1
stx unrlatch3+1 stx unrlatch3+1
stx unrlatch4+1
inx inx
stx unrlatchin+1 stx unrlatchin+1
inx inx
@ -273,7 +279,7 @@ minus03 lda (A1L), y
bne minus03 bne minus03
plp plp
bne plus07 bne plus07
ldx #3 ldx #$16
minus04 stx A1L minus04 stx A1L
txa txa
asl asl
@ -286,7 +292,7 @@ minus05 bcs plus06
lsr lsr
bne minus05 bne minus05
tya tya
sta nibtbl, x sta nibtbl-$16, x
!if enable_write=1 { !if enable_write=1 {
txa txa
ora #$80 ora #$80
@ -299,6 +305,15 @@ plus07 rts
} else { ;enable_floppy } else { ;enable_floppy
slot lda $cfff slot lda $cfff
sta unrentry+1 sta unrentry+1
!if load_high=1 {
!if lc_bank=1 {
lda $c089
lda $c089
} else { ;lc_bank
lda $c081
lda $c081
} ;lc_bank
} ;load_high
ldy #0 ldy #0
- lda unrelochdd, y - lda unrelochdd, y
sta reloc, y sta reloc, y
@ -329,6 +344,16 @@ opendir ;read volume directory key block
} ;enable_write } ;enable_write
stx adrlo stx adrlo
stx secsize1 stx secsize1
!if allow_multi=1 {
asl reqcmd
bcc seldrive
inx
seldrive lsr reqcmd
unrdrvsel=unrelocdsk+(*-reloc)
lda $c0ea, x
} ;allow_multi
unrblocklo=unrelocdsk+(*-reloc) unrblocklo=unrelocdsk+(*-reloc)
lda #2 lda #2
unrblockhi=unrelocdsk+(*-reloc) unrblockhi=unrelocdsk+(*-reloc)
@ -514,7 +539,6 @@ plus15
} ;override_adr } ;override_adr
;cache KEY_POINTER (loaded backwards) ;cache KEY_POINTER (loaded backwards)
;and construct single-entry index block in case of seedling
ldy #$12 ldy #$12
lda (A1L), y lda (A1L), y
@ -524,9 +548,7 @@ plus15
lda (A1L), y lda (A1L), y
sta dirbuf sta dirbuf
ldy #0 ldy #0
sty dirbuf+257 sty entries
sty dirbuf+1
sty namlo
;read index block in case of sapling ;read index block in case of sapling
@ -578,6 +600,12 @@ plus17
sta adrlo sta adrlo
stx adrhi stx adrhi
!if allow_aux=1 {
ldx auxreq
sta $c002, x
sta $c004, x
}
;set read size to min(length, $200) ;set read size to min(length, $200)
readfile lda sizelo readfile lda sizelo
@ -591,8 +619,8 @@ plus18 sta secsize1
;fetch data block and read it ;fetch data block and read it
ldy namlo ldy entries
inc namlo inc entries
lda dirbuf, y lda dirbuf, y
ldx dirbuf+256, y ldx dirbuf+256, y
jsr seekread jsr seekread
@ -619,6 +647,91 @@ plus18 sta secsize1
unrdrvoff=unrelocdsk+(*-reloc) unrdrvoff=unrelocdsk+(*-reloc)
readdone lda $c0e8 readdone lda $c0e8
!if allow_aux=1 {
sta $c002
sta $c004
}
seekret rts
;no tricks here, just the regular stuff
seek sty step
asl phase
txa
asl
copy_cur tax
sta tmptrk
sec
sbc phase
beq seekret
bcs plus20
eor #$ff
inx
bcc plus21
plus20 sbc #1
dex
plus21 cmp step
bcc plus22
lda step
plus22 cmp #8
bcs plus23
tay
sec
plus23 txa
pha
ldx step1, y
bne plus24
minus24 clc
lda tmptrk
ldx step2, y
plus24 stx tmpsec
and #3
rol
tax
unrseek=unrelocdsk+(*-reloc)
sta $c0e0, x
minus25 ldx #$13
minus26 dex
bne minus26
dec tmpsec
bne minus25
lsr
bcs minus24
pla
inc step
bne copy_cur
step1 !byte 1, $30, $28, $24, $20, $1e, $1d, $1c
step2 !byte $70, $2c, $26, $22, $1f, $1e, $1d, $1c
readadr
minus19 jsr readd5aa
cmp #$96
bne minus19
ldy #3
minus20 sta curtrk
jsr readnib
rol
sta tmpsec
jsr readnib
and tmpsec
dey
bne minus20
rts
readd5aa
minus21 jsr readnib
minus22 cmp #$d5
bne minus21
jsr readnib
cmp #$aa
bne minus22
tay ;we need Y=#$AA later
readnib
unrread3=unrelocdsk+(*-reloc)
minus23 lda $c0ec
bpl minus23
rts rts
readdirsec readdirsec
@ -707,14 +820,14 @@ readdata jsr readd5aa
unrread1=unrelocdsk+(*-reloc) unrread1=unrelocdsk+(*-reloc)
minus07 ldx $c0ec minus07 ldx $c0ec
bpl minus07 bpl minus07
eor nibtbl-$80, x eor nibtbl-$96, x
sta bit2tbl-$aa, y sta bit2tbl-$aa, y
iny iny
bne minus07 bne minus07
unrread2=unrelocdsk+(*-reloc) unrread2=unrelocdsk+(*-reloc)
minus08 ldx $c0ec minus08 ldx $c0ec
bpl minus08 bpl minus08
eor nibtbl-$80, x eor nibtbl-$96, x
sta (adrlo), y ;the real address sta (adrlo), y ;the real address
iny iny
cpy secsize cpy secsize
@ -755,63 +868,67 @@ minus12 dey
cmpsecwr jsr readadr cmpsecwr jsr readadr
cmp reqsec cmp reqsec
bne cmpsecwr bne cmpsecwr
ldy #(epilog_e-epilog)
minus13 jsr readnib ;skip tail #$DE #$AA #$EB some #$FFs ...
cmp epilog-1, y
bne minus13 ldy #$24
dey minus13 dey
bne minus13 bpl minus13
;write sector data ;write sector data
unrlatch1=unrelocdsk+(*-reloc) tya
lda $c0ed ldx #$56
lda #$ff
unrlatchout=unrelocdsk+(*-reloc) unrlatchout=unrelocdsk+(*-reloc)
sta $c0ef sta $c0ef
unrread4=unrelocdsk+(*-reloc) unrread4=unrelocdsk+(*-reloc)
ora $c0ec ora $c0ec
nop ;2 cycles
lsr phase ;7 cycles
ldy #4 ldy #4
cmp $ea ;3 cycles
cmp ($ea,x) ;6 cycles
minus14 jsr writenib1 minus14 jsr writenib1
dey dey
bne minus14 bne minus14
cmp $ea ;3 cycles
ldy #(prolog_e-prolog) ldy #(prolog_e-prolog)
cmp $ea ;3 cycles
minus15 lda prolog-1, y minus15 lda prolog-1, y
jsr writenib3 jsr writenib3
dey dey
bne minus15 bne minus15
tya tya
ldy #$56 !byte $c5 ;(1 cycle), turns into cmp $ea and 3 cycles
minus16 eor bit2tbl-1, y minus16 nop ;2 cycles
tax cmp $ea ;3 cycles
lda xlattbl, x eor bit2tbl-1, x
unrlatch2=unrelocdsk+(*-reloc) tay
lda xlattbl, y
unrlatch1=unrelocdsk+(*-reloc)
sta $c0ed sta $c0ed
unrread5=unrelocdsk+(*-reloc) unrread5=unrelocdsk+(*-reloc)
lda $c0ec lda $c0ec
lsr phase ;7 cycles lda bit2tbl-1, x
lda bit2tbl-1, y dex
dey
bne minus16 bne minus16
minus17 lsr phase ;7 cycles !byte $c5 ;(1 cycle), turns into cmp $ea and 3 cycles
eor encbuf, y minus17 nop ;2 cycles
tax cmp $ea ;3 cycles
lda xlattbl, x eor encbuf, x
unrlatch3=unrelocdsk+(*-reloc) tay
lda xlattbl, y
unrlatch2=unrelocdsk+(*-reloc)
sta $c0ed sta $c0ed
unrread6=unrelocdsk+(*-reloc) unrread6=unrelocdsk+(*-reloc)
lda $c0ec lda $c0ec
lda encbuf, y lda encbuf, x
iny inx
bne minus17 bne minus17
tax tax
lda xlattbl, x lda xlattbl, x
jsr writenib2 nop ;2 cycles
cmp $ea ;3 cycles nop ;2 cycles
jsr writenib4
ldy #(epilog_e-epilog) ldy #(epilog_e-epilog)
cmp $ea ;3 cycles
minus18 lda epilog-1, y minus18 lda epilog-1, y
jsr writenib3 jsr writenib3
dey dey
@ -822,13 +939,11 @@ unrread7=unrelocdsk+(*-reloc)
lda $c0ec lda $c0ec
rts rts
writenib1 lsr phase ;7 cycles writenib1 cmp ($ea,x) ;6 cycles
cmp $ea ;3 cycles writenib2 cmp ($ea,x) ;6 cycles
!byte $c9 ;2 cycles writenib3 cmp $ea ;3 cycles
writenib2 !byte $c9 ;2 cycles writenib4
writenib3 cmp $ea ;3 cycles unrlatch3=unrelocdsk+(*-reloc)
unrlatch4=unrelocdsk+(*-reloc)
sta $c0ed sta $c0ed
unrread8=unrelocdsk+(*-reloc) unrread8=unrelocdsk+(*-reloc)
ora $c0ec ora $c0ec
@ -838,100 +953,21 @@ prolog_e
epilog !byte $ff, $eb, $aa, $de epilog !byte $ff, $eb, $aa, $de
epilog_e epilog_e
} ;enable_write } ;enable_write
;no tricks here, just the regular stuff
readadr
minus19 jsr readd5aa
cmp #$96
bne minus19
ldy #3
minus20 sta curtrk
jsr readnib
rol
sta tmpsec
jsr readnib
and tmpsec
dey
bne minus20
rts
readd5aa
minus21 jsr readnib
minus22 cmp #$d5
bne minus21
jsr readnib
cmp #$aa
bne minus22
tay ;we need Y=#$AA later
readnib
unrread3=unrelocdsk+(*-reloc)
minus23 lda $c0ec
bpl minus23
seekret rts
seek sty step
asl phase
txa
asl
copy_cur tax
sta tmptrk
sec
sbc phase
beq seekret
bcs plus20
eor #$ff
inx
bcc plus21
plus20 sbc #1
dex
plus21 cmp step
bcc plus22
lda step
plus22 cmp #8
bcs plus23
tay
sec
plus23 txa
pha
ldx step1, y
bne plus24
minus24 clc
lda tmptrk
ldx step2, y
plus24 stx tmpsec
and #3
rol
tax
unrseek=unrelocdsk+(*-reloc)
sta $c0e0, x
minus25 ldx #$13
minus26 dex
bne minus26
dec tmpsec
bne minus25
lsr
bcs minus24
pla
inc step
bne copy_cur
step1 !byte 1, $30, $28, $24, $20, $1e, $1d, $1c
step2 !byte $70, $2c, $26, $22, $1f, $1e, $1d, $1c
nibtbl = *
bit2tbl = nibtbl+128
!if enable_write=1 { !if enable_write=1 {
xlattbl = bit2tbl+86 !align 255,0
} ;enable_write
bit2tbl = *
nibtbl = bit2tbl+86
!if enable_write=1 {
xlattbl = nibtbl+106
dataend = xlattbl+64 dataend = xlattbl+64
} else { ;enable_write } else { ;enable_write
dataend = bit2tbl+86 dataend = nibtbl+106
} ;enable_write } ;enable_write
;hack to error out when code is too large for current address ;hack to error out when code is too large for current address
!if reloc<$c000 { !if reloc<$c000 {
!if dataend>$c000 { !if dataend>$c000 {
1=* !serious "code is too large"
} }
} }
} ;enable_floppy } ;enable_floppy
@ -1145,7 +1181,6 @@ plus34
} ;override_adr } ;override_adr
;cache KEY_POINTER (loaded backwards) ;cache KEY_POINTER (loaded backwards)
;and construct single-entry index block in case of seedling
ldy #$12 ldy #$12
lda (A1L), y lda (A1L), y
@ -1155,9 +1190,7 @@ plus34
lda (A1L), y lda (A1L), y
sta dirbuf sta dirbuf
ldy #0 ldy #0
sty dirbuf+257 sty entries
sty dirbuf+1
sty namlo
;read index block in case of sapling ;read index block in case of sapling
@ -1204,6 +1237,12 @@ plus36
sta adrlo sta adrlo
stx adrhi stx adrhi
!if allow_aux=1 {
ldx auxreq
sta $c002, x
sta $c004, x
} ;allow_aux
;set read size to min(length, $200) ;set read size to min(length, $200)
hddreadfile hddreadfile
@ -1229,8 +1268,8 @@ plus37 php
;fetch data block and read it ;fetch data block and read it
ldy namlo ldy entries
inc namlo inc entries
lda dirbuf, y lda dirbuf, y
ldx dirbuf+256, y ldx dirbuf+256, y
jsr hddseekread jsr hddseekread
@ -1244,6 +1283,11 @@ plus37 php
bcc plus38 bcc plus38
lda sizelo lda sizelo
bne hddreadfile bne hddreadfile
!if allow_aux=1 {
hddreaddone
sta $c002
sta $c004
} ;allow_aux
rts rts
plus38 pla plus38 pla
@ -1260,15 +1304,25 @@ minus28 lda (adrlo), y
sta (A1L), y sta (A1L), y
iny iny
bne minus28 bne minus28
inc adrhi
inc A1H inc A1H
plus39 inc adrhi
plus39 lda sizelo
!if allow_aux=1 {
beq hddreaddone
} else {
beq plus40
} ;allow_aux
minus29 lda (adrlo), y minus29 lda (adrlo), y
sta (A1L), y sta (A1L), y
iny iny
cpy sizelo cpy sizelo
bne minus29 bne minus29
!if allow_aux=1 {
beq hddreaddone
} else {
plus40
rts rts
} ;allow_aux
hddreaddirsec ldy #1 hddreaddirsec ldy #1
sty command sty command