adjustable memory size
This commit is contained in:
parent
1f98c57eb0
commit
14d04d32ee
|
@ -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 */
|
||||
|
||||
|
|
Loading…
Reference in a new issue