HFS.java
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28: package xeij;
29:
30: import java.awt.event.*;
31: import java.io.*;
32: import java.lang.*;
33: import java.util.*;
34: import javax.swing.*;
35:
36: public class HFS {
37:
38: public static final boolean HFS_DEBUG_TRACE = false;
39: public static final boolean HFS_DEBUG_FILE_INFO = false;
40:
41: public static final boolean HFS_REPORT_INCOMPATIBLE_COMMAND = false;
42:
43:
44: public static final boolean HFS_COMMAND_TRACE = false;
45: public static boolean hfsCommandTraceOn;
46:
47:
48: public static final boolean HFS_USE_THREAD = true;
49: public static final long HFS_THREAD_DELAY = 0L;
50: public static java.util.Timer hfsTimer;
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80: public static final int HFS_STATE_IDLE = 0;
81: public static final int HFS_STATE_X68K = 1;
82: public static final int HFS_STATE_HOST = 2;
83: public static final int HFS_STATE_BUSY = 3;
84: public static final int HFS_STATE_DONE = 4;
85: public static int hfsState;
86:
87:
88: public static final boolean HFS_BUFFER_TRACE = false;
89: public static final int HFS_BUFFER_SIZE = 1024 * 64;
90:
91:
92:
93:
94: public static final int HFS_BUFFER_STEP = 128;
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121: public static final int HFS_ADDRESS = 0x00e9f020;
122: public static final int HFS_BOOT_HANDLE = HFS_ADDRESS + 0;
123: public static final int HFS_INSTALL_HANDLE = HFS_ADDRESS + 4;
124: public static final int HFS_INSTALL_PARAMETER = HFS_ADDRESS + 8;
125: public static final int HFS_HUMAN68K_MAGIC = HFS_ADDRESS + 12;
126: public static final int HFS_BOOT_ROUTINE = HFS_ADDRESS + 20;
127: public static final int HFS_INSTALL_ROUTINE = HFS_ADDRESS + 24;
128: public static final int HFS_MAGIC = HFS_ADDRESS + 28;
129: public static final int HFS_ROM_SIZE = 32;
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144: public static final int HFS_NEXT_DEVICE = 0;
145: public static final int HFS_DEVICE_TYPE = 4;
146: public static final int HFS_STRATEGY_HANDLE = 6;
147: public static final int HFS_INTERRUPT_HANDLE = 10;
148: public static final int HFS_DEVICE_NAME = 14;
149: public static final int HFS_DRIVE_NUMBER = 22;
150: public static final int HFS_STRATEGY_ROUTINE = 24;
151: public static final int HFS_INTERRUPT_ROUTINE = 28;
152: public static final int HFS_DEVICE_SIZE = 32;
153:
154:
155: public static final int HFS_MIN_UNITS = 1;
156: public static final int HFS_MAX_UNITS = 16;
157: public static final String HFS_DUMMY_UNIT_NAME = "*HFS*";
158: public static final HFUnit[] hfsUnitArray = new HFUnit[HFS_MAX_UNITS];
159: public static int hfsBootUnit;
160: public static final int[] hfsDeviceUnitArray = new int[HFS_MAX_UNITS];
161: public static int hfsDeviceUnitCount;
162:
163:
164: public static JMenu hfsMenu;
165:
166:
167: public static javax.swing.filechooser.FileFilter hfsFileFilter;
168:
169:
170: public static OpenDialog hfsOpenDialog;
171: public static int hfsOpenUnit;
172: public static ArrayList<File[]> hfsOpenHistory;
173:
174:
175: public static int hfsDeviceHeader;
176: public static int hfsRequestHeader;
177: public static int hfsRequest1Number;
178: public static int hfsRequest2Command;
179: public static int hfsRequest13Mode;
180: public static int hfsRequest14Namests;
181: public static int hfsRequest18Param;
182: public static int hfsRequest22Fcb;
183: public static int hfsRequest3Error;
184: public static int hfsRequest18Result;
185: public static HFUnit hfsRequestUnit;
186:
187:
188:
189: public static final boolean HFS_USE_TWENTY_ONE = false;
190: public static final int HFS_TW_VERBOSE_MODE = 1 << 31;
191: public static final int HFS_TW_CASE_SENSITIVE = 1 << 30;
192: public static final int HFS_TW_SPECIAL_CHARACTER = 1 << 29;
193: public static final int HFS_TW_MULTI_PERIOD = 1 << 28;
194: public static final int HFS_TW_NOT_TWENTY_ONE = 1 << 27;
195: public static final int HFS_TW_DISABLE_PRINTER_ECHO = 1 << 26;
196: public static final int HFS_TW_USE_SYSROOT = 1 << 25;
197: public static final int HFS_TW_WARN_CASE_MISMATCH = 1 << 24;
198: public static final int HFS_TW_USE_STRONG_SYSROOT = 1 << 23;
199:
200:
201: public static int hfsTwentyOneOption;
202:
203:
204: public static final boolean HFS_UTF8_WARNING = true;
205: public static boolean hfsUTF8WarningOn;
206: public static HashSet<String> hfsUTF8WarningSet;
207:
208:
209:
210:
211:
212: public static void hfsInit () {
213:
214:
215: if (HFS_COMMAND_TRACE) {
216: hfsCommandTraceOn = false;
217: }
218:
219:
220: if (HFS_USE_THREAD) {
221: hfsTimer = new java.util.Timer ();
222: }
223:
224:
225: if (HFS_USE_TWENTY_ONE) {
226: hfsTwentyOneOption = 0;
227: }
228:
229:
230:
231: hfsFileFilter = new javax.swing.filechooser.FileFilter () {
232: @Override public boolean accept (File file) {
233: if (file.isDirectory ()) {
234: return true;
235: }
236: String path = file.getPath ();
237: if (hfsIsInserted (path)) {
238: return false;
239: }
240: return true;
241: }
242: @Override public String getDescription () {
243: return (Multilingual.mlnJapanese ?
244: "ルートになるディレクトリまたはそこにあるかも知れないファイル" :
245: "Directory to be the root or files that may be found there");
246: }
247: };
248:
249:
250: hfsOpenDialog = null;
251: hfsOpenUnit = 0;
252: hfsOpenHistory = new ArrayList<File[]> ();
253: for (int i = JFileChooser2.MAXIMUM_HISTORY_COUNT - 1; 0 <= i; i--) {
254: hfsAddHistory (JFileChooser2.pathsToFiles (Settings.sgsGetString ("hfhistory" + i)));
255: }
256:
257:
258:
259: hfsBootUnit = 0;
260:
261: hfsDeviceUnitCount = 0;
262: for (int u = 0; u < HFS_MAX_UNITS; u++) {
263: HFUnit unit = hfsUnitArray[u] = new HFUnit (u);
264: if (u < HFS_MIN_UNITS) {
265: unit.connect (false);
266: }
267: }
268:
269:
270: for (int u = 0; u < HFS_MAX_UNITS; u++) {
271: HFUnit unit = hfsUnitArray[u];
272: String path = Settings.sgsGetString ("hf" + u);
273: boolean userWriteProtect = false;
274: if (path.toUpperCase ().endsWith (":R")) {
275: path = path.substring (0, path.length () - 2);
276: userWriteProtect = true;
277: }
278: boolean hostWriteProtect = !new File (path).canWrite ();
279: if (path.length () != 0) {
280: unit.connect (true);
281: if (unit.insert (path,
282: userWriteProtect || hostWriteProtect)) {
283: hfsAddHistory (new File (path).getAbsoluteFile ());
284: }
285: }
286: }
287: if (HFS_UTF8_WARNING) {
288: hfsUTF8WarningOn = Settings.sgsGetOnOff ("utf8warning");
289: hfsUTF8WarningSet = new HashSet<String> ();
290: }
291:
292:
293: hfsMenu = ComponentFactory.createMenu ("HFS");
294: ComponentFactory.addComponents (
295: hfsMenu,
296: ComponentFactory.createHorizontalBox (
297: Multilingual.mlnText (ComponentFactory.createLabel ("Host file system"),
298: "ja", "ホストファイルシステム")),
299: ComponentFactory.createHorizontalSeparator ()
300: );
301: for (HFUnit unit : hfsUnitArray) {
302: hfsMenu.add (unit.getMenuBox ());
303: }
304: if (HFS_UTF8_WARNING) {
305: ComponentFactory.addComponents (
306: hfsMenu,
307: ComponentFactory.createHorizontalSeparator (),
308: Multilingual.mlnText (
309: ComponentFactory.createCheckBoxMenuItem (hfsCommandTraceOn, "UTF-8 warning", new ActionListener () {
310: @Override public void actionPerformed (ActionEvent ae) {
311: hfsUTF8WarningOn = ((JCheckBoxMenuItem) ae.getSource ()).isSelected ();
312: }
313: }),
314: "ja", "UTF-8 警告")
315: );
316: }
317: if (HFS_COMMAND_TRACE) {
318: ComponentFactory.addComponents (
319: hfsMenu,
320: ComponentFactory.createHorizontalSeparator (),
321: Multilingual.mlnText (
322: ComponentFactory.createCheckBoxMenuItem (hfsCommandTraceOn, "HFS command trace", new ActionListener () {
323: @Override public void actionPerformed (ActionEvent ae) {
324: hfsCommandTraceOn = ((JCheckBoxMenuItem) ae.getSource ()).isSelected ();
325: }
326: }),
327: "ja", "HFS コマンドトレース")
328: );
329: }
330:
331:
332: MainMemory.mmrWl (HFS_BOOT_HANDLE, HFS_BOOT_ROUTINE);
333: MainMemory.mmrWl (HFS_INSTALL_HANDLE, HFS_INSTALL_ROUTINE);
334: MainMemory.mmrWl (HFS_INSTALL_PARAMETER, 0);
335: MainMemory.mmrWl (HFS_HUMAN68K_MAGIC, 'H' << 24 | 'u' << 16 | 'm' << 8 | 'a');
336: MainMemory.mmrWl (HFS_HUMAN68K_MAGIC + 4, 'n' << 24 | '6' << 16 | '8' << 8 | 'k');
337: MainMemory.mmrWl (HFS_BOOT_ROUTINE, XEiJ.EMX_OPCODE_HFSBOOT << 16 | 0x4e75);
338: MainMemory.mmrWl (HFS_INSTALL_ROUTINE, XEiJ.EMX_OPCODE_HFSINST << 16 | 0x4e75);
339: MainMemory.mmrWl (HFS_MAGIC, 'J' << 24 | 'H' << 16 | 'F' << 8 | 'S');
340:
341: hfsState = HFS_STATE_IDLE;
342:
343: }
344:
345:
346:
347:
348:
349: public static void hfsTini () {
350:
351: if (HFS_USE_THREAD) {
352: if (hfsTimer != null) {
353: hfsTimer.schedule (new TimerTask () {
354: @Override public void run () {
355: for (HFUnit unit : hfsUnitArray) {
356: unit.hfuTini ();
357: }
358: hfsTimer.cancel ();
359: }
360: }, HFS_THREAD_DELAY);
361: }
362: } else {
363: for (HFUnit unit : hfsUnitArray) {
364: unit.hfuTini ();
365: }
366: }
367:
368:
369:
370: if (hfsOpenDialog != null) {
371: Settings.sgsPutOnOff ("hfreadonly", hfsOpenDialog.getReadOnly ());
372: Settings.sgsPutOnOff ("hfappreboot", hfsOpenDialog.getReboot ());
373: ArrayList<String> pathsList = hfsOpenDialog.getHistory ();
374: int n = pathsList.size ();
375: for (int i = 0; i < n; i++) {
376: Settings.sgsPutString ("hfhistory" + i, pathsList.get (i));
377: }
378: for (int i = n; i < HFS_MAX_UNITS; i++) {
379: Settings.sgsPutString ("hfhistory" + i, "");
380: }
381: }
382:
383:
384: for (int u = 0; u < HFS_MAX_UNITS; u++) {
385: AbstractUnit unit = hfsUnitArray[u];
386: Settings.sgsPutString (
387: "hf" + u,
388: unit.abuConnected && unit.abuInserted ?
389: unit.abuWriteProtected ? unit.abuPath + ":R" : unit.abuPath :
390: "");
391: }
392:
393: if (HFS_UTF8_WARNING) {
394: Settings.sgsPutOnOff ("utf8warning", hfsUTF8WarningOn);
395: }
396:
397: }
398:
399:
400:
401: public static boolean hfsIsInserted (String path) {
402: for (HFUnit unit : hfsUnitArray) {
403: if (unit != null &&
404: unit.abuConnected &&
405: unit.abuInserted &&
406: unit.abuPath.equals (path)) {
407: return true;
408: }
409: }
410: return false;
411: }
412:
413:
414:
415:
416: public static void hfsReset () {
417: for (HFUnit unit : hfsUnitArray) {
418: unit.hfuTini ();
419: }
420: }
421:
422:
423:
424: public static boolean hfsIPLBoot () {
425: return hfsUnitArray[hfsBootUnit].hfuIPLBoot ();
426: }
427:
428:
429:
430:
431:
432:
433:
434:
435:
436:
437:
438:
439:
440:
441:
442:
443:
444:
445: public static void hfsInstall () throws M68kException {
446: if (XEiJ.regRn[2] != 0) {
447: XEiJ.regRn[2] = -1;
448: } else {
449: XEiJ.regRn[2] = 1;
450: int a1 = XEiJ.regRn[9];
451: hfsDeviceHeader = a1;
452: MC68060.mmuWriteLongData (a1 + HFS_NEXT_DEVICE, -1, XEiJ.regSRS);
453: MC68060.mmuWriteWordData (a1 + HFS_DEVICE_TYPE, 0x2000, XEiJ.regSRS);
454: MC68060.mmuWriteLongData (a1 + HFS_STRATEGY_HANDLE, a1 + HFS_STRATEGY_ROUTINE, XEiJ.regSRS);
455: MC68060.mmuWriteLongData (a1 + HFS_INTERRUPT_HANDLE, a1 + HFS_INTERRUPT_ROUTINE, XEiJ.regSRS);
456: MC68060.mmuWriteLongData (a1 + HFS_DEVICE_NAME, 0x01 << 24 | 'X' << 16 | 'E' << 8 | 'I', XEiJ.regSRS);
457: MC68060.mmuWriteLongData (a1 + HFS_DEVICE_NAME + 4, 'J' << 24 | 'H' << 16 | 'F' << 8 | 'S', XEiJ.regSRS);
458: MC68060.mmuWriteLongData (a1 + HFS_STRATEGY_ROUTINE, XEiJ.EMX_OPCODE_HFSSTR << 16 | 0x4e75, XEiJ.regSRS);
459: MC68060.mmuWriteLongData (a1 + HFS_INTERRUPT_ROUTINE, XEiJ.EMX_OPCODE_HFSINT << 16 | 0x4e75, XEiJ.regSRS);
460: }
461: }
462:
463:
464:
465: public static void hfsStrategy () throws M68kException {
466: hfsRequestHeader = XEiJ.regRn[13];
467:
468: if (false && HFS_DEBUG_TRACE) {
469: System.out.printf ("hfsStrategy\n");
470: System.out.printf (" hfsRequestHeader = %08x\n", hfsRequestHeader);
471: }
472:
473: }
474:
475:
476:
477:
478: public static boolean hfsInterrupt () throws M68kException {
479:
480: if (false && HFS_DEBUG_TRACE) {
481: System.out.printf ("hfsInterrupt\n");
482: System.out.printf (" hfsRequestHeader = %08x\n", hfsRequestHeader);
483: System.out.printf (" hfsState = %d\n", hfsState);
484: }
485:
486: int a5 = hfsRequestHeader;
487:
488: if (hfsState == HFS_STATE_IDLE) {
489:
490: if (HFS_DEBUG_TRACE) {
491: int number = MC68060.mmuPeekByteZeroData (a5 + 1, XEiJ.regSRS);
492: int command = MC68060.mmuPeekByteZeroData (a5 + 2, XEiJ.regSRS);
493: int mode = MC68060.mmuPeekByteZeroData (a5 + 13, XEiJ.regSRS);
494: int namests = MC68060.mmuPeekLongData (a5 + 14, XEiJ.regSRS);
495: int param = MC68060.mmuPeekLongData (a5 + 18, XEiJ.regSRS);
496: int fcb = MC68060.mmuPeekLongData (a5 + 22, XEiJ.regSRS);
497: if (!(hfsRequest2Command == 0x57 ||
498: hfsRequest2Command == 0x4c && param == 1)) {
499: for (int i = 0; i < 26; i++) {
500: System.out.printf (" %02x", MC68060.mmuPeekByteZeroData (a5 + i, XEiJ.regSRS));
501: }
502: System.out.println ();
503: System.out.printf (" Number: %02x\n", number);
504: System.out.printf (" Command: %02x\n", command);
505: System.out.printf (" Mode: %02x\n", mode);
506: System.out.printf (" Namests: %08x:", namests);
507: for (int i = 0; i < 88; i++) {
508: System.out.printf (" %02x", MC68060.mmuPeekByteZeroData (namests + i, XEiJ.regSRS));
509: }
510: System.out.println ();
511: System.out.printf (" Param: %08x\n", param);
512: System.out.printf (" Fcb: %08x:", fcb);
513: for (int i = 0; i < 96; i++) {
514: System.out.printf (" %02x", MC68060.mmuPeekByteZeroData (fcb + i, XEiJ.regSRS));
515: }
516: System.out.println ();
517: }
518: }
519:
520:
521:
522: hfsRequest1Number = MC68060.mmuReadByteZeroData (a5 + 1, XEiJ.regSRS);
523: hfsRequest2Command = MC68060.mmuReadByteZeroData (a5 + 2, XEiJ.regSRS) & 0x7f;
524: hfsRequest13Mode = MC68060.mmuReadByteZeroData (a5 + 13, XEiJ.regSRS);
525: hfsRequest14Namests = MC68060.mmuReadLongData (a5 + 14, XEiJ.regSRS);
526: hfsRequest18Param = MC68060.mmuReadLongData (a5 + 18, XEiJ.regSRS);
527: hfsRequest22Fcb = MC68060.mmuReadLongData (a5 + 22, XEiJ.regSRS);
528: hfsRequest3Error = 0;
529: hfsRequest18Result = 0;
530:
531: if (hfsRequest2Command == 0x40) {
532:
533:
534:
535:
536:
537:
538:
539:
540:
541:
542:
543:
544:
545:
546:
547:
548:
549:
550:
551:
552:
553:
554:
555:
556:
557:
558:
559:
560:
561:
562:
563:
564:
565: if (HFS_COMMAND_TRACE && hfsCommandTraceOn) {
566: int pc = MainMemory.mmrGetLevelZeroPC ();
567: System.out.println (LabeledAddress.lblSearch (new StringBuilder (), pc).toString ());
568: System.out.printf ("%08x initialize(internaldrive=0x%02,param=0x%08x)\n",
569: pc, hfsRequest22Fcb >>> 24, hfsRequest18Param);
570: }
571: MC68060.mmuWriteByteData (a5 + 2, 0x00, XEiJ.regSRS);
572:
573:
574:
575: hfsDeviceUnitCount = 0;
576: int bootUnit = -1;
577: for (int u = 0; u < HFS_MAX_UNITS; u++) {
578: if (hfsUnitArray[u].isConnected ()) {
579: if (u == hfsBootUnit) {
580: bootUnit = hfsDeviceUnitCount;
581: }
582: hfsDeviceUnitArray[hfsDeviceUnitCount++] = u;
583: }
584: }
585: if (hfsDeviceUnitCount > 0 && bootUnit >= 0) {
586: MC68060.mmuWriteByteData (a5 + 13, hfsDeviceUnitCount, XEiJ.regSRS);
587: MC68060.mmuWriteLongData (a5 + 14, hfsDeviceHeader + 34, XEiJ.regSRS);
588: MC68060.mmuWriteByteData (a5 + 22, 1 + bootUnit, XEiJ.regSRS);
589: } else {
590: hfsRequest3Error = HFUnit.DEV_ABORT | HFUnit.DEV_INVALID_UNIT_NUMBER;
591: hfsRequest18Result = -1;
592: }
593: hfsState = HFS_STATE_DONE;
594:
595: } else {
596:
597: if (hfsRequest1Number < hfsDeviceUnitCount) {
598:
599: hfsRequestUnit = hfsUnitArray[hfsDeviceUnitArray[hfsRequest1Number]];
600: hfsState = HFS_STATE_X68K;
601: hfsRequestUnit.hfuCall ();
602: } else {
603: hfsRequest3Error = HFUnit.DEV_ABORT | HFUnit.DEV_INVALID_UNIT_NUMBER;
604: hfsRequest18Result = -1;
605: hfsState = HFS_STATE_DONE;
606: }
607:
608: }
609:
610: }
611:
612: if (HFS_USE_THREAD) {
613: while (hfsState != HFS_STATE_DONE) {
614: if (hfsState == HFS_STATE_X68K) {
615: hfsRequestUnit.hfuCallX68k ();
616: if (hfsState == HFS_STATE_X68K) {
617: return true;
618: }
619: }
620: if (hfsState == HFS_STATE_HOST) {
621: hfsState = HFS_STATE_BUSY;
622: hfsTimer.schedule (new TimerTask () {
623: @Override public void run () {
624: hfsRequestUnit.hfuCallHost ();
625: }
626: }, HFS_THREAD_DELAY);
627: }
628:
629: if (hfsState == HFS_STATE_BUSY) {
630: return true;
631: }
632: }
633: } else {
634: while (hfsState != HFS_STATE_DONE) {
635: while (hfsState == HFS_STATE_X68K) {
636: hfsRequestUnit.hfuCallX68k ();
637: }
638: if (hfsState == HFS_STATE_HOST) {
639: hfsState = HFS_STATE_BUSY;
640: }
641: if (hfsState == HFS_STATE_BUSY) {
642: hfsRequestUnit.hfuCallHost ();
643: }
644: }
645: }
646:
647: if (HFS_COMMAND_TRACE && hfsCommandTraceOn) {
648: System.out.printf ("\terror=0x%04x,result=0x%08x\n", hfsRequest3Error, hfsRequest18Result);
649: }
650:
651: MC68060.mmuWriteByteData (a5 + 3, hfsRequest3Error, XEiJ.regSRS);
652: MC68060.mmuWriteByteData (a5 + 4, hfsRequest3Error >> 8, XEiJ.regSRS);
653: MC68060.mmuWriteLongData (a5 + 18, hfsRequest18Result, XEiJ.regSRS);
654:
655: hfsState = HFS_STATE_IDLE;
656: return false;
657: }
658:
659: static class OpenDialog extends AbstractOpenDialog {
660: public OpenDialog () {
661: super (XEiJ.frmFrame,
662: "Host file system directory to assign Human68k drives",
663: "Human68k のドライブを割り当てるホストファイルシステムのディレクトリ",
664: true,
665: hfsFileFilter);
666: }
667: @Override public void openFiles (File[] files, boolean reboot) {
668: hfsOpenFiles (files, reboot);
669: }
670: }
671:
672:
673:
674: public static void hfsOpenFiles (File[] list, boolean reset) {
675: boolean success = true;
676: for (int u = hfsOpenUnit, k = 0; k < list.length; ) {
677: if (HFS_MAX_UNITS <= u) {
678: success = false;
679: break;
680: }
681: HFUnit unit = hfsUnitArray[u];
682: if (!unit.abuConnected) {
683: u++;
684: continue;
685: }
686: File file = list[k++];
687: if (!file.isDirectory ()) {
688: file = file.getParentFile ();
689: if (file == null || !file.isDirectory ()) {
690: success = false;
691: continue;
692: }
693: }
694: if (!unit.insert (file.getPath (),
695: hfsOpenDialog.getReadOnly () || !file.canWrite ())) {
696: success = false;
697: continue;
698: }
699: u++;
700: }
701: if (success) {
702: hfsAddHistory (list);
703: if (reset) {
704: hfsBootUnit = hfsOpenUnit;
705: XEiJ.mpuReset (0xa000, HFS_BOOT_HANDLE);
706: }
707: }
708: }
709:
710:
711:
712:
713: public static void hfsAddHistory (File file) {
714: hfsAddHistory (new File[] { file });
715: }
716:
717:
718:
719: public static void hfsAddHistory (File[] files) {
720: if (hfsOpenDialog == null) {
721: hfsOpenHistory.add (files);
722: } else {
723: hfsOpenDialog.addHistory (files);
724: }
725: }
726:
727:
728:
729:
730:
731: public void hfsCheckTwentyOneOption () {
732: hfsTwentyOneOption = 0;
733: if (HFS_USE_TWENTY_ONE) {
734: int a = MainMemory.mmrTwentyOneOptionAddress;
735: if (0 < a) {
736: hfsTwentyOneOption = MC68060.mmuPeekLongData (a, 1);
737: }
738: }
739: }
740:
741:
742:
743:
744:
745:
746:
747:
748:
749:
750:
751:
752:
753:
754:
755:
756:
757:
758:
759:
760:
761:
762:
763:
764:
765:
766:
767:
768:
769:
770:
771:
772:
773:
774:
775:
776:
777:
778:
779:
780:
781:
782:
783:
784:
785:
786:
787:
788:
789:
790:
791:
792:
793:
794:
795:
796:
797:
798:
799:
800:
801:
802:
803:
804:
805:
806:
807:
808:
809:
810:
811:
812:
813:
814:
815:
816:
817:
818: public static class HFUnit extends AbstractUnit {
819:
820:
821:
822:
823:
824: public static final int DEV_IGNORE = 0x4000;
825: public static final int DEV_RETRY = 0x2000;
826: public static final int DEV_ABORT = 0x1000;
827:
828: public static final int DEV_INVALID_UNIT_NUMBER = 0x0001;
829: public static final int DEV_INSERT_MEDIA = 0x0002;
830: public static final int DEV_UNKNOWN_COMMAND = 0x0003;
831: public static final int DEV_CRC_ERROR = 0x0004;
832: public static final int DEV_MANEGEMENT_AREA_BROKEN = 0x0005;
833: public static final int DEV_SEEK_ERROR = 0x0006;
834: public static final int DEV_INVALID_MEDIA = 0x0007;
835: public static final int DEV_SECTOR_NOT_FOUND = 0x0008;
836: public static final int DEV_PRINTER_NOT_CONNECTED = 0x0009;
837: public static final int DEV_WRITE_ERROR = 0x000a;
838: public static final int DEV_READ_ERROR = 0x000b;
839: public static final int DEV_MISCELLANEOUS_ERROR = 0x000c;
840: public static final int DEV_UNPROTECT_MEDIA = 0x000d;
841: public static final int DEV_CANNOT_WRITE = 0x000e;
842: public static final int DEV_FILE_SHARING_VIOLATION = 0x000f;
843:
844:
845:
846: public static final int DOS_INVALID_FUNCTION = -1;
847: public static final int DOS_FILE_NOT_FOUND = -2;
848: public static final int DOS_DIRECTORY_NOT_FOUND = -3;
849: public static final int DOS_TOO_MANY_HANDLES = -4;
850: public static final int DOS_NOT_A_FILE = -5;
851: public static final int DOS_HANDLE_IS_NOT_OPENED = -6;
852: public static final int DOS_BROKEN_MEMORY_CHAIN = -7;
853: public static final int DOS_NOT_ENOUGH_MEMORY = -8;
854: public static final int DOS_INVALID_MEMORY_CHAIN = -9;
855: public static final int DOS_INVALID_ENVIRONMENT = -10;
856: public static final int DOS_ABNORMAL_X_FILE = -11;
857: public static final int DOS_INVALID_ACCESS_MODE = -12;
858: public static final int DOS_ILLEGAL_FILE_NAME = -13;
859: public static final int DOS_INVALID_PARAMETER = -14;
860: public static final int DOS_ILLEGAL_DRIVE_NUMBER = -15;
861: public static final int DOS_CURRENT_DIRECTORY = -16;
862: public static final int DOS_CANNOT_IOCTRL = -17;
863: public static final int DOS_NO_MORE_FILES = -18;
864: public static final int DOS_CANNOT_WRITE = -19;
865: public static final int DOS_DIRECTORY_EXISTS = -20;
866: public static final int DOS_RM_NONEMPTY_DIRECTORY = -21;
867: public static final int DOS_MV_NONEMPTY_DIRECTORY = -22;
868: public static final int DOS_DISK_FULL = -23;
869: public static final int DOS_DIRECTORY_FULL = -24;
870: public static final int DOS_SEEK_OVER_EOF = -25;
871: public static final int DOS_ALREADY_SUPERVISOR = -26;
872: public static final int DOS_THREAD_EXISTS = -27;
873: public static final int DOS_COMMUNICATION_FAILED = -28;
874: public static final int DOS_TOO_MANY_THREADS = -29;
875: public static final int DOS_NOT_ENOUGH_LOCK_AREA = -32;
876: public static final int DOS_FILE_IS_LOCKED = -33;
877: public static final int DOS_OPENED_HANDLE_EXISTS = -34;
878: public static final int DOS_FILE_EXISTS = -80;
879:
880:
881:
882: private static final int HFU_FILES_MAGIC = '*' << 24 | 'H' << 16 | 'F' << 8 | 'S';
883:
884: public String hfuRootPath;
885:
886:
887: public HashMap<Integer,ArrayDeque<byte[]>> hfuFilesBufferToArrayDeque;
888: public int hfuFilesBufferCounter;
889:
890:
891: public class HFHandle {
892: public int hfhFcb;
893: public File hfhFile;
894: public RandomAccessFile hfhRaf;
895: public byte[] hfhBuffer;
896: public long hfhStart;
897: public long hfhEnd;
898: public boolean hfhDirty;
899: public HFHandle (int fcb, File file, RandomAccessFile raf) {
900: hfhFcb = fcb;
901: hfhFile = file;
902: hfhRaf = raf;
903: hfhBuffer = new byte[HFS_BUFFER_SIZE];
904: hfhStart = 0L;
905: hfhEnd = 0L;
906: hfhDirty = false;
907: }
908: @Override public String toString () {
909: return String.format ("HFHandle{fcb:0x%08x,file:\"%s\",start:%d,end:%d,dirty:%b}", hfhFcb, hfhFile.toString (), hfhStart, hfhEnd, hfhDirty);
910: }
911: }
912: public HashMap<Integer,HFHandle> hfuFcbToHandle;
913: public LinkedList<HFHandle> hfuClosedHandle;
914: public HFHandle hfuNewHandle (int fcb, File file, RandomAccessFile raf) {
915: HFHandle handle = hfuClosedHandle.pollFirst ();
916: if (handle == null) {
917: return new HFHandle (fcb, file, raf);
918: }
919: handle.hfhFcb = fcb;
920: handle.hfhFile = file;
921: handle.hfhRaf = raf;
922: Arrays.fill (handle.hfhBuffer, (byte) 0);
923: handle.hfhStart = 0L;
924: handle.hfhEnd = 0L;
925: handle.hfhDirty = false;
926: return handle;
927: }
928: public void hfuRecycleHandle (HFHandle handle) {
929: hfuClosedHandle.push (handle);
930: }
931:
932:
933: public final byte[] hfuTargetNameArray1 = new byte[88];
934: public final byte[] hfuTargetNameArray2 = new byte[88];
935: public String hfuTargetName1;
936: public String hfuTargetName2;
937: public long hfuTargetLastModified;
938: public int hfuTargetOpenMode;
939: public HFHandle hfuTargetHandle;
940: public long hfuTargetPosition;
941: public long hfuTargetFileSize;
942: public long hfuTargetLength;
943: public long hfuTargetAddress;
944: public long hfuTargetTransferred;
945: public long hfuTargetTotalSpace;
946: public long hfuTargetFreeSpace;
947:
948:
949:
950: public HFUnit (int number) {
951: super (number);
952: hfuRootPath = null;
953: hfuFilesBufferToArrayDeque = new HashMap<Integer,ArrayDeque<byte[]>> ();
954: hfuFilesBufferCounter = 0;
955: hfuFcbToHandle = new HashMap<Integer,HFHandle> ();
956: hfuClosedHandle = new LinkedList<HFHandle> ();
957: }
958:
959:
960:
961:
962:
963: public void hfuTini () {
964: for (HFHandle handle : hfuFcbToHandle.values ()) {
965: RandomAccessFile raf = handle.hfhRaf;
966:
967: if (handle.hfhDirty) {
968: if (HFS_BUFFER_TRACE) {
969: System.out.printf ("delaywrite(fcb=0x%08x,name=\"%s\",start=0x%08x,end=0x%08x)\n", handle.hfhFcb, handle.hfhFile.toString(), handle.hfhStart, handle.hfhEnd);
970: }
971: try {
972: raf.seek (handle.hfhStart);
973: } catch (IOException ioe) {
974: System.out.println ((Multilingual.mlnJapanese ? "シークエラー: " : "Seek error: ") + handle.toString ());
975: }
976: try {
977: raf.write (handle.hfhBuffer, 0, (int) (handle.hfhEnd - handle.hfhStart));
978: } catch (IOException ioe) {
979: System.out.println ((Multilingual.mlnJapanese ? "遅延書き込みに失敗しました: " : "Delayed write failed: ") + handle.toString ());
980: }
981: handle.hfhDirty = false;
982: }
983: try {
984: raf.close ();
985: } catch (IOException ioe) {
986: System.out.println ((Multilingual.mlnJapanese ? "クローズエラー: " : "Close error: ") + handle.toString ());
987: }
988: }
989: hfuFcbToHandle.clear ();
990: hfuFilesBufferToArrayDeque.clear ();
991:
992: }
993:
994:
995:
996:
997:
998:
999:
1000:
1001: public boolean hfuIPLBoot () {
1002: if (!abuConnected) {
1003: return false;
1004: }
1005:
1006: byte[] rr = XEiJ.rscGetResource ("HUMAN.SYS");
1007: if (rr == null ||
1008: ByteArray.byaRwz (rr, 0x00) != ('H' << 8 | 'U') ||
1009: ByteArray.byaRls (rr, 0x04) != 0x00006800 ||
1010: ByteArray.byaRls (rr, 0x08) != 0x00006800) {
1011: return false;
1012: }
1013: int textData = ByteArray.byaRls (rr, 0x0c) + ByteArray.byaRls (rr, 0x10);
1014: int bssCommStack = ByteArray.byaRls (rr, 0x14);
1015: System.arraycopy (rr, 0x40, MainMemory.mmrM8, 0x00006800, textData);
1016: Arrays.fill (MainMemory.mmrM8, 0x00006800 + textData, 0x00006800 + textData + bssCommStack, (byte) 0);
1017: return true;
1018: }
1019:
1020:
1021:
1022: @Override protected boolean eject () {
1023: String path = abuPath;
1024: if (!super.eject ()) {
1025: return false;
1026: }
1027: if (path.length () != 0) {
1028: hfsAddHistory (new File (path).getAbsoluteFile ());
1029: System.out.println (Multilingual.mlnJapanese ?
1030: path + " を hf" + abuNumber + " から切り離しました" :
1031: path + " was ejected from hf" + abuNumber);
1032: }
1033: return true;
1034: }
1035:
1036:
1037:
1038: @Override protected boolean open () {
1039: if (!super.open ()) {
1040: return false;
1041: }
1042: hfsOpenUnit = abuNumber;
1043: if (hfsOpenDialog == null) {
1044: hfsOpenDialog = new OpenDialog ();
1045: hfsOpenDialog.setReadOnly (Settings.sgsGetOnOff ("hfreadonly"));
1046: hfsOpenDialog.setReboot (Settings.sgsGetOnOff ("hfappreboot"));
1047: for (File[] files : hfsOpenHistory) {
1048: hfsOpenDialog.addHistory (files);
1049: }
1050: hfsOpenHistory.clear ();
1051: }
1052: hfsOpenDialog.rescanCurrentDirectory ();
1053: XEiJ.pnlExitFullScreen (true);
1054: hfsOpenDialog.setVisible (true);
1055: return true;
1056: }
1057:
1058:
1059:
1060: @Override protected boolean load (String path) {
1061: File file = new File (path).getAbsoluteFile ();
1062: if (!file.isDirectory ()) {
1063: file = file.getParentFile ();
1064: if (file == null || !file.isDirectory ()) {
1065: return false;
1066: }
1067: }
1068: hfuRootPath = file.getAbsolutePath ();
1069: hfsAddHistory (new File (path).getAbsoluteFile ());
1070: System.out.println (Multilingual.mlnJapanese ?
1071: hfuRootPath + " を hf" + abuNumber + " に接続しました" :
1072: hfuRootPath + " was inserted in hf" + abuNumber);
1073: return true;
1074: }
1075:
1076:
1077:
1078: public void hfuCall () throws M68kException {
1079: switch (hfsRequest2Command) {
1080: case 0x41:
1081: hfuCallChdir ();
1082: break;
1083: case 0x42:
1084: hfuCallMkdir ();
1085: break;
1086: case 0x43:
1087: hfuCallRmdir ();
1088: break;
1089: case 0x44:
1090: hfuCallRename ();
1091: break;
1092: case 0x45:
1093: hfuCallDelete ();
1094: break;
1095: case 0x46:
1096: hfuCallChmod ();
1097: break;
1098: case 0x47:
1099: hfuCallFiles ();
1100: break;
1101: case 0x48:
1102: hfuCallNfiles ();
1103: break;
1104: case 0x49:
1105: hfuCallCreateNewfile ();
1106: break;
1107: case 0x4a:
1108: hfuCallOpen ();
1109: break;
1110: case 0x4b:
1111: hfuCallClose ();
1112: break;
1113: case 0x4c:
1114: hfuCallRead ();
1115: break;
1116: case 0x4d:
1117: hfuCallWrite ();
1118: break;
1119: case 0x4e:
1120: hfuCallSeek ();
1121: break;
1122: case 0x4f:
1123: hfuCallFiledate ();
1124: break;
1125: case 0x50:
1126: hfuCallDskfre ();
1127: break;
1128: case 0x51:
1129: hfuCallDrvctrl ();
1130: break;
1131: case 0x52:
1132: hfuCallGetdpb ();
1133: break;
1134: case 0x53:
1135: hfuCallDiskred ();
1136: break;
1137: case 0x54:
1138: hfuCallDiskwrt ();
1139: break;
1140: case 0x55:
1141: hfuCallSpecialCtrl ();
1142: break;
1143: case 0x56:
1144: hfuCallFflush ();
1145: break;
1146: case 0x57:
1147: hfuCallMediacheck ();
1148: break;
1149: case 0x58:
1150: hfuCallLock ();
1151: break;
1152: default:
1153: hfsRequest3Error = DEV_ABORT | DEV_UNKNOWN_COMMAND;
1154: hfsRequest18Result = -1;
1155: hfsState = HFS_STATE_DONE;
1156: }
1157: }
1158:
1159:
1160:
1161: public void hfuCallX68k () throws M68kException {
1162: switch (hfsRequest2Command) {
1163:
1164:
1165:
1166:
1167:
1168:
1169:
1170:
1171:
1172:
1173:
1174:
1175:
1176:
1177:
1178:
1179:
1180:
1181:
1182:
1183: case 0x47:
1184: hfuCallFilesX68k ();
1185: break;
1186:
1187:
1188:
1189:
1190:
1191: case 0x49:
1192: hfuCallCreateNewfileX68k ();
1193: break;
1194: case 0x4a:
1195: hfuCallOpenX68k ();
1196: break;
1197: case 0x4b:
1198: hfuCallCloseX68k ();
1199: break;
1200: case 0x4c:
1201: hfuCallReadX68k ();
1202: break;
1203: case 0x4d:
1204: hfuCallWriteX68k ();
1205: break;
1206:
1207:
1208:
1209:
1210:
1211:
1212:
1213:
1214: case 0x50:
1215: hfuCallDskfreX68k ();
1216: break;
1217:
1218:
1219:
1220:
1221:
1222:
1223:
1224:
1225:
1226:
1227:
1228:
1229:
1230:
1231:
1232:
1233:
1234:
1235:
1236:
1237:
1238:
1239:
1240:
1241:
1242:
1243: }
1244: }
1245:
1246:
1247:
1248: public void hfuCallHost () {
1249: switch (hfsRequest2Command) {
1250: case 0x41:
1251: hfuCallChdirHost ();
1252: break;
1253: case 0x42:
1254: hfuCallMkdirHost ();
1255: break;
1256: case 0x43:
1257: hfuCallRmdirHost ();
1258: break;
1259: case 0x44:
1260: hfuCallRenameHost ();
1261: break;
1262: case 0x45:
1263: hfuCallDeleteHost ();
1264: break;
1265: case 0x46:
1266: hfuCallChmodHost ();
1267: break;
1268: case 0x47:
1269: hfuCallFilesHost ();
1270: break;
1271:
1272:
1273:
1274:
1275:
1276: case 0x49:
1277: hfuCallCreateNewfileHost ();
1278: break;
1279: case 0x4a:
1280: hfuCallOpenHost ();
1281: break;
1282: case 0x4b:
1283: hfuCallCloseHost ();
1284: break;
1285: case 0x4c:
1286: hfuCallReadHost ();
1287: break;
1288: case 0x4d:
1289: hfuCallWriteHost ();
1290: break;
1291:
1292:
1293:
1294:
1295:
1296:
1297:
1298:
1299: case 0x50:
1300: hfuCallDskfreHost ();
1301: break;
1302:
1303:
1304:
1305:
1306:
1307:
1308:
1309:
1310:
1311:
1312:
1313:
1314:
1315:
1316:
1317:
1318:
1319: case 0x56:
1320: hfuCallFflushHost ();
1321: break;
1322:
1323:
1324:
1325:
1326:
1327:
1328:
1329:
1330: }
1331: }
1332:
1333:
1334:
1335:
1336:
1337:
1338:
1339:
1340:
1341:
1342:
1343:
1344:
1345:
1346:
1347:
1348:
1349: public void hfuCallChdir () throws M68kException {
1350: hfuTargetName1 = hfuNamestsToPath (hfsRequest14Namests, false);
1351: if (hfuTargetName1 == null) {
1352: hfsRequest18Result = DOS_ILLEGAL_FILE_NAME;
1353: hfsState = HFS_STATE_DONE;
1354: return;
1355: }
1356: if (HFS_COMMAND_TRACE && hfsCommandTraceOn) {
1357: int pc = MainMemory.mmrGetLevelZeroPC ();
1358: System.out.println (LabeledAddress.lblSearch (new StringBuilder (), pc).toString ());
1359: System.out.printf ("%08x chdir(name=\"%s\")\n",
1360: pc, hfuTargetName1);
1361: }
1362: if (!abuInserted) {
1363: hfsRequest3Error = DEV_RETRY | DEV_ABORT | DEV_INSERT_MEDIA;
1364: hfsRequest18Result = -1;
1365: hfsState = HFS_STATE_DONE;
1366: return;
1367: }
1368: hfsRequest18Result = 0;
1369: hfsState = HFS_STATE_HOST;
1370: }
1371:
1372:
1373: public void hfuCallChdirHost () {
1374: File file1 = new File (hfuTargetName1);
1375: hfsRequest18Result = (!file1.isDirectory () || file1.list() == null ? DOS_DIRECTORY_NOT_FOUND :
1376: 0);
1377: hfsState = HFS_STATE_DONE;
1378: }
1379:
1380:
1381:
1382:
1383:
1384:
1385:
1386:
1387:
1388:
1389:
1390:
1391:
1392:
1393:
1394:
1395: public void hfuCallMkdir () throws M68kException {
1396: hfuTargetName1 = hfuNamestsToPath (hfsRequest14Namests);
1397: if (hfuTargetName1 == null) {
1398: hfsRequest18Result = DOS_ILLEGAL_FILE_NAME;
1399: hfsState = HFS_STATE_DONE;
1400: return;
1401: }
1402: if (HFS_COMMAND_TRACE && hfsCommandTraceOn) {
1403: int pc = MainMemory.mmrGetLevelZeroPC ();
1404: System.out.println (LabeledAddress.lblSearch (new StringBuilder (), pc).toString ());
1405: System.out.printf ("%08x mkdir(name=\"%s\")\n",
1406: pc, hfuTargetName1);
1407: }
1408: if (!abuInserted) {
1409: hfsRequest3Error = DEV_RETRY | DEV_ABORT | DEV_INSERT_MEDIA;
1410: hfsRequest18Result = -1;
1411: hfsState = HFS_STATE_DONE;
1412: return;
1413: }
1414: if (abuWriteProtected) {
1415: hfsRequest3Error = DEV_IGNORE | DEV_RETRY | DEV_ABORT | DEV_CANNOT_WRITE;
1416: hfsRequest18Result = -1;
1417: hfsState = HFS_STATE_DONE;
1418: return;
1419: }
1420: hfsRequest18Result = 0;
1421: hfsState = HFS_STATE_HOST;
1422: }
1423:
1424:
1425: public void hfuCallMkdirHost () {
1426: try {
1427: File file1 = new File (hfuTargetName1);
1428: hfsRequest18Result = (!file1.mkdir () ? DOS_DIRECTORY_EXISTS :
1429: 0);
1430: } catch (Exception e) {
1431: hfsRequest18Result = DOS_CANNOT_WRITE;
1432: }
1433: hfsState = HFS_STATE_DONE;
1434: }
1435:
1436:
1437:
1438:
1439:
1440:
1441:
1442:
1443:
1444:
1445:
1446:
1447:
1448:
1449:
1450:
1451: public void hfuCallRmdir () throws M68kException {
1452: hfuTargetName1 = hfuNamestsToPath (hfsRequest14Namests);
1453: if (hfuTargetName1 == null) {
1454: hfsRequest18Result = DOS_ILLEGAL_FILE_NAME;
1455: hfsState = HFS_STATE_DONE;
1456: return;
1457: }
1458: if (HFS_COMMAND_TRACE && hfsCommandTraceOn) {
1459: int pc = MainMemory.mmrGetLevelZeroPC ();
1460: System.out.println (LabeledAddress.lblSearch (new StringBuilder (), pc).toString ());
1461: System.out.printf ("%08x rmdir(name=\"%s\")\n",
1462: pc, hfuTargetName1);
1463: }
1464: if (!abuInserted) {
1465: hfsRequest3Error = DEV_RETRY | DEV_ABORT | DEV_INSERT_MEDIA;
1466: hfsRequest18Result = -1;
1467: hfsState = HFS_STATE_DONE;
1468: return;
1469: }
1470: if (abuWriteProtected) {
1471: hfsRequest3Error = DEV_IGNORE | DEV_RETRY | DEV_ABORT | DEV_CANNOT_WRITE;
1472: hfsRequest18Result = -1;
1473: hfsState = HFS_STATE_DONE;
1474: return;
1475: }
1476: hfsRequest18Result = 0;
1477: hfsState = HFS_STATE_HOST;
1478: }
1479:
1480:
1481: public void hfuCallRmdirHost () {
1482: try {
1483: File file1 = new File (hfuTargetName1);
1484: hfsRequest18Result = (!file1.isDirectory () ? DOS_DIRECTORY_NOT_FOUND :
1485: !file1.canWrite () ? DOS_CANNOT_WRITE :
1486: !file1.delete () ? DOS_RM_NONEMPTY_DIRECTORY :
1487: 0);
1488: } catch (Exception e) {
1489: hfsRequest18Result = DOS_CANNOT_WRITE;
1490: }
1491: hfsState = HFS_STATE_DONE;
1492: }
1493:
1494:
1495:
1496:
1497:
1498:
1499:
1500:
1501:
1502:
1503:
1504:
1505:
1506:
1507:
1508:
1509:
1510: public void hfuCallRename () throws M68kException {
1511: hfuTargetName1 = hfuNamestsToPath (hfsRequest14Namests);
1512: if (hfuTargetName1 == null) {
1513: hfsRequest18Result = DOS_ILLEGAL_FILE_NAME;
1514: hfsState = HFS_STATE_DONE;
1515: return;
1516: }
1517: hfuTargetName2 = hfuNamestsToPath (hfsRequest18Param);
1518: if (hfuTargetName2 == null) {
1519: hfsRequest18Result = DOS_ILLEGAL_FILE_NAME;
1520: hfsState = HFS_STATE_DONE;
1521: return;
1522: }
1523: if (HFS_COMMAND_TRACE && hfsCommandTraceOn) {
1524: int pc = MainMemory.mmrGetLevelZeroPC ();
1525: System.out.println (LabeledAddress.lblSearch (new StringBuilder (), pc).toString ());
1526: System.out.printf ("%08x rename(from=\"%s\",to=\"%s\")\n",
1527: pc, hfuTargetName1, hfuTargetName2);
1528: }
1529: if (!abuInserted) {
1530: hfsRequest3Error = DEV_RETRY | DEV_ABORT | DEV_INSERT_MEDIA;
1531: hfsRequest18Result = -1;
1532: hfsState = HFS_STATE_DONE;
1533: return;
1534: }
1535: if (abuWriteProtected) {
1536: hfsRequest3Error = DEV_IGNORE | DEV_RETRY | DEV_ABORT | DEV_CANNOT_WRITE;
1537: hfsRequest18Result = -1;
1538: hfsState = HFS_STATE_DONE;
1539: return;
1540: }
1541: hfsRequest18Result = 0;
1542: hfsState = HFS_STATE_HOST;
1543: }
1544:
1545:
1546: public void hfuCallRenameHost () {
1547: try {
1548: File file1 = new File (hfuTargetName1);
1549: File file2 = new File (hfuTargetName2);
1550: hfsRequest18Result = (!file1.exists () ? DOS_FILE_NOT_FOUND :
1551: !file1.renameTo (file2) ? file1.isFile () ? DOS_CANNOT_WRITE : DOS_MV_NONEMPTY_DIRECTORY :
1552: 0);
1553: } catch (Exception e) {
1554: hfsRequest18Result = DOS_CANNOT_WRITE;
1555: }
1556: hfsState = HFS_STATE_DONE;
1557: }
1558:
1559:
1560:
1561:
1562:
1563:
1564:
1565:
1566:
1567:
1568:
1569:
1570:
1571:
1572:
1573: public void hfuCallDelete () throws M68kException {
1574: hfuTargetName1 = hfuNamestsToPath (hfsRequest14Namests);
1575: if (hfuTargetName1 == null) {
1576: hfsRequest18Result = DOS_ILLEGAL_FILE_NAME;
1577: hfsState = HFS_STATE_DONE;
1578: return;
1579: }
1580: if (HFS_COMMAND_TRACE && hfsCommandTraceOn) {
1581: int pc = MainMemory.mmrGetLevelZeroPC ();
1582: System.out.println (LabeledAddress.lblSearch (new StringBuilder (), pc).toString ());
1583: System.out.printf ("%08x delete(name=\"%s\")\n",
1584: pc, hfuTargetName1);
1585: }
1586: if (!abuInserted) {
1587: hfsRequest3Error = DEV_RETRY | DEV_ABORT | DEV_INSERT_MEDIA;
1588: hfsRequest18Result = -1;
1589: hfsState = HFS_STATE_DONE;
1590: return;
1591: }
1592: if (abuWriteProtected) {
1593: hfsRequest3Error = DEV_IGNORE | DEV_RETRY | DEV_ABORT | DEV_CANNOT_WRITE;
1594: hfsRequest18Result = -1;
1595: hfsState = HFS_STATE_DONE;
1596: return;
1597: }
1598: hfsRequest18Result = 0;
1599: hfsState = HFS_STATE_HOST;
1600: }
1601:
1602:
1603: public void hfuCallDeleteHost () {
1604: try {
1605: File file1 = new File (hfuTargetName1);
1606: hfsRequest18Result = (!file1.isFile () ? DOS_FILE_NOT_FOUND :
1607: !file1.canWrite () ? DOS_CANNOT_WRITE :
1608: !file1.delete () ? DOS_CANNOT_WRITE :
1609: 0);
1610: } catch (Exception e) {
1611: hfsRequest18Result = DOS_CANNOT_WRITE;
1612: }
1613: hfsState = HFS_STATE_DONE;
1614: }
1615:
1616:
1617:
1618:
1619:
1620:
1621:
1622:
1623:
1624:
1625:
1626:
1627:
1628:
1629:
1630: public void hfuCallChmod () throws M68kException {
1631: hfuTargetName1 = hfuNamestsToPath (hfsRequest14Namests);
1632: if (hfuTargetName1 == null) {
1633: hfsRequest18Result = DOS_ILLEGAL_FILE_NAME;
1634: hfsState = HFS_STATE_DONE;
1635: return;
1636: }
1637: if (HFS_COMMAND_TRACE && hfsCommandTraceOn) {
1638: int pc = MainMemory.mmrGetLevelZeroPC ();
1639: System.out.println (LabeledAddress.lblSearch (new StringBuilder (), pc).toString ());
1640: System.out.printf ("%08x chmod(name=\"%s\",mode=0x%02x)\n",
1641: pc, hfuTargetName1, hfsRequest13Mode);
1642: }
1643: if (!abuInserted) {
1644: hfsRequest3Error = DEV_RETRY | DEV_ABORT | DEV_INSERT_MEDIA;
1645: hfsRequest18Result = -1;
1646: hfsState = HFS_STATE_DONE;
1647: return;
1648: }
1649: if (hfsRequest13Mode != 255 && abuWriteProtected) {
1650: hfsRequest3Error = DEV_IGNORE | DEV_RETRY | DEV_ABORT | DEV_CANNOT_WRITE;
1651: hfsRequest18Result = -1;
1652: hfsState = HFS_STATE_DONE;
1653: return;
1654: }
1655: hfsRequest18Result = 0;
1656: hfsState = HFS_STATE_HOST;
1657: }
1658:
1659:
1660: public void hfuCallChmodHost () {
1661: File file1 = new File (hfuTargetName1);
1662: if (!file1.exists ()) {
1663: hfsRequest18Result = DOS_FILE_NOT_FOUND;
1664: } else if (hfsRequest13Mode == 255) {
1665: hfsRequest18Result = ((file1.isFile () ? HumanMedia.HUM_ARCHIVE : 0) |
1666: (file1.isDirectory () ? HumanMedia.HUM_DIRECTORY : 0) |
1667: (file1.isHidden () ? HumanMedia.HUM_HIDDEN : 0) |
1668: (!file1.canWrite () ? HumanMedia.HUM_READONLY : 0));
1669: } else {
1670: hfsRequest18Result = 0;
1671: boolean oldReadonly = !file1.canWrite ();
1672: boolean newReadonly = (hfsRequest13Mode & HumanMedia.HUM_READONLY) != 0;
1673: if (oldReadonly != newReadonly) {
1674: try {
1675: if (!file1.setWritable (!newReadonly)) {
1676: hfsRequest18Result = DOS_CANNOT_WRITE;
1677: }
1678: } catch (Exception e) {
1679: hfsRequest18Result = DOS_CANNOT_WRITE;
1680: }
1681: }
1682: if (false) {
1683: boolean oldHidden = file1.isHidden ();
1684: boolean newHidden = (hfsRequest13Mode & HumanMedia.HUM_HIDDEN) != 0;
1685: if (oldHidden != newHidden) {
1686: hfsRequest18Result = DOS_CANNOT_WRITE;
1687: }
1688: if ((hfsRequest13Mode & HumanMedia.HUM_VOLUME) != 0) {
1689: hfsRequest18Result = DOS_CANNOT_WRITE;
1690: }
1691: }
1692: }
1693: hfsState = HFS_STATE_DONE;
1694: }
1695:
1696:
1697:
1698:
1699:
1700:
1701:
1702:
1703:
1704:
1705:
1706:
1707:
1708:
1709:
1710:
1711:
1712:
1713:
1714:
1715:
1716:
1717:
1718:
1719:
1720:
1721:
1722:
1723:
1724:
1725:
1726:
1727:
1728:
1729:
1730:
1731:
1732:
1733:
1734:
1735:
1736:
1737:
1738:
1739:
1740:
1741:
1742:
1743:
1744:
1745:
1746:
1747: public void hfuCallFiles () throws M68kException {
1748:
1749: byte[] w = hfuTargetNameArray1;
1750: MC68060.mmuReadByteArray (hfsRequest14Namests, w, 0, 88, XEiJ.regSRS);
1751: String dirName = hfuTargetName1 = hfuNamestsToPath (w, false);
1752: if (hfuTargetName1 == null) {
1753: hfsRequest18Result = DOS_ILLEGAL_FILE_NAME;
1754: hfsState = HFS_STATE_DONE;
1755: return;
1756: }
1757: if (HFS_COMMAND_TRACE && hfsCommandTraceOn) {
1758: int pc = MainMemory.mmrGetLevelZeroPC ();
1759: System.out.println (LabeledAddress.lblSearch (new StringBuilder (), pc).toString ());
1760: System.out.printf ("%08x files(name=\"%s\",mode=0x%02x)\n",
1761: pc, dirName, hfsRequest13Mode);
1762: }
1763: if (!abuInserted) {
1764: hfsRequest3Error = DEV_RETRY | DEV_ABORT | DEV_INSERT_MEDIA;
1765: hfsRequest18Result = -1;
1766: hfsState = HFS_STATE_DONE;
1767: return;
1768: }
1769: hfsRequest18Result = 0;
1770: hfsState = HFS_STATE_HOST;
1771: }
1772:
1773:
1774: public void hfuCallFilesHost () {
1775: byte[] w = hfuTargetNameArray1;
1776: String dirName = hfuTargetName1;
1777: File parent = new File (dirName);
1778:
1779: String[] children = parent.list ();
1780: if (children == null) {
1781: hfsRequest18Result = DOS_DIRECTORY_NOT_FOUND;
1782: hfsState = HFS_STATE_DONE;
1783: return;
1784: }
1785:
1786:
1787:
1788:
1789:
1790:
1791:
1792:
1793:
1794:
1795:
1796:
1797:
1798:
1799: for (int i = 21; i <= 28; i++) {
1800: w[i] = w[67 - 21 + i];
1801: }
1802: if (w[74] == '?' && w[78] == '\0') {
1803: for (int i = 29; i <= 38; i++) {
1804: w[i] = '?';
1805: }
1806: } else {
1807: for (int i = 29; i <= 38; i++) {
1808: w[i] = w[78 - 29 + i];
1809: }
1810: }
1811: for (int i = 38; i >= 21 && (w[i] == '\0' || w[i] == ' '); i--) {
1812: w[i] = '\0';
1813: }
1814: for (int i = 39; i <= 41; i++) {
1815: w[i] = w[75 - 39 + i];
1816: }
1817: for (int i = 41; i >= 39 && (w[i] == '\0' || w[i] == ' '); i--) {
1818: w[i] = '\0';
1819: }
1820:
1821: for (int i = 21; i <= 41; i++) {
1822: int c = w[i] & 255;
1823: if ('A' <= c && c <= 'Z') {
1824: w[i] = (byte) (c | 0x20);
1825: } else if (0x81 <= c && c <= 0x9f || 0xe0 <= c && c <= 0xef) {
1826: i++;
1827: }
1828: }
1829:
1830: boolean isRoot = dirName.equals (hfuRootPath);
1831: boolean humansysRequired = isRoot;
1832: boolean commandxRequired = isRoot;
1833: ArrayDeque<byte[]> deque = new ArrayDeque<byte[]> ();
1834: if (isRoot) {
1835: if ((hfsRequest13Mode & HumanMedia.HUM_VOLUME) != 0 &&
1836: w[21] == '?' && w[39] == '?') {
1837:
1838: int l = dirName.length ();
1839: while (2 <= l &&
1840: (dirName.charAt (l - 1) == '/' ||
1841: dirName.charAt (l - 1) == '\\' ||
1842: (dirName.charAt (l - 1) == '.' &&
1843: (dirName.charAt (l - 2) == '/' ||
1844: dirName.charAt (l - 2) == '\\')))) {
1845: l--;
1846: }
1847: byte[] b = new byte[32];
1848:
1849:
1850:
1851:
1852:
1853: hfuFileInfo (parent, b);
1854: b[0] = HumanMedia.HUM_VOLUME;
1855: b[5] = b[6] = b[7] = b[8] = 0;
1856: int k = 9;
1857: for (int i = 0; i < l; i++) {
1858: int c = CharacterCode.chrCharToSJIS[dirName.charAt (i)];
1859: if (c < 0x0100) {
1860: if (9 + 21 < k + 1) {
1861: k = 0;
1862: break;
1863: }
1864: b[k++] = (byte) c;
1865: } else {
1866: if (9 + 21 < k + 2) {
1867: k = 0;
1868: break;
1869: }
1870: b[k++] = (byte) (c >> 8);
1871: b[k++] = (byte) c;
1872: }
1873: }
1874: if (k == 0) {
1875: k = 9;
1876:
1877: for (int i = 0; i < l; i++) {
1878: int c = CharacterCode.chrCharToSJIS[dirName.charAt (i)];
1879: if (c < 0x0100) {
1880: if (9 + 5 < k + 1) {
1881: break;
1882: }
1883: b[k++] = (byte) c;
1884: } else {
1885: if (9 + 5 < k + 2) {
1886: break;
1887: }
1888: b[k++] = (byte) (c >> 8);
1889: b[k++] = (byte) c;
1890: }
1891: }
1892:
1893: b[k++] = (byte) '_';
1894:
1895: int j = 9 + 21;
1896: for (int i = l - 1; 0 <= i; i--) {
1897: int c = CharacterCode.chrCharToSJIS[dirName.charAt (i)];
1898: if (c < 0x0100) {
1899: if (j - 1 < k) {
1900: break;
1901: }
1902: b[--j] = (byte) c;
1903: } else {
1904: if (j - 2 < k) {
1905: break;
1906: }
1907: b[--j] = (byte) c;
1908: b[--j] = (byte) (c >> 8);
1909: }
1910: }
1911: if (k < j) {
1912: while (j < 9 + 21) {
1913: b[k++] = b[j++];
1914: }
1915: } else {
1916: k = 9 + 21;
1917: }
1918: }
1919: for (int i = k; i <= 31; i++) {
1920: b[i] = '\0';
1921: }
1922: if (b[27] != '\0') {
1923: b[30] = b[29];
1924: b[29] = b[28];
1925: b[28] = b[27];
1926: b[27] = (byte) '.';
1927: }
1928: if (HFS_DEBUG_FILE_INFO) {
1929: System.out.print ("FILES ");
1930: hfuPrintFileInfo (b);
1931: }
1932:
1933: deque.addLast (b);
1934: }
1935: }
1936: childrenLoop:
1937: for (String childName : children) {
1938: int l = childName.length ();
1939: if (l == 0) {
1940: continue childrenLoop;
1941: }
1942:
1943: boolean isHumansys = false;
1944: boolean isCommandx = false;
1945: if (isRoot) {
1946: if (childName.equals (".") || childName.equals ("..")) {
1947: continue childrenLoop;
1948: }
1949: isHumansys = childName.equalsIgnoreCase ("HUMAN.SYS");
1950: if (isHumansys) {
1951: humansysRequired = false;
1952: }
1953: isCommandx = childName.equalsIgnoreCase ("COMMAND.X");
1954: if (isCommandx) {
1955: commandxRequired = false;
1956: }
1957: }
1958:
1959:
1960:
1961:
1962:
1963: byte[] b = new byte[32];
1964:
1965:
1966:
1967:
1968:
1969: int k = 9;
1970: for (int i = 0; i < l; i++) {
1971: int c = CharacterCode.chrCharToSJIS[childName.charAt (i)];
1972: if (c <= 0x1f ||
1973: c == '/' || c == '\\' ||
1974: (c == '-' && i == 0) ||
1975: c == '"' || c == '\'' ||
1976:
1977: c == ',' ||
1978: c == ';' || c == '<' || c == '=' || c == '>' ||
1979: c == '[' || c == ']' ||
1980: c == '|') {
1981: continue childrenLoop;
1982: }
1983: if (c < 0x0100) {
1984: if (k >= 31) {
1985: continue childrenLoop;
1986: }
1987: b[k++] = (byte) c;
1988: } else {
1989: if (k >= 30) {
1990: continue childrenLoop;
1991: }
1992: b[k++] = (byte) (c >> 8);
1993: b[k++] = (byte) c;
1994: }
1995: }
1996: for (int i = k; i <= 31; i++) {
1997: b[i] = '\0';
1998: }
1999:
2000:
2001:
2002:
2003:
2004:
2005:
2006:
2007: int m = (b[k - 1] == '.' ? k :
2008: k >= 9 + 3 && b[k - 2] == '.' ? k - 2 :
2009: k >= 9 + 4 && b[k - 3] == '.' ? k - 3 :
2010: k >= 9 + 5 && b[k - 4] == '.' ? k - 4 :
2011: k);
2012: if (m > 9 + 18) {
2013: continue childrenLoop;
2014: }
2015: {
2016: int i = 0;
2017: for (int j = 9; j < m; j++) {
2018: w[i++] = b[j];
2019: }
2020: while (i <= 17) {
2021: w[i++] = '\0';
2022: }
2023: for (int j = m + 1; j < k; j++) {
2024: w[i++] = b[j];
2025: }
2026: while (i <= 20) {
2027: w[i++] = '\0';
2028: }
2029: }
2030:
2031:
2032:
2033:
2034:
2035:
2036:
2037:
2038:
2039:
2040:
2041: {
2042: int f = 0x20;
2043: for (int i = 0; i <= 20; i++) {
2044: int c = w[i] & 255;
2045: int d = w[21 + i] & 255;
2046: if (d != '?' && ('A' <= c && c <= 'Z' ? c | f : c) != d) {
2047: continue childrenLoop;
2048: }
2049: f = f != 0x00 && (0x81 <= c && c <= 0x9f || 0xe0 <= c && c <= 0xef) ? 0x00 : 0x20;
2050: }
2051: }
2052:
2053: File file = new File (parent, childName);
2054: if (0xffffffffL < file.length ()) {
2055: continue childrenLoop;
2056: }
2057: hfuFileInfo (file, b);
2058: if (isHumansys) {
2059: b[0] |= HumanMedia.HUM_SYSTEM;
2060: }
2061: if (HFS_DEBUG_FILE_INFO) {
2062: System.out.print ("FILES ");
2063: hfuPrintFileInfo (b);
2064: }
2065: if ((b[0] & hfsRequest13Mode) == 0) {
2066: continue childrenLoop;
2067: }
2068:
2069: deque.addLast (b);
2070: }
2071: if (false) {
2072: if (isRoot) {
2073: if (humansysRequired) {
2074:
2075: }
2076: if (commandxRequired) {
2077:
2078: }
2079: }
2080: }
2081: if (deque.isEmpty ()) {
2082: hfsRequest18Result = DOS_FILE_NOT_FOUND;
2083: hfsState = HFS_STATE_DONE;
2084: return;
2085: }
2086: hfuFilesBufferCounter++;
2087: hfuFilesBufferToArrayDeque.put (hfuFilesBufferCounter, deque);
2088: hfsRequest18Result = 0;
2089: hfsState = HFS_STATE_X68K;
2090: }
2091:
2092:
2093: public void hfuCallFilesX68k () throws M68kException {
2094: MC68060.mmuWriteLongData (hfsRequest18Param + 2, HFU_FILES_MAGIC, XEiJ.regSRS);
2095: MC68060.mmuWriteLongData (hfsRequest18Param + 6, hfuFilesBufferCounter, XEiJ.regSRS);
2096:
2097:
2098: int key = hfuFilesBufferCounter;
2099: ArrayDeque<byte[]> deque = hfuFilesBufferToArrayDeque.get (key);
2100: if (deque == null) {
2101: hfsRequest18Result = DOS_NO_MORE_FILES;
2102: hfsState = HFS_STATE_DONE;
2103: return;
2104: }
2105: byte[] b = deque.pollFirst ();
2106: MC68060.mmuWriteByteArray (hfsRequest18Param + 21, b, 0, 32, XEiJ.regSRS);
2107: if (deque.isEmpty ()) {
2108: MC68060.mmuWriteLongData (hfsRequest18Param + 2, 0, XEiJ.regSRS);
2109: MC68060.mmuWriteLongData (hfsRequest18Param + 6, 0, XEiJ.regSRS);
2110: hfuFilesBufferToArrayDeque.remove (key);
2111: }
2112: hfsRequest18Result = 0;
2113: hfsState = HFS_STATE_DONE;
2114: }
2115:
2116:
2117:
2118:
2119:
2120:
2121:
2122:
2123:
2124:
2125:
2126:
2127:
2128:
2129:
2130: public void hfuCallNfiles () throws M68kException {
2131: if (HFS_COMMAND_TRACE && hfsCommandTraceOn) {
2132: int pc = MainMemory.mmrGetLevelZeroPC ();
2133: System.out.println (LabeledAddress.lblSearch (new StringBuilder (), pc).toString ());
2134: System.out.printf ("%08x nfiles()\n",
2135: pc);
2136: }
2137: if (!abuInserted) {
2138: hfsRequest3Error = DEV_RETRY | DEV_ABORT | DEV_INSERT_MEDIA;
2139: hfsRequest18Result = -1;
2140: hfsState = HFS_STATE_DONE;
2141: return;
2142: }
2143: if (MC68060.mmuReadLongData (hfsRequest18Param + 2, XEiJ.regSRS) != HFU_FILES_MAGIC) {
2144: hfsRequest18Result = DOS_NO_MORE_FILES;
2145: hfsState = HFS_STATE_DONE;
2146: return;
2147: }
2148: int key = MC68060.mmuReadLongData (hfsRequest18Param + 6, XEiJ.regSRS);
2149: ArrayDeque<byte[]> deque = hfuFilesBufferToArrayDeque.get (key);
2150: if (deque == null) {
2151: hfsRequest18Result = DOS_NO_MORE_FILES;
2152: hfsState = HFS_STATE_DONE;
2153: return;
2154: }
2155: byte[] b = deque.pollFirst ();
2156: MC68060.mmuWriteByteArray (hfsRequest18Param + 21, b, 0, 32, XEiJ.regSRS);
2157: if (deque.isEmpty ()) {
2158: MC68060.mmuWriteLongData (hfsRequest18Param + 2, 0, XEiJ.regSRS);
2159: MC68060.mmuWriteLongData (hfsRequest18Param + 6, 0, XEiJ.regSRS);
2160: hfuFilesBufferToArrayDeque.remove (key);
2161: }
2162: hfsRequest18Result = 0;
2163: hfsState = HFS_STATE_DONE;
2164: }
2165:
2166:
2167:
2168:
2169:
2170:
2171:
2172:
2173:
2174:
2175:
2176:
2177:
2178:
2179:
2180:
2181:
2182:
2183: public void hfuCallCreateNewfile () throws M68kException {
2184: byte[] w = hfuTargetNameArray1;
2185: MC68060.mmuReadByteArray (hfsRequest14Namests, w, 0, 88, XEiJ.regSRS);
2186: hfuTargetName1 = hfuNamestsToPath (w, true);
2187: if (hfuTargetName1 == null) {
2188: hfsRequest18Result = DOS_ILLEGAL_FILE_NAME;
2189: hfsState = HFS_STATE_DONE;
2190: return;
2191: }
2192: if (HFS_COMMAND_TRACE && hfsCommandTraceOn) {
2193: int pc = MainMemory.mmrGetLevelZeroPC ();
2194: System.out.println (LabeledAddress.lblSearch (new StringBuilder (), pc).toString ());
2195: System.out.printf ("%08x %s(fcb=0x%08x,name=\"%s\",mode=0x%02x)\n",
2196: pc, hfsRequest18Param == 0 ? "newfile" : "create", hfsRequest22Fcb, hfuTargetName1, hfsRequest13Mode);
2197: }
2198: if (!abuInserted) {
2199: hfsRequest3Error = DEV_RETRY | DEV_ABORT | DEV_INSERT_MEDIA;
2200: hfsRequest18Result = -1;
2201: hfsState = HFS_STATE_DONE;
2202: return;
2203: }
2204: if (abuWriteProtected) {
2205: hfsRequest3Error = DEV_IGNORE | DEV_RETRY | DEV_ABORT | DEV_CANNOT_WRITE;
2206: hfsRequest18Result = -1;
2207: hfsState = HFS_STATE_DONE;
2208: return;
2209: }
2210: hfsRequest18Result = 0;
2211: hfsState = HFS_STATE_HOST;
2212: }
2213:
2214:
2215: public void hfuCallCreateNewfileHost () {
2216: byte[] b = hfuTargetNameArray2;
2217: File file = new File (hfuTargetName1);
2218: if (file.exists ()) {
2219: if (hfsRequest18Param == 0) {
2220: hfsRequest18Result = DOS_FILE_EXISTS;
2221: hfsState = HFS_STATE_DONE;
2222: return;
2223: }
2224:
2225:
2226:
2227: if (file.isDirectory () ||
2228: !file.delete ()) {
2229: hfsRequest18Result = DOS_CANNOT_WRITE;
2230: hfsState = HFS_STATE_DONE;
2231: return;
2232: }
2233: }
2234: RandomAccessFile raf;
2235: try {
2236: raf = new RandomAccessFile (file, "rw");
2237: } catch (IOException ioe) {
2238: hfsRequest18Result = DOS_CANNOT_WRITE;
2239: hfsState = HFS_STATE_DONE;
2240: return;
2241: }
2242: if (hfuFcbToHandle.isEmpty ()) {
2243: prevent ();
2244: }
2245: hfuFileInfo (file, b);
2246: if (HFS_DEBUG_FILE_INFO) {
2247: System.out.print ("CREATE ");
2248: hfuPrintFileInfo (b);
2249: }
2250: int fcb = hfsRequest22Fcb;
2251: HFHandle handle = hfuTargetHandle = hfuNewHandle (fcb, file, raf);
2252: hfuFcbToHandle.put (fcb, handle);
2253: hfsRequest18Result = 0;
2254: hfsState = HFS_STATE_X68K;
2255: }
2256:
2257:
2258: public void hfuCallCreateNewfileX68k () throws M68kException {
2259: HFHandle handle = hfuTargetHandle;
2260: int fcb = handle.hfhFcb;
2261: byte[] w = hfuTargetNameArray1;
2262: byte[] b = hfuTargetNameArray2;
2263:
2264:
2265:
2266:
2267:
2268:
2269:
2270:
2271:
2272:
2273:
2274:
2275:
2276:
2277:
2278:
2279:
2280:
2281: for (int i = 0; i < 8 + 3; i++) {
2282: MC68060.mmuWriteByteData (fcb + 36 + i, w[67 + i], XEiJ.regSRS);
2283: }
2284: MC68060.mmuWriteByteData (fcb + 47, b[0], XEiJ.regSRS);
2285: for (int i = 0; i < 10; i++) {
2286: MC68060.mmuWriteByteData (fcb + 48 + i, w[78 + i], XEiJ.regSRS);
2287: }
2288: MC68060.mmuWriteLongData (fcb + 58, ByteArray.byaRls (b, 1), XEiJ.regSRS);
2289: MC68060.mmuWriteWordData (fcb + 62, 0, XEiJ.regSRS);
2290: MC68060.mmuWriteLongData (fcb + 64, ByteArray.byaRls (b, 5), XEiJ.regSRS);
2291: hfsRequest18Result = 0;
2292: hfsState = HFS_STATE_DONE;
2293: }
2294:
2295:
2296:
2297:
2298:
2299:
2300:
2301:
2302:
2303:
2304:
2305:
2306:
2307:
2308:
2309: public void hfuCallOpen () throws M68kException {
2310: byte[] w = hfuTargetNameArray1;
2311: MC68060.mmuReadByteArray (hfsRequest14Namests, w, 0, 88, XEiJ.regSRS);
2312: hfuTargetName1 = hfuNamestsToPath (w, true);
2313: if (hfuTargetName1 == null) {
2314: hfsRequest18Result = DOS_ILLEGAL_FILE_NAME;
2315: hfsState = HFS_STATE_DONE;
2316: return;
2317: }
2318: int fcb = hfsRequest22Fcb;
2319: hfuTargetOpenMode = MC68060.mmuReadByteZeroData (fcb + 14, XEiJ.regSRS);
2320: if (HFS_COMMAND_TRACE && hfsCommandTraceOn) {
2321: int pc = MainMemory.mmrGetLevelZeroPC ();
2322: System.out.println (LabeledAddress.lblSearch (new StringBuilder (), pc).toString ());
2323: System.out.printf ("%08x open(fcb=0x%08x,name=\"%s\",mode=0x%02x)\n",
2324: pc, hfsRequest22Fcb, hfuTargetName1, hfuTargetOpenMode);
2325: }
2326: if (!abuInserted) {
2327: hfsRequest3Error = DEV_RETRY | DEV_ABORT | DEV_INSERT_MEDIA;
2328: hfsRequest18Result = -1;
2329: hfsState = HFS_STATE_DONE;
2330: return;
2331: }
2332: if (hfuTargetOpenMode != 0 && abuWriteProtected) {
2333: hfsRequest3Error = DEV_IGNORE | DEV_RETRY | DEV_ABORT | DEV_CANNOT_WRITE;
2334: hfsRequest18Result = -1;
2335: hfsState = HFS_STATE_DONE;
2336: return;
2337: }
2338: hfsRequest18Result = 0;
2339: hfsState = HFS_STATE_HOST;
2340: }
2341:
2342:
2343: public void hfuCallOpenHost () {
2344: byte[] b = hfuTargetNameArray2;
2345: File file = new File (hfuTargetName1);
2346:
2347:
2348:
2349:
2350: if (!file.exists ()) {
2351: hfsRequest18Result = DOS_FILE_NOT_FOUND;
2352: hfsState = HFS_STATE_DONE;
2353: return;
2354: }
2355: if (0xffffffffL < file.length ()) {
2356: hfsRequest18Result = DOS_FILE_NOT_FOUND;
2357: hfsState = HFS_STATE_DONE;
2358: return;
2359: }
2360: hfuFileInfo (file, b);
2361: if (HFS_DEBUG_FILE_INFO) {
2362: System.out.print ("OPEN ");
2363: hfuPrintFileInfo (b);
2364: }
2365: RandomAccessFile raf;
2366: try {
2367: raf = new RandomAccessFile (file, hfuTargetOpenMode == 0 ? "r" : "rw");
2368: if (HFS_UTF8_WARNING &&
2369: hfsUTF8WarningOn &&
2370: !hfsUTF8WarningSet.contains (hfuTargetName1)) {
2371: hfsUTF8WarningSet.add (hfuTargetName1);
2372:
2373: int ll = (int) Math.min (4096, file.length ());
2374: byte[] bb = new byte[ll];
2375: int kk = 0;
2376: while (kk < ll) {
2377: int tt = raf.read (bb, kk, ll - kk);
2378: if (tt < 0) {
2379: break;
2380: }
2381: kk += tt;
2382: }
2383: raf.seek (0);
2384: if (!hfuUTF8WarningTest (bb, kk)) {
2385: System.out.println ("The character encoding of " + hfuTargetName1 + " is UTF-8, not SJIS.");
2386: }
2387: }
2388: } catch (IOException ioe) {
2389: hfsRequest18Result = DOS_FILE_NOT_FOUND;
2390: hfsState = HFS_STATE_DONE;
2391: return;
2392: }
2393: if (hfuFcbToHandle.isEmpty ()) {
2394: prevent ();
2395: }
2396: int fcb = hfsRequest22Fcb;
2397: HFHandle handle = hfuTargetHandle = hfuNewHandle (fcb, file, raf);
2398: hfuFcbToHandle.put (fcb, handle);
2399: hfsRequest18Result = 0;
2400: hfsState = HFS_STATE_X68K;
2401: }
2402:
2403:
2404:
2405: private static boolean hfuUTF8WarningTest (byte[] b, int k) {
2406:
2407:
2408:
2409:
2410:
2411: for (int i = 0; i < k; i++) {
2412: int c = b[i] & 0xff;
2413: if (c <= 0x7f) {
2414: if (c != 0x00) {
2415: continue;
2416: }
2417: } else if (c <= 0xbf) {
2418: } else if (c <= 0xdf) {
2419: int d = i + 1 < k ? b[i + 1] & 0xff : -1;
2420: if (d == -1 || (0x80 <= d && d <= 0xbf)) {
2421: i++;
2422: continue;
2423: }
2424: } else if (c <= 0xef) {
2425: int d = i + 1 < k ? b[i + 1] & 0xff : -1;
2426: int e = i + 2 < k ? b[i + 2] & 0xff : -1;
2427: if ((d == -1 || (0x80 <= d && d <= 0xbf)) &&
2428: (e == -1 || (0x80 <= e && e <= 0xbf))) {
2429: i += 2;
2430: continue;
2431: }
2432: } else if (c <= 0xf7) {
2433: int d = i + 1 < k ? b[i + 1] & 0xff : -1;
2434: int e = i + 2 < k ? b[i + 2] & 0xff : -1;
2435: int f = i + 3 < k ? b[i + 3] & 0xff : -1;
2436: if ((d == -1 || (0x80 <= d && d <= 0xbf)) &&
2437: (e == -1 || (0x80 <= e && e <= 0xbf)) &&
2438: (f == -1 || (0x80 <= f && f <= 0xbf))) {
2439: i += 3;
2440: continue;
2441: }
2442: } else {
2443: }
2444: return true;
2445: }
2446:
2447:
2448:
2449:
2450:
2451: for (int i = 0; i < k; i++) {
2452: int c = b[i] & 0xff;
2453: if ((0x00 <= c && c <= 0x7f) ||
2454: (0xa0 <= c && c <= 0xdf)) {
2455: if (c != 0x00) {
2456: continue;
2457: }
2458: } else if (c == 0x80 ||
2459: (0xf0 <= c && c <= 0xf5)) {
2460: if (k <= i + 1 || b[i + 1] != 0x00) {
2461: i++;
2462: continue;
2463: }
2464: } else if ((0x81 <= c && c <= 0x9f) ||
2465: (0xe0 <= c && c <= 0xef)) {
2466: int d = i + 1 < k ? b[i + 1] & 0xff : -1;
2467: if (d == -1 || (0x40 <= d && d <= 0xfc && d != 0x7f)) {
2468: i++;
2469: continue;
2470: }
2471: } else {
2472: }
2473: return false;
2474: }
2475: return true;
2476: }
2477:
2478:
2479: public void hfuCallOpenX68k () throws M68kException {
2480: HFHandle handle = hfuTargetHandle;
2481: int fcb = handle.hfhFcb;
2482: byte[] w = hfuTargetNameArray1;
2483: byte[] b = hfuTargetNameArray2;
2484:
2485:
2486:
2487:
2488:
2489:
2490:
2491:
2492:
2493:
2494:
2495:
2496:
2497:
2498:
2499:
2500:
2501:
2502: for (int i = 0; i < 8 + 3; i++) {
2503: MC68060.mmuWriteByteData (fcb + 36 + i, w[67 + i], XEiJ.regSRS);
2504: }
2505: MC68060.mmuWriteByteData (fcb + 47, b[0], XEiJ.regSRS);
2506: for (int i = 0; i < 10; i++) {
2507: MC68060.mmuWriteByteData (fcb + 48 + i, w[78 + i], XEiJ.regSRS);
2508: }
2509: MC68060.mmuWriteLongData (fcb + 58, ByteArray.byaRls (b, 1), XEiJ.regSRS);
2510: MC68060.mmuWriteWordData (fcb + 62, 0, XEiJ.regSRS);
2511: MC68060.mmuWriteLongData (fcb + 64, ByteArray.byaRls (b, 5), XEiJ.regSRS);
2512: hfsRequest18Result = 0;
2513: hfsState = HFS_STATE_DONE;
2514: }
2515:
2516:
2517:
2518:
2519:
2520:
2521:
2522:
2523:
2524:
2525:
2526:
2527:
2528:
2529:
2530: public void hfuCallClose () throws M68kException {
2531: if (HFS_COMMAND_TRACE && hfsCommandTraceOn) {
2532: int pc = MainMemory.mmrGetLevelZeroPC ();
2533: System.out.println (LabeledAddress.lblSearch (new StringBuilder (), pc).toString ());
2534: System.out.printf ("%08x close(fcb=0x%08x)\n",
2535: pc, hfsRequest22Fcb);
2536: }
2537: if (!abuInserted) {
2538: hfsRequest3Error = DEV_RETRY | DEV_ABORT | DEV_INSERT_MEDIA;
2539: hfsRequest18Result = -1;
2540: hfsState = HFS_STATE_DONE;
2541: return;
2542: }
2543: int fcb = hfsRequest22Fcb;
2544: HFHandle handle = hfuTargetHandle = hfuFcbToHandle.remove (fcb);
2545: if (handle == null) {
2546:
2547: hfsRequest18Result = 0;
2548: hfsState = HFS_STATE_DONE;
2549: return;
2550: }
2551: hfsRequest18Result = 0;
2552: hfsState = HFS_STATE_HOST;
2553: }
2554:
2555:
2556: public void hfuCallCloseHost () {
2557: HFHandle handle = hfuTargetHandle;
2558: if (hfsRequest18Result != 0) {
2559: File file = handle.hfhFile;
2560: if (!file.setLastModified (hfuTargetLastModified)) {
2561: System.out.println ((Multilingual.mlnJapanese ? "最終更新日時を設定できません: " : "Could not set last modified date and time: ") + handle.toString ());
2562: }
2563: if (hfuFcbToHandle.isEmpty ()) {
2564: allow ();
2565: }
2566: hfuRecycleHandle (handle);
2567: handle = hfuTargetHandle = null;
2568: hfsRequest18Result = 0;
2569: hfsState = HFS_STATE_DONE;
2570: return;
2571: }
2572: RandomAccessFile raf = handle.hfhRaf;
2573:
2574: if (handle.hfhDirty) {
2575: if (HFS_BUFFER_TRACE) {
2576: System.out.printf ("delaywrite(fcb=0x%08x,name=\"%s\",start=0x%08x,end=0x%08x)\n", handle.hfhFcb, handle.hfhFile.toString(), handle.hfhStart, handle.hfhEnd);
2577: }
2578: try {
2579: handle.hfhRaf.seek (handle.hfhStart);
2580: } catch (IOException ioe) {
2581: System.out.println ((Multilingual.mlnJapanese ? "シークエラー: " : "Seek error: ") + handle.toString ());
2582: }
2583: try {
2584: handle.hfhRaf.write (handle.hfhBuffer, 0, (int) (handle.hfhEnd - handle.hfhStart));
2585: } catch (IOException ioe) {
2586: System.out.println ((Multilingual.mlnJapanese ? "遅延書き込みに失敗しました: " : "Delayed write failed: ") + handle.toString ());
2587: }
2588: handle.hfhDirty = false;
2589: }
2590: try {
2591: raf.close ();
2592: } catch (IOException ioe) {
2593: System.out.println ((Multilingual.mlnJapanese ? "クローズエラー: " : "Close error: ") + handle.toString ());
2594: }
2595: hfsRequest18Result = 0;
2596: hfsState = HFS_STATE_X68K;
2597: }
2598:
2599:
2600: public void hfuCallCloseX68k () throws M68kException {
2601: HFHandle handle = hfuTargetHandle;
2602: int fcb = handle.hfhFcb;
2603: if ((MC68060.mmuReadByteZeroData (fcb + 14, XEiJ.regSRS) & 15) == 0) {
2604: if (hfuFcbToHandle.isEmpty ()) {
2605: allow ();
2606: }
2607: hfuRecycleHandle (handle);
2608: handle = hfuTargetHandle = null;
2609: hfsRequest18Result = 0;
2610: hfsState = HFS_STATE_DONE;
2611: return;
2612: }
2613: if ((MC68060.mmuReadByteZeroData (fcb + 1, XEiJ.regSRS) & 0x40) != 0) {
2614: hfuTargetLastModified = System.currentTimeMillis ();
2615: } else {
2616: int time = MC68060.mmuReadWordZeroData (fcb + 58, XEiJ.regSRS);
2617: int date = MC68060.mmuReadWordZeroData (fcb + 60, XEiJ.regSRS);
2618: hfuTargetLastModified = DnT.dntCmilYearMontMdayHourMinuSeco (
2619: (date >> 9) + 1980, date >> 5 & 15, date & 31,
2620: time >> 11, time >> 5 & 63, (time & 31) << 1) - RP5C15.rtcCmilGap;
2621: }
2622: hfsRequest18Result = 1;
2623: hfsState = HFS_STATE_HOST;
2624: }
2625:
2626:
2627:
2628:
2629:
2630:
2631:
2632:
2633:
2634:
2635:
2636:
2637:
2638:
2639:
2640: public void hfuCallRead () throws M68kException {
2641: if (HFS_BUFFER_TRACE || (HFS_COMMAND_TRACE && hfsCommandTraceOn)) {
2642: int pc = MainMemory.mmrGetLevelZeroPC ();
2643: System.out.println (LabeledAddress.lblSearch (new StringBuilder (), pc).toString ());
2644: System.out.printf ("%08x read(fcb=0x%08x,address=0x%08x,length=0x%08x)\n",
2645: pc, hfsRequest22Fcb, hfsRequest14Namests, hfsRequest18Param);
2646: }
2647: if (!abuInserted) {
2648: hfsRequest3Error = DEV_RETRY | DEV_ABORT | DEV_INSERT_MEDIA;
2649: hfsRequest18Result = -1;
2650: hfsState = HFS_STATE_DONE;
2651: return;
2652: }
2653: int fcb = hfsRequest22Fcb;
2654: HFHandle handle = hfuTargetHandle = hfuFcbToHandle.get (fcb);
2655: if (handle == null) {
2656: hfsRequest18Result = DOS_HANDLE_IS_NOT_OPENED;
2657: hfsState = HFS_STATE_DONE;
2658: return;
2659: }
2660: hfuTargetLength = hfsRequest18Param & 0xffffffffL;
2661: if (HFS_BUFFER_TRACE) {
2662: System.out.printf ("length=%d\n", hfuTargetLength);
2663: }
2664: hfuTargetPosition = MC68060.mmuReadLongData (fcb + 6, XEiJ.regSRS) & 0xffffffffL;
2665: if (HFS_BUFFER_TRACE) {
2666: System.out.printf ("position=%d\n", hfuTargetPosition);
2667: }
2668: hfuTargetFileSize = MC68060.mmuReadLongData (fcb + 64, XEiJ.regSRS) & 0xffffffffL;
2669: if (HFS_BUFFER_TRACE) {
2670: System.out.printf ("fileSize=%d\n", hfuTargetFileSize);
2671: }
2672: hfuTargetLength = Math.min (hfuTargetLength, hfuTargetFileSize - hfuTargetPosition);
2673: if (HFS_BUFFER_TRACE) {
2674: System.out.printf ("length=%d\n", hfuTargetLength);
2675: }
2676: if (hfuTargetLength == 0L) {
2677: hfsRequest18Result = 0;
2678: hfsState = HFS_STATE_DONE;
2679: return;
2680: }
2681: hfuTargetAddress = hfsRequest14Namests & 0xffffffffL;
2682: if (HFS_BUFFER_TRACE) {
2683: System.out.printf ("address=0x%08x\n", hfuTargetAddress);
2684: }
2685: hfuTargetTransferred = 0L;
2686: if (HFS_BUFFER_TRACE) {
2687: System.out.printf ("transferred=%d\n", hfuTargetTransferred);
2688: }
2689:
2690:
2691:
2692:
2693:
2694:
2695:
2696:
2697:
2698:
2699:
2700:
2701:
2702:
2703:
2704:
2705:
2706:
2707:
2708: if (hfuTargetFileSize == 0 ||
2709: (0 < handle.hfhEnd &&
2710: handle.hfhStart <= hfuTargetPosition && hfuTargetPosition < handle.hfhStart + HFS_BUFFER_SIZE)) {
2711:
2712: hfsRequest18Result = 0;
2713: hfsState = HFS_STATE_X68K;
2714: } else {
2715:
2716: hfsRequest18Result = 0;
2717: hfsState = HFS_STATE_HOST;
2718: }
2719: }
2720:
2721:
2722: public void hfuCallReadHost () {
2723: HFHandle handle = hfuTargetHandle;
2724: RandomAccessFile raf = handle.hfhRaf;
2725:
2726: if (handle.hfhDirty) {
2727: if (HFS_BUFFER_TRACE) {
2728: System.out.printf ("delaywrite(fcb=0x%08x,name=\"%s\",start=0x%08x,end=0x%08x)\n", handle.hfhFcb, handle.hfhFile.toString(), handle.hfhStart, handle.hfhEnd);
2729: }
2730: try {
2731: raf.seek (handle.hfhStart);
2732: } catch (IOException ioe) {
2733: System.out.println ((Multilingual.mlnJapanese ? "シークエラー: " : "Seek error: ") + handle.toString ());
2734: }
2735: try {
2736: raf.write (handle.hfhBuffer, 0, (int) (handle.hfhEnd - handle.hfhStart));
2737: } catch (IOException ioe) {
2738: System.out.println ((Multilingual.mlnJapanese ? "遅延書き込みに失敗しました: " : "Delayed write failed: ") + handle.toString ());
2739: }
2740: handle.hfhDirty = false;
2741: }
2742:
2743: int ll = (int) Math.min (HFS_BUFFER_SIZE,
2744: hfuTargetFileSize - hfuTargetPosition
2745: );
2746: int kk = 0;
2747: Arrays.fill (handle.hfhBuffer, (byte) 0);
2748: handle.hfhStart = hfuTargetPosition;
2749: handle.hfhEnd = hfuTargetPosition + ll;
2750: handle.hfhDirty = false;
2751: if (HFS_BUFFER_TRACE) {
2752: System.out.printf ("preread(fcb=0x%08x,name=\"%s\",start=0x%08x,end=0x%08x)\n", handle.hfhFcb, handle.hfhFile.toString(), handle.hfhStart, handle.hfhEnd);
2753: }
2754: if (0 < ll) {
2755: try {
2756: raf.seek (hfuTargetPosition);
2757: } catch (IOException ioe) {
2758: System.out.println ((Multilingual.mlnJapanese ? "シークエラー: " : "Seek error: ") + handle.toString ());
2759: }
2760: try {
2761: while (kk < ll) {
2762: int tt = raf.read (handle.hfhBuffer, kk, ll - kk);
2763: if (tt < 0) {
2764:
2765: hfsRequest18Result = -1;
2766: hfsState = HFS_STATE_DONE;
2767: return;
2768: }
2769: kk += tt;
2770: }
2771: } catch (IOException ioe) {
2772: System.out.println ((Multilingual.mlnJapanese ? "リードエラー: " : "Read error: ") + handle.toString ());
2773: hfsRequest18Result = -1;
2774: hfsState = HFS_STATE_DONE;
2775: return;
2776: }
2777: }
2778:
2779: hfsRequest18Result = 0;
2780: hfsState = HFS_STATE_X68K;
2781: }
2782:
2783:
2784: public void hfuCallReadX68k () throws M68kException {
2785: HFHandle handle = hfuTargetHandle;
2786: int fcb = handle.hfhFcb;
2787:
2788: long tt = Math.min (hfuTargetLength - hfuTargetTransferred,
2789: handle.hfhEnd - hfuTargetPosition
2790: );
2791: long t = Math.min (HFS_BUFFER_STEP, tt);
2792: if (HFS_BUFFER_TRACE) {
2793: System.out.printf ("t=%d\n", t);
2794: }
2795: MC68060.mmuWriteByteArray ((int) (hfuTargetAddress + hfuTargetTransferred),
2796: handle.hfhBuffer,
2797: (int) (hfuTargetPosition - handle.hfhStart),
2798: (int) t,
2799: XEiJ.regSRS);
2800: hfuTargetPosition += t;
2801: if (HFS_BUFFER_TRACE) {
2802: System.out.printf ("position=%d\n", hfuTargetPosition);
2803: }
2804: MC68060.mmuWriteLongData (fcb + 6, (int) hfuTargetPosition, XEiJ.regSRS);
2805: hfuTargetTransferred += t;
2806: if (HFS_BUFFER_TRACE) {
2807: System.out.printf ("transferred=%d\n", hfuTargetTransferred);
2808: }
2809: if (hfuTargetLength <= hfuTargetTransferred) {
2810: hfsRequest18Result = (int) hfuTargetTransferred;
2811: hfsState = HFS_STATE_DONE;
2812: return;
2813: }
2814: if (t < tt) {
2815:
2816: hfsRequest18Result = 0;
2817: hfsState = HFS_STATE_X68K;
2818: } else {
2819:
2820: hfsRequest18Result = 0;
2821: hfsState = HFS_STATE_HOST;
2822: }
2823: }
2824:
2825:
2826:
2827:
2828:
2829:
2830:
2831:
2832:
2833:
2834:
2835:
2836:
2837:
2838:
2839: public void hfuCallWrite () throws M68kException {
2840: if (HFS_BUFFER_TRACE || (HFS_COMMAND_TRACE && hfsCommandTraceOn)) {
2841: int pc = MainMemory.mmrGetLevelZeroPC ();
2842: System.out.println (LabeledAddress.lblSearch (new StringBuilder (), pc).toString ());
2843: System.out.printf ("%08x write(fcb=0x%08x,address=0x%08x,length=0x%08x)\n",
2844: pc, hfsRequest22Fcb, hfsRequest14Namests, hfsRequest18Param);
2845: }
2846: if (!abuInserted) {
2847: hfsRequest3Error = DEV_RETRY | DEV_ABORT | DEV_INSERT_MEDIA;
2848: hfsRequest18Result = -1;
2849: hfsState = HFS_STATE_DONE;
2850: return;
2851: }
2852: if (abuWriteProtected) {
2853: hfsRequest3Error = DEV_IGNORE | DEV_RETRY | DEV_ABORT | DEV_CANNOT_WRITE;
2854: hfsRequest18Result = -1;
2855: hfsState = HFS_STATE_DONE;
2856: return;
2857: }
2858: int fcb = hfsRequest22Fcb;
2859: HFHandle handle = hfuTargetHandle = hfuFcbToHandle.get (fcb);
2860: if (handle == null) {
2861: hfsRequest18Result = DOS_HANDLE_IS_NOT_OPENED;
2862: hfsState = HFS_STATE_DONE;
2863: return;
2864: }
2865: hfuTargetLength = hfsRequest18Param & 0xffffffffL;
2866: if (HFS_BUFFER_TRACE) {
2867: System.out.printf ("length=%d\n", hfuTargetLength);
2868: }
2869: hfuTargetPosition = MC68060.mmuReadLongData (fcb + 6, XEiJ.regSRS) & 0xffffffffL;
2870: if (HFS_BUFFER_TRACE) {
2871: System.out.printf ("position=%d\n", hfuTargetPosition);
2872: }
2873: hfuTargetFileSize = MC68060.mmuReadLongData (fcb + 64, XEiJ.regSRS) & 0xffffffffL;
2874: if (HFS_BUFFER_TRACE) {
2875: System.out.printf ("fileSize=%d\n", hfuTargetFileSize);
2876: }
2877: if (hfuTargetLength == 0L) {
2878: if (hfuTargetFileSize <= hfuTargetPosition) {
2879: hfsRequest18Result = 0;
2880: hfsState = HFS_STATE_DONE;
2881: return;
2882: }
2883: MC68060.mmuWriteLongData (fcb + 64, (int) hfuTargetPosition, XEiJ.regSRS);
2884: hfsRequest18Result = 1;
2885: hfsState = HFS_STATE_HOST;
2886: return;
2887: }
2888: if (0xffffffffL < hfuTargetPosition + hfuTargetLength) {
2889: hfuTargetLength = 0xffffffffL - hfuTargetPosition;
2890: if (HFS_BUFFER_TRACE) {
2891: System.out.printf ("length=%d\n", hfuTargetLength);
2892: }
2893: if (hfuTargetLength == 0L) {
2894: hfsRequest18Result = 0;
2895: hfsState = HFS_STATE_DONE;
2896: return;
2897: }
2898: }
2899: hfuTargetAddress = hfsRequest14Namests & 0xffffffffL;
2900: if (HFS_BUFFER_TRACE) {
2901: System.out.printf ("address=0x%08x\n", hfuTargetAddress);
2902: }
2903: hfuTargetTransferred = 0L;
2904: if (HFS_BUFFER_TRACE) {
2905: System.out.printf ("transferred=%d\n", hfuTargetTransferred);
2906: }
2907:
2908:
2909:
2910:
2911:
2912:
2913:
2914:
2915:
2916:
2917:
2918:
2919:
2920:
2921:
2922:
2923:
2924:
2925:
2926: if (hfuTargetFileSize == 0 ||
2927: (0 < handle.hfhEnd &&
2928: handle.hfhStart <= hfuTargetPosition && hfuTargetPosition < handle.hfhStart + HFS_BUFFER_SIZE)) {
2929:
2930: hfsRequest18Result = 0;
2931: hfsState = HFS_STATE_X68K;
2932: } else {
2933:
2934: hfsRequest18Result = 0;
2935: hfsState = HFS_STATE_HOST;
2936: }
2937: }
2938:
2939:
2940: public void hfuCallWriteHost () {
2941: HFHandle handle = hfuTargetHandle;
2942: RandomAccessFile raf = handle.hfhRaf;
2943: if (hfsRequest18Result != 0) {
2944: if (handle.hfhStart <= hfuTargetPosition && hfuTargetPosition < handle.hfhEnd) {
2945:
2946: Arrays.fill (handle.hfhBuffer, (int) (hfuTargetPosition - handle.hfhStart), (int) (handle.hfhEnd - handle.hfhStart), (byte) 0);
2947: handle.hfhEnd = hfuTargetPosition;
2948: if (HFS_BUFFER_TRACE) {
2949: System.out.printf ("truncate(fcb=0x%08x,name=\"%s\",start=0x%08x,end=0x%08x)\n", handle.hfhFcb, handle.hfhFile.toString(), handle.hfhStart, handle.hfhEnd);
2950: }
2951: }
2952: try {
2953: raf.seek (hfuTargetPosition);
2954: } catch (IOException ioe) {
2955: System.out.println ((Multilingual.mlnJapanese ? "シークエラー: " : "Seek error: ") + handle.toString ());
2956: }
2957:
2958: try {
2959: raf.setLength (hfuTargetPosition);
2960: } catch (IOException ioe) {
2961: System.out.println ((Multilingual.mlnJapanese ? "ファイルの長さを設定できません: " : "Could not set length of file: ") + handle.toString ());
2962: hfsRequest18Result = -1;
2963: hfsState = HFS_STATE_DONE;
2964: return;
2965: }
2966: hfsRequest18Result = 0;
2967: hfsState = HFS_STATE_DONE;
2968: return;
2969: }
2970:
2971: if (handle.hfhDirty) {
2972: if (HFS_BUFFER_TRACE) {
2973: System.out.printf ("delaywrite(fcb=0x%08x,name=\"%s\",start=0x%08x,end=0x%08x)\n", handle.hfhFcb, handle.hfhFile.toString(), handle.hfhStart, handle.hfhEnd);
2974: }
2975: try {
2976: raf.seek (handle.hfhStart);
2977: } catch (IOException ioe) {
2978: System.out.println ((Multilingual.mlnJapanese ? "シークエラー: " : "Seek error: ") + handle.toString ());
2979: }
2980: try {
2981: raf.write (handle.hfhBuffer, 0, (int) (handle.hfhEnd - handle.hfhStart));
2982: } catch (IOException ioe) {
2983: System.out.println ((Multilingual.mlnJapanese ? "遅延書き込みに失敗しました: " : "Delayed write failed: ") + handle.toString ());
2984: }
2985: handle.hfhDirty = false;
2986: }
2987:
2988: int ll = (int) Math.min (HFS_BUFFER_SIZE,
2989: hfuTargetFileSize - hfuTargetPosition
2990: );
2991: int kk = 0;
2992: Arrays.fill (handle.hfhBuffer, (byte) 0);
2993: handle.hfhStart = hfuTargetPosition;
2994: handle.hfhEnd = hfuTargetPosition + ll;
2995: handle.hfhDirty = false;
2996: if (HFS_BUFFER_TRACE) {
2997: System.out.printf ("preread(fcb=0x%08x,name=\"%s\",start=0x%08x,end=0x%08x)\n", handle.hfhFcb, handle.hfhFile.toString(), handle.hfhStart, handle.hfhEnd);
2998: }
2999: if (0 < ll) {
3000: try {
3001: raf.seek (hfuTargetPosition);
3002: } catch (IOException ioe) {
3003: System.out.println ((Multilingual.mlnJapanese ? "シークエラー: " : "Seek error: ") + handle.toString ());
3004: }
3005: try {
3006: while (kk < ll) {
3007: int tt = raf.read (handle.hfhBuffer, kk, ll - kk);
3008: if (tt < 0) {
3009:
3010: hfsRequest18Result = -1;
3011: hfsState = HFS_STATE_DONE;
3012: return;
3013: }
3014: kk += tt;
3015: }
3016: } catch (IOException ioe) {
3017: System.out.println ((Multilingual.mlnJapanese ? "リードエラー: " : "Read error: ") + handle.toString ());
3018: hfsRequest18Result = -1;
3019: hfsState = HFS_STATE_DONE;
3020: return;
3021: }
3022: }
3023:
3024: hfsRequest18Result = 0;
3025: hfsState = HFS_STATE_X68K;
3026: }
3027:
3028:
3029: public void hfuCallWriteX68k () throws M68kException {
3030: HFHandle handle = hfuTargetHandle;
3031: int fcb = handle.hfhFcb;
3032:
3033: long tt = Math.min (hfuTargetLength - hfuTargetTransferred,
3034: handle.hfhStart + HFS_BUFFER_SIZE - hfuTargetPosition
3035: );
3036: long t = Math.min (HFS_BUFFER_STEP, tt);
3037: if (HFS_BUFFER_TRACE) {
3038: System.out.printf ("t=%d\n", t);
3039: }
3040: MC68060.mmuReadByteArray ((int) (hfuTargetAddress + hfuTargetTransferred),
3041: handle.hfhBuffer,
3042: (int) (hfuTargetPosition - handle.hfhStart),
3043: (int) t,
3044: XEiJ.regSRS);
3045: handle.hfhEnd = Math.max (handle.hfhEnd, hfuTargetPosition + t);
3046: handle.hfhDirty = true;
3047: if (HFS_BUFFER_TRACE) {
3048: System.out.printf ("written(fcb=0x%08x,name=\"%s\",start=0x%08x,end=0x%08x,dirty=%b)\n", handle.hfhFcb, handle.hfhFile.toString(), handle.hfhStart, handle.hfhEnd, handle.hfhDirty);
3049: }
3050: hfuTargetPosition += t;
3051: if (HFS_BUFFER_TRACE) {
3052: System.out.printf ("position=%d\n", hfuTargetPosition);
3053: }
3054: MC68060.mmuWriteLongData (fcb + 6, (int) hfuTargetPosition, XEiJ.regSRS);
3055: if (hfuTargetFileSize < hfuTargetPosition) {
3056: hfuTargetFileSize = hfuTargetPosition;
3057: if (HFS_BUFFER_TRACE) {
3058: System.out.printf ("fileSize=%d\n", hfuTargetFileSize);
3059: }
3060: MC68060.mmuWriteLongData (fcb + 64, (int) hfuTargetFileSize, XEiJ.regSRS);
3061: }
3062: hfuTargetTransferred += t;
3063: if (HFS_BUFFER_TRACE) {
3064: System.out.printf ("transferred=%d\n", hfuTargetTransferred);
3065: }
3066: if (hfuTargetLength <= hfuTargetTransferred) {
3067: hfsRequest18Result = (int) hfuTargetTransferred;
3068: hfsState = HFS_STATE_DONE;
3069: return;
3070: }
3071: if (t < tt) {
3072:
3073: hfsRequest18Result = 0;
3074: hfsState = HFS_STATE_X68K;
3075: } else {
3076:
3077: hfsRequest18Result = 0;
3078: hfsState = HFS_STATE_HOST;
3079: }
3080: }
3081:
3082:
3083:
3084:
3085:
3086:
3087:
3088:
3089:
3090:
3091:
3092:
3093:
3094:
3095:
3096: public void hfuCallSeek () throws M68kException {
3097: if (HFS_COMMAND_TRACE && hfsCommandTraceOn) {
3098: int pc = MainMemory.mmrGetLevelZeroPC ();
3099: System.out.println (LabeledAddress.lblSearch (new StringBuilder (), pc).toString ());
3100: System.out.printf ("%08x seek(fcb=0x%08x,offset=0x%08x,mode=0x%02x)\n",
3101: pc, hfsRequest22Fcb, hfsRequest18Param, hfsRequest13Mode);
3102: }
3103: if (!abuInserted) {
3104: hfsRequest3Error = DEV_RETRY | DEV_ABORT | DEV_INSERT_MEDIA;
3105: hfsRequest18Result = -1;
3106: hfsState = HFS_STATE_DONE;
3107: return;
3108: }
3109: int mode = hfsRequest13Mode;
3110: long offset64 = (long) hfsRequest18Param;
3111: int fcb = hfsRequest22Fcb;
3112: HFHandle handle = hfuFcbToHandle.get (fcb);
3113: if (handle == null) {
3114: hfsRequest18Result = DOS_HANDLE_IS_NOT_OPENED;
3115: hfsState = HFS_STATE_DONE;
3116: return;
3117: }
3118: long current64 = (long) MC68060.mmuReadLongData (fcb + 6, XEiJ.regSRS);
3119: long end64 = (long) MC68060.mmuReadLongData (fcb + 64, XEiJ.regSRS);
3120:
3121: current64 = current64 & 0x00000000ffffffffL;
3122:
3123: end64 = end64 & 0x00000000ffffffffL;
3124: if (mode == 0) {
3125:
3126: offset64 = offset64 & 0x00000000ffffffffL;
3127:
3128: current64 = offset64;
3129: } else if (mode == 1) {
3130:
3131: offset64 = ((offset64 + 0x0000000080000000L) & 0x00000000ffffffffL) - 0x0000000080000000L;
3132:
3133: current64 = current64 + offset64;
3134: } else if (mode == 2) {
3135:
3136: offset64 = ((offset64 - 0x0000000000000001L) & 0x00000000ffffffffL) - 0x00000000ffffffffL;
3137:
3138: current64 = end64 + offset64;
3139: } else {
3140:
3141: hfsRequest18Result = DOS_INVALID_PARAMETER;
3142: hfsState = HFS_STATE_DONE;
3143: return;
3144: }
3145: if (current64 < 0x0000000000000000L || end64 < current64) {
3146:
3147: hfsRequest18Result = DOS_SEEK_OVER_EOF;
3148: hfsState = HFS_STATE_DONE;
3149: return;
3150: }
3151:
3152: MC68060.mmuWriteLongData (fcb + 6, (int) current64, XEiJ.regSRS);
3153:
3154: hfsRequest18Result = (int) current64;
3155: hfsState = HFS_STATE_DONE;
3156: }
3157:
3158:
3159:
3160:
3161:
3162:
3163:
3164:
3165:
3166:
3167:
3168:
3169:
3170:
3171:
3172:
3173: public void hfuCallFiledate () throws M68kException {
3174: if (HFS_COMMAND_TRACE && hfsCommandTraceOn) {
3175: int pc = MainMemory.mmrGetLevelZeroPC ();
3176: System.out.println (LabeledAddress.lblSearch (new StringBuilder (), pc).toString ());
3177: System.out.printf ("%08x filedate(fcb=0x%08x,datetime=0x%08x)\n",
3178: pc, hfsRequest22Fcb, hfsRequest18Param);
3179: }
3180: if (!abuInserted) {
3181: hfsRequest3Error = DEV_RETRY | DEV_ABORT | DEV_INSERT_MEDIA;
3182: hfsRequest18Result = -1;
3183: hfsState = HFS_STATE_DONE;
3184: return;
3185: }
3186: int fcb = hfsRequest22Fcb;
3187: int datetime = hfsRequest18Param;
3188: if (datetime == 0) {
3189: datetime = (MC68060.mmuReadWordZeroData (fcb + 60, XEiJ.regSRS) << 16 |
3190: MC68060.mmuReadWordZeroData (fcb + 58, XEiJ.regSRS));
3191: } else {
3192:
3193:
3194:
3195: int time = datetime & 0xffff;
3196: int date = datetime >>> 16;
3197: MC68060.mmuWriteWordData (fcb + 58, time, XEiJ.regSRS);
3198: MC68060.mmuWriteWordData (fcb + 60, date, XEiJ.regSRS);
3199:
3200: int type = MC68060.mmuModifyByteSignData (fcb + 1, XEiJ.regSRS);
3201: if ((type & 0x40) != 0) {
3202: MC68060.mmuWriteByteData (fcb + 1, type & ~0x40, XEiJ.regSRS);
3203: }
3204: }
3205: hfsRequest18Result = datetime;
3206: hfsState = HFS_STATE_DONE;
3207: }
3208:
3209:
3210:
3211:
3212:
3213:
3214:
3215:
3216:
3217:
3218:
3219:
3220:
3221:
3222:
3223:
3224:
3225:
3226:
3227:
3228: public void hfuCallDskfre () throws M68kException {
3229: if (HFS_COMMAND_TRACE && hfsCommandTraceOn) {
3230: int pc = MainMemory.mmrGetLevelZeroPC ();
3231: System.out.println (LabeledAddress.lblSearch (new StringBuilder (), pc).toString ());
3232: System.out.printf ("%08x dskfre(buffer=0x%08x)\n",
3233: pc, hfsRequest14Namests);
3234: }
3235: if (!abuInserted) {
3236: hfsRequest3Error = DEV_RETRY | DEV_ABORT | DEV_INSERT_MEDIA;
3237: hfsRequest18Result = -1;
3238: hfsState = HFS_STATE_DONE;
3239: return;
3240: }
3241: hfsRequest18Result = 0;
3242: hfsState = HFS_STATE_HOST;
3243: }
3244:
3245:
3246: public void hfuCallDskfreHost () {
3247: File file = new File (hfuRootPath);
3248: hfuTargetTotalSpace = file.getTotalSpace ();
3249: hfuTargetFreeSpace = file.getFreeSpace ();
3250: hfsRequest18Result = 0;
3251: hfsState = HFS_STATE_X68K;
3252: }
3253:
3254:
3255: public void hfuCallDskfreX68k () throws M68kException {
3256: int totalSpace = (int) Math.min (0x7fffffffL, hfuTargetTotalSpace);
3257: int freeSpace = (int) Math.min (0x7fffffffL, hfuTargetFreeSpace);
3258: int clusterBit = Math.max (0, 7 - Integer.numberOfLeadingZeros (totalSpace));
3259: MC68060.mmuWriteWordData (hfsRequest14Namests, freeSpace >>> clusterBit + 10, XEiJ.regSRS);
3260: MC68060.mmuWriteWordData (hfsRequest14Namests + 2, totalSpace >>> clusterBit + 10, XEiJ.regSRS);
3261: MC68060.mmuWriteWordData (hfsRequest14Namests + 4, 1 << clusterBit, XEiJ.regSRS);
3262: MC68060.mmuWriteWordData (hfsRequest14Namests + 6, 1 << 10, XEiJ.regSRS);
3263: hfsRequest18Result = freeSpace;
3264: hfsState = HFS_STATE_DONE;
3265:
3266: }
3267:
3268:
3269:
3270:
3271:
3272:
3273:
3274:
3275:
3276:
3277:
3278:
3279:
3280:
3281:
3282:
3283:
3284:
3285:
3286:
3287:
3288:
3289:
3290:
3291: public void hfuCallDrvctrl () throws M68kException {
3292: if (HFS_COMMAND_TRACE && hfsCommandTraceOn) {
3293: int pc = MainMemory.mmrGetLevelZeroPC ();
3294: System.out.println (LabeledAddress.lblSearch (new StringBuilder (), pc).toString ());
3295: System.out.printf ("%08x drvctrl(mode=0x%02x,param=0x%08x)\n",
3296: pc, hfsRequest13Mode, hfsRequest14Namests);
3297: }
3298: switch (hfsRequest13Mode) {
3299: case 1:
3300: if (hfuFcbToHandle.isEmpty ()) {
3301: eject ();
3302: }
3303: break;
3304: case 2:
3305: prevent ();
3306: break;
3307: case 3:
3308: if (hfuFcbToHandle.isEmpty ()) {
3309: allow ();
3310: }
3311: break;
3312: }
3313: MC68060.mmuWriteByteData (hfsRequestHeader + 13,
3314: (abuInserted ? ABU_INSERTED : 0) |
3315: (abuWriteProtected ? ABU_WRITE_PROTECTED : 0) |
3316: (abuBuffered ? ABU_BUFFERED : 0) |
3317: (abuEjectPrevented ? ABU_EJECT_PREVENTED : 0), XEiJ.regSRS);
3318: hfsRequest18Result = 0;
3319: hfsState = HFS_STATE_DONE;
3320: }
3321:
3322:
3323:
3324:
3325:
3326:
3327:
3328:
3329:
3330:
3331:
3332:
3333:
3334:
3335:
3336:
3337:
3338:
3339:
3340:
3341:
3342:
3343:
3344:
3345:
3346:
3347:
3348:
3349:
3350:
3351:
3352:
3353:
3354:
3355:
3356:
3357:
3358:
3359:
3360: public void hfuCallGetdpb () throws M68kException {
3361: if (HFS_REPORT_INCOMPATIBLE_COMMAND ||
3362: (HFS_COMMAND_TRACE && hfsCommandTraceOn)) {
3363: int pc = MainMemory.mmrGetLevelZeroPC ();
3364: System.out.println (LabeledAddress.lblSearch (new StringBuilder (), pc).toString ());
3365: System.out.printf ("%08x getdpb(buffer=0x%08x)\n",
3366: pc, hfsRequest14Namests);
3367: }
3368: MC68060.mmuWriteLongData (hfsRequest14Namests , 0, XEiJ.regSRS);
3369: MC68060.mmuWriteLongData (hfsRequest14Namests + 4, 0, XEiJ.regSRS);
3370: MC68060.mmuWriteLongData (hfsRequest14Namests + 8, 0, XEiJ.regSRS);
3371: MC68060.mmuWriteLongData (hfsRequest14Namests + 12, 0, XEiJ.regSRS);
3372: hfsRequest18Result = 0;
3373: hfsState = HFS_STATE_DONE;
3374: }
3375:
3376:
3377:
3378:
3379:
3380:
3381:
3382:
3383:
3384:
3385:
3386:
3387:
3388:
3389:
3390: public void hfuCallDiskred () throws M68kException {
3391: if (HFS_REPORT_INCOMPATIBLE_COMMAND ||
3392: (HFS_COMMAND_TRACE && hfsCommandTraceOn)) {
3393: int pc = MainMemory.mmrGetLevelZeroPC ();
3394: System.out.println (LabeledAddress.lblSearch (new StringBuilder (), pc).toString ());
3395: System.out.printf ("%08x diskred(buffer=0x%08x,start=0x%08x,count=0x%08x,mediabyte=0x%02x)\n",
3396: pc, hfsRequest14Namests, hfsRequest22Fcb, hfsRequest18Param, hfsRequest13Mode);
3397: }
3398: int l = hfsRequest18Param << 10;
3399: for (int i = 0; i < l; i += 4) {
3400: MC68060.mmuWriteLongData (hfsRequest14Namests + i, 0, XEiJ.regSRS);
3401: }
3402: hfsRequest18Result = 0;
3403: hfsState = HFS_STATE_DONE;
3404: }
3405:
3406:
3407:
3408:
3409:
3410:
3411:
3412:
3413:
3414:
3415:
3416:
3417:
3418:
3419:
3420: public void hfuCallDiskwrt () throws M68kException {
3421: if (HFS_REPORT_INCOMPATIBLE_COMMAND ||
3422: (HFS_COMMAND_TRACE && hfsCommandTraceOn)) {
3423: int pc = MainMemory.mmrGetLevelZeroPC ();
3424: System.out.println (LabeledAddress.lblSearch (new StringBuilder (), pc).toString ());
3425: System.out.printf ("%08x diskwrt(buffer=0x%08x,start=0x%08x,count=0x%08x,mediabyte=0x%02x)\n",
3426: pc, hfsRequest14Namests, hfsRequest22Fcb, hfsRequest18Param, hfsRequest13Mode);
3427: }
3428: hfsRequest18Result = 0;
3429: hfsState = HFS_STATE_DONE;
3430: }
3431:
3432:
3433:
3434:
3435:
3436:
3437:
3438:
3439:
3440:
3441:
3442:
3443:
3444:
3445:
3446:
3447:
3448: public void hfuCallSpecialCtrl () throws M68kException {
3449: if (HFS_REPORT_INCOMPATIBLE_COMMAND ||
3450: (HFS_COMMAND_TRACE && hfsCommandTraceOn)) {
3451: int pc = MainMemory.mmrGetLevelZeroPC ();
3452: System.out.println (LabeledAddress.lblSearch (new StringBuilder (), pc).toString ());
3453: System.out.printf ("%08x ioctrl(command=0x%08x,param=0x%08x)\n",
3454: pc, hfsRequest18Param, hfsRequest14Namests);
3455: }
3456:
3457: hfsRequest18Result = DOS_CANNOT_IOCTRL;
3458: hfsState = HFS_STATE_DONE;
3459: }
3460:
3461:
3462:
3463:
3464:
3465:
3466:
3467:
3468:
3469:
3470:
3471:
3472:
3473:
3474:
3475: public void hfuCallFflush () throws M68kException {
3476: if (HFS_COMMAND_TRACE && hfsCommandTraceOn) {
3477: int pc = MainMemory.mmrGetLevelZeroPC ();
3478: System.out.println (LabeledAddress.lblSearch (new StringBuilder (), pc).toString ());
3479: System.out.printf ("%08x fflush()\n",
3480: pc);
3481: }
3482: hfsRequest18Result = 0;
3483: hfsState = HFS_STATE_HOST;
3484: }
3485:
3486:
3487: public void hfuCallFflushHost () {
3488: for (HFHandle handle : hfuFcbToHandle.values ()) {
3489:
3490: if (handle.hfhDirty) {
3491: if (HFS_BUFFER_TRACE) {
3492: System.out.printf ("delaywrite(fcb=0x%08x,name=\"%s\",start=0x%08x,end=0x%08x)\n", handle.hfhFcb, handle.hfhFile.toString(), handle.hfhStart, handle.hfhEnd);
3493: }
3494: RandomAccessFile raf = handle.hfhRaf;
3495: try {
3496: raf.seek (handle.hfhStart);
3497: } catch (IOException ioe) {
3498: System.out.println ((Multilingual.mlnJapanese ? "シークエラー: " : "Seek error: ") + handle.toString ());
3499: }
3500: try {
3501: raf.write (handle.hfhBuffer, 0, (int) (handle.hfhEnd - handle.hfhStart));
3502: } catch (IOException ioe) {
3503: System.out.println ((Multilingual.mlnJapanese ? "遅延書き込みに失敗しました: " : "Delayed write failed: ") + handle.toString ());
3504: }
3505: handle.hfhDirty = false;
3506: }
3507: handle.hfhStart = 0L;
3508: handle.hfhEnd = 0L;
3509: }
3510: hfsRequest18Result = 0;
3511: hfsState = HFS_STATE_DONE;
3512: }
3513:
3514:
3515:
3516:
3517:
3518:
3519:
3520:
3521:
3522:
3523:
3524:
3525:
3526:
3527:
3528: public void hfuCallMediacheck () throws M68kException {
3529: if (HFS_COMMAND_TRACE && hfsCommandTraceOn) {
3530: int pc = MainMemory.mmrGetLevelZeroPC ();
3531: System.out.println (LabeledAddress.lblSearch (new StringBuilder (), pc).toString ());
3532: System.out.printf ("%08x mediacheck()\n",
3533: pc);
3534: }
3535: hfsRequest18Result = hasBeenEjected () ? -1 : 0;
3536: hfsState = HFS_STATE_DONE;
3537: }
3538:
3539:
3540:
3541:
3542:
3543:
3544:
3545:
3546:
3547:
3548:
3549:
3550:
3551:
3552:
3553: public void hfuCallLock () throws M68kException {
3554: if (HFS_REPORT_INCOMPATIBLE_COMMAND ||
3555: (HFS_COMMAND_TRACE && hfsCommandTraceOn)) {
3556: int pc = MainMemory.mmrGetLevelZeroPC ();
3557: System.out.println (LabeledAddress.lblSearch (new StringBuilder (), pc).toString ());
3558: System.out.printf ("%08x %s(fcb=0x%08x,offset=0x%08x,length=0x%08x)\n",
3559: pc, hfsRequest13Mode == 0 ? "lock" : "unlock", hfsRequest22Fcb, hfsRequest18Param, hfsRequest14Namests);
3560: }
3561: if (true) {
3562: hfsRequest18Result = -1;
3563: } else {
3564: hfsRequest18Result = 0;
3565: }
3566: hfsState = HFS_STATE_DONE;
3567: }
3568:
3569:
3570:
3571:
3572:
3573:
3574:
3575:
3576:
3577:
3578: private void hfuFileInfo (File file, byte[] b) {
3579:
3580: b[0] = (byte) ((file.isFile () ? HumanMedia.HUM_ARCHIVE : 0) |
3581: (file.isDirectory () ? HumanMedia.HUM_DIRECTORY : 0) |
3582: (file.isHidden () ? HumanMedia.HUM_HIDDEN : 0) |
3583: (!file.canWrite () ? HumanMedia.HUM_READONLY : 0));
3584:
3585: long dttm = DnT.dntDttmCmil (file.lastModified () + RP5C15.rtcCmilGap);
3586:
3587: int time = DnT.dntHourDttm (dttm) << 11 | DnT.dntMinuDttm (dttm) << 5 | DnT.dntSecoDttm (dttm) >> 1;
3588: b[1] = (byte) (time >> 8);
3589: b[2] = (byte) time;
3590:
3591: int date = DnT.dntYearDttm (dttm) - 1980 << 9 | DnT.dntMontDttm (dttm) << 5 | DnT.dntMdayDttm (dttm);
3592: b[3] = (byte) (date >> 8);
3593: b[4] = (byte) date;
3594:
3595: int size = (int) Math.min (0xffffffffL, file.length ());
3596: b[5] = (byte) (size >> 24);
3597: b[6] = (byte) (size >> 16);
3598: b[7] = (byte) (size >> 8);
3599: b[8] = (byte) size;
3600: }
3601:
3602:
3603:
3604:
3605:
3606:
3607:
3608:
3609: public void hfuPrintFileInfo (byte[] b) {
3610: StringBuilder sb = new StringBuilder ();
3611:
3612: int attr = b[0] & 255;
3613: sb.append ((attr & HumanMedia.HUM_EXECUTABLE) != 0 ? 'e' : '-');
3614: sb.append ((attr & HumanMedia.HUM_LINK ) != 0 ? 'l' : '-');
3615: sb.append ((attr & HumanMedia.HUM_ARCHIVE ) != 0 ? 'a' : '-');
3616: sb.append ((attr & HumanMedia.HUM_DIRECTORY ) != 0 ? 'd' : '-');
3617: sb.append ((attr & HumanMedia.HUM_VOLUME ) != 0 ? 'v' : '-');
3618: sb.append ((attr & HumanMedia.HUM_SYSTEM ) != 0 ? 's' : '-');
3619: sb.append ((attr & HumanMedia.HUM_HIDDEN ) != 0 ? 'h' : '-');
3620: sb.append ((attr & HumanMedia.HUM_READONLY ) != 0 ? 'r' : '-');
3621: sb.append (" ");
3622:
3623: int date = (char) (b[3] << 8 | b[4] & 255);
3624: XEiJ.fmtSB02u (XEiJ.fmtSB02u (XEiJ.fmtSB04u (sb, (date >>> 9) + 1980).append ('-'), date >>> 5 & 15).append ('-'), date & 31);
3625: sb.append (" ");
3626:
3627: int time = (char) (b[1] << 8 | b[2] & 255);
3628: XEiJ.fmtSB02u (XEiJ.fmtSB02u (XEiJ.fmtSB02u (sb, time >>> 11).append (':'), time >>> 5 & 63).append (':'), time << 1 & 63);
3629: sb.append (" ");
3630:
3631: if ((attr & HumanMedia.HUM_DIRECTORY) != 0) {
3632: sb.append (" <dir>");
3633: } else if ((attr & HumanMedia.HUM_VOLUME) != 0) {
3634: sb.append (" <vol>");
3635: } else {
3636: int size = (b[5] << 8 | b[6] & 255) << 16 | (char) (b[7] << 8 | b[8] & 255);
3637: XEiJ.fmtSBnd (sb, 10, size);
3638: }
3639: sb.append (" ");
3640:
3641: int l = b.length;
3642: for (int i = 9; i < l; i++) {
3643: int s = b[i] & 255;
3644: char c;
3645: if (0x81 <= s && s <= 0x9f || 0xe0 <= s && s <= 0xef) {
3646: int t = i + 1 < l ? b[i + 1] & 255 : 0;
3647: if (0x40 <= t && t != 0x7f && t <= 0xfc) {
3648: c = CharacterCode.chrSJISToChar[s << 8 | t];
3649: if (c == 0) {
3650: c = '※';
3651: }
3652: i++;
3653: } else {
3654: c = '.';
3655: }
3656: } else {
3657: c = CharacterCode.chrSJISToChar[s];
3658: if (c < 0x20 || c == 0x7f) {
3659: c = '.';
3660: }
3661: }
3662: sb.append (c);
3663: }
3664: System.out.println (sb.toString ());
3665: }
3666:
3667:
3668:
3669:
3670:
3671:
3672:
3673:
3674:
3675:
3676:
3677:
3678:
3679:
3680:
3681:
3682:
3683:
3684:
3685:
3686:
3687: private String hfuNamestsToPath (int namests) throws M68kException {
3688: byte[] w = new byte[88];
3689: MC68060.mmuReadByteArray (namests, w, 0, 88, XEiJ.regSRS);
3690: return hfuNamestsToPath (w, true);
3691: }
3692: private String hfuNamestsToPath (int namests, boolean full) throws M68kException {
3693: byte[] w = new byte[88];
3694: MC68060.mmuReadByteArray (namests, w, 0, 88, XEiJ.regSRS);
3695: return hfuNamestsToPath (w, full);
3696: }
3697: private String hfuNamestsToPath (byte[] ns, boolean full) throws M68kException {
3698: if (HFS_COMMAND_TRACE && hfsCommandTraceOn) {
3699: StringBuilder sb = new StringBuilder ();
3700: sb.append ("\"");
3701: for (int i = 0; i < 88; i++) {
3702: if (i == 2 || i == 67 || i == 75 || i == 78) {
3703: sb.append ("\"+\"");
3704: }
3705: int c = ns[i] & 0xff;
3706: if (c == '\b') {
3707: sb.append ("\\b");
3708: } else if (c == '\f') {
3709: sb.append ("\\f");
3710: } else if (c == '\n') {
3711: sb.append ("\\n");
3712: } else if (c == '\r') {
3713: sb.append ("\\r");
3714: } else if (c == '\t') {
3715: sb.append ("\\t");
3716: } else if (c == '\0') {
3717: sb.append ("\\0");
3718: } else if (0x20 <= c && c <= 0x7e) {
3719: sb.append ((char) c);
3720: } else {
3721: sb.append (String.format ("\\x%02x", c));
3722: }
3723: }
3724: sb.append ("\"");
3725: String s = sb.toString ();
3726: int pc = MainMemory.mmrGetLevelZeroPC ();
3727: System.out.printf ("%08x hfuNamestsToPath(ns=%s,full=%b)\n", pc, s, full);
3728: }
3729: byte[] bb = new byte[88];
3730: int k = 0;
3731: for (int i = 2; i < 67; ) {
3732: for (; i < 67 && ns[i] == 0x09; i++) {
3733: }
3734: if (i >= 67 || ns[i] == 0x00) {
3735: break;
3736: }
3737: bb[k++] = 0x2f;
3738: for (; i < 67 && ns[i] != 0x00 && ns[i] != 0x09; i++) {
3739: bb[k++] = ns[i];
3740: }
3741: }
3742: if (full) {
3743: bb[k++] = 0x2f;
3744: for (int i = 67; i < 75; i++) {
3745: bb[k++] = ns[i];
3746: }
3747: for (int i = 78; i < 88; i++) {
3748: bb[k++] = ns[i];
3749: }
3750: for (; k > 0 && bb[k - 1] == 0x00; k--) {
3751: }
3752: for (; k > 0 && bb[k - 1] == 0x20; k--) {
3753: }
3754: bb[k++] = 0x2e;
3755: for (int i = 75; i < 78; i++) {
3756: bb[k++] = ns[i];
3757: }
3758: for (; k > 0 && bb[k - 1] == 0x20; k--) {
3759: }
3760: for (; k > 0 && bb[k - 1] == 0x2e; k--) {
3761: }
3762: }
3763: StringBuilder sb = new StringBuilder (hfuRootPath);
3764: int h = 0x00;
3765: int dot = 0;
3766: for (int i = 0; i < k; i++) {
3767: int l = bb[i] & 255;
3768: if (h != 0x00 && 0x40 <= l && l != 0x7f && l <= 0xfc) {
3769: int c = CharacterCode.chrSJISToChar[h << 8 | l];
3770: if (c != 0x0000) {
3771: sb.append ((char) c);
3772: } else {
3773: XEiJ.fmtHex2 (XEiJ.fmtHex2 (sb.append ('%'), h).append ('%'), l);
3774: }
3775: h = 0x00;
3776: dot |= 2;
3777: } else {
3778: if (h != 0x00) {
3779: XEiJ.fmtHex2 (sb.append ('%'), h);
3780: h = 0x00;
3781: }
3782: if (0x81 <= l && l <= 0x9f || 0xe0 <= l && l <= 0xef) {
3783: h = l;
3784: } else {
3785: int c = CharacterCode.chrSJISToChar[l];
3786: if (0x20 <= c && c != 0x7f) {
3787: sb.append ((char) c);
3788: } else {
3789: XEiJ.fmtHex2 (sb.append ('%'), l);
3790: }
3791: if (c == '/') {
3792: if (dot == 1) {
3793: return null;
3794: }
3795: dot = 0;
3796: } else if (c == '.') {
3797: dot |= 1;
3798: } else {
3799: dot |= 2;
3800: }
3801: }
3802: }
3803: }
3804: if (h != 0x00) {
3805: XEiJ.fmtHex2 (sb.append ('%'), h);
3806: }
3807: if (dot == 1) {
3808: return null;
3809: }
3810: return sb.toString ();
3811: }
3812:
3813: }
3814:
3815:
3816:
3817: }
3818:
3819:
3820: