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