checkpoint
authoradam <adam@megacz.com>
Fri, 22 Sep 2006 12:28:41 +0000 (13:28 +0100)
committeradam <adam@megacz.com>
Fri, 22 Sep 2006 12:28:41 +0000 (13:28 +0100)
src/com/atmel/fpslic/Fpslic.java
src/edu/berkeley/slipway/Demo.java
src/edu/berkeley/slipway/FtdiBoard.java
src/edu/berkeley/slipway/gui/Gui.java
src/edu/berkeley/slipway/gui/ZoomingPanel.java

index 78381b3..fa7dc5d 100644 (file)
@@ -50,7 +50,7 @@ public abstract class Fpslic {
         public Sector south() { return row==0 ?             null : new Sector(col, row-4); }
         public Sector east()  { return col+4>=getWidth() ?  null : new Sector(col+4, row); }
         public Sector west()  { return col==0 ?             null : new Sector(col-4, row); }
-        public Cell cell() { return Fpslic.this.cell(col, row); }
+        public Cell cell()    { return Fpslic.this.cell(col, row); }
     }
 
     public final class SectorWire {
@@ -125,7 +125,8 @@ public abstract class Fpslic {
             return (connect & 0x2)!=0;
         }
         public SectorWire driverRight() {
-            System.out.println("checking " + Integer.toString(code(true), 16) + " " + Integer.toString(_row(), 16) + " " + Integer.toString(_col(), 16));
+            //System.out.println("checking " + Integer.toString(code(true), 16) + " " +
+            //Integer.toString(_row(), 16) + " " + Integer.toString(_col(), 16));
             int ret = mode4(z(code(true)), _row(), _col());
             ret = (ret >> (global?3:0)) & 0x7;
             switch(ret) {
@@ -136,6 +137,13 @@ public abstract class Fpslic {
                 default: throw new Error("multiple drivers on " + this + "!");
             }
         }
+
+        public boolean touches(Cell c) {
+            return
+                horizontal
+                ? (c.row==_row() && (_col()/4 == c.col/4))
+                : (c.col==_col() && (_row()/4 == c.row/4));
+        }
     }
     /*    
     public final class SwitchBox {
@@ -393,6 +401,29 @@ public abstract class Fpslic {
         public boolean yo()               { return (mode4(1, row, col) & 0x02) != 0; }
         public void xo(boolean center)    { mode4(1, row, col, 0, center); }
         public void yo(boolean center)    { mode4(1, row, col, 1, center); }
+
+        public void xo(Cell c) {
+            if (c.row==row || c.col==col) {   // use the y-input
+                xlut(LUT_OTHER);
+                yi(c);
+            } else {
+                xlut(LUT_SELF);
+                xi(c);
+            }
+            xo(false);
+        }
+
+        public void yo(Cell c) {
+            if (!(c.row==row || c.col==col)) {   // use the x-input
+                ylut(LUT_OTHER);
+                xi(c);
+            } else {
+                ylut(LUT_SELF);
+                yi(c);
+            }
+            yo(false);
+        }
+
         public boolean b() { return (mode4(1, row, col) & (1 << 3)) == 0; }
         public boolean f() { return (mode4(1, row, col) & (1 << 2)) == 0; }
         public boolean x() { return (mode4(1, row, col) & (1 << 1)) != 0; }
@@ -448,6 +479,19 @@ public abstract class Fpslic {
             }
         }
 
+        public void xi(SectorWire sw) {
+            if (!sw.touches(this)) throw new RuntimeException("invalid argument");
+            xi(sw.plane);
+        }
+
+        public void xi(Cell c) {
+            if      (c.row==row-1 && c.col==col-1) xi(SW);
+            else if (c.row==row+1 && c.col==col-1) xi(NW);
+            else if (c.row==row-1 && c.col==col+1) xi(SE);
+            else if (c.row==row+1 && c.col==col+1) xi(NE);
+            else throw new RuntimeException("invalid argument");
+        }
+
         public int yi() {
             if ((mode4(0x02, row, col) & (1<<6))!=0) return L4;
             switch(mode4(0x04, row, col) & 0xff) {
@@ -480,6 +524,24 @@ public abstract class Fpslic {
             }
         }
 
+        public void yi(SectorWire sw) {
+            if (!sw.touches(this)) throw new RuntimeException("invalid argument");
+            yi(sw.plane);
+        }
+
+        public void yi(Cell c) {
+            if      (c.row==row-1 && c.col==col)   yi(SOUTH);
+            else if (c.row==row+1 && c.col==col)   yi(NORTH);
+            else if (c.row==row   && c.col==col-1) yi(WEST);
+            else if (c.row==row   && c.col==col+1) yi(EAST);
+            else throw new RuntimeException("invalid argument");
+        }
+
+        public void wi(SectorWire sw) {
+            if (!sw.touches(this)) throw new RuntimeException("invalid argument");
+            wi(sw.plane);
+        }
+
         public void wi(int source) {
             switch(source) {
                 case L4:    mode4(0x03, row, col, 1<<5, 0xEC); break;
@@ -507,6 +569,11 @@ public abstract class Fpslic {
         }
 
        
+        public void zi(SectorWire sw) {
+            if (!sw.touches(this)) throw new RuntimeException("invalid argument");
+            zi(sw.plane);
+        }
+
         public void zi(int source) {
             switch(source) {
                 case L4:    mode4(0x02, row, col, 1<<7, 0xDB); break;
index cff81c4..358daf1 100644 (file)
@@ -217,6 +217,30 @@ public class Demo {
             at40k.cell(22,15).yi(WEST);
             at40k.cell(22,15).ylut(0xAA);
             */
+
+            Fpslic.Cell root = at40k.cell(10,20);
+            
+            root.yo(root.north());
+            root.ylut(~LUT_SELF);
+            root.c(YLUT);
+            root = root.north();
+
+            root.yo(root.east());
+            root.ylut(~LUT_SELF);
+            root.c(YLUT);
+            root = root.east();
+
+            root.yo(root.south());
+            root.ylut(~LUT_SELF);
+            root.c(YLUT);
+            root = root.south();
+
+            root.yo(root.west());
+            root.c(YLUT);
+            root = root.west();
+
+            //////////////////////////////////////////////////////////////////////////////
+
             at40k.cell(23,15).h(3, true);
             at40k.cell(23,15).yi(L3);
             at40k.cell(23,15).ylut(0xAA);
index 7c83724..ab95011 100644 (file)
@@ -90,6 +90,9 @@ public class FtdiBoard extends Fpslic implements Board {
                         byte b = in.readByte();
                         ByteCallback bc = (ByteCallback)callbacks.remove(0);
                         bc.call(b);
+                        synchronized(lock) {
+                            lock.notifyAll();
+                        }
                     } catch (Exception e) {
                         e.printStackTrace();
                     }
@@ -131,6 +134,24 @@ public class FtdiBoard extends Fpslic implements Board {
 
     private Vector callbacks = new Vector();
 
+    private Object lock = new Object();
+    private static final int limit = 40;
+
+    private void enqueue(ByteCallback bcb) {
+        synchronized(lock) {
+            try {
+                while (callbacks.size() >= limit) {
+                    System.out.println("block");
+                    lock.wait(100);
+                    System.out.println("unblock => " + callbacks.size());
+                }
+            } catch (Exception e) {
+                throw new RuntimeException(e);
+            }
+        }
+        callbacks.add(bcb);
+    }
+
     public static abstract class ByteCallback {
         public int result;
         public abstract void call(byte b) throws Exception;
@@ -149,7 +170,7 @@ public class FtdiBoard extends Fpslic implements Board {
                     }
                 };
             synchronized(bc) {
-                callbacks.add(bc);
+                enqueue(bc);
                 out.writeByte(3);
                 out.flush();
                 bc.wait();
@@ -159,13 +180,13 @@ public class FtdiBoard extends Fpslic implements Board {
     }
 
     public synchronized void readBus(ByteCallback bc) throws IOException {
-        callbacks.add(bc);
+        enqueue(bc);
         out.writeByte(2);
         out.flush();
     }
 
     public synchronized void readInterrupts(ByteCallback bc) throws IOException {
-        callbacks.add(bc);
+        enqueue(bc);
         out.writeByte(3);
         out.flush();
     }
index 37bfaf5..371da77 100644 (file)
@@ -60,11 +60,17 @@ public class Gui extends ZoomingPanel implements KeyListener, MouseMotionListene
         this.drone = drone;
         for(int i=0; i<ca.length; i++)
             ca[i] = new Cell[128];
-        for(int x=7; x<17; x++)
-            for(int y=7; y<17; y++)
-                new Cell(x-7,y-7, at40k.cell(x, y));
+        for(int x=9; x<14; x++)
+            for(int y=19; y<at40k.getHeight(); y++)
+                new Cell(x,y, at40k.cell(x, y));
+
+
+        new Thread() {
+            public void run() {
+                while(true) scan();
+            }
+        }.start();
 
-        scan();
         /*
         Fpslic.Cell c = at40k.cell(0,0);
         for(int i=0; i<256; i++) {
@@ -77,6 +83,7 @@ public class Gui extends ZoomingPanel implements KeyListener, MouseMotionListene
     public class Cell {
         Fpslic.Cell cell;
         boolean in = false;
+        public boolean scanme = false;
         public boolean xon = false;
         public boolean yon = false;
         public boolean xknown = false;
@@ -90,7 +97,7 @@ public class Gui extends ZoomingPanel implements KeyListener, MouseMotionListene
             cells.add(this);
         }
         public void clear() {
-            gg.color(in ? selectedcell : nonselectedcell);
+            gg.color(in ? selectedcell : (scanme ? new Color(0xbb, 0xbb, 0xbb) : nonselectedcell));
             g.fillRect(0, 0, SIZE, SIZE);
         }
         public void draw() {
@@ -713,11 +720,11 @@ public class Gui extends ZoomingPanel implements KeyListener, MouseMotionListene
     }
 
     public void scan() {
-        System.out.println("scan");
-        for(int x=2; x<6; x++)
-            for(int y=2; y<6; y++)
+        for(int x=0; x<at40k.getWidth(); x++)
+            for(int y=0; y<at40k.getHeight(); y++)
                 if (ca[x][y] != null)
-                    scan(ca[x][y]);
+                    if (ca[x][y].scanme)
+                        scan(ca[x][y]);
     }
     public void scan(final Gui.Cell c) {
         try {
@@ -761,10 +768,8 @@ 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;
@@ -781,8 +786,6 @@ public class Gui extends ZoomingPanel implements KeyListener, MouseMotionListene
                     break;
             }
             made--;
-            System.out.println("made="+made);
-            if (made==0) scan();
         }
     }
 
index 4a3150f..66b2dc4 100644 (file)
@@ -117,6 +117,18 @@ public abstract class ZoomingPanel extends JComponent implements KeyListener, Mo
                 case VK_O:
                     readMode4();
                     break;
+                case VK_0: {
+                    c.xlut(0x00);
+                    c.ylut(0x00);
+                    repaint();
+                    return;
+                }
+                case VK_1: {
+                    c.xlut(0xff);
+                    c.ylut(0xff);
+                    repaint();
+                    return;
+                }
             }
 
         else switch(k.getKeyCode()) {
@@ -156,7 +168,10 @@ public abstract class ZoomingPanel extends JComponent implements KeyListener, Mo
                 return;
 
             case VK_F: c.f(!c.f()); repaint(); return;
-            case VK_S: c.ff_reset_value(!c.ff_reset_value()); repaint(); return;
+            case VK_S:
+                Gui.Cell gc = whichCell(mousex,mousey);
+                gc.scanme = !gc.scanme;
+                //case VK_S: c.ff_reset_value(!c.ff_reset_value()); repaint(); return;
             case VK_R: c.b(!c.b()); repaint(); return;
 
             case VK_T: