1 package edu.berkeley.slipway.demos;
3 import edu.berkeley.slipway.*;
4 import com.atmel.fpslic.*;
5 import static com.atmel.fpslic.FpslicConstants.*;
6 import static com.atmel.fpslic.FpslicUtil.*;
7 import edu.berkeley.slipway.gui.*;
9 import java.awt.event.*;
10 import java.awt.color.*;
11 import org.ibex.util.*;
14 import static edu.berkeley.slipway.demos.Demo.*;
15 import static edu.berkeley.slipway.demos.ExperimentUtils.*;
17 public class DemoVisualizer extends Frame implements KeyListener, MouseMotionListener, MouseListener {
18 public static final int WIDTH = 40;
19 public static final int HEIGHT = 40;
20 public static final int LW = 15;
21 public static final int LH = 15;
22 public static final Color RED = new Color(0xaa, 0x55, 0x55);
23 public static final Color BLUE = new Color(0x55, 0x55, 0xaa);
24 private final FpslicDevice dev;
25 private final SlipwayBoard board;
28 public DemoVisualizer(final FpslicDevice dev, final SlipwayBoard board) {
32 addMouseMotionListener(this);
33 addMouseListener(this);
40 if (!enabled) continue;
42 Fpslic.Cell cell = dev.cell(21, 22);
52 } catch (Exception e) {
58 public boolean enabled = false;
59 public void mouseClicked(MouseEvent e) { }
60 public void mouseEntered(MouseEvent e) { }
61 public void mouseExited(MouseEvent e) { }
62 public void mouseReleased(MouseEvent e) { }
63 public void keyTyped(KeyEvent k) { }
64 public void keyReleased(KeyEvent k) { }
65 public void keyPressed(KeyEvent keyevent) {
67 switch(keyevent==null ? '_' : keyevent.getKeyChar()) {
69 if (selx==-1 || sely==-1) break;
70 FpslicDevice.Cell cell = dev.cell(selx, sely);
72 drawCell(getGraphics(), selx, sely);
76 if (selx==-1 || sely==-1) break;
77 FpslicDevice.Cell cell = dev.cell(selx, sely);
80 drawCell(getGraphics(), selx, sely);
85 if (selx==-1 || sely==-1) break;
86 FpslicDevice.Cell cell = dev.cell(selx, sely);
89 drawCell(getGraphics(), selx, sely);
94 System.out.println("interrupt_count: " + board.readInterruptCount());
102 System.out.println("low => " + mx);
103 copy(dev.cell(mx, Demo.yofs-2), NORTH, NORTH);
104 copy(dev.cell(mx, Demo.yofs-3), NORTH, NORTH);
105 //dev.cell(mx, Demo.yofs-3).ylut(~dev.cell(mx, Demo.yofs-3).ylut());
106 //dev.cell(mx, Demo.yofs-3).xlut(~dev.cell(mx, Demo.yofs-3).xlut());
108 int mx = 23-(masterx-23);
109 System.out.println("high => " + mx);
110 copy(dev.cell(mx, Demo.yofs), NW, NW);//NORTH, NORTH);
111 copy(dev.cell(mx, Demo.yofs-1), NORTH, NORTH);
112 //for(int x=mx-1; x>=1; x--)
113 //copy(dev.cell(x, Demo.yofs), EAST, EAST);
114 for(int y=Demo.yofs+1; y<=23; y++)
115 copy(dev.cell(1, y), SOUTH, SOUTH);
116 //dev.cell(mx, Demo.yofs-1).ylut(~dev.cell(mx, Demo.yofs-1).ylut());
117 //dev.cell(mx, Demo.yofs-1).xlut(~dev.cell(mx, Demo.yofs-1).xlut());
122 System.out.println("low => " + mx);
123 copy(dev.cell(mx, Demo.yofs-2), SOUTH, SOUTH);
124 copy(dev.cell(mx, Demo.yofs-3), NORTH, NORTH);
125 dev.cell(mx, Demo.yofs-3).ylut(~dev.cell(mx, Demo.yofs-3).ylut());
126 dev.cell(mx, Demo.yofs-3).xlut(~dev.cell(mx, Demo.yofs-3).xlut());
128 int mx = 23-(masterx-23);
129 System.out.println("high => " + mx);
130 copy(dev.cell(mx, Demo.yofs), SOUTH, SOUTH);
132 copy(dev.cell(mx, Demo.yofs-1), NORTH, NORTH);
134 copy(dev.cell(mx, Demo.yofs-1), NORTH, SW);
136 FpslicDevice.Cell lc = null;
137 for(int k=0; k<10; k++) {
138 int y = Demo.yofs-2-(k*2);
139 copy(dev.cell(left?(mx-1):mx, y), SOUTH, left?NE:NW);
140 copy(lc = dev.cell(left?(mx-1):mx, y-1), NORTH, left?SE:SW);
143 copy(lc, NORTH, NORTH);
145 //for(int x=mx-1; x>=1; x--)
146 //copy(dev.cell(x, Demo.yofs), EAST, EAST);
147 //for(int y=Demo.yofs+1; y<=23; y++)
148 //copy(dev.cell(1, y), SOUTH, SOUTH);
151 dev.cell(mx+2, Demo.yofs).ylut(0x00);
152 dev.cell(mx+2, Demo.yofs).xlut(0x00);
156 dev.cell(mx, Demo.yofs-1).ylut(~LUT_Z);
157 dev.cell(mx, Demo.yofs-1).xlut(LUT_Z);
158 loopback(dev.cell(mx, Demo.yofs-1), YLUT);
160 dev.cell(mx, Demo.yofs).ylut(~LUT_SELF);
161 dev.cell(mx, Demo.yofs).xlut(~LUT_OTHER);
167 //enabled = !enabled;
172 //enabled = !enabled;
174 for(int cap=0; cap<15; cap++) {
176 try { Thread.sleep(100); } catch (Exception e) { }
177 //showit(dev, board, this);
178 fill(dev, board, cap);
179 board.readInterruptCount();
180 long now = System.currentTimeMillis();
181 try { Thread.sleep(4000); } catch (Exception e) { }
182 int count = board.readInterruptCount();
183 long now2 = System.currentTimeMillis();
184 System.out.println(cap + " , " + (((float)count * (2*2*2*2*2*2*2*2*2*1000))/(now2-now)));
186 } catch (Exception e) { e.printStackTrace(); }
191 showit(dev, board, this);
193 public void mousePressed(MouseEvent e) { }
194 public void mouseMoved(MouseEvent e) {
197 if (selx >= 0 && selx < 24 && sely >= 0 && sely < 24) {
200 FpslicDevice.Cell cell = dev.cell(cx, cy);
204 selx = (x-20)/(WIDTH+2);
205 sely = (23 - (y-20)/(HEIGHT+2))+1;
207 public void mouseDragged(MouseEvent e) { mousePressed(e); }
208 public void paint(Graphics g) {
209 System.out.println("paintall");
210 g.setColor(Color.white);
211 g.fillRect(0, 0, getWidth(), getHeight());
212 g.setFont(new Font("sansserif", Font.BOLD, 24));
213 for(int x=0; x<24; x++)
214 for(int y=0; y<24; y++)
216 for(int x=0; x<=23; x+=4)
217 for(int y=23; y>=0; y-=4)
218 drawSector(g, dev.cell(x, y).sector());
221 public void refresh() { }
222 public static int left(FpslicDevice.Cell cell) { return (cell.col) *(WIDTH+2)+20; }
223 public static int top(FpslicDevice.Cell cell) { return (23-cell.row)*(HEIGHT+2)+60; }
224 public void drawSector(Graphics g, FpslicDevice.Sector sector) {
225 g.setColor(Color.gray);
226 ((Graphics2D)g).setStroke(new BasicStroke(1));
227 int px = ((sector.col)*(WIDTH+2))+20-1;
228 int py = ((23-(sector.row+3))*(HEIGHT+2))+60-1;
229 g.drawRect(px, py, (WIDTH+2)*4+2, (HEIGHT+2)*4+2);
231 for(int dir=0; dir<2; dir++) {
233 for(int y=h?sector.row:sector.col; y<(h?sector.row+4:sector.col+4); y++)
234 for(int plane=0; plane<=4; plane++) {
235 FpslicDevice.Cell cell = h ? dev.cell(sector.col, y) : dev.cell(y, sector.row);
236 FpslicDevice.Cell cell_east = h ? dev.cell(sector.col-1, y) : dev.cell(y, sector.row-1);
237 FpslicDevice.Cell cell_west = h ? dev.cell(sector.col+4, y) : dev.cell(y, sector.row+4);
238 boolean draw = false;
240 if (cell_east!=null &&
241 (cell_east.hwire(plane).drives(cell.hwire(plane)) ||
242 cell_east.hwire(plane).drives(cell.hwire(plane))))
244 if (cell_west!=null &&
245 (cell_west.hwire(plane).drives(cell.hwire(plane)) ||
246 cell_west.hwire(plane).drives(cell.hwire(plane))))
249 if (cell_east!=null &&
250 (cell_east.vwire(plane).drives(cell.vwire(plane)) ||
251 cell_east.vwire(plane).drives(cell.vwire(plane))))
253 if (cell_west!=null &&
254 (cell_west.vwire(plane).drives(cell.vwire(plane)) ||
255 cell_west.vwire(plane).drives(cell.vwire(plane))))
259 for(int x=h?sector.col:sector.row; x<(h?sector.col+4:sector.row+4); x++)
260 if (((h ? dev.cell(x,y).hx(plane) : dev.cell(y,x).vx(plane))) ||
261 (h?dev.cell(x,y).out(plane):dev.cell(y,x).out(plane)))
264 g.setColor(new Color(0xff, 0x00, 0xff));
266 g.drawLine(left(cell),
268 left(cell) + 4*(WIDTH+2),
272 g.drawLine(left(cell)+3,
273 top(cell) + (HEIGHT+2),
275 top(cell) - 3*(HEIGHT+2)
283 public void drawCell(Graphics g, int cx, int cy) {
284 int x = (cx*(WIDTH+2))+20;
285 int y = ((23-cy)*(HEIGHT+2))+60;
286 if (g.getClipBounds() != null && !g.getClipBounds().intersects(new Rectangle(x, y, x+WIDTH, y+HEIGHT))) return;
287 drawCell(g, cx, cy, Color.white);
289 public void drawCell(Graphics g, int cx, int cy, Color bg) {
290 int x = (cx*(WIDTH+2))+20;
291 int y = ((23-cy)*(HEIGHT+2))+60;
293 //System.out.println("drawcell " + cx + "," + cy);
294 FpslicDevice.Cell cell = dev.cell(cx, cy);
296 g.fillRect(x, y, WIDTH, HEIGHT);
298 g.setColor((selx==cx && sely==cy) ? Color.red : Color.black);
299 g.drawRect(x, y, WIDTH, HEIGHT);
301 //g.setColor((selx==cx && sely==cy) ? Color.red : Color.gray);
302 //g.drawRect(x+(WIDTH-(LW*2))/2-1, y+(HEIGHT-LW)/2-1, LW*2+1, LH+1);
305 //g.fillRect(x+(WIDTH-(LW*2))/2, y+(HEIGHT-LW)/2, LW, LH);
306 //g.setColor(Color.white);
307 //g.drawString("1", x+(WIDTH-(LW*2))/2, y+(HEIGHT-LW)/2);
310 //g.fillRect(x+(WIDTH-(LW*2))/2+LW, y+(HEIGHT-LW)/2, LW, LH);
311 //g.setColor(Color.white);
312 //g.drawString("0", x+(WIDTH-(LW*2))/2+LW, y+(HEIGHT-LW)/2);
316 ((Graphics2D)g).setStroke(new BasicStroke((float)1));
318 case NORTH: g.drawLine(x+WIDTH/2+5, y-10, x+WIDTH/2+5, y+HEIGHT/2); break;
319 case SOUTH: g.drawLine(x+WIDTH/2-5, y+HEIGHT+10, x+WIDTH/2-5, y+HEIGHT/2); break;
320 case EAST: g.drawLine(x+WIDTH+10, y+HEIGHT/2+5, x+WIDTH/2, y+HEIGHT/2+5); break;
321 case WEST: g.drawLine(x-10, y+HEIGHT/2-5, x+WIDTH/2, y+HEIGHT/2-5); break;
325 ((Graphics2D)g).setStroke(new BasicStroke((float)1));
327 case NW: g.drawLine(x-10+3, y-10, x+WIDTH/2+3, y+HEIGHT/2); break;
328 case SW: g.drawLine(x-10-3, y+HEIGHT+10, x+WIDTH/2-3, y+HEIGHT/2); break;
329 case NE: g.drawLine(x+WIDTH+10+3, y-10, x+WIDTH/2+3, y+HEIGHT/2); break;
330 case SE: g.drawLine(x+WIDTH+10-3, y+HEIGHT+10, x+WIDTH/2-3, y+HEIGHT/2); break;
333 ((Graphics2D)g).setStroke(new BasicStroke(1));
336 if (selx==cx && sely==cy) {
337 int xp = 23 * (WIDTH+2) + 100;
339 g.setColor(Color.white);
340 g.fillRect(xp, yp, 300, 1000);
341 g.setColor(Color.black);
342 g.drawString("Cell " + cx + "," + cy, xp, (yp+=15));
343 //g.drawString("X-Lut: " + bin8(cell.xlut()), xp, (yp+=15));
344 g.drawString("X-Lut: " + cell.printXLut(), xp, (yp+=15));
345 //g.drawString("Y-Lut: " + bin8(cell.ylut()), xp, (yp+=15));
346 g.drawString("Y-Lut: " + cell.printYLutX(), xp, (yp+=15));
349 if ((cell.ylut()&0xff)==0xff && (cell.xlut()&0xff)==0xff) {
350 g.setColor(new Color(0x00, 0x00, 0xff));
351 g.drawString("1", left(cell) + 12, top(cell) + 30);
353 if ((cell.ylut()&0xff)==0x00 && (cell.xlut()&0xff)==0x00) {
354 g.setColor(new Color(0x00, 0x00, 0xff));
355 g.drawString("0", left(cell) + 12, top(cell) + 30);
357 if ((cell.ylut()&0xff)==0xB2) {
358 //System.out.println("muller @ " + cell);
360 //g.drawString("X="+(x?"1":"0"), left(cell) + 10, top(cell) + 20);
361 g.setColor(new Color(0x00, 0xaa, 0x00));
362 g.drawString("C", left(cell) + 12, top(cell) + 30);
367 public static void showit(FpslicDevice dev, SlipwayBoard board, final DemoVisualizer vis) {
368 final Color red = new Color(0xff, 0x99, 0x99);
369 final Color green = new Color(0x99, 0xff, 0x99);
370 final Graphics g = vis.getGraphics();
371 g.setFont(new Font("sansserif", Font.BOLD, 24));
372 for(int xx=0; xx<=dev.getWidth()-2; xx++) {
373 for(int yy=dev.getHeight()-1; yy>=0; yy--) {
376 final FpslicDevice.Cell cell = dev.cell(x, y);
377 if ((cell.ylut()&0xff)!=0xB2) continue;
378 SlipwayBoard.ByteCallback bc = new SlipwayBoard.ByteCallback() {
379 public void call(byte b) throws Exception {
380 boolean v = (b & 0x80) != 0;
381 vis.drawCell(g, x, y, v?red:green);
385 ExperimentUtils.scan(cell, YLUT, true);
386 board.readFpgaData(bc);
387 ExperimentUtils.scan(cell, NONE, false);
388 } catch (IOException ex) {
389 throw new RuntimeException(ex);