Skip to content

Implement Event Hook Dispatch Pipeline #348

Description

@maxolasersquad

Objective

Implement the event dispatch pipeline allowing plugins to subscribe to emulator events (CPU cycles, frame rendering, memory access traps, system reset).

Scope & Requirements

  • Define PluginEventHooks_t containing optional function pointers:
    • on_cpu_cycle(uint64_t total_cycles)
    • on_frame_ready(const uint32_t* pixels, int width, int height, int pitch)
    • on_memory_read(uint16_t addr, uint8_t value)
    • on_memory_write(uint16_t addr, uint8_t value)
    • on_frontend_render(SDL_Renderer* renderer)
    • on_reset(bool cold_reset)
  • Implement hook registration inside PluginManager_t.
  • Maintain fast-path dispatch arrays per hook type.
  • When no plugins subscribe to a hook type (such as memory read/write traps or cycle ticks), bypass dispatch completely without branching overhead in the critical CPU loop.
  • Ensure hook callbacks preserve CPU state and handle re-entrant safety during reset.

Testing & Verification

  • Register multiple mock plugin hooks and dispatch frame, cycle, memory, and reset events, verifying callbacks fire with correct arguments in registration order.
  • Register sparse hook structures containing null pointers for unhandled events and verify dispatches safely skip unhandled hooks without crashing.
  • Unregister hooks and verify subsequent event dispatches no longer invoke unregistered callbacks.
  • Verify event dispatch when the hook list is completely empty is a fast no-op.
  • Benchmark the CPU execution loop with zero registered cycle or memory hooks to confirm zero performance penalty.
  • Verify reset callbacks execute cleanly during both warm and cold emulator reset sequences.
  • Test re-entrancy safety when a hook callback invokes a core state inspection function.

Acceptance Criteria

  • Subscribed plugins receive callbacks on frame generation, memory access, and reset events.
  • Unregistering or shutting down a plugin removes it from active dispatch lists.
  • Emulation execution speed remains unaffected when no plugins subscribe to cycle-level hooks.

Activity

  1. added this to the Plugin Engine milestone on Sep 6, 2026
  2. changed the title [-]Task 06: Implement Event Hook Dispatch Pipeline[/-] [+]Implement Event Hook Dispatch Pipeline[/+] on Sep 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

sdl3Affects the SDL3 frontend.

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions