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