X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fslipway%2Fgui%2FGui.java;h=829479fd256c70eb1f46d2bd74ff753d93e7b235;hb=05bfa73d5415e19943cf36c094dbdb50304a341c;hp=37bfaf54248095f42c98d1d6bb0eb8ca6699b551;hpb=57f6ad104a6e2bf0433a86f5c8e1f31c1715dab9;p=slipway.git diff --git a/src/edu/berkeley/slipway/gui/Gui.java b/src/edu/berkeley/slipway/gui/Gui.java index 37bfaf5..829479f 100644 --- a/src/edu/berkeley/slipway/gui/Gui.java +++ b/src/edu/berkeley/slipway/gui/Gui.java @@ -56,15 +56,30 @@ public class Gui extends ZoomingPanel implements KeyListener, MouseMotionListene } public Gui(Fpslic at40k, FtdiBoard drone) { + this(at40k, drone, 24, 24); + } + public Gui(Fpslic at40k, FtdiBoard drone, int width, int height) { + super(drone); this.at40k = at40k; this.drone = drone; for(int i=0; i (12 & ~0x3) && sw.north()!=null && sw.north().drives(sw)) + sw.north().drives(sw, false); + while(sw.row > (12 & ~0x3) && sw.south() != null) { + //System.out.println(sw + " -> " + sw.south()); + if (sw.drives(sw.south())!=setup) sw.drives(sw.south(), setup); + sw = sw.south(); + } + if (sw.row < (12 & ~0x3) && sw.south() != null && sw.south().drives(sw)) + sw.north().drives(sw, false); + while(sw.row < (12 & ~0x3) && sw.north() != null) { + //System.out.println(sw + " -> " + sw.north()); + if (sw.drives(sw.north())!=setup) sw.drives(sw.north(), setup); + sw = sw.north(); + } + + //cell = dev.cell(19, 15); + cell = dev.cell(cell.col, 15); + /* + System.out.println("cell is " + cell); + cell.xlut(0xff); + cell.ylut(0xff); + cell.b(false); + cell.f(false); + cell.c(XLUT); + cell.out(L3, true); + cell.oe(NONE); + */ + if (cell.hx(L3) != setup) cell.h(L3, setup); + if (cell.vx(L3) != setup) cell.v(L3, setup); + sw = cell.hwire(L3); + + if (sw.west()!=null && sw.west().drives(sw)) { sw.west().drives(sw, false); } + while(sw.east() != null) { + //System.out.println(sw + " -> " + sw.east()); + if (sw.drives(sw.east())!=setup) sw.drives(sw.east(), setup); + sw = sw.east(); + } + + } + int made = 0; private class BCB extends FtdiBoard.ByteCallback { @@ -761,13 +933,9 @@ public class Gui extends ZoomingPanel implements KeyListener, MouseMotionListene public BCB(Gui.Cell c, int who) { this.who = who; this.c = c; made++; - System.out.println("made="+made); } 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; @@ -781,11 +949,31 @@ public class Gui extends ZoomingPanel implements KeyListener, MouseMotionListene break; } made--; - System.out.println("made="+made); - if (made==0) scan(); } } + public Gate getGate(byte lut, boolean xlut) { + for(Gate g : knownGates) + if (g.setLut(lut, xlut)) + return g; + return unknownGate; + } + + public Gate unknownGate = new Circle("?"); + public Gate[] knownGates = + new Gate[] { + new And(), + new Or(), + new Circle("0") { public boolean result(boolean x, boolean y, boolean z) { return false; } }, + new Circle("1") { public boolean result(boolean x, boolean y, boolean z) { return true; } }, + new Circle("x") { public boolean result(boolean x, boolean y, boolean z) { return x; } }, + new Circle("y") { public boolean result(boolean x, boolean y, boolean z) { return y; } }, + new Circle("z") { public boolean result(boolean x, boolean y, boolean z) { return z; } }, + new Circle("~x") { public boolean result(boolean x, boolean y, boolean z) { return !x; } }, + new Circle("~y") { public boolean result(boolean x, boolean y, boolean z) { return !y; } }, + new Circle("~z") { public boolean result(boolean x, boolean y, boolean z) { return !z; } } + }; + // FIXME: 2-input gates? public abstract class Gate { public boolean invert_x; @@ -793,7 +981,7 @@ public class Gui extends ZoomingPanel implements KeyListener, MouseMotionListene 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) { + public void draw(Graphics2D g, Color fill, Color stroke, Color text) { GeneralPath p = new GeneralPath(); makePath(p); g.setColor(fill); @@ -803,28 +991,36 @@ public class Gui extends ZoomingPanel implements KeyListener, MouseMotionListene AffineTransform a = g.getTransform(); g.scale(1, -1); - g.setColor(Color.white); - if (label() != null) g.drawString(label(), 7, -14); + if (label() != null) { + g.setColor(text); + g.drawString(label(), 7, -14); + } g.setTransform(a); } public String label() { return null; } - public boolean setLut(int lut) { + public boolean setLut(int lut, boolean xlut) { + /* 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; + */ + boolean good = true; for(int bit=0; bit<8; bit++) { - boolean x = (bit & 0x1) != 0; - boolean y = (bit & 0x2) != 0; + boolean x = xlut ? ((bit & 0x1) != 0) : ((bit & 0x2) != 0); + boolean y = xlut ? ((bit & 0x2) != 0) : ((bit & 0x1) != 0); boolean z = (bit & 0x4) != 0; boolean expect = (lut & (1<