telnet now will load the IBM logo and run through it.
This commit is contained in:
parent
8c22cf9308
commit
c9c9cf67da
@ -1,3 +1,6 @@
|
|||||||
|
use std::fs::File;
|
||||||
|
use std::io::{BufReader, Read};
|
||||||
|
use std::path::{Path, PathBuf};
|
||||||
use crate::chip8::computer::Chip8Computer;
|
use crate::chip8::computer::Chip8Computer;
|
||||||
use crate::chip8::cpu_states::Chip8CpuStates;
|
use crate::chip8::cpu_states::Chip8CpuStates;
|
||||||
use crate::chip8::cpu_states::Chip8CpuStates::WaitingForInstruction;
|
use crate::chip8::cpu_states::Chip8CpuStates::WaitingForInstruction;
|
||||||
@ -142,4 +145,26 @@ impl Chip8ComputerManager {
|
|||||||
ManagerDumpables::Keyboard => self.computer.keypad.format_as_string(),
|
ManagerDumpables::Keyboard => self.computer.keypad.format_as_string(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn load_new_program_from_disk_to_system_memory(&mut self, file_to_load: &Path) {
|
||||||
|
println!("ComputerManager: Preparing to load {}", file_to_load.display());
|
||||||
|
// load the file into bytes...
|
||||||
|
let file = File::open(file_to_load).unwrap();
|
||||||
|
let mut reader = BufReader::new(file);
|
||||||
|
let mut chunks = Vec::new();
|
||||||
|
|
||||||
|
loop {
|
||||||
|
let mut buffer = vec![0u8; 1];
|
||||||
|
let bytes_read = reader.read(&mut buffer).unwrap_or(0);
|
||||||
|
if bytes_read == 0 {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
buffer.truncate(bytes_read);
|
||||||
|
chunks.push(buffer[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
self.load_new_program_to_system_memory(chunks);
|
||||||
|
// ...then use the existing method
|
||||||
|
self.core_should_run = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,6 +5,7 @@ use gemma::chip8::quirk_modes::QuirkMode;
|
|||||||
use crate::telnet_utils::list_of_files_in_directory;
|
use crate::telnet_utils::list_of_files_in_directory;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
use gemma::constants::RESOURCES_ROOT;
|
||||||
|
|
||||||
const CANT_NOTIFY_ERROR: &str = "Unable to notify client";
|
const CANT_NOTIFY_ERROR: &str = "Unable to notify client";
|
||||||
const MENU_TEXT: &str = r#"
|
const MENU_TEXT: &str = r#"
|
||||||
@ -84,11 +85,14 @@ pub fn handle_client(mut stream: TcpStream) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
"load" => {
|
"load" => {
|
||||||
|
let file_to_use = p1.unwrap_or("default.ch8");
|
||||||
// chip8 = Chip8ComputerManager::from(chip8).load_new_program_to_system_memory()
|
// chip8 = Chip8ComputerManager::from(chip8).load_new_program_to_system_memory()
|
||||||
message_to_send = format!("Preparing to load {} from disk.",
|
message_to_send = format!("Preparing to load {} from disk.",
|
||||||
p1.unwrap_or("default.ch8").trim());
|
p1.unwrap_or("default.ch8").trim());
|
||||||
chip8.start();
|
|
||||||
|
chip8.load_new_program_from_disk_to_system_memory(
|
||||||
|
Path::new(format!("{}/roms/{}", RESOURCES_ROOT, file_to_use).as_str())
|
||||||
|
);
|
||||||
}
|
}
|
||||||
"menu" => {
|
"menu" => {
|
||||||
message_to_send = MENU_TEXT.to_string();
|
message_to_send = MENU_TEXT.to_string();
|
||||||
|
|||||||
BIN
resources/roms/default.ch8
Normal file
BIN
resources/roms/default.ch8
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user