pub(super) fn exec(self, ctx: &mut impl CpuContext, arg: u8) {
        trace!("Evaluating {} A,{}", self, arg);
        match self {
            Self::Add => {
                let (res, flags) = add8_flags(ctx.cpustate().regs.acc, arg);
                ctx.cpustate_mut().regs.acc = res;
                ctx.cpustate_mut().regs.flags = flags;
            }
            Self::AddCarry => {
                let (mut res, mut flags) = add8_flags(ctx.cpustate().regs.acc, arg);
                if ctx.cpustate().regs.flags.contains(Flags::CARRY) {
                    let (res2, flags2) = add8_flags(res, 1);
                    res = res2;
                    flags |= flags2;
                }
                ctx.cpustate_mut().regs.acc = res;
                ctx.cpustate_mut().regs.flags = flags;
            }
            Self::Sub => {
                let (res, flags) = sub8_flags(ctx.cpustate().regs.acc, arg);
                ctx.cpustate_mut().regs.acc = res;
                ctx.cpustate_mut().regs.flags = flags;
            }
            Self::SubCarry => {
                let (mut res, mut flags) = sub8_flags(ctx.cpustate().regs.acc, arg);
                if ctx.cpustate().regs.flags.contains(Flags::CARRY) {
                    let (res2, flags2) = sub8_flags(res, 1);
                    res = res2;
                    flags |= flags2;
                }
                ctx.cpustate_mut().regs.acc = res;
                ctx.cpustate_mut().regs.flags = flags;
            }
            Self::And => {
                let res = ctx.cpustate().regs.acc & arg;
                ctx.cpustate_mut().regs.acc = res;
                ctx.cpustate_mut().regs.flags = Flags::HALFCARRY | Flags::check_zero(res);
            }
            Self::Or => {
                let res = ctx.cpustate().regs.acc | arg;
                ctx.cpustate_mut().regs.acc = res;
                ctx.cpustate_mut().regs.flags = Flags::check_zero(res);
            }
            Self::Xor => {
                let res = ctx.cpustate().regs.acc ^ arg;
                ctx.cpustate_mut().regs.acc = res;
                ctx.cpustate_mut().regs.flags = Flags::check_zero(res);
            }
            Self::Compare => {
                let (_, flags) = sub8_flags(ctx.cpustate().regs.acc, arg);
                ctx.cpustate_mut().regs.flags = flags;
            }
        }
    }
/// Evaluate this ALU operation, updating the accumulator and flags. The argument to the
/// operation should already have been loaded by the caller and passed as `arg`.
Evaluate this ALU operation, updating the accumulator and flags. The argument to the
operation should already have been loaded by the caller and passed as `arg`.
Evaluate this ALU operation updating the accumulator and flags . The argument to the operation should already have been loaded by the caller and passed as ` arg ` .
pub(super) fn exec(self, ctx: &mut impl CpuContext, arg: u8) {
        trace!("Evaluating {} A,{}", self, arg);
        match self {
            Self::Add => {
                let (res, flags) = add8_flags(ctx.cpustate().regs.acc, arg);
                ctx.cpustate_mut().regs.acc = res;
                ctx.cpustate_mut().regs.flags = flags;
            }
            Self::AddCarry => {
                let (mut res, mut flags) = add8_flags(ctx.cpustate().regs.acc, arg);
                if ctx.cpustate().regs.flags.contains(Flags::CARRY) {
                    let (res2, flags2) = add8_flags(res, 1);
                    res = res2;
                    flags |= flags2;
                }
                ctx.cpustate_mut().regs.acc = res;
                ctx.cpustate_mut().regs.flags = flags;
            }
            Self::Sub => {
                let (res, flags) = sub8_flags(ctx.cpustate().regs.acc, arg);
                ctx.cpustate_mut().regs.acc = res;
                ctx.cpustate_mut().regs.flags = flags;
            }
            Self::SubCarry => {
                let (mut res, mut flags) = sub8_flags(ctx.cpustate().regs.acc, arg);
                if ctx.cpustate().regs.flags.contains(Flags::CARRY) {
                    let (res2, flags2) = sub8_flags(res, 1);
                    res = res2;
                    flags |= flags2;
                }
                ctx.cpustate_mut().regs.acc = res;
                ctx.cpustate_mut().regs.flags = flags;
            }
            Self::And => {
                let res = ctx.cpustate().regs.acc & arg;
                ctx.cpustate_mut().regs.acc = res;
                ctx.cpustate_mut().regs.flags = Flags::HALFCARRY | Flags::check_zero(res);
            }
            Self::Or => {
                let res = ctx.cpustate().regs.acc | arg;
                ctx.cpustate_mut().regs.acc = res;
                ctx.cpustate_mut().regs.flags = Flags::check_zero(res);
            }
            Self::Xor => {
                let res = ctx.cpustate().regs.acc ^ arg;
                ctx.cpustate_mut().regs.acc = res;
                ctx.cpustate_mut().regs.flags = Flags::check_zero(res);
            }
            Self::Compare => {
                let (_, flags) = sub8_flags(ctx.cpustate().regs.acc, arg);
                ctx.cpustate_mut().regs.flags = flags;
            }
        }
    }
