diff --git a/coraxhard.ch8 b/coraxhard.ch8 new file mode 100644 index 0000000..9fc874c Binary files /dev/null and b/coraxhard.ch8 differ diff --git a/emma/src/bin/support/emmagui_support.rs b/emma/src/bin/support/emmagui_support.rs index 5d03298..fc06a18 100644 --- a/emma/src/bin/support/emmagui_support.rs +++ b/emma/src/bin/support/emmagui_support.rs @@ -53,7 +53,8 @@ impl EmmaGui { let mut buffer = Vec::new(); println!("PREPARING TO LOAD 1-chip8-logo.ch8"); - let mut input_file = File::open(Path::new("./1-chip8-logo.ch8")).expect("put 1-chip8-logo.ch8 in this directory"); + // let mut input_file = File::open(Path::new("./1-chip8-logo.ch8")).expect("put 1-chip8-logo.ch8 in this directory"); + let mut input_file = File::open(Path::new("./coraxhard.ch8")).expect("put 1-chip8-logo.ch8 in this directory"); input_file.read_to_end(&mut buffer).expect("unable to read file"); system_to_control.load_bytes_to_memory(0x200, buffer.into()); } diff --git a/emma/src/chip8/instructions.rs b/emma/src/chip8/instructions.rs index 838708a..641ada7 100644 --- a/emma/src/chip8/instructions.rs +++ b/emma/src/chip8/instructions.rs @@ -545,6 +545,13 @@ impl Chip8CpuInstructions { // // read nibble bytes from memory starting at I + let start_position = input.registers.peek_i(); + let num_bytes_to_read = *n; + for i in start_position..start_position + num_bytes_to_read { + // let current_byte = input.memory[i as usize]; + // println!("READ BYTE [{current_byte:8b}"); + } + let mut did_change: bool = false; for draw_x in 0..*n { @@ -582,7 +589,8 @@ impl Chip8CpuInstructions { // Set Vx = delay timer value. // // The value of DT is placed into Vx. - input.registers.poke(*x as u8, input.delay_timer.current() as u8); + let value_to_set = input.registers.peek(*x as u8); + input.delay_timer.set_timer(value_to_set as i32); } Chip8CpuInstructions::LdVxK(x) => { // Fx0A - LD Vx, K @@ -595,6 +603,7 @@ impl Chip8CpuInstructions { // Set delay timer = Vx. // // DT is set equal to the value of Vx. + println!("SETTING DELAY TIMER TO [{}]", *new_time); input.delay_timer.set_timer(*new_time as i32); } Chip8CpuInstructions::LdStVx(new_time) => { @@ -987,17 +996,65 @@ mod test { fn RndVxByte_test() {} fn DrawVxVyNibble_test() {} fn SkpVx_test() { + // skip if key pressed + } fn SnKpVx_test() { + // skip key not pressed } - fn LdVxDt() { + #[test] + fn LdVxDt_test() { + // delay timer reading + let mut x = Chip8Computer::new(); + // set the value we want in the timer to V0... + Chip8CpuInstructions::LdVxByte(0x0, 0x10).execute(&mut x); + // ...then tell the CPU to use that value for the timer. + Chip8CpuInstructions::LdVxDt(0x0).execute(&mut x); + x.delay_timer.tick(); + x.delay_timer.tick(); + x.delay_timer.tick(); + assert_eq!(x.delay_timer.current(), 0xd); + for i in 0..0x10 { + x.delay_timer.tick(); + } + assert_eq!(x.delay_timer.current(), 0x00); + x.delay_timer.tick(); + assert_eq!(x.delay_timer.current(), 0x00); } - fn LdVxK_test() {} - fn LdStVx_test() {} + fn LdVxK_test() { + // Wait for a key press, store the value of the key in Vx. + // All execution stops until a key is pressed, then the value of that key is stored in Vx. + + } + fn LdStVx_test() { + // sound timer setting + } fn LdIVx_test() {} fn LdVxI_test() {} -} \ No newline at end of file +/* + #[test] + fn LdDtVx_test() { + + // delay timer setting + let mut x = Chip8Computer::new(); + + // lets set our delay timer... + Chip8CpuInstructions::LdVxByte(0x0, 0x80).execute(&mut x); + Chip8CpuInstructions::LdDtVx(0x0).execute(&mut x); + + // now that we have our timer set to 0x80 we should tick it 0x10 times + // so we are then down to 0x70 + for i in 0..0x10 { + x.delay_timer.tick(); + } + // Then tell the CPU to copy that timer over into our V0 + Chip8CpuInstructions::LdVxK(0x0).execute(&mut x); + let register_value = x.registers.peek(0); + // assert_eq!(register_value, 0x70); + } + */ +}