Exemplo n.º 1
0
        public void CheckAnd_Ani_()
        {
            // ANDI #<data>,<ea>
            // 0000 0010 0001 1001  0x0219
            // 0000 0000 0000 0101  0x000A
            // ANDI #10,(A1)

            byte[] data = new byte[]
            {
                0x02, 0x19, 0x00, 0x0A
            };

            MegadriveState state = new MegadriveState(new Data(data), 0x00000000, 0x00000000, 0x000000, 0x3FFFFF, 0x0FF0000, 0xFFFFFF);

            state.WriteAReg(0x1, 0x00FF0000);
            state.WriteByte(0x00FF0000, 0xFF);
            state.WriteByte(0x00FF0002, 0xAA);
            state.WriteDReg(0x1, 0xFF);
            state.FetchOpCode();

            var opcode = new ANDI(state);

            Assert.That(opcode.Assembly, Is.EqualTo("ANDI #10,(A1)+"));
            Assert.That(state.PC, Is.EqualTo(0x04));
            Assert.That(state.ReadAReg(0x1), Is.EqualTo(0x00FF0001));
            Assert.That(state.ReadByte(0x00FF0000), Is.EqualTo(0x0000000A));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ANDI"/> class.
        /// </summary>
        /// <param name="state">machine state.</param>
        public ANDI(MegadriveState state)
            : base("00000010ssmmmxxx", state)
        {
            var allowedModes = new[]
            {
                EffectiveAddressMode.DataRegister,
                EffectiveAddressMode.Address,
                EffectiveAddressMode.AddressPostIncrement,
                EffectiveAddressMode.AddressPreDecrement,
                EffectiveAddressMode.AddressWithDisplacement,
                EffectiveAddressMode.AddressWithIndex,
                EffectiveAddressMode.AbsoluteWord,
                EffectiveAddressMode.AbsoluteLong,
            };

            this.ValidateEffectiveAddress(this.DecodeEffectiveAddressMode(), allowedModes);

            this.EffectiveAddress = this.FetchEffectiveAddress();
            this.immediate        = this.ReadImmediate();

            var val = this.ReadValueForEffectiveAddress();

            val &= this.immediate;
            this.WriteValueToEffectiveAddress(this.DecodeEffectiveAddressMode(), this.GetXn(), val);

            this.state.Condition_N = this.IsNegative(val);
            this.state.Condition_Z = this.IsZero(val);
            this.state.Condition_V = false;
            this.state.Condition_C = false;
        }
        private OpCode decode_4XX0(MegadriveState state)
        {
            if (state.OpCode.CheckBits("0100100xxxxxxxxx") || state.OpCode.CheckBits("0100110xxxxxxxxx"))
            {
                if (state.OpCode.CheckBits("0100100xxx000xxx") || state.OpCode.CheckBits("0100110xxx000xxx"))
                {
                    throw new NotImplementedException("EXT");
                }
                else
                {
                    return(new MOVEM(state));
                }
            }

            if (state.OpCode.CheckBits("0100011xxxxxxxxx"))
            {
                if (state.OpCode.CheckBits("0100011011xxxxxx"))
                {
                    return(new MOVEtoSR(state));
                }
                else
                {
                    throw new NotImplementedException();
                }
            }

            throw new NotImplementedException();
        }
        public OpCode Decode(MegadriveState state)
        {
            switch (state.OpCode & 0xF000)
            {
            // 0000
            case 0x0000:
                return(decode_0000(state));

            // 0001
            // 0010
            // 0011
            case 0x1000:
            case 0x2000:
            case 0x3000:
                return(decode_X000(state));

            // 0100
            case 0x4000:
                return(decode_4000(state));

            // 0101
            case 0x5000:
                return(decode_5000(state));

            // 0110
            case 0x6000:
                return(decode_6000(state));

            // 0111
            case 0x7000:
                return(decode_7000(state));

            // 1000
            case 0x8000:
                return(decode_8000(state));

            // 1001
            case 0x9000:
                return(decode_9000(state));

            // 1011
            case 0xB000:
                return(decode_B000(state));

            // 1100
            case 0xC000:
                return(decode_C000(state));

            // 1101
            case 0xD000:
                return(decode_D000(state));

            // 1110
            case 0xE000:
                return(decode_E000(state));

            default:
                return(new Invalid(state));
            }
        }
Exemplo n.º 5
0
        public void CheckIsZeroSetsZ()
        {
            // TST <ea>
            // 0100 1010 1011 1001  0x4AB9
            // 0000 0000 1111 1111  0x00FF
            // 0000 0000 0000 0000  0x0000
            // TST 0x00FF0000

            byte[] data = new byte[]
            {
                0x4A, 0xB9, 0x00, 0xFF, 0x00, 0x00
            };

            MegadriveState state = new MegadriveState(new Data(data), 0x00000000, 0x00000000, 0x000000, 0x3FFFFF, 0x0FF0000, 0xFFFFFF);

            state.WriteByte(0xFF0000, 0x00);
            state.FetchOpCode();

            state.SR |= 0x0011;

            var opcode = new TST(state);

            Assert.That(opcode.Assembly, Is.EqualTo("TST.l $00FF0000"));

            Assert.That(opcode.Size, Is.EqualTo(Size.Long));

            Assert.That(state.PC, Is.EqualTo(0x00000006));

            Assert.That(state.Condition_X, Is.True);    // not affected
            Assert.That(state.Condition_N, Is.False);
            Assert.That(state.Condition_Z, Is.True);
            Assert.That(state.Condition_V, Is.False);   // always cleared
            Assert.That(state.Condition_C, Is.False);   // always cleared
        }
Exemplo n.º 6
0
        public void CheckAddD1To_A0i_()
        {
            // ADD Dn,<ea>
            // 1101 dddD ssmm mxxx
            // 1101 0011 0001 1000  0xD318
            // ADD D1,(A0)+

            byte[] data = new byte[]
            {
                0xD3, 0x18
            };

            MegadriveState state = new MegadriveState(new Data(data), 0x00000000, 0x00000000, 0x000000, 0x3FFFFF, 0x0FF0000, 0xFFFFFF);

            state.WriteDReg(0x1, 0x22221111);
            state.WriteAReg(0x0, 0x00FF0000);
            state.WriteByte(0x00FF0000, 0x22);
            state.FetchOpCode();

            var opcode = new ADD(state);

            Assert.That(opcode.Assembly, Is.EqualTo("ADD.B D1,(A0)+"));
            Assert.That(state.PC, Is.EqualTo(0x02));
            Assert.That(state.ReadAReg(0x0), Is.EqualTo(0x00FF0001));
            Assert.That(state.ReadDReg(0x1), Is.EqualTo(0x22221111));
            Assert.That(state.ReadByte(0x00FF0000), Is.EqualTo(0x33));
        }
        public void CheckMove_d16A0_ToD1()
        {
            // MOVE <ea>,<ea>
            // 0001 0010 0010 1000  0x1228
            // 0000 0000 0000 0002  0x0002
            // MOVE (d16,A0),D1

            byte[] data = new byte[]
            {
                0x12, 0x28, 0x00, 0x02
            };

            MegadriveState state = new MegadriveState(new Data(data), 0x00000000, 0x00000000, 0x000000, 0x3FFFFF, 0x0FF0000, 0xFFFFFF);

            state.WriteAReg(0x0, 0x00FF0000);
            state.WriteByte(0x00FF0002, 0xAA);
            state.FetchOpCode();

            var opcode = new MOVE(state);

            Assert.That(opcode.Assembly, Is.EqualTo("MOVE.b ($0002,A0),D1"));
            Assert.That(state.PC, Is.EqualTo(0x04));
            Assert.That(state.ReadAReg(0x0), Is.EqualTo(0x00FF0000));
            Assert.That(state.ReadDReg(0x1), Is.EqualTo(0x000000AA));
        }
Exemplo n.º 8
0
        public void CheckLoad_A0_ToA1()
        {
            // LEA <ea>,An
            // 0100 0011 1101 0000  0x43D0
            // LEA (A0),A1

            byte[] data = new byte[]
            {
                0x43, 0xD0
            };

            MegadriveState state = new MegadriveState(new Data(data), 0x00000000, 0x00000000, 0x000000, 0x3FFFFF, 0x0FF0000, 0xFFFFFF);

            state.WriteAReg(0x0, 0x00FF0000);
            state.WriteByte(0x00FF0000, 0xAA);
            state.FetchOpCode();

            var opcode = new LEA(state);

            Assert.That(opcode.Assembly, Is.EqualTo("LEA (A0),A1"));
            Assert.That(opcode.Size, Is.EqualTo(Size.Long));

            Assert.That(state.PC, Is.EqualTo(0x00000002));
            Assert.That(state.ReadAReg(0x0), Is.EqualTo(0x00FF0000));
            Assert.That(state.ReadAReg(0x1), Is.EqualTo(0x00FF0000));
        }
Exemplo n.º 9
0
        public void CheckMoveNumberToDRegister(byte number, DataRegister register)
        {
            // 0111ddd0bbbbbbbb
            // MOVEQ #0,D0

            byte hi = 0x70;
            byte lo = number;

            hi |= (byte)((byte)register << 1);

            byte[] data = new byte[]
            {
                hi, lo
            };

            MegadriveState state = new MegadriveState(new Data(data), 0x00000000, 0x00000000, 0x000000, 0x3FFFFF, 0x0FF0000, 0xFFFFFF);

            state.WriteAReg(0x5, 0xFF0000);
            for (int i = 0; i < 16; i++)
            {
                state.WriteByte((uint)(0xFF0000 + i), (byte)(0x00 + i));
            }
            state.FetchOpCode();

            var opcode = new MOVEQ(state);

            Assert.That(opcode.Assembly, Is.EqualTo($"MOVEQ #{number},{register}"));
            Assert.That(opcode.Size, Is.EqualTo(Size.Long));
            Assert.That(state.ReadDReg((byte)register), Is.EqualTo(number));
        }
Exemplo n.º 10
0
        public void CheckMove_dA0_ToA1()
        {
            // 00ss aaa0 01mm mxxx
            // 0010 0010 0110 0000  0x2260
            // MOVEM <ea>,An
            // MOVEM -(A0),A1

            byte[] data = new byte[]
            {
                0x22, 0x60
            };

            MegadriveState state = new MegadriveState(new Data(data), 0x00000000, 0x00000000, 0x000000, 0x3FFFFF, 0x0FF0000, 0xFFFFFF);

            state.WriteByte(0x00FF0000, 0xAA);
            state.WriteByte(0x00FF0001, 0xBB);
            state.WriteByte(0x00FF0002, 0xCC);
            state.WriteByte(0x00FF0003, 0xDD);
            state.WriteAReg(0x0, 0x00FF0004);
            state.FetchOpCode();

            var opcode = new MOVEA(state);

            Assert.That(opcode.Assembly, Is.EqualTo($"MOVEA -(A0),A1"));
            Assert.That(opcode.Size, Is.EqualTo(Size.Long));
            Assert.That(state.ReadAReg(0x0), Is.EqualTo(0x00FF0000));
            Assert.That(state.ReadAReg(0x1), Is.EqualTo(0xAABBCCDD));
        }
Exemplo n.º 11
0
        public void CheckAdd_dA0_ToD1()
        {
            // ADD Dn,<ea>
            // 1101 dddD ssmm mxxx
            // 1101 0010 0010 0000  0xD220
            // ADD -(A0),D1

            byte[] data = new byte[]
            {
                0xD2, 0x20
            };

            MegadriveState state = new MegadriveState(new Data(data), 0x00000000, 0x00000000, 0x000000, 0x3FFFFF, 0x0FF0000, 0xFFFFFF);

            state.WriteDReg(0x1, 0x22221111);
            state.WriteAReg(0x0, 0x00FF0001);
            state.WriteByte(0x00FF0000, 0x22);
            state.FetchOpCode();

            var opcode = new ADD(state);

            Assert.That(opcode.Assembly, Is.EqualTo("ADD.B -(A0),D1"));
            Assert.That(state.PC, Is.EqualTo(0x02));
            Assert.That(state.ReadAReg(0x0), Is.EqualTo(0x00FF0000));
            Assert.That(state.ReadDReg(0x1), Is.EqualTo(0x00000033));
            Assert.That(state.ReadByte(0x00FF0000), Is.EqualTo(0x22));
        }
Exemplo n.º 12
0
        public void CheckLoad_d16PC_ToA5()
        {
            // LEA <ea>,An
            // 0100 1011 1111 1010  0x4BFA
            // 0000 0000 0111 1100  0x007C

            // LEA (d16,PC),A5
            // LEA (124,PC),A5

            byte[] data = new byte[]
            {
                0x4B, 0xFA, 0x00, 0x7C
            };

            MegadriveState state = new MegadriveState(new Data(data), 0x00000000, 0x00000000, 0x000000, 0x3FFFFF, 0x0FF0000, 0xFFFFFF);

            state.FetchOpCode();

            var opcode = new LEA(state);

            Assert.That(opcode.Assembly, Is.EqualTo("LEA ($007C,PC),A5"));
            Assert.That(opcode.Size, Is.EqualTo(Size.Long));

            Assert.That(state.PC, Is.EqualTo(0x00000004));
            Assert.That(state.ReadAReg(0x5), Is.EqualTo(0x7E));
        }
Exemplo n.º 13
0
        public void CheckMove_A0i_ToA1()
        {
            // 00ss aaa0 01mm mxxx
            // 0001 0010 0101 1000  0x1258
            // MOVEM <ea>,An
            // MOVEM (A0)+,A1

            byte[] data = new byte[]
            {
                0x12, 0x58
            };

            MegadriveState state = new MegadriveState(new Data(data), 0x00000000, 0x00000000, 0x000000, 0x3FFFFF, 0x0FF0000, 0xFFFFFF);

            state.WriteByte(0x00FF0000, 0xAA);
            state.WriteByte(0x00FF0001, 0xBB);
            state.WriteAReg(0x0, 0x00FF0000);
            state.FetchOpCode();

            var opcode = new MOVEA(state);

            Assert.That(opcode.Assembly, Is.EqualTo($"MOVEA (A0)+,A1"));
            Assert.That(opcode.Size, Is.EqualTo(Size.Word));
            Assert.That(state.ReadAReg(0x0), Is.EqualTo(0x00FF0002));
            Assert.That(state.ReadAReg(0x1), Is.EqualTo(0xAABB));
        }
Exemplo n.º 14
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MOVEUSP"/> class.
        /// </summary>
        /// <param name="state">machine state.</param>
        public MOVEUSP(MegadriveState state)
            : base("010011100110Daaa", state)
        {
            this.direction = this.GetDirection();
            this.register  = this.GetAn();

            if (this.state.Condition_Supervisor)
            {
                switch (this.direction)
                {
                case MoveDirection.MemoryToRegister:
                    throw new NotImplementedException();
                    break;

                case MoveDirection.RegisterToMemory:
                    throw new NotImplementedException();
                    break;

                default:
                    throw new InvalidStateException();
                }
            }
            else
            {
                Writer.Write("TRAP", ConsoleColor.Red);
            }
        }
Exemplo n.º 15
0
        private OpCode decode_8000(MegadriveState state)
        {
            // divu
            // 1000 ddd0 11mm mxxx
            if (state.OpCode.CheckBits("1000xxx011xxxxxx"))
            {
                throw new NotImplementedException("DIVU");
            }

            // divs
            // 1000 ddd1 11mm mxxx
            if (state.OpCode.CheckBits("1000xxx111xxxxxx"))
            {
                throw new NotImplementedException("DIVS");
            }

            // sbcd
            // 1000 xxx1 0000 Mxxx
            if (state.OpCode.CheckBits("1000xxx10000xxxx"))
            {
                throw new NotImplementedException("SBCD");
            }

            // or
            // 1000 dddD ssmm mxxx
            throw new NotImplementedException("OR");
        }
Exemplo n.º 16
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Bcc"/> class.
        /// </summary>
        /// <param name="state">machine state.</param>
        public Bcc(MegadriveState state)
            : base("0110ccccbbbbbbbb", state)
        {
            if (this.Size == Size.Word)
            {
                this.EffectiveAddress = this.FetchEffectiveAddress(EffectiveAddressMode.Immediate, 0x00);
            }

            if (this.Size == Size.Byte)
            {
                this.EffectiveAddress = (byte)this.GetImmediate();
            }

            if (this.CheckCondition())
            {
                if (this.Size == Size.Word)
                {
                    this.state.PC += (uint)((short)this.EffectiveAddress - 2);
                }

                if (this.Size == Size.Byte)
                {
                    this.state.PC += (uint)((sbyte)this.EffectiveAddress);
                }
            }
        }
Exemplo n.º 17
0
        private OpCode decode_E000(MegadriveState state)
        {
            if (state.OpCode.CheckBits("1110xxxx11xxxxxx"))
            {
                return(decode_E0C0(state));
            }

            return(decode_E0X0(state));
        }
Exemplo n.º 18
0
        private OpCode decode_50C0(MegadriveState state)
        {
            if (state.OpCode.CheckBits("0101xxxx11001xxx"))
            {
                return(new DBcc(state));
            }

            // 0101 xxxx 11?? ?xxx
            throw new NotImplementedException("Scc?");
        }
Exemplo n.º 19
0
 private OpCode decode_X000(MegadriveState state)
 {
     if (state.OpCode.GetBits(6, 3) == 0x0001)
     {
         return(new MOVEA(state));
     }
     else
     {
         return(new MOVE(state));
     }
 }
Exemplo n.º 20
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ADDX"/> class.
        /// </summary>
        /// <param name="state">machine state.</param>
        public ADDX(MegadriveState state)
            : base("1101xxx1ss00Dyyy", state)
        {
            throw new NotImplementedException();

            //X — Set the same as the carry bit.
            //N — Set if the result is negative; cleared otherwise.
            //Z — Cleared if the result is nonzero; unchanged otherwise.
            //V — Set if an overflow occurs; cleared otherwise.
            //C — Set if a carry is generated; cleared otherwise.
        }
Exemplo n.º 21
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TST"/> class.
        /// </summary>
        /// <param name="state">machine state.</param>
        public TST(MegadriveState state)
            : base("01001010ssmmmxxx", state)
        {
            this.EffectiveAddress = this.FetchEffectiveAddress();

            var val = this.ReadValueForEffectiveAddress();

            state.Condition_N = this.IsNegative(val);
            state.Condition_Z = this.IsZero(val);
            state.Condition_V = false;
            state.Condition_C = false;
        }
Exemplo n.º 22
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MOVEQ"/> class.
        /// </summary>
        /// <param name="state">machine state</param>
        public MOVEQ(MegadriveState state)
            : base("0111ddd0bbbbbbbb", state)
        {
            this.immediate = this.GetImmediate();
            this.register  = this.GetDn();

            this.state.WriteDReg((byte)this.register, this.immediate);

            this.state.Condition_N = this.IsNegative(this.immediate);
            this.state.Condition_Z = this.IsZero(this.immediate);
            this.state.Condition_V = false;
            this.state.Condition_C = false;
        }
Exemplo n.º 23
0
        private OpCode decode_6000(MegadriveState state)
        {
            if (state.OpCode.CheckBits("01100000xxxxxxxx"))
            {
                return(new BRA(state));
            }

            if (state.OpCode.CheckBits("01100001xxxxxxxx"))
            {
                throw new NotImplementedException("BSR");
            }

            return(new Bcc(state));
        }
Exemplo n.º 24
0
        private OpCode decode_D000(MegadriveState state)
        {
            if (state.OpCode.CheckBits("1101xxxx11xxxxxx"))
            {
                throw new NotImplementedException("ADDA");
            }

            if (state.OpCode.CheckBits("1101xxx1xx000xxx") || state.OpCode.CheckBits("1101xxx1xx001xxx"))
            {
                return(new ADDX(state));
            }

            // add
            return(new ADD(state));
        }
Exemplo n.º 25
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MOVE"/> class.
        /// </summary>
        /// <param name="state">machine state.</param>
        public MOVE(MegadriveState state)
            : base("00ss______mmmxxx", state)
        {
            this.SrcEA = this.FetchEffectiveAddress(this.DecodeEffectiveAddressMode(this.GetSrcM(), this.GetSrcXn()), this.GetSrcXn());
            this.DstEA = this.FetchEffectiveAddress(this.DecodeEffectiveAddressMode(this.GetDstM(), this.GetDstXn()), this.GetDstXn());

            var srcVal = this.ReadValueForEffectiveAddress(this.DecodeEffectiveAddressMode(this.GetSrcM(), this.GetSrcXn()), this.SrcEA, this.GetSrcXn());

            this.WriteValueToEffectiveAddress(this.DecodeEffectiveAddressMode(this.GetDstM(), this.GetDstXn()), this.DstEA, this.GetDstXn(), srcVal, false);

            this.state.Condition_N = this.IsNegative(srcVal);
            this.state.Condition_Z = this.IsZero(srcVal);
            this.state.Condition_V = false;
            this.state.Condition_C = false;
        }
Exemplo n.º 26
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DBcc"/> class.
        /// </summary>
        /// <param name="state">machine state.</param>
        public DBcc(MegadriveState state)
            : base("0101cccc11001ddd", state)
        {
            this.displacement = (short)this.ReadDataUsingPC(this.Size); // always WORD

            if (!this.CheckCondition())
            {
                short dn = (short)(this.state.ReadDReg((byte)this.GetDn()) - 1);
                this.state.WriteDReg((byte)this.GetDn(), (uint)dn);
                if (dn != -1)
                {
                    this.state.PC = (uint)(this.state.PC - 2 + this.displacement);
                }
            }
        }
Exemplo n.º 27
0
        private OpCode decode_0200(MegadriveState state)
        {
            switch (state.OpCode.GetBits(0, 8))
            {
            // 0000 0010 0011 1100
            case 0x023C:
                throw new NotImplementedException("ANDItoCCR");

            // 0000 0010 0111 1100
            case 0x027C:
                throw new NotImplementedException("ANDItoSR");

            default:
                return(new ANDI(state));
            }
        }
Exemplo n.º 28
0
        private OpCode decode_0000(MegadriveState state)
        {
            if (state.OpCode.GetBits(8, 1) == 0x1)
            {
                // MOVEP
                if (state.OpCode.GetBits(3, 3) == 0x1)
                {
                    throw new NotImplementedException("MOVEP");
                }

                // BTST, BCHG, BCLR, BSET
                switch (state.OpCode.GetBits(6, 2))
                {
                case 0x00:
                    return(new BTST(state));

                case 0x01:
                    throw new NotImplementedException("BCHG");

                case 0x02:
                    return(new BCLR(state));

                case 0x03:
                    throw new NotImplementedException("BSET");
                }
            }

            switch (state.OpCode.GetBits(8, 4))
            {
            // 0000 0110 xxxx xxxx
            case 0x0006:
                throw new NotImplementedException("ADDI");

            // 0000 1100 xxxx xxxx
            case 0x000C:
                throw new NotImplementedException("CMPI");

            // 0000 0010 xxxx xxxx
            case 0x0002:
                return(decode_0200(state));

            // TODO: BTST

            default:
                throw new NotImplementedException();
            }
        }
Exemplo n.º 29
0
        public void CheckA5PostIncMoveLongToReg()
        {
            // MOVEM <ea>,<ea>
            // 0100 1100 1101 1101  0x4CDD
            // 0001 1111 0000 0000  0x1F00
            // MOVEM (A5)+,0001111100000000

            byte[] data = new byte[]
            {
                0x4C, 0xDD, 0x1F, 0x00
            };

            MegadriveState state = new MegadriveState(new Data(data), 0x00000000, 0x00000000, 0x000000, 0x3FFFFF, 0x0FF0000, 0xFFFFFF);

            state.WriteAReg(0x5, 0xFF0000);
            for (int i = 0; i < 64; i++)
            {
                state.WriteByte((uint)(0xFF0000 + i), (byte)(0x00 + i));
            }
            state.FetchOpCode();

            var opcode = new MOVEM(state);

            Assert.That(opcode.Assembly, Is.EqualTo("MOVEM (A5)+,%0001111100000000"));
            Assert.That(opcode.Size, Is.EqualTo(Size.Long));

            Assert.That(state.ReadAReg(0x0), Is.EqualTo(0x00010203));
            Assert.That(state.ReadAReg(0x1), Is.EqualTo(0x04050607));
            Assert.That(state.ReadAReg(0x2), Is.EqualTo(0x08090A0B));
            Assert.That(state.ReadAReg(0x3), Is.EqualTo(0x0C0D0E0F));
            Assert.That(state.ReadAReg(0x4), Is.EqualTo(0x10111213));
            Assert.That(state.ReadAReg(0x5), Is.EqualTo(0x00FF0014));
            Assert.That(state.ReadAReg(0x6), Is.EqualTo(0x0000));
            Assert.That(state.ReadAReg(0x7), Is.EqualTo(0x0000));

            Assert.That(state.ReadDReg(0x0), Is.EqualTo(0x0000));
            Assert.That(state.ReadDReg(0x1), Is.EqualTo(0x0000));
            Assert.That(state.ReadDReg(0x2), Is.EqualTo(0x0000));
            Assert.That(state.ReadDReg(0x3), Is.EqualTo(0x0000));
            Assert.That(state.ReadDReg(0x4), Is.EqualTo(0x0000));
            Assert.That(state.ReadDReg(0x5), Is.EqualTo(0x0000));
            Assert.That(state.ReadDReg(0x6), Is.EqualTo(0x0000));
            Assert.That(state.ReadDReg(0x7), Is.EqualTo(0x0000));

            Assert.That(state.PC, Is.EqualTo(0x00000004));
            Assert.That(state.ReadAReg(0x5), Is.EqualTo(0x00FF0014));
        }
Exemplo n.º 30
0
        public void CheckA5PostIncMoveWordToReg()
        {
            // MOVEM <ea>,<ea>
            // 0100 1100 1001 1101  0x4C9D
            // 0000 0000 1110 0000  0x00E0
            // MOVEM (A5)+,0000000011100000

            byte[] data = new byte[]
            {
                0x4C, 0x9D, 0x00, 0xE0
            };

            MegadriveState state = new MegadriveState(new Data(data), 0x00000000, 0x00000000, 0x000000, 0x3FFFFF, 0x0FF0000, 0xFFFFFF);

            state.WriteAReg(0x5, 0xFF0000);
            for (int i = 0; i < 16; i++)
            {
                state.WriteByte((uint)(0xFF0000 + i), (byte)(0x00 + i));
            }
            state.FetchOpCode();

            var opcode = new MOVEM(state);

            Assert.That(opcode.Assembly, Is.EqualTo("MOVEM (A5)+,%0000000011100000"));
            Assert.That(opcode.Size, Is.EqualTo(Size.Word));

            Assert.That(state.ReadAReg(0x0), Is.EqualTo(0x0000));
            Assert.That(state.ReadAReg(0x1), Is.EqualTo(0x0000));
            Assert.That(state.ReadAReg(0x2), Is.EqualTo(0x0000));
            Assert.That(state.ReadAReg(0x3), Is.EqualTo(0x0000));
            Assert.That(state.ReadAReg(0x4), Is.EqualTo(0x0000));
            Assert.That(state.ReadAReg(0x5), Is.EqualTo(0xFF0006));
            Assert.That(state.ReadAReg(0x6), Is.EqualTo(0x0000));
            Assert.That(state.ReadAReg(0x7), Is.EqualTo(0x0000));

            Assert.That(state.ReadDReg(0x0), Is.EqualTo(0x0000));
            Assert.That(state.ReadDReg(0x1), Is.EqualTo(0x0000));
            Assert.That(state.ReadDReg(0x2), Is.EqualTo(0x0000));
            Assert.That(state.ReadDReg(0x3), Is.EqualTo(0x0000));
            Assert.That(state.ReadDReg(0x4), Is.EqualTo(0x0000));
            Assert.That(state.ReadDReg(0x5), Is.EqualTo(0x0001));
            Assert.That(state.ReadDReg(0x6), Is.EqualTo(0x0203));
            Assert.That(state.ReadDReg(0x7), Is.EqualTo(0x0405));

            Assert.That(state.PC, Is.EqualTo(0x00000004));
            Assert.That(state.ReadAReg(0x5), Is.EqualTo(0x00FF0006));
        }