View Javadoc
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.*; 25 import javax.swing.text.*; 26 import java.io.*; 27 import java.net.*; 28 import java.awt.*; 29 import java.util.regex.*; 30 import org.mythsim.swing.*; 31 32 /*** 33 * The Memory Window. 34 * @author Jason Vroustouris 35 */ 36 public class MemoryFrame extends MythPlugInFrame { 37 int marker[]; 38 int codeMarker[] = new int[256]; 39 int codeLength[] = new int[256]; 40 String codeString[]; 41 JTextPane jTextPane = new JTextPane(){ 42 public void setSize(Dimension d){ 43 if (d.width < getParent().getSize().width) 44 d.width = getParent().getSize().width; 45 super.setSize(d); 46 } 47 public boolean getScrollableTracksViewportWidth(){ 48 return false; 49 } 50 }; 51 52 JScrollPane jScrollPane = new JScrollPane(jTextPane); 53 Highlighter hl = jTextPane.getHighlighter(); 54 EditorKit ek = jTextPane.getEditorKit(); 55 56 public MemoryFrame(MythSimSwing a, JFrame owner) { 57 super("Memory", // title 58 true, // resizable 59 true, // closable 60 true, // maximizable 61 true, // iconifiable 62 500, // set size x 63 300, // set size y 64 0, // set location x 65 300, // set location y 66 a, 67 owner); // MythSim object 68 jTextPane.setEditable(false); 69 jTextPane.setPreferredSize(new Dimension(100,100)); 70 71 getContentPane().add(jScrollPane); 72 step(); 73 } 74 public void setup() { 75 for (int i=0; i<256; i++) { 76 codeMarker[i] = 0; 77 codeLength[i] = 5; 78 } 79 step(); 80 } 81 public void step() { 82 String temp = "Address\t(low,high)\tlow\thigh\n"; 83 temp += "-----------------------------------------\n"; 84 int ir0=0; 85 int ir1=0; 86 for (int i=0; i<256; i+=2) { 87 ir1=ms.getStatus(MythSim.MAIN_MEMORY+i); 88 ir0=ms.getStatus(MythSim.MAIN_MEMORY+i+1); 89 temp += i + ":"; 90 temp += "\t"; 91 temp += "(" + ir1 + "," + ir0 + ")"; 92 temp += "\t"; 93 temp += instruction16bit(ir0,ir1); 94 temp += "\n"; 95 } 96 jTextPane.setText(temp); 97 setAddress(ms.tc2normal(ms.getStatus(MythSim.MAR))); 98 } 99 100 /*** Select a give address in the source */ 101 public void setAddress(int a) { 102 selectAddress(a,this.SELECTION_COLOR_MEM); 103 } 104 public static String instruction16bit(int ir1, int ir0) { 105 boolean a[] = MythSim.int2bit(ir1); 106 boolean b[] = MythSim.int2bit(ir0); 107 String temp = ""; 108 if (b[7]) temp+="1"; else temp+='0'; 109 if (b[6]) temp+="1"; else temp+='0'; 110 if (b[5]) temp+="1"; else temp+='0'; 111 if (b[4]) temp+="1"; else temp+='0'; 112 if (b[3]) temp+="1"; else temp+='0'; 113 if (b[2]) temp+="1"; else temp+='0'; 114 if (b[1]) temp+="1"; else temp+='0'; 115 if (b[0]) temp+="1"; else temp+='0'; 116 temp+="\t"; 117 118 if (a[7]) temp+="1"; else temp+='0'; 119 if (a[6]) temp+="1"; else temp+='0'; 120 if (a[5]) temp+="1"; else temp+='0'; 121 if (a[4]) temp+="1"; else temp+='0'; 122 if (a[3]) temp+="1"; else temp+='0'; 123 if (a[2]) temp+="1"; else temp+='0'; 124 if (a[1]) temp+="1"; else temp+='0'; 125 if (a[0]) temp+="1"; else temp+='0'; 126 temp+="\t"; 127 128 /*switch(opcode(ir1)) { 129 case 0: 130 temp+="no-op"; 131 break; 132 case 1: 133 temp+="add "; 134 temp+="r"+ ri(ir1); 135 temp+=", r"+ rj(ir0); 136 temp+=", r"+ rk(ir0); 137 break; 138 case 2: 139 temp+="li "; 140 temp+="r"+ ri(ir1); 141 temp+=", "+ ir0; 142 break; 143 case 3: 144 temp+="bz r3"; 145 temp+=", "+ ir0; 146 break; 147 case 4: 148 temp+="bzn r3"; 149 temp+=", "+ ir0; 150 break; 151 case 5: 152 temp+="jump "; 153 temp+=ir0; 154 break; 155 case 6: 156 temp+="move "; 157 temp+="r"+ ri(ir1); 158 temp+=", r"+ rj(ir0); 159 break; 160 case 7: 161 temp+="sb "; 162 temp+="r"+ rk(ir0); 163 temp+=", r"+ rj(ir0); 164 break; 165 case 8: 166 temp+="lb "; 167 temp+="r"+ ri(ir1); 168 temp+=", r"+ rj(ir0); 169 break; 170 case 9: 171 temp+="stop"; 172 break; 173 }*/ 174 return temp; 175 } 176 177 void selectAddress(int a, Color b) { 178 String file = jTextPane.getText(); 179 String ls = System.getProperty("line.separator"); 180 file = file.replaceAll(ls,"\n"); 181 String line[] = file.split("\n"); 182 int lineMarker[] = new int[line.length+1]; 183 int codeMarker[] = new int[256]; 184 for (int i=0; i<256; i++) codeMarker[i]=0; 185 int currentMarker = 0; 186 for (int i=0; i<line.length; i++) { 187 lineMarker[i] = currentMarker; 188 String pair[] = line[i].split(":"); 189 if (pair.length == 2) { 190 int addr = Integer.parseInt(pair[0]); 191 codeMarker[addr]=i; 192 codeMarker[addr+1]=i; 193 } 194 currentMarker += line[i].length() + 1; 195 } 196 197 // BAD HACK to FIX Last Line Selection 198 if (lineMarker[codeMarker[a]+1] == 0) { 199 lineMarker[codeMarker[a]+1] = file.length(); 200 } 201 202 203 try { 204 //System.out.print("(-" + lineMarker[codeMarker[a]] + "," + lineMarker[codeMarker[a]+1] + ")"); 205 hl.removeAllHighlights(); 206 hl.addHighlight(lineMarker[codeMarker[a]],lineMarker[codeMarker[a]+1],new DefaultHighlighter.DefaultHighlightPainter(b)); 207 jTextPane.select(lineMarker[codeMarker[a]],lineMarker[codeMarker[a]+1]); 208 } catch (Throwable t) { 209 t.printStackTrace(); 210 } 211 } 212 213 }

This page was automatically generated by Maven