comparison level1/modules/ddisk.asm @ 1729:7bdc60c48533

Additional Dragon changes from Phill Harvey-Smith
author boisy
date Wed, 17 Nov 2004 01:24:21 +0000 (2004-11-17)
parents 78ce0a5ffc8e
children b992196e2ac9
comparison
equal deleted inserted replaced
1728:843c3687eabd 1729:7bdc60c48533
24 * Drive Selects, motor and write precompensation is controled 24 * Drive Selects, motor and write precompensation is controled
25 * through the IO port of an AY-8912, which itself is connected 25 * through the IO port of an AY-8912, which itself is connected
26 * to a 3rd PIA mapped at FF24 to FF27, this PIA also has it's 26 * to a 3rd PIA mapped at FF24 to FF27, this PIA also has it's
27 * inturrupt lines connected to the CPU's FIRQ. 27 * inturrupt lines connected to the CPU's FIRQ.
28 * 28 *
29 * 2004-11-15, P.Harvey-Smith.
30 * Fixed bug in inturrupt handling code that was making the
31 * Dragon Alpha crash if a disk was accessed with no disk
32 * in the drive. As the Alpha is using a simulated NMI disable
33 * we have to ensure that the NMI enabling routine has completed
34 * BEFORE isuing a command to the disk controler, or if the
35 * inturrupt happens in the middle of the enable routine it
36 * causes the machine to crash !
37 *
29 nam DDisk 38 nam DDisk
30 ttl Dragon Floppy driver 39 ttl Dragon Floppy driver
31 40
32 * Disassembled 02/04/21 22:37:46 by Disasm v1.6 (C) 1988 by RML 41 * Disassembled 02/04/21 22:37:46 by Disasm v1.6 (C) 1988 by RML
33 42
34 ifp1 43 ifp1
35 use defsfile 44 use defsfile.dragon
36 endc 45 endc
37 46
38 IFNE DragonAlpha 47 IFNE DragonAlpha
39 48
40 * Dragon Alpha has a third PIA at FF24, this is used for 49 * Dragon Alpha has a third PIA at FF24, this is used for
60 CMDREG EQU DPCMDREG+IO ; command/status 69 CMDREG EQU DPCMDREG+IO ; command/status
61 TRKREG EQU DPTRKREG+IO ; Track register 70 TRKREG EQU DPTRKREG+IO ; Track register
62 SECREG EQU DPSECREG+IO ; Sector register 71 SECREG EQU DPSECREG+IO ; Sector register
63 DATAREG EQU DPDATAREG+IO ; Data register 72 DATAREG EQU DPDATAREG+IO ; Data register
64 73
74 ; Disk IO bitmasks
75
76 NMIEn EQU NMIEnA
77 WPCEn EQU WPCEnA
78 SDensEn EQU SDensEnA
79 MotorOn EQU MotorOnA
80
65 ELSE 81 ELSE
66 82
67 DPPIADA EQU DPPIA1DA 83 DPPIADA EQU DPPIA1DA
68 DPPIACRA EQU DPPIA1CRA 84 DPPIACRA EQU DPPIA1CRA
69 DPPIADB EQU DPPIA1DB 85 DPPIADB EQU DPPIA1DB
83 CMDREG EQU DPCMDREG+IO ; command/status 99 CMDREG EQU DPCMDREG+IO ; command/status
84 TRKREG EQU DPTRKREG+IO ; Track register 100 TRKREG EQU DPTRKREG+IO ; Track register
85 SECREG EQU DPSECREG+IO ; Sector register 101 SECREG EQU DPSECREG+IO ; Sector register
86 DATAREG EQU DPDATAREG+IO ; Data register 102 DATAREG EQU DPDATAREG+IO ; Data register
87 103
104 ; Disk IO bitmasks
105
106 NMIEn EQU NMIEnD
107 WPCEn EQU WPCEnD
108 SDensEn EQU SDensEnD
109 MotorOn EQU MotorOnD
110
88 ENDC 111 ENDC
89
90 ; DskCmd Masks
91 NMIEn EQU %00100000
92 WPCEn EQU %00010000
93 MotorOn EQU %00000100
94 SDensEn EQU %00001000
95 112
96 * Disk Commands 113 * Disk Commands
97 FrcInt EQU %11010000 114 FrcInt EQU %11010000
98 ReadCmnd EQU %10001000 115 ReadCmnd EQU %10001000
99 RestCmnd EQU %00000000 116 RestCmnd EQU %00000000
148 lbra GetStat ; Get status 165 lbra GetStat ; Get status
149 lbra SetStat ; Set status 166 lbra SetStat ; Set status
150 lbra Term ; Terminate device 167 lbra Term ; Terminate device
151 168
152 169
170 IRQPkt fcb $00 Normal bits (flip byte)
171 fcb $01 Bit 1 is interrupt request flag (Mask byte)
172 fcb 10 Priority byte
173
174 IRQFlag FCB 0
175
153 * Init 176 * Init
154 * 177 *
155 * Entry: 178 * Entry:
156 * Y = address of device descriptor 179 * Y = address of device descriptor
157 * U = address of device memory area 180 * U = address of device memory area
193 leax >NMIService,pcr ; Setup NMI handler 216 leax >NMIService,pcr ; Setup NMI handler
194 stx >D.XNMI+1 217 stx >D.XNMI+1
195 lda #$7E ; $7E = JMP 218 lda #$7E ; $7E = JMP
196 sta >D.XSWI 219 sta >D.XSWI
197 220
221 pshs y
222 leax IRQPkt,PC ; point at IRQ definition packet
223 leay IRQFlag,pcr
224 tfr y,d
225 leay IRQHandler,pcr
226 os9 F$IRQ
227 puls y
228
229
198 ldd #$0100 ; Request a page of system ram 230 ldd #$0100 ; Request a page of system ram
199 pshs u ; used to verify writes 231 pshs u ; used to verify writes
200 os9 F$SRqMem 232 os9 F$SRqMem
201 tfr u,x 233 tfr u,x
202 puls u 234 puls u
203 bcs Return 235 bcs Return
204 stx >BuffPtr,u ; Save verify page pointer 236 stx >BuffPtr,u ; Save verify page pointer
205 clrb 237 clrb
206 Return rts 238 Return rts
207 239
240 IRQHandler
241 inc $8000
242 rts
243
208 * GetStat 244 * GetStat
209 * 245 *
210 * Entry: 246 * Entry:
211 * A = function code 247 * A = function code
212 * Y = address of path descriptor 248 * Y = address of path descriptor
240 * 276 *
241 * Exit: 277 * Exit:
242 * CC = carry set on error 278 * CC = carry set on error
243 * B = error code 279 * B = error code
244 * 280 *
245 Read lda #$91 ; Retry count 281 Read
282 pshs a,x
283 lda <PD.Drv,y
284 cmpa #1
285 bne readxxx
286 ldx #$55aa
287
288 readxxx
289 puls a,x
290
291 lda #$91 ; Retry count
246 cmpx #$0000 ; LSN ? 292 cmpx #$0000 ; LSN ?
247 bne L0096 ; No : Just do read, 293 bne L0096 ; No : Just do read,
248 bsr L0096 ; Yes : do read and copy disk params 294 bsr L0096 ; Yes : do read and copy disk params
249 bcs L008C 295 bcs L008C
250 ldx PD.Buf,y 296 ldx PD.Buf,y
326 sta <DPPIACRB 372 sta <DPPIACRB
327 lda <DPPIADB ; Clear any outstanding inturrupt 373 lda <DPPIADB ; Clear any outstanding inturrupt
328 ldy #$FFFF 374 ldy #$FFFF
329 lda #NMIEn+MotorOn ; Enable NMI, and turn motor on 375 lda #NMIEn+MotorOn ; Enable NMI, and turn motor on
330 ora >DrivSel,u ; mask in drives 376 ora >DrivSel,u ; mask in drives
331 ORB >SideSel,U * Set up Side 377 ORB >SideSel,U ; Set up Side
332 stb <DPCmdReg ; issue command to controler
333 378
334 IFNE DragonAlpha ; Turn on drives & NMI 379 IFNE DragonAlpha ; Turn on drives & NMI
335 lbsr AlphaDskCtl 380 lbsr AlphaDskCtl
336 ELSE 381 ELSE
337 sta >DskCtl 382 sta >DskCtl
338 ENDC 383 ENDC
384
385 stb <DPCmdReg ; issue command to controler
339 386
340 rts 387 rts
341 388
342 389
343 * Restore saved iO states of peripherals. 390 * Restore saved iO states of peripherals.
486 533
487 TFR X,D 534 TFR X,D
488 LDX >CDrvTab,U 535 LDX >CDrvTab,U
489 CMPD #0 ; Skip calculation of track 0 536 CMPD #0 ; Skip calculation of track 0
490 BEQ SeekT1 537 BEQ SeekT1
491 CMPD 1,X ; Has an illegal LSN been 538 CMPD DD.TOT+1,X ; Has an illegal LSN been
492 BLO SeekT2 539 BLO SeekT2
493 E.Sect COMB 540 E.Sect COMB
494 LDB #E$Sect 541 LDB #E$Sect
495 RTS 542 RTS
496 543
541 SeekT8 PULS B ; Count from 0 for other types 588 SeekT8 PULS B ; Count from 0 for other types
542 589
543 SeekT11 STB >SecReg ; Write sector number to controler 590 SeekT11 STB >SecReg ; Write sector number to controler
544 LBSR Delay 591 LBSR Delay
545 CMPB >SecReg 592 CMPB >SecReg
546 BNE SeekT11 593 BNE SeekT11
547 594
548 SeekTS LDB <V.Trak,X ; Entry point for SS.WTrk command 595 SeekTS LDB <V.Trak,X ; Entry point for SS.WTrk command
549 STB >TrkReg 596 STB >TrkReg
550 TST >Settle,U ; If settle has been flagged then wait for settle 597 TST >Settle,U ; If settle has been flagged then wait for settle
551 BNE SeekT5 598 BNE SeekT5
552 CMPA <V.Trak,X ; otherwise check if this is 599 CMPA <V.Trak,X ; otherwise check if this is
653 ldb >CmdReg ; Poll until not busy 700 ldb >CmdReg ; Poll until not busy
654 bitb #$01 701 bitb #$01
655 beq Delay3 702 beq Delay3
656 lda #$F0 703 lda #$F0
657 sta >D.DskTmr ;>$006F 704 sta >D.DskTmr ;>$006F
658 bra FDCCmdWait 705 lda #$1
706 sta IRQFlag
707 bra FDCCmdWait
659 708
660 FDCCmdMotorOn 709 FDCCmdMotorOn
661 lda #MotorOn ; Turn on motor 710 lda #MotorOn ; Turn on motor
662 ora >DrivSel,u 711 ora >DrivSel,u
663 712
734 bra FDCCommand 783 bra FDCCommand
735 784
736 ;Start drive motors 785 ;Start drive motors
737 StartMotor 786 StartMotor
738 pshs x,b,a 787 pshs x,b,a
739 lda >D.DskTmr ; if timer = 0 then wait for motors to 788 lda >D.DskTmr ; if timer <> 0 then skip as motor already on
740 bne SpinUp ; spin up 789 bne SpinUp
741 lda #MotorOn 790 lda #MotorOn ; else spin up
742 791
743 IFNE DragonAlpha 792 IFNE DragonAlpha
744 bsr AlphaDskCtl 793 bsr AlphaDskCtl
745 ELSE 794 ELSE
746 sta >DskCtl 795 sta >DskCtl
747 ENDC 796 ENDC
748 797
749 ldx #$A000 798 ldx #$A000 ; Wait a little while for motors to get up to speed
750 StartMotorLoop 799 StartMotorLoop
751 nop 800 nop
752 nop 801 nop
753 leax -1,x 802 leax -1,x
754 bne StartMotorLoop 803 bne StartMotorLoop
804
755 SpinUp lda #$F0 ; Start external motor timer 805 SpinUp lda #$F0 ; Start external motor timer
756 sta >D.DskTmr ; external to driver 806 sta >D.DskTmr ; external to driver
757 puls pc,x,b,a 807 puls pc,x,b,a
758 808
759 ; Set Write Precompensation according to media type 809 ; Set Write Precompensation according to media type
774 824
775 ; Translate DragonDos Drive select mechinisim to work on Alpha 825 ; Translate DragonDos Drive select mechinisim to work on Alpha
776 ; Takes byte that would be output to $FF48, reformats it and 826 ; Takes byte that would be output to $FF48, reformats it and
777 ; outputs to Alpha AY-8912's IO port, which is connected to 827 ; outputs to Alpha AY-8912's IO port, which is connected to
778 ; Drive selects, motor on and enable precomp. 828 ; Drive selects, motor on and enable precomp.
829 ; This code now expects Alpha NMI/DDEN etc codes, as defined
830 ; at top of this file (and dgndefs). The exception to this is
831 ; the drive number is still passed in the bottom 2 bits and
832 ; converted with a lookup table.
833 ; We do not need to preserve the ROM select bit as this code
834 ; operates in RAM only mode.
779 ; Also sets NMIFlag. 835 ; Also sets NMIFlag.
780 836
781 AlphaDskCtlB 837
782 pshs A 838 DrvTab FCB Drive0A,Drive1A,Drive2A,Drive3A
783 tfr b,a
784 bsr AlphaDskCtl
785 puls A
786 rts
787 839
788 AlphaDskCtl 840 AlphaDskCtl
789 PSHS A,B,CC 841 PSHS x,A,B,CC
790
791 anda #~DDenMask ; Dragon Alpha has DDen perminently enabled
792 842
793 PSHS A 843 PSHS A
794 ANDA #NMIMask ; mak out nmi enable bit 844 ANDA #NMIEn ; mask out nmi enable bit
795 sta >NMIFlag,u ; Save it for later use 845 sta >NMIFlag,u ; Save it for later use
796 846
797 lda ,s 847 lda ,s ; Convert drives
798 anda #EnpMask ; Extract enp mask 848 anda #%00000011 ; mask out drive number
799 pshs a ; save it 849 leax DrvTab,pcr ; point at table
800 850 lda a,x ; get bitmap
801 lda 1,s 851 ldb ,s
802 ANDA #DSMask ; Mask Out drive select bits 852 andb #%11111100 ; mask out drive number
803 853 stb ,s
804 ; Shift a bit in B left, a times, to convert drive number 854 ora ,s ; recombine
805 ; to DS bit. 855 sta ,s
806 856
807 ldb #$01 857
808 ShiftNext 858 lda #AYIOREG ; AY-8912 IO register
809 cmpa #$00 ; Done all shifts ? 859 sta PIA2DB ; Output to PIA
810 beq ShiftDone 860 ldb #AYREGLatch ; Latch register to modify
811 lslb 861 stb PIA2DA
812 deca 862
813 bra ShiftNext 863 clr PIA2DA ; Idle AY
814 864
815 ShiftDone 865 lda ,s+ ; Fetch saved Drive Selects
816 lda 1,s 866 sta PIA2DB ; output to PIA
817 anda #MotorMask ; Extract motor bit 867 ldb #AYWriteReg ; Write value to latched register
818 cmpa #MotorMask ; Motor on ? 868 stb PIA2DA ; Set register
819 beq MotorIsOn ; Yes leave it on. 869
820 870 clr PIA2DA ; Idle AY
821 clrb ; No zero out DS bits
822
823 MotorIsOn
824 ora ,s ; Recombine with ENP bit.
825 leas 1,s ; drop off stack
826 lsla
827 lsla
828 pshs b
829 ora ,s
830 leas 1,s
831 871
832 pshs a ; Save motor/drive select state 872 PULS x,A,B,CC
833 ldb PIADA ; get BDIR/BC1/Rom select
834 andb #$FC ; Mask out BCDIR/BC1, so we don't change other bits
835 pshs b ; save mask
836
837 lda #AYIOREG ; AY-8912 IO register
838 sta PIADB ; Output to PIA
839 orb #AYREGLatch ; Latch register to modify
840 stb PIADA
841
842 clrb
843 orb ,s ; Restore saved bits
844 stb PIADA ; Idle AY
845
846 lda 1,s ; Fetch saved Drive Selects
847 sta PIADB ; output to PIA
848 ldb #AYWriteReg ; Write value to latched register
849 orb ,s ; Restore saved bits
850 stb PIADA ; Set register
851
852 clrb
853 orb ,s ; Restore saved bits
854 stb PIADA ; Idle AY
855
856 leas 3,s ; drop saved bytes
857
858 PULS A,B,CC
859 RTS 873 RTS
860 874
861 ENDC 875 ENDC
862 876
863 emod 877 emod