added test and added possible correction for sbc #31
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi,
This is my first time submitting a pull request, so please excuse any errors.
Firstly, thank you for making this guide. It's been an amazing learning journey and I've learnt a lot.
I had written tests for all the opcodes for chapter 3.3 and I thought it would be useful to add to the repo for future users.
While testing with your code, I noticed that tests for SBC was failing. On further inspectioin, I noticed that there MIGHT be a error with your SBC code.
In the book you had mentioned
but I'm not sure if you implemented it in your code:
fn sbc(&mut self, mode: &AddressingMode) { let addr = self.get_operand_address(&mode); let data = self.mem_read(addr); self.add_to_register_a(((data as i8).wrapping_neg().wrapping_sub(1)) as u8); }
My tests were always failing by 1. I tried 10-10. It should have been 0, but I'm getting 255 with your code. I changed the code a bit and I was getting the code to pass the tests. It's below.
fn sbc(&mut self, mode: &AddressingMode) { let addr = self.get_operand_address(mode); let data = self.mem_read(addr); self.add_to_register_a(!data + 1); }
Let me know if this is correct, else I'll have a look again and. But I think the tests will be useful otherwise as well.