FDC.java
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13: package xeij;
14:
15: import java.awt.event.*;
16: import java.io.*;
17: import java.lang.*;
18: import java.util.*;
19: import javax.swing.*;
20: import javax.swing.filechooser.*;
21:
22: public class FDC {
23:
24: public static final boolean FDC_DEBUG_TRACE = false;
25: public static final boolean FDC_DEBUG_DEFAULT = true;
26: public static boolean fdcDebugLogOn;
27:
28:
29: public static final int FDC_STATUS_PORT = 0x00e94001;
30: public static final int FDC_DATA_PORT = 0x00e94003;
31: public static final int FDC_DRIVE_STATUS = 0x00e94005;
32: public static final int FDC_DRIVE_SELECT = 0x00e94007;
33:
34:
35: public static final int FDC_MIN_UNITS = 2;
36: public static final int FDC_MAX_UNITS = 4;
37:
38: public static FDUnit[] fdcUnitArray;
39:
40:
41: public static JMenu fdcMenu;
42:
43:
44: public static javax.swing.filechooser.FileFilter fdcFileFilter;
45:
46:
47: public static OpenDialog fdcOpenDialog;
48: public static int fdcOpenUnit;
49: public static ArrayList<File[]> fdcOpenHistory;
50:
51:
52: public static JDialog fdcFormatDialog;
53: public static JCheckBox fdcFormatX86SafeCheckBox;
54: public static JFileChooser2 fdcFormatFileChooser;
55: public static FDMedia fdcFormatMedia;
56:
57: public static boolean fdcFormatX86SafeOn;
58: public static JCheckBox fdcFormatCopyHumanSysCheckBox;
59: public static JCheckBox fdcFormatCopyCommandXCheckBox;
60: public static boolean fdcFormatCopyHumanSysOn;
61: public static boolean fdcFormatCopyCommandXOn;
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108: public static final int FDC_RQM = 0x80;
109: public static final int FDC_MPU_TO_FDC = 0x00;
110: public static final int FDC_FDC_TO_MPU = 0x40;
111: public static final int FDC_NDM = 0x20;
112: public static final int FDC_CB = 0x10;
113: public static final int FDC_D3B = 0x08;
114: public static final int FDC_D2B = 0x04;
115: public static final int FDC_D1B = 0x02;
116: public static final int FDC_D0B = 0x01;
117: public static int fdcStatus;
118: public static int fdcLastStatus;
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151: public static final int FDC_ST0_NT = 0x00 << 24;
152: public static final int FDC_ST0_AT = 0x40 << 24;
153: public static final int FDC_ST0_IC = 0x80 << 24;
154: public static final int FDC_ST0_AI = 0xc0 << 24;
155: public static final int FDC_ST0_SE = 0x20 << 24;
156: public static final int FDC_ST0_EC = 0x10 << 24;
157: public static final int FDC_ST0_NR = 0x08 << 24;
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184: public static final int FDC_ST1_EN = 0x80 << 16;
185: public static final int FDC_ST1_DE = 0x20 << 16;
186: public static final int FDC_ST1_OR = 0x10 << 16;
187: public static final int FDC_ST1_ND = 0x04 << 16;
188: public static final int FDC_ST1_NW = 0x02 << 16;
189: public static final int FDC_ST1_MA = 0x01 << 16;
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215: public static final int FDC_ST2_CM = 0x40 << 8;
216: public static final int FDC_ST2_DD = 0x20 << 8;
217: public static final int FDC_ST2_NC = 0x10 << 8;
218: public static final int FDC_ST2_SH = 0x08 << 8;
219: public static final int FDC_ST2_SN = 0x04 << 8;
220: public static final int FDC_ST2_BC = 0x02 << 8;
221: public static final int FDC_ST2_MD = 0x01 << 8;
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242: public static final int FDC_ST3_FT = 0x80;
243: public static final int FDC_ST3_WP = 0x40;
244: public static final int FDC_ST3_RY = 0x20;
245: public static final int FDC_ST3_T0 = 0x10;
246: public static final int FDC_ST3_TS = 0x08;
247:
248:
249:
250: public static final String[] FDC_COMMAND_NAME = {
251: "INVALID",
252: "INVALID",
253: "READ DIAGNOSTIC",
254: "SPECIFY",
255: "SENSE DEVICE STATUS",
256: "WRITE DATA",
257: "READ DATA",
258: "RECALIBRATE",
259: "SENSE INTERRUPT STATUS",
260: "WRITE DELETED DATA",
261: "READ ID",
262: "INVALID",
263: "READ DELETED DATA",
264: "WRITE ID",
265: "INVALID",
266: "SEEK",
267: "INVALID",
268: "SCAN EQUAL",
269: "INVALID",
270: "INVALID",
271: "RESET STANDBY",
272: "SET STANDBY",
273: "SOFTWARE RESET",
274: "INVALID",
275: "INVALID",
276: "SCAN LOW OR EQUAL",
277: "INVALID",
278: "INVALID",
279: "INVALID",
280: "SCAN HIGH OR EQUAL",
281: "INVALID",
282: "INVALID",
283: };
284:
285:
286:
287:
288:
289:
290:
291:
292:
293:
294:
295:
296:
297:
298:
299:
300:
301:
302:
303:
304:
305:
306:
307:
308:
309:
310:
311:
312:
313:
314:
315:
316:
317:
318:
319:
320:
321: public static final byte[] FDC_COMMAND_LENGTH = "\1\1\t\3\2\t\t\2\1\t\2\1\t\6\1\3\1\t\1\1\1\1\1\1\1\t\1\1\1\t\1\1".getBytes (XEiJ.ISO_8859_1);
322: public static int fdcCommandNumber;
323:
324:
325: public static final byte[] fdcCommandBuffer = new byte[256];
326: public static final byte[] fdcResultBuffer = new byte[256];
327: public static final byte[] fdcTempBuffer = new byte[16384];
328: public static byte[] fdcReadHandle;
329: public static byte[] fdcWriteHandle;
330: public static int fdcIndex;
331: public static int fdcStart;
332: public static int fdcLimit;
333:
334:
335: public static boolean fdcEnforcedReady;
336:
337:
338:
339:
340: public static FDUnit fdcDriveLastSelected;
341:
342:
343:
344:
345:
346:
347:
348:
349:
350:
351:
352:
353:
354:
355:
356:
357:
358:
359:
360:
361:
362:
363:
364:
365:
366:
367:
368:
369:
370:
371:
372:
373:
374:
375:
376:
377:
378:
379:
380:
381:
382:
383:
384:
385:
386:
387:
388:
389:
390:
391:
392:
393:
394:
395:
396:
397:
398:
399:
400:
401:
402:
403:
404:
405:
406:
407:
408:
409:
410:
411:
412:
413:
414:
415:
416:
417:
418:
419:
420:
421:
422:
423:
424:
425:
426:
427:
428:
429:
430:
431:
432:
433:
434:
435:
436:
437:
438:
439:
440:
441:
442:
443:
444:
445:
446:
447:
448:
449:
450:
451:
452:
453:
454:
455:
456:
457:
458:
459:
460:
461:
462:
463:
464:
465:
466:
467:
468:
469:
470:
471:
472:
473:
474:
475:
476:
477:
478:
479:
480:
481:
482:
483:
484:
485:
486:
487:
488:
489:
490:
491:
492:
493:
494:
495:
496:
497:
498:
499:
500:
501:
502:
503:
504:
505:
506:
507:
508:
509:
510:
511:
512:
513:
514:
515:
516:
517:
518:
519:
520:
521:
522:
523:
524:
525:
526:
527:
528:
529:
530:
531:
532:
533:
534:
535:
536:
537:
538:
539:
540:
541:
542:
543:
544:
545:
546:
547:
548: public static int fdcSRT;
549:
550:
551:
552: public static void fdcInit () {
553: if (FDC_DEBUG_TRACE) {
554: System.out.printf ("%08x fdcInit()\n", XEiJ.regPC0);
555: fdcDebugLogOn = FDC_DEBUG_DEFAULT;
556: }
557:
558:
559:
560:
561: fdcFileFilter = new javax.swing.filechooser.FileFilter () {
562: @Override public boolean accept (File file) {
563: if (file.isDirectory ()) {
564: return true;
565: }
566: if (!file.isFile ()) {
567: return false;
568: }
569: String path = file.getPath ();
570: if (fdcIsInsertedPath (path)) {
571: return false;
572: }
573: int dotIndex = path.lastIndexOf ('.');
574: String upperExt = dotIndex < 0 ? "" : path.substring (dotIndex + 1).toUpperCase ();
575: if (upperExt.equals ("DIM")) {
576: return true;
577: }
578: long longLength = file.length ();
579: if (1024 * 1024 * 16 <= longLength) {
580: return false;
581: }
582: int length = (int) longLength;
583: for (FDMedia media : FDMedia.FDM_ARRAY) {
584: if (media.fdmBytesPerDisk == length) {
585: return true;
586: }
587: }
588: return false;
589: }
590: @Override public String getDescription () {
591: return (Multilingual.mlnJapanese ?
592: "フロッピーディスクのイメージファイル (*.XDF,*.2HD,*.2HC,*.DIM,etc.)" :
593: "Floppy disk image files (*.XDF,*.2HD,*.2HC,*.DIM,etc.)");
594: }
595: };
596:
597:
598: fdcOpenDialog = null;
599: fdcOpenUnit = 0;
600: fdcOpenHistory = new ArrayList<File[]> ();
601: for (int i = JFileChooser2.MAXIMUM_HISTORY_COUNT - 1; 0 <= i; i--) {
602: fdcAddHistory (JFileChooser2.pathsToFiles (Settings.sgsGetString ("fdhistory" + i)));
603: }
604:
605:
606: fdcFormatDialog = null;
607: fdcFormatX86SafeCheckBox = null;
608: fdcFormatFileChooser = null;
609: fdcFormatMedia = FDMedia.FDM_2HD;
610:
611: fdcFormatX86SafeOn = true;
612: fdcFormatCopyHumanSysCheckBox = null;
613: fdcFormatCopyCommandXCheckBox = null;
614: fdcFormatCopyHumanSysOn = true;
615: fdcFormatCopyCommandXOn = true;
616:
617:
618:
619: fdcUnitArray = new FDUnit[FDC_MAX_UNITS];
620: for (int u = 0; u < FDC_MAX_UNITS; u++) {
621: FDUnit unit = fdcUnitArray[u] = new FDUnit (u);
622: if (u < FDC_MIN_UNITS) {
623: unit.connect (false);
624: }
625: String path = Settings.sgsGetString ("fd" + u);
626: boolean userWriteProtect = false;
627: if (path.toUpperCase ().endsWith (":R")) {
628: path = path.substring (0, path.length () - 2);
629: userWriteProtect = true;
630: }
631: boolean hostWriteProtect = !new File (path).canWrite ();
632: if (path.length () != 0) {
633: unit.connect (true);
634: if (unit.insert (path,
635: userWriteProtect || hostWriteProtect)) {
636: fdcAddHistory (new File (path).getAbsoluteFile ());
637: }
638: }
639: }
640:
641:
642:
643:
644: fdcCPhase ();
645: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
646: fdcLastStatus = -1;
647: }
648: fdcEnforcedReady = false;
649: fdcDriveLastSelected = null;
650: fdcSRT = 3;
651: }
652:
653:
654: public static void fdcReset () {
655: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
656: System.out.printf ("%08x fdcReset()\n", XEiJ.regPC0);
657: }
658:
659:
660:
661:
662:
663:
664:
665: fdcCPhase ();
666: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
667: fdcLastStatus = -1;
668: }
669: fdcEnforcedReady = false;
670: fdcDriveLastSelected = null;
671: fdcSRT = 3;
672:
673:
674: for (int u = 0; u <= 3; u++) {
675: FDUnit unit = fdcUnitArray[u];
676: if (unit.fduIsInserted ()) {
677: IOInterrupt.ioiFddFall ();
678: IOInterrupt.ioiFddRise ();
679: break;
680: }
681: }
682:
683: }
684:
685:
686:
687:
688: public static void fdcTini () {
689: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
690: System.out.printf ("%08x fdcTini()\n", XEiJ.regPC0);
691: }
692: for (FDUnit unit : fdcUnitArray) {
693: unit.fduTini ();
694: }
695:
696:
697:
698: if (fdcOpenDialog != null) {
699: Settings.sgsPutOnOff ("fdreadonly", fdcOpenDialog.getReadOnly ());
700: Settings.sgsPutOnOff ("fdappreboot", fdcOpenDialog.getReboot ());
701: ArrayList<String> pathsList = fdcOpenDialog.getHistory ();
702: int n = pathsList.size ();
703: for (int i = 0; i < n; i++) {
704: Settings.sgsPutString ("fdhistory" + i, pathsList.get (i));
705: }
706: for (int i = n; i < FDC_MAX_UNITS; i++) {
707: Settings.sgsPutString ("fdhistory" + i, "");
708: }
709: }
710:
711:
712: for (int u = 0; u < FDC_MAX_UNITS; u++) {
713: AbstractUnit unit = fdcUnitArray[u];
714: Settings.sgsPutString (
715: "fd" + u,
716: unit.abuConnected && unit.abuInserted ?
717: unit.abuWriteProtected ? unit.abuPath + ":R" : unit.abuPath :
718: "");
719: }
720:
721: }
722:
723: public static void fdcMakeMenu () {
724:
725:
726: ActionListener listener = new ActionListener () {
727: @Override public void actionPerformed (ActionEvent ae) {
728: Object source = ae.getSource ();
729: String command = ae.getActionCommand ();
730: switch (command) {
731: case "Create new floppy disk image files":
732: fdcOpenFormatDialog ();
733: break;
734: case "FDC debug log":
735: if (FDC_DEBUG_TRACE) {
736: fdcDebugLogOn = ((JCheckBoxMenuItem) source).isSelected ();
737: }
738: break;
739: }
740: }
741: };
742:
743:
744: fdcMenu = ComponentFactory.createMenu ("FD");
745: ComponentFactory.addComponents (
746: fdcMenu,
747: ComponentFactory.createHorizontalBox (
748: Multilingual.mlnText (ComponentFactory.createLabel ("Floppy disk"),
749: "ja", "フロッピーディスク")),
750: ComponentFactory.createHorizontalSeparator ()
751: );
752: for (FDUnit unit : fdcUnitArray) {
753: fdcMenu.add (unit.getMenuBox ());
754: }
755: ComponentFactory.addComponents (
756: fdcMenu,
757: ComponentFactory.createHorizontalSeparator (),
758: Multilingual.mlnText (ComponentFactory.createMenuItem ("Create new floppy disk image files", listener),
759: "ja", "フロッピーディスクのイメージファイルの新規作成"),
760: !FDC_DEBUG_TRACE ? null :
761: Multilingual.mlnText (ComponentFactory.createCheckBoxMenuItem (fdcDebugLogOn, "FDC debug log", listener), "ja", "FDC デバッグログ")
762: );
763:
764: }
765:
766:
767:
768: public static boolean fdcIsInsertedPath (String path) {
769: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
770: System.out.printf ("%08x fdcIsInsertedPath(\"%s\")\n", XEiJ.regPC0, path);
771: }
772: boolean inserted = false;
773: for (FDUnit unit : fdcUnitArray) {
774: if (unit != null &&
775: unit.abuConnected &&
776: unit.fduIsInserted () &&
777: unit.abuPath.equals (path)) {
778: inserted = true;
779: break;
780: }
781: }
782: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
783: System.out.printf ("\tinserted=%b\n", inserted);
784: }
785: return inserted;
786: }
787:
788: static class OpenDialog extends AbstractOpenDialog {
789: public OpenDialog () {
790: super (XEiJ.frmFrame,
791: "Open floppy disk image files",
792: "フロッピーディスクのイメージファイルを開く",
793: false,
794: fdcFileFilter);
795: }
796: @Override public void openFiles (File[] files, boolean reboot) {
797: fdcOpenFiles (files, reboot);
798: }
799: }
800:
801:
802:
803: public static void fdcOpenFiles (File[] list, boolean reset) {
804: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
805: System.out.printf ("%08x fdcOpenFiles({", XEiJ.regPC0);
806: for (int i = 0; i < list.length; i++) {
807: if (0 < i) {
808: System.out.print (',');
809: }
810: System.out.printf ("\"%s\"", list[i].getPath ());
811: }
812: System.out.printf ("},%b)\n", reset);
813: }
814: boolean success = true;
815: for (int u = fdcOpenUnit, k = 0; k < list.length; ) {
816: if (FDC_MAX_UNITS <= u) {
817: success = false;
818: break;
819: }
820: FDUnit unit = fdcUnitArray[u];
821: if (!unit.abuConnected) {
822: u++;
823: continue;
824: }
825: File file = list[k++];
826: if (!file.isFile ()) {
827: success = false;
828: continue;
829: }
830: if (!unit.insert (file.getPath (),
831: fdcOpenDialog.getReadOnly () || !file.canWrite ())) {
832: success = false;
833: continue;
834: }
835: u++;
836: }
837: if (success) {
838: fdcAddHistory (list);
839: if (reset) {
840: XEiJ.mpuReset (0x9070 | fdcOpenUnit << 8, -1);
841: }
842: }
843: }
844:
845:
846:
847:
848: public static void fdcMakeFormatDialog () {
849:
850: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
851: System.out.printf ("%08x fdcMakeFormatDialog()\n", XEiJ.regPC0);
852: }
853:
854:
855: ActionListener listener = new ActionListener () {
856: @Override public void actionPerformed (ActionEvent ae) {
857: switch (ae.getActionCommand ()) {
858: case JFileChooser.APPROVE_SELECTION:
859: case "Start formatting":
860: {
861: File[] list = fdcFormatFileChooser.getSelectedFiles ();
862: if (list.length > 0) {
863: fdcFormatDialog.setVisible (false);
864: if (!fdcFormatFiles (list)) {
865:
866: }
867: }
868: }
869: break;
870: case JFileChooser.CANCEL_SELECTION:
871: case "Cancel":
872: fdcFormatDialog.setVisible (false);
873: break;
874: case "2HD (1232KB)":
875: fdcFormatMedia = FDMedia.FDM_2HD;
876: fdcFormatX86SafeCheckBox.setSelected (false);
877: fdcFormatX86SafeCheckBox.setEnabled (false);
878: break;
879: case "2HC (1200KB)":
880: fdcFormatMedia = FDMedia.FDM_2HC;
881: fdcFormatX86SafeCheckBox.setSelected (false);
882: fdcFormatX86SafeCheckBox.setEnabled (false);
883: break;
884: case "2DD (640KB)":
885: fdcFormatMedia = FDMedia.FDM_2DD8;
886: fdcFormatX86SafeCheckBox.setSelected (false);
887: fdcFormatX86SafeCheckBox.setEnabled (false);
888: break;
889: case "2DD (720KB)":
890: fdcFormatMedia = FDMedia.FDM_2DD9;
891: fdcFormatX86SafeCheckBox.setSelected (false);
892: fdcFormatX86SafeCheckBox.setEnabled (false);
893: break;
894: case "2HQ (1440KB)":
895: fdcFormatMedia = FDMedia.FDM_2HQ;
896: fdcFormatX86SafeCheckBox.setEnabled (true);
897: fdcFormatX86SafeCheckBox.setSelected (fdcFormatX86SafeOn);
898: break;
899: case "2DD (800KB)":
900: fdcFormatMedia = FDMedia.FDM_2DD10;
901: fdcFormatX86SafeCheckBox.setSelected (false);
902: fdcFormatX86SafeCheckBox.setEnabled (false);
903: break;
904: case "2HDE(1440KB)":
905: fdcFormatMedia = FDMedia.FDM_2HDE;
906: fdcFormatX86SafeCheckBox.setSelected (false);
907: fdcFormatX86SafeCheckBox.setEnabled (false);
908: break;
909: case "2HS (1440KB)":
910: fdcFormatMedia = FDMedia.FDM_2HS;
911: fdcFormatX86SafeCheckBox.setSelected (false);
912: fdcFormatX86SafeCheckBox.setEnabled (false);
913: break;
914:
915:
916:
917: case "HUMAN.SYS":
918: fdcFormatCopyHumanSysOn = fdcFormatCopyHumanSysCheckBox.isSelected ();
919: if (fdcFormatCopyHumanSysOn) {
920: fdcFormatCopyCommandXCheckBox.setEnabled (true);
921: fdcFormatCopyCommandXCheckBox.setSelected (fdcFormatCopyCommandXOn);
922: } else {
923: fdcFormatCopyCommandXCheckBox.setEnabled (false);
924: fdcFormatCopyCommandXCheckBox.setSelected (false);
925: }
926: break;
927: case "COMMAND.X":
928: fdcFormatCopyCommandXOn = fdcFormatCopyCommandXCheckBox.isSelected ();
929: break;
930: case "x86-safe":
931: fdcFormatX86SafeOn = ((JCheckBox) ae.getSource ()).isSelected ();
932: break;
933: }
934: }
935: };
936:
937:
938: fdcMakeFormatFileChooser ();
939: fdcFormatFileChooser.setFileFilter (fdcFileFilter);
940: fdcFormatFileChooser.addActionListener (listener);
941:
942:
943: ButtonGroup mediaGroup = new ButtonGroup ();
944: fdcFormatDialog = Multilingual.mlnTitle (
945: ComponentFactory.createModalDialog (
946: XEiJ.frmFrame,
947: "Create new floppy disk image files",
948: ComponentFactory.createBorderPanel (
949: 0, 0,
950: ComponentFactory.createVerticalBox (
951: fdcFormatFileChooser,
952: ComponentFactory.createHorizontalBox (
953: Box.createHorizontalStrut (12),
954: Box.createHorizontalGlue (),
955: ComponentFactory.createVerticalBox (
956: ComponentFactory.createHorizontalBox (
957: ComponentFactory.createRadioButtonMenuItem (mediaGroup, fdcFormatMedia == FDMedia.FDM_2HD, "2HD (1232KB)", listener),
958: ComponentFactory.createRadioButtonMenuItem (mediaGroup, fdcFormatMedia == FDMedia.FDM_2HC, "2HC (1200KB)", listener),
959: ComponentFactory.createRadioButtonMenuItem (mediaGroup, fdcFormatMedia == FDMedia.FDM_2DD8, "2DD (640KB)", listener),
960: ComponentFactory.createRadioButtonMenuItem (mediaGroup, fdcFormatMedia == FDMedia.FDM_2DD9, "2DD (720KB)", listener),
961: ComponentFactory.createRadioButtonMenuItem (mediaGroup, fdcFormatMedia == FDMedia.FDM_2HQ, "2HQ (1440KB)", listener)
962: ),
963: ComponentFactory.createHorizontalBox (
964: ComponentFactory.createRadioButtonMenuItem (mediaGroup, fdcFormatMedia == FDMedia.FDM_2DD10, "2DD (800KB)", listener),
965: ComponentFactory.createRadioButtonMenuItem (mediaGroup, fdcFormatMedia == FDMedia.FDM_2HDE, "2HDE(1440KB)", listener),
966: ComponentFactory.createRadioButtonMenuItem (mediaGroup, fdcFormatMedia == FDMedia.FDM_2HS, "2HS (1440KB)", listener),
967: Box.createHorizontalGlue (),
968: fdcFormatX86SafeCheckBox = ComponentFactory.setEnabled (
969: Multilingual.mlnText (ComponentFactory.createCheckBox (fdcFormatMedia == FDMedia.FDM_2HQ && fdcFormatX86SafeOn, "x86-safe", listener), "ja", "x86 セーフ"),
970: fdcFormatMedia == FDMedia.FDM_2HQ),
971: Box.createHorizontalStrut (12)
972: )
973: ),
974: Box.createHorizontalGlue (),
975: Box.createHorizontalStrut (12)
976: ),
977: Box.createVerticalStrut (12),
978: ComponentFactory.createHorizontalBox (
979: Box.createHorizontalStrut (12),
980: Box.createHorizontalGlue (),
981:
982: fdcFormatCopyHumanSysCheckBox = ComponentFactory.createCheckBox (fdcFormatCopyHumanSysOn, "HUMAN.SYS", listener),
983: Box.createHorizontalStrut (12),
984: fdcFormatCopyCommandXCheckBox = ComponentFactory.setEnabled (
985: ComponentFactory.createCheckBox (fdcFormatCopyHumanSysOn && fdcFormatCopyCommandXOn, "COMMAND.X", listener),
986: fdcFormatCopyHumanSysOn),
987: Box.createHorizontalGlue (),
988: Box.createHorizontalStrut (12),
989: Multilingual.mlnText (ComponentFactory.createButton ("Start formatting", KeyEvent.VK_F, listener), "ja", "フォーマットを開始する"),
990: Box.createHorizontalStrut (12),
991: Multilingual.mlnText (ComponentFactory.createButton ("Cancel", KeyEvent.VK_C, listener), "ja", "キャンセル"),
992: Box.createHorizontalStrut (12)
993: ),
994: Box.createVerticalStrut (12)
995: )
996: )
997: ),
998: "ja", "フロッピーディスクのイメージファイルの新規作成");
999:
1000: }
1001:
1002:
1003:
1004: public static void fdcMakeFormatFileChooser () {
1005: if (fdcFormatFileChooser == null) {
1006: fdcFormatFileChooser = new JFileChooser2 ();
1007:
1008: fdcFormatFileChooser.setControlButtonsAreShown (false);
1009: }
1010: }
1011:
1012:
1013:
1014:
1015: public static void fdcOpenFormatDialog () {
1016: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
1017: System.out.printf ("%08x fdcOpenFormatDialog()\n", XEiJ.regPC0);
1018: }
1019: if (fdcFormatDialog == null) {
1020: fdcMakeFormatDialog ();
1021: }
1022: fdcFormatFileChooser.rescanCurrentDirectory ();
1023: XEiJ.pnlExitFullScreen (true);
1024: fdcFormatDialog.setVisible (true);
1025: }
1026:
1027:
1028:
1029:
1030: public static boolean fdcFormatFiles (File[] list) {
1031: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
1032: System.out.printf ("%08x fdcFormatFiles({", XEiJ.regPC0);
1033: for (int i = 0; i < list.length; i++) {
1034: if (0 < i) {
1035: System.out.print (',');
1036: }
1037: System.out.printf ("\"%s\"", list[i].getPath ());
1038: }
1039: System.out.println ('}');
1040: }
1041: boolean success = true;
1042: format:
1043: {
1044:
1045: byte[] diskImage = new byte[fdcFormatMedia.fdmBytesPerDisk];
1046: if (!fdcFormatMedia.fdmMakeFormatData (diskImage, fdcFormatCopyHumanSysOn, fdcFormatCopyCommandXOn, fdcFormatX86SafeOn)) {
1047: success = false;
1048: break format;
1049: }
1050: byte[] dimImage = null;
1051: int dimSize = 0;
1052:
1053: int u = 0;
1054: for (File file : list) {
1055: String path = file.getPath ();
1056: String upperPath = path.toUpperCase ();
1057: if (upperPath.endsWith (".DIM")) {
1058: if (fdcIsInsertedPath (path)) {
1059: success = false;
1060: break format;
1061: }
1062: if (dimImage == null) {
1063: dimImage = new byte[256 + fdcFormatMedia.fdmBytesPerDisk];
1064: dimSize = fdcFormatMedia.fdmMakeDimImage (dimImage, diskImage);
1065: if (dimSize < 0) {
1066: success = false;
1067: break format;
1068: }
1069: }
1070: if (!XEiJ.rscPutFile (path, dimImage, 0, dimSize)) {
1071: success = false;
1072: break format;
1073: }
1074: } else {
1075: boolean extNotSpecified = true;
1076: for (String mediaExt : fdcFormatMedia.fdmExtensionArray) {
1077: if (upperPath.endsWith (mediaExt)) {
1078: extNotSpecified = false;
1079: break;
1080: }
1081: }
1082: if (extNotSpecified) {
1083: if (!path.endsWith (".")) {
1084: path += ".";
1085: }
1086: path += fdcFormatMedia.fdmExtensionArray[0].toLowerCase ();
1087: upperPath = path.toUpperCase ();
1088: }
1089: if (fdcIsInsertedPath (path)) {
1090: success = false;
1091: break format;
1092: }
1093: if (!XEiJ.rscPutFile (path, diskImage, 0, fdcFormatMedia.fdmBytesPerDisk)) {
1094: success = false;
1095: break format;
1096: }
1097: }
1098:
1099: while (u < FDC_MAX_UNITS) {
1100: FDUnit unit = fdcUnitArray[u++];
1101: if (unit.abuConnected &&
1102: !unit.fduIsInserted () &&
1103: unit.insert (path,
1104: false)) {
1105:
1106: break;
1107: }
1108: }
1109: }
1110: }
1111: if (success) {
1112: fdcAddHistory (list);
1113: }
1114: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
1115: System.out.printf ("\tsuccess=%b\n", success);
1116: }
1117: return success;
1118: }
1119:
1120:
1121:
1122:
1123: public static void fdcAddHistory (File file) {
1124: fdcAddHistory (new File[] { file });
1125: }
1126:
1127:
1128:
1129: public static void fdcAddHistory (File[] files) {
1130: if (fdcOpenDialog == null) {
1131: fdcOpenHistory.add (files);
1132: } else {
1133: fdcOpenDialog.addHistory (files);
1134: }
1135: fdcMakeFormatFileChooser ();
1136: fdcFormatFileChooser.addHistory (files);
1137: fdcFormatFileChooser.selectLastFiles ();
1138: }
1139:
1140:
1141:
1142:
1143:
1144: public static int fdcPeekStatus () {
1145: return fdcStatus;
1146: }
1147:
1148:
1149:
1150:
1151: public static int fdcReadStatus () {
1152: int d = fdcStatus;
1153: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
1154: if (fdcLastStatus == d) {
1155: System.out.print ('=');
1156: } else {
1157: fdcLastStatus = d;
1158: System.out.printf ("%08x fdcReadStatus(0x00e94001)=%s\n", XEiJ.regPC0, fdcStatusToString (d));
1159: }
1160: }
1161: return d;
1162: }
1163:
1164:
1165:
1166:
1167: public static int fdcPeekData () {
1168: return (fdcReadHandle == null ? 0 :
1169: fdcReadHandle[fdcIndex] & 255);
1170: }
1171:
1172:
1173:
1174:
1175: public static int fdcReadData () {
1176: if (fdcReadHandle == null) {
1177: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
1178: System.out.printf ("%08x fdcReadData(0x00e94003=???)=0x00\n", XEiJ.regPC0);
1179: }
1180: return 0;
1181: }
1182: int d = fdcReadHandle[fdcIndex] & 255;
1183: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
1184: if (fdcIndex < fdcStart + 8 || fdcLimit - 8 <= fdcIndex) {
1185: System.out.printf ("%08x fdcReadData(0x00e94003=%s[0x%08x])=0x%02x\n",
1186: XEiJ.regPC0,
1187: fdcReadHandle == fdcResultBuffer ? "fdcResultBuffer" :
1188: fdcReadHandle == fdcTempBuffer ? "fdcTempBuffer" :
1189: "fduImage",
1190: fdcIndex,
1191: d);
1192: }
1193: }
1194: fdcIndex++;
1195: if (fdcIndex < fdcLimit) {
1196: if (fdcReadHandle != fdcResultBuffer) {
1197: HD63450.dmaFallPCL (0);
1198: } else {
1199: if (fdcIndex == 1) {
1200: fdcStatus &= ~(1 << (d & 3));
1201: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
1202: System.out.printf ("\tfdcStatus=%s\n", fdcStatusToString (fdcStatus));
1203: }
1204: }
1205: }
1206: } else {
1207: if (fdcReadHandle != fdcResultBuffer) {
1208: fdcEPhaseEnd ();
1209: } else {
1210: fdcRPhaseEnd ();
1211: }
1212: }
1213: return d;
1214: }
1215:
1216:
1217:
1218:
1219: public static int fdcPeekDriveStatus () {
1220: return (fdcDriveLastSelected == null ? 0 :
1221: fdcDriveLastSelected.fduDriveStatus ());
1222: }
1223:
1224:
1225:
1226:
1227: public static int fdcReadDriveStatus () {
1228: int d = (fdcDriveLastSelected == null ? 0 :
1229: fdcDriveLastSelected.fduDriveStatus ());
1230: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
1231: System.out.printf ("%08x fdcReadDriveStatus(0x00e94005)=0x%02x(挿入=%d 誤挿入=%d)\n",
1232: XEiJ.regPC0,
1233: d,
1234: d >> 7,
1235: d >> 6 & 1);
1236: }
1237: return d;
1238: }
1239:
1240:
1241:
1242:
1243: public static void fdcWriteCommand (int d) {
1244: if (fdcWriteHandle != fdcCommandBuffer) {
1245: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
1246: System.out.printf ("%08x fdcWriteCommand(0x00e94001=???,0x%02x)\n",
1247: XEiJ.regPC0,
1248: d & 255);
1249: }
1250: return;
1251: }
1252: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
1253: if (fdcIndex < fdcStart + 8 || fdcLimit - 8 <= fdcIndex) {
1254: System.out.printf ("%08x fdcWriteCommand(0x00e94001=%s[0x%08x],0x%02x)\n",
1255: XEiJ.regPC0,
1256: "fdcCommandBuffer",
1257: fdcIndex,
1258: d & 255);
1259: }
1260: }
1261: fdcWriteHandle[fdcIndex++] = (byte) d;
1262: if (fdcLimit <= fdcIndex) {
1263: fdcCPhaseEnd ();
1264: }
1265: }
1266:
1267:
1268:
1269:
1270: public static void fdcWriteData (int d) {
1271: if (fdcWriteHandle == null) {
1272: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
1273: System.out.printf ("%08x fdcWriteData(0x00e94003=???,0x%02x)\n",
1274: XEiJ.regPC0,
1275: d & 255);
1276: }
1277: return;
1278: }
1279: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
1280: if (fdcIndex < fdcStart + 8 || fdcLimit - 8 <= fdcIndex) {
1281: System.out.printf ("%08x fdcWriteData(0x00e94003=%s[0x%08x],0x%02x)\n",
1282: XEiJ.regPC0,
1283: fdcWriteHandle == fdcCommandBuffer ? "fdcCommandBuffer" :
1284: fdcWriteHandle == fdcTempBuffer ? "fdcTempBuffer" :
1285: "fduImage",
1286: fdcIndex,
1287: d & 255);
1288: }
1289: }
1290: fdcWriteHandle[fdcIndex++] = (byte) d;
1291: if (fdcIndex < fdcLimit) {
1292: if (fdcWriteHandle != fdcCommandBuffer) {
1293: HD63450.dmaFallPCL (0);
1294: }
1295: } else if (fdcWriteHandle == fdcCommandBuffer) {
1296: fdcCPhaseEnd ();
1297: } else {
1298: fdcEPhaseEnd ();
1299: }
1300: }
1301:
1302:
1303:
1304:
1305: public static void fdcCPhase () {
1306: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
1307: System.out.printf ("%08x fdcCPhase()\n", XEiJ.regPC0);
1308: }
1309:
1310: fdcStatus = (FDC_RQM | FDC_MPU_TO_FDC |
1311: (fdcStatus & (FDC_D3B | FDC_D2B | FDC_D1B | FDC_D0B)));
1312: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
1313: System.out.printf ("\tfdcStatus=%s\n", fdcStatusToString (fdcStatus));
1314: }
1315:
1316: fdcReadHandle = null;
1317: fdcWriteHandle = fdcCommandBuffer;
1318: fdcIndex = fdcStart = 0;
1319: fdcLimit = 1;
1320: fdcCommandNumber = -1;
1321: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
1322: System.out.printf ("\tfdcCommandNumber=%d\n", fdcCommandNumber);
1323: }
1324: for (int u = 0; u <= 3; u++) {
1325: FDUnit unit = fdcUnitArray[u];
1326: if (unit.fduSeekStepWaiting) {
1327: unit.fduSeekStepWaiting = false;
1328: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
1329: System.out.printf ("\tfduSeekStepWaiting%d=%b\n", u, unit.fduSeekStepWaiting);
1330: }
1331: unit.fduSeekStep ();
1332: }
1333: if ((fdcStatus & 1 << u) != 0) {
1334: if (unit.fduSeekEndInterruptWaiting) {
1335: unit.fduSeekEndInterruptWaiting = false;
1336: unit.fduSeekEndInterruptRequest = true;
1337: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
1338: System.out.printf ("\tfduSeekEndInterruptWaiting%d=%b\n", u, unit.fduSeekEndInterruptWaiting);
1339: System.out.printf ("\tfduSeekEndInterruptRequest%d=%b\n", u, unit.fduSeekEndInterruptRequest);
1340: }
1341: IOInterrupt.ioiFdcRise ();
1342: }
1343: } else {
1344: if (unit.fduAttentionCheckWaiting) {
1345: unit.fduAttentionCheckWaiting = false;
1346: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
1347: System.out.printf ("\tfduAttentionCheckWaiting%d=%b\n", u, unit.fduAttentionCheckWaiting);
1348: }
1349: boolean ready = unit.fduIsReady ();
1350: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
1351: System.out.printf ("\tready%d=%b\n", u, ready);
1352: }
1353: if (ready != unit.fduSavedReady) {
1354: unit.fduSavedReady = ready;
1355: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
1356: System.out.printf ("\tfduSavedReady%d=%b\n", u, unit.fduSavedReady);
1357: }
1358: if (!unit.fduAttentionInterruptRequest) {
1359: unit.fduAttentionInterruptRequest = true;
1360: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
1361: System.out.printf ("\tfduAttentionInterruptRequest%d=%b\n", u, unit.fduAttentionInterruptRequest);
1362: }
1363: IOInterrupt.ioiFdcRise ();
1364: }
1365: }
1366: }
1367: }
1368: }
1369: }
1370:
1371:
1372:
1373: public static void fdcCPhaseEnd () {
1374: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
1375: System.out.printf ("%08x fdcCPhaseEnd()\n", XEiJ.regPC0);
1376: }
1377: if (fdcCommandNumber < 0) {
1378: fdcCommandNumber = fdcCommandBuffer[0] & 31;
1379: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
1380: System.out.printf ("\tfdcCommandNumber=%d\n", fdcCommandNumber);
1381: }
1382: fdcLimit = FDC_COMMAND_LENGTH[fdcCommandNumber];
1383: if (1 < fdcLimit) {
1384: fdcStatus |= FDC_CB;
1385: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
1386: System.out.printf ("\tfdcStatus=%s\n", fdcStatusToString (fdcStatus));
1387: }
1388:
1389:
1390:
1391: return;
1392: }
1393:
1394: }
1395:
1396: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
1397: System.out.printf ("********* %s {",
1398: FDC_COMMAND_NAME[fdcCommandNumber]);
1399: for (int i = 0; i < fdcLimit; i++) {
1400: if (i > 0) {
1401: System.out.print (',');
1402: }
1403: System.out.printf ("0x%02x", fdcCommandBuffer[i] & 255);
1404: }
1405: System.out.println ("} ********");
1406: }
1407: FDUnit unit = fdcUnitArray[fdcCommandBuffer[1] & 3];
1408: switch (fdcCommandNumber) {
1409:
1410:
1411:
1412: case 0x03:
1413: fdcCommandSpecify ();
1414: break;
1415: case 0x04:
1416: unit.fduCommandSenseDeviceStatus ();
1417: break;
1418: case 0x05:
1419: unit.fduCommandWriteData ();
1420: break;
1421: case 0x06:
1422: unit.fduCommandReadData ();
1423: break;
1424: case 0x07:
1425: unit.fduCommandRecalibrate ();
1426: break;
1427: case 0x08:
1428: fdcCommandSenseInterruptStatus ();
1429: break;
1430:
1431:
1432:
1433: case 0x0a:
1434: unit.fduCommandReadId ();
1435: break;
1436:
1437:
1438:
1439: case 0x0d:
1440: unit.fduCommandWriteId ();
1441: break;
1442: case 0x0f:
1443: unit.fduCommandSeek ();
1444: break;
1445: case 0x11:
1446: unit.fduCommandScan ();
1447: break;
1448:
1449:
1450:
1451:
1452:
1453:
1454: case 0x16:
1455: fdcCommandSoftwareReset ();
1456: break;
1457: case 0x19:
1458: unit.fduCommandScan ();
1459: break;
1460: case 0x1d:
1461: unit.fduCommandScan ();
1462: break;
1463:
1464:
1465:
1466:
1467:
1468:
1469:
1470:
1471:
1472:
1473:
1474:
1475:
1476:
1477: default:
1478: fdcCommandInvalid ();
1479: }
1480: }
1481:
1482:
1483:
1484: public static void fdcEPhaseEnd () {
1485: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
1486: System.out.printf ("%08x fdcEPhaseEnd()\n", XEiJ.regPC0);
1487: }
1488: FDUnit unit = fdcUnitArray[fdcCommandBuffer[1] & 3];
1489: switch (unit.fduCommandNumber) {
1490: case 0x05:
1491: unit.fduWriteDataEPhaseEnd ();
1492: break;
1493: case 0x06:
1494: unit.fduReadDataEPhaseEnd ();
1495: break;
1496: case 0x0d:
1497: unit.fduWriteIdEPhaseEnd ();
1498: break;
1499: case 0x11:
1500: unit.fduScanEqualEPhaseEnd ();
1501: break;
1502: case 0x19:
1503: unit.fduScanLowOrEqualEPhaseEnd ();
1504: break;
1505: case 0x1d:
1506: unit.fduScanHighOrEqualEPhaseEnd ();
1507: break;
1508: }
1509: }
1510:
1511:
1512:
1513: public static void fdcRPhase (int limit) {
1514: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
1515: System.out.printf ("%08x fdcRPhase({", XEiJ.regPC0);
1516: for (int i = 0; i < limit; i++) {
1517: if (0 < i) {
1518: System.out.print (',');
1519: }
1520: System.out.printf ("0x%02x", fdcResultBuffer[i] & 255);
1521: }
1522: System.out.println ("})");
1523: }
1524: fdcStatus = (FDC_RQM | FDC_FDC_TO_MPU | FDC_CB |
1525: (fdcStatus & (FDC_D3B | FDC_D2B | FDC_D1B | FDC_D0B)));
1526: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
1527: System.out.printf ("\tfdcStatus=%s\n", fdcStatusToString (fdcStatus));
1528: }
1529: fdcReadHandle = fdcResultBuffer;
1530: fdcWriteHandle = null;
1531: fdcIndex = fdcStart = 0;
1532: fdcLimit = limit;
1533: }
1534:
1535:
1536:
1537: public static void fdcRPhaseEnd () {
1538: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
1539: System.out.printf ("%08x fdcRPhaseEnd()\n", XEiJ.regPC0);
1540: }
1541: fdcCPhase ();
1542:
1543: for (int u = 0; u <= 3; u++) {
1544: FDUnit unit = fdcUnitArray[u];
1545: if (unit.fduSeekEndInterruptRequest) {
1546: IOInterrupt.ioiFdcRise ();
1547: break;
1548: }
1549: }
1550: }
1551:
1552:
1553:
1554:
1555:
1556: public static void fdcWriteDriveControl (int d) {
1557:
1558: IOInterrupt.ioiFddFall ();
1559: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
1560: System.out.printf ("%08x fdcWriteDriveControl(0x00e94005,0x%02x(BLK=%d PRV=%d EJT=%d US3=%d US2=%d US1=%d US0=%d))\n",
1561: XEiJ.regPC0,
1562: d & 255,
1563: d >> 7,
1564: d >> 6 & 1,
1565: d >> 5 & 1,
1566: d >> 3 & 1,
1567: d >> 2 & 1,
1568: d >> 1 & 1,
1569: d & 1);
1570: }
1571:
1572: int u = Integer.numberOfTrailingZeros (d & 15);
1573: if (u < 4) {
1574: FDUnit unit = fdcUnitArray[u];
1575: if (unit.abuConnected) {
1576: unit.fduDriveControl (d);
1577: }
1578: fdcDriveLastSelected = unit;
1579: } else {
1580: fdcDriveLastSelected = null;
1581: }
1582: }
1583:
1584:
1585:
1586:
1587: public static void fdcWriteDriveSelect (int d) {
1588: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
1589: System.out.printf ("%08x fdcWriteDriveSelect(0x00e94007,0x%02x(MT=%d 2DD=%d US=%d))\n",
1590: XEiJ.regPC0,
1591: d & 255,
1592: d >> 7,
1593: d >> 4 & 1,
1594: d & 3);
1595: }
1596: IOInterrupt.ioiFddFall ();
1597: FDUnit unit = fdcUnitArray[d & 3];
1598: if (unit.abuConnected &&
1599: unit.fduIsInserted ()) {
1600: unit.fduDoubleDensity = d << 31 - 4 < 0;
1601: if ((byte) d < 0) {
1602: unit.fduMotorOn ();
1603: } else {
1604: unit.fduMotorOff ();
1605: }
1606: }
1607: }
1608:
1609:
1610:
1611: public static void fdcSetEnforcedReady (boolean enforcedReady) {
1612: fdcEnforcedReady = enforcedReady;
1613: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
1614: System.out.printf ("%08x fdcSetEnforcedReady(%b)\n", XEiJ.regPC0, enforcedReady);
1615: }
1616: }
1617:
1618:
1619:
1620:
1621:
1622:
1623:
1624:
1625:
1626:
1627:
1628: public static void fdcCommandSpecify () {
1629: int srt = fdcCommandBuffer[1] >> 4 & 15;
1630: int hut = fdcCommandBuffer[1] & 15;
1631: int hlt = fdcCommandBuffer[2] >> 1 & 127;
1632: int nd = fdcCommandBuffer[2] & 1;
1633: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
1634: System.out.printf ("%08x fdcCommandSpecify(SRT=%d HUT=%d HLT=%d ND=%d)\n", XEiJ.regPC0, srt, hut, hlt, nd);
1635: }
1636: fdcSRT = srt;
1637: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
1638: System.out.printf ("\tfdcSRT=%d\n", fdcSRT);
1639: }
1640: fdcCPhase ();
1641: }
1642:
1643:
1644:
1645:
1646:
1647:
1648:
1649:
1650:
1651:
1652:
1653: public static void fdcCommandSenseInterruptStatus () {
1654: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
1655: System.out.printf ("%08x fdcCommandSenseInterruptStatus()\n", XEiJ.regPC0);
1656: }
1657:
1658: IOInterrupt.ioiFdcFall ();
1659: for (int u = 0; u <= 3; u++) {
1660: FDUnit unit = fdcUnitArray[u];
1661: if ((fdcStatus & 1 << u) != 0) {
1662: if (unit.fduSeekEndInterruptWaiting) {
1663: unit.fduSeekEndInterruptWaiting = false;
1664: unit.fduSeekEndInterruptRequest = true;
1665: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
1666: System.out.printf ("\tfduSeekEndInterruptWaiting%d=%b\n", u, unit.fduSeekEndInterruptWaiting);
1667: System.out.printf ("\tfduSeekEndInterruptRequest%d=%b\n", u, unit.fduSeekEndInterruptRequest);
1668: }
1669: } else {
1670: if (unit.fduAttentionCheckWaiting) {
1671: unit.fduAttentionCheckWaiting = false;
1672: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
1673: System.out.printf ("\tfduAttentionCheckWaiting%d=%b\n", u, unit.fduAttentionCheckWaiting);
1674: }
1675: boolean ready = unit.fduIsReady ();
1676: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
1677: System.out.printf ("\tready%d=%b\n", u, ready);
1678: }
1679: if (ready != unit.fduSavedReady) {
1680: unit.fduSavedReady = ready;
1681: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
1682: System.out.printf ("\tfduSavedReady%d=%b\n", u, unit.fduSavedReady);
1683: }
1684: if (!unit.fduAttentionInterruptRequest) {
1685: unit.fduAttentionInterruptRequest = true;
1686: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
1687: System.out.printf ("\tfduAttentionInterruptRequest%d=%b\n", u, unit.fduAttentionInterruptRequest);
1688: }
1689: }
1690: }
1691: }
1692: }
1693: }
1694: }
1695: int status = FDC_ST0_IC;
1696: for (int u = 0; u <= 3; u++) {
1697: FDUnit unit = fdcUnitArray[u];
1698: if (unit.fduSeekEndInterruptRequest) {
1699: unit.fduSeekEndInterruptRequest = false;
1700: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
1701: System.out.printf ("\tfduSeekEndInterruptRequest%d=%b\n", u, unit.fduSeekEndInterruptRequest);
1702: }
1703: status = unit.fduSeekResultStatus | u << 24 | (unit.fduPCN & 255) << 16;
1704: break;
1705: }
1706: if (unit.fduAttentionInterruptRequest) {
1707: unit.fduAttentionInterruptRequest = false;
1708: status = FDC_ST0_AI | u << 24 | (unit.fduPCN & 255) << 16;
1709: break;
1710: }
1711: }
1712: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
1713: System.out.printf ("\tstatus=%s\n", fdcResultStatusToString (status & 0xff000000));
1714: }
1715: fdcResultBuffer[0] = (byte) (status >> 24);
1716: if (status == FDC_ST0_IC) {
1717: fdcRPhase (1);
1718: } else {
1719: fdcResultBuffer[1] = (byte) (status >> 16);
1720: fdcRPhase (2);
1721: }
1722: }
1723:
1724:
1725:
1726:
1727: public static void fdcCommandResetStandby () {
1728: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
1729: System.out.printf ("%08x fdcCommandResetStandby()\n", XEiJ.regPC0);
1730: }
1731:
1732: fdcCPhase ();
1733: }
1734:
1735:
1736:
1737:
1738: public static void fdcCommandSetStandby () {
1739: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
1740: System.out.printf ("%08x fdcCommandSetStandby()\n", XEiJ.regPC0);
1741: }
1742:
1743: fdcCPhase ();
1744: }
1745:
1746:
1747:
1748:
1749: public static void fdcCommandSoftwareReset () {
1750: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
1751: System.out.printf ("%08x fdcCommandSoftwareReset()\n", XEiJ.regPC0);
1752: }
1753:
1754: fdcCPhase ();
1755: }
1756:
1757:
1758:
1759:
1760:
1761:
1762:
1763:
1764:
1765:
1766:
1767:
1768:
1769:
1770:
1771:
1772:
1773: public static void fdcCommandInvalid () {
1774: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
1775: System.out.printf ("%08x fdcCommandInvalid()\n", XEiJ.regPC0);
1776: }
1777: int status = FDC_ST0_IC;
1778: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
1779: System.out.printf ("\tstatus=%s\n", fdcResultStatusToString (status));
1780: }
1781: fdcResultBuffer[0] = (byte) (status >> 24);
1782: fdcRPhase (1);
1783: }
1784:
1785:
1786: public static String fdcResultStatusToString (int status) {
1787: int ic = status >> 24 + 6 & 3;
1788: return String.format ("0x%08x\n" +
1789: "\t\tST0=0x%02x(IC=%d(%s) SE=%d EC=%d NR=%d HD=%d US=%d)\n" +
1790: "\t\tST1=0x%02x(EN=%d DE=%d OR=%d ND=%d NW=%d MA=%d)\n" +
1791: "\t\tST2=0x%02x(CM=%d DD=%d NC=%d SH=%d SN=%d BC=%d MD=%d)",
1792: status,
1793: status >> 24 & 255,
1794: ic, ic == 0 ? "NT" : ic == 1 ? "AT" : ic == 2 ? "IC" : "AI",
1795: status >> 24 + 5 & 1,
1796: status >> 24 + 4 & 1,
1797: status >> 24 + 3 & 1,
1798: status >> 24 + 2 & 1,
1799: status >> 24 + 0 & 3,
1800: status >> 16 & 255,
1801: status >> 16 + 7 & 1,
1802: status >> 16 + 5 & 1,
1803: status >> 16 + 4 & 1,
1804: status >> 16 + 2 & 1,
1805: status >> 16 + 1 & 1,
1806: status >> 16 + 0 & 1,
1807: status >> 8 & 255,
1808: status >> 8 + 6 & 1,
1809: status >> 8 + 5 & 1,
1810: status >> 8 + 4 & 1,
1811: status >> 8 + 3 & 1,
1812: status >> 8 + 2 & 1,
1813: status >> 8 + 1 & 1,
1814: status >> 8 + 0 & 1);
1815: }
1816:
1817:
1818: public static String fdcStatusToString (int status) {
1819: return String.format ("0x%02x(RQM=%d DIO=%d(%s) NDM=%d CB=%d D3B=%d D2B=%d D1B=%d D0B=%d)",
1820: status,
1821: status >> 7,
1822: status >> 6 & 1,
1823: (status >> 6 & 1) == 0 ? "MPU->FDC" : "FDC->MPU",
1824: status >> 5 & 1,
1825: status >> 4 & 1,
1826: status >> 3 & 1,
1827: status >> 2 & 1,
1828: status >> 1 & 1,
1829: status & 1);
1830: }
1831:
1832:
1833:
1834:
1835:
1836:
1837:
1838: public static class FDUnit extends AbstractUnit {
1839:
1840: public FDMedia fduMedia;
1841: public byte[] fduImage;
1842: public boolean fduWritten;
1843:
1844: public int fduCommandNumber;
1845:
1846:
1847:
1848:
1849:
1850:
1851:
1852:
1853:
1854:
1855:
1856:
1857: public boolean fduIsInserted () {
1858: return abuConnected && abuInserted && fduMedia != null;
1859: }
1860:
1861:
1862:
1863:
1864:
1865:
1866:
1867: public boolean fduBlinking;
1868:
1869:
1870:
1871: public boolean fduPrevented;
1872:
1873:
1874:
1875:
1876:
1877:
1878:
1879:
1880:
1881: public boolean fduDoubleDensity;
1882:
1883:
1884:
1885: public boolean fduIsWriteProtected () {
1886: return abuWriteProtected;
1887: }
1888:
1889:
1890:
1891:
1892:
1893:
1894: public boolean fduIsReady () {
1895: return (fdcEnforcedReady ||
1896: (abuConnected &&
1897: fduIsInserted () &&
1898: (fduMotorStatus == FDU_MOTOR_RUN_SOON ||
1899: fduMotorStatus == FDU_MOTOR_DECELERATING ||
1900: fduMotorStatus == FDU_MOTOR_RUNNING)));
1901: }
1902:
1903:
1904:
1905:
1906:
1907:
1908: public static final int FDU_ACCESS_OFF = 0;
1909: public static final int FDU_ACCESS_GREEN_BLINKING = 1;
1910: public static final int FDU_ACCESS_GREEN_ON = 2;
1911: public static final int FDU_ACCESS_RED_ON = 3;
1912:
1913:
1914:
1915:
1916:
1917: public static final int FDU_EJECT_OFF = 0;
1918: public static final int FDU_EJECT_GREEN_ON = 1;
1919:
1920:
1921:
1922: public static final long FDU_SEEK_INTERVAL = XEiJ.TMR_FREQ * 1 / 1000;
1923: public int fduNCN;
1924: public int fduPCN;
1925: public int fduPHN;
1926: public int fduPRN;
1927: public int fduPNN;
1928: public int fduEOT;
1929: public int fduSTP;
1930: public int fduSRC;
1931: public boolean fduSeekStepWaiting;
1932: public boolean fduSeekEndInterruptWaiting;
1933: public boolean fduSeekEndInterruptRequest;
1934: public int fduSeekResultStatus;
1935:
1936:
1937:
1938: public final TickerQueue.Ticker fduSeekTicker = new TickerQueue.Ticker () {
1939: @Override protected void tick () {
1940: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
1941: System.out.printf ("%08x fduSeekTicker%d.tick()\n", XEiJ.regPC0, abuNumber);
1942: }
1943: if ((fdcStatus & 1 << abuNumber) != 0) {
1944: if ((fdcStatus & FDC_CB) != 0) {
1945: fduSeekStepWaiting = true;
1946: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
1947: System.out.printf ("\tfduSeekStepWaiting%d=%b\n", abuNumber, fduSeekStepWaiting);
1948: }
1949: } else {
1950: fduSeekStep ();
1951: }
1952: } else {
1953: fduSeekStep ();
1954: }
1955: }
1956: };
1957:
1958:
1959:
1960: public void fduSeekStep () {
1961: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
1962: System.out.printf ("%08x fduSeekStep%d()\n", XEiJ.regPC0, abuNumber);
1963: }
1964: if (fduPCN != fduNCN) {
1965: fduSRC--;
1966: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
1967: System.out.printf ("\tfduSRC%d=%d\n", abuNumber, fduSRC);
1968: }
1969: if (fduSRC == 0) {
1970: fduSRC = 16 - fdcSRT;
1971: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
1972: System.out.printf ("\tfduSRC%d=%d\n", abuNumber, fduSRC);
1973: }
1974: if (fduPCN < fduNCN) {
1975: fduPCN++;
1976: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
1977: System.out.printf ("\tfduPCN%d=%d\n", abuNumber, fduPCN);
1978: }
1979: } else {
1980: fduPCN--;
1981: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
1982: System.out.printf ("\tfduPCN%d=%d\n", abuNumber, fduPCN);
1983: }
1984: }
1985: }
1986: TickerQueue.tkqAdd (fduSeekTicker, XEiJ.mpuClockTime + FDU_SEEK_INTERVAL);
1987: return;
1988: }
1989:
1990:
1991: switch (fduCommandNumber) {
1992:
1993:
1994:
1995: case 0x05:
1996: fduWriteDataEPhase ();
1997: break;
1998: case 0x06:
1999: fduReadDataEPhase ();
2000: break;
2001: case 0x07:
2002: case 0x0f:
2003:
2004: fduSeekEnd ();
2005: break;
2006:
2007:
2008:
2009:
2010:
2011:
2012: case 0x11:
2013: case 0x19:
2014: case 0x1d:
2015: fduScanEPhase ();
2016: break;
2017: }
2018: }
2019:
2020:
2021:
2022: public void fduSeekEnd () {
2023: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
2024: System.out.printf ("%08x fduSeekEnd%d()\n", XEiJ.regPC0, abuNumber);
2025: }
2026: if ((fdcStatus & FDC_CB) != 0) {
2027: fduSeekEndInterruptWaiting = true;
2028: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
2029: System.out.printf ("\tfduSeekEndInterruptWaiting%d=%b\n", abuNumber, fduSeekEndInterruptWaiting);
2030: }
2031: } else {
2032: if (!fduSeekEndInterruptRequest) {
2033: fduSeekEndInterruptRequest = true;
2034: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
2035: System.out.printf ("\tfduSeekEndInterruptRequest%d=%b\n", abuNumber, fduSeekEndInterruptRequest);
2036: }
2037: IOInterrupt.ioiFdcRise ();
2038: }
2039: }
2040: }
2041:
2042:
2043:
2044:
2045:
2046:
2047:
2048:
2049:
2050:
2051:
2052:
2053:
2054:
2055:
2056:
2057:
2058:
2059:
2060:
2061:
2062:
2063:
2064:
2065:
2066:
2067:
2068:
2069:
2070:
2071:
2072:
2073:
2074:
2075:
2076:
2077:
2078:
2079:
2080:
2081:
2082:
2083:
2084:
2085:
2086:
2087:
2088:
2089:
2090:
2091:
2092:
2093:
2094:
2095:
2096:
2097:
2098:
2099:
2100:
2101:
2102:
2103:
2104:
2105:
2106:
2107:
2108:
2109:
2110:
2111:
2112:
2113:
2114:
2115:
2116:
2117:
2118:
2119:
2120:
2121:
2122:
2123:
2124:
2125:
2126:
2127:
2128:
2129:
2130:
2131:
2132:
2133:
2134:
2135:
2136: public static final int FDU_MOTOR_SLEEPING = 0;
2137: public static final int FDU_MOTOR_ACCELERATING = 1;
2138: public static final int FDU_MOTOR_SLEEP_SOON = 2;
2139: public static final int FDU_MOTOR_RUN_SOON = 3;
2140: public static final int FDU_MOTOR_DECELERATING = 4;
2141: public static final int FDU_MOTOR_RUNNING = 5;
2142: public int fduMotorStatus;
2143: public static final long FDU_MOTOR_ON_DELAY = XEiJ.TMR_FREQ * 100 / 1000000;
2144: public static final long FDU_MOTOR_OFF_DELAY = XEiJ.TMR_FREQ * 3;
2145: public static final long FDU_MOTOR_INTERRUPT_DELAY = XEiJ.TMR_FREQ * 100 / 1000000;
2146: public boolean fduSavedReady;
2147: public boolean fduAttentionCheckWaiting;
2148: public boolean fduAttentionInterruptRequest;
2149:
2150:
2151:
2152: public void fduMotorOn () {
2153: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
2154: System.out.printf ("%08x fduMotorOn%d()\n", XEiJ.regPC0, abuNumber);
2155: }
2156: if (!fduIsInserted ()) {
2157: return;
2158: }
2159: switch (fduMotorStatus) {
2160: case FDU_MOTOR_SLEEPING:
2161: fduMotorStatus = FDU_MOTOR_ACCELERATING;
2162: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
2163: System.out.printf ("\tfduMotorStatus%d=%d\n", abuNumber, fduMotorStatus);
2164: }
2165: if (!fduPrevented) {
2166: prevent ();
2167: }
2168: TickerQueue.tkqAdd (fduMotorAcceleratingTicker, XEiJ.mpuClockTime + FDU_MOTOR_ON_DELAY);
2169: break;
2170: case FDU_MOTOR_SLEEP_SOON:
2171: TickerQueue.tkqRemove (fduMotorSleepSoonTicker);
2172: fduMotorStatus = FDU_MOTOR_ACCELERATING;
2173: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
2174: System.out.printf ("\tfduMotorStatus%d=%d\n", abuNumber, fduMotorStatus);
2175: }
2176: TickerQueue.tkqAdd (fduMotorAcceleratingTicker, XEiJ.mpuClockTime + FDU_MOTOR_ON_DELAY);
2177: break;
2178: case FDU_MOTOR_DECELERATING:
2179: TickerQueue.tkqRemove (fduMotorDeceleratingTicker);
2180: fduMotorStatus = FDU_MOTOR_RUN_SOON;
2181: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
2182: System.out.printf ("\tfduMotorStatus%d=%d\n", abuNumber, fduMotorStatus);
2183: }
2184: TickerQueue.tkqAdd (fduMotorRunSoonTicker, XEiJ.mpuClockTime + FDU_MOTOR_INTERRUPT_DELAY);
2185: break;
2186: }
2187: }
2188:
2189:
2190:
2191: public final TickerQueue.Ticker fduMotorAcceleratingTicker = new TickerQueue.Ticker () {
2192: @Override protected void tick () {
2193: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
2194: System.out.printf ("%08x fduMotorAcceleratingTicker%d.tick()\n", XEiJ.regPC0, abuNumber);
2195: }
2196: fduMotorStatus = FDU_MOTOR_RUN_SOON;
2197: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
2198: System.out.printf ("\tfduMotorStatus%d=%d\n", abuNumber, fduMotorStatus);
2199: }
2200:
2201: TickerQueue.tkqAdd (fduMotorRunSoonTicker, XEiJ.mpuClockTime + FDU_MOTOR_INTERRUPT_DELAY);
2202: }
2203: };
2204:
2205:
2206:
2207: public final TickerQueue.Ticker fduMotorRunSoonTicker = new TickerQueue.Ticker () {
2208: @Override protected void tick () {
2209: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
2210: System.out.printf ("%08x fduMotorRunSoonTicker%d.tick()\n", XEiJ.regPC0, abuNumber);
2211: }
2212: fduMotorStatus = FDU_MOTOR_RUNNING;
2213: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
2214: System.out.printf ("\tfduMotorStatus%d=%d\n", abuNumber, fduMotorStatus);
2215: }
2216: fduMotorInterrupt ();
2217: }
2218: };
2219:
2220:
2221:
2222: @SuppressWarnings ("fallthrough") public void fduMotorOff () {
2223: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
2224: System.out.printf ("%08x fduMotorOff%d()\n", XEiJ.regPC0, abuNumber);
2225: }
2226: if (!fduIsInserted ()) {
2227: return;
2228: }
2229: switch (fduMotorStatus) {
2230: case FDU_MOTOR_ACCELERATING:
2231: TickerQueue.tkqRemove (fduMotorAcceleratingTicker);
2232: fduMotorStatus = FDU_MOTOR_SLEEP_SOON;
2233: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
2234: System.out.printf ("\tfduMotorStatus%d=%d\n", abuNumber, fduMotorStatus);
2235: }
2236: TickerQueue.tkqAdd (fduMotorSleepSoonTicker, XEiJ.mpuClockTime + FDU_MOTOR_INTERRUPT_DELAY);
2237: break;
2238: case FDU_MOTOR_RUN_SOON:
2239: TickerQueue.tkqRemove (fduMotorRunSoonTicker);
2240:
2241: case FDU_MOTOR_RUNNING:
2242: fduMotorStatus = FDU_MOTOR_DECELERATING;
2243: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
2244: System.out.printf ("\tfduMotorStatus%d=%d\n", abuNumber, fduMotorStatus);
2245: }
2246: TickerQueue.tkqAdd (fduMotorDeceleratingTicker, XEiJ.mpuClockTime + FDU_MOTOR_OFF_DELAY);
2247: break;
2248: }
2249: }
2250:
2251:
2252:
2253: public final TickerQueue.Ticker fduMotorDeceleratingTicker = new TickerQueue.Ticker () {
2254: @Override protected void tick () {
2255: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
2256: System.out.printf ("%08x fduMotorDeceleratingTicker%d.tick()\n", XEiJ.regPC0, abuNumber);
2257: }
2258: fduMotorStatus = FDU_MOTOR_SLEEP_SOON;
2259: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
2260: System.out.printf ("\tfduMotorStatus%d=%d\n", abuNumber, fduMotorStatus);
2261: }
2262:
2263: TickerQueue.tkqAdd (fduMotorSleepSoonTicker, XEiJ.mpuClockTime + FDU_MOTOR_INTERRUPT_DELAY);
2264: }
2265: };
2266:
2267:
2268:
2269: public final TickerQueue.Ticker fduMotorSleepSoonTicker = new TickerQueue.Ticker () {
2270: @Override protected void tick () {
2271: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
2272: System.out.printf ("%08x fduMotorSleepSoonTicker%d.tick()\n", XEiJ.regPC0, abuNumber);
2273: }
2274: fduMotorStatus = FDU_MOTOR_SLEEPING;
2275: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
2276: System.out.printf ("\tfduMotorStatus%d=%d\n", abuNumber, fduMotorStatus);
2277: }
2278: if (!fduPrevented) {
2279: allow ();
2280: }
2281: fduMotorInterrupt ();
2282: }
2283: };
2284:
2285:
2286:
2287: public void fduMotorInterrupt () {
2288: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
2289: System.out.printf ("%08x fduMotorInterrupt%d()\n", XEiJ.regPC0, abuNumber);
2290: }
2291: if ((fdcStatus & 1 << abuNumber) != 0) {
2292: fduAttentionCheckWaiting = true;
2293: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
2294: System.out.printf ("\tfduAttentionCheckWaiting%d=%b\n", abuNumber, fduAttentionCheckWaiting);
2295: }
2296: } else {
2297: if ((fdcStatus & FDC_CB) != 0) {
2298: fduAttentionCheckWaiting = true;
2299: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
2300: System.out.printf ("\tfduAttentionCheckWaiting%d=%b\n", abuNumber, fduAttentionCheckWaiting);
2301: }
2302: } else {
2303: boolean ready = fduIsReady ();
2304: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
2305: System.out.printf ("\tready%d=%b\n", abuNumber, ready);
2306: }
2307: if (ready != fduSavedReady) {
2308: fduSavedReady = ready;
2309: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
2310: System.out.printf ("\tfduSavedReady%d=%b\n", abuNumber, fduSavedReady);
2311: }
2312: if (!fduAttentionInterruptRequest) {
2313: fduAttentionInterruptRequest = true;
2314: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
2315: System.out.printf ("\tfduAttentionInterruptRequest%d=%b\n", abuNumber, fduAttentionInterruptRequest);
2316: }
2317: IOInterrupt.ioiFdcRise ();
2318: }
2319: }
2320: }
2321: }
2322: }
2323:
2324:
2325:
2326:
2327:
2328:
2329: public FDUnit (int number) {
2330: super (number);
2331:
2332: fduMedia = null;
2333: fduImage = null;
2334: fduWritten = false;
2335:
2336: fduBlinking = false;
2337: fduPrevented = false;
2338: fduDoubleDensity = false;
2339:
2340: fduNCN = 0;
2341: fduPCN = 0;
2342: fduPHN = 0;
2343: fduPRN = 1;
2344: fduPNN = 3;
2345: fduEOT = 1;
2346: fduSTP = 1;
2347: fduSeekStepWaiting = false;
2348: fduSeekEndInterruptWaiting = false;
2349: fduSeekEndInterruptRequest = false;
2350: fduSeekResultStatus = FDC_ST0_IC;
2351:
2352: fduMotorStatus = FDU_MOTOR_SLEEPING;
2353: fduSavedReady = false;
2354: fduAttentionCheckWaiting = false;
2355: fduAttentionInterruptRequest = false;
2356: }
2357:
2358:
2359:
2360:
2361: public void fduTini () {
2362: if (fduIsInserted ()) {
2363: fduFlush ();
2364: }
2365: }
2366:
2367:
2368:
2369: public boolean fduFlush () {
2370: if (!abuConnected ||
2371: !fduIsInserted () ||
2372: !fduWritten) {
2373: return true;
2374: }
2375: if (fduIsWriteProtected ()) {
2376: return false;
2377: }
2378: int dotIndex = abuPath.lastIndexOf ('.');
2379: String upperExt = dotIndex < 0 ? "" : abuPath.substring (dotIndex + 1).toUpperCase ();
2380: if (upperExt.equals ("DIM")) {
2381: byte[] dimImage = new byte[256 + fduMedia.fdmBytesPerDisk];
2382: int dimSize = fduMedia.fdmMakeDimImage (dimImage, fduImage);
2383: if (dimSize < 0) {
2384:
2385: XEiJ.pnlExitFullScreen (true);
2386: JOptionPane.showMessageDialog (null,
2387: Multilingual.mlnJapanese ?
2388: fduMedia.fdmName + " を *.DIM に変換できません" :
2389: fduMedia.fdmName + " cannot be converted to *.DIM");
2390: return false;
2391: }
2392: if (!XEiJ.rscPutFile (abuPath, dimImage, 0, dimSize)) {
2393: return false;
2394: }
2395: } else {
2396: if (!XEiJ.rscPutFile (abuPath, fduImage, 0, fduMedia.fdmBytesPerDisk)) {
2397: return false;
2398: }
2399: }
2400: fduWritten = false;
2401: return true;
2402: }
2403:
2404:
2405:
2406: @Override protected void connect (boolean disconnectable) {
2407: super.connect (disconnectable);
2408: fduImage = new byte[FDMedia.FDM_BUFFER_SIZE];
2409: }
2410:
2411:
2412:
2413: @Override protected void disconnect () {
2414: super.disconnect ();
2415: fduImage = null;
2416: }
2417:
2418:
2419:
2420: public void blink () {
2421: if (!abuConnected ||
2422: fduBlinking) {
2423: return;
2424: }
2425: fduBlinking = true;
2426:
2427: }
2428:
2429:
2430:
2431: public void darken () {
2432: if (!abuConnected ||
2433: !fduBlinking) {
2434: return;
2435: }
2436: fduBlinking = false;
2437:
2438: }
2439:
2440:
2441:
2442: @Override protected boolean eject () {
2443: if (!fduFlush ()) {
2444: return false;
2445: }
2446: fduMotorStatus = FDU_MOTOR_SLEEPING;
2447: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
2448: System.out.printf ("\tfduMotorStatus%d=%d\n", abuNumber, fduMotorStatus);
2449: }
2450: boolean inserted = fduIsInserted ();
2451: String path = abuPath;
2452: if (!super.eject ()) {
2453: return false;
2454: }
2455: if (fduMedia != null) {
2456: fdcAddHistory (new File (path).getAbsoluteFile ());
2457: System.out.println (Multilingual.mlnJapanese ?
2458: path + " を fd" + abuNumber + " から取り出しました" :
2459: path + " was ejected from fd" + abuNumber);
2460: }
2461: fduMedia = null;
2462: fduPCN = 0;
2463: fduPHN = 0;
2464: fduPRN = 1;
2465: fduPNN = 3;
2466:
2467: if (inserted) {
2468: IOInterrupt.ioiFddFall ();
2469: IOInterrupt.ioiFddRise ();
2470: }
2471: return true;
2472: }
2473:
2474:
2475:
2476: @Override protected boolean open () {
2477: if (!super.open ()) {
2478: return false;
2479: }
2480: fdcOpenUnit = abuNumber;
2481: if (fdcOpenDialog == null) {
2482: fdcOpenDialog = new OpenDialog ();
2483: fdcOpenDialog.setReadOnly (Settings.sgsGetOnOff ("fdreadonly"));
2484: fdcOpenDialog.setReboot (Settings.sgsGetOnOff ("fdappreboot"));
2485: for (File[] files : fdcOpenHistory) {
2486: fdcOpenDialog.addHistory (files);
2487: }
2488: fdcOpenHistory.clear ();
2489: }
2490: fdcOpenDialog.rescanCurrentDirectory ();
2491: XEiJ.pnlExitFullScreen (true);
2492: fdcOpenDialog.setVisible (true);
2493: return true;
2494: }
2495:
2496:
2497:
2498: public boolean insert (String path, boolean writeProtected) {
2499: if (fdcIsInsertedPath (path)) {
2500: return false;
2501: }
2502: if (!super.insert (path, writeProtected)) {
2503: return false;
2504: }
2505: if (fduMedia != null) {
2506: IOInterrupt.ioiFddFall ();
2507: IOInterrupt.ioiFddRise ();
2508: }
2509: return true;
2510: }
2511:
2512:
2513:
2514:
2515: @Override protected boolean load (String path) {
2516: fduMedia = FDMedia.fdmPathToMedia (path, fduImage);
2517: if (fduMedia == null) {
2518: return false;
2519: }
2520: if (abuWriteProtected && !abuUnprotectable) {
2521: fduMedia.fdmReviveFiles (fduImage);
2522: }
2523: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
2524: System.out.println ("media = " + fduMedia.fdmName);
2525: System.out.println ("------------------------------------------------------------------------");
2526: fduMedia.fdmPrintInfo ();
2527: System.out.println ("------------------------------------------------------------------------");
2528: }
2529: fduWritten = false;
2530: fdcAddHistory (new File (path).getAbsoluteFile ());
2531: System.out.println (Multilingual.mlnJapanese ?
2532: path + " を fd" + abuNumber + " に挿入しました" :
2533: path + " was inserted in fd" + abuNumber);
2534: return true;
2535: }
2536:
2537:
2538:
2539:
2540: public String getName () {
2541: return abuPath.substring (abuPath.lastIndexOf (File.separatorChar) + 1);
2542: }
2543:
2544:
2545:
2546:
2547: public int fduDriveStatus () {
2548: return fduIsInserted () ? 0x80 : 0;
2549: }
2550:
2551:
2552:
2553:
2554:
2555: public void fduDriveControl (int d) {
2556: if (d << 31 - 5 < 0) {
2557: eject ();
2558: }
2559: if (d << 31 - 6 < 0) {
2560: fduPrevented = true;
2561: prevent ();
2562: } else {
2563: fduPrevented = false;
2564: allow ();
2565: }
2566: if ((byte) d < 0) {
2567: fduBlinking = true;
2568: blink ();
2569: } else {
2570: fduBlinking = false;
2571: darken ();
2572: }
2573: }
2574:
2575:
2576:
2577:
2578:
2579:
2580:
2581:
2582:
2583:
2584:
2585:
2586:
2587:
2588:
2589:
2590:
2591:
2592:
2593:
2594:
2595:
2596:
2597:
2598:
2599:
2600:
2601:
2602:
2603:
2604:
2605:
2606:
2607:
2608:
2609:
2610:
2611:
2612:
2613:
2614:
2615:
2616:
2617:
2618:
2619:
2620: public void fduCommandReadDiagnostic () {
2621:
2622: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
2623: System.out.printf ("%08x READ DIAGNOSTIC is not implemented\n", XEiJ.regPC0);
2624: }
2625: fdcCommandInvalid ();
2626: }
2627:
2628:
2629:
2630:
2631:
2632:
2633:
2634:
2635:
2636:
2637: public void fduCommandSenseDeviceStatus () {
2638:
2639: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
2640: System.out.printf ("%08x fduCommandSenseDeviceStatus%d()\n", XEiJ.regPC0, abuNumber);
2641: }
2642: int st3 = ((fduIsWriteProtected () ? FDC_ST3_WP : 0) |
2643: (fduIsReady () ? FDC_ST3_RY : 0) |
2644: (fduIsInserted () && fduIsReady () && fduPCN == 0 ? FDC_ST3_T0 : 0) |
2645:
2646: (fduPHN & 1) << 2 |
2647: abuNumber);
2648: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
2649: System.out.printf ("\t\tST3=0x%02x(FT=%d WP=%d RY=%d T0=%d TS=%d HD=%d US=%d)\n",
2650: st3,
2651: st3 >> 7,
2652: st3 >> 6 & 1,
2653: st3 >> 5 & 1,
2654: st3 >> 4 & 1,
2655: st3 >> 3 & 1,
2656: st3 >> 2 & 1,
2657: st3 & 3);
2658: }
2659: fdcResultBuffer[0] = (byte) st3;
2660: fdcRPhase (1);
2661: }
2662:
2663:
2664:
2665:
2666:
2667:
2668:
2669:
2670:
2671:
2672:
2673:
2674:
2675:
2676:
2677:
2678:
2679:
2680:
2681:
2682:
2683:
2684:
2685:
2686:
2687:
2688:
2689:
2690:
2691:
2692:
2693:
2694:
2695:
2696:
2697:
2698:
2699:
2700:
2701:
2702:
2703:
2704:
2705:
2706:
2707:
2708: public void fduCommandWriteData () {
2709:
2710: int ncn = fdcCommandBuffer[2] & 255;
2711: int phn = fdcCommandBuffer[3] & 255;
2712: int prn = fdcCommandBuffer[4] & 255;
2713: int pnn = fdcCommandBuffer[5] & 255;
2714: int eot = fdcCommandBuffer[6] & 255;
2715: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
2716: System.out.printf ("%08x fduCommandWriteData%d(NCN=%d H=%d R=%d N=%d EOT=%d)\n",
2717: XEiJ.regPC0, abuNumber, ncn, phn, prn, pnn, eot);
2718: }
2719: fduCommandNumber = fdcCommandNumber;
2720: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
2721: System.out.printf ("\tfduCommandNumber%d=0x%02x\n", abuNumber, fduCommandNumber);
2722: }
2723: if (!fduIsReady ()) {
2724: fduEPhaseEnd (FDC_ST0_AT | FDC_ST0_NR | ((fduPHN & 1) << 2 | abuNumber) << 24);
2725: return;
2726: }
2727: if (fduIsWriteProtected ()) {
2728: fduEPhaseEnd (FDC_ST0_AT | FDC_ST1_NW | ((fduPHN & 1) << 2 | abuNumber) << 24);
2729: return;
2730: }
2731: fduNCN = ncn;
2732: fduPHN = phn;
2733: fduPRN = prn;
2734: fduPNN = pnn;
2735: fduEOT = eot;
2736: fduSRC = 16 - fdcSRT;
2737: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
2738: System.out.printf ("\tfduNCN%d=%d\n", abuNumber, fduNCN);
2739: System.out.printf ("\tfduPHN%d=%d\n", abuNumber, fduPHN);
2740: System.out.printf ("\tfduPRN%d=%d\n", abuNumber, fduPRN);
2741: System.out.printf ("\tfduPNN%d=%d\n", abuNumber, fduPNN);
2742: System.out.printf ("\tfduEOT%d=%d\n", abuNumber, fduEOT);
2743: System.out.printf ("\tfduSRC%d=%d\n", abuNumber, fduSRC);
2744: }
2745: fdcStatus = (FDC_MPU_TO_FDC | FDC_CB |
2746: (fdcStatus & (FDC_D3B | FDC_D2B | FDC_D1B | FDC_D0B)));
2747: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
2748: System.out.printf ("\tfdcStatus=%s\n", fdcStatusToString (fdcStatus));
2749: }
2750: TickerQueue.tkqAdd (fduSeekTicker, XEiJ.mpuClockTime + FDU_SEEK_INTERVAL);
2751: }
2752:
2753: public void fduWriteDataEPhase () {
2754: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
2755: System.out.printf ("%08x fduWriteDataEPhase%d()\n", XEiJ.regPC0, abuNumber);
2756: }
2757: if (fduPCN != fduNCN) {
2758: fduEPhaseEnd (FDC_ST0_AT | FDC_ST0_NR | ((fduPHN & 1) << 2 | abuNumber) << 24);
2759: return;
2760: }
2761:
2762: fduWritten = true;
2763: fdcStatus = (FDC_RQM | FDC_MPU_TO_FDC | FDC_CB |
2764: (fdcStatus & (FDC_D3B | FDC_D2B | FDC_D1B | FDC_D0B)));
2765: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
2766: System.out.printf ("\tfdcStatus=%s\n", fdcStatusToString (fdcStatus));
2767: }
2768:
2769: int o = fduCalcOffset ();
2770: if (o < 0) {
2771: fduEPhaseEnd (FDC_ST0_AT | FDC_ST1_MA | ((fduPHN & 1) << 2 | abuNumber) << 24);
2772: return;
2773: }
2774: fdcReadHandle = null;
2775: fdcWriteHandle = fduImage;
2776: fdcIndex = fdcStart = o;
2777: fdcLimit = o + (128 << fduPNN);
2778: HD63450.dmaFallPCL (0);
2779: }
2780:
2781:
2782: public void fduWriteDataEPhaseEnd () {
2783: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
2784: System.out.printf ("%08x fduWriteDataEPhaseEnd%d()\n", XEiJ.regPC0, abuNumber);
2785: }
2786: if (fduPRN == fduEOT) {
2787: HD63450.dmaRisePCL (0);
2788: fduEPhaseEnd (FDC_ST0_NT | ((fduPHN & 1) << 2 | abuNumber) << 24);
2789: return;
2790: }
2791:
2792: if (fduMedia == FDMedia.FDM_2HS && fduPCN == 0 && fduPHN == 0 && fduPRN == 1) {
2793: fduPRN = 11;
2794: } else {
2795: fduPRN++;
2796: }
2797: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
2798: System.out.printf ("\tfduPRN%d=%d\n", abuNumber, fduPRN);
2799: }
2800: int o = fduCalcOffset ();
2801: if (o < 0) {
2802: fduEPhaseEnd (FDC_ST0_AT | FDC_ST1_MA | (fduPHN << 2 | abuNumber << 24));
2803: return;
2804: }
2805: fdcIndex = fdcStart = o;
2806: fdcLimit = o + (128 << fduPNN);
2807: }
2808:
2809:
2810:
2811:
2812:
2813:
2814:
2815:
2816:
2817:
2818:
2819:
2820:
2821:
2822:
2823:
2824:
2825:
2826:
2827:
2828:
2829:
2830:
2831:
2832:
2833:
2834:
2835:
2836:
2837:
2838:
2839:
2840:
2841:
2842:
2843:
2844:
2845:
2846:
2847:
2848:
2849:
2850:
2851:
2852:
2853:
2854:
2855:
2856: public void fduCommandReadData () {
2857:
2858: int ncn = fdcCommandBuffer[2] & 255;
2859: int phn = fdcCommandBuffer[3] & 255;
2860: int prn = fdcCommandBuffer[4] & 255;
2861: int pnn = fdcCommandBuffer[5] & 255;
2862: int eot = fdcCommandBuffer[6] & 255;
2863: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
2864: System.out.printf ("%08x fduCommandReadData%d(NCN=%d H=%d R=%d N=%d EOT=%d)\n",
2865: XEiJ.regPC0, abuNumber, ncn, phn, prn, pnn, eot);
2866: }
2867: fduCommandNumber = fdcCommandNumber;
2868: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
2869: System.out.printf ("\tfduCommandNumber%d=0x%02x\n", abuNumber, fduCommandNumber);
2870: }
2871: if (!fduIsReady ()) {
2872: fduEPhaseEnd (FDC_ST0_AT | FDC_ST0_NR | ((fduPHN & 1) << 2 | abuNumber) << 24);
2873: return;
2874: }
2875: fduNCN = ncn;
2876: fduPHN = phn;
2877: fduPRN = prn;
2878: fduPNN = pnn;
2879: fduEOT = eot;
2880: fduSRC = 16 - fdcSRT;
2881: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
2882: System.out.printf ("\tfduNCN%d=%d\n", abuNumber, fduNCN);
2883: System.out.printf ("\tfduPHN%d=%d\n", abuNumber, fduPHN);
2884: System.out.printf ("\tfduPRN%d=%d\n", abuNumber, fduPRN);
2885: System.out.printf ("\tfduPNN%d=%d\n", abuNumber, fduPNN);
2886: System.out.printf ("\tfduEOT%d=%d\n", abuNumber, fduEOT);
2887: System.out.printf ("\tfduSRC%d=%d\n", abuNumber, fduSRC);
2888: }
2889: fdcStatus = (FDC_MPU_TO_FDC | FDC_CB |
2890: (fdcStatus & (FDC_D3B | FDC_D2B | FDC_D1B | FDC_D0B)));
2891: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
2892: System.out.printf ("\tfdcStatus=%s\n", fdcStatusToString (fdcStatus));
2893: }
2894: fdcReadHandle = null;
2895: fdcWriteHandle = null;
2896: TickerQueue.tkqAdd (fduSeekTicker, XEiJ.mpuClockTime + FDU_SEEK_INTERVAL);
2897: }
2898:
2899: public void fduReadDataEPhase () {
2900: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
2901: System.out.printf ("%08x fduReadDataEPhase%d()\n", XEiJ.regPC0, abuNumber);
2902: }
2903: if (fduPCN != fduNCN) {
2904: fduEPhaseEnd (FDC_ST0_AT | FDC_ST0_NR | ((fduPHN & 1) << 2 | abuNumber) << 24);
2905: return;
2906: }
2907:
2908: fdcStatus = (FDC_RQM | FDC_FDC_TO_MPU | FDC_CB |
2909: (fdcStatus & (FDC_D3B | FDC_D2B | FDC_D1B | FDC_D0B)));
2910: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
2911: System.out.printf ("\tfdcStatus=%s\n", fdcStatusToString (fdcStatus));
2912: }
2913:
2914: int o = fduCalcOffset ();
2915: if (o < 0) {
2916: fduEPhaseEnd (FDC_ST0_AT | FDC_ST1_MA | ((fduPHN & 1) << 2 | abuNumber) << 24);
2917: return;
2918: }
2919: fdcReadHandle = fduImage;
2920: fdcWriteHandle = null;
2921: fdcIndex = fdcStart = o;
2922: fdcLimit = o + (128 << fduPNN);
2923: HD63450.dmaFallPCL (0);
2924: }
2925:
2926:
2927: public void fduReadDataEPhaseEnd () {
2928: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
2929: System.out.printf ("%08x fduReadDataEPhaseEnd%d()\n", XEiJ.regPC0, abuNumber);
2930: }
2931: if (fduPRN == fduEOT) {
2932: HD63450.dmaRisePCL (0);
2933: fduEPhaseEnd (FDC_ST0_NT | ((fduPHN & 1) << 2 | abuNumber) << 24);
2934: return;
2935: }
2936:
2937: if (fduMedia == FDMedia.FDM_2HS && fduPCN == 0 && fduPHN == 0 && fduPRN == 1) {
2938: fduPRN = 11;
2939: } else {
2940: fduPRN++;
2941: }
2942: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
2943: System.out.printf ("\tfduPRN%d=%d\n", abuNumber, fduPRN);
2944: }
2945: int o = fduCalcOffset ();
2946: if (o < 0) {
2947: fduEPhaseEnd (FDC_ST0_AT | FDC_ST1_MA | ((fduPHN & 1) << 2 | abuNumber) << 24);
2948: return;
2949: }
2950: fdcIndex = fdcStart = o;
2951: fdcLimit = o + (128 << fduPNN);
2952: }
2953:
2954:
2955:
2956:
2957:
2958:
2959:
2960:
2961:
2962:
2963:
2964: public void fduCommandRecalibrate () {
2965: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
2966: System.out.printf ("%08x fduCommandRecalibrate%d()\n", XEiJ.regPC0, abuNumber);
2967: }
2968: fduCommandNumber = fdcCommandNumber;
2969: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
2970: System.out.printf ("\tfduCommandNumber%d=0x%02x\n", abuNumber, fduCommandNumber);
2971: }
2972: fdcStatus |= 1 << abuNumber;
2973: fduNCN = 0;
2974: fduSRC = 16 - fdcSRT;
2975: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
2976: System.out.printf ("\tfdcStatus=%s\n", fdcStatusToString (fdcStatus));
2977: System.out.printf ("\tfduNCN%d=%d\n", abuNumber, fduNCN);
2978: System.out.printf ("\tfduSRC%d=%d\n", abuNumber, fduSRC);
2979: }
2980: if (fdcEnforcedReady && !abuConnected) {
2981: fduSeekResultStatus = FDC_ST0_AT | FDC_ST0_SE | FDC_ST0_EC;
2982: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
2983: System.out.printf ("\tfduSeekResultStatus=%s\n", fdcResultStatusToString (fduSeekResultStatus));
2984: }
2985: fdcCPhase ();
2986: fduSeekEnd ();
2987: } else if (!fduIsReady ()) {
2988: fduSeekResultStatus = FDC_ST0_AT | FDC_ST0_SE | FDC_ST0_NR;
2989: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
2990: System.out.printf ("\tfduSeekResultStatus=%s\n", fdcResultStatusToString (fduSeekResultStatus));
2991: }
2992: fdcCPhase ();
2993: fduSeekEnd ();
2994: } else {
2995: fduSeekResultStatus = FDC_ST0_NT | FDC_ST0_SE;
2996: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
2997: System.out.printf ("\tfduSeekResultStatus=%s\n", fdcResultStatusToString (fduSeekResultStatus));
2998: }
2999: TickerQueue.tkqAdd (fduSeekTicker, XEiJ.mpuClockTime + FDU_SEEK_INTERVAL);
3000: fdcCPhase ();
3001: }
3002: }
3003:
3004:
3005:
3006:
3007:
3008:
3009:
3010:
3011:
3012:
3013:
3014:
3015:
3016:
3017:
3018:
3019:
3020:
3021:
3022:
3023:
3024:
3025:
3026:
3027:
3028:
3029:
3030:
3031:
3032:
3033:
3034:
3035:
3036:
3037:
3038:
3039:
3040:
3041:
3042:
3043:
3044:
3045:
3046:
3047:
3048:
3049: public void fduCommandWriteDeletedData () {
3050:
3051: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
3052: System.out.printf ("%08x WRITE DELETED DATA is not implemented\n", XEiJ.regPC0);
3053: }
3054: fdcCommandInvalid ();
3055: }
3056:
3057:
3058:
3059:
3060:
3061:
3062:
3063:
3064:
3065:
3066:
3067:
3068:
3069:
3070:
3071:
3072:
3073:
3074:
3075:
3076:
3077:
3078:
3079:
3080: public void fduCommandReadId () {
3081: int hd = fdcCommandBuffer[1] >> 2 & 1;
3082: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
3083: System.out.printf ("%08x fduCommandReadId%d(HD=%d)\n", XEiJ.regPC0, abuNumber, hd);
3084: }
3085: fduCommandNumber = fdcCommandNumber;
3086: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
3087: System.out.printf ("\tfduCommandNumber%d=0x%02x\n", abuNumber, fduCommandNumber);
3088: }
3089: fduPHN = hd;
3090: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
3091: System.out.printf ("\tfduPHN%d=%d\n", abuNumber, fduPHN);
3092: }
3093: if (!fduIsReady ()) {
3094: fduEPhaseEnd (FDC_ST0_AT | FDC_ST0_NR | ((fduPHN & 1) << 2 | abuNumber) << 24);
3095: return;
3096: }
3097:
3098:
3099: if (fduMedia == FDMedia.FDM_2HS) {
3100: if (fduPCN == 0 && fduPHN == 0) {
3101: if (fduPRN == 1) {
3102: fduPRN = 11;
3103: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
3104: System.out.printf ("\tfduPRN%d=%d\n", abuNumber, fduPRN);
3105: }
3106: } else if (fduPRN == 18) {
3107: fduPRN = 1;
3108: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
3109: System.out.printf ("\tfduPRN%d=%d\n", abuNumber, fduPRN);
3110: }
3111: } else {
3112: fduPRN++;
3113: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
3114: System.out.printf ("\tfduPRN%d=%d\n", abuNumber, fduPRN);
3115: }
3116: }
3117: } else {
3118: if (fduPRN == 18) {
3119: fduPRN = 10;
3120: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
3121: System.out.printf ("\tfduPRN%d=%d\n", abuNumber, fduPRN);
3122: }
3123: } else {
3124: fduPRN++;
3125: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
3126: System.out.printf ("\tfduPRN%d=%d\n", abuNumber, fduPRN);
3127: }
3128: }
3129: }
3130: } else {
3131: if (fduPRN == fduMedia.fdmSectorsPerTrack) {
3132: fduPRN = 1;
3133: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
3134: System.out.printf ("\tfduPRN%d=%d\n", abuNumber, fduPRN);
3135: }
3136: } else {
3137: fduPRN++;
3138: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
3139: System.out.printf ("\tfduPRN%d=%d\n", abuNumber, fduPRN);
3140: }
3141: }
3142: }
3143:
3144: if (fduMedia == FDMedia.FDM_2HDE) {
3145: if (!(fduPCN == 0 && fduPHN == 0 && fduPRN == 1)) {
3146: fduPHN |= 128;
3147: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
3148: System.out.printf ("\tfduPHN%d=%d\n", abuNumber, fduPHN);
3149: }
3150: }
3151: }
3152:
3153: fduPNN = fduMedia.fdmSectorScale;
3154: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
3155: System.out.printf ("\tfduPNN%d=%d\n", abuNumber, fduPNN);
3156: }
3157: int o = fduCalcOffset ();
3158: if (o < 0) {
3159: fduEPhaseEnd (FDC_ST0_AT | FDC_ST1_MA | ((fduPHN & 1) << 2 | abuNumber) << 24);
3160: return;
3161: }
3162: fduEPhaseEnd (FDC_ST0_NT | ((fduPHN & 1) << 2 | abuNumber) << 24);
3163: }
3164:
3165:
3166:
3167:
3168:
3169:
3170:
3171:
3172:
3173:
3174:
3175:
3176:
3177:
3178:
3179:
3180:
3181:
3182:
3183:
3184:
3185:
3186:
3187:
3188:
3189:
3190:
3191:
3192:
3193:
3194:
3195:
3196:
3197:
3198:
3199:
3200:
3201:
3202:
3203:
3204:
3205:
3206:
3207:
3208:
3209:
3210:
3211:
3212: public void fduCommandReadDeletedData () {
3213:
3214: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
3215: System.out.printf ("%08x READ DELETED DATA is not implemented\n", XEiJ.regPC0);
3216: }
3217: fdcCommandInvalid ();
3218: }
3219:
3220:
3221:
3222:
3223:
3224:
3225:
3226:
3227:
3228:
3229:
3230:
3231:
3232:
3233:
3234:
3235:
3236:
3237:
3238:
3239:
3240:
3241:
3242:
3243:
3244:
3245:
3246:
3247:
3248:
3249:
3250:
3251:
3252:
3253: public void fduCommandWriteId () {
3254:
3255: fduCommandNumber = fdcCommandNumber;
3256: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
3257: System.out.printf ("\tfduCommandNumber%d=0x%02x\n", abuNumber, fduCommandNumber);
3258: }
3259: if (!fduIsReady ()) {
3260: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
3261: System.out.printf ("%08x unit=%d,is not ready\n", XEiJ.regPC0, abuNumber);
3262: }
3263: fduEPhaseEnd (FDC_ST0_AT | FDC_ST0_NR | ((fduPHN & 1) << 2 | abuNumber) << 24);
3264: return;
3265: }
3266: if (fduIsWriteProtected ()) {
3267: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
3268: System.out.printf ("%08x unit=%d,is read-only\n", XEiJ.regPC0, abuNumber);
3269: }
3270: fduEPhaseEnd (FDC_ST0_AT | FDC_ST1_NW | ((fduPHN & 1) << 2 | abuNumber) << 24);
3271: return;
3272: }
3273:
3274: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
3275: System.out.printf ("%08x FDC E-Phase\n", XEiJ.regPC0);
3276: }
3277: fdcStatus = (FDC_RQM | FDC_MPU_TO_FDC | FDC_CB |
3278: (fdcStatus & (FDC_D3B | FDC_D2B | FDC_D1B | FDC_D0B)));
3279: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
3280: System.out.printf ("\tfdcStatus=%s\n", fdcStatusToString (fdcStatus));
3281: }
3282: fdcReadHandle = null;
3283: fdcWriteHandle = fdcTempBuffer;
3284: fdcIndex = fdcStart = 0;
3285: fdcLimit = (fdcCommandBuffer[3] & 255) << 2;
3286: HD63450.dmaFallPCL (0);
3287: }
3288:
3289:
3290: public void fduWriteIdEPhaseEnd () {
3291: HD63450.dmaRisePCL (0);
3292:
3293: if (fdcTempBuffer[0] == 0 && fdcTempBuffer[1] == 0) {
3294: int prn1 = fdcTempBuffer[2] & 255;
3295: int pnn1 = fdcTempBuffer[3] & 255;
3296: int pcn2 = fdcTempBuffer[4] & 255;
3297: int phn2 = fdcTempBuffer[5] & 255;
3298: int prn2 = fdcTempBuffer[6] & 255;
3299: int pnn2 = fdcTempBuffer[7] & 255;
3300: int sectors = fdcLimit >> 2;
3301: FDMedia media = null;
3302: if (phn2 == 0 && prn1 == 1 && prn2 == 2) {
3303: if (!fduDoubleDensity) {
3304: if (pnn1 == 3 && pnn2 == 3) {
3305: if (sectors == 8) {
3306: media = FDMedia.FDM_2HD;
3307: }
3308: } else if (pnn1 == 2 && pnn2 == 2) {
3309: if (sectors == 15) {
3310: media = FDMedia.FDM_2HC;
3311: } else if (sectors == 18) {
3312: media = FDMedia.FDM_2HQ;
3313: }
3314: }
3315: } else {
3316: if (pnn1 == 2 && pnn2 == 2) {
3317: if (sectors == 8) {
3318: media = FDMedia.FDM_2DD8;
3319: } else if (sectors == 9) {
3320: media = FDMedia.FDM_2DD9;
3321: } else if (sectors == 10) {
3322: media = FDMedia.FDM_2DD10;
3323: }
3324: }
3325: }
3326: } else if (phn2 == 128 && prn1 == 1 && prn2 == 2) {
3327: if (!fduDoubleDensity) {
3328: if (pnn1 == 3 && pnn2 == 3) {
3329: if (sectors == 9) {
3330: media = FDMedia.FDM_2HDE;
3331: }
3332: }
3333: }
3334: } else if (phn2 == 0 && prn1 == 1 && prn2 == 11) {
3335: if (!fduDoubleDensity) {
3336: if (pnn1 == 3 && pnn2 == 3) {
3337: if (sectors == 9) {
3338: media = FDMedia.FDM_2HS;
3339: }
3340: }
3341: }
3342: }
3343: if (media != null) {
3344: fduMedia = media;
3345: } else {
3346: fduMedia = FDMedia.FDM_2HD;
3347: }
3348: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
3349: System.out.println ("media = " + fduMedia.fdmName);
3350: System.out.println ("------------------------------------------------------------------------");
3351: fduMedia.fdmPrintInfo ();
3352: System.out.println ("------------------------------------------------------------------------");
3353: }
3354: }
3355: for (int i = 0; i < fdcLimit; i += 4) {
3356: fduPCN = fdcTempBuffer[i ] & 255;
3357: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
3358: System.out.printf ("%08x unit=%d,fduPCN=%d\n", XEiJ.regPC0, abuNumber, fduPCN);
3359: }
3360: fduPHN = fdcTempBuffer[i + 1] & 255;
3361: fduPRN = fdcTempBuffer[i + 2] & 255;
3362: fduPNN = fdcTempBuffer[i + 3] & 255;
3363: int o = fduCalcOffset ();
3364: if (o < 0) {
3365:
3366: if (0 < fduPCN) {
3367: fduPCN--;
3368: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
3369: System.out.printf ("%08x unit=%d,fduPCN=%d\n", XEiJ.regPC0, abuNumber, fduPCN);
3370: }
3371: o = fduCalcOffset ();
3372: fduPCN++;
3373: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
3374: System.out.printf ("%08x unit=%d,fduPCN=%d\n", XEiJ.regPC0, abuNumber, fduPCN);
3375: }
3376: }
3377: if (o < 0) {
3378: fduEPhaseEnd (FDC_ST0_AT | FDC_ST0_EC | ((fduPHN & 1) << 2 | abuNumber) << 24);
3379: return;
3380: }
3381: } else {
3382: Arrays.fill (fduImage, o, o + (128 << fduPNN), fdcCommandBuffer[5]);
3383: fduWritten = true;
3384: }
3385: }
3386: fduEPhaseEnd (FDC_ST0_NT | ((fduPHN & 1) << 2 | abuNumber) << 24);
3387: }
3388:
3389:
3390:
3391:
3392:
3393:
3394:
3395:
3396:
3397:
3398:
3399:
3400:
3401:
3402: public void fduCommandSeek () {
3403: int ncn = fdcCommandBuffer[2] & 255;
3404: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
3405: System.out.printf ("%08x fduCommandSeek%d(NCN=%d)\n", XEiJ.regPC0, abuNumber, ncn);
3406: }
3407: fduCommandNumber = fdcCommandNumber;
3408: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
3409: System.out.printf ("\tfduCommandNumber%d=0x%02x\n", abuNumber, fduCommandNumber);
3410: }
3411: fdcStatus |= 1 << abuNumber;
3412: fduNCN = ncn;
3413: fduSRC = 16 - fdcSRT;
3414: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
3415: System.out.printf ("\tfdcStatus=%s\n", fdcStatusToString (fdcStatus));
3416: System.out.printf ("\tfduNCN%d=%d\n", abuNumber, fduNCN);
3417: System.out.printf ("\tfduSRC%d=%d\n", abuNumber, fduSRC);
3418: }
3419: if (fdcEnforcedReady && !abuConnected) {
3420: fduSeekResultStatus = FDC_ST0_AT | FDC_ST0_SE | FDC_ST0_EC;
3421: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
3422: System.out.printf ("\tfduSeekResultStatus=%s\n", fdcResultStatusToString (fduSeekResultStatus));
3423: }
3424: fdcCPhase ();
3425: fduSeekEnd ();
3426: } else if (!fduIsReady ()) {
3427: fduSeekResultStatus = FDC_ST0_AT | FDC_ST0_SE | FDC_ST0_NR;
3428: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
3429: System.out.printf ("\tfduSeekResultStatus=%s\n", fdcResultStatusToString (fduSeekResultStatus));
3430: }
3431: fdcCPhase ();
3432: fduSeekEnd ();
3433: } else {
3434: fduSeekResultStatus = FDC_ST0_NT | FDC_ST0_SE;
3435: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
3436: System.out.printf ("\tfduSeekResultStatus=%s\n", fdcResultStatusToString (fduSeekResultStatus));
3437: }
3438: TickerQueue.tkqAdd (fduSeekTicker, XEiJ.mpuClockTime + FDU_SEEK_INTERVAL);
3439: fdcCPhase ();
3440: }
3441: }
3442:
3443:
3444:
3445:
3446:
3447:
3448:
3449:
3450:
3451:
3452:
3453:
3454:
3455:
3456:
3457:
3458:
3459:
3460:
3461:
3462:
3463:
3464:
3465:
3466:
3467:
3468:
3469:
3470:
3471:
3472:
3473:
3474:
3475:
3476:
3477:
3478:
3479:
3480:
3481:
3482:
3483:
3484:
3485:
3486:
3487:
3488:
3489:
3490:
3491:
3492:
3493:
3494:
3495:
3496:
3497:
3498:
3499:
3500:
3501:
3502: public void fduCommandScan () {
3503:
3504: int ncn = fdcCommandBuffer[2] & 255;
3505: int phn = fdcCommandBuffer[3] & 255;
3506: int prn = fdcCommandBuffer[4] & 255;
3507: int pnn = fdcCommandBuffer[5] & 255;
3508: int eot = fdcCommandBuffer[6] & 255;
3509: int stp = fdcCommandBuffer[8] & 3;
3510: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
3511: System.out.printf ("%08x fduCommandScan%d(NCN=%d H=%d R=%d N=%d EOT=%d STP=%d)\n",
3512: XEiJ.regPC0, abuNumber, ncn, phn, prn, pnn, eot, stp);
3513: }
3514: fduCommandNumber = fdcCommandNumber;
3515: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
3516: System.out.printf ("\tfduCommandNumber%d=0x%02x\n", abuNumber, fduCommandNumber);
3517: }
3518: if (!fduIsReady ()) {
3519: fduEPhaseEnd (FDC_ST0_AT | FDC_ST0_NR | ((fduPHN & 1) << 2 | abuNumber) << 24);
3520: return;
3521: }
3522: fduNCN = ncn;
3523: fduPHN = phn;
3524: fduPRN = prn;
3525: fduPNN = pnn;
3526: fduEOT = eot;
3527: fduSTP = stp;
3528: fduSRC = 16 - fdcSRT;
3529: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
3530: System.out.printf ("\tfduNCN%d=%d\n", abuNumber, fduNCN);
3531: System.out.printf ("\tfduPHN%d=%d\n", abuNumber, fduPHN);
3532: System.out.printf ("\tfduPRN%d=%d\n", abuNumber, fduPRN);
3533: System.out.printf ("\tfduPNN%d=%d\n", abuNumber, fduPNN);
3534: System.out.printf ("\tfduEOT%d=%d\n", abuNumber, fduEOT);
3535: System.out.printf ("\tfduSTP%d=%d\n", abuNumber, fduSTP);
3536: System.out.printf ("\tfduSRC%d=%d\n", abuNumber, fduSRC);
3537: }
3538: fdcStatus = (FDC_MPU_TO_FDC | FDC_CB |
3539: (fdcStatus & (FDC_D3B | FDC_D2B | FDC_D1B | FDC_D0B)));
3540: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
3541: System.out.printf ("\tfdcStatus=%s\n", fdcStatusToString (fdcStatus));
3542: }
3543: fdcReadHandle = null;
3544: fdcWriteHandle = null;
3545: TickerQueue.tkqAdd (fduSeekTicker, XEiJ.mpuClockTime + FDU_SEEK_INTERVAL);
3546: }
3547:
3548: public void fduScanEPhase () {
3549: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
3550: System.out.printf ("%08x fduScanEPhase%d()\n", XEiJ.regPC0, abuNumber);
3551: }
3552:
3553: fdcStatus = (FDC_RQM | FDC_MPU_TO_FDC | FDC_CB |
3554: (fdcStatus & (FDC_D3B | FDC_D2B | FDC_D1B | FDC_D0B)));
3555: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
3556: System.out.printf ("\tfdcStatus=%s\n", fdcStatusToString (fdcStatus));
3557: }
3558:
3559: fdcReadHandle = null;
3560: fdcWriteHandle = fdcTempBuffer;
3561: fdcIndex = fdcStart = 0;
3562: fdcLimit = 128 << fduPNN;
3563: HD63450.dmaFallPCL (0);
3564: }
3565:
3566:
3567: public void fduScanEqualEPhaseEnd () {
3568: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
3569: System.out.printf ("%08x fduScanEqualEPhaseEnd%d()\n", XEiJ.regPC0, abuNumber);
3570: }
3571: int o = fduCalcOffset ();
3572: if (o < 0) {
3573: fduEPhaseEnd (FDC_ST0_AT | FDC_ST1_MA | ((fduPHN & 1) << 2 | abuNumber) << 24);
3574: return;
3575: }
3576:
3577: scan:
3578: {
3579: int l = 128 << fduPNN;
3580: for (int i = 0; i < l; i++) {
3581: int d = fdcTempBuffer[i] & 255;
3582: if (d != 0xff && (fduImage[o + i] & 255) != d) {
3583: break scan;
3584: }
3585: }
3586:
3587: HD63450.dmaRisePCL (0);
3588: fduEPhaseEnd (FDC_ST0_NT | FDC_ST2_SH | ((fduPHN & 1) << 2 | abuNumber) << 24);
3589: return;
3590: }
3591: if (fduPRN == fduEOT) {
3592: HD63450.dmaRisePCL (0);
3593: fduEPhaseEnd (FDC_ST0_NT | FDC_ST2_SN | ((fduPHN & 1) << 2 | abuNumber) << 24);
3594: return;
3595: }
3596:
3597: fduPRN += fduSTP;
3598: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
3599: System.out.printf ("\tfduPRN%d=%d\n", abuNumber, fduPRN);
3600: }
3601: fdcIndex = fdcStart = 0;
3602:
3603: }
3604:
3605:
3606: public void fduScanLowOrEqualEPhaseEnd () {
3607: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
3608: System.out.printf ("%08x fduScanLowOrEqualEPhaseEnd%d()\n", XEiJ.regPC0, abuNumber);
3609: }
3610: int o = fduCalcOffset ();
3611: if (o < 0) {
3612: fduEPhaseEnd (FDC_ST0_AT | FDC_ST1_MA | ((fduPHN & 1) << 2 | abuNumber) << 24);
3613: return;
3614: }
3615: scan:
3616: {
3617: int l = 128 << fduPNN;
3618: for (int i = 0; i < l; i++) {
3619: int d = fdcTempBuffer[i] & 255;
3620: if (d != 0xff && (fduImage[o + i] & 255) > d) {
3621: break scan;
3622: }
3623: }
3624:
3625: HD63450.dmaRisePCL (0);
3626: fduEPhaseEnd (FDC_ST0_NT | ((fduPHN & 1) << 2 | abuNumber) << 24);
3627: return;
3628: }
3629: if (fduPRN == fduEOT) {
3630: HD63450.dmaRisePCL (0);
3631: fduEPhaseEnd (FDC_ST0_NT | FDC_ST2_SN | ((fduPHN & 1) << 2 | abuNumber) << 24);
3632: return;
3633: }
3634:
3635: fduPRN += fduSTP;
3636: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
3637: System.out.printf ("\tfduPRN%d=%d\n", abuNumber, fduPRN);
3638: }
3639: fdcIndex = fdcStart = 0;
3640: fdcLimit = 128 << fduPNN;
3641: }
3642:
3643:
3644: public void fduScanHighOrEqualEPhaseEnd () {
3645: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
3646: System.out.printf ("%08x fduScanHighOrEqualEPhaseEnd%d()\n", XEiJ.regPC0, abuNumber);
3647: }
3648: int o = fduCalcOffset ();
3649: if (o < 0) {
3650: fduEPhaseEnd (FDC_ST0_AT | FDC_ST1_MA | ((fduPHN & 1) << 2 | abuNumber) << 24);
3651: return;
3652: }
3653: scan:
3654: {
3655: int l = 128 << fduPNN;
3656: for (int i = 0; i < l; i++) {
3657: int d = fdcTempBuffer[i] & 255;
3658: if (d != 0xff && (fduImage[o + i] & 255) < d) {
3659: break scan;
3660: }
3661: }
3662:
3663: HD63450.dmaRisePCL (0);
3664: fduEPhaseEnd (FDC_ST0_NT | ((fduPHN & 1) << 2 | abuNumber) << 24);
3665: return;
3666: }
3667: if (fduPRN == fduEOT) {
3668: HD63450.dmaRisePCL (0);
3669: fduEPhaseEnd (FDC_ST0_NT | FDC_ST2_SN | ((fduPHN & 1) << 2 | abuNumber) << 24);
3670: return;
3671: }
3672:
3673: fduPRN += fduSTP;
3674: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
3675: System.out.printf ("\tfduPRN%d=%d\n", abuNumber, fduPRN);
3676: }
3677: fdcIndex = fdcStart = 0;
3678: fdcLimit = 128 << fduPNN;
3679: }
3680:
3681:
3682:
3683: public int fduCalcOffset () {
3684: int o = (fduMedia == null ? -1 :
3685: fduDoubleDensity == fduMedia.fdmDoubleDensity &&
3686: fduPNN == fduMedia.fdmSectorScale &&
3687: fduPCN < fduMedia.fdmCylindersPerDisk &&
3688: (fduMedia == FDMedia.FDM_2HDE ?
3689: fduPHN == (fduPCN == 0 && fduPRN == 1 ? 0 : 128) || fduPHN == 129 :
3690: fduPHN < fduMedia.fdmTracksPerCylinder) &&
3691: (fduMedia == FDMedia.FDM_2HS ?
3692: fduPCN == 0 && fduPHN == 0 ? fduPRN == 1 || (11 <= fduPRN && fduPRN <= 18) : 10 <= fduPRN && fduPRN <= 18 :
3693: 1 <= fduPRN && fduPRN <= fduMedia.fdmSectorsPerTrack) ?
3694: fduMedia.fdmBytesPerSector * (
3695: (fduPRN <= fduMedia.fdmSectorsPerTrack ? fduPRN : fduPRN - fduMedia.fdmSectorsPerTrack) - 1 +
3696: fduMedia.fdmSectorsPerTrack * (
3697: ((fduPHN & 1) + fduMedia.fdmTracksPerCylinder * fduPCN))) :
3698: -1);
3699: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
3700: System.out.printf ("\tfduCalcOffset(C=%d H=%d R=%d N=%d)=%d\n", fduPCN, fduPHN, fduPRN, fduPNN, o);
3701: }
3702: return o;
3703: }
3704:
3705:
3706:
3707: public void fduEPhaseEnd (int status) {
3708: if (FDC_DEBUG_TRACE && fdcDebugLogOn) {
3709: System.out.printf ("%08x fduEPhaseEnd%d(%s)\n", XEiJ.regPC0, abuNumber, fdcResultStatusToString (status));
3710: }
3711:
3712:
3713: fdcResultBuffer[0] = (byte) (status >> 24);
3714: fdcResultBuffer[1] = (byte) (status >> 16);
3715: fdcResultBuffer[2] = (byte) (status >> 8);
3716: fdcResultBuffer[3] = (byte) fduPCN;
3717: fdcResultBuffer[4] = (byte) fduPHN;
3718: fdcResultBuffer[5] = (byte) fduPRN;
3719: fdcResultBuffer[6] = (byte) fduPNN;
3720:
3721: fdcRPhase (7);
3722:
3723: IOInterrupt.ioiFdcRise ();
3724: }
3725:
3726:
3727: }
3728:
3729:
3730:
3731: }
3732:
3733:
3734: