Difference between revisions of "Memory map"

From SpecNext official Wiki
Jump to: navigation, search
(SRAM memory map)
Line 119: Line 119:
 
The SpecNext site provided the following raw memory map for the Next's entire static physical memory space without memory management:  
 
The SpecNext site provided the following raw memory map for the Next's entire static physical memory space without memory management:  
  
* $00000 - ZX Spectrum Rom
+
* $000000 - ZX Spectrum Rom
* $10000 - ESXDOS Rom
+
* $010000 - ESXDOS Rom
* $14000 - Multiface ROM
+
* $014000 - Multiface ROM
* $18000 - Multiface extra ROM
+
* $018000 - Multiface extra ROM
* $1c000 - Multiface RAM
+
* $01c000 - Multiface RAM
* $20000 - DivMMC RAM
+
* $020000 - DivMMC RAM
* $60000 - Spectrum 128k Ram
+
* $060000 - Spectrum 128k Ram
* $80000 - Extra RAM
+
* $080000 - Extra RAM
* $FFFFF - End of addressable space
+
* $0FFFFF - End of addressable space on standard Next
 +
* $1FFFFF - End of addressable space on 2mb expanded Next
  
 
However it is not clear if any Spectrum code will be able to make use of this memory map since the Z80 cores only support 16-bit addresses. This may therefore only be useful for FPGA development.
 
However it is not clear if any Spectrum code will be able to make use of this memory map since the Z80 cores only support 16-bit addresses. This may therefore only be useful for FPGA development.

Revision as of 15:51, 24 September 2017

The Next supports two memory management models which operate in tandem.

128-style memory management

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-$3fff Slot 1, usually ROM, but usable for Layer 2.
$4000-$7fff Slot 2, usually used for the ULA 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. On the 128k Spectrum, there are 8 available banks, numbered 0-7. In standard mode, any bank can be switched into Slot 4 (via 128k Spectrum standards) and also any bank can be written to (but not read) in Slot 1 (via Layer 2 standards)

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). On Next, there are more than 7 banks as there as a total of 1Mb of system memory. 512k of these is occupied by the hardware ROM and RAM images and the standard Spectrum 128k RAM banks, but the remaining 512k provides 32 additional banks. The necessary extra bits are written to the lowest 3 bits of Next Memory Bank Select ($DFFD / 57341). If the Next has been chip upgraded to 2mb of memory, then the additional memory provides 96 extra banks for a total of 104 banks including the initial 8; however, there are only 6 memory selection bits available in this model, so the highest bank that can be accessed is bank 64.

Layer 2 switching can allow any bank to be written to in Slot 1 by "lying" that it is the address of Layer 2, then writing to it using the Layer 2 paging system without enabling display. Note, however, that data cannot be read from a bank switched in in this way.

"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

Beware that these will have the effect of paging out the ROM. Some programs may assume that they can find ROM service routines at fixed addresses in Slot 1. 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.

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.

ROM paging and selection

Slot 1 is usually mapped to ROM. ROM is not considered one of the numbered banks; ROM segments are selected by separate methods. The 128k Spectrum has 2 ROM pages which are selected in slot 1 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).

Activating Layer 2's paging will cause writes into slot 1 to go to the selected Layer 2 bank instead. Reads will continue to access the selected ROM page (or RAM bank if AllRam mode is enabled). This allows Layer 2 to be used without conflict by repurposing an operation (attempting to write to ROM) that would normally be useless.

Screen

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 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 bank 7 (the "shadow screen") instead, which can be used as an alternate screen. Beware 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.

By default, extra banks 8-13 are used for Layer 2, although these can be reselected or reused if you are not using layer 2.

Next Memory Management

The Next also includes its own higher-level memory management tool. This divides memory into 8 slots as follows:

Area Description
$0000-$1fff Slot 1, usually ROM, but usable for Layer 2.
$2000-$3fff Slot 2, usually ROM, but usable for Layer 2.
$4000-$5fff Slot 3, usually used for the ULA screen.
$6000-$7fff Slot 4, usually used for the ULA screen.
$8000-$9fff Slot 5, Free RAM.
$a000-$bfff Slot 6, Free RAM.
$c000-$dfff Slot 7, Free RAM.
$c000-$dfff Slot 8, Free RAM.

The page accessed in a slot is selected by writing to the bottom 7 bits of Next registers from Template:NextRegNo:$50 upwards. Since pages are 8k big in this model, this fills in the most significant 3 bits of the 16-bit address and then the remaining 5 bits for the expansion.

Since pages are half the size that they are in the Spectrum 128 model, there are 208 addressable banks in this model, addressed as 0-207. In addition, in Slots 1 and 2 only, the ROM can be paged in by writing $FF to the page. Which ROM is active is selected using the 128k model as above.

Slot List

Banks (128k) Banks (Next) True Address Description
0 0-1 $000000-$003fff Standard RAM, may be used by EsxDOS
1 2-3 $004000-$007fff Standard RAM, contended on 128, may be used by EsxDOS
2 4-5 $008000-$00afff Standard RAM
3 6-7 $00b000-$00ffff Standard RAM, contended on 128, may be used by EsxDOS
4 8-9 $010000-$013fff Standard RAM, contended on +2/+3
5 10-11 $014000-$017fff ULA Screen, contended except on Pentagon
6 12-13 $018000-$01afff Standard RAM, contended on +2/+3
7 14-15 $01b000-$01ffff ULA Shadow Screen, contended except on Pentagon
8 16-17 $020000-$023fff Next RAM, Default Layer 2
9-10 18-21 $024000-$02afff Next RAM
11 22-23 $02b000-$02ffff Next RAM, Default Layer 2 Shadow Screen
12-39 24-79 $030000-$09ffff Next RAM
40-63 80-127 $0a0000-$0fffff 2Mb Expanded Next RAM (accessible via 128 memory management)
-- 128-207 $100000-$19fffff 2Mb Expanded Next RAM (accessible via Next manegement only)


SRAM memory map

The SpecNext site provided the following raw memory map for the Next's entire static physical memory space without memory management:

  • $000000 - ZX Spectrum Rom
  • $010000 - ESXDOS Rom
  • $014000 - Multiface ROM
  • $018000 - Multiface extra ROM
  • $01c000 - Multiface RAM
  • $020000 - DivMMC RAM
  • $060000 - Spectrum 128k Ram
  • $080000 - Extra RAM
  • $0FFFFF - End of addressable space on standard Next
  • $1FFFFF - End of addressable space on 2mb expanded Next

However it is not clear if any Spectrum code will be able to make use of this memory map since the Z80 cores only support 16-bit addresses. This may therefore only be useful for FPGA development.