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