MemoryDumpList.java
     1: //========================================================================================
     2: //  MemoryDumpList.java
     3: //    en:Memory dump list
     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: package xeij;
    14: 
    15: import java.awt.*;  //BasicStroke,BorderLayout,BoxLayout,Color,Component,Container,Cursor,Desktop,Dimension,Font,FlowLayout,Frame,Graphics,Graphics2D,GraphicsDevice,GraphicsEnvironment,GridLayout,Image,Insets,Paint,Point,Rectangle,RenderingHints,Robot,Shape,Stroke,TexturePaint,Toolkit
    16: 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
    17: import java.lang.*;  //Boolean,Character,Class,Comparable,Double,Exception,Float,IllegalArgumentException,Integer,Long,Math,Number,Object,Runnable,SecurityException,String,StringBuilder,System
    18: import java.util.*;  //ArrayList,Arrays,Calendar,GregorianCalendar,HashMap,Map,Map.Entry,TimeZone,Timer,TimerTask,TreeMap
    19: import javax.swing.*;  //AbstractSpinnerModel,Box,ButtonGroup,DefaultListModel,ImageIcon,JApplet,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
    20: import javax.swing.event.*;  //CaretEvent,CaretListener,ChangeEvent,ChangeListener,DocumentEvent,DocumentListener,ListSelectionListener
    21: import javax.swing.text.*;  //AbstractDocument,BadLocationException,DefaultCaret,Document,DocumentFilter,JTextComponent,ParagraphView,Style,StyleConstants,StyleContext,StyledDocument
    22: 
    23: public class MemoryDumpList {
    24: 
    25:   public static final int DMP_ITEM_SIZE = 0x00000010;  //項目の最小サイズ
    26:   public static final int DMP_PAGE_SIZE = 0x00000400;  //ページのサイズ
    27:   public static final int DMP_ITEM_MASK = -DMP_ITEM_SIZE;
    28:   public static final int DMP_PAGE_MASK = -DMP_PAGE_SIZE;
    29:   public static final int DMP_MAX_ITEMS = DMP_PAGE_SIZE / DMP_ITEM_SIZE + 2;  //ページの最大項目数。先頭と末尾の番兵を含む
    30: 
    31:   public static final char[] DMP_BASE = (
    32:     //         11111111112222222222333333333344444444445555555555666666666677777777778
    33:     //12345678901234567890123456789012345678901234567890123456789012345678901234567890
    34:     "xxxxxxxx  xx xx xx xx  xx xx xx xx  xx xx xx xx  xx xx xx xx ").toCharArray ();
    35:   public static final int DMP_DATA_START = 10;  //行頭からデータの開始位置までのオフセット
    36:   public static final int[] DMP_DATA_ADDRESS = {
    37:     0,   1, -1,  2,  3, -1,  4,  5, -1,  6,  7, -1, -1,
    38:     8,   9, -1, 10, 11, -1, 12, 13, -1, 14, 15, -1, -1,
    39:     16, 17, -1, 18, 19, -1, 20, 21, -1, 22, 23, -1, -1,
    40:     24, 25, -1, 26, 27, -1, 28, 29, -1, 30, 31,
    41:   };  //データの開始位置からのオフセット→データのアドレス*2+(0=上位,1=下位)。-1=空白
    42:   public static final int[] DMP_DATA_OFFSET = {
    43:     0,   1,  3,  4,  6,  7,  9, 10,
    44:     13, 14, 16, 17, 19, 20, 22, 23,
    45:     26, 27, 29, 30, 32, 33, 35, 36,
    46:     39, 40, 42, 43, 45, 46, 48, 49,
    47:   };  //データのアドレス*2+(0=上位,1=下位)→データの開始位置からのオフセット
    48: 
    49:   public static int dmpItemCount;  //ページに含まれる項目の数。先頭と末尾の番兵を含む。0=構築前または再構築要求
    50:   public static int dmpItemIndex;  //キャレットがある項目の番号
    51:   public static int dmpPageAddress;  //ページの先頭アドレス
    52:   public static final int[] dmpAddressArray = new int[DMP_MAX_ITEMS];  //項目の先頭アドレスの配列。先頭は前のページの末尾、末尾は次のページの先頭。スピナーのヒント
    53:   public static final int[] dmpSplitArray = new int[DMP_MAX_ITEMS];  //項目を区切る位置の配列。先頭は0
    54:   public static final int[] dmpCaretArray = new int[DMP_MAX_ITEMS];  //項目が選択されたときキャレットを移動させる位置の配列。行の手前にヘッダやラベルなどを挿入しないときはdmpSplitArrayと同じ
    55: 
    56:   public static JFrame dmpFrame;  //ウインドウ
    57:   public static ScrollTextArea dmpBoard;  //スクロールテキストエリア
    58:   public static JTextArea dmpTextArea;  //テキストエリア
    59:   public static Hex8Spinner dmpSpinner;  //スピナー
    60: 
    61:   public static int dmpFunctionCode;  //ファンクションコード
    62:   public static DecimalSpinner dmpFCSpinner;  //ファンクションコードスピナー
    63: 
    64:   public static boolean dmpSecondBridge;  //true=行末からはみ出して書いた文字を行頭にも書く
    65:   public static Color dmpCellophaneColor;  //dmpSecondBridgeではみ出した部分に被せるセロファンの色
    66: 
    67:   //dmpInit ()
    68:   //  初期化
    69:   public static void dmpInit () {
    70: 
    71:     dmpItemCount = 0;  //構築前
    72:     dmpItemIndex = 0;
    73:     dmpPageAddress = 0;
    74: 
    75:     dmpFunctionCode = 5;
    76: 
    77:     //dmpAddressArray = new int[DMP_MAX_ITEMS];
    78:     //dmpSplitArray = new int[DMP_MAX_ITEMS];
    79:     //dmpCaretArray = new int[DMP_MAX_ITEMS];
    80: 
    81:     dmpFrame = null;
    82: 
    83:   }  //dmpInit()
    84: 
    85:   //dmpStart ()
    86:   public static void dmpStart () {
    87:     if (RestorableFrame.rfmGetOpened (Settings.SGS_DMP_FRAME_KEY)) {
    88:       dmpOpen (-1, -1, true);
    89:     }
    90:   }  //dmpStart()
    91: 
    92:   //dmpOpen (address, functionCode, forceUpdate)
    93:   //  メモリダンプリストウインドウを開く
    94:   //  既に開いているときは手前に持ってくる
    95:   public static void dmpOpen (int address, int functionCode, boolean forceUpdate) {
    96:     if (dmpFrame == null) {
    97:       dmpMake ();
    98:     }
    99:     dmpUpdate (address, functionCode, forceUpdate);
   100:     XEiJ.pnlExitFullScreen (false);
   101:     dmpFrame.setVisible (true);
   102:     XEiJ.dbgVisibleMask |= XEiJ.DBG_DMP_VISIBLE_MASK;
   103:   }  //dmpOpen(int,int,boolean)
   104: 
   105:   static class MemoryDumpTextArea extends ScrollTextArea {
   106:     @Override public void paintAfterText (JTextArea textArea, Graphics2D g2) {
   107:       if (MemoryDumpList.dmpSecondBridge) {
   108:         try {
   109:           g2.setPaint (MemoryDumpList.dmpCellophaneColor);
   110:           Rectangle r0 = textArea.modelToView2D (61).getBounds ();  //0の位置
   111:           Rectangle r1 = textArea.modelToView2D (62).getBounds ();  //1の位置
   112:           g2.fillRect (r0.x - (r1.x - r0.x), r0.y,
   113:                        r1.x - r0.x, r0.height * DMP_MAX_ITEMS);  //左側
   114:           g2.fillRect (r0.x + (r1.x - r0.x) * 16, r0.y,
   115:                        r1.x - r0.x, r0.height * DMP_MAX_ITEMS);  //右側
   116:         } catch (BadLocationException ble) {
   117:         }
   118:       }
   119:     }
   120:   }
   121: 
   122:   //dmpMake ()
   123:   //  メモリダンプリストウインドウを作る
   124:   public static void dmpMake () {
   125: 
   126:     //スクロールテキストエリア
   127:     dmpBoard = ComponentFactory.setPreferredSize (
   128:       ComponentFactory.setFont (new MemoryDumpTextArea (), LnF.lnfMonospacedFont),
   129:       500, 400);
   130:     dmpBoard.setMargin (new Insets (2, 4, 2, 4));
   131:     dmpBoard.setHighlightCursorOn (true);
   132:     dmpTextArea = dmpBoard.getTextArea ();
   133:     dmpTextArea.setEditable (false);
   134:     dmpTextArea.addMouseWheelListener ((mwe) -> {
   135:       int n = mwe.getWheelRotation ();
   136:       JViewport v = dmpBoard.getViewport ();
   137:       Point p = v.getViewPosition ();
   138:       v.setViewPosition (new Point (p.x,
   139:                                     Math.max (0,
   140:                                               Math.min (dmpTextArea.getSize ().height - v.getExtentSize ().height,
   141:                                                         p.y + n * dmpTextArea.getFont ().getSize () * 5))));
   142:     });
   143: 
   144:     //スピナー
   145:     dmpSpinner = new Hex8Spinner (dmpPageAddress, DMP_ITEM_MASK, true);
   146: 
   147:     //スピナーのチェンジリスナー
   148:     //  スピナーが操作されたとき、そのアドレスの行にテキストエリアのキャレットを移動させる
   149:     //  ページの範囲外になったときはテキストエリアを再構築する
   150:     //  ページの構築中に呼び出されたときは何もしない
   151:     dmpSpinner.addChangeListener (new ChangeListener () {
   152:       @Override public void stateChanged (ChangeEvent ce) {
   153:         if (XEiJ.dbgEventMask == 0) {  //テキストは構築済みでsetTextの中ではない
   154:           dmpUpdate (dmpSpinner.getIntValue (), dmpFunctionCode, false);
   155:         }
   156:       }
   157:     });
   158: 
   159:     //テキストエリアのキャレットリスナー
   160:     //  テキストエリアがクリックされてキャレットが動いたとき、その行のアドレスをスピナーに設定する
   161:     //  クリックでテキストエリアに移ってしまったフォーカスをスピナーに戻す
   162:     //  ページの構築中に呼び出されたときは何もしない
   163:     //    setText→キャレットリスナー→スピナーのチェンジリスナー→setTextとなるとsetTextの二重呼び出しでエラーが出る
   164:     ComponentFactory.addListener (
   165:       dmpTextArea,
   166:       new CaretListener () {
   167:         @Override public void caretUpdate (CaretEvent ce) {
   168:           if (XEiJ.dbgEventMask == 0) {  //テキストは構築済みでsetTextの中ではない
   169:             int p = ce.getDot ();  //キャレットの位置
   170:             if (p == ce.getMark ()) {  //選択範囲がない
   171:               int i = Arrays.binarySearch (dmpSplitArray, 1, dmpItemCount, p + 1);  //項目の先頭のときも次の項目を検索してから1つ戻る
   172:               i = (i >> 31 ^ i) - 1;  //キャレットがある位置を含む項目の番号
   173:               dmpSpinner.setHintIndex (i);
   174:             }
   175:           }
   176:         }
   177:       });
   178: 
   179:     //テキストエリアのマウスリスナー
   180:     ComponentFactory.addListener (
   181:       dmpTextArea,
   182:       new MouseAdapter () {
   183:         @Override public void mousePressed (MouseEvent me) {
   184:           if (XEiJ.mpuTask == null && me.isPopupTrigger ()) {
   185:             XEiJ.dbgShowPopup (me, dmpTextArea, false);
   186:           }
   187:         }
   188:         @Override public void mouseReleased (MouseEvent me) {
   189:           if (XEiJ.mpuTask == null && me.isPopupTrigger ()) {
   190:             XEiJ.dbgShowPopup (me, dmpTextArea, false);
   191:           }
   192:         }
   193:       });
   194: 
   195:     //テキストエリアのフォーカスリスナー
   196:     ComponentFactory.addListener (
   197:       dmpBoard,
   198:       new FocusAdapter () {
   199:         @Override public void focusGained (FocusEvent fe) {
   200:           dmpBoard.setCaretVisible (true);
   201:         }
   202:         @Override public void focusLost (FocusEvent fe) {
   203:           dmpBoard.setCaretVisible (false);
   204:         }
   205:       });
   206: 
   207:     //テキストエリアのキーリスナー
   208:     ComponentFactory.addListener (
   209:       dmpBoard,
   210:       new KeyAdapter () {
   211:         @Override public void keyTyped (KeyEvent ke) {
   212:           if (XEiJ.dbgEventMask == 0) {  //テキストは構築済みでsetTextの中ではない
   213:             int x = Character.digit (ke.getKeyChar (), 16);
   214:             if (x >= 0) {  //16進数のキーが押された
   215:               int p = dmpTextArea.getCaretPosition ();  //キャレットの位置
   216:               int i = Arrays.binarySearch (dmpSplitArray, 1, dmpItemCount, p + 1);
   217:               i = (i >> 31 ^ i) - 1;  //キャレットがある位置を含む項目の番号
   218:               int t = p - dmpCaretArray[i] - DMP_DATA_START;  //最初のデータの位置からのオフセット
   219:               if (t >= 0 && t < DMP_DATA_ADDRESS.length) {
   220:                 t = DMP_DATA_ADDRESS[t];
   221:                 if (t >= 0) {  //データがある
   222:                   int a = dmpAddressArray[i] + (t >> 1);  //アドレス
   223:                   XEiJ.dbgEventMask++;  //キャレットが動くがキャレットリスナーが反応しないようにする
   224:                   if ((t & 1) == 0) {  //上位
   225:                     try {
   226:                       MC68060.mmuPokeByte (a, x << 4 | Character.digit (dmpTextArea.getText (p + 1, 1).charAt (0), 16), dmpFunctionCode);  //書き込む
   227:                     } catch (BadLocationException ble) {
   228:                     }
   229:                     dmpTextArea.replaceRange (XEiJ.fmtHex2 (MC68060.mmuPeekByteZero (a, dmpFunctionCode)), p, p + 2);  //読み出す
   230:                     dmpTextArea.setCaretPosition (p + 1);  //下位の位置
   231:                   } else {  //下位
   232:                     try {
   233:                       MC68060.mmuPokeByte (a, Character.digit (dmpTextArea.getText (p - 1, 1).charAt (0), 16) << 4 | x, dmpFunctionCode);  //書き込む
   234:                     } catch (BadLocationException ble) {
   235:                     }
   236:                     dmpTextArea.replaceRange (XEiJ.fmtHex2 (MC68060.mmuPeekByteZero (a, dmpFunctionCode)), p - 1, p + 1);  //読み出す
   237:                     if (t < 31) {
   238:                       dmpTextArea.setCaretPosition (dmpCaretArray[i] + DMP_DATA_START + DMP_DATA_OFFSET[t + 1]);  //次のアドレスの上位の位置
   239:                     }
   240:                   }
   241:                   XEiJ.dbgEventMask--;
   242:                 }
   243:               }
   244:             }
   245:           }
   246:         }
   247:       });
   248: 
   249:     //ボタンのアクションリスナー
   250:     ActionListener listener = new ActionListener () {
   251:       @Override public void actionPerformed (ActionEvent ae) {
   252:         Object source = ae.getSource ();
   253:         switch (ae.getActionCommand ()) {
   254:         case "Reload":
   255:           dmpItemCount = 0;  //再構築要求
   256:           dmpUpdate (dmpAddressArray[dmpItemIndex], dmpFunctionCode, true);
   257:           break;
   258:         case "Second bridge":  //セカンドブリッジ
   259:           dmpSecondBridge = ((JCheckBox) ae.getSource ()).isSelected ();
   260:           dmpItemCount = 0;  //再構築要求
   261:           dmpUpdate (dmpAddressArray[dmpItemIndex], dmpFunctionCode, true);
   262:           break;
   263:         }
   264:       }
   265:     };
   266: 
   267:     //再読み込みボタン
   268:     JButton reloadButton =
   269:       Multilingual.mlnToolTipText (
   270:         ComponentFactory.createImageButton (
   271:           XEiJ.createImage (
   272:             20, 14,
   273:             "11111111111111111111" +
   274:             "1..................1" +
   275:             "1.......1111.......1" +
   276:             "1......111111.1....1" +
   277:             "1.....11....111....1" +
   278:             "1....11.....111....1" +
   279:             "1....11....1111....1" +
   280:             "1....11............1" +
   281:             "1....11............1" +
   282:             "1.....11....11.....1" +
   283:             "1......111111......1" +
   284:             "1.......1111.......1" +
   285:             "1..................1" +
   286:             "11111111111111111111",
   287:             LnF.lnfRGB[0],
   288:             LnF.lnfRGB[12]),
   289:           "Reload", listener),
   290:         "ja", "再読み込み");
   291: 
   292:     //ファンクションコードスピナー
   293:     dmpFCSpinner = ComponentFactory.createDecimalSpinner (
   294:       dmpFunctionCode,  //value
   295:       0,  //minimum
   296:       7,  //maximum
   297:       1,  //stepSize
   298:       0,  //option
   299:       new ChangeListener () {
   300:         @Override public void stateChanged (ChangeEvent ce) {
   301:           if (XEiJ.dbgEventMask == 0) {  //テキストは構築済みでsetTextの中ではない
   302:             dmpUpdate (dmpPageAddress, dmpFCSpinner.getIntValue (), false);
   303:           }
   304:         }
   305:       });
   306: 
   307:     //セカンドブリッジチェックボックス
   308:     dmpSecondBridge = false;
   309:     dmpCellophaneColor = new Color ((LnF.lnfRGB[5] & 0x00ffffff) | 0xcc000000, true);
   310:     JCheckBox secondBridgeCheckBox =
   311:       Multilingual.mlnToolTipText (
   312:         ComponentFactory.createIconCheckBox (
   313:           dmpSecondBridge,
   314:           XEiJ.createImage (
   315:             20, 14,
   316:             "22222222222222222222" +
   317:             "2..................2" +
   318:             "2...........11111..2" +
   319:             "2...........11111..2" +
   320:             "2....111111111111..2" +
   321:             "2...........11111..2" +
   322:             "2...........11111..2" +
   323:             "2..................2" +
   324:             "2..................2" +
   325:             "2....1111111111....2" +
   326:             "2..................2" +
   327:             "2..................2" +
   328:             "2..................2" +
   329:             "22222222222222222222",
   330:             LnF.lnfRGB[0],
   331:             LnF.lnfRGB[12],
   332:             LnF.lnfRGB[12]),
   333:           XEiJ.createImage (
   334:             20, 14,
   335:             "22222222222222222222" +
   336:             "2..................2" +
   337:             "2...........11111..2" +
   338:             "2...........11111..2" +
   339:             "2....111111111111..2" +
   340:             "2...........11111..2" +
   341:             "2...........11111..2" +
   342:             "2..11111...........2" +
   343:             "2..11111...........2" +
   344:             "2..111111111111....2" +
   345:             "2..11111...........2" +
   346:             "2..11111...........2" +
   347:             "2..................2" +
   348:             "22222222222222222222",
   349:             LnF.lnfRGB[0],
   350:             LnF.lnfRGB[12],
   351:             LnF.lnfRGB[12]),
   352:           "Second bridge", listener),
   353:         "ja", "セカンドブリッジ");
   354: 
   355:     //ウインドウ
   356:     dmpFrame = Multilingual.mlnTitle (
   357:       ComponentFactory.createRestorableSubFrame (
   358:         Settings.SGS_DMP_FRAME_KEY,
   359:         "Memory dump list",
   360:         null,
   361:         ComponentFactory.createBorderPanel (
   362:           dmpBoard,
   363:           ComponentFactory.createHorizontalBox (
   364: 
   365:             dmpFCSpinner,
   366: 
   367:             dmpSpinner,
   368:             reloadButton,
   369:             secondBridgeCheckBox,
   370:             Box.createHorizontalGlue ()
   371:             )
   372:           )
   373:         ),
   374:       "ja", "メモリダンプリスト");
   375:     ComponentFactory.addListener (
   376:       dmpFrame,
   377:       new WindowAdapter () {
   378:         @Override public void windowClosing (WindowEvent we) {
   379:           XEiJ.dbgVisibleMask &= ~XEiJ.DBG_DMP_VISIBLE_MASK;
   380:         }
   381:       });
   382: 
   383:   }  //dmpMake()
   384: 
   385:   //dmpUpdate (address, functionCode, forceUpdate)
   386:   //  メモリダンプリストウインドウを更新する
   387:   public static void dmpUpdate (int address, int functionCode, boolean forceUpdate) {
   388: 
   389:     XEiJ.dbgEventMask++;  //構築開始
   390: 
   391:     if (address == -1) {  //spを表示
   392:       address = XEiJ.regRn[15];
   393:       forceUpdate = true;
   394:     }
   395: 
   396:     if (functionCode == -1) {  //spのユーザ/スーパーバイザに従う
   397:       functionCode = XEiJ.regSRS != 0 ? 5 : 1;
   398:       forceUpdate = true;
   399:     }
   400: 
   401:     if (dmpFunctionCode != functionCode) {  //ファンクションコードが一致しない
   402:       dmpFunctionCode = functionCode;
   403:       forceUpdate = true;
   404:       dmpFCSpinner.setIntValue (functionCode);
   405:     }
   406: 
   407:     if (forceUpdate) {  //再構築要求
   408:       dmpItemCount = 0;
   409:     }
   410: 
   411:     if (dmpItemCount != 0) {  //構築前または再構築要求のいずれでもない
   412:       int i = Arrays.binarySearch (dmpAddressArray, 1, dmpItemCount, address + 1);  //項目の先頭のときも次の項目を検索してから1つ戻る
   413:       i = (i >> 31 ^ i) - 1;  //目的のアドレスを含む項目の番号
   414:       if (0 < i && i < dmpItemCount - 1 &&  //ページの内側
   415:           dmpAddressArray[i] == address) {  //項目の先頭
   416: 
   417:         //再構築しない
   418: 
   419:         if (dmpItemIndex != i) {  //キャレットがある項目を変更する必要がある
   420:           dmpItemIndex = i;
   421:           dmpTextArea.setCaretPosition (dmpCaretArray[i]);
   422:         }
   423: 
   424:         XEiJ.dbgEventMask--;  //構築終了
   425: 
   426:         return;
   427:       }
   428:     }
   429: 
   430:     //再構築する
   431: 
   432:     //構築前または再構築要求または先頭または末尾の番兵が選択された
   433:     //  0x00000000の境界を跨ぐとき反対側を指すことがあるので先頭と末尾の番兵を区別しない
   434:     address &= DMP_ITEM_MASK;  //目的のアドレスを含む項目の先頭アドレス
   435:     dmpPageAddress = address & DMP_PAGE_MASK;  //ページの先頭アドレス
   436:     int pageEndAddress = dmpPageAddress + DMP_PAGE_SIZE;  //ページの末尾アドレス。0になることがある
   437: 
   438:     //先頭の番兵
   439:     dmpAddressArray[0] = dmpPageAddress - DMP_ITEM_SIZE;  //昇順を維持するためマスクしない
   440:     dmpSplitArray[0] = 0;
   441:     dmpCaretArray[0] = 0;
   442:     StringBuilder sb = new StringBuilder (
   443:       //         1111111111222222222233333333334444444444555555555566666666667777777777
   444:       //1234567890123456789012345678901234567890123456789012345678901234567890123456789
   445:       //xxxxxxx  xx xx xx xx  xx xx xx xx  xx xx xx xx  xx xx xx xx  ................
   446:       "▲        +0 +1 +2 +3  +4 +5 +6 +7  +8 +9 +A +B  +C +D +E +F  0123456789ABCDEF\n");
   447:     int itemCount = 1;  //項目数
   448:     int itemAddress = dmpPageAddress;  //項目の先頭アドレス
   449:     boolean bridge = false;  //1=先頭はSJISの2バイトコードの2バイト目
   450:     for (int k = 1; k <= 200; k++) {  //最大100文字200バイトまで遡る。長い文章でもSJISの2バイトコードの1バイト目ばかりが続くわけではないので十分だろう
   451:       int h = MC68060.mmuPeekByteZero (itemAddress - k, functionCode);
   452:       if ((0x81 <= h && h <= 0x9f) ||
   453:           (0xe0 <= h && h <= 0xef)) {  //SJISの2バイトコードの1バイト目
   454:         bridge = !bridge;
   455:       } else {
   456:         break;
   457:       }
   458:     }
   459: 
   460:     do {
   461:       int itemEndAddress = itemAddress + DMP_ITEM_SIZE;  //項目の末尾アドレス
   462:       //項目の開始
   463:       if (itemAddress == address) {
   464:         dmpItemIndex = itemCount;  //目的のアドレスを含む項目の番号
   465:       }
   466:       dmpAddressArray[itemCount] = itemAddress;  //項目の先頭アドレス
   467:       dmpSplitArray[itemCount] = sb.length ();  //項目を区切る位置
   468:       dmpCaretArray[itemCount] = sb.length ();  //項目が選択されたときキャレットを移動させる位置
   469:       //アドレス
   470:       XEiJ.fmtHex8 (DMP_BASE,  0, itemAddress);
   471:       //データ
   472:       XEiJ.fmtHex2 (DMP_BASE, 10, MC68060.mmuPeekByteZero (itemAddress     , functionCode));
   473:       XEiJ.fmtHex2 (DMP_BASE, 13, MC68060.mmuPeekByteZero (itemAddress +  1, functionCode));
   474:       XEiJ.fmtHex2 (DMP_BASE, 16, MC68060.mmuPeekByteZero (itemAddress +  2, functionCode));
   475:       XEiJ.fmtHex2 (DMP_BASE, 19, MC68060.mmuPeekByteZero (itemAddress +  3, functionCode));
   476:       XEiJ.fmtHex2 (DMP_BASE, 23, MC68060.mmuPeekByteZero (itemAddress +  4, functionCode));
   477:       XEiJ.fmtHex2 (DMP_BASE, 26, MC68060.mmuPeekByteZero (itemAddress +  5, functionCode));
   478:       XEiJ.fmtHex2 (DMP_BASE, 29, MC68060.mmuPeekByteZero (itemAddress +  6, functionCode));
   479:       XEiJ.fmtHex2 (DMP_BASE, 32, MC68060.mmuPeekByteZero (itemAddress +  7, functionCode));
   480:       XEiJ.fmtHex2 (DMP_BASE, 36, MC68060.mmuPeekByteZero (itemAddress +  8, functionCode));
   481:       XEiJ.fmtHex2 (DMP_BASE, 39, MC68060.mmuPeekByteZero (itemAddress +  9, functionCode));
   482:       XEiJ.fmtHex2 (DMP_BASE, 42, MC68060.mmuPeekByteZero (itemAddress + 10, functionCode));
   483:       XEiJ.fmtHex2 (DMP_BASE, 45, MC68060.mmuPeekByteZero (itemAddress + 11, functionCode));
   484:       XEiJ.fmtHex2 (DMP_BASE, 49, MC68060.mmuPeekByteZero (itemAddress + 12, functionCode));
   485:       XEiJ.fmtHex2 (DMP_BASE, 52, MC68060.mmuPeekByteZero (itemAddress + 13, functionCode));
   486:       XEiJ.fmtHex2 (DMP_BASE, 55, MC68060.mmuPeekByteZero (itemAddress + 14, functionCode));
   487:       XEiJ.fmtHex2 (DMP_BASE, 58, MC68060.mmuPeekByteZero (itemAddress + 15, functionCode));
   488:       sb.append (DMP_BASE);
   489:       //キャラクタ
   490:       boolean nextBridge = false;
   491:       int a;
   492:       if (!bridge) {  //行末からはみ出して書いた文字はない
   493:         sb.append (' ');
   494:         a = itemAddress;
   495:       } else if (itemAddress == dmpPageAddress ||  //1行目は常に
   496:                  dmpSecondBridge) {  //2行目以降は設定に従い、行末からはみ出して書いた文字を行頭にも書く
   497:         a = itemAddress - 1;
   498:       } else {  //行末からはみ出して書いた文字を行頭には書かない
   499:         sb.append ("  ");
   500:         a = itemAddress + 1;
   501:       }
   502:       for (; a < itemEndAddress; a++) {
   503:         int h = MC68060.mmuPeekByteZero (a, functionCode);
   504:         int c;
   505:         if ((0x81 <= h && h <= 0x9f) ||
   506:             (0xe0 <= h && h <= 0xef)) {  //SJISの2バイトコードの1バイト目
   507:           int l = MC68060.mmuPeekByteZero (a + 1, functionCode);  //これは範囲外になる場合がある
   508:           if (0x40 <= l && l <= 0xfc && l != 0x7f) {  //SJISの2バイトコードの2バイト目
   509:             c = CharacterCode.chrSJISToChar[h << 8 | l];  //2バイトで変換する
   510:             if (c == 0) {  //対応する文字がない
   511:               c = '※';
   512:             } else if (c == 0x3000) {  //全角空白
   513:               c = '\u2b1a';  //U+2B1A Dotted Square
   514:             }
   515:             a++;
   516:             if (a == itemEndAddress) {  //行末からはみ出した
   517:               nextBridge = true;
   518:             }
   519:           } else {  //SJISの2バイトコードの2バイト目ではない
   520:             c = '.';  //SJISの2バイトコードの1バイト目ではなかった
   521:           }
   522:         } else {  //SJISの2バイトコードの1バイト目ではない
   523:           c = CharacterCode.chrSJISToChar[h];  //1バイトで変換する
   524:           if (c < 0x20 || c == 0x7f) {  //対応する文字がないまたは制御コード
   525:             c = '.';
   526:           }
   527:         }
   528:         sb.append ((char) c);
   529:       }  //for a
   530:       sb.append ('\n');
   531:       //項目の終了
   532:       itemCount++;
   533:       itemAddress = itemEndAddress;
   534:       bridge = nextBridge;
   535:     } while (itemAddress < pageEndAddress);
   536: 
   537:     //末尾の番兵
   538:     dmpAddressArray[itemCount] = itemAddress;  //昇順を維持するためマスクしない
   539:     dmpSplitArray[itemCount] = sb.length ();
   540:     dmpCaretArray[itemCount] = sb.length ();
   541:     sb.append (
   542:       //         1111111111222222222233333333334444444444555555555566666666667777777777
   543:       //1234567890123456789012345678901234567890123456789012345678901234567890123456789
   544:       "▼        +0 +1 +2 +3  +4 +5 +6 +7  +8 +9 +A +B  +C +D +E +F  0123456789ABCDEF");
   545:     itemCount++;
   546:     dmpItemCount = itemCount;
   547: 
   548:     //テキスト
   549:     dmpTextArea.setText (sb.toString ());
   550:     dmpTextArea.setCaretPosition (dmpCaretArray[dmpItemIndex]);
   551: 
   552:     //スピナー
   553:     dmpSpinner.setHintArray (dmpAddressArray, itemCount);
   554:     dmpSpinner.setHintIndex (dmpItemIndex);
   555: 
   556:     XEiJ.dbgEventMask--;  //構築終了
   557: 
   558:   }  //dmpUpdate(int,int,boolean)
   559: 
   560: }  //class MemoryDumpList
   561: 
   562: 
   563: