Trinity-11 / FoenixIDE

Development and Debugging Suite for the C256 Foenix Family of Computers
GNU General Public License v3.0
48 stars 14 forks source link

BIT command requires small correction #13

Closed aniou closed 4 years ago

aniou commented 4 years ago

Hi, BIT command is somewhat irregular and surprising, when comes to flag setting. According to manuals there is a difference in modes (immediate and others) and only Z flag is set from result - N and V are set from argument (but not in Immediate case). See: http://www.6502.org/tutorials/65c816opcodes.html#6.1.2.2

Following code should works for me:

        public void ExecuteBIT(byte instruction, AddressModes addressMode, int signature)
        {
            int data = GetValue(addressMode, signature, cpu.A.Width);
            int result = cpu.A.Value & data;
            cpu.Flags.SetZ(cpu.A.Value & data);
            if (addressMode != AddressModes.Immediate)
            {
                if (cpu.A.Width == 2)
                {
                    cpu.Flags.oVerflow = (data & 0x4000) == 0x4000;
                    cpu.Flags.Negative = (data & 0x8000) == 0x8000;
                }
                else 
                { 
                    cpu.Flags.oVerflow = (data & 0x40) == 0x40;
                    cpu.Flags.Negative = (data & 0x80) == 0x80;
                }
            }
        }
dtremblay commented 4 years ago

Thanks for your bug fixes! Your changes have been included in release-0.5.2.2.

Added a new unit test "TestBit", which uses the example provided in the URL provided.