From: adam Date: Wed, 26 Jul 2006 10:00:25 +0000 (+0100) Subject: checkpoint X-Git-Tag: mpar_demo_release~111 X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=c81e9648d49cfd68568db00d8f6e3c2437ecb9d5;p=slipway.git checkpoint --- diff --git a/src/edu/berkeley/obits/device/atmel/At40k.java b/src/edu/berkeley/obits/device/atmel/At40k.java index e36e863..58116a0 100644 --- a/src/edu/berkeley/obits/device/atmel/At40k.java +++ b/src/edu/berkeley/obits/device/atmel/At40k.java @@ -172,7 +172,7 @@ public class At40k { public void xlut(int table) { dev.mode4(7, row, col, (byte)(table & 0xff)); } public byte xlut() { return (byte)(dev.mode4(7, row, col) & 0xff); } public String printXLut() { return printLut(xlut(), "x", "y", "t"); } - public String printXLutX() { return printLut(xlut(), str(xi(), "x"), str(yi(), "y"), str(ti(), "t")); } + public String printXLutX() { return printLut(xlut(), str(xi(), "x"), str(yi(), "y"), str(ti_source(), "t")); } public String str(int x, String def) { switch(x) { @@ -198,7 +198,7 @@ public class At40k { public void ylut(int table) { dev.mode4(6, row, col, (byte)(table & 0xff)); } public byte ylut() { return (byte)(dev.mode4(6, row, col) & 0xff); } public String printYLut() { return printLut(ylut(), "y", "x", "t"); } - public String printYLutX() { return printLut(ylut(), str(yi(), "y"), str(xi(), "x"), str(ti(), "t")) + Integer.toString(ylut() & 0xff, 16); } + public String printYLutX() { return printLut(ylut(), str(yi(), "y"), str(xi(), "x"), str(ti_source(), "t")) + Integer.toString(ylut() & 0xff, 16); } public void ff_reset_value(boolean value) { //dev.mode4( /* FIXME WRONG!!! */, row, col, 3, !value); return; @@ -275,7 +275,8 @@ public class At40k { } } - public int ti() { + + public int ti_source() { switch(dev.mode4(1, row, col) & 0x30) { case 0x20: return zi(); case 0x10: return FB; @@ -283,15 +284,30 @@ public class At40k { default: throw new Error("ack!"); } } + + public int t() { + System.err.println("found " + (dev.mode4(1, row, col) & 0x34)); + switch(dev.mode4(1, row, col) & 0x34) { + case 0x20: return TMUX_Z; + case 0x24: return TMUX_W_AND_Z; + case 0x34: return TMUX_FB; + case 0x14: return TMUX_W_AND_FB; + case 0x00: return TMUX_W; + //default: throw new RuntimeException("unknown!"); + default: return TMUX_W; + } + } + public void t(int code) { int result = 0; switch(code) { - case TMUX_Z: throw new Error("not implemented, but should be possible"); - case TMUX_W_AND_Z: result = 0x20; break; - - case TMUX_FB: result = 0x34; break; /* I think this is actually W_AND_FB, sadly */ + case TMUX_Z: result = 0x20; break; // TOTALLYBOGUS throw new Error("not implemented, but should be possible"); + case TMUX_W_AND_Z: result = 0x24; break; + case TMUX_FB: result = 0x34; break; /* I think this is actually W_AND_FB, sadly */ case TMUX_W_AND_FB: result = 0x14; break; - case TMUX_W: result = 0x00; break; + case TMUX_W: result = 0x00; break; + //default: throw new RuntimeException("unknown code! " + code); + default: result = 0x00; break; } dev.mode4(1, row, col, result, 0x34); } @@ -308,9 +324,11 @@ public class At40k { public boolean win_easable() { } */ - public int t() { + + public int ti() { 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... // need to find the bit that sets the w-mux off @@ -410,6 +428,7 @@ public class At40k { case L2: dev.mode4(0x03, row, col, 4, false); dev.mode4(0x05, row, col, 1<<1); break; case L1: dev.mode4(0x03, row, col, 4, false); dev.mode4(0x05, row, col, 1<<2); break; case L0: dev.mode4(0x03, row, col, 4, false); dev.mode4(0x05, row, col, 1<<3); break; + case NONE: dev.mode4(0x03, row, col, 4, false); dev.mode4(0x05, row, col, 0); break; default: throw new RuntimeException("invalid argument"); } } @@ -441,6 +460,7 @@ public class At40k { case L2: dev.mode4(0x02, row, col, 6, false); dev.mode4(0x04, row, col, 1<<1); break; case L1: dev.mode4(0x02, row, col, 6, false); dev.mode4(0x04, row, col, 1<<2); break; case L0: dev.mode4(0x02, row, col, 6, false); dev.mode4(0x04, row, col, 1<<3); break; + case NONE: dev.mode4(0x02, row, col, 6, false); dev.mode4(0x04, row, col, 0); break; default: throw new RuntimeException("invalid argument"); } } @@ -452,6 +472,7 @@ public class At40k { case L2: dev.mode4(0x03, row, col, 1<<7, 0xEC); break; case L1: dev.mode4(0x03, row, col, 1<<3, 0xEC); break; case L0: dev.mode4(0x03, row, col, 1<<2, 0xEC); break; + case NONE: dev.mode4(0x03, row, col, 0, 0xEC); break; default: throw new RuntimeException("invalid argument"); } } @@ -478,6 +499,7 @@ public class At40k { case L2: dev.mode4(0x02, row, col, 1<<4, 0xDB); break; case L1: dev.mode4(0x02, row, col, 1<<3, 0xDB); break; case L0: dev.mode4(0x02, row, col, 1<<2, 0xDB); break; + case NONE: dev.mode4(0x02, row, col, 0, 0xDB); break; default: throw new RuntimeException("invalid argument"); } } @@ -538,7 +560,7 @@ public class At40k { return yo_relevant(); } public boolean c_relevant() { - switch(t()) { + switch(ti()) { case 0x34: return true; case 0x14: return true; case 0x10: return true; @@ -572,7 +594,7 @@ public class At40k { public boolean fb_relevant() { if (!(zi_to_xlut_relevant()) || !(zi_to_ylut_relevant())) return false; - switch(t()) { + switch(ti()) { case 0x34: return true; case 0x14: return true; case 0x10: return true; diff --git a/src/edu/berkeley/obits/gui/G.java b/src/edu/berkeley/obits/gui/G.java index 095b958..feecf13 100644 --- a/src/edu/berkeley/obits/gui/G.java +++ b/src/edu/berkeley/obits/gui/G.java @@ -29,6 +29,11 @@ public class G { public void line(double x1, double y1, double x2, double y2) { g.draw(new Line2D.Double(x1, y1, x2, y2)); } + public void line(double x1, double y1, double x2, double y2, int stroke) { + g.setStroke(new BasicStroke(stroke)); + g.draw(new Line2D.Double(x1, y1, x2, y2)); + g.setStroke(new BasicStroke(1)); + } public void color(Color c) { g.setColor(c); } public void color(int color) { diff --git a/src/edu/berkeley/obits/gui/Gui.java b/src/edu/berkeley/obits/gui/Gui.java index 6b1f472..374d54c 100644 --- a/src/edu/berkeley/obits/gui/Gui.java +++ b/src/edu/berkeley/obits/gui/Gui.java @@ -212,9 +212,9 @@ public class Gui extends ZoomingPanel implements KeyListener, MouseMotionListene // 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) + if (((cell.xlut_relevant() && cell.xi_to_xlut_relevant()) || + (cell.ylut_relevant() && cell.xi_to_ylut_relevant())) + && (cell.xi() != NONE) && (cell.xi() < L0 || cell.xi() > L4) ) { P xi2 = corner(cell.xi(), SIZE + 2*BEVEL, -1).translate(-BEVEL, -BEVEL); switch(cell.xi()) { @@ -512,6 +512,34 @@ public class Gui extends ZoomingPanel implements KeyListener, MouseMotionListene } } + public void pressed() { + dragFrom = oldcell; + } + public void released() { + if (dragFrom == null || oldcell == null) return; + if (Math.abs(dragFrom._y - oldcell._y) > 1) return; + if (Math.abs(dragFrom._x - oldcell._x) > 1) return; + if (dragFrom._x == oldcell._x && dragFrom._y == oldcell._y+1) oldcell.cell.yi(NORTH); + if (dragFrom._x == oldcell._x && dragFrom._y == oldcell._y-1) oldcell.cell.yi(SOUTH); + if (dragFrom._x == oldcell._x+1 && dragFrom._y == oldcell._y) oldcell.cell.yi(EAST); + if (dragFrom._x == oldcell._x-1 && dragFrom._y == oldcell._y) oldcell.cell.yi(WEST); + if (dragFrom._x == oldcell._x+1 && dragFrom._y == oldcell._y+1) oldcell.cell.xi(NE); + if (dragFrom._x == oldcell._x+1 && dragFrom._y == oldcell._y-1) oldcell.cell.xi(SE); + if (dragFrom._x == oldcell._x-1 && dragFrom._y == oldcell._y+1) oldcell.cell.xi(NW); + if (dragFrom._x == oldcell._x-1 && dragFrom._y == oldcell._y-1) oldcell.cell.xi(SW); + repaint(); + } + public void drawKeyboard(Image keyboardImage, Graphics2D g) { + int width = 300; + int height = (keyboardImage.getHeight(null) * width) / keyboardImage.getWidth(null); + g.drawImage(keyboardImage, + 0, getHeight() - height, + width, getHeight(), + 0, 0, + keyboardImage.getWidth(null), keyboardImage.getHeight(null), + null); + } + public void _paint(Graphics2D g) { this.g = g; @@ -545,12 +573,9 @@ public class Gui extends ZoomingPanel implements KeyListener, MouseMotionListene 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: " + XLUT_EQUATIONS[newcell.cell.xlut() & 0xff], - getWidth() - 200 + 10, (line += 15)); - g.drawString(" ylut: " + YLUT_EQUATIONS[newcell.cell.ylut() & 0xff], - getWidth() - 200 + 10, (line += 15)); + g.drawString("selected: " + newcell._x + "," + newcell._y, getWidth() - 200 + 10, (line += 15)); + g.drawString(" xlut: " + XLUT_EQUATIONS[newcell.cell.xlut() & 0xff], getWidth() - 200 + 10, (line += 15)); + g.drawString(" ylut: " + YLUT_EQUATIONS[newcell.cell.ylut() & 0xff], getWidth() - 200 + 10, (line += 15)); String xi = "??"; switch(newcell.cell.xi()) { case NW : xi = "NW"; break; @@ -560,7 +585,7 @@ public class Gui extends ZoomingPanel implements KeyListener, MouseMotionListene case NONE : xi = "."; break; default: xi = "L"+(newcell.cell.xi()-L0); break; } - g.drawString(" xi: " + xi, getWidth() - 200 + 10, (line += 15)); + g.drawString("x-in mux: " + xi, getWidth() - 200 + 10, (line += 15)); String yi = "??"; switch(newcell.cell.yi()) { @@ -571,14 +596,15 @@ public class Gui extends ZoomingPanel implements KeyListener, MouseMotionListene case NONE : yi = "."; break; default: yi = "L"+(newcell.cell.yi()-L0); break; } - g.drawString(" yi: " + yi, getWidth() - 200 + 10, (line += 15)); + g.drawString("y-in mux: " + yi, getWidth() - 200 + 10, (line += 15)); - g.drawString(" wi: " + (newcell.cell.wi()==NONE ? "." : ("L"+(newcell.cell.wi()-L0))), + g.drawString("w-in mux: " + (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))), + g.drawString("z-in mux: " + (newcell.cell.zi()==NONE ? "." : ("L"+(newcell.cell.zi()-L0))), getWidth() - 200 + 10, (line += 15)); + g.drawString("t-in mux: ", getWidth() - 200 + 10, (line += 15)); - g.drawString(" FF: " + (newcell.cell.ff_reset_value() ? "reset=SET" : "."), + g.drawString(" set/rst: " + (newcell.cell.ff_reset_value() ? "reset=SET" : "."), getWidth() - 200 + 10, (line += 15)); String outs = ""; @@ -587,17 +613,17 @@ public class Gui extends ZoomingPanel implements KeyListener, MouseMotionListene 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, + g.drawString(" h conn: " + 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, + g.drawString(" v conn: " + vs, getWidth() - 200 + 10, (line += 15)); - g.drawString(" OE: " + (newcell.cell.oe()==H4 ? "H4" : newcell.cell.oe()==V4 ? "V4" : "."), + g.drawString("out enab: " + (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"), + g.drawString(" c-mux: " + (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" : "."), + g.drawString(" fb src: " + (newcell.cell.f() ? "clocked" : "."), getWidth() - 200 + 10, (line += 15)); g.drawString(" bypass: " + (newcell.cell.b() ? "clocked" : "."), getWidth() - 200 + 10, (line += 15)); @@ -607,10 +633,45 @@ public class Gui extends ZoomingPanel implements KeyListener, MouseMotionListene getWidth() - 200 + 10, (line += 15)); } + if (shiftkey) { + drawKeyboard(keyboard2, g); + } else switch(lastChar) { + case 'x': + case 'y': + case 'z': + case 'w': + case 'o': + case 'h': + case 'v': + drawKeyboard(keyboard3, g); + break; + default: + drawKeyboard(keyboard1, g); + break; + } + + while (mousebutton) { + + if (dragFrom == null || oldcell == null) break; + if (Math.abs(dragFrom._y - oldcell._y) > 1) break; + if (Math.abs(dragFrom._x - oldcell._x) > 1) break; + g.setTransform(t); + if (dragFrom._x == oldcell._x || dragFrom._y == oldcell._y) + gg.color(BLUE); + else + gg.color(RED); + + gg.line( oldcell._x * SIZE + SIZE/2, + oldcell._y * SIZE + SIZE/2, + dragFrom._x * SIZE + SIZE/2, + dragFrom._y * SIZE + SIZE/2, 5); + break; + } + this.g = null; this.gg = null; } - + Cell dragFrom = null; public void clear() { Graphics2D g = (Graphics2D)getGraphics(); @@ -867,4 +928,8 @@ public class Gui extends ZoomingPanel implements KeyListener, MouseMotionListene public boolean result(boolean x, boolean y, boolean z) { return z; } } + private static Image keyboard1 = Toolkit.getDefaultToolkit().createImage("keyboard1.png"); + private static Image keyboard2 = Toolkit.getDefaultToolkit().createImage("keyboard2.png"); + private static Image keyboard3 = Toolkit.getDefaultToolkit().createImage("keyboard3.png"); + } diff --git a/src/edu/berkeley/obits/gui/ZoomingPanel.java b/src/edu/berkeley/obits/gui/ZoomingPanel.java index 2903373..39d3326 100644 --- a/src/edu/berkeley/obits/gui/ZoomingPanel.java +++ b/src/edu/berkeley/obits/gui/ZoomingPanel.java @@ -71,6 +71,7 @@ public abstract class ZoomingPanel extends JComponent implements KeyListener, Mo public void keyTyped(KeyEvent k) { } public void keyReleased(KeyEvent k) { + shiftkey = (k.getModifiers() & k.SHIFT_MASK) != 0; if (k.getKeyCode() == k.VK_ALT) { if (drag) { drag = false; @@ -84,13 +85,17 @@ public abstract class ZoomingPanel extends JComponent implements KeyListener, Mo } } public char lastChar; + public int keyMode; public void keyPressed(KeyEvent k) { + shiftkey = (k.getModifiers() & k.SHIFT_MASK) != 0; keyPressed0(k); char c = k.getKeyChar(); if (c=='q') c = 'y'; lastChar = c; } + public boolean shiftkey = false; public void keyPressed0(KeyEvent k) { + repaint(); if (k.getKeyCode() == k.VK_ALT) { drag = true; dragx = mousex; @@ -104,64 +109,43 @@ public abstract class ZoomingPanel extends JComponent implements KeyListener, Mo } Gui.Cell cell = whichCell(mousex, mousey); At40k.Cell c = cell == null ? null : cell.cell; - switch(k.getKeyCode()) { - case VK_PLUS: - if (xkey) { - c.xlut(LUT_SELF | LUT_OTHER | LUT_Z); - repaint(); - return; - } else if (ykey) { - c.ylut(LUT_SELF | LUT_OTHER | LUT_Z); - repaint(); - return; - } - scale += 0.1; repaint(); return; - case VK_MULTIPLY: - if (xkey) { - c.xlut(LUT_SELF & LUT_OTHER & LUT_Z); - repaint(); - return; - } else if (ykey) { - c.ylut(LUT_SELF & LUT_OTHER & LUT_Z); - repaint(); - return; - } - scale += 0.1; repaint(); return; - case VK_MINUS: scale -= 0.1; repaint(); return; + if ((k.getModifiers() & k.ALT_MASK) != 0) + switch(k.getKeyCode()) { + case VK_S: + writeMode4(); + break; + case VK_O: + readMode4(); + break; + } + + else switch(k.getKeyCode()) { case VK_ESCAPE: scale = 1.0; recenter = null; repaint(); return; - case VK_NUMPAD7: whichCell(mousex, mousey).cell.xi(NW); repaint(); return; - case VK_NUMPAD8: whichCell(mousex, mousey).cell.yi(NORTH); repaint(); return; - case VK_NUMPAD9: whichCell(mousex, mousey).cell.xi(NE); repaint(); return; - case VK_NUMPAD4: whichCell(mousex, mousey).cell.yi(WEST); repaint(); return; - case VK_NUMPAD6: whichCell(mousex, mousey).cell.yi(EAST); repaint(); return; - case VK_NUMPAD1: whichCell(mousex, mousey).cell.xi(SW); repaint(); return; - case VK_NUMPAD2: whichCell(mousex, mousey).cell.yi(SOUTH); repaint(); return; - case VK_NUMPAD3: whichCell(mousex, mousey).cell.xi(SE); repaint(); return; - case VK_0: - case VK_1: - case VK_2: - case VK_3: - case VK_4: { + case VK_0: case VK_1: case VK_2: case VK_3: case VK_4: { int i = L0 + (k.getKeyChar() - '0'); switch(lastChar) { case 'x': c.xi(i); break; - case 'y': c.yi(i); break; + case 'y': case 'q': c.yi(i); break; case 'w': c.wi(i); break; case 'z': c.zi(i); break; - case ' ': c.out(i, !c.out(i)); break; + case 'o': c.out(i, !c.out(i)); break; + case 'h': c.h(i, !c.hx(i)); break; + case 'v': c.v(i, !c.vx(i)); break; } repaint(); return; } - //case VK_F: c.t(TMUX_W_AND_FB); repaint(); return; - case VK_W: c.t(TMUX_W); repaint(); return; - //case VK_Z: c.t(TMUX_W_AND_Z); repaint(); return; + case VK_W: if (lastChar == 'w') c.wi(NONE); repaint(); return; + case VK_X: if (lastChar == 'x') c.xi(NONE); repaint(); return; + case VK_Y: if (lastChar == 'y') c.yi(NONE); repaint(); return; + case VK_Z: if (lastChar == 'z') c.zi(NONE); repaint(); return; + case VK_Q: if (lastChar == 'q') c.yi(NONE); repaint(); return; case VK_C: if (lastChar == 'x') { c.xo(true); repaint(); return; } - if (lastChar == 'y') { c.yo(true); repaint(); return; } + if (lastChar == 'y' || lastChar == 'q') { c.yo(true); repaint(); return; } switch(c.c()) { case XLUT: c.c(YLUT); break; case YLUT: c.c(ZMUX); break; @@ -172,38 +156,22 @@ public abstract class ZoomingPanel extends JComponent implements KeyListener, Mo return; case VK_F: c.f(!c.f()); repaint(); return; - case VK_B: c.b(!c.b()); repaint(); return; - - case VK_X: - if (lastChar == 'x') { c.xo(false); repaint(); return; } - xkey = true; - return; + case VK_S: c.ff_reset_value(!c.ff_reset_value()); repaint(); return; + case VK_R: c.b(!c.b()); repaint(); return; - case VK_Q: - case VK_Y: - if (lastChar == 'y') { c.yo(false); repaint(); return; } - ykey = true; - return; - - case VK_R: - boolean reg = c.f(); - c.f(!reg); - c.b(!reg); + case VK_T: + switch(c.t()) { + case TMUX_FB: c.t(TMUX_W_AND_FB); break; + case TMUX_W_AND_FB: c.t(TMUX_W); break; + case TMUX_W: c.t(TMUX_W_AND_Z); break; + case TMUX_W_AND_Z: c.t(TMUX_Z); break; + case TMUX_Z: c.t(TMUX_FB); break; + } + System.err.println("set " + c.t()); repaint(); return; - case VK_SPACE: - scan(); - break; - - case VK_S: - writeMode4(); - break; - case VK_L: - readMode4(); - break; - - case VK_O: + case VK_E: switch(c.oe()) { case H4: c.oe(V4); break; case V4: c.oe(NONE); break; @@ -212,8 +180,6 @@ public abstract class ZoomingPanel extends JComponent implements KeyListener, Mo repaint(); return; - // xlut table - // ylut table // ff reset polarity // h0..h5, v0..v5 // xi=0..5 @@ -221,10 +187,11 @@ public abstract class ZoomingPanel extends JComponent implements KeyListener, Mo // zi=0..5 // wi=0..5 // t-mux + } } - Gui.Cell oldcell = null; + public Gui.Cell oldcell = null; public abstract Gui.Cell whichCell(int x, int y); public void mouseMoved(MouseEvent m) { @@ -259,10 +226,15 @@ public abstract class ZoomingPanel extends JComponent implements KeyListener, Mo public void mouseDragged(MouseEvent m) { mouseMoved(m); - dragx = m.getX(); - dragy = m.getY(); + //dragx = m.getX(); + //dragy = m.getY(); + } + public abstract void pressed(); + public abstract void released(); public void mousePressed(MouseEvent m) { + mousebutton = true; + /* recenter = new Point2D.Float(m.getX(), m.getY()); try { @@ -272,14 +244,16 @@ public abstract class ZoomingPanel extends JComponent implements KeyListener, Mo } repaint(); */ + pressed(); } public void mouseEntered(MouseEvent e) { } public void mouseExited(MouseEvent e) { } public void mouseClicked(MouseEvent e) { } public void mouseReleased(MouseEvent e) { - + mousebutton = false; + released(); } - + public boolean mousebutton = false; public boolean xkey = false; public boolean ykey = false;