PHLEGM v10 / PhlegmulatorArchitecture proposal27 October 2026

Networked Shared
Sessions

A system for multiple remote input devices and a display visible to every connected participant—without running a separate emulated machine for each user.

One authoritative hostOne CPU, memory state, and emulated machine.
Many users and devicesIndependent or shared controller assignments.
Shared video and audioEvery permitted participant can view the session live.
01 / Purpose

What this system is designed to solve

Today, an emulator usually assumes its input devices and display are attached to the same computer. Networked Shared Sessions extends Phlegmulator so people on other computers can see the running emulated machine, hear its audio, and operate assigned controls over a local network or the internet.

The host runs the emulator. Guests do not run an independent copy of the emulated hardware; instead, their keyboards, gamepads, joysticks, and other devices are converted into authorized virtual input signals at the host.

The central requirementEvery participant admitted to a shared session must have access to its live emulated display, even if that participant has no input device assigned. Input and display sharing are one integrated feature, not two unrelated features.

Because there is only one emulated machine, all users interact with the same memory contents, running program, and game or application. A guest may experience slightly more video delay than another guest because of network conditions, but the underlying machine state is shared and authoritative.

02 / Architecture

How the pieces connect

Host

Executes microcode and machine hardware; receives authorized virtual control states; produces frames and audio.

Connection service

Helps guests find and securely connect to a host. Direct peer connections are preferred when possible.

Guests

Decode media, display the session, and send changes from one or more physical devices.

A session is tied to a running emulator instance, not merely to a downloadable machine definition. The existing Hosted Definitions feature remains separate: it discovers or downloads machine definitions, while Network Sessions finds and joins active emulation sessions.

03 / Inputs

Multiple physical devices, one virtual hardware interface

Clients can attach keyboards, mice, digital/analog joysticks, modern gamepads, touch controls, and machine-specific peripherals where the selected machine supports them. One client may contribute more than one device. Devices receive session-scoped identifiers, so two guests with identical controllers are not confused.

Physical device→Device adapter / mapping→Secure input channel→Host arbitration→Emulated port
Example assignment in one shared session
ParticipantLocal hardwareHost assignmentCan watch?
HostKeyboardEmulated keyboardYes
Guest AGamepadPort 1Yes
Guest BGamepadPort 2Yes
Guest CJoystickPort 1 (shared)Yes
Guest DNo controllerSpectatorYes

Controller capacity depends on the emulated machine and its configured peripherals, not on the number of people allowed to connect. For instance, two standard SNES controller ports do not automatically become four ports because four guests joined. A data-defined multitap can legitimately expand hardware capacity.

04 / PHLEGM design rule

Keep machine behavior in .phlegm definitions

The network layer should be generic. It must not include special cases for the Commodore keyboard, NES controller shift registers, or SNES ports. Instead, the machine's existing or extended .phlegm files describe the input hardware, while a separate mapping layer translates remote physical devices into those hardware interfaces.

Owned by the machine definitionOwned by the session or device profile
Port count, controller types, register mappingsWhich person/device is assigned to each port
Keyboard matrix and scan behaviorWhich host/guest keyboard keys map to virtual keys
Polling and latch behaviorTransport format, update cadence, connection status
Multitap or expansion-device capabilitiesPermission, arbitration policy and priority
Illustrative design schema — NOT existing .phlegm syntax

machine.input_interfaces:
  keyboard:
    type: matrix
    source: <machine-defined matrix and scan rules>
  controller_port_1:
    compatible_devices: <defined controller types>
    source: <machine-defined electrical/register behavior>
  controller_port_2:
    compatible_devices: <defined controller types>
    source: <machine-defined electrical/register behavior>

session.assignments:
  guest-A/gamepad-0: controller_port_1
  guest-B/gamepad-0: controller_port_2
  guest-C/keyboard-0: keyboard

The example expresses the division of responsibility. The actual serialization must match PHLEGM v10's real definition grammar and compiler/runtime interfaces.

