Skip to main content

ym2149_core/
command.rs

1/// A command contains a value to be written to a specific register of the YM2149.
2#[derive(Debug, Clone, Copy)]
3pub struct Command {
4    pub register: u8,
5    pub value: u8,
6}
7
8#[allow(unused)]
9impl Command {
10    /// Creates a new Command from a register (u8) and value (u8).
11    pub fn new(register: u8, value: u8) -> Self {
12        Self { register, value }
13    }
14
15    /// Returns self as an array containing two bytes, [0] for register, and [1] for value.
16    pub fn as_array(&self) -> [u8; 2] {
17        [self.register, self.value]
18    }
19}
20
21/// Helper trait that lets you implement an "output" for the commands that the driver generates.
22///
23/// Example:
24/// ```no_run
25/// use ym2149_core::command::{Command, CommandOutput};
26///
27/// struct DebugWriter;
28///
29/// impl CommandOutput for DebugWriter {
30///     fn execute(&mut self, command: Command) {
31///         let arr = command.as_array();
32///         println!("Writing 0b{:08b} to register 0b{:08b}.", arr[0], arr[1]);
33///     }
34/// }
35/// ```
36pub trait CommandOutput {
37    fn execute(&mut self, command: Command);
38}