funkheld Wrote:---------------------------------
The only slot that can be switched is slot 3 which starts at $c000 and ends at $ffff.
----------------------------------
I don't understand this sentence.
Zilog 80 has 16 bit address bus, hence it can work with 2^16 addresses (that is 64K of addressable memory). The processor doesn't make any difference between rom and ram memory, for each memory address there are three possibilities actually - 1. rom, 2. ram, 3. nothing at all. But all the processor does is:
1. read a byte from a memory address (that is from one of 2^16 possible addresses, the processor does not know it it is mapped to rom, ram or nothing at all, it will take whatever is on databus).
2. write a byte to a memory address ( --||-- ).
On different Spectrum models, the memory is mapped differently. Let's see the difference:
First,
let's take a look how it is on the early Spectrum 16K model - the first 16K (addresses $0000-$3FFF) is mapped to rom memory, then we have 16K of ram memory (addresses $4000-7FFF), and on the remaining 32K ($8000-$FFFF) there isn't anything physically mounted.
When reading from rom address and from ram address, the processor gets the byte located in that memory location. When reading from an upper address which is not mapped to anything, the processor always gets $FF. The processor does not know the origin of the byte it gets, it just reads the byte and processes it.
When writing, the processor puts the byte it wants to write on databus, puts the two-byte address on address bus and processes the writting normally, but then:
- if the address belongs to ram, the byte is actually written to the memory location at this address.
- if the address belongs to rom or to "nothing", the byte gets lost.
The processor does not know it, it did what it was told to do - write this byte to this address, it does not check whether the byte is actually written anywhere.
On 48K model, we have 16K rom (same as on 16K model), but then whole remaining 48K address space is mapped to the ram memory. So every read actually reads something from physical memory (be it rom or ram). Writing to rom (lowest 16K of address space) is lost, and everything above 16K is actually written to ram memory.
So far so good... But it gets complicated
on 128K model - there we have 128K of ram memory, and the same Z80 processor.
As we know this processor can only see the address space of 64K in total. The first 16K belong to rom, leaving only 48K of addressable memory to ram. So, how can we make it use 128K ram?
The answer is - by something called "memory paging". Let's look at the 128K of ram memory as eight memory banks (also called pages), 16K each. We will call them "page 0", "page 1", ... "page 7".
The first 16K belongs to rom (the rom slot - $0000-$7FFF). The following 16K ($4000-7FFF, let's call it
the first ram slot) always belongs to ram page 5, the next 16K ($8000-$BFFF - the second ram slot) belongs to page 2.
Then the remaining 16K of addressable memory ($C000-$FFFF - the third ram slot) can be mapped to any ram page! When the Spectrum is turned on, the page 0 is mapped there. However, when the processor executes an "out" instruction to address $7ffd, the page mapped to this "slot" gets changed (the lowest three bits in byte written to this port determine which ram page is going to be switched in - 0 to 7). That is how each byte in the 128K of ram can be accessed.
So I hope you now understand what Duefecty means by:
Duefectu Wrote:The only slot that can be switched is slot 3 which starts at $c000 and ends at $ffff.
Executing an out instruction to address $7ffd does more than switching the ram page on the third slot. So read carefully
here and
here.
I'd also say that, if you want to use ram pages switching technique, it is usually (depending on your use case it might not be so) good practice to avoid
contendend ram pages (on 128K/+2 odd pages are contended, and even pages not, you can find more details about it in the first link I gave above).
I didn't cover +3/+2A models. Although there is also 128K of ram, the ram switching system is somewhat different there, more complicated but more powerful; you can find more in the links given above.