public void StmibLdmda_StoreThreeRegisters_RegistersCorrect()
        {
            const uint targetAddress = InternalWramRegion.REGION_START + 0x1000;

            AgbCpu cpu = CpuUtil.CreateCpu();

            FillRegistersWithDummyData(cpu);

            cpu.CurrentRegisterSet.GetRegister(0) = targetAddress;

            CpuUtil.RunCpu(cpu, new uint[]
            {
                0xA200A0E9 // STMIB r0!, {r1, r5, r7}
            }, true);

            Assert.Equal((uint)targetAddress + 0xC, cpu.CurrentRegisterSet.GetRegister(0));
            Assert.Equal((uint)0x11111111, cpu.MemoryMap.ReadU32(targetAddress + (1 * 4)));
            Assert.Equal((uint)0x55555555, cpu.MemoryMap.ReadU32(targetAddress + (2 * 4)));
            Assert.Equal((uint)0x77777777, cpu.MemoryMap.ReadU32(targetAddress + (3 * 4)));

            CpuUtil.RunCpu(cpu, new uint[]
            {
                0xA20030E8 // LDMDA r0!, {r1, r5, r7}
            }, true);

            Assert.Equal((uint)targetAddress, cpu.CurrentRegisterSet.GetRegister(0));
            Assert.Equal((uint)0x11111111, cpu.CurrentRegisterSet.GetRegister(1));
            Assert.Equal((uint)0x55555555, cpu.CurrentRegisterSet.GetRegister(5));
            Assert.Equal((uint)0x77777777, cpu.CurrentRegisterSet.GetRegister(7));
        }
        public void Stm_StoreAllRegistersExceptPcAndPostIncrement_MemoryCorrect()
        {
            const uint targetAddress = InternalWramRegion.REGION_START + 0x1000;

            AgbCpu cpu = CpuUtil.CreateCpu();

            FillRegistersWithDummyData(cpu);

            cpu.CurrentRegisterSet.GetRegister(0) = targetAddress;

            CpuUtil.RunCpu(cpu, new uint[]
            {
                0xFEFF80E8 // STMIA r0, {r1-r14}
            }, true);

            Assert.Equal((uint)0x11111111, cpu.MemoryMap.ReadU32(targetAddress + (0 * 4)));
            Assert.Equal((uint)0x22222222, cpu.MemoryMap.ReadU32(targetAddress + (1 * 4)));
            Assert.Equal((uint)0x33333333, cpu.MemoryMap.ReadU32(targetAddress + (2 * 4)));
            Assert.Equal((uint)0x44444444, cpu.MemoryMap.ReadU32(targetAddress + (3 * 4)));
            Assert.Equal((uint)0x55555555, cpu.MemoryMap.ReadU32(targetAddress + (4 * 4)));
            Assert.Equal((uint)0x66666666, cpu.MemoryMap.ReadU32(targetAddress + (5 * 4)));
            Assert.Equal((uint)0x77777777, cpu.MemoryMap.ReadU32(targetAddress + (6 * 4)));
            Assert.Equal((uint)0x88888888, cpu.MemoryMap.ReadU32(targetAddress + (7 * 4)));
            Assert.Equal((uint)0x99999999, cpu.MemoryMap.ReadU32(targetAddress + (8 * 4)));
            Assert.Equal((uint)0xAAAAAAAA, cpu.MemoryMap.ReadU32(targetAddress + (9 * 4)));
            Assert.Equal((uint)0xBBBBBBBB, cpu.MemoryMap.ReadU32(targetAddress + (10 * 4)));
            Assert.Equal((uint)0xCCCCCCCC, cpu.MemoryMap.ReadU32(targetAddress + (11 * 4)));
            Assert.Equal((uint)0xDDDDDDDD, cpu.MemoryMap.ReadU32(targetAddress + (12 * 4)));
            Assert.Equal((uint)0xEEEEEEEE, cpu.MemoryMap.ReadU32(targetAddress + (13 * 4)));
            Assert.Equal(InternalWramRegion.REGION_START + 12, cpu.MemoryMap.ReadU32(targetAddress + (14 * 4)));
        }
        public void PushPop_PushAndPopThreeRegisters_RegistersCorrect()
        {
            const uint targetAddress = InternalWramRegion.REGION_START + 0x1000;

            AgbCpu cpu = CpuUtil.CreateCpu();

            FillRegistersWithDummyData(cpu);

            cpu.CurrentRegisterSet.GetRegister(CpuUtil.SP) = targetAddress;

            CpuUtil.RunCpu(cpu, new uint[]
            {
                0xA2402DE9 // PUSH {r1, r5, r7, LR}
            }, true);

            cpu.CurrentRegisterSet.GetRegister(1)          = 0xDEADBEEF;
            cpu.CurrentRegisterSet.GetRegister(5)          = 0xCAFEBABE;
            cpu.CurrentRegisterSet.GetRegister(7)          = 0xFEEDFACE;
            cpu.CurrentRegisterSet.GetRegister(CpuUtil.LR) = 0xF00DC0DE;

            CpuUtil.RunCpu(cpu, new uint[]
            {
                0xA240BDE8 // POP {r1, r5, r7, LR}
            }, true);

            Assert.Equal((uint)0x11111111, cpu.CurrentRegisterSet.GetRegister(1));
            Assert.Equal((uint)0x55555555, cpu.CurrentRegisterSet.GetRegister(5));
            Assert.Equal((uint)0x77777777, cpu.CurrentRegisterSet.GetRegister(7));
            Assert.Equal((uint)0xEEEEEEEE, cpu.CurrentRegisterSet.GetRegister(CpuUtil.LR));
        }
        public void Branch_BranchWithPositiveOffset_PcCorrect()
        {
            AgbCpu cpu = CpuUtil.CreateCpu();

            CpuUtil.RunCpu(cpu, new ushort[]
            {
                0xE3FF // B #2046
            }, true);

            Assert.Equal(InternalWramRegion.REGION_START + 0x4 + 2046, cpu.CurrentRegisterSet.GetRegister(CpuUtil.PC));
        }
        public void Branch_LoadHiBits_LrCorrect()
        {
            AgbCpu cpu = CpuUtil.CreateCpu();

            CpuUtil.RunCpu(cpu, new ushort[]
            {
                0xF3FF
            }, true);

            Assert.Equal(cpu.CurrentRegisterSet.GetRegister(CpuUtil.PC) + 2 + (0b01111111111 << 12), cpu.CurrentRegisterSet.GetRegister(CpuUtil.LR));
        }
