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); }
private bool ADD(ushort instruction) { int register = ParserFunctions.GetX(instruction); byte value = ParserFunctions.GetValue(instruction); Register[register] += value; return(false); }
private bool LD(ushort instruction) { byte x = ParserFunctions.GetX(instruction); var value = ParserFunctions.GetValue(instruction); Register[x] = value; return(false); }
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); }
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); }
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); }