RootPointerList.java
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28: package xeij;
29:
30: import java.awt.*;
31: import java.awt.event.*;
32: import java.lang.*;
33: import javax.swing.*;
34:
35: public class RootPointerList {
36:
37: public static final boolean RTL_ON = true;
38:
39: public static final long RTL_SPAN = XEiJ.TMR_FREQ * 3;
40: public static final int RTL_HASH_BITS = 6;
41: public static final int RTL_HASH_SIZE = 1 << RTL_HASH_BITS;
42: public static final int RTL_HASH_COEFF = 0x5efc103f;
43:
44:
45: public static class RootPointerRecord {
46: public int rbrRootPointer;
47: public RootPointerRecord rbrNextRecord;
48: public long rbrTimeLimit;
49:
50: public boolean rbrThisTaskIsStoppable;
51: }
52:
53:
54: public static boolean rtlCurrentSupervisorTaskIsStoppable;
55: public static boolean rtlCurrentUserTaskIsStoppable;
56:
57:
58: public static final RootPointerRecord[] rtlHashTable = new RootPointerRecord[RTL_HASH_SIZE];
59:
60:
61: public static RootPointerRecord rtlFreeRecordList;
62:
63:
64: public static JFrame rtlFrame;
65: public static ScrollTextArea rtlBoard;
66: public static JTextArea rtlTextArea;
67:
68:
69: public static final int RTL_INTERVAL = 10;
70: public static int rtlTimer;
71:
72: public static void rtlInit () {
73:
74:
75: rtlCurrentSupervisorTaskIsStoppable = true;
76: rtlCurrentUserTaskIsStoppable = true;
77:
78:
79: for (int hashCode = 0; hashCode < RTL_HASH_SIZE; hashCode++) {
80: rtlHashTable[hashCode] = null;
81: }
82:
83:
84: rtlFreeRecordList = null;
85:
86:
87: rtlFrame = null;
88:
89:
90: rtlTimer = 0;
91:
92: }
93:
94:
95: public static void rtlStart () {
96: if (RestorableFrame.rfmGetOpened (Settings.SGS_RTL_FRAME_KEY)) {
97: rtlOpen ();
98: }
99: }
100:
101:
102:
103: public static void rtlOpen () {
104: if (rtlFrame == null) {
105: rtlMakeFrame ();
106: } else {
107: rtlUpdateFrame ();
108: }
109: XEiJ.dbgVisibleMask |= XEiJ.DBG_RTL_VISIBLE_MASK;
110: XEiJ.pnlExitFullScreen (false);
111: rtlFrame.setVisible (true);
112: }
113:
114:
115:
116:
117: public static void rtlMakeFrame () {
118:
119:
120: rtlBoard = ComponentFactory.setPreferredSize (
121: ComponentFactory.setFont (new ScrollTextArea (), LnF.lnfMonospacedFont),
122: 300, 200);
123: rtlBoard.setMargin (new Insets (2, 4, 2, 4));
124: rtlTextArea = rtlBoard.getTextArea ();
125: rtlTextArea.setEditable (false);
126:
127:
128: ComponentFactory.addListener (
129: rtlTextArea,
130: new MouseAdapter () {
131: @Override public void mousePressed (MouseEvent me) {
132: String text = rtlTextArea.getText ();
133:
134: int offset = rtlTextArea.viewToModel2D (new Point (0, me.getY ()));
135: if (offset < 0 || text.length () <= offset) {
136: return;
137: }
138: if (0 < offset) {
139: offset = text.lastIndexOf ("\n", offset - 1) + 1;
140: }
141: if (Character.digit (text.charAt (offset), 16) < 0) {
142: return;
143: }
144: int rootPointer = Integer.parseInt (text.substring (offset, offset + 8), 16);
145: int hashCode = rootPointer * RTL_HASH_COEFF >>> -RTL_HASH_BITS;
146: for (RootPointerRecord record = rtlHashTable[hashCode]; record != null; record = record.rbrNextRecord) {
147: if (record.rbrRootPointer == rootPointer) {
148:
149: record.rbrThisTaskIsStoppable = !record.rbrThisTaskIsStoppable;
150: if (record.rbrRootPointer == MC68060.mmuSRP) {
151: rtlCurrentSupervisorTaskIsStoppable = record.rbrThisTaskIsStoppable;
152: }
153: if (record.rbrRootPointer == MC68060.mmuURP) {
154: rtlCurrentUserTaskIsStoppable = record.rbrThisTaskIsStoppable;
155: }
156: return;
157: }
158: }
159: }
160: });
161:
162:
163: rtlFrame = Multilingual.mlnTitle (
164: ComponentFactory.createRestorableSubFrame (
165: Settings.SGS_RTL_FRAME_KEY,
166: "Root pointer list",
167: null,
168: ComponentFactory.createVerticalBox (
169: rtlBoard
170: )
171: ),
172: "ja", "ルートポインタリスト");
173:
174:
175: ComponentFactory.addListener (
176: rtlFrame,
177: new WindowAdapter () {
178: @Override public void windowClosing (WindowEvent we) {
179: XEiJ.dbgVisibleMask &= ~XEiJ.DBG_RTL_VISIBLE_MASK;
180: }
181: });
182:
183: }
184:
185:
186:
187: public static void rtlUpdateFrame () {
188:
189: if (rtlFrame == null) {
190: return;
191: }
192:
193:
194: rtlSetRootPointer (MC68060.mmuURP, false);
195: rtlSetRootPointer (MC68060.mmuSRP, true);
196:
197: StringBuilder sb = new StringBuilder ();
198: for (int hashCode = 0; hashCode < RTL_HASH_SIZE; hashCode++) {
199: RootPointerRecord prevRecord = null;
200: for (RootPointerRecord record = rtlHashTable[hashCode]; record != null; record = record.rbrNextRecord) {
201: if (record.rbrTimeLimit <= XEiJ.mpuClockTime) {
202: if (prevRecord != null) {
203: prevRecord.rbrNextRecord = null;
204: } else {
205: rtlHashTable[hashCode] = null;
206: }
207: RootPointerRecord lastRecord = record;
208: while (lastRecord.rbrNextRecord != null) {
209: lastRecord = lastRecord.rbrNextRecord;
210: }
211: lastRecord.rbrNextRecord = rtlFreeRecordList;
212: rtlFreeRecordList = record;
213: break;
214: }
215: XEiJ.fmtHex8 (sb, record.rbrRootPointer).append (record.rbrThisTaskIsStoppable ? Multilingual.mlnJapanese ? "\t停止許可" : "\tstoppable" : Multilingual.mlnJapanese ? "\t停止禁止" : "\tunstoppable").append ('\n');
216: prevRecord = record;
217: }
218: }
219:
220: if (rtlTextArea != null) {
221: rtlTextArea.setText (sb.toString ());
222: }
223:
224: }
225:
226:
227:
228: public static void rtlSetRootPointer (int rootPointer, boolean supervisor) {
229: int hashCode = rootPointer * RTL_HASH_COEFF >>> -RTL_HASH_BITS;
230: RootPointerRecord prevRecord = null;
231: for (RootPointerRecord record = rtlHashTable[hashCode]; record != null; record = record.rbrNextRecord) {
232: if (record.rbrRootPointer == rootPointer) {
233: if (prevRecord != null) {
234: prevRecord.rbrNextRecord = record.rbrNextRecord;
235: record.rbrNextRecord = rtlHashTable[hashCode];
236: rtlHashTable[hashCode] = record;
237: }
238: record.rbrTimeLimit = XEiJ.mpuClockTime + RTL_SPAN;
239:
240:
241:
242:
243: if (supervisor) {
244: rtlCurrentSupervisorTaskIsStoppable = record.rbrThisTaskIsStoppable;
245: } else {
246: rtlCurrentUserTaskIsStoppable = record.rbrThisTaskIsStoppable;
247: }
248: return;
249: }
250: prevRecord = record;
251: }
252:
253: RootPointerRecord record;
254: if (rtlFreeRecordList == null) {
255: record = new RootPointerRecord ();
256: } else {
257: record = rtlFreeRecordList;
258: rtlFreeRecordList = record.rbrNextRecord;
259: }
260: record.rbrRootPointer = rootPointer;
261: record.rbrNextRecord = rtlHashTable[hashCode];
262: rtlHashTable[hashCode] = record;
263: record.rbrTimeLimit = XEiJ.mpuClockTime + RTL_SPAN;
264:
265: record.rbrThisTaskIsStoppable = true;
266: if (supervisor) {
267: rtlCurrentSupervisorTaskIsStoppable = record.rbrThisTaskIsStoppable;
268: } else {
269: rtlCurrentUserTaskIsStoppable = record.rbrThisTaskIsStoppable;
270: }
271: }
272:
273: }
274:
275:
276: