Exemplo n.º 1
0
        private static Mos6502State Asl(int address, Mos6502State currentState, MemoryUnit memory)
        {
            var operand = address == 0 ? currentState.A : memory.ReadByte(address);
            var r       = operand << 1;

            var flags = currentState.P;

            flags = flags.SetIf(r > 0xFF, Mos6502Flags.Carry);
            r     = (byte)r;

            // Set Zero flag **only** if the accumulator changes to zero.
            if (address == 0)
            {
                flags = flags.SetIf(r == 0, Mos6502Flags.Zero);
            }
            flags = flags.SetIf((r & 0b1000_0000) != 0, Mos6502Flags.Negative);

            if (address == 0)
            {
                return(currentState.With(a: (byte)r, p: flags));
            }
            else
            {
                memory.WriteByte(address, (byte)r);
                return(currentState.With(p: flags));
            }
        }
Exemplo n.º 2
0
        private static Mos6502State Ahx(int address, Mos6502State currentState, MemoryUnit memory)
        {
            // AHX is an unofficial opcode with odd behavior
            // Based this test on https://github.com/anurse/remy/blob/4f01c0e16ac9b8db1553d97588c9d8927884cef1/src/hw/mos6502/exec/store.rs#L158
            // I don't remember where I figured that behavior out then :(.
            var highByte = (address & 0xFF00) >> 8;
            var val      = currentState.A & currentState.X & highByte;

            memory.WriteByte(address, (byte)val);
            return(currentState);
        }