Commits

Cat's Eye Technologies  committed a4660f1

Show tape, input and output, end program on END or out of bounds.

  • Participants
  • Parent commits 89fe77a

Comments (0)

Files changed (2)

File impl/wunnel.js/demo/wunnel.html

     font-family: monospace;
     float: left;
 }
+#tape_display {
+    border: 1px solid black;
+}
 #output {
     color: white;
     background: #008000;
 <div id="display_container">
   <pre id="program_display"></pre>
   <pre id="op_table_display"></pre>
+  <div style="clear: both"></div>
+  <canvas id="tape_display" width="400" height="100"></canvas><br />
+  Input: <input id="input"></input><br />
+  Output: <div id="output"></div>
 </div>
 
 <textarea id="program" rows="25" cols="40"></textarea>
          o    oooo o
 </div>
 
+<div id="just-end" class="example_program"
+>.
+
+
+  o
+  
+  
+o o</div>
+
+<div id="experiment" class="example_program"
+>.    .
+
+
+
+    oo o
+    o  o
+
+
+o    o
+
+
+
+o    o
+</div>
+
 </body>
 <script src="../src/yoob/playfield.js"></script>
 <script src="../src/yoob/playfield-html-view.js"></script>
   };
   var c = (new WunnelController()).init({
       programView: programView,
-      opTableView: opTableView
+      opTableView: opTableView,
+      tapeCanvas: document.getElementById("tape_display"),
+      inputElem: document.getElementById("input"),
+      outputElem: document.getElementById("output")
   });
   c.connect({
     'start': 'start',

File impl/wunnel.js/src/wunnel-controller.js

  * requires yoob.Playfield
  * requires yoob.Cursor
  * requires yoob.Tape
- * ...VERY INCOMPLETE.
+ * ...INCOMPLETE.
  */
 function WunnelPlayfield() {
     this.setDefault(' ');
+    
+    this.inBounds = function(x, y) {
+        return (x >= this.minX && x <= this.maxX &&
+                y >= this.minY && y <= this.maxY);
+    };
 };
 WunnelPlayfield.prototype = new yoob.Playfield();
 
 
 
 function OpTableCursor() {
-    this.getX = function() { return this.x; }
-    this.getY = function() { return this.y; }
-    this.setX = function(x) { this.x = x; }
-    this.setY = function(y) { this.y = y; }
-    
     this.advance = function() {
         this.x += this.dx;
         if (this.x < 0) this.x = 5;
     this.init = function(cfg) {
         this.programView = cfg.programView;
         this.opTableView = cfg.opTableView;
+        this.tapeCanvas = cfg.tapeCanvas;
+        this.inputElem = cfg.inputElem;
+        this.outputElem = cfg.outputElem;
 
         pf = new WunnelPlayfield();
         ip = new WunnelCursor(0, 0, 1, 1);
     };
 
     this.step = function() {
+        if (halted) return;
+
         var instruction = pf.get(ip.x, ip.y);
         var k = optab.get(opp.x, opp.y);
 
         if (this.genusMoreThanZero(instruction)) {
             if (k === 'END') {
                 halted = true;
-                return errors;
+                return;
             } else if (k === 'NOP') {
             } else if (k === 'SHU') {
                 if (ip.isHeaded(-1, 0)) {
             } else if (k === 'PLU') {
                 tape.put(head, 1);
             } else if (k === 'OUT') {
-                var i = tape.get(head);
-                if (i === 0) {
-                    //world.output(new CharacterElement('0'));
-                } else {
-                    //world.output(new CharacterElement('1'));
+                this.outputElem.innerHTML += (tape.get(head) === 0 ? '0' : '1');
+            } else if (k === 'INP') {
+                var c = this.inputElem.value;
+                if (c === '') {
+                    needsInput = true;
+                    halted = true; // XXX
+                    return;
                 }
-            } else if (k === 'INP') {
-                var c = '0'; // world.inputCharacter();
-                if (c == null) {
-                    needsInput = true;
-                    return errors;
-                }
-                if (c === '1') {
-                    tape.put(head, 1);
-                } else {
-                    tape.put(head, 0);
-                }
+                tape.put(head, c.charAt(0) === '1' ? 1 : 0);
+                this.inputElem.value = c.substr(1);
             }
         } else {
             opp.advance();
         }
 
         ip.advance();
-        /*
-        if (playfield.hasFallenOffEdge(ip)) {
+        if (!pf.inBounds(ip.x, ip.y)) {
             halted = true;
         }
-        */
 
-        this.programView.draw();
-        this.opTableView.draw();
-
+        this.draw();
         needsInput = false;
     }
 
 
         tape = new yoob.Tape();
         head = 0;
+
+        halted = false;
+        this.draw();
+    };
+    
+    this.draw = function() {
         this.programView.draw();
         this.opTableView.draw();
+        tape.drawCanvas(this.tapeCanvas, 12, 12, []);
     };
 };
 WunnelController.prototype = new yoob.Controller();