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.core; 22 23 import java.io.*; 24 import java.util.*; 25 import javax.swing.*; 26 import javax.swing.text.*; 27 import java.awt.*; 28 import org.mythsim.text.*; 29 30 /*** 31 * Interface to parsers. 32 * @author Jason Vroustouris 33 */ 34 public class MythParser { 35 String memorySource = ""; 36 String microcodeSource = ""; 37 //Vector ucodememory = new Vector(); 38 Vector ucodememory = null; 39 int ucodeSize = 0; 40 int ucodeCounter = 0; 41 int clock = 0; 42 int startSelect = 0; 43 44 int memory[] = new int[256]; 45 int size = 0; 46 int counter = 0; 47 MythSim ms; 48 49 // Microcode Parser Functions 50 51 /*** @return microcode source file in string */ 52 public String getMicrocodeSource() { 53 return microcodeSource; 54 } 55 56 public int[][] toUcodeIntArray() { 57 ControlWord cw = new ControlWord(); 58 int mpa[][] = new int[ucodememory.size()][MythSim.CONTROL_WORD_LENGTH]; 59 for (int i = 0; i < ucodeSize; i++) { 60 cw = ( (ControlWord) ucodememory.get(i)); 61 for (int j = 0; j < MythSim.CONTROL_WORD_LENGTH; j++) { 62 mpa[i][j] = cw.get(j); 63 } 64 } 65 return mpa; 66 } 67 68 public Integer[][] toIntegerArray() { 69 ControlWord cw = new ControlWord(); 70 Integer mpa[][] = new Integer[ucodememory.size()][27]; 71 for (int i = 0; i < ucodeSize; i++) { 72 cw = ( (ControlWord) ucodememory.get(i)); 73 for (int j = 0; j < 26; j++) { 74 mpa[i][j] = new Integer(cw.get(j)); 75 } 76 } 77 return mpa; 78 } 79 80 public Object[][] toUcodeObjectArray() { 81 ControlWord cw = new ControlWord(); 82 Object mpa[][] = new Object[ucodememory.size()][27]; 83 for (int i = 0; i < ucodeSize; i++) { 84 mpa[i][0] = new String(Text.address(i)); 85 cw = ( (ControlWord) ucodememory.get(i)); 86 String temp = ""; 87 temp += cw.get(7); 88 temp += cw.get(6); 89 temp += cw.get(5); 90 temp += cw.get(4); 91 temp += cw.get(3); 92 temp += cw.get(2); 93 temp += cw.get(1); 94 temp += cw.get(0); 95 mpa[i][1] = new String(temp); 96 for (int j = 8; j < 26; j++) { 97 mpa[i][j - 6] = new Integer(cw.get(j)); 98 } 99 } 100 return mpa; 101 } 102 103 public Object[][] toCodeArray() { 104 ControlWord cw = new ControlWord(); 105 Object mpa[][] = new Object[ucodememory.size()][1]; 106 for (int i = 0; i < ucodeSize; i++) { 107 cw = ( (ControlWord) ucodememory.get(i)); 108 mpa[i][0] = new String(cw.line()); 109 } 110 return mpa; 111 } 112 113 public MythParser() {}; 114 115 /*** parse microcode and memory source files. */ 116 public MythParser(File ucodeFile, File memFile, MythSim _ms) throws Exception { 117 ms = _ms; 118 FileReader fr = null; 119 try { 120 // Microcode Parser 121 fr = new FileReader(ucodeFile); 122 123 UcodeParser ucodeParser = new UcodeParser(fr); 124 ucodeParser.parse(); 125 if (!ucodeParser.isValid()) { 126 throw new MythParserError(ucodeParser.errorMessages()); 127 } 128 ucodememory = ucodeParser.getUcodeVector(); 129 ucodeSize = ucodememory.size(); 130 //ustore(); 131 fr.close(); 132 fr = new FileReader(ucodeFile); 133 BufferedReader br = new BufferedReader(fr); 134 String line = br.readLine(); 135 while (line != null) { 136 microcodeSource += line + "\n"; 137 line = br.readLine(); 138 } 139 fr.close(); 140 141 // Memory Parser 142 for (int i = 0; i < 256; i++) { 143 memory[i] = -1; 144 } 145 146 fr = new FileReader(memFile); 147 MemParser memParser = new MemParser(fr); 148 memParser.parse(); 149 if (!memParser.isValid()) { 150 throw new MythParserError(memParser.errorMessages()); 151 } 152 153 fr.close(); 154 155 fr = new FileReader(memFile); 156 br = new BufferedReader(fr); 157 line = br.readLine(); 158 while (line != null) { 159 memorySource += line + "\n"; 160 line = br.readLine(); 161 } 162 memory = memParser.getMemoryArray(); 163 fr.close(); 164 165 } 166 167 catch (Exception e) { 168 fr.close(); 169 throw e; 170 } 171 172 } 173 174 public void ustore() { 175 ControlWord.printHead(); 176 for (int i = 0; i < ucodeSize; i++) { 177 if (i % 5 == 0 && i != 0) { 178 System.out.println(""); 179 } 180 ( (ControlWord) ucodememory.get(i)).print(); 181 } 182 } 183 184 // Memory Parser Functions 185 186 /*** @return memory source file in string */ 187 public String getMemorySource() { 188 return memorySource; 189 } 190 191 public boolean notDone() { 192 return counter < size; 193 } 194 195 public int[] toMemIntArray() { 196 return memory; 197 } 198 199 public String[] toStringArray() { 200 String temp[] = new String[256]; 201 for (int i = 0; i < 256; i++) { 202 temp[i] = Text.int2bin(memory[i]); 203 } 204 return temp; 205 } 206 207 public Object[][] toMemObjectArray() { 208 Object temp[][] = new Object[256][2]; 209 for (int i = 0; i < 256; i++) { 210 temp[i][0] = "" + i; 211 temp[i][1] = Text.int2bin(memory[i]); 212 } 213 return temp; 214 } 215 216 /*** Parse address (before ":") */ 217 int parseAddress(String a) { 218 return Integer.parseInt(a); 219 } 220 221 /*** Parse value (after ":") */ 222 int parseValue(String a) { 223 if (a.length() == 8) { 224 return string2int(a); 225 } 226 else { 227 return Integer.parseInt(a); 228 } 229 } 230 231 /*** Convert an 8bit binary string to a int. */ 232 int string2int(String a) { 233 String b = a.replaceAll(" ", ""); 234 if (b.length() == 8) { 235 int t = 0; 236 char c[] = b.toCharArray(); 237 if (c[0] == '1') { 238 t -= 128; 239 } 240 if (c[1] == '1') { 241 t += 64; 242 } 243 if (c[2] == '1') { 244 t += 32; 245 } 246 if (c[3] == '1') { 247 t += 16; 248 } 249 if (c[4] == '1') { 250 t += 8; 251 } 252 if (c[5] == '1') { 253 t += 4; 254 } 255 if (c[6] == '1') { 256 t += 2; 257 } 258 if (c[7] == '1') { 259 t += 1; 260 } 261 return t; 262 } 263 else { 264 return -129; 265 } 266 } 267 268 }

This page was automatically generated by Maven