Skip to content

Implement sfx_play() sound effect subroutine #312

@jonathanpeppers

Description

@jonathanpeppers

Problem

sfx_play(byte sound, byte channel) is declared in NESLib but has no 6502 implementation in BuiltInSubroutines.cs. The crypto sample has 6 sfx_play calls that are commented out as a workaround.

// These are all commented out because sfx_play has no implementation:
// sfx_play(3, 2);  // pickup sound
// sfx_play(4, 2);  // level complete
// sfx_play(5, 3);  // attack sound
// sfx_play(1, 0);  // damage taken
// sfx_play(2, 3);  // enemy killed
// sfx_play(0, 0);  // item placed

What's Needed

A 6502 implementation of sfx_play that plays sound effects through the NES APU. This is typically provided by a sound engine like FamiTone2 or Pently.

cc65/neslib implementation

In the original cc65 neslib, sfx_play is part of the FamiTone2 sound engine. It:

  1. Takes a sound effect index in A and channel (0-3) in X
  2. Loads the sound effect data pointer from a table
  3. Starts playback on the specified APU channel
  4. The NMI handler calls sfx_update each frame to advance the sound

References

Implementation Options

  1. Port FamiTone2's sfx routines to BuiltInSubroutines.cs -- most compatible with existing neslib samples
  2. Stub implementation -- play a simple beep on the specified channel (minimal but functional)
  3. No-op -- emit an RTS stub so the transpiler doesn't crash but no sound plays

Context

The crypto sample (PR #211) has 6 sound effects for gameplay feedback. Without sfx_play, the game is silent.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions