So I've had to uproot and redo a lot of what I had done earlier because I didn't have a sophisticated enough FSM to do more complex addressing modes. I'm sort of at a crossroads when it comes to updating processor status registers with results.
As an example, I am implementing absolute addressing mode using the FSM I've indicated. The ADC instruction requires four cycles - on the rising edge of the fourth clock, the FSM is in the ABS_2 state and the value to put into the accumulator is ready to be registered with the transition back to the FETCH state.
I'd like to solicit some suggestions on how to get the processor status values stored properly at that time as well. My thought was to use an 8-bit mask of some sort to determine what the new value of the P register should be based upon the mask and the value to be stored in the accumulator - then combinatorially generate a new value for the P register that gets registered in at the same time as the accumulator does. To me that doesn't feel like a particularly clean way to do it though. If anyone has any suggestions, I'd appreciate hearing them.
Also, I'm aware that there are also special instructions that use and set flags differently - if anyone has advice on handling those, I'd appreciate it too. Thanks.
Updating Processor Status Flags on Emulator
- GARTHWILSON
- Forum Moderator
- Posts: 8773
- Joined: 30 Aug 2002
- Location: Southern California
- Contact:
Re: Updating Processor Status Flags on Emulator
Quote:
My thought was to use an 8-bit mask of some sort to determine what the new value of the P register should be based upon the mask and the value to be stored in the accumulator - then combinatorially generate a new value for the P register that gets registered in at the same time as the accumulator does.
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
Re: Updating Processor Status Flags on Emulator
GARTHWILSON wrote:
Quote:
My thought was to use an 8-bit mask of some sort to determine what the new value of the P register should be based upon the mask and the value to be stored in the accumulator - then combinatorially generate a new value for the P register that gets registered in at the same time as the accumulator does.
- GARTHWILSON
- Forum Moderator
- Posts: 8773
- Joined: 30 Aug 2002
- Location: Southern California
- Contact:
Re: Updating Processor Status Flags on Emulator
The branch, jump, no-op, store, push, and RTS instructions won't affect the status. Something like INX or PLX will make the status apply to the new X register value, while INY or PLY will make the status apply to the new Y register value. Something like INC <absolute> will make it reflect the new value of the memory location you operated on, even though you didn't affect A, X, or Y. Math operations will affect the V flag, but logical operations will not.
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
Re: Updating Processor Status Flags on Emulator
GARTHWILSON wrote:
The branch, jump, no-op, store, push, and RTS instructions won't affect the status. Something like INX or PLX will make the status apply to the new X register value, while INY or PLY will make the status apply to the new Y register value. Something like INC <absolute> will make it reflect the new value of the memory location you operated on, even though you didn't affect A, X, or Y. Math operations will affect the V flag, but logical operations will not.
Re: Updating Processor Status Flags on Emulator
Basically every operand going through the ALU must generate flags, every address must not.
In the 6502 the load instructions and move register instructions (- TXS) are routed through the ALU although they don't calculate anything other than the flags. Address indexing and branch offset calculation also use the ALU but do not update the processor status.
In the 6502 the load instructions and move register instructions (- TXS) are routed through the ALU although they don't calculate anything other than the flags. Address indexing and branch offset calculation also use the ALU but do not update the processor status.
6502 sources on GitHub: https://github.com/Klaus2m5
Re: Updating Processor Status Flags on Emulator
Klaus2m5 wrote:
Basically every operand going through the ALU must generate flags, every address must not.
- GARTHWILSON
- Forum Moderator
- Posts: 8773
- Joined: 30 Aug 2002
- Location: Southern California
- Contact:
Re: Updating Processor Status Flags on Emulator
Any '02 data sheet will have that info. For the NMOS 6502, see for example:
6500 Microprocessors (Preliminary) (May 1976) http://6502.org/documents/datasheets/mo ... y_1976.pdf
or for 65c02 (which I highly encourage you make your simulator for, because it is far superior to the NMOS 6502):
W65C02S Microprocessor (May 17, 2013) http://6502.org/documents/datasheets/wd ... 7_2013.pdf which has the flag-effect info starting on page 28.
6500 Microprocessors (Preliminary) (May 1976) http://6502.org/documents/datasheets/mo ... y_1976.pdf
or for 65c02 (which I highly encourage you make your simulator for, because it is far superior to the NMOS 6502):
W65C02S Microprocessor (May 17, 2013) http://6502.org/documents/datasheets/wd ... 7_2013.pdf which has the flag-effect info starting on page 28.
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
Re: Updating Processor Status Flags on Emulator
GARTHWILSON wrote:
Any '02 data sheet will have that info. For the NMOS 6502, see for example:
6500 Microprocessors (Preliminary) (May 1976) http://6502.org/documents/datasheets/mo ... y_1976.pdf
or for 65c02 (which I highly encourage you make your simulator for, because it is far superior to the NMOS 6502):
W65C02S Microprocessor (May 17, 2013) http://6502.org/documents/datasheets/wd ... 7_2013.pdf which has the flag-effect info starting on page 28.
6500 Microprocessors (Preliminary) (May 1976) http://6502.org/documents/datasheets/mo ... y_1976.pdf
or for 65c02 (which I highly encourage you make your simulator for, because it is far superior to the NMOS 6502):
W65C02S Microprocessor (May 17, 2013) http://6502.org/documents/datasheets/wd ... 7_2013.pdf which has the flag-effect info starting on page 28.
Re: Updating Processor Status Flags on Emulator
I didn't say that opcodes go into the ALU. I said operands go into the ALU.
See the block diagram at http://www.pagetable.com/?p=39 for reference.
The ALU is also used to generate the memory address (indexing, relative addressing). In this case the processor status must not be altered.
I should have looked at the block diagram earlier. It shows that N and Z flag update is independant of the ALU and comes directly from the data bus (DB7, DBZ). So a load instruction does not need to go through the ALU to set those flags. Only C and V are gated from the ALU (ACR, AVR) in case of a shift or a add/subtract operand.
See the block diagram at http://www.pagetable.com/?p=39 for reference.
The ALU is also used to generate the memory address (indexing, relative addressing). In this case the processor status must not be altered.
I should have looked at the block diagram earlier. It shows that N and Z flag update is independant of the ALU and comes directly from the data bus (DB7, DBZ). So a load instruction does not need to go through the ALU to set those flags. Only C and V are gated from the ALU (ACR, AVR) in case of a shift or a add/subtract operand.
6502 sources on GitHub: https://github.com/Klaus2m5