Difference between revisions of "Memory map"
(→= Interactions between paging methods) |
(→128-style memory management) |
||
Line 79: | Line 79: | ||
=== 128-style memory management === | === 128-style memory management === | ||
− | 128-style memory management can only alter the bank addressed at $c000 (slot 4 | + | 128-style memory management can only alter the bank addressed at $c000 (16k-slot 4, or 8k-slot 7-8). The active 16k-bank at $c000 is selected by writing the 3 LSBs of the 16k-bank number to the bottom 3 bits of {{PortNo|$7FFD}}, and the 3 MSBs to the bottom 3 bits of {{PortNo|$DFFD}}. (The reason for the division is that the original Spectrum 128, having only 128k of memory, only needed 3 bits.) |
On an unexpanded Next, this allows any 16k-bank to be paged in at $c000. On an expanded next, there are not enough bits available to access the banks at the bottom of the expanded memory, so Next memory management must be used to access these. | On an unexpanded Next, this allows any 16k-bank to be paged in at $c000. On an expanded next, there are not enough bits available to access the banks at the bottom of the expanded memory, so Next memory management must be used to access these. | ||
If you are using the standard interrupt handler or OS routines, then any time you write to {{PortNo|$7FFD}} you should also store the value at $5B5C. Any time you write to {{PortNo|$1FFD}} you should also store the value at $5B67. There is no corresponding system variable for the Next-only {{PortNo|$DFFD}} and standard OS routines may not support the extended banks properly. | If you are using the standard interrupt handler or OS routines, then any time you write to {{PortNo|$7FFD}} you should also store the value at $5B5C. Any time you write to {{PortNo|$1FFD}} you should also store the value at $5B67. There is no corresponding system variable for the Next-only {{PortNo|$DFFD}} and standard OS routines may not support the extended banks properly. | ||
− | + | ||
== 128 Special Paging Mode == | == 128 Special Paging Mode == | ||
"Special paging mode" (also called "AllRam mode" or "CP/M mode") is enabled by writing a value with the LSB set to {{PortNo|$1FFD}}. Depending on the 3 low bits of this value a memory configuration is selected as follows: | "Special paging mode" (also called "AllRam mode" or "CP/M mode") is enabled by writing a value with the LSB set to {{PortNo|$1FFD}}. Depending on the 3 low bits of this value a memory configuration is selected as follows: |
Revision as of 19:10, 24 September 2017
The Next supports two memory management models which operate in tandem. One is a unique memory management system for the Next. The other is an expanded version of the memory manager from the original Spectrum 128 and +2/+3 series.
Contents
Global Memory Map
The total available RAM space of the Next is 512k on an unexpanded Next, or 1536k - 1.5mb - on a Next expanded to 2Mb. (The base Next has 1mb of memory but 512k of it is reserved for the ROMs and firmware.)
The Z80 processor in the next can access only 16k of memory at a time, and so the memory is divided into banks which are used in determining which memory it sees. Spectrum 128k memory management uses 16k banks. Next memory management uses 8k banks.
16k-bank | 8k-bank | True Address | Description |
---|---|---|---|
- | - | $000000-$00ffff | ZX Spectrum ROM |
- | - | $010000-$013fff | EsxDOS ROM |
- | - | $014000-$017fff | Multiface ROM |
- | - | $018000-$01bfff | Multiface Extra ROM |
- | - | $01c000-$01ffff | Multiface RAM |
- | - | $020000-$05ffff | DivMMC RAM |
0 | 0-1 | $060000-$063fff | Standard RAM, may be used by EsxDOS |
1 | 2-3 | $064000-$067fff | Standard RAM, contended on 128, may be used by EsxDOS |
2 | 4-5 | $068000-$06afff | Standard RAM |
3 | 6-7 | $06b000-$06ffff | Standard RAM, contended on 128, may be used by EsxDOS |
4 | 8-9 | $070000-$073fff | Standard RAM, contended on +2/+3 |
5 | 10-11 | $074000-$077fff | ULA Screen, contended except on Pentagon |
6 | 12-13 | $078000-$07afff | Standard RAM, contended on +2/+3 |
7 | 14-15 | $07b000-$07ffff | ULA Shadow Screen, contended except on Pentagon |
8 | 16-17 | $080000-$083fff | Next RAM, Default Layer 2 |
9-10 | 18-21 | $084000-$08afff | Next RAM |
11 | 22-23 | $08b000-$08ffff | Next RAM, Default Layer 2 Shadow Screen |
12-39 | 24-79 | $090000-$0fffff | Next RAM |
40-63 | 80-127 | $100000-$15ffff | 2Mb Expanded Next RAM (accessible via 128 memory management) |
-- | 128-207 | $160000-$1ffffff | 2Mb Expanded Next RAM (accessible via Next management only) |
Z80 Visible Memory map
At start up, the 16-bit address space of the Z80 is mapped to memory as follows:
Area | 16k-slot | 8k-slot | Default 16k-bank | Default 8k-bank | Description |
---|---|---|---|---|---|
$0000-$1fff | 1 | 1 | ROM | ROM (255) | Normally ROM. Writes mappable by layer 2. IRQ and NMI routines here. |
$2000-$3fff | 2 | ROM (255) | Normally ROM. Writes mapped by Layer 2. | ||
$4000-$5fff | 2 | 3 | 5 | 10 | Normally used for normal/shadow ULA screen. |
$6000-$7fff | 4 | 11 | Normally used for normal/shadow ULA screen. | ||
$8000-$9fff | 3 | 5 | 2 | 4 | Free RAM. |
$a000-$bfff | 6 | 5 | Free RAM. | ||
$c000-$dfff | 4 | 7 | 0 | 0 | Free RAM. Only this area is remappable by 128 memory management. |
$e000-$ffff | 8 | 1 | Free RAM. Only this area is remappable by 128 memory management. |
Paging techniques
128-style memory management
128-style memory management can only alter the bank addressed at $c000 (16k-slot 4, or 8k-slot 7-8). The active 16k-bank at $c000 is selected by writing the 3 LSBs of the 16k-bank number to the bottom 3 bits of Memory Paging Control ($7FFD / 32765), and the 3 MSBs to the bottom 3 bits of Next Memory Bank Select ($DFFD / 57341). (The reason for the division is that the original Spectrum 128, having only 128k of memory, only needed 3 bits.)
On an unexpanded Next, this allows any 16k-bank to be paged in at $c000. On an expanded next, there are not enough bits available to access the banks at the bottom of the expanded memory, so Next memory management must be used to access these.
If you are using the standard interrupt handler or OS routines, then any time you write to Memory Paging Control ($7FFD / 32765) you should also store the value at $5B5C. Any time you write to Plus 3 Memory Paging Control ($1FFD / 8189) you should also store the value at $5B67. There is no corresponding system variable for the Next-only Next Memory Bank Select ($DFFD / 57341) and standard OS routines may not support the extended banks properly.
128 Special Paging Mode
"Special paging mode" (also called "AllRam mode" or "CP/M mode") is enabled by writing a value with the LSB set to Plus 3 Memory Paging Control ($1FFD / 8189). Depending on the 3 low bits of this value a memory configuration is selected as follows:
Bits | Slot 1 | Slot 2 | Slot 3 | Slot 4 |
---|---|---|---|---|
%001 | 0 | 1 | 2 | 3 |
%011 | 4 | 5 | 6 | 7 |
%101 | 4 | 5 | 6 | 3 |
%111 | 4 | 7 | 6 | 3 |
Layer 2 Switching
Layer 2 switching can allow any 16k-bank to be written to (but not read) in Slot 1, by writing the 16k-bank number to Layer 2 RAM Page Register ($12) and then enabling Layer 2 paging by writing a value with the LSB set to Layer 2 Access Port ($123B / 4667).
Writing to this area will then write the appropriate area of memory, whereas reading from it will give the area mapped by other memory management.
Next Memory Management
The 8k-bank accessed in a slot is selected by writing the 8k-bank number to the bottom 7 bits of the 8 Next registers from Memory management slot 0 bank ($50) upwards. $50 addresses 8k-slot 0, $51 addresses 8k-slot 1, and so on.
In addition, in Slots 1 and 2 only, the ROM can be paged in by writing $FF to the page.
Interactions between paging methods
Changes made in 128 style and Next style memory management are synchronized. The most recent change always has priority. This means that
- using 128-style memory management to select a new 16k-bank in 16k-slot 4 will update the MMU registers for the two 8k-slots with the corresponding 8k-bank numbers.
- enabling AllRam mode will update all of the 8k-bank values with the appropriate 8k-slot numbers. These may then be overwritten using Next memory management without needing to alter the value at port $1FFD.
Since the 128-style memory management ports are not readable, there is no synchronization applicable in the other direction.
ROM paging and selection
$0000-$3fff is usually mapped to ROM. This area can only be fully remapped using Next memory management. ROM is not considered one of the numbered banks; it is mapped to the two 8k-banks by default, or by setting their 8k-bank numbers to 255.
The 128k Spectrum has 2 ROM pages. Which of these is mapped is selected by altering Bit 4 of Memory Paging Control ($7FFD / 32765). The +2a/+3 has 4 ROM pages; the extra bit needed to select between these is bit 2 of Plus 3 Memory Paging Control ($1FFD / 8189). This maintains compatibility with the original machines' ROM paging as long as the ROM is not paged out.
Paging out ROM
ROM can be paged out by enabling AllRam mode, or by using Next memory management. Beware that some programs may assume that they can find ROM service routines at fixed addresses between $0000-$3fff. More importantly, if the default interrupt mode (IM 1) is set, the Z80 will jump the program counter to $0038 every frame expecting to find an interrupt handler there. If it does not, pain and suffering will likely result. DI is your friend. On the plus side, this does allow you to write your own interrupt handler without the nuisance of using IM 2.
Activating Layer 2's paging will not affect ROM operation, because it only remaps writes, not reads.
Screen
16k-Bank 5 is the bank read by the ULA to determine what to show on screen. The ULA connects directly to the larger memory space ignoring mapping; the screen is always 16k-Bank 5, no matter where in memory it is (or if it is switched in at all). Setting bit 3 of Memory Paging Control ($7FFD / 32765) will have the ULA read from 16k-bank 7 (the "shadow screen") instead, which can be used as an alternate screen. Beware that this does not map 16k-bank 7 into RAM; to alter 16k-bank 7 it must be mapped by other means.