Difference between revisions of "Memory map"

From SpecNext official Wiki
Jump to: navigation, search
(Created page with "The Memory Map of the Next is based on the memory structure of the ZX Spectrum 128. The Z80's 16-bit bus can only access 64k of memory, laid out as follows: * $0000-$3999: RO...")
 
Line 1: Line 1:
The Memory Map of the Next is based on the memory structure of the ZX Spectrum 128. The Z80's 16-bit bus can only access 64k of memory, laid out as follows:
+
The Memory Map of the Next is based on the memory structure of the ZX Spectrum 128 and +2a/+3.  
  
* $0000-$3999: ROM.
+
The Z80's 16-bit bus can only access 64k of memory, which is divided into 4 "slots" as follows. Each of these 4 slots is mapped to a 16k ''bank'' of memory within the larger available address space.
* $4000-$7999: Screen. Depending on the video mode, not all of this RAM may be used for the screen. The remainder can be used freely but is slowed down by contention with the ULA drawing the screen. This is also bank 5.
 
* $8000-$BFFF: Free RAM. This is also bank 2.
 
* $C000-$FFFF: Switchable RAM bank.  
 
  
The selected bank is set using {{PortNo|$7FFD}}.
+
{|class="wikitable"
 +
! Area !! Description
 +
|-
 +
| $0000-$3999 || Slot 1 (Usually ROM)
 +
|-
 +
| $4000-$7999 || Slot 2, usually used for the screen. Defaults to bank 5.
 +
|-
 +
| $8000-$BFFF || Slot 3, Free RAM. Defaults to bank 2.
 +
|-
 +
| $C000-$FFFF || Slot 4, Free RAM. Defaults to bank 0.
 +
|}
 +
 
 +
On the 48k Spectrum this is all the available memory there is, so no switching can be performed.
 +
 
 +
In standard mode, only Slot 4 is switchable. The active bank at slot 4 is selected by writing to the bottom 3 bits of {{PortNo|$7FFD}}. This can be any bank from 0 to 7, which means it can end up doubling the bank at $8000 (2) or $4000 (5).
 +
 
 +
"Special paging 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:
 +
{| class="wikitable"
 +
! 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
 +
|}
 +
 
 +
== ROM paging and selection ==
 +
Slot 1 is usually ROM. Some programs may assume that they can find ROM service routines here. 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. [[Extended Z80 instruction set#DI|DI]] is your friend.
 +
 
 +
The 128k Spectrum has 2 ROM pages which are selected between by altering Bit 4 of {{PortNo|$7FFD}}. The +2a/+3 has 4 ROM pages; the extra bit needed to select between these is bit 2 of {{PortNo|$1FFD}}.
 +
 
 +
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.
 +
 
 +
== Screen ==
 +
Bank 5 is the slot read by the ULA for the screen. Setting bit 3 of {{PortNo|$7FFD}} will have the ULA read from bank 7 (the "shadow screen") instead, which can be used as an alternate screen. Note that this does ''not'' remap slot 2; to alter bank 7 it must be switched in to slot 4. On the 128k Spectrum, banks 1, 3, 5, and 7 are all contended; on the +2a/+3, banks 4, 5, 6, and 7 are contended. Contended memory is subject to delays.

Revision as of 17:05, 18 August 2017

The Memory Map of the Next is based on the memory structure of the ZX Spectrum 128 and +2a/+3.

The Z80's 16-bit bus can only access 64k of memory, which is divided into 4 "slots" as follows. Each of these 4 slots is mapped to a 16k bank of memory within the larger available address space.

Area Description
$0000-$3999 Slot 1 (Usually ROM)
$4000-$7999 Slot 2, usually used for the screen. Defaults to bank 5.
$8000-$BFFF Slot 3, Free RAM. Defaults to bank 2.
$C000-$FFFF Slot 4, Free RAM. Defaults to bank 0.

On the 48k Spectrum this is all the available memory there is, so no switching can be performed.

In standard mode, only Slot 4 is switchable. The active bank at slot 4 is selected by writing to the bottom 3 bits of Memory Paging Control ($7FFD / 32765). This can be any bank from 0 to 7, which means it can end up doubling the bank at $8000 (2) or $4000 (5).

"Special paging 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

ROM paging and selection

Slot 1 is usually ROM. Some programs may assume that they can find ROM service routines here. 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.

The 128k Spectrum has 2 ROM pages which are selected between 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).

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.

Screen

Bank 5 is the slot read by the ULA for the screen. Setting bit 3 of Memory Paging Control ($7FFD / 32765) will have the ULA read from bank 7 (the "shadow screen") instead, which can be used as an alternate screen. Note that this does not remap slot 2; to alter bank 7 it must be switched in to slot 4. On the 128k Spectrum, banks 1, 3, 5, and 7 are all contended; on the +2a/+3, banks 4, 5, 6, and 7 are contended. Contended memory is subject to delays.