+/TECS
git clone https://git.julia.blue/+/TECS
bf94f33
master
1/** 2 * A library that supports various program execution services. 3 */ 4class Sys { 5 6 /** Performs all the initializations required by the OS. */ 7 function void init() { 8 do Memory.init(); 9 do Keyboard.init(); 10 do Math.init(); 11 do Output.init(); 12 do Screen.init(); 13 do Main.main(); 14 do Sys.halt(); 15 } 16 17 /** Halts the program execution. */ 18 function void halt() { 19 while(true){} 20 } 21 22 /** Waits approximately duration milliseconds and returns. */ 23 function void wait(int duration) { 24 var int delay; 25 if(duration < 0){ 26 do Sys.error(1); 27 } 28 let delay = 500; // Adjust based on cpu speed 29 while(duration > 0){ 30 while(delay > 0){ 31 let delay = delay - 1; 32 } 33 let delay = 500; 34 let duration = duration - 1; 35 } 36 return; 37 } 38 39 /** Displays the given error code in the form "ERR<errorCode>", 40 * and halts the program's execution. */ 41 function void error(int errorCode) { 42 do Output.printString("ERR<"); 43 do Output.printInt(errorCode); 44 do Output.printString(">"); 45 do Sys.halt(); 46 } 47}