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