1 package edu.berkeley.obits;
3 import static edu.berkeley.obits.device.atmel.AtmelDevice.Constants.*;
4 import static edu.berkeley.obits.device.atmel.AtmelDevice.Util.*;
5 import edu.berkeley.obits.device.atmel.*;
6 import edu.berkeley.obits.gui.*;
8 import java.awt.event.*;
9 import java.awt.color.*;
10 import org.ibex.util.*;
15 public class AtmelSerial {
17 //public static boolean mullers = false;
18 public static boolean mullers = true;
19 public static int masterx = 1;
20 public static SerialPort detectObitsPort() throws Exception {
21 Enumeration e = CommPortIdentifier.getPortIdentifiers();
22 while(e.hasMoreElements()) {
23 CommPortIdentifier cpi = (CommPortIdentifier)e.nextElement();
24 Log.info(AtmelSerial.class, "trying " + cpi.getName());
25 if (cpi.getName().startsWith("/dev/cu.usbserial-"))
26 return new RXTXPort(cpi.getName());
27 if (cpi.getName().startsWith("/dev/ttyS0"))
28 return new RXTXPort(cpi.getName());
30 Log.info(AtmelSerial.class, "returning null...");
33 public static int PIPELEN=20;
34 public static void main(String[] s) throws Exception {
35 //AvrDrone device = new AvrDrone(detectObitsPort());
36 //AvrDrone device = new AvrDrone();
37 AvrDrone device = new AvrDrone(new FtdiBoard());
38 At40k at40k = new At40k.At40k10(device);
40 long begin = System.currentTimeMillis();
41 device.readMode4(System.in);
42 long end = System.currentTimeMillis();
43 Log.info(AtmelSerial.class, "finished in " + ((end-begin)/1000) + "s");
45 Log.info(AtmelSerial.class, "issuing command");
47 //at40k.iob_top(2, true).oe(false);
48 //at40k.iob_top(2, false).oe(false);
49 //at40k.iob_top(1, true).oe(false);
51 // this command confirmed to turn *on* led0
52 //at40k.iob_top(1, false).output(0);
54 for(int i=0; i<20; i++) {
55 at40k.iob_bot(i, false).output(0);
56 at40k.iob_bot(i, true).output(0);
60 //System.out.println("tick");
62 //System.out.println("tick");
63 //at40k.cell(0x01, 0x17).xlut((byte)0x);
66 System.out.println(Integer.toString(0xff & at40k.cell(0x01, 0x17).xlut(), 16));
67 System.out.println(Integer.toString(0xff & at40k.cell(0x01, 0x17).ylut(), 16));
68 at40k.cell(0x01, 0x17).ylut((byte)0xff);
71 //at40k.cell(0x01, 0x17).wi(L1);
73 System.out.println("a: " + at40k.new SectorWire(true, 0, 4, 0x17).driverRight());
74 System.out.println("b: " + at40k.new SectorWire(true, 1, 4, 0x17).driverRight());
75 At40k.SectorWire h0p0 = at40k.new SectorWire(true, 0, 0, 0x17);
76 At40k.SectorWire h0p1 = at40k.new SectorWire(true, 1, 0, 0x17);
77 At40k.SectorWire h0p2 = at40k.new SectorWire(true, 2, 0, 0x17);
78 At40k.SectorWire h4p0 = at40k.new SectorWire(true, 0, 4, 0x17);
79 At40k.SectorWire h4p1 = at40k.new SectorWire(true, 1, 4, 0x17);
80 At40k.SectorWire h4p2 = at40k.new SectorWire(true, 2, 4, 0x17);
82 //h4p1.drives(h0p1, false);
83 //at40k.cell(0x04, 0x17).out(L1, false);
84 //at40k.cell(0x04, 0x17).h(L0, false);
86 for(int plane=0; plane<5; plane++) {
87 at40k.new SectorWire(true, plane, 4, 0x17).drives(at40k.new SectorWire(true, plane, 0, 0x17), false);
88 at40k.cell(0x04, 0x17).out(plane, false);
89 at40k.cell(0x04, 0x17).h(plane, false);
90 at40k.cell(0x01, 0x17).h(plane, false);
92 try { Thread.sleep(2000); } catch (Exception e) { }
95 at40k.new SectorWire(true, plane, 4, 0x17).drives(at40k.new SectorWire(true, plane, 0, 0x17), true);
96 at40k.cell(0x04, 0x17).out(plane, true);
97 at40k.cell(0x04, 0x17).h(plane, true);
98 at40k.cell(0x01, 0x17).h(plane, true);
99 at40k.cell(0x01, 0x17).wi(plane);
104 System.out.println("xlut is " + hex(at40k.cell(0x04, 0x17).xlut()));
105 System.out.println("ylut is " + hex(at40k.cell(0x04, 0x17).ylut()));
106 At40k.Cell cell = at40k.cell(0x04, 0x17);
109 System.out.println(cell.c());
116 //cell.t(false, false, true);
117 cell.t(false, true, false);
128 for(int i=3; i>=1; i--) {
129 at40k.cell(i, 0x17).yi(EAST);
130 at40k.cell(i, 0x17).ylut(0x55);
131 at40k.cell(i, 0x17).yo(false);
135 //System.out.println("reading port status: " + Integer.toString(device.readBus() & 0xff, 16));
140 at40k.cell(23, 8).ylut(0xff);
141 at40k.cell(23, 11).ylut(0xff);
142 at40k.iob_right(8, true).enableOutput();
143 at40k.iob_right(11, true).enableOutput();
145 //for(int x=4; x<=22; x++) swap(at40k.cell(x, 22), NW, NORTH);
148 // entry cell: just copy X->X Y->Y
149 //at40k.cell(4,23).b(false);
150 //at40k.cell(4,23).yo(false);
151 //at40k.cell(4,23).ylut(at40k.cell(4,23).xlut());
152 //at40k.cell(4,23).xo(false);
154 at40k.cell(4,23).xlut(0x55);
155 at40k.cell(4,23).ylut(0x55);
158 at40k.cell(4,23).xlut(0x71);
159 at40k.cell(4,23).ylut(0x44);
160 at40k.cell(4,23).c(YLUT);
161 at40k.cell(4,23).f(false);
162 at40k.cell(4,23).t(false, false, true);
165 //for(int x=6; x<=23; x++) copy(at40k.cell(x, 23), NW, WEST); // top row copies to the right
167 copy(at40k.cell(5, 22), NW, NORTH);
168 for(int x=6; x<=22; x++) copy(at40k.cell(x, 22), NW, WEST); // second top row copies to the right
169 //for(int y=22; y>=10; y--) copy(at40k.cell(23, y), NW, NORTH); // right edge copies down
170 for(int y=21; y>=9; y--) copy(at40k.cell(22, y), NW, NORTH); // second right edge copies down
171 copy(at40k.cell(23, 9), NW, WEST); // second output
174 handshaker(at40k.cell(4,23));
175 at40k.cell(4,23).xi(NW);
176 at40k.cell(4,23).yi(SOUTH);
178 //handshaker(at40k.cell(5,23));
179 //at40k.cell(5,23).yi(NORTH);
181 at40k.cell(5,23).yi(NORTH);
182 at40k.cell(5,23).xlut(0x55);
183 at40k.cell(5,23).xi(SW);
184 at40k.cell(5,23).ylut(0x55);
185 at40k.cell(5,22).yi(NORTH);
186 at40k.cell(5,22).xlut(0x55);
188 bounce(at40k.cell(4,22));
190 // cell southeast of entry cell
191 at40k.cell(3,22).xi(NE); // NW->xin
192 at40k.cell(3,22).ylut(0x33); // xin->y
193 at40k.cell(3,22).yo(false); // y->yout
194 copy(at40k.cell(3, 21), NW, NORTH); // second top row copies to the right
195 copy(at40k.cell(4, 21), NW, EAST); // second top row copies to the right
196 copy(at40k.cell(5, 21), NW, EAST); // second top row copies to the right
197 copy(at40k.cell(6, 21), NW, EAST); // second top row copies to the right
198 copy(at40k.cell(6, 22), NW, SOUTH); // second top row copies to the right
201 at40k.cell(05,22).xlut(0xff);
202 at40k.cell(05,22).ylut(0xff);
203 at40k.cell(05,22).c(XLUT);
204 at40k.cell(05,22).f(false);
205 at40k.cell(05,22).b(false);
206 at40k.cell(05,22).oe(NONE);
207 at40k.cell(05,22).v(L3, true);
208 at40k.cell(05,22).out(L3, true);
211 at40k.cell(4,23).ylut(~0xCC);
212 at40k.cell(4,23).xlut(~0xAA);
213 at40k.cell(5,23).ylut(~0xAA);
214 at40k.cell(5,23).xlut(~0xAA);
215 for(int i=6; i<PIPELEN+2; i++) {
216 at40k.cell(i, 23).ylut(0xAA);
217 at40k.cell(i, 23).xlut(0xCC);
218 at40k.cell(i, 23).yi(WEST);
223 System.out.println("doit");
224 if (mullers) doitx(at40k, device);
225 //System.out.println("counter");
226 //counter(at40k, device);
228 at40k.cell(21,15).yi(WEST);
229 at40k.cell(21,15).ylut(0xAA);
231 at40k.cell(22,15).yi(WEST);
232 at40k.cell(22,15).ylut(0xAA);
234 at40k.cell(23,15).h(3, true);
235 at40k.cell(23,15).yi(L3);
236 at40k.cell(23,15).ylut(0xAA);
237 at40k.iob_right(15, true).enableOutput(WEST);
240 At40k.Cell c = at40k.cell(10,10);
247 copy(c.west(), EAST, NW);
248 copy(c.west().north().west(), SE, SE);
257 copy(c.east(), WEST, SE);
258 copy(c.east().south().east(), NW, NW);
261 copy(c.north(), SOUTH, SOUTH);
262 c.xlut((LUT_SELF & ~LUT_OTHER) | LUT_Z);
276 copy(c.north(), SOUTH, SOUTH);
277 c.xlut((LUT_SELF & ~LUT_OTHER) | LUT_Z);
298 c.hwire(L4).west().drives(c.hwire(L4), false);
299 c.hwire(L4).east().drives(c.hwire(L4), false);
310 c.hwire(L4).west().drives(c.hwire(L4), false);
311 c.hwire(L4).east().drives(c.hwire(L4), false);
315 copy(c.south(), NORTH, NORTH);
316 c.xlut(((~LUT_SELF) & (~LUT_OTHER)) | LUT_Z);
330 copy(c.south(), NORTH, NORTH);
331 c.xlut((LUT_SELF & LUT_OTHER) | LUT_Z);
345 // catch a rising transition
356 c.hwire(L2).west().drives(c.hwire(L2), false);
357 c.hwire(L2).east().drives(c.hwire(L2), false);
363 c = at40k.cell(20,20);
373 c = at40k.cell(21,20);
404 at40k.cell(9,10).xo(true);
405 at40k.cell(9,10).yo(true);
406 at40k.cell(9,10).c(YLUT);
407 at40k.cell(9,10).b(false);
409 //for(int x=5; x<PIPELEN; x++) {
410 //at40k.cell(x,23).hwire(L0).drives(at40k.cell(x,23).hwire(L0).east());
414 at40k.cell(22,11).ylut(0xff);
415 at40k.cell(23,11).yi(L3);
416 //at40k.cell(23,11).yi(WEST);
417 //at40k.cell(23,11).xi(L1);
418 at40k.cell(23,11).ylut(0xAA);
419 at40k.iob_right(11, true).enableOutput(WEST);
420 at40k.cell(23,11).v(L3, true);
421 at40k.cell(23,11).yo(false);
427 System.out.println("correct: " + at40k.cell(19,15).hwire(L3) + " drives " + at40k.cell(20,15).hwire(L3));
428 System.out.println("correct: " + at40k.cell(15,15).hwire(L3) + " drives " + at40k.cell(19,15).hwire(L3));
429 System.out.println("correct: " + at40k.cell(11,15).hwire(L3) + " drives " + at40k.cell(15,15).hwire(L3));
430 System.out.println("correct: " + at40k.cell(07,15).hwire(L3) + " drives " + at40k.cell(11,15).hwire(L3));
432 at40k.cell(19,15).hwire(L3).drives(at40k.cell(20,15).hwire(L3), true);
433 at40k.cell(15,15).hwire(L3).drives(at40k.cell(19,15).hwire(L3), true);
434 at40k.cell(11,15).hwire(L3).drives(at40k.cell(15,15).hwire(L3), true);
435 at40k.cell(07,15).hwire(L3).drives(at40k.cell(11,15).hwire(L3), true);
437 //at40k.cell(05,vv).xlut(0xff);
438 //at40k.cell(05,vv).ylut(0xff);
440 at40k.cell(vx,vv).c(YLUT);
441 at40k.cell(vx,vv).f(false);
442 at40k.cell(vx,vv).b(false);
443 at40k.cell(vx,vv).oe(NONE);
444 at40k.cell(vx,vv).v(L3, true);
445 at40k.cell(vx,vv).out(L3, true);
448 at40k.cell(vx,15).v(L3, true);
449 at40k.cell(vx,15).h(L3, true);
450 at40k.cell(vx,19).vwire(L3).drives(at40k.cell(vx,15).vwire(L3), true);
451 at40k.cell(vx,23).vwire(L3).drives(at40k.cell(vx,19).vwire(L3), true);
454 //at40k.cell(5,23).ylut(0x00);
455 //at40k.cell(6,22).ylut(0xff);
456 //at40k.cell(22,11).ylut(0xff);
458 At40k.Cell cell = at40k.cell(4, 16);
469 //scan(at40k, cell, YLUT, true);
470 //scan(at40k, cell, YLUT, false);
472 //device.scanFPGA(true);
474 at40k.cell(10,10).f(true);
475 at40k.cell(10,10).c(ZMUX);
477 at40k.cell(8,7).xlut(LUT_SELF);
478 at40k.cell(8,7).xi(NW);
480 at40k.cell(7,8).xlut(LUT_SELF & LUT_Z);
481 at40k.cell(7,8).xi(SE);
482 at40k.cell(7,8).c(XLUT);
483 at40k.cell(7,8).f(false);
484 at40k.cell(7,8).b(false);
485 at40k.cell(7,8).t(TMUX_FB);
486 at40k.cell(7,8).xo(false);
487 System.out.println(at40k.cell(7,8).fb_relevant());
489 at40k.cell(6,13).xi(SE);
490 at40k.cell(6,13).c(ZMUX);
491 at40k.cell(6,13).xlut(LUT_SELF);
492 at40k.cell(6,13).ylut(LUT_OTHER);
493 at40k.cell(6,13).xo(false);
494 at40k.cell(6,13).yo(false);
495 at40k.cell(7,12).xi(SE);
497 for(int i=0; i<24; i++) {
498 at40k.iob_bot(i, true).enableOutput(NORTH);
499 at40k.iob_bot(i, false).enableOutput(NW);
500 at40k.cell(i, 0).xlut(0xff);
501 at40k.cell(i, 0).ylut(0xff);
506 Gui vis = new Gui(at40k, device);
507 Frame fr = new Frame();
508 fr.addKeyListener(vis);
509 fr.setLayout(new BorderLayout());
510 fr.add(vis, BorderLayout.CENTER);
512 fr.setSize(900, 900);
516 synchronized(AtmelSerial.class) { AtmelSerial.class.wait(); }
520 Visualizer v = new Visualizer(at40k, device);
522 v.setSize(1380, 1080);
523 At40k.Cell cell = at40k.cell(4, 23);
525 Image img = v.createImage(v.getWidth(), v.getHeight());
529 cell = at40k.cell(x,y);
530 scan(at40k, cell, YLUT, true);
540 //selfTest(device, at40k, v);
541 System.out.println("save: " + AvrDrone.save + " of " + (AvrDrone.saveof*5));
543 at40k.iob_top(0, true).enableInput();
544 copy(at40k.cell(0, 23), NORTH, NORTH);
545 at40k.iob_bot(0, true).enableOutput(NORTH);
547 for(int i=0; i<10000; i++) {
549 try { Thread.sleep(100); } catch (Exception e) { }
553 //at40k.cell(0x01, 0x17).h(0, false);
554 //at40k.cell(0x01, 0x17).xi(NE);
555 //at40k.cell(0x01, 0x17).ylut((byte)0x55);
557 //at40k.cell(0x04, 0x17).xlut((byte)0x10);
558 //at40k.cell(0x04, 0x17).ylut((byte)0x10);
559 //at40k.cell(0x04, 0x17).yo(false);
560 //at40k.cell(0x04, 0x17).xo();
563 at40k.cell(0x01, 0x17).xi(L0);
564 at40k.cell(0x01, 0x17).h(L0, true);
567 at40k.cell(0x03, 0x17).xlut((byte)0x55);
568 at40k.cell(0x03, 0x17).ylut((byte)0x55);
569 at40k.cell(0x03, 0x17).yi(EAST);
570 at40k.cell(0x03, 0x17).ylut((byte)0x55);
571 at40k.cell(0x03, 0x17).yo(true);
573 at40k.cell(0x03, 0x17).f(false);
574 at40k.cell(0x03, 0x17).c(XLUT);
575 at40k.cell(0x03, 0x17).oe(NONE);
576 at40k.cell(0x03, 0x17).out(L0, true);
578 at40k.cell(0x02, 0x17).yi(EAST);
579 at40k.cell(0x02, 0x17).ylut((byte)0x55);
580 at40k.cell(0x02, 0x17).yo(false);
582 at40k.cell(0x01, 0x17).yi(EAST);
583 at40k.cell(0x01, 0x17).ylut((byte)0x55);
584 at40k.cell(0x01, 0x17).yo(false);
586 at40k.cell(0x01, 0x17).h(L0, true);
587 at40k.cell(0x01, 0x17).v(L0, false);
589 //at40k.cell(0x01, 0x17).yi(L0);
590 //at40k.cell(0x01, 0x17).xi(L0);
591 //at40k.cell(0x01, 0x17).ylut((byte)0x33);
594 at40k.cell(0x03, 0x17).h(L0, true);
595 at40k.cell(0x03, 0x17).out(L0, true);
596 at40k.cell(0x03, 0x17).c(XLUT);
597 at40k.cell(0x03, 0x17).f(false);
600 at40k.cell(0x01, 0x17).xin(4);
601 at40k.cell(0x01, 0x17).yin(4);
602 at40k.cell(0x01, 0x16).ylut((byte)0x00);
603 device.mode4(2, 0x17, 0x01, 0);
605 for(int i=0; i<10; i++) {
607 System.out.println("tick");
608 //at40k.cell(0x01, 0x17).xlut((byte)0xFF);
609 at40k.cell(0x00, 0x17).ylut((byte)0x00);
612 System.out.println("tick");
613 //at40k.cell(0x01, 0x17).xlut((byte)0x00);
614 at40k.cell(0x00, 0x17).ylut((byte)0xFF);
621 at40k.iob_top(0, true).output(0);
622 at40k.iob_top(0, true).oe(false);
623 at40k.iob_top(0, true).pullup();
627 Log.info(AtmelSerial.class, "issuing command");
628 at40k.iob_top(1, true).pulldown();
631 Log.info(AtmelSerial.class, "done");
633 } catch (Exception e) { e.printStackTrace(); }
636 public static void scan(At40k dev, At40k.Cell cell, int source, boolean setup) {
638 if (source != NONE) cell.c(source);
639 if (cell.b()) cell.b(false);
640 if (cell.f()) cell.f(false);
642 if (cell.out(L3)!=setup) cell.out(L3, setup);
643 if (cell.vx(L3)!=setup) cell.v(L3, setup);
645 At40k.SectorWire sw = cell.vwire(L3);
646 //System.out.println("wire is: " + sw);
648 if (sw.row > (12 & ~0x3) && sw.north()!=null && sw.north().drives(sw))
649 sw.north().drives(sw, false);
650 while(sw.row > (12 & ~0x3) && sw.south() != null) {
651 //System.out.println(sw + " -> " + sw.south());
652 if (sw.drives(sw.south())!=setup) sw.drives(sw.south(), setup);
655 if (sw.row < (12 & ~0x3) && sw.south() != null && sw.south().drives(sw))
656 sw.north().drives(sw, false);
657 while(sw.row < (12 & ~0x3) && sw.north() != null) {
658 //System.out.println(sw + " -> " + sw.north());
659 if (sw.drives(sw.north())!=setup) sw.drives(sw.north(), setup);
663 //cell = dev.cell(19, 15);
664 cell = dev.cell(cell.col, 15);
666 System.out.println("cell is " + cell);
675 if (cell.hx(L3) != setup) cell.h(L3, setup);
676 if (cell.vx(L3) != setup) cell.v(L3, setup);
679 if (sw.west()!=null && sw.west().drives(sw)) { sw.west().drives(sw, false); }
680 while(sw.east() != null) {
681 //System.out.println(sw + " -> " + sw.east());
682 if (sw.drives(sw.east())!=setup) sw.drives(sw.east(), setup);
688 public static void copy(At40k.Cell c, int xdir, int ydir) {
690 case NW: case NE: case SW: case SE: {
695 case NORTH: case SOUTH: case EAST: case WEST: {
701 default: throw new Error();
704 case NW: case NE: case SW: case SE: {
709 case NORTH: case SOUTH: case EAST: case WEST: {
715 default: throw new Error();
720 public static String hex(int x) {
721 return Long.toString(x & 0xffffffffL, 16);
724 public static void handshaker(At40k.Cell cell) {
729 cell.t(false, false, true);
732 public static class Visualizer extends Frame implements KeyListener, MouseMotionListener, MouseListener {
733 public static final int WIDTH = 40;
734 public static final int HEIGHT = 40;
735 public static final int LW = 15;
736 public static final int LH = 15;
737 public static final Color RED = new Color(0xaa, 0x55, 0x55);
738 public static final Color BLUE = new Color(0x55, 0x55, 0xaa);
739 private final At40k dev;
740 private final AvrDrone drone;
743 public Visualizer(final At40k dev, final AvrDrone drone) {
747 addMouseMotionListener(this);
748 addMouseListener(this);
749 addKeyListener(this);
755 if (!enabled) continue;
757 At40k.Cell cell = dev.cell(21, 22);
767 } catch (Exception e) {
773 public boolean enabled = false;
774 public void mouseClicked(MouseEvent e) { }
775 public void mouseEntered(MouseEvent e) { }
776 public void mouseExited(MouseEvent e) { }
777 public void mouseReleased(MouseEvent e) {
779 public void keyTyped(KeyEvent k) {
781 public void keyReleased(KeyEvent k) {
783 public void keyPressed(KeyEvent keyevent) {
784 boolean scan = false;
785 switch(keyevent==null ? '_' : keyevent.getKeyChar()) {
787 if (selx==-1 || sely==-1) break;
788 At40k.Cell cell = dev.cell(selx, sely);
791 drawCell(getGraphics(), selx, sely);
796 System.out.println("interrupt_count: " + drone.readCount());
804 System.out.println("low => " + mx);
805 copy(dev.cell(mx, yofs-2), NORTH, NORTH);
806 copy(dev.cell(mx, yofs-3), NORTH, NORTH);
807 //dev.cell(mx, yofs-3).ylut(~dev.cell(mx, yofs-3).ylut());
808 //dev.cell(mx, yofs-3).xlut(~dev.cell(mx, yofs-3).xlut());
810 int mx = 23-(masterx-23);
811 System.out.println("high => " + mx);
812 copy(dev.cell(mx, yofs), NW, NW);//NORTH, NORTH);
813 copy(dev.cell(mx, yofs-1), NORTH, NORTH);
814 //for(int x=mx-1; x>=1; x--)
815 //copy(dev.cell(x, yofs), EAST, EAST);
816 for(int y=yofs+1; y<=23; y++)
817 copy(dev.cell(1, y), SOUTH, SOUTH);
818 //dev.cell(mx, yofs-1).ylut(~dev.cell(mx, yofs-1).ylut());
819 //dev.cell(mx, yofs-1).xlut(~dev.cell(mx, yofs-1).xlut());
824 System.out.println("low => " + mx);
825 copy(dev.cell(mx, yofs-2), SOUTH, SOUTH);
826 copy(dev.cell(mx, yofs-3), NORTH, NORTH);
827 dev.cell(mx, yofs-3).ylut(~dev.cell(mx, yofs-3).ylut());
828 dev.cell(mx, yofs-3).xlut(~dev.cell(mx, yofs-3).xlut());
830 int mx = 23-(masterx-23);
831 System.out.println("high => " + mx);
832 copy(dev.cell(mx, yofs), SOUTH, SOUTH);
834 copy(dev.cell(mx, yofs-1), NORTH, NORTH);
836 copy(dev.cell(mx, yofs-1), NORTH, SW);
838 At40k.Cell lc = null;
839 for(int k=0; k<10; k++) {
840 int y = yofs-2-(k*2);
841 copy(dev.cell(left?(mx-1):mx, y), SOUTH, left?NE:NW);
842 copy(lc = dev.cell(left?(mx-1):mx, y-1), NORTH, left?SE:SW);
845 copy(lc, NORTH, NORTH);
847 //for(int x=mx-1; x>=1; x--)
848 //copy(dev.cell(x, yofs), EAST, EAST);
849 //for(int y=yofs+1; y<=23; y++)
850 //copy(dev.cell(1, y), SOUTH, SOUTH);
853 dev.cell(mx+2, yofs).ylut(0x00);
854 dev.cell(mx+2, yofs).xlut(0x00);
858 dev.cell(mx, yofs-1).ylut(~LUT_Z);
859 dev.cell(mx, yofs-1).xlut(LUT_Z);
860 loopback(dev.cell(mx, yofs-1), YLUT);
862 dev.cell(mx, yofs).ylut(~LUT_SELF);
863 dev.cell(mx, yofs).xlut(~LUT_OTHER);
869 //enabled = !enabled;
874 //enabled = !enabled;
876 for(int cap=0; cap<15; cap++) {
878 try { Thread.sleep(100); } catch (Exception e) { }
879 //showit(dev, drone, this);
880 fill(dev, drone, cap);
882 long now = System.currentTimeMillis();
883 try { Thread.sleep(4000); } catch (Exception e) { }
884 int count = drone.readCount();
885 long now2 = System.currentTimeMillis();
886 System.out.println(cap + " , " + (((float)count * (2*2*2*2*2*2*2*2*2*1000))/(now2-now)));
888 } catch (Exception e) { e.printStackTrace(); }
892 if (selx==-1 || sely==-1) break;
893 At40k.Cell cell = dev.cell(selx, sely);
895 drawCell(getGraphics(), selx, sely);
899 if (selx==-1 || sely==-1) break;
900 At40k.Cell cell = dev.cell(selx, sely);
903 drawCell(getGraphics(), selx, sely);
909 showit(dev, drone, this);
911 public void mousePressed(MouseEvent e) {
912 final At40k.Cell cell = dev.cell(selx, sely);
913 if (cell==null) return;
914 final int old = cell.c();
915 AvrDrone.ByteCallback bc = new AvrDrone.ByteCallback() {
916 public void call(byte b) throws Exception {
917 boolean y = (b & 0x80) != 0;
919 Graphics g = getGraphics();
920 g.setFont(new Font("sansserif", Font.BOLD, 14));
921 g.setColor(Color.white);
922 //g.drawString("X=0", left(cell) + 10, top(cell) + 20);
923 //g.drawString("X=1", left(cell) + 10, top(cell) + 20);
924 //g.setColor(Color.white);
925 //g.drawString("Y=0", left(cell) + 8, top(cell) + 35);
926 //g.drawString("Y=1", left(cell) + 8, top(cell) + 35);
928 //g.drawString("X="+(x?"1":"0"), left(cell) + 10, top(cell) + 20);
929 String v = (cell.c()==YLUT ? "Y" : cell.c()==XLUT ? "X" : "C");
930 g.drawString(v+"="+(y?"0":"1"), left(cell) + 8, top(cell) + 35);
932 g.drawString(v+"="+(y?"1":"0"), left(cell) + 8, top(cell) + 35);
934 scan(dev, cell, NONE, true);
936 //scan(dev, cell, XLUT, true);
937 //boolean x = (drone.readBus() & 0x80) != 0;
938 scan(dev, cell, NONE, false);
941 public void mouseMoved(MouseEvent e) {
944 if (selx >= 0 && selx < 24 && sely >= 0 && sely < 24) {
947 At40k.Cell cell = dev.cell(cx, cy);
951 drawCell(getGraphics(), cx, cy);
952 drawSector(getGraphics(), dev.cell(cx, cy).sector());
955 selx = (x-20)/(WIDTH+2);
956 sely = (23 - (y-20)/(HEIGHT+2))+1;
958 At40k.Cell cell = dev.cell(selx, sely);
959 if (selx >= 0 && selx < 24 && sely >= 0 && sely < 24) {
960 drawCell(getGraphics(), selx, sely);
961 drawSector(getGraphics(), dev.cell(selx, sely).sector());
965 public void mouseDragged(MouseEvent e) { mousePressed(e); }
966 public void paint(Graphics g) {
967 System.out.println("paintall");
968 g.setColor(Color.white);
969 g.fillRect(0, 0, getWidth(), getHeight());
970 g.setFont(new Font("sansserif", Font.BOLD, 24));
971 for(int x=0; x<24; x++)
972 for(int y=0; y<24; y++)
974 for(int x=0; x<=23; x+=4)
975 for(int y=23; y>=0; y-=4)
976 drawSector(g, dev.cell(x, y).sector());
979 g.drawString("Ready", (5*(WIDTH+2))+20, 40);
981 g.drawString("Send", (3*(WIDTH+2))+20, 40);
986 public void refresh() {
987 Graphics g = getGraphics();
989 int data = drone.readBus() & 0xff;
990 for(int i=0; i<8; i++) {
991 g.setColor((data & (1<<i))==0 ? Color.black : Color.green);
992 g.drawString("D"+i, (24*(WIDTH+2))+20, ((23-(i+7))*(HEIGHT+2))+60-HEIGHT/2);
996 public static int left(At40k.Cell cell) { return (cell.col) *(WIDTH+2)+20; }
997 public static int top(At40k.Cell cell) { return (23-cell.row)*(HEIGHT+2)+60; }
998 public void drawSector(Graphics g, At40k.Sector sector) {
999 g.setColor(Color.gray);
1000 ((Graphics2D)g).setStroke(new BasicStroke(1));
1001 int px = ((sector.col)*(WIDTH+2))+20-1;
1002 int py = ((23-(sector.row+3))*(HEIGHT+2))+60-1;
1003 g.drawRect(px, py, (WIDTH+2)*4+2, (HEIGHT+2)*4+2);
1005 for(int dir=0; dir<2; dir++) {
1007 for(int y=h?sector.row:sector.col; y<(h?sector.row+4:sector.col+4); y++)
1008 for(int plane=0; plane<=4; plane++) {
1009 At40k.Cell cell = h ? dev.cell(sector.col, y) : dev.cell(y, sector.row);
1010 At40k.Cell cell_east = h ? dev.cell(sector.col-1, y) : dev.cell(y, sector.row-1);
1011 At40k.Cell cell_west = h ? dev.cell(sector.col+4, y) : dev.cell(y, sector.row+4);
1012 boolean draw = false;
1014 if (cell_east!=null &&
1015 (cell_east.hwire(plane).drives(cell.hwire(plane)) ||
1016 cell_east.hwire(plane).drives(cell.hwire(plane))))
1018 if (cell_west!=null &&
1019 (cell_west.hwire(plane).drives(cell.hwire(plane)) ||
1020 cell_west.hwire(plane).drives(cell.hwire(plane))))
1023 if (cell_east!=null &&
1024 (cell_east.vwire(plane).drives(cell.vwire(plane)) ||
1025 cell_east.vwire(plane).drives(cell.vwire(plane))))
1027 if (cell_west!=null &&
1028 (cell_west.vwire(plane).drives(cell.vwire(plane)) ||
1029 cell_west.vwire(plane).drives(cell.vwire(plane))))
1033 for(int x=h?sector.col:sector.row; x<(h?sector.col+4:sector.row+4); x++)
1034 if (((h ? dev.cell(x,y).hx(plane) : dev.cell(y,x).vx(plane))) ||
1035 (h?dev.cell(x,y).out(plane):dev.cell(y,x).out(plane)))
1038 g.setColor(new Color(0xff, 0x00, 0xff));
1040 g.drawLine(left(cell),
1042 left(cell) + 4*(WIDTH+2),
1046 g.drawLine(left(cell)+3,
1047 top(cell) + (HEIGHT+2),
1049 top(cell) - 3*(HEIGHT+2)
1057 public void drawCell(Graphics g, int cx, int cy) {
1058 int x = (cx*(WIDTH+2))+20;
1059 int y = ((23-cy)*(HEIGHT+2))+60;
1060 if (g.getClipBounds() != null && !g.getClipBounds().intersects(new Rectangle(x, y, x+WIDTH, y+HEIGHT))) return;
1061 drawCell(g, cx, cy, Color.white);
1063 public void drawCell(Graphics g, int cx, int cy, Color bg) {
1064 int x = (cx*(WIDTH+2))+20;
1065 int y = ((23-cy)*(HEIGHT+2))+60;
1067 //System.out.println("drawcell " + cx + "," + cy);
1068 At40k.Cell cell = dev.cell(cx, cy);
1070 g.fillRect(x, y, WIDTH, HEIGHT);
1072 g.setColor((selx==cx && sely==cy) ? Color.red : Color.black);
1073 g.drawRect(x, y, WIDTH, HEIGHT);
1075 //g.setColor((selx==cx && sely==cy) ? Color.red : Color.gray);
1076 //g.drawRect(x+(WIDTH-(LW*2))/2-1, y+(HEIGHT-LW)/2-1, LW*2+1, LH+1);
1079 //g.fillRect(x+(WIDTH-(LW*2))/2, y+(HEIGHT-LW)/2, LW, LH);
1080 //g.setColor(Color.white);
1081 //g.drawString("1", x+(WIDTH-(LW*2))/2, y+(HEIGHT-LW)/2);
1084 //g.fillRect(x+(WIDTH-(LW*2))/2+LW, y+(HEIGHT-LW)/2, LW, LH);
1085 //g.setColor(Color.white);
1086 //g.drawString("0", x+(WIDTH-(LW*2))/2+LW, y+(HEIGHT-LW)/2);
1090 ((Graphics2D)g).setStroke(new BasicStroke((float)1));
1092 case NORTH: g.drawLine(x+WIDTH/2+5, y-10, x+WIDTH/2+5, y+HEIGHT/2); break;
1093 case SOUTH: g.drawLine(x+WIDTH/2-5, y+HEIGHT+10, x+WIDTH/2-5, y+HEIGHT/2); break;
1094 case EAST: g.drawLine(x+WIDTH+10, y+HEIGHT/2+5, x+WIDTH/2, y+HEIGHT/2+5); break;
1095 case WEST: g.drawLine(x-10, y+HEIGHT/2-5, x+WIDTH/2, y+HEIGHT/2-5); break;
1099 ((Graphics2D)g).setStroke(new BasicStroke((float)1));
1101 case NW: g.drawLine(x-10+3, y-10, x+WIDTH/2+3, y+HEIGHT/2); break;
1102 case SW: g.drawLine(x-10-3, y+HEIGHT+10, x+WIDTH/2-3, y+HEIGHT/2); break;
1103 case NE: g.drawLine(x+WIDTH+10+3, y-10, x+WIDTH/2+3, y+HEIGHT/2); break;
1104 case SE: g.drawLine(x+WIDTH+10-3, y+HEIGHT+10, x+WIDTH/2-3, y+HEIGHT/2); break;
1107 ((Graphics2D)g).setStroke(new BasicStroke(1));
1110 if (selx==cx && sely==cy) {
1111 int xp = 23 * (WIDTH+2) + 100;
1113 g.setColor(Color.white);
1114 g.fillRect(xp, yp, 300, 1000);
1115 g.setColor(Color.black);
1116 g.drawString("Cell " + cx + "," + cy, xp, (yp+=15));
1117 //g.drawString("X-Lut: " + bin8(cell.xlut()), xp, (yp+=15));
1118 g.drawString("X-Lut: " + cell.printXLut(), xp, (yp+=15));
1119 //g.drawString("Y-Lut: " + bin8(cell.ylut()), xp, (yp+=15));
1120 g.drawString("Y-Lut: " + cell.printYLutX(), xp, (yp+=15));
1123 if ((cell.ylut()&0xff)==0xff && (cell.xlut()&0xff)==0xff) {
1124 g.setColor(new Color(0x00, 0x00, 0xff));
1125 g.drawString("1", left(cell) + 12, top(cell) + 30);
1127 if ((cell.ylut()&0xff)==0x00 && (cell.xlut()&0xff)==0x00) {
1128 g.setColor(new Color(0x00, 0x00, 0xff));
1129 g.drawString("0", left(cell) + 12, top(cell) + 30);
1131 if ((cell.ylut()&0xff)==0xB2) {
1132 //System.out.println("muller @ " + cell);
1134 //g.drawString("X="+(x?"1":"0"), left(cell) + 10, top(cell) + 20);
1135 g.setColor(new Color(0x00, 0xaa, 0x00));
1136 g.drawString("C", left(cell) + 12, top(cell) + 30);
1142 private static String pad(int i, String s) { if (s.length()>i) return s; return "0"+pad((i-1),s); }
1143 public static String bin8(byte b) {
1146 for(int i=7; i>=0; i--)
1147 ret += (n & (1<<i))==0 ? "0" : "1";
1151 public static void selfTest(AvrDrone device, At40k at40k, Visualizer v) {
1154 long now = System.currentTimeMillis();
1155 for(int x=0; x<24; x++)
1156 for(int y=0; y<24; y++) {
1157 At40k.Cell cell = at40k.cell(x,y);
1158 scan(at40k, cell, YLUT, true);
1159 //v.paint(img.getGraphics());
1160 //v.getGraphics().drawImage(img, 0, 0, null);
1162 boolean a = (device.readBus() & 0x80)!=0;
1164 boolean b = (device.readBus() & 0x80)!=0;
1166 //System.out.println("pass " + x+","+y);
1167 Graphics g = v.getGraphics();
1168 g.setColor(Color.green);
1169 g.drawString("pass", v.left(cell) + 10, v.top(cell) + 20);
1171 System.out.println("FAIL!!!! " + x+","+y+" => " + a + " " + b);
1173 Graphics g = v.getGraphics();
1174 g.setColor(Color.red);
1175 g.drawString("FAIL", v.left(cell) + 10, v.top(cell) + 20);
1177 scan(at40k, cell, YLUT, false);
1180 System.out.println("failures: " + fail);
1181 System.out.println("scan time: " + (System.currentTimeMillis()-now) + "ms");
1185 public static void bounce(At40k.Cell cell, int xi, int yi) {
1186 cell.xlut((byte)0xCC);
1187 cell.ylut((byte)0xCC);
1193 public static void muller(At40k.Cell cell, int xi, int yi) {
1197 cell.t(false, false, true);
1204 /** watches for a rising/falling edge on Yin, emits a pulse on Xout */
1205 public static void pulse_detect(At40k.Cell c, int in, boolean falling) {
1209 case NW: case NE: case SW: case SE: {
1212 if (!falling) c.ylut(lutSwap(0x0C)); /* x & !z */
1213 else c.ylut(lutSwap(0x30)); /* !x & z */
1217 case NORTH: case SOUTH: case EAST: case WEST: {
1220 if (!falling) c.xlut(0x0C); /* y & !z */
1221 else c.xlut(0x30); /* !y & z */
1225 default: throw new Error();
1229 /** watches for a pulse on Xin, copies value of Yin */
1230 public static void pulse_copy(At40k.Cell cell, int xi, int yi, boolean invert) {
1231 loopback(cell, YLUT);
1232 if (!invert) cell.ylut(0xB8); /* yo = x ? yi : z => 1011 1000 */
1233 else cell.ylut(0x74); /* yo = x ? !yi : z => 0111 0100 */
1234 if (!invert) cell.xlut(lutSwap(0xB8)); /* yo = x ? yi : z => 1011 1000 */
1235 else cell.xlut(lutSwap(0x74)); /* yo = x ? !yi : z => 0111 0100 */
1240 public static void loopback(At40k.Cell cell, int cin) {
1243 cell.t(false, false, true);
1248 public static void doit(At40k at40k, AvrDrone device) throws Exception {
1250 At40k.Cell led = at40k.cell(1, 23);
1254 led.ylut(~LUT_SELF);
1258 At40k.Cell c = at40k.cell(1, 22);
1266 c.v(L0, /*false*/true);
1273 for(int i=0; i<4; i++) at40k.cell(i, 20).h(L0, false);
1274 At40k.Cell z = at40k.cell(1, 20);
1285 z.hwire(L0).east().drives(z.hwire(L0), false);
1286 z.hwire(L1).east().drives(z.hwire(L1), false);
1287 z.vwire(L0).south().drives(z.vwire(L0), false);
1288 z.vwire(L1).south().drives(z.vwire(L1), false);
1291 z = at40k.cell(0, 20);
1309 for(int y=20; y<=22; y++)
1310 for(int x=2; x<=5; x++) {
1311 c = at40k.cell(x, y);
1315 //c = at40k.cell(2, 22);
1319 c = at40k.cell(1, 21);
1333 c = at40k.cell(13, 22);
1334 c.xlut(LUT_OTHER | 0xF0);
1336 c.t(false, false, true);
1343 // this gate detects a rising edge on its Xin (delayed copy on Yin); when viewed, it inverts its state
1344 c = at40k.cell(14, 22);
1349 c.t(false, false, true);
1354 c.ylut(0xA6); // (x & !z) ? ~y : y
1357 c = at40k.cell(14, 20);
1360 c = at40k.cell(14, 21);
1364 c = at40k.cell(13, 22);
1366 c.xlut(LUT_OTHER);// | 0xF0);
1368 //c = at40k.cell(13, 22);
1369 //copy(c, NW, EAST);
1375 c.t(false, false, true);
1380 c.ylut(0x54); // (x || z) & !y
1384 c = at40k.cell(2, 21);
1389 c.t(false, false, true);
1396 //at40k.cell(2, 21).xlut(0xF0);
1398 at40k.cell(3, 22).ylut(LUT_OTHER);
1399 at40k.cell(3, 22).xi(SW);
1401 //at40k.iob_top(5, true).enableOutput(SOUTH);
1402 //at40k.iob_top(5, false).enableOutput(SE);
1405 public static int yofs = mullers ? 19 : 22;
1406 public static void counter(At40k at40k, AvrDrone device) throws Exception {
1407 // watch for rising edge from south, emit pulse on Xout (to NE)
1408 //copy(at40k.cell(16,23), SW, WEST);
1410 for(int x=22; x>=1; x-=2) {
1411 pulse_detect(at40k.cell(x, yofs), SE, false);
1412 pulse_detect(at40k.cell(x, yofs-1), EAST, true);
1413 pulse_copy(at40k.cell(x-1, yofs), SE, SOUTH, false);
1414 pulse_copy(at40k.cell(x-1, yofs-1), NE, NORTH, true);
1416 //pulse_detect(at40k.cell(15, 22), NORTH, false);
1417 //pulse_detect(at40k.cell(16, 22), NW, true);
1418 //pulse_copy(at40k.cell(16, 21), NW, WEST, false);
1419 //pulse_copy(at40k.cell(15, 21), NE, EAST, true);
1421 for(int x=23; x>1; x-=2) {
1422 pulse_detect(at40k.cell(x-1, yofs-2), SW, false);
1423 pulse_detect(at40k.cell(x-1, yofs-3), WEST, true);
1424 pulse_copy(at40k.cell(x, yofs-2), SW, SOUTH, false);
1425 pulse_copy(at40k.cell(x, yofs-3), NW, NORTH, true);
1427 //pulse_detect(at40k.cell(15, 22), NORTH, false);
1428 //pulse_detect(at40k.cell(16, 22), NW, true);
1429 //pulse_copy(at40k.cell(16, 21), NW, WEST, false);
1430 //pulse_copy(at40k.cell(15, 21), NE, EAST, true);
1432 copy(at40k.cell(1, yofs-2), SOUTH, SOUTH);
1433 copy(at40k.cell(1, yofs-3), NORTH, NORTH);
1434 at40k.cell(1, yofs-3).ylut(~at40k.cell(1, yofs-3).ylut());
1435 at40k.cell(1, yofs-3).xlut(~at40k.cell(1, yofs-3).xlut());
1437 copy(at40k.cell(23, yofs), SOUTH, SOUTH);
1438 copy(at40k.cell(23, yofs-1), SOUTH, SOUTH);
1440 for(int i=23; i>yofs; i--) copy(at40k.cell(1, i), SOUTH, SOUTH);
1442 //at40k.iob_top(1, true).slew(SLOW);
1443 //at40k.iob_top(1, false).slew(SLOW);
1446 public static void fill(At40k at40k, AvrDrone device, int num) throws Exception {
1447 //muller(at40k.cell(PIPELEN,22), NE, WEST);
1448 At40k.Cell a = at40k.cell(10,22);
1449 At40k.Cell b = at40k.cell(11,22);
1451 for(int i=0; i<num; i++) {
1452 //System.out.println(i);
1455 try { Thread.sleep(1); } catch (Exception e) { }
1458 try { Thread.sleep(1); } catch (Exception e) { }
1463 public static void showit(At40k dev, AvrDrone drone, final Visualizer vis) {
1464 final long then = System.currentTimeMillis();
1465 final Graphics g = vis.getGraphics();
1466 g.setFont(new Font("sansserif", Font.BOLD, 24));
1467 final Color red = new Color(0xff, 0x99, 0x99);
1468 final Color green = new Color(0x99, 0xff, 0x99);
1469 for(int xx=0; xx<=22; xx++) {
1470 for(int yy=23; yy>=0; yy--) {
1471 //for(int xx=5; xx<=PIPELEN-1; xx++) {
1472 //for(int yy=21; yy<=22; yy++) {
1475 final At40k.Cell cell = dev.cell(x, y);
1476 if ((cell.ylut()&0xff)!=0xB2) continue;
1477 AvrDrone.ByteCallback bc = new AvrDrone.ByteCallback() {
1478 public void call(byte b) throws Exception {
1479 boolean v = (b & 0x80) != 0;
1480 vis.drawCell(g, x, y, v?red:green);
1481 //if (x==PIPELEN-1 && y==22) System.out.println("time: " + (System.currentTimeMillis()-then));
1484 scan(dev, cell, NONE, true);
1486 //scan(dev, cell, YLUT, false);
1488 dev.cell(x, 15).h(L3, false);
1489 dev.cell(x, 15).v(L3, false);
1493 public static void drain(At40k at40k, AvrDrone device) throws Exception {
1494 At40k.Cell a = at40k.cell(10,22);
1495 At40k.Cell b = at40k.cell(11,22);
1498 for(int i=0; i<30; i++) {
1499 //System.out.println(i);
1502 try { Thread.sleep(1); } catch (Exception e) { }
1505 try { Thread.sleep(1); } catch (Exception e) { }
1510 public static void doitx(At40k at40k, AvrDrone device) throws Exception {
1511 for(int i=5; i<PIPELEN+1; i++) bounce(at40k.cell(i, 23), SE, SOUTH);
1512 for(int x=5; x<PIPELEN; x++) muller(at40k.cell(x, 22), x==PIPELEN-1 ? SE : NE, WEST);
1514 bounce(at40k.cell(PIPELEN, 21), NW, WEST);
1516 for(int x=5; x<PIPELEN; x++) muller(at40k.cell(x, 21), SW, x==PIPELEN-1 ? NORTH : EAST);
1517 for(int x=4; x<PIPELEN+1; x++) bounce(at40k.cell(x, 20), NW, NORTH);
1519 bounce(at40k.cell(4, 22), SE, EAST);
1520 //muller(at40k.cell(4PIPELEN-1,21), SW, NORTH);
1522 //muller(at40k.cell(4,22), NE, WEST);
1523 //at40k.cell(4,22).ylut(0xEE);
1524 muller(at40k.cell(5, 22), NE, SOUTH);
1525 muller(at40k.cell(5, 21), NW, EAST);
1527 for(int x=4; x>=0; x--) {
1528 at40k.cell(x, 21).ylut(0xAA);
1529 at40k.cell(x, 21).yi(EAST);
1530 at40k.cell(x, 21).yo(false);
1533 at40k.cell(0, 22).ylut(0xAA);
1534 at40k.cell(0, 22).yi(SOUTH);
1535 at40k.cell(0, 22).yo(false);
1537 at40k.cell(0, 23).ylut(~0xAA);
1538 at40k.cell(0, 23).xlut(~0xcc);
1539 at40k.cell(0, 23).yi(SOUTH);
1540 at40k.cell(0, 23).yo(false);
1542 for(int x=3; x<=23; x+=2) {
1543 pulse_detect(at40k.cell(x-1, 19), SW, false);
1544 pulse_detect(at40k.cell(x-1, 18), WEST, true);
1545 pulse_copy(at40k.cell(x, 19), SW, SOUTH, false);
1546 pulse_copy(at40k.cell(x, 18), NW, NORTH, true);
1549 pulse_detect(at40k.cell(x-1, 16), SW, false);
1550 pulse_detect(at40k.cell(x-1, 15), WEST, true);
1551 pulse_copy(at40k.cell(x, 16), SW, SOUTH, false);
1552 pulse_copy(at40k.cell(x, 15), NW, NORTH, true);
1554 //pulse_detect(at40k.cell(15, 22), NORTH, false);
1555 //pulse_detect(at40k.cell(16, 22), NW, true);
1556 //pulse_copy(at40k.cell(16, 21), NW, WEST, false);
1557 //pulse_copy(at40k.cell(15, 21), NE, EAST, true);
1559 for(int x=14; x>=1; x--)
1560 copy(at40k.cell(x, 17), EAST, EAST);
1561 for(int x=4; x>=0; x--)
1562 copy(at40k.cell(x, 21), EAST, EAST);
1563 copy(at40k.cell(13, 17), SOUTH, SOUTH);
1565 copy(at40k.cell(0, 20), NORTH, NORTH);
1566 copy(at40k.cell(0, 19), NORTH, NORTH);
1567 copy(at40k.cell(0, 18), NORTH, NORTH);
1568 copy(at40k.cell(0, 17), NORTH, NORTH);
1569 copy(at40k.cell(0, 16), NORTH, NORTH);
1570 copy(at40k.cell(1, 16), WEST, WEST);
1571 copy(at40k.cell(1, 15), NORTH, NORTH);
1573 copy(at40k.cell(1, 20), SOUTH, SOUTH);
1574 copy(at40k.cell(1, 19), SOUTH, SOUTH);
1575 copy(at40k.cell(1, 18), SOUTH, SOUTH);
1577 for(int y=20; y<=23; y++)
1578 copy(at40k.cell(23, y), SOUTH, SOUTH);
1581 //for(int x=19; x<=23; x++)
1582 //copy(at40k.cell(x, 0), WEST, WEST);
1583 //copy(at40k.cell(18, 19), NW, NW);
1584 //at40k.iob_top(5, true).enableOutput(SOUTH);
1585 //at40k.iob_top(5, false).enableOutput(SOUTH);