diff --git a/simple_test_machine/programs/assemble.bat b/simple_test_machine/programs/assemble.bat index 1c2d357..85b7c34 100644 --- a/simple_test_machine/programs/assemble.bat +++ b/simple_test_machine/programs/assemble.bat @@ -1,8 +1,9 @@ +@echo off + REM Usage: Drop the win2c64 directory into the same directory with this script REM Directory structure should be: ./assemble.bat ./win2c64/win2c64.exe ./bin -@echo off set src_file=%1 echo assembling %src_file% diff --git a/simple_test_machine/programs/echo.asm b/simple_test_machine/programs/echo.asm index ea431ca..03a0e9d 100644 --- a/simple_test_machine/programs/echo.asm +++ b/simple_test_machine/programs/echo.asm @@ -1,6 +1,6 @@ ; echo example - takes input and then prints it back out -; This is for testing input of the Simple Test Machine +; This is for testing I/O of the Simple Test Machine ; by Joey Pollack ; assemble with win2c64 (or lin2c64, or mac2c64) using the -R option diff --git a/simple_test_machine/src/machine.rs b/simple_test_machine/src/machine.rs index d7e085c..961838a 100644 --- a/simple_test_machine/src/machine.rs +++ b/simple_test_machine/src/machine.rs @@ -132,33 +132,37 @@ impl Console let mut value = bus.read(CONSOLE_FLAGS_ADDR); if (value & READ_LINE_FLAG) != 0 { + // reset the flag + value &= !(READ_LINE_FLAG); + let mut buffer = String::new(); let stdin = io::stdin(); stdin.read_line(&mut buffer).expect("Failed to read input from the console"); // Make sure the string will fit in the input buffer if (buffer.len() + 1) as u16 >= INPUT_BUF_SIZE - { - // reset the read flag and set the overflow flag - value &= !(READ_LINE_FLAG); + { + // The input is too large for the buffer so + // set the overflow flag value |= READ_OVERFLOW_FLAG; - bus.write(CONSOLE_FLAGS_ADDR, value); - - println!("ERROR: Console cannot store input string into memory, string is too large"); - return; } // Store input in the input buffer for (i, byte) in buffer.chars().enumerate() { + // Truncate the input if it's too large for the buffer + if i as u16 >= INPUT_BUF_SIZE + { + break; + } + bus.write(INPUT_BUF_ADDR + (i as u16), byte as u8); } // Add the null byte to the end bus.write(INPUT_BUF_ADDR + buffer.len() as u16, 0); - // reset the flag - value &= !(READ_LINE_FLAG); + // store the flags back into memory bus.write(CONSOLE_FLAGS_ADDR, value); }