Critical separationRemote packets are not allowed to write emulator memory or poke hardware registers directly. They are interpreted as device input by the same normal hardware path used for local control.
05 / Collaboration

What happens when two people control the same device?

For each emulated input device, the host maintains an authoritative current state. Inputs may be assigned exclusively to one user, shared among several users, or not assigned at all for spectators.

Exclusive

Only the selected participant can change the device state. Best for competitive multiplayer.

Shared

Multiple participants jointly operate one emulated keyboard or controller, using configured merging rules.

Spectator

A guest watches and listens but cannot influence hardware until the host grants input access.

Host override

The host can release a controller, move it to another guest, deny access, or disconnect a participant.

Input typeSuggested default mergeReason
Ordinary digital buttons/keysPressed if any authorized contributor holds the controlAllows collaborative keyboard and button use.
Opposing directions (left/right, up/down)Neutralize simultaneous opposites, unless machine policy overridesAvoids contradictory directional states.
Analog axesExclusive owner or priority-based active contributorPrevents unnatural summed or averaged joystick movement.
Mouse / pointerSingle active owner by defaultPrevents multiple cursors fighting over one virtual pointer.

Button presses should be tracked per contributing device. If Guest A holds a key and Guest B releases the same key, the combined key should remain held until A also releases it. On disconnect, revocation, or device reassignment, the host removes only that contributor's held states—preventing stuck keys without erasing another user's input.

06 / Essential feature

Live display visible to every shared user

The host captures the emulator's completed framebuffer or equivalent final video surface after emulated video hardware has produced a frame. That image is sent to a media encoder, distributed to connected clients, and displayed in their viewing windows.

This is not desktop screen sharing. Remote users should not see the host's unrelated windows, notifications, other monitors, or private applications. They see only the designated emulated display.

PPU / video output→Completed framebuffer→Nonblocking encoder→Network stream→Guest viewer
  • Same content: everyone views output from the same host machine state. Individual playback delay may differ by client.
  • Native image behavior: retain the machine's aspect ratio, refresh characteristics, pixel geometry, and display timing. Do not stretch a 4:3 framebuffer into 16:9 by default.
  • Client scaling: each guest independently chooses windowed/fullscreen and nearest-neighbor or other supported scaling.
  • Spectators included: a guest without an input assignment still receives video and, if enabled, audio.
  • Adaptive quality: lower the transmitted resolution, bitrate, or streamed frame rate for poor connections without altering emulated CPU/PPU timing.
  • No stale backlog: if a viewer falls behind, skip old network video frames instead of delaying the host machine.
Important distinctionSkipping an encoded network video frame must never mean skipping the emulated machine's internal video processing or changing its emulation timing. The host keeps running accurately even if a remote viewer receives fewer frames.
07 / Sound

Share the APU output alongside video

The completed mixed audio from the emulated APU is routed to local playback as usual and, independently, into a network audio encoder. Opus is a sensible candidate for interactive network playback; the exact codec and integration should follow the selected native media stack.

Each guest should have a local volume/mute control. Host-generated audio/video presentation timestamps keep sound aligned with the corresponding emulated display. A small bounded client jitter buffer can smooth network variation, with a user-selectable tradeoff between delay and stability.

For systems with no audio device or when sound sharing is disabled, the rest of the shared session continues to work. Remote audio must not block the emulated APU or change its timing.

08 / Networking

Different traffic needs different handling

Logical channelDirectionBehavior
Session controlBoth waysReliable ordered delivery for join/leave, role grants, assignments, configuration and host commands.
Live inputGuest → hostLow latency; sequence numbers and full-state refreshes; stale states are discarded rather than queued indefinitely.
Display/audioHost → guestsReal-time encoded streams; bounded buffering; prefer recent playback over perfect delivery of old frames.

Recommended transport: evaluate a native WebRTC implementation for encrypted media, data channels, and NAT traversal. WebRTC is a design recommendation, not a claim that PHLEGM already includes this functionality. Other native transports are possible if they satisfy the latency and security requirements.