Exemplo n.º 6
0
        public void Msr_SetCpsrModeByImmediate_ModeCorrect()
        {
            AgbCpu cpu = CpuUtil.CreateCpu();

            CpuUtil.RunCpu(cpu, new uint[]
            {
                0xE329F01F // MSR CPSR, #0x1F
            });

            Assert.Equal(CpuMode.System, cpu.CurrentStatus.Mode);
        }
Exemplo n.º 7
0
        public void BranchExchange_BranchToPcAtHalfWordBoundary_PcSetToNearestWordBoundaryAndInArmMode()
        {
            AgbCpu cpu = CpuUtil.CreateCpu();

            CpuUtil.RunCpu(cpu, new ushort[]
            {
                0xff47 // BX PC
            });

            Assert.Equal(InternalWramRegion.REGION_START + 0x4, cpu.CurrentRegisterSet.GetRegister(CpuUtil.PC));
            Assert.False(cpu.CurrentStatus.Thumb);
        }
Exemplo n.º 8
0
        public void Subtract_SubtractImmediateFromRegZero_RegZeroCorrect()
        {
            AgbCpu cpu = CpuUtil.CreateCpu();

            cpu.CurrentRegisterSet.GetRegister(0) = 0x0000F000;

            CpuUtil.RunCpu(cpu, new ushort[]
            {
                0xff38 // SUB r0, #0xff
            });

            Assert.Equal((uint)0x0000EF01, cpu.CurrentRegisterSet.GetRegister(0));
        }
Exemplo n.º 9
0
        public void Add_AddImmediateToRegOne_RegZeroCorrect()
        {
            AgbCpu cpu = CpuUtil.CreateCpu();

            cpu.CurrentRegisterSet.GetRegister(0) = 0x0000F000;

            CpuUtil.RunCpu(cpu, new ushort[]
            {
                0xff30 // ADD r0, #0xff
            });

            Assert.Equal((uint)0x0000F0FF, cpu.CurrentRegisterSet.GetRegister(0));
        }
Exemplo n.º 10
0
        public void Branch_BranchWithNegativeOffsetAndPassingCondition_PcCorrect()
        {
            AgbCpu cpu = CpuUtil.CreateCpu();

            cpu.CurrentStatus.Zero = true;

            CpuUtil.RunCpu(cpu, new ushort[]
            {
                0xD080 // B{cond} #0xFF
            }, true);

            Assert.Equal(InternalWramRegion.REGION_START + 0x4 - 256, cpu.CurrentRegisterSet.GetRegister(CpuUtil.PC));
        }
        public void Move_MoveImmediateToRegZero_RegZeroCorrect()
        {
            AgbCpu cpu = CpuUtil.CreateCpu();

            cpu.CurrentRegisterSet.GetRegister(0) = 0xDEADBEEF;

            CpuUtil.RunCpu(cpu, new uint[]
            {
                0xE3A00EFF // MOV r0, #0x0FF0
            });

            Assert.Equal((uint)0x00000FF0, cpu.CurrentRegisterSet.GetRegister(0));
        }
Exemplo n.º 12
0
        public void AddToSp_WithPositiveOffset_SpCorrect()
        {
            AgbCpu cpu = CpuUtil.CreateCpu();

            cpu.CurrentRegisterSet.GetRegister(CpuUtil.SP) = InternalWramRegion.REGION_START;

            CpuUtil.RunCpu(cpu, new ushort[]
            {
                0xB07F // ADD SP, #0x1FC
            }, true);

            Assert.Equal(InternalWramRegion.REGION_START + 0x1FC, cpu.CurrentRegisterSet.GetRegister(CpuUtil.SP));
        }
Exemplo n.º 13
0
        public void MoveNegative_MvnWithRegOne_RegZeroCorrect()
        {
            AgbCpu cpu = CpuUtil.CreateCpu();

            cpu.CurrentRegisterSet.GetRegister(0) = 0xDEADBEEF;
            cpu.CurrentRegisterSet.GetRegister(1) = 0x000000FF;

            CpuUtil.RunCpu(cpu, new ushort[]
            {
                0xc843 // MVN r0, r1
            });

            Assert.Equal((uint)0xFFFFFF00, cpu.CurrentRegisterSet.GetRegister(0));
        }
Exemplo n.º 14
0
        public void Msr_MoveRegZeroToCpsr_CpsrCorrect()
        {
            AgbCpu cpu = CpuUtil.CreateCpu();

            cpu.CurrentRegisterSet.GetRegister(0) = 0b11111000000000000000000011110000;

            CpuUtil.RunCpu(cpu, new uint[]
            {
                0xE129F000 // MSR CPSR, r0
            });

            Assert.Equal((uint)0b11111000000000000000000011110000, cpu.CurrentStatus.RegisterValue);
            Assert.Equal((uint)0b11111000000000000000000011110000, cpu.CurrentRegisterSet.GetRegister(0));
        }
Exemplo n.º 15
0
        public void Msr_SetCpsrFlagsByImmediate_FlagsCorrect()
        {
            AgbCpu cpu = CpuUtil.CreateCpu();

            CpuUtil.RunCpu(cpu, new uint[]
            {
                0xE328F20F // MSR CPSR, #0xF0000000
            });

            Assert.True(cpu.CurrentStatus.Negative);
            Assert.True(cpu.CurrentStatus.Zero);
            Assert.True(cpu.CurrentStatus.Carry);
            Assert.True(cpu.CurrentStatus.Overflow);
        }
        public void Branch_BranchWithNoLoadedBits_PcCorrect()
        {
            AgbCpu cpu = CpuUtil.CreateCpu();

            cpu.CurrentRegisterSet.GetRegister(CpuUtil.LR) = 0xDEADBEEF;

            CpuUtil.RunCpu(cpu, new ushort[]
            {
                0xF800
            }, true);

            Assert.Equal(InternalWramRegion.REGION_START + 0x2 + 0x1, cpu.CurrentRegisterSet.GetRegister(CpuUtil.LR));
            Assert.Equal(0xDEADBEEF, cpu.CurrentRegisterSet.GetRegister(CpuUtil.PC));
        }
Exemplo n.º 17
0
        public void BitClear_BicWithRegZeroAndRegOne_RegZeroCorrect()
        {
            AgbCpu cpu = CpuUtil.CreateCpu();

            cpu.CurrentRegisterSet.GetRegister(0) = 0x000000FF;
            cpu.CurrentRegisterSet.GetRegister(1) = 0xFFFFFF00;

            CpuUtil.RunCpu(cpu, new ushort[]
            {
                0x8843 // BIC r0, r1
            });

            Assert.Equal((uint)0x000000FF, cpu.CurrentRegisterSet.GetRegister(0));
            Assert.Equal((uint)0xFFFFFF00, cpu.CurrentRegisterSet.GetRegister(1));
        }
