fixed heinous bug in switchbox routing
[slipway.git] / src / edu / berkeley / slipway / AsyncPaperDemo.java
1 package edu.berkeley.slipway;
2
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.*;
8 import java.awt.*;
9 import java.awt.event.*;
10 import java.awt.color.*;
11 import org.ibex.util.*;
12 import java.io.*;
13 import java.util.*;
14 import gnu.io.*;
15
16 public class AsyncPaperDemo {
17
18     FtdiBoard fpslic;
19
20     public AsyncPaperDemo() throws Exception {
21         fpslic = new FtdiBoard();
22     }
23
24     public void main() throws Exception {
25
26         turnOnLeds();
27         setupScanCell();
28
29         Fpslic.Cell root = fpslic.cell(2, 2);
30             
31         root.yo(root.north());
32         root.ylut(~LUT_SELF);
33         root.c(YLUT);
34         root = root.north();
35
36         root.yo(root.east());
37         root.ylut(~LUT_SELF);
38         root.c(YLUT);
39         root = root.east();
40
41         root.yo(root.south());
42         root.ylut(~LUT_SELF);
43         root.c(YLUT);
44         root = root.south();
45
46         root.yo(root.west());
47         root.c(YLUT);
48         root = root.west();
49
50         root = fpslic.cell(3, 7);
51         root.h(1, true);
52         root.h(2, true);
53         root.wi(L1);
54         root.zi(L2);
55         root.c(YLUT);
56         root.t(TMUX_W);
57         root.b(false);
58         root.f(false);
59         root.ylut(LUT_SELF);
60         root.yi(EAST);
61         root.xlut(LUT_Z);
62         root.xo(false);
63
64         root.west().out(2, true);
65         root.west().h(2, true);
66         root.west().c(YLUT);
67
68         root.west().west().out(1, true);
69         root.west().west().h(1, true);
70         root.west().west().c(YLUT);
71
72         root.ne().xo(root);
73
74         runGui(24, 24);
75     }
76
77     private void turnOnLeds() {
78         for(int i=0; i<24; i++) {
79             fpslic.iob_bot(i, true).enableOutput(NORTH);
80             fpslic.iob_bot(i, false).enableOutput(NW);
81             fpslic.cell(i, 0).xlut(0xff);
82             fpslic.cell(i, 0).ylut(0xff);
83         }
84     }
85
86     private void setupScanCell() {
87         fpslic.cell(23,15).h(3, true);
88         fpslic.cell(23,15).yi(L3);
89         fpslic.cell(23,15).ylut(0xAA);
90         fpslic.iob_right(15, true).enableOutput(WEST);
91     }
92
93     private void runGui(int width, int height) throws Exception {
94         Gui vis = new Gui(fpslic, fpslic, width, height);
95         Frame fr = new Frame();
96         fr.addKeyListener(vis);
97         fr.setLayout(new BorderLayout());
98         fr.add(vis, BorderLayout.CENTER);
99         fr.pack();
100         fr.setSize(900, 900);
101         vis.repaint();
102         fr.repaint();
103         fr.show();
104         synchronized(Demo.class) { Demo.class.wait(); }
105     }
106 }
107
108