Run an opcode returning an expression - #2
Open
jkoudys wants to merge 13 commits into
Open
Conversation
This is shorter, but it also removes any magic-numbering that relies on 0xFF being the 'empty'
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Here's a neat way to keep it clean. Deeply nested control flow (eg returns that are 2-match-levels deep) are hard to follow and create fast-outs that can be tricky to handle. We can use a
Resultso that opcodes that don't match can always be returned. This separates the formatting and branching of an error into something you can format and handle as you see fit.Since we're already making a
Result, rather than aResult<(), Error>(or possibly anOption<()>that maps an error if no op was found), we might as well return something on that expression. PC updates seem to be the big thing chip8's figuring out in these calls, so we can make that an expression and lighten the number of mutations we need to figure out. Using anOption<()>in there might save us from the defaultpc + 2being written a bunch, but in the grand scheme it's not a huge deal.I noticed you were inconsistent with some
0x00hex noting, with au16as0x00instead of0x0000. It's a common style preference for writing emulators, but if not consistent, just make them 0.Threw in some named params on the debug formatter. which keeps the output string readable on its own, separate from the input data. Also saves a dozen
?s.