// 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/KeyboardTest/Main.jack /** Test program for the OS Keyboard class. */ class Main { /** Gets input from the user and verifies its contents. */ function void main() { var char c, key; var String s; var int i; var boolean ok; do StdIO.printString("StdIO test:"); do StdIO.println(); let ok = false; while (~ok) { do StdIO.printString("Please press the number '3': "); let c = UART.readChar(); do StdIO.println(); if (c = 51) { do StdIO.printString("ok"); do StdIO.println(); let ok = true; } } let ok = false; do StdIO.printString("readLine test:"); do StdIO.println(); do StdIO.printString("(Verify echo and usage of 'backspace')"); do StdIO.println(); while (~ok) { let s = StdIO.readLine("Please type 'JACK' and press enter: "); if (s.length() = 4) { if ((s.charAt(0) = 74) & (s.charAt(1) = 65) & (s.charAt(2) = 67) & (s.charAt(3) = 75)) { do StdIO.printString("ok"); do StdIO.println(); let ok = true; } } } let ok = false; do StdIO.printString("readInt test:"); do StdIO.println(); do StdIO.printString("(Verify echo and usage of 'backspace')"); do StdIO.println(); while (~ok) { let i = StdIO.readInt("Please type '-32123' and press enter: "); if (i = (-32123)) { do StdIO.printString("ok"); do StdIO.println(); let ok = true; } } do StdIO.println(); do StdIO.printString("Test completed successfully"); return; } }