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