NEX file format

The NEX (Next Executable) format is the primary distribution format for the ZX Spectrum Next. It loads multi-bank programs quickly, with support for loading screens, custom border colours and machine configuration. FantASM implements versions 1.2 and 1.3 (matching sjasmplus).

Set the header fields from source with the !nex directive; see the example below.

Header structure (512 bytes)

The file begins with a 512-byte header. All multi-byte values are little-endian.

OffsetSizeNameDescription
04Magic“Next”
44Version“V1.2” or “V1.3”
81RAM Req0 = 768K, 1 = 1792K
91Num BanksNumber of 16K banks to load (0–112).
101ScreenLoading screen flags.
111BorderBorder colour (0–7).
122SPStack pointer (0 = do not set).
142PCEntry point (0 = no start).
162ObsoleteObsolete numFiles.
18112Bank BitmapBitmap of which 16K banks are present.
1301Load Bar0 = disable, 1 = enable loading progress bar.
1311Load Bar ColourColour of the progress bar.
1321Load DelayDelay (frames) after each bank is loaded.
1331Start DelayDelay (frames) after all banks are loaded.
1341Preserve Regs0 = reset machine state, 1 = preserve most NextRegs.
1353Core VersionMinimum required core version (major, minor, subminor).
1381HiRes ColourBits 5–3 for port 255.
1391Entry Bank16K bank mapped into $C000–$FFFF at start.
1402File Handle Cfg0 = close, 1 = handle in BC, 0x4000+ = address.
1421Exp Bus DisableV1.3: 0 = disable expansion bus, 1 = no-op.
1431Has ChecksumV1.3: 0 = no checksum, 1 = CRC-32C in header.
1444Banks OffsetV1.3: file offset where bank data starts.
1482CLI BufferV1.3: address of buffer for command-line copy.
1502CLI Buffer SizeV1.3: size of the provided buffer.
1521Screen 2V1.3: extended screen flag.
1531Copper FlagV1.3: 0 = no copper, 1 = 2048-byte copper block.
1544Tilemap ConfigV1.3: NextReg $6B, $6C, $6E, $6F values.
1581L2 Bar Pos YV1.3: Y position of the loading bar for Layer 2 modes.
5084CRC32CV1.3: CRC-32C checksum (Castagnoli).

Bank mapping

NEX stores data in 16KB “banks” — even though the Next pages memory in 8KB banks internally, the NEX format uses the traditional 16KB numbering:

  • Bank 5$4000–$7FFF
  • Bank 2$8000–$BFFF
  • Bank 0 → typically $C000–$FFFF (along with banks 1, 3, 4, 6, 7…)

The Bank Bitmap (offset 18) records which banks are present.

File layout

  1. Header (512 bytes).
  2. Loading screen data (optional).
  3. Copper data (optional, V1.3).
  4. Bank data — 16,384 bytes per bank marked in the bitmap.

Banks are usually stored in the order 5, 2, 0, 1, 3, 4, 6, 7, 8, 9, 10, …

Assembler directives

Configure the header from source with !nex:

!nex pc start_label     ; entry point PC
!nex sp $FF00           ; initial SP
!nex bank 10            ; explicitly include bank 10
!nex screen 1           ; loading screen type
!nex bar 1, 4, 10, 5    ; loadBar, barColour, startDelay, loadDelay
!nex border 3           ; initial border colour
!nex core 2, 0, 28      ; minimum required core version
!nex entry 10           ; entry bank mapped at start
!nex preserve 1         ; preserve NextRegs
!nex crc 1              ; enable CRC-32C checksum (V1.3)

V1.3 enhancements

Version 1.3 adds a CRC-32C integrity checksum, a flexible banks-offset (data can follow screens at any position), expansion-bus disable during load, and enhanced 320×256 / 640×256 loading screens.