<!-- PDF page 251 -->

### NextZXOS and NextBASIC memory allocation

Before we begin to elaborate on *NextZXOS'* memory usage, it should be mentioned that Standard memory management and MMU management are internally synchronised for most cases. Every time a 16K bank is being paged in, the equivalent MMU unit gets the 8K bank component of the larger 16K bank *NextZXOS* uses. As mentioned previously *NextZXOS* also supports **allRAM** mode where the ROM is paged out; this is mainly used by *CP/M*. With this information out of the way, let's see how *NextZXOS* uses the memory.

By default the first 9 RAM banks are used as follows:

| Bank | Description | Address Range |
|---|---|---|
| 0 | Standard 48K Spectrum memory | 49152 – 65535 |
| 1 | RAMdisk | |
| 2 | Standard 48K Spectrum memory | 32768 – 49151 |
| 3 | RAMdisk | |
| 4 | RAMdisk | |
| 5 | Standard 48K Spectrum memory | 16384 – 32767 |
| 6 | RAMdisk | |
| 7 | Used for workspace and data structures by *NextZXOS* | |
| 8 | Used for additional screen data (for *LoRes*, *HiRes* and *HiColour*) and other data by *NextZXOS* | |
| 9 – 111 | Available for user programs (By default banks **9**,**10** and **11** are used by *Layer 2*) | |

Generally speaking, banks **9+** are always available to the programmer, and can be accessed using the **BANK** command, while banks **0** – **8** can be used with the following exceptions:

- Bank **0** can be used, only if **CLEAR** has set the RAMTOP to below **49152**.
- Bank **2** can be used, only if **CLEAR** has set the RAMTOP to below **32768**.
- Banks **1**,**3**,**4**,6 can be used if the **BANK 1346 USR** command has been used.
- Banks **7** and **8 can never be used**.
- Bank **5** can be used with caution.
- Banks **9**, **10** and **11** can be used for other purposes if you aren't using *Layer 2* or you have changed their assignments with the **LAYER BANK** command.

From the above, it is easy to surmise what the initial bank assignments are after boot:

| Slot 1 | Slot 2 | Slot 3 | Slot 4 |
|---|---|---|---|
| **ROM** | **Bank 5** | **Bank 2** | **Bank 0** |

In case you were thinking that *this looks easy enough – I could page in any bank I want*, don't! In actuality, *NextZXOS* and *NextBASIC* expect certain things to be in certain places at all times within the memory map which is organised in the following manner:

![Fig. 48 – Memory map usage by NextBASIC](/documentation/manual/rev3/figures/p251-fig48-nextbasic-memory-usage.png)
```
 DISP_FILE1                    COLOUR_FILE1           SYSVARS            CHANS
+------------------------------+----------------------+------------------+---------------------~
| Display File                 | Attributes           | System Variables | Channel Information ~
+------------------------------+----------------------+------------------+---------------------~
  16384/4000h                    22528/5800h            23296/5B00h        23734/5CB6h

    PROG                                  VARS       E_LINE                       WORKSP
+-~~+----+------------------------+---------+---+-----------------------+--+---+~~-+
| ~ |80h | NextBASIC Program      |Variables|80h| Command or Program    |NL|80h| ~ |
| ~ |    |                        |         |   | Line being Edited     |  |   | ~ |
+-~~+----+------------------------+---------+---+-----------------------+--+---+~~-+

 WORKSP                    STKBOT           STKEND  STACK                RAMTOP   UDG    P_RAMT
                                                     POINTER
+-------+--+---------------+---------------+-------+--------+-------------+--+----+--------------~
|INPUT  |NL| Temporary     | Calculator    | Spare | Machine| NextBASIC   |? |3Eh | User Defined ~
|Data   |  | Workspace     | Stack         |       | Stack  | Return Stack|  |    | Graphics     ~
+-------+--+---------------+---------------+-------+--------+-------------+--+----+--------------~
```

*Fig. 48 – Memory map usage by NextBASIC*

