test case can not pass in /code/ch3.3/cpu.rs
123zmz123 opened this issue · comments
seems like we need comment 3 line to pass the test.
pub fn reset(&mut self){
//self.register_a = 0;
//self.register_x = 0;
self.register_y = 0;
self.stack_pointer = STACK_RESET;
self.status = CpuFlags::from_bits_truncate(0b100100);
//self.memory = [0; 0xFFFF];
self.program_counter = self.mem_read_u16(0xFFFC);
}
Hey @123zmz123. Thank you for pointing this out! You might be right. Do you mind creating a PR ? I would be very grateful :)
Hey @123zmz123. Thank you for pointing this out! You might be right. Do you mind creating a PR ? I would be very grateful :)
Cool! wait for me.
ch5.1 also have this issue. Test 'test_0xaa_tax_move_a_to_x' and 'test_inx_overflow' will not pass because load_and_run() will call reset(), which reset all variables to default value.
Commit 1a4e5f5 fixed the ch3.3, but all subsequent chapters have the same problem which is still unfixed.
There were other ways this could have been fixed. Personally I would have kept using the load_and_run
helper function for tests, but instead edited it to be something like:
pub fn load_and_run(&mut self, program: Vec<u8>) {
self.load(program);
self.program_counter = self.mem_read_u16(0xFFFC);
self.run()
}
So not a full reset, but just re-read 0xFFFC after loading something.
In general there are quite a few unit tests failing, which was causing me confusing whilst following this great tutorial.
I'll happily have a go at putting together a pull request to fix all tests for all chapters, if you want to give your thoughts on my suggestion above.
In addition, I'm getting quite a few compiler warnings (E.g. Unused imports and naming conventions on enums). I can create a separate pull request for that.
Actually, just noticed pull request #12 does exactly what I was suggesting above, but we still need to do this for all the subsequent chapters.
Do you still have time to work on this project? It would be a shame for this to gradually rot, just as Rust is about to hit the big time. I've really enjoyed following it so far; I'm about 1/2 way through.