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