mirror of
https://github.com/soconnor0919/eceg431.git
synced 2025-12-11 06:34:43 -05:00
60 lines
1.7 KiB
Plaintext
60 lines
1.7 KiB
Plaintext
// This file is part of www.nand2tetris.org
|
|
// and the book "The Elements of Computing Systems"
|
|
// by Nisan and Schocken, MIT Press.
|
|
// File name: projects/12/Sys.jack
|
|
|
|
/**
|
|
* A library that supports various program execution services.
|
|
*/
|
|
class Sys {
|
|
|
|
/** Performs all the initializations required by the OS. */
|
|
function void init() {
|
|
// do Memory.poke(8000, 1); // Start
|
|
do Memory.init();
|
|
// do Memory.poke(8000, 2); // Mem init done
|
|
do Math.init();
|
|
// do Memory.poke(8000, 3); // Math init done
|
|
do Screen.init();
|
|
do Output.init();
|
|
do Keyboard.init();
|
|
do Main.main();
|
|
do Sys.halt();
|
|
return;
|
|
}
|
|
|
|
/** Halts the program execution. */
|
|
function void halt() {
|
|
while (true) {}
|
|
return;
|
|
}
|
|
|
|
/** Waits approximately duration milliseconds and returns. */
|
|
function void wait(int duration) {
|
|
var int i, j;
|
|
let i = 0;
|
|
|
|
while (i < duration) {
|
|
let j = 0;
|
|
// Calibration: loop count determines delay.
|
|
// On typical VM emulator settings (Fast), ~50-100 loops might be 1ms?
|
|
// "WaitWithInput" sample in Snake used loop for waiting.
|
|
|
|
while (j < 50) {
|
|
let j = j + 1;
|
|
}
|
|
let i = i + 1;
|
|
}
|
|
return;
|
|
}
|
|
|
|
/** Displays the given error code in the form "ERR<errorCode>",
|
|
* and halts the program's execution. */
|
|
function void error(int errorCode) {
|
|
do Output.printString("ERR");
|
|
do Output.printInt(errorCode);
|
|
do Sys.halt();
|
|
return;
|
|
}
|
|
}
|