6502 datapath

This page discusses the 6502 datapath, using the terminology from Hanson's Block Diagram and is probably best understood by reference to it

We're interested in which datapath control signals are active in each of the two phases.

A full cycle consists of phi1 and phi2. When we say a signal is "effective", we mean it actually does something.

All datapath control signals are latched during phi2; they are set mostly from opcode and timing data, but also some internal state. We work broadly from left to right. (Which is right to left on Balazs' schematic)

External busses and signals

DOR is latched from DB during phi1, and driven onto the data pins in phi2, if a write is done (and, on the 6501, only if the asynchronous DBE signal is on).

DL is latched during phi2, and then put on ADL, ADH, or DB on the next phi1; during phi2, the old value in DL is put on that bus.

ABL and ABH can be loaded from ADL and ADH respectively during phi1; they are put on the address pins in that same phi1, and stay there until changed again.

R/#W is latched during phi2, and then delayed until phi1, where it is output.

Address values

ADL/ABL, ADH/ABH:
We already saw these. Effective on the next phi1.
0/ADL0, 0/ADL1, 0/ADL2, 0/ADH0, 0/ADH(1-7)
These set the interrupt vector fetch address, and the zero page and stack high address. Effective on phi2 and the next phi1.

The register file

Y/SB, X/SB, SB/Y, SB/X
Move the X and Y registers from/to the SB. Latched on phi2, just like everything else; effective on the next phi1.
SB/S, S/S, effective on the next phi1.
S/SB, S/ADL, effective on phi2 and the next phi1.
The S register is actually two latches in series. This makes it possible to read a value from SB and write a value to ADL at the same time. On phi2, the value from the "in" latch is forwarded to the "out" latch (and onto the driven bus, if any).

(Note the two "tuning fork" structures, which have contacts either on the top or bottom, which select whether X, Y, A write SB and DB only during phi1, or slightly longer, during "not phi2". We think this might be a timing fix, or an option left open until after silicon showed which choice worked best)

ALU inputs

SB/ADD, 0/ADD, nDB/ADD, DB/ADD, ADL/ADD
Two options for one side, three for the other. Effective on the next phi1.

ALU operation selection

ANDS, EORS, ORS, 1/ADDC, SRS, SUMS, DAA, DSA
Select the ALU operation. Effective on the next phi1 and phi2.

(The overflow and carry out signals AVR and ACR are output from the ALU back to the control logic, latched during phi2, used in phi1. The decimal carries are picked up at phi2 as well).

ALU output register

The ALU output register (ADD) is written during phi2. The value can be used the next cycle:

ADD/SB7, ADD/SB(0-6), ADD/ADL, effective on phi2 and the next phi1.
The ADL output is for address calculations. For output to SB, the top bit is handled separately for rotate right instructions: the ALU always computes a zero there; by not driving it to the bus a one will be read.
SB/AC, effective on the next phi1.
Lines 1-3,5-7 are fed through the decimal adjust first, to finish the proper BCD add/subtract result if necessary, before writing it to the accumulator.
AC/SB, AC/DB, effective on the next phi1.
Write the A reg back to one of the busses.

The Program Counter

ADH/PCH, PCH/PCH, PCL/PCL, ADL/PCL
select whether to use the current PC, or take a new value from the internal address busses. Effective on the next phi1.
PCH/DB, PCL/DB, PCH/ADH, PCL/ADL
write the PC to one of the busses. Effective on phi2 and the next phi1.
I/PC, effective during the next phi1 and phi2.
Increment the PC, or not. When incrementing, the new value is put on ADL,ADH because there are no internal latches in the PC incrementer. For every instruction, the first two bytes are fetched (during execution of the previous instruction); I/PC peeks ahead (or back, if you want to look at it that way) to the next instruction that is predecoded, so it can skip incrementing PC if that is a one-byte instruction.
P/DB
Write the flag values to the DB; effective on phi2 and the next phi1. The DB can be read to set the flag values as well; it is read during phi2, and then latched in the flag register on the next phi1.
SB/DB, SB/ADH
Connect two busses together. Effective on phi2 and the next phi1.

Precharge

All internal busses (SB, DB, ADL, ADH) are driven high during phi2, as a sort of precharge. In fact commonly they are also driven by data signals during phi2, causing an intermediate voltage to appear on the bus.

A note on signal naming

In our Javascript simulation the datapath control signals are tabulated according to Hanson's names, but in the layout they are named with a prefix according to their position across the chip. So

will be found as

in the source. See also the table below.

As Balazs used another naming scheme in his very useful but incomplete schematic, we should also cross-reference his names:

Balazs || Hanson || JSSim || note
R1x7Y/SBdpc0_YSBdrive sb from y
R1x6SB/Ydpc1_SBYload y from sb
R1x5X/SBdpc2_XSBdrive sb from x
R1x4SB/Xdpc3_SBXload x from sb
R1x2S/SBdpc4_SSBdrive sb from stack pointer
R1x1S/ADLdpc5_SADLdrive adl from stack pointer
R1x3SB/Sdpc6_SBSload stack pointer from sb
?S/Sdpc7_SSrecirculate stack pointer
R2x1notDB/ADDdpc8_nDBADDalu b side: select not-idb input
R2x2DB/ADDdpc9_DBADDalu b side: select idb input
R2x3ADL/ADDdpc10_ADLADDalu b side: select adl input
R2x4 (??)SB/ADDdpc11_SBADDalu a side: select sb
R2x50/ADDdpc12_0ADDalu a side: select zero
R2x6ORSdpc13_ORSalu op: a or b
R2x7SRSdpc14_SRSalu op: logical right shift
R2x8ANDSdpc15_ANDSalu op: a and b
R2x9EORSdpc16_EORSalu op: a xor b (?)
R2x12SUMSdpc17_SUMSalu op: a plus b (?)
?DAAdpc18_#DAAdecimal related (inverted)
R2x14,7ADD/SB(7)dpc19_ADDSB7alu to sb bit 7 only
R2x14ADD/SB(0-6)dpc20_ADDSB06alu to sb bits 6-0 only
R2x15ADD/ADLdpc21_ADDADLalu to adl
R2x20,6DSAdpc22_#DSAdecimal related/SBC only (inverted)
R3x4SB/ACdpc23_SBAC(optionally decimal-adjusted) sb to acc
R3x1AC/SBdpc24_ACSBacc to sb
R3x3SB/DBdpc25_SBDBsb pass-connects to idb (bi-directionally)
R3x2AC/DBdpc26_ACDBacc to idb
R3x0SB/ADHdpc27_SBADHsb pass-connects to adh (bi-directionally)
R3x5,00/ADH0dpc28_0ADH0zero to adh0 bit0 only
R3x50/ADH(1-7)dpc29_0ADH17zero to adh bits 7-1 only
R4x2ADH/PCHdpc30_ADHPCHload pch from adh
R4x3PCH/PCHdpc31_PCHPCHload pch from pch incremented
R4x4PCH/ADHdpc32_PCHADHdrive adh from pch incremented
R4x1PCH/DBdpc33_PCHDBdrive idb from pch incremented
!!PCLCdpc34_PCLCpch carry in and pcl FF detect?
CarryPCHCdpc35_PCHCpcl 0x?F detect - half-carry
notCarryI/PCdpc36_#IPCpcl carry in (inverted)
R5x1PCL/DBdpc37_PCLDBdrive idb from pcl incremented
R5x4PCL/ADLdpc38_PCLADLdrive adl from pcl incremented
R5x3PCL/PCLdpc39_PCLPCLload pcl from pcl incremented
R5x2ADL/PCLdpc40_ADLPCLload pcl from adl
Dkx2DL/ADLdpc41_DL/ADLpass-connect adl to mux node driven by idl
Dkx3DL/ADHdpc42_DL/ADHpass-connect adh to mux node driven by idl
Dkx1DL/DBdpc43_DL/DBpass-connect idb to mux node driven by idl