LAN: permit directly joined hosts and optional local discovery. Internet: use signaling plus ICE/STUN/TURN where needed for connections across routers and firewalls. A relay may be required on restrictive networks. Session discovery services do not need to execute the emulated machine.

A native client should require no JavaScript in the emulator's runtime path. An optional browser client would naturally use browser technologies for media and controller access, but must not dictate the native implementation.

09 / Correctness

Handling latency without breaking emulation

Client inputs arrive later than local inputs; that delay cannot be eliminated entirely over the internet. The design goal is to minimize it, avoid stale input, and preserve hardware-accurate polling on the host.

  1. Client detects a change. Button, axis, keyboard, or pointer state changes are converted using the active device mapping.
  2. Client sends a numbered state update. Include session/device identity, assignment generation, sequence number, and input values; client timestamp is useful for diagnostics but not trusted as authoritative host time.
  3. Host checks permission and freshness. Reject invalid, obsolete, duplicate, oversize, or unauthorized data before it reaches the emulated machine.
  4. Host applies input at a defined boundary. Update the virtual device state at the normal point where the emulated hardware reads or latches control signals, without waiting for an acknowledgment.
  5. Host streams the result. The next relevant video/audio output is captured and sent to viewers with presentation timestamps.
Conceptual input-state message
{
  protocol_version: 1,
  session_id:   <opaque session ID>,
  device_id:    <connection-scoped ID>,
  assignment_revision: <number>,
  sequence:     <increasing number>,
  buttons:      <bitset>,
  axes:         <normalized values>,
  pointer:      <optional motion/position>,
  client_time:  <diagnostic monotonic timestamp>
}

Authentication: established secure connection, NOT claimed fields.

Send immediate state changes plus periodic snapshots for loss recovery. When a connection ends or an input lease expires, the host releases that participant's contributions. Keep jitter/input queues bounded. Avoid rollback or speculative emulation in the first version; those techniques introduce complexity and can be assessed later if measurements justify them.

10 / Experience

New Network Sessions interface

Add a Network Sessions area to Phlegmulator, clearly separate from Hosted Definitions. The host can start a session, generate an invitation, view participants, grant input access, assign controller ports, toggle audio/video sharing, and end the session. Guests can discover or join a session, inspect device mappings, adjust their own viewer settings, and leave.

GUI controlPurpose
Host / Join SessionCreate or connect to an active shared emulator instance.
Connected UsersView guests, roles, and connection health.
Input DevicesList devices local to each participant and their session assignments.
Assign / RevokeChange virtual controller, keyboard, or pointer ownership.
Shared Display / AudioManage streaming policy and local playback controls.
Invite / Disconnect / EndControl session admission and termination.
DiagnosticsMonitor RTT, packet loss, encode time, stream FPS, and input-to-display delay estimates.

Access rule: a client given input permissions should automatically receive the session's live display. Otherwise, they would be operating a machine whose response they cannot see. A policy that deliberately disables display sharing should also disable remote interactive control or clearly reject the configuration.

11 / Permissions

Let guests control hardware, not the host computer

The host is always the authority for joining, device assignment, role changes, resets, and other privileged operations. Each connection has an authenticated session identity with an explicit role. Invitations should be unguessable, revocable and preferably time-limited.

  • Encrypt traffic; verify authenticated peers and message integrity.
  • Allow spectators without implicitly granting input.
  • Require explicit host authorization before enabling any remote device control.
  • Validate input payload lengths, device types, assignment revisions, and update rates.
  • Reject remote commands that attempt filesystem access, script execution, arbitrary memory changes, or compiler control.
  • Do not send ROMs, cartridge/program images, machine files, or unrelated host data just to enable viewing.
  • Expose only the emulated framebuffer and optional audio—not the entire desktop.
No automatic software distributionJoining a session is not permission to transfer a software image. The host runs the software locally and streams its output. If file transfer is ever added, it must be an independently authorized and validated feature.
12 / Runtime behavior

Keep network work off the emulation hot path

PHLEGM's interpreter, microcode execution, and hardware timing should not wait on internet traffic. Network functions should be connected by bounded, nonblocking queues and independently scheduled workers. The following responsibilities are logical partitions, not a requirement to create exactly six operating-system threads.

