A2osX/LIB/LIBBLKDEV.S.D2.txt
2021-02-22 18:17:37 +01:00

565 lines
8.1 KiB
Plaintext
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

NEW
AUTO 3,1
*/--------------------------------------
*\--------------------------------------
D2MotorControl >PULLB MotorOn
>PULLB DrvSlt
jsr CheckDiskII
bcs .9
lda MotorOn
asl
lda #IO.D2.DrvOff
adc Slotn0
tax
lda $C000,x
clc
.9 rts
*/--------------------------------------
*\--------------------------------------
D2Recalibrate >PULLB DrvSlt
jsr CheckDiskII
bcs .9
lda #168
ldy Slotn0
lda IO.D2.Ph0On,y
lda #IO.D2.SeekTimeR
jsr D2.Wait100usecA
.1 dec
dec
pha
and #6
ora Slotn0
phy
plx
tay
lda IO.D2.Ph0On,y
lda #IO.D2.SeekTimeR
jsr D2.Wait100usecA
lda IO.D2.Ph0Off,x
lda #IO.D2.SeekTimeR
jsr D2.Wait100usecA
pla
bne .1
jsr D2.Wait25600usec
lda IO.D2.Ph0Off,y
clc
.9 rts
*/--------------------------------------
*\--------------------------------------
D2MoveHead >PULLB MoveTo
>PULLB MoveFrom
>PULLB DrvSlt
jsr CheckDiskII
bcs .9
php
sei
jsr D2MoveHead.SEI
plp
clc
.9 rts
D2MoveHead.SEI lda MoveFrom
tay
and #6
ora Slotn0
tax
tya
inc
bra .3
.1 pha
jsr .8
bcs .2
* Current < Target, must move in
inc
.HS B0 BCS
* Current > Target, must move out
.2 dec
sta MoveFrom
and #6
ora Slotn0
tax
pla
bcs .3
* Current < Target, must move in
inc
inc
.3 and #6
ora Slotn0
tay
* lda Slotn0
* ora #IO.D2.RData
* sta .4+1
* sta .5+1
sta IO.D2.Ph0On,x
*.4 lda IO.D2.RData SELF MODIFIED
sta IO.D2.Ph0On,y
*.5 lda IO.D2.RData SELF MODIFIED
lda #IO.D2.SeekTimeF
jsr D2.Wait100usecA
lda MoveFrom
cmp MoveTo
bne .1
jsr D2.Wait25600usec
.8 sta IO.D2.Ph0Off,x
nop
nop
sta IO.D2.Ph0Off,y
rts
*/--------------------------------------
* # D2TrkRead16s
* Write a track (16 sectors)
* PUSHB = DSSS0000
* PUSHB = TrackNum * 4 : 0->136+
* PUSHW = Ptr to 16*256 buffer
* ## RETURN VALUE
* CC : success, A = VolNum
* CS : A = Error
*\--------------------------------------
D2TrkRead16s >PULLW ZPPtr1
>PULLB TrkNum
>PULLB DrvSlt
jsr CheckDiskII
bcs .9
lda VolNum
clc
.9
D2TrkRead16s.RTS
rts
*/--------------------------------------
* # D2TrkWrite16s
* Write a track (16 sectors)
* PUSHB = DSSS0000
* PUSHB = TrackNum * 4 : 0->136+
* PUSHW = Ptr to 16*256 buffer
* ## RETURN VALUE
* CC : success
* CS : A = Error
*\--------------------------------------
D2TrkWrite16s >PULLW ZPPtr1
>PULLB TrkNum
>PULLB VolNum
>PULLB DrvSlt
jsr CheckDiskII
bcs D2TrkRead16s.RTS
>LDYAI TRACK16.LEN+256+1
>SYSCALL2 GetMem
bcs D2TrkRead16s.RTS
>STYA ZPPtr2
stx hTrkBuf
lda TrkNum
jsr D2.Trk2Qtrk
tay
and #6
ora Slotn0
tax
tya
inc
and #6
ora Slotn0
tay
sta IO.D2.Ph0On,x
stx PhX
sta IO.D2.Ph0On,y
sty PhY
* lda #5
* jsr D2.Wait100usecA
* ldx PhX
* sta IO.D2.Ph0Off,x
* ldy PhY
* sta IO.D2.Ph0Off,y
stz SectNum
ldy #0 put 256 FF sync bytes for slooooow drives
jsr PutSyncBytePtr2
ldy #TRACK16.GAP1
jsr PutSyncBytePtr2
.1 jsr PutAddrHeadPtr2
jsr HeaderCheckSum
ldy #3
.2 lda Checksum,y
jsr PutByte44Ptr2
dey
bpl .2
jsr PutTailPtr2
ldy #TRACK16.GAP2
jsr PutSyncBytePtr2
jsr PutDataHeadPtr2
jsr PutData
jsr PutTailPtr2
ldy #TRACK16.GAP3
jsr PutSyncBytePtr2
inc ZPPtr1+1
inc SectNum
lda SectNum
cmp #16
bne .1
lda #0
sta (ZPPtr2)
ldx PhX
sta IO.D2.Ph0Off,x
ldy PhY
sta IO.D2.Ph0Off,y
* jsr D2.Wait25600usec
jsr D2WriteTrackPtr2
php
pha
lda hTrkBuf
>SYSCALL2 FreeMem
pla
plp
rts
*/--------------------------------------
*\--------------------------------------
D2TrkReadNIB
*/--------------------------------------
* # D2TrkWriteNIB
* Write a track (NIBBLE)
* **In:**
* PUSHB = DSSS0000
* PUSHW = Ptr to NIBBLE buffer (0 ended)
* ## RETURN VALUE
* CC : success
* CS : A = Error
* A=0, currently starting/seeking...
*\--------------------------------------
D2TrkWriteNIB >PULLW ZPPtr1
>PULLB DrvSlt
jsr CheckDiskII was it a DISK II ?
bcs .9
.9 rts
*--------------------------------------
* A=DSSS0000
*--------------------------------------
CheckDiskII pha
and #$70 only 0SSS
sta Slotn0
lsr
lsr
lsr
lsr
ora #$C0 make Cn
sta ZPPtr3+1
stz ZPPtr3
ldx #3 4 bytes to check
.1 ldy DiskII.OFS,x
.2 lda (ZPPtr3),y
cmp DiskII.SIG,x
bne .9
dex
bpl .1
pla all bytes match, Disk II
asl
lda #0
adc #IO.D2.DrvSel1
adc Slotn0
tax
lda $C000,x
ldx Slotn0
lda IO.D2.ReadMode,x
lda IO.D2.RData,x
clc
rts
.9 pla
lda #MLI.E.NODEV
sec
rts
*--------------------------------------
* A=DSSS0000
*--------------------------------------
DrvSpinCheck ldy #0
lda IO.D2.RData,x
.1 pha
pla
cmp IO.D2.RData,x
bne .8 spinning
dey
bne .1
clc CC:not spinning
rts
.8 sec
rts
*--------------------------------------
D2.Trk2Qtrk asl x2
sta .1+1
bit VolNum
bpl .1 x4
bvs .1 > $C0 ? (VOL=254)
lsr x3
.1 adc #$ff SELF MODIFIED
rts
*--------------------------------------
D2.Wait25600usec
lda #0
D2.Wait100usecA phx
.1 ldx #20 (2)
.2 dex (2)
bne .2 (3)
dec (2)
bne .1 (3)
plx
rts (6)
*--------------------------------------
PutSyncBytePtr2 lda #$7f
.1 jsr PutBytePtr2
dey
bne .1
rts
*--------------------------------------
PutAddrHeadPtr2 ldy #2
.1 lda ADDR.Head,y
jsr PutBytePtr2
dey
bpl .1
rts
*--------------------------------------
PutDataHeadPtr2 ldy #2
.1 lda DATA.Head,y
jsr PutBytePtr2
dey
bpl .1
rts
*--------------------------------------
PutTailPtr2 ldy #2
.1 lda TAIL,y
jsr PutBytePtr2
dey
bpl .1
rts
*--------------------------------------
HeaderCheckSum lda VolNum
eor TrkNum
eor SectNum
sta Checksum
rts
*--------------------------------------
PutData stz Checksum
lda ZPPtr1
ldy ZPPtr1+1
clc
adc #86
bcc .1
iny
clc
.1 sta ZPPtr3
sty ZPPtr3+1
adc #86
bcc .2
iny
.2 sta ZPPtr4
sty ZPPtr4+1
ldy #85
.3 lda (ZPPtr1),y
and #3
tax
lda D2.XX000000,x
pha
lda (ZPPtr3),y
and #3
tax
pla
ora D2.00XX0000,x
pha
lda (ZPPtr4),y
and #3
tax
pla
ora D2.0000XX00,x
tax
eor Checksum
sta Checksum
lda FC2Nib,x
jsr PutBytePtr2
dey
bpl .3
ldy #0
.4 lda (ZPPtr1),y
and #$FC
tax
eor Checksum
sta Checksum
lda FC2Nib,x
jsr PutBytePtr2
iny
bne .4
ldx Checksum
lda FC2Nib,x
jsr PutBytePtr2
rts
*--------------------------------------
PutByte44Ptr2 pha
ror
jsr .1
pla
.1 ora #$AA
*--------------------------------------
PutBytePtr2 sta (ZPPtr2)
inc ZPPtr2
bne .8
inc ZPPtr2+1
.8 rts
*--------------------------------------
D2WriteTrackPtr2
lda hTrkBuf
>SYSCALL2 GetMemPtr
>STYA ZPPtr1
php
sei
ldy #TrkWriter.Size
.1 lda TrkWriter-1,y
sta $1ff,y
dey
bne .1
ldx Slotn0
jsr $200
bcs .9
plp
clc
rts
.9 plp
sec
rts
*--------------------------------------
MAN
SAVE usr/src/lib/libblkdev.s.d2
LOAD usr/src/lib/libblkdev.s
ASM