<!-- PDF page 265 -->

### Extending NextBASIC Programs with BANK

Unlike previous iterations of Sinclair BASIC, *NextBASIC* makes it possible to write programs larger than the approximate 41K which used to be the norm with previous ZX Spectrum models. This is achieved through the use of BANK command extensions; whole sections of *NextBASIC* programs can be copied into any memory bank available to the user (and saved/loaded with the **SAVE / LOAD...BANK** commands as described in *Chapter 20* as well as the previous section). Programs can then switch between lines in the "main" program area and those held in a bank.

The following new commands are available to manage banked sections of *NextBASIC* programs: **BANK LINE**, **BANK LIST** and **BANK LIST PROC()**, **BANK MERGE**, **BANK GO TO**, **BANK GOSUB**, **BANK PROC** and **BANK RESTORE**. We have covered these as well in the appropriate sections of this guide, so they're mentioned here in brief for completeness and reference. Syntax is as follows

**BANK** *n* **LINE** *x,y*

Copies lines *x* through *y* (inclusive) from the main program to bank *n*. The total number of bytes used in the bank will be shown. Once this has been done, it is not possible to change or delete any lines in the banked section, except by completely overwriting the bank's contents using another **BANK...LINE** command or by executing a command that will replace the bank's contents with something else.

**BANK** *n* **LIST** [*l* | **PROC** *name*<b>()</b>]

Lists lines, optionally starting with line or label *l* or from a procedure named *name*, in bank *n*.

**BANK** *n* **MERGE**

Copy all lines back from bank *n* into the main program. This won't overwrite line numbers that did not exist in the source bank

**BANK** *n* **GO TO** *l*

performs a **GO TO** line or label *l* in bank *n*. To **GO TO** to a line or label in the main program from a banked section, the bank number should be **255**.

**BANK** *n* **GOSUB** *l*

branches using **GOSUB** to the subroutine located at line or label *l* in bank *n*. To **GOSUB** to a subroutine in the main program from a banked section, as with **GO TO** above, the bank number should be **255**.

**BANK** *n* **PROC** *name* (*parameter1*[<b>,...,</b>*parameterN]*)[**TO** *variable1[,...,variableN*]]

branches to the **PROC** named *name* located in bank *n* with optional parameters *parameter1* to *parameterN* and optional return values stored in *variable1* to *variableN*. To branch to a **PROC** in the main program from a banked section, as with **GO TO** above, the bank number should be **255**.

**BANK** *n* **RESTORE** *l*

Sets the **DATA** pointer to line or label *l* in bank *n* ready for the next **READ** operation.

It's noted that **BANK LINE** and **BANK MERGE** can only be given as direct commands and not as part of a saved program be it in a bank or in the main section.

### NextZXOS Paging Mechanism Overview

As we discussed in the introduction to this chapter the CPUs used in all previous models of the ZX Spectrum line as well as this one, can only address **65536** bytes. The original 128K ZX Spectrum crammed in more than twice the amount of memory than it could address clocking in at **131072** bytes of RAM and **32768** bytes of ROM making **163840** bytes

