Skip to content

Commit

Permalink
add volume controls to SDL2 frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
39bytes committed Aug 25, 2024
1 parent db00f44 commit 5198268
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,18 @@ cd target/release
./nesrs <path-to-rom>
```
Controls are bound to:
- Z: B
- X: A
- A: Select
- S: Start
- Arrow keys: Up/Down/Left/Right
- `Z`: B
- `X`: A
- `A`: Select
- `S`: Start
- `Arrow keys`: Up/Down/Left/Right

There are 5 save state slots. Save states can be loaded with the number keys 1-5, and written with SHIFT + [number].
Meta controls (Not controller inputs):
- `Space`: Pause/unpause emulation
- `[`: Decrease volume
- `]`: Increase volume
- `1-5`: Load save state [1-5]
- `Shift+[1-5]`: Write save state to slot [1-5]

## Running the WASM frontend locally
Ensure that you have [wasm-pack](https://rustwasm.github.io/wasm-pack/), [Node](https://nodejs.org/en) and [pnpm](https://pnpm.io/) installed.
Expand Down
4 changes: 4 additions & 0 deletions emu/src/audio_sample_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ impl AudioSampleBuffer {
self.clear();
}

pub fn volume(&self) -> f32 {
self.volume
}

pub fn set_volume(&mut self, volume: f32) {
self.volume = clamp(volume, 0.0, 1.0);
}
Expand Down
4 changes: 4 additions & 0 deletions emu/src/nes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ impl Nes {
&mut self.audio_buffer
}

pub fn volume(&self) -> f32 {
self.audio_buffer.volume()
}

pub fn set_volume(&mut self, volume: f32) {
self.audio_buffer.set_volume(volume);
}
Expand Down
6 changes: 6 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,12 @@ pub fn main() -> Result<()> {
};
}
}
Keycode::LeftBracket => {
nes.set_volume(nes.volume() - 0.05);
}
Keycode::RightBracket => {
nes.set_volume(nes.volume() + 0.05);
}
_ => {}
},
_ => {}
Expand Down

0 comments on commit 5198268

Please sign in to comment.