Some preface: Interface is a trait that has a read method and write method.
Is this a good way to build an opcode matrix? If not, what improvements can I make?
const OPCODE_MATRIX: [fn(&mut Chip6502, &mut dyn Interface) -> (); 2] = [
|cpu, _interface| {
cpu.nop();
},
|cpu, interface| {
let value = cpu.get_immediate(interface);
cpu.sta(value);
},
];
impl Chip6502 {
pub(crate) fn instruction<T: Interface>(&mut self, interface: &mut T, instruction: u8) {
OPCODE_MATRIX[instruction as usize](self, interface);
}
}```