From 14d04d32eecba751ec0c11b1669c7883f4238e83 Mon Sep 17 00:00:00 2001 From: Lea Date: Wed, 25 Jan 2023 19:33:56 +0100 Subject: [PATCH] adjustable memory size --- src/emulator/main.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/emulator/main.rs b/src/emulator/main.rs index e721ae0..52a635b 100644 --- a/src/emulator/main.rs +++ b/src/emulator/main.rs @@ -3,6 +3,8 @@ use instructions::arithmetic; mod instructions; +const MEMORY_SIZE: usize = 8192; + pub struct EmulatorState { a: u8, b: u8, @@ -21,7 +23,7 @@ pub struct EmulatorState { /// Enable interrupts ei: bool, /// Memory map - memory: [u8; 8000], + memory: [u8; MEMORY_SIZE], } pub struct ConditionCodes { @@ -117,7 +119,7 @@ fn main() { cc: ConditionCodes { z: true, s: true, p: true, c: true }, pc: 0, ei: true, - memory: [0; 8000], + memory: [0; MEMORY_SIZE], }; // Load the ROM into memory @@ -127,13 +129,16 @@ fn main() { .expect("Provide a path to a ROM file to emulate as an argument"); let file = fs::read(filename).expect("where file"); - for i in 0..8000 { + for i in 0..8192 { state.memory[i] = file[i]; } - while state.pc < 8000 { + while state.pc < 8192 { tick(&mut state); } + + println!("Program counter reached end of memory; exiting"); + print_state(&state); } fn tick(state: &mut EmulatorState) { @@ -145,7 +150,7 @@ fn tick(state: &mut EmulatorState) { }; match instruction { - 0x00 => {} // NOP + 0x00 => {} // NOP /* ADD */