Settings.java
     1: //========================================================================================
     2: //  Settings.java
     3: //    en:Settings
     4: //    ja:設定
     5: //  Copyright (C) 2003-2025 Makoto Kamada
     6: //
     7: //  This file is part of the XEiJ (X68000 Emulator in Java).
     8: //  You can use, modify and redistribute the XEiJ if the conditions are met.
     9: //  Read the XEiJ License for more details.
    10: //  https://stdkmd.net/xeij/
    11: //========================================================================================
    12: 
    13: //----------------------------------------------------------------------------------------
    14: //
    15: //  設定ファイル
    16: //    XEiJの動作環境を指示する「設定」が1つ以上記述されているファイル
    17: //    場所
    18: //      Windowsのとき(os.nameがWindowsを含むとき)
    19: //        %APPDATA%\XEiJ\XEiJ.ini    C:\Users\%USERNAME%\AppData\Roaming\XEiJ\XEiJ.iniなど。%~%は環境変数
    20: //      その他
    21: //        ~/XEiJ.ini                 ~はuser.home
    22: //        ./XEiJ.ini                 .はuser.dir
    23: //    内容
    24: //      [タイトルA]
    25: //      キーワードA1=値A1
    26: //      キーワードA2=値A2
    27: //          :
    28: //      [タイトルB]
    29: //      キーワードB1=値B1
    30: //      キーワードB2=値B2
    31: //          :
    32: //
    33: //  設定の種類
    34: //    設定にはデフォルト設定とユーザ設定がある
    35: //    デフォルト設定(default)
    36: //      タイトルがdefaultの設定
    37: //      プログラムに埋め込まれている定数にhomeとlangを加えたもの
    38: //      デフォルト設定にないキーワードは指定できない
    39: //      デフォルト設定と同じ値のパラメータは保存されない
    40: //    ユーザ設定
    41: //      タイトルがdefault以外の設定
    42: //      saveonexit=onのとき設定ファイルに保存される
    43: //      無題設定と仮設定とその他のユーザ設定がある
    44: //      無題設定(notitle)
    45: //        [notitle]のユーザ設定
    46: //        起動時にユーザ設定が1つもないときデフォルト設定が無題設定にコピーされて現在の設定になる
    47: //        自動で作られることを除けば普通のユーザ設定
    48: //        設定ファイルの先頭に配置される
    49: //        設定ファイルの最初の設定が無題設定のとき[notitle]を省略できる
    50: //      仮設定(temporary)
    51: //        [temporary]のユーザ設定
    52: //        -config=defaultを指定するとデフォルト設定が仮設定にコピーされて現在の設定になる
    53: //        -config=defaultを指定するとデフォルト設定に巻き戻されるので常用は避けた方が良い
    54: //        設定ファイルの無題設定の後に配置される
    55: //      その他のユーザ設定
    56: //        設定ファイルの無題設定と仮設定の後に配置される
    57: //        その他のユーザ設定の順序はユーザが自由に並べ替えることができる
    58: //
    59: //  パラメータ
    60: //    設定ファイル
    61: //      キーワード=値
    62: //      1行に1組ずつ書く
    63: //      キーワードと値の前後に余分な空白があってはならない
    64: //    コマンドライン
    65: //      -キーワード=値
    66: //      1引数に1組ずつ書く
    67: //      キーワードと値の前後に余分な空白があってはならない
    68: //    キーワード
    69: //      英小文字で始まり英小文字と数字で構成される文字列
    70: //    値
    71: //      空白以外で始まり空白以外で終わる文字列
    72: //      空列または空白を含む文字列は"~"で囲む
    73: //      デフォルト設定で値がonまたはoffのパラメータはonまたはoffだけ指定できる
    74: //      デフォルト設定で値がyesまたはnoのパラメータはyesまたはnoだけ指定できる
    75: //      デフォルト設定で値が符号と数字だけのパラメータは符号と数字だけ指定できる
    76: //      キーワードがdataで終わるパラメータ
    77: //        値がgzip+base64で圧縮されている
    78: //        値が非常に大きい場合があり、原則として文字列の状態では編集できない
    79: //        バイナリデータとして編集する機能を付けてもよい
    80: //
    81: //  デフォルト設定で環境に合わせて作られるパラメータ
    82: //    home=path
    83: //      ホームディレクトリ。末尾の区切り文字は含まない
    84: //      ファイルチューザーが最初に開くディレクトリ
    85: //    lang=en
    86: //    lang=ja
    87: //      表示言語
    88: //
    89: //  設定ファイルの特別なパラメータ
    90: //    [タイトル]
    91: //      新しい設定の開始。設定のタイトル
    92: //      []、[default]は不可
    93: //      -config=タイトルで設定を選択するときに使う
    94: //      タイトルが同じ設定が複数存在してはならない
    95: //      改行を含むことはできない
    96: //      [、]を除く文字は何でも書けるが、"、'、`、$などはコマンドラインで選択するときに書きにくいので避けた方が良い
    97: //      設定ファイルの最初の設定が無題設定のとき[notitle]を省略できる
    98: //    current=yes
    99: //    current=no
   100: //      現在の設定かどうか
   101: //      current=yesのユーザ設定が1つだけ存在する
   102: //    description=説明
   103: //      設定の説明
   104: //
   105: //  コマンドラインの特別なパラメータ
   106: //    -config=~はコマンドラインの最後に書いても他のパラメータよりも優先して解釈される
   107: //    -config=default
   108: //      デフォルト設定が仮設定にコピーされて現在の設定になる
   109: //      一時的にデフォルト設定で起動したいときに使う
   110: //      他のパラメータはデフォルト設定がコピーされた仮設定に上書きされる
   111: //      仮設定は-config=defaultを指定すると消えてしまうので、仮設定の常用は避けた方が良い
   112: //      仮設定以外の設定はcurrent=yesがcurrent=noになるものを除いて変化しない。すべての設定が初期化されるわけではない
   113: //    -config=タイトル
   114: //      タイトルで選択されたユーザ設定(無題設定、仮設定を含む)が現在の設定になる
   115: //      他のパラメータは選択されたユーザ設定に上書きされる
   116: //
   117: //  その他の特筆すべきパラメータ
   118: //    saveonexit=on
   119: //    saveonexit=off
   120: //      終了時に設定ファイルを更新するかどうか
   121: //      現在の設定がsaveonexit=offのとき終了時に設定ファイルが更新されない
   122: //      設定ファイルにエラーがあったとき
   123: //        設定ファイルを更新してしまうとエラーの箇所やそれ以降に書かれていた内容が消えてしまう恐れがある
   124: //        現在の設定がsaveonexit=onでも終了時に設定ファイルを更新せず手動で修正することを促す
   125: //
   126: //----------------------------------------------------------------------------------------
   127: 
   128: package xeij;
   129: 
   130: import java.awt.*;  //BasicStroke,BorderLayout,BoxLayout,Color,Component,Container,Cursor,Desktop,Dimension,Font,Frame,Graphics,Graphics2D,GraphicsDevice,GraphicsEnvironment,GridLayout,Image,Insets,Paint,Point,Rectangle,RenderingHints,Robot,Shape,Stroke,TexturePaint,Toolkit
   131: import java.awt.event.*;  //ActionEvent,ActionListener,ComponentAdapter,ComponentEvent,ComponentListener,FocusAdapter,FocusEvent,FocusListener,InputEvent,KeyAdapter,KeyEvent,KeyListener,MouseAdapter,MouseEvent,MouseListener,MouseMotionAdapter,MouseWheelEvent,WindowAdapter,WindowEvent,WindowListener,WindowStateListener
   132: import java.io.*;  //BufferedInputStream,BufferedOutputStream,BufferedReader,BufferedWriter,File,FileInputStream,FileNotFoundException,FileReader,InputStream,InputStreamReader,IOException,OutputStreamWriter,RandomAccessFile
   133: import java.lang.*;  //Boolean,Character,Class,Comparable,Double,Exception,Float,IllegalArgumentException,Integer,Long,Math,Number,Object,Runnable,SecurityException,String,StringBuilder,System
   134: import java.net.*;  //MalformedURLException,URI,URL
   135: import java.util.*;  //ArrayList,Arrays,Calendar,GregorianCalendar,HashMap,Map,Map.Entry,Timer,TimerTask,TreeMap
   136: import java.util.regex.*;  //Matcher,Pattern
   137: //import javax.jnlp.*;  //BasicService,PersistenceService,ServiceManager,UnavailableServiceException
   138: import javax.swing.*;  //AbstractSpinnerModel,Box,ButtonGroup,DefaultListModel,ImageIcon,JButton,JCheckBox,JCheckBoxMenuItem,JDialog,JFileChooser,JFrame,JLabel,JList,JMenu,JMenuBar,JMenuItem,JPanel,JRadioButton,JScrollPane,JSpinner,JTextArea,JTextField,JTextPane,JViewport,ScrollPaneConstants,SpinnerListModel,SpinnerNumberModel,SwingConstants,SwingUtilities,UIManager,UIDefaults,UnsupportedLookAndFeelException
   139: import javax.swing.event.*;  //CaretListener,ChangeEvent,ChangeListener,DocumentEvent,DocumentListener,ListSelectionListener
   140: import netscape.javascript.*;  //JSException,JSObject。jfxrt.jarではなくplugin.jarを使うこと
   141: 
   142: public class Settings {
   143: 
   144:   //RestorableFrameのキーの一覧
   145:   //  ウインドウの位置とサイズ(~rect)、状態(~stat)、開くかどうか(~open)のパラメータで使う
   146:   public static final String SGS_ACM_FRAME_KEY = "acm";  //ACM アドレス変換キャッシュモニタ
   147:   public static final String SGS_ATW_FRAME_KEY = "atw";  //ATW 論理空間モニタ
   148:   public static final String SGS_BFN_FRAME_KEY = "bfn";  //BFN ボタン機能
   149:   public static final String SGS_BLG_FRAME_KEY = "blg";  //BLG 分岐ログ
   150:   public static final String SGS_DBP_FRAME_KEY = "dbp";  //DBP データブレークポイント
   151:   public static final String SGS_DDP_FRAME_KEY = "ddp";  //DDP 逆アセンブルリスト
   152:   public static final String SGS_DGT_FRAME_KEY = "dgt";  //DGT コンソールウインドウ
   153:   public static final String SGS_DMP_FRAME_KEY = "dmp";  //DMP メモリダンプリスト
   154:   public static final String SGS_DRP_FRAME_KEY = "drp";  //DRP レジスタ
   155:   public static final String SGS_FNT_FRAME_KEY = "fnt";  //FNT フォントエディタ
   156:   public static final String SGS_FRM_FRAME_KEY = "frm";  //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";  //KBS キーボード設定
   160:   public static final String SGS_OLG_FRAME_KEY = "olg";  //OLG OPMログ
   161:   public static final String SGS_PAA_FRAME_KEY = "paa";  //PAA 物理空間モニタ
   162:   public static final String SGS_PFF_FRAME_KEY = "pff";  //PFF プロファイリング
   163:   public static final String SGS_PFV_FRAME_KEY = "pfv";  //PFV プログラムフロービジュアライザ
   164:   public static final String SGS_PPI_FRAME_KEY = "ppi";  //PPI ジョイスティック
   165:   public static final String SGS_PRN_FRAME_KEY = "prn";  //PRN プリンタ
   166:   public static final String SGS_RBP_FRAME_KEY = "rbp";  //RBP ラスタブレークポイント
   167:   public static final String SGS_RTL_FRAME_KEY = "rtl";  //RTL ルートポインタリスト
   168:   public static final String SGS_SMN_FRAME_KEY = "smn";  //SMN 音声モニタ
   169:   public static final String SGS_SMT_FRAME_KEY = "smt";  //SMT 表示モードテスト
   170:   public static final String SGS_SPV_FRAME_KEY = "spv";  //SPV スプライトパターンビュア
   171:   public static final String SGS_PLV_FRAME_KEY = "plv";  //PLV パレットビュア
   172:   public static final String SGS_TRM_FRAME_KEY = "trm";  //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:   //  キーワードはnullではない。値もnullではない
   206:   //  キーワードは""ではない。値が""のときは指定されていないものとみなす
   207:   //  デフォルト設定で値がonまたはoffのパラメータはonまたはoffだけ指定できる
   208:   //  デフォルト設定で値がyesまたはnoのパラメータはyesまたはnoだけ指定できる
   209:   //  デフォルト設定で値が符号と数字だけのパラメータは符号と数字だけ指定できる
   210:   //      キーワードがdataで終わるパラメータ
   211:   //        値がgzip+base64で圧縮されている
   212: 
   213:   public static final String SGS_DEFAULT_PARAMETERS = (
   214:     //PRG
   215:     "verbose;on;" +  //冗長表示(on/off)
   216:     //SGS
   217:     //"_;;" +  //この設定の設定名。ここには書かない
   218:     "saveonexit;on;" +  //終了時に設定を保存(on/off)
   219:     "xxxopen;on;" +  //開いていたウインドウを復元する(on/off)
   220:     "config;;" +  //復元する設定の設定名。パラメータで指定する。設定ファイルには出力しない
   221:     "lang;en;" +  //言語(en/ja)。初期値は動作環境の言語
   222:     "home;;" +  //ホームディレクトリ。初期値は動作環境のホームディレクトリ
   223:     "dir;;" +  //カレントディレクトリ。初期値は動作環境のカレントディレクトリ
   224:     //LNF
   225:     "hsb;240,240,240,70,50,30,0,50,100;" +  //配色
   226:     "hhssbb;none;" +  //配色(廃止)
   227:     "fontsize;14;" +  //文字の大きさ(10/12/14/16/18)
   228:     //KBD
   229:     "keyboard;standard;" +  //キーボードの種類(none,standard,compact)
   230:     "hidekeyboard;on;" +  //全画面表示のときキーボードを隠す(on/off)
   231:     "keymapus;off;" +  //USレイアウト(on/off)
   232:     "keymap;;" +  //Zキーボード以外のキーマップ
   233:     "zkeyboard;off;" +  //Zキーボード(on/off)
   234:     "zkeymap;;" +  //Zキーボードのキーマップ
   235:     //BFN
   236:     "f11key;fullscreen;" +  //F11 全画面表示の切り替え
   237:     "shiftf11key;maximized;" +  //Shift+F11 最大化の切り替え
   238:     "ctrlf11key;donothing;" +  //Ctrl+F11
   239:     "altf11key;donothing;" +  //Alt+F11
   240:     "f12key;seamless;" +  //F12 シームレスマウスの切り替え
   241:     "shiftf12key;donothing;" +  //Shift+F12
   242:     "ctrlf12key;donothing;" +  //Ctrl+F12
   243:     "altf12key;donothing;" +  //Alt+F12
   244:     "wheel;seamless;" +  //WheelButton シームレスマウスの切り替え
   245:     "shiftwheel;donothing;" +  //Shift+WheelButton
   246:     "ctrlwheel;donothing;" +  //Ctrl+WheelButton
   247:     "altwheel;donothing;" +  //Alt+WheelButton
   248:     "wheelup;trace1;" +  //WheelScrollUp トレース1回
   249:     "shiftwheelup;trace10;" +  //Shift+WheelScrollUp トレース10回
   250:     "ctrlwheelup;trace100;" +  //Ctrl+WheelScrollUp トレース100回
   251:     "altwheelup;donothing;" +  //Alt+WheelScrollUp
   252:     "wheeldown;step1;" +  //WheelScrollDown ステップ1回
   253:     "shiftwheeldown;step10;" +  //Shift+WheelScrollDown ステップ10回
   254:     "ctrlwheeldown;step100;" +  //Ctrl+WheelScrollDown ステップ100回
   255:     "altwheeldown;return;" +  //Alt+WheelScrollDown ステップアンティルリターン
   256:     "button4;donothing;" +  //Button4
   257:     "shiftbutton4;donothing;" +  //Shift+Button4
   258:     "ctrlbutton4;donothing;" +  //Ctrl+Button4
   259:     "altbutton4;donothing;" +  //Alt+Button4
   260:     "button5;donothing;" +  //Button5
   261:     "shiftbutton5;donothing;" +  //Shift+Button5
   262:     "ctrlbutton5;donothing;" +  //Ctrl+Button5
   263:     "altbutton5;donothing;" +  //Alt+Button5
   264:     "mousewheel;;" +
   265:     //GIF
   266:     "gifwaitingtime;;" +  //GIFアニメーション録画の待ち時間(s)
   267:     "gifrecordingtime;10;" +  //GIFアニメーション録画の録画時間(s)
   268:     "gifmagnification;100;" +  //GIFアニメーション録画の倍率(%)
   269:     "gifinterpolation;bilinear;" +  //アニメーション録画の補間アルゴリズム(nearest,bilinear,bicubic)
   270:     //PNL
   271:     "scaling;fitinwindow;" +  //画面スケーリングモード(fullscreen,maximized,fitinwindow,fixedscale)
   272:     "fixedscale;100;" +  //固定倍率
   273:     "aspectratio256x256;4:3;" +  //アスペクト比256x256
   274:     "aspectratio384x256;4:3;" +  //アスペクト比384x256
   275:     "aspectratio512x512;4:3;" +  //アスペクト比512x512
   276:     "aspectratio768x512;3:2;" +  //アスペクト比768x512
   277:     "interpolation;bilinear;" +  //補間アルゴリズム(nearest,bilinear,bicubic)
   278:     "refreshrate;none;" +  //ホストのリフレッシュレート
   279:     "adjustvsync;off;" +  //垂直同期周波数をホストのリフレッシュレートに合わせる(on/off)
   280:     //PNL
   281:     "usecanvas;on;" +  //キャンバスを使う(on/off)
   282:     "rotation;0;" +  //回転(0/1/2/3)
   283:     //MUS
   284:     "seamless;on;" +  //シームレス/エクスクルーシブ(on/off)
   285:     "followscroll;on;" +  //スクロールに追従する(on/off)
   286:     "ctrlright;off;" +  //Ctrlキー+左ボタンを右ボタンとみなす(on/off)
   287:     "edgeaccel;off;" +  //縁部加速
   288:     "mousespeed;;" +  //マウスカーソルの速度(0~40)
   289:     "hostspixelunits;off;" +  //ホストの画素単位で動く(on/off)
   290:     //TXC
   291:     "textcopyarea;display;" +  //範囲モード(display/c_width/vram/enclosed)
   292:     "textcopy;off;" +  //マウスで都度選択(on/off)
   293:     //MDL
   294:     "model;Hybrid;" +  //機種(Shodai|ACE|EXPERT|PRO|SUPER|XVI|Xellent30|Compact|Hybrid|X68030|030Compact|060turbo)
   295:     "mpu010;off;" +  //機種のMPUが68000のとき68010に変更する(on/off)
   296:     "mpu;none;" +  //MPUの種類(-1=機種に従う/0=MC68000/1=MC68010/3=MC68EC030/6=MC68060)
   297:     "clock;none;" +  //MPUの動作周波数(-1=機種に従う,1..1000,Shodai,ACE,EXPERT,PRO,SUPER,XVI,Xellent30,Compact,Hybrid,X68030,030Compact,060turbo,060turboPRO)
   298:     "mhz;200;" +  //任意の周波数(1~1000)。任意の負荷率がonのときの周波数のスピナーの値
   299:     "util;off;" +  //任意の負荷率(on/off)
   300:     "ratio;100;" +  //任意の負荷率(1~100)
   301:     "waitcycles;on;" +  //ウェイトサイクル(on/off)
   302:     //FPU
   303:     "copro0;2;" +  //マザーボードコプロセッサ。0=なし,1=MC68881,2=MC68882,7=フルスペック,+8=三倍精度
   304:     "copro1;2;" +  //拡張コプロセッサ#1。0=なし,1=MC68881,2=MC68882,7=フルスペック,+8=三倍精度
   305:     "copro2;2;" +  //拡張コプロセッサ#2。0=なし,1=MC68881,2=MC68882,7=フルスペック,+8=三倍精度
   306:     "onchipfpu;7;" +  //オンチップFPU。0=なし,6=MC68060,7=フルスペック,+8=三倍精度
   307:     //FPK
   308:     "fefunc;on;" +  //FEファンクション命令(on/off)
   309:     "rejectfloat;off;" +  //FLOATn.Xを組み込まない(on/off)
   310:     //BUS
   311:     "himem68000;off;" +  //060turboのハイメモリはX68000でも有効(on/off)
   312:     "highmemory;;" +  //X68030のハイメモリのサイズ(MB)(0/16)
   313:     "highmemorysave;off;" +  //X68030のハイメモリの内容を保存する(on/off)
   314:     "highmemorydata;;" +  //X68030のハイメモリの内容(gzip+base64)
   315:     "highmemory060turbo;off;" +  //060turboのローカルメモリを使う(on/off)
   316:     "localmemory;128;" +  //060turboのローカルメモリのサイズ(MB)(0/16/32/64/128/256)
   317:     "localmemorysave;off;" +  //060turboのローカルメモリの内容を保存する(on/off)
   318:     "localmemorydata;;" +  //060turboのローカルメモリの内容(gzip+base64)
   319:     "cutfc2pin;off;" +  //FC2ピンをカットする(on/off)
   320:     //MMR
   321:     "memory;12;" +  //メインメモリのサイズ(0/1/2/4/6/8/10/12)。0は既定値
   322:     "memorysave;on;" +  //メインメモリの内容を保存する(on/off)
   323:     "memorydata;;" +  //メインメモリの内容(gzip+base64)
   324:     //CON
   325:     "pastepipe;off;" +  //貼り付けパイプと制御パイプを使う(on/off)
   326:     "pipeencoding;sjis;" +  //貼り付けパイプと制御パイプの文字コード(sjis/utf8)
   327:     //CRT
   328:     "intermittent;0;" +  //間欠描画(0~4)
   329:     "stereoscopic;off;" +  //立体視(on/off)
   330:     "stereoscopicmethod;nakedeyecrossing;" +  //立体視の方法(nakedeyecrossing/nakedeyeparallel/sidebyside/topandbottom)
   331:     "extendedgraphic;off;" +  //拡張グラフィック画面(on/off)
   332:     "scanline;medium;" + //走査線エフェクト(off/weak/medium/strong/black)
   333:     "dotclock;,,;" +  //ドットクロックオシレータ(low,high,vga)
   334:     "eleventhbit;off;" +  //1024ドットノンインターレース(on/off)
   335:     "sphericalscrolling;off;" +  //球面スクロール(on/off)
   336:     "r00bit0zero;off;" +  //CRTC R00のビット0(on/off)
   337:     //SPR
   338:     "sprras;32;" +  //ラスタあたりのスプライトの枚数(0~/*2040*/1016)
   339:     "dblspr;off;" +  //256枚のスプライト(on/off)(廃止)
   340:     "numspr;128;" +  //スプライトの枚数(128/256/504/1016/* /2040*/)
   341:     "sprbank;off;" +  //4096個のパターン(on/off)
   342:     "spr768x512;off;" +  //768x512でスプライトを表示(on/off)
   343:     "spr512bg1;off;" +  //512x512でBG1を表示(on/off)
   344:     "sprrcscroll;off;" +  //行スクロールと列スクロール(on/off)
   345:     //SND
   346:     "sound;on;" +  //音声出力(on/off)
   347:     "volume;20;" +  //ボリューム(0~40)
   348:     "soundinterpolation;linear;" +  //音声補間(thinning/linear/constant-area/linear-area)
   349:     //OPM
   350:     "opmoutput;on;" +  //OPM出力
   351:     //PCM
   352:     "pcmoutput;on;" +  //PCM出力
   353:     "pcminterpolation;linear;" +  //PCM補間(constant/linear/hermite)
   354:     "pcmoscfreq;0;" +  //PCM原発振周波数(0=8MHz/4MHz,1=8MHz/16MHz)
   355:     //FDC
   356:     //  ユニットとヒストリは後で設定する
   357:     "fdreadonly;off;" +  //書き込み禁止(on/off)
   358:     "fdappreboot;off;" +  //ここから再起動(on/off)
   359:     //HDC
   360:     //  ユニットとヒストリは後で設定する
   361:     "sareadonly;off;" +  //書き込み禁止(on/off)
   362:     "saappreboot;off;" +  //ここから再起動(on/off)
   363:     //SPC
   364:     //  ユニットとヒストリは後で設定する
   365:     "screadonly;off;" +  //SCSI HDを書き込み禁止で開く(on/off)
   366:     "scappreboot;off;" +  //ここから再起動(on/off)
   367:     //HCD ホストCD-ROM
   368:     "hcddebug;off;" +  //デバッグ情報(on/off)
   369:     "hcdconnect;off;" +  //接続する(on/off)
   370:     "hcdscsiid;6;" +  //SCSI ID(0~15)
   371:     "hcdvolume;25;" +  //音量(0~100)
   372:     //HFS
   373:     //  ユニットとヒストリは後で設定する
   374:     "hfreadonly;off;" +  //書き込み禁止(on/off)
   375:     "hfappreboot;off;" +  //ここから再起動(on/off)
   376:     "utf8warning;off;" +  //HFSで開いたファイルがUTF-8のとき警告する
   377:     //PPI
   378:     "joykey;on;" +  //キーボードの一部をジョイスティックとみなす
   379:     "joyauto;on;" +  //ジョイスティックポートが連続的に読み出されている間だけ有効
   380:     "joyblock;on;" +  //ジョイスティック入力データとして処理されたキーボード入力データを取り除く
   381:     "normal2button1;;" +  //ノーマル2ボタンパッド#1の設定
   382:     "normal2button2;;" +  //ノーマル2ボタンパッド#2の設定
   383:     "megadrive3button1;;" +  //メガドラ3ボタンパッド#1の設定
   384:     "megadrive3button2;;" +  //メガドラ3ボタンパッド#2の設定
   385:     "megadrive6button1;;" +  //メガドラ6ボタンパッド#1の設定
   386:     "megadrive6button2;;" +  //メガドラ6ボタンパッド#2の設定
   387:     "cyberstickdigital1;;" +  //サイバースティック(デジタルモード)#1の設定
   388:     "cyberstickdigital2;;" +  //サイバースティック(デジタルモード)#2の設定
   389:     "cyberstickanalog1;;" +  //サイバースティック(アナログモード)#1の設定
   390:     "cyberstickanalog2;;" +  //サイバースティック(アナログモード)#2の設定
   391:     "shiromadokun1;;" +  //白窓君1の仕様
   392:     "shiromadokun2;;" +  //白窓君2の仕様
   393:     "joystick1;normal2button1;" +  //ジョイスティックポート1に接続するデバイス
   394:     "joystick2;normal2button2;" +  //ジョイスティックポート2に接続するデバイス
   395:     "xinput;off;" +  //XInput(on/off)
   396:     //EXS
   397:     "scsiex;off;" +  //on=拡張SCSIポートを有効にする
   398:     //SMR
   399:     "boot;default;" +  //起動デバイス(default/std/fdN/hdN/scN/hfN/rom$X/ram$X)
   400:     "keydly;-1;" +  //リピートディレイ(-1=既定/200+100*n)
   401:     "keyrep;-1;" +  //リピートインターバル(-1=既定/30+5*n^2)
   402:     "sram;none;" +  //SRAMイメージファイル名
   403:     "sramdata;;" +  //SRAMの内容(gzip+base64)
   404:     "sramsize;16;" +  //SRAMの容量(16/32/64)
   405:     "romdb;none;" +  //ROMデバッガ起動フラグ
   406:     "modifymemorysize;on;" +  //SRAMにあるメモリサイズを修正する
   407:     "srambuserror;off;" +  //SRAMへの書き込み時のバスエラー
   408:     //BNK
   409:     "bankdata;;" +  //バンクメモリの内容(gzip+base64)
   410:     //ROM
   411:     "rom;none;" +  //ROMのイメージファイル名
   412:     "cgrom;none;" + //CGROMのイメージファイル名
   413:     "rom30;none;" +  //X68030のIPLROMのイメージファイル名
   414:     "scsiinrom;none;" +  //SCSIINROMのイメージファイル名
   415:     "scsiexrom;none;" +  //SCSIEXROMのイメージファイル名
   416:     "iplrom;none;" +  //IPLROMのイメージファイル名
   417:     "x68000logo;none;" +  //X68000ロゴファイル名
   418:     "iplrom16style;7;" +  //IPLROM 1.6のメッセージのスタイル
   419:     "iplrom256k;off;" +  //X68000のIPLROMを256KBに改造する
   420:     "iplrom16;off;" +  //IPLROM 1.6を使う
   421:     "omusubi;off;" +  //おむすびフォントを使う
   422:     //PRN
   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:     //SCC
   438:     "sccfreq;5000000;" +  //SCCの動作周波数
   439:     //SPV
   440:     "spvbank;0;" +  //バンク
   441:     "spvblock;-1;" +  //パレットブロック
   442:     "spvflip;-1;" +  //反転
   443:     "spvhex;off;" +  //Hex
   444:     "spvscale;0;" +  //倍率
   445:     "spvsize;-1;" +  //サイズ
   446:     //PLV
   447:     "plvarrgt;2;" +  //配置
   448:     "plvhex;off;" +  //Hex
   449:     "plvscale;0;" +  //倍率
   450:     //TRM
   451:     "rs232cconnection;Terminal+%E2%87%94+AUX;" +  //接続。textをURLEncoderにかけて/で連結
   452:     "terminalsettings;38400/B8/PN/S1/RTS;" +  //ターミナルの通信設定。38400などを/で連結
   453:     "additionalport;none;" +  //追加ポート。portDescriptorを,で連結。エンコード
   454:     "tcpiphost;0.0.0.0;" +  //TCP/IPホスト
   455:     "tcpipport;54321;" +  //TCP/IPポート番号
   456:     "tcpiputf8;off;" +  //SJIS⇔UTF-8変換
   457:     //  PPPサーバー
   458:     "pppaddress;192.168.10.1:192.168.10.2;" +  //ローカルIPアドレス:リモートIPアドレス
   459:     "pppdebug;off;" +  //デバッグ表示あり
   460:     "pppdirect;off;" +  //モデム層を省略する
   461:     "ppplog;off;" +  //pppdの標準エラー出力をターミナルに出力する
   462:     "pppserver;off;" +  //PPPサーバー有効
   463:     //XT3
   464:     "xt3dipsw;3;" +  //Xellent30のDIPSW(0~3)
   465:     "xt3memorykb;256;" +  //Xellent30のメモリのサイズ(256/1024)
   466:     "xt3memorydata;;" +  //Xellent30のメモリの内容(gzip+base64)
   467:     "xt3memorysave;off;"  //Xellent30のメモリの保存フラグ(on/off)
   468:     );
   469: 
   470:   public static final String SGS_APPDATA_FOLDER = "XEiJ";  //Windowsのみ。AppData/Roamingフォルダに掘るフォルダの名前
   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);  //-bootに指定できる起動デバイス名
   474: 
   475:   public static String sgsAppDataRoamingFolder;  //Windowsのみ。AppData/Roamingフォルダ。1人のユーザが複数のPCで同期して利用できるファイルを入れる
   476:   public static String sgsAppDataLocalFolder;  //Windowsのみ。AppData/Localフォルダ。1人のユーザがこのPCだけで利用できるファイルを入れる
   477:   public static String sgsHomeDirectory;  //ホームディレクトリ
   478:   public static String sgsCurrentDirectory;  //カレントディレクトリ
   479: 
   480:   public static File sgsIniParentDirectory;  //Windowsのみ。設定ファイルの親ディレクトリ。なければnull。設定ファイルを-iniで指定したときもnull
   481:   public static String sgsIniParentPath;  //Windowsのみ。設定ファイルの親ディレクトリのパス。なければnull
   482:   public static File sgsIniFile;  //設定ファイル
   483:   public static String sgsIniPath;  //設定ファイルのパス
   484: 
   485:   public static boolean sgsSaveOnExit;  //true=終了時に設定を保存する
   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;  //デフォルトの設定。SGS_DEFAULT_PARAMETERSを変換したもの
   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:   //DictionaryComparator
   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);  //(c1<0)==isdigit(c1)
   518:           for (e1++; e1 < l1; e1++) {
   519:             c2 = s1.charAt (e1);
   520:             c2 = ('0' - 1) - c2 & c2 - ('9' + 1);  //(c2<0)==isdigit(c2)
   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);  //(c1<0)==isdigit(c1)
   529:           for (e2++; e2 < l2; e2++) {
   530:             c2 = s2.charAt (e2);
   531:             c2 = ('0' - 1) - c2 & c2 - ('9' + 1);  //(c2<0)==isdigit(c2)
   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:               //  部分文字列が残っている方は数字ではないので1文字比較するだけで大小関係がはっきりする
   573:               //f = (b1 < l1 ? s1.charAt (b1) : -1) - (b2 < l2 ? s2.charAt (b2) : -1);
   574:               f = (e1 - b1) - (e2 - b2);  //部分文字列が片方だけ残っているときは残っている方が大きい
   575:               break compare;
   576:             }
   577:           }  //if 両方数字のとき/どちらかが数字ではないとき
   578:         }  //for b1,b2
   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:       }  //compare
   590:       return (f >> 31) - (-f >> 31);
   591:     }  //compare(String,String)
   592:   };  //DictionaryComparator
   593: 
   594:   //sgsInit ()
   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:     //  SGS_DEFAULT_PARAMETERSを分解してデフォルトの設定sgsDefaultMapを作る
   616:     //  デフォルトの設定sgsDefaultMapには設定名を表すキー"_"が存在しない
   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] : "";  //splitで末尾の空要素が削除されるのでa[i+1]が存在しないとき""とみなす
   623:         sgsDefaultMap.put (key, value);
   624:       }
   625:     }
   626:     //  ユニット
   627:     //  SCSI HDのイメージファイル
   628:     //    拡張  内蔵  sc[0-7]  sc[8-15]
   629:     //    -----------------------------
   630:     //    有効  有効    拡張     内蔵
   631:     //    有効  無効    拡張     無効
   632:     //    無効  有効    内蔵     無効
   633:     //    無効  無効    無効     無効
   634:     for (int i = 0; i < FDC.FDC_MAX_UNITS; i++) {
   635:       sgsDefaultMap.put ("fd" + i, "none");  //FD
   636:     }
   637:     for (int i = 0; i < 16; i++) {
   638:       sgsDefaultMap.put ("hd" + i, "none");  //SASIまたはSCSI
   639:       sgsDefaultMap.put ("sa" + i, "none");  //SASI
   640:       sgsDefaultMap.put ("sc" + i, "none");  //SCSI
   641:     }
   642:     for (int i = 0; i < HFS.HFS_MAX_UNITS; i++) {
   643:       sgsDefaultMap.put ("hf" + i, "none");  //HFS
   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", "");  //ウインドウの位置とサイズ(x,y,width,height)
   655:       sgsDefaultMap.put (key + "stat", "normal");  //ウインドウの状態(iconified/maximized/h-maximized/v-maximized/normal)
   656:       sgsDefaultMap.put (key + "open", "off");  //ウインドウが開いているかどうか。メインのフレームも終了時にはoffになっている
   657:     }
   658: 
   659:     //開始時の設定
   660:     //  デフォルトの設定sgsDefaultMapのコピーに言語やホームディレクトリを追加して開始時の設定sgsStartMapを作る
   661:     //  開始時の設定sgsStartMapには設定名を表すキー"_"が存在しない
   662:     sgsStartMap = new HashMap<String,String> (sgsDefaultMap);
   663: 
   664:     //hf0の初期値はカレントディレクトリ
   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));  //System.getenv()はMap<String,String>
   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 ()));  //System.getProperties()はHashtable<Object,Object>
   680:       m.forEach ((k, v) -> System.out.println (k + " = " + v));
   681:     }
   682: 
   683:     //AppDataフォルダ
   684:     boolean isWindows = System.getProperty ("os.name").indexOf ("Windows") >= 0;  //true=Windows
   685:     sgsAppDataRoamingFolder = isWindows ? System.getenv ("APPDATA") : null;
   686:     sgsAppDataLocalFolder = isWindows ? System.getenv ("LOCALAPPDATA") : null;
   687:     //ホームディレクトリ
   688:     //  new File("")
   689:     sgsHomeDirectory = System.getProperty ("user.home");
   690:     //カレントディレクトリ
   691:     //  new File(".")
   692:     sgsCurrentDirectory = System.getProperty ("user.dir");
   693: 
   694:     //デフォルトの設定ファイルの場所
   695:     if (sgsAppDataRoamingFolder != null) {  //Windows
   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 {  //Windows以外
   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:     //  開始時の設定sgsStartMapをコピーして現在の設定sgsCurrentMapを作る
   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:     //  -iniで設定ファイルが変更される場合がある
   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];  //引数。nullではないはず
   729:     arg:
   730:       {
   731:         boolean boot = false;  //true=valueは-bootの値
   732:         if (value.startsWith ("-")) {  //引数が"-"で始まっている
   733:           //!!! 値が必要なものと必要でないものを区別したい
   734:           int k = value.indexOf ('=', 1);
   735:           if (k >= 0) {  //引数が"-"で始まっていて2文字目以降に"="がある
   736:             key = value.substring (1, k);  //"-"の後ろから"="の手前まではキー
   737:             value = value.substring (k + 1);  //"="の後ろは値
   738:           } else {  //引数が"-"で始まっていて2文字目以降に"="がない
   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");  //値は"1"
   745:           }
   746:           if (!key.equalsIgnoreCase ("boot")) {  //-bootではない
   747:             break arg;
   748:           }
   749:           boot = true;
   750:         }
   751:         //引数が"-"で始まっていないまたは-bootの値
   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;  //末尾の":R"を取り除いた部分
   758:         File file = new File (valueWithoutColonR);
   759:         if (file.isDirectory ()) {  //ディレクトリがある
   760:           key = "hf" + hfNumber++;  //HFS
   761:         } else if (file.isFile ()) {  //ファイルがある
   762:           //FDMedia.fdmPathToMediaが大きすぎるファイルを処理できないので、
   763:           //先に拡張子でハードディスクを区別する
   764:           if (valueWithoutColonR.toUpperCase ().endsWith (".HDF")) {
   765:             key = "sa" + hdNumber++;  //SASI ハードディスク
   766:           } else if (valueWithoutColonR.toUpperCase ().endsWith (".HDS")) {
   767:             key = "sc" + scNumber++;  //SCSI ハードディスク/CD-ROM
   768:           } else if (FDMedia.fdmPathToMedia (valueWithoutColonR, null) != null) {
   769:             key = "fd" + fdNumber++;  //フロッピーディスク
   770:           } else if (HDMedia.hdmPathToMedia (valueWithoutColonR, null) != null) {
   771:             key = "sa" + hdNumber++;  //SASI ハードディスク
   772:           } else {
   773:             key = "sc" + scNumber++;  //SCSI ハードディスク/CD-ROM
   774:           }
   775:         } else {  //ファイルもディレクトリもない
   776:           String[] zipSplittedName = XEiJ.RSC_ZIP_SEPARATOR.split (valueWithoutColonR, 2);  //*.zip/entryを*.zipとentryに分ける
   777:           if (zipSplittedName.length == 2 &&  //*.zip/entryで
   778:               new File (zipSplittedName[0]).isFile ()) {  //*.zipがある
   779:             if (FDMedia.fdmPathToMedia (valueWithoutColonR, null) != null) {
   780:               key = "fd" + fdNumber++;  //フロッピーディスク
   781:             } else if (HDMedia.hdmPathToMedia (valueWithoutColonR, null) != null) {
   782:               key = "sa" + hdNumber++;  //SASI ハードディスク
   783:             } else {
   784:               System.out.println (Multilingual.mlnJapanese ? value + " は不明な起動デバイスです" :
   785:                                   value + " is unknown boot device");
   786:               continue;
   787:             }
   788:           } else {  //*.zip.entryでないか*.zipがない
   789:             System.out.println (Multilingual.mlnJapanese ? value + " は不明な起動デバイスです" :
   790:                                 value + " is unknown boot device");
   791:             continue;
   792:           }
   793:         }
   794:         if (boot) {  //-bootの値のとき
   795:           sgsPutParameter (argumentMap, "boot", key);  //起動デバイスを設定する
   796:         }
   797:       }  //arg
   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:     //設定ファイルを読み込んですべての設定sgsRootMapに格納する
   820:     sgsDecodeRootMap (sgsLoadIniFile ());
   821: 
   822:     //コマンドラインなどのパラメータで使用する設定を選択する
   823:     if (argumentMap.containsKey ("config")) {  //キー"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");  //キー"config"は指定されなかったことにする
   838:     }
   839: 
   840:     //コマンドラインなどのパラメータを現在の設定に上書きする
   841:     //argumentMap.forEach ((k, v) -> sgsCurrentMap.put (k, v));
   842:     for (String key : argumentMap.keySet ()) {
   843:       sgsCurrentMap.put (key, argumentMap.get (key));
   844:     }
   845: 
   846:     //PRG
   847:     String paramLang = sgsCurrentMap.get ("lang").toLowerCase ();
   848:     Multilingual.mlnChange (paramLang.equals ("ja") ? "ja" : "en");
   849:     XEiJ.prgVerbose = sgsGetOnOff ("verbose");  //冗長表示
   850:     //SGS
   851:     sgsSaveOnExit = sgsGetOnOff ("saveonexit");  //終了時に設定を保存するか
   852:     sgsXxxOpen = sgsGetOnOff ("xxxopen");  //開いていたウインドウを復元する
   853:     //LNF
   854:     //  色
   855:     //KBD
   856:     //MUS
   857:     //MPU
   858:     //FPK
   859:     //BUS
   860:     //MMR
   861:     //CRT
   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:     //SND
   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:     //OPM
   880:     OPM.opmOutputMask = sgsGetOnOff ("opmoutput") ? -1 : 0;  //OPM出力
   881:     //PCM
   882:     {
   883:       ADPCM.pcmOutputOn = sgsGetOnOff ("pcmoutput");  //PCM出力
   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:     //FDC
   892:     //fdNはFDCで解釈する
   893:     //HDC
   894:     //hdNはHDCで解釈する
   895:     //SPC
   896:     //scNはSPCで解釈する
   897:     //HFS
   898:     //hfNはHFSで解釈する
   899:     //PPI
   900:     //SMR
   901:     //BNK
   902:     //FNT
   903:     //PRN
   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:   }  //sgsInit()
   927: 
   928:   //sgsTini ()
   929:   //  後始末
   930:   public static void sgsTini () {
   931:     if (sgsSaveOnExit) {  //終了時に設定を保存する
   932:       sgsSaveAllSettings ();
   933:     }
   934:   }  //sgsTini()
   935: 
   936: 
   937: 
   938:   //value = sgsGetString (key)
   939:   //value = sgsGetString (key, def)
   940:   //  現在の設定を読み出す。前後の空白を取り除く。noneまたは""のときdefを返す
   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;  //noneまたは""のときdefを返す
   952:   }
   953: 
   954:   //sgsPutString (key, value)
   955:   //  現在の設定に書き込む。前後の空白を取り除く。""をnoneとみなす
   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);  //""をnoneとみなす
   963:   }
   964: 
   965:   //b = sgsGetOnOff (key)
   966:   //b = sgsGetOnOff (key, def)
   967:   //  現在の設定を読み出す。前後の空白を取り除く
   968:   //  0とoffとnoはfalse、1とonとyesはtrue、それ以外はdef
   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 :  //0とoffとnoはfalse
   982:             value.equals ("1") ||
   983:             value.equalsIgnoreCase ("on") ||
   984:             value.equalsIgnoreCase ("yes") ? true :  //1とonとyesはtrue
   985:             def);  //それ以外はdef
   986:   }
   987: 
   988:   //sgsPutOnOff (key, b)
   989:   //  現在の設定に書き込む。trueをon、falseをoffとみなす
   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");  //trueをon、falseをoffとみなす
   996:   }
   997: 
   998:   //i = sgsGetInt (key)
   999:   //i = sgsGetInt (key, i0)
  1000:   //i = sgsGetInt (key, i0, min, max)
  1001:   //  現在の設定から整数を読み出す。整数でないか範囲外のときi0になる
  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:   //sgsPutInt (key, i)
  1028:   //sgsPutInt (key, i, i0)
  1029:   //  現在の設定に整数を書き込む。i0のとき""になる
  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:   //ia = sgsGetIntArray (key)
  1042:   //ia = sgsGetIntArray (key, n)
  1043:   //ia = sgsGetIntArray (key, n, v)
  1044:   //  現在の設定を読み出す。','で区切る。前後の空白を取り除く。""を0に、それ以外の文字列を10進数とみなして整数に変換する。失敗したときは0
  1045:   //  nは要素の数。-1=可変
  1046:   //  vは指定されなかった要素の値
  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 (",");  //','で区切る。"".split(",").length==1であることに注意
  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);  //10進数とみなして整数に変換する
  1070:         } catch (NumberFormatException nfe) {
  1071:         }
  1072:       }
  1073:     }
  1074:     return ia;
  1075:   }
  1076: 
  1077:   //sgsPutIntArray (key, ia)
  1078:   //sgsPutIntArray (key, ia, v)
  1079:   //  現在の設定に書き込む。vを""に、それ以外の整数を10進数の文字列に変換する。','で区切って並べる。末尾のvの並びを省略する
  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--;  //末尾のvの並びを省略する
  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) {  //vを""に、それ以外の整数を10進数の文字列に変換する
  1098:         sb.append (ia[i]);
  1099:       }
  1100:     }
  1101:     sgsCurrentMap.put (key, sb.toString ());
  1102:   }
  1103: 
  1104:   //array = sgsGetData (key)
  1105:   //  現在の設定を読み出す。gzip+base64で解凍する
  1106:   //  ""のときは長さが0の配列を返す
  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:   //sgsPutData (key, array)
  1117:   //sgsPutData (key, array, offset, length)
  1118:   //  現在の設定に書き込む。gzip+base64で圧縮する
  1119:   //  中途半端に短くすると長さで種類を見分けることができなくなるので末尾の0は切り捨てない
  1120:   //  すべて0のときは""を書き込む
  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) {  //0ではない
  1132:         value = ByteArray.byaEncodeBase64 (ByteArray.byaEncodeGzip (array, offset, length));
  1133:         break;
  1134:       }
  1135:     }
  1136:     sgsCurrentMap.put (key, value);
  1137:   }
  1138: 
  1139: 
  1140: 
  1141:   //sgsMakeMenu ()
  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:   }  //sgsMakeMenu()
  1180: 
  1181:   //sgsSaveAllSettings ()
  1182:   //  設定ファイルを保存する
  1183:   public static void sgsSaveAllSettings () {
  1184:     //MLN
  1185:     sgsCurrentMap.put ("lang", Multilingual.mlnLang);  //言語
  1186:     //PRG
  1187:     sgsCurrentMap.put ("verbose", XEiJ.prgVerbose ? "on" : "off");  //冗長表示
  1188:     //SGS
  1189:     sgsCurrentMap.put ("saveonexit", sgsSaveOnExit ? "on" : "off");  //終了時に設定を保存する
  1190:     sgsCurrentMap.put ("xxxopen", sgsXxxOpen ? "on" : "off");  //開いていたウインドウを復元する
  1191:     //PNL
  1192:     //MUS
  1193:     //FPK
  1194:     sgsCurrentMap.put ("fefunc", FEFunction.fpkOn ? "on" : "off");  //FEファンクション命令
  1195:     sgsCurrentMap.put ("rejectfloat", FEFunction.fpkRejectFloatOn ? "on" : "off");  //FLOATn.Xを組み込まない
  1196:     //BUS
  1197:     //MMR
  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:     //CRT
  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:     //SND
  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:     //OPM
  1218:     sgsCurrentMap.put ("opmoutput", OPM.opmOutputMask != 0 ? "on" : "off");  //OPM出力
  1219:     //PCM
  1220:     sgsCurrentMap.put ("pcmoutput", ADPCM.pcmOutputOn ? "on" : "off");  //PCM出力
  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:     //PPI
  1228:     //SMR
  1229:     //BNK
  1230:     //FNT
  1231:     //PRN
  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:   }  //sgsSaveSettings()
  1253: 
  1254:   //sgsDecodeRootMap (text)
  1255:   //  テキストをsgsRootMapに変換する
  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)) {  //同じ設定名が2回出てきたとき
  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);  //sgsPutParameterは設定名のキー"_"を受け付けないことに注意
  1285:           sgsRootMap.put (value, map);
  1286:         }
  1287:         continue;
  1288:       }
  1289:       if (map == null) {  //新しい設定名が指定されるまで読み飛ばす
  1290:         continue;
  1291:       }
  1292:       sgsPutParameter (map, key, value);
  1293:     }  //for line
  1294:   }  //sgsDecodeRootMap()
  1295: 
  1296:   //strings = sgsEncodeRootMap ()
  1297:   //  sgsRootMapを文字列のリストに変換する
  1298:   public static ArrayList<String> sgsEncodeRootMap () {
  1299:     ArrayList<String> strings = new ArrayList<String> ();  //StringBuilderは大きすぎると失敗する
  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");  //1行空ける
  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") &&  //キー"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:   }  //sgsEncodeRootMap()
  1323: 
  1324:   //sgsDeleteAllSettings ()
  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:   }  //sgsDeleteAllSettings()
  1339: 
  1340:   //sgsPutParameter (map, key, value)
  1341:   //  マップにパラメータを追加する
  1342:   //  デフォルトの設定sgsDefaultMapにないパラメータは無視される。設定名のキー"_"を受け付けないことに注意
  1343:   //  デフォルトの値が"off"または"on"のパラメータの値は"0","no","off"を指定すると"off"、それ以外は"on"に読み替えられる
  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")) {  //デフォルトの値が"off"または"on"のとき
  1348:         value = (value.equals ("0") ||
  1349:                  value.equalsIgnoreCase ("no") ||
  1350:                  value.equalsIgnoreCase ("off") ? "off" : "on");  //"0","no","off"を"off"にそれ以外を"on"に読み替える
  1351:       }
  1352:       map.put (key, value);  //マップに追加する
  1353:     }
  1354:   }  //sgsPutParameter(HashMap<String,String>,String,String)
  1355: 
  1356: 
  1357: 
  1358:   //text = sgsLoadIniFile ()
  1359:   //  設定ファイルを読み込む
  1360:   public static String sgsLoadIniFile () {
  1361:     return XEiJ.rscGetTextFile (sgsIniPath);
  1362:   }  //sgsLoadIniFile()
  1363: 
  1364:   //sgsSaveIniFile ()
  1365:   //  設定ファイルに書き出す
  1366:   public static void sgsSaveIniFile (ArrayList<String> strings) {
  1367:     XEiJ.rscPutTextFile (sgsIniPath, strings);
  1368:   }
  1369: 
  1370:   //sgsDeleteIniFile ()
  1371:   //  設定ファイルを削除する
  1372:   public static void sgsDeleteIniFile () {
  1373:     if (sgsIniFile.isFile ()) {  //XEiJ.iniがある
  1374:       if (sgsIniFile.delete ()) {  //XEiJ.iniを削除する。削除できた
  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 ()) {  //XEiJ.ini.bakがある
  1384:       if (bakFile.delete ()) {  //XEiJ.ini.bakを削除する。削除できた
  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 ()) {  //XEiJ.ini.tmpがある
  1394:       if (tmpFile.delete ()) {  //XEiJ.ini.tmpを削除する。削除できた
  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 ()) {  //AppData/Roaming/XEiJがある
  1403:       if (sgsIniParentDirectory.delete ()) {  //AppData/Roaming/XEiJの削除を試みる。ディレクトリが空でなければ失敗する。削除できた
  1404:         System.out.println (sgsIniParentPath + (Multilingual.mlnJapanese ? " を削除しました" : " was removed"));
  1405:       } else {  //削除できない
  1406:         System.out.println (sgsIniParentPath + (Multilingual.mlnJapanese ? " を削除できません" : " cannot be removed"));
  1407:       }
  1408:     }
  1409:   }  //sgsDeleteIniFile()
  1410: 
  1411: 
  1412: 
  1413: }  //class Settings
  1414: 
  1415: 
  1416: