Next Breakpoints
Besides the breakpoints every machine has (see Breakpoints), the ZX Spectrum Next can stop on events of its own hardware. Use them when the question is who changed this rather than what runs here: who switched the CPU speed, which Copper instruction changed the palette, what moved sprite 12.
Applies to: ZX Spectrum Next.
| To stop when… | Type | Command | Also from |
|---|---|---|---|
| a Next Register is written | NextReg write | bp-set nr:$07 | the Breakpoint dialog |
| the Copper completes a list instruction | Copper instruction | bp-set cu:$00B | the Copper List’s gutter, a .copper source line |
| an attribute byte of a sprite is written | Sprite attribute write | bp-set sp:$0C | the Sprite Inspector’s row menu |
| an interrupt is taken, lost or waits too long, or an NMI is taken | Interrupt event | bp-set int:ack:line | see Debugging interrupts |
| a palette entry is written, or a device’s live palette bank flips | Palette write | bp-set pal:spr1:$03 | the Palette document; see Debugging palettes |
The types are offered by the Breakpoint dialog as well. Hit counts, conditions, logpoints and one-shots work on all of them, as on any other breakpoint.
NextReg Write Breakpoints (ZX Spectrum Next)
Every other breakpoint names a place: an address, an offset in a bank, a source line. A NextReg write breakpoint names an event: stop when a particular Next Register is written.
bp-set nr:$07The Next’s registers are where the machine’s behaviour actually lives: the CPU speed, the MMU slots,
the Layer 2 base, sprite control, the interrupt configuration. When something writes one of them
unexpectedly, the alternatives are an I/O write breakpoint on port $253B, which fires on every
NextReg write in the system including NextZXOS’s own, or reading the disassembly until you spot the
NEXTREG instruction. Neither works well on a .nex file you did not write.
The breakpoint catches a write from the CPU whichever way it arrives: through port $253B, through
the NEXTREG instructions, or from a DMA transfer the program set up.
Breaking On One Value
Add = and a value to break only when that value is written, and / and a mask to compare only some
of the bits:
bp-set nr:$07=$03 ; only when $07 is set to $03
bp-set nr:$07=$03/$0f ; only when its low nibble becomes $3The value is part of the breakpoint’s identity, so nr:$07 and nr:$07=$03 are two breakpoints and
both can be set at once. The same thing can be typed as options (bp-set nr:$07 -v $03 -m $0f),
which is what the Breakpoint Dialog writes for you.
Copper Writes
By default only CPU writes break. A copper list runs every frame, so a breakpoint that fired on its
writes would stop the machine constantly. Add -c when the copper is what you are chasing:
bp-set nr:$40 -cThe row and its tooltip say which of the two the breakpoint is watching. Writes performed by a reset or by Klive’s own display hotkeys are never reported.
What You See When It Fires
The machine stops after the instruction that wrote the register, not before it. A Z80
instruction cannot be interrupted part-way, and several NextReg writes can happen inside one of them
(a DMA burst to $253B, or a busy copper list), so a breakpoint that tried to withhold
the write would have to drop or duplicate some of them.
Nothing is lost by this. The breakpoint reports the value the register held and the value
written, so the row reads $00 → $03: you see both sides of the change rather than only the one a
stop-before would have shown.
The Breakpoints view shows the register’s documented name beside its key, and the old and new values once the machine has stopped on it. The output pane says the same thing in words:
NextReg breakpoint: $07 (CPU speed) $00 -> $03 at PC=$8005The row and the message both name where the write came from: the address of the instruction that did it, and the partition that address was paged from. On a Next the same address means different code depending on what is paged there, so the address alone does not identify the instruction.
Breaking On A Reset
Writing NextReg $02 asks the machine to reset: bit 0 for a soft reset, bit 1 for a hard one. That
makes nr:$02 the most useful breakpoint of the lot and the one with the most to go wrong, because
a reset discards exactly the two things you set the breakpoint to find out.
bp-set nr:$02Klive stops before carrying the reset out. The machine is still standing where the write happened: the program counter, the MMU slots and every other register are as the program left them, and the Memory view shows the paging that was in force. The reset is performed when you resume.
This is the one place where a NextReg breakpoint changes when the machine does something, rather
than only watching. Without a breakpoint on $02, or with one that is disabled, the reset happens
exactly as it always did.
These breakpoints are stored in the project, not in a .nex.dis sidecar: they watch a hardware
register, so they mean the same thing whichever NEX file is loaded.
Copper Breakpoints (ZX Spectrum Next)
A Copper breakpoint names another event: the Copper completes an instruction of its list. The
list holds 1024 instructions, so the breakpoint names a list index, $000 to $3FF:
bp-set cu:$00B- A
MOVE(or aNOP) fires when the Copper issues it. - A
WAITfires when its condition is satisfied (when the raster reaches the line and position it waits for), not when the Copper arrives at it. That is the moment that matters: “the beam has reached line 96”. - The
HALT(WAIT 511,63) never completes, so a breakpoint on it never fires.
Hit counts, conditions, logpoints and one-shots work as on any other breakpoint. A list that runs
once per frame passes each instruction once per frame, so -hit counts frames:
bp-set cu:$00B -hit 50 ; the 50th frame
bp-set cu:$00B -once ; once, then the breakpoint is removedIn a condition, ADDR is the list index and VAL is the 16-bit instruction word, so
-if VAL != $BE78 stops only when the CPU has patched the instruction.
The Copper runs on to the end of the Z80 instruction. The Copper executes at 28 MHz, locked to the beam, and the machine can only stop between Z80 instructions. By the time it stops, the Copper may have completed several more instructions. The stop message, the Breakpoints view and the Copper List therefore report the hit (the instruction and the beam position where it completed) separately from where the Copper is now.
Copper breakpoint: $002 WAIT 96, 8 satisfied at line 96, hc 76 (x 64); CPU at $8019 in 05You can set a Copper breakpoint from the Copper List’s gutter, from the Copper instruction type
of the Breakpoint Dialog, or by clicking the margin of a .copper source
line while the program runs: Klive finds where that line’s instruction sits in the Copper’s memory
and sets the breakpoint on that index.
Sprite Attribute Breakpoints (ZX Spectrum Next)
A sprite attribute breakpoint stops when an attribute byte of a sprite is written. It names the
sprite, $00 to $7F:
bp-set sp:$0CIt catches every way the hardware stores an attribute byte:
- port
$57, written by the CPU (OUT,OTIR) or by the DMA; - the NextReg mirrors
$35-$39and$75-$79on the sprite$34selects, written by the CPU (NEXTREG, port$253B), the DMA or the Copper.
Selecting a sprite ($303B, $34) is not a write. A four-byte sprite (attribute 3, bit 6 clear) skips
its fifth byte without writing it, so a breakpoint on attribute 4 does not fire for it.
To watch only some of the five bytes, add -attr with a list. Attributes 0 and 1 hold X and Y, so
this stops only when sprite 12 moves:
bp-set sp:$0C -attr 0,1
bp-set sp:$0C -attr 0-3 -hit 10Hit counts, conditions, logpoints and one-shots work as on any other breakpoint. In a condition,
ADDR is the attribute byte (0-4) and VAL is the value written, so
-if ADDR == 3 && (VAL & $80) == 0 stops when the sprite is made invisible.
The machine stops after the instruction during which the byte was written, and the stop message reports the byte’s previous and new values and who wrote it:
Sprite breakpoint: sprite $0C attr 0 (X) $00 -> $40 through port $57, written at $800C in 05
Sprite breakpoint: sprite $14 attr 3 (visible, pattern) $00 -> $C0 by the Copper, with the CPU at $8026You can set a sprite attribute breakpoint from the Sprite Inspector: right-click a sprite and choose Break on attribute write, or Run until attribute write for a one-shot. The Sprite attribute write type of the Breakpoint Dialog has a checkbox for each attribute byte.