Permalink
Browse files

Add mouse handling to the browser frontend.

  • Loading branch information...
1 parent 0120bd4 commit 4f0260a9a482712be2adf85f1a906ae294c3a23a @nelhage committed May 30, 2011
Showing with 26 additions and 0 deletions.
  1. +20 −0 CPU.js
  2. +6 −0 beta.html
View
20 CPU.js
@@ -9,6 +9,7 @@ const ISR_MOUSE = (PC_SUPERVISOR | 0x00000010);
const CALL_HALT = 0x00;
const CALL_RDCHR = 0x01;
const CALL_WRCHR = 0x02;
+const CALL_MOUSE = 0x05;
/* Interrupt flags in 'pending_interrupts' */
const INT_CLK = 0x0001;
@@ -102,6 +103,16 @@ function callout(op) {
if (CPU.key_buffer.length == 0)
CPU.pending_interrupts &= ~INT_KBD;
break;
+ case CALL_MOUSE:
+ var mouse;
+ if (CPU.mouse) {
+ mouse = (CPU.mouse.x << 16) | (CPU.mouse.y & 0xFFFF);
+ CPU.mouse = null;
+ } else {
+ mouse = -1;
+ }
+ CPU.regs[0] = mouse;
+ CPU.pending_interrupts &= ~INT_MOUSE;
}
} else {
invalid(op);
@@ -173,6 +184,7 @@ var CPU = {
clock: null,
run_timer: null,
key_buffer: [],
+ mouse: null,
decode: function(op) {
return {
@@ -196,6 +208,7 @@ var CPU = {
CPU.clock = null;
CPU.run_timer = null;
CPU.key_buffer = [];
+ CPU.mouse = null;
},
step: function() {
@@ -228,6 +241,8 @@ var CPU = {
isr = ISR_CLK;
} else if (CPU.pending_interrupts & INT_KBD) {
isr = ISR_KBD;
+ } else if (CPU.pending_interrupts & INT_MOUSE) {
+ isr = ISR_MOUSE;
}
if (isr) {
CPU.regs[XP] = CPU.PC + 4;
@@ -272,6 +287,11 @@ var CPU = {
CPU.key_buffer.push(ch);
},
+ click: function(x, y) {
+ CPU.mouse = {x:x, y:y};
+ CPU.pending_interrupts |= INT_MOUSE;
+ },
+
jmp: function(addr) {
debug("jump %x", addr);
CPU.PC = (addr & (0x7FFFFFFC | (CPU.PC & PC_SUPERVISOR)));
View
@@ -29,6 +29,9 @@
term.type("--- Program terminated ----");
}});
CPU.run();
+
+ var div = document.getElementById('termDiv');
+ div.onmousedown = mouseHandler;
}
function initTerm() {
@@ -39,6 +42,9 @@
if (ch == 13) ch = 10;
CPU.press_key(ch);
}
+ function mouseHandler(evt) {
+ CPU.click(evt.x, evt.y);
+ }
</script>
</head>

0 comments on commit 4f0260a

Please sign in to comment.