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