/** * A library that supports various program execution services. */ class Sys { /** Performs all the initializations required by the OS. */ function void init() { do Memory.init(); do Keyboard.init(); do Math.init(); do Output.init(); do Screen.init(); do Main.main(); do Sys.halt(); } /** Halts the program execution. */ function void halt() { while(true){} } /** Waits approximately duration milliseconds and returns. */ function void wait(int duration) { var int delay; if(duration < 0){ do Sys.error(1); } let delay = 500; // Adjust based on cpu speed while(duration > 0){ while(delay > 0){ let delay = delay - 1; } let delay = 500; let duration = duration - 1; } return; } /** Displays the given error code in the form "ERR", * and halts the program's execution. */ function void error(int errorCode) { do Output.printString("ERR<"); do Output.printInt(errorCode); do Output.printString(">"); do Sys.halt(); } }