예제 #1
0
        private void IncrementInstructionRegister(OpCodeData opCodeData)
        {
            UInt16 instructionRegisterValue = _instructionRegister.GetRegisterValue();
            Byte   vXValue = _registers.GetRegisterValue(opCodeData.X);

            _instructionRegister.SetRegisterValue(value: (UInt16)(instructionRegisterValue + vXValue));
        }
예제 #2
0
        public void Tick()
        {
            UInt16 currentMemoryLocation = _programCounter.GetRegisterValue(0x0);

            Byte[] opCodeBytes = new Byte[2] {
                _memory.GetValueAtLocation(currentMemoryLocation++),
                _memory.GetValueAtLocation(currentMemoryLocation++)
            };
            _programCounter.SetRegisterValue(value: currentMemoryLocation);

            UInt16 currentInstruction = (UInt16)((opCodeBytes[0] << 8) + opCodeBytes[1]);

            Trace.WriteLine(currentInstruction);

            OpCodeData opCodeData = new OpCodeData
            {
                Address = (UInt16)(currentInstruction & 0x0FFF),
                Nibble  = (Byte)(currentInstruction & 0x000F),
                OpCode  = currentInstruction,
                Value   = (Byte)(currentInstruction & 0x00FF),
                X       = (Byte)((currentInstruction & 0x0F00) >> 8),
                Y       = (Byte)((currentInstruction & 0x00F0) >> 4)
            };

            _opCodesDirector.HandleOpCode(opCodeData);
            Trace.WriteLine(_generalPurposeRegisters.DebugString());
            _cpuTimer.Start();
        }
예제 #3
0
        public override void Execute(OpCodeData opCodeData)
        {
            UInt16 currentAddress = _programCounter.GetRegisterValue();

            _stackPointer.Push(currentAddress);
            _programCounter.SetRegisterValue(value: opCodeData.Address);
        }
예제 #4
0
        public override void Execute(OpCodeData opCodeData)
        {
            Byte randomValue = (Byte) new Random().Next(255);
            Byte newValue    = (Byte)(randomValue & opCodeData.Value);

            _registers.SetRegisterValue(opCodeData.X, newValue);
        }
예제 #5
0
        public override void Execute(OpCodeData opCodeData)
        {
            Byte registerValue = _registers.GetRegisterValue(opCodeData.X);

            registerValue += opCodeData.Value;

            _registers.SetRegisterValue(opCodeData.X, registerValue);
        }
예제 #6
0
        public override void Execute(OpCodeData opCodeData)
        {
            Byte   vXValue             = _registers.GetRegisterValue(opCodeData.X);
            UInt16 programCounterValue = _programCounter.GetRegisterValue();

            if (opCodeData.Value == 0x9E)
            {
                if (_keyManager.IsKeyPressed(vXValue) == true)
                {
                    _programCounter.SetRegisterValue(value: (UInt16)(programCounterValue + 2));
                }
            }
            else if (opCodeData.Value == 0xA1)
            {
                if (_keyManager.IsKeyPressed(vXValue) == false)
                {
                    _programCounter.SetRegisterValue(value: (UInt16)(programCounterValue + 2));
                }
            }
        }
예제 #7
0
        public override void Execute(OpCodeData opCodeData)
        {
            Byte registerValue = _registers.GetRegisterValue(opCodeData.X);

            if (registerValue != opCodeData.Value)
            {
                UInt16 programCounter = _programCounter.GetRegisterValue();
                programCounter += 2;
                _programCounter.SetRegisterValue(value: programCounter);
            }
        }
 public override void Execute(OpCodeData opCodeData)
 {
     if (opCodeData.Nibble == 0x0)
     {
         _screen.ClearScreen();
     }
     else if (opCodeData.Nibble == 0xE)
     {
         UInt16 memoryAddress = _stackPointer.Pop();
         _programCounter.SetRegisterValue(value: memoryAddress);
     }
 }
예제 #9
0
        public override void Execute(OpCodeData opCodeData)
        {
            Byte vX = _registers.GetRegisterValue(opCodeData.X);
            Byte vY = _registers.GetRegisterValue(opCodeData.Y);

            if (vX == vY)
            {
                UInt16 programCounter = _programCounter.GetRegisterValue();
                programCounter += 2;
                _programCounter.SetRegisterValue(value: programCounter);
            }
        }
예제 #10
0
        public override void Execute(OpCodeData opCodeData)
        {
            Byte   sizeOfSprite = opCodeData.Nibble;
            Byte   startingX    = _registers.GetRegisterValue(opCodeData.X);
            Byte   startingY    = _registers.GetRegisterValue(opCodeData.Y);
            UInt16 instructionRegisterLocation = _instructionRegister.GetRegisterValue();

            Trace.WriteLine($"{startingX},{startingY}");

            _registers.SetRegisterValue(0xF, 0x0);
            for (Byte spritePosition = 0; spritePosition < sizeOfSprite; spritePosition++)
            {
                Byte     spriteByte = _memory.GetValueAtLocation((UInt16)(instructionRegisterLocation + spritePosition));
                BitArray bitArray   = new BitArray(new Byte[] { spriteByte });

                for (Byte bitArrayIndex = 7; bitArrayIndex > 0; bitArrayIndex--)
                {
                    Byte xPosition = (Byte)((startingX + (7 - bitArrayIndex)) % _screenWidth);
                    Byte yPosition = (Byte)((startingY + spritePosition) % _screenHeight);


                    Boolean oldState    = _screen.GetStateAtLocation(xPosition, yPosition);
                    Boolean spriteState = bitArray[bitArrayIndex];
                    Boolean newState    = oldState ^ spriteState;

                    if (oldState != spriteState)
                    {
                        _screen.SetDirtyFlag();
                    }

                    _screen.SetStateAtLocation(xPosition, yPosition, newState);

                    if (oldState == true && newState == false)
                    {
                        _registers.SetRegisterValue(0xF, 0x1);
                    }
                }
            }
        }
예제 #11
0
 public override void Execute(OpCodeData opCodeData)
 {
     _programCounter.SetRegisterValue(value: opCodeData.Address);
 }
예제 #12
0
 public override void Execute(OpCodeData opCodeData)
 {
     _instructionRegister.SetRegisterValue(value: opCodeData.Address);
 }
예제 #13
0
 public override void Execute(OpCodeData opCodeData)
 {
     _registers.SetRegisterValue(opCodeData.X, opCodeData.Value);
 }
        public override void Execute(OpCodeData opCodeData)
        {
            Byte v0Value = _registers.GetRegisterValue(0x0);

            _programCounter.SetRegisterValue(value: (UInt16)(v0Value + opCodeData.Address));
        }
예제 #15
0
        private void CopyDelayTimerToRegister(OpCodeData opCodeData)
        {
            Byte delayTimerValue = _delayTimer.GetValue();

            _registers.SetRegisterValue(opCodeData.X, delayTimerValue);
        }
예제 #16
0
        private void AddAndCarry(OpCodeData opCodeData)
        {
            Byte vXValue = _registers.GetRegisterValue(opCodeData.X);
            Byte vYValue = _registers.GetRegisterValue(opCodeData.Y);

            UInt16 result = (UInt16)(vXValue + vYValue);

            if (result > 0xFF)
            {
                _registers.SetRegisterValue(0xF, 0x1);
            }

            _registers.SetRegisterValue(opCodeData.X, (Byte)(vXValue + vYValue));
        }