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