Mercurial > hg > Members > kono > nitros9-code
comparison level1/modules/ddisk.asm @ 1821:82e134e51305
Fixed fatal read errors on the Dragon 64.
author | afra |
---|---|
date | Sun, 24 Apr 2005 02:16:01 +0000 |
parents | 11f38ece79ef |
children | c074e97abf3d |
comparison
equal
deleted
inserted
replaced
1820:be7da2ee5fe8 | 1821:82e134e51305 |
---|---|
39 * Fixed up so that double sided disks now work, origional | 39 * Fixed up so that double sided disks now work, origional |
40 * double sided code taken from Jon Bird's pages at : | 40 * double sided code taken from Jon Bird's pages at : |
41 * http://www.onastick.clara.net/dragon.html and modified | 41 * http://www.onastick.clara.net/dragon.html and modified |
42 * for NitrOS9. | 42 * for NitrOS9. |
43 * | 43 * |
44 * 2004-1127, P.Harvey-Smith. | 44 * 2004-11-27, P.Harvey-Smith. |
45 * Reformatted with tab=8. | 45 * Reformatted with tab=8. |
46 * | 46 * |
47 * 2005-04-22, P.Harvey-Smith. | |
48 * Hopefully fixed a bug that was causing the Dragon 64 target to | |
49 * crash and burn when reading disks, this made a successfull boot | |
50 * almost imposible ! Fixed by writing disk command before writing | |
51 * disc control register, the Alpha target needs them the other way | |
52 * around. Still has a problem doing lots of retries. | |
53 * | |
54 * 2005-04-24, P.Harvey-Smith. | |
55 * Fixed constant lost data errors reading disks, again by slightly | |
56 * re-ordering the instructions in the read data loop. | |
47 * | 57 * |
48 | 58 |
49 nam DDisk | 59 nam DDisk |
50 ttl Dragon Floppy driver | 60 ttl Dragon Floppy driver |
51 | 61 |
70 PIACRA EQU DPPIACRA+IO ; Side A Control. | 80 PIACRA EQU DPPIACRA+IO ; Side A Control. |
71 PIADB EQU DPPIADB+IO ; Side A Data/DDR | 81 PIADB EQU DPPIADB+IO ; Side A Data/DDR |
72 PIACRB EQU DPPIACRB+IO ; Side A Control. | 82 PIACRB EQU DPPIACRB+IO ; Side A Control. |
73 | 83 |
74 ;WD2797 Floppy disk controler, used in Alpha Note registers in reverse order ! | 84 ;WD2797 Floppy disk controler, used in Alpha Note registers in reverse order ! |
75 DPCMDREG EQU DPCmdRegA ; command/status | 85 DPCMDREG EQU DPCmdRegA ; command/status |
76 DPTRKREG EQU DPTrkRegA ; Track register | 86 DPTRKREG EQU DPTrkRegA ; Track register |
77 DPSECREG EQU DPSecRegA ; Sector register | 87 DPSECREG EQU DPSecRegA ; Sector register |
78 DPDATAREG EQU DPDataRegA ; Data register | 88 DPDATAREG EQU DPDataRegA ; Data register |
79 | 89 |
80 CMDREG EQU DPCMDREG+IO ; command/status | 90 CMDREG EQU DPCMDREG+IO ; command/status |
81 TRKREG EQU DPTRKREG+IO ; Track register | 91 TRKREG EQU DPTRKREG+IO ; Track register |
82 SECREG EQU DPSECREG+IO ; Sector register | 92 SECREG EQU DPSECREG+IO ; Sector register |
83 DATAREG EQU DPDATAREG+IO ; Data register | 93 DATAREG EQU DPDATAREG+IO ; Data register |
142 SaveACIACmd rmb 1 ; Saved copy of ACIA command reg | 152 SaveACIACmd rmb 1 ; Saved copy of ACIA command reg |
143 BuffPtr rmb 2 ; Buffer pointer | 153 BuffPtr rmb 2 ; Buffer pointer |
144 SideSel rmb 1 ; Side select. | 154 SideSel rmb 1 ; Side select. |
145 NMIFlag rmb 1 ; Flag for Alpha, should this NMI do an RTI ? | 155 NMIFlag rmb 1 ; Flag for Alpha, should this NMI do an RTI ? |
146 | 156 |
157 DskError rmb 1 | |
158 | |
147 VIRQPak rmb 2 ; Vi.Cnt word for VIRQ | 159 VIRQPak rmb 2 ; Vi.Cnt word for VIRQ |
148 u00B3 rmb 2 ; Vi.Rst word for VIRQ | 160 u00B3 rmb 2 ; Vi.Rst word for VIRQ |
149 u00B5 rmb 1 ; Vi.Stat byte for VIRQ (drive motor timeout) | 161 u00B5 rmb 1 ; Vi.Stat byte for VIRQ (drive motor timeout) |
150 | 162 |
151 VIRQInstalled rmb 1 ; Is VIRQ Installed yet ? | 163 VIRQInstalled rmb 1 ; Is VIRQ Installed yet ? |
156 fcs /DDisk/ | 168 fcs /DDisk/ |
157 fcb edition | 169 fcb edition |
158 | 170 |
159 VIRQCnt fdb TkPerSec*4 Initial count for VIRQ (4 seconds) | 171 VIRQCnt fdb TkPerSec*4 Initial count for VIRQ (4 seconds) |
160 | 172 |
161 start lbra Init ; Initialise Driver | 173 start lbra Init ; Initialise Driver |
162 lbra Read ; Read sector | 174 lbra Read ; Read sector |
163 lbra Write ; Write sector | 175 lbra Write ; Write sector |
164 lbra GetStat ; Get status | 176 lbra GetStat ; Get status |
165 lbra SetStat ; Set status | 177 lbra SetStat ; Set status |
166 lbra Term ; Terminate device | 178 lbra Term ; Terminate device |
167 | 179 |
168 IRQPkt fcb $00 ; Normal bits (flip byte) | 180 IRQPkt fcb $00 ; Normal bits (flip byte) |
169 fcb $01 ; Bit 1 is interrupt request flag (Mask byte) | 181 fcb $01 ; Bit 1 is interrupt request flag (Mask byte) |
170 fcb 10 ; Priority byte | 182 fcb 10 ; Priority byte |
171 | 183 |
172 | 184 |
173 * Init | 185 * Init |
174 * | 186 * |
175 * Entry: | 187 * Entry: |
296 rts | 308 rts |
297 | 309 |
298 ; Read Retry | 310 ; Read Retry |
299 | 311 |
300 ReadDataRetry | 312 ReadDataRetry |
313 | |
314 lbsr RetryErrorDisplay | |
315 | |
301 bcc ReadDataWithRetry ; Retry entry point | 316 bcc ReadDataWithRetry ; Retry entry point |
302 pshs x,b,a | 317 pshs x,b,a |
303 lbsr ResetTrack0 ; Reset track 0 | 318 lbsr ResetTrack0 ; Reset track 0 |
304 puls x,b,a | 319 puls x,b,a |
305 | 320 |
316 bcs ReadDataExit | 331 bcs ReadDataExit |
317 ldx PD.Buf,y ; Target address for data | 332 ldx PD.Buf,y ; Target address for data |
318 pshs y,dp,cc | 333 pshs y,dp,cc |
319 ldb #ReadCmnd ; Read command | 334 ldb #ReadCmnd ; Read command |
320 bsr PrepDiskRW ; Prepare disk | 335 bsr PrepDiskRW ; Prepare disk |
336 | |
321 DoReadDataLoop | 337 DoReadDataLoop |
322 lda <DPPIACRB ; Is data ready ? | 338 lda <DPPIACRB ; Is data ready ? |
323 bmi ReadDataReady ; Yes : read it | 339 bmi ReadDataReady ; Yes : read it |
324 leay -1,y | 340 leay -1,y |
325 bne DoReadDataLoop | 341 bne DoReadDataLoop |
335 ldb <DPPIADB ; Clear PIA inturrupt status | 351 ldb <DPPIADB ; Clear PIA inturrupt status |
336 sta ,x+ ; save data in memory | 352 sta ,x+ ; save data in memory |
337 bra ReadDataWait ; do next | 353 bra ReadDataWait ; do next |
338 | 354 |
339 PrepDiskRW | 355 PrepDiskRW |
356 | |
357 clr DskError,u | |
358 | |
340 lda #$FF ; Make DP=$FF, to make io easier | 359 lda #$FF ; Make DP=$FF, to make io easier |
341 tfr a,dp | 360 tfr a,dp |
342 lda <DPAciaCmd ; Save ACIA Command reg | 361 lda <DPAciaCmd ; Save ACIA Command reg |
343 sta >SaveACIACmd,u | 362 sta >SaveACIACmd,u |
344 anda #$FE ; Disable ACIA inturrupt | 363 anda #$FE ; Disable ACIA inturrupt |
366 ora >DrivSel,u ; mask in drives | 385 ora >DrivSel,u ; mask in drives |
367 ORB >SideSel,U ; Set up Side | 386 ORB >SideSel,U ; Set up Side |
368 | 387 |
369 IFNE DragonAlpha ; Turn on drives & NMI | 388 IFNE DragonAlpha ; Turn on drives & NMI |
370 lbsr AlphaDskCtl | 389 lbsr AlphaDskCtl |
390 stb <DPCmdReg ; issue command to controler | |
371 ELSE | 391 ELSE |
372 sta >DskCtl | 392 stb <DPCmdReg ; issue command to controler |
393 sta <DPDskCtl | |
373 ENDC | 394 ENDC |
374 | 395 |
375 stb <DPCmdReg ; issue command to controler | |
376 | 396 |
377 rts | 397 rts |
378 | 398 |
379 ; | 399 ; |
380 ; Restore saved iO states of peripherals. | 400 ; Restore saved iO states of peripherals. |
384 lda >DrivSel,u ; Deselect drives, but leave motor on | 404 lda >DrivSel,u ; Deselect drives, but leave motor on |
385 ora #MotorOn | 405 ora #MotorOn |
386 IFNE DragonAlpha ; Turn off drives & NMI | 406 IFNE DragonAlpha ; Turn off drives & NMI |
387 lbsr AlphaDskCtl | 407 lbsr AlphaDskCtl |
388 ELSE | 408 ELSE |
389 sta >DskCtl | 409 sta <DPDskCtl |
390 ENDC | 410 ENDC |
391 | 411 |
392 lda >SavePIA0CRB,u ; Recover PIA0 state | 412 lda >SavePIA0CRB,u ; Recover PIA0 state |
393 sta <DPPia0CRB | 413 sta <DPPia0CRB |
394 lda <DPPIACRB ; Recover ACIA state | 414 lda <DPPIACRB ; Recover ACIA state |
438 pshs y,dp,cc | 458 pshs y,dp,cc |
439 ldb #WritCmnd ; Write command | 459 ldb #WritCmnd ; Write command |
440 | 460 |
441 WriteTrackCmd | 461 WriteTrackCmd |
442 lbsr PrepDiskRW ; Prepare for disk r/w | 462 lbsr PrepDiskRW ; Prepare for disk r/w |
443 lda ,x+ ; get byte to write | 463 lda ,x+ ; get byte to write |
444 L015A ldb <DPPIACRB ; Ready to write ? | 464 L015A ldb <DPPIACRB ; Ready to write ? |
445 bmi WriteDataReady ; Yes, do it. | 465 bmi WriteDataReady ; Yes, do it. |
446 leay -1,y | 466 leay -1,y |
447 bne L015A | 467 bne L015A |
448 bsr RestoreSavedIO ; Restore saved peripheral states | 468 bsr RestoreSavedIO ; Restore saved peripheral states |
477 RealNMI | 497 RealNMI |
478 leas R$Size,s ; Drop regs from stack | 498 leas R$Size,s ; Drop regs from stack |
479 bsr RestoreSavedIO ; Restore saved IO states | 499 bsr RestoreSavedIO ; Restore saved IO states |
480 puls y,dp,cc | 500 puls y,dp,cc |
481 ldb >CmdReg | 501 ldb >CmdReg |
482 bitb #LostMask ; check for lost record | 502 |
503 stb DskError,u | |
504 | |
505 bitb #LostMask ; check for lost record | |
483 lbne RetReadError ; yes : return read error | 506 lbne RetReadError ; yes : return read error |
484 lbra TestForError ; esle test for other errors | 507 lbra TestForError ; esle test for other errors |
485 | 508 |
486 ; Verify a written sector. | 509 ; Verify a written sector. |
487 WriteVerify | 510 WriteVerify |
572 PSHS B | 595 PSHS B |
573 SeekT9 LDB PD.Typ,Y ; Dragon and Coco disks | 596 SeekT9 LDB PD.Typ,Y ; Dragon and Coco disks |
574 BITB #TYP.SBO ; count sectors from 1 no | 597 BITB #TYP.SBO ; count sectors from 1 no |
575 BNE SeekT8 | 598 BNE SeekT8 |
576 PULS B | 599 PULS B |
577 INCB ; so increment sector number | 600 INCB ; so increment sector number |
578 BRA SeekT11 | 601 BRA SeekT11 |
579 SeekT8 PULS B ; Count from 0 for other types | 602 SeekT8 PULS B ; Count from 0 for other types |
580 | 603 |
581 SeekT11 STB >SecReg ; Write sector number to controler | 604 SeekT11 STB >SecReg ; Write sector number to controler |
582 LBSR Delay | 605 LBSR Delay |
947 | 970 |
948 PULS x,A,B,CC | 971 PULS x,A,B,CC |
949 RTS | 972 RTS |
950 | 973 |
951 ENDC | 974 ENDC |
975 | |
976 | |
977 ShowReg | |
978 pshs d,x,y,cc,dp,u | |
979 pshs x | |
980 leax RegBuffD,pcr | |
981 bsr RegDToHex | |
982 | |
983 puls d | |
984 leax RegBuffX,pcr | |
985 bsr RegDToHex | |
986 | |
987 tfr Y,D | |
988 leax RegBuffY,pcr | |
989 bsr RegDToHex | |
990 | |
991 tfr u,d | |
992 leax RegBuffU,pcr | |
993 bsr RegDToHex | |
994 | |
995 tfr s,d | |
996 leax RegBuffS,pcr | |
997 bsr RegDToHex | |
998 | |
999 tfr cc,a | |
1000 leax RegBuffCC,pcr | |
1001 bsr RegAToHex | |
1002 | |
1003 tfr dp,a | |
1004 leax RegBuffDP,pcr | |
1005 bsr RegAToHex | |
1006 | |
1007 lda #1 * stdout | |
1008 leax RegBuff,pcr | |
1009 ldy #RegBuffEnd-RegBuff | |
1010 os9 I$write | |
1011 | |
1012 ShowRegEnd | |
1013 puls d,x,y,cc,dp,u | |
1014 rts | |
1015 | |
1016 RegDtoHex | |
1017 pshs d | |
1018 bsr RegAToHex | |
1019 tfr b,a | |
1020 bsr RegAToHex | |
1021 puls d | |
1022 rts | |
1023 | |
1024 RegAToHex | |
1025 pshs d,y | |
1026 | |
1027 leay HexTable,pcr | |
1028 tfr a,b | |
1029 anda #$f0 | |
1030 lsra | |
1031 lsra | |
1032 lsra | |
1033 lsra | |
1034 lda a,y | |
1035 sta ,x+ | |
1036 tfr b,a | |
1037 anda #$0f | |
1038 lda a,y | |
1039 sta ,x+ | |
1040 | |
1041 puls d,y | |
1042 rts | |
1043 | |
1044 RetryErrorDisplay | |
1045 pshs a,x,cc | |
1046 | |
1047 lda DskError,u | |
1048 leax ErrCode,pcr | |
1049 bsr RegAToHex | |
1050 | |
1051 leax RetryMess,pcr | |
1052 bsr PrintStdOut | |
1053 puls a,x,cc,pc | |
1054 | |
1055 | |
1056 PrintDot | |
1057 pshs x,cc | |
1058 leax DotMess,pcr | |
1059 bsr PrintStdOut | |
1060 puls x,cc,pc | |
1061 | |
1062 | |
1063 PrintReadDone | |
1064 pshs x,cc | |
1065 leax ReadDoneMess,pcr | |
1066 bsr PrintStdOut | |
1067 puls x,cc,pc | |
1068 | |
1069 PrintReadDoneFail | |
1070 pshs x,cc | |
1071 leax ReadDoneFailMess,pcr | |
1072 bsr PrintStdOut | |
1073 puls x,cc,pc | |
1074 | |
1075 | |
1076 PrintStdOut | |
1077 pshs d,x,y,u,cc,dp | |
1078 leax -2,x | |
1079 ldy ,x++ | |
1080 lda #1 | |
1081 os9 I$write | |
1082 puls d,x,y,u,cc,dp,pc | |
1083 | |
1084 PrintCtrlByte | |
1085 pshs a,cc,x | |
1086 | |
1087 leax CtrlCode,pcr | |
1088 bsr RegAToHex | |
1089 | |
1090 leax CtrlMess,pcr | |
1091 ldy #CtrlMessLen | |
1092 bsr PrintStdOut | |
1093 puls a,cc,x,pc | |
1094 | |
1095 PrintCmdByte | |
1096 pshs a,cc,x | |
1097 | |
1098 leax CmdCode,pcr | |
1099 bsr RegAToHex | |
1100 | |
1101 leax CmdMess,pcr | |
1102 bsr PrintStdOut | |
1103 puls a,cc,x,pc | |
1104 | |
1105 PrintNMIMess | |
1106 pshs x,cc | |
1107 leax NMIMess,pcr | |
1108 bsr PrintStdOut | |
1109 puls x,cc,pc | |
1110 | |
1111 | |
1112 PrintTimeout | |
1113 pshs x,cc | |
1114 leax TimeoutMess,pcr | |
1115 bsr PrintStdOut | |
1116 puls x,cc,pc | |
1117 | |
1118 RegBuff | |
1119 fcc "A B X Y U " | |
1120 fcb C$CR,C$LF | |
1121 RegBuffD | |
1122 fcc "0000 " | |
1123 RegBuffX | |
1124 fcc "0000 " | |
1125 RegBuffY | |
1126 fcc "0000 " | |
1127 RegBuffU | |
1128 fcc "0000 " | |
1129 RegBuffS | |
1130 fcc "0000 " | |
1131 RegBuffCC | |
1132 fcc "00 " | |
1133 RegBuffDP | |
1134 fcc "00 " | |
1135 | |
1136 fcb C$CR,C$LF,0 | |
1137 RegBuffEnd | |
1138 | |
1139 HexTable | |
1140 fcc "0123456789ABCDEF" | |
1141 | |
1142 | |
1143 fdb RetryMessLen | |
1144 RetryMess | |
1145 fcc "Read error: retry (" | |
1146 ErrCode fcc "00)" | |
1147 fcb C$CR,C$LF,0 | |
1148 | |
1149 RetryMessLen EQU *-RetryMess | |
1150 | |
1151 | |
1152 fdb CtrlMessLen | |
1153 CtrlMess | |
1154 fcc "Control byte (" | |
1155 CtrlCode fcc "00)" | |
1156 fcb C$CR,C$LF,0 | |
1157 CtrlMessLen EQU *-CtrlMess | |
1158 | |
1159 | |
1160 | |
1161 fdb CtrlMessLen | |
1162 CmdMess | |
1163 fcc "Command byte (" | |
1164 CmdCode fcc "00)" | |
1165 fcb C$CR,C$LF,0 | |
1166 CmdMessLen EQU *-CmdMess | |
1167 | |
1168 fdb 1 | |
1169 DotMess fcc "." | |
1170 fcb 0 | |
1171 | |
1172 | |
1173 fdb ReadDoneMessLen | |
1174 ReadDoneMess | |
1175 fcc "Read Succeded" | |
1176 fcb C$CR,C$LF,0 | |
1177 ReadDoneMessLen EQU *-ReadDoneMess | |
1178 | |
1179 fdb ReadDoneFailMessLen | |
1180 ReadDoneFailMess | |
1181 fcc "Read Failed" | |
1182 fcb C$CR,C$LF,0 | |
1183 ReadDoneFailMessLen EQU *-ReadDoneFailMess | |
1184 | |
1185 | |
1186 fdb NMIMessLen | |
1187 NMIMess | |
1188 fcc "In NMI" | |
1189 fcb C$CR,C$LF,0 | |
1190 NMIMessLen EQU *-NMIMess | |
1191 | |
1192 fdb TimeoutMessLen | |
1193 TimeoutMess | |
1194 fcc "Timout !" | |
1195 fcb C$CR,C$LF,0 | |
1196 TimeoutMessLen EQU *-TimeoutMess | |
952 | 1197 |
953 emod | 1198 emod |
954 eom equ * | 1199 eom equ * |
955 end | 1200 end |