Add wait for PC to stop function to Lua
[jpcrr.git] / org / jpc / emulator / StatusDumper.java
blob84405bc43e9f1200e30fab2341c7d141816c7423
1 /*
2 JPC-RR: A x86 PC Hardware Emulator
3 Release 1
5 Copyright (C) 2007-2009 Isis Innovation Limited
6 Copyright (C) 2009 H. Ilari Liusvaara
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License version 2 as published by
10 the Free Software Foundation.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License along
18 with this program; if not, write to the Free Software Foundation, Inc.,
19 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 Based on JPC x86 PC Hardware emulator,
22 A project from the Physics Dept, The University of Oxford
24 Details about original JPC can be found at:
26 www-jpc.physics.ox.ac.uk
30 package org.jpc.emulator;
32 import java.io.*;
34 public class StatusDumper
36 int extraIndent;
37 java.util.HashMap<String, Integer> nextObjectNumber;
38 PrintStream underlyingPrintStream;
39 static final Boolean TRUE;
40 static final Boolean FALSE;
41 java.util.HashMap<String, Boolean> seenObjects;
42 java.util.HashMap<Integer, ObjectListEntry> chainingLists;
43 int objectsCount;
45 static class ObjectListEntry
47 public Object object;
48 public String num;
49 public ObjectListEntry next;
52 static
54 TRUE = new Boolean(true);
55 FALSE = new Boolean(false);
58 public StatusDumper(PrintStream ps)
60 extraIndent = -1;
61 nextObjectNumber = new java.util.HashMap<String, Integer>();
62 underlyingPrintStream = ps;
63 seenObjects = new java.util.HashMap<String, Boolean>();
64 chainingLists = new java.util.HashMap<Integer, ObjectListEntry>();
65 objectsCount = 0;
68 public int dumpedObjects()
70 return objectsCount;
73 public void println(String S)
75 String X = "";
76 for(int i = 0; i < extraIndent; i++)
77 X = X + "\t";
78 X = X + S;
79 underlyingPrintStream.println(X);
82 public void printArray(boolean[] A, String N)
84 if(A == null) {
85 println("\t" + N + " null");
86 return;
88 println("\t" + N + ":");
89 String S = "\t\t";
90 for(int i = 0; i < A.length; i++) {
91 if(i % 16 == 15) {
92 S = S + A[i] + "";
93 println(S);
94 S = "\t\t";
95 } else {
96 S = S + A[i] + " ";
101 public void printArray(byte[] A, String N)
103 if(A == null) {
104 println("\t" + N + " null");
105 return;
107 println("\t" + N + ":");
108 String S = "\t\t";
109 for(int i = 0; i < A.length; i++) {
110 if(i % 16 == 15) {
111 S = S + A[i] + "";
112 println(S);
113 S = "\t\t";
114 } else {
115 S = S + A[i] + " ";
120 public void printArray(int[] A, String N)
122 if(A == null) {
123 println("\t" + N + " null");
124 return;
126 println("\t" + N + ":");
127 String S = "\t\t";
128 for(int i = 0; i < A.length; i++) {
129 if(i % 16 == 15) {
130 S = S + A[i] + "";
131 println(S);
132 S = "\t\t";
133 } else {
134 S = S + A[i] + " ";
139 public void printArray(long[] A, String N)
141 if(A == null) {
142 println("\t" + N + " null");
143 return;
145 println("\t" + N + ":");
146 String S = "\t\t";
147 for(int i = 0; i < A.length; i++) {
148 if(i % 16 == 15) {
149 S = S + A[i] + "";
150 println(S);
151 S = "\t\t";
152 } else {
153 S = S + A[i] + " ";
158 private void addObject(Object O, String n)
160 Integer hcode = new Integer(O.hashCode());
161 ObjectListEntry e = new ObjectListEntry();
162 e.object = O;
163 e.num = n;
164 e.next = null;
165 if(!chainingLists.containsKey(hcode)) {
166 chainingLists.put(hcode, e);
167 } else {
168 e.next = chainingLists.get(hcode);
169 chainingLists.put(hcode, e);
173 private String lookupObject(Object O)
175 Integer hcode = new Integer(O.hashCode());
176 if(!chainingLists.containsKey(hcode))
177 return null;
178 ObjectListEntry e = chainingLists.get(hcode);
179 while(e != null) {
180 if(e.object == O)
181 return e.num;
182 e = e.next;
184 return null;
187 public String objectNumber(Object O)
189 String assignedNum;
190 boolean isNew = false;
192 if(O == null)
193 return "NULL";
195 assignedNum = lookupObject(O);
196 if(assignedNum == null)
197 isNew = true;
199 if(isNew) {
200 String cName = O.getClass().getName();
201 if(!nextObjectNumber.containsKey(cName)) {
202 nextObjectNumber.put(cName, new Integer(1));
203 assignedNum = cName + "-1";
204 } else {
205 int seqno = nextObjectNumber.get(cName).intValue();
206 nextObjectNumber.put(cName, new Integer(seqno + 1));
207 assignedNum = cName + "-" + (seqno + 1);
209 addObject(O, assignedNum);
210 seenObjects.put(assignedNum, FALSE);
212 return assignedNum;
215 public boolean dumped(Object O)
217 boolean seenBefore = false;
218 String obj = objectNumber(O);
220 seenBefore = seenObjects.get(obj).booleanValue();
221 if(!seenBefore) {
222 extraIndent++;
223 seenObjects.put(obj, TRUE);
224 objectsCount++;
225 return false;
226 } else
227 return true;
230 public void endObject()
232 println("--- END OF OBJECT ---");
233 extraIndent--;