forked from Lea/invadeez
add extra derives on structs and enums
This commit is contained in:
parent
1b7b942dff
commit
4017733dce
|
@ -20,7 +20,7 @@ fn set_cc(state: &mut EmulatorState, result: u16, flags: u8) {
|
|||
|
||||
/// Add values of `register` and `A`
|
||||
pub fn add(register: Register, state: &mut EmulatorState) {
|
||||
let result = get_register(®ister, state) as u16 + state.a as u16;
|
||||
let result = get_register(register, state) as u16 + state.a as u16;
|
||||
set_cc(state, result, 0b1111);
|
||||
state.a = (result & 0xff) as u8;
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ pub fn adi(byte: u8, state: &mut EmulatorState) {
|
|||
|
||||
/// Add values of `register` and `A` and add +1 if carry bit is set
|
||||
pub fn adc(register: Register, state: &mut EmulatorState) {
|
||||
let result = get_register(®ister, state) as u16 + state.a as u16 + u16::from(state.cc.c);
|
||||
let result = get_register(register, state) as u16 + state.a as u16 + u16::from(state.cc.c);
|
||||
set_cc(state, result, 0b1111);
|
||||
state.a = (result & 0xff) as u8;
|
||||
}
|
||||
|
@ -64,14 +64,14 @@ pub fn dad(register: Register, state: &mut EmulatorState) {
|
|||
|
||||
/// Increase register
|
||||
pub fn inr(register: Register, state: &mut EmulatorState) {
|
||||
let (result, _) = get_register(®ister, state).overflowing_add(1);
|
||||
let (result, _) = get_register(register, state).overflowing_add(1);
|
||||
set_cc(state, result as u16, 0b1101);
|
||||
set_register(®ister, result, state);
|
||||
set_register(register, result, state);
|
||||
}
|
||||
|
||||
/// Decrease register
|
||||
pub fn dcr(register: Register, state: &mut EmulatorState) {
|
||||
let (result, _) = get_register(®ister, state).overflowing_sub(1);
|
||||
let (result, _) = get_register(register, state).overflowing_sub(1);
|
||||
set_cc(state, result as u16, 0b1101);
|
||||
set_register(®ister, result, state);
|
||||
set_register(register, result, state);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
use crate::MEMORY_SIZE;
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Debug)]
|
||||
pub struct EmulatorState {
|
||||
pub a: u8,
|
||||
pub b: u8,
|
||||
|
@ -21,6 +22,7 @@ pub struct EmulatorState {
|
|||
pub memory: [u8; MEMORY_SIZE],
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
||||
pub struct ConditionCodes {
|
||||
/// Zero (Z), set if the result is zero.
|
||||
pub z: bool,
|
||||
|
@ -35,7 +37,7 @@ pub struct ConditionCodes {
|
|||
// ac: bool,
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Debug)]
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
||||
pub enum Register {
|
||||
B,
|
||||
C,
|
||||
|
@ -63,7 +65,7 @@ pub fn register_from_num(b: u8) -> Register {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn get_register(register: &Register, state: &EmulatorState) -> u8 {
|
||||
pub fn get_register(register: Register, state: &EmulatorState) -> u8 {
|
||||
match register {
|
||||
Register::B => state.b,
|
||||
Register::C => state.c,
|
||||
|
@ -77,7 +79,7 @@ pub fn get_register(register: &Register, state: &EmulatorState) -> u8 {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn set_register(register: &Register, value: u8, state: &mut EmulatorState) {
|
||||
pub fn set_register(register: Register, value: u8, state: &mut EmulatorState) {
|
||||
match register {
|
||||
Register::B => state.b = value,
|
||||
Register::C => state.c = value,
|
||||
|
|
Loading…
Reference in a new issue