Beispiel #1
0
        private bool SKP(ushort instruction)
        {
            var value = ParserFunctions.GetValue(instruction);
            var x     = ParserFunctions.GetX(instruction);
            var key   = Register[x];

            switch (value)
            {
            case 0x9e:
                if (keyboard.GetValue(key))
                {
                    InstructionPointer += 2;
                }
                break;

            case 0xa1:
                if (!keyboard.GetValue(key))
                {
                    InstructionPointer += 2;
                    break;
                }
                break;

            default:
                throw new InvalidOperationException();
            }
            return(false);
        }
Beispiel #2
0
        private bool ADD(ushort instruction)
        {
            int  register = ParserFunctions.GetX(instruction);
            byte value    = ParserFunctions.GetValue(instruction);

            Register[register] += value;
            return(false);
        }
Beispiel #3
0
        private bool LD(ushort instruction)
        {
            byte x     = ParserFunctions.GetX(instruction);
            var  value = ParserFunctions.GetValue(instruction);

            Register[x] = value;
            return(false);
        }
Beispiel #4
0
        private bool RND(ushort instruction)
        {
            byte randomValue = RandomFunc();
            var  register    = ParserFunctions.GetX(instruction);
            var  mask        = ParserFunctions.GetValue(instruction);

            Register[register] = (byte)(randomValue & mask);
            return(false);
        }
Beispiel #5
0
        private bool REG(ushort instruction)
        {
            byte subcommand = ParserFunctions.GetSubCommand(instruction);
            var  command    = RegisterCommands[subcommand];

            var regX = ParserFunctions.GetX(instruction);
            var regY = ParserFunctions.GetY(instruction);

            command(regX, regY);
            return(false);
        }
Beispiel #6
0
        private bool SE(ushort instruction)
        {
            byte x        = ParserFunctions.GetX(instruction);
            byte regValue = Register[x];
            byte opValue  = ParserFunctions.GetValue(instruction);

            if (regValue == opValue)
            {
                InstructionPointer += 2;
            }
            return(false);
        }
Beispiel #7
0
        private bool SNEV(ushort instruction)
        {
            var regX = ParserFunctions.GetX(instruction);
            var regY = ParserFunctions.GetY(instruction);

            var regValueX = Register[regX];
            var regValueY = Register[regY];

            if (regValueX != regValueY)
            {
                InstructionPointer += 2;
            }

            return(true);
        }
Beispiel #8
0
        private bool SEV(ushort instruction)
        {
            byte x         = ParserFunctions.GetX(instruction);
            byte regValueX = Register[x];

            byte y         = ParserFunctions.GetY(instruction);
            byte regValueY = Register[y];

            if (regValueX == regValueY)
            {
                InstructionPointer += 2;
            }

            return(false);
        }
Beispiel #9
0
        private bool DRW(ushort instruction)
        {
            var Vx    = ParserFunctions.GetX(instruction);
            var Vy    = ParserFunctions.GetY(instruction);
            var x     = Register[Vx];
            var y     = Register[Vy];
            var count = ParserFunctions.GetSubCommand(instruction);

            byte[] sprite = new byte[count];
            for (ushort i = 0; i < count; i++)
            {
                sprite[i] = memory.GetValue((ushort)(AddressRegister + i));
            }
            var collision = SetSprite(x, y, sprite, count);

            Register[0xF] = (byte)collision;
            // Draw screen
            display.Print();

            return(false);
        }
Beispiel #10
0
        bool LDS(ushort instruction)
        {
            var register   = ParserFunctions.GetX(instruction);
            var subcommand = ParserFunctions.GetValue(instruction);

            switch (subcommand)
            {
            case 0x15:
                DelayTimer.Value = Register[register];
                break;

            case 0x07:
                Register[register] = DelayTimer.Value;
                break;

            case 0x18:
                SoundTimer.Value = Register[register];
                break;

            case 0x1e:
                AddressRegister += Register[register];
                break;

            case 0x29:
                AddressRegister = (ushort)(Register[register] * SPRITE_SIZE);
                break;

            case 0x33:
                byte value    = Register[register];
                byte hundreds = (byte)(value / 100);
                byte tens     = (byte)((value - (hundreds * 100)) / 10);
                byte ones     = (byte)(value - ((hundreds * 100) + (tens * 10)));
                memory.SetValue(AddressRegister, hundreds);
                memory.SetValue((ushort)(AddressRegister + 1), tens);
                memory.SetValue((ushort)(AddressRegister + 2), ones);
                break;

            case 0x55:
                for (int i = 0; i <= register; i++)
                {
                    ushort address = (ushort)(AddressRegister + i);
                    memory.SetValue(address, Register[i]);
                }
                break;

            case 0x0a:
                var key = keyboard.WaitForValue();
                Register[register] = key;
                break;

            case 0x65:
                for (int i = 0; i <= register; i++)
                {
                    ushort address = (ushort)(AddressRegister + i);
                    Register[i] = memory.GetValue(address);
                }
                break;

            default:
                throw new NotImplementedException(string.Format("Subcommand {0:x} not implemented", subcommand));
            }

            return(false);
        }