1 package edu.berkeley.cs.obits;
4 import org.ibex.util.*;
8 public static String pad(int len, String s) { if (s.length() >= len) return s.toUpperCase(); return "0"+pad(len-1,s); }
9 public static String hex32(int i) { return pad(8, Long.toString(i & 0xffffffffffffffffL, 16)); }
10 public static String hex24(int i) { return pad(6, Integer.toString((i & 0xffffff), 16)); }
11 public static String hex8(int i) { return pad(2, Integer.toString((i & 0xff), 16)); }
12 public static String bin8(int i) { return pad(8, Integer.toString((i & 0xff), 2)); }
13 public static String dec2(int i) { return pad(2, Integer.toString(i & 0xff)); }
15 public static void main(String[] s) throws Exception {
16 Log.level = Log.DEBUG;
17 new Bits().read(System.in);
20 private static class Bits {
21 private byte[] bits = new byte[0];
22 //public int get(int whichByte, int whichBit, int len) { }
23 //public void set(int whichByte, int whichBit, int len, int val) { }
25 private int control = 0;
26 public int control() { return control; }
27 public void control(int control) { this.control = control; }
29 public void read2(InputStream bitstream) throws IOException {
30 DataInputStream dis = new DataInputStream(new Encode.Ascii.In(16, bitstream));
33 dis.readUnsignedByte();
34 dis.readUnsignedByte();
35 dis.readUnsignedByte();
36 int i = dis.readUnsignedByte();
37 System.out.println(bin8(i));
39 } catch (EOFException e) {
42 public void read(InputStream bitstream) throws IOException {
43 DataInputStream dis = new DataInputStream(new Encode.Ascii.In(2, bitstream));
44 int b = dis.readUnsignedByte();
45 if (b != 0x00) throw new Error("bitstream did not start with zero-byte; got " + b);
46 Log.debug(this, "saw leading zero-byte");
47 b = dis.readUnsignedByte();
48 if (b != 0xB7) throw new Error("bitstream did not start with preamble byte B7; got " + b);
49 Log.debug(this, "saw preamble byte");
50 control(dis.readInt());
51 Log.debug(this, "set control register to " + hex32(control()));
52 int numWindows = dis.readShort();
53 Log.debug(this, "this bitstream has " + numWindows + " window(s)");
55 for(int i=0; i<numWindows; i++) {
56 int start = (dis.readUnsignedByte() << 16) | (int)dis.readShort();
57 int end = (dis.readUnsignedByte() << 16) | (int)dis.readShort();
59 Log.debug(this, " window " + dec2(i) + " spans addresses " + hex24(start) + " - " + hex24(end) + "[count="+count+"]");
60 int _z = (start & 0x0000ff) >> 0;
61 int _y = (start & 0x00ff00) >> 8;
62 int _x = (start & 0xff0000) >> 16;
63 int z_ = (end & 0x0000ff) >> 0;
64 int y_ = (end & 0x00ff00) >> 8;
65 int x_ = (end & 0xff0000) >> 16;
66 int z = (start & 0x0000ff) >> 0;
67 int y = (start & 0x00ff00) >> 8;
68 int x = (start & 0xff0000) >> 16;
72 mode4(x, y, z, dis.readUnsignedByte());
74 if (x > 15) { x = 0; y++; }
75 if (y > 15) { y = 0; z++; }
87 } while(!valid(x,y,z));
89 //Log.debug(this, " read " + count + " bytes (" + hex24(count)+")");
92 Log.debug(this, "done " + count);
93 b = dis.readUnsignedByte();
94 if (b != 0xB7) throw new Error("bitstream did not start with preamble byte B7; got " + bin8(b));
95 Log.debug(this, "done2");
99 public boolean valid(int x, int y, int z) {
101 case 0x00: case 0x01: break;
103 if (x > 15) return false;
104 if (y > 15) return false;
108 public void mode4(int x, int y, int z, int d) {
109 //Log.debug(this, " ("+dec2(x)+","+dec2(y)+"):"+hex8(z)+" = "+bin8(d));
110 //System.out.println(hex8(z)+hex8(y)+hex8(x)+hex8(d));
115 public static class At40k extends FPGA {
118 public At40k(int width, int height) { this.width = width; this.height = height; }
120 public static class At40k10 extends At40k { public At40k10() { super(24, 24); } }
122 public Sector sector(int col, int row) { return new Sector(col, row); }
123 public final class Sector {
124 public final int col;
125 public final int row;
126 public Sector(int col, int row) {
127 if (row % 4 != 0) throw new Error("Sector must be created with a multiple-of-4 row");
128 if (col % 4 != 0) throw new Error("Sector must be created with a multiple-of-4 col");
134 public Cell cell(int col, int row) { return new Cell(col, row); }
135 public final class Cell {
136 public final int col;
137 public final int row;
138 public Sector getSector() { return sector(col - (col % 4), row - (row % 4)); }
139 public Cell(int col, int row) {
145 public class Sector {
146 Cell[][] = new Cell[4][4];
149 Buf[] west = new Buf[4];
150 Buf[] east = new Buf[4];
151 Buf[] north = new Buf[4];
152 Buf[] south = new Buf[4];
153 Pip pass = new Pip[4][4][5][2];
159 public final Port[] h = new Port[5] { port(), port(), port(), port(), port() };
160 public final Port[] v = new Port[5] { port(), port(), port(), port(), port() };
161 public final Port[] s = new Port[5] { port(), port(), port(), port(), port() };
162 public final Port nw, sw, se, ne;
163 public final Port n, s, w, e;
164 public final Port xout, yout;
166 public final Pip zin = pip( s[0], s[1], s[2], s[3], s[4]);
167 public final Pip win = pip( s[0], s[1], s[2], s[3], s[4]);
168 public final Pip xin = pip(nw, ne, sw, se, s[0], s[1], s[2], s[3], s[4]);
169 public final Pip yin = pip(n, s, e, w, s[0], s[1], s[2], s[3], s[4]);
171 public final Pip wpip = pip(win, zin, and(win, zin), fb);
172 public final Pip zpip = pip(zin, one, zero);
174 public final Lut xlut = lut(xpip, wmux, ypip);
175 public final Lut ylut = lut(xpip, wmux, ypip);
176 public final Mux zmux = mux(xlut, ylut, zpip);
177 public final Reg reg = reg(zmux);
178 public final Pip center = pip(reg, zmux);
180 public final Pip fb = pip(zmux, reg);
182 public final Pip center = pip(zmux, reg);
183 public final Pip xout = pip(xlut, center);
184 public final Pip yout = pip(ylut, center);
186 public final Pip oe = pip(one, h[4], v[4]);
187 public final Buf out = buf(fb, oe);
189 public final Pip[] o = pip5(out, s);
190 public final Pip[] h = pip5(h, s);
191 public final Pip[] v = pip5(v, s);
198 public class At94k extends At40k {