Address the tape with a yoob.Cursor which is displayed in the view.
Chris Pressey
5 years ago
113 | 113 | } else if (k === 'NOP') { |
114 | 114 | } else if (k === 'SHU') { |
115 | 115 | if (ip.isHeaded(-1, 0)) { |
116 | ip.setY(ip.getY() - tape.get(head)); | |
116 | ip.setY(ip.getY() - tape.read()); | |
117 | 117 | } else if (ip.isHeaded(1, 0)) { |
118 | ip.setY(ip.getY() + tape.get(head)); | |
118 | ip.setY(ip.getY() + tape.read()); | |
119 | 119 | } else if (ip.isHeaded(0, -1)) { |
120 | ip.setX(ip.getX() + tape.get(head)); | |
120 | ip.setX(ip.getX() + tape.read()); | |
121 | 121 | } else if (ip.isHeaded(0, 1)) { |
122 | ip.setX(ip.getX() - tape.get(head)); | |
122 | ip.setX(ip.getX() - tape.read()); | |
123 | 123 | } |
124 | 124 | } else if (k === 'ROT') { |
125 | 125 | ip.rotateCounterclockwise(); |
127 | 127 | opp.rotateCounterclockwise(); |
128 | 128 | opp.rotateCounterclockwise(); |
129 | 129 | } else if (k === 'LEF') { |
130 | head--; | |
130 | head.moveLeft(); | |
131 | 131 | } else if (k === 'RIG') { |
132 | head++; | |
132 | head.moveRight(); | |
133 | 133 | } else if (k === 'NEG') { |
134 | tape.put(head, -1); | |
134 | tape.write(-1); | |
135 | 135 | } else if (k === 'BLA') { |
136 | tape.put(head, 0); | |
136 | tape.write(0); | |
137 | 137 | } else if (k === 'PLU') { |
138 | tape.put(head, 1); | |
138 | tape.write(1); | |
139 | 139 | } else if (k === 'OUT') { |
140 | this.outputElem.innerHTML += (tape.get(head) === 0 ? '0' : '1'); | |
140 | this.outputElem.innerHTML += (tape.read() === 0 ? '0' : '1'); | |
141 | 141 | } else if (k === 'INP') { |
142 | 142 | var c = this.inputElem.value; |
143 | 143 | if (c === '') { |
144 | 144 | return 'block'; |
145 | 145 | } |
146 | tape.put(head, c.charAt(0) === '1' ? 1 : 0); | |
146 | tape.write(c.charAt(0) === '1' ? 1 : 0); | |
147 | 147 | this.inputElem.value = c.substr(1); |
148 | 148 | } |
149 | 149 | } else { |
171 | 171 | opp.dx = 0; |
172 | 172 | opp.dy = 1; |
173 | 173 | |
174 | tape = (new yoob.Tape()).init({}); | |
174 | head = (new yoob.Cursor()).init(); | |
175 | tape = (new yoob.Tape()).init({ | |
176 | cursors: [head] | |
177 | }); | |
175 | 178 | this.tapeView.setTape(tape); |
176 | head = 0; | |
177 | 179 | |
178 | 180 | this.inputElem.value = ""; |
179 | 181 | this.outputElem.innerHTML = ""; |