32 Bit address support #1
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
By changing the addressing modes, it is possible to convert the 6502 from using 16 bit addresses to 32 bit addresses. Any instruction which deals with 2-byte addresses is modified to work with 4-byte addresses instead.
The 6502 has 15 addressing modes. Here is how each of them will change:
Overall, there are not too many different changes.
The registers all remain 8 bits, except for the program counter which obviously must be 32 bits.
The vector addresses also change since they are 32 bit now instead of 16 bit.
Backwards compatibility is NOT a requirement. There is NO need to have a 16 bit mode, or be able to run existing 6502 code in any way.
Starting from the top, the first thing that needs to change is state
IND0All
IND0does is go toINDX1, bypassing theINDX0state where the zp address is added with the X register. This state therefore requires no modifications since it will be handled by theINDXnstates.We will revisit this one when we handle the other zero page indirect modes.
second state that needs changed is
ABSncurrently there are 2 states, for loading 2 bytes
ABS0 increments the program counter
The ALU is set to add by default, AI is set to 0 by default, BI is set to DIMUX by default.
ABS1 sets the next address to the combination of DIMUX and the ALU output
So, in order to support 32 bit addresses we need to have 16 more bits of temporary storage. Right now it uses the ALU output register, as well as the input register. We can have an ALU shift register which simple stores the last 2 results of the ALU. In the final state when we jump to the new address, it will do
AB = {DIMUX, ALU_SR[1] ALU_SR[0], ADD}This will be the result of ABS3. ABS0,1,2 will all be the same, just incrementing PC
Actually before we do that, we need to do the vectors so that we can even reset the chip.
We start in state BRK0
This sets the address to the current stack pointer, which will still only be 16 bits. We can hardcode the upper 16 bits to 0.
In BRK0 and BRK1, as well as JSR0 and JSR1, we push the current PC to the stack. We need to add 2 more states so that we can write all 32 bits, instead of just 16
In BRK2 we write the processor status register, so we can just move that back a few cycles
BRK1 and BRK2 increment the address, our stats will do the same
Here is where the vectors are harcoded. We will change these vectors to be at 0xFFFFFFF4, 0xFFFFFFF8, and 0xFFFFFFFC.
The BRK changes are added in
9476c6a0ddNow that we have those, we need to update the JMP state, since it is only waiting 1 cycle for an address
JMP does not really do anything. If we add 2 more JMP0 like states as well as the ALU shift register, this should be trivial.
JMP changes are added in
019b84f41dThis is the Absolute jump
Lets tackle absolute for normal instructions next.
747438a9b6This was pretty simple, we just copy the ABS0 state two more times.
abs,x next.
Looks like we can just copy this state
2 more times
Added abs,x here
cb6cac1245abs,y should also be handled by abs,x add those to the test also
Lets tackle absolute,x indirect.
This is states JMPIXn
Like absx, We can probably just copy this state twice
Ok that is one in
dc339cb725Now for regular indirect. We can just copy JMPI0 twice.
Added in
b31d7490b2Lets do Indirect Indexed, since it is apparently the most common indirection mode.
according to the state listing, here are the steps that we do
How should we make this work with 32 bit addresses?
The first step loads the LSB and sends the ZP index to ALU
the second step reads the MSB and sends the LSB to ALU to add Y
the third step reads
So we need to do a combination of steps 2 and 3. Instead of loading data from the calculated address, we need to read the 3rd and 4th bytes from zero page and add the carry. Only then can we read from the computed address.
Hmm that plan would not work because we need the ALU to be adding the offset, whereas this instruction also uses the ALU to generate the address.