ResponsibilityConstraint
Emulation / microcodeRemains authoritative and timing-correct.
Local renderingContinues when networking is slow or absent.
Input receptionChecks and stages only current valid states.
Media capture/encodingOperates asynchronously; never blocks the emulated video/audio hardware.
Network transmissionUses bounded buffers and rate adaptation.
Session controlMaintains authenticated roles, permissions, and lifecycle state.

For small groups, encode one suitable common stream and fan it out rather than encoding identical output separately for each user. If guests have vastly different bandwidth, add a small number of quality tiers or adaptive layers. Large spectator audiences could later use a relay/SFU rather than multiplying the host's upload load indefinitely.

Preserve speed controlsNormal, unlimited, and other emulation speed options remain machine/execution concerns. A slow client must not secretly throttle the host or reduce the emulated hardware's clock. The viewer may receive fewer transmitted frames while the authoritative emulator continues normally.
13 / Delivery plan

Build it in measurable phases

Phase 1 — Virtual input boundary and LAN sessions

Extract machine-independent input adapters, device identities, host-side arbitration, permission checks, and basic local-network connections. Demonstrate two remote controllers operating one host machine.

Phase 2 — Shared display

Add completed-frame capture, native encoding, media distribution, and a guest viewer. Every permitted guest sees the same machine output without desktop capture.

Phase 3 — Shared audio and sync

Stream emulated APU output with timestamped presentation and bounded buffering. Validate that guest playback does not affect emulation timing.

Phase 4 — Internet connectivity and security hardening

Add signaling, secure invitations, authentication, NAT traversal, relaying when required, and comprehensive malformed-packet handling.

Phase 5 — Optional browser viewer

Provide audiovisual viewing and gamepad/keyboard input in a browser, separately from the native emulator runtime.

Phase 6 — Advanced multiuser controls

Improve per-user quality settings, collaborative inputs, large spectator sessions, host administration, and instrumented latency diagnostics.

Phases are a proposed development sequence, not a statement that these components are already implemented.

14 / Verification

What would prove the design works?

TestPass condition
Two remote controllersEach user controls a different data-defined port on the same running machine.
Shared controllerContributors merge correctly; releasing one user does not release another's held button.
Shared keyboardMultiple authorized keyboards use the machine's real keyboard matrix behavior.
SpectatorA viewer with no device assignment can still see display and hear enabled audio.
Same machine outputAll guests view frames derived from the host's one emulated framebuffer, with no separate guest emulation.
Disconnect / revokeOnly the departing participant's input contributions are cleared; no stuck keys.
Packet loss / jitterOutdated input is discarded, snapshots recover states, and media degrades gracefully.
Slow viewerThe remote stream may skip frames, but host emulation timing and local display remain stable.
Data-driven device expansionMachine-defined expansion peripherals increase ports without new network-specific code.
Permission attackA spectator cannot inject controls, write memory, request host files, or run scripts.

Representative machine tests should include a Commodore PET keyboard matrix, Commodore 64 keyboard/joystick, NES dual controllers, and SNES controllers with and without a data-defined multitap. These test targets must use real machine definitions rather than hand-built networking shortcuts.

15 / Summary

One machine. Many operators. A shared view.

The architecture separates emulated hardware behavior from remote device transport and audiovisual distribution. That separation is what keeps the feature scalable, reusable, and consistent with PHLEGM v10's data-driven design.

Remote users connect to a session, watch the host's actual emulated display, hear its audio if enabled, and provide inputs that the host maps to ordinary virtual hardware ports. The host remains authoritative, handles conflicts and permissions, and never lets media encoding or networking interrupt execution.

Recommended governing principleOne authoritative emulated machine + multiple independently assigned user input devices + live shared display/audio for all connected participants. All machine-specific behavior continues to come from machine-owned .phlegm definitions.

Status: design explanation only. This document does not modify PHLEGM v10 source code, define final wire protocols, or claim networking support already exists.