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