jsos
college code for operating system fundamentals in js
git clone https://9o.is/git/jsos.git
devices.js
(1977B)
1 /* ------------
2 Devices.js
3
4 Requires global.js.
5
6 Routines for the simulation, NOT for our client OS itself. In this manner, it's A LITTLE BIT like a hypervisor,
7 in that the Document envorinment inside a browser is the "bare metal" (so to speak) for which we write code
8 that hosts our client OS. But that analogy only goes so far, and the lines are blurred, because we are using
9 JavaScript in both the host and client environments.
10
11 This (and simulation scripts) is the only place that we should see "web" code, like
12 DOM manipulation and JavaScript event handling, and so on. (Index.html is the only place for markup.)
13
14 This code references page numbers in the text book:
15 Operating System Concepts 8th editiion by Silberschatz, Galvin, and Gagne. ISBN 978-0-470-12872-5
16 ------------ */
17
18 var hardwareClockID = -1;
19
20 /*
21 * The Hardware Clock Pulse: increments the hardware (host)
22 * clock and calls the kernel clock pulse event handler.
23 */
24 function simClockPulse() {
25 _OSclock++;
26 krnOnCPUClockPulse();
27 }
28
29
30 /*
31 * The Keyboard Interrupt, a HARDWARE Interrupt Request.
32 * Listen for keydown event in the document and invoke
33 * simOnKeypress function. (See pages 560-561 in text book.)
34 */
35 function simEnableKeyboardInterrupt() {
36 document.addEventListener("keydown", simOnKeypress, false);
37 }
38
39 /*
40 * Removes the Keyboard Interrupt.
41 */
42 function simDisableKeyboardInterrupt() {
43 document.removeEventListener("keydown", simOnKeypress, false);
44 }
45
46 /*
47 * Puts the key pressed in the keyboard interrupt queue so
48 * that it gets to the Interrupt handler.
49 *
50 * NOTE:
51 * - canvas element ONLY receives focus if you give it a tabindex.
52 * - the pressed key code in the params is Mozilla-specific.
53 */
54 function simOnKeypress(event) {
55 if (event.target.id == CANVAS_ID) {
56 event.preventDefault();
57 var params = new Array(event.which, event.shiftKey);
58 _KernelInterruptQueue.enqueue( new Interrupt(KEYBOARD_IRQ, params) );
59 }
60 }