A camera need not move every time the player takes a step. Keep a quiet area on screen, and scroll only when the player pushes beyond it. The camera should also stop at the edge of the world rather than revealing an empty border.

Include, initialise and call
Reserve CAMERA, PLAYER, LEFT_EDGE, RIGHT_EDGE, SCROLL_LIMIT, SHIFTED, VALID as 7 contiguous private bytes in that order. Include the helper once. Call camera_deadzone_init at the intended reset boundary: it clears every named byte, including input fields. Set the starting values afterwards, then call camera_deadzone_step for each intended service.
Initialise, establish valid world/view limits and update PLAYER in world coordinates. Service after movement, then pass CAMERA to the renderer’s coordinate conversion or scrolling backend. The normal 40–80 dead zone moves the camera from zero to ten for player 90, then to twenty for player 100.
CAMERA and PLAYER are unsigned world coordinates. LEFT_EDGE/RIGHT_EDGE are permitted screen-relative player thresholds, with LEFT_EDGE ≤ RIGHT_EDGE. SCROLL_LIMIT is the largest camera coordinate; the current CAMERA must already be within 0–SCROLL_LIMIT. Invalid bounds leave CAMERA unchanged and clear SHIFTED/VALID. Otherwise step sets VALID, moves just enough to put the player on the crossed threshold, clamps to 0–SCROLL_LIMIT and sets SHIFTED exactly when CAMERA changes. Player and bounds survive.
Reusable initialisation and service
; SPDX-License-Identifier: MIT
; Camera Dead Zones. Contiguous private bytes: CAMERA, PLAYER, LEFT_EDGE, RIGHT_EDGE, SCROLL_LIMIT, SHIFTED, VALID.
; init clears all fields; set inputs afterwards. No I/O, waits or IRQ ownership.
; AF/BC/DE/HL change; IX/IY survive.
camera_deadzone_init:
xor a
ld (CAMERA),a
ld (PLAYER),a
ld (LEFT_EDGE),a
ld (RIGHT_EDGE),a
ld (SCROLL_LIMIT),a
ld (SHIFTED),a
ld (VALID),a
ret
camera_deadzone_step:
xor a
ld (SHIFTED),a
ld (VALID),a
ld a,(RIGHT_EDGE)
ld b,a
ld a,(LEFT_EDGE)
cp b
jr c,camera_check_position
ret nz
camera_check_position:
ld a,(SCROLL_LIMIT)
ld b,a
ld a,(CAMERA)
cp b
jr c,camera_valid
ret nz
camera_valid:
ld a,1
ld (VALID),a
ld a,(CAMERA)
ld b,a
ld a,(PLAYER)
sub b
jr c,camera_left
ld c,a
ld a,(LEFT_EDGE)
cp c
jr c,camera_check_right
jr nz,camera_left
camera_check_right:
ld a,(RIGHT_EDGE)
cp c
ret nc
ld b,a
ld a,(PLAYER)
sub b
jr camera_cap
camera_left:
ld a,(LEFT_EDGE)
ld b,a
ld a,(PLAYER)
sub b
jr nc,camera_cap
xor a
camera_cap:
ld c,a
ld a,(SCROLL_LIMIT)
cp c
jr nc,camera_have
ld c,a
camera_have:
ld a,(CAMERA)
cp c
ret z
ld a,c
ld (CAMERA),a
ld a,1
ld (SHIFTED),a
ret
component_end:State, registers and ownership
Seven bytes. CAMERA persists; PLAYER and the three bounds are inputs; SHIFTED and VALID are replaced flags. PLAYER − CAMERA is computed without byte-wrap mistakes, including when the player lies to the left of the camera.
AF/BC/DE/HL may change; IX/IY survive. A direct CALL needs two return-address stack bytes.
The implementation binds fixed symbols and has one mutation owner. Independent users need separate state blocks and scoped/renamed labels, including routine labels; sharing the same bindings means sharing the state. Do not let an interrupt and the main loop mutate the same block without an explicit ownership policy.
The standalone tape program enters at $8000, disables interrupts and owns bitmap/attribute RAM. It does not restore BASIC. Those choices belong to the test program; the helper itself never takes over the display.
A caller you can adapt
The buildable program supplies bindings and include order. Its separate client retains state between calls. checked_step calls the public camera_deadzone_step entry and checks register sentinels; emit_state records diagnostics. Your game can call the public entry directly, remove the diagnostics and consume the documented outputs.
Bindings, buildable caller and include order
org $8000
CUSTOM equ 0
BROKEN equ 0
COYOTE_STEPS equ 4
BUFFER_STEPS equ 4
TEXT_CAP equ 8
PROPERTY_COUNT equ 16
STREAM_BYTES equ 13
CRC_POLY equ 7
include "caller.inc"
include "exercise.inc"
component_start:
include "component.inc"
include "data.inc"
include "cases.inc"
include "../../physics/rectangle-overlap/display.inc"
code_end:
STATE:
CAMERA: defb 0
PLAYER: defb 0
LEFT_EDGE: defb 0
RIGHT_EDGE: defb 0
SCROLL_LIMIT: defb 0
SHIFTED: defb 0
VALID: defb 0
input_ptr: defw 0
output_ptr: defw 0
cases_left: defb 0
ready: defb 0
preview: defs 8,0
OUTPUT: defs 1300,0
end startA separate client retaining state between calls
preview_rules:
if CUSTOM
ld a,0
ld (CAMERA),a
ld a,90
ld (PLAYER),a
ld a,60
ld (LEFT_EDGE),a
ld a,60
ld (RIGHT_EDGE),a
ld a,155
ld (SCROLL_LIMIT),a
if BROKEN
ld a,(CAMERA)
ld b,a
ld a,(PLAYER)
sub b
ld (PLAYER),a
call checked_step
else
call checked_step
endif
call emit_state
ld a,100
ld (PLAYER),a
if BROKEN
ld a,(CAMERA)
ld b,a
ld a,(PLAYER)
sub b
ld (PLAYER),a
call checked_step
else
call checked_step
endif
call emit_state
else
ld a,0
ld (CAMERA),a
ld a,90
ld (PLAYER),a
ld a,40
ld (LEFT_EDGE),a
ld a,80
ld (RIGHT_EDGE),a
ld a,155
ld (SCROLL_LIMIT),a
if BROKEN
ld a,(CAMERA)
ld b,a
ld a,(PLAYER)
sub b
ld (PLAYER),a
call checked_step
else
call checked_step
endif
call emit_state
ld a,100
ld (PLAYER),a
if BROKEN
ld a,(CAMERA)
ld b,a
ld a,(PLAYER)
sub b
ld (PLAYER),a
call checked_step
else
call checked_step
endif
call emit_state
endif
retThe display fields are CAMERA, PLAYER, LEFT_EDGE, RIGHT_EDGE, SCROLL_LIMIT, SHIFTED, VALID; remaining display fields are zero. Each is one hexadecimal byte. The normal row is 14 64 28 50 9B 01 01 00. This is a completed state observation, not a recording of an actual character jumping, a camera scrolling or an asset being displayed.
Make it your own
The custom caller sets both thresholds to 60. The dead zone has zero width, so the camera tracks the player at that screen position until a world edge prevents it. The two calls finish at camera 40 instead of 20.
Maintained custom configuration or caller
org $8000
CUSTOM equ 1
BROKEN equ 0
COYOTE_STEPS equ 2
BUFFER_STEPS equ 2
TEXT_CAP equ 4
PROPERTY_COUNT equ 16
STREAM_BYTES equ 13
CRC_POLY equ 49
include "caller.inc"
include "exercise.inc"
component_start:
include "component.inc"
include "data.inc"
include "cases.inc"
include "../../physics/rectangle-overlap/display.inc"
code_end:
STATE:
CAMERA: defb 0
PLAYER: defb 0
LEFT_EDGE: defb 0
RIGHT_EDGE: defb 0
SCROLL_LIMIT: defb 0
SHIFTED: defb 0
VALID: defb 0
input_ptr: defw 0
output_ptr: defw 0
cases_left: defb 0
ready: defb 0
preview: defs 8,0
OUTPUT: defs 1300,0
end startThe custom row is 28 64 3C 3C 9B 01 01 00. These records qualify the named builds and inputs; another layout, format or input domain needs explicit bounds and fresh execution evidence.
Common mistake and repair
The wrong client subtracts CAMERA from PLAYER before calling the world-coordinate API. The second request supplies screen position 90 in place of world position 100, leaving the camera at ten. Keep world and screen coordinates separate and subtract the camera only in the rendering path.
Select the deliberately wrong client
org $8000
CUSTOM equ 0
BROKEN equ 1
COYOTE_STEPS equ 4
BUFFER_STEPS equ 4
TEXT_CAP equ 8
PROPERTY_COUNT equ 16
STREAM_BYTES equ 13
CRC_POLY equ 7
include "caller.inc"
include "exercise.inc"
component_start:
include "component.inc"
include "data.inc"
include "cases.inc"
include "../../physics/rectangle-overlap/display.inc"
code_end:
STATE:
CAMERA: defb 0
PLAYER: defb 0
LEFT_EDGE: defb 0
RIGHT_EDGE: defb 0
SCROLL_LIMIT: defb 0
SHIFTED: defb 0
VALID: defb 0
input_ptr: defw 0
output_ptr: defw 0
cases_left: defb 0
ready: defb 0
preview: defs 8,0
OUTPUT: defs 1300,0
end start
The BROKEN branch is visible in the client. repaired.asm restores the normal selection; its executable matches demo exactly. Spectrum tape filenames may differ while loaded CODE remains identical. The fault is a labelled experiment, not a suggested alternative.
Cost, limits and verification
The measured layout has 122 code bytes, 0 immutable data bytes and 7 private state bytes. Alignment, stack usage, diagnostic tables and display machinery are additional. The extents come from the loaded program’s symbols, not from counting source lines.
A relative-position comparison and one clamped correction, with no map copy or display transfer. C64/Amiga hardware capabilities are not reduced to this logical byte coordinate; their renderers may need wider and differently split scroll values.
The byte world is a bounded example, not a universal camera range. Wider maps need wider coordinates; smoothing adds fractional state and a time-step policy. Hardware coarse/fine scrolling, exposed map columns and parallax remain separate display-specific work. If bounds shrink, first move CAMERA into the new valid interval.
Four native runs use Spectrum 48K with stock ROM tape loading and USR entry; Asm198x 0.0.72 and Emu198x 0.44.2. Each checks 64 boundary/varied/error cases, dirty initialisation and every state of a separate sequential client against an independent integer model. This is not exhaustive coverage of every possible byte combination. Source/tool/firmware hashes, immutable loaded code/data, native startup/completion, preserved-register sentinels, helper/data sizes, screenshot bytes/pixels and exact repair are checked. Deliberately altered observations must fail. Firmware is hashed, never distributed.