From e847739b51f485baab505becdf4241471017d207 Mon Sep 17 00:00:00 2001 From: adam Date: Tue, 25 Jul 2006 03:50:58 +0100 Subject: [PATCH] checkpoint --- src/edu/berkeley/obits/AtmelSerial.java | 35 +- src/edu/berkeley/obits/device/atmel/At40k.java | 235 +++--- .../berkeley/obits/device/atmel/AtmelDevice.java | 48 ++ src/edu/berkeley/obits/device/atmel/AvrDrone.java | 1 + src/edu/berkeley/obits/gui/Gui.java | 806 +++++++++++++------- src/edu/berkeley/obits/gui/P.java | 4 + src/edu/berkeley/obits/gui/ZoomingPanel.java | 165 +++- 7 files changed, 891 insertions(+), 403 deletions(-) diff --git a/src/edu/berkeley/obits/AtmelSerial.java b/src/edu/berkeley/obits/AtmelSerial.java index cffe6c7..a4a0f22 100644 --- a/src/edu/berkeley/obits/AtmelSerial.java +++ b/src/edu/berkeley/obits/AtmelSerial.java @@ -22,28 +22,22 @@ public class AtmelSerial { while(e.hasMoreElements()) { CommPortIdentifier cpi = (CommPortIdentifier)e.nextElement(); Log.info(AtmelSerial.class, "trying " + cpi.getName()); - if (cpi.getName().startsWith("/dev/cu.usbserial-")) return new RXTXPort(cpi.getName()); - if (cpi.getName().startsWith("/dev/ttyS0")) return new RXTXPort(cpi.getName()); + if (cpi.getName().startsWith("/dev/cu.usbserial-")) + return new RXTXPort(cpi.getName()); + if (cpi.getName().startsWith("/dev/ttyS0")) + return new RXTXPort(cpi.getName()); } Log.info(AtmelSerial.class, "returning null..."); return null; } public static int PIPELEN=20; public static void main(String[] s) throws Exception { - //AvrDrone device = new AvrDrone(detectObitsPort()); + //AvrDrone device = new AvrDrone(detectObitsPort()); AvrDrone device = new AvrDrone(); At40k at40k = new At40k.At40k10(device); - int count = 0; try { long begin = System.currentTimeMillis(); - BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); - for(String str = br.readLine(); str != null; str = br.readLine()) { - long foo = Long.parseLong(str, 16); - device.mode4((int)(foo >> 24), (int)(foo >> 16), (int)(foo >> 8), (int)(foo >> 0)); - count++; - if (count % 100 == 0) Log.info(AtmelSerial.class, "wrote " + count + " configuration octets"); - } - device.flush(); + device.readMode4(System.in); long end = System.currentTimeMillis(); Log.info(AtmelSerial.class, "finished in " + ((end-begin)/1000) + "s"); Thread.sleep(1000); @@ -402,8 +396,15 @@ public class AtmelSerial { c.out(L2, true); c.out(L3, true); c.out(L4, true); + c.xo(true); + c.yo(true); c.c(ZMUX); + at40k.cell(9,10).xo(true); + at40k.cell(9,10).yo(true); + at40k.cell(9,10).c(YLUT); + at40k.cell(9,10).b(false); + //for(int x=5; x you can't! this is a false connection in my diagram + // need to find the bit that sets the w-mux off // what does it mean for both bits (0x30) to be set to 1? //if (fb && z) throw new RuntimeException("invalid combination"); int result = 0; @@ -316,95 +336,6 @@ public class At40k { dev.mode4(1, row, col, result, 0x34); } - public boolean xlut_relevant() { return xlut_relevant(true); } - public boolean xlut_relevant(boolean recurse) { - if ((c()==XLUT || c()==ZMUX) && c_relevant()) return true; - if (xo()) return false; - if (nw() != null && nw().xi()==SE && nw().xi_relevant() && (recurse || nw().xlut_relevant())) return true; - if (ne() != null && ne().xi()==SW && ne().xi_relevant() && (recurse || ne().xlut_relevant())) return true; - if (sw() != null && sw().xi()==NE && sw().xi_relevant() && (recurse || sw().xlut_relevant())) return true; - if (se() != null && se().xi()==NW && se().xi_relevant() && (recurse || se().xlut_relevant())) return true; - return false; - } - public boolean xi_to_ylut_relevant() { - int lut = ylut(); - if (((lut & 0xcc) >> 2) == (lut & 0x33)) return false; - return true; - } - public boolean yi_to_xlut_relevant() { - int lut = xlut(); - if (((lut & 0xcc) >> 2) == (lut & 0x33)) return false; - return true; - } - public boolean xi_relevant() { return xi_to_xlut_relevant() || xi_to_ylut_relevant(); } - public boolean yi_relevant() { return yi_to_xlut_relevant() || yi_to_ylut_relevant(); } - public boolean zi_to_xlut_relevant() { - int lut = xlut(); - if (((lut & LUT_Z) >> 4) == (lut & LUT_Z)) return false; - return true; - } - public boolean zi_to_ylut_relevant() { - int lut = ylut(); - if (((lut & LUT_Z) >> 4) == (lut & LUT_Z)) return false; - return true; - } - public boolean xi_to_xlut_relevant() { - int lut = xlut(); - if (((lut & LUT_SELF) >> 1) == (lut & (LUT_SELF >> 1))) return false; - return true; - } - public boolean yi_to_ylut_relevant() { - int lut = ylut(); - if (((lut & LUT_SELF) >> 1) == (lut & (LUT_SELF >> 1))) return false; - return true; - } - public boolean ylut_relevant() { - if ((c()==YLUT || c()==ZMUX) && c_relevant()) return true; - if (yo()) return false; - if (north() != null && north().yi()==SOUTH) return true; - if (east() != null && east().yi()==WEST) return true; - if (south() != null && south().yi()==NORTH) return true; - if (west() != null && west().yi()==EAST) return true; - return false; - } - public boolean c_relevant() { - // FIXME: feedback line! - for(int i=0; i<5; i++) - if (out(i)) return true; - if (xo() || yo()) return true; - return false; - } - - public boolean register_relevant() { - if (!c_relevant() && !fb_relevant()) return false; - if (f() && out_relevant()) return true; - if (f() && fb_relevant()) return true; - if (b() && xo()) return true; - if (b() && yo()) return true; - return false; - } - public boolean out_relevant() { - boolean out = false; - boolean connect = false; - for(int i=0; i<4; i++) { - if (out(L0+i)) out = true; - if (hx(L0+i)) connect = true; - if (vx(L0+i)) connect = true; - } - return out && connect; - } - public boolean fb_relevant() { - //if (!c_relevant()) return false; - if (!(zi_to_xlut_relevant() && xlut_relevant()) || - !(zi_to_ylut_relevant() && ylut_relevant())) return false; - switch(t()) { - case 0x34: return true; - case 0x14: return true; - case 0x10: return true; - case 0x30: return true; - } - return false; - } public void c(int source) { switch(source) { @@ -425,10 +356,10 @@ public class At40k { } public void b(boolean registered) { dev.mode4(1, row, col, 3, !registered); } public void f(boolean registered) { dev.mode4(1, row, col, 2, !registered); } - public boolean xo() { return (dev.mode4(1, row, col) & 0x01) != 0; } - public boolean yo() { return (dev.mode4(1, row, col) & 0x02) != 0; } - public void xo(boolean center) { dev.mode4(1, row, col, 1, center); } - public void yo(boolean center) { dev.mode4(1, row, col, 0, center); } + public boolean xo() { return (dev.mode4(1, row, col) & 0x01) != 0; } + public boolean yo() { return (dev.mode4(1, row, col) & 0x02) != 0; } + public void xo(boolean center) { dev.mode4(1, row, col, 0, center); } + public void yo(boolean center) { dev.mode4(1, row, col, 1, center); } public boolean b() { return (dev.mode4(1, row, col) & (1 << 3)) == 0; } public boolean f() { return (dev.mode4(1, row, col) & (1 << 2)) == 0; } public boolean x() { return (dev.mode4(1, row, col) & (1 << 1)) != 0; } @@ -453,16 +384,16 @@ public class At40k { public int xi() { // FIXME: can be multiple - if ((dev.mode4(0x03, row, col) & (1<<4))!=0) return L3; + if ((dev.mode4(0x03, row, col) & (1<<4))!=0) return L4; switch(dev.mode4(0x05, row, col) & 0xff) { case 0x80: return SW; case (1<<6): return NE; case (1<<5): return SE; case (1<<4): return NW; - case (1<<3): return L3; - case (1<<2): return L2; - case (1<<1): return L1; - case (1<<0): return L0; + case (1<<3): return L0; + case (1<<2): return L1; + case (1<<1): return L2; + case (1<<0): return L3; case 0: return NONE; default: throw new Error(); } @@ -490,10 +421,10 @@ public class At40k { case (1<<5): return SOUTH; case (1<<6): return WEST; case (1<<4): return EAST; - case (1<<3): return L3; - case (1<<2): return L2; - case (1<<1): return L1; - case (1<<0): return L0; + case (1<<3): return L0; + case (1<<2): return L1; + case (1<<1): return L2; + case (1<<0): return L3; case 0: return NONE; default: throw new Error(); } @@ -539,6 +470,7 @@ public class At40k { } } + public void zi(int source) { switch(source) { case L4: dev.mode4(0x02, row, col, 1<<7, 0xDB); break; @@ -557,12 +489,99 @@ public class At40k { case (1<<4): return L2; case (1<<3): return L1; case (1<<2): return L0; + case (1<<1): return NONE; /* huh? */ case (1<<0): return NONE; /* huh? */ case 0: return NONE; default: throw new RuntimeException("invalid argument: zi=="+(dev.mode4(0x02, row, col) & 0xDB)); } } + + // Relevance ////////////////////////////////////////////////////////////////////////////// + + public boolean xo_relevant() { return xo_relevant(NE) || xo_relevant(SE) || xo_relevant(NW) || xo_relevant(SW); } + public boolean xo_relevant(int direction) { + switch(direction) { + case NE: return ne() != null && ne().xi()==SW /*&& ne().xi_relevant()*/; + case NW: return nw() != null && nw().xi()==SE /*&& nw().xi_relevant()*/; + case SE: return se() != null && se().xi()==NW /*&& se().xi_relevant()*/; + case SW: return sw() != null && sw().xi()==NE /*&& sw().xi_relevant()*/; + default: return false; + } + } + public boolean yo_relevant() { return yo_relevant(NORTH) || yo_relevant(SOUTH) || yo_relevant(EAST) || yo_relevant(WEST); } + public boolean yo_relevant(int direction) { + switch(direction) { + case NORTH: return north() != null && north().yi()==SOUTH /*&& north().yi_relevant()*/; + case EAST: return east() != null && east().yi()==WEST /*&& east().yi_relevant()*/; + case SOUTH: return south() != null && south().yi()==NORTH /*&& south().yi_relevant()*/; + case WEST: return west() != null && west().yi()==EAST /*&& west().yi_relevant()*/; + default: return false; + } + } + public boolean xi_relevant() { return xi_to_xlut_relevant() || xi_to_ylut_relevant(); } + public boolean yi_relevant() { return yi_to_xlut_relevant() || yi_to_ylut_relevant(); } + public boolean xi_to_ylut_relevant() { return (((ylut() & 0xcc) >> 2) != (ylut() & 0x33)); } + public boolean yi_to_xlut_relevant() { return (((xlut() & 0xcc) >> 2) != (xlut() & 0x33)); } + public boolean zi_to_xlut_relevant() { return (((xlut() & LUT_Z) >> 4) != (xlut() & LUT_Z)); } + public boolean zi_to_ylut_relevant() { return (((ylut() & LUT_Z) >> 4) != (ylut() & LUT_Z)); } + public boolean xi_to_xlut_relevant() { return (((xlut() & LUT_SELF) >> 1) != (xlut() & (LUT_SELF >> 1))); } + public boolean yi_to_ylut_relevant() { return (((ylut() & LUT_SELF) >> 1) != (ylut() & (LUT_SELF >> 1))); } + public boolean xlut_relevant() { + if ((c()==XLUT || c()==ZMUX) && c_relevant()) return true; + if (xo()) return false; + return xo_relevant(); + } + public boolean ylut_relevant() { + if ((c()==YLUT || c()==ZMUX) && c_relevant()) return true; + if (yo()) return false; + return yo_relevant(); + } + public boolean c_relevant() { + switch(t()) { + case 0x34: return true; + case 0x14: return true; + case 0x10: return true; + case 0x30: return true; + } + for(int i=0; i<5; i++) + if (out(i)) + return true; + if (xo() || yo()) return true; + return false; + } + + public boolean register_relevant() { + if (!c_relevant()) return false; + if (f() && out_relevant()) return true; + if (f() && fb_relevant()) return true; + if (b() && xo()) return true; + if (b() && yo()) return true; + return false; + } + public boolean out_relevant() { + boolean out = false; + boolean connect = false; + for(int i=0; i<4; i++) { + if (out(L0+i)) out = true; + if (hx(L0+i)) connect = true; + if (vx(L0+i)) connect = true; + } + return out && connect; + } + public boolean fb_relevant() { + if (!(zi_to_xlut_relevant()) || + !(zi_to_ylut_relevant())) return false; + switch(t()) { + case 0x34: return true; + case 0x14: return true; + case 0x10: return true; + case 0x30: return true; + } + return false; + } + + } public IOB iob_bot(int col, boolean primary) { return new IOB(col, 0, primary, true); } diff --git a/src/edu/berkeley/obits/device/atmel/AtmelDevice.java b/src/edu/berkeley/obits/device/atmel/AtmelDevice.java index 27f6c36..ae77df1 100644 --- a/src/edu/berkeley/obits/device/atmel/AtmelDevice.java +++ b/src/edu/berkeley/obits/device/atmel/AtmelDevice.java @@ -3,6 +3,8 @@ package edu.berkeley.obits.device.atmel; import edu.berkeley.obits.*; //import static edu.berkeley.cs.obits.device.atmel.Wires.*; import java.util.*; +import java.io.*; +import org.ibex.util.Log; public abstract class AtmelDevice extends Bits implements Device { @@ -63,9 +65,55 @@ public abstract class AtmelDevice extends Bits implements Device { public static final int TMUX_Z = 0x00001004; public static final int TMUX_W_AND_FB = 0x00001008; public static final int TMUX_FB = 0x00001010; + + } /** issue a command to the device in Mode4 format; see Gosset's documentation for further details */ + public int getWidth() { return 24; } + public int getHeight() { return 24; } + + private static String hex2(int i) { + String ret = Integer.toString(i, 16); + while(ret.length() < 2) ret = "0"+ret; + return ret.toUpperCase(); + } + + public void readMode4(InputStream in) throws IOException { + int count = 0; + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + for(String str = br.readLine(); str != null; str = br.readLine()) { + long foo = Long.parseLong(str, 16); + mode4((int)(foo >> 24), (int)(foo >> 16), (int)(foo >> 8), (int)(foo >> 0)); + count++; + if (count % 100 == 0) Log.info(AtmelSerial.class, "wrote " + count + " configuration octets"); + } + flush(); + } + + public void writeMode4(Writer w) throws IOException { + for(int x=0; x 0x09 && z < 0x10) || + (z > 0x11 && z < 0x20) || + (z > 0x29 && z < 0x30) || + (z > 0x39 && z < 0x40) || + (z > 0x41 && z < 0x60) || + (z > 0x67 && z < 0x70) || + (z > 0x77 && z < 0xD0) || + (z > 0xD3)) + continue; + w.write(hex2(z)); + w.write(hex2(y)); + w.write(hex2(x)); + w.write(hex2(mode4(z, y, x) & 0xff)); + w.write('\n'); + } + w.flush(); + } + + public abstract void mode4(int z, int y, int x, int d) throws DeviceException; public abstract byte mode4(int z, int y, int x); public byte mode4zyx(int zyx) { return mode4(zyx>>24, (zyx>>16)&0xff, (zyx>>8)&0xff); } diff --git a/src/edu/berkeley/obits/device/atmel/AvrDrone.java b/src/edu/berkeley/obits/device/atmel/AvrDrone.java index fc65f01..0d580c5 100644 --- a/src/edu/berkeley/obits/device/atmel/AvrDrone.java +++ b/src/edu/berkeley/obits/device/atmel/AvrDrone.java @@ -86,6 +86,7 @@ public class AvrDrone extends AtmelDevice { private Thread reader = new Thread() { public void run() { + System.out.println("*** reader thread begun"); while(true) { try { byte b = sp==null ? 0 : in.readByte(); diff --git a/src/edu/berkeley/obits/gui/Gui.java b/src/edu/berkeley/obits/gui/Gui.java index 15a2bd2..6b1f472 100644 --- a/src/edu/berkeley/obits/gui/Gui.java +++ b/src/edu/berkeley/obits/gui/Gui.java @@ -12,46 +12,72 @@ import org.ibex.util.*; import java.io.*; import java.util.*; import javax.swing.*; +import static edu.berkeley.obits.gui.GuiConstants.*; public class Gui extends ZoomingPanel implements KeyListener, MouseMotionListener { Graphics2D g; G gg; - public static int SIZE = 92; - public static int RINGS = 3; - public static int BEVEL = 5; - public static int CORE_SIZE = 64; - public static int CORE_OFFSET = 10; - public static int HOFF = 52; - - public static int RED = 0xff0000; - public static int BLUE = 0x0000ff; - - public static final P YLUT_OUTPUT_POINT = new P(SIZE-CORE_OFFSET-CORE_SIZE+51 - 2, CORE_OFFSET + 41 - 3); - public static final P XLUT_OUTPUT_POINT = new P(SIZE-CORE_OFFSET-CORE_SIZE+17 - 2, CORE_OFFSET + 41 - 3); - At40k at40k; + AvrDrone drone; - private HashSet cells = new HashSet(); private Cell[][] ca = new Cell[128][]; - public static final Color nonselectedcell = new Color(0xcc, 0xcc, 0xcc); - public static final Color selectedcell = new Color(0x44, 0x44, 0xff); + //public static final Color nonselectedcell = new Color(0x44, 0x44, 0x44); + public static final Color nonselectedcell = new Color(0xee, 0xee, 0xee); + public static final Color selectedcell = new Color(0x00, 0x00, 0x00); - public Gui(At40k at40k) { + public void writeMode4() { + try { + final JFileChooser fc = new JFileChooser(); + int returnVal = fc.showSaveDialog(this); + Writer pw = new OutputStreamWriter(new FileOutputStream(fc.getSelectedFile())); + drone.writeMode4(pw); + pw.flush(); + pw.close(); + System.err.println("done writing"); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public void readMode4() { + try { + final JFileChooser fc = new JFileChooser(); + int returnVal = fc.showOpenDialog(this); + drone.readMode4(new FileInputStream(fc.getSelectedFile())); + System.err.println("done reading"); + repaint(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public Gui(At40k at40k, AvrDrone drone) { this.at40k = at40k; + this.drone = drone; for(int i=0; i= L0 && plane <= L4 && cell.hx(plane)) { - P p1 = new P(38, 18); - p1 = rotateInner(p1); - if (cell.zi_to_xlut_relevant() && cell.xlut_relevant()) - route(new P(84, 84 - 2*(plane-L0)), p1, 3); - p1 = new P(64, 18); - p1 = rotateInner(p1); - if (cell.zi_to_ylut_relevant() && cell.ylut_relevant()) - route(new P(84, 84 - 2*(plane-L0)), p1, 3); - } - plane = cell.wi(); - if (plane >= L0 && plane <= L4 && cell.hx(plane)) { - P p1 = new P(38, 18); - p1 = rotateInner(p1); - if (cell.zi_to_xlut_relevant() && cell.xlut_relevant()) - route(new P(84, 84 - 2*(plane-L0)), p1, 3); - p1 = rotateInner(new P(64, 18)); - if (cell.zi_to_ylut_relevant() && cell.ylut_relevant()) - route(new P(84, 84 - 2*(plane-L0)), p1, 3); - } - } - public void drawVwires() { - gg.color(Color.magenta); + } for(int i=0; i<5; i++) - if (cell.vwire(i).isDriven()) + if (cell.vwire(i).isDriven()) { + gg.color(cell.out(i) ? ORANGE : MAGENTA); gg.line(2*(1+RINGS)+2*i, 0, 2*(1+RINGS)+2*i, SIZE); - int plane = cell.zi(); - if (plane >= L0 && plane <= L4 && cell.vx(plane)) { - P p1 = new P(38, 18); - p1 = rotateInner(p1); - if (cell.zi_to_xlut_relevant() && cell.xlut_relevant()) - route(new P(17 - 2*(plane-L0), 8), p1, 3); - p1 = new P(64, 18); - p1 = rotateInner(p1); - if (cell.zi_to_ylut_relevant() && cell.ylut_relevant()) - route(new P(17 - 2*(plane-L0), 8), p1, 3); - } - plane = cell.wi(); - if (plane >= L0 && plane <= L4 && cell.vx(plane)) { - P p1 = new P(38, 18); - p1 = rotateInner(p1); - if (cell.zi_to_xlut_relevant() && cell.xlut_relevant()) - route(new P(17 - 2*(plane-L0), 8), p1, 3); - p1 = new P(64, 18); - p1 = rotateInner(p1); - if (cell.zi_to_ylut_relevant() && cell.ylut_relevant()) - route(new P(17 - 2*(plane-L0), 8), p1, 3); - } - } - public P corner(int corner, int ring) { - switch(corner) { - case NW: return new P(0 +2*ring, SIZE -2*xring); - case SW: return new P(0 +2*ring, 0 +2*xring); - case NE: return new P(SIZE -2*ring, SIZE -2*xring); - case SE: return new P(SIZE -2*ring, 0 +2*xring); - default: return null; } + if (cell.zi_to_xlut_relevant()) wire(cell.zi(), true); + if (cell.zi_to_ylut_relevant()) wire(cell.zi(), false); + if (cell.zi_to_xlut_relevant()) wire(cell.wi(), true); + if (cell.zi_to_ylut_relevant()) wire(cell.wi(), false); + } + + public void wire(int plane, boolean xlut) { + if (!(plane >= L0 && plane <= L4 && cell.vx(plane))) return; + if (xlut ? xlut_relevant(cell) : cell.ylut_relevant()) + route(new P(17 - 2*(plane-L0), 8), + rotateInner(xlut ? new P(38, 18) : new P(64, 18)), + 3); + } + + public P corner(int corner, int size, int ring) { + switch(corner) { + case NW: return new P(0 +2*ring, size -2*ring); + case SW: return new P(0 +2*ring, 0 +2*ring); + case NE: return new P(size -2*ring, size -2*ring); + case SE: return new P(size -2*ring, 0 +2*ring); + default: return null; } + } public void drawInternalRouting() { - gg.color(new Color(0, 107, 51)); + gg.color(ORANGE); if (cell.fb_relevant()) { if (cell.f()) { gg.line(51, 74, 37, 74); - gg.line(37, 74, 50, 12); + gg.line(37, 74, 51, 12); } else if (cell.c() == XLUT) { - gg.line(32, 52, 50, 52); - gg.line(50, 52, 50, 12); + gg.color(LIGHTRED); + gg.line(33, 52, 51, 52); + gg.line(51, 52, 51, 12); } else if (cell.c() == YLUT) { - gg.line(68, 52, 50, 52); - gg.line(50, 52, 50, 12); + gg.color(LIGHTBLUE); + gg.line(67, 52, 51, 52); + gg.line(51, 52, 51, 12); } else { - gg.line(50, 56, 41, 56); - gg.line(41, 56, 50, 12); + gg.line(51, 56, 41, 56); + gg.line(41, 56, 51, 12); } - if (cell.xlut_relevant()) { + if (xlut_relevant(cell)) { gg.line(52, 12, XLUT_OUTPUT_POINT.getX(), 12); gg.line(XLUT_OUTPUT_POINT.getX(), 12, XLUT_OUTPUT_POINT.getX(), 32); } @@ -188,11 +195,10 @@ public class Gui extends ZoomingPanel implements KeyListener, MouseMotionListene } public void drawLocal() { - if (!cell.ylut_relevant() && !cell.xlut_relevant()) return; - P in = new P(HOFF, 0); - P join = new P(HOFF, CORE_OFFSET); - in = rotateOuter(in); - join = rotateInner(join); + if (!cell.ylut_relevant() && !xlut_relevant(cell)) return; + + P in = rotateOuter(new P(HOFF, 0)); + P join = rotateInner(new P(HOFF, CORE_OFFSET)); int rot = rot(); switch(rot) { case 0: case 2: @@ -203,134 +209,94 @@ public class Gui extends ZoomingPanel implements KeyListener, MouseMotionListene break; } - P xi = corner(cell.xi(), xring); - P xi2 = null; - gg.color(new Color(0xff, 0x00, 0x00)); - int xring = 4; - if (cell.xi_relevant() && cell.xlut_relevant()) + // x-input to cell + gg.color(RED); + P xi = corner(cell.xi(), SIZE, 4); + if ((cell.xlut_relevant() && cell.xi_to_xlut_relevant()) || + (cell.ylut_relevant() && cell.xi_to_ylut_relevant()) + && (cell.xi() != NONE) + ) { + P xi2 = corner(cell.xi(), SIZE + 2*BEVEL, -1).translate(-BEVEL, -BEVEL); switch(cell.xi()) { - case NW: - xi2 = new P(-BEVEL, SIZE+BEVEL); + case NW: case NE: xi = translate(xi, 0, -3); xi2 = translate(xi2, 0, -3); - gg.line(xi2, xi); break; - - case SW: - xi2 = new P(-BEVEL, -BEVEL); + case SW: case SE: xi = translate(xi, 0, 3); xi2 = translate(xi2, 0, 3); - gg.line(xi2, xi); - break; - - case NE: - xi2 = new P(SIZE+BEVEL, SIZE+BEVEL); - xi = translate(xi, 0, -3); - xi2 = translate(xi2, 0, -3); - gg.line(xi2, xi); - break; - - case SE: - xi2 = new P(SIZE+BEVEL, -BEVEL); - xi = translate(xi, 0, 3); - xi2 = translate(xi2, 0, 3); - gg.line(xi2, xi); break; } + gg.line(xi2, xi); + } - if (cell.xlut_relevant()) { - P c; - gg.color(BLUE); - if (cell.yi_to_xlut_relevant()) - route(in, rotateInner(new P(SIZE - CORE_OFFSET - CORE_SIZE/2 - CORE_SIZE / 6, 20)), 5); + if (xlut_relevant(cell)) { - gg.color(RED); if (cell.xi_to_xlut_relevant() && xi != null) route(xi, rotateInner(new P(SIZE - CORE_OFFSET - CORE_SIZE/2 - CORE_SIZE / 3, 20)), 4); - P xo = XLUT_OUTPUT_POINT; - P xout = new P(SIZE-CORE_OFFSET-CORE_SIZE+17 - 2, CORE_OFFSET + CORE_SIZE - 3); - xo = rotateInner(xo); - xout = rotateInner(xout); - gg.color(new Color(0xff, 0xcc, 0xcc)); - xring = 6; - if (cell.ne() != null && cell.ne().xi()==SW && cell.ne().xi_relevant() && cell.ne().xlut_relevant()) { - gg.line(xo, xout); - P xoo = new P(SIZE-2*xring, SIZE-2*xring); - P xoo2 = new P(SIZE, SIZE); - xoo = translate(xoo, -3, 0); - xoo2 = translate(xoo2, -3, 0); - gg.line(xoo2, xoo); - route(xout, xoo, xring); + // xlut y-input + gg.color(BLUE); + if (cell.yi_to_xlut_relevant()) + route(in, rotateInner(new P(SIZE - CORE_OFFSET - CORE_SIZE/2 - CORE_SIZE / 6, 20)), 5); + + // xlut output + int xring = 4; + gg.color(cell.xo() ? ORANGE : LIGHTRED); + P xout = rotateInner(new P(SIZE-CORE_OFFSET-CORE_SIZE+17 - 2, CORE_OFFSET + CORE_SIZE - 3)); + if (cell.xo()) { + xout = rotateInner(new P(51, 74)); + gg.line(rotateInner(new P(51, 62)), xout); + } else if (cell.xo_relevant()) { + gg.line(rotateInner(XLUT_OUTPUT_POINT), xout); } - if (cell.nw() != null && cell.nw().xi()==SE && cell.nw().xi_relevant() && cell.nw().xlut_relevant()) { - gg.line(xo, xout); - P xoo = new P(0+2*xring, SIZE-2*xring); - P xoo2 = new P(0, SIZE); - xoo = translate(xoo, 3, 0); - xoo2 = translate(xoo2, 3, 0); - gg.line(xoo2, xoo); - route(xout, xoo, xring); + if (cell.xo_relevant(NE)) { + gg.line(corner(NE, SIZE, xring).translate(0, 3), corner(NE, SIZE, 0).translate(0, 3)); + route(xout, corner(NE, SIZE, xring).translate(0, 3), xring); } - if (cell.se() != null && cell.se().xi()==NW && cell.se().xi_relevant() && cell.se().xlut_relevant()) { - gg.line(xo, xout); - P xoo = new P(SIZE-2*xring, 0+2*xring); - P xoo2 = new P(SIZE, 0); - xoo = translate(xoo, -3, 0); - xoo2 = translate(xoo2, -3, 0); - gg.line(xoo2, xoo); - route(xout, xoo, xring); + if (cell.xo_relevant(NW)) { + gg.line(corner(NW, SIZE, xring).translate(0, 3), corner(NW, SIZE, 0).translate(0, 3)); + route(xout, corner(NW, SIZE, xring).translate(0, 3), xring); } - if (cell.sw() != null && cell.sw().xi()==NE && cell.sw().xi_relevant() && cell.sw().xlut_relevant()) { - gg.line(xo, xout); - P xoo = new P(0+2*xring, 0+2*xring); - P xoo2 = new P(0, 0); - xoo = translate(xoo, 3, 0); - xoo2 = translate(xoo2, 3, 0); - gg.line(xoo2, xoo); - route(xout, xoo, xring); + if (cell.xo_relevant(SE)) { + gg.line(corner(SE, SIZE, xring).translate(0, -3), corner(SE, SIZE, 0).translate(0, -3)); + route(xout, corner(SE, SIZE, xring).translate(0, -3), xring); + } + if (cell.xo_relevant(SW)) { + gg.line(corner(SW, SIZE, xring).translate(0, -3), corner(SW, SIZE, 0).translate(0, -3)); + route(xout, corner(SW, SIZE, xring).translate(0, -3), xring); } } if (cell.ylut_relevant()) { - gg.color(new Color(0x00, 0x00, 0xff)); - P c; - if (cell.yi_to_ylut_relevant()) { - c = new P(SIZE - CORE_OFFSET - CORE_SIZE/2 + CORE_SIZE / 6, 20); - c = rotateInner(c); - route(in, c, 5); - } - gg.color(new Color(0xff, 0x00, 0x00)); - if (cell.xi_to_ylut_relevant()) { - c = rotateInner(new P(SIZE - CORE_OFFSET - CORE_SIZE/2 + CORE_SIZE / 3, 20)); - if (xi != null) - route(xi, c, 4); - } - P yo = rotateInner(YLUT_OUTPUT_POINT); + // ylut y-input + gg.color(BLUE); + if (cell.yi_to_ylut_relevant()) + route(in, rotateInner(new P(SIZE - CORE_OFFSET - CORE_SIZE/2 + CORE_SIZE / 6, 20)), 5); + + // ylut x-input + gg.color(RED); + if (xi != null && cell.xi_to_ylut_relevant()) + route(xi, rotateInner(new P(SIZE - CORE_OFFSET - CORE_SIZE/2 + CORE_SIZE / 3, 20)), 4); + + // lines directly from the ylut output to the four neighbors + gg.color(cell.yo() ? ORANGE : LIGHTBLUE); P yout = rotateInner(new P(SIZE-CORE_OFFSET-CORE_SIZE+51 - 2, CORE_OFFSET + CORE_SIZE - 3)); - gg.color(0xbbbbff); - if (cell.north() != null && cell.north().yi()==SOUTH && cell.north().yi_relevant() && cell.north().ylut_relevant()) { - gg.line(yo, yout); - route(yout, new P(SIZE-40, SIZE+ 0), 2); - } - if (cell.east() != null && cell.east().yi()==WEST && cell.east().yi_relevant() && cell.east().ylut_relevant()) { - gg.line(yo, yout); - route(yout, new P(SIZE+ 0, 40), 2); - } - if (cell.south() != null && cell.south().yi()==NORTH && cell.south().yi_relevant() && cell.south().ylut_relevant()) { - gg.line(yo, yout); - route(yout, new P( 40, 0), 2); - } - if (cell.west() != null && cell.west().yi()==EAST && cell.west().yi_relevant() && cell.west().ylut_relevant()) { - gg.line(yo, yout); - route(yout, new P( 0, SIZE-40), 2); + if (cell.yo()) { + yout = rotateInner(new P(51, 74)); + gg.line(rotateInner(new P(51, 62)), yout); + } else if (cell.yo_relevant()) { + gg.line(rotateInner(YLUT_OUTPUT_POINT), yout); } + if (cell.yo_relevant(NORTH)) route(yout, new P(SIZE-40, SIZE+ 0), 2); + if (cell.yo_relevant(EAST)) route(yout, new P(SIZE+ 0, 40), 2); + if (cell.yo_relevant(SOUTH)) route(yout, new P( 40, 0), 2); + if (cell.yo_relevant(WEST)) route(yout, new P( 0, SIZE-40), 2); } } - private AffineTransform rotateOuterTransform() { int rot = rot(); AffineTransform a = new AffineTransform(); @@ -346,6 +312,7 @@ public class Gui extends ZoomingPanel implements KeyListener, MouseMotionListene private P rotateOuter(P p) { return p.transform(rotateOuterTransform()); } private P rotateInner(P p) { return p.transform(rotateInnerTransform()); } + private P unRotateInner(P p) { return p.inverseTransform(rotateInnerTransform()); } private AffineTransform rotateInnerTransform() { int rot = rot(); @@ -385,27 +352,21 @@ public class Gui extends ZoomingPanel implements KeyListener, MouseMotionListene gg.line(p2, projected); p2 = projected; - double x1 = p1.getX(); - double y1 = p1.getY(); - double x2 = p2.getX(); - double y2 = p2.getY(); - - if (x1==x2 || y1==y2) { + if (p1.x==p2.x || p1.y==p2.y) { gg.line(p1, p2); return; } - if ((x1==SIZE-ring*2 || x1==ring*2) && !(y1==SIZE-ring*2 || y1==ring*2)) { - P p3 = new P(x1, y2 > SIZE/2 ? SIZE-ring*2 : ring*2); + if ((p1.x==SIZE-ring*2 || p1.x==ring*2) && !(p1.y==SIZE-ring*2 || p1.y==ring*2)) { + P p3 = new P(p1.x, p2.y > SIZE/2 ? SIZE-ring*2 : ring*2); gg.line(p1, p3); route(p3, p2, ring); - } else if ((y1==SIZE-ring*2 || y1==ring*2) && !(x1==SIZE-ring*2 || x1==ring*2)) { - P p3 = new P(x2 > SIZE/2 ? SIZE-ring*2 : ring*2, y1); + } else if ((p1.y==SIZE-ring*2 || p1.y==ring*2) && !(p1.x==SIZE-ring*2 || p1.x==ring*2)) { + P p3 = new P(p2.x > SIZE/2 ? SIZE-ring*2 : ring*2, p1.y); gg.line(p1, p3); route(p3, p2, ring); } else route(p2, p1, ring); - } private int rot() { @@ -442,34 +403,20 @@ public class Gui extends ZoomingPanel implements KeyListener, MouseMotionListene //gg.color(Color.gray); //g.drawRect(0, 0, CORE_SIZE, CORE_SIZE); - g.scale(1, -1); + //g.scale(1, -1); - GeneralPath p = new GeneralPath(); - p.moveTo(29.141f, 36.301f); - p.lineTo(29.141f, 36.301f-7.161f); - p.curveTo(27.71f, 11.24f, 23.413f, 9.45f, 14.82f, 0.5f); - p.curveTo(6.229f, 9.45f, 1.932f, 11.24f, 0.5f, 29.141f); - p.lineTo(0.5f, 29.141f+7.161f); - float x = 0.5f; - float y = 29.141f+7.161f; - p.curveTo(5.729f+x, -1.789f+y, - 6.444f+x, -2.686f+y, - 14.32f+x, -3.58f+y); - p.curveTo(22.697f, 33.616f, 23.413f, 34.512f, 29.141f, 36.301f); - g.translate(0, -40f); - if (cell.xlut_relevant()) { - gg.color(Color.white); - g.fill(p); - gg.color(Color.red); - g.draw(p); - } + Gate gate = new Muller(); + + g.translate(2, 5f); + if (xlut_relevant(cell)) + gate.draw(g, + !xknown ? Color.gray : xon ? Color.red : Color.white, + (xon && xknown) ? Color.white : Color.red); g.translate(34f, 0f); - if (cell.ylut_relevant()) { - gg.color(Color.white); - g.fill(p); - gg.color(Color.blue); - g.draw(p); - } + if (cell.ylut_relevant()) + gate.draw(g, + !yknown ? Color.gray : yon ? Color.blue : Color.white, + (yon && yknown) ? Color.white : Color.blue); } finally { g.setTransform(t); } @@ -477,45 +424,91 @@ public class Gui extends ZoomingPanel implements KeyListener, MouseMotionListene public void drawMux() { if (!cell.c_relevant()) return; gg.color(Color.black); - if (cell.xlut_relevant() && (cell.c() == ZMUX || cell.c() == XLUT)) { - gg.color(new Color(0xff, 0xbb, 0xbb)); + if (xlut_relevant(cell) && (cell.c() == ZMUX || cell.c() == XLUT)) { + gg.color(LIGHTRED); gg.line(XLUT_OUTPUT_POINT, new P(XLUT_OUTPUT_POINT.getX(), 52)); gg.line(new P(XLUT_OUTPUT_POINT.getX(), 52), new P(51, 52)); } if (cell.ylut_relevant() && (cell.c() == ZMUX || cell.c() == YLUT)) { - gg.color(new Color(0xbb, 0xbb, 0xff)); + gg.color(LIGHTBLUE); gg.line(YLUT_OUTPUT_POINT, new P(YLUT_OUTPUT_POINT.getX(), 52)); gg.line(new P(YLUT_OUTPUT_POINT.getX(), 52), new P(51, 52)); } - gg.line(51, 52, 51, 51+25); + if (cell.c() == ZMUX) + gg.color(ORANGE); + + gg.line(51, 52, 51, 51+23); + + if (cell.register_relevant() && cell.f() && !cell.b()) { + gg.line(51, 56, 60, 56); + gg.line(60, 56, 60, 51+25); + } else { + gg.line(51, 51+23, 51, 51+25); + } + if (cell.c() == ZMUX) { - gg.color(Color.black); - gg.line(51, 52, 51, 51+25); - gg.line(46, 54, 46+2, 54+5); - gg.line(46+2, 54+5, 60-2, 54+5); - gg.line(60-2, 54+5, 60, 54); - gg.line(60, 54, 46, 54); + + gg.color(GREEN); + int plane = cell.zi()+1; + route(unRotateInner(new P(8 + 2*(plane-L0), 76 + 2*(plane-L0))), + new P(51, 20), + 3); + gg.line(new P(51, 20), new P(51, 50)); + + GeneralPath p = new GeneralPath(); + p.moveTo(45, 50); + p.lineTo(47, 54); + p.lineTo(56, 54); + p.lineTo(58, 50); + p.lineTo(45, 50); + gg.color(WHITE); + gg.g.fill(p); + + gg.color(ORANGE); + gg.g.draw(p); + + } + } + public int ccolor() { + switch(cell.c()) { + case XLUT: return LIGHTRED; + case YLUT: return LIGHTBLUE; + case ZMUX: return ORANGE; } + return BLACK; } public void drawRegister() { if (!cell.register_relevant()) return; + + int dark = ccolor(); gg.color(Color.white); - g.fillRect(48, 58, 10, 14); - gg.color(Color.black); - g.drawRect(48, 58, 10, 14); - gg.line(57, 70, 54, 68); - gg.line(54, 68, 57, 66); + g.fillRect(47, 58, 9, 14); + gg.color(dark); + g.drawRect(47, 58, 9, 14); + + GeneralPath p = new GeneralPath(); + p.moveTo(56, 70); + p.lineTo(53, 68); + p.lineTo(56, 66); + p.lineTo(56, 70); + gg.color(cell.ff_reset_value() ? WHITE : dark); + g.fill(p); + gg.color(dark); + g.draw(p); } public void drawBorder() { gg.color(Color.gray); - //gg.line(0, BEVEL, BEVEL, 0); gg.line(BEVEL, 0, SIZE-BEVEL, 0); - //gg.line(SIZE-BEVEL, 0, SIZE, BEVEL); gg.line(SIZE, BEVEL, SIZE, SIZE-BEVEL); - //gg.line(SIZE, SIZE-BEVEL, SIZE-BEVEL, SIZE); gg.line(SIZE-BEVEL, SIZE, BEVEL, SIZE); - //gg.line(BEVEL, SIZE, 0, SIZE-BEVEL); gg.line(0, SIZE-BEVEL, 0, BEVEL); + /* + gg.color(0xdddddd); + gg.line(0, BEVEL, BEVEL, 0); + gg.line(SIZE-BEVEL, 0, SIZE, BEVEL); + gg.line(SIZE, SIZE-BEVEL, SIZE-BEVEL, SIZE); + gg.line(BEVEL, SIZE, 0, SIZE-BEVEL); + */ } } @@ -531,7 +524,12 @@ public class Gui extends ZoomingPanel implements KeyListener, MouseMotionListene AffineTransform t = g.getTransform(); for(Cell c : cells) { g.setTransform(t); - g.translate( c._x * SIZE/* + (10 * (c._x/4))*/, c._y * SIZE/* + (10 * (c._y/4))*/); + g.translate( c._x * SIZE /*+ (10 * (c._x/4))*/, c._y * SIZE /*+ (10 * (c._y/4))*/); + c.clear(); + } + for(Cell c : cells) { + g.setTransform(t); + g.translate( c._x * SIZE /*+ (10 * (c._x/4))*/, c._y * SIZE /*+ (10 * (c._y/4))*/); c.draw(); } g.setTransform(t); @@ -539,18 +537,19 @@ public class Gui extends ZoomingPanel implements KeyListener, MouseMotionListene g.setTransform(new AffineTransform()); gg.color(selectedcell); - g.fillRect(getWidth() - 200, 0, 200, 100); + g.fillRect(getWidth() - 200, 0, 200, 600); gg.color(Color.white); - g.drawRect(getWidth() - 200, 0, 200, 100); + g.drawRect(getWidth() - 200, 0, 200, 600); Cell newcell = whichCell(mousex, mousey); int line = 10; + g.setFont(new Font("monospaced", 0, 14)); if (newcell != null && newcell.cell != null) { g.drawString("selected: " + newcell._x + ","+newcell._y, getWidth() - 200 + 10, (line += 15)); - g.drawString(" xlut: " + AtmelSerial.bin8(newcell.cell.xlut()), + g.drawString(" xlut: " + XLUT_EQUATIONS[newcell.cell.xlut() & 0xff], getWidth() - 200 + 10, (line += 15)); - g.drawString(" ylut: " + AtmelSerial.bin8(newcell.cell.ylut()), + g.drawString(" ylut: " + YLUT_EQUATIONS[newcell.cell.ylut() & 0xff], getWidth() - 200 + 10, (line += 15)); String xi = "??"; switch(newcell.cell.xi()) { @@ -558,16 +557,55 @@ public class Gui extends ZoomingPanel implements KeyListener, MouseMotionListene case NE : xi = "NE"; break; case SW : xi = "SW"; break; case SE : xi = "SE"; break; + case NONE : xi = "."; break; + default: xi = "L"+(newcell.cell.xi()-L0); break; } g.drawString(" xi: " + xi, getWidth() - 200 + 10, (line += 15)); + String yi = "??"; switch(newcell.cell.yi()) { case NORTH : yi = "NORTH"; break; case SOUTH : yi = "SOUTH"; break; case EAST : yi = "EAST"; break; case WEST : yi = "WEST"; break; + case NONE : yi = "."; break; + default: yi = "L"+(newcell.cell.yi()-L0); break; } g.drawString(" yi: " + yi, getWidth() - 200 + 10, (line += 15)); + + g.drawString(" wi: " + (newcell.cell.wi()==NONE ? "." : ("L"+(newcell.cell.wi()-L0))), + getWidth() - 200 + 10, (line += 15)); + g.drawString(" zi: " + (newcell.cell.zi()==NONE ? "." : ("L"+(newcell.cell.zi()-L0))), + getWidth() - 200 + 10, (line += 15)); + + g.drawString(" FF: " + (newcell.cell.ff_reset_value() ? "reset=SET" : "."), + getWidth() - 200 + 10, (line += 15)); + + String outs = ""; + for(int i=0; i<5; i++) outs += (newcell.cell.out(L0+i) ? (i+" ") : ". "); + g.drawString(" out: " + outs, + getWidth() - 200 + 10, (line += 15)); + String hs = ""; + for(int i=0; i<5; i++) hs += (newcell.cell.hx(L0+i) ? (i+" ") : ". "); + g.drawString(" H: " + hs, + getWidth() - 200 + 10, (line += 15)); + String vs = ""; + for(int i=0; i<5; i++) vs += (newcell.cell.vx(L0+i) ? (i+" ") : ". "); + g.drawString(" V: " + vs, + getWidth() - 200 + 10, (line += 15)); + g.drawString(" OE: " + (newcell.cell.oe()==H4 ? "H4" : newcell.cell.oe()==V4 ? "V4" : "."), + getWidth() - 200 + 10, (line += 15)); + g.drawString(" center: " + (newcell.cell.c()==ZMUX ? "zmux" : newcell.cell.c()==XLUT ? "x-lut" : "y-lut"), + getWidth() - 200 + 10, (line += 15)); + g.drawString(" fb/out: " + (newcell.cell.f() ? "clocked" : "."), + getWidth() - 200 + 10, (line += 15)); + g.drawString(" bypass: " + (newcell.cell.b() ? "clocked" : "."), + getWidth() - 200 + 10, (line += 15)); + g.drawString(" x out: " + (newcell.cell.xo() ? (newcell.cell.b() ? "register" : "center") : "."), + getWidth() - 200 + 10, (line += 15)); + g.drawString(" y out: " + (newcell.cell.yo() ? (newcell.cell.b() ? "register" : "center") : "."), + getWidth() - 200 + 10, (line += 15)); + } this.g = null; this.gg = null; @@ -592,11 +630,241 @@ public class Gui extends ZoomingPanel implements KeyListener, MouseMotionListene } catch (Exception e) { e.printStackTrace(); } - int col = ((int)p.getX()) / (SIZE + BEVEL); - int row = ((int)p.getY()) / (SIZE + BEVEL); + int col = ((int)p.getX()+0) / SIZE; + int row = ((int)p.getY()+0) / SIZE; for(Cell c : cells) if (c._x == col && c._y == row) return c; return null; } + + public static boolean xlut_relevant(At40k.Cell c) { + return c.xlut_relevant(); + } + + public void mouseClicked(MouseEvent e) { + System.out.println("click"); + final Cell c = whichCell(e.getX(), e.getY()); + if (c==null) return; + System.out.println("click at " + c._x + "," + c._y); + scan(c); + } + + public void scan() { + for(int x=0; x cells = new HashSet(); + public abstract void scan(final Gui.Cell c); + public abstract void scan(); + public abstract void writeMode4(); + public abstract void readMode4(); } -- 1.7.10.4