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