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