alphashock wrote: ↑
Wed Mar 25, 2020 7:44 am
According to "Synertek Hardware Manual" branch operations cycle breakdown look something like this
Code: Select all
Address Bus Data Bus
T0 PC OPCODE
T1 PC + 1 OFFSET
T2* PC + 2 + OFFSET OPCODE
T3** PC + 2 + OFFSET + C OPCODE
* skip if branch not taken
** skip if branch not taken; skip if branch operation doesn't cross page boundary
That description is incorrect - state T2 fetches from PC + 2, and state T3 fetches from PC + 2 + OFFSET; it's not until T0 of the next
instruction that you'd fetch from PC + 2 + OFFSET + C.
Of course, technically all
of those cycles are fetching from PC, since PC gets updated in real time as they proceed:
* T0 fetches the byte at PC (opcode) and post-increments PC
* T1 fetches the byte at PC (operand) and post-increments PC
* If the branch was taken, T2 fetches the byte at PC (what would've been the next opcode) and then adds the previous operand to PCL. If not, it runs T0 for the next instruction.
* If T2 resulted in a carry, T3 fetches the byte at PC (what would've been the next opcode, but in the wrong page) and then fixes PCH. If not, it runs T0 for the next instruction.
For reference, I got the above information from "64doc":
Code: Select all
Relative addressing (BCC, BCS, BNE, BEQ, BPL, BMI, BVC, BVS)
# address R/W description
--- --------- --- ---------------------------------------------
1 PC R fetch opcode, increment PC
2 PC R fetch operand, increment PC
3 PC R Fetch opcode of next instruction,
If branch is taken, add operand to PCL.
Otherwise increment PC.
4+ PC* R Fetch opcode of next instruction.
Fix PCH. If it did not change, increment PC.
5! PC R Fetch opcode of next instruction,
Notes: The opcode fetch of the next instruction is included to
this diagram for illustration purposes. When determining
real execution times, remember to subtract the last
* The high byte of Program Counter (PCH) may be invalid
at this time, i.e. it may be smaller or bigger by $100.
+ If branch is taken, this cycle will be executed.
! If branch occurs to different page, this cycle will be