Exemplo n.º 18
0
        public void Multiply_RegOneAndRegTwo_RegZeroCorrect()
        {
            AgbCpu cpu = CpuUtil.CreateCpu();

            cpu.CurrentRegisterSet.GetRegister(0) = 0xFFFFFFF6;
            cpu.CurrentRegisterSet.GetRegister(1) = 0x00000014;

            CpuUtil.RunCpu(cpu, new ushort[]
            {
                0x4843, // MUL r0, r1
            });

            Assert.Equal((uint)0xFFFFFF38, cpu.CurrentRegisterSet.GetRegister(0));
            Assert.Equal((uint)0x00000014, cpu.CurrentRegisterSet.GetRegister(1));
        }
Exemplo n.º 19
0
        public void Orr_OrRegZeroAndRegOne_RegZeroCorrect()
        {
            AgbCpu cpu = CpuUtil.CreateCpu();

            cpu.CurrentRegisterSet.GetRegister(0) = 0xCAFE0000;
            cpu.CurrentRegisterSet.GetRegister(1) = 0x0000BABE;

            CpuUtil.RunCpu(cpu, new ushort[]
            {
                0x0843 // AND r0, r1
            });

            Assert.Equal((uint)0xCAFEBABE, cpu.CurrentRegisterSet.GetRegister(0));
            Assert.Equal((uint)0x0000BABE, cpu.CurrentRegisterSet.GetRegister(1));
        }
Exemplo n.º 20
0
        public void Negate_SubtractZeroFromRegOne_RegZeroCorrect()
        {
            AgbCpu cpu = CpuUtil.CreateCpu();

            cpu.CurrentRegisterSet.GetRegister(0) = 0xDEADBEEF;
            cpu.CurrentRegisterSet.GetRegister(1) = 0x00001000;

            CpuUtil.RunCpu(cpu, new ushort[]
            {
                0x4842 // NEG r0, r1
            });

            Assert.Equal((uint)0xFFFFF000, cpu.CurrentRegisterSet.GetRegister(0));
            Assert.Equal((uint)0x00001000, cpu.CurrentRegisterSet.GetRegister(1));
        }
Exemplo n.º 21
0
        public void BranchExchange_BranchToRegEight_PcCorrectAndInThumbMode()
        {
            AgbCpu cpu = CpuUtil.CreateCpu();

            cpu.CurrentRegisterSet.GetRegister(8) = InternalWramRegion.REGION_START + 1;

            CpuUtil.RunCpu(cpu, new ushort[]
            {
                0xc747 // BX r8
            });

            Assert.Equal(InternalWramRegion.REGION_START, cpu.CurrentRegisterSet.GetRegister(CpuUtil.PC));
            Assert.Equal(InternalWramRegion.REGION_START + 1, cpu.CurrentRegisterSet.GetRegister(8));
            Assert.True(cpu.CurrentStatus.Thumb);
        }
        public void Branch_BranchWithLoadedHiBits_PcCorrect()
        {
            AgbCpu cpu = CpuUtil.CreateCpu();

            cpu.CurrentRegisterSet.GetRegister(CpuUtil.LR) = 0xDEADBEEF;

            CpuUtil.RunCpu(cpu, new ushort[]
            {
                0xF3FF,
                0xFBFF
            }, true);

            Assert.Equal(InternalWramRegion.REGION_START + 0x4 + 0x1, cpu.CurrentRegisterSet.GetRegister(CpuUtil.LR));
            Assert.Equal((uint)0x33FF802, cpu.CurrentRegisterSet.GetRegister(CpuUtil.PC)); // TODO: is this correct?
        }
Exemplo n.º 23
0
        public void BranchAndExchange_BranchToRegZero_PcCorrect()
        {
            const uint targetAddress = InternalWramRegion.REGION_START + 0x1000;

            AgbCpu cpu = CpuUtil.CreateCpu();

            cpu.CurrentRegisterSet.GetRegister(0) = targetAddress;

            CpuUtil.RunCpu(cpu, new uint[]
            {
                0xE12FFF10 // BX r0
            });

            Assert.Equal(targetAddress, cpu.CurrentRegisterSet.GetRegister(CpuUtil.PC));
        }
Exemplo n.º 24
0
        public void Move_MoveRegNineToRegEight_RegEightCorrect()
        {
            AgbCpu cpu = CpuUtil.CreateCpu();

            cpu.CurrentRegisterSet.GetRegister(8) = 0xCAFEBABE;
            cpu.CurrentRegisterSet.GetRegister(9) = 0xDEADBEEF;

            CpuUtil.RunCpu(cpu, new ushort[]
            {
                0xC846 // MOV r8, r9
            });

            Assert.Equal((uint)0xDEADBEEF, cpu.CurrentRegisterSet.GetRegister(8));
            Assert.Equal((uint)0xDEADBEEF, cpu.CurrentRegisterSet.GetRegister(9));
        }
        public void Move_MoveRegOneToRegZero_RegZeroCorrect()
        {
            AgbCpu cpu = CpuUtil.CreateCpu();

            cpu.CurrentRegisterSet.GetRegister(0) = 0xDEADBEEF;
            cpu.CurrentRegisterSet.GetRegister(1) = 0xCAFEBABE;

            CpuUtil.RunCpu(cpu, new uint[]
            {
                0xE1A00001 // MOV r0, r1
            });

            Assert.Equal(0xCAFEBABE, cpu.CurrentRegisterSet.GetRegister(0));
            Assert.Equal(0xCAFEBABE, cpu.CurrentRegisterSet.GetRegister(1));
        }
        public void And_AndRegOneAndImmediate_RegZeroCorrect()
        {
            AgbCpu cpu = CpuUtil.CreateCpu();

            cpu.CurrentRegisterSet.GetRegister(0) = 0xDEADBEEF;
            cpu.CurrentRegisterSet.GetRegister(1) = 0xCAFEBABE;

            CpuUtil.RunCpu(cpu, new uint[]
            {
                0xE2010CFF // AND r1, #0xFF00
            });

            Assert.Equal((uint)0x0000BA00, cpu.CurrentRegisterSet.GetRegister(0));
            Assert.Equal(0xCAFEBABE, cpu.CurrentRegisterSet.GetRegister(1));
        }
Exemplo n.º 27
0
        public void Eor_RegOneWithRegTwo_RegZeroCorrect()
        {
            AgbCpu cpu = CpuUtil.CreateCpu();

            cpu.CurrentRegisterSet.GetRegister(0) = 0xCAFEBABE;
            cpu.CurrentRegisterSet.GetRegister(1) = 0xDEADBEEF;

            CpuUtil.RunCpu(cpu, new ushort[]
            {
                0x4840 // EOR r0, r1
            });

            Assert.Equal((uint)0x14530451, cpu.CurrentRegisterSet.GetRegister(0));
            Assert.Equal((uint)0xDEADBEEF, cpu.CurrentRegisterSet.GetRegister(1));
        }
        public void GetRelativeAddress_LoadRegSevenWithPcRelativeAddress_RegSevenCorrect()
        {
            const uint targetAddress = InternalWramRegion.REGION_START + 0x4 + 0x3FC;

            AgbCpu cpu = CpuUtil.CreateCpu();

            cpu.CurrentRegisterSet.GetRegister(7) = 0xDEADBEEF;

            CpuUtil.RunCpu(cpu, new ushort[]
            {
                0xA7FF // ADD r7, PC, #0x3FC
            }, true);

            Assert.Equal(targetAddress, cpu.CurrentRegisterSet.GetRegister(7));
        }
        public void Sub_ImmediateToRegOne_RegZeroCorrect()
        {
            AgbCpu cpu = CpuUtil.CreateCpu();

            cpu.CurrentRegisterSet.GetRegister(0) = 0xDEADBEEF;
            cpu.CurrentRegisterSet.GetRegister(1) = 0x0000F000;

            CpuUtil.RunCpu(cpu, new ushort[]
            {
                0xC81F // SUB r0, r1, #7
            });

            Assert.Equal((uint)0x0000F000 - 0x7, cpu.CurrentRegisterSet.GetRegister(0));
            Assert.Equal((uint)0x0000F000, cpu.CurrentRegisterSet.GetRegister(1));
        }
Exemplo n.º 30
0
        public void Lsr_ShiftRegZeroRightByRegOne_RegZeroCorrect()
        {
            AgbCpu cpu = CpuUtil.CreateCpu();

            cpu.CurrentRegisterSet.GetRegister(0) = 0xFF800000;
            cpu.CurrentRegisterSet.GetRegister(1) = 0xFEFEFE18;

            CpuUtil.RunCpu(cpu, new ushort[]
            {
                0xc840 // LSR r0, r1
            });

            Assert.Equal((uint)0x000000FF, cpu.CurrentRegisterSet.GetRegister(0));
            Assert.Equal((uint)0xFEFEFE18, cpu.CurrentRegisterSet.GetRegister(1));
            Assert.True(cpu.CurrentStatus.Carry);
        }