1 package edu.berkeley.obits;
3 import edu.berkeley.slipway.*;
4 import static com.atmel.fpslic.Fpslic.Constants.*;
5 import static com.atmel.fpslic.Fpslic.Util.*;
6 import edu.berkeley.obits.device.atmel.*;
7 import edu.berkeley.obits.gui.*;
9 import java.awt.event.*;
10 import java.awt.color.*;
11 import org.ibex.util.*;
16 public class AtmelSerial {
18 //public static boolean mullers = false;
19 public static boolean mullers = true;
20 public static int masterx = 1;
21 public static SerialPort detectObitsPort() throws Exception {
22 Enumeration e = CommPortIdentifier.getPortIdentifiers();
23 while(e.hasMoreElements()) {
24 CommPortIdentifier cpi = (CommPortIdentifier)e.nextElement();
25 Log.info(AtmelSerial.class, "trying " + cpi.getName());
26 if (cpi.getName().startsWith("/dev/cu.usbserial-"))
27 return new RXTXPort(cpi.getName());
28 if (cpi.getName().startsWith("/dev/ttyS0"))
29 return new RXTXPort(cpi.getName());
31 Log.info(AtmelSerial.class, "returning null...");
34 public static int PIPELEN=20;
35 public static void main(String[] s) throws Exception {
36 //AvrDrone device = new AvrDrone(detectObitsPort());
37 //AvrDrone device = new AvrDrone();
38 AvrDrone device = new AvrDrone(new FtdiBoard());
39 At40k at40k = new At40k.At40k10(device);
41 long begin = System.currentTimeMillis();
42 device.readMode4(new ProgressInputStream("configuring fabric", System.in, 111740));
43 long end = System.currentTimeMillis();
44 Log.info(AtmelSerial.class, "finished in " + ((end-begin)/1000) + "s");
46 Log.info(AtmelSerial.class, "issuing command");
48 //at40k.iob_top(2, true).oe(false);
49 //at40k.iob_top(2, false).oe(false);
50 //at40k.iob_top(1, true).oe(false);
52 // this command confirmed to turn *on* led0
53 //at40k.iob_top(1, false).output(0);
55 for(int i=0; i<20; i++) {
56 at40k.iob_bot(i, false).output(0);
57 at40k.iob_bot(i, true).output(0);
61 //System.out.println("tick");
63 //System.out.println("tick");
64 //at40k.cell(0x01, 0x17).xlut((byte)0x);
67 System.out.println(Integer.toString(0xff & at40k.cell(0x01, 0x17).xlut(), 16));
68 System.out.println(Integer.toString(0xff & at40k.cell(0x01, 0x17).ylut(), 16));
69 at40k.cell(0x01, 0x17).ylut((byte)0xff);
72 //at40k.cell(0x01, 0x17).wi(L1);
74 System.out.println("a: " + at40k.new SectorWire(true, 0, 4, 0x17).driverRight());
75 System.out.println("b: " + at40k.new SectorWire(true, 1, 4, 0x17).driverRight());
76 At40k.SectorWire h0p0 = at40k.new SectorWire(true, 0, 0, 0x17);
77 At40k.SectorWire h0p1 = at40k.new SectorWire(true, 1, 0, 0x17);
78 At40k.SectorWire h0p2 = at40k.new SectorWire(true, 2, 0, 0x17);
79 At40k.SectorWire h4p0 = at40k.new SectorWire(true, 0, 4, 0x17);
80 At40k.SectorWire h4p1 = at40k.new SectorWire(true, 1, 4, 0x17);
81 At40k.SectorWire h4p2 = at40k.new SectorWire(true, 2, 4, 0x17);
83 //h4p1.drives(h0p1, false);
84 //at40k.cell(0x04, 0x17).out(L1, false);
85 //at40k.cell(0x04, 0x17).h(L0, false);
87 for(int plane=0; plane<5; plane++) {
88 at40k.new SectorWire(true, plane, 4, 0x17).drives(at40k.new SectorWire(true, plane, 0, 0x17), false);
89 at40k.cell(0x04, 0x17).out(plane, false);
90 at40k.cell(0x04, 0x17).h(plane, false);
91 at40k.cell(0x01, 0x17).h(plane, false);
93 try { Thread.sleep(2000); } catch (Exception e) { }
96 at40k.new SectorWire(true, plane, 4, 0x17).drives(at40k.new SectorWire(true, plane, 0, 0x17), true);
97 at40k.cell(0x04, 0x17).out(plane, true);
98 at40k.cell(0x04, 0x17).h(plane, true);
99 at40k.cell(0x01, 0x17).h(plane, true);
100 at40k.cell(0x01, 0x17).wi(plane);
105 System.out.println("xlut is " + hex(at40k.cell(0x04, 0x17).xlut()));
106 System.out.println("ylut is " + hex(at40k.cell(0x04, 0x17).ylut()));
107 At40k.Cell cell = at40k.cell(0x04, 0x17);
110 System.out.println(cell.c());
117 //cell.t(false, false, true);
118 cell.t(false, true, false);
129 for(int i=3; i>=1; i--) {
130 at40k.cell(i, 0x17).yi(EAST);
131 at40k.cell(i, 0x17).ylut(0x55);
132 at40k.cell(i, 0x17).yo(false);
136 //System.out.println("reading port status: " + Integer.toString(device.readBus() & 0xff, 16));
141 at40k.cell(23, 8).ylut(0xff);
142 at40k.cell(23, 11).ylut(0xff);
143 at40k.iob_right(8, true).enableOutput();
144 at40k.iob_right(11, true).enableOutput();
146 //for(int x=4; x<=22; x++) swap(at40k.cell(x, 22), NW, NORTH);
149 // entry cell: just copy X->X Y->Y
150 //at40k.cell(4,23).b(false);
151 //at40k.cell(4,23).yo(false);
152 //at40k.cell(4,23).ylut(at40k.cell(4,23).xlut());
153 //at40k.cell(4,23).xo(false);
155 at40k.cell(4,23).xlut(0x55);
156 at40k.cell(4,23).ylut(0x55);
159 at40k.cell(4,23).xlut(0x71);
160 at40k.cell(4,23).ylut(0x44);
161 at40k.cell(4,23).c(YLUT);
162 at40k.cell(4,23).f(false);
163 at40k.cell(4,23).t(false, false, true);
166 //for(int x=6; x<=23; x++) copy(at40k.cell(x, 23), NW, WEST); // top row copies to the right
168 copy(at40k.cell(5, 22), NW, NORTH);
169 for(int x=6; x<=22; x++) copy(at40k.cell(x, 22), NW, WEST); // second top row copies to the right
170 //for(int y=22; y>=10; y--) copy(at40k.cell(23, y), NW, NORTH); // right edge copies down
171 for(int y=21; y>=9; y--) copy(at40k.cell(22, y), NW, NORTH); // second right edge copies down
172 copy(at40k.cell(23, 9), NW, WEST); // second output
175 handshaker(at40k.cell(4,23));
176 at40k.cell(4,23).xi(NW);
177 at40k.cell(4,23).yi(SOUTH);
179 //handshaker(at40k.cell(5,23));
180 //at40k.cell(5,23).yi(NORTH);
182 at40k.cell(5,23).yi(NORTH);
183 at40k.cell(5,23).xlut(0x55);
184 at40k.cell(5,23).xi(SW);
185 at40k.cell(5,23).ylut(0x55);
186 at40k.cell(5,22).yi(NORTH);
187 at40k.cell(5,22).xlut(0x55);
189 bounce(at40k.cell(4,22));
191 // cell southeast of entry cell
192 at40k.cell(3,22).xi(NE); // NW->xin
193 at40k.cell(3,22).ylut(0x33); // xin->y
194 at40k.cell(3,22).yo(false); // y->yout
195 copy(at40k.cell(3, 21), NW, NORTH); // second top row copies to the right
196 copy(at40k.cell(4, 21), NW, EAST); // second top row copies to the right
197 copy(at40k.cell(5, 21), NW, EAST); // second top row copies to the right
198 copy(at40k.cell(6, 21), NW, EAST); // second top row copies to the right
199 copy(at40k.cell(6, 22), NW, SOUTH); // second top row copies to the right
202 at40k.cell(05,22).xlut(0xff);
203 at40k.cell(05,22).ylut(0xff);
204 at40k.cell(05,22).c(XLUT);
205 at40k.cell(05,22).f(false);
206 at40k.cell(05,22).b(false);
207 at40k.cell(05,22).oe(NONE);
208 at40k.cell(05,22).v(L3, true);
209 at40k.cell(05,22).out(L3, true);
212 at40k.cell(4,23).ylut(~0xCC);
213 at40k.cell(4,23).xlut(~0xAA);
214 at40k.cell(5,23).ylut(~0xAA);
215 at40k.cell(5,23).xlut(~0xAA);
216 for(int i=6; i<PIPELEN+2; i++) {
217 at40k.cell(i, 23).ylut(0xAA);
218 at40k.cell(i, 23).xlut(0xCC);
219 at40k.cell(i, 23).yi(WEST);
224 System.out.println("doit");
225 if (mullers) doitx(at40k, device);
226 //System.out.println("counter");
227 //counter(at40k, device);
229 at40k.cell(21,15).yi(WEST);
230 at40k.cell(21,15).ylut(0xAA);
232 at40k.cell(22,15).yi(WEST);
233 at40k.cell(22,15).ylut(0xAA);
235 at40k.cell(23,15).h(3, true);
236 at40k.cell(23,15).yi(L3);
237 at40k.cell(23,15).ylut(0xAA);
238 at40k.iob_right(15, true).enableOutput(WEST);
241 At40k.Cell c = at40k.cell(10,10);
248 copy(c.west(), EAST, NW);
249 copy(c.west().north().west(), SE, SE);
258 copy(c.east(), WEST, SE);
259 copy(c.east().south().east(), NW, NW);
262 copy(c.north(), SOUTH, SOUTH);
263 c.xlut((LUT_SELF & ~LUT_OTHER) | LUT_Z);
277 copy(c.north(), SOUTH, SOUTH);
278 c.xlut((LUT_SELF & ~LUT_OTHER) | LUT_Z);
299 c.hwire(L4).west().drives(c.hwire(L4), false);
300 c.hwire(L4).east().drives(c.hwire(L4), false);
311 c.hwire(L4).west().drives(c.hwire(L4), false);
312 c.hwire(L4).east().drives(c.hwire(L4), false);
316 copy(c.south(), NORTH, NORTH);
317 c.xlut(((~LUT_SELF) & (~LUT_OTHER)) | LUT_Z);
331 copy(c.south(), NORTH, NORTH);
332 c.xlut((LUT_SELF & LUT_OTHER) | LUT_Z);
346 // catch a rising transition
357 c.hwire(L2).west().drives(c.hwire(L2), false);
358 c.hwire(L2).east().drives(c.hwire(L2), false);
364 c = at40k.cell(20,20);
374 c = at40k.cell(21,20);
405 at40k.cell(9,10).xo(true);
406 at40k.cell(9,10).yo(true);
407 at40k.cell(9,10).c(YLUT);
408 at40k.cell(9,10).b(false);
410 //for(int x=5; x<PIPELEN; x++) {
411 //at40k.cell(x,23).hwire(L0).drives(at40k.cell(x,23).hwire(L0).east());
415 at40k.cell(22,11).ylut(0xff);
416 at40k.cell(23,11).yi(L3);
417 //at40k.cell(23,11).yi(WEST);
418 //at40k.cell(23,11).xi(L1);
419 at40k.cell(23,11).ylut(0xAA);
420 at40k.iob_right(11, true).enableOutput(WEST);
421 at40k.cell(23,11).v(L3, true);
422 at40k.cell(23,11).yo(false);
428 System.out.println("correct: " + at40k.cell(19,15).hwire(L3) + " drives " + at40k.cell(20,15).hwire(L3));
429 System.out.println("correct: " + at40k.cell(15,15).hwire(L3) + " drives " + at40k.cell(19,15).hwire(L3));
430 System.out.println("correct: " + at40k.cell(11,15).hwire(L3) + " drives " + at40k.cell(15,15).hwire(L3));
431 System.out.println("correct: " + at40k.cell(07,15).hwire(L3) + " drives " + at40k.cell(11,15).hwire(L3));
433 at40k.cell(19,15).hwire(L3).drives(at40k.cell(20,15).hwire(L3), true);
434 at40k.cell(15,15).hwire(L3).drives(at40k.cell(19,15).hwire(L3), true);
435 at40k.cell(11,15).hwire(L3).drives(at40k.cell(15,15).hwire(L3), true);
436 at40k.cell(07,15).hwire(L3).drives(at40k.cell(11,15).hwire(L3), true);
438 //at40k.cell(05,vv).xlut(0xff);
439 //at40k.cell(05,vv).ylut(0xff);
441 at40k.cell(vx,vv).c(YLUT);
442 at40k.cell(vx,vv).f(false);
443 at40k.cell(vx,vv).b(false);
444 at40k.cell(vx,vv).oe(NONE);
445 at40k.cell(vx,vv).v(L3, true);
446 at40k.cell(vx,vv).out(L3, true);
449 at40k.cell(vx,15).v(L3, true);
450 at40k.cell(vx,15).h(L3, true);
451 at40k.cell(vx,19).vwire(L3).drives(at40k.cell(vx,15).vwire(L3), true);
452 at40k.cell(vx,23).vwire(L3).drives(at40k.cell(vx,19).vwire(L3), true);
455 //at40k.cell(5,23).ylut(0x00);
456 //at40k.cell(6,22).ylut(0xff);
457 //at40k.cell(22,11).ylut(0xff);
459 At40k.Cell cell = at40k.cell(4, 16);
470 //scan(at40k, cell, YLUT, true);
471 //scan(at40k, cell, YLUT, false);
473 //device.scanFPGA(true);
475 at40k.cell(10,10).f(true);
476 at40k.cell(10,10).c(ZMUX);
478 at40k.cell(8,7).xlut(LUT_SELF);
479 at40k.cell(8,7).xi(NW);
481 at40k.cell(7,8).xlut(LUT_SELF & LUT_Z);
482 at40k.cell(7,8).xi(SE);
483 at40k.cell(7,8).c(XLUT);
484 at40k.cell(7,8).f(false);
485 at40k.cell(7,8).b(false);
486 at40k.cell(7,8).t(TMUX_FB);
487 at40k.cell(7,8).xo(false);
488 System.out.println(at40k.cell(7,8).fb_relevant());
490 at40k.cell(6,13).xi(SE);
491 at40k.cell(6,13).c(ZMUX);
492 at40k.cell(6,13).xlut(LUT_SELF);
493 at40k.cell(6,13).ylut(LUT_OTHER);
494 at40k.cell(6,13).xo(false);
495 at40k.cell(6,13).yo(false);
496 at40k.cell(7,12).xi(SE);
498 for(int i=0; i<24; i++) {
499 at40k.iob_bot(i, true).enableOutput(NORTH);
500 at40k.iob_bot(i, false).enableOutput(NW);
501 at40k.cell(i, 0).xlut(0xff);
502 at40k.cell(i, 0).ylut(0xff);
507 Gui vis = new Gui(at40k, device);
508 Frame fr = new Frame();
509 fr.addKeyListener(vis);
510 fr.setLayout(new BorderLayout());
511 fr.add(vis, BorderLayout.CENTER);
513 fr.setSize(900, 900);
517 synchronized(AtmelSerial.class) { AtmelSerial.class.wait(); }
521 Visualizer v = new Visualizer(at40k, device);
523 v.setSize(1380, 1080);
524 At40k.Cell cell = at40k.cell(4, 23);
526 Image img = v.createImage(v.getWidth(), v.getHeight());
530 cell = at40k.cell(x,y);
531 scan(at40k, cell, YLUT, true);
541 //selfTest(device, at40k, v);
542 System.out.println("save: " + AvrDrone.save + " of " + (AvrDrone.saveof*5));
544 at40k.iob_top(0, true).enableInput();
545 copy(at40k.cell(0, 23), NORTH, NORTH);
546 at40k.iob_bot(0, true).enableOutput(NORTH);
548 for(int i=0; i<10000; i++) {
550 try { Thread.sleep(100); } catch (Exception e) { }
554 //at40k.cell(0x01, 0x17).h(0, false);
555 //at40k.cell(0x01, 0x17).xi(NE);
556 //at40k.cell(0x01, 0x17).ylut((byte)0x55);
558 //at40k.cell(0x04, 0x17).xlut((byte)0x10);
559 //at40k.cell(0x04, 0x17).ylut((byte)0x10);
560 //at40k.cell(0x04, 0x17).yo(false);
561 //at40k.cell(0x04, 0x17).xo();
564 at40k.cell(0x01, 0x17).xi(L0);
565 at40k.cell(0x01, 0x17).h(L0, true);
568 at40k.cell(0x03, 0x17).xlut((byte)0x55);
569 at40k.cell(0x03, 0x17).ylut((byte)0x55);
570 at40k.cell(0x03, 0x17).yi(EAST);
571 at40k.cell(0x03, 0x17).ylut((byte)0x55);
572 at40k.cell(0x03, 0x17).yo(true);
574 at40k.cell(0x03, 0x17).f(false);
575 at40k.cell(0x03, 0x17).c(XLUT);
576 at40k.cell(0x03, 0x17).oe(NONE);
577 at40k.cell(0x03, 0x17).out(L0, true);
579 at40k.cell(0x02, 0x17).yi(EAST);
580 at40k.cell(0x02, 0x17).ylut((byte)0x55);
581 at40k.cell(0x02, 0x17).yo(false);
583 at40k.cell(0x01, 0x17).yi(EAST);
584 at40k.cell(0x01, 0x17).ylut((byte)0x55);
585 at40k.cell(0x01, 0x17).yo(false);
587 at40k.cell(0x01, 0x17).h(L0, true);
588 at40k.cell(0x01, 0x17).v(L0, false);
590 //at40k.cell(0x01, 0x17).yi(L0);
591 //at40k.cell(0x01, 0x17).xi(L0);
592 //at40k.cell(0x01, 0x17).ylut((byte)0x33);
595 at40k.cell(0x03, 0x17).h(L0, true);
596 at40k.cell(0x03, 0x17).out(L0, true);
597 at40k.cell(0x03, 0x17).c(XLUT);
598 at40k.cell(0x03, 0x17).f(false);
601 at40k.cell(0x01, 0x17).xin(4);
602 at40k.cell(0x01, 0x17).yin(4);
603 at40k.cell(0x01, 0x16).ylut((byte)0x00);
604 device.mode4(2, 0x17, 0x01, 0);
606 for(int i=0; i<10; i++) {
608 System.out.println("tick");
609 //at40k.cell(0x01, 0x17).xlut((byte)0xFF);
610 at40k.cell(0x00, 0x17).ylut((byte)0x00);
613 System.out.println("tick");
614 //at40k.cell(0x01, 0x17).xlut((byte)0x00);
615 at40k.cell(0x00, 0x17).ylut((byte)0xFF);
622 at40k.iob_top(0, true).output(0);
623 at40k.iob_top(0, true).oe(false);
624 at40k.iob_top(0, true).pullup();
628 Log.info(AtmelSerial.class, "issuing command");
629 at40k.iob_top(1, true).pulldown();
632 Log.info(AtmelSerial.class, "done");
634 } catch (Exception e) { e.printStackTrace(); }
637 public static void scan(At40k dev, At40k.Cell cell, int source, boolean setup) {
639 if (source != NONE) cell.c(source);
640 if (cell.b()) cell.b(false);
641 if (cell.f()) cell.f(false);
643 if (cell.out(L3)!=setup) cell.out(L3, setup);
644 if (cell.vx(L3)!=setup) cell.v(L3, setup);
646 At40k.SectorWire sw = cell.vwire(L3);
647 //System.out.println("wire is: " + sw);
649 if (sw.row > (12 & ~0x3) && sw.north()!=null && sw.north().drives(sw))
650 sw.north().drives(sw, false);
651 while(sw.row > (12 & ~0x3) && sw.south() != null) {
652 //System.out.println(sw + " -> " + sw.south());
653 if (sw.drives(sw.south())!=setup) sw.drives(sw.south(), setup);
656 if (sw.row < (12 & ~0x3) && sw.south() != null && sw.south().drives(sw))
657 sw.north().drives(sw, false);
658 while(sw.row < (12 & ~0x3) && sw.north() != null) {
659 //System.out.println(sw + " -> " + sw.north());
660 if (sw.drives(sw.north())!=setup) sw.drives(sw.north(), setup);
664 //cell = dev.cell(19, 15);
665 cell = dev.cell(cell.col, 15);
667 System.out.println("cell is " + cell);
676 if (cell.hx(L3) != setup) cell.h(L3, setup);
677 if (cell.vx(L3) != setup) cell.v(L3, setup);
680 if (sw.west()!=null && sw.west().drives(sw)) { sw.west().drives(sw, false); }
681 while(sw.east() != null) {
682 //System.out.println(sw + " -> " + sw.east());
683 if (sw.drives(sw.east())!=setup) sw.drives(sw.east(), setup);
689 public static void copy(At40k.Cell c, int xdir, int ydir) {
691 case NW: case NE: case SW: case SE: {
696 case NORTH: case SOUTH: case EAST: case WEST: {
702 default: throw new Error();
705 case NW: case NE: case SW: case SE: {
710 case NORTH: case SOUTH: case EAST: case WEST: {
716 default: throw new Error();
721 public static String hex(int x) {
722 return Long.toString(x & 0xffffffffL, 16);
725 public static void handshaker(At40k.Cell cell) {
730 cell.t(false, false, true);
733 public static class Visualizer extends Frame implements KeyListener, MouseMotionListener, MouseListener {
734 public static final int WIDTH = 40;
735 public static final int HEIGHT = 40;
736 public static final int LW = 15;
737 public static final int LH = 15;
738 public static final Color RED = new Color(0xaa, 0x55, 0x55);
739 public static final Color BLUE = new Color(0x55, 0x55, 0xaa);
740 private final At40k dev;
741 private final AvrDrone drone;
744 public Visualizer(final At40k dev, final AvrDrone drone) {
748 addMouseMotionListener(this);
749 addMouseListener(this);
750 addKeyListener(this);
756 if (!enabled) continue;
758 At40k.Cell cell = dev.cell(21, 22);
768 } catch (Exception e) {
774 public boolean enabled = false;
775 public void mouseClicked(MouseEvent e) { }
776 public void mouseEntered(MouseEvent e) { }
777 public void mouseExited(MouseEvent e) { }
778 public void mouseReleased(MouseEvent e) {
780 public void keyTyped(KeyEvent k) {
782 public void keyReleased(KeyEvent k) {
784 public void keyPressed(KeyEvent keyevent) {
785 boolean scan = false;
786 switch(keyevent==null ? '_' : keyevent.getKeyChar()) {
788 if (selx==-1 || sely==-1) break;
789 At40k.Cell cell = dev.cell(selx, sely);
792 drawCell(getGraphics(), selx, sely);
797 System.out.println("interrupt_count: " + drone.readCount());
805 System.out.println("low => " + mx);
806 copy(dev.cell(mx, yofs-2), NORTH, NORTH);
807 copy(dev.cell(mx, yofs-3), NORTH, NORTH);
808 //dev.cell(mx, yofs-3).ylut(~dev.cell(mx, yofs-3).ylut());
809 //dev.cell(mx, yofs-3).xlut(~dev.cell(mx, yofs-3).xlut());
811 int mx = 23-(masterx-23);
812 System.out.println("high => " + mx);
813 copy(dev.cell(mx, yofs), NW, NW);//NORTH, NORTH);
814 copy(dev.cell(mx, yofs-1), NORTH, NORTH);
815 //for(int x=mx-1; x>=1; x--)
816 //copy(dev.cell(x, yofs), EAST, EAST);
817 for(int y=yofs+1; y<=23; y++)
818 copy(dev.cell(1, y), SOUTH, SOUTH);
819 //dev.cell(mx, yofs-1).ylut(~dev.cell(mx, yofs-1).ylut());
820 //dev.cell(mx, yofs-1).xlut(~dev.cell(mx, yofs-1).xlut());
825 System.out.println("low => " + mx);
826 copy(dev.cell(mx, yofs-2), SOUTH, SOUTH);
827 copy(dev.cell(mx, yofs-3), NORTH, NORTH);
828 dev.cell(mx, yofs-3).ylut(~dev.cell(mx, yofs-3).ylut());
829 dev.cell(mx, yofs-3).xlut(~dev.cell(mx, yofs-3).xlut());
831 int mx = 23-(masterx-23);
832 System.out.println("high => " + mx);
833 copy(dev.cell(mx, yofs), SOUTH, SOUTH);
835 copy(dev.cell(mx, yofs-1), NORTH, NORTH);
837 copy(dev.cell(mx, yofs-1), NORTH, SW);
839 At40k.Cell lc = null;
840 for(int k=0; k<10; k++) {
841 int y = yofs-2-(k*2);
842 copy(dev.cell(left?(mx-1):mx, y), SOUTH, left?NE:NW);
843 copy(lc = dev.cell(left?(mx-1):mx, y-1), NORTH, left?SE:SW);
846 copy(lc, NORTH, NORTH);
848 //for(int x=mx-1; x>=1; x--)
849 //copy(dev.cell(x, yofs), EAST, EAST);
850 //for(int y=yofs+1; y<=23; y++)
851 //copy(dev.cell(1, y), SOUTH, SOUTH);
854 dev.cell(mx+2, yofs).ylut(0x00);
855 dev.cell(mx+2, yofs).xlut(0x00);
859 dev.cell(mx, yofs-1).ylut(~LUT_Z);
860 dev.cell(mx, yofs-1).xlut(LUT_Z);
861 loopback(dev.cell(mx, yofs-1), YLUT);
863 dev.cell(mx, yofs).ylut(~LUT_SELF);
864 dev.cell(mx, yofs).xlut(~LUT_OTHER);
870 //enabled = !enabled;
875 //enabled = !enabled;
877 for(int cap=0; cap<15; cap++) {
879 try { Thread.sleep(100); } catch (Exception e) { }
880 //showit(dev, drone, this);
881 fill(dev, drone, cap);
883 long now = System.currentTimeMillis();
884 try { Thread.sleep(4000); } catch (Exception e) { }
885 int count = drone.readCount();
886 long now2 = System.currentTimeMillis();
887 System.out.println(cap + " , " + (((float)count * (2*2*2*2*2*2*2*2*2*1000))/(now2-now)));
889 } catch (Exception e) { e.printStackTrace(); }
893 if (selx==-1 || sely==-1) break;
894 At40k.Cell cell = dev.cell(selx, sely);
896 drawCell(getGraphics(), selx, sely);
900 if (selx==-1 || sely==-1) break;
901 At40k.Cell cell = dev.cell(selx, sely);
904 drawCell(getGraphics(), selx, sely);
910 showit(dev, drone, this);
912 public void mousePressed(MouseEvent e) {
913 final At40k.Cell cell = dev.cell(selx, sely);
914 if (cell==null) return;
915 final int old = cell.c();
916 AvrDrone.ByteCallback bc = new AvrDrone.ByteCallback() {
917 public void call(byte b) throws Exception {
918 boolean y = (b & 0x80) != 0;
920 Graphics g = getGraphics();
921 g.setFont(new Font("sansserif", Font.BOLD, 14));
922 g.setColor(Color.white);
923 //g.drawString("X=0", left(cell) + 10, top(cell) + 20);
924 //g.drawString("X=1", left(cell) + 10, top(cell) + 20);
925 //g.setColor(Color.white);
926 //g.drawString("Y=0", left(cell) + 8, top(cell) + 35);
927 //g.drawString("Y=1", left(cell) + 8, top(cell) + 35);
929 //g.drawString("X="+(x?"1":"0"), left(cell) + 10, top(cell) + 20);
930 String v = (cell.c()==YLUT ? "Y" : cell.c()==XLUT ? "X" : "C");
931 g.drawString(v+"="+(y?"0":"1"), left(cell) + 8, top(cell) + 35);
933 g.drawString(v+"="+(y?"1":"0"), left(cell) + 8, top(cell) + 35);
936 scan(dev, cell, NONE, true);
938 //scan(dev, cell, XLUT, true);
939 //boolean x = (drone.readBus() & 0x80) != 0;
940 scan(dev, cell, NONE, false);
941 } catch (IOException ex) {
942 throw new RuntimeException(ex);
946 public void mouseMoved(MouseEvent e) {
949 if (selx >= 0 && selx < 24 && sely >= 0 && sely < 24) {
952 At40k.Cell cell = dev.cell(cx, cy);
956 drawCell(getGraphics(), cx, cy);
957 drawSector(getGraphics(), dev.cell(cx, cy).sector());
960 selx = (x-20)/(WIDTH+2);
961 sely = (23 - (y-20)/(HEIGHT+2))+1;
963 At40k.Cell cell = dev.cell(selx, sely);
964 if (selx >= 0 && selx < 24 && sely >= 0 && sely < 24) {
965 drawCell(getGraphics(), selx, sely);
966 drawSector(getGraphics(), dev.cell(selx, sely).sector());
970 public void mouseDragged(MouseEvent e) { mousePressed(e); }
971 public void paint(Graphics g) {
972 System.out.println("paintall");
973 g.setColor(Color.white);
974 g.fillRect(0, 0, getWidth(), getHeight());
975 g.setFont(new Font("sansserif", Font.BOLD, 24));
976 for(int x=0; x<24; x++)
977 for(int y=0; y<24; y++)
979 for(int x=0; x<=23; x+=4)
980 for(int y=23; y>=0; y-=4)
981 drawSector(g, dev.cell(x, y).sector());
984 g.drawString("Ready", (5*(WIDTH+2))+20, 40);
986 g.drawString("Send", (3*(WIDTH+2))+20, 40);
991 public void refresh() {
992 Graphics g = getGraphics();
994 int data = drone.readBus() & 0xff;
995 for(int i=0; i<8; i++) {
996 g.setColor((data & (1<<i))==0 ? Color.black : Color.green);
997 g.drawString("D"+i, (24*(WIDTH+2))+20, ((23-(i+7))*(HEIGHT+2))+60-HEIGHT/2);
1001 public static int left(At40k.Cell cell) { return (cell.col) *(WIDTH+2)+20; }
1002 public static int top(At40k.Cell cell) { return (23-cell.row)*(HEIGHT+2)+60; }
1003 public void drawSector(Graphics g, At40k.Sector sector) {
1004 g.setColor(Color.gray);
1005 ((Graphics2D)g).setStroke(new BasicStroke(1));
1006 int px = ((sector.col)*(WIDTH+2))+20-1;
1007 int py = ((23-(sector.row+3))*(HEIGHT+2))+60-1;
1008 g.drawRect(px, py, (WIDTH+2)*4+2, (HEIGHT+2)*4+2);
1010 for(int dir=0; dir<2; dir++) {
1012 for(int y=h?sector.row:sector.col; y<(h?sector.row+4:sector.col+4); y++)
1013 for(int plane=0; plane<=4; plane++) {
1014 At40k.Cell cell = h ? dev.cell(sector.col, y) : dev.cell(y, sector.row);
1015 At40k.Cell cell_east = h ? dev.cell(sector.col-1, y) : dev.cell(y, sector.row-1);
1016 At40k.Cell cell_west = h ? dev.cell(sector.col+4, y) : dev.cell(y, sector.row+4);
1017 boolean draw = false;
1019 if (cell_east!=null &&
1020 (cell_east.hwire(plane).drives(cell.hwire(plane)) ||
1021 cell_east.hwire(plane).drives(cell.hwire(plane))))
1023 if (cell_west!=null &&
1024 (cell_west.hwire(plane).drives(cell.hwire(plane)) ||
1025 cell_west.hwire(plane).drives(cell.hwire(plane))))
1028 if (cell_east!=null &&
1029 (cell_east.vwire(plane).drives(cell.vwire(plane)) ||
1030 cell_east.vwire(plane).drives(cell.vwire(plane))))
1032 if (cell_west!=null &&
1033 (cell_west.vwire(plane).drives(cell.vwire(plane)) ||
1034 cell_west.vwire(plane).drives(cell.vwire(plane))))
1038 for(int x=h?sector.col:sector.row; x<(h?sector.col+4:sector.row+4); x++)
1039 if (((h ? dev.cell(x,y).hx(plane) : dev.cell(y,x).vx(plane))) ||
1040 (h?dev.cell(x,y).out(plane):dev.cell(y,x).out(plane)))
1043 g.setColor(new Color(0xff, 0x00, 0xff));
1045 g.drawLine(left(cell),
1047 left(cell) + 4*(WIDTH+2),
1051 g.drawLine(left(cell)+3,
1052 top(cell) + (HEIGHT+2),
1054 top(cell) - 3*(HEIGHT+2)
1062 public void drawCell(Graphics g, int cx, int cy) {
1063 int x = (cx*(WIDTH+2))+20;
1064 int y = ((23-cy)*(HEIGHT+2))+60;
1065 if (g.getClipBounds() != null && !g.getClipBounds().intersects(new Rectangle(x, y, x+WIDTH, y+HEIGHT))) return;
1066 drawCell(g, cx, cy, Color.white);
1068 public void drawCell(Graphics g, int cx, int cy, Color bg) {
1069 int x = (cx*(WIDTH+2))+20;
1070 int y = ((23-cy)*(HEIGHT+2))+60;
1072 //System.out.println("drawcell " + cx + "," + cy);
1073 At40k.Cell cell = dev.cell(cx, cy);
1075 g.fillRect(x, y, WIDTH, HEIGHT);
1077 g.setColor((selx==cx && sely==cy) ? Color.red : Color.black);
1078 g.drawRect(x, y, WIDTH, HEIGHT);
1080 //g.setColor((selx==cx && sely==cy) ? Color.red : Color.gray);
1081 //g.drawRect(x+(WIDTH-(LW*2))/2-1, y+(HEIGHT-LW)/2-1, LW*2+1, LH+1);
1084 //g.fillRect(x+(WIDTH-(LW*2))/2, y+(HEIGHT-LW)/2, LW, LH);
1085 //g.setColor(Color.white);
1086 //g.drawString("1", x+(WIDTH-(LW*2))/2, y+(HEIGHT-LW)/2);
1089 //g.fillRect(x+(WIDTH-(LW*2))/2+LW, y+(HEIGHT-LW)/2, LW, LH);
1090 //g.setColor(Color.white);
1091 //g.drawString("0", x+(WIDTH-(LW*2))/2+LW, y+(HEIGHT-LW)/2);
1095 ((Graphics2D)g).setStroke(new BasicStroke((float)1));
1097 case NORTH: g.drawLine(x+WIDTH/2+5, y-10, x+WIDTH/2+5, y+HEIGHT/2); break;
1098 case SOUTH: g.drawLine(x+WIDTH/2-5, y+HEIGHT+10, x+WIDTH/2-5, y+HEIGHT/2); break;
1099 case EAST: g.drawLine(x+WIDTH+10, y+HEIGHT/2+5, x+WIDTH/2, y+HEIGHT/2+5); break;
1100 case WEST: g.drawLine(x-10, y+HEIGHT/2-5, x+WIDTH/2, y+HEIGHT/2-5); break;
1104 ((Graphics2D)g).setStroke(new BasicStroke((float)1));
1106 case NW: g.drawLine(x-10+3, y-10, x+WIDTH/2+3, y+HEIGHT/2); break;
1107 case SW: g.drawLine(x-10-3, y+HEIGHT+10, x+WIDTH/2-3, y+HEIGHT/2); break;
1108 case NE: g.drawLine(x+WIDTH+10+3, y-10, x+WIDTH/2+3, y+HEIGHT/2); break;
1109 case SE: g.drawLine(x+WIDTH+10-3, y+HEIGHT+10, x+WIDTH/2-3, y+HEIGHT/2); break;
1112 ((Graphics2D)g).setStroke(new BasicStroke(1));
1115 if (selx==cx && sely==cy) {
1116 int xp = 23 * (WIDTH+2) + 100;
1118 g.setColor(Color.white);
1119 g.fillRect(xp, yp, 300, 1000);
1120 g.setColor(Color.black);
1121 g.drawString("Cell " + cx + "," + cy, xp, (yp+=15));
1122 //g.drawString("X-Lut: " + bin8(cell.xlut()), xp, (yp+=15));
1123 g.drawString("X-Lut: " + cell.printXLut(), xp, (yp+=15));
1124 //g.drawString("Y-Lut: " + bin8(cell.ylut()), xp, (yp+=15));
1125 g.drawString("Y-Lut: " + cell.printYLutX(), xp, (yp+=15));
1128 if ((cell.ylut()&0xff)==0xff && (cell.xlut()&0xff)==0xff) {
1129 g.setColor(new Color(0x00, 0x00, 0xff));
1130 g.drawString("1", left(cell) + 12, top(cell) + 30);
1132 if ((cell.ylut()&0xff)==0x00 && (cell.xlut()&0xff)==0x00) {
1133 g.setColor(new Color(0x00, 0x00, 0xff));
1134 g.drawString("0", left(cell) + 12, top(cell) + 30);
1136 if ((cell.ylut()&0xff)==0xB2) {
1137 //System.out.println("muller @ " + cell);
1139 //g.drawString("X="+(x?"1":"0"), left(cell) + 10, top(cell) + 20);
1140 g.setColor(new Color(0x00, 0xaa, 0x00));
1141 g.drawString("C", left(cell) + 12, top(cell) + 30);
1147 private static String pad(int i, String s) { if (s.length()>i) return s; return "0"+pad((i-1),s); }
1148 public static String bin8(byte b) {
1151 for(int i=7; i>=0; i--)
1152 ret += (n & (1<<i))==0 ? "0" : "1";
1156 public static void selfTest(AvrDrone device, At40k at40k, Visualizer v) {
1159 long now = System.currentTimeMillis();
1160 for(int x=0; x<24; x++)
1161 for(int y=0; y<24; y++) {
1162 At40k.Cell cell = at40k.cell(x,y);
1163 scan(at40k, cell, YLUT, true);
1164 //v.paint(img.getGraphics());
1165 //v.getGraphics().drawImage(img, 0, 0, null);
1167 boolean a = (device.readBus() & 0x80)!=0;
1169 boolean b = (device.readBus() & 0x80)!=0;
1171 //System.out.println("pass " + x+","+y);
1172 Graphics g = v.getGraphics();
1173 g.setColor(Color.green);
1174 g.drawString("pass", v.left(cell) + 10, v.top(cell) + 20);
1176 System.out.println("FAIL!!!! " + x+","+y+" => " + a + " " + b);
1178 Graphics g = v.getGraphics();
1179 g.setColor(Color.red);
1180 g.drawString("FAIL", v.left(cell) + 10, v.top(cell) + 20);
1182 scan(at40k, cell, YLUT, false);
1185 System.out.println("failures: " + fail);
1186 System.out.println("scan time: " + (System.currentTimeMillis()-now) + "ms");
1190 public static void bounce(At40k.Cell cell, int xi, int yi) {
1191 cell.xlut((byte)0xCC);
1192 cell.ylut((byte)0xCC);
1198 public static void muller(At40k.Cell cell, int xi, int yi) {
1202 cell.t(false, false, true);
1209 /** watches for a rising/falling edge on Yin, emits a pulse on Xout */
1210 public static void pulse_detect(At40k.Cell c, int in, boolean falling) {
1214 case NW: case NE: case SW: case SE: {
1217 if (!falling) c.ylut(lutSwap(0x0C)); /* x & !z */
1218 else c.ylut(lutSwap(0x30)); /* !x & z */
1222 case NORTH: case SOUTH: case EAST: case WEST: {
1225 if (!falling) c.xlut(0x0C); /* y & !z */
1226 else c.xlut(0x30); /* !y & z */
1230 default: throw new Error();
1234 /** watches for a pulse on Xin, copies value of Yin */
1235 public static void pulse_copy(At40k.Cell cell, int xi, int yi, boolean invert) {
1236 loopback(cell, YLUT);
1237 if (!invert) cell.ylut(0xB8); /* yo = x ? yi : z => 1011 1000 */
1238 else cell.ylut(0x74); /* yo = x ? !yi : z => 0111 0100 */
1239 if (!invert) cell.xlut(lutSwap(0xB8)); /* yo = x ? yi : z => 1011 1000 */
1240 else cell.xlut(lutSwap(0x74)); /* yo = x ? !yi : z => 0111 0100 */
1245 public static void loopback(At40k.Cell cell, int cin) {
1248 cell.t(false, false, true);
1253 public static void doit(At40k at40k, AvrDrone device) throws Exception {
1255 At40k.Cell led = at40k.cell(1, 23);
1259 led.ylut(~LUT_SELF);
1263 At40k.Cell c = at40k.cell(1, 22);
1271 c.v(L0, /*false*/true);
1278 for(int i=0; i<4; i++) at40k.cell(i, 20).h(L0, false);
1279 At40k.Cell z = at40k.cell(1, 20);
1290 z.hwire(L0).east().drives(z.hwire(L0), false);
1291 z.hwire(L1).east().drives(z.hwire(L1), false);
1292 z.vwire(L0).south().drives(z.vwire(L0), false);
1293 z.vwire(L1).south().drives(z.vwire(L1), false);
1296 z = at40k.cell(0, 20);
1314 for(int y=20; y<=22; y++)
1315 for(int x=2; x<=5; x++) {
1316 c = at40k.cell(x, y);
1320 //c = at40k.cell(2, 22);
1324 c = at40k.cell(1, 21);
1338 c = at40k.cell(13, 22);
1339 c.xlut(LUT_OTHER | 0xF0);
1341 c.t(false, false, true);
1348 // this gate detects a rising edge on its Xin (delayed copy on Yin); when viewed, it inverts its state
1349 c = at40k.cell(14, 22);
1354 c.t(false, false, true);
1359 c.ylut(0xA6); // (x & !z) ? ~y : y
1362 c = at40k.cell(14, 20);
1365 c = at40k.cell(14, 21);
1369 c = at40k.cell(13, 22);
1371 c.xlut(LUT_OTHER);// | 0xF0);
1373 //c = at40k.cell(13, 22);
1374 //copy(c, NW, EAST);
1380 c.t(false, false, true);
1385 c.ylut(0x54); // (x || z) & !y
1389 c = at40k.cell(2, 21);
1394 c.t(false, false, true);
1401 //at40k.cell(2, 21).xlut(0xF0);
1403 at40k.cell(3, 22).ylut(LUT_OTHER);
1404 at40k.cell(3, 22).xi(SW);
1406 //at40k.iob_top(5, true).enableOutput(SOUTH);
1407 //at40k.iob_top(5, false).enableOutput(SE);
1410 public static int yofs = mullers ? 19 : 22;
1411 public static void counter(At40k at40k, AvrDrone device) throws Exception {
1412 // watch for rising edge from south, emit pulse on Xout (to NE)
1413 //copy(at40k.cell(16,23), SW, WEST);
1415 for(int x=22; x>=1; x-=2) {
1416 pulse_detect(at40k.cell(x, yofs), SE, false);
1417 pulse_detect(at40k.cell(x, yofs-1), EAST, true);
1418 pulse_copy(at40k.cell(x-1, yofs), SE, SOUTH, false);
1419 pulse_copy(at40k.cell(x-1, yofs-1), NE, NORTH, true);
1421 //pulse_detect(at40k.cell(15, 22), NORTH, false);
1422 //pulse_detect(at40k.cell(16, 22), NW, true);
1423 //pulse_copy(at40k.cell(16, 21), NW, WEST, false);
1424 //pulse_copy(at40k.cell(15, 21), NE, EAST, true);
1426 for(int x=23; x>1; x-=2) {
1427 pulse_detect(at40k.cell(x-1, yofs-2), SW, false);
1428 pulse_detect(at40k.cell(x-1, yofs-3), WEST, true);
1429 pulse_copy(at40k.cell(x, yofs-2), SW, SOUTH, false);
1430 pulse_copy(at40k.cell(x, yofs-3), NW, NORTH, true);
1432 //pulse_detect(at40k.cell(15, 22), NORTH, false);
1433 //pulse_detect(at40k.cell(16, 22), NW, true);
1434 //pulse_copy(at40k.cell(16, 21), NW, WEST, false);
1435 //pulse_copy(at40k.cell(15, 21), NE, EAST, true);
1437 copy(at40k.cell(1, yofs-2), SOUTH, SOUTH);
1438 copy(at40k.cell(1, yofs-3), NORTH, NORTH);
1439 at40k.cell(1, yofs-3).ylut(~at40k.cell(1, yofs-3).ylut());
1440 at40k.cell(1, yofs-3).xlut(~at40k.cell(1, yofs-3).xlut());
1442 copy(at40k.cell(23, yofs), SOUTH, SOUTH);
1443 copy(at40k.cell(23, yofs-1), SOUTH, SOUTH);
1445 for(int i=23; i>yofs; i--) copy(at40k.cell(1, i), SOUTH, SOUTH);
1447 //at40k.iob_top(1, true).slew(SLOW);
1448 //at40k.iob_top(1, false).slew(SLOW);
1451 public static void fill(At40k at40k, AvrDrone device, int num) throws Exception {
1452 //muller(at40k.cell(PIPELEN,22), NE, WEST);
1453 At40k.Cell a = at40k.cell(10,22);
1454 At40k.Cell b = at40k.cell(11,22);
1456 for(int i=0; i<num; i++) {
1457 //System.out.println(i);
1460 try { Thread.sleep(1); } catch (Exception e) { }
1463 try { Thread.sleep(1); } catch (Exception e) { }
1468 public static void showit(At40k dev, AvrDrone drone, final Visualizer vis) {
1469 final long then = System.currentTimeMillis();
1470 final Graphics g = vis.getGraphics();
1471 g.setFont(new Font("sansserif", Font.BOLD, 24));
1472 final Color red = new Color(0xff, 0x99, 0x99);
1473 final Color green = new Color(0x99, 0xff, 0x99);
1474 for(int xx=0; xx<=22; xx++) {
1475 for(int yy=23; yy>=0; yy--) {
1476 //for(int xx=5; xx<=PIPELEN-1; xx++) {
1477 //for(int yy=21; yy<=22; yy++) {
1480 final At40k.Cell cell = dev.cell(x, y);
1481 if ((cell.ylut()&0xff)!=0xB2) continue;
1482 AvrDrone.ByteCallback bc = new AvrDrone.ByteCallback() {
1483 public void call(byte b) throws Exception {
1484 boolean v = (b & 0x80) != 0;
1485 vis.drawCell(g, x, y, v?red:green);
1486 //if (x==PIPELEN-1 && y==22) System.out.println("time: " + (System.currentTimeMillis()-then));
1489 scan(dev, cell, NONE, true);
1492 //scan(dev, cell, YLUT, false);
1494 dev.cell(x, 15).h(L3, false);
1495 dev.cell(x, 15).v(L3, false);
1496 } catch (IOException ex) {
1497 throw new RuntimeException(ex);
1502 public static void drain(At40k at40k, AvrDrone device) throws Exception {
1503 At40k.Cell a = at40k.cell(10,22);
1504 At40k.Cell b = at40k.cell(11,22);
1507 for(int i=0; i<30; i++) {
1508 //System.out.println(i);
1511 try { Thread.sleep(1); } catch (Exception e) { }
1514 try { Thread.sleep(1); } catch (Exception e) { }
1519 public static void doitx(At40k at40k, AvrDrone device) throws Exception {
1520 for(int i=5; i<PIPELEN+1; i++) bounce(at40k.cell(i, 23), SE, SOUTH);
1521 for(int x=5; x<PIPELEN; x++) muller(at40k.cell(x, 22), x==PIPELEN-1 ? SE : NE, WEST);
1523 bounce(at40k.cell(PIPELEN, 21), NW, WEST);
1525 for(int x=5; x<PIPELEN; x++) muller(at40k.cell(x, 21), SW, x==PIPELEN-1 ? NORTH : EAST);
1526 for(int x=4; x<PIPELEN+1; x++) bounce(at40k.cell(x, 20), NW, NORTH);
1528 bounce(at40k.cell(4, 22), SE, EAST);
1529 //muller(at40k.cell(4PIPELEN-1,21), SW, NORTH);
1531 //muller(at40k.cell(4,22), NE, WEST);
1532 //at40k.cell(4,22).ylut(0xEE);
1533 muller(at40k.cell(5, 22), NE, SOUTH);
1534 muller(at40k.cell(5, 21), NW, EAST);
1536 for(int x=4; x>=0; x--) {
1537 at40k.cell(x, 21).ylut(0xAA);
1538 at40k.cell(x, 21).yi(EAST);
1539 at40k.cell(x, 21).yo(false);
1542 at40k.cell(0, 22).ylut(0xAA);
1543 at40k.cell(0, 22).yi(SOUTH);
1544 at40k.cell(0, 22).yo(false);
1546 at40k.cell(0, 23).ylut(~0xAA);
1547 at40k.cell(0, 23).xlut(~0xcc);
1548 at40k.cell(0, 23).yi(SOUTH);
1549 at40k.cell(0, 23).yo(false);
1551 for(int x=3; x<=23; x+=2) {
1552 pulse_detect(at40k.cell(x-1, 19), SW, false);
1553 pulse_detect(at40k.cell(x-1, 18), WEST, true);
1554 pulse_copy(at40k.cell(x, 19), SW, SOUTH, false);
1555 pulse_copy(at40k.cell(x, 18), NW, NORTH, true);
1558 pulse_detect(at40k.cell(x-1, 16), SW, false);
1559 pulse_detect(at40k.cell(x-1, 15), WEST, true);
1560 pulse_copy(at40k.cell(x, 16), SW, SOUTH, false);
1561 pulse_copy(at40k.cell(x, 15), NW, NORTH, true);
1563 //pulse_detect(at40k.cell(15, 22), NORTH, false);
1564 //pulse_detect(at40k.cell(16, 22), NW, true);
1565 //pulse_copy(at40k.cell(16, 21), NW, WEST, false);
1566 //pulse_copy(at40k.cell(15, 21), NE, EAST, true);
1568 for(int x=14; x>=1; x--)
1569 copy(at40k.cell(x, 17), EAST, EAST);
1570 for(int x=4; x>=0; x--)
1571 copy(at40k.cell(x, 21), EAST, EAST);
1572 copy(at40k.cell(13, 17), SOUTH, SOUTH);
1574 copy(at40k.cell(0, 20), NORTH, NORTH);
1575 copy(at40k.cell(0, 19), NORTH, NORTH);
1576 copy(at40k.cell(0, 18), NORTH, NORTH);
1577 copy(at40k.cell(0, 17), NORTH, NORTH);
1578 copy(at40k.cell(0, 16), NORTH, NORTH);
1579 copy(at40k.cell(1, 16), WEST, WEST);
1580 copy(at40k.cell(1, 15), NORTH, NORTH);
1582 copy(at40k.cell(1, 20), SOUTH, SOUTH);
1583 copy(at40k.cell(1, 19), SOUTH, SOUTH);
1584 copy(at40k.cell(1, 18), SOUTH, SOUTH);
1586 for(int y=20; y<=23; y++)
1587 copy(at40k.cell(23, y), SOUTH, SOUTH);
1590 //for(int x=19; x<=23; x++)
1591 //copy(at40k.cell(x, 0), WEST, WEST);
1592 //copy(at40k.cell(18, 19), NW, NW);
1593 //at40k.iob_top(5, true).enableOutput(SOUTH);
1594 //at40k.iob_top(5, false).enableOutput(SOUTH);