20-bit addressing for the 6502

For discussing the 65xx hardware itself or electronics projects.
Post Reply
User avatar
BigEd
Posts: 11463
Joined: 11 Dec 2008
Location: England
Contact:

20-bit addressing for the 6502

Post by BigEd »

Today I came across a description of the Apple III's memory system, and found that in addition to a fairly conventional banking system to expand memory beyond 64k, it also offers
- relocatable page zero and stack (both relocations are coupled)
- (zp),y accesses can fetch a third pointer byte from a specific page to offer 24-bit addressing (only 20 bits implemented)

The extra byte of pointer fetch doesn't cost an extra cycle, because the RAM is organised to fetch related pairs of bytes already, for purposes of video output.

Although the address mangling must cost some time in each access, the 1981-era system is only running at 2MHz so no extra cycles are needed.

More detail can be found at
http://apple3.org/Documents/Magazines/A ... ssing.html
and
https://archive.org/stream/apple3_Info_ ... 0/mode/2up
https://archive.org/stream/BankSwitchRa ... /mode/2up

(as seen in our mos6502 post this week archived here. And the slightly upstream article here.)

(Acorn did something similar in their in-house Turbo second processor, but took an extra cycle for the fetch of the third pointer byte:
viewtopic.php?f=4&t=1465
)

Edit: link rot!
Last edited by BigEd on Tue Sep 14, 2021 7:54 pm, edited 2 times in total.
User avatar
BigEd
Posts: 11463
Joined: 11 Dec 2008
Location: England
Contact:

Re: 20-bit addressing for the 6502

Post by BigEd »

(I wondered if I should mention Dr Jefyll's ingenious KimKlone 6502 extension, but it looks like it uses bank byte registers throughout, with no simple 3-byte pointer support. I'm ready to be corrected on that.)
User avatar
Dr Jefyll
Posts: 3525
Joined: 11 Dec 2009
Location: Ontario, Canada
Contact:

Re: 20-bit addressing for the 6502

Post by Dr Jefyll »

Thanks for the mention, Ed. :)
BigEd wrote:
no simple 3-byte pointer support
Yes and no. To use a 24-bit address you need an extra instruction to load one of the bank registers beforehand. But that's pretty easy to tolerate, given that KK can load a bank register in as little as 2 cycles -- just as fast as a load to A, X or Y. The available address modes are Immediate, Absolute, Zero-page and Zero-page,X. (see the KK Instruction list)

In the following example K2 is loaded using immediate mode. IOW the high-address byte going into the bank register is stored as part of the LDK2 instruction. This is a good choice when the subsequent instruction(s) will use Absolute mode -- where, again, the address bytes are stored as part of the instruction.

Code: Select all

;;;;;;;;;;;;;;;; we all know how to use a 16-bit address
LDA    $3456   ; (4 cycles) get what's at $3456

;;;;;;;;;;;;;;;; here's the KK equivalent for a 24-bit address
LDK2   #$12    ; (2 cycles) load K2 (one of the four bank registers)
LDA_K2 $3456   ; (4 cycles) get what's at $123456
cheers,
Jeff

[Add code example. Other edits.]
In 1988 my 65C02 got six new registers and 44 new full-speed instructions!
https://laughtonelectronics.com/Arcana/ ... mmary.html
Post Reply