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

opcode match #41

Closed
narakai opened this issue Jun 20, 2023 · 2 comments
Closed

opcode match #41

narakai opened this issue Jun 20, 2023 · 2 comments

Comments

@narakai
Copy link

narakai commented Jun 20, 2023

Hi,

In CPUOpcodes.h, I found there are opcodes and respective hex number in enum OperationImplied, but other enums like Operation1, Operation2..., there are only opcodes defined, no hex number at all. So I am wondering why we can still use opcodes(should be a hex number) in 'Switch-Case' to match the codes in these enum?

Say enum Operation1
{
ORA, /* there's no hex like ORA = E9 defined ?*/
AND,
EOR,
ADC,
STA,
LDA,
CMP,
SBC,
};

In CPU.cc:

switch (op){
case ORA:
// do some stuff
break;
}

@amhndu
Copy link
Owner

amhndu commented Jun 21, 2023

In the opcode, operation is represented by the highest 3 bits. Thus if you mask the opcode by 11100000b (0xE0) and shift by 5, you get the operation which is a number from 0 to 7. The enum value is just this number.

See constants OperationMask and OperationShift and example decode logic.

Reference: https://llx.com/Neil/a2/opcodes.html

@narakai
Copy link
Author

narakai commented Jun 21, 2023

Thanks for the reply, it helps a lot!

@narakai narakai closed this as completed Jun 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants