Viewport
The **viewport** is the visible portion of the game world displayed on screen. It contains a fixed-size array of **slots** that hold active game objects (enemies, fuel depots, etc.) currently visible or about to scroll into view.
The viewport is implemented as the viewport_slots array with 15 slots (46 bytes total: 15 × 3 bytes + 1 end marker byte).
Slot
A **slot** is a 3-byte entry in the viewport array (viewport_slots) that can hold one game object. Each slot has the following structure:
Byte Contents
0 X position (0-255 pixels)
1 Y position (0-255 pixels, increases as object scrolls down)
2 Object definition byte (type, orientation, activation state)
A slot can be in one of three states:
State X Value Description
Empty $00 (SET_MARKER_EMPTY_SLOT) Slot is unused, skipped during iteration
Occupied $01-$FE Contains a valid game object
End marker $FF (SET_MARKER_END_OF_SET) Marks end of active objects
The **current_slot_ptr** at current_slot_ptr is an iterator that traverses slots during the main object processing loop (operate_viewport_slots). It advances through all slots (including empty ones), checking each slot's state before processing.
Object Definition Byte
The **object definition byte** (byte 2 of each slot) encodes the object's type and state using bit fields:
Bit(s) Meaning
0-2 Object type (OBJECT_* constants: helicopter, ship, tank, etc.)
3 Rock flag (1=rock decoration on land, 0=interactive object)
4 Unused
5 Tank location (1=river bank, 0=bridge)
6 Orientation (1=left-facing, 0=right-facing)
7 Activation (1=active/interactive, 0=spawning/inactive)
Objects spawn with bit 7 clear (inactive). On their first frame in the viewport, operate_viewport_slots sets bit 7 to activate them, enabling movement and collision.
Slot Markers
Two special values in the X position byte (byte 0) serve as **markers**:
Constant Value Purpose
SET_MARKER_EMPTY_SLOT $00 Marks an unused slot (skip during iteration)
SET_MARKER_END_OF_SET $FF Marks end of active objects (reset iterator)
When the iterator (current_slot_ptr) encounters SET_MARKER_END_OF_SET, it resets to the beginning of the array via reset_slot_ptr.