mirror of
https://github.com/soconnor0919/eceg431.git
synced 2025-12-11 22:54:43 -05:00
project12 - complete
This commit is contained in:
31
12/Sys.jack
31
12/Sys.jack
@@ -10,18 +10,49 @@ class Sys {
|
||||
|
||||
/** Performs all the initializations required by the OS. */
|
||||
function void init() {
|
||||
do Memory.init();
|
||||
do Math.init();
|
||||
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?
|
||||
// User requested 2 seconds wait in test.
|
||||
// "WaitWithInput" sample in Snake used loop for waiting.
|
||||
|
||||
// Standard N2T value is roughly 50-100.
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user