A moving wall should carry an actor ahead of its leading face, or report that the actor cannot fit.

Use it in a project
One-axis half-open intervals use unsigned byte coordinates. ACTOR_SIZE/SOLID_SIZE must be nonzero; both solid endpoints plus size and the actor endpoint must fit in a byte. The old intervals must not overlap. MINIMUM/MAXIMUM bound the actor’s leading coordinate. Return POSITION, PUSHED and BLOCKED. If the swept solid would push the actor outside those limits, leave POSITION unchanged and set BLOCKED=1. Invalid geometry returns VALID=0. The helper never changes the solid.
Include component.inc once (MOS callers include the shared 6502 implementation through it). Reserve the public fields in this exact order: POSITION, PUSHED, BLOCKED, VALID, ACTOR_POSITION, ACTOR_SIZE, SOLID_OLD, SOLID_NEW, SOLID_SIZE, MINIMUM, MAXIMUM. They occupy 11 contiguous bytes. Also reserve the private workspace: T0, T1, T2, T3 (4 bytes). Array names in the explanation refer to the numbered consecutive bindings, such as C0, C1 and so on.
Call moving_solid_push_init once at the intended reset boundary. It clears inputs as well as outputs and workspace. Set your starting state and configuration afterwards, then call moving_solid_push_step whenever the described event occurs. The helper reads no device, waits for no frame and installs no interrupt handler.
| Ownership | Fields |
|---|---|
| Retain between calls | none |
| Supply before service | actor geometry, old/new solid geometry and bounds |
| Read after service | POSITION, PUSHED, BLOCKED and VALID |
Sweep the solid’s leading face across the actor. A rightward push places the actor at the new right face; a leftward push subtracts the actor size from the new left face. Validate the required destination before returning it.
Reusable initialisation and service
; SPDX-License-Identifier: MIT
; Push an Actor with a Moving Solid. See README.md for the byte interface and ownership.
; init clears the public fields and private workspace; set inputs afterwards.
moving_solid_push_init:
ld a,0
ld (POSITION),a
ld (PUSHED),a
ld (BLOCKED),a
ld (VALID),a
ld (ACTOR_POSITION),a
ld (ACTOR_SIZE),a
ld (SOLID_OLD),a
ld (SOLID_NEW),a
ld (SOLID_SIZE),a
ld (MINIMUM),a
ld (MAXIMUM),a
ld (T0),a
ld (T1),a
ld (T2),a
ld (T3),a
ret
moving_solid_push_step:
; POSITION = ACTOR_POSITION
ld a,(ACTOR_POSITION)
ld (POSITION),a
; PUSHED = 0
ld a,0
ld (PUSHED),a
; BLOCKED = 0
ld a,0
ld (BLOCKED),a
; VALID = 0
ld a,0
ld (VALID),a
; if ACTOR_SIZE == 0:
ld a,(ACTOR_SIZE)
cp 0
jp z,moving_solid_push_L1
jp moving_solid_push_L2
moving_solid_push_L1:
; return
ret
jp moving_solid_push_L3
moving_solid_push_L2:
moving_solid_push_L3:
; if SOLID_SIZE == 0:
ld a,(SOLID_SIZE)
cp 0
jp z,moving_solid_push_L4
jp moving_solid_push_L5
moving_solid_push_L4:
; return
ret
jp moving_solid_push_L6
moving_solid_push_L5:
moving_solid_push_L6:
; if MINIMUM > MAXIMUM:
ld a,(MINIMUM)
ld b,a
ld a,(MAXIMUM)
ld c,a
ld a,b
cp c
jp z,moving_solid_push_L8
jp nc,moving_solid_push_L7
jp moving_solid_push_L8
moving_solid_push_L7:
; return
ret
jp moving_solid_push_L9
moving_solid_push_L8:
moving_solid_push_L9:
; if ACTOR_POSITION < MINIMUM:
ld a,(ACTOR_POSITION)
ld b,a
ld a,(MINIMUM)
ld c,a
ld a,b
cp c
jp c,moving_solid_push_L10
jp moving_solid_push_L11
moving_solid_push_L10:
; return
ret
jp moving_solid_push_L12
moving_solid_push_L11:
moving_solid_push_L12:
; if ACTOR_POSITION > MAXIMUM:
ld a,(ACTOR_POSITION)
ld b,a
ld a,(MAXIMUM)
ld c,a
ld a,b
cp c
jp z,moving_solid_push_L14
jp nc,moving_solid_push_L13
jp moving_solid_push_L14
moving_solid_push_L13:
; return
ret
jp moving_solid_push_L15
moving_solid_push_L14:
moving_solid_push_L15:
; T0 = ACTOR_POSITION + ACTOR_SIZE
ld a,(ACTOR_POSITION)
ld b,a
ld a,(ACTOR_SIZE)
ld c,a
ld a,b
add a,c
ld (T0),a
; if T0 < ACTOR_POSITION:
ld a,(T0)
ld b,a
ld a,(ACTOR_POSITION)
ld c,a
ld a,b
cp c
jp c,moving_solid_push_L16
jp moving_solid_push_L17
moving_solid_push_L16:
; return
ret
jp moving_solid_push_L18
moving_solid_push_L17:
moving_solid_push_L18:
; T1 = SOLID_OLD + SOLID_SIZE
ld a,(SOLID_OLD)
ld b,a
ld a,(SOLID_SIZE)
ld c,a
ld a,b
add a,c
ld (T1),a
; if T1 < SOLID_OLD:
ld a,(T1)
ld b,a
ld a,(SOLID_OLD)
ld c,a
ld a,b
cp c
jp c,moving_solid_push_L19
jp moving_solid_push_L20
moving_solid_push_L19:
; return
ret
jp moving_solid_push_L21
moving_solid_push_L20:
moving_solid_push_L21:
; T2 = SOLID_NEW + SOLID_SIZE
ld a,(SOLID_NEW)
ld b,a
ld a,(SOLID_SIZE)
ld c,a
ld a,b
add a,c
ld (T2),a
; if T2 < SOLID_NEW:
ld a,(T2)
ld b,a
ld a,(SOLID_NEW)
ld c,a
ld a,b
cp c
jp c,moving_solid_push_L22
jp moving_solid_push_L23
moving_solid_push_L22:
; return
ret
jp moving_solid_push_L24
moving_solid_push_L23:
moving_solid_push_L24:
; if SOLID_OLD < T0:
ld a,(SOLID_OLD)
ld b,a
ld a,(T0)
ld c,a
ld a,b
cp c
jp c,moving_solid_push_L25
jp moving_solid_push_L26
moving_solid_push_L25:
; if T1 > ACTOR_POSITION:
ld a,(T1)
ld b,a
ld a,(ACTOR_POSITION)
ld c,a
ld a,b
cp c
jp z,moving_solid_push_L29
jp nc,moving_solid_push_L28
jp moving_solid_push_L29
moving_solid_push_L28:
; return
ret
jp moving_solid_push_L30
moving_solid_push_L29:
moving_solid_push_L30:
jp moving_solid_push_L27
moving_solid_push_L26:
moving_solid_push_L27:
; VALID = 1
ld a,1
ld (VALID),a
; if SOLID_NEW > SOLID_OLD:
ld a,(SOLID_NEW)
ld b,a
ld a,(SOLID_OLD)
ld c,a
ld a,b
cp c
jp z,moving_solid_push_L32
jp nc,moving_solid_push_L31
jp moving_solid_push_L32
moving_solid_push_L31:
; if T1 <= ACTOR_POSITION:
ld a,(T1)
ld b,a
ld a,(ACTOR_POSITION)
ld c,a
ld a,b
cp c
jp c,moving_solid_push_L34
jp z,moving_solid_push_L34
jp moving_solid_push_L35
moving_solid_push_L34:
; if T2 > ACTOR_POSITION:
ld a,(T2)
ld b,a
ld a,(ACTOR_POSITION)
ld c,a
ld a,b
cp c
jp z,moving_solid_push_L38
jp nc,moving_solid_push_L37
jp moving_solid_push_L38
moving_solid_push_L37:
; if T2 > MAXIMUM:
ld a,(T2)
ld b,a
ld a,(MAXIMUM)
ld c,a
ld a,b
cp c
jp z,moving_solid_push_L41
jp nc,moving_solid_push_L40
jp moving_solid_push_L41
moving_solid_push_L40:
; BLOCKED = 1
ld a,1
ld (BLOCKED),a
; return
ret
jp moving_solid_push_L42
moving_solid_push_L41:
moving_solid_push_L42:
; T3 = T2 + ACTOR_SIZE
ld a,(T2)
ld b,a
ld a,(ACTOR_SIZE)
ld c,a
ld a,b
add a,c
ld (T3),a
; if T3 < T2:
ld a,(T3)
ld b,a
ld a,(T2)
ld c,a
ld a,b
cp c
jp c,moving_solid_push_L43
jp moving_solid_push_L44
moving_solid_push_L43:
; BLOCKED = 1
ld a,1
ld (BLOCKED),a
; return
ret
jp moving_solid_push_L45
moving_solid_push_L44:
moving_solid_push_L45:
; POSITION = T2
ld a,(T2)
ld (POSITION),a
; PUSHED = 1
ld a,1
ld (PUSHED),a
jp moving_solid_push_L39
moving_solid_push_L38:
moving_solid_push_L39:
jp moving_solid_push_L36
moving_solid_push_L35:
moving_solid_push_L36:
jp moving_solid_push_L33
moving_solid_push_L32:
moving_solid_push_L33:
; if SOLID_NEW < SOLID_OLD:
ld a,(SOLID_NEW)
ld b,a
ld a,(SOLID_OLD)
ld c,a
ld a,b
cp c
jp c,moving_solid_push_L46
jp moving_solid_push_L47
moving_solid_push_L46:
; if SOLID_OLD >= T0:
ld a,(SOLID_OLD)
ld b,a
ld a,(T0)
ld c,a
ld a,b
cp c
jp nc,moving_solid_push_L49
jp moving_solid_push_L50
moving_solid_push_L49:
; if SOLID_NEW < T0:
ld a,(SOLID_NEW)
ld b,a
ld a,(T0)
ld c,a
ld a,b
cp c
jp c,moving_solid_push_L52
jp moving_solid_push_L53
moving_solid_push_L52:
; if SOLID_NEW < ACTOR_SIZE:
ld a,(SOLID_NEW)
ld b,a
ld a,(ACTOR_SIZE)
ld c,a
ld a,b
cp c
jp c,moving_solid_push_L55
jp moving_solid_push_L56
moving_solid_push_L55:
; BLOCKED = 1
ld a,1
ld (BLOCKED),a
; return
ret
jp moving_solid_push_L57
moving_solid_push_L56:
moving_solid_push_L57:
; T3 = SOLID_NEW - ACTOR_SIZE
ld a,(SOLID_NEW)
ld b,a
ld a,(ACTOR_SIZE)
ld c,a
ld a,b
sub c
ld (T3),a
; if T3 < MINIMUM:
ld a,(T3)
ld b,a
ld a,(MINIMUM)
ld c,a
ld a,b
cp c
jp c,moving_solid_push_L58
jp moving_solid_push_L59
moving_solid_push_L58:
; BLOCKED = 1
ld a,1
ld (BLOCKED),a
; return
ret
jp moving_solid_push_L60
moving_solid_push_L59:
moving_solid_push_L60:
; POSITION = T3
ld a,(T3)
ld (POSITION),a
; PUSHED = 1
ld a,1
ld (PUSHED),a
jp moving_solid_push_L54
moving_solid_push_L53:
moving_solid_push_L54:
jp moving_solid_push_L51
moving_solid_push_L50:
moving_solid_push_L51:
jp moving_solid_push_L48
moving_solid_push_L47:
moving_solid_push_L48:
ret
component_end:Machine contract
AF/BC/DE/HL may change; IX/IY are preserved. A direct CALL needs two return-address stack bytes. The helper makes no nested calls and adds no other stack use. Its named scratch is private workspace, not a pointer, a ROM variable or shared zero-page space that the game may borrow concurrently. The samples use fixed symbol bindings. Scope or rename every label and binding, including the component_end measurement marker, and allocate a separate block for each independent instance. Different helpers can also use common field names, so combining them needs separate namespaces or explicitly renamed bindings. Give each block one mutation owner.
The 48K diagnostic boots through ROM tape loading and USR, disables interrupts and owns the screen. The helper performs no port or screen writes.
Adapt the caller
demo.asm supplies the bindings and include order. exercise.inc first runs table cases, then a separate client retaining state between calls. A game can call the public step entry directly and remove the diagnostic packet and display. Do not copy the diagnostic’s hardware takeover into an existing game loop.
Build with make ASM198X=/path/to/asm198x. The Makefile produces normal, custom, deliberately wrong and repaired programs. Tools must already be installed; the sample downloads nothing.
Bindings 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:
POSITION: defb 0
PUSHED: defb 0
BLOCKED: defb 0
VALID: defb 0
ACTOR_POSITION: defb 0
ACTOR_SIZE: defb 0
SOLID_OLD: defb 0
SOLID_NEW: defb 0
SOLID_SIZE: defb 0
MINIMUM: defb 0
MAXIMUM: defb 0
T0: defb 0
T1: defb 0
T2: defb 0
T3: 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 client retaining state between calls
preview_rules:
if CUSTOM
; ACTOR_POSITION = 5
ld a,5
ld (ACTOR_POSITION),a
; ACTOR_SIZE = 2
ld a,2
ld (ACTOR_SIZE),a
; SOLID_OLD = 10
ld a,10
ld (SOLID_OLD),a
; SOLID_NEW = 0
ld a,0
ld (SOLID_NEW),a
; SOLID_SIZE = 2
ld a,2
ld (SOLID_SIZE),a
; MINIMUM = 0
ld a,0
ld (MINIMUM),a
; MAXIMUM = 30
ld a,30
ld (MAXIMUM),a
if BROKEN
; SOLID_OLD = SOLID_NEW
ld a,(SOLID_NEW)
ld (SOLID_OLD),a
endif
call checked_step
call emit_state
ret
else
; ACTOR_POSITION = 10
ld a,10
ld (ACTOR_POSITION),a
; ACTOR_SIZE = 2
ld a,2
ld (ACTOR_SIZE),a
; SOLID_OLD = 0
ld a,0
ld (SOLID_OLD),a
; SOLID_NEW = 12
ld a,12
ld (SOLID_NEW),a
; SOLID_SIZE = 2
ld a,2
ld (SOLID_SIZE),a
; MINIMUM = 0
ld a,0
ld (MINIMUM),a
; MAXIMUM = 30
ld a,30
ld (MAXIMUM),a
if BROKEN
; SOLID_OLD = SOLID_NEW
ld a,(SOLID_NEW)
ld (SOLID_OLD),a
endif
call checked_step
call emit_state
endif
retCustomise it
Try a leftward push whose required destination would be negative, and handle BLOCKED. The maintained custom caller changes its inputs or client sequence rather than hiding a different implementation behind the same label. Compare every state of the two clients, not only their final display.
Custom client selection
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:
POSITION: defb 0
PUSHED: defb 0
BLOCKED: defb 0
VALID: defb 0
ACTOR_POSITION: defb 0
ACTOR_SIZE: defb 0
SOLID_OLD: defb 0
SOLID_NEW: defb 0
SOLID_SIZE: defb 0
MINIMUM: defb 0
MAXIMUM: defb 0
T0: defb 0
T1: defb 0
T2: defb 0
T3: 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 diagnostic row is 05 00 01 01 05 02 0A 00. The full client trace in the source explains how it gets there.
Mistake and repair
The wrong caller replaces the old solid position with the new one before the sweep. In this example, the actor occupies [10,12) and the solid occupies [12,14): they only touch. With old and new positions both 12, the helper sees no movement and returns POSITION=10, PUSHED=0, BLOCKED=0 and VALID=1. Keep previous/current positions distinct so the sweep can produce the required push.
The BROKEN branch lives in the sequential client, not the reusable helper. wrong.asm selects it; repaired.asm restores the normal call sequence. The repaired executable matches the normal program (for Spectrum, compare loaded CODE rather than the tape filename).
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:
POSITION: defb 0
PUSHED: defb 0
BLOCKED: defb 0
VALID: defb 0
ACTOR_POSITION: defb 0
ACTOR_SIZE: defb 0
SOLID_OLD: defb 0
SOLID_NEW: defb 0
SOLID_SIZE: defb 0
MINIMUM: defb 0
MAXIMUM: defb 0
T0: defb 0
T1: defb 0
T2: defb 0
T3: 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
Cost and alternatives
The measured helper extent is 586 code bytes; public state is 11 bytes and private scratch is 4 bytes. There are no immutable helper tables. Caller data, the test cases, return-address stack, alignment and display buffers cost additional space. These are assembled sizes, not cycle measurements.
Constant work for one pair. Multiple actors need a validation/commit policy or rollback; resolving only the last frame’s overlap can miss a fast moving solid.
This handles one actor and one axis, without initial penetration. A real moving-solid transaction must inspect all affected actors and other obstacles before committing the solid’s movement. BLOCKED asks the caller to choose stop, crush or another explicit rule; it does not authorise leaving overlapping objects.
Execution evidence
Four variants run on 48K PAL ROM tape load and USR, using Asm198x 0.0.72, Emu198x 0.44.2. Each executes 64 boundary/varied/error table cases, dirty initialisation and the separate retained-state client. An independent mathematical/container model checks every public byte after every call. This is bounded example coverage, not exhaustive correctness for every possible state.
The records retain loaded immutable code, completion, register sentinels, full packets, source/tool/firmware hashes and captures. The public gate validates these retained observations and rejects altered evidence; it does not run restricted firmware. No firmware is distributed. The eight displayed bytes are the first eight public fields, zero-padded when shorter; the packet includes every field.
Where it fits
Swept axis collision: A moving actor against a static wall and a moving wall against an actor need different response ownership.