// reads .rel files produced by as6811 assembler // Fred Martin / computer science / UML // Thu Oct 10 01:22:26 2002 import java.io.*; class ReadRel { static byte[] code = new byte[512]; static int codesize; public static byte[] read(File f) { codesize= 0; // init code to zeros for (int i=0; i<512; i++) code[i]= 0; try { FileReader fr = new FileReader(f); BufferedReader br = new BufferedReader(fr); String s; while ((s = br.readLine()) != null) codesize += parse(s); } catch (Exception e) { e.printStackTrace(); } System.out.println("Read " + codesize + " bytes of code from file " + f); return code; } private static int parse(String line) { int addr, i; int l = line.length(); int count= 0; if (l < 1) return count; if (line.charAt(0) != 'T') return count; // grab addr of code addr = 256 * Integer.parseInt(line.substring(2, 4), 16) + Integer.parseInt(line.substring(5, 7), 16); // plow thru line grabbing bytes for (i= 8; i < l; i+=3) { code[addr] = (byte)Integer.parseInt(line.substring(i, i + 2), 16); addr++; count++; } return count; } }