A2osX/LIB/LIBBLKDEV.S.BB.txt

584 lines
13 KiB
Plaintext
Raw Normal View History

2020-05-08 19:02:27 +00:00
NEW
AUTO 3,1
.LIST OFF
*--------------------------------------
2020-05-12 15:17:25 +00:00
dcmd .EQ $42 disk command (=1 for read)
unit .EQ $43 (16*slot)+(128*(drive-1))
buff .EQ $44 ram address
blok .EQ $46 disk address
dent .EQ $48 device call entry address
idxl .EQ $4a pointer to low page of index block
idxh .EQ $4c pointer to high page of index block
idxp .EQ $4e index byte pointer
2020-05-13 17:00:37 +00:00
2020-05-12 15:17:25 +00:00
iobuff .EQ $60
* the following are for disk ii only
dbuf .EQ $26
2020-06-13 19:27:06 +00:00
BB.Slotn0 .EQ $2b
2020-05-12 15:17:25 +00:00
oddbits .EQ $3c
sector .EQ $3d
2020-05-13 17:00:37 +00:00
BB.RetryCnt .EQ $40
2020-05-12 15:17:25 +00:00
BB.TargetTrk .EQ $41
2020-06-07 08:06:51 +00:00
BB.CurrentQTrack .EQ $50
BB.TargetQTrack .EQ $51
2020-05-13 17:00:37 +00:00
BB.HdrPtr .EQ $52
2020-05-12 15:17:25 +00:00
BB.Hdr .EQ $54
BB.HdrTrk .EQ $55
BB.HdrVol .EQ $56
BB.Hdr96 .EQ $57
nbuf1 .EQ $300
dnib .EQ $2d6
clrscrn .EQ $fc58
scrn .EQ $5b6
sosid .EQ $c00
entlen .EQ sosid+$23
kernel .EQ $2000
2020-05-08 19:02:27 +00:00
*--------------------------------------
.PH $800
xboot .DA #1
2020-05-13 17:00:37 +00:00
sec apple iii enters xboot 'ora $38'
2020-06-07 08:06:51 +00:00
* bcs BB.AppleII branch if not apple iii native mode
bcc *
2020-05-12 15:17:25 +00:00
*--------------------------------------
2020-06-07 08:06:51 +00:00
*BB.AppleIII lda #$9f make apple iii boot using block 1
2020-05-28 21:13:52 +00:00
* pha the return address is $a000
* lda #$ff
* pha
* inc
* tax ldx #0
2020-05-13 17:00:37 +00:00
2020-05-28 21:13:52 +00:00
* inc lda #1 (read block 1)
2020-05-13 17:00:37 +00:00
2020-05-28 21:13:52 +00:00
* jmp $f479
2020-05-12 15:17:25 +00:00
*--------------------------------------
2020-05-13 17:00:37 +00:00
BB.AppleII stx unit save unit number
2020-05-12 15:17:25 +00:00
cmp #$03 for disk ii
php save result, it may be irrelevant
txa find out if disk ii
and #$70 strip drive # if any
lsr
lsr get slot address
lsr
2020-05-08 19:02:27 +00:00
lsr
ora #$c0
2020-05-12 15:17:25 +00:00
sta dent+1
ldy #$ff look at last byte
2020-05-08 19:02:27 +00:00
sty dent
2020-05-12 15:17:25 +00:00
plp restore carry (if disk ii & sect 0&2 read)
2020-05-08 19:02:27 +00:00
2020-05-12 15:17:25 +00:00
iny make y=0
lda (dent),y get device entry addr
bne ndsk2 branch if not disk ii (16 sector)
bcs isdsk2 branch if it is disk ii, but block 0 read
lda #3 make rom read only sector 2
sta xboot to complete block 0
2020-05-08 19:02:27 +00:00
inc sector was = 1
2020-05-13 17:00:37 +00:00
2020-05-12 15:17:25 +00:00
lda dent+1 do rts to re-enter rom
pha
2020-05-08 19:02:27 +00:00
lda #$5b
pha
rts go read sector 2 into $900
*--------------------------------------
2020-05-12 15:17:25 +00:00
isdsk2 sta BB.HdrTrk A=0, make sure previous track =0
2020-05-08 19:02:27 +00:00
sta dent and dent points at beginning of slot
2020-05-12 15:17:25 +00:00
2020-05-08 19:02:27 +00:00
ldy #$63 move code from card to ram
mvboot lda (dent),y
sta zzstart-$5e,y
iny
cpy #$eb have we moved enough?
bne mvboot
2020-06-11 21:04:56 +00:00
ldx #mods.cnt now modify code to handle errors.
2020-05-08 19:02:27 +00:00
2020-06-11 21:04:56 +00:00
modboot ldy mods-1,x
lda chgs-1,x
sta zzstart,y
2020-05-12 15:17:25 +00:00
2020-06-11 21:04:56 +00:00
cpx #8
bcs .1
2020-05-12 15:17:25 +00:00
2020-06-13 19:27:06 +00:00
lda endcode-1,x
sta zzzend-1,x
2020-06-11 21:04:56 +00:00
.1 dex
bne modboot
2020-05-12 15:17:25 +00:00
lda #BB.Hdr
sta BB.HdrPtr
2020-05-13 17:00:37 +00:00
stx BB.HdrPtr+1 X=0
2020-05-08 19:02:27 +00:00
2020-06-13 19:27:06 +00:00
lda /BB.ReadBlock reset device entry
2020-05-08 19:02:27 +00:00
sta dent+1 to point at disk ii routines.
2020-06-13 19:27:06 +00:00
lda #BB.ReadBlock get low addr (must be <$80)
2020-05-13 17:00:37 +00:00
*--------------------------------------
2020-05-08 19:02:27 +00:00
ndsk2 ldy #0 make sure y=0 again.
cmp #$f9
bcs bterr1 branch if not bootable device.
sta dent save low adr of device call entry.
sty iobuff
sty idxl
sty idxh y=0
sty idxp
sty blok+1
iny
2020-05-12 15:17:25 +00:00
sty dcmd set read command.
2020-05-08 19:02:27 +00:00
iny
sty blok to read directory blocks
lda #$c 2-5 at $c00
sta iobuff+1
sta idxl+1
rddir jsr goread call read block routine.
bcs bterr2 give up on error.
inc iobuff+1
inc iobuff+1
inc blok
lda blok have all directory blocks been read?
cmp #6
bcc rddir loop if not.
lda sosid is it a prodos (sos) directory?
ora sosid+1
bterr1 bne booterr branch if not.
2020-06-07 08:06:51 +00:00
*--------------------------------------
2020-05-08 19:02:27 +00:00
lda #4 begin look-up with first entry past header.
2020-06-07 08:06:51 +00:00
* bne nxdent1 branch always
.HS 2C BIT ABS
2020-05-08 19:02:27 +00:00
nxdent lda idxl
2020-06-07 08:06:51 +00:00
2020-05-08 19:02:27 +00:00
nxdent1 clc
adc entlen bump to next directory entry.
tay save in y for now.
bcc nxdent2 branch if not a page cross.
inc idxl+1
lda idxl+1 check for new block.
lsr if even then new block.
bcs nxdent2
cmp #$a have all file names been compared?
2020-05-12 15:17:25 +00:00
beq booterr branch if no pro.kernel.
2020-05-08 19:02:27 +00:00
ldy #4 else, begin at block beginning.
2020-06-07 08:06:51 +00:00
nxdent2 sty idxl
2020-05-13 17:00:37 +00:00
2020-06-13 19:27:06 +00:00
ldy #6
2020-05-08 19:02:27 +00:00
lookpro lda (idxl),y look for matching name.
2020-05-13 17:00:37 +00:00
cmp BB.ProDOS,y
2020-05-08 19:02:27 +00:00
bne nxdent branch if no match.
2020-06-13 19:27:06 +00:00
dey
bpl lookpro
2020-05-08 19:02:27 +00:00
2020-06-13 19:27:06 +00:00
* ldy #$10 get file type & index block addr.
2020-06-07 08:06:51 +00:00
* lda (idxl),y
* cmp #S.FI.T.SYS is it a system file?
* bne booterr
2020-06-13 19:27:06 +00:00
* iny
ldy #$11
2020-05-08 19:02:27 +00:00
lda (idxl),y
sta blok
iny
lda (idxl),y
sta blok+1
2020-05-12 15:17:25 +00:00
2020-05-08 19:02:27 +00:00
lda #0 now set up to read kernel.
sta idxl
2020-05-12 15:17:25 +00:00
2020-05-08 19:02:27 +00:00
ldy #$1e read index block at $1e00 and
sty idxl+1 kernel at $2000
sty iobuff+1
iny
sty idxh+1
rdkernl jsr goread read index block.
bterr2 bcs booterr
inc iobuff+1
inc iobuff+1
2020-05-12 15:17:25 +00:00
2020-05-08 19:02:27 +00:00
ldy idxp get index pointer
inc idxp bump for next time.
lda (idxl),y
sta blok
lda (idxh),y high disk addr.
sta blok+1
ora (idxl),y if both=0 then done.
bne rdkernl branch if more to read.
jmp kernel go execute kernel code.
2020-05-12 15:17:25 +00:00
*--------------------------------------
2020-06-07 08:06:51 +00:00
booterr
* jsr clrscrn clear video
2020-05-28 21:13:52 +00:00
* ldy #BB.MSG.ERR.Len-1
2020-05-08 19:02:27 +00:00
2020-05-28 21:13:52 +00:00
*.1 lda BB.MSG.ERR,y
* sta scrn,y
* dey
* bpl .1
2020-05-12 15:17:25 +00:00
2020-05-14 11:47:46 +00:00
jmp $ff69
2020-05-12 15:17:25 +00:00
*--------------------------------------
2020-05-08 19:02:27 +00:00
goread lda iobuff
sta buff
lda iobuff+1
sta buff+1
jmp (dent)
*--------------------------------------
2020-05-12 15:17:25 +00:00
mods .DA #mod1,#mod2,#mod3,#mod4,#mod5,#mod6,#mod7,#mod8,#mod8+1,#mod9
2020-05-13 17:00:37 +00:00
mods.cnt .EQ *-mods
2020-05-12 15:17:25 +00:00
chgs .DA #chg1,#chg2,#chg3,#chg4,#chg5,#chg6,#chg7,#$91,#BB.HdrPtr,#BB.HdrTrk
2020-06-13 19:27:06 +00:00
endcode ldx BB.Slotn0
2020-05-08 19:02:27 +00:00
clc
rts
2020-06-07 08:06:51 +00:00
jmp BB.Seek
2020-05-08 19:02:27 +00:00
*--------------------------------------
2020-05-28 21:13:52 +00:00
*BB.MSG.ERR .AS -"ERR"
*BB.MSG.ERR.Len .EQ *-BB.MSG.ERR
2020-05-13 17:00:37 +00:00
BB.ProDOS .DA #$26 $20 = storage type + 6 = "PRODOS" len
.AS "PRODOS"
2020-05-08 19:02:27 +00:00
*--------------------------------------
2020-06-13 19:27:06 +00:00
BB.ReadBlock lda blok figure out track & sector.
2020-05-08 19:02:27 +00:00
and #7 strip track for now.
cmp #4
and #3
php
asl
plp
rol now we have the first sector of block.
sta sector
2020-05-12 15:17:25 +00:00
2020-05-08 19:02:27 +00:00
lda blok+1 get high block #
lsr shift hi addr to carry.
lda blok now figure track #
ror
lsr
lsr
2020-05-12 15:17:25 +00:00
sta BB.TargetTrk
2020-05-08 19:02:27 +00:00
lda buff+1
2020-05-12 15:17:25 +00:00
sta dbuf+1
2020-06-13 19:27:06 +00:00
ldx BB.Slotn0
2020-05-12 15:17:25 +00:00
lda IO.D2.DrvOn,x
2020-06-13 19:27:06 +00:00
lda IO.D2.Ph0Off,x
2020-05-12 15:17:25 +00:00
2020-06-07 08:06:51 +00:00
jsr BB.Seek go read sector.
2020-05-12 15:17:25 +00:00
2020-05-08 19:02:27 +00:00
inc dbuf+1 bump address
inc sector
inc sector and sector #
2020-06-13 19:27:06 +00:00
bcs .9 branch if error.
2020-05-12 15:17:25 +00:00
2020-06-07 08:06:51 +00:00
jsr BB.Seek
2020-05-08 19:02:27 +00:00
2020-06-13 19:27:06 +00:00
.9 ldy IO.D2.DrvOff,x
2020-05-28 21:13:52 +00:00
rts return error status in carry.
2020-05-12 15:17:25 +00:00
*--------------------------------------
2020-06-07 08:06:51 +00:00
BB.Seek lda BB.HdrTrk get track we're on
2020-05-12 15:17:25 +00:00
jsr BB.Trk2Qtrk
2020-06-07 08:06:51 +00:00
sta BB.CurrentQTrack
2020-05-08 19:02:27 +00:00
2020-06-07 08:06:51 +00:00
lda BB.TargetTrk
jsr BB.Trk2Qtrk
sta BB.TargetQTrack
2020-05-12 15:17:25 +00:00
2020-06-07 08:06:51 +00:00
ldy #0
2020-05-12 15:17:25 +00:00
2020-06-07 08:06:51 +00:00
.1 lda BB.TargetQTrack
sec
sbc BB.CurrentQTrack
2020-05-28 21:13:52 +00:00
beq .8
2020-05-12 15:17:25 +00:00
2020-06-07 08:06:51 +00:00
bcc .2
* Current < Target, must move in
cmp #2
bcc .6 one QT remaining
lda BB.CurrentQTrack
and #$FE from QT1 or QT3
inc
inc
bra .4
* Current > Target, must move out
2020-05-12 15:17:25 +00:00
2020-06-07 08:06:51 +00:00
.2 cmp #$FF
2020-06-17 19:05:36 +00:00
bcs .60 one QT remaining
2020-05-28 21:13:52 +00:00
2020-06-07 08:06:51 +00:00
lda BB.CurrentQTrack
2020-06-17 19:05:36 +00:00
and #$FE from QT1 or QT3
2020-05-28 21:13:52 +00:00
2020-06-07 08:06:51 +00:00
dec
2020-06-17 19:05:36 +00:00
dec
2020-05-23 18:45:32 +00:00
2020-06-07 08:06:51 +00:00
.4 sta BB.CurrentQTrack
and #6
2020-06-13 19:27:06 +00:00
ora BB.Slotn0
2020-06-07 08:06:51 +00:00
tax
pha
tya
beq .5
2020-05-28 21:13:52 +00:00
2020-06-07 08:06:51 +00:00
lda IO.D2.Ph0Off,y
2020-05-12 15:17:25 +00:00
2020-06-07 08:06:51 +00:00
.5 lda IO.D2.Ph0On,x
ply
2020-06-13 19:27:06 +00:00
jsr BB.WaitPh
2020-06-07 08:06:51 +00:00
bra .1
2020-05-28 21:13:52 +00:00
2020-06-07 08:06:51 +00:00
* Last QTrack
2020-05-28 21:13:52 +00:00
2020-06-17 19:05:36 +00:00
.6 tya
2020-06-07 08:06:51 +00:00
inc
inc
2020-06-17 19:05:36 +00:00
and #$f6
tax
lda IO.D2.Ph0On,x
2020-06-11 21:04:56 +00:00
bra .7
.60 tya
2020-06-17 19:05:36 +00:00
tax
2020-06-11 21:04:56 +00:00
* sec
adc #5
2020-06-17 19:05:36 +00:00
and #$f6
tay
lda IO.D2.Ph0On,y
2020-06-11 21:04:56 +00:00
2020-06-17 19:05:36 +00:00
.7 phx
2020-06-13 19:27:06 +00:00
jsr BB.WaitPh
2020-05-23 18:45:32 +00:00
2020-06-13 19:27:06 +00:00
.80 jsr BB.Wait25600usec
2020-05-23 18:45:32 +00:00
2020-06-11 21:04:56 +00:00
plx
2020-06-13 19:27:06 +00:00
lda IO.D2.Ph0Off,y
2020-06-17 19:05:36 +00:00
lda IO.D2.Ph0Off,x
2020-06-07 08:06:51 +00:00
bra BB.Read
2020-05-19 13:00:17 +00:00
2020-06-07 08:06:51 +00:00
.8 tya
beq BB.Read
2020-05-12 15:17:25 +00:00
2020-06-13 19:27:06 +00:00
pha
2020-06-11 21:04:56 +00:00
bra .80
2020-05-12 15:17:25 +00:00
*--------------------------------------
2020-06-17 19:05:36 +00:00
BB.WaitPh lda #IO.D2.SeekTime
2020-06-13 19:27:06 +00:00
.HS 2C BIT ABS
2020-06-07 08:06:51 +00:00
BB.Wait25600usec
lda #0
2020-06-13 19:27:06 +00:00
sec (6) JSR (2)
2020-05-12 15:17:25 +00:00
2020-06-11 21:04:56 +00:00
.1 ldx #19 (2)
2020-05-08 19:02:27 +00:00
2020-05-13 17:00:37 +00:00
.2 dex (2) delay 86 usec.
bne .2 (2+) 2 + 5x16 + 2 + 2
2020-05-08 19:02:27 +00:00
2020-06-17 19:05:36 +00:00
* ldx BB.Slotn0 (3)
* bit IO.D2.DrvOn,x (4) Slow down ACC boards
2020-06-07 08:06:51 +00:00
sbc #1 (2)
bne .1 (2+)
2020-05-08 19:02:27 +00:00
2020-06-05 19:26:34 +00:00
rts (6)
2020-05-12 15:17:25 +00:00
*--------------------------------------
BB.Trk2Qtrk asl x2
sta .1+1
bit BB.HdrVol
2020-05-23 18:45:32 +00:00
bpl .1 x4
2020-05-12 15:17:25 +00:00
lsr x3
.1 adc #$ff SELF MODIFIED
2020-05-28 21:13:52 +00:00
BB.Trk2Qtrk.RTS rts
2020-05-12 15:17:25 +00:00
*--------------------------------------
2020-06-13 19:27:06 +00:00
BB.Read ldx BB.Slotn0
2020-05-08 19:02:27 +00:00
2020-05-12 15:17:25 +00:00
ldy #$7f allow 127 mistakes.
2020-05-13 17:00:37 +00:00
sty BB.RetryCnt
2020-05-08 19:02:27 +00:00
php
tryread plp fix stack.
rdhead sec anticipate error.
2020-05-13 17:00:37 +00:00
dec BB.RetryCnt if = 0 then give up!
2020-05-28 21:13:52 +00:00
beq BB.Trk2Qtrk.RTS branch if can't fine/read sector.
2020-06-13 19:27:06 +00:00
2020-05-08 19:02:27 +00:00
clc indicate reading header.
rddata php carry set if reading sector.
rd0 dey every time y=0 decrement find count.
beq tryread
2020-05-12 15:17:25 +00:00
*--------------------------------------
2020-05-08 19:02:27 +00:00
* from zzstart to zzend code is moved from rom and modified to match this code...
2020-05-12 15:17:25 +00:00
*--------------------------------------
zzstart .EQ *
2020-05-08 19:02:27 +00:00
2020-05-12 15:17:25 +00:00
rd1 lda IO.D2.RData,x read a byte from the state machine.
bpl rd1 loop until ready.
.DUMMY
2020-05-08 19:02:27 +00:00
rd1a eor #$d5 mark 1?
mod1 .EQ *-zzstart+1
bne rd0 branch if not.
chg1 .EQ rd0-*
2020-05-12 15:17:25 +00:00
rd2 lda IO.D2.RData,x
2020-05-08 19:02:27 +00:00
bpl rd2
cmp #$aa mark 2?
bne rd1a
nop waste a little time.
2020-05-12 15:17:25 +00:00
rd3 lda IO.D2.RData,x
2020-05-08 19:02:27 +00:00
bpl rd3
cmp #$96 header mark 3?
beq rdhd1 branch if it is.
plp were we looking for data mark 3?
mod2 .EQ *-zzstart+1
bcc rdhead branch if not.
chg2 .EQ rdhead-*
eor #$ad data mark 3?
beq rddt1 go read data field if true...
mod3 .EQ *-zzstart+1
rdhd0 bne rdhead otherwise, start over.
2020-05-12 15:17:25 +00:00
chg3 .EQ rdhead-*
2020-05-08 19:02:27 +00:00
rdhd1 ldy #3 read in trk,sect,&volume #.
2020-05-12 15:17:25 +00:00
mod8 .EQ *-zzstart
rdhd2 sta (BB.HdrPtr),y save last result in .. , BB.HdrTrk , BB.HdrVol , ..
2020-06-13 19:27:06 +00:00
rdhd3 lda IO.D2.RData,x
2020-05-08 19:02:27 +00:00
bpl rdhd3
rol
sta oddbits save odd bits (7,5,3,1)
2020-06-13 19:27:06 +00:00
rdhd4 lda IO.D2.RData,x
2020-05-08 19:02:27 +00:00
bpl rdhd4
and oddbits combine even and odd to form value.
dey
bne rdhd2 read in next pair.
plp
cmp sector last byte formed is sector#
mod4 .EQ *-zzstart+1
bne rdhead branch if target sector not found.
chg4 .EQ rdhead-*
2020-05-12 15:17:25 +00:00
mod9 .EQ *-zzstart+1
lda BB.HdrTrk previous result is track #
cmp BB.TargetTrk is desired track found?
2020-05-08 19:02:27 +00:00
mod5 .EQ *-zzstart+1
bne goseek re-seek if mismatch.
2020-05-12 15:17:25 +00:00
2020-05-08 19:02:27 +00:00
chg5a .EQ *
mod6 .EQ *-zzstart+1
bcs rddata branch if proper track always.
chg6 .EQ rddata-*
2020-05-12 15:17:25 +00:00
*--------------------------------------
2020-05-08 19:02:27 +00:00
rddt1 ldy #$56 read 2 bit groupings first.
rddt1a sty oddbits
2020-05-12 15:17:25 +00:00
rddt2 ldy IO.D2.RData,x
2020-05-08 19:02:27 +00:00
bpl rddt2
eor dnib,y denibblize using table left from boot rom.
ldy oddbits save in nbuf1
dey
sta nbuf1,y
bne rddt1a loop until all 86 groups are read.
rddt3 sty oddbits now count up for 6-bit groups.
2020-05-12 15:17:25 +00:00
rddt4 ldy IO.D2.RData,x
2020-05-08 19:02:27 +00:00
bpl rddt4
eor dnib,y
ldy oddbits save result to specified buffer.
sta (dbuf),y
iny
bne rddt3 loop for 256 bytes.
2020-05-12 15:17:25 +00:00
rdchk ldy IO.D2.RData,x now verify checksum...
2020-05-08 19:02:27 +00:00
bpl rdchk
eor dnib,y must be equal...
mod7 .EQ *-zzstart+1
bne rdhd0 branch if error.
chg7 .EQ rdhd0-*
ldy #0 make y=0
nxttwo ldx #$56 now combine 2-bit group with 6 bit group
twobit dex all done with this group?
bmi nxttwo branch if so.
2020-05-12 15:17:25 +00:00
lda (dbuf),y
2020-05-08 19:02:27 +00:00
lsr nbuf1,x
rol
lsr nbuf1,x
rol
2020-05-12 15:17:25 +00:00
sta (dbuf),y
2020-05-08 19:02:27 +00:00
iny
bne twobit
2020-05-12 15:17:25 +00:00
*--------------------------------------
2020-06-13 19:27:06 +00:00
zzzend ldx BB.Slotn0
2020-05-08 19:02:27 +00:00
clc indicate good read.
rts
2020-05-12 15:17:25 +00:00
chg5 .EQ *-chg5a
2020-06-07 08:06:51 +00:00
goseek jmp BB.Seek
2020-05-12 15:17:25 +00:00
.ED
*--------------------------------------
.LIST ON
BB.End .EQ *
BB.Free .EQ $a00-*
.BS BB.Free
.LIST OFF
2020-05-08 19:02:27 +00:00
.EP
*--------------------------------------
MAN
2020-05-26 14:23:09 +00:00
SAVE usr/src/lib/libblkdev.s.bb
LOAD usr/src/lib/libblkdev.s
2020-05-08 19:02:27 +00:00
ASM