A passenger should inherit a moving platform’s displacement without changing the platform’s own position.

Use it in a project
PASSENGER, PLATFORM_OLD and PLATFORM_NEW are unsigned byte coordinates on one axis. MINIMUM/MAXIMUM bound the passenger’s allowed coordinate. If SUPPORTED is nonzero, add the signed platform displacement and clamp at those limits; otherwise keep PASSENGER. Return POSITION, CLAMPED and VALID. Reversed limits or an already out-of-range passenger return POSITION=PASSENGER and VALID=0.
Include component.inc once (MOS callers include the shared 6502 implementation through it). Reserve the public fields in this exact order: POSITION, CLAMPED, VALID, PASSENGER, PLATFORM_OLD, PLATFORM_NEW, SUPPORTED, MINIMUM, MAXIMUM. They occupy 9 contiguous bytes. Also reserve the private workspace: T0, T1 (2 bytes). Array names in the explanation refer to the numbered consecutive bindings, such as C0, C1 and so on.
Call moving_platform_carry_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_platform_carry_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 | passenger, platform coordinates, support and bounds |
| Read after service | POSITION, CLAMPED and VALID |
Choose the displacement sign by comparing platform coordinates. Check byte carry or borrow before applying world bounds, so arithmetic wrapping cannot put the passenger on the opposite side of the level.
Reusable initialisation and service
; SPDX-License-Identifier: MIT
; Carry a Supported Passenger. See README.md for the byte interface and ownership.
; init clears the public fields and private workspace; set inputs afterwards.
moving_platform_carry_init:
lda #0
sta POSITION
sta CLAMPED
sta VALID
sta PASSENGER
sta PLATFORM_OLD
sta PLATFORM_NEW
sta SUPPORTED
sta MINIMUM
sta MAXIMUM
sta T0
sta T1
rts
moving_platform_carry_step:
; POSITION = PASSENGER
lda PASSENGER
sta POSITION
; CLAMPED = 0
lda #0
sta CLAMPED
; VALID = 0
lda #0
sta VALID
; if MINIMUM > MAXIMUM:
lda MINIMUM
cmp MAXIMUM
beq moving_platform_carry_L5
bcs moving_platform_carry_L4
moving_platform_carry_L5:
jmp moving_platform_carry_L2
moving_platform_carry_L4:
jmp moving_platform_carry_L1
moving_platform_carry_L1:
; return
rts
jmp moving_platform_carry_L3
moving_platform_carry_L2:
moving_platform_carry_L3:
; if PASSENGER < MINIMUM:
lda PASSENGER
cmp MINIMUM
bcc moving_platform_carry_L9
moving_platform_carry_L10:
jmp moving_platform_carry_L7
moving_platform_carry_L9:
jmp moving_platform_carry_L6
moving_platform_carry_L6:
; return
rts
jmp moving_platform_carry_L8
moving_platform_carry_L7:
moving_platform_carry_L8:
; if PASSENGER > MAXIMUM:
lda PASSENGER
cmp MAXIMUM
beq moving_platform_carry_L15
bcs moving_platform_carry_L14
moving_platform_carry_L15:
jmp moving_platform_carry_L12
moving_platform_carry_L14:
jmp moving_platform_carry_L11
moving_platform_carry_L11:
; return
rts
jmp moving_platform_carry_L13
moving_platform_carry_L12:
moving_platform_carry_L13:
; VALID = 1
lda #1
sta VALID
; if SUPPORTED == 0:
lda SUPPORTED
cmp #0
beq moving_platform_carry_L19
moving_platform_carry_L20:
jmp moving_platform_carry_L17
moving_platform_carry_L19:
jmp moving_platform_carry_L16
moving_platform_carry_L16:
; return
rts
jmp moving_platform_carry_L18
moving_platform_carry_L17:
moving_platform_carry_L18:
; if PLATFORM_NEW >= PLATFORM_OLD:
lda PLATFORM_NEW
cmp PLATFORM_OLD
bcs moving_platform_carry_L24
moving_platform_carry_L25:
jmp moving_platform_carry_L22
moving_platform_carry_L24:
jmp moving_platform_carry_L21
moving_platform_carry_L21:
; T0 = PLATFORM_NEW - PLATFORM_OLD
lda PLATFORM_NEW
sec
sbc PLATFORM_OLD
sta T0
; T1 = PASSENGER + T0
lda PASSENGER
clc
adc T0
sta T1
; if T1 < PASSENGER:
lda T1
cmp PASSENGER
bcc moving_platform_carry_L29
moving_platform_carry_L30:
jmp moving_platform_carry_L27
moving_platform_carry_L29:
jmp moving_platform_carry_L26
moving_platform_carry_L26:
; POSITION = MAXIMUM
lda MAXIMUM
sta POSITION
; CLAMPED = 1
lda #1
sta CLAMPED
; return
rts
jmp moving_platform_carry_L28
moving_platform_carry_L27:
moving_platform_carry_L28:
; if T1 > MAXIMUM:
lda T1
cmp MAXIMUM
beq moving_platform_carry_L35
bcs moving_platform_carry_L34
moving_platform_carry_L35:
jmp moving_platform_carry_L32
moving_platform_carry_L34:
jmp moving_platform_carry_L31
moving_platform_carry_L31:
; POSITION = MAXIMUM
lda MAXIMUM
sta POSITION
; CLAMPED = 1
lda #1
sta CLAMPED
; return
rts
jmp moving_platform_carry_L33
moving_platform_carry_L32:
moving_platform_carry_L33:
; POSITION = T1
lda T1
sta POSITION
jmp moving_platform_carry_L23
moving_platform_carry_L22:
; T0 = PLATFORM_OLD - PLATFORM_NEW
lda PLATFORM_OLD
sec
sbc PLATFORM_NEW
sta T0
; if PASSENGER < T0:
lda PASSENGER
cmp T0
bcc moving_platform_carry_L39
moving_platform_carry_L40:
jmp moving_platform_carry_L37
moving_platform_carry_L39:
jmp moving_platform_carry_L36
moving_platform_carry_L36:
; POSITION = MINIMUM
lda MINIMUM
sta POSITION
; CLAMPED = 1
lda #1
sta CLAMPED
; return
rts
jmp moving_platform_carry_L38
moving_platform_carry_L37:
moving_platform_carry_L38:
; T1 = PASSENGER - T0
lda PASSENGER
sec
sbc T0
sta T1
; if T1 < MINIMUM:
lda T1
cmp MINIMUM
bcc moving_platform_carry_L44
moving_platform_carry_L45:
jmp moving_platform_carry_L42
moving_platform_carry_L44:
jmp moving_platform_carry_L41
moving_platform_carry_L41:
; POSITION = MINIMUM
lda MINIMUM
sta POSITION
; CLAMPED = 1
lda #1
sta CLAMPED
; return
rts
jmp moving_platform_carry_L43
moving_platform_carry_L42:
moving_platform_carry_L43:
; POSITION = T1
lda T1
sta POSITION
moving_platform_carry_L23:
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
CLAMPED=$81
VALID=$82
PASSENGER=$83
PLATFORM_OLD=$84
PLATFORM_NEW=$85
SUPPORTED=$86
MINIMUM=$87
MAXIMUM=$88
T0=$89
T1=$8a
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 {
; PASSENGER = 2
lda #2
sta PASSENGER
; PLATFORM_OLD = 10
lda #10
sta PLATFORM_OLD
; PLATFORM_NEW = 0
lda #0
sta PLATFORM_NEW
; SUPPORTED = 1
lda #1
sta SUPPORTED
; MINIMUM = 0
lda #0
sta MINIMUM
; MAXIMUM = 100
lda #100
sta MAXIMUM
!if BROKEN {
; PLATFORM_OLD = PLATFORM_NEW
lda PLATFORM_NEW
sta PLATFORM_OLD
}
jsr checked_step
jsr emit_state
rts
} else {
; PASSENGER = 20
lda #20
sta PASSENGER
; PLATFORM_OLD = 5
lda #5
sta PLATFORM_OLD
; PLATFORM_NEW = 9
lda #9
sta PLATFORM_NEW
; SUPPORTED = 1
lda #1
sta SUPPORTED
; MINIMUM = 0
lda #0
sta MINIMUM
; MAXIMUM = 100
lda #100
sta MAXIMUM
!if BROKEN {
; PLATFORM_OLD = PLATFORM_NEW
lda PLATFORM_NEW
sta PLATFORM_OLD
}
jsr checked_step
jsr emit_state
}
rtsCustomise it
Carry left past the lower world limit and observe the clamp. 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
CLAMPED=$81
VALID=$82
PASSENGER=$83
PLATFORM_OLD=$84
PLATFORM_NEW=$85
SUPPORTED=$86
MINIMUM=$87
MAXIMUM=$88
T0=$89
T1=$8a
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 00 01 01 02 0A 00 01 00. The full client trace in the source explains how it gets there.
Mistake and repair
The wrong caller overwrites the old platform coordinate with the new one. Its measured displacement becomes zero and the passenger stays behind. Keep both positions until passenger carry is complete.
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
CLAMPED=$81
VALID=$82
PASSENGER=$83
PLATFORM_OLD=$84
PLATFORM_NEW=$85
SUPPORTED=$86
MINIMUM=$87
MAXIMUM=$88
T0=$89
T1=$8a
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 259 code bytes; public state is 9 bytes and private scratch is 2 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 axis. A wider fixed-point position preserves subpixel platform motion; this byte version assumes both coordinates share the same unit and do not wrap.
SUPPORTED comes from the caller’s contact test. Carry alone does not resolve walls or crush situations; after moving the platform, apply carry once and resolve the passenger against other geometry. A clamp can break relative alignment, which needs a game policy.
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
One-way platforms: Support must be established using the chosen contact and pass-through rules.