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: hfsOpenDialog.setVisible (true);
1054: return true;
1055: }
1056:
1057:
1058:
1059: @Override protected boolean load (String path) {
1060: File file = new File (path).getAbsoluteFile ();
1061: if (!file.isDirectory ()) {
1062: file = file.getParentFile ();
1063: if (file == null || !file.isDirectory ()) {
1064: return false;
1065: }
1066: }
1067: hfuRootPath = file.getAbsolutePath ();
1068: hfsAddHistory (new File (path).getAbsoluteFile ());
1069: System.out.println (Multilingual.mlnJapanese ?
1070: hfuRootPath + " を hf" + abuNumber + " に接続しました" :
1071: hfuRootPath + " was inserted in hf" + abuNumber);
1072: return true;
1073: }
1074:
1075:
1076:
1077: public void hfuCall () throws M68kException {
1078: switch (hfsRequest2Command) {
1079: case 0x41:
1080: hfuCallChdir ();
1081: break;
1082: case 0x42:
1083: hfuCallMkdir ();
1084: break;
1085: case 0x43:
1086: hfuCallRmdir ();
1087: break;
1088: case 0x44:
1089: hfuCallRename ();
1090: break;
1091: case 0x45:
1092: hfuCallDelete ();
1093: break;
1094: case 0x46:
1095: hfuCallChmod ();
1096: break;
1097: case 0x47:
1098: hfuCallFiles ();
1099: break;
1100: case 0x48:
1101: hfuCallNfiles ();
1102: break;
1103: case 0x49:
1104: hfuCallCreateNewfile ();
1105: break;
1106: case 0x4a:
1107: hfuCallOpen ();
1108: break;
1109: case 0x4b:
1110: hfuCallClose ();
1111: break;
1112: case 0x4c:
1113: hfuCallRead ();
1114: break;
1115: case 0x4d:
1116: hfuCallWrite ();
1117: break;
1118: case 0x4e:
1119: hfuCallSeek ();
1120: break;
1121: case 0x4f:
1122: hfuCallFiledate ();
1123: break;
1124: case 0x50:
1125: hfuCallDskfre ();
1126: break;
1127: case 0x51:
1128: hfuCallDrvctrl ();
1129: break;
1130: case 0x52:
1131: hfuCallGetdpb ();
1132: break;
1133: case 0x53:
1134: hfuCallDiskred ();
1135: break;
1136: case 0x54:
1137: hfuCallDiskwrt ();
1138: break;
1139: case 0x55:
1140: hfuCallSpecialCtrl ();
1141: break;
1142: case 0x56:
1143: hfuCallFflush ();
1144: break;
1145: case 0x57:
1146: hfuCallMediacheck ();
1147: break;
1148: case 0x58:
1149: hfuCallLock ();
1150: break;
1151: default:
1152: hfsRequest3Error = DEV_ABORT | DEV_UNKNOWN_COMMAND;
1153: hfsRequest18Result = -1;
1154: hfsState = HFS_STATE_DONE;
1155: }
1156: }
1157:
1158:
1159:
1160: public void hfuCallX68k () throws M68kException {
1161: switch (hfsRequest2Command) {
1162:
1163:
1164:
1165:
1166:
1167:
1168:
1169:
1170:
1171:
1172:
1173:
1174:
1175:
1176:
1177:
1178:
1179:
1180:
1181:
1182: case 0x47:
1183: hfuCallFilesX68k ();
1184: break;
1185:
1186:
1187:
1188:
1189:
1190: case 0x49:
1191: hfuCallCreateNewfileX68k ();
1192: break;
1193: case 0x4a:
1194: hfuCallOpenX68k ();
1195: break;
1196: case 0x4b:
1197: hfuCallCloseX68k ();
1198: break;
1199: case 0x4c:
1200: hfuCallReadX68k ();
1201: break;
1202: case 0x4d:
1203: hfuCallWriteX68k ();
1204: break;
1205:
1206:
1207:
1208:
1209:
1210:
1211:
1212:
1213: case 0x50:
1214: hfuCallDskfreX68k ();
1215: break;
1216:
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: public void hfuCallHost () {
1248: switch (hfsRequest2Command) {
1249: case 0x41:
1250: hfuCallChdirHost ();
1251: break;
1252: case 0x42:
1253: hfuCallMkdirHost ();
1254: break;
1255: case 0x43:
1256: hfuCallRmdirHost ();
1257: break;
1258: case 0x44:
1259: hfuCallRenameHost ();
1260: break;
1261: case 0x45:
1262: hfuCallDeleteHost ();
1263: break;
1264: case 0x46:
1265: hfuCallChmodHost ();
1266: break;
1267: case 0x47:
1268: hfuCallFilesHost ();
1269: break;
1270:
1271:
1272:
1273:
1274:
1275: case 0x49:
1276: hfuCallCreateNewfileHost ();
1277: break;
1278: case 0x4a:
1279: hfuCallOpenHost ();
1280: break;
1281: case 0x4b:
1282: hfuCallCloseHost ();
1283: break;
1284: case 0x4c:
1285: hfuCallReadHost ();
1286: break;
1287: case 0x4d:
1288: hfuCallWriteHost ();
1289: break;
1290:
1291:
1292:
1293:
1294:
1295:
1296:
1297:
1298: case 0x50:
1299: hfuCallDskfreHost ();
1300: break;
1301:
1302:
1303:
1304:
1305:
1306:
1307:
1308:
1309:
1310:
1311:
1312:
1313:
1314:
1315:
1316:
1317:
1318: case 0x56:
1319: hfuCallFflushHost ();
1320: break;
1321:
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: public void hfuCallChdir () throws M68kException {
1349: hfuTargetName1 = hfuNamestsToPath (hfsRequest14Namests, false);
1350: if (hfuTargetName1 == null) {
1351: hfsRequest18Result = DOS_ILLEGAL_FILE_NAME;
1352: hfsState = HFS_STATE_DONE;
1353: return;
1354: }
1355: if (HFS_COMMAND_TRACE && hfsCommandTraceOn) {
1356: int pc = MainMemory.mmrGetLevelZeroPC ();
1357: System.out.println (LabeledAddress.lblSearch (new StringBuilder (), pc).toString ());
1358: System.out.printf ("%08x chdir(name=\"%s\")\n",
1359: pc, hfuTargetName1);
1360: }
1361: if (!abuInserted) {
1362: hfsRequest3Error = DEV_RETRY | DEV_ABORT | DEV_INSERT_MEDIA;
1363: hfsRequest18Result = -1;
1364: hfsState = HFS_STATE_DONE;
1365: return;
1366: }
1367: hfsRequest18Result = 0;
1368: hfsState = HFS_STATE_HOST;
1369: }
1370:
1371:
1372: public void hfuCallChdirHost () {
1373: File file1 = new File (hfuTargetName1);
1374: hfsRequest18Result = (!file1.isDirectory () || file1.list() == null ? DOS_DIRECTORY_NOT_FOUND :
1375: 0);
1376: hfsState = HFS_STATE_DONE;
1377: }
1378:
1379:
1380:
1381:
1382:
1383:
1384:
1385:
1386:
1387:
1388:
1389:
1390:
1391:
1392:
1393:
1394: public void hfuCallMkdir () throws M68kException {
1395: hfuTargetName1 = hfuNamestsToPath (hfsRequest14Namests);
1396: if (hfuTargetName1 == null) {
1397: hfsRequest18Result = DOS_ILLEGAL_FILE_NAME;
1398: hfsState = HFS_STATE_DONE;
1399: return;
1400: }
1401: if (HFS_COMMAND_TRACE && hfsCommandTraceOn) {
1402: int pc = MainMemory.mmrGetLevelZeroPC ();
1403: System.out.println (LabeledAddress.lblSearch (new StringBuilder (), pc).toString ());
1404: System.out.printf ("%08x mkdir(name=\"%s\")\n",
1405: pc, hfuTargetName1);
1406: }
1407: if (!abuInserted) {
1408: hfsRequest3Error = DEV_RETRY | DEV_ABORT | DEV_INSERT_MEDIA;
1409: hfsRequest18Result = -1;
1410: hfsState = HFS_STATE_DONE;
1411: return;
1412: }
1413: if (abuWriteProtected) {
1414: hfsRequest3Error = DEV_IGNORE | DEV_RETRY | DEV_ABORT | DEV_CANNOT_WRITE;
1415: hfsRequest18Result = -1;
1416: hfsState = HFS_STATE_DONE;
1417: return;
1418: }
1419: hfsRequest18Result = 0;
1420: hfsState = HFS_STATE_HOST;
1421: }
1422:
1423:
1424: public void hfuCallMkdirHost () {
1425: try {
1426: File file1 = new File (hfuTargetName1);
1427: hfsRequest18Result = (!file1.mkdir () ? DOS_DIRECTORY_EXISTS :
1428: 0);
1429: } catch (Exception e) {
1430: hfsRequest18Result = DOS_CANNOT_WRITE;
1431: }
1432: hfsState = HFS_STATE_DONE;
1433: }
1434:
1435:
1436:
1437:
1438:
1439:
1440:
1441:
1442:
1443:
1444:
1445:
1446:
1447:
1448:
1449:
1450: public void hfuCallRmdir () throws M68kException {
1451: hfuTargetName1 = hfuNamestsToPath (hfsRequest14Namests);
1452: if (hfuTargetName1 == null) {
1453: hfsRequest18Result = DOS_ILLEGAL_FILE_NAME;
1454: hfsState = HFS_STATE_DONE;
1455: return;
1456: }
1457: if (HFS_COMMAND_TRACE && hfsCommandTraceOn) {
1458: int pc = MainMemory.mmrGetLevelZeroPC ();
1459: System.out.println (LabeledAddress.lblSearch (new StringBuilder (), pc).toString ());
1460: System.out.printf ("%08x rmdir(name=\"%s\")\n",
1461: pc, hfuTargetName1);
1462: }
1463: if (!abuInserted) {
1464: hfsRequest3Error = DEV_RETRY | DEV_ABORT | DEV_INSERT_MEDIA;
1465: hfsRequest18Result = -1;
1466: hfsState = HFS_STATE_DONE;
1467: return;
1468: }
1469: if (abuWriteProtected) {
1470: hfsRequest3Error = DEV_IGNORE | DEV_RETRY | DEV_ABORT | DEV_CANNOT_WRITE;
1471: hfsRequest18Result = -1;
1472: hfsState = HFS_STATE_DONE;
1473: return;
1474: }
1475: hfsRequest18Result = 0;
1476: hfsState = HFS_STATE_HOST;
1477: }
1478:
1479:
1480: public void hfuCallRmdirHost () {
1481: try {
1482: File file1 = new File (hfuTargetName1);
1483: hfsRequest18Result = (!file1.isDirectory () ? DOS_DIRECTORY_NOT_FOUND :
1484: !file1.canWrite () ? DOS_CANNOT_WRITE :
1485: !file1.delete () ? DOS_RM_NONEMPTY_DIRECTORY :
1486: 0);
1487: } catch (Exception e) {
1488: hfsRequest18Result = DOS_CANNOT_WRITE;
1489: }
1490: hfsState = HFS_STATE_DONE;
1491: }
1492:
1493:
1494:
1495:
1496:
1497:
1498:
1499:
1500:
1501:
1502:
1503:
1504:
1505:
1506:
1507:
1508:
1509: public void hfuCallRename () throws M68kException {
1510: hfuTargetName1 = hfuNamestsToPath (hfsRequest14Namests);
1511: if (hfuTargetName1 == null) {
1512: hfsRequest18Result = DOS_ILLEGAL_FILE_NAME;
1513: hfsState = HFS_STATE_DONE;
1514: return;
1515: }
1516: hfuTargetName2 = hfuNamestsToPath (hfsRequest18Param);
1517: if (hfuTargetName2 == null) {
1518: hfsRequest18Result = DOS_ILLEGAL_FILE_NAME;
1519: hfsState = HFS_STATE_DONE;
1520: return;
1521: }
1522: if (HFS_COMMAND_TRACE && hfsCommandTraceOn) {
1523: int pc = MainMemory.mmrGetLevelZeroPC ();
1524: System.out.println (LabeledAddress.lblSearch (new StringBuilder (), pc).toString ());
1525: System.out.printf ("%08x rename(from=\"%s\",to=\"%s\")\n",
1526: pc, hfuTargetName1, hfuTargetName2);
1527: }
1528: if (!abuInserted) {
1529: hfsRequest3Error = DEV_RETRY | DEV_ABORT | DEV_INSERT_MEDIA;
1530: hfsRequest18Result = -1;
1531: hfsState = HFS_STATE_DONE;
1532: return;
1533: }
1534: if (abuWriteProtected) {
1535: hfsRequest3Error = DEV_IGNORE | DEV_RETRY | DEV_ABORT | DEV_CANNOT_WRITE;
1536: hfsRequest18Result = -1;
1537: hfsState = HFS_STATE_DONE;
1538: return;
1539: }
1540: hfsRequest18Result = 0;
1541: hfsState = HFS_STATE_HOST;
1542: }
1543:
1544:
1545: public void hfuCallRenameHost () {
1546: try {
1547: File file1 = new File (hfuTargetName1);
1548: File file2 = new File (hfuTargetName2);
1549: hfsRequest18Result = (!file1.exists () ? DOS_FILE_NOT_FOUND :
1550: !file1.renameTo (file2) ? file1.isFile () ? DOS_CANNOT_WRITE : DOS_MV_NONEMPTY_DIRECTORY :
1551: 0);
1552: } catch (Exception e) {
1553: hfsRequest18Result = DOS_CANNOT_WRITE;
1554: }
1555: hfsState = HFS_STATE_DONE;
1556: }
1557:
1558:
1559:
1560:
1561:
1562:
1563:
1564:
1565:
1566:
1567:
1568:
1569:
1570:
1571:
1572: public void hfuCallDelete () throws M68kException {
1573: hfuTargetName1 = hfuNamestsToPath (hfsRequest14Namests);
1574: if (hfuTargetName1 == null) {
1575: hfsRequest18Result = DOS_ILLEGAL_FILE_NAME;
1576: hfsState = HFS_STATE_DONE;
1577: return;
1578: }
1579: if (HFS_COMMAND_TRACE && hfsCommandTraceOn) {
1580: int pc = MainMemory.mmrGetLevelZeroPC ();
1581: System.out.println (LabeledAddress.lblSearch (new StringBuilder (), pc).toString ());
1582: System.out.printf ("%08x delete(name=\"%s\")\n",
1583: pc, hfuTargetName1);
1584: }
1585: if (!abuInserted) {
1586: hfsRequest3Error = DEV_RETRY | DEV_ABORT | DEV_INSERT_MEDIA;
1587: hfsRequest18Result = -1;
1588: hfsState = HFS_STATE_DONE;
1589: return;
1590: }
1591: if (abuWriteProtected) {
1592: hfsRequest3Error = DEV_IGNORE | DEV_RETRY | DEV_ABORT | DEV_CANNOT_WRITE;
1593: hfsRequest18Result = -1;
1594: hfsState = HFS_STATE_DONE;
1595: return;
1596: }
1597: hfsRequest18Result = 0;
1598: hfsState = HFS_STATE_HOST;
1599: }
1600:
1601:
1602: public void hfuCallDeleteHost () {
1603: try {
1604: File file1 = new File (hfuTargetName1);
1605: hfsRequest18Result = (!file1.isFile () ? DOS_FILE_NOT_FOUND :
1606: !file1.canWrite () ? DOS_CANNOT_WRITE :
1607: !file1.delete () ? DOS_CANNOT_WRITE :
1608: 0);
1609: } catch (Exception e) {
1610: hfsRequest18Result = DOS_CANNOT_WRITE;
1611: }
1612: hfsState = HFS_STATE_DONE;
1613: }
1614:
1615:
1616:
1617:
1618:
1619:
1620:
1621:
1622:
1623:
1624:
1625:
1626:
1627:
1628:
1629: public void hfuCallChmod () throws M68kException {
1630: hfuTargetName1 = hfuNamestsToPath (hfsRequest14Namests);
1631: if (hfuTargetName1 == null) {
1632: hfsRequest18Result = DOS_ILLEGAL_FILE_NAME;
1633: hfsState = HFS_STATE_DONE;
1634: return;
1635: }
1636: if (HFS_COMMAND_TRACE && hfsCommandTraceOn) {
1637: int pc = MainMemory.mmrGetLevelZeroPC ();
1638: System.out.println (LabeledAddress.lblSearch (new StringBuilder (), pc).toString ());
1639: System.out.printf ("%08x chmod(name=\"%s\",mode=0x%02x)\n",
1640: pc, hfuTargetName1, hfsRequest13Mode);
1641: }
1642: if (!abuInserted) {
1643: hfsRequest3Error = DEV_RETRY | DEV_ABORT | DEV_INSERT_MEDIA;
1644: hfsRequest18Result = -1;
1645: hfsState = HFS_STATE_DONE;
1646: return;
1647: }
1648: if (hfsRequest13Mode != 255 && abuWriteProtected) {
1649: hfsRequest3Error = DEV_IGNORE | DEV_RETRY | DEV_ABORT | DEV_CANNOT_WRITE;
1650: hfsRequest18Result = -1;
1651: hfsState = HFS_STATE_DONE;
1652: return;
1653: }
1654: hfsRequest18Result = 0;
1655: hfsState = HFS_STATE_HOST;
1656: }
1657:
1658:
1659: public void hfuCallChmodHost () {
1660: File file1 = new File (hfuTargetName1);
1661: if (!file1.exists ()) {
1662: hfsRequest18Result = DOS_FILE_NOT_FOUND;
1663: } else if (hfsRequest13Mode == 255) {
1664: hfsRequest18Result = ((file1.isFile () ? HumanMedia.HUM_ARCHIVE : 0) |
1665: (file1.isDirectory () ? HumanMedia.HUM_DIRECTORY : 0) |
1666: (file1.isHidden () ? HumanMedia.HUM_HIDDEN : 0) |
1667: (!file1.canWrite () ? HumanMedia.HUM_READONLY : 0));
1668: } else {
1669: hfsRequest18Result = 0;
1670: boolean oldReadonly = !file1.canWrite ();
1671: boolean newReadonly = (hfsRequest13Mode & HumanMedia.HUM_READONLY) != 0;
1672: if (oldReadonly != newReadonly) {
1673: try {
1674: if (!file1.setWritable (!newReadonly)) {
1675: hfsRequest18Result = DOS_CANNOT_WRITE;
1676: }
1677: } catch (Exception e) {
1678: hfsRequest18Result = DOS_CANNOT_WRITE;
1679: }
1680: }
1681: if (false) {
1682: boolean oldHidden = file1.isHidden ();
1683: boolean newHidden = (hfsRequest13Mode & HumanMedia.HUM_HIDDEN) != 0;
1684: if (oldHidden != newHidden) {
1685: hfsRequest18Result = DOS_CANNOT_WRITE;
1686: }
1687: if ((hfsRequest13Mode & HumanMedia.HUM_VOLUME) != 0) {
1688: hfsRequest18Result = DOS_CANNOT_WRITE;
1689: }
1690: }
1691: }
1692: hfsState = HFS_STATE_DONE;
1693: }
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: public void hfuCallFiles () throws M68kException {
1747:
1748: byte[] w = hfuTargetNameArray1;
1749: MC68060.mmuReadByteArray (hfsRequest14Namests, w, 0, 88, XEiJ.regSRS);
1750: String dirName = hfuTargetName1 = hfuNamestsToPath (w, false);
1751: if (hfuTargetName1 == null) {
1752: hfsRequest18Result = DOS_ILLEGAL_FILE_NAME;
1753: hfsState = HFS_STATE_DONE;
1754: return;
1755: }
1756: if (HFS_COMMAND_TRACE && hfsCommandTraceOn) {
1757: int pc = MainMemory.mmrGetLevelZeroPC ();
1758: System.out.println (LabeledAddress.lblSearch (new StringBuilder (), pc).toString ());
1759: System.out.printf ("%08x files(name=\"%s\",mode=0x%02x)\n",
1760: pc, dirName, hfsRequest13Mode);
1761: }
1762: if (!abuInserted) {
1763: hfsRequest3Error = DEV_RETRY | DEV_ABORT | DEV_INSERT_MEDIA;
1764: hfsRequest18Result = -1;
1765: hfsState = HFS_STATE_DONE;
1766: return;
1767: }
1768: hfsRequest18Result = 0;
1769: hfsState = HFS_STATE_HOST;
1770: }
1771:
1772:
1773: public void hfuCallFilesHost () {
1774: byte[] w = hfuTargetNameArray1;
1775: String dirName = hfuTargetName1;
1776: File parent = new File (dirName);
1777:
1778: String[] children = parent.list ();
1779: if (children == null) {
1780: hfsRequest18Result = DOS_DIRECTORY_NOT_FOUND;
1781: hfsState = HFS_STATE_DONE;
1782: return;
1783: }
1784:
1785:
1786:
1787:
1788:
1789:
1790:
1791:
1792:
1793:
1794:
1795:
1796:
1797:
1798: for (int i = 21; i <= 28; i++) {
1799: w[i] = w[67 - 21 + i];
1800: }
1801: if (w[74] == '?' && w[78] == '\0') {
1802: for (int i = 29; i <= 38; i++) {
1803: w[i] = '?';
1804: }
1805: } else {
1806: for (int i = 29; i <= 38; i++) {
1807: w[i] = w[78 - 29 + i];
1808: }
1809: }
1810: for (int i = 38; i >= 21 && (w[i] == '\0' || w[i] == ' '); i--) {
1811: w[i] = '\0';
1812: }
1813: for (int i = 39; i <= 41; i++) {
1814: w[i] = w[75 - 39 + i];
1815: }
1816: for (int i = 41; i >= 39 && (w[i] == '\0' || w[i] == ' '); i--) {
1817: w[i] = '\0';
1818: }
1819:
1820: for (int i = 21; i <= 41; i++) {
1821: int c = w[i] & 255;
1822: if ('A' <= c && c <= 'Z') {
1823: w[i] = (byte) (c | 0x20);
1824: } else if (0x81 <= c && c <= 0x9f || 0xe0 <= c && c <= 0xef) {
1825: i++;
1826: }
1827: }
1828:
1829: boolean isRoot = dirName.equals (hfuRootPath);
1830: boolean humansysRequired = isRoot;
1831: boolean commandxRequired = isRoot;
1832: ArrayDeque<byte[]> deque = new ArrayDeque<byte[]> ();
1833: if (isRoot) {
1834: if ((hfsRequest13Mode & HumanMedia.HUM_VOLUME) != 0 &&
1835: w[21] == '?' && w[39] == '?') {
1836:
1837: int l = dirName.length ();
1838: while (2 <= l &&
1839: (dirName.charAt (l - 1) == '/' ||
1840: dirName.charAt (l - 1) == '\\' ||
1841: (dirName.charAt (l - 1) == '.' &&
1842: (dirName.charAt (l - 2) == '/' ||
1843: dirName.charAt (l - 2) == '\\')))) {
1844: l--;
1845: }
1846: byte[] b = new byte[32];
1847:
1848:
1849:
1850:
1851:
1852: hfuFileInfo (parent, b);
1853: b[0] = HumanMedia.HUM_VOLUME;
1854: b[5] = b[6] = b[7] = b[8] = 0;
1855: int k = 9;
1856: for (int i = 0; i < l; i++) {
1857: int c = CharacterCode.chrCharToSJIS[dirName.charAt (i)];
1858: if (c < 0x0100) {
1859: if (9 + 21 < k + 1) {
1860: k = 0;
1861: break;
1862: }
1863: b[k++] = (byte) c;
1864: } else {
1865: if (9 + 21 < k + 2) {
1866: k = 0;
1867: break;
1868: }
1869: b[k++] = (byte) (c >> 8);
1870: b[k++] = (byte) c;
1871: }
1872: }
1873: if (k == 0) {
1874: k = 9;
1875:
1876: for (int i = 0; i < l; i++) {
1877: int c = CharacterCode.chrCharToSJIS[dirName.charAt (i)];
1878: if (c < 0x0100) {
1879: if (9 + 5 < k + 1) {
1880: break;
1881: }
1882: b[k++] = (byte) c;
1883: } else {
1884: if (9 + 5 < k + 2) {
1885: break;
1886: }
1887: b[k++] = (byte) (c >> 8);
1888: b[k++] = (byte) c;
1889: }
1890: }
1891:
1892: b[k++] = (byte) '_';
1893:
1894: int j = 9 + 21;
1895: for (int i = l - 1; 0 <= i; i--) {
1896: int c = CharacterCode.chrCharToSJIS[dirName.charAt (i)];
1897: if (c < 0x0100) {
1898: if (j - 1 < k) {
1899: break;
1900: }
1901: b[--j] = (byte) c;
1902: } else {
1903: if (j - 2 < k) {
1904: break;
1905: }
1906: b[--j] = (byte) c;
1907: b[--j] = (byte) (c >> 8);
1908: }
1909: }
1910: if (k < j) {
1911: while (j < 9 + 21) {
1912: b[k++] = b[j++];
1913: }
1914: } else {
1915: k = 9 + 21;
1916: }
1917: }
1918: for (int i = k; i <= 31; i++) {
1919: b[i] = '\0';
1920: }
1921: if (b[27] != '\0') {
1922: b[30] = b[29];
1923: b[29] = b[28];
1924: b[28] = b[27];
1925: b[27] = (byte) '.';
1926: }
1927: if (HFS_DEBUG_FILE_INFO) {
1928: System.out.print ("FILES ");
1929: hfuPrintFileInfo (b);
1930: }
1931:
1932: deque.addLast (b);
1933: }
1934: }
1935: childrenLoop:
1936: for (String childName : children) {
1937: int l = childName.length ();
1938: if (l == 0) {
1939: continue childrenLoop;
1940: }
1941:
1942: boolean isHumansys = false;
1943: boolean isCommandx = false;
1944: if (isRoot) {
1945: if (childName.equals (".") || childName.equals ("..")) {
1946: continue childrenLoop;
1947: }
1948: isHumansys = childName.equalsIgnoreCase ("HUMAN.SYS");
1949: if (isHumansys) {
1950: humansysRequired = false;
1951: }
1952: isCommandx = childName.equalsIgnoreCase ("COMMAND.X");
1953: if (isCommandx) {
1954: commandxRequired = false;
1955: }
1956: }
1957:
1958:
1959:
1960:
1961:
1962: byte[] b = new byte[32];
1963:
1964:
1965:
1966:
1967:
1968: int k = 9;
1969: for (int i = 0; i < l; i++) {
1970: int c = CharacterCode.chrCharToSJIS[childName.charAt (i)];
1971: if (c <= 0x1f ||
1972: c == '/' || c == '\\' ||
1973: (c == '-' && i == 0) ||
1974: c == '"' || c == '\'' ||
1975:
1976: c == ',' ||
1977: c == ';' || c == '<' || c == '=' || c == '>' ||
1978: c == '[' || c == ']' ||
1979: c == '|') {
1980: continue childrenLoop;
1981: }
1982: if (c < 0x0100) {
1983: if (k >= 31) {
1984: continue childrenLoop;
1985: }
1986: b[k++] = (byte) c;
1987: } else {
1988: if (k >= 30) {
1989: continue childrenLoop;
1990: }
1991: b[k++] = (byte) (c >> 8);
1992: b[k++] = (byte) c;
1993: }
1994: }
1995: for (int i = k; i <= 31; i++) {
1996: b[i] = '\0';
1997: }
1998:
1999:
2000:
2001:
2002:
2003:
2004:
2005:
2006: int m = (b[k - 1] == '.' ? k :
2007: k >= 9 + 3 && b[k - 2] == '.' ? k - 2 :
2008: k >= 9 + 4 && b[k - 3] == '.' ? k - 3 :
2009: k >= 9 + 5 && b[k - 4] == '.' ? k - 4 :
2010: k);
2011: if (m > 9 + 18) {
2012: continue childrenLoop;
2013: }
2014: {
2015: int i = 0;
2016: for (int j = 9; j < m; j++) {
2017: w[i++] = b[j];
2018: }
2019: while (i <= 17) {
2020: w[i++] = '\0';
2021: }
2022: for (int j = m + 1; j < k; j++) {
2023: w[i++] = b[j];
2024: }
2025: while (i <= 20) {
2026: w[i++] = '\0';
2027: }
2028: }
2029:
2030:
2031:
2032:
2033:
2034:
2035:
2036:
2037:
2038:
2039:
2040: {
2041: int f = 0x20;
2042: for (int i = 0; i <= 20; i++) {
2043: int c = w[i] & 255;
2044: int d = w[21 + i] & 255;
2045: if (d != '?' && ('A' <= c && c <= 'Z' ? c | f : c) != d) {
2046: continue childrenLoop;
2047: }
2048: f = f != 0x00 && (0x81 <= c && c <= 0x9f || 0xe0 <= c && c <= 0xef) ? 0x00 : 0x20;
2049: }
2050: }
2051:
2052: File file = new File (parent, childName);
2053: if (0xffffffffL < file.length ()) {
2054: continue childrenLoop;
2055: }
2056: hfuFileInfo (file, b);
2057: if (isHumansys) {
2058: b[0] |= HumanMedia.HUM_SYSTEM;
2059: }
2060: if (HFS_DEBUG_FILE_INFO) {
2061: System.out.print ("FILES ");
2062: hfuPrintFileInfo (b);
2063: }
2064: if ((b[0] & hfsRequest13Mode) == 0) {
2065: continue childrenLoop;
2066: }
2067:
2068: deque.addLast (b);
2069: }
2070: if (false) {
2071: if (isRoot) {
2072: if (humansysRequired) {
2073:
2074: }
2075: if (commandxRequired) {
2076:
2077: }
2078: }
2079: }
2080: if (deque.isEmpty ()) {
2081: hfsRequest18Result = DOS_FILE_NOT_FOUND;
2082: hfsState = HFS_STATE_DONE;
2083: return;
2084: }
2085: hfuFilesBufferCounter++;
2086: hfuFilesBufferToArrayDeque.put (hfuFilesBufferCounter, deque);
2087: hfsRequest18Result = 0;
2088: hfsState = HFS_STATE_X68K;
2089: }
2090:
2091:
2092: public void hfuCallFilesX68k () throws M68kException {
2093: MC68060.mmuWriteLongData (hfsRequest18Param + 2, HFU_FILES_MAGIC, XEiJ.regSRS);
2094: MC68060.mmuWriteLongData (hfsRequest18Param + 6, hfuFilesBufferCounter, XEiJ.regSRS);
2095:
2096:
2097: int key = hfuFilesBufferCounter;
2098: ArrayDeque<byte[]> deque = hfuFilesBufferToArrayDeque.get (key);
2099: if (deque == null) {
2100: hfsRequest18Result = DOS_NO_MORE_FILES;
2101: hfsState = HFS_STATE_DONE;
2102: return;
2103: }
2104: byte[] b = deque.pollFirst ();
2105: MC68060.mmuWriteByteArray (hfsRequest18Param + 21, b, 0, 32, XEiJ.regSRS);
2106: if (deque.isEmpty ()) {
2107: MC68060.mmuWriteLongData (hfsRequest18Param + 2, 0, XEiJ.regSRS);
2108: MC68060.mmuWriteLongData (hfsRequest18Param + 6, 0, XEiJ.regSRS);
2109: hfuFilesBufferToArrayDeque.remove (key);
2110: }
2111: hfsRequest18Result = 0;
2112: hfsState = HFS_STATE_DONE;
2113: }
2114:
2115:
2116:
2117:
2118:
2119:
2120:
2121:
2122:
2123:
2124:
2125:
2126:
2127:
2128:
2129: public void hfuCallNfiles () throws M68kException {
2130: if (HFS_COMMAND_TRACE && hfsCommandTraceOn) {
2131: int pc = MainMemory.mmrGetLevelZeroPC ();
2132: System.out.println (LabeledAddress.lblSearch (new StringBuilder (), pc).toString ());
2133: System.out.printf ("%08x nfiles()\n",
2134: pc);
2135: }
2136: if (!abuInserted) {
2137: hfsRequest3Error = DEV_RETRY | DEV_ABORT | DEV_INSERT_MEDIA;
2138: hfsRequest18Result = -1;
2139: hfsState = HFS_STATE_DONE;
2140: return;
2141: }
2142: if (MC68060.mmuReadLongData (hfsRequest18Param + 2, XEiJ.regSRS) != HFU_FILES_MAGIC) {
2143: hfsRequest18Result = DOS_NO_MORE_FILES;
2144: hfsState = HFS_STATE_DONE;
2145: return;
2146: }
2147: int key = MC68060.mmuReadLongData (hfsRequest18Param + 6, XEiJ.regSRS);
2148: ArrayDeque<byte[]> deque = hfuFilesBufferToArrayDeque.get (key);
2149: if (deque == null) {
2150: hfsRequest18Result = DOS_NO_MORE_FILES;
2151: hfsState = HFS_STATE_DONE;
2152: return;
2153: }
2154: byte[] b = deque.pollFirst ();
2155: MC68060.mmuWriteByteArray (hfsRequest18Param + 21, b, 0, 32, XEiJ.regSRS);
2156: if (deque.isEmpty ()) {
2157: MC68060.mmuWriteLongData (hfsRequest18Param + 2, 0, XEiJ.regSRS);
2158: MC68060.mmuWriteLongData (hfsRequest18Param + 6, 0, XEiJ.regSRS);
2159: hfuFilesBufferToArrayDeque.remove (key);
2160: }
2161: hfsRequest18Result = 0;
2162: hfsState = HFS_STATE_DONE;
2163: }
2164:
2165:
2166:
2167:
2168:
2169:
2170:
2171:
2172:
2173:
2174:
2175:
2176:
2177:
2178:
2179:
2180:
2181:
2182: public void hfuCallCreateNewfile () throws M68kException {
2183: byte[] w = hfuTargetNameArray1;
2184: MC68060.mmuReadByteArray (hfsRequest14Namests, w, 0, 88, XEiJ.regSRS);
2185: hfuTargetName1 = hfuNamestsToPath (w, true);
2186: if (hfuTargetName1 == null) {
2187: hfsRequest18Result = DOS_ILLEGAL_FILE_NAME;
2188: hfsState = HFS_STATE_DONE;
2189: return;
2190: }
2191: if (HFS_COMMAND_TRACE && hfsCommandTraceOn) {
2192: int pc = MainMemory.mmrGetLevelZeroPC ();
2193: System.out.println (LabeledAddress.lblSearch (new StringBuilder (), pc).toString ());
2194: System.out.printf ("%08x %s(fcb=0x%08x,name=\"%s\",mode=0x%02x)\n",
2195: pc, hfsRequest18Param == 0 ? "newfile" : "create", hfsRequest22Fcb, hfuTargetName1, hfsRequest13Mode);
2196: }
2197: if (!abuInserted) {
2198: hfsRequest3Error = DEV_RETRY | DEV_ABORT | DEV_INSERT_MEDIA;
2199: hfsRequest18Result = -1;
2200: hfsState = HFS_STATE_DONE;
2201: return;
2202: }
2203: if (abuWriteProtected) {
2204: hfsRequest3Error = DEV_IGNORE | DEV_RETRY | DEV_ABORT | DEV_CANNOT_WRITE;
2205: hfsRequest18Result = -1;
2206: hfsState = HFS_STATE_DONE;
2207: return;
2208: }
2209: hfsRequest18Result = 0;
2210: hfsState = HFS_STATE_HOST;
2211: }
2212:
2213:
2214: public void hfuCallCreateNewfileHost () {
2215: byte[] b = hfuTargetNameArray2;
2216: File file = new File (hfuTargetName1);
2217: if (file.exists ()) {
2218: if (hfsRequest18Param == 0) {
2219: hfsRequest18Result = DOS_FILE_EXISTS;
2220: hfsState = HFS_STATE_DONE;
2221: return;
2222: }
2223:
2224:
2225:
2226: if (file.isDirectory () ||
2227: !file.delete ()) {
2228: hfsRequest18Result = DOS_CANNOT_WRITE;
2229: hfsState = HFS_STATE_DONE;
2230: return;
2231: }
2232: }
2233: RandomAccessFile raf;
2234: try {
2235: raf = new RandomAccessFile (file, "rw");
2236: } catch (IOException ioe) {
2237: hfsRequest18Result = DOS_CANNOT_WRITE;
2238: hfsState = HFS_STATE_DONE;
2239: return;
2240: }
2241: if (hfuFcbToHandle.isEmpty ()) {
2242: prevent ();
2243: }
2244: hfuFileInfo (file, b);
2245: if (HFS_DEBUG_FILE_INFO) {
2246: System.out.print ("CREATE ");
2247: hfuPrintFileInfo (b);
2248: }
2249: int fcb = hfsRequest22Fcb;
2250: HFHandle handle = hfuTargetHandle = hfuNewHandle (fcb, file, raf);
2251: hfuFcbToHandle.put (fcb, handle);
2252: hfsRequest18Result = 0;
2253: hfsState = HFS_STATE_X68K;
2254: }
2255:
2256:
2257: public void hfuCallCreateNewfileX68k () throws M68kException {
2258: HFHandle handle = hfuTargetHandle;
2259: int fcb = handle.hfhFcb;
2260: byte[] w = hfuTargetNameArray1;
2261: byte[] b = hfuTargetNameArray2;
2262:
2263:
2264:
2265:
2266:
2267:
2268:
2269:
2270:
2271:
2272:
2273:
2274:
2275:
2276:
2277:
2278:
2279:
2280: for (int i = 0; i < 8 + 3; i++) {
2281: MC68060.mmuWriteByteData (fcb + 36 + i, w[67 + i], XEiJ.regSRS);
2282: }
2283: MC68060.mmuWriteByteData (fcb + 47, b[0], XEiJ.regSRS);
2284: for (int i = 0; i < 10; i++) {
2285: MC68060.mmuWriteByteData (fcb + 48 + i, w[78 + i], XEiJ.regSRS);
2286: }
2287: MC68060.mmuWriteLongData (fcb + 58, ByteArray.byaRls (b, 1), XEiJ.regSRS);
2288: MC68060.mmuWriteWordData (fcb + 62, 0, XEiJ.regSRS);
2289: MC68060.mmuWriteLongData (fcb + 64, ByteArray.byaRls (b, 5), XEiJ.regSRS);
2290: hfsRequest18Result = 0;
2291: hfsState = HFS_STATE_DONE;
2292: }
2293:
2294:
2295:
2296:
2297:
2298:
2299:
2300:
2301:
2302:
2303:
2304:
2305:
2306:
2307:
2308: public void hfuCallOpen () throws M68kException {
2309: byte[] w = hfuTargetNameArray1;
2310: MC68060.mmuReadByteArray (hfsRequest14Namests, w, 0, 88, XEiJ.regSRS);
2311: hfuTargetName1 = hfuNamestsToPath (w, true);
2312: if (hfuTargetName1 == null) {
2313: hfsRequest18Result = DOS_ILLEGAL_FILE_NAME;
2314: hfsState = HFS_STATE_DONE;
2315: return;
2316: }
2317: int fcb = hfsRequest22Fcb;
2318: hfuTargetOpenMode = MC68060.mmuReadByteZeroData (fcb + 14, XEiJ.regSRS);
2319: if (HFS_COMMAND_TRACE && hfsCommandTraceOn) {
2320: int pc = MainMemory.mmrGetLevelZeroPC ();
2321: System.out.println (LabeledAddress.lblSearch (new StringBuilder (), pc).toString ());
2322: System.out.printf ("%08x open(fcb=0x%08x,name=\"%s\",mode=0x%02x)\n",
2323: pc, hfsRequest22Fcb, hfuTargetName1, hfuTargetOpenMode);
2324: }
2325: if (!abuInserted) {
2326: hfsRequest3Error = DEV_RETRY | DEV_ABORT | DEV_INSERT_MEDIA;
2327: hfsRequest18Result = -1;
2328: hfsState = HFS_STATE_DONE;
2329: return;
2330: }
2331: if (hfuTargetOpenMode != 0 && abuWriteProtected) {
2332: hfsRequest3Error = DEV_IGNORE | DEV_RETRY | DEV_ABORT | DEV_CANNOT_WRITE;
2333: hfsRequest18Result = -1;
2334: hfsState = HFS_STATE_DONE;
2335: return;
2336: }
2337: hfsRequest18Result = 0;
2338: hfsState = HFS_STATE_HOST;
2339: }
2340:
2341:
2342: public void hfuCallOpenHost () {
2343: byte[] b = hfuTargetNameArray2;
2344: File file = new File (hfuTargetName1);
2345:
2346:
2347:
2348:
2349: if (!file.exists ()) {
2350: hfsRequest18Result = DOS_FILE_NOT_FOUND;
2351: hfsState = HFS_STATE_DONE;
2352: return;
2353: }
2354: if (0xffffffffL < file.length ()) {
2355: hfsRequest18Result = DOS_FILE_NOT_FOUND;
2356: hfsState = HFS_STATE_DONE;
2357: return;
2358: }
2359: hfuFileInfo (file, b);
2360: if (HFS_DEBUG_FILE_INFO) {
2361: System.out.print ("OPEN ");
2362: hfuPrintFileInfo (b);
2363: }
2364: RandomAccessFile raf;
2365: try {
2366: raf = new RandomAccessFile (file, hfuTargetOpenMode == 0 ? "r" : "rw");
2367: if (HFS_UTF8_WARNING &&
2368: hfsUTF8WarningOn &&
2369: !hfsUTF8WarningSet.contains (hfuTargetName1)) {
2370: hfsUTF8WarningSet.add (hfuTargetName1);
2371:
2372: int ll = (int) Math.min (4096, file.length ());
2373: byte[] bb = new byte[ll];
2374: int kk = 0;
2375: while (kk < ll) {
2376: int tt = raf.read (bb, kk, ll - kk);
2377: if (tt < 0) {
2378: break;
2379: }
2380: kk += tt;
2381: }
2382: raf.seek (0);
2383: if (!hfuUTF8WarningTest (bb, kk)) {
2384: System.out.println ("The character encoding of " + hfuTargetName1 + " is UTF-8, not SJIS.");
2385: }
2386: }
2387: } catch (IOException ioe) {
2388: hfsRequest18Result = DOS_FILE_NOT_FOUND;
2389: hfsState = HFS_STATE_DONE;
2390: return;
2391: }
2392: if (hfuFcbToHandle.isEmpty ()) {
2393: prevent ();
2394: }
2395: int fcb = hfsRequest22Fcb;
2396: HFHandle handle = hfuTargetHandle = hfuNewHandle (fcb, file, raf);
2397: hfuFcbToHandle.put (fcb, handle);
2398: hfsRequest18Result = 0;
2399: hfsState = HFS_STATE_X68K;
2400: }
2401:
2402:
2403:
2404: private static boolean hfuUTF8WarningTest (byte[] b, int k) {
2405:
2406:
2407:
2408:
2409:
2410: for (int i = 0; i < k; i++) {
2411: int c = b[i] & 0xff;
2412: if (c <= 0x7f) {
2413: if (c != 0x00) {
2414: continue;
2415: }
2416: } else if (c <= 0xbf) {
2417: } else if (c <= 0xdf) {
2418: int d = i + 1 < k ? b[i + 1] & 0xff : -1;
2419: if (d == -1 || (0x80 <= d && d <= 0xbf)) {
2420: i++;
2421: continue;
2422: }
2423: } else if (c <= 0xef) {
2424: int d = i + 1 < k ? b[i + 1] & 0xff : -1;
2425: int e = i + 2 < k ? b[i + 2] & 0xff : -1;
2426: if ((d == -1 || (0x80 <= d && d <= 0xbf)) &&
2427: (e == -1 || (0x80 <= e && e <= 0xbf))) {
2428: i += 2;
2429: continue;
2430: }
2431: } else if (c <= 0xf7) {
2432: int d = i + 1 < k ? b[i + 1] & 0xff : -1;
2433: int e = i + 2 < k ? b[i + 2] & 0xff : -1;
2434: int f = i + 3 < k ? b[i + 3] & 0xff : -1;
2435: if ((d == -1 || (0x80 <= d && d <= 0xbf)) &&
2436: (e == -1 || (0x80 <= e && e <= 0xbf)) &&
2437: (f == -1 || (0x80 <= f && f <= 0xbf))) {
2438: i += 3;
2439: continue;
2440: }
2441: } else {
2442: }
2443: return true;
2444: }
2445:
2446:
2447:
2448:
2449:
2450: for (int i = 0; i < k; i++) {
2451: int c = b[i] & 0xff;
2452: if ((0x00 <= c && c <= 0x7f) ||
2453: (0xa0 <= c && c <= 0xdf)) {
2454: if (c != 0x00) {
2455: continue;
2456: }
2457: } else if (c == 0x80 ||
2458: (0xf0 <= c && c <= 0xf5)) {
2459: if (k <= i + 1 || b[i + 1] != 0x00) {
2460: i++;
2461: continue;
2462: }
2463: } else if ((0x81 <= c && c <= 0x9f) ||
2464: (0xe0 <= c && c <= 0xef)) {
2465: int d = i + 1 < k ? b[i + 1] & 0xff : -1;
2466: if (d == -1 || (0x40 <= d && d <= 0xfc && d != 0x7f)) {
2467: i++;
2468: continue;
2469: }
2470: } else {
2471: }
2472: return false;
2473: }
2474: return true;
2475: }
2476:
2477:
2478: public void hfuCallOpenX68k () throws M68kException {
2479: HFHandle handle = hfuTargetHandle;
2480: int fcb = handle.hfhFcb;
2481: byte[] w = hfuTargetNameArray1;
2482: byte[] b = hfuTargetNameArray2;
2483:
2484:
2485:
2486:
2487:
2488:
2489:
2490:
2491:
2492:
2493:
2494:
2495:
2496:
2497:
2498:
2499:
2500:
2501: for (int i = 0; i < 8 + 3; i++) {
2502: MC68060.mmuWriteByteData (fcb + 36 + i, w[67 + i], XEiJ.regSRS);
2503: }
2504: MC68060.mmuWriteByteData (fcb + 47, b[0], XEiJ.regSRS);
2505: for (int i = 0; i < 10; i++) {
2506: MC68060.mmuWriteByteData (fcb + 48 + i, w[78 + i], XEiJ.regSRS);
2507: }
2508: MC68060.mmuWriteLongData (fcb + 58, ByteArray.byaRls (b, 1), XEiJ.regSRS);
2509: MC68060.mmuWriteWordData (fcb + 62, 0, XEiJ.regSRS);
2510: MC68060.mmuWriteLongData (fcb + 64, ByteArray.byaRls (b, 5), XEiJ.regSRS);
2511: hfsRequest18Result = 0;
2512: hfsState = HFS_STATE_DONE;
2513: }
2514:
2515:
2516:
2517:
2518:
2519:
2520:
2521:
2522:
2523:
2524:
2525:
2526:
2527:
2528:
2529: public void hfuCallClose () throws M68kException {
2530: if (HFS_COMMAND_TRACE && hfsCommandTraceOn) {
2531: int pc = MainMemory.mmrGetLevelZeroPC ();
2532: System.out.println (LabeledAddress.lblSearch (new StringBuilder (), pc).toString ());
2533: System.out.printf ("%08x close(fcb=0x%08x)\n",
2534: pc, hfsRequest22Fcb);
2535: }
2536: if (!abuInserted) {
2537: hfsRequest3Error = DEV_RETRY | DEV_ABORT | DEV_INSERT_MEDIA;
2538: hfsRequest18Result = -1;
2539: hfsState = HFS_STATE_DONE;
2540: return;
2541: }
2542: int fcb = hfsRequest22Fcb;
2543: HFHandle handle = hfuTargetHandle = hfuFcbToHandle.remove (fcb);
2544: if (handle == null) {
2545:
2546: hfsRequest18Result = 0;
2547: hfsState = HFS_STATE_DONE;
2548: return;
2549: }
2550: hfsRequest18Result = 0;
2551: hfsState = HFS_STATE_HOST;
2552: }
2553:
2554:
2555: public void hfuCallCloseHost () {
2556: HFHandle handle = hfuTargetHandle;
2557: if (hfsRequest18Result != 0) {
2558: File file = handle.hfhFile;
2559: if (!file.setLastModified (hfuTargetLastModified)) {
2560: System.out.println ((Multilingual.mlnJapanese ? "最終更新日時を設定できません: " : "Could not set last modified date and time: ") + handle.toString ());
2561: }
2562: if (hfuFcbToHandle.isEmpty ()) {
2563: allow ();
2564: }
2565: hfuRecycleHandle (handle);
2566: handle = hfuTargetHandle = null;
2567: hfsRequest18Result = 0;
2568: hfsState = HFS_STATE_DONE;
2569: return;
2570: }
2571: RandomAccessFile raf = handle.hfhRaf;
2572:
2573: if (handle.hfhDirty) {
2574: if (HFS_BUFFER_TRACE) {
2575: 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);
2576: }
2577: try {
2578: handle.hfhRaf.seek (handle.hfhStart);
2579: } catch (IOException ioe) {
2580: System.out.println ((Multilingual.mlnJapanese ? "シークエラー: " : "Seek error: ") + handle.toString ());
2581: }
2582: try {
2583: handle.hfhRaf.write (handle.hfhBuffer, 0, (int) (handle.hfhEnd - handle.hfhStart));
2584: } catch (IOException ioe) {
2585: System.out.println ((Multilingual.mlnJapanese ? "遅延書き込みに失敗しました: " : "Delayed write failed: ") + handle.toString ());
2586: }
2587: handle.hfhDirty = false;
2588: }
2589: try {
2590: raf.close ();
2591: } catch (IOException ioe) {
2592: System.out.println ((Multilingual.mlnJapanese ? "クローズエラー: " : "Close error: ") + handle.toString ());
2593: }
2594: hfsRequest18Result = 0;
2595: hfsState = HFS_STATE_X68K;
2596: }
2597:
2598:
2599: public void hfuCallCloseX68k () throws M68kException {
2600: HFHandle handle = hfuTargetHandle;
2601: int fcb = handle.hfhFcb;
2602: if ((MC68060.mmuReadByteZeroData (fcb + 14, XEiJ.regSRS) & 15) == 0) {
2603: if (hfuFcbToHandle.isEmpty ()) {
2604: allow ();
2605: }
2606: hfuRecycleHandle (handle);
2607: handle = hfuTargetHandle = null;
2608: hfsRequest18Result = 0;
2609: hfsState = HFS_STATE_DONE;
2610: return;
2611: }
2612: if ((MC68060.mmuReadByteZeroData (fcb + 1, XEiJ.regSRS) & 0x40) != 0) {
2613: hfuTargetLastModified = System.currentTimeMillis ();
2614: } else {
2615: int time = MC68060.mmuReadWordZeroData (fcb + 58, XEiJ.regSRS);
2616: int date = MC68060.mmuReadWordZeroData (fcb + 60, XEiJ.regSRS);
2617: hfuTargetLastModified = DnT.dntCmilYearMontMdayHourMinuSeco (
2618: (date >> 9) + 1980, date >> 5 & 15, date & 31,
2619: time >> 11, time >> 5 & 63, (time & 31) << 1) - RP5C15.rtcCmilGap;
2620: }
2621: hfsRequest18Result = 1;
2622: hfsState = HFS_STATE_HOST;
2623: }
2624:
2625:
2626:
2627:
2628:
2629:
2630:
2631:
2632:
2633:
2634:
2635:
2636:
2637:
2638:
2639: public void hfuCallRead () throws M68kException {
2640: if (HFS_BUFFER_TRACE || (HFS_COMMAND_TRACE && hfsCommandTraceOn)) {
2641: int pc = MainMemory.mmrGetLevelZeroPC ();
2642: System.out.println (LabeledAddress.lblSearch (new StringBuilder (), pc).toString ());
2643: System.out.printf ("%08x read(fcb=0x%08x,address=0x%08x,length=0x%08x)\n",
2644: pc, hfsRequest22Fcb, hfsRequest14Namests, hfsRequest18Param);
2645: }
2646: if (!abuInserted) {
2647: hfsRequest3Error = DEV_RETRY | DEV_ABORT | DEV_INSERT_MEDIA;
2648: hfsRequest18Result = -1;
2649: hfsState = HFS_STATE_DONE;
2650: return;
2651: }
2652: int fcb = hfsRequest22Fcb;
2653: HFHandle handle = hfuTargetHandle = hfuFcbToHandle.get (fcb);
2654: if (handle == null) {
2655: hfsRequest18Result = DOS_HANDLE_IS_NOT_OPENED;
2656: hfsState = HFS_STATE_DONE;
2657: return;
2658: }
2659: hfuTargetLength = hfsRequest18Param & 0xffffffffL;
2660: if (HFS_BUFFER_TRACE) {
2661: System.out.printf ("length=%d\n", hfuTargetLength);
2662: }
2663: hfuTargetPosition = MC68060.mmuReadLongData (fcb + 6, XEiJ.regSRS) & 0xffffffffL;
2664: if (HFS_BUFFER_TRACE) {
2665: System.out.printf ("position=%d\n", hfuTargetPosition);
2666: }
2667: hfuTargetFileSize = MC68060.mmuReadLongData (fcb + 64, XEiJ.regSRS) & 0xffffffffL;
2668: if (HFS_BUFFER_TRACE) {
2669: System.out.printf ("fileSize=%d\n", hfuTargetFileSize);
2670: }
2671: hfuTargetLength = Math.min (hfuTargetLength, hfuTargetFileSize - hfuTargetPosition);
2672: if (HFS_BUFFER_TRACE) {
2673: System.out.printf ("length=%d\n", hfuTargetLength);
2674: }
2675: if (hfuTargetLength == 0L) {
2676: hfsRequest18Result = 0;
2677: hfsState = HFS_STATE_DONE;
2678: return;
2679: }
2680: hfuTargetAddress = hfsRequest14Namests & 0xffffffffL;
2681: if (HFS_BUFFER_TRACE) {
2682: System.out.printf ("address=0x%08x\n", hfuTargetAddress);
2683: }
2684: hfuTargetTransferred = 0L;
2685: if (HFS_BUFFER_TRACE) {
2686: System.out.printf ("transferred=%d\n", hfuTargetTransferred);
2687: }
2688:
2689:
2690:
2691:
2692:
2693:
2694:
2695:
2696:
2697:
2698:
2699:
2700:
2701:
2702:
2703:
2704:
2705:
2706:
2707: if (hfuTargetFileSize == 0 ||
2708: (0 < handle.hfhEnd &&
2709: handle.hfhStart <= hfuTargetPosition && hfuTargetPosition < handle.hfhStart + HFS_BUFFER_SIZE)) {
2710:
2711: hfsRequest18Result = 0;
2712: hfsState = HFS_STATE_X68K;
2713: } else {
2714:
2715: hfsRequest18Result = 0;
2716: hfsState = HFS_STATE_HOST;
2717: }
2718: }
2719:
2720:
2721: public void hfuCallReadHost () {
2722: HFHandle handle = hfuTargetHandle;
2723: RandomAccessFile raf = handle.hfhRaf;
2724:
2725: if (handle.hfhDirty) {
2726: if (HFS_BUFFER_TRACE) {
2727: 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);
2728: }
2729: try {
2730: raf.seek (handle.hfhStart);
2731: } catch (IOException ioe) {
2732: System.out.println ((Multilingual.mlnJapanese ? "シークエラー: " : "Seek error: ") + handle.toString ());
2733: }
2734: try {
2735: raf.write (handle.hfhBuffer, 0, (int) (handle.hfhEnd - handle.hfhStart));
2736: } catch (IOException ioe) {
2737: System.out.println ((Multilingual.mlnJapanese ? "遅延書き込みに失敗しました: " : "Delayed write failed: ") + handle.toString ());
2738: }
2739: handle.hfhDirty = false;
2740: }
2741:
2742: int ll = (int) Math.min (HFS_BUFFER_SIZE,
2743: hfuTargetFileSize - hfuTargetPosition
2744: );
2745: int kk = 0;
2746: Arrays.fill (handle.hfhBuffer, (byte) 0);
2747: handle.hfhStart = hfuTargetPosition;
2748: handle.hfhEnd = hfuTargetPosition + ll;
2749: handle.hfhDirty = false;
2750: if (HFS_BUFFER_TRACE) {
2751: 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);
2752: }
2753: if (0 < ll) {
2754: try {
2755: raf.seek (hfuTargetPosition);
2756: } catch (IOException ioe) {
2757: System.out.println ((Multilingual.mlnJapanese ? "シークエラー: " : "Seek error: ") + handle.toString ());
2758: }
2759: try {
2760: while (kk < ll) {
2761: int tt = raf.read (handle.hfhBuffer, kk, ll - kk);
2762: if (tt < 0) {
2763:
2764: hfsRequest18Result = -1;
2765: hfsState = HFS_STATE_DONE;
2766: return;
2767: }
2768: kk += tt;
2769: }
2770: } catch (IOException ioe) {
2771: System.out.println ((Multilingual.mlnJapanese ? "リードエラー: " : "Read error: ") + handle.toString ());
2772: hfsRequest18Result = -1;
2773: hfsState = HFS_STATE_DONE;
2774: return;
2775: }
2776: }
2777:
2778: hfsRequest18Result = 0;
2779: hfsState = HFS_STATE_X68K;
2780: }
2781:
2782:
2783: public void hfuCallReadX68k () throws M68kException {
2784: HFHandle handle = hfuTargetHandle;
2785: int fcb = handle.hfhFcb;
2786:
2787: long tt = Math.min (hfuTargetLength - hfuTargetTransferred,
2788: handle.hfhEnd - hfuTargetPosition
2789: );
2790: long t = Math.min (HFS_BUFFER_STEP, tt);
2791: if (HFS_BUFFER_TRACE) {
2792: System.out.printf ("t=%d\n", t);
2793: }
2794: MC68060.mmuWriteByteArray ((int) (hfuTargetAddress + hfuTargetTransferred),
2795: handle.hfhBuffer,
2796: (int) (hfuTargetPosition - handle.hfhStart),
2797: (int) t,
2798: XEiJ.regSRS);
2799: hfuTargetPosition += t;
2800: if (HFS_BUFFER_TRACE) {
2801: System.out.printf ("position=%d\n", hfuTargetPosition);
2802: }
2803: MC68060.mmuWriteLongData (fcb + 6, (int) hfuTargetPosition, XEiJ.regSRS);
2804: hfuTargetTransferred += t;
2805: if (HFS_BUFFER_TRACE) {
2806: System.out.printf ("transferred=%d\n", hfuTargetTransferred);
2807: }
2808: if (hfuTargetLength <= hfuTargetTransferred) {
2809: hfsRequest18Result = (int) hfuTargetTransferred;
2810: hfsState = HFS_STATE_DONE;
2811: return;
2812: }
2813: if (t < tt) {
2814:
2815: hfsRequest18Result = 0;
2816: hfsState = HFS_STATE_X68K;
2817: } else {
2818:
2819: hfsRequest18Result = 0;
2820: hfsState = HFS_STATE_HOST;
2821: }
2822: }
2823:
2824:
2825:
2826:
2827:
2828:
2829:
2830:
2831:
2832:
2833:
2834:
2835:
2836:
2837:
2838: public void hfuCallWrite () throws M68kException {
2839: if (HFS_BUFFER_TRACE || (HFS_COMMAND_TRACE && hfsCommandTraceOn)) {
2840: int pc = MainMemory.mmrGetLevelZeroPC ();
2841: System.out.println (LabeledAddress.lblSearch (new StringBuilder (), pc).toString ());
2842: System.out.printf ("%08x write(fcb=0x%08x,address=0x%08x,length=0x%08x)\n",
2843: pc, hfsRequest22Fcb, hfsRequest14Namests, hfsRequest18Param);
2844: }
2845: if (!abuInserted) {
2846: hfsRequest3Error = DEV_RETRY | DEV_ABORT | DEV_INSERT_MEDIA;
2847: hfsRequest18Result = -1;
2848: hfsState = HFS_STATE_DONE;
2849: return;
2850: }
2851: if (abuWriteProtected) {
2852: hfsRequest3Error = DEV_IGNORE | DEV_RETRY | DEV_ABORT | DEV_CANNOT_WRITE;
2853: hfsRequest18Result = -1;
2854: hfsState = HFS_STATE_DONE;
2855: return;
2856: }
2857: int fcb = hfsRequest22Fcb;
2858: HFHandle handle = hfuTargetHandle = hfuFcbToHandle.get (fcb);
2859: if (handle == null) {
2860: hfsRequest18Result = DOS_HANDLE_IS_NOT_OPENED;
2861: hfsState = HFS_STATE_DONE;
2862: return;
2863: }
2864: hfuTargetLength = hfsRequest18Param & 0xffffffffL;
2865: if (HFS_BUFFER_TRACE) {
2866: System.out.printf ("length=%d\n", hfuTargetLength);
2867: }
2868: hfuTargetPosition = MC68060.mmuReadLongData (fcb + 6, XEiJ.regSRS) & 0xffffffffL;
2869: if (HFS_BUFFER_TRACE) {
2870: System.out.printf ("position=%d\n", hfuTargetPosition);
2871: }
2872: hfuTargetFileSize = MC68060.mmuReadLongData (fcb + 64, XEiJ.regSRS) & 0xffffffffL;
2873: if (HFS_BUFFER_TRACE) {
2874: System.out.printf ("fileSize=%d\n", hfuTargetFileSize);
2875: }
2876: if (hfuTargetLength == 0L) {
2877: if (hfuTargetFileSize <= hfuTargetPosition) {
2878: hfsRequest18Result = 0;
2879: hfsState = HFS_STATE_DONE;
2880: return;
2881: }
2882: MC68060.mmuWriteLongData (fcb + 64, (int) hfuTargetPosition, XEiJ.regSRS);
2883: hfsRequest18Result = 1;
2884: hfsState = HFS_STATE_HOST;
2885: return;
2886: }
2887: if (0xffffffffL < hfuTargetPosition + hfuTargetLength) {
2888: hfuTargetLength = 0xffffffffL - hfuTargetPosition;
2889: if (HFS_BUFFER_TRACE) {
2890: System.out.printf ("length=%d\n", hfuTargetLength);
2891: }
2892: if (hfuTargetLength == 0L) {
2893: hfsRequest18Result = 0;
2894: hfsState = HFS_STATE_DONE;
2895: return;
2896: }
2897: }
2898: hfuTargetAddress = hfsRequest14Namests & 0xffffffffL;
2899: if (HFS_BUFFER_TRACE) {
2900: System.out.printf ("address=0x%08x\n", hfuTargetAddress);
2901: }
2902: hfuTargetTransferred = 0L;
2903: if (HFS_BUFFER_TRACE) {
2904: System.out.printf ("transferred=%d\n", hfuTargetTransferred);
2905: }
2906:
2907:
2908:
2909:
2910:
2911:
2912:
2913:
2914:
2915:
2916:
2917:
2918:
2919:
2920:
2921:
2922:
2923:
2924:
2925: if (hfuTargetFileSize == 0 ||
2926: (0 < handle.hfhEnd &&
2927: handle.hfhStart <= hfuTargetPosition && hfuTargetPosition < handle.hfhStart + HFS_BUFFER_SIZE)) {
2928:
2929: hfsRequest18Result = 0;
2930: hfsState = HFS_STATE_X68K;
2931: } else {
2932:
2933: hfsRequest18Result = 0;
2934: hfsState = HFS_STATE_HOST;
2935: }
2936: }
2937:
2938:
2939: public void hfuCallWriteHost () {
2940: HFHandle handle = hfuTargetHandle;
2941: RandomAccessFile raf = handle.hfhRaf;
2942: if (hfsRequest18Result != 0) {
2943: if (handle.hfhStart <= hfuTargetPosition && hfuTargetPosition < handle.hfhEnd) {
2944:
2945: Arrays.fill (handle.hfhBuffer, (int) (hfuTargetPosition - handle.hfhStart), (int) (handle.hfhEnd - handle.hfhStart), (byte) 0);
2946: handle.hfhEnd = hfuTargetPosition;
2947: if (HFS_BUFFER_TRACE) {
2948: 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);
2949: }
2950: }
2951: try {
2952: raf.seek (hfuTargetPosition);
2953: } catch (IOException ioe) {
2954: System.out.println ((Multilingual.mlnJapanese ? "シークエラー: " : "Seek error: ") + handle.toString ());
2955: }
2956:
2957: try {
2958: raf.setLength (hfuTargetPosition);
2959: } catch (IOException ioe) {
2960: System.out.println ((Multilingual.mlnJapanese ? "ファイルの長さを設定できません: " : "Could not set length of file: ") + handle.toString ());
2961: hfsRequest18Result = -1;
2962: hfsState = HFS_STATE_DONE;
2963: return;
2964: }
2965: hfsRequest18Result = 0;
2966: hfsState = HFS_STATE_DONE;
2967: return;
2968: }
2969:
2970: if (handle.hfhDirty) {
2971: if (HFS_BUFFER_TRACE) {
2972: 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);
2973: }
2974: try {
2975: raf.seek (handle.hfhStart);
2976: } catch (IOException ioe) {
2977: System.out.println ((Multilingual.mlnJapanese ? "シークエラー: " : "Seek error: ") + handle.toString ());
2978: }
2979: try {
2980: raf.write (handle.hfhBuffer, 0, (int) (handle.hfhEnd - handle.hfhStart));
2981: } catch (IOException ioe) {
2982: System.out.println ((Multilingual.mlnJapanese ? "遅延書き込みに失敗しました: " : "Delayed write failed: ") + handle.toString ());
2983: }
2984: handle.hfhDirty = false;
2985: }
2986:
2987: int ll = (int) Math.min (HFS_BUFFER_SIZE,
2988: hfuTargetFileSize - hfuTargetPosition
2989: );
2990: int kk = 0;
2991: Arrays.fill (handle.hfhBuffer, (byte) 0);
2992: handle.hfhStart = hfuTargetPosition;
2993: handle.hfhEnd = hfuTargetPosition + ll;
2994: handle.hfhDirty = false;
2995: if (HFS_BUFFER_TRACE) {
2996: 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);
2997: }
2998: if (0 < ll) {
2999: try {
3000: raf.seek (hfuTargetPosition);
3001: } catch (IOException ioe) {
3002: System.out.println ((Multilingual.mlnJapanese ? "シークエラー: " : "Seek error: ") + handle.toString ());
3003: }
3004: try {
3005: while (kk < ll) {
3006: int tt = raf.read (handle.hfhBuffer, kk, ll - kk);
3007: if (tt < 0) {
3008:
3009: hfsRequest18Result = -1;
3010: hfsState = HFS_STATE_DONE;
3011: return;
3012: }
3013: kk += tt;
3014: }
3015: } catch (IOException ioe) {
3016: System.out.println ((Multilingual.mlnJapanese ? "リードエラー: " : "Read error: ") + handle.toString ());
3017: hfsRequest18Result = -1;
3018: hfsState = HFS_STATE_DONE;
3019: return;
3020: }
3021: }
3022:
3023: hfsRequest18Result = 0;
3024: hfsState = HFS_STATE_X68K;
3025: }
3026:
3027:
3028: public void hfuCallWriteX68k () throws M68kException {
3029: HFHandle handle = hfuTargetHandle;
3030: int fcb = handle.hfhFcb;
3031:
3032: long tt = Math.min (hfuTargetLength - hfuTargetTransferred,
3033: handle.hfhStart + HFS_BUFFER_SIZE - hfuTargetPosition
3034: );
3035: long t = Math.min (HFS_BUFFER_STEP, tt);
3036: if (HFS_BUFFER_TRACE) {
3037: System.out.printf ("t=%d\n", t);
3038: }
3039: MC68060.mmuReadByteArray ((int) (hfuTargetAddress + hfuTargetTransferred),
3040: handle.hfhBuffer,
3041: (int) (hfuTargetPosition - handle.hfhStart),
3042: (int) t,
3043: XEiJ.regSRS);
3044: handle.hfhEnd = Math.max (handle.hfhEnd, hfuTargetPosition + t);
3045: handle.hfhDirty = true;
3046: if (HFS_BUFFER_TRACE) {
3047: 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);
3048: }
3049: hfuTargetPosition += t;
3050: if (HFS_BUFFER_TRACE) {
3051: System.out.printf ("position=%d\n", hfuTargetPosition);
3052: }
3053: MC68060.mmuWriteLongData (fcb + 6, (int) hfuTargetPosition, XEiJ.regSRS);
3054: if (hfuTargetFileSize < hfuTargetPosition) {
3055: hfuTargetFileSize = hfuTargetPosition;
3056: if (HFS_BUFFER_TRACE) {
3057: System.out.printf ("fileSize=%d\n", hfuTargetFileSize);
3058: }
3059: MC68060.mmuWriteLongData (fcb + 64, (int) hfuTargetFileSize, XEiJ.regSRS);
3060: }
3061: hfuTargetTransferred += t;
3062: if (HFS_BUFFER_TRACE) {
3063: System.out.printf ("transferred=%d\n", hfuTargetTransferred);
3064: }
3065: if (hfuTargetLength <= hfuTargetTransferred) {
3066: hfsRequest18Result = (int) hfuTargetTransferred;
3067: hfsState = HFS_STATE_DONE;
3068: return;
3069: }
3070: if (t < tt) {
3071:
3072: hfsRequest18Result = 0;
3073: hfsState = HFS_STATE_X68K;
3074: } else {
3075:
3076: hfsRequest18Result = 0;
3077: hfsState = HFS_STATE_HOST;
3078: }
3079: }
3080:
3081:
3082:
3083:
3084:
3085:
3086:
3087:
3088:
3089:
3090:
3091:
3092:
3093:
3094:
3095: public void hfuCallSeek () throws M68kException {
3096: if (HFS_COMMAND_TRACE && hfsCommandTraceOn) {
3097: int pc = MainMemory.mmrGetLevelZeroPC ();
3098: System.out.println (LabeledAddress.lblSearch (new StringBuilder (), pc).toString ());
3099: System.out.printf ("%08x seek(fcb=0x%08x,offset=0x%08x,mode=0x%02x)\n",
3100: pc, hfsRequest22Fcb, hfsRequest18Param, hfsRequest13Mode);
3101: }
3102: if (!abuInserted) {
3103: hfsRequest3Error = DEV_RETRY | DEV_ABORT | DEV_INSERT_MEDIA;
3104: hfsRequest18Result = -1;
3105: hfsState = HFS_STATE_DONE;
3106: return;
3107: }
3108: int mode = hfsRequest13Mode;
3109: long offset64 = (long) hfsRequest18Param;
3110: int fcb = hfsRequest22Fcb;
3111: HFHandle handle = hfuFcbToHandle.get (fcb);
3112: if (handle == null) {
3113: hfsRequest18Result = DOS_HANDLE_IS_NOT_OPENED;
3114: hfsState = HFS_STATE_DONE;
3115: return;
3116: }
3117: long current64 = (long) MC68060.mmuReadLongData (fcb + 6, XEiJ.regSRS);
3118: long end64 = (long) MC68060.mmuReadLongData (fcb + 64, XEiJ.regSRS);
3119:
3120: current64 = current64 & 0x00000000ffffffffL;
3121:
3122: end64 = end64 & 0x00000000ffffffffL;
3123: if (mode == 0) {
3124:
3125: offset64 = offset64 & 0x00000000ffffffffL;
3126:
3127: current64 = offset64;
3128: } else if (mode == 1) {
3129:
3130: offset64 = ((offset64 + 0x0000000080000000L) & 0x00000000ffffffffL) - 0x0000000080000000L;
3131:
3132: current64 = current64 + offset64;
3133: } else if (mode == 2) {
3134:
3135: offset64 = ((offset64 - 0x0000000000000001L) & 0x00000000ffffffffL) - 0x00000000ffffffffL;
3136:
3137: current64 = end64 + offset64;
3138: } else {
3139:
3140: hfsRequest18Result = DOS_INVALID_PARAMETER;
3141: hfsState = HFS_STATE_DONE;
3142: return;
3143: }
3144: if (current64 < 0x0000000000000000L || end64 < current64) {
3145:
3146: hfsRequest18Result = DOS_SEEK_OVER_EOF;
3147: hfsState = HFS_STATE_DONE;
3148: return;
3149: }
3150:
3151: MC68060.mmuWriteLongData (fcb + 6, (int) current64, XEiJ.regSRS);
3152:
3153: hfsRequest18Result = (int) current64;
3154: hfsState = HFS_STATE_DONE;
3155: }
3156:
3157:
3158:
3159:
3160:
3161:
3162:
3163:
3164:
3165:
3166:
3167:
3168:
3169:
3170:
3171:
3172: public void hfuCallFiledate () throws M68kException {
3173: if (HFS_COMMAND_TRACE && hfsCommandTraceOn) {
3174: int pc = MainMemory.mmrGetLevelZeroPC ();
3175: System.out.println (LabeledAddress.lblSearch (new StringBuilder (), pc).toString ());
3176: System.out.printf ("%08x filedate(fcb=0x%08x,datetime=0x%08x)\n",
3177: pc, hfsRequest22Fcb, hfsRequest18Param);
3178: }
3179: if (!abuInserted) {
3180: hfsRequest3Error = DEV_RETRY | DEV_ABORT | DEV_INSERT_MEDIA;
3181: hfsRequest18Result = -1;
3182: hfsState = HFS_STATE_DONE;
3183: return;
3184: }
3185: int fcb = hfsRequest22Fcb;
3186: int datetime = hfsRequest18Param;
3187: if (datetime == 0) {
3188: datetime = (MC68060.mmuReadWordZeroData (fcb + 60, XEiJ.regSRS) << 16 |
3189: MC68060.mmuReadWordZeroData (fcb + 58, XEiJ.regSRS));
3190: } else {
3191:
3192:
3193:
3194: int time = datetime & 0xffff;
3195: int date = datetime >>> 16;
3196: MC68060.mmuWriteWordData (fcb + 58, time, XEiJ.regSRS);
3197: MC68060.mmuWriteWordData (fcb + 60, date, XEiJ.regSRS);
3198:
3199: int type = MC68060.mmuModifyByteSignData (fcb + 1, XEiJ.regSRS);
3200: if ((type & 0x40) != 0) {
3201: MC68060.mmuWriteByteData (fcb + 1, type & ~0x40, XEiJ.regSRS);
3202: }
3203: }
3204: hfsRequest18Result = datetime;
3205: hfsState = HFS_STATE_DONE;
3206: }
3207:
3208:
3209:
3210:
3211:
3212:
3213:
3214:
3215:
3216:
3217:
3218:
3219:
3220:
3221:
3222:
3223:
3224:
3225:
3226:
3227: public void hfuCallDskfre () throws M68kException {
3228: if (HFS_COMMAND_TRACE && hfsCommandTraceOn) {
3229: int pc = MainMemory.mmrGetLevelZeroPC ();
3230: System.out.println (LabeledAddress.lblSearch (new StringBuilder (), pc).toString ());
3231: System.out.printf ("%08x dskfre(buffer=0x%08x)\n",
3232: pc, hfsRequest14Namests);
3233: }
3234: if (!abuInserted) {
3235: hfsRequest3Error = DEV_RETRY | DEV_ABORT | DEV_INSERT_MEDIA;
3236: hfsRequest18Result = -1;
3237: hfsState = HFS_STATE_DONE;
3238: return;
3239: }
3240: hfsRequest18Result = 0;
3241: hfsState = HFS_STATE_HOST;
3242: }
3243:
3244:
3245: public void hfuCallDskfreHost () {
3246: File file = new File (hfuRootPath);
3247: hfuTargetTotalSpace = file.getTotalSpace ();
3248: hfuTargetFreeSpace = file.getFreeSpace ();
3249: hfsRequest18Result = 0;
3250: hfsState = HFS_STATE_X68K;
3251: }
3252:
3253:
3254: public void hfuCallDskfreX68k () throws M68kException {
3255: int totalSpace = (int) Math.min (0x7fffffffL, hfuTargetTotalSpace);
3256: int freeSpace = (int) Math.min (0x7fffffffL, hfuTargetFreeSpace);
3257: int clusterBit = Math.max (0, 7 - Integer.numberOfLeadingZeros (totalSpace));
3258: MC68060.mmuWriteWordData (hfsRequest14Namests, freeSpace >>> clusterBit + 10, XEiJ.regSRS);
3259: MC68060.mmuWriteWordData (hfsRequest14Namests + 2, totalSpace >>> clusterBit + 10, XEiJ.regSRS);
3260: MC68060.mmuWriteWordData (hfsRequest14Namests + 4, 1 << clusterBit, XEiJ.regSRS);
3261: MC68060.mmuWriteWordData (hfsRequest14Namests + 6, 1 << 10, XEiJ.regSRS);
3262: hfsRequest18Result = freeSpace;
3263: hfsState = HFS_STATE_DONE;
3264:
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: public void hfuCallDrvctrl () throws M68kException {
3291: if (HFS_COMMAND_TRACE && hfsCommandTraceOn) {
3292: int pc = MainMemory.mmrGetLevelZeroPC ();
3293: System.out.println (LabeledAddress.lblSearch (new StringBuilder (), pc).toString ());
3294: System.out.printf ("%08x drvctrl(mode=0x%02x,param=0x%08x)\n",
3295: pc, hfsRequest13Mode, hfsRequest14Namests);
3296: }
3297: switch (hfsRequest13Mode) {
3298: case 1:
3299: if (hfuFcbToHandle.isEmpty ()) {
3300: eject ();
3301: }
3302: break;
3303: case 2:
3304: prevent ();
3305: break;
3306: case 3:
3307: if (hfuFcbToHandle.isEmpty ()) {
3308: allow ();
3309: }
3310: break;
3311: }
3312: MC68060.mmuWriteByteData (hfsRequestHeader + 13,
3313: (abuInserted ? ABU_INSERTED : 0) |
3314: (abuWriteProtected ? ABU_WRITE_PROTECTED : 0) |
3315: (abuBuffered ? ABU_BUFFERED : 0) |
3316: (abuEjectPrevented ? ABU_EJECT_PREVENTED : 0), XEiJ.regSRS);
3317: hfsRequest18Result = 0;
3318: hfsState = HFS_STATE_DONE;
3319: }
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: public void hfuCallGetdpb () throws M68kException {
3360: if (HFS_REPORT_INCOMPATIBLE_COMMAND ||
3361: (HFS_COMMAND_TRACE && hfsCommandTraceOn)) {
3362: int pc = MainMemory.mmrGetLevelZeroPC ();
3363: System.out.println (LabeledAddress.lblSearch (new StringBuilder (), pc).toString ());
3364: System.out.printf ("%08x getdpb(buffer=0x%08x)\n",
3365: pc, hfsRequest14Namests);
3366: }
3367: MC68060.mmuWriteLongData (hfsRequest14Namests , 0, XEiJ.regSRS);
3368: MC68060.mmuWriteLongData (hfsRequest14Namests + 4, 0, XEiJ.regSRS);
3369: MC68060.mmuWriteLongData (hfsRequest14Namests + 8, 0, XEiJ.regSRS);
3370: MC68060.mmuWriteLongData (hfsRequest14Namests + 12, 0, XEiJ.regSRS);
3371: hfsRequest18Result = 0;
3372: hfsState = HFS_STATE_DONE;
3373: }
3374:
3375:
3376:
3377:
3378:
3379:
3380:
3381:
3382:
3383:
3384:
3385:
3386:
3387:
3388:
3389: public void hfuCallDiskred () throws M68kException {
3390: if (HFS_REPORT_INCOMPATIBLE_COMMAND ||
3391: (HFS_COMMAND_TRACE && hfsCommandTraceOn)) {
3392: int pc = MainMemory.mmrGetLevelZeroPC ();
3393: System.out.println (LabeledAddress.lblSearch (new StringBuilder (), pc).toString ());
3394: System.out.printf ("%08x diskred(buffer=0x%08x,start=0x%08x,count=0x%08x,mediabyte=0x%02x)\n",
3395: pc, hfsRequest14Namests, hfsRequest22Fcb, hfsRequest18Param, hfsRequest13Mode);
3396: }
3397: int l = hfsRequest18Param << 10;
3398: for (int i = 0; i < l; i += 4) {
3399: MC68060.mmuWriteLongData (hfsRequest14Namests + i, 0, XEiJ.regSRS);
3400: }
3401: hfsRequest18Result = 0;
3402: hfsState = HFS_STATE_DONE;
3403: }
3404:
3405:
3406:
3407:
3408:
3409:
3410:
3411:
3412:
3413:
3414:
3415:
3416:
3417:
3418:
3419: public void hfuCallDiskwrt () throws M68kException {
3420: if (HFS_REPORT_INCOMPATIBLE_COMMAND ||
3421: (HFS_COMMAND_TRACE && hfsCommandTraceOn)) {
3422: int pc = MainMemory.mmrGetLevelZeroPC ();
3423: System.out.println (LabeledAddress.lblSearch (new StringBuilder (), pc).toString ());
3424: System.out.printf ("%08x diskwrt(buffer=0x%08x,start=0x%08x,count=0x%08x,mediabyte=0x%02x)\n",
3425: pc, hfsRequest14Namests, hfsRequest22Fcb, hfsRequest18Param, hfsRequest13Mode);
3426: }
3427: hfsRequest18Result = 0;
3428: hfsState = HFS_STATE_DONE;
3429: }
3430:
3431:
3432:
3433:
3434:
3435:
3436:
3437:
3438:
3439:
3440:
3441:
3442:
3443:
3444:
3445:
3446:
3447: public void hfuCallSpecialCtrl () throws M68kException {
3448: if (HFS_REPORT_INCOMPATIBLE_COMMAND ||
3449: (HFS_COMMAND_TRACE && hfsCommandTraceOn)) {
3450: int pc = MainMemory.mmrGetLevelZeroPC ();
3451: System.out.println (LabeledAddress.lblSearch (new StringBuilder (), pc).toString ());
3452: System.out.printf ("%08x ioctrl(command=0x%08x,param=0x%08x)\n",
3453: pc, hfsRequest18Param, hfsRequest14Namests);
3454: }
3455:
3456: hfsRequest18Result = DOS_CANNOT_IOCTRL;
3457: hfsState = HFS_STATE_DONE;
3458: }
3459:
3460:
3461:
3462:
3463:
3464:
3465:
3466:
3467:
3468:
3469:
3470:
3471:
3472:
3473:
3474: public void hfuCallFflush () throws M68kException {
3475: if (HFS_COMMAND_TRACE && hfsCommandTraceOn) {
3476: int pc = MainMemory.mmrGetLevelZeroPC ();
3477: System.out.println (LabeledAddress.lblSearch (new StringBuilder (), pc).toString ());
3478: System.out.printf ("%08x fflush()\n",
3479: pc);
3480: }
3481: hfsRequest18Result = 0;
3482: hfsState = HFS_STATE_HOST;
3483: }
3484:
3485:
3486: public void hfuCallFflushHost () {
3487: for (HFHandle handle : hfuFcbToHandle.values ()) {
3488:
3489: if (handle.hfhDirty) {
3490: if (HFS_BUFFER_TRACE) {
3491: 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);
3492: }
3493: RandomAccessFile raf = handle.hfhRaf;
3494: try {
3495: raf.seek (handle.hfhStart);
3496: } catch (IOException ioe) {
3497: System.out.println ((Multilingual.mlnJapanese ? "シークエラー: " : "Seek error: ") + handle.toString ());
3498: }
3499: try {
3500: raf.write (handle.hfhBuffer, 0, (int) (handle.hfhEnd - handle.hfhStart));
3501: } catch (IOException ioe) {
3502: System.out.println ((Multilingual.mlnJapanese ? "遅延書き込みに失敗しました: " : "Delayed write failed: ") + handle.toString ());
3503: }
3504: handle.hfhDirty = false;
3505: }
3506: handle.hfhStart = 0L;
3507: handle.hfhEnd = 0L;
3508: }
3509: hfsRequest18Result = 0;
3510: hfsState = HFS_STATE_DONE;
3511: }
3512:
3513:
3514:
3515:
3516:
3517:
3518:
3519:
3520:
3521:
3522:
3523:
3524:
3525:
3526:
3527: public void hfuCallMediacheck () throws M68kException {
3528: if (HFS_COMMAND_TRACE && hfsCommandTraceOn) {
3529: int pc = MainMemory.mmrGetLevelZeroPC ();
3530: System.out.println (LabeledAddress.lblSearch (new StringBuilder (), pc).toString ());
3531: System.out.printf ("%08x mediacheck()\n",
3532: pc);
3533: }
3534: hfsRequest18Result = hasBeenEjected () ? -1 : 0;
3535: hfsState = HFS_STATE_DONE;
3536: }
3537:
3538:
3539:
3540:
3541:
3542:
3543:
3544:
3545:
3546:
3547:
3548:
3549:
3550:
3551:
3552: public void hfuCallLock () throws M68kException {
3553: if (HFS_REPORT_INCOMPATIBLE_COMMAND ||
3554: (HFS_COMMAND_TRACE && hfsCommandTraceOn)) {
3555: int pc = MainMemory.mmrGetLevelZeroPC ();
3556: System.out.println (LabeledAddress.lblSearch (new StringBuilder (), pc).toString ());
3557: System.out.printf ("%08x %s(fcb=0x%08x,offset=0x%08x,length=0x%08x)\n",
3558: pc, hfsRequest13Mode == 0 ? "lock" : "unlock", hfsRequest22Fcb, hfsRequest18Param, hfsRequest14Namests);
3559: }
3560: if (true) {
3561: hfsRequest18Result = -1;
3562: } else {
3563: hfsRequest18Result = 0;
3564: }
3565: hfsState = HFS_STATE_DONE;
3566: }
3567:
3568:
3569:
3570:
3571:
3572:
3573:
3574:
3575:
3576:
3577: private void hfuFileInfo (File file, byte[] b) {
3578:
3579: b[0] = (byte) ((file.isFile () ? HumanMedia.HUM_ARCHIVE : 0) |
3580: (file.isDirectory () ? HumanMedia.HUM_DIRECTORY : 0) |
3581: (file.isHidden () ? HumanMedia.HUM_HIDDEN : 0) |
3582: (!file.canWrite () ? HumanMedia.HUM_READONLY : 0));
3583:
3584: long dttm = DnT.dntDttmCmil (file.lastModified () + RP5C15.rtcCmilGap);
3585:
3586: int time = DnT.dntHourDttm (dttm) << 11 | DnT.dntMinuDttm (dttm) << 5 | DnT.dntSecoDttm (dttm) >> 1;
3587: b[1] = (byte) (time >> 8);
3588: b[2] = (byte) time;
3589:
3590: int date = DnT.dntYearDttm (dttm) - 1980 << 9 | DnT.dntMontDttm (dttm) << 5 | DnT.dntMdayDttm (dttm);
3591: b[3] = (byte) (date >> 8);
3592: b[4] = (byte) date;
3593:
3594: int size = (int) Math.min (0xffffffffL, file.length ());
3595: b[5] = (byte) (size >> 24);
3596: b[6] = (byte) (size >> 16);
3597: b[7] = (byte) (size >> 8);
3598: b[8] = (byte) size;
3599: }
3600:
3601:
3602:
3603:
3604:
3605:
3606:
3607:
3608: public void hfuPrintFileInfo (byte[] b) {
3609: StringBuilder sb = new StringBuilder ();
3610:
3611: int attr = b[0] & 255;
3612: sb.append ((attr & HumanMedia.HUM_EXECUTABLE) != 0 ? 'e' : '-');
3613: sb.append ((attr & HumanMedia.HUM_LINK ) != 0 ? 'l' : '-');
3614: sb.append ((attr & HumanMedia.HUM_ARCHIVE ) != 0 ? 'a' : '-');
3615: sb.append ((attr & HumanMedia.HUM_DIRECTORY ) != 0 ? 'd' : '-');
3616: sb.append ((attr & HumanMedia.HUM_VOLUME ) != 0 ? 'v' : '-');
3617: sb.append ((attr & HumanMedia.HUM_SYSTEM ) != 0 ? 's' : '-');
3618: sb.append ((attr & HumanMedia.HUM_HIDDEN ) != 0 ? 'h' : '-');
3619: sb.append ((attr & HumanMedia.HUM_READONLY ) != 0 ? 'r' : '-');
3620: sb.append (" ");
3621:
3622: int date = (char) (b[3] << 8 | b[4] & 255);
3623: XEiJ.fmtSB02u (XEiJ.fmtSB02u (XEiJ.fmtSB04u (sb, (date >>> 9) + 1980).append ('-'), date >>> 5 & 15).append ('-'), date & 31);
3624: sb.append (" ");
3625:
3626: int time = (char) (b[1] << 8 | b[2] & 255);
3627: XEiJ.fmtSB02u (XEiJ.fmtSB02u (XEiJ.fmtSB02u (sb, time >>> 11).append (':'), time >>> 5 & 63).append (':'), time << 1 & 63);
3628: sb.append (" ");
3629:
3630: if ((attr & HumanMedia.HUM_DIRECTORY) != 0) {
3631: sb.append (" <dir>");
3632: } else if ((attr & HumanMedia.HUM_VOLUME) != 0) {
3633: sb.append (" <vol>");
3634: } else {
3635: int size = (b[5] << 8 | b[6] & 255) << 16 | (char) (b[7] << 8 | b[8] & 255);
3636: XEiJ.fmtSBnd (sb, 10, size);
3637: }
3638: sb.append (" ");
3639:
3640: int l = b.length;
3641: for (int i = 9; i < l; i++) {
3642: int s = b[i] & 255;
3643: char c;
3644: if (0x81 <= s && s <= 0x9f || 0xe0 <= s && s <= 0xef) {
3645: int t = i + 1 < l ? b[i + 1] & 255 : 0;
3646: if (0x40 <= t && t != 0x7f && t <= 0xfc) {
3647: c = CharacterCode.chrSJISToChar[s << 8 | t];
3648: if (c == 0) {
3649: c = '※';
3650: }
3651: i++;
3652: } else {
3653: c = '.';
3654: }
3655: } else {
3656: c = CharacterCode.chrSJISToChar[s];
3657: if (c < 0x20 || c == 0x7f) {
3658: c = '.';
3659: }
3660: }
3661: sb.append (c);
3662: }
3663: System.out.println (sb.toString ());
3664: }
3665:
3666:
3667:
3668:
3669:
3670:
3671:
3672:
3673:
3674:
3675:
3676:
3677:
3678:
3679:
3680:
3681:
3682:
3683:
3684:
3685:
3686: private String hfuNamestsToPath (int namests) throws M68kException {
3687: byte[] w = new byte[88];
3688: MC68060.mmuReadByteArray (namests, w, 0, 88, XEiJ.regSRS);
3689: return hfuNamestsToPath (w, true);
3690: }
3691: private String hfuNamestsToPath (int namests, boolean full) throws M68kException {
3692: byte[] w = new byte[88];
3693: MC68060.mmuReadByteArray (namests, w, 0, 88, XEiJ.regSRS);
3694: return hfuNamestsToPath (w, full);
3695: }
3696: private String hfuNamestsToPath (byte[] ns, boolean full) throws M68kException {
3697: if (HFS_COMMAND_TRACE && hfsCommandTraceOn) {
3698: StringBuilder sb = new StringBuilder ();
3699: sb.append ("\"");
3700: for (int i = 0; i < 88; i++) {
3701: if (i == 2 || i == 67 || i == 75 || i == 78) {
3702: sb.append ("\"+\"");
3703: }
3704: int c = ns[i] & 0xff;
3705: if (c == '\b') {
3706: sb.append ("\\b");
3707: } else if (c == '\f') {
3708: sb.append ("\\f");
3709: } else if (c == '\n') {
3710: sb.append ("\\n");
3711: } else if (c == '\r') {
3712: sb.append ("\\r");
3713: } else if (c == '\t') {
3714: sb.append ("\\t");
3715: } else if (c == '\0') {
3716: sb.append ("\\0");
3717: } else if (0x20 <= c && c <= 0x7e) {
3718: sb.append ((char) c);
3719: } else {
3720: sb.append (String.format ("\\x%02x", c));
3721: }
3722: }
3723: sb.append ("\"");
3724: String s = sb.toString ();
3725: int pc = MainMemory.mmrGetLevelZeroPC ();
3726: System.out.printf ("%08x hfuNamestsToPath(ns=%s,full=%b)\n", pc, s, full);
3727: }
3728: byte[] bb = new byte[88];
3729: int k = 0;
3730: for (int i = 2; i < 67; ) {
3731: for (; i < 67 && ns[i] == 0x09; i++) {
3732: }
3733: if (i >= 67 || ns[i] == 0x00) {
3734: break;
3735: }
3736: bb[k++] = 0x2f;
3737: for (; i < 67 && ns[i] != 0x00 && ns[i] != 0x09; i++) {
3738: bb[k++] = ns[i];
3739: }
3740: }
3741: if (full) {
3742: bb[k++] = 0x2f;
3743: for (int i = 67; i < 75; i++) {
3744: bb[k++] = ns[i];
3745: }
3746: for (int i = 78; i < 88; i++) {
3747: bb[k++] = ns[i];
3748: }
3749: for (; k > 0 && bb[k - 1] == 0x00; k--) {
3750: }
3751: for (; k > 0 && bb[k - 1] == 0x20; k--) {
3752: }
3753: bb[k++] = 0x2e;
3754: for (int i = 75; i < 78; i++) {
3755: bb[k++] = ns[i];
3756: }
3757: for (; k > 0 && bb[k - 1] == 0x20; k--) {
3758: }
3759: for (; k > 0 && bb[k - 1] == 0x2e; k--) {
3760: }
3761: }
3762: StringBuilder sb = new StringBuilder (hfuRootPath);
3763: int h = 0x00;
3764: int dot = 0;
3765: for (int i = 0; i < k; i++) {
3766: int l = bb[i] & 255;
3767: if (h != 0x00 && 0x40 <= l && l != 0x7f && l <= 0xfc) {
3768: int c = CharacterCode.chrSJISToChar[h << 8 | l];
3769: if (c != 0x0000) {
3770: sb.append ((char) c);
3771: } else {
3772: XEiJ.fmtHex2 (XEiJ.fmtHex2 (sb.append ('%'), h).append ('%'), l);
3773: }
3774: h = 0x00;
3775: dot |= 2;
3776: } else {
3777: if (h != 0x00) {
3778: XEiJ.fmtHex2 (sb.append ('%'), h);
3779: h = 0x00;
3780: }
3781: if (0x81 <= l && l <= 0x9f || 0xe0 <= l && l <= 0xef) {
3782: h = l;
3783: } else {
3784: int c = CharacterCode.chrSJISToChar[l];
3785: if (0x20 <= c && c != 0x7f) {
3786: sb.append ((char) c);
3787: } else {
3788: XEiJ.fmtHex2 (sb.append ('%'), l);
3789: }
3790: if (c == '/') {
3791: if (dot == 1) {
3792: return null;
3793: }
3794: dot = 0;
3795: } else if (c == '.') {
3796: dot |= 1;
3797: } else {
3798: dot |= 2;
3799: }
3800: }
3801: }
3802: }
3803: if (h != 0x00) {
3804: XEiJ.fmtHex2 (sb.append ('%'), h);
3805: }
3806: if (dot == 1) {
3807: return null;
3808: }
3809: return sb.toString ();
3810: }
3811:
3812: }
3813:
3814:
3815:
3816: }
3817:
3818:
3819: