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