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:
lda #0
sta POSITION
sta PUSHED
sta BLOCKED
sta VALID
sta ACTOR_POSITION
sta ACTOR_SIZE
sta SOLID_OLD
sta SOLID_NEW
sta SOLID_SIZE
sta MINIMUM
sta MAXIMUM
sta T0
sta T1
sta T2
sta T3
rts
moving_solid_push_step:
; POSITION = ACTOR_POSITION
lda ACTOR_POSITION
sta POSITION
; PUSHED = 0
lda #0
sta PUSHED
; BLOCKED = 0
lda #0
sta BLOCKED
; VALID = 0
lda #0
sta VALID
; if ACTOR_SIZE == 0:
lda ACTOR_SIZE
cmp #0
beq moving_solid_push_L4
moving_solid_push_L5:
jmp moving_solid_push_L2
moving_solid_push_L4:
jmp moving_solid_push_L1
moving_solid_push_L1:
; return
rts
jmp moving_solid_push_L3
moving_solid_push_L2:
moving_solid_push_L3:
; if SOLID_SIZE == 0:
lda SOLID_SIZE
cmp #0
beq moving_solid_push_L9
moving_solid_push_L10:
jmp moving_solid_push_L7
moving_solid_push_L9:
jmp moving_solid_push_L6
moving_solid_push_L6:
; return
rts
jmp moving_solid_push_L8
moving_solid_push_L7:
moving_solid_push_L8:
; if MINIMUM > MAXIMUM:
lda MINIMUM
cmp MAXIMUM
beq moving_solid_push_L15
bcs moving_solid_push_L14
moving_solid_push_L15:
jmp moving_solid_push_L12
moving_solid_push_L14:
jmp moving_solid_push_L11
moving_solid_push_L11:
; return
rts
jmp moving_solid_push_L13
moving_solid_push_L12:
moving_solid_push_L13:
; if ACTOR_POSITION < MINIMUM:
lda ACTOR_POSITION
cmp MINIMUM
bcc moving_solid_push_L19
moving_solid_push_L20:
jmp moving_solid_push_L17
moving_solid_push_L19:
jmp moving_solid_push_L16
moving_solid_push_L16:
; return
rts
jmp moving_solid_push_L18
moving_solid_push_L17:
moving_solid_push_L18:
; if ACTOR_POSITION > MAXIMUM:
lda ACTOR_POSITION
cmp MAXIMUM
beq moving_solid_push_L25
bcs moving_solid_push_L24
moving_solid_push_L25:
jmp moving_solid_push_L22
moving_solid_push_L24:
jmp moving_solid_push_L21
moving_solid_push_L21:
; return
rts
jmp moving_solid_push_L23
moving_solid_push_L22:
moving_solid_push_L23:
; T0 = ACTOR_POSITION + ACTOR_SIZE
lda ACTOR_POSITION
clc
adc ACTOR_SIZE
sta T0
; if T0 < ACTOR_POSITION:
lda T0
cmp ACTOR_POSITION
bcc moving_solid_push_L29
moving_solid_push_L30:
jmp moving_solid_push_L27
moving_solid_push_L29:
jmp moving_solid_push_L26
moving_solid_push_L26:
; return
rts
jmp moving_solid_push_L28
moving_solid_push_L27:
moving_solid_push_L28:
; T1 = SOLID_OLD + SOLID_SIZE
lda SOLID_OLD
clc
adc SOLID_SIZE
sta T1
; if T1 < SOLID_OLD:
lda T1
cmp SOLID_OLD
bcc moving_solid_push_L34
moving_solid_push_L35:
jmp moving_solid_push_L32
moving_solid_push_L34:
jmp moving_solid_push_L31
moving_solid_push_L31:
; return
rts
jmp moving_solid_push_L33
moving_solid_push_L32:
moving_solid_push_L33:
; T2 = SOLID_NEW + SOLID_SIZE
lda SOLID_NEW
clc
adc SOLID_SIZE
sta T2
; if T2 < SOLID_NEW:
lda T2
cmp SOLID_NEW
bcc moving_solid_push_L39
moving_solid_push_L40:
jmp moving_solid_push_L37
moving_solid_push_L39:
jmp moving_solid_push_L36
moving_solid_push_L36:
; return
rts
jmp moving_solid_push_L38
moving_solid_push_L37:
moving_solid_push_L38:
; if SOLID_OLD < T0:
lda SOLID_OLD
cmp T0
bcc moving_solid_push_L44
moving_solid_push_L45:
jmp moving_solid_push_L42
moving_solid_push_L44:
jmp moving_solid_push_L41
moving_solid_push_L41:
; if T1 > ACTOR_POSITION:
lda T1
cmp ACTOR_POSITION
beq moving_solid_push_L50
bcs moving_solid_push_L49
moving_solid_push_L50:
jmp moving_solid_push_L47
moving_solid_push_L49:
jmp moving_solid_push_L46
moving_solid_push_L46:
; return
rts
jmp moving_solid_push_L48
moving_solid_push_L47:
moving_solid_push_L48:
jmp moving_solid_push_L43
moving_solid_push_L42:
moving_solid_push_L43:
; VALID = 1
lda #1
sta VALID
; if SOLID_NEW > SOLID_OLD:
lda SOLID_NEW
cmp SOLID_OLD
beq moving_solid_push_L55
bcs moving_solid_push_L54
moving_solid_push_L55:
jmp moving_solid_push_L52
moving_solid_push_L54:
jmp moving_solid_push_L51
moving_solid_push_L51:
; if T1 <= ACTOR_POSITION:
lda T1
cmp ACTOR_POSITION
bcc moving_solid_push_L59
beq moving_solid_push_L59
moving_solid_push_L60:
jmp moving_solid_push_L57
moving_solid_push_L59:
jmp moving_solid_push_L56
moving_solid_push_L56:
; if T2 > ACTOR_POSITION:
lda T2
cmp ACTOR_POSITION
beq moving_solid_push_L65
bcs moving_solid_push_L64
moving_solid_push_L65:
jmp moving_solid_push_L62
moving_solid_push_L64:
jmp moving_solid_push_L61
moving_solid_push_L61:
; if T2 > MAXIMUM:
lda T2
cmp MAXIMUM
beq moving_solid_push_L70
bcs moving_solid_push_L69
moving_solid_push_L70:
jmp moving_solid_push_L67
moving_solid_push_L69:
jmp moving_solid_push_L66
moving_solid_push_L66:
; BLOCKED = 1
lda #1
sta BLOCKED
; return
rts
jmp moving_solid_push_L68
moving_solid_push_L67:
moving_solid_push_L68:
; T3 = T2 + ACTOR_SIZE
lda T2
clc
adc ACTOR_SIZE
sta T3
; if T3 < T2:
lda T3
cmp T2
bcc moving_solid_push_L74
moving_solid_push_L75:
jmp moving_solid_push_L72
moving_solid_push_L74:
jmp moving_solid_push_L71
moving_solid_push_L71:
; BLOCKED = 1
lda #1
sta BLOCKED
; return
rts
jmp moving_solid_push_L73
moving_solid_push_L72:
moving_solid_push_L73:
; POSITION = T2
lda T2
sta POSITION
; PUSHED = 1
lda #1
sta PUSHED
jmp moving_solid_push_L63
moving_solid_push_L62:
moving_solid_push_L63:
jmp moving_solid_push_L58
moving_solid_push_L57:
moving_solid_push_L58:
jmp moving_solid_push_L53
moving_solid_push_L52:
moving_solid_push_L53:
; if SOLID_NEW < SOLID_OLD:
lda SOLID_NEW
cmp SOLID_OLD
bcc moving_solid_push_L79
moving_solid_push_L80:
jmp moving_solid_push_L77
moving_solid_push_L79:
jmp moving_solid_push_L76
moving_solid_push_L76:
; if SOLID_OLD >= T0:
lda SOLID_OLD
cmp T0
bcs moving_solid_push_L84
moving_solid_push_L85:
jmp moving_solid_push_L82
moving_solid_push_L84:
jmp moving_solid_push_L81
moving_solid_push_L81:
; if SOLID_NEW < T0:
lda SOLID_NEW
cmp T0
bcc moving_solid_push_L89
moving_solid_push_L90:
jmp moving_solid_push_L87
moving_solid_push_L89:
jmp moving_solid_push_L86
moving_solid_push_L86:
; if SOLID_NEW < ACTOR_SIZE:
lda SOLID_NEW
cmp ACTOR_SIZE
bcc moving_solid_push_L94
moving_solid_push_L95:
jmp moving_solid_push_L92
moving_solid_push_L94:
jmp moving_solid_push_L91
moving_solid_push_L91:
; BLOCKED = 1
lda #1
sta BLOCKED
; return
rts
jmp moving_solid_push_L93
moving_solid_push_L92:
moving_solid_push_L93:
; T3 = SOLID_NEW - ACTOR_SIZE
lda SOLID_NEW
sec
sbc ACTOR_SIZE
sta T3
; if T3 < MINIMUM:
lda T3
cmp MINIMUM
bcc moving_solid_push_L99
moving_solid_push_L100:
jmp moving_solid_push_L97
moving_solid_push_L99:
jmp moving_solid_push_L96
moving_solid_push_L96:
; BLOCKED = 1
lda #1
sta BLOCKED
; return
rts
jmp moving_solid_push_L98
moving_solid_push_L97:
moving_solid_push_L98:
; POSITION = T3
lda T3
sta POSITION
; PUSHED = 1
lda #1
sta PUSHED
jmp moving_solid_push_L88
moving_solid_push_L87:
moving_solid_push_L88:
jmp moving_solid_push_L83
moving_solid_push_L82:
moving_solid_push_L83:
jmp moving_solid_push_L78
moving_solid_push_L77:
moving_solid_push_L78:
rts
component_end:Machine contract
A/X/status may change; Y and decimal mode are preserved. Use CLD for binary arithmetic. A direct JSR 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 diagnostic PRG owns screen, font and colour RAM and disables interrupts; it does not return to BASIC. The reusable helper does none of those things.
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
POSITION=$80
PUSHED=$81
BLOCKED=$82
VALID=$83
ACTOR_POSITION=$84
ACTOR_SIZE=$85
SOLID_OLD=$86
SOLID_NEW=$87
SOLID_SIZE=$88
MINIMUM=$89
MAXIMUM=$8a
T0=$8b
T1=$8c
T2=$8d
T3=$8e
STATE=$80
input_ptr=$70
cases_left=$72
ptr=$74
saved_y=$76
OUTPUT=$c000
preview=OUTPUT+1400
ready=OUTPUT+1408
CUSTOM=0
BROKEN=0
COYOTE_STEPS=4
BUFFER_STEPS=4
TEXT_CAP=8
PROPERTY_COUNT=16
STREAM_BYTES=13
CRC_POLY=7
!source "caller.inc"
!source "exercise.inc"
component_start:
!source "component.inc"
!source "data.inc"
!source "cases.inc"
hex_font:
!byte 0,0,0,0,0,0,0,0,0,56,40,40,40,56,0,0,0,16,48,16,16,56,0,0,0,56,8,56,32,56,0,0,0,56,8,56,8,56,0,0,0,40,40,56,8,8,0,0,0,56,32,56,8,56,0,0,0,56,32,56,40,56,0,0,0,56,8,8,8,8,0,0,0,56,40,56,40,56,0,0,0,56,40,56,8,56,0,0,0,16,40,56,40,40,0,0,0,48,40,48,40,48,0,0,0,56,32,32,32,56,0,0,0,48,40,40,40,48,0,0,0,56,32,48,32,56,0,0,0,56,32,48,32,32,0,0
code_end:A client retaining state between calls
preview_rules:
!if CUSTOM {
; ACTOR_POSITION = 5
lda #5
sta ACTOR_POSITION
; ACTOR_SIZE = 2
lda #2
sta ACTOR_SIZE
; SOLID_OLD = 10
lda #10
sta SOLID_OLD
; SOLID_NEW = 0
lda #0
sta SOLID_NEW
; SOLID_SIZE = 2
lda #2
sta SOLID_SIZE
; MINIMUM = 0
lda #0
sta MINIMUM
; MAXIMUM = 30
lda #30
sta MAXIMUM
!if BROKEN {
; SOLID_OLD = SOLID_NEW
lda SOLID_NEW
sta SOLID_OLD
}
jsr checked_step
jsr emit_state
rts
} else {
; ACTOR_POSITION = 10
lda #10
sta ACTOR_POSITION
; ACTOR_SIZE = 2
lda #2
sta ACTOR_SIZE
; SOLID_OLD = 0
lda #0
sta SOLID_OLD
; SOLID_NEW = 12
lda #12
sta SOLID_NEW
; SOLID_SIZE = 2
lda #2
sta SOLID_SIZE
; MINIMUM = 0
lda #0
sta MINIMUM
; MAXIMUM = 30
lda #30
sta MAXIMUM
!if BROKEN {
; SOLID_OLD = SOLID_NEW
lda SOLID_NEW
sta SOLID_OLD
}
jsr checked_step
jsr emit_state
}
rtsCustomise 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
POSITION=$80
PUSHED=$81
BLOCKED=$82
VALID=$83
ACTOR_POSITION=$84
ACTOR_SIZE=$85
SOLID_OLD=$86
SOLID_NEW=$87
SOLID_SIZE=$88
MINIMUM=$89
MAXIMUM=$8a
T0=$8b
T1=$8c
T2=$8d
T3=$8e
STATE=$80
input_ptr=$70
cases_left=$72
ptr=$74
saved_y=$76
OUTPUT=$c000
preview=OUTPUT+1400
ready=OUTPUT+1408
CUSTOM=1
BROKEN=0
COYOTE_STEPS=2
BUFFER_STEPS=2
TEXT_CAP=4
PROPERTY_COUNT=16
STREAM_BYTES=13
CRC_POLY=49
!source "caller.inc"
!source "exercise.inc"
component_start:
!source "component.inc"
!source "data.inc"
!source "cases.inc"
hex_font:
!byte 0,0,0,0,0,0,0,0,0,56,40,40,40,56,0,0,0,16,48,16,16,56,0,0,0,56,8,56,32,56,0,0,0,56,8,56,8,56,0,0,0,40,40,56,8,8,0,0,0,56,32,56,8,56,0,0,0,56,32,56,40,56,0,0,0,56,8,8,8,8,0,0,0,56,40,56,40,56,0,0,0,56,40,56,8,56,0,0,0,16,40,56,40,40,0,0,0,48,40,48,40,48,0,0,0,56,32,32,32,56,0,0,0,48,40,40,40,48,0,0,0,56,32,48,32,56,0,0,0,56,32,48,32,32,0,0
code_end:The 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
POSITION=$80
PUSHED=$81
BLOCKED=$82
VALID=$83
ACTOR_POSITION=$84
ACTOR_SIZE=$85
SOLID_OLD=$86
SOLID_NEW=$87
SOLID_SIZE=$88
MINIMUM=$89
MAXIMUM=$8a
T0=$8b
T1=$8c
T2=$8d
T3=$8e
STATE=$80
input_ptr=$70
cases_left=$72
ptr=$74
saved_y=$76
OUTPUT=$c000
preview=OUTPUT+1400
ready=OUTPUT+1408
CUSTOM=0
BROKEN=1
COYOTE_STEPS=4
BUFFER_STEPS=4
TEXT_CAP=8
PROPERTY_COUNT=16
STREAM_BYTES=13
CRC_POLY=7
!source "caller.inc"
!source "exercise.inc"
component_start:
!source "component.inc"
!source "data.inc"
!source "cases.inc"
hex_font:
!byte 0,0,0,0,0,0,0,0,0,56,40,40,40,56,0,0,0,16,48,16,16,56,0,0,0,56,8,56,32,56,0,0,0,56,8,56,8,56,0,0,0,40,40,56,8,8,0,0,0,56,32,56,8,56,0,0,0,56,32,56,40,56,0,0,0,56,8,8,8,8,0,0,0,56,40,56,40,56,0,0,0,56,40,56,8,56,0,0,0,16,40,56,40,40,0,0,0,48,40,48,40,48,0,0,0,56,32,32,32,56,0,0,0,48,40,40,40,48,0,0,0,56,32,48,32,56,0,0,0,56,32,48,32,32,0,0
code_end:
Cost and alternatives
The measured helper extent is 448 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 PAL stock-ROM PRG, 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.