public final int col;
public final int row;
+ public Cell(int col, int row) {
+ this.row = row;
+ this.col = col;
+ }
+
+ // Accessors for Neighbors //////////////////////////////////////////////////////////////////////////////
+
public SectorWire hwire(int plane) { return new SectorWire(true, plane, col, row); }
public SectorWire vwire(int plane) { return new SectorWire(false, plane, col, row); }
public Cell east() { return cell(col+1, row); }
public Cell nw() { return cell(col-1, row+1); }
public Cell se() { return cell(col+1, row-1); }
public Cell sw() { return cell(col-1, row-1); }
-
public Sector sector() { return new Sector(this); }
- public Cell(int col, int row) {
- this.row = row;
- this.col = col;
- }
/* bit positions mean: [MSB] zxy z_y zx_ z__ _xy __y _x_ ___ [LSB] */
public void lut(int xlut, int ylut) { xlut(xlut); ylut(ylut); }
public void ff_reset_value(boolean value) {
//dev.mode4( /* FIXME WRONG!!! */, row, col, 3, !value); return;
}
+ /** FIXME!!! */
+ public boolean ff_reset_value() { return false; }
+ public boolean columnClocked() {
+ return false;
+ }
public void out(int plane, boolean enable) {
switch(plane) {
}
dev.mode4(1, row, col, result, 0x34);
}
+ /*
+ private void fmux(int source) {
+ switch(source) {
+ case ZMUX:
+ case FB:
+ case ALWAYS_ON:
+ default: throw new Error("unknown argument to fmux()");
+ }
+ }
+
+ public boolean win_easable() {
+ }
+ */
public int t() {
return dev.mode4(1, row, col) & 0x34;
}
public void t(boolean ignore_z_and_fb, boolean zm_drives_fb, boolean fb_drives_wm) {
// still not totally satisfied...
- // how to we distinguish between z&w vs z or w&fb vs fb? ==> 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;
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) {
}
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; }
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();
}
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();
}
}
}
+
public void zi(int source) {
switch(source) {
case L4: dev.mode4(0x02, row, col, 1<<7, 0xDB); break;
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); }
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<Cell> cells = new HashSet<Cell>();
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<ca.length; i++)
ca[i] = new Cell[128];
- for(int x=0; x<7; x++)
- for(int y=0; y<7; y++)
- new Cell(x,y, at40k.cell(x+7, y+7));
+ for(int x=7; x<17; x++)
+ for(int y=7; y<17; y++)
+ new Cell(x-7,y-7, at40k.cell(x, y));
+ /*
+ At40k.Cell c = at40k.cell(0,0);
+ for(int i=0; i<256; i++) {
+ c.ylut(i);
+ System.out.println(c.printYLut());
+ }
+ */
}
-
public class Cell {
At40k.Cell cell;
boolean in = false;
+ public boolean xon = false;
+ public boolean yon = false;
+ public boolean xknown = false;
+ public boolean yknown = false;
int _x, _y;
public Cell(int x, int y, At40k.Cell cell) {
_x = x;
this.cell = cell;
cells.add(this);
}
- public void draw() {
+ public void clear() {
gg.color(in ? selectedcell : nonselectedcell);
g.fillRect(0, 0, SIZE, SIZE);
+ }
+ public void draw() {
- drawHwires();
- drawVwires();
+ drawWires();
drawLocal();
AffineTransform t = g.getTransform();
+
+ drawBuffer();
g.transform(rotateInnerTransform());
drawMux();
drawRegister();
drawInternalRouting();
- drawBuffer();
g.setTransform(t);
drawGates();
drawBorder();
}
public void drawBuffer() {
+ /*
if (!cell.out_relevant()) return;
- gg.color(Color.black);
- gg.line(21, 64, 28, 60);
- gg.line(21, 64, 28, 68);
- gg.line(28, 60, 28, 68);
+
+ GeneralPath p = new GeneralPath();
+ p.moveTo(24, 61);
+ p.lineTo(22, 68);
+ p.lineTo(29, 66);
+ p.lineTo(24, 61);
+ gg.color(cell.oe() == NONE ? Color.white : Color.green);
+ g.fill(p);
+ gg.color(Color.green);
+ g.draw(p);
gg.color(Color.magenta);
if (cell.oe() == V4) {
- gg.line(16, 53, 25, 53);
- gg.line(25, 53, 25, 62);
+ gg.line(24, 62, 16, 63);
} else if (cell.oe() == H4) {
- gg.line(25, 76, 25, 67);
+ gg.line(24, 67, 24, 76);
}
-
+ */
}
- public void drawHwires() {
- gg.color(Color.magenta);
+ public void drawWires() {
+ gg.color(MAGENTA);
for(int i=0; i<5; i++)
- if (cell.hwire(i).isDriven())
+ if (cell.hwire(i).isDriven()) {
+ gg.color(cell.out(i) ? ORANGE : MAGENTA);
gg.line(0, SIZE-(2*(1+RINGS)+2*i), SIZE, SIZE-(2*(1+RINGS)+2*i));
- int plane = cell.zi();
- 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 = 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);
}
}
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:
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();
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();
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() {
//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);
}
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);
+ */
}
}
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);
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()) {
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;
} 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<ca.length; x++)
+ for(int y=0; y<ca[x].length; y++)
+ if (ca[x][y] != null)
+ scan(ca[x][y]);
+ }
+ public void scan(final Gui.Cell c) {
+ final At40k.Cell cell = c.cell;
+ AtmelSerial.scan(at40k, cell, NONE, true);
+ boolean safe = !cell.fb_relevant();
+ if (cell.xo()) safe = false;
+ if (cell.yo()) safe = false;
+ for(int i=0; i<5; i++)
+ if (cell.out(i))
+ safe = false;
+ if (safe) {
+ int oldc = cell.c();
+ if (cell.xlut_relevant()) {
+ cell.c(XLUT);
+ drone.readBus(new BCB(c, XLUT));
+ }
+ if (cell.ylut_relevant()) {
+ cell.c(YLUT);
+ drone.readBus(new BCB(c, YLUT));
+ }
+ cell.c(oldc);
+ } else {
+ switch(cell.c()) {
+ case XLUT: if (cell.xlut_relevant()) drone.readBus(new BCB(c, XLUT)); break;
+ case YLUT: if (cell.ylut_relevant()) drone.readBus(new BCB(c, YLUT)); break;
+ }
+
+ }
+ AtmelSerial.scan(at40k, cell, NONE, false);
+ }
+
+ private class BCB implements AvrDrone.ByteCallback {
+ Gui.Cell c;
+ int who;
+ public BCB(Gui.Cell c, int who) { this.who = who; this.c = c; }
+ public void call(byte b) throws Exception {
+ System.out.println("callback: " + b);
+ boolean on = (b & 0x80) != 0;
+ c.xknown = false;
+ c.yknown = false;
+ switch(who) {
+ case YLUT:
+ c.yknown = true;
+ c.yon = on;
+ repaint();
+ break;
+ case XLUT:
+ c.xknown = true;
+ c.xon = on;
+ repaint();
+ break;
+ }
+ }
+ }
+
+ // FIXME: 2-input gates?
+ public abstract class Gate {
+ public boolean invert_x;
+ public boolean invert_y;
+ public boolean invert_z;
+ public boolean invert_out;
+ public abstract boolean result(boolean x, boolean y, boolean z);
+ public void draw(Graphics2D g, Color fill, Color stroke) {
+ GeneralPath p = new GeneralPath();
+ makePath(p);
+ g.setColor(fill);
+ g.fill(p);
+ g.setColor(stroke);
+ g.draw(p);
+
+ AffineTransform a = g.getTransform();
+ g.scale(1, -1);
+ g.setColor(Color.white);
+ if (label() != null) g.drawString(label(), 7, -14);
+ g.setTransform(a);
+ }
+ public String label() { return null; }
+ public boolean setLut(int lut) {
+ for(int inverts = 0; inverts < 16; inverts++) {
+ invert_x = (inverts & 0x1) != 0;
+ invert_y = (inverts & 0x2) != 0;
+ invert_z = (inverts & 0x4) != 0;
+ invert_out = (inverts & 0x8) != 0;
+ for(int bit=0; bit<8; bit++) {
+ boolean x = (bit & 0x1) != 0;
+ boolean y = (bit & 0x2) != 0;
+ boolean z = (bit & 0x4) != 0;
+ boolean expect = (lut & (1<<bit)) != 0;
+
+ // FIXME symmetry issues here....
+ boolean result = result(x ^ invert_x, y ^ invert_y, z ^ invert_z) ^ invert_out;
+ if (result == expect) return true;
+ }
+ }
+ return false;
+ }
+ public abstract void makePath(GeneralPath gp);
+ }
+
+ public class Or extends Gate {
+ public boolean result(boolean x, boolean y, boolean z) { return x || y || z; }
+ public String label() { return "+"; }
+ public void draw(Graphics2D g, Color fill, Color stroke) {
+ AffineTransform at = g.getTransform();
+ g.scale(1, -1);
+ g.translate(0, -40);
+ super.draw(g, fill, stroke);
+ g.setTransform(at);
+ }
+ public void makePath(GeneralPath gp) {
+ gp.moveTo(29.141f, 36.301f);
+ gp.lineTo(29.141f, 36.301f-7.161f);
+ gp.curveTo(27.71f, 11.24f, 23.413f, 9.45f, 14.82f, 0.5f);
+ gp.curveTo(6.229f, 9.45f, 1.932f, 11.24f, 0.5f, 29.141f);
+ gp.lineTo(0.5f, 29.141f+7.161f);
+ float x = 0.5f;
+ float y = 29.141f+7.161f;
+ gp.curveTo(5.729f+x, -1.789f+y,
+ 6.444f+x, -2.686f+y,
+ 14.32f+x, -3.58f+y);
+ gp.curveTo(22.697f, 33.616f, 23.413f, 34.512f, 29.141f, 36.301f);
+ }
+ }
+
+ public class And extends Gate {
+ public boolean result(boolean x, boolean y, boolean z) { return x && y && z; }
+ public String label() { return "&"; }
+ public void makePath(GeneralPath gp) {
+ gp.moveTo(0, 2);
+ gp.lineTo(0, 19);
+ gp.curveTo(0, 27, 3, 35, 13, 35);
+ gp.curveTo(20, 35, 23, 27, 23, 19);
+ gp.lineTo(23, 2);
+ gp.closePath();
+ }
+ }
+
+ public class Muller extends And {
+ public String label() { return "C"; }
+ public void draw(Graphics2D g, Color fill, Color stroke) {
+ super.draw(g, fill, stroke);
+ g.setColor(stroke);
+ g.drawLine(0, 0, 23, 0);
+ }
+ }
+
+ public class Xor extends Or {
+ public boolean result(boolean x, boolean y, boolean z) { return x ^ y ^ z; }
+ public String label() { return "^"; }
+ public void draw(Graphics2D g, Color fill, Color stroke) {
+ super.draw(g, fill, stroke);
+ g.setColor(stroke);
+ AffineTransform at = g.getTransform();
+ g.scale(1, -1);
+ g.translate(0, -40);
+
+ g.translate(0, 4);
+ GeneralPath gp = new GeneralPath();
+ float x = 0.5f;
+ float y = 29.141f+7.161f;
+ gp.moveTo(x,y);
+ gp.curveTo(5.729f+x, -1.789f+y,
+ 6.444f+x, -2.686f+y,
+ 14.32f+x, -3.58f+y);
+ gp.curveTo(22.697f, 33.616f, 23.413f, 34.512f, 29.141f, 36.301f);
+ g.draw(gp);
+
+ g.setTransform(at);
+ }
+ }
+
+ public abstract class Mux extends Gate {
+ public String label() { return "?"; }
+ public void makePath(GeneralPath gp) {
+ gp.moveTo(0, 15);
+ gp.lineTo(2, 23);
+ gp.lineTo(23, 23);
+ gp.lineTo(25, 15);
+ gp.lineTo(0, 15);
+ }
+ }
+
+ public class X_Mux extends Mux {
+ public boolean result(boolean x, boolean y, boolean z) { return x ? y : z; }
+ }
+ public class Y_Mux extends Mux {
+ public boolean result(boolean x, boolean y, boolean z) { return y ? x : z; }
+ }
+ public class Z_Mux extends Mux {
+ public boolean result(boolean x, boolean y, boolean z) { return z ? x : y; }
+ }
+
+
+ public abstract class Buf extends Gate {
+ public void makePath(GeneralPath gp) {
+ gp.moveTo(0, 15);
+ gp.lineTo(13, 35);
+ gp.lineTo(25, 15);
+ gp.lineTo(0, 15);
+ }
+ }
+
+ public class X extends Buf {
+ public boolean result(boolean x, boolean y, boolean z) { return x; }
+ }
+ public class Y extends Buf {
+ public boolean result(boolean x, boolean y, boolean z) { return y; }
+ }
+ public class Z extends Buf {
+ public boolean result(boolean x, boolean y, boolean z) { return z; }
+ }
+
}