pub ( super ) fn exec ( self , ctx : & mut impl CpuContext , arg : u8 ) { trace ! ( " " self arg ) ; match self { Self :: Add => { let ( res , flags ) = add8_flags ( ctx . cpustate ( ) . regs . acc , arg ) ; ctx . cpustate_mut ( ) . regs . acc = res ; ctx . cpustate_mut ( ) . regs . flags = flags ; } Self :: AddCarry => { let ( mut res , mut flags ) = add8_flags ( ctx . cpustate ( ) . regs . acc , arg ) ; if ctx . cpustate ( ) . regs . flags . contains ( Flags :: CARRY ) { let ( res2 , flags2 ) = add8_flags ( res , 1 ) ; res = res2 ; flags |= flags2 ; } ctx . cpustate_mut ( ) . regs . acc = res ; ctx . cpustate_mut ( ) . regs . flags = flags ; } Self :: Sub => { let ( res , flags ) = sub8_flags ( ctx . cpustate ( ) . regs . acc , arg ) ; ctx . cpustate_mut ( ) . regs . acc = res ; ctx . cpustate_mut ( ) . regs . flags = flags ; } Self :: SubCarry => { let ( mut res , mut flags ) = sub8_flags ( ctx . cpustate ( ) . regs . acc , arg ) ; if ctx . cpustate ( ) . regs . flags . contains ( Flags :: CARRY ) { let ( res2 , flags2 ) = sub8_flags ( res , 1 ) ; res = res2 ; flags |= flags2 ; } ctx . cpustate_mut ( ) . regs . acc = res ; ctx . cpustate_mut ( ) . regs . flags = flags ; } Self :: And => { let res = ctx . cpustate ( ) . regs . acc & arg ; ctx . cpustate_mut ( ) . regs . acc = res ; ctx . cpustate_mut ( ) . regs . flags = Flags :: HALFCARRY | Flags :: check_zero ( res ) ; } Self :: Or => { let res = ctx . cpustate ( ) . regs . acc | arg ; ctx . cpustate_mut ( ) . regs . acc = res ; ctx . cpustate_mut ( ) . regs . flags = Flags :: check_zero ( res ) ; } Self :: Xor => { let res = ctx . cpustate ( ) . regs . acc ^ arg ; ctx . cpustate_mut ( ) . regs . acc = res ; ctx . cpustate_mut ( ) . regs . flags = Flags :: check_zero ( res ) ; } Self :: Compare => { let ( _ , flags ) = sub8_flags ( ctx . cpustate ( ) . regs . acc , arg ) ; ctx . cpustate_mut ( ) . regs . flags = flags ; } } }
Evaluate this ALU operation, updating the accumulator and flags.
Evaluate this ALU operation updating the accumulator and flags .
self
ctx
&mut impl CpuContext
arg
u8
self
ctx
&mut impl CpuContext
arg
u8