1746
|
1 ********************************************************************
|
|
2 * rb1773 - Western Digital 1773 Disk Controller Driver
|
|
3 *
|
|
4 * $Id$
|
|
5 *
|
|
6 * This driver has been tested with the following controllers:
|
|
7 * - Tandy FD-502 "shortie" disk controller
|
|
8 * - Disto Super Controller I
|
|
9 * - Disto Super Controller II
|
|
10 *
|
|
11 * This driver can also be assembled to support the no-halt feature of
|
|
12 * the Disto Super Controller II.
|
|
13 *
|
|
14 *
|
|
15 * A lot of references to **.CYL or <u00B6 using 16 bit registers can be
|
|
16 * changed to 8 bit registers with a +1 offset, since track #'s >255 are
|
|
17 * ignored
|
|
18 *
|
|
19 * NOTE: 512 bytes is reserved as a physical sector buffer. Any reads/
|
|
20 * writes are done from this buffer to the controller. Copies of the 256
|
|
21 * byte chunk needed are done by a block memory move
|
|
22 *
|
|
23 *
|
|
24 ********** DISTO SUPER CONTROLLER II NOTES **********
|
|
25 *
|
|
26 * SCII 0=standard controller 1=Disto Super Controller II
|
|
27 * SCIIALT 0=Normal I/O register 1=Alternative registers; See below
|
|
28 *
|
|
29 * Disto Super Controller II Registers:
|
|
30 *
|
|
31 * $FF74 RW.Dat --- R/W Buffer data #1
|
|
32 * $FF75 mirror of $FF74
|
|
33 * $FF76 RW.Ctrl --- Write D0 = 0 FDC Write Op #2
|
|
34 * = 1 FDC Read Op #2
|
|
35 * D1 = 0 Normal Mode
|
|
36 * = 1 Buffered I/O Mode
|
|
37 * D2 = 0 Normal NMI
|
|
38 * = 1 Masked NMI
|
|
39 * D3 = 0 No FIRQ (Masked)
|
|
40 * = 1 Enabled FIRQ
|
|
41 * Read D7 = FDC INT Status (Inverted)
|
|
42 * $FF77 mirror of $FF76
|
|
43 * #1: any write to $FF76-$FF77 clears Buffer counter
|
|
44 * #2: in buffered mode only
|
|
45 *
|
|
46 * Alternate port is at $FF58-$FF5B in case of hardware conflicts.
|
|
47 *
|
|
48 * Edt/Rev YYYY/MM/DD Modified by
|
|
49 * Comment
|
|
50 * ------------------------------------------------------------------
|
|
51 * 11 1993/05/12 ???
|
|
52 * Special opts for TC9 to slow controller reads and writes TFM's
|
|
53 * between sector buffers & in drive table init/copies.
|
|
54 * Changed software timing loop (drive spin-up) to F$Sleep for 32 ticks
|
|
55 * Shrunk (slowed slightly) error returns
|
|
56 * Added blobstop code
|
|
57 *
|
|
58 * 11r1 2003/09/03 Boisy G. Pitre
|
|
59 * Added code to sense if HW is present or not and return error if not.
|
|
60 *
|
|
61 * 1r0 2004/05/20 Boisy G. Pitre
|
|
62 * Restarted edition due to name change; backported to Level 1
|
|
63 *
|
|
64 * 2004/06/01 Robert Gault
|
|
65 * Added code to obtain an SCII driver, at least for the Sleep mode. It
|
|
66 * would be quite difficult and probably not worth the effort to permit
|
|
67 * selection of both Sleep and IRQ SCII drivers. However, both normal
|
|
68 * and Alt SCII I/O registers are supported.
|
|
69 *
|
|
70 * Cleaned up some errors in the last version of rb1773.
|
|
71 *
|
|
72 * 2004/07/11 Robert Gault
|
|
73 * Corrected the error handling code for read & write to separate SCII errors
|
|
74 * from OS-9 errors. Changed drive test from compare #4 to compare #N.Drives to
|
|
75 * permit up to 6 drives using alternate table.
|
|
76 *
|
|
77 * 2005/01/27 Robert Gault
|
|
78 * Separated the sector write and format write loops so that the CPU clock
|
|
79 * can be slowed down during formats. This "corrects" problems some hardware
|
|
80 * have with the current NitrOS-9 during formats.
|
|
81
|
|
82 nam rb1773
|
|
83 ttl Western Digital 1773 Disk Controller Driver
|
|
84
|
|
85 * These lines needed if assembling with on a Color computer.
|
|
86 *SCII set 1 * 0=not present 1=present
|
|
87 *SCIIALT set 1 * 0=normal address 1=alternate
|
|
88 SCIIHACK set 0 * 0=stock model 1=512 byte buffer
|
|
89 *H6309 set 1
|
|
90 *LEVEL set 2
|
|
91 * These lines needed if not using latest os9def files.
|
|
92 *TkPerSec set 60
|
|
93 *DPort set $FF40
|
|
94
|
|
95 * This should be changed for NitrOS9 project to "use defsfile"
|
|
96 IFP1
|
|
97 use defsfile
|
|
98 ENDC
|
|
99
|
|
100 tylg set Drivr+Objct
|
|
101 atrv set ReEnt+rev
|
|
102 rev set $00
|
|
103 edition set 1
|
|
104
|
|
105 * Configuration Settings
|
|
106 N.Drives equ 4 number of drives to support
|
|
107 TC9 equ 0 Set to 1 for TC9 special slowdowns
|
|
108 PRECOMP equ 0 Set to 1 to turn on write precompensation
|
|
109
|
|
110 * Disto Super Controller defs
|
|
111 IFEQ SCIIALT
|
|
112 RW.Dat equ $FF74
|
|
113 RW.Ctrl equ $FF76
|
|
114 ELSE
|
|
115 RW.Dat equ $FF58
|
|
116 RW.Ctrl equ $FF5A
|
|
117 ENDC
|
|
118
|
|
119
|
|
120 * WD-17X3 Definitions
|
|
121 CtrlReg equ $00 Control register for Tandy controllers; not part of WD
|
|
122 WD_Cmd equ $08
|
|
123 WD_Stat equ WD_Cmd
|
|
124 WD_Trak equ $09
|
|
125 WD_Sect equ $0A
|
|
126 WD_Data equ $0B
|
|
127
|
|
128 * WD-17X3 Commands
|
|
129 S$Read equ $80 Read sector
|
|
130 S$Format equ $A0 Format track
|
|
131 S$FrcInt equ $D0 Force interrupt
|
|
132
|
|
133 * Control Register Definitions
|
|
134 C_HALT equ %10000000 Halt line to CPU is active when set
|
|
135 C_SIDSEL equ %01000000 Side select (0 = front side, 1 = back side)
|
|
136 C_DBLDNS equ %00100000 Density (0 = single, 1 = double)
|
|
137 C_WPRCMP equ %00010000 Write precompensation (0 = off, 1 = on)
|
|
138 C_MOTOR equ %00001000 Drive motor (0 = off, 1 = on)
|
|
139 C_DRV2 equ %00000100 Drive 2 selected when set
|
|
140 C_DRV1 equ %00000010 Drive 1 selected when set
|
|
141 C_DRV0 equ %00000001 Drive 0 selected when set
|
|
142
|
|
143 mod eom,name,tylg,atrv,start,size
|
|
144
|
|
145 u0000 rmb DRVBEG+(DRVMEM*N.Drives)
|
|
146 lastdrv rmb 2 Last drive table accessed (ptr)
|
|
147 ctlimg rmb 1 Bit mask for control reg (drive #, side,etc)
|
|
148 u00AA rmb 1 drive change flag
|
|
149 sectbuf rmb 2 Ptr to 512 byte sector buffer
|
|
150 currside rmb 1 head flag; 0=front 1 = back
|
|
151 u00AE rmb 1 LSB of LSN
|
|
152 IFGT Level-1
|
|
153 FBlock rmb 2 block number for format
|
|
154 FTask rmb 1 task number for format
|
|
155 ENDC
|
|
156 VIRQPak rmb 2 Vi.Cnt word for VIRQ
|
|
157 u00B3 rmb 2 Vi.Rst word for VIRQ
|
|
158 u00B5 rmb 1 Vi.Stat byte for VIRQ (drive motor timeout)
|
|
159 loglsn rmb 2 OS9's logical sector #
|
|
160 * Removed next line and added two new ones. RG
|
|
161 * PCDOS does not ask driver for any info.
|
|
162 * physlsn rmb 2 PCDOS (512 byte sector) #
|
|
163 flag512 rmb 1 PCDOS (512 byte sector) 0=no, 1=yes
|
|
164 flagform rmb 1 SCII format flag
|
|
165 size equ .
|
|
166
|
|
167 fcb DIR.+SHARE.+PEXEC.+PWRIT.+PREAD.+EXEC.+UPDAT.
|
|
168
|
|
169 name fcs /rb1773/
|
|
170 fcb edition
|
|
171
|
|
172 VIRQCnt fdb TkPerSec*4 Initial count for VIRQ (4 seconds)
|
|
173
|
|
174 IRQPkt fcb $00 Normal bits (flip byte)
|
|
175 fcb $01 Bit 1 is interrupt request flag (Mask byte)
|
|
176 fcb 10 Priority byte
|
|
177
|
|
178 * Init
|
|
179 *
|
|
180 * Entry:
|
|
181 * Y = address of device descriptor
|
|
182 * U = address of device memory area
|
|
183 *
|
|
184 * Exit:
|
|
185 * CC = carry set on error
|
|
186 * B = error code
|
|
187 *
|
|
188 * New code added 09/03/2003 by Boisy G. Pitre
|
|
189 * Write a pattern to $FF4B and read it back to verify that the hardware
|
|
190 * does exist.
|
|
191 Init equ *
|
|
192 * Two new lines for SCII. RG
|
|
193 IFNE SCII
|
|
194 clr RW.Ctrl clear SCII control register
|
|
195 clr flagform,u clear SCII format flag
|
|
196 ENDC
|
|
197 ldx V.PORT,u get Base port address
|
|
198 lda WD_Data,x get byte at FDC Data register
|
|
199 coma complement it to modify it
|
|
200 sta WD_Data,x write it
|
|
201 clrb
|
|
202 Init2 decb delay a bit...
|
|
203 bmi Init2
|
|
204 suba WD_Data,x read it back
|
|
205 lbne NoHW if not zero, we didn't read what we wrote
|
|
206 **
|
|
207 IFEQ Level-1
|
|
208 clr >D.DskTmr flag drive motor as not running
|
|
209 ELSE
|
|
210 clr <D.MotOn flag drive motor as not running
|
|
211 ENDC
|
|
212 leax WD_Stat,x point to Status/Command register
|
|
213 lda #S$FrcInt "Force Interrupt" command
|
|
214 sta ,x send to FDC
|
|
215 lbsr FDCDelay time delay for ~ 108 cycles
|
|
216 lda ,x eat status register
|
|
217 ldd #$FF*256+N.Drives 'invalid' value & # of drives
|
|
218 leax DRVBEG,u point to start of drive tables
|
|
219 l1 sta ,x DD.TOT MSB to bogus value
|
|
220 sta <V.TRAK,x init current track # to bogus value
|
|
221 leax <DRVMEM,x point to next drive table
|
|
222 decb done all drives yet?
|
|
223 bne l1 no, init them all
|
|
224 leax >NMISvc,pc point to NMI service routine
|
|
225 IFGT Level-1
|
|
226 stx <D.NMI install as system NMI
|
|
227 ELSE
|
|
228 stx >D.XNMI+1 NMI jump vector operand
|
|
229 lda #$7E JMP code
|
|
230 sta >D.XNMI NMI jump vector opcode
|
|
231 ENDC
|
|
232 pshs y save device dsc. ptr
|
|
233 leay >u00B5,u point to Vi.Stat in VIRQ packet
|
|
234 tfr y,d make it the status register ptr for IRQ
|
|
235 leay >IRQSvc,pc point to IRQ service routine
|
|
236 leax >IRQPkt,pc point to IRQ packet
|
|
237 os9 F$IRQ install IRQ
|
|
238 puls y Get back device dsc. ptr
|
|
239 bcs Return If we can't install IRQ, exit
|
|
240 ldd #512 Request 512 byte sector buffer
|
|
241 pshs u Preserve device mem ptr
|
|
242 os9 F$SRqMem Request sector buffer
|
|
243 tfr u,x Move ptr to sector buffer to x
|
|
244 puls u Restore device mem ptr
|
|
245 bcs Return If error, exit with it
|
|
246 stx >sectbuf,u Save ptr to sector buffer
|
|
247
|
|
248 * GetStat
|
|
249 *
|
|
250 * Entry:
|
|
251 * A = function code
|
|
252 * Y = address of path descriptor
|
|
253 * U = address of device memory area
|
|
254 *
|
|
255 * Exit:
|
|
256 * CC = carry set on error
|
|
257 * B = error code
|
|
258 *
|
|
259 GetStat clrb no GetStt calls - return, no error, ignore
|
|
260 Return rts
|
|
261
|
|
262 * Term
|
|
263 *
|
|
264 * Entry:
|
|
265 * U = address of device memory area
|
|
266 *
|
|
267 * Exit:
|
|
268 * CC = carry set on error
|
|
269 * B = error code
|
|
270 *
|
|
271 Term leay >VIRQPak,u Point to VIRQ packet
|
|
272 IFNE H6309
|
|
273 tfr 0,x "remove"
|
|
274 ELSE
|
|
275 ldx #$0000
|
|
276 ENDC
|
|
277 os9 F$VIRQ Remove VIRQ
|
|
278 IFNE H6309
|
|
279 tfr 0,x "remove"
|
|
280 ELSE
|
|
281 ldx #$0000
|
|
282 ENDC
|
|
283 leay >IRQSvc,pc point to IRQ service routine
|
|
284 os9 F$IRQ Remove IRQ
|
|
285 pshs u Save device mem ptr
|
|
286 ldu >sectbuf,u Get pointer to sector buffer
|
|
287 ldd #512 Return sector buffer memory
|
|
288 os9 F$SRtMem
|
|
289 puls u Restore device mem ptr
|
|
290 clr >DPort+CtrlReg shut off drive motors
|
|
291 IFEQ Level-1
|
|
292 clr >D.DskTmr Clear out drive motor timeout flag
|
|
293 ELSE
|
|
294 clr <D.MotOn Clear out drive motor timeout flag
|
|
295 ENDC
|
|
296 ex rts return
|
|
297
|
|
298 * Check if 512 byte sector conversion needed
|
|
299 * Entry: B:X=LSN
|
|
300 * U=Static mem ptr
|
|
301 * Y=Path dsc. ptr
|
|
302 * Exit: X=New LSN (same as original for 256 byte sectors, 1/2 of original
|
|
303 * for 512 byte sectors
|
|
304 * regD changed
|
|
305 Chk512 equ *
|
|
306 clr flag512,u set to 256 byte sector
|
|
307 stx >loglsn,u save OS9 LSN
|
|
308 lda <PD.TYP,y get device type from path dsc.
|
|
309 anda #%00000100 mask out all but 512 byte sector flag
|
|
310 bne Log2Phys 512 byte sectors, go process
|
|
311 rts RG
|
|
312
|
|
313 * 512 byte sector processing goes here
|
|
314 * regB should be saved and not just cleared at end because there is
|
|
315 * a subsequent tst for the msb of lsn. The test is pointless if B
|
|
316 * is changed.
|
|
317 Log2Phys pshs b save MSB of LSN; new RG
|
|
318 * Minor inefficiencies here that I have changed, RG
|
|
319 tfr x,d
|
|
320 IFNE H6309
|
|
321 lsrd
|
|
322 ELSE
|
|
323 lsra
|
|
324 rorb
|
|
325 ENDC
|
|
326 tfr d,x move new LSN back to regX
|
|
327 * New line for stock SCII controller with 256 max no-halt.
|
|
328 inc flag512,u set to 512 byte sector
|
|
329 puls b,pc regB will be tested later for >0
|
|
330
|
|
331 start lbra Init
|
|
332 bra Read
|
|
333 nop
|
|
334 lbra Write
|
|
335 bra GetStat
|
|
336 nop
|
|
337 lbra SetStat
|
|
338 bra Term
|
|
339 nop
|
|
340
|
|
341 * Read
|
|
342 *
|
|
343 * Entry:
|
|
344 * B = MSB of LSN
|
|
345 * X = LSB of LSN
|
|
346 * Y = address of path descriptor
|
|
347 * U = address of device memory area
|
|
348 *
|
|
349 * Exit:
|
|
350 * CC = carry set on error
|
|
351 * B = error code
|
|
352 *
|
|
353 Read bsr Chk512 go check for 512 byte sector/adjust if needed
|
|
354 lda #%10010001 error flags (see Disto SCII source)
|
|
355 pshs x preserve sector #
|
|
356 lbsr ReadWithRetry go read the sector
|
|
357 puls x restore sector #
|
|
358 bcs ex if error, exit
|
|
359 pshs y,x save path dsc ptr & LSN
|
|
360 leax ,x LSN0?, ie. tstx
|
|
361 bne L012D no, go calculate normally
|
|
362 puls y,x yes, restore path dsc ptr & LSN
|
|
363 lda <PD.TYP,y get type from path dsc.
|
|
364 bita #TYP.NSF standard OS-9 format?
|
|
365 beq L00F0 yes, skip ahead
|
|
366 lbsr MakeDTEntry else make a drive table entry
|
|
367 pshs y,x save path dsc ptr
|
|
368 bra L012D
|
|
369
|
|
370 * LSN0, standard OS-9 format - copy part of LSN0 into drive table
|
|
371 L00F0 ldx >sectbuf,u Get ptr to sector buffer
|
|
372 pshs y,x Preserve path dsc. ptr & sector buffer ptr
|
|
373 ldy >lastdrv,u Get last drive table accessed ptr
|
|
374 IFNE H6309
|
|
375 ldw #DD.SIZ # bytes to copy from new LSN0 to drive table
|
|
376 tfm x+,y+ Copy them
|
|
377 ELSE
|
|
378 ldb #DD.SIZ
|
|
379 L00F0Lp lda ,x+
|
|
380 sta ,y+
|
|
381 decb
|
|
382 bne L00F0Lp
|
|
383 ENDC
|
|
384 ldy >lastdrv,u Get drive table ptr back
|
|
385 lda <DD.FMT,y Get format for disk in drive
|
|
386 ldy 2,s restore path descriptor pointer
|
|
387 ldb <PD.DNS,y Get path's density settings
|
|
388 bita #FMT.DNS Disk in drive double density?
|
|
389 beq L0115 No, all drives can read single, skip ahead
|
|
390 bitb #DNS.MFM Can our path dsc. handle double density?
|
|
391 beq erbtyp No, illegal
|
|
392 L0115 bita #FMT.TDNS Is new disk 96/135 tpi?
|
|
393 beq L011D No, all drives handle 48 tpi, so skip ahead
|
|
394 bitb #DNS.DTD Can path dsc. handle 96/135 tpi?
|
|
395 beq erbtyp No, illegal
|
|
396 L011D bita #FMT.SIDE Is new disk double sided?
|
|
397 beq L0128 No, all drives handle single sided, we're done
|
|
398 lda <PD.SID,y Get # sides path dsc. can handle
|
|
399 suba #2 sides higher or equal to 2?
|
|
400 blo erbtyp Yes, exit with illegal type error
|
|
401 L0128 clrb No error
|
|
402 * LSN's other than 0 come straight here
|
|
403 L012D ldy 2,s Get path dsc. ptr back??
|
|
404 ldx PD.BUF,y Get path dsc. buffer ptr
|
|
405 * lda <PD.TYP,y Get path dsc. disk type, RG
|
|
406 ldy >sectbuf,u Get ptr to sector buffer
|
|
407 IFNE H6309
|
|
408 ldw #256 OS9 sector size (even if physical was 512)
|
|
409 ENDC
|
|
410 * anda #%00000100 Mask out all but 512 byte sector flag, RG
|
|
411 * Next replaces the two lines removed, RG
|
|
412 tst flag512,u Is it a 512 byte sector?
|
|
413 beq L014B If normal sector, just copy it
|
|
414 ldd >loglsn,u Get OS9's LSN (twice of the 'real' 512 sector)
|
|
415 andb #$01 Mask out all but odd/even sector indicator
|
|
416 beq L014B Even, use 1st half of 512 byte sector
|
|
417 IFNE H6309
|
|
418 addr w,y Odd, bump sector buffer ptr to 2nd half
|
|
419 ELSE
|
|
420 leay 256,y
|
|
421 ENDC
|
|
422 L014B equ *
|
|
423 IFNE H6309
|
|
424 tfm y+,x+ Copy from physical sector buffer to PD buffer
|
|
425 puls pc,y,x restore path dsc & sector buffer ptrs & return
|
|
426 ELSE
|
|
427 pshs d
|
|
428 clrb
|
|
429 L014BLp lda ,y+
|
|
430 sta ,x+
|
|
431 decb
|
|
432 bne L014BLp
|
|
433 puls pc,y,x,d restore path dsc & sector buffer ptrs & return
|
|
434 ENDC
|
|
435
|
|
436 erbtyp comb
|
|
437 ldb #E$BTyp Error - wrong type error
|
|
438 puls pc,y,x
|
|
439
|
|
440 **********************
|
|
441 * Read error - retry handler
|
|
442 Retry
|
|
443 bcc ReadWithRetry Normal retry, try reading again
|
|
444 pshs x,d Preserve regs
|
|
445 lbsr sktrk0 Seek to track 0 (attempt to recalibrate)
|
|
446 puls x,d Restore regs & try reading again
|
|
447
|
|
448
|
|
449 * Read With Retry: Do read with retries
|
|
450 *
|
|
451 * ENTER reg B,X=working lsn on disk
|
|
452 * Y=path descriptor
|
|
453 * U=driver data
|
|
454 * A=retry sequence mix of read & seek track 0
|
|
455 * EXIT X,Y,U preserved; D,CC changed
|
|
456 * B=error if any
|
|
457 * CC=error flag
|
|
458 ReadWithRetry
|
|
459 pshs x,d Preserve regs
|
|
460 bsr ReadSector Go read sector
|
|
461 puls x,d Restore regs (A=retry flags)
|
|
462 lbcc L01D7 No error, return
|
|
463 lsra Shift retry flags
|
|
464 bne Retry Still more retries allowed, go do them
|
|
465 * otherwise, final try before we give up
|
|
466 ReadSector
|
|
467 lbsr L02AC Do double-step/precomp etc. if needed, seek
|
|
468 lbcs L01D7 Error somewhere, exit with it
|
|
469 L0176 ldx >sectbuf,u Get physical sector buffer ptr
|
|
470 ldb #S$Read Read sector command
|
|
471 IFNE SCII
|
|
472 * If SCII not hacked for 512 byte no-halt, must use halt for 512b sectors RG
|
|
473 IFEQ SCIIHACK
|
|
474 clra SCII normal mode, normal NMI
|
|
475 tst flag512,u SCII must use halt mode for 512 byte sectors
|
|
476 bne L0176B
|
|
477 ENDC
|
|
478 lda #7 SCII read, buffered mode, masked NMI
|
|
479 bsr L01A1B send commands and wait
|
|
480 * New lines needed because the SCII has error other than OS-9 errors. RG
|
|
481 bcs ngood
|
|
482 * This now becomes a subroutine call. RG
|
|
483 * lbcs L03AF get the errors
|
|
484 lbsr L03AF get the errors
|
|
485 bcc good
|
|
486 ngood rts
|
|
487
|
|
488 good pshs y
|
|
489 IFNE H6309
|
|
490 ldw #256 set counter
|
|
491 ldy #RW.DAT source of data
|
|
492 IFNE SCIIHACK
|
|
493 tst flag512,u
|
|
494 beq sc2rlp
|
|
495 ldw #512 bump up counter to 512 byte sector
|
|
496 ENDC
|
|
497 * Don't use tfm if no halt important else need orcc #$50 for tfm
|
|
498 * If an interrupt occurs during a tfm transfer, the SCII counter
|
|
499 * will update but the tfm will repeat a byte and lose track.
|
|
500 * If orcc #$50 used, then key presses may be lost even with no-halt
|
|
501 * mode.
|
|
502 sc2rlp lda ,y read byte from SCII
|
|
503 sta ,x+ transfer byte to system buffer
|
|
504 decw update counter
|
|
505 bne sc2rlp
|
|
506 ELSE
|
|
507 ldy #256
|
|
508 IFNE SCIIHACK
|
|
509 tst flag512,u
|
|
510 beq sc2rlp
|
|
511 ldy #512
|
|
512 ENDC
|
|
513 sc2rlp lda >RW.DAT
|
|
514 sta ,x+
|
|
515 leay -1,y
|
|
516 bne sc2rlp
|
|
517 ENDC
|
|
518 clrb no errors
|
|
519 puls y,pc
|
|
520 ENDC
|
|
521
|
|
522 L0176B bsr L01A1 Send to controller & time delay to let it settle
|
|
523 *** Next few lines are commented out for blobstop patches
|
|
524 *L0180 bita >DPort+WD_Stat check status register
|
|
525 * bne L0197 eat it & start reading sector
|
|
526 * leay -1,y bump timeout timer down
|
|
527 * bne L0180 keep trying until it reaches 0 or sector read
|
|
528 * lda >ctlimg,u get current drive settings
|
|
529 * ora #C_MOTOR turn drive motor on
|
|
530 * sta >DPort+CtrlReg send to controller
|
|
531 * puls y,cc restore regs
|
|
532 * lbra L03E0 exit with Read Error
|
|
533 *** Blobstop fixes
|
|
534 stb >DPort+CtrlReg send B to control register
|
|
535 nop allow HALT to take effect
|
|
536 nop
|
|
537 bra L0197 and a bit more time
|
|
538 * Read loop - exited with NMI
|
|
539 * Entry: X=ptr to sector buffer
|
|
540 * B=Control register settings
|
|
541 L0197 lda >DPort+WD_Data get byte from controller
|
|
542 sta ,x+ store into sector buffer
|
|
543 * stb >DPort+CtrlReg drive info
|
|
544 nop -- blobstop fix
|
|
545 bra L0197 Keep reading until sector done
|
|
546
|
|
547 L01A1 orcc #IntMasks Shut off IRQ & FIRQ
|
|
548 * No-halt mode must enter here, skipping IRQ shutoff.
|
|
549 L01A1B stb >DPort+WD_Cmd Send command
|
|
550 IFNE SCII
|
|
551 sta >RW.Ctrl tell SCII what to do
|
|
552 ENDC
|
|
553 L01A1C ldb #C_DBLDNS+C_MOTOR Double density & motor on
|
|
554 orb >ctlimg,u Merge with current drive settings
|
|
555 stb >DPort+CtrlReg Send to control register
|
|
556 IFNE SCII
|
|
557 tst flagform,u Format uses halt mode
|
|
558 bne s512
|
|
559 IFEQ SCIIHACK
|
|
560 tst flag512,u SCII uses halt with 512 byte sectors
|
|
561 beq s256
|
|
562 ELSE
|
|
563 bra s256
|
|
564 ENDC
|
|
565 ENDC
|
|
566 s512 ldb #C_HALT+C_DBLDNS+C_MOTOR Enable halt, double density & motor on
|
|
567 orb >ctlimg,u Merge that with current drive settings
|
|
568 lbra FDCDelay Time delay to wait for command to settle
|
|
569 IFNE SCII
|
|
570 s256 ldb #4 normal mode, NMI masked
|
|
571 lda #255 time out slices
|
|
572 pshs a,x
|
|
573 SC2tmr1 ldx #1
|
|
574 lbsr Delay sleep or timer
|
|
575 dec ,s count
|
|
576 beq tmout
|
|
577 tst >RW.Ctrl check status
|
|
578 bmi SC2tmr1 loop on not ready
|
|
579 stb RW.Ctrl clear SCII but don't generate NMI
|
|
580 clrb
|
|
581 puls a,x,pc
|
|
582 tmout stb RW.Ctrl clear SCII buffer counter
|
|
583 lda #$D0 force interrupt
|
|
584 sta DPort+WD_Cmd
|
|
585 comb set carry
|
|
586 puls a,x,pc
|
|
587 ENDC
|
|
588
|
|
589 * Delay for some number of ticks (1 tick = 1/60 second).
|
|
590 * For a hard delay, we need to delay for 14833 cycles at .89MHz or
|
|
591 * 29666 cycles at 1.78MHz
|
|
592 * Entry: X = number of ticks to delay
|
|
593 Delay
|
|
594 pshs d [5+] [4+]
|
|
595 IFGT Level-1
|
|
596 ldd <D.Proc [6] [5] process pointer
|
|
597 cmpd <D.SysPrc [is it the system?
|
|
598 beq hardloop [3] [3]
|
|
599 os9 F$Sleep if not system then sleep
|
|
600 puls d,pc [5+] [4+]
|
|
601 ENDC
|
|
602 hardloop tfr x,d we want X in A,B
|
|
603 l1@ equ *
|
|
604 IFEQ Level-1
|
|
605 ldx #1482/2 [3] [3]
|
|
606 ELSE
|
|
607 IFNE H6309
|
|
608 ldx #1854 [3] [3]
|
|
609 ELSE
|
|
610 ldx #1482 [3] [3]
|
|
611 ENDC
|
|
612 ENDC
|
|
613 l2@ nop [2] [1]
|
|
614 nop [2] [1]
|
|
615 nop [2] [1]
|
|
616 leax -1,x [4+] [4+]
|
|
617 bne l2@ [3] [3]
|
|
618 subd #$0001 [4] [3]
|
|
619 bne l1@ [3] [3]
|
|
620 puls d,pc [5+] [4+]
|
|
621
|
|
622 * Write
|
|
623 * Entry:
|
|
624 * B = MSB of LSN
|
|
625 * X = LSB of LSN
|
|
626 * Y = address of path descriptor
|
|
627 * U = address of device memory area
|
|
628 *
|
|
629 * Exit:
|
|
630 * CC = carry set on error
|
|
631 * B = error code
|
|
632 *
|
|
633 Write lbsr Chk512 go adjust LSN for 512 byte sector if needed
|
|
634 * Next line was lda #%1001001 which was an error RG
|
|
635 lda #%10010001 retry flags for I/O errors (see Disto SCII source)
|
|
636 L01C4 pshs x,d preserve LSN, retries
|
|
637 bsr L01E8 go write the sector
|
|
638 puls x,d restore LSN, retries
|
|
639 bcs L01D8 error writing, go to write retry handler
|
|
640 tst <PD.VFY,y no error, do we want physical verify?
|
|
641 bne L01D6 no, exit without error
|
|
642 lbsr verify go re-read & verify 64 out of 256 bytes
|
|
643 bcs L01D8 error on verify, go to write retry handler
|
|
644 L01D6 clrb no error & return
|
|
645 L01D7 rts
|
|
646
|
|
647 * Write error retry handler
|
|
648 L01D8 lsra Shift retry flags
|
|
649 lbeq L03AF Too many retries, exit with error
|
|
650 bcc L01C4 Normal retry, attemp to re-write sector
|
|
651 pshs x,d Preserve flags & sector #
|
|
652 lbsr sktrk0 Seek to track 0 (attempt to recalibrate)
|
|
653 puls x,d Restore flags & sector #
|
|
654 bra L01C4 Try re-writing now
|
|
655
|
|
656 * 512 byte sector write here
|
|
657 L01E8 lbsr L02AC Go do double-step/write precomp if needed
|
|
658 bcs L01D7 Error, exit with it
|
|
659 pshs y,d Preserve path dsc. ptr & LSN
|
|
660 * Since I have modified chk512 the next two lines are replaced. RG
|
|
661 * lda <PD.TYP,y Get device type
|
|
662 * anda #%00000100 512 byte sector?
|
|
663 tst flag512,u go if 256 byte sectors
|
|
664 beq L020D Not 512 then skip ahead
|
|
665 lbsr L0176 Go read the sector in
|
|
666 ldd >loglsn,u Get OS9 LSN
|
|
667 andb #$01 Even or odd?
|
|
668 beq L020D Even, skip ahead
|
|
669 ldx >sectbuf,u Get physical sector buffer ptr
|
|
670 leax >$0100,x Point to 2nd half
|
|
671 bra L0211 Copy caller's buffer to 2nd half of sector
|
|
672
|
|
673 L020D ldx >sectbuf,u Get physical sector buffer ptr
|
|
674
|
|
675 L0211 ldy PD.BUF,y Get path dsc. buffer ptr
|
|
676 IFNE H6309
|
|
677 ldw #256 Copy write buffer to sector buffer
|
|
678 tfm y+,x+
|
|
679 ELSE
|
|
680 clrb
|
|
681 L0211Lp lda ,y+
|
|
682 sta ,x+
|
|
683 decb
|
|
684 bne L0211Lp
|
|
685 ENDC
|
|
686 puls y,d Get path dsc. ptr & LSN back
|
|
687 ldx >sectbuf,u Get physical sector buffer ptr again
|
|
688 * See read routine for explanation of SCII code. RG
|
|
689 IFNE SCII
|
|
690 IFEQ SCIIHACK
|
|
691 clra SCII write, normal mode & NMI
|
|
692 tst flag512,u
|
|
693 bne wr512
|
|
694 ENDC
|
|
695 lda #4 SCII normal mode, masked NMI
|
|
696 sta RW.Ctrl tell SCII
|
|
697 pshs y
|
|
698 ldy #RW.Dat Send data to SCII RAM buffer
|
|
699 IFNE H6309
|
|
700 ldw #256
|
|
701 tst flag512,u
|
|
702 beq wrbuf
|
|
703 ldw #512
|
|
704 wrbuf lda ,x+
|
|
705 sta ,y
|
|
706 decw
|
|
707 bne wrbuf
|
|
708 ELSE
|
|
709 ldy #256
|
|
710 tst flag512,u
|
|
711 beq wrbuf
|
|
712 ldy #512
|
|
713 wrbuf lda ,x+
|
|
714 sta >RW.DAT
|
|
715 leay -1,y
|
|
716 bne wrbuf
|
|
717 ENDC
|
|
718 puls y
|
|
719 ldb #$A0 Write sector command
|
|
720 lda #6 SCII masked NMI, buffered mode, write
|
|
721 * See Read section for explanation of error changes below. RG
|
|
722 * lbra L01A1B send command to controller
|
|
723 lbsr L01A1B send command to controller
|
|
724 bcs wngood SCII error, then go
|
|
725 lbra L03AF check for OS-9 errors
|
|
726 wngood rts
|
|
727 ENDC
|
|
728 wr512 ldb #S$Format
|
|
729
|
|
730 * Format track comes here with B=$F0 (write track)
|
|
731 * as does write sector with B=$A0
|
|
732 *WrTrk pshs y,cc Preserve path dsc. ptr & CC
|
|
733 WrTrk lbsr L01A1 Send command to controller (including delay)
|
|
734 *** Commented out for blobstop fixes
|
|
735 *L0229 bita >DPort+WD_Stat Controller done yet?
|
|
736 * bne L0240 Yes, go write sector out
|
|
737 * leay -$01,y No, bump wait counter
|
|
738 * bne L0229 Still more tries, continue
|
|
739 * lda >ctlimg,u Get current drive control register settings
|
|
740 * ora #C_MOTOR Drive motor on (but drive select off)
|
|
741 * sta >DPort+CtrlReg Send to controller
|
|
742 * puls y,cc Restore regs
|
|
743 * lbra L03AF Check for errors from status register
|
|
744
|
|
745 *** added blobstop
|
|
746 IFGT Level-1
|
|
747 lda FBlock+1,u get the block number for format
|
|
748 beq L0230 if not format, don't do anything
|
|
749 sta >$FFA1 otherwise map the block in
|
|
750 * added delay for for MMU line settling. RG 2005/1/23
|
|
751 nop
|
|
752 nop
|
|
753 ENDC
|
|
754 L0230 stb >DPort+CtrlReg send data to control register
|
|
755 * These lines converted to separate sector writes from format. RG
|
|
756 * nop
|
|
757 * nop
|
|
758 cmpb #$F0 if format, then
|
|
759 beq L0240b go to special loop
|
|
760 bra L0240 wait a bit for HALT to enable
|
|
761
|
|
762 * Write sector routine (Entry: B= drive/side select) (NMI will break out)
|
|
763 * Part of timing change mentioned above. RG
|
|
764 *L0240 nop --- wait a bit more
|
|
765 L0240 lda ,x+ Get byte from write buffer
|
|
766 sta >DPort+WD_Data Save to FDC's data register
|
|
767 * EAT 2 CYCLES: TC9 ONLY (TRY 1 CYCLE AND SEE HOW IT WORKS)
|
|
768 IFEQ TC9-1
|
|
769 nop
|
|
770 nop
|
|
771 ELSE
|
|
772 * See above. RG
|
|
773 nop
|
|
774 ENDC
|
|
775 * stb >DPort+CtrlReg Set up to read next byte
|
|
776 bra L0240 Go read it
|
|
777 * Special loop for format slows CPU clock. RG
|
|
778 L0240b sta >$FFD8
|
|
779 L0240c lda ,x+
|
|
780 sta >DPort+WD_Data
|
|
781 bra L0240b
|
|
782 * NMI routine
|
|
783 NMISvc leas R$Size,s Eat register stack
|
|
784 * Added to compensate above change in format loop. RG
|
|
785 sta >$FFD9
|
|
786 IFGT Level-1
|
|
787 ldx <D.SysDAT get pointer to system DAT image
|
|
788 lda 3,x get block number 1
|
|
789 sta >$FFA1 map it back into memory
|
|
790 ENDC
|
|
791 andcc #^IntMasks turn IRQ's on again
|
|
792 ldb >DPort+WD_Stat Get status register
|
|
793 IFNE SCII
|
|
794 clr RW.Ctrl Clear SCII command register
|
|
795 ENDC
|
|
796 bitb #%00000100 Did we lose data in the transfer?
|
|
797 lbeq L03B2 Otherwise, check for drive errors
|
|
798 comb -- blobstop error code
|
|
799 ldb #E$DevBsy -- device busy
|
|
800 rts -- and exit
|
|
801
|
|
802 verify pshs x,d
|
|
803 * Removed unneeded code. Data never sent to PD.BUF anyway so there is
|
|
804 * no need to redirect the PD.BUF pointer. RG
|
|
805 * ldx PD.BUF,y Get write buffer ptr
|
|
806 * pshs x Preserve it
|
|
807 * ldx >sectbuf,u Get sector buffer ptr
|
|
808 * stx PD.BUF,y Save as write buffer ptr
|
|
809 * ldx 4,s
|
|
810 lbsr ReadSector Go read sector we just wrote
|
|
811 * puls x Get original write buffer ptr
|
|
812 * stx PD.BUF,y Restore path dsc. version
|
|
813 bcs L02A3 If error reading, exit with it
|
|
814 ldx PD.BUF,y Get system buffer ptr
|
|
815 pshs u,y Preserve device mem, path dsc. ptrs
|
|
816 * See change in chk512 routine. RG
|
|
817 * ldb <PD.TYP,y Get type from path dsc.
|
|
818 ldy >sectbuf,u Get sector buffer ptr
|
|
819 * andb #%00000100 512 byte sector?
|
|
820 tst flag512,u 512 byte sector?
|
|
821 beq L028D No, skip ahead
|
|
822 ldd >loglsn,u Get OS9's sector #
|
|
823 andb #$01 Odd/even sector?
|
|
824 beq L028D Even; compare first half
|
|
825 leay >$0100,y Odd, compare second half
|
|
826 L028D tfr x,u Move PD.BUF ptr to U (since cmpx is faster)
|
|
827 clra check all 256 bytes
|
|
828 L028F ldx ,u++ Get 2 bytes from original write buffer
|
|
829 cmpx ,y++ Same as corresponding bytes in re-read sector?
|
|
830 bne vfybad No, error & return
|
|
831 inca
|
|
832 bpl L028F No, continue
|
|
833 bra L02A1 carry is clear by virtue of last cmpx
|
|
834 vfybad comb set carry
|
|
835 L02A1 puls u,y
|
|
836 L02A3 puls pc,x,d
|
|
837
|
|
838 L02A5 pshs a Save Caller's track #
|
|
839 ldb <V.TRAK,x Get track # drive is currently on
|
|
840 bra L02E9 Go save it to controller & continue
|
|
841
|
|
842 L02AC lbsr L0376 Go set up controller for drive, spin motor up
|
|
843 bsr L032B Get track/sector # (A=Trk, B=Sector)
|
|
844 pshs a Save track #
|
|
845 lda >currside,u Get side 1/2 flag
|
|
846 beq L02C4 Side 1, skip ahead
|
|
847 lda >ctlimg,u Get control register settings
|
|
848 ora #C_SIDSEL Set side 2 (drive 3) select
|
|
849 sta >ctlimg,u Save it back
|
|
850 L02C4 lda <PD.TYP,y Get drive type settings
|
|
851 bita #%00000010 ??? (Base 0/1 for sector #?)
|
|
852 bne L02CC Skip ahead
|
|
853 incb Bump sector # up by 1
|
|
854 L02CC stb >DPort+WD_Sect Save into Sector register
|
|
855 ldx >lastdrv,u Get last drive table accessed
|
|
856 ldb <V.TRAK,x Get current track # on device
|
|
857 lda <DD.FMT,x Get drive format specs
|
|
858 lsra Shift track & bit densities to match PD
|
|
859 eora <PD.DNS,y Check for differences with path densities
|
|
860 anda #%00000010 Keep only 48 vs. 96/135 tpi differences
|
|
861 pshs a Save differences
|
|
862 lda 1,s Get track # back
|
|
863 tst ,s+ Are tpi's different?
|
|
864 beq L02E9 No, continue normally
|
|
865 lsla Yes, multiply track # by 2 ('double-step')
|
|
866 lslb Multiply current track # by 2 ('double-step')
|
|
867 L02E9 stb >DPort+WD_Trak Save current track # onto controller
|
|
868
|
|
869 * From here to the line before L0307 is for write precomp, but is not used.
|
|
870 * Unless write precomp is needed, all of this is useless
|
|
871 * I think most (if not all) drives do NOT need precomp
|
|
872 IFEQ PRECOMP-1
|
|
873 ldb #21 Pre-comp track #
|
|
874 pshs b Save it
|
|
875 ldb <PD.DNS,y Get current density settings
|
|
876 andb #%00000010 Just want to check track density
|
|
877 beq L02F9 48 tpi, skip ahead
|
|
878 lsl ,s Multiply pre-comp value by 2 ('double-step')
|
|
879 L02F9 cmpa ,s+ Is track # high enough to warrant precomp?
|
|
880 bls L0307 No, continue normally
|
|
881 ldb >ctlimg,u
|
|
882 orb #C.WRPCMP Turn on Write precomp
|
|
883 stb >ctlimg,u
|
|
884 ENDC
|
|
885
|
|
886 L0307 tst >u00AA,u ??? Get flag (same drive flag?)
|
|
887 bne L0314 no, skip ahead
|
|
888 ldb ,s get track #
|
|
889 cmpb <V.TRAK,x same as current track on this drive?
|
|
890 beq L0321 yes, skip ahead
|
|
891 L0314 sta >DPort+WD_Data save track # to data register
|
|
892 ldb <PD.STP,y get stepping rate
|
|
893 andb #%00000011 just keep usable settings (6-30 ms)
|
|
894 eorb #%00011011 set proper bits for controller
|
|
895 lbsr L03E4 send command to controller & time delay
|
|
896 L0321 puls a get track # back
|
|
897 sta <V.TRAK,x save as current track #
|
|
898 sta >DPort+WD_Trak save to controller
|
|
899 clrb no error & return
|
|
900 rts
|
|
901
|
|
902 * Entry: B:X LSN
|
|
903 * Exit: A=Track #
|
|
904 * B=Sector #
|
|
905 * <currside=00 = Head 1 , $FF = Head 2
|
|
906 L032B tstb Sector # > 65535?
|
|
907 bne L033F Yes, illegal for floppy
|
|
908 tfr x,d Move sector # to D
|
|
909 leax ,x LSN 0? ie. "tstx"
|
|
910 beq L0371 Yes, exit this routine
|
|
911 ldx >lastdrv,u Get previous drive table ptr
|
|
912 cmpd DD.TOT+1,x Within range of drive spec?
|
|
913 blo L0343 Yes, go calculate track/sector #'s
|
|
914 L033F comb Exit with Bad sector # error
|
|
915 ldb #E$Sect
|
|
916 rts
|
|
917
|
|
918 * Calculate track/sector #'s?
|
|
919 * These two sections could be combined into one with a final
|
|
920 * test of DD.FMT. Then currside can be set and regA can be lsra
|
|
921 * as needed. RG
|
|
922 L0343 stb >u00AE,u Save LSB of LSN
|
|
923 clr ,-s Clear track # on stack
|
|
924 ldb <DD.FMT,x Get drive format
|
|
925 lsrb Shift out # sides into carry
|
|
926 ldb >u00AE,u Get LSB of LSN again
|
|
927 bcc L0367 Single sided drive, skip ahead
|
|
928 bra L035D Double sided drive, skip ahead
|
|
929 * Double sided drive handling here
|
|
930 L0355 com >currside,u Odd/even sector track flag
|
|
931 bne L035D Odd, so don't bump track # up
|
|
932 inc ,s Bump up track #
|
|
933
|
|
934 * Changed this to more effient code. RG
|
|
935 *L035D subb DD.TKS,x Subtract # sectors/track
|
|
936 * sbca #$00
|
|
937 L035D subd DD.SPT,x
|
|
938 bcc L0355 Still more sectors left, continue
|
|
939 bra L036D Wrapped, skip ahead
|
|
940 * Single sided drive handling here
|
|
941 L0365 inc ,s Bump track # up
|
|
942
|
|
943 * See above. RG
|
|
944 *L0367 subb DD.TKS,x Subtract # sectors/track
|
|
945 * sbca #$00
|
|
946 L0367 subd DD.SPT,x
|
|
947 bcc L0365 Still more, go bump the track up
|
|
948 * Next possible because upper limit is 256 sectors/track. RG
|
|
949 L036D addb DD.TKS,x Bump sector # back up from negative value
|
|
950 puls a Get the track #
|
|
951 L0371 rts A=track #, B=Sector #, <currside=Odd
|
|
952
|
|
953 * Drive control register bit mask table
|
|
954 * May want an option here for double sided SDDD disks ex. RG
|
|
955 * fcb $1 drive0
|
|
956 * fcb $2 drive1
|
|
957 * fcb $41 drive2
|
|
958 * fcb $42 drive3
|
|
959 * fcb $4 drive4
|
|
960 * fcb $44 drive5
|
|
961
|
|
962 L0372 fcb $01 Drive 0
|
|
963 fcb $02 Drive 1
|
|
964 fcb $04 Drive 2
|
|
965 fcb $40 Drive 3 / Side select
|
|
966
|
|
967 * Changes regD; X,Y,U preserved
|
|
968 L0376 clr >u00AA,u clear drive change flag
|
|
969 chkdrv lda <PD.DRV,y Get drive # requested
|
|
970 * It is possible to have more than 4 drive # so the change below. RG
|
|
971 * cmpa #4 Drive 0-3?
|
|
972 cmpa #N.Drives Drive 0-6 if alternate table used?
|
|
973 blo L0385 Yes, continue normally
|
|
974 NoHW comb Illegal drive # error
|
|
975 ldb #E$Unit
|
|
976 rts
|
|
977
|
|
978 * Entry: A=drive #, X=LSN (Physical, not OS9 logical if PCDOS disk)
|
|
979 L0385 pshs x,d Save sector #, drive # & B???
|
|
980 leax >L0372,pc Point to drive bit mask table
|
|
981 ldb a,x Get bit mask for drive # we want
|
|
982 stb >ctlimg,u Save mask
|
|
983 leax DRVBEG,u Point to beginning of drive tables
|
|
984 ldb #DRVMEM Get size of each drive table
|
|
985 mul Calculate offset to drive table we want
|
|
986 leax d,x Point to it
|
|
987 cmpx >lastdrv,u Same as Last drive table accessed?
|
|
988 beq L03A6 Yes, skip ahead
|
|
989 stx >lastdrv,u Save new drive table ptr
|
|
990 com >u00AA,u Set drive change flag
|
|
991 L03A6 clr >currside,u Set side (head) flag to side 1
|
|
992 lbsr L04B3 Go set up VIRQ to wait for drive motor
|
|
993 puls pc,x,d Restore sector #,drive #,B & return
|
|
994
|
|
995 L03AF ldb >DPort+WD_Stat Get status register from FDC
|
|
996 * This line needed when returning to Disk Basic but probably
|
|
997 * not needed for OS-9. RG
|
|
998 IFNE SCII
|
|
999 clr RW.Ctrl return SCII to halt mode
|
|
1000 ENDC
|
|
1001 L03B2 bitb #%11111000 any of the error bits set?
|
|
1002 beq L03CA No, exit without error
|
|
1003 aslb Drive not ready?
|
|
1004 bcs L03CC Yes, use that error code
|
|
1005 aslb Write protect error?
|
|
1006 bcs L03D0 Yes, use that error code
|
|
1007 aslb Write fault error?
|
|
1008 bcs L03D4 Yes, use that error code
|
|
1009 aslb Sector not found?
|
|
1010 bcs L03D8 Yes, use Seek error code
|
|
1011 aslb CRC error?
|
|
1012 bcs L03DC Yes, use that error code
|
|
1013 L03CA clrb No error & return
|
|
1014 rts
|
|
1015
|
|
1016 L03CC ldb #E$NotRdy not ready
|
|
1017 fcb $8C skip 2 bytes
|
|
1018
|
|
1019 L03D0 ldb #E$WP write protect
|
|
1020 fcb $8C skip 2 bytes
|
|
1021
|
|
1022 L03D4 ldb #E$Write write error
|
|
1023 fcb $8C
|
|
1024
|
|
1025 L03D8 ldb #E$Seek seek error
|
|
1026 fcb $8C
|
|
1027
|
|
1028 L03DC ldb #E$CRC CRC error
|
|
1029 * fcb $8C
|
|
1030
|
|
1031 *L03E0 ldb #E$Read Read error
|
|
1032 orcc #Carry set carry
|
|
1033 rts
|
|
1034
|
|
1035 L03E4 bsr L0404 Send command to controller & waste some time
|
|
1036 L03E6 ldb >DPort+WD_Stat Check FDC status register
|
|
1037 bitb #$01 Is controller still busy?
|
|
1038 beq L0403 No, exit
|
|
1039 ldd >VIRQCnt,pc Get initial count value for drive motor speed
|
|
1040 std >VIRQPak,u Save it
|
|
1041 * Again, I'm trying to match Kevin Darling code. It may not be needed. RG
|
|
1042 pshs x
|
|
1043 ldx #1 Sleep remainder of slice
|
|
1044 lbsr Delay
|
|
1045 puls x
|
|
1046 bra L03E6 Wait for controller to finish previous command
|
|
1047
|
|
1048 * Send command to FDC
|
|
1049 L03F7 lda #C_MOTOR
|
|
1050 * lda #%00001000 Mask in Drive motor on bit
|
|
1051 ora >ctlimg,u Merge in drive/side selects
|
|
1052 sta >DPort+CtrlReg Turn the drive motor on & select drive
|
|
1053 stb >DPort+WD_Cmd Save command & return
|
|
1054 L0403 rts
|
|
1055
|
|
1056 L0404 bsr L03F7 Go send command to controller
|
|
1057
|
|
1058 * This loop has been changed from nested LBSRs to timing loop.
|
|
1059 * People with crystal upgrades should modify the loop counter
|
|
1060 * to get a 58+ us delay time. MINIMUM 58us.
|
|
1061 FDCDelay
|
|
1062 pshs a 14 cycles, plus 3*loop counter
|
|
1063 IFEQ Level-1
|
|
1064 lda #18 (only do about a 100 cycle delay for now)
|
|
1065 ELSE
|
|
1066 lda #29 (only do about a 100 cycle delay for now)
|
|
1067 ENDC
|
|
1068 L0409 deca for total ~63 us delay (123 cycles max.)
|
|
1069 bne L0409
|
|
1070 puls a,pc restore register and exit
|
|
1071
|
|
1072 * SetStat
|
|
1073 *
|
|
1074 * Entry:
|
|
1075 * A = function code
|
|
1076 * Y = address of path descriptor
|
|
1077 * U = address of device memory area
|
|
1078 *
|
|
1079 * Exit:
|
|
1080 * CC = carry set on error
|
|
1081 * B = error code
|
|
1082 *
|
|
1083 SetStat ldx PD.RGS,y Get caller's register stack ptr
|
|
1084 ldb R$B,x Get function code
|
|
1085 cmpb #SS.WTrk Write track?
|
|
1086 beq SSWTrk Yes, go do it
|
|
1087 cmpb #SS.Reset Restore head to track 0?
|
|
1088 lbeq sktrk0 Yes, go do it --- beq
|
|
1089 comb set carry for error
|
|
1090 ldb #E$UnkSvc return illegal service request error
|
|
1091 rts
|
|
1092
|
|
1093 SSWTrk pshs u,y preserve register stack & descriptor
|
|
1094
|
|
1095 * Level 2 Code
|
|
1096 IFGT Level-1
|
|
1097
|
|
1098 *--- new code
|
|
1099 ldb #1 1 block to allocate
|
|
1100 os9 F$AllRAM allocate some RAM
|
|
1101 lbcs L0489 error out if at all
|
|
1102 leax >FBlock,u point to 'my' DAT image
|
|
1103 std ,x save a copy of the block
|
|
1104 os9 F$ResTsk reserve a task number for the copy
|
|
1105 bcs FError error out
|
|
1106 stb 2,x save temporary task number in FTask,u
|
|
1107 lslb 2 bytes per entry
|
|
1108 ldu <D.TskIPt get task image table pointer
|
|
1109 stx b,u save pointer to the task's DAT image
|
|
1110 lsrb get the right number again
|
|
1111 IFNE H6309
|
|
1112 tfr 0,u destination is address 0
|
|
1113 ELSE
|
|
1114 ldu #$0000
|
|
1115 ENDC
|
|
1116 *--- end new code
|
|
1117
|
|
1118 ldx 2,s get pointer to descriptor
|
|
1119 * stu >FBlock,x
|
|
1120 ldx <D.Proc Get current process ptr
|
|
1121 lda P$Task,x Get task # for current process
|
|
1122 * ldb <D.SysTsk Get system task #
|
|
1123 ldy ,s
|
|
1124 ldx PD.RGS,y Get register stack ptr
|
|
1125 ldx R$X,x Get ptr to caller's track buffer
|
|
1126 ldy #$1A00 Size of track buffer
|
|
1127 os9 F$Move Copy from caller to temporary task
|
|
1128 bcs L0479 Error copying, exit
|
|
1129 puls u,y
|
|
1130 pshs u,y
|
|
1131
|
|
1132 ENDC
|
|
1133 * End of Level 2 Code
|
|
1134
|
|
1135 lbsr L0376 Go check drive #/wait for it to spin up
|
|
1136 ldx PD.RGS,y Get caller's register stack ptr
|
|
1137 ldb R$Y+1,x Get caller's side/density
|
|
1138 bitb #$01 Check side
|
|
1139 beq L0465 Side 1, skip ahead
|
|
1140 * I think this next line is not needed. RG
|
|
1141 com >currside,u * Why? This is normally used with
|
|
1142 * calculate track. RG
|
|
1143 ldb >ctlimg,u Get current control register settings
|
|
1144 * orb #%01000000 Mask in side 2
|
|
1145 orb #C_SIDSEL Mask in side 2
|
|
1146 stb >ctlimg,u Save updated control register
|
|
1147 L0465 lda R$U+1,x Get caller's track #
|
|
1148 ldx >lastdrv,u Get current drive table ptr
|
|
1149 lbsr L02A5
|
|
1150 bcs L0489
|
|
1151 ldb #$F0 Write track command
|
|
1152 *---
|
|
1153 IFEQ Level-1
|
|
1154 ldx PD.RGS,y
|
|
1155 ldx R$X,x
|
|
1156 ELSE
|
|
1157 ldx #$2000 start writing from block 1
|
|
1158 ENDC
|
|
1159
|
|
1160 IFNE SCII
|
|
1161 lda #1 normal unbuffered write
|
|
1162 * Next line prevents WrTrk from switching to SCII buffered mode. RG
|
|
1163 sta flagform,u
|
|
1164 ENDC
|
|
1165 lbsr WrTrk Go write the track
|
|
1166 IFNE SCII
|
|
1167 clr flagform,u permit no-halt mode RG
|
|
1168 ENDC
|
|
1169
|
|
1170 IFGT Level-1
|
|
1171 L0479 ldu 2,s
|
|
1172 pshs b,cc Preserve error
|
|
1173 ldb >FTask,u point to task
|
|
1174 os9 F$RelTsk release the task
|
|
1175 fcb $8C skip 2 bytes
|
|
1176
|
|
1177 * format comes here when block allocation passes, but task allocation
|
|
1178 * gives error. So er de-allocate the block.
|
|
1179 FError
|
|
1180 pshs b,cc save error code, cc
|
|
1181 ldx >FBlock,u point to block
|
|
1182 ldb #1 1 block to return
|
|
1183 os9 F$DelRAM de-allocate image RAM blocks
|
|
1184 clr FBlock+1,u ensure that the block # in FBlock is zero.
|
|
1185 puls b,cc Restore error
|
|
1186 ENDC
|
|
1187
|
|
1188 L0489 puls pc,u,y Restore regs & return
|
|
1189
|
|
1190 * seek the head to track 0
|
|
1191 sktrk0 lbsr chkdrv
|
|
1192 ldx >lastdrv,u
|
|
1193 clr <$15,x
|
|
1194 lda #1 was 5 but that causes head banging
|
|
1195 L0497 ldb <PD.STP,y
|
|
1196 andb #%00000011 Just keep usable settings (6-30 ms)
|
|
1197 eorb #%01001011 Set proper bits for controller
|
|
1198 pshs a
|
|
1199 lbsr L03E4
|
|
1200 puls a
|
|
1201 deca
|
|
1202 bne L0497
|
|
1203 ldb <PD.STP,y
|
|
1204 andb #%00000011 Just keep usable settings (6-30 ms)
|
|
1205 eorb #%00001011 Set proper bits for controller
|
|
1206 lbra L03E4
|
|
1207
|
|
1208 L04B3 pshs y,x,d Preserve regs
|
|
1209 ldd >VIRQCnt,pc Get VIRQ initial count value
|
|
1210 std >VIRQPak,u Save it
|
|
1211 lda >ctlimg,u ?Get drive?
|
|
1212 ora #C_MOTOR Turn drive motor on for that drive
|
|
1213 * ora #%00001000 Turn drive motor on for that drive
|
|
1214 sta >DPort+CtrlReg Send drive motor on command to FDC
|
|
1215 IFEQ Level-1
|
|
1216 lda >D.DskTmr Get VIRQ flag
|
|
1217 ELSE
|
|
1218 lda <D.MotOn Get VIRQ flag
|
|
1219 ENDC
|
|
1220 bmi L04DE Not installed yet, try installing it
|
|
1221 bne L04E0 Drive already up to speed, exit without error
|
|
1222
|
|
1223 * Drive motor speed timing loop (could be F$Sleep call now) (was over .5 sec)
|
|
1224 * 32 was not sufficient for one of my drives. RG
|
|
1225 ldx #50 wait for 32 ticks; increased it RG
|
|
1226 lbsr Delay
|
|
1227
|
|
1228 L04DE bsr InsVIRQ Install VIRQ to wait for drive motors
|
|
1229 L04E0 clrb No error & return
|
|
1230 puls pc,y,x,d
|
|
1231
|
|
1232 InsVIRQ lda #$01 Flag drive motor is up to speed
|
|
1233 IFEQ Level-1
|
|
1234 sta >D.DskTmr
|
|
1235 ELSE
|
|
1236 sta <D.MotOn
|
|
1237 ENDC
|
|
1238 ldx #$0001 Install VIRQ entry
|
|
1239 leay >VIRQPak,u Point to packet
|
|
1240 clr Vi.Stat,y Reset Status byte
|
|
1241 ldd >VIRQCnt,pc Get initial VIRQ count value
|
|
1242 os9 F$VIRQ Install VIRQ
|
|
1243 bcc VIRQOut No error, exit
|
|
1244 lda #$80 Flag that VIRQ wasn't installed
|
|
1245 IFEQ Level-1
|
|
1246 sta >D.DskTmr
|
|
1247 ELSE
|
|
1248 sta <D.MotOn
|
|
1249 ENDC
|
|
1250 VIRQOut clra
|
|
1251 rts
|
|
1252
|
|
1253 * IRQ service routine for VIRQ (drive motor time)
|
|
1254 * Entry: U=Ptr to VIRQ memory area
|
|
1255 IRQSvc pshs a
|
|
1256 lda <D.DMAReq
|
|
1257 beq L0509
|
|
1258 bsr InsVIRQ
|
|
1259 bra IRQOut
|
|
1260 L0509 sta >DPort+CtrlReg
|
|
1261 * I changed this to a clear. Don't see the point of an AND. RG
|
|
1262 * IFNE H6309
|
|
1263 * aim #$FE,>u00B5,u
|
|
1264 * ELSE
|
|
1265 * lda u00B5,u
|
|
1266 * anda #$FE
|
|
1267 * sta u00B5,u
|
|
1268 * ENDC
|
|
1269 * fdb u00B5 --- so changes in data size won't affect anything
|
|
1270 clr u00B5,u
|
|
1271 IFEQ Level-1
|
|
1272 clr >D.DskTmr
|
|
1273 ELSE
|
|
1274 clr <D.MotOn
|
|
1275 ENDC
|
|
1276 IRQOut puls pc,a
|
|
1277
|
|
1278 * Non-OS9 formatted floppies need a drive table entry constructed
|
|
1279 * by hand since there is no RBF LSN0.
|
|
1280 *
|
|
1281 * Entry: X=LSN
|
|
1282 * Y=Path dsc. ptr
|
|
1283 * U=Device mem ptr
|
|
1284 MakeDTEntry
|
|
1285 pshs x Preserve Logical sector #
|
|
1286 ldx >lastdrv,u Get last drive table accessed ptr
|
|
1287 clra
|
|
1288 pshs x,a Save ptr & NUL byte
|
|
1289 IFNE H6309
|
|
1290 ldw #20 Clear 20 bytes
|
|
1291 tfm s,x+
|
|
1292 ELSE
|
|
1293 ldb #20
|
|
1294 L051ALp clr ,x+
|
|
1295 decb
|
|
1296 bne L051ALp
|
|
1297 ENDC
|
|
1298 puls x,a Eat NUL & get back drive table ptr
|
|
1299 ldb <PD.CYL+1,y Get # cylinders on drive (ignores high byte)
|
|
1300 lda <PD.SID,y Get # sides
|
|
1301 mul Calculate # tracks on drive (1 per head)
|
|
1302 IFNE H6309
|
|
1303 decd Adjust to ignore track 0
|
|
1304 ELSE
|
|
1305 subd #$0001
|
|
1306 ENDC
|
|
1307 lda <PD.SCT+1,y Get # sectors/track
|
|
1308 sta DD.TKS,x Save in drive table
|
|
1309 sta <DD.SPT+1,x Save in other copy in drive table
|
|
1310 mul Calculate # sectors on drive (minus track 0)
|
|
1311 pshs x Preserve drive table ptr
|
|
1312 tfr d,x Move # sectors on drive to X
|
|
1313 lda <PD.T0S+1,y Get # sectors on track 0
|
|
1314 leax a,x Add that many sectors to total
|
|
1315 lda <PD.TYP,y Get device type settings
|
|
1316 anda #%00000100 Mask out all but 512 byte sector flag
|
|
1317 beq L0550 Not 512 byte sector, skip ahead
|
|
1318 IFNE H6309
|
|
1319 addr x,x Multiply by 2 (convert to 256 byte OS9 sectors)
|
|
1320 ELSE
|
|
1321 tfr x,d
|
|
1322 leax d,x
|
|
1323 ENDC
|
|
1324 L0550 tfr x,d Move # sectors to D
|
|
1325 puls x Get back drive table ptr
|
|
1326 std DD.TOT+1,x Save # sectors allowed on drive
|
|
1327 lda #UPDAT.+EXEC. Owner's read/write/exec attributes
|
|
1328 sta DD.ATT,x Set attributes for disk
|
|
1329 lda <PD.DNS,y Get density settings
|
|
1330 lsla Shift for DD.FMT
|
|
1331 pshs a Preserve it a sec
|
|
1332 lda <PD.SID,y Get # sides
|
|
1333 deca Adjust to base 0
|
|
1334 ora ,s+ Merge with density settings
|
|
1335 sta <DD.FMT,x Save in device table
|
|
1336 clrb No error?
|
|
1337 puls pc,x Restore original LSN & return
|
|
1338
|
|
1339 emod
|
|
1340 eom equ *
|
|
1341 end
|
|
1342
|