private void IncrementInstructionRegister(OpCodeData opCodeData) { UInt16 instructionRegisterValue = _instructionRegister.GetRegisterValue(); Byte vXValue = _registers.GetRegisterValue(opCodeData.X); _instructionRegister.SetRegisterValue(value: (UInt16)(instructionRegisterValue + vXValue)); }
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); } }
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(); }
public override void Execute(OpCodeData opCodeData) { UInt16 currentAddress = _programCounter.GetRegisterValue(); _stackPointer.Push(currentAddress); _programCounter.SetRegisterValue(value: opCodeData.Address); }
public override void Execute(OpCodeData opCodeData) { Byte registerValue = _registers.GetRegisterValue(opCodeData.X); registerValue += opCodeData.Value; _registers.SetRegisterValue(opCodeData.X, registerValue); }
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) { 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); } } } }
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)); } } }
public override void Execute(OpCodeData opCodeData) { Byte v0Value = _registers.GetRegisterValue(0x0); _programCounter.SetRegisterValue(value: (UInt16)(v0Value + opCodeData.Address)); }
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)); }