Mercurial > hg > Members > kono > nitros9-code
annotate level1/modules/boot_1773.asm @ 1575:8cc9bf35384f
term renamed
author | boisy |
---|---|
date | Tue, 18 May 2004 02:57:00 +0000 |
parents | d669aab7d6d8 |
children | 1e026af2217c |
rev | line source |
---|---|
230 | 1 ******************************************************************** |
1287 | 2 * Boot - WD1773 Boot module |
230 | 3 * |
4 * $Id$ | |
5 * | |
1287 | 6 * Edt/Rev YYYY/MM/DD Modified by |
7 * Comment | |
230 | 8 * ------------------------------------------------------------------ |
1287 | 9 * 4 1985/??/?? |
10 * Original Tandy distribution version. | |
11 * | |
12 * 6 1998/10/12 Boisy G. Pitre | |
13 * Obtained from L2 Upgrade archive, has 6ms step rate and disk timeout | |
14 * changes. | |
15 * | |
16 * 6r2 2003/05/18 Boisy G. Pitre | |
17 * Added '.' output for each sector for OS-9 L2 and NitrOS9 for | |
18 * Mark Marlette (a special request :). | |
1291
92e9f7416fc9
Added BLOB-stop fix, changed one line as per Robert Gault's suggestion
boisy
parents:
1287
diff
changeset
|
19 * |
92e9f7416fc9
Added BLOB-stop fix, changed one line as per Robert Gault's suggestion
boisy
parents:
1287
diff
changeset
|
20 * 6r3 2003/08/31 Robert Gault |
92e9f7416fc9
Added BLOB-stop fix, changed one line as per Robert Gault's suggestion
boisy
parents:
1287
diff
changeset
|
21 * Put BLOB-stop code in place, changed orb #$30 to orb #$28 |
1520 | 22 * |
23 * 6r4 2004/02/17 Rodney Hamilton | |
24 * Minor optimizations, improvements in source comments | |
230 | 25 |
210
6bf55704c623
Boot is adapted from OS-9 Level Two boot module, now boots from
boisy
parents:
201
diff
changeset
|
26 nam Boot |
1287 | 27 ttl WD1773 Boot module |
0 | 28 |
1287 | 29 IFP1 |
0 | 30 use defsfile |
1287 | 31 ENDC |
0 | 32 |
1520 | 33 * FDC Control Register bits at $FF40 |
34 HALTENA equ %10000000 | |
35 SIDESEL equ %01000000 DRVSEL3 if no DS drives | |
36 DDEN equ %00100000 | |
37 READY equ %00010000 READY for Tandy WD1773-based controllers | |
1516 | 38 MOTON equ %00001000 |
1520 | 39 DRVSEL2 equ %00000100 |
1516 | 40 DRVSEL1 equ %00000010 |
41 DRVSEL0 equ %00000001 | |
42 | |
1520 | 43 * Default Boot Drive is /d0 |
44 BootDr set DRVSEL0 | |
45 | |
46 * WD17x3 DPort offsets | |
47 CONTROL equ 0 | |
48 CMDREG equ 8+0 write-only | |
49 STATREG equ CMDREG read-only | |
1516 | 50 TRACKREG equ 8+1 |
51 SECTREG equ 8+2 | |
52 DATAREG equ 8+3 | |
53 | |
1515 | 54 * Sector Size |
55 SECTSIZE equ 256 | |
56 | |
1520 | 57 * Step Rates: |
58 * $00 = 6ms | |
59 * $01 = 12ms | |
60 * $02 = 20ms | |
61 * $03 = 30ms | |
1213
4e235f213651
Lots of changes: bootscripts and bootlists added, sources massaged...
boisy
parents:
1166
diff
changeset
|
62 STEP set $00 |
210
6bf55704c623
Boot is adapted from OS-9 Level Two boot module, now boots from
boisy
parents:
201
diff
changeset
|
63 |
1287 | 64 tylg set Systm+Objct |
0 | 65 atrv set ReEnt+rev |
1520 | 66 rev set $04 |
1287 | 67 edition set 6 |
230 | 68 |
0 | 69 mod eom,name,tylg,atrv,start,size |
230 | 70 |
1520 | 71 * NOTE: these are U-stack offsets, not DP |
1515 | 72 drvsel rmb 1 |
1514 | 73 buffptr rmb 2 |
74 currtrak rmb 1 | |
1515 | 75 *ddfmt rmb 1 |
1514 | 76 ddtks rmb 1 no. of sectors per track |
1515 | 77 *ddtot rmb 1 |
1514 | 78 dblsided rmb 1 |
1520 | 79 side rmb 1 side 2 flag |
0 | 80 size equ . |
81 | |
82 name fcs /Boot/ | |
230 | 83 fcb edition |
0 | 84 |
1287 | 85 start clra clear A |
86 ldb #size get our 'stack' size | |
87 MakeStak pshs a save 0 on stack | |
88 decb and continue... | |
89 bne MakeStak until we've created our stack | |
0 | 90 |
1287 | 91 tfr s,u put 'stack statics' in U |
1516 | 92 * ldx #DPort |
93 lda #%11010000 ($D0) Force Interrupt (stops any command in progress) | |
1520 | 94 sta >DPort+CMDREG write command to command register |
1516 | 95 * sta CMDREG,x write command to command register |
1520 | 96 lbsr Delay2 delay 54~ |
97 lda >DPort+STATREG clear status register | |
1516 | 98 * lda STATREG,x read status register |
0 | 99 lda #$FF |
1515 | 100 sta currtrak,u set current track to 255 |
101 leax >NMIRtn,pcr point to NMI routine | |
1166 | 102 IFGT Level-1 |
1515 | 103 stx <D.NMI save address |
1166 | 104 ELSE |
1515 | 105 stx >D.XNMI+1 save address |
0 | 106 lda #$7E |
1213
4e235f213651
Lots of changes: bootscripts and bootlists added, sources massaged...
boisy
parents:
1166
diff
changeset
|
107 sta >D.XNMI |
1166 | 108 ENDC |
1516 | 109 lda #MOTON+BootDr turn on drive motor |
1520 | 110 sta >DPort+CONTROL |
210
6bf55704c623
Boot is adapted from OS-9 Level Two boot module, now boots from
boisy
parents:
201
diff
changeset
|
111 |
1520 | 112 * MOTOR ON spin-up delay loop (~307 mSec) |
1166 | 113 IFGT Level-1 |
1520 | 114 ldd #50000 |
1166 | 115 ELSE |
1520 | 116 ldd #25000 |
1166 | 117 ENDC |
1363 | 118 IFNE H6309 |
1287 | 119 nop |
120 ENDC | |
121 L003A nop | |
122 nop | |
1363 | 123 IFNE H6309 |
1287 | 124 nop |
125 nop | |
126 nop | |
127 ENDC | |
0 | 128 subd #$0001 |
210
6bf55704c623
Boot is adapted from OS-9 Level Two boot module, now boots from
boisy
parents:
201
diff
changeset
|
129 bne L003A |
0 | 130 |
1515 | 131 * search for memory to use as a sector buffer |
132 pshs u,y,x,b,a save regs | |
133 ldd #SECTSIZE get sector size in D | |
134 os9 F$SRqMem request that much memory | |
135 bcs L00AA branch if there is an error | |
136 tfr u,d move pointer to D temporarily | |
137 ldu $06,s restore U (saved earlier) | |
138 std buffptr,u save alloced mem pointer in statics | |
1287 | 139 clrb |
0 | 140 |
141 * go get LSN0 | |
1515 | 142 ldx #$0000 we want LSN0 |
143 bsr ReadSect go get it | |
144 bcs L00AA branch if error | |
0 | 145 |
1515 | 146 * From LSN0, we get various pieces of info. |
147 * ldd DD.TOT+1,y | |
148 * std ddtot,u | |
1520 | 149 lda <DD.FMT,y get format byte of LSN0 |
150 * sta ddfmt,u save it for ??? | |
151 anda #FMT.SIDE keep side bit | |
152 sta dblsided,u and save it | |
153 lda DD.TKS,y get sectors per track | |
154 sta ddtks,u and save | |
155 ldd <DD.BSZ,y get bootfile size | |
156 std ,s save on stack | |
157 ldx <DD.BT+1,y get start sector of bootfile | |
158 pshs x push on the stack | |
159 ldd #SECTSIZE load D with sector size | |
160 ldu buffptr,u and point to the buffer pointer | |
161 os9 F$SRtMem return the memory | |
162 ldd $02,s get the bootfile size | |
1166 | 163 IFGT Level-1 |
1287 | 164 os9 F$BtMem |
1166 | 165 ELSE |
1520 | 166 os9 F$SRqMem get the memory from the system |
1166 | 167 ENDC |
1520 | 168 puls x pull bootfile start sector off stack |
169 bcs L00AA branch if error | |
170 stu 2,s save pointer to bootfile mem on stack | |
171 stu 8+buffptr,s also save to buffptr,u | |
172 ldu 6,s reload original U | |
173 * ldd 2,s get pointer to bootfile mem | |
174 * std buffptr,u and save pointer | |
175 ldd ,s get bootfile size | |
176 beq L00A3 branch if zero | |
0 | 177 |
178 * this loop reads a sector at a time from the bootfile | |
1515 | 179 * X = start sector |
180 * D = bootfile size | |
1520 | 181 L0091 pshs x,b,a save params |
1287 | 182 clrb |
1520 | 183 bsr ReadSect read sector |
184 bcs L00A8 branch if error | |
1287 | 185 IFGT Level-1 |
1520 | 186 lda #'. dump out a period for boot debugging |
187 jsr <D.BtBug do the debug stuff | |
1287 | 188 ENDC |
1520 | 189 puls x,b,a restore params |
190 * RVH NOTE: the next 3 lines assume sector size=256=LSN size? | |
191 inc buffptr,u point to next 256 bytes | |
192 leax 1,x move to next sector | |
193 subd #SECTSIZE subtract sector bytes from size | |
194 bhi L0091 continue if more space | |
1287 | 195 L00A3 clrb |
0 | 196 puls b,a |
210
6bf55704c623
Boot is adapted from OS-9 Level Two boot module, now boots from
boisy
parents:
201
diff
changeset
|
197 bra L00AC |
6bf55704c623
Boot is adapted from OS-9 Level Two boot module, now boots from
boisy
parents:
201
diff
changeset
|
198 L00A8 leas $04,s |
6bf55704c623
Boot is adapted from OS-9 Level Two boot module, now boots from
boisy
parents:
201
diff
changeset
|
199 L00AA leas $02,s |
1295
cbe5b5313422
Removed poke to FFD9 for CoCo 3 since this is done by rel
boisy
parents:
1291
diff
changeset
|
200 L00AC puls u,y,x |
1287 | 201 leas size,s clean up stack |
1520 | 202 clr >DPort+CONTROL shut off floppy disk |
1287 | 203 rts |
0 | 204 |
1520 | 205 L00B7 lda #DDEN+MOTON+BootDr permit alternate drives |
1516 | 206 sta drvsel,u save drive selection byte |
207 clr currtrak,u clear current track | |
0 | 208 lda #$05 |
1287 | 209 lbsr L0170 |
1520 | 210 ldb #0+STEP RESTORE cmd |
1287 | 211 lbra L0195 |
0 | 212 |
1287 | 213 * Read a sector from the 1773 |
214 * Entry: X = LSN to read | |
215 ReadSect lda #$91 | |
216 cmpx #$0000 LSN0? | |
1515 | 217 bne L00DF branch if not |
218 bsr L00DF else branch subroutine | |
219 bcs L00D6 branch if error | |
220 ldy buffptr,u get buffer pointer in Y for caller | |
1287 | 221 clrb |
222 L00D6 rts | |
223 | |
224 L00D7 bcc L00DF | |
0 | 225 pshs x,b,a |
1287 | 226 bsr L00B7 |
0 | 227 puls x,b,a |
1515 | 228 L00DF pshs x,b,a save LSN, command |
1287 | 229 bsr L00EA |
1520 | 230 puls x,b,a restore LSN, command |
1515 | 231 bcc L00D6 branch if OK |
1287 | 232 lsra |
233 bne L00D7 | |
234 L00EA bsr L013C | |
1515 | 235 bcs L00D6 if error, return to caller |
236 ldx buffptr,u get address of buffer to fill | |
237 orcc #IntMasks mask interrupts | |
238 pshs y save Y | |
0 | 239 ldy #$FFFF |
1516 | 240 ldb #%10000000 ($80) READ SECTOR command |
241 stb >DPort+CMDREG write to command register | |
1520 | 242 ldb drvsel,u (DDEN+MOTORON+BootDr) |
243 * NOTE: The 1773 FDC multiplexes the write precomp enable and ready | |
244 * signals on the ENP/RDY pin, so the READY bit must always be ON for | |
245 * read and seek commands. (from the FD502 FDC Service Manual) | |
246 orb #DDEN+READY set DDEN+READY bits ($30) | |
247 tst side,u are we on side 2? | |
1287 | 248 beq L0107 |
1520 | 249 orb #SIDESEL set side 2 bit |
250 L0107 stb >DPort+CONTROL | |
251 lbsr Delay2 delay 54~ | |
252 orb #HALTENA HALT enable ($80) | |
253 * lda #%00000010 RESTORE cmd ($02) | |
1516 | 254 *L0111 bita >DPort+STATREG |
1291
92e9f7416fc9
Added BLOB-stop fix, changed one line as per Robert Gault's suggestion
boisy
parents:
1287
diff
changeset
|
255 * bne L0123 |
92e9f7416fc9
Added BLOB-stop fix, changed one line as per Robert Gault's suggestion
boisy
parents:
1287
diff
changeset
|
256 * leay -$01,y |
92e9f7416fc9
Added BLOB-stop fix, changed one line as per Robert Gault's suggestion
boisy
parents:
1287
diff
changeset
|
257 * bne L0111 |
1515 | 258 * lda drvsel,u |
1520 | 259 * sta >DPort+CONTROL |
1291
92e9f7416fc9
Added BLOB-stop fix, changed one line as per Robert Gault's suggestion
boisy
parents:
1287
diff
changeset
|
260 * puls y |
92e9f7416fc9
Added BLOB-stop fix, changed one line as per Robert Gault's suggestion
boisy
parents:
1287
diff
changeset
|
261 * bra L0138 |
1520 | 262 stb >DPort+CONTROL |
1291
92e9f7416fc9
Added BLOB-stop fix, changed one line as per Robert Gault's suggestion
boisy
parents:
1287
diff
changeset
|
263 nop |
92e9f7416fc9
Added BLOB-stop fix, changed one line as per Robert Gault's suggestion
boisy
parents:
1287
diff
changeset
|
264 nop |
92e9f7416fc9
Added BLOB-stop fix, changed one line as per Robert Gault's suggestion
boisy
parents:
1287
diff
changeset
|
265 bra L0123 |
1516 | 266 |
267 * Sector READ Loop | |
268 L0123 lda >DPort+DATAREG read from WD DATA register | |
0 | 269 sta ,x+ |
1520 | 270 * stb >DPort+CONTROL |
1291
92e9f7416fc9
Added BLOB-stop fix, changed one line as per Robert Gault's suggestion
boisy
parents:
1287
diff
changeset
|
271 nop |
1287 | 272 bra L0123 |
1520 | 273 * RVH NOTE: This ONLY works for double density boot disks! The Tandy |
274 * controllers internally gate HALT enable with the DDEN bit, which | |
275 * means that reading a single-density boot disk will not generate the | |
276 * NMI signal needed to exit the read loop! Single-density disks must | |
277 * use a polled I/O loop instead. | |
210
6bf55704c623
Boot is adapted from OS-9 Level Two boot module, now boots from
boisy
parents:
201
diff
changeset
|
278 |
1515 | 279 NMIRtn leas R$Size,s adjust stack |
0 | 280 puls y |
1516 | 281 ldb >DPort+STATREG read WD STATUS register |
282 bitb #$9C any errors? | |
283 * bitb #$04 LOST DATA bit set? | |
284 beq RetOK branch if not | |
285 * beq ChkErr branch if not | |
286 L0138 comb else we will return error | |
210
6bf55704c623
Boot is adapted from OS-9 Level Two boot module, now boots from
boisy
parents:
201
diff
changeset
|
287 ldb #E$Read |
1516 | 288 RetOK rts |
0 | 289 |
1516 | 290 L013C lda #MOTON+BootDr permit alternate drives |
291 sta drvsel,u save byte to static mem | |
1520 | 292 clr side,u start on side 1 |
0 | 293 tfr x,d |
294 cmpd #$0000 | |
1287 | 295 beq L016C |
1515 | 296 clr ,-s clear space on stack |
1520 | 297 tst dblsided,u double sided disk? |
1514 | 298 beq L0162 branch if not |
1287 | 299 bra L0158 |
1515 | 300 * Double-sided code |
1520 | 301 L0152 com side,u flag side 2 |
1287 | 302 bne L0158 |
210
6bf55704c623
Boot is adapted from OS-9 Level Two boot module, now boots from
boisy
parents:
201
diff
changeset
|
303 inc ,s |
1515 | 304 L0158 subb ddtks,u |
210
6bf55704c623
Boot is adapted from OS-9 Level Two boot module, now boots from
boisy
parents:
201
diff
changeset
|
305 sbca #$00 |
1287 | 306 bcc L0152 |
307 bra L0168 | |
308 L0160 inc ,s | |
1514 | 309 L0162 subb ddtks,u |
210
6bf55704c623
Boot is adapted from OS-9 Level Two boot module, now boots from
boisy
parents:
201
diff
changeset
|
310 sbca #$00 |
1287 | 311 bcc L0160 |
1514 | 312 L0168 addb #18 add sectors per track |
313 puls a get current track indicator off of stack | |
1287 | 314 L016C incb |
1516 | 315 stb >DPort+SECTREG save in sector register |
316 L0170 ldb currtrak,u get current track in B | |
317 stb >DPort+TRACKREG save in track register | |
1520 | 318 cmpa currtrak,u same as A? |
1516 | 319 beq L018D branch if so |
1514 | 320 sta currtrak,u |
1516 | 321 sta >DPort+DATAREG |
322 ldb #$10+STEP SEEK command | |
323 bsr L0195 send command to controller | |
0 | 324 pshs x |
1520 | 325 * Seek Delay |
326 ldx #$222E delay ~39 mSec (78mS L1) | |
1287 | 327 L0187 leax -$01,x |
328 bne L0187 | |
0 | 329 puls x |
1287 | 330 L018D clrb |
331 rts | |
1516 | 332 |
333 *ChkErr bitb #$98 evaluate WD status (READY, RNF, CRC err) | |
334 * bne L0138 | |
335 * clrb | |
336 * rts | |
337 | |
1520 | 338 L0195 bsr L01A8 issue FDC cmd, wait 54~ |
1516 | 339 L0197 ldb >DPort+STATREG |
1520 | 340 bitb #$01 still BUSY? |
341 bne L0197 loop until command completes | |
1287 | 342 rts |
1516 | 343 |
344 * Entry: B = command byte | |
1515 | 345 L019F lda drvsel,u |
1520 | 346 sta >DPort+CONTROL |
1516 | 347 stb >DPort+CMDREG |
1287 | 348 rts |
1515 | 349 |
1520 | 350 * issue command and wait 54 clocks |
351 * Controller requires a min delay of 14uS (DD) or 28uS (SD) | |
352 * following a command write before status register is valid | |
353 L01A8 | |
354 bsr L019F | |
1515 | 355 * Delay branches |
1520 | 356 * 54 clock delay including bsr (=30uS/L2,60us/L1) |
1515 | 357 Delay2 |
1363 | 358 IFNE H6309 |
1287 | 359 nop |
360 nop | |
361 ENDC | |
1515 | 362 lbsr Delay3 |
363 Delay3 | |
1363 | 364 IFNE H6309 |
1287 | 365 nop |
366 nop | |
367 ENDC | |
1515 | 368 lbsr Delay4 |
369 Delay4 | |
1363 | 370 IFNE H6309 |
1287 | 371 nop |
372 ENDC | |
373 rts | |
210
6bf55704c623
Boot is adapted from OS-9 Level Two boot module, now boots from
boisy
parents:
201
diff
changeset
|
374 |
1166 | 375 IFGT Level-1 |
1287 | 376 * Filler to get $1D0 |
377 Filler fill $39,$1D0-3-* | |
1166 | 378 ENDC |
0 | 379 |
380 emod | |
381 eom equ * | |
48 | 382 end |