X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fslipway%2FDemoVisualizer.java;fp=src%2Fedu%2Fberkeley%2Fslipway%2FDemoVisualizer.java;h=0000000000000000000000000000000000000000;hb=a639737cdb1c89b00c2fd2ee21ed9e0308afbf0f;hp=6d9f89275deb85e318afaec9799a153730d4e9a7;hpb=fbe3858bf294051a2f12ff3a5192007ca7803c94;p=slipway.git diff --git a/src/edu/berkeley/slipway/DemoVisualizer.java b/src/edu/berkeley/slipway/DemoVisualizer.java deleted file mode 100644 index 6d9f892..0000000 --- a/src/edu/berkeley/slipway/DemoVisualizer.java +++ /dev/null @@ -1,469 +0,0 @@ -package edu.berkeley.slipway; - -import edu.berkeley.slipway.*; -import com.atmel.fpslic.*; -import static com.atmel.fpslic.FpslicConstants.*; -import static com.atmel.fpslic.FpslicUtil.*; -import edu.berkeley.slipway.gui.*; -import java.awt.*; -import java.awt.event.*; -import java.awt.color.*; -import org.ibex.util.*; -import java.io.*; -import java.util.*; -import gnu.io.*; -import static edu.berkeley.slipway.Demo.*; - -public class DemoVisualizer extends Frame implements KeyListener, MouseMotionListener, MouseListener { - public static final int WIDTH = 40; - public static final int HEIGHT = 40; - public static final int LW = 15; - public static final int LH = 15; - public static final Color RED = new Color(0xaa, 0x55, 0x55); - public static final Color BLUE = new Color(0x55, 0x55, 0xaa); - private final Fpslic dev; - private final FtdiBoard drone; - int selx = -1; - int sely = -1; - public DemoVisualizer(final Fpslic dev, final FtdiBoard drone) { - this.dev = dev; - this.drone = drone; - show(); - addMouseMotionListener(this); - addMouseListener(this); - addKeyListener(this); - new Thread() { - public void run() { - try { - while(true) { - Thread.sleep(500); - if (!enabled) continue; - /* - Fpslic.Cell cell = dev.cell(21, 22); - cell.xlut(0xff); - cell.ylut(0xff); - */ - keyPressed(null); - /* - cell.xlut(0x00); - cell.ylut(0x00); - */ - } - } catch (Exception e) { - e.printStackTrace(); - } - } - }.start(); - } - public boolean enabled = false; - public void mouseClicked(MouseEvent e) { } - public void mouseEntered(MouseEvent e) { } - public void mouseExited(MouseEvent e) { } - public void mouseReleased(MouseEvent e) { - } - public void keyTyped(KeyEvent k) { - } - public void keyReleased(KeyEvent k) { - } - public void keyPressed(KeyEvent keyevent) { - boolean scan = false; - switch(keyevent==null ? '_' : keyevent.getKeyChar()) { - case '1': { - if (selx==-1 || sely==-1) break; - Fpslic.Cell cell = dev.cell(selx, sely); - cell.xlut(0xff); - cell.ylut(0xff); - drawCell(getGraphics(), selx, sely); - drone.flush(); - break; - } - case 'i': { - System.out.println("interrupt_count: " + drone.readCount()); - break; - } - case 'x': { - masterx+=2; - if (mullers) { - if (masterx <= 22) { - int mx = masterx; - System.out.println("low => " + mx); - copy(dev.cell(mx, Demo.yofs-2), NORTH, NORTH); - copy(dev.cell(mx, Demo.yofs-3), NORTH, NORTH); - //dev.cell(mx, Demo.yofs-3).ylut(~dev.cell(mx, Demo.yofs-3).ylut()); - //dev.cell(mx, Demo.yofs-3).xlut(~dev.cell(mx, Demo.yofs-3).xlut()); - } else { - int mx = 23-(masterx-23); - System.out.println("high => " + mx); - copy(dev.cell(mx, Demo.yofs), NW, NW);//NORTH, NORTH); - copy(dev.cell(mx, Demo.yofs-1), NORTH, NORTH); - //for(int x=mx-1; x>=1; x--) - //copy(dev.cell(x, Demo.yofs), EAST, EAST); - for(int y=Demo.yofs+1; y<=23; y++) - copy(dev.cell(1, y), SOUTH, SOUTH); - //dev.cell(mx, Demo.yofs-1).ylut(~dev.cell(mx, Demo.yofs-1).ylut()); - //dev.cell(mx, Demo.yofs-1).xlut(~dev.cell(mx, Demo.yofs-1).xlut()); - } - } else { - if (masterx <= 22) { - int mx = masterx; - System.out.println("low => " + mx); - copy(dev.cell(mx, Demo.yofs-2), SOUTH, SOUTH); - copy(dev.cell(mx, Demo.yofs-3), NORTH, NORTH); - dev.cell(mx, Demo.yofs-3).ylut(~dev.cell(mx, Demo.yofs-3).ylut()); - dev.cell(mx, Demo.yofs-3).xlut(~dev.cell(mx, Demo.yofs-3).xlut()); - } else { - int mx = 23-(masterx-23); - System.out.println("high => " + mx); - copy(dev.cell(mx, Demo.yofs), SOUTH, SOUTH); - /* - copy(dev.cell(mx, Demo.yofs-1), NORTH, NORTH); - */ - copy(dev.cell(mx, Demo.yofs-1), NORTH, SW); - boolean left = true; - Fpslic.Cell lc = null; - for(int k=0; k<10; k++) { - int y = Demo.yofs-2-(k*2); - copy(dev.cell(left?(mx-1):mx, y), SOUTH, left?NE:NW); - copy(lc = dev.cell(left?(mx-1):mx, y-1), NORTH, left?SE:SW); - left = !left; - } - copy(lc, NORTH, NORTH); - - //for(int x=mx-1; x>=1; x--) - //copy(dev.cell(x, Demo.yofs), EAST, EAST); - //for(int y=Demo.yofs+1; y<=23; y++) - //copy(dev.cell(1, y), SOUTH, SOUTH); - - if (mx<21) { - dev.cell(mx+2, Demo.yofs).ylut(0x00); - dev.cell(mx+2, Demo.yofs).xlut(0x00); - } - - /* - dev.cell(mx, Demo.yofs-1).ylut(~LUT_Z); - dev.cell(mx, Demo.yofs-1).xlut(LUT_Z); - loopback(dev.cell(mx, Demo.yofs-1), YLUT); - */ - dev.cell(mx, Demo.yofs).ylut(~LUT_SELF); - dev.cell(mx, Demo.yofs).xlut(~LUT_OTHER); - } - } - break; - } - case ' ': { - //enabled = !enabled; - scan = true; - break; - } - case '4': { - //enabled = !enabled; - try { - for(int cap=0; cap<15; cap++) { - drain(dev, drone); - try { Thread.sleep(100); } catch (Exception e) { } - //showit(dev, drone, this); - fill(dev, drone, cap); - drone.readCount(); - long now = System.currentTimeMillis(); - try { Thread.sleep(4000); } catch (Exception e) { } - int count = drone.readCount(); - long now2 = System.currentTimeMillis(); - System.out.println(cap + " , " + (((float)count * (2*2*2*2*2*2*2*2*2*1000))/(now2-now))); - } - } catch (Exception e) { e.printStackTrace(); } - break; - } - case 'C': { - if (selx==-1 || sely==-1) break; - Fpslic.Cell cell = dev.cell(selx, sely); - cell.ylut(0xB2); - drawCell(getGraphics(), selx, sely); - break; - } - case '0': { - if (selx==-1 || sely==-1) break; - Fpslic.Cell cell = dev.cell(selx, sely); - cell.xlut(0x00); - cell.ylut(0x00); - drawCell(getGraphics(), selx, sely); - drone.flush(); - break; - } - } - if (!scan) return; - showit(dev, drone, this); - } - public void mousePressed(MouseEvent e) { - final Fpslic.Cell cell = dev.cell(selx, sely); - if (cell==null) return; - final int old = cell.c(); - FtdiBoard.ByteCallback bc = new FtdiBoard.ByteCallback() { - public void call(byte b) throws Exception { - boolean y = (b & 0x80) != 0; - //cell.c(old); - Graphics g = getGraphics(); - g.setFont(new Font("sansserif", Font.BOLD, 14)); - g.setColor(Color.white); - //g.drawString("X=0", left(cell) + 10, top(cell) + 20); - //g.drawString("X=1", left(cell) + 10, top(cell) + 20); - //g.setColor(Color.white); - //g.drawString("Y=0", left(cell) + 8, top(cell) + 35); - //g.drawString("Y=1", left(cell) + 8, top(cell) + 35); - //g.setColor(RED); - //g.drawString("X="+(x?"1":"0"), left(cell) + 10, top(cell) + 20); - String v = (cell.c()==YLUT ? "Y" : cell.c()==XLUT ? "X" : "C"); - g.drawString(v+"="+(y?"0":"1"), left(cell) + 8, top(cell) + 35); - g.setColor(BLUE); - g.drawString(v+"="+(y?"1":"0"), left(cell) + 8, top(cell) + 35); - } }; - /* - try { - scan(dev, cell, NONE, true); - drone.readBus(bc); - //scan(dev, cell, XLUT, true); - //boolean x = (drone.readBus() & 0x80) != 0; - scan(dev, cell, NONE, false); - } catch (IOException ex) { - throw new RuntimeException(ex); - } - */ - } - - public void mouseMoved(MouseEvent e) { - int x = e.getX(); - int y = e.getY(); - if (selx >= 0 && selx < 24 && sely >= 0 && sely < 24) { - int cx = selx; - int cy = sely; - Fpslic.Cell cell = dev.cell(cx, cy); - selx = -1; - sely = -1; - /* - drawCell(getGraphics(), cx, cy); - drawSector(getGraphics(), dev.cell(cx, cy).sector()); - */ - } - selx = (x-20)/(WIDTH+2); - sely = (23 - (y-20)/(HEIGHT+2))+1; - /* - Fpslic.Cell cell = dev.cell(selx, sely); - if (selx >= 0 && selx < 24 && sely >= 0 && sely < 24) { - drawCell(getGraphics(), selx, sely); - drawSector(getGraphics(), dev.cell(selx, sely).sector()); - } - */ - } - public void mouseDragged(MouseEvent e) { mousePressed(e); } - public void paint(Graphics g) { - System.out.println("paintall"); - g.setColor(Color.white); - g.fillRect(0, 0, getWidth(), getHeight()); - g.setFont(new Font("sansserif", Font.BOLD, 24)); - for(int x=0; x<24; x++) - for(int y=0; y<24; y++) - drawCell(g,x,y); - for(int x=0; x<=23; x+=4) - for(int y=23; y>=0; y-=4) - drawSector(g, dev.cell(x, y).sector()); - /* - g.setColor(BLUE); - g.drawString("Ready", (5*(WIDTH+2))+20, 40); - g.setColor(RED); - g.drawString("Send", (3*(WIDTH+2))+20, 40); - g.setColor(BLUE); - */ - refresh(); - } - public void refresh() { - Graphics g = getGraphics(); - /* - int data = drone.readBus() & 0xff; - for(int i=0; i<8; i++) { - g.setColor((data & (1<=0; yy--) { - //for(int xx=5; xx<=PIPELEN-1; xx++) { - //for(int yy=21; yy<=22; yy++) { - final int x = xx; - final int y = yy; - final Fpslic.Cell cell = dev.cell(x, y); - if ((cell.ylut()&0xff)!=0xB2) continue; - FtdiBoard.ByteCallback bc = new FtdiBoard.ByteCallback() { - public void call(byte b) throws Exception { - boolean v = (b & 0x80) != 0; - vis.drawCell(g, x, y, v?red:green); - //if (x==PIPELEN-1 && y==22) System.out.println("time: " + (System.currentTimeMillis()-then)); - } - }; - /* - scan(dev, cell, NONE, true); - try { - drone.readBus(bc); - //scan(dev, cell, YLUT, false); - cell.v(L3, false); - dev.cell(x, 15).h(L3, false); - dev.cell(x, 15).v(L3, false); - } catch (IOException ex) { - throw new RuntimeException(ex); - } - */ - } - } - } - -}