LogicalSpaceMonitor.java
     1: //========================================================================================
     2: //  LogicalSpaceMonitor.java
     3: //    en:Logical space monitor
     4: //    ja:論理空間モニタ
     5: //  Copyright (C) 2003-2024 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 javax.swing.*;  //AbstractButton,AbstractSpinnerModel,Box,ButtonGroup,DefaultListModel,ImageIcon,JApplet,JButton,JCheckBox,JCheckBoxMenuItem,JComponent,JDialog,JFileChooser,JFrame,JLabel,JList,JMenu,JMenuBar,JMenuItem,JPanel,JRadioButton,JScrollPane,JSpinner,JTextArea,JTextField,JTextPane,JViewport,ScrollPaneConstants,SpinnerListModel,SpinnerNumberModel,SwingConstants,SwingUtilities,UIManager,UIDefaults,UnsupportedLookAndFeelException
    19: 
    20: public class LogicalSpaceMonitor {
    21: 
    22:   public static JFrame atwFrame;  //ウインドウ
    23:   public static final ScrollTextArea[] atwBoard = new ScrollTextArea[2];  //スクロールテキストエリア
    24:   public static final JTextArea[] atwTextArea = new JTextArea[2];  //テキストエリア
    25: 
    26:   //atwInit ()
    27:   //  初期化
    28:   public static void atwInit () {
    29:     atwFrame = null;
    30:   }  //atwInit()
    31: 
    32:   //atwStart ()
    33:   public static void atwStart () {
    34:     if (RestorableFrame.rfmGetOpened (Settings.SGS_ATW_FRAME_KEY)) {
    35:       atwOpen ();
    36:     }
    37:   }  //atwStart()
    38: 
    39:   //atwOpen ()
    40:   //  アドレス変換ウインドウを開く
    41:   //  既に開いているときは手前に持ってくる
    42:   public static void atwOpen () {
    43:     if (atwFrame == null) {
    44:       atwMake ();
    45:     }
    46:     atwUpdate ();
    47:     XEiJ.pnlExitFullScreen (false);
    48:     atwFrame.setVisible (true);
    49:     XEiJ.dbgVisibleMask |= XEiJ.DBG_ATW_VISIBLE_MASK;
    50:   }  //atwOpen()
    51: 
    52:   //atwMake ()
    53:   //  アドレス変換ウインドウを作る
    54:   public static void atwMake () {
    55: 
    56:     for (int m = 0; m < 2; m++) {
    57:       //スクロールテキストエリア
    58:       atwBoard[m] = ComponentFactory.setPreferredSize (
    59:         ComponentFactory.setFont (new ScrollTextArea (), LnF.lnfMonospacedFont),
    60:         550, 250);
    61:       atwBoard[m].setMargin (new Insets (2, 4, 2, 4));
    62:       atwBoard[m].setHighlightCursorOn (true);
    63:       atwTextArea[m] = atwBoard[m].getTextArea ();
    64:       atwTextArea[m].setEditable (false);
    65:     }
    66: 
    67:     //テキストエリアのマウスリスナー
    68:     ComponentFactory.addListener (
    69:       atwTextArea[0],
    70:       new MouseAdapter () {
    71:         @Override public void mousePressed (MouseEvent me) {
    72:           if (XEiJ.mpuTask == null && me.isPopupTrigger ()) {
    73:             XEiJ.dbgShowPopup (me, atwTextArea[0], false);
    74:           }
    75:         }
    76:         @Override public void mouseReleased (MouseEvent me) {
    77:           if (XEiJ.mpuTask == null && me.isPopupTrigger ()) {
    78:             XEiJ.dbgShowPopup (me, atwTextArea[0], false);
    79:           }
    80:         }
    81:       });
    82:     ComponentFactory.addListener (
    83:       atwTextArea[1],
    84:       new MouseAdapter () {
    85:         @Override public void mousePressed (MouseEvent me) {
    86:           if (XEiJ.mpuTask == null && me.isPopupTrigger ()) {
    87:             XEiJ.dbgShowPopup (me, atwTextArea[1], false);
    88:           }
    89:         }
    90:         @Override public void mouseReleased (MouseEvent me) {
    91:           if (XEiJ.mpuTask == null && me.isPopupTrigger ()) {
    92:             XEiJ.dbgShowPopup (me, atwTextArea[1], false);
    93:           }
    94:         }
    95:       });
    96: 
    97:     //ボタンのアクションリスナー
    98:     ActionListener listener = new ActionListener () {
    99:       @Override public void actionPerformed (ActionEvent ae) {
   100:         Object source = ae.getSource ();
   101:         switch (ae.getActionCommand ()) {
   102:         case "Update":
   103:           atwUpdate ();
   104:           break;
   105:         }
   106:       }
   107:     };
   108: 
   109:     //ウインドウ
   110:     atwFrame = Multilingual.mlnTitle (
   111:       ComponentFactory.createRestorableSubFrame (
   112:         Settings.SGS_ATW_FRAME_KEY,
   113:         "Logical space monitor",
   114:         null,
   115:         ComponentFactory.createBorderPanel (
   116:           ComponentFactory.createVerticalSplitPane (
   117:             ComponentFactory.createVerticalBox (
   118:               ComponentFactory.createHorizontalBox (
   119:                 Multilingual.mlnText (ComponentFactory.createLabel ("User mode"), "ja", "ユーザモード"),
   120:                 Box.createHorizontalGlue ()
   121:                 ),
   122:               atwBoard[0]
   123:               ),
   124:             ComponentFactory.createVerticalBox (
   125:               ComponentFactory.createHorizontalBox (
   126:                 Multilingual.mlnText (ComponentFactory.createLabel ("Supervisor mode"), "ja", "スーパーバイザモード"),
   127:                 Box.createHorizontalGlue ()
   128:                 ),
   129:               atwBoard[1]
   130:               )
   131:             ),
   132:           ComponentFactory.createHorizontalBox (
   133:             Multilingual.mlnToolTipText (
   134:               ComponentFactory.createImageButton (
   135:                 XEiJ.createImage (
   136:                   20, 14,
   137:                   "11111111111111111111" +
   138:                   "1..................1" +
   139:                   "1.......1111.......1" +
   140:                   "1......111111.1....1" +
   141:                   "1.....11....111....1" +
   142:                   "1....11.....111....1" +
   143:                   "1....11....1111....1" +
   144:                   "1....11............1" +
   145:                   "1....11............1" +
   146:                   "1.....11....11.....1" +
   147:                   "1......111111......1" +
   148:                   "1.......1111.......1" +
   149:                   "1..................1" +
   150:                   "11111111111111111111",
   151:                   LnF.lnfRGB[0],
   152:                   LnF.lnfRGB[12]),
   153:                 "Update", listener),
   154:               "ja", "更新"),
   155:             Box.createHorizontalGlue ()
   156:             )
   157:           )
   158:         ),
   159:       "ja", "論理空間モニタ");
   160:     ComponentFactory.addListener (
   161:       atwFrame,
   162:       new WindowAdapter () {
   163:         @Override public void windowClosing (WindowEvent we) {
   164:           XEiJ.dbgVisibleMask &= ~XEiJ.DBG_ATW_VISIBLE_MASK;
   165:         }
   166:       });
   167: 
   168:   }  //atwMake()
   169: 
   170:   //atwUpdate ()
   171:   //  アドレス変換ウインドウを更新する
   172:   public static void atwUpdate () {
   173:     for (int m = 0; m < 2; m++) {
   174:       StringBuilder sb = new StringBuilder ();
   175:       sb.append (Multilingual.mlnJapanese ?
   176:                  //xxxxxxx-xxxxxxxx  xxxxxxxx-xxxxxxxx
   177:                  "  論理アドレス       物理アドレス\n" :
   178:                  " Logical address   Physical address\n");
   179:       int l0 = 0x00000000;
   180:       int p0 = MC68060.mmuTranslatePeek (l0, m, 0);
   181:       int f0 = MC68060.mmuPeekFlags;
   182:       if ((p0 ^ l0) == 1) {
   183:         p0 = 1;
   184:       }
   185:       int l1 = MC68060.mmuPageSize;
   186:       while (l1 != 0x00000000) {
   187:         int p1 = MC68060.mmuTranslatePeek (l1, m, 0);
   188:         int f1 = MC68060.mmuPeekFlags;
   189:         if ((p1 ^ l1) == 1) {
   190:           p1 = 1;
   191:         }
   192:         if (!(p0 == 1 && p1 == 1 ||
   193:               p0 != 1 && p1 != 1 && p1 - p0 == l1 - l0 && f0 == f1)) {
   194:           if (p0 != 1) {
   195:             XEiJ.fmtHex8 (XEiJ.fmtHex8 (XEiJ.fmtHex8 (XEiJ.fmtHex8 (sb, l0).append ('-'), l1 - 1).append ("  "), p0).append ('-'), p0 + (l1 - l0) - 1).append (' ');
   196:             if ((f0 & MC68060.MMU_DESCRIPTOR_SUPERVISOR_PROTECTED) != 0) {
   197:               sb.append (Multilingual.mlnJapanese ? " [スーパーバイザ]" : " [Supervisor]");
   198:             }
   199:             if ((f0 & MC68060.MMU_DESCRIPTOR_MODIFIED) != 0) {
   200:               sb.append (Multilingual.mlnJapanese ? " [修正済み]" : " [Modified]");
   201:             }
   202:             if ((f0 & MC68060.MMU_DESCRIPTOR_USED) != 0) {
   203:               sb.append (Multilingual.mlnJapanese ? " [使用済み]" : " [Used]");
   204:             }
   205:             if ((f0 & MC68060.MMU_DESCRIPTOR_WRITE_PROTECTED) != 0) {
   206:               sb.append (Multilingual.mlnJapanese ? " [書き込み禁止]" : " [Write-protected]");
   207:             }
   208:             sb.append ('\n');
   209:           }
   210:           l0 = l1;
   211:           p0 = p1;
   212:           f0 = f1;
   213:         }
   214:         l1 += MC68060.mmuPageSize;
   215:       }
   216:       if (p0 != 1) {
   217:         XEiJ.fmtHex8 (XEiJ.fmtHex8 (XEiJ.fmtHex8 (XEiJ.fmtHex8 (sb, l0).append ('-'), l1 - 1).append ("  "), p0).append ('-'), p0 + (l1 - l0) - 1).append (' ');
   218:         if ((f0 & MC68060.MMU_DESCRIPTOR_SUPERVISOR_PROTECTED) != 0) {
   219:           sb.append (Multilingual.mlnJapanese ? " [スーパーバイザ]" : " [Supervisor]");
   220:         }
   221:         if ((f0 & MC68060.MMU_DESCRIPTOR_MODIFIED) != 0) {
   222:           sb.append (Multilingual.mlnJapanese ? " [修正済み]" : " [Modified]");
   223:         }
   224:         if ((f0 & MC68060.MMU_DESCRIPTOR_USED) != 0) {
   225:           sb.append (Multilingual.mlnJapanese ? " [使用済み]" : " [Used]");
   226:         }
   227:         if ((f0 & MC68060.MMU_DESCRIPTOR_WRITE_PROTECTED) != 0) {
   228:           sb.append (Multilingual.mlnJapanese ? " [書き込み禁止]" : " [Write-protected]");
   229:         }
   230:         sb.append ('\n');
   231:       }
   232:       atwTextArea[m].setText (sb.toString ());
   233:       atwTextArea[m].setCaretPosition (0);
   234:     }
   235:   }  //atwUpdate()
   236: 
   237: }  //class LogicalSpaceMonitor
   238: 
   239: 
   240: