From c9c9cf67dacbf27768119991cd357f8d8808c527 Mon Sep 17 00:00:00 2001 From: Trevor Merritt Date: Thu, 22 May 2025 14:15:38 -0400 Subject: [PATCH] telnet now will load the IBM logo and run through it. --- gemma/src/chip8/computer_manager.rs | 25 +++++++++++++++++++++++++ gemmatelnet/src/client_handler.rs | 8 ++++++-- resources/roms/default.ch8 | Bin 0 -> 132 bytes 3 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 resources/roms/default.ch8 diff --git a/gemma/src/chip8/computer_manager.rs b/gemma/src/chip8/computer_manager.rs index 8174890..98be529 100644 --- a/gemma/src/chip8/computer_manager.rs +++ b/gemma/src/chip8/computer_manager.rs @@ -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::cpu_states::Chip8CpuStates; use crate::chip8::cpu_states::Chip8CpuStates::WaitingForInstruction; @@ -142,4 +145,26 @@ impl Chip8ComputerManager { 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; + } } diff --git a/gemmatelnet/src/client_handler.rs b/gemmatelnet/src/client_handler.rs index f1b53fa..deabf3a 100644 --- a/gemmatelnet/src/client_handler.rs +++ b/gemmatelnet/src/client_handler.rs @@ -5,6 +5,7 @@ use gemma::chip8::quirk_modes::QuirkMode; use crate::telnet_utils::list_of_files_in_directory; use std::io::Write; use std::path::Path; +use gemma::constants::RESOURCES_ROOT; const CANT_NOTIFY_ERROR: &str = "Unable to notify client"; const MENU_TEXT: &str = r#" @@ -84,11 +85,14 @@ pub fn handle_client(mut stream: TcpStream) { ); } "load" => { - + let file_to_use = p1.unwrap_or("default.ch8"); // chip8 = Chip8ComputerManager::from(chip8).load_new_program_to_system_memory() message_to_send = format!("Preparing to load {} from disk.", 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" => { message_to_send = MENU_TEXT.to_string(); diff --git a/resources/roms/default.ch8 b/resources/roms/default.ch8 new file mode 100644 index 0000000000000000000000000000000000000000..677f227f03beb6243aa91d9fafcf576690eb66d0 GIT binary patch literal 132 zcmZR0ut+O`Cz0cVd;#Yo%M0?0JPJT;mPO$}l4DUCm@K^@FQoCG;Xi{76av{Gt_6cV z5Ly6P{~H({0AT|Vg6SU&e;Dk5a@Gu%3_lotFf*_-@H6aZ_|5Q{;W2~rQ`Scet?Z4A M4NMK}580jr00m|(Pyhe` literal 0 HcmV?d00001