Exemplo n.º 1
0
        public void _Cxkk_RND_vx_byte(byte kk,
                                      byte rand)
        {
            var registers = new RegisterModule();

            var random = new TestRandom(rand);


            var emulator = CHIP8Factory.GetChip8(registers: registers,
                                                 random: random);

            var instructions = new byte[]
            {
                0xC0,                    //Set v0 = kk & random byte
                kk
            };

            emulator.LoadProgram(instructions);

            emulator.Tick += (e,
                              a) =>
            {
                emulator.Stop();
            };

            emulator.Start();

            Assert.Equal(rand & kk,
                         registers.GetGeneralValue(0));
        }
Exemplo n.º 2
0
        public void _8xy3_XOR_vx_vy(byte x,
                                    byte y)
        {
            /*
             * 8xy3 - Performs a bitwise exclusive OR on the values of Vx and Vy, then stores the result in Vx.
             */
            var registers = new RegisterModule();

            var emulator = CHIP8Factory.GetChip8(registers: registers);

            var instructions = new byte[]
            {
                0x60,                    //LD v0 with x,
                x,
                0x61,                    //LD v1 with y
                y,
                0x80,                    //Bitwise xor, store in v0
                0x13
            };

            emulator.LoadProgram(instructions);

            emulator.Start();

            var expectedResult = x ^ y;

            Assert.Equal(expectedResult,
                         registers.GetGeneralValue(0));
        }
Exemplo n.º 3
0
        public void _6xkk_LD_vx_byte()
        {
            /*
             * 6xkk - LD Vx, byte Set Vx = kk. The interpreter puts the value kk into register Vx.
             */
            var registers = new RegisterModule();

            var emulator = CHIP8Factory.GetChip8(registers: registers);

            var instructions = new byte[]
            {
                0x60,                    //LD v0 with byte 0x12
                0x12
            };

            emulator.LoadProgram(instructions);

            emulator.Start();

            Assert.Equal(0x12,
                         registers.GetGeneralValue(0));
        }
Exemplo n.º 4
0
        public void _8xy0_LD_vx_vy()
        {
            /*
             * 8xy0 - Stores the value of register Vy in register Vx.
             */
            var registers = new RegisterModule();

            var emulator = CHIP8Factory.GetChip8(registers: registers);

            var instructions = new byte[]
            {
                0x61,                    //LD v1 with byte 0x12
                0x12,
                0x80,                    // Store value at v1 in v0
                0x10
            };

            emulator.LoadProgram(instructions);

            emulator.Start();

            Assert.Equal(0x12,
                         registers.GetGeneralValue(0));
        }
Exemplo n.º 5
0
        public void _7xkk_LD_vx_byte()
        {
            /*
             * 7xkk - Adds the value kk to the value of register Vx, then stores the result in Vx.
             */
            var registers = new RegisterModule();

            var emulator = CHIP8Factory.GetChip8(registers: registers);

            var instructions = new byte[]
            {
                0x60,                    //LD v0 with byte 0x12
                0x12,
                0x70,                    // Add 0x10 to v0 and save it in v0
                0x10
            };

            emulator.LoadProgram(instructions);

            emulator.Start();

            Assert.Equal(0x22,
                         registers.GetGeneralValue(0));
        }
Exemplo n.º 6
0
        public void _Fx65_LD_Vx_I()
        {
            /*
             * Set registers v0 through vx from memory starting at I
             */

            var registers = new RegisterModule();

            registers.SetI(0x278);

            var startPoint = registers.GetI();

            var memory = new MemoryModule(Enumerable.Repeat((byte)0x0,
                                                            4096));

            memory[startPoint] = 0x7D;

            startPoint++;

            memory[startPoint] = 0x55;

            startPoint++;

            memory[startPoint] = 0x18;

            startPoint++;

            memory[startPoint] = 0x90;

            var emulator = CHIP8Factory.GetChip8(registers: registers,
                                                 mem: memory);

            var instructions = new byte[]
            {
                0xF3,                    //Set v0 - v3 from memory
                0x65
            };

            emulator.LoadProgram(instructions);

            emulator.Tick += (e,
                              a) =>
            {
                emulator.Stop();
            };

            emulator.Start();

            var v0 = registers.GetGeneralValue(0);

            var v1 = registers.GetGeneralValue(1);

            var v2 = registers.GetGeneralValue(2);

            var v3 = registers.GetGeneralValue(3);

            Assert.Equal(0x7D,
                         v0);
            Assert.Equal(0x55,
                         v1);
            Assert.Equal(0x18,
                         v2);
            Assert.Equal(0x90,
                         v3);
        }