Dvi.ship: software implementatino
authorAdam Megacz <adam@megacz.com>
Sat, 29 Aug 2009 23:05:21 +0000 (16:05 -0700)
committerAdam Megacz <adam@megacz.com>
Sat, 29 Aug 2009 23:05:21 +0000 (16:05 -0700)
ships/Dvi.ship

index ee02bc4..100314f 100644 (file)
@@ -551,36 +551,69 @@ NET  sram_oe_b            LOC="B12";   # Bank 20, Vcco=3.3V, DCI using 49.9 ohm
 == TeX ==============================================================
 
 == Fleeterpreter ====================================================
 == TeX ==============================================================
 
 == Fleeterpreter ====================================================
-
-  private java.awt.Frame frame = null;
-  public void service() {
-  if (box_inPixelX.dataReadyForShip() &&
-      box_inPixelY.dataReadyForShip() &&
-      box_inPixelValue.dataReadyForShip()
-      ) {
-      long x      = box_inPixelX.removeDataForShip();
-      long y      = box_inPixelY.removeDataForShip();
-      long d      = box_inPixelValue.removeDataForShip();
-
-      if (frame==null) {
-           frame = new java.awt.Frame();
-           java.awt.Dimension dim = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
-           frame.setSize((int)dim.getWidth(),(int)dim.getHeight());
-           frame.show();
-           frame.setBackground(new java.awt.Color(0,0,0));
-      }
-      java.awt.Color c = new java.awt.Color(
-         ((d & (1L<<2))!=0) ? 0xff : 0x00,
-         ((d & (1L<<1))!=0) ? 0xff : 0x00,
-         ((d & (1L<<0))!=0) ? 0xff : 0x00
-      );
-      java.awt.Graphics2D g = (java.awt.Graphics2D)frame.getGraphics();
-      g.transform(java.awt.geom.AffineTransform.getScaleInstance(((double)frame.getWidth())/640, ((double)frame.getHeight())/480));
-      g.setColor(c);
-      g.fillRect((int)x,(int)y,1,1);
-
+private java.awt.Frame frame = null;
+private java.awt.Panel panel = null;
+private long[][] bits;
+public static int SCREEN_WIDTH = 577;
+public static int SCREEN_HEIGHT = 478;
+public void service() {
+    long x,y,d;
+    if (box_inPixelX.dataReadyForShip() &&
+        box_inPixelY.dataReadyForShip() &&
+        box_inPixelValue.dataReadyForShip()) {
+        x      = box_inPixelX.removeDataForShip();
+        y      = box_inPixelY.removeDataForShip();
+        d      = box_inPixelValue.removeDataForShip();
+    } else if (box_inAddrWrite.dataReadyForShip() &&
+               box_inDataWrite.dataReadyForShip() &&
+               box_out.readyForDataFromShip()) {
+        long addr = box_inAddrWrite.removeDataForShip();
+        x      = addr % SCREEN_WIDTH;
+        y      = addr / SCREEN_WIDTH;
+        d      = box_inDataWrite.removeDataForShip();
+        box_out.addDataFromShip(0,true);
+    } else if (box_inAddrRead.dataReadyForShip() &&
+               box_out.readyForDataFromShip()) {
+        long addr = box_inAddrRead.removeDataForShip();
+        x      = addr % SCREEN_WIDTH;
+        y      = addr / SCREEN_WIDTH;
+        box_out.addDataFromShip(bits[(int)x][(int)y],false);
+        return;
+    } else {
+        return;
+    }
+    if (frame==null) {
+        frame = new java.awt.Frame();
+        bits = new long[SCREEN_WIDTH][SCREEN_HEIGHT];
+        for(int i=0; i<SCREEN_WIDTH; i++) bits[i] = new long[SCREEN_HEIGHT];
+        frame.setSize(SCREEN_WIDTH,SCREEN_HEIGHT);
+        panel = new java.awt.Panel() {
+                public void paint(java.awt.Graphics g_) {
+                    java.awt.Graphics2D g2 = (java.awt.Graphics2D)g_;
+                    g2.transform(java.awt.geom.AffineTransform.getScaleInstance(((double)panel.getWidth())/SCREEN_WIDTH,
+                                                                                ((double)panel.getHeight())/SCREEN_HEIGHT));
+                    for(int xx=0; xx<SCREEN_WIDTH; xx++) {
+                        for(int yy=0; yy<SCREEN_HEIGHT; yy++) {
+                            long d = bits[xx][yy];
+                            java.awt.Color c = new java.awt.Color(
+                                                                  (int)(((d >> 12) & ~((-1L) << 6)) << 2),
+                                                                  (int)(((d >>  6) & ~((-1L) << 6)) << 2),
+                                                                  (int)(((d >>  0) & ~((-1L) << 6)) << 2)
+                                                                  );
+                            g2.setColor(c);
+                            g2.fillRect((int)xx,(int)yy,1,1);
+                        }
+                    }
+                }
+            };
+        frame.setLayout(new java.awt.BorderLayout());
+        frame.add(panel, java.awt.BorderLayout.CENTER);
+        panel.setBackground(java.awt.Color.black);
+        frame.show();
     }
     }
-  }
+    bits[(int)x][(int)y] = d;
+    panel.repaint();
+}
 
 == FleetSim ==============================================================
 
 
 == FleetSim ==============================================================