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