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: rtlFrame.setVisible (true);
111: }
112:
113:
114:
115:
116: public static void rtlMakeFrame () {
117:
118:
119: rtlBoard = ComponentFactory.setPreferredSize (
120: ComponentFactory.setFont (new ScrollTextArea (), LnF.lnfMonospacedFont),
121: 300, 200);
122: rtlBoard.setMargin (new Insets (2, 4, 2, 4));
123: rtlTextArea = rtlBoard.getTextArea ();
124: rtlTextArea.setEditable (false);
125:
126:
127: ComponentFactory.addListener (
128: rtlTextArea,
129: new MouseAdapter () {
130: @Override public void mousePressed (MouseEvent me) {
131: String text = rtlTextArea.getText ();
132:
133: int offset = rtlTextArea.viewToModel2D (new Point (0, me.getY ()));
134: if (offset < 0 || text.length () <= offset) {
135: return;
136: }
137: if (0 < offset) {
138: offset = text.lastIndexOf ("\n", offset - 1) + 1;
139: }
140: if (Character.digit (text.charAt (offset), 16) < 0) {
141: return;
142: }
143: int rootPointer = Integer.parseInt (text.substring (offset, offset + 8), 16);
144: int hashCode = rootPointer * RTL_HASH_COEFF >>> -RTL_HASH_BITS;
145: for (RootPointerRecord record = rtlHashTable[hashCode]; record != null; record = record.rbrNextRecord) {
146: if (record.rbrRootPointer == rootPointer) {
147:
148: record.rbrThisTaskIsStoppable = !record.rbrThisTaskIsStoppable;
149: if (record.rbrRootPointer == MC68060.mmuSRP) {
150: rtlCurrentSupervisorTaskIsStoppable = record.rbrThisTaskIsStoppable;
151: }
152: if (record.rbrRootPointer == MC68060.mmuURP) {
153: rtlCurrentUserTaskIsStoppable = record.rbrThisTaskIsStoppable;
154: }
155: return;
156: }
157: }
158: }
159: });
160:
161:
162: rtlFrame = Multilingual.mlnTitle (
163: ComponentFactory.createRestorableSubFrame (
164: Settings.SGS_RTL_FRAME_KEY,
165: "Root pointer list",
166: null,
167: ComponentFactory.createVerticalBox (
168: rtlBoard
169: )
170: ),
171: "ja", "ルートポインタリスト");
172:
173:
174: ComponentFactory.addListener (
175: rtlFrame,
176: new WindowAdapter () {
177: @Override public void windowClosing (WindowEvent we) {
178: XEiJ.dbgVisibleMask &= ~XEiJ.DBG_RTL_VISIBLE_MASK;
179: }
180: });
181:
182: }
183:
184:
185:
186: public static void rtlUpdateFrame () {
187:
188: if (rtlFrame == null) {
189: return;
190: }
191:
192:
193: rtlSetRootPointer (MC68060.mmuURP, false);
194: rtlSetRootPointer (MC68060.mmuSRP, true);
195:
196: StringBuilder sb = new StringBuilder ();
197: for (int hashCode = 0; hashCode < RTL_HASH_SIZE; hashCode++) {
198: RootPointerRecord prevRecord = null;
199: for (RootPointerRecord record = rtlHashTable[hashCode]; record != null; record = record.rbrNextRecord) {
200: if (record.rbrTimeLimit <= XEiJ.mpuClockTime) {
201: if (prevRecord != null) {
202: prevRecord.rbrNextRecord = null;
203: } else {
204: rtlHashTable[hashCode] = null;
205: }
206: RootPointerRecord lastRecord = record;
207: while (lastRecord.rbrNextRecord != null) {
208: lastRecord = lastRecord.rbrNextRecord;
209: }
210: lastRecord.rbrNextRecord = rtlFreeRecordList;
211: rtlFreeRecordList = record;
212: break;
213: }
214: XEiJ.fmtHex8 (sb, record.rbrRootPointer).append (record.rbrThisTaskIsStoppable ? Multilingual.mlnJapanese ? "\t停止許可" : "\tstoppable" : Multilingual.mlnJapanese ? "\t停止禁止" : "\tunstoppable").append ('\n');
215: prevRecord = record;
216: }
217: }
218:
219: if (rtlTextArea != null) {
220: rtlTextArea.setText (sb.toString ());
221: }
222:
223: }
224:
225:
226:
227: public static void rtlSetRootPointer (int rootPointer, boolean supervisor) {
228: int hashCode = rootPointer * RTL_HASH_COEFF >>> -RTL_HASH_BITS;
229: RootPointerRecord prevRecord = null;
230: for (RootPointerRecord record = rtlHashTable[hashCode]; record != null; record = record.rbrNextRecord) {
231: if (record.rbrRootPointer == rootPointer) {
232: if (prevRecord != null) {
233: prevRecord.rbrNextRecord = record.rbrNextRecord;
234: record.rbrNextRecord = rtlHashTable[hashCode];
235: rtlHashTable[hashCode] = record;
236: }
237: record.rbrTimeLimit = XEiJ.mpuClockTime + RTL_SPAN;
238:
239:
240:
241:
242: if (supervisor) {
243: rtlCurrentSupervisorTaskIsStoppable = record.rbrThisTaskIsStoppable;
244: } else {
245: rtlCurrentUserTaskIsStoppable = record.rbrThisTaskIsStoppable;
246: }
247: return;
248: }
249: prevRecord = record;
250: }
251:
252: RootPointerRecord record;
253: if (rtlFreeRecordList == null) {
254: record = new RootPointerRecord ();
255: } else {
256: record = rtlFreeRecordList;
257: rtlFreeRecordList = record.rbrNextRecord;
258: }
259: record.rbrRootPointer = rootPointer;
260: record.rbrNextRecord = rtlHashTable[hashCode];
261: rtlHashTable[hashCode] = record;
262: record.rbrTimeLimit = XEiJ.mpuClockTime + RTL_SPAN;
263:
264: record.rbrThisTaskIsStoppable = true;
265: if (supervisor) {
266: rtlCurrentSupervisorTaskIsStoppable = record.rbrThisTaskIsStoppable;
267: } else {
268: rtlCurrentUserTaskIsStoppable = record.rbrThisTaskIsStoppable;
269: }
270: }
271:
272: }
273:
274:
275: