Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Use a buffer for keyboard input.

  • Loading branch information...
commit 40274037ae3b14cb62a2e12fe5de9840d6e26288 1 parent bc8f7ae
Nelson Elhage authored

Showing 1 changed file with 10 additions and 7 deletions. Show diff stats Hide diff stats

  1. +10 7 CPU.js
17 CPU.js
@@ -96,9 +96,12 @@ function callout(op) {
96 96 CPU.config.write(CPU.regs[op.ra]);
97 97 break;
98 98 case CALL_RDCHR:
99   - CPU.regs[0] = CPU.next_key;
100   - CPU.next_key = 0;
101   - CPU.pending_interrupts &= ~INT_KBD;
  99 + if (CPU.key_buffer.length)
  100 + CPU.regs[0] = CPU.key_buffer.shift();
  101 + else
  102 + CPU.regs[0] = 0;
  103 + if (CPU.key_buffer.length == 0)
  104 + CPU.pending_interrupts &= ~INT_KBD;
102 105 break;
103 106 }
104 107 } else {
@@ -169,7 +172,7 @@ var CPU = {
169 172 callback: null,
170 173 config: null,
171 174 clock: null,
172   - next_key: 0,
  175 + key_buffer: [],
173 176
174 177 decode: function(op) {
175 178 return {
@@ -191,7 +194,7 @@ var CPU = {
191 194 CPU.callback = null;
192 195 CPU.config = {};
193 196 CPU.clock = null;
194   - CPU.next_key = 0;
  197 + CPU.key_buffer = [];
195 198 },
196 199
197 200 step: function() {
@@ -251,7 +254,7 @@ var CPU = {
251 254
252 255 _run: function() {
253 256 var i = 0;
254   - while (i++ < 100 && !CPU.halt)
  257 + while (i++ < 1000 && !CPU.halt)
255 258 CPU.step();
256 259 if (CPU.halt) {
257 260 if (CPU.clock)
@@ -264,7 +267,7 @@ var CPU = {
264 267
265 268 press_key: function(ch) {
266 269 CPU.pending_interrupts |= INT_KBD;
267   - CPU.next_key = ch;
  270 + CPU.key_buffer.push(ch);
268 271 },
269 272
270 273 jmp: function(addr) {

0 comments on commit 4027403

Please sign in to comment.
Something went wrong with that request. Please try again.