Redundant reset methods? #28
Comments
I guess you could also be cheeky and have a pub fn reset(&mut self) {
*self = Cpu::new();
} Then you still get the same semantics with that fn, and the niceties you get with initializing everything properly in the ctor :) |
Something "feels" a bit wrong with doing away with the function entirely; perhaps I'm thinking I really want a |
Yeah it's a matter of "style" really, I can see wanting a reset method to stay closer to the actual chip or something. On the PlayStation I know that the RAM, VRAM and some registers are not reset when you press the "reset" button but I don't actually bother keeping track of that when a reset is requested by the user. I just put random "garbage" data in them by default. My main concern with a "partial reset" would be to end up with a strange bug that would only happen in certain situations after a partial reset and would be a pain to reproduce and track down. If you always reset to the the same "clean" state you run should be more deterministic, hopefully... |
Considering Obviously doing so would require you to add a |
@iherbig: For |
I'll go ahead and fix this on one of the next streams probably. I'd like to request nobody does a PR for it, because I want to talk about why we want to do this on stream :) |
I definitely think a separate Look forward to your next stream, Jake. |
This is not a big deal I've noticed that your
Cpu
has a reset method. I did something similar when I implemented a GameBoy emulator but I got rid of it after a while. The main problem is that I was worried about adding a new state variable to the struct and forget to reset it properly in the method. Moreover you end up having a lot of redundant code between your constructor and reset function.For this reason I prefer to have a constructor that builds an instance of the module "at reset". When I need to reset something I simply build a new instance and replace the old. Since Rust will raise an error if you don't initialize something in your constructor you're sure you won't forget to set the reset value correctly.
Good luck with your project!
The text was updated successfully, but these errors were encountered: