diff --git a/README.md b/README.md index dfccac0..2e55c47 100644 --- a/README.md +++ b/README.md @@ -75,14 +75,14 @@ cargo run --bin rusty_man_computer -- --ram demos/factorial.bin At the moment, the easiest way to write a program is using the assembly language in the [online simulator](https://peterhigginson.co.uk/lmc/). Write the assembly code, click "ASSEMBLE INTO RAM", and click-and-drag to copy the contents of the memory text boxes (you can leave out any empty memory at the end). -At the moment, you have to use a text editor to ensure that each memory cell is only separated by a space, and not a line break. (This can also be accomplished by pasting the memory contents into the address bar of your browser, and copying it from there.) - Then you can run `bin_creator`, giving it the file name that the binary file should be written to, e.g. ```bash cargo run --bin bin_creator -- my_program.bin ``` +Follow the prompt to paste the memory data into your terminal, and press Enter twice in a row to mark the end of the data. + Then you can run the program as described above, e.g. ```bash diff --git a/src/bin_creator.rs b/src/bin_creator.rs index 6832cde..6d0c491 100644 --- a/src/bin_creator.rs +++ b/src/bin_creator.rs @@ -14,10 +14,16 @@ fn main() -> Result<(), Box> { let filename = &args[1]; // Let the user paste in a string - println!("Paste in the memory data:"); + println!("Paste the memory data below, then press Enter twice to submit:"); let mut line = String::new(); let stdin = io::stdin(); - stdin.lock().read_line(&mut line)?; + // Accept input until enter is pressed twice + loop { + stdin.lock().read_line(&mut line)?; + if line.chars().rev().take(2).collect::() == "\n\n" { + break; + } + } // Split the string into a vector i16 signed ints let memory_data_items: Vec = line @@ -34,5 +40,6 @@ fn main() -> Result<(), Box> { // Write the memory data to a binary file fs::write(filename, memory_data_bytes)?; + println!("Successfully created binary file: {}", filename); Ok(()) }