Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a way to get an opcode or InstructionType from a partial decode #18

Closed
rzumer opened this issue Jan 27, 2024 · 1 comment
Closed
Labels
enhancement New feature or request

Comments

@rzumer
Copy link
Owner

rzumer commented Jan 27, 2024

It can be a pain to identify where we are in the decoding process when implementing an emulator, and this would avoid having to store fetched bytes elsewhere temporarily. For example DJNZ has an extended M1 cycle followed by an operand read, so at the stage where the extension has to be inserted, the decoder result is still an error, and we can't blindly fetch the operand; cycle timing is critical, because some input lines are sampled regularly at a certain clock (edge) of every machine cycle.

When fetching the opcode byte, it's not possible to identify DJNZ definitely unless we know both the opcode and the decoder state from a try_decode() call either before or after it. It can be too restrictive depending on how low-level the emulator gets.

Another example is LD (IX/IY+d), n. This is the only indexed instruction that is not in the bitwise instruction table and does not end with the displacement fetch. When this occurs, the displacement computation overlaps with the final fetch cycle. But since the decoder state (when invoking try_decode() with each pushed byte) goes RootOpcode, IndexedOpcode, IndexedOperand, IndexedOperand, we can't distinguish between other indexed 4-byte instructions unless we know the full context of the decoding process. So we either need to save some more intermediary information or add IndexedDisplacement to replace IndexedOperand when the next value that the decoder needs is the displacement.

@rzumer rzumer added the enhancement New feature or request label Jan 27, 2024
@rzumer rzumer changed the title Store last InstructionDecoder result Provide a way to get an opcode or InstructionType from a partial decode Feb 2, 2024
@rzumer rzumer mentioned this issue Feb 7, 2024
Merged
@rzumer
Copy link
Owner Author

rzumer commented Feb 7, 2024

Displacement DecoderState variants added in #21.

For DJNZ it's a little more complicated, so I don't know if I'll implement some other way to identify it more easily. There are multiple relative jump root instructions, so it's not possible to rely solely on the RootDisplacement state, but matching the opcode byte or the decoded instruction type after obtaining that state variant and pushing the operand byte is doable even if it's not the most elegant solution. I'm not keen on decomposing incomplete decodes further into partial instructions because of the performance implications.

@rzumer rzumer closed this as completed Feb 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant