Skip to content

Push an Actor with a Moving Solid on Amiga

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

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

Amiga shows the working diagnostic row 0E 01 00 01 0A 02 00 0C.
A completed native caller displays 0E 01 00 01 0A 02 00 0C. The public field order below identifies these bytes; the capture is a state diagnostic, not a recording of a finished game.

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

component.inc
; 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:
    move.b #0,d0
    move.b d0,POSITION
    move.b d0,PUSHED
    move.b d0,BLOCKED
    move.b d0,VALID
    move.b d0,ACTOR_POSITION
    move.b d0,ACTOR_SIZE
    move.b d0,SOLID_OLD
    move.b d0,SOLID_NEW
    move.b d0,SOLID_SIZE
    move.b d0,MINIMUM
    move.b d0,MAXIMUM
    move.b d0,T0
    move.b d0,T1
    move.b d0,T2
    move.b d0,T3
    rts
moving_solid_push_step:
; POSITION = ACTOR_POSITION
    move.b ACTOR_POSITION,d0
    move.b d0,POSITION
; PUSHED = 0
    move.b #0,d0
    move.b d0,PUSHED
; BLOCKED = 0
    move.b #0,d0
    move.b d0,BLOCKED
; VALID = 0
    move.b #0,d0
    move.b d0,VALID
; if ACTOR_SIZE == 0:
    move.b ACTOR_SIZE,d0
    cmp.b #0,d0
    beq moving_solid_push_L1
    jmp moving_solid_push_L2
moving_solid_push_L1:
; return
    rts
    jmp moving_solid_push_L3
moving_solid_push_L2:
moving_solid_push_L3:
; if SOLID_SIZE == 0:
    move.b SOLID_SIZE,d0
    cmp.b #0,d0
    beq moving_solid_push_L4
    jmp moving_solid_push_L5
moving_solid_push_L4:
; return
    rts
    jmp moving_solid_push_L6
moving_solid_push_L5:
moving_solid_push_L6:
; if MINIMUM > MAXIMUM:
    move.b MINIMUM,d0
    move.b MAXIMUM,d1
    cmp.b d1,d0
    bhi moving_solid_push_L7
    jmp moving_solid_push_L8
moving_solid_push_L7:
; return
    rts
    jmp moving_solid_push_L9
moving_solid_push_L8:
moving_solid_push_L9:
; if ACTOR_POSITION < MINIMUM:
    move.b ACTOR_POSITION,d0
    move.b MINIMUM,d1
    cmp.b d1,d0
    bcs moving_solid_push_L10
    jmp moving_solid_push_L11
moving_solid_push_L10:
; return
    rts
    jmp moving_solid_push_L12
moving_solid_push_L11:
moving_solid_push_L12:
; if ACTOR_POSITION > MAXIMUM:
    move.b ACTOR_POSITION,d0
    move.b MAXIMUM,d1
    cmp.b d1,d0
    bhi moving_solid_push_L13
    jmp moving_solid_push_L14
moving_solid_push_L13:
; return
    rts
    jmp moving_solid_push_L15
moving_solid_push_L14:
moving_solid_push_L15:
; T0 = ACTOR_POSITION + ACTOR_SIZE
    move.b ACTOR_POSITION,d0
    move.b ACTOR_SIZE,d1
    add.b d1,d0
    move.b d0,T0
; if T0 < ACTOR_POSITION:
    move.b T0,d0
    move.b ACTOR_POSITION,d1
    cmp.b d1,d0
    bcs moving_solid_push_L16
    jmp moving_solid_push_L17
moving_solid_push_L16:
; return
    rts
    jmp moving_solid_push_L18
moving_solid_push_L17:
moving_solid_push_L18:
; T1 = SOLID_OLD + SOLID_SIZE
    move.b SOLID_OLD,d0
    move.b SOLID_SIZE,d1
    add.b d1,d0
    move.b d0,T1
; if T1 < SOLID_OLD:
    move.b T1,d0
    move.b SOLID_OLD,d1
    cmp.b d1,d0
    bcs moving_solid_push_L19
    jmp moving_solid_push_L20
moving_solid_push_L19:
; return
    rts
    jmp moving_solid_push_L21
moving_solid_push_L20:
moving_solid_push_L21:
; T2 = SOLID_NEW + SOLID_SIZE
    move.b SOLID_NEW,d0
    move.b SOLID_SIZE,d1
    add.b d1,d0
    move.b d0,T2
; if T2 < SOLID_NEW:
    move.b T2,d0
    move.b SOLID_NEW,d1
    cmp.b d1,d0
    bcs moving_solid_push_L22
    jmp moving_solid_push_L23
moving_solid_push_L22:
; return
    rts
    jmp moving_solid_push_L24
moving_solid_push_L23:
moving_solid_push_L24:
; if SOLID_OLD < T0:
    move.b SOLID_OLD,d0
    move.b T0,d1
    cmp.b d1,d0
    bcs moving_solid_push_L25
    jmp moving_solid_push_L26
moving_solid_push_L25:
; if T1 > ACTOR_POSITION:
    move.b T1,d0
    move.b ACTOR_POSITION,d1
    cmp.b d1,d0
    bhi moving_solid_push_L28
    jmp moving_solid_push_L29
moving_solid_push_L28:
; return
    rts
    jmp moving_solid_push_L30
moving_solid_push_L29:
moving_solid_push_L30:
    jmp moving_solid_push_L27
moving_solid_push_L26:
moving_solid_push_L27:
; VALID = 1
    move.b #1,d0
    move.b d0,VALID
; if SOLID_NEW > SOLID_OLD:
    move.b SOLID_NEW,d0
    move.b SOLID_OLD,d1
    cmp.b d1,d0
    bhi moving_solid_push_L31
    jmp moving_solid_push_L32
moving_solid_push_L31:
; if T1 <= ACTOR_POSITION:
    move.b T1,d0
    move.b ACTOR_POSITION,d1
    cmp.b d1,d0
    bls moving_solid_push_L34
    jmp moving_solid_push_L35
moving_solid_push_L34:
; if T2 > ACTOR_POSITION:
    move.b T2,d0
    move.b ACTOR_POSITION,d1
    cmp.b d1,d0
    bhi moving_solid_push_L37
    jmp moving_solid_push_L38
moving_solid_push_L37:
; if T2 > MAXIMUM:
    move.b T2,d0
    move.b MAXIMUM,d1
    cmp.b d1,d0
    bhi moving_solid_push_L40
    jmp moving_solid_push_L41
moving_solid_push_L40:
; BLOCKED = 1
    move.b #1,d0
    move.b d0,BLOCKED
; return
    rts
    jmp moving_solid_push_L42
moving_solid_push_L41:
moving_solid_push_L42:
; T3 = T2 + ACTOR_SIZE
    move.b T2,d0
    move.b ACTOR_SIZE,d1
    add.b d1,d0
    move.b d0,T3
; if T3 < T2:
    move.b T3,d0
    move.b T2,d1
    cmp.b d1,d0
    bcs moving_solid_push_L43
    jmp moving_solid_push_L44
moving_solid_push_L43:
; BLOCKED = 1
    move.b #1,d0
    move.b d0,BLOCKED
; return
    rts
    jmp moving_solid_push_L45
moving_solid_push_L44:
moving_solid_push_L45:
; POSITION = T2
    move.b T2,d0
    move.b d0,POSITION
; PUSHED = 1
    move.b #1,d0
    move.b d0,PUSHED
    jmp moving_solid_push_L39
moving_solid_push_L38:
moving_solid_push_L39:
    jmp moving_solid_push_L36
moving_solid_push_L35:
moving_solid_push_L36:
    jmp moving_solid_push_L33
moving_solid_push_L32:
moving_solid_push_L33:
; if SOLID_NEW < SOLID_OLD:
    move.b SOLID_NEW,d0
    move.b SOLID_OLD,d1
    cmp.b d1,d0
    bcs moving_solid_push_L46
    jmp moving_solid_push_L47
moving_solid_push_L46:
; if SOLID_OLD >= T0:
    move.b SOLID_OLD,d0
    move.b T0,d1
    cmp.b d1,d0
    bcc moving_solid_push_L49
    jmp moving_solid_push_L50
moving_solid_push_L49:
; if SOLID_NEW < T0:
    move.b SOLID_NEW,d0
    move.b T0,d1
    cmp.b d1,d0
    bcs moving_solid_push_L52
    jmp moving_solid_push_L53
moving_solid_push_L52:
; if SOLID_NEW < ACTOR_SIZE:
    move.b SOLID_NEW,d0
    move.b ACTOR_SIZE,d1
    cmp.b d1,d0
    bcs moving_solid_push_L55
    jmp moving_solid_push_L56
moving_solid_push_L55:
; BLOCKED = 1
    move.b #1,d0
    move.b d0,BLOCKED
; return
    rts
    jmp moving_solid_push_L57
moving_solid_push_L56:
moving_solid_push_L57:
; T3 = SOLID_NEW - ACTOR_SIZE
    move.b SOLID_NEW,d0
    move.b ACTOR_SIZE,d1
    sub.b d1,d0
    move.b d0,T3
; if T3 < MINIMUM:
    move.b T3,d0
    move.b MINIMUM,d1
    cmp.b d1,d0
    bcs moving_solid_push_L58
    jmp moving_solid_push_L59
moving_solid_push_L58:
; BLOCKED = 1
    move.b #1,d0
    move.b d0,BLOCKED
; return
    rts
    jmp moving_solid_push_L60
moving_solid_push_L59:
moving_solid_push_L60:
; POSITION = T3
    move.b T3,d0
    move.b d0,POSITION
; PUSHED = 1
    move.b #1,d0
    move.b d0,PUSHED
    jmp moving_solid_push_L54
moving_solid_push_L53:
moving_solid_push_L54:
    jmp moving_solid_push_L51
moving_solid_push_L50:
moving_solid_push_L51:
    jmp moving_solid_push_L48
moving_solid_push_L47:
moving_solid_push_L48:
    rts
component_end:

Machine contract

D0–D3/A0–A1/CCR may change; D4–D7/A2–A6 are preserved. A direct BSR/JSR needs four 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 A500 OCS diagnostic cold-boots an OFS disk, owns the Copper and bitplane and disables interrupt/DMA sources. The helper does not take over hardware or allocate Chip RAM.

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 and BUILD198X=/path/to/build198x. The Makefile produces normal, custom, deliberately wrong and repaired programs. Tools must already be installed; the sample downloads nothing.

Bindings and include order

demo.asm
    section code,code_c
CUSTOM = 0
BROKEN = 0
COYOTE_STEPS = 4
BUFFER_STEPS = 4
TEXT_CAP = 8
PROPERTY_COUNT = 16
STREAM_BYTES = 13
CRC_POLY = 7
    include "caller.inc"
    include "exercise.inc"
component_start:
    include "component.inc"
    even
    include "data.inc"
    include "cases.inc"
    even
    include "display.inc"
    include "../../framework/turn-deadline/font.inc"
code_end:
STATE:
POSITION: dc.b 0
PUSHED: dc.b 0
BLOCKED: dc.b 0
VALID: dc.b 0
ACTOR_POSITION: dc.b 0
ACTOR_SIZE: dc.b 0
SOLID_OLD: dc.b 0
SOLID_NEW: dc.b 0
SOLID_SIZE: dc.b 0
MINIMUM: dc.b 0
MAXIMUM: dc.b 0
T0: dc.b 0
T1: dc.b 0
T2: dc.b 0
T3: dc.b 0
    even
ready: dc.w 0
preview: dcb.b 8,0
OUTPUT: dcb.b 1300,0
    even
signature: dc.b "198XNIGHTONE000",0
    even
copperlist:
    dc.w $08e,$2c81,$090,$2cc1,$092,$0038,$094,$00d0
    dc.w $100,$1200,$102,0,$104,0,$108,0,$10a,0
    dc.w $180,$012,$182,$fff
copbpl:
    dc.w $0e0,0,$0e2,0
    dc.w $ffff,$fffe
plane: dcb.b 10240,0

A client retaining state between calls

exercise.inc, excerpt
preview_rules:
    ifne CUSTOM
; ACTOR_POSITION = 5
    move.b #5,d0
    move.b d0,ACTOR_POSITION
; ACTOR_SIZE = 2
    move.b #2,d0
    move.b d0,ACTOR_SIZE
; SOLID_OLD = 10
    move.b #10,d0
    move.b d0,SOLID_OLD
; SOLID_NEW = 0
    move.b #0,d0
    move.b d0,SOLID_NEW
; SOLID_SIZE = 2
    move.b #2,d0
    move.b d0,SOLID_SIZE
; MINIMUM = 0
    move.b #0,d0
    move.b d0,MINIMUM
; MAXIMUM = 30
    move.b #30,d0
    move.b d0,MAXIMUM
    ifne BROKEN
; SOLID_OLD = SOLID_NEW
    move.b SOLID_NEW,d0
    move.b d0,SOLID_OLD
    endif
    bsr checked_step
    bsr emit_state
    rts
    else
; ACTOR_POSITION = 10
    move.b #10,d0
    move.b d0,ACTOR_POSITION
; ACTOR_SIZE = 2
    move.b #2,d0
    move.b d0,ACTOR_SIZE
; SOLID_OLD = 0
    move.b #0,d0
    move.b d0,SOLID_OLD
; SOLID_NEW = 12
    move.b #12,d0
    move.b d0,SOLID_NEW
; SOLID_SIZE = 2
    move.b #2,d0
    move.b d0,SOLID_SIZE
; MINIMUM = 0
    move.b #0,d0
    move.b d0,MINIMUM
; MAXIMUM = 30
    move.b #30,d0
    move.b d0,MAXIMUM
    ifne BROKEN
; SOLID_OLD = SOLID_NEW
    move.b SOLID_NEW,d0
    move.b d0,SOLID_OLD
    endif
    bsr checked_step
    bsr emit_state
    endif
    rts

Customise 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

custom.asm
    section code,code_c
CUSTOM = 1
BROKEN = 0
COYOTE_STEPS = 2
BUFFER_STEPS = 2
TEXT_CAP = 4
PROPERTY_COUNT = 16
STREAM_BYTES = 13
CRC_POLY = 49
    include "caller.inc"
    include "exercise.inc"
component_start:
    include "component.inc"
    even
    include "data.inc"
    include "cases.inc"
    even
    include "display.inc"
    include "../../framework/turn-deadline/font.inc"
code_end:
STATE:
POSITION: dc.b 0
PUSHED: dc.b 0
BLOCKED: dc.b 0
VALID: dc.b 0
ACTOR_POSITION: dc.b 0
ACTOR_SIZE: dc.b 0
SOLID_OLD: dc.b 0
SOLID_NEW: dc.b 0
SOLID_SIZE: dc.b 0
MINIMUM: dc.b 0
MAXIMUM: dc.b 0
T0: dc.b 0
T1: dc.b 0
T2: dc.b 0
T3: dc.b 0
    even
ready: dc.w 0
preview: dcb.b 8,0
OUTPUT: dcb.b 1300,0
    even
signature: dc.b "198XNIGHTONE000",0
    even
copperlist:
    dc.w $08e,$2c81,$090,$2cc1,$092,$0038,$094,$00d0
    dc.w $100,$1200,$102,0,$104,0,$108,0,$10a,0
    dc.w $180,$012,$182,$fff
copbpl:
    dc.w $0e0,0,$0e2,0
    dc.w $ffff,$fffe
plane: dcb.b 10240,0

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

wrong.asm
    section code,code_c
CUSTOM = 0
BROKEN = 1
COYOTE_STEPS = 4
BUFFER_STEPS = 4
TEXT_CAP = 8
PROPERTY_COUNT = 16
STREAM_BYTES = 13
CRC_POLY = 7
    include "caller.inc"
    include "exercise.inc"
component_start:
    include "component.inc"
    even
    include "data.inc"
    include "cases.inc"
    even
    include "display.inc"
    include "../../framework/turn-deadline/font.inc"
code_end:
STATE:
POSITION: dc.b 0
PUSHED: dc.b 0
BLOCKED: dc.b 0
VALID: dc.b 0
ACTOR_POSITION: dc.b 0
ACTOR_SIZE: dc.b 0
SOLID_OLD: dc.b 0
SOLID_NEW: dc.b 0
SOLID_SIZE: dc.b 0
MINIMUM: dc.b 0
MAXIMUM: dc.b 0
T0: dc.b 0
T1: dc.b 0
T2: dc.b 0
T3: dc.b 0
    even
ready: dc.w 0
preview: dcb.b 8,0
OUTPUT: dcb.b 1300,0
    even
signature: dc.b "198XNIGHTONE000",0
    even
copperlist:
    dc.w $08e,$2c81,$090,$2cc1,$092,$0038,$094,$00d0
    dc.w $100,$1200,$102,0,$104,0,$108,0,$10a,0
    dc.w $180,$012,$182,$fff
copbpl:
    dc.w $0e0,0,$0e2,0
    dc.w $ffff,$fffe
plane: dcb.b 10240,0
Amiga shows the deliberate error row 0A 00 00 01 0A 02 0C 0C.
The wrong client completes with 0A 00 00 01 0A 02 0C 0C; its changed inputs and state explain the result.

Cost and alternatives

The measured helper extent is 726 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 A500 OCS PAL, Kickstart1.3 OFS cold boot, using Asm198x 0.0.72, Emu198x 0.44.2 and Build198x 0.2.9. 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.

The Craft · Maths for Games · Source and native evidence.