adjustable memory size

This commit is contained in:
Lea 2023-01-25 19:33:56 +01:00
parent 1f98c57eb0
commit 14d04d32ee
Signed by: Lea
GPG key ID: 1BAFFE8347019C42

View file

@ -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) {