1 /*
2 * MythSim
3 *
4 * Copyright (C) 2002-2004 Jason Vroustouris <jasonv@jasonv.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21 package org.mythsim.swing.plugin;
22 import org.mythsim.core.*;
23 import javax.swing.*;
24 import javax.swing.text.*;
25 import java.io.*;
26 import java.net.*;
27 import java.awt.*;
28 import java.util.regex.*;
29 import org.mythsim.swing.*;
30
31 /***
32 * The ALU Window.
33 * @author Jason Vroustouris
34 */
35 public class ALUFrame extends MythPlugInFrame {
36 JTextPane jTextPane = new JTextPane(){
37 public void setSize(Dimension d){
38 if (d.width < getParent().getSize().width)
39 d.width = getParent().getSize().width;
40 super.setSize(d);
41 }
42 public boolean getScrollableTracksViewportWidth(){
43 return false;
44 }
45 };
46
47 int last_clock = 0;
48 int second_to_last_clock = 0;
49 JScrollPane jScrollPane = new JScrollPane(jTextPane);
50 DefaultStyledDocument logDoc = new DefaultStyledDocument();
51 SimpleAttributeSet logAttrib = new SimpleAttributeSet();
52 Highlighter hl = jTextPane.getHighlighter();
53 EditorKit ek = jTextPane.getEditorKit();
54
55 public ALUFrame (MythSimSwing a, JFrame owner) {
56 super("ALU", // title
57 true, // resizable
58 true, // closable
59 true, // maximizable
60 true, // iconifiable
61 400, // set size x
62 200, // set size y
63 0, // set location x
64 300, // set location y
65 a,
66 owner); // MythSim object
67 jTextPane.setDocument(logDoc);
68 jTextPane.setEditable(false);
69 jTextPane.setPreferredSize(new Dimension(10,10));
70 jTextPane.setFont(new Font("Courier", Font.PLAIN, 12));
71
72 getContentPane().add(jScrollPane);
73 }
74 public void setup() {
75 jTextPane.setText("");
76 }
77 public void step() {
78 String temp = "";
79 int clock = ms.getStatus(MythSim.CLOCK);
80 if (clock==0) {
81 jTextPane.setText("");
82 } else {
83 if (clock == last_clock) {
84 return;
85 }
86 else if (clock != last_clock+1) {
87 temp += " Skipping... \n";
88 }
89 }
90
91 second_to_last_clock = last_clock;
92 last_clock = clock;
93
94 int alu_sel = ms.getStatus(MythSim.ALU_SEL);
95 String Reg_A_Num = "" + ms.getStatus(MythSim.VA_SEL_BUS);
96 String Reg_B_Num = "" + ms.getStatus(MythSim.VB_SEL_BUS);
97 String Reg_A_Val = bit8(ms.getRegA());
98 String Reg_B_Val = bit8(ms.getRegB());
99 String Reg_B_Val_Not = bit8not(ms.getRegB());
100 String Cin_Val = bit8(ms.getStatus(MythSim.C_IN));
101 temp +=" ALU_BUS:";
102 temp += "\t" + ms.getStatus(MythSim.C_OUT) + " " + bit8(ms.getStatus(MythSim.ALU_BUS));
103 if (ms.getStatus(MythSim.V)==1) {
104 temp += " V";
105 }
106
107 temp += "\n -------------------------------- \n";
108 String result_temp = "";
109 if (ms.getStatus(MythSim.VR0_WRITE_BUS)==1) result_temp += "=>R0";
110 if (ms.getStatus(MythSim.VR1_WRITE_BUS)==1) result_temp += "=>R1";
111 if (ms.getStatus(MythSim.VR2_WRITE_BUS)==1) result_temp += "=>R2";
112 if (ms.getStatus(MythSim.VR3_WRITE_BUS)==1) result_temp += "=>R3";
113 if (ms.getStatus(MythSim.R4_WRITE)==1) result_temp += "=>R4";
114 if (ms.getStatus(MythSim.R5_WRITE)==1) result_temp += "=>R5";
115 if (ms.getStatus(MythSim.R6_WRITE)==1) result_temp += "=>R6";
116 if (ms.getStatus(MythSim.R7_WRITE)==1) result_temp += "=>R7";
117 if (result_temp.length() != 0) {
118
119 if (ms.getStatus(MythSim.RESULT_SEL) == 0)
120 temp += " ALU_BUS=>RESULT_BUS";
121 if (ms.getStatus(MythSim.RESULT_SEL) == 1)
122 temp += " MDR=>RESULT_BUS";
123 if (ms.getStatus(MythSim.RESULT_SEL) == 2)
124 temp += " IR_CONST4=>RESULT_BUS";
125 if (ms.getStatus(MythSim.RESULT_SEL) == 3)
126 temp += " IR_CONST8=>RESULT_BUS";
127 temp += result_temp + " ";
128 }
129
130 if (ms.getStatus(MythSim.MAR_SEL)==1) temp += "\n ALU_BUS=>MAR ";
131 if (ms.getStatus(MythSim.MDR_SEL)==1) temp += "\n ALU_BUS=>MDR ";
132 if (ms.getStatus(MythSim.MDR_SEL)==2) temp += "\n DATA_BUS=>MDR ";
133 if (ms.getStatus(MythSim.IR0_SEL)==1) temp += "\n DATA_BUS=>IR0 ";
134 if (ms.getStatus(MythSim.IR1_SEL)==1) temp += "\n DATA_BUS=>IR1 ";
135 temp+="\n -------------------------------- ";
136 temp += "\n " + MythSim.funcName(alu_sel);
137
138 temp += " \n";
139 switch(alu_sel) {
140 case MythSimSwing.ALU_NOT:
141 temp += " r" + Reg_A_Num + ":\t " + Reg_A_Val + " \n";
142 break;
143 case MythSimSwing.ALU_OR:
144 case MythSimSwing.ALU_AND:
145 case MythSimSwing.ALU_XOR:
146 temp += " r" + Reg_A_Num + ":\t " + Reg_A_Val + " \n";
147 temp += " r" + Reg_B_Num + ":\t " + Reg_B_Val + " \n";
148 break;
149 case MythSimSwing.ALU_ADD:
150 temp += " r" + Reg_A_Num + ":\t " + Reg_A_Val + " \n";
151 temp += " r" + Reg_B_Num + ":\t " + Reg_B_Val + " \n";
152 temp += " c_in:\t " + Cin_Val + " \n";
153 break;
154 case MythSimSwing.ALU_ADDA:
155 temp += " r" + Reg_A_Num + ":\t " + Reg_A_Val + " \n";
156 temp += " c_in:\t " + Cin_Val + " \n";
157 break;
158 case MythSimSwing.ALU_SUB:
159 temp += " r" + Reg_A_Num + ":\t " + Reg_A_Val + " \n";
160 temp += " r" + Reg_B_Num + "':\t " + Reg_B_Val_Not + " \n";
161 temp += " c_in:\t " + Cin_Val + " \n";
162 break;
163 case MythSimSwing.ALU_SUBA:
164 temp += " r" + Reg_A_Num + ":\t " + Reg_A_Val + " \n";
165 temp += "\t 1111 1111 \n";
166 temp += " c_in:\t " + Cin_Val + " \n";
167 break;
168 default:
169 break;
170 }
171 temp+=" ================================ ";
172 temp += "[" + clock + "] \n";
173 //jTextPane.setText(temp);
174 appendToScreen(temp);
175 }
176
177 public void appendToScreen(String text) {
178 try {
179 int doc_length = logDoc.getLength();
180 logDoc.insertString(doc_length, text, logAttrib);
181 doc_length = logDoc.getLength();
182 hl.removeAllHighlights();
183 hl.addHighlight(doc_length-text.length(),doc_length,new DefaultHighlighter.DefaultHighlightPainter(new Color(200,200,200)));
184
185 } catch (BadLocationException ble) {
186 System.err.println("Couldn't insert initial text.");
187 }
188 }
189
190
191 private String bit8(int v) {
192 boolean a[] = MythSim.int2bit(v);
193 String temp = "";
194 if (a[7]) temp+="1"; else temp+='0';
195 if (a[6]) temp+="1"; else temp+='0';
196 if (a[5]) temp+="1"; else temp+='0';
197 if (a[4]) temp+="1"; else temp+='0';
198 temp+=" ";
199 if (a[3]) temp+="1"; else temp+='0';
200 if (a[2]) temp+="1"; else temp+='0';
201 if (a[1]) temp+="1"; else temp+='0';
202 if (a[0]) temp+="1"; else temp+='0';
203 temp += " (" + v + ") ";
204 return temp;
205 }
206 private String bit8not(int v) {
207 boolean a[] = MythSim.int2bit(v);
208 String temp = "";
209 if (a[7]) temp+="0"; else temp+='1';
210 if (a[6]) temp+="0"; else temp+='1';
211 if (a[5]) temp+="0"; else temp+='1';
212 if (a[4]) temp+="0"; else temp+='1';
213 temp+=" ";
214 if (a[3]) temp+="0"; else temp+='1';
215 if (a[2]) temp+="0"; else temp+='1';
216 if (a[1]) temp+="0"; else temp+='1';
217 if (a[0]) temp+="0"; else temp+='1';
218 temp += " (" + v + ") ";
219 return temp;
220 }
221
222
223 }
This page was automatically generated by Maven