comparison level1/modules/rb1773.asm @ 1581:c35df03d98db

IRQ properly deleted
author boisy
date Fri, 21 May 2004 03:18:56 +0000
parents 1a19aed5dc34
children dc3272e71faa
comparison
equal deleted inserted replaced
1580:79fd895a3123 1581:c35df03d98db
6 * ignored 6 * ignored
7 * 7 *
8 * NOTE: 512 bytes is reserved as a physical sector buffer. Any reads/ 8 * NOTE: 512 bytes is reserved as a physical sector buffer. Any reads/
9 * writes are done from this buffer to the controller. Copies of the 256 9 * writes are done from this buffer to the controller. Copies of the 256
10 * byte chunk needed are done by a block memory move 10 * byte chunk needed are done by a block memory move
11 11 *
12 * Disto Super Controller II Registers:
13 *
14 * $FF74 RW.Dat --- R/W Buffer data #1
15 * $FF75 mirror of $FF74
16 * $FF76 RW.Ctrl --- Write D0 = 0 FDC Write Op #2
17 * = 1 FDC Read Op #2
18 * D1 = 0 Normal Mode
19 * = 1 Buffered I/O Mode
20 * D2 = 0 Normal NMI
21 * = 1 Masked NMI
22 * D3 = 0 No FIRQ (Masked)
23 * = 1 Enabled FIRQ
24 * Read D7 = FDC INT Status (Inverted)
25 * $FF77 mirror of $FF76
26 * #1: any write to $FF76-$FF77 clears Buffer counter
27 * #2: in buffered mode only
28 *
12 * $Id$ 29 * $Id$
13 * 30 *
14 * Edt/Rev YYYY/MM/DD Modified by 31 * Edt/Rev YYYY/MM/DD Modified by
15 * Comment 32 * Comment
16 * ------------------------------------------------------------------ 33 * ------------------------------------------------------------------
21 * Shrunk (slowed slightly) error returns 38 * Shrunk (slowed slightly) error returns
22 * Added blobstop code 39 * Added blobstop code
23 * 40 *
24 * 11r1 2003/09/03 Boisy G. Pitre 41 * 11r1 2003/09/03 Boisy G. Pitre
25 * Added code to sense if HW is present or not and return error if not. 42 * Added code to sense if HW is present or not and return error if not.
43 *
44 * 1r0 2004/05/20 Boisy G. Pitre
45 * Restarted edition due to name change; backported to Level 1
26 46
27 nam rb1773 47 nam rb1773
28 ttl Western Digital 1773 Disk Controller Driver 48 ttl Western Digital 1773 Disk Controller Driver
29 49
30 IFP1 50 IFP1
31 use defsfile 51 use defsfile
32 ENDC 52 ENDC
33 53
34 tylg set Drivr+Objct 54 tylg set Drivr+Objct
35 atrv set ReEnt+rev 55 atrv set ReEnt+rev
36 rev set $01 56 rev set $00
37 edition set 11 57 edition set 1
38 58
39 * Configuration Settings 59 * Configuration Settings
40 N.Drives equ 4 number of drives to support 60 N.Drives equ 4 number of drives to support
41 TC9 equ 0 Set to 1 for TC9 special slowdowns 61 TC9 equ 0 Set to 1 for TC9 special slowdowns
42 PRECOMP equ 0 Set to 1 to turn on write precompensation 62 PRECOMP equ 0 Set to 1 to turn on write precompensation
46 WD_Cmd equ $08 66 WD_Cmd equ $08
47 WD_Stat equ WD_Cmd 67 WD_Stat equ WD_Cmd
48 WD_Trak equ $09 68 WD_Trak equ $09
49 WD_Sect equ $0A 69 WD_Sect equ $0A
50 WD_Data equ $0B 70 WD_Data equ $0B
71
72 * WD-17X3 Commands
73 S$FrcInt equ $D0
51 74
52 * Control Register Definitions 75 * Control Register Definitions
53 C_HALT equ %10000000 Halt line to CPU is active when set 76 C_HALT equ %10000000 Halt line to CPU is active when set
54 C_SIDSEL equ %01000000 Side select (0 = front side, 1 = back side) 77 C_SIDSEL equ %01000000 Side select (0 = front side, 1 = back side)
55 C_DBLDNS equ %00100000 Density (0 = single, 1 = double) 78 C_DBLDNS equ %00100000 Density (0 = single, 1 = double)
70 u00AE rmb 1 93 u00AE rmb 1
71 FBlock rmb 2 block number for format 94 FBlock rmb 2 block number for format
72 IFGT Level-1 95 IFGT Level-1
73 FTask rmb 1 task number for format 96 FTask rmb 1 task number for format
74 ENDC 97 ENDC
75 u00B1 rmb 2 Vi.Cnt word for VIRQ 98 VIRQPak rmb 2 Vi.Cnt word for VIRQ
76 u00B3 rmb 2 Vi.Rst word for VIRQ 99 u00B3 rmb 2 Vi.Rst word for VIRQ
77 u00B5 rmb 1 Vi.Stat byte for VIRQ (drive motor timeout) 100 u00B5 rmb 1 Vi.Stat byte for VIRQ (drive motor timeout)
78 u00B6 rmb 2 OS9's logical sector # 101 loglsn rmb 2 OS9's logical sector #
79 u00B8 rmb 1 PCDOS (512 byte sector) sector # 102 physlsn rmb 1 PCDOS (512 byte sector) sector #
80 size equ . 103 size equ .
81 104
82 fcb DIR.+SHARE.+PEXEC.+PWRIT.+PREAD.+EXEC.+UPDAT. 105 fcb DIR.+SHARE.+PEXEC.+PWRIT.+PREAD.+EXEC.+UPDAT.
83 106
84 name fcs /rb1773/ 107 name fcs /rb1773/
85 fcb edition 108 fcb edition
86 109
87 VIRQCnt fdb $00F0 Initial count for VIRQ (240) 110 VIRQCnt fdb TkPerSec*4 Initial count for VIRQ (4 seconds)
88 111
89 IRQPkt fcb $00 Normal bits (flip byte) 112 IRQPkt fcb $00 Normal bits (flip byte)
90 fcb $01 Bit 1 is interrupt request flag (Mask byte) 113 fcb $01 Bit 1 is interrupt request flag (Mask byte)
91 fcb 10 Priority byte 114 fcb 10 Priority byte
92 115
117 clr >D.DskTmr flag drive motor as not running 140 clr >D.DskTmr flag drive motor as not running
118 ELSE 141 ELSE
119 clr <D.MotOn flag drive motor as not running 142 clr <D.MotOn flag drive motor as not running
120 ENDC 143 ENDC
121 leax WD_Stat,x point to Status/Command register 144 leax WD_Stat,x point to Status/Command register
122 lda #$D0 force Interrupt command 145 lda #S$FrcInt "Force Interrupt" command
123 sta ,x send to FDC 146 sta ,x send to FDC
124 lbsr FDCDelay time delay for ~ 108 cycles 147 lbsr FDCDelay time delay for ~ 108 cycles
125 lda ,x eat status register 148 lda ,x eat status register
126 ldd #$FF*256+N.Drives 'invalid' value & # of drives 149 ldd #$FF*256+N.Drives 'invalid' value & # of drives
127 sta >u00B8,u set 512 byte sector # to bogus value 150 sta >physlsn,u set 512 byte sector # to bogus value
128 sta >u00B8+1,u 151 sta >physlsn+1,u
129 leax DRVBEG,u point to start of drive tables 152 leax DRVBEG,u point to start of drive tables
130 L004B sta ,x DD.TOT MSB to bogus value 153 l@ sta ,x DD.TOT MSB to bogus value
131 sta <V.TRAK,x init current track # to bogus value 154 sta <V.TRAK,x init current track # to bogus value
132 leax <DRVMEM,x point to next drive table 155 leax <DRVMEM,x point to next drive table
133 decb done all 4 drives yet? 156 decb done all drives yet?
134 bne L004B no, init them all 157 bne l@ no, init them all
135 leax >NMISvc,pc point to NMI service routine 158 leax >NMISvc,pc point to NMI service routine
136 IFGT Level-1 159 IFGT Level-1
137 stx <D.NMI install as system NMI 160 stx <D.NMI install as system NMI
138 ELSE 161 ELSE
139 stx >D.XNMI+1 NMI jump vector operand 162 stx >D.XNMI+1 NMI jump vector operand
146 leay >IRQSvc,pc point to IRQ service routine 169 leay >IRQSvc,pc point to IRQ service routine
147 leax >IRQPkt,pc point to IRQ packet 170 leax >IRQPkt,pc point to IRQ packet
148 os9 F$IRQ install IRQ 171 os9 F$IRQ install IRQ
149 puls y Get back device dsc. ptr 172 puls y Get back device dsc. ptr
150 bcs Return If we can't install IRQ, exit 173 bcs Return If we can't install IRQ, exit
174 IFNE SCII
175 lda MPI.Slct
176 sta mpislot,u
177 ldd #RW.Ctrl
178 leay SC2vec,pcr
179 os9 F$IRQ
180 bcs Return
181 pshs cc
182 orcc #IntMasks
183 lda $FF23
184 * disable FIRQ from cart. set flag on falling edge of CART
185 anda #$FC
186 sta $FF23
187 lda $FF22
188 lda D.IRQER
189 ora #1 enable CART IRQ
190 sta D.IRQER .. save in IRQENR shadow
191 sta IRQENR .. and actual register
192 puls cc
193 ENDC
151 ldd #512 Request 512 byte sector buffer 194 ldd #512 Request 512 byte sector buffer
152 pshs u Preserve device mem ptr 195 pshs u Preserve device mem ptr
153 os9 F$SRqMem Request sector buffer 196 os9 F$SRqMem Request sector buffer
154 tfr u,x Move ptr to sector buffer to x 197 tfr u,x Move ptr to sector buffer to x
155 puls u Restore device mem ptr 198 puls u Restore device mem ptr
177 * 220 *
178 * Exit: 221 * Exit:
179 * CC = carry set on error 222 * CC = carry set on error
180 * B = error code 223 * B = error code
181 * 224 *
182 Term leay >u00B1,u Point to VIRQ packet 225 Term leay >VIRQPak,u Point to VIRQ packet
183 IFNE H6309 226 IFNE H6309
184 tfr 0,x "remove" 227 tfr 0,x "remove"
185 ELSE 228 ELSE
186 ldx #$0000 229 ldx #$0000
187 ENDC 230 ENDC
189 IFNE H6309 232 IFNE H6309
190 tfr 0,x "remove" 233 tfr 0,x "remove"
191 ELSE 234 ELSE
192 ldx #$0000 235 ldx #$0000
193 ENDC 236 ENDC
237 leay >IRQSvc,pc point to IRQ service routine
194 os9 F$IRQ Remove IRQ 238 os9 F$IRQ Remove IRQ
239 IFNE SCII
240 IFNE H6309
241 tfr 0,x "remove"
242 ELSE
243 ldx #$0000
244 ENDC
245 leay SC2vec,pcr
246 os9 F$IRQ Remove IRQ
247 ENDC
195 pshs u Save device mem ptr 248 pshs u Save device mem ptr
196 ldu >sectbuf,u Get pointer to sector buffer 249 ldu >sectbuf,u Get pointer to sector buffer
197 ldd #512 Return sector buffer memory 250 ldd #512 Return sector buffer memory
198 os9 F$SRtMem 251 os9 F$SRtMem
199 puls u Restore device mem ptr 252 puls u Restore device mem ptr
201 IFEQ Level-1 254 IFEQ Level-1
202 clr >D.DskTmr Clear out drive motor timeout flag 255 clr >D.DskTmr Clear out drive motor timeout flag
203 ELSE 256 ELSE
204 clr <D.MotOn Clear out drive motor timeout flag 257 clr <D.MotOn Clear out drive motor timeout flag
205 ENDC 258 ENDC
206 L00AB rts return 259 ex rts return
207 260
208 * Check if 512 byte sector conversion needed 261 * Check if 512 byte sector conversion needed
209 * Entry: B:X=LSN 262 * Entry: B:X=LSN
210 * U=Static mem ptr 263 * U=Static mem ptr
211 * Y=Path dsc. ptr 264 * Y=Path dsc. ptr
212 * Exit: X=New LSN (same as original for 256 byte sectors, 1/2 of original 265 * Exit: X=New LSN (same as original for 256 byte sectors, 1/2 of original
213 * for 512 byte sectors 266 * for 512 byte sectors
214 L00AC pshs x,b Save LSN 267 Chk512 pshs x,b save LSN
215 stx >u00B6,u Save OS9 LSN 268 stx >loglsn,u save OS9 LSN
216 lda <PD.TYP,y Get device type from path dsc. 269 lda <PD.TYP,y get device type from path dsc.
217 anda #%00000100 Mask out all but 512 byte sector flag 270 anda #%00000100 mask out all but 512 byte sector flag
218 bne L00BB 512 byte sectors, go process 271 bne Log2Phys 512 byte sectors, go process
219 L00CA puls pc,x,b Restore LSN & return 272 L00CA puls pc,x,b restore LSN & return
220
221 * 512 byte sector processing goes here 273 * 512 byte sector processing goes here
222 L00BB puls x,b Get back LSN 274 Log2Phys puls x,b Get back LSN
223 clrb Clear carry for rotate (also high byte of LSN) 275 clrb Clear carry for rotate (also high byte of LSN)
224 tfr x,d Move to mathable register 276 tfr x,d Move to mathable register
225 IFNE H6309 277 IFNE H6309
226 rord Divide LSN by 2 278 rord Divide LSN by 2
227 ELSE 279 ELSE
228 rora 280 rora
229 rorb 281 rorb
230 ENDC 282 ENDC
231 tfr d,x Move new LSN back to X 283 tfr d,x Move new LSN back to X
232 stx >u00B8,u Save 'physical' LSN (for controller) 284 stx >physlsn,u Save 'physical' LSN (for controller)
233 clrb No error & return 285 clrb No error & return
234 rts 286 rts
235 287
236 start lbra Init 288 start lbra Init
237 bra Read 289 bra Read
253 * 305 *
254 * Exit: 306 * Exit:
255 * CC = carry set on error 307 * CC = carry set on error
256 * B = error code 308 * B = error code
257 * 309 *
258 Read bsr L00AC Go check for 512 byte sector/adjust if needed 310 Read bsr Chk512 go check for 512 byte sector/adjust if needed
259 lda #%10010001 Error flags (see Disto SCII source) 311 lda #%10010001 error flags (see Disto SCII source)
260 pshs x Preserve sector # 312 pshs x preserve sector #
261 lbsr L0162 Go read the sector 313 lbsr L0162 go read the sector
262 puls x Restore sector # 314 puls x restore sector #
263 bcs L00AB If error, exit 315 bcs ex if error, exit
264 pshs y,x Save path dsc ptr & LSN 316 pshs y,x save path dsc ptr & LSN
265 leax ,x LSN0? 317 leax ,x LSN0?
266 bne L012D No, go calculate normally 318 bne L012D no, go calculate normally
267 puls y,x Yes, restore path dsc ptr & LSN 319 puls y,x yes, restore path dsc ptr & LSN
268 lda <PD.TYP,y Get type from path dsc. 320 lda <PD.TYP,y get type from path dsc.
269 bita #TYP.NSF Standard OS-9 format? 321 bita #TYP.NSF standard OS-9 format?
270 beq L00F0 Yes, skip ahead 322 beq L00F0 yes, skip ahead
271 lbsr L051A 323 lbsr L051A
272 pshs y,x save path dsc ptr 324 pshs y,x save path dsc ptr
273 bra L012D 325 bra L012D
274 326
275 * LSN0, standard OS-9 format 327 * LSN0, standard OS-9 format
314 IFNE H6309 366 IFNE H6309
315 ldw #256 OS9 sector size (even if physical was 512) 367 ldw #256 OS9 sector size (even if physical was 512)
316 ENDC 368 ENDC
317 anda #%00000100 Mask out all but 512 byte sector flag 369 anda #%00000100 Mask out all but 512 byte sector flag
318 beq L014B If normal sector, just copy it 370 beq L014B If normal sector, just copy it
319 ldd >u00B6,u Get OS9's LSN (twice of the 'real' 512 sector) 371 ldd >loglsn,u Get OS9's LSN (twice of the 'real' 512 sector)
320 andb #$01 Mask out all but odd/even sector indicator 372 andb #$01 Mask out all but odd/even sector indicator
321 beq L014B Even, use 1st half of 512 byte sector 373 beq L014B Even, use 1st half of 512 byte sector
322 IFNE H6309 374 IFNE H6309
323 addr w,y Odd, bump sector buffer ptr to 2nd half 375 addr w,y Odd, bump sector buffer ptr to 2nd half
324 ELSE 376 ELSE
409 * 461 *
410 * Exit: 462 * Exit:
411 * CC = carry set on error 463 * CC = carry set on error
412 * B = error code 464 * B = error code
413 * 465 *
414 Write lbsr L00AC Go adjust LSN for 512 byte sector if needed 466 Write lbsr Chk512 go adjust LSN for 512 byte sector if needed
415 lda #%1001001 Retry flags for I/O errors (see Disto SCII source) 467 lda #%1001001 retry flags for I/O errors (see Disto SCII source)
416 L01C4 pshs x,d Preserve LSN, retries 468 L01C4 pshs x,d preserve LSN, retries
417 bsr L01E8 Go write the sector 469 bsr L01E8 go write the sector
418 puls x,d Restore LSN, retries 470 puls x,d restore LSN, retries
419 bcs L01D8 Error writing, go to write retry handler 471 bcs L01D8 error writing, go to write retry handler
420 tst <PD.VFY,y No error, do we want physical verify? 472 tst <PD.VFY,y no error, do we want physical verify?
421 bne L01D6 No, exit without error 473 bne L01D6 no, exit without error
422 lbsr verify Go re-read & verify 32 out of 256 bytes 474 lbsr verify go re-read & verify 32 out of 256 bytes
423 bcs L01D8 Error on verify, go to write retry handler 475 bcs L01D8 error on verify, go to write retry handler
424 L01D6 clrb No error & return 476 L01D6 clrb no error & return
425 L01D7 rts 477 L01D7 rts
426 478
427 * Write error retry handler 479 * Write error retry handler
428 L01D8 lsra Shift retry flags 480 L01D8 lsra Shift retry flags
429 lbeq L03AF Too many retries, exit with error 481 lbeq L03AF Too many retries, exit with error
440 lda <PD.TYP,y Get device type 492 lda <PD.TYP,y Get device type
441 anda #%00000100 512 byte sector? 493 anda #%00000100 512 byte sector?
442 beq L020D No, skip ahead 494 beq L020D No, skip ahead
443 lda #$91 ??? appears to be useless 495 lda #$91 ??? appears to be useless
444 lbsr L0176 Go read the sector in 496 lbsr L0176 Go read the sector in
445 ldd >u00B6,u Get OS9 LSN 497 ldd >loglsn,u Get OS9 LSN
446 andb #$01 Even or odd? 498 andb #$01 Even or odd?
447 beq L020D Even, skip ahead 499 beq L020D Even, skip ahead
448 ldx >sectbuf,u Get physical sector buffer ptr 500 ldx >sectbuf,u Get physical sector buffer ptr
449 leax >$0100,x Point to 2nd half 501 leax >$0100,x Point to 2nd half
450 bra L0211 Copy caller's buffer to 2nd half of sector 502 bra L0211 Copy caller's buffer to 2nd half of sector
531 pshs u,y Preserve device mem, path dsc. ptrs 583 pshs u,y Preserve device mem, path dsc. ptrs
532 ldb <PD.TYP,y Get type from path dsc. 584 ldb <PD.TYP,y Get type from path dsc.
533 ldy >sectbuf,u Get sector buffer ptr 585 ldy >sectbuf,u Get sector buffer ptr
534 andb #%00000100 512 byte sector? 586 andb #%00000100 512 byte sector?
535 beq L028D No, skip ahead 587 beq L028D No, skip ahead
536 ldd >u00B6,u Get OS9's sector # 588 ldd >loglsn,u Get OS9's sector #
537 andb #$01 Odd/even sector? 589 andb #$01 Odd/even sector?
538 beq L028D Even; compare first half 590 beq L028D Even; compare first half
539 leay >$0100,y Odd, compare second half 591 leay >$0100,y Odd, compare second half
540 L028D tfr x,u Move PD.BUF ptr to U (since cmpx is faster) 592 L028D tfr x,u Move PD.BUF ptr to U (since cmpx is faster)
541 lda #32 # of 'spotty' checks to do 593 lda #32 # of 'spotty' checks to do
731 L03E4 bsr L0404 Send command to controller & waste some time 783 L03E4 bsr L0404 Send command to controller & waste some time
732 L03E6 ldb >DPort+WD_Stat Check FDC status register 784 L03E6 ldb >DPort+WD_Stat Check FDC status register
733 bitb #$01 Is controller still busy? 785 bitb #$01 Is controller still busy?
734 beq L0403 No, exit 786 beq L0403 No, exit
735 ldd >VIRQCnt,pc Get initial count value for drive motor speed 787 ldd >VIRQCnt,pc Get initial count value for drive motor speed
736 std >u00B1,u Save it 788 std >VIRQPak,u Save it
737 bra L03E6 Wait for controller to finish previous command 789 bra L03E6 Wait for controller to finish previous command
738 790
739 * Send command to FDC 791 * Send command to FDC
740 L03F7 lda #C_MOTOR 792 L03F7 lda #C_MOTOR
741 * lda #%00001000 Mask in Drive motor on bit 793 * lda #%00001000 Mask in Drive motor on bit
886 eorb #%00001011 Set proper bits for controller 938 eorb #%00001011 Set proper bits for controller
887 lbra L03E4 939 lbra L03E4
888 940
889 L04B3 pshs y,x,d Preserve regs 941 L04B3 pshs y,x,d Preserve regs
890 ldd >VIRQCnt,pc Get VIRQ initial count value 942 ldd >VIRQCnt,pc Get VIRQ initial count value
891 std >u00B1,u Save it 943 std >VIRQPak,u Save it
892 lda >CtlImg,u ?Get drive? 944 lda >CtlImg,u ?Get drive?
893 ora #C_MOTOR Turn drive motor on for that drive 945 ora #C_MOTOR Turn drive motor on for that drive
894 * ora #%00001000 Turn drive motor on for that drive 946 * ora #%00001000 Turn drive motor on for that drive
895 sta >DPort+CtrlReg Send drive motor on command to FDC 947 sta >DPort+CtrlReg Send drive motor on command to FDC
896 IFEQ Level-1 948 IFEQ Level-1
914 sta >D.DskTmr 966 sta >D.DskTmr
915 ELSE 967 ELSE
916 sta <D.MotOn 968 sta <D.MotOn
917 ENDC 969 ENDC
918 ldx #$0001 Install VIRQ entry 970 ldx #$0001 Install VIRQ entry
919 leay >u00B1,u Point to packet 971 leay >VIRQPak,u Point to packet
920 clr Vi.Stat,y Reset Status byte 972 clr Vi.Stat,y Reset Status byte
921 ldd >VIRQCnt,pc Get initial VIRQ count value 973 ldd >VIRQCnt,pc Get initial VIRQ count value
922 os9 F$VIRQ Install VIRQ 974 os9 F$VIRQ Install VIRQ
923 bcc VIRQOut No error, exit 975 bcc VIRQOut No error, exit
924 lda #$80 Flag that VIRQ wasn't installed 976 lda #$80 Flag that VIRQ wasn't installed