<!-- PDF page 271 -->

## Chapter 24 – The System Variables

### Overview

Certain locations in memory are set aside for specific uses by the system. There are a few routines (used to keep the paging in order), and some locations called system variables (or SYSVARS). You can use **PEEK** and **DPEEK** to read them, in order to find out various things about the system, and on some of them you can usefully change with **POKE** and **DPOKE**. They are listed here with their uses.

The area occupied by SYSVARS spans the addresses **23296** (**5B00h**) to **23733** (**5CB5h**) (inclusive) and a subset of them are used in 48K BASIC – addresses **23552** (**5C00h**) to **23733** (**5CB5h**).

Note that in 48K mode, there is a buffer area between **23296** (**5B00h**) and **23552** (**5C00h**) which was used for controlling the printer. This was quite a popular location for small machine code programs on the old 48K Spectrum and if any of these routines are tried in *NextBASIC*, the computer will invariably crash. It's advisable that any 48K BASIC program that uses **PEEK**, **POKE** and **USR** to either be run in 48K BASIC mode (although it can be entered in *NextBASIC* mode and transferred using the **SPECTRUM** command) or examined thoroughly and converted so it won't use any of these commands. Alternatively, any machine code routine embedded within it should be moved to a safer area.

### System Variables

The system variables listed below, all have unique names, but do not confuse them with *NextBASIC* variables. The computer will not recognize the names as referring to system variables, and they are given solely as mnemonics to be human-readable.

The abbreviations in column 1 of the table that follows have the following meanings:

**X** The variables should not be poked because the system might crash.\
**N** Poking the variable will have no lasting effect\
**R** Routine entry point. Not a variable.

The number in column 1 is the number of bytes in the variable. For two bytes, the first one is the least significant byte; the reverse of what you might expect. So to **POKE** a value *v* to a two byte variable at address *n*, use **DPOKE** instead, as it does the conversion for you. Otherwise you'll need to enter the following for SYSVAR *n* value *v*:

```
POKE n,v-256*INT (v/256)
POKE n+1,INT (v/256)
```

and to peek its value, either use **DPEEK** or the expression:

```
PEEK n+256*PEEK (n+1)
```

<table>
<thead>
<tr><th rowspan="2">Notes</th><th colspan="2">Address</th><th rowspan="2">Name</th><th rowspan="2">Description</th></tr>
<tr><th>Hex</th><th>Dec</th></tr>
</thead>
<tbody>
<tr><td><b>R16</b></td><td>5B00</td><td>23296</td><td><b>SWAP</b></td><td>Paging subroutine</td></tr>
<tr><td><b>R17</b></td><td>5B10</td><td>23312</td><td><b>STOO</b></td><td>Paging subroutine. Entered with interrupts already disabled and AF, BC on the stack.</td></tr>
<tr><td><b>R9</b></td><td>5B21</td><td>23329</td><td><b>YOUNGER</b></td><td>Paging subroutine</td></tr>
<tr><td><b>R16</b></td><td>5B2A</td><td>23338</td><td><b>REGNUOY</b></td><td>Paging subroutine</td></tr>
<tr><td><b>R24</b></td><td>5B3A</td><td>23354</td><td><b>ONERR</b></td><td>Paging subroutine</td></tr>
<tr><td><b>X2</b></td><td>5B52</td><td>23378</td><td><b>OLDHL</b></td><td>Temporary register store while switching ROMs</td></tr>
<tr><td><b>X2</b></td><td>5B54</td><td>23380</td><td><b>OLDBC</b></td><td>Temporary register store while switching ROMs</td></tr>
<tr><td><b>X2</b></td><td>5B56</td><td>23382</td><td><b>OLDAF</b></td><td>Temporary register store while switching ROMs</td></tr>
<tr><td><b>X1</b></td><td>5B58</td><td>23384</td><td><b>CACHEBNK</b></td><td>8K Bank ID holding cached program data</td></tr>
<tr><td><b>N1</b></td><td>5859</td><td>23385</td><td></td><td>Reserved for system use</td></tr>
</tbody>
</table>

