// 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() { //OSの初期化 //do Array.init(); // Memoryは他のinit関数が使うので最初に初期化 do Memory.init(); do Keyboard.init(); do Math.init(); do Output.init(); do Screen.init(); //do String.init(); //Main.main()を呼び出す 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, max; let max = 100; let j = 0; while(j < duration) { let i = 0; while(i < max) {let i = i + 1;} let j = j + 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("Error: "); do Output.printInt(errorCode); //処理完了 do Sys.halt(); return; } }