Settings.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:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
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:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128: package xeij;
129:
130: import java.awt.*;
131: import java.awt.event.*;
132: import java.io.*;
133: import java.lang.*;
134: import java.net.*;
135: import java.util.*;
136: import java.util.regex.*;
137:
138: import javax.swing.*;
139: import javax.swing.event.*;
140: import netscape.javascript.*;
141:
142: public class Settings {
143:
144:
145:
146: public static final String SGS_ACM_FRAME_KEY = "acm";
147: public static final String SGS_ATW_FRAME_KEY = "atw";
148: public static final String SGS_BFN_FRAME_KEY = "bfn";
149: public static final String SGS_BLG_FRAME_KEY = "blg";
150: public static final String SGS_DBP_FRAME_KEY = "dbp";
151: public static final String SGS_DDP_FRAME_KEY = "ddp";
152: public static final String SGS_DGT_FRAME_KEY = "dgt";
153: public static final String SGS_DMP_FRAME_KEY = "dmp";
154: public static final String SGS_DRP_FRAME_KEY = "drp";
155: public static final String SGS_FNT_FRAME_KEY = "fnt";
156: public static final String SGS_FRM_FRAME_KEY = "frm";
157: public static final String SGS_GRS_FRAME_KEY = "grs";
158: public static final String SGS_GSA_FRAME_KEY = "gsa";
159: public static final String SGS_KBS_FRAME_KEY = "kbs";
160: public static final String SGS_OLG_FRAME_KEY = "olg";
161: public static final String SGS_PAA_FRAME_KEY = "paa";
162: public static final String SGS_PFF_FRAME_KEY = "pff";
163: public static final String SGS_PFV_FRAME_KEY = "pfv";
164: public static final String SGS_PPI_FRAME_KEY = "ppi";
165: public static final String SGS_PRN_FRAME_KEY = "prn";
166: public static final String SGS_RBP_FRAME_KEY = "rbp";
167: public static final String SGS_RTL_FRAME_KEY = "rtl";
168: public static final String SGS_SMN_FRAME_KEY = "smn";
169: public static final String SGS_SMT_FRAME_KEY = "smt";
170: public static final String SGS_SPV_FRAME_KEY = "spv";
171: public static final String SGS_PLV_FRAME_KEY = "plv";
172: public static final String SGS_TRM_FRAME_KEY = "trm";
173: public static final String[] SGS_FRAME_KEYS = {
174: SGS_ACM_FRAME_KEY,
175: SGS_ATW_FRAME_KEY,
176: SGS_BFN_FRAME_KEY,
177: SGS_BLG_FRAME_KEY,
178: SGS_DBP_FRAME_KEY,
179: SGS_DDP_FRAME_KEY,
180: SGS_DGT_FRAME_KEY,
181: SGS_DMP_FRAME_KEY,
182: SGS_DRP_FRAME_KEY,
183: SGS_FNT_FRAME_KEY,
184: SGS_FRM_FRAME_KEY,
185: SGS_GRS_FRAME_KEY,
186: SGS_GSA_FRAME_KEY,
187: SGS_KBS_FRAME_KEY,
188: SGS_OLG_FRAME_KEY,
189: SGS_PAA_FRAME_KEY,
190: SGS_PFF_FRAME_KEY,
191: SGS_PFV_FRAME_KEY,
192: SGS_PPI_FRAME_KEY,
193: SGS_PRN_FRAME_KEY,
194: SGS_RBP_FRAME_KEY,
195: SGS_RTL_FRAME_KEY,
196: SGS_SMN_FRAME_KEY,
197: SGS_SMT_FRAME_KEY,
198: SGS_SPV_FRAME_KEY,
199: SGS_PLV_FRAME_KEY,
200: SGS_TRM_FRAME_KEY,
201: };
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213: public static final String SGS_DEFAULT_PARAMETERS = (
214:
215: "verbose;on;" +
216:
217:
218: "saveonexit;on;" +
219: "xxxopen;on;" +
220: "config;;" +
221: "lang;en;" +
222: "home;;" +
223: "dir;;" +
224:
225: "hsb;240,240,240,70,50,30,0,50,100;" +
226: "hhssbb;none;" +
227: "fontsize;14;" +
228:
229: "keyboard;standard;" +
230: "hidekeyboard;on;" +
231: "keymapus;off;" +
232: "keymap;;" +
233: "zkeyboard;off;" +
234: "zkeymap;;" +
235:
236: "f11key;fullscreen;" +
237: "shiftf11key;maximized;" +
238: "ctrlf11key;donothing;" +
239: "altf11key;donothing;" +
240: "f12key;seamless;" +
241: "shiftf12key;donothing;" +
242: "ctrlf12key;donothing;" +
243: "altf12key;donothing;" +
244: "wheel;seamless;" +
245: "shiftwheel;donothing;" +
246: "ctrlwheel;donothing;" +
247: "altwheel;donothing;" +
248: "wheelup;trace1;" +
249: "shiftwheelup;trace10;" +
250: "ctrlwheelup;trace100;" +
251: "altwheelup;donothing;" +
252: "wheeldown;step1;" +
253: "shiftwheeldown;step10;" +
254: "ctrlwheeldown;step100;" +
255: "altwheeldown;return;" +
256: "button4;donothing;" +
257: "shiftbutton4;donothing;" +
258: "ctrlbutton4;donothing;" +
259: "altbutton4;donothing;" +
260: "button5;donothing;" +
261: "shiftbutton5;donothing;" +
262: "ctrlbutton5;donothing;" +
263: "altbutton5;donothing;" +
264: "mousewheel;;" +
265:
266: "gifwaitingtime;;" +
267: "gifrecordingtime;10;" +
268: "gifmagnification;100;" +
269: "gifinterpolation;bilinear;" +
270:
271: "scaling;fitinwindow;" +
272: "fixedscale;100;" +
273: "aspectratio256x256;4:3;" +
274: "aspectratio384x256;4:3;" +
275: "aspectratio512x512;4:3;" +
276: "aspectratio768x512;3:2;" +
277: "interpolation;bilinear;" +
278: "refreshrate;none;" +
279: "adjustvsync;off;" +
280:
281: "usecanvas;on;" +
282: "rotation;0;" +
283:
284: "seamless;on;" +
285: "followscroll;on;" +
286: "ctrlright;off;" +
287: "edgeaccel;off;" +
288: "mousespeed;;" +
289: "hostspixelunits;off;" +
290:
291: "textcopyarea;display;" +
292: "textcopy;off;" +
293:
294: "model;Hybrid;" +
295: "mpu010;off;" +
296: "mpu;none;" +
297: "clock;none;" +
298: "mhz;200;" +
299: "util;off;" +
300: "ratio;100;" +
301: "waitcycles;on;" +
302:
303: "copro0;2;" +
304: "copro1;2;" +
305: "copro2;2;" +
306: "onchipfpu;7;" +
307:
308: "fefunc;on;" +
309: "rejectfloat;off;" +
310:
311: "himem68000;off;" +
312: "highmemory;;" +
313: "highmemorysave;off;" +
314: "highmemorydata;;" +
315: "highmemory060turbo;off;" +
316: "localmemory;128;" +
317: "localmemorysave;off;" +
318: "localmemorydata;;" +
319: "cutfc2pin;off;" +
320:
321: "memory;12;" +
322: "memorysave;on;" +
323: "memorydata;;" +
324:
325: "pastepipe;off;" +
326: "pipeencoding;sjis;" +
327:
328: "intermittent;0;" +
329: "stereoscopic;off;" +
330: "stereoscopicmethod;nakedeyecrossing;" +
331: "extendedgraphic;off;" +
332: "scanline;medium;" +
333: "dotclock;,,;" +
334: "eleventhbit;off;" +
335: "sphericalscrolling;off;" +
336: "r00bit0zero;off;" +
337:
338: "sprras;32;" +
339: "dblspr;off;" +
340: "numspr;128;" +
341: "sprbank;off;" +
342: "spr768x512;off;" +
343: "spr512bg1;off;" +
344: "sprrcscroll;off;" +
345:
346: "sound;on;" +
347: "volume;20;" +
348: "soundinterpolation;linear;" +
349:
350: "opmoutput;on;" +
351:
352: "pcmoutput;on;" +
353: "pcminterpolation;linear;" +
354: "pcmoscfreq;0;" +
355:
356:
357: "fdreadonly;off;" +
358: "fdappreboot;off;" +
359:
360:
361: "sareadonly;off;" +
362: "saappreboot;off;" +
363:
364:
365: "screadonly;off;" +
366: "scappreboot;off;" +
367:
368: "hcddebug;off;" +
369: "hcdconnect;off;" +
370: "hcdscsiid;6;" +
371: "hcdvolume;25;" +
372:
373:
374: "hfreadonly;off;" +
375: "hfappreboot;off;" +
376: "utf8warning;off;" +
377:
378: "joykey;on;" +
379: "joyauto;on;" +
380: "joyblock;on;" +
381: "normal2button1;;" +
382: "normal2button2;;" +
383: "megadrive3button1;;" +
384: "megadrive3button2;;" +
385: "megadrive6button1;;" +
386: "megadrive6button2;;" +
387: "cyberstickdigital1;;" +
388: "cyberstickdigital2;;" +
389: "cyberstickanalog1;;" +
390: "cyberstickanalog2;;" +
391: "shiromadokun1;;" +
392: "shiromadokun2;;" +
393: "joystick1;normal2button1;" +
394: "joystick2;normal2button2;" +
395: "xinput;off;" +
396:
397: "scsiex;off;" +
398:
399: "boot;default;" +
400: "keydly;-1;" +
401: "keyrep;-1;" +
402: "sram;none;" +
403: "sramdata;;" +
404: "sramsize;16;" +
405: "romdb;none;" +
406: "modifymemorysize;on;" +
407: "srambuserror;off;" +
408:
409: "bankdata;;" +
410:
411: "rom;none;" +
412: "cgrom;none;" +
413: "rom30;none;" +
414: "scsiinrom;none;" +
415: "scsiexrom;none;" +
416: "iplrom;none;" +
417: "x68000logo;none;" +
418: "iplrom16style;7;" +
419: "iplrom256k;off;" +
420: "iplrom16;off;" +
421: "omusubi;off;" +
422:
423: "prnauto;off;" +
424: "prnpath;printer;" +
425: "prndipsw;;" +
426: "prnsize;A4;" +
427: "prnorientation;portrait;" +
428: "prntopmargin;11;" +
429: "prnleftmargin;14;" +
430: "prnrightmargin;14;" +
431: "prnbottommargin;11;" +
432: "prnrotation;;" +
433: "prndarkmode;off;" +
434: "prnonline;on;" +
435: "prnsinglecolor;;" +
436: "prnscalefactor;;" +
437:
438: "sccfreq;5000000;" +
439:
440: "spvbank;0;" +
441: "spvblock;-1;" +
442: "spvflip;-1;" +
443: "spvhex;off;" +
444: "spvscale;0;" +
445: "spvsize;-1;" +
446:
447: "plvarrgt;2;" +
448: "plvhex;off;" +
449: "plvscale;0;" +
450:
451: "rs232cconnection;Terminal+%E2%87%94+AUX;" +
452: "terminalsettings;38400/B8/PN/S1/RTS;" +
453: "additionalport;none;" +
454: "tcpiphost;0.0.0.0;" +
455: "tcpipport;54321;" +
456: "tcpiputf8;off;" +
457:
458: "pppaddress;192.168.10.1:192.168.10.2;" +
459: "pppdebug;off;" +
460: "pppdirect;off;" +
461: "ppplog;off;" +
462: "pppserver;off;" +
463:
464: "mercury;off;" +
465: "mercuryoe;on;" +
466:
467: "xt3dipsw;3;" +
468: "xt3memorykb;256;" +
469: "xt3memorydata;;" +
470: "xt3memorysave;off;"
471: );
472:
473: public static final String SGS_APPDATA_FOLDER = "XEiJ";
474: public static final String SGS_INI = "XEiJ.ini";
475:
476: public static final Pattern SGS_BOOT_DEVICE_PATTERN = Pattern.compile ("^(?:default|std|(?:fd|hd|sc|hf)\\d+|r[oa]m\\$[0-9A-Fa-f]+)$", Pattern.CASE_INSENSITIVE);
477:
478: public static String sgsAppDataRoamingFolder;
479: public static String sgsAppDataLocalFolder;
480: public static String sgsHomeDirectory;
481: public static String sgsCurrentDirectory;
482:
483: public static File sgsIniParentDirectory;
484: public static String sgsIniParentPath;
485: public static File sgsIniFile;
486: public static String sgsIniPath;
487:
488: public static boolean sgsSaveOnExit;
489: public static boolean sgsXxxOpen;
490: public static JCheckBoxMenuItem sgsSaveOnExitCheckBox;
491: public static String sgsSaveiconValue;
492: public static String sgsIrbbenchValue;
493:
494: public static HashMap<String,String> sgsDefaultMap;
495: public static HashMap<String,String> sgsStartMap;
496: public static HashMap<String,String> sgsCurrentMap;
497: public static HashMap<String,HashMap<String,String>> sgsRootMap;
498:
499: public static JMenu sgsMenu;
500:
501:
502:
503:
504:
505:
506: public static final Comparator<String> DictionaryComparator = new Comparator<String> () {
507: @Override public int compare (String s1, String s2) {
508: int l1 = s1.length ();
509: int l2 = s2.length ();
510: int b1, b2;
511: int e1, e2;
512: int f = 0;
513: compare:
514: {
515: for (b1 = 0, b2 = 0; b1 < l1 && b2 < l2; b1 = e1, b2 = e2) {
516: int c1, c2;
517:
518: e1 = b1;
519: c1 = s1.charAt (e1);
520: c1 = ('0' - 1) - c1 & c1 - ('9' + 1);
521: for (e1++; e1 < l1; e1++) {
522: c2 = s1.charAt (e1);
523: c2 = ('0' - 1) - c2 & c2 - ('9' + 1);
524: if ((c1 ^ c2) < 0) {
525: break;
526: }
527: c1 = c2;
528: }
529: e2 = b2;
530: c1 = s2.charAt (e2);
531: c1 = ('0' - 1) - c1 & c1 - ('9' + 1);
532: for (e2++; e2 < l2; e2++) {
533: c2 = s2.charAt (e2);
534: c2 = ('0' - 1) - c2 & c2 - ('9' + 1);
535: if ((c1 ^ c2) < 0) {
536: break;
537: }
538: c1 = c2;
539: }
540: c1 = s1.charAt (b1);
541: c2 = s2.charAt (b2);
542: if ((('0' - 1) - c1 & c1 - ('9' + 1) & ('0' - 1) - c2 & c2 - ('9' + 1)) < 0) {
543:
544: for (; b1 < e1 && s1.charAt (b1) == '0'; b1++) {
545: }
546: for (; b2 < e2 && s2.charAt (b2) == '0'; b2++) {
547: }
548:
549: f = (e1 - b1) - (e2 - b2);
550: if (f != 0) {
551: break compare;
552: }
553:
554: for (; b1 < e1 && b2 < e2; b1++, b2++) {
555: f = s1.charAt (b1) - s2.charAt (b2);
556: if (f != 0) {
557: break compare;
558: }
559: }
560: } else {
561:
562:
563: for (; b1 < e1 && b2 < e2; b1++, b2++) {
564: c1 = s1.charAt (b1);
565: c2 = s2.charAt (b2);
566: f = ((c1 + ((('A' - 1) - c1 & c1 - ('Z' + 1)) >> 31 & 'a' - 'A')) -
567: (c2 + ((('A' - 1) - c2 & c2 - ('Z' + 1)) >> 31 & 'a' - 'A')));
568: if (f != 0) {
569: break compare;
570: }
571: }
572: if (b1 < e1 || b2 < e2) {
573:
574:
575:
576:
577: f = (e1 - b1) - (e2 - b2);
578: break compare;
579: }
580: }
581: }
582: f = (l1 - b1) - (l2 - b2);
583:
584: if (f == 0) {
585: for (b1 = 0, b2 = 0; b1 < l1 && b2 < l2; b1++, b2++) {
586: f = s1.charAt (b1) - s2.charAt (b2);
587: if (f != 0) {
588: break compare;
589: }
590: }
591: }
592: }
593: return (f >> 31) - (-f >> 31);
594: }
595: };
596:
597:
598:
599: public static void sgsInit () {
600:
601: sgsAppDataRoamingFolder = null;
602: sgsAppDataLocalFolder = null;
603: sgsHomeDirectory = null;
604: sgsCurrentDirectory = null;
605:
606: sgsIniParentDirectory = null;
607: sgsIniParentPath = null;
608: sgsIniFile = null;
609: sgsIniPath = null;
610:
611: sgsSaveOnExit = true;
612: sgsSaveOnExitCheckBox = null;
613:
614: sgsSaveiconValue = null;
615: sgsIrbbenchValue = null;
616:
617:
618:
619:
620: sgsDefaultMap = new HashMap<String,String> ();
621: {
622: String[] a = SGS_DEFAULT_PARAMETERS.split (";");
623: for (int i = 0, l = a.length; i < l; i += 2) {
624: String key = a[i];
625: String value = i + 1 < l ? a[i + 1] : "";
626: sgsDefaultMap.put (key, value);
627: }
628: }
629:
630:
631:
632:
633:
634:
635:
636:
637: for (int i = 0; i < FDC.FDC_MAX_UNITS; i++) {
638: sgsDefaultMap.put ("fd" + i, "none");
639: }
640: for (int i = 0; i < 16; i++) {
641: sgsDefaultMap.put ("hd" + i, "none");
642: sgsDefaultMap.put ("sa" + i, "none");
643: sgsDefaultMap.put ("sc" + i, "none");
644: }
645: for (int i = 0; i < HFS.HFS_MAX_UNITS; i++) {
646: sgsDefaultMap.put ("hf" + i, "none");
647: }
648:
649: for (int i = 0; i < JFileChooser2.MAXIMUM_HISTORY_COUNT; i++) {
650: sgsDefaultMap.put ("fdhistory" + i, "none");
651: sgsDefaultMap.put ("sahistory" + i, "none");
652: sgsDefaultMap.put ("schistory" + i, "none");
653: sgsDefaultMap.put ("hfhistory" + i, "none");
654: }
655:
656: for (String key : SGS_FRAME_KEYS) {
657: sgsDefaultMap.put (key + "rect", "");
658: sgsDefaultMap.put (key + "stat", "normal");
659: sgsDefaultMap.put (key + "open", "off");
660: }
661:
662:
663:
664:
665: sgsStartMap = new HashMap<String,String> (sgsDefaultMap);
666:
667:
668: sgsStartMap.put ("hf0", sgsHomeDirectory != null ? sgsHomeDirectory : HFS.HFS_DUMMY_UNIT_NAME);
669:
670:
671: sgsStartMap.put ("lang", Multilingual.mlnLang);
672:
673: if (false) {
674:
675: System.out.println ("\n[System.getenv()]");
676: new TreeMap<String,String> (System.getenv ()).forEach ((k, v) -> System.out.println (k + " = " + v));
677: }
678: if (false) {
679:
680: System.out.println ("\n[System.getProperties()]");
681: TreeMap<String,String> m = new TreeMap<String,String> ();
682: System.getProperties ().forEach ((k, v) -> m.put (k.toString (), v.toString ()));
683: m.forEach ((k, v) -> System.out.println (k + " = " + v));
684: }
685:
686:
687: boolean isWindows = System.getProperty ("os.name").indexOf ("Windows") >= 0;
688: sgsAppDataRoamingFolder = isWindows ? System.getenv ("APPDATA") : null;
689: sgsAppDataLocalFolder = isWindows ? System.getenv ("LOCALAPPDATA") : null;
690:
691:
692: sgsHomeDirectory = System.getProperty ("user.home");
693:
694:
695: sgsCurrentDirectory = System.getProperty ("user.dir");
696:
697:
698: if (sgsAppDataRoamingFolder != null) {
699: sgsIniParentPath = new File (sgsAppDataRoamingFolder + File.separator + SGS_APPDATA_FOLDER).getAbsolutePath ();
700: sgsIniParentDirectory = new File (sgsIniParentPath);
701: sgsIniPath = sgsIniParentPath + File.separator + SGS_INI;
702: sgsIniFile = new File (sgsIniPath);
703: } else {
704: sgsIniParentPath = null;
705: sgsIniParentDirectory = null;
706: sgsIniPath = new File ((sgsHomeDirectory != null ? sgsHomeDirectory :
707: sgsCurrentDirectory != null ? sgsCurrentDirectory :
708: ".") + File.separator + SGS_INI).getAbsolutePath ();
709: sgsIniFile = new File (sgsIniPath);
710: }
711:
712:
713:
714:
715: sgsCurrentMap = new HashMap<String,String> (sgsStartMap);
716: sgsCurrentMap.put ("_", "");
717:
718:
719: sgsRootMap = new HashMap<String,HashMap<String,String>> ();
720: sgsRootMap.put ("", sgsCurrentMap);
721:
722:
723:
724: HashMap<String,String> argumentMap = new HashMap<String,String> ();
725: int fdNumber = 0;
726: int hdNumber = 0;
727: int scNumber = 0;
728: int hfNumber = 0;
729: for (int i = 0; i < XEiJ.prgArgs.length; i++) {
730: String key = null;
731: String value = XEiJ.prgArgs[i];
732: arg:
733: {
734: boolean boot = false;
735: if (value.startsWith ("-")) {
736:
737: int k = value.indexOf ('=', 1);
738: if (k >= 0) {
739: key = value.substring (1, k);
740: value = value.substring (k + 1);
741: } else {
742:
743: key = value.substring (1);
744: value = (i + 1 < XEiJ.prgArgs.length && !XEiJ.prgArgs[i + 1].startsWith ("-") ?
745: XEiJ.prgArgs[++i]
746: :
747: "1");
748: }
749: if (!key.equalsIgnoreCase ("boot")) {
750: break arg;
751: }
752: boot = true;
753: }
754:
755: if (SGS_BOOT_DEVICE_PATTERN.matcher (value).matches ()) {
756:
757: key = "boot";
758: break arg;
759: }
760: String valueWithoutColonR = value.endsWith (":R") ? value.substring (0, value.length () - 2) : value;
761: File file = new File (valueWithoutColonR);
762: if (file.isDirectory ()) {
763: key = "hf" + hfNumber++;
764: } else if (file.isFile ()) {
765:
766:
767: if (valueWithoutColonR.toUpperCase ().endsWith (".HDF")) {
768: key = "sa" + hdNumber++;
769: } else if (valueWithoutColonR.toUpperCase ().endsWith (".HDS")) {
770: key = "sc" + scNumber++;
771: } else if (FDMedia.fdmPathToMedia (valueWithoutColonR, null) != null) {
772: key = "fd" + fdNumber++;
773: } else if (HDMedia.hdmPathToMedia (valueWithoutColonR, null) != null) {
774: key = "sa" + hdNumber++;
775: } else {
776: key = "sc" + scNumber++;
777: }
778: } else {
779: String[] zipSplittedName = XEiJ.RSC_ZIP_SEPARATOR.split (valueWithoutColonR, 2);
780: if (zipSplittedName.length == 2 &&
781: new File (zipSplittedName[0]).isFile ()) {
782: if (FDMedia.fdmPathToMedia (valueWithoutColonR, null) != null) {
783: key = "fd" + fdNumber++;
784: } else if (HDMedia.hdmPathToMedia (valueWithoutColonR, null) != null) {
785: key = "sa" + hdNumber++;
786: } else {
787: System.out.println (Multilingual.mlnJapanese ? value + " は不明な起動デバイスです" :
788: value + " is unknown boot device");
789: continue;
790: }
791: } else {
792: System.out.println (Multilingual.mlnJapanese ? value + " は不明な起動デバイスです" :
793: value + " is unknown boot device");
794: continue;
795: }
796: }
797: if (boot) {
798: sgsPutParameter (argumentMap, "boot", key);
799: }
800: }
801:
802: switch (key) {
803: case "ini":
804: sgsIniParentPath = null;
805: sgsIniParentDirectory = null;
806: sgsIniPath = new File (value).getAbsolutePath ();
807: sgsIniFile = new File (sgsIniPath);
808: break;
809: case "saveicon":
810: sgsSaveiconValue = value;
811: break;
812: case "irbbench":
813: sgsIrbbenchValue = value;
814: break;
815: default:
816: sgsPutParameter (argumentMap, key, value);
817: }
818: }
819: System.out.println (Multilingual.mlnJapanese ? "設定ファイルは " + sgsIniPath + " です" :
820: "INI file is " + sgsIniPath);
821:
822:
823: sgsDecodeRootMap (sgsLoadIniFile ());
824:
825:
826: if (argumentMap.containsKey ("config")) {
827: String name = argumentMap.get ("config");
828: if (name.equals ("default")) {
829: sgsCurrentMap.clear ();
830: sgsCurrentMap = new HashMap<String,String> (sgsStartMap);
831: sgsCurrentMap.put ("_", "");
832: sgsRootMap.put ("", sgsCurrentMap);
833: } else if (name.length () != 0 &&
834: sgsRootMap.containsKey (name)) {
835: sgsCurrentMap.clear ();
836: sgsCurrentMap = new HashMap<String,String> (sgsRootMap.get (name));
837: sgsCurrentMap.put ("_", "");
838: sgsRootMap.put ("", sgsCurrentMap);
839: }
840: argumentMap.remove ("config");
841: }
842:
843:
844:
845: for (String key : argumentMap.keySet ()) {
846: sgsCurrentMap.put (key, argumentMap.get (key));
847: }
848:
849:
850: String paramLang = sgsCurrentMap.get ("lang").toLowerCase ();
851: Multilingual.mlnChange (paramLang.equals ("ja") ? "ja" : "en");
852: XEiJ.prgVerbose = sgsGetOnOff ("verbose");
853:
854: sgsSaveOnExit = sgsGetOnOff ("saveonexit");
855: sgsXxxOpen = sgsGetOnOff ("xxxopen");
856:
857:
858:
859:
860:
861:
862:
863:
864:
865: if (CRTC.CRT_ENABLE_INTERMITTENT) {
866: CRTC.crtIntermittentInterval = XEiJ.fmtParseInt (sgsCurrentMap.get ("intermittent"), 0, 0, 4, 0);
867: }
868: if (CRTC.CRT_EXTENDED_GRAPHIC) {
869: CRTC.crtExtendedGraphicRequest = sgsGetOnOff ("extendedgraphic");
870: }
871:
872: SoundSource.sndPlayOn = sgsGetOnOff ("sound");
873: SoundSource.sndVolume = XEiJ.fmtParseInt (sgsCurrentMap.get ("volume"), 0, 0, SoundSource.SND_VOLUME_MAX, SoundSource.SND_VOLUME_DEFAULT);
874: {
875: String s = sgsCurrentMap.get ("soundinterpolation").toLowerCase ();
876: SoundSource.sndRateConverter = (s.equals ("thinning") ? SoundSource.SND_CHANNELS == 1 ? SoundSource.SNDRateConverter.THINNING_MONO : SoundSource.SNDRateConverter.THINNING_STEREO :
877: s.equals ("linear") ? SoundSource.SND_CHANNELS == 1 ? SoundSource.SNDRateConverter.LINEAR_MONO : SoundSource.SNDRateConverter.LINEAR_STEREO :
878: s.equals ("constant-area") ? SoundSource.SNDRateConverter.CONSTANT_AREA_STEREO_48000 :
879: s.equals ("linear-area") ? SoundSource.SNDRateConverter.LINEAR_AREA_STEREO_48000 :
880: SoundSource.SND_CHANNELS == 1 ? SoundSource.SNDRateConverter.LINEAR_MONO : SoundSource.SNDRateConverter.LINEAR_STEREO);
881: }
882:
883: OPM.opmOutputMask = sgsGetOnOff ("opmoutput") ? -1 : 0;
884:
885: {
886: ADPCM.pcmOutputOn = sgsGetOnOff ("pcmoutput");
887: String s = sgsCurrentMap.get ("pcminterpolation").toLowerCase ();
888: ADPCM.pcmInterpolationAlgorithm = (s.equals ("constant") ? ADPCM.PCM_INTERPOLATION_CONSTANT :
889: s.equals ("linear") ? ADPCM.PCM_INTERPOLATION_LINEAR :
890: s.equals ("hermite") ? ADPCM.PCM_INTERPOLATION_HERMITE :
891: ADPCM.PCM_INTERPOLATION_LINEAR);
892: ADPCM.pcmOSCFreqRequest = XEiJ.fmtParseInt (sgsCurrentMap.get ("pcmoscfreq"), 0, 0, 1, 0);
893: }
894:
895:
896:
897:
898:
899:
900:
901:
902:
903:
904:
905:
906:
907:
908:
909: for (String key : SGS_FRAME_KEYS) {
910:
911: int[] rect = sgsGetIntArray (key + "rect", 4, 0);
912:
913: String s = sgsGetString (key + "stat").toLowerCase ();
914: int state = (s.equals ("iconified") ? Frame.ICONIFIED :
915: s.equals ("maximized") ? Frame.MAXIMIZED_BOTH :
916: s.equals ("h-maximized") ? Frame.MAXIMIZED_HORIZ :
917: s.equals ("v-maximized") ? Frame.MAXIMIZED_VERT :
918: Frame.NORMAL);
919:
920: boolean opened = sgsXxxOpen && sgsGetOnOff (key + "open");
921: RestorableFrame.rfmSet (key, rect, state, opened);
922: }
923:
924: if (sgsIrbbenchValue != null) {
925: InstructionBenchmark.irbBench (sgsIrbbenchValue);
926: System.exit (0);
927: }
928:
929: }
930:
931:
932:
933: public static void sgsTini () {
934: if (sgsSaveOnExit) {
935: sgsSaveAllSettings ();
936: }
937: }
938:
939:
940:
941:
942:
943:
944: public static String sgsGetString (String key) {
945: return sgsGetString (key, "");
946: }
947: public static String sgsGetString (String key, String def) {
948: String value = sgsCurrentMap.get (key);
949: if (value == null) {
950: System.err.println ("sgsGetString: undefined key " + key);
951: return def;
952: }
953: value = value.trim ();
954: return value.equalsIgnoreCase ("none") || value.equals ("") ? def : value;
955: }
956:
957:
958:
959: public static void sgsPutString (String key, String value) {
960: if (!sgsCurrentMap.containsKey (key)) {
961: System.err.println ("sgsPutString: undefined key " + key);
962: return;
963: }
964: value = value.trim ();
965: sgsCurrentMap.put (key, value.length () == 0 ? "none" : value);
966: }
967:
968:
969:
970:
971:
972: public static boolean sgsGetOnOff (String key) {
973: return sgsGetOnOff (key, false);
974: }
975: public static boolean sgsGetOnOff (String key, boolean def) {
976: String value = sgsCurrentMap.get (key);
977: if (value == null) {
978: System.err.println ("sgsGetOnOff: undefined key " + key);
979: return false;
980: }
981: value = value.trim ();
982: return (value.equals ("0") ||
983: value.equalsIgnoreCase ("off") ||
984: value.equalsIgnoreCase ("no") ? false :
985: value.equals ("1") ||
986: value.equalsIgnoreCase ("on") ||
987: value.equalsIgnoreCase ("yes") ? true :
988: def);
989: }
990:
991:
992:
993: public static void sgsPutOnOff (String key, boolean b) {
994: if (!sgsCurrentMap.containsKey (key)) {
995: System.err.println ("sgsPutOnOff: undefined key " + key);
996: return;
997: }
998: sgsCurrentMap.put (key, b ? "on" : "off");
999: }
1000:
1001:
1002:
1003:
1004:
1005: public static int sgsGetInt (String key) {
1006: return sgsGetInt (key, 0, Integer.MIN_VALUE, Integer.MAX_VALUE);
1007: }
1008: public static int sgsGetInt (String key, int i0) {
1009: return sgsGetInt (key, i0, Integer.MIN_VALUE, Integer.MAX_VALUE);
1010: }
1011: public static int sgsGetInt (String key, int i0, int min, int max) {
1012: String value = sgsCurrentMap.get (key);
1013: if (value == null) {
1014: System.err.println ("sgsGetInt: undefined key " + key);
1015: return i0;
1016: }
1017: value = value.trim ();
1018: if (value.length () != 0) {
1019: try {
1020: int i = Integer.parseInt (value, 10);
1021: if (min <= i && i <= max) {
1022: return i;
1023: }
1024: } catch (NumberFormatException nfe) {
1025: }
1026: }
1027: return i0;
1028: }
1029:
1030:
1031:
1032:
1033: public static void sgsPutInt (String key, int i) {
1034: sgsPutInt (key, i, 0);
1035: }
1036: public static void sgsPutInt (String key, int i, int i0) {
1037: if (!sgsCurrentMap.containsKey (key)) {
1038: System.err.println ("sgsPutInt: undefined key " + key);
1039: return;
1040: }
1041: sgsCurrentMap.put (key, i == i0 ? "" : String.valueOf (i));
1042: }
1043:
1044:
1045:
1046:
1047:
1048:
1049:
1050: public static int[] sgsGetIntArray (String key) {
1051: return sgsGetIntArray (key, -1, 0);
1052: }
1053: public static int[] sgsGetIntArray (String key, int n) {
1054: return sgsGetIntArray (key, n, 0);
1055: }
1056: public static int[] sgsGetIntArray (String key, int n, int v) {
1057: String value = sgsCurrentMap.get (key);
1058: if (value == null) {
1059: System.err.println ("sgsGetIntArray: undefined key " + key);
1060: value = "";
1061: }
1062: String[] sa = value.length () == 0 ? new String[0] : value.split (",");
1063: if (n < 0) {
1064: n = sa.length;
1065: }
1066: int[] ia = new int[n];
1067: Arrays.fill (ia, v);
1068: for (int i = 0; i < n && i < sa.length; i++) {
1069: String s = sa[i].trim ();
1070: if (s.length () != 0) {
1071: try {
1072: ia[i] = Integer.parseInt (s, 10);
1073: } catch (NumberFormatException nfe) {
1074: }
1075: }
1076: }
1077: return ia;
1078: }
1079:
1080:
1081:
1082:
1083: public static void sgsPutIntArray (String key, int[] ia) {
1084: sgsPutIntArray (key, ia, 0);
1085: }
1086: public static void sgsPutIntArray (String key, int[] ia, int v) {
1087: if (!sgsCurrentMap.containsKey (key)) {
1088: System.err.println ("sgsPutIntArray: undefined key " + key);
1089: return;
1090: }
1091: int n = ia.length;
1092: while (0 < n && ia[n - 1] == v) {
1093: n--;
1094: }
1095: StringBuilder sb = new StringBuilder ();
1096: for (int i = 0; i < n; i++) {
1097: if (i != 0) {
1098: sb.append (',');
1099: }
1100: if (ia[i] != v) {
1101: sb.append (ia[i]);
1102: }
1103: }
1104: sgsCurrentMap.put (key, sb.toString ());
1105: }
1106:
1107:
1108:
1109:
1110: public static byte[] sgsGetData (String key) {
1111: String value = sgsCurrentMap.get (key);
1112: if (value == null) {
1113: System.err.println ("sgsGetData: undefined key " + key);
1114: value = "";
1115: }
1116: return value.length () == 0 ? new byte[0] : ByteArray.byaDecodeGzip (ByteArray.byaDecodeBase64 (value));
1117: }
1118:
1119:
1120:
1121:
1122:
1123:
1124: public static void sgsPutData (String key, byte[] array) {
1125: sgsPutData (key, array, 0, array.length);
1126: }
1127: public static void sgsPutData (String key, byte[] array, int offset, int length) {
1128: if (!sgsCurrentMap.containsKey (key)) {
1129: System.err.println ("sgsPutData: undefined key " + key);
1130: return;
1131: }
1132: String value = "";
1133: for (int i = 0; i < length; i++) {
1134: if (array[offset + i] != 0) {
1135: value = ByteArray.byaEncodeBase64 (ByteArray.byaEncodeGzip (array, offset, length));
1136: break;
1137: }
1138: }
1139: sgsCurrentMap.put (key, value);
1140: }
1141:
1142:
1143:
1144:
1145:
1146: public static void sgsMakeMenu () {
1147:
1148: ActionListener listener = new ActionListener () {
1149: @Override public void actionPerformed (ActionEvent ae) {
1150: Object source = ae.getSource ();
1151: String command = ae.getActionCommand ();
1152: switch (command) {
1153: case "Save settings on exit":
1154: sgsSaveOnExit = ((JCheckBoxMenuItem) ae.getSource ()).isSelected ();
1155: break;
1156: case "Restore windows that were open":
1157: sgsXxxOpen = ((JCheckBoxMenuItem) ae.getSource ()).isSelected ();
1158: break;
1159: case "Delete all settings":
1160: sgsDeleteAllSettings ();
1161: break;
1162: }
1163: }
1164: };
1165:
1166: sgsMenu = Multilingual.mlnText (
1167: ComponentFactory.createMenu (
1168: "Configuration file",
1169: sgsSaveOnExitCheckBox =
1170: Multilingual.mlnText (
1171: ComponentFactory.createCheckBoxMenuItem (sgsSaveOnExit, "Save settings on exit", listener),
1172: "ja", "終了時に設定を保存する"),
1173: Multilingual.mlnText (
1174: ComponentFactory.createCheckBoxMenuItem (sgsXxxOpen, "Restore windows that were open", listener),
1175: "ja", "開いていたウインドウを復元する"),
1176: ComponentFactory.createHorizontalSeparator (),
1177: Multilingual.mlnText (
1178: ComponentFactory.createMenuItem ("Delete all settings", listener),
1179: "ja", "すべての設定を消去する")
1180: ),
1181: "ja", "設定ファイル");
1182: }
1183:
1184:
1185:
1186: public static void sgsSaveAllSettings () {
1187:
1188: sgsCurrentMap.put ("lang", Multilingual.mlnLang);
1189:
1190: sgsCurrentMap.put ("verbose", XEiJ.prgVerbose ? "on" : "off");
1191:
1192: sgsCurrentMap.put ("saveonexit", sgsSaveOnExit ? "on" : "off");
1193: sgsCurrentMap.put ("xxxopen", sgsXxxOpen ? "on" : "off");
1194:
1195:
1196:
1197: sgsCurrentMap.put ("fefunc", FEFunction.fpkOn ? "on" : "off");
1198: sgsCurrentMap.put ("rejectfloat", FEFunction.fpkRejectFloatOn ? "on" : "off");
1199:
1200:
1201: sgsCurrentMap.put ("memory", String.valueOf (MainMemory.mmrMemorySizeRequest >>> 20));
1202: sgsCurrentMap.put ("memorysave", MainMemory.mmrMemorySaveOn ? "on" : "off");
1203: sgsCurrentMap.put ("memorydata", MainMemory.mmrMemorySaveOn ? ByteArray.byaEncodeBase64 (ByteArray.byaEncodeGzip (MainMemory.mmrM8, 0x00000000, MainMemory.mmrMemorySizeCurrent)) : "");
1204:
1205: if (CRTC.CRT_ENABLE_INTERMITTENT) {
1206: sgsCurrentMap.put ("intermittent", String.valueOf (CRTC.crtIntermittentInterval));
1207: }
1208: if (CRTC.CRT_EXTENDED_GRAPHIC) {
1209: sgsCurrentMap.put ("extendedgraphic", CRTC.crtExtendedGraphicRequest ? "on" : "off");
1210: }
1211:
1212: sgsCurrentMap.put ("sound", SoundSource.sndPlayOn ? "on" : "off");
1213: sgsCurrentMap.put ("volume", String.valueOf (SoundSource.sndVolume));
1214: sgsCurrentMap.put ("soundinterpolation",
1215: SoundSource.sndRateConverter == (SoundSource.SND_CHANNELS == 1 ? SoundSource.SNDRateConverter.THINNING_MONO : SoundSource.SNDRateConverter.THINNING_STEREO) ? "thinning" :
1216: SoundSource.sndRateConverter == (SoundSource.SND_CHANNELS == 1 ? SoundSource.SNDRateConverter.LINEAR_MONO : SoundSource.SNDRateConverter.LINEAR_STEREO) ? "linear" :
1217: SoundSource.sndRateConverter == SoundSource.SNDRateConverter.CONSTANT_AREA_STEREO_48000 ? "constant-area" :
1218: SoundSource.sndRateConverter == SoundSource.SNDRateConverter.LINEAR_AREA_STEREO_48000 ? "linear-area" :
1219: "linear");
1220:
1221: sgsCurrentMap.put ("opmoutput", OPM.opmOutputMask != 0 ? "on" : "off");
1222:
1223: sgsCurrentMap.put ("pcmoutput", ADPCM.pcmOutputOn ? "on" : "off");
1224: sgsCurrentMap.put ("pcminterpolation",
1225: ADPCM.pcmInterpolationAlgorithm == ADPCM.PCM_INTERPOLATION_CONSTANT ? "constant" :
1226: ADPCM.pcmInterpolationAlgorithm == ADPCM.PCM_INTERPOLATION_LINEAR ? "linear" :
1227: ADPCM.pcmInterpolationAlgorithm == ADPCM.PCM_INTERPOLATION_HERMITE ? "hermite" :
1228: "linear");
1229: sgsCurrentMap.put ("pcmoscfreq", String.valueOf (ADPCM.pcmOSCFreqRequest));
1230:
1231:
1232:
1233:
1234:
1235:
1236:
1237: for (String key : SGS_FRAME_KEYS) {
1238:
1239: sgsPutIntArray (key + "rect", RestorableFrame.rfmGetRect (key), 0);
1240:
1241: int state = RestorableFrame.rfmGetState (key);
1242: sgsPutString (key + "stat",
1243: (state & Frame.ICONIFIED) == Frame.ICONIFIED ? "iconified" :
1244: (state & Frame.MAXIMIZED_BOTH) == Frame.MAXIMIZED_BOTH ? "maximized" :
1245: (state & Frame.MAXIMIZED_BOTH) == Frame.MAXIMIZED_HORIZ ? "h-maximized" :
1246: (state & Frame.MAXIMIZED_BOTH) == Frame.MAXIMIZED_VERT ? "v-maximized" :
1247: "normal");
1248:
1249: sgsPutOnOff (key + "open", sgsXxxOpen && RestorableFrame.rfmGetOpened (key));
1250: }
1251:
1252:
1253: sgsSaveIniFile (sgsEncodeRootMap ());
1254:
1255: }
1256:
1257:
1258:
1259: public static void sgsDecodeRootMap (String text) {
1260: sgsRootMap.clear ();
1261: sgsCurrentMap.clear ();
1262: sgsCurrentMap = new HashMap<String,String> (sgsStartMap);
1263: sgsCurrentMap.put ("_", "");
1264: sgsRootMap.put ("", sgsCurrentMap);
1265: HashMap<String,String> map = sgsCurrentMap;
1266: for (String line : text.split ("\n")) {
1267: line = line.trim ();
1268: if (line.length () == 0 ||
1269: line.startsWith ("#")) {
1270: continue;
1271: }
1272: int i = line.indexOf ('=');
1273: if (i < 0) {
1274: continue;
1275: }
1276: String key = line.substring (0, i).trim ().toLowerCase ();
1277: String value = line.substring (i + 1).trim ();
1278: if (key.equals ("_")) {
1279: if (sgsRootMap.containsKey (value)) {
1280: if (false) {
1281: map = null;
1282: } else {
1283: map = sgsRootMap.get (value);
1284: }
1285: } else {
1286: map = new HashMap<String,String> (sgsStartMap);
1287: map.put (key, value);
1288: sgsRootMap.put (value, map);
1289: }
1290: continue;
1291: }
1292: if (map == null) {
1293: continue;
1294: }
1295: sgsPutParameter (map, key, value);
1296: }
1297: }
1298:
1299:
1300:
1301: public static ArrayList<String> sgsEncodeRootMap () {
1302: ArrayList<String> strings = new ArrayList<String> ();
1303: String[] nameArray = sgsRootMap.keySet ().toArray (new String[0]);
1304: Arrays.sort (nameArray, DictionaryComparator);
1305: for (String name : nameArray) {
1306: HashMap<String,String> map = sgsRootMap.get (name);
1307: if (map != sgsCurrentMap) {
1308: strings.add ("\n");
1309: }
1310: String[] keyArray = map.keySet ().toArray (new String[0]);
1311: Arrays.sort (keyArray, DictionaryComparator);
1312: for (String key : keyArray) {
1313: String value = map.get (key);
1314: if (!(map == sgsCurrentMap && key.equals ("_")) &&
1315: !key.equals ("config") &&
1316: !value.equals (sgsStartMap.get (key))) {
1317: strings.add (key);
1318: strings.add ("=");
1319: strings.add (value);
1320: strings.add ("\n");
1321: }
1322: }
1323: }
1324: return strings;
1325: }
1326:
1327:
1328:
1329: public static void sgsDeleteAllSettings () {
1330: XEiJ.pnlExitFullScreen (true);
1331: if (JOptionPane.showConfirmDialog (
1332: XEiJ.frmFrame,
1333: Multilingual.mlnJapanese ? "すべての設定を消去しますか?" : "Do you want to delete all settings?",
1334: Multilingual.mlnJapanese ? "確認" : "Confirmation",
1335: JOptionPane.YES_NO_OPTION,
1336: JOptionPane.PLAIN_MESSAGE) == JOptionPane.YES_OPTION) {
1337: sgsDeleteIniFile ();
1338: sgsSaveOnExit = false;
1339: sgsSaveOnExitCheckBox.setSelected (sgsSaveOnExit);
1340: }
1341: }
1342:
1343:
1344:
1345:
1346:
1347: public static void sgsPutParameter (HashMap<String,String> map, String key, String value) {
1348: if (sgsDefaultMap.containsKey (key)) {
1349: String defaultValue = sgsDefaultMap.get (key);
1350: if (defaultValue.equals ("off") || defaultValue.equals ("on")) {
1351: value = (value.equals ("0") ||
1352: value.equalsIgnoreCase ("no") ||
1353: value.equalsIgnoreCase ("off") ? "off" : "on");
1354: }
1355: map.put (key, value);
1356: }
1357: }
1358:
1359:
1360:
1361:
1362:
1363: public static String sgsLoadIniFile () {
1364: return XEiJ.rscGetTextFile (sgsIniPath);
1365: }
1366:
1367:
1368:
1369: public static void sgsSaveIniFile (ArrayList<String> strings) {
1370: XEiJ.rscPutTextFile (sgsIniPath, strings);
1371: }
1372:
1373:
1374:
1375: public static void sgsDeleteIniFile () {
1376: if (sgsIniFile.isFile ()) {
1377: if (sgsIniFile.delete ()) {
1378: System.out.println (sgsIniPath + (Multilingual.mlnJapanese ? " を削除しました" : " was removed"));
1379: } else {
1380: System.out.println (sgsIniPath + (Multilingual.mlnJapanese ? " を削除できません" : " cannot be removed"));
1381: return;
1382: }
1383: }
1384: String bakPath = sgsIniPath + ".bak";
1385: File bakFile = new File (bakPath);
1386: if (bakFile.isFile ()) {
1387: if (bakFile.delete ()) {
1388: System.out.println (bakPath + (Multilingual.mlnJapanese ? " を削除しました" : " was removed"));
1389: } else {
1390: System.out.println (bakPath + (Multilingual.mlnJapanese ? " を削除できません" : " cannot be removed"));
1391: return;
1392: }
1393: }
1394: String tmpPath = sgsIniPath + ".tmp";
1395: File tmpFile = new File (tmpPath);
1396: if (tmpFile.isFile ()) {
1397: if (tmpFile.delete ()) {
1398: System.out.println (tmpPath + (Multilingual.mlnJapanese ? " を削除しました" : " was removed"));
1399: } else {
1400: System.out.println (tmpPath + (Multilingual.mlnJapanese ? " を削除できません" : " cannot be removed"));
1401: return;
1402: }
1403: }
1404: if (sgsIniParentDirectory != null &&
1405: sgsIniParentDirectory.isDirectory ()) {
1406: if (sgsIniParentDirectory.delete ()) {
1407: System.out.println (sgsIniParentPath + (Multilingual.mlnJapanese ? " を削除しました" : " was removed"));
1408: } else {
1409: System.out.println (sgsIniParentPath + (Multilingual.mlnJapanese ? " を削除できません" : " cannot be removed"));
1410: }
1411: }
1412: }
1413:
1414:
1415:
1416: }
1417:
1418:
1419: