void Se_3(ChipInstruction inst) { if (VRegisters[inst.X] == inst.KK) { IncrementPC(); } }
void Sne_4(ChipInstruction inst) { if (VRegisters[inst.X] != inst.KK) { IncrementPC(); } }
void Load_F65(ChipInstruction inst) { for (int i = 0; i <= inst.X; i++) { VRegisters[i] = Memory[AddressRegister + i]; } }
void Sne_9(ChipInstruction inst) { if (VRegisters[inst.X] != VRegisters[inst.Y]) { IncrementPC(); } }
void Load_F85(ChipInstruction inst) { for (int i = 0; i <= inst.X; i++) { VRegisters[i] = RPLRegisters[i]; } }
void Se_5(ChipInstruction inst) { if (VRegisters[inst.X] == VRegisters[inst.Y]) { IncrementPC(); } }
void Load_F33(ChipInstruction inst) { byte val = VRegisters[inst.X]; Memory[AddressRegister] = (byte)(val / 100); Memory[AddressRegister + 1] = (byte)((val % 100) / 10); Memory[AddressRegister + 2] = (byte)((val % 100) % 10); }
void Load_F07(ChipInstruction inst) { if (DelayTimer < 0) { DelayTimer = 0; } this.VRegisters[inst.X] = (byte)this.DelayTimer; }
protected void OnPixelSet(ChipInstruction inst) { m_VRegs[0xF] = 0; byte x = m_VRegs[inst.X]; byte y = m_VRegs[inst.Y]; byte read = 0; if (inst.N > 0) { // Loop through the sprite bytes by N for (byte i = 0; i < inst.N; i++) { // Get the next byte of the sprite data read = Memory.ReadByte((int)(m_IReg + i)); // Sprite is always 8 in width, loop through each bit for (byte j = 0; j < 8; j++) { // If we hit an on bit then Set a pixel at X, Y if ((read & (0x80 >> j)) != 0) { // If we colliude, set VF if (VideoInterface.SetPixel((x + j), (y + i))) { m_VRegs[0xF] = 1; } } } } } else { for (int k = 0; k < 0x10; k++) { ushort data = Tools.Create16(Memory.ReadByte((int)(m_IReg + (k << 1))), Memory.ReadByte((int)(m_IReg + (k << 1) + 1))); for (int m = 0; m < 0x10; m++) { if ((data & (((int)0x8000) >> m)) != 0) { if (VideoInterface.SetPixel((x + m), (y + k))) { m_VRegs[0xF] = 1; } } } } } if (m_VRegs[0xF] == 1 && m_AntiFlickerHack) { return; } VideoInterface.RenderWait(); }
public void Step(int cycles) { while (cycles > 0) { cycles--; byte a = SystemMemory.ReadByte(m_CodeEngine.PC); byte b = SystemMemory.ReadByte(m_CodeEngine.PC + 1); ushort data = Tools.Create16(a, b); ChipOpCode opcode = Disassembler.DecodeInstruction(data); //Console.WriteLine("Instuction: " + opcode.ToString()); //Console.WriteLine(m_CodeEngine.PC.ToString("X2") + " " + opcode.ToString()); ChipInstruction inst = new ChipInstruction(data, opcode); inst.Address = m_CodeEngine.PC; m_CodeEngine.IncrementPC(); if (m_PatchEngine.PatchAddress(m_CodeEngine, (ushort)(m_CodeEngine.PC - 2))) { continue; } if (opcode == ChipOpCode.Unknown) { if (data != 0) { //Console.WriteLine(m_CodeEngine.PC.ToString("X2")); Console.WriteLine("Syscall: " + inst.NNN.ToString("x")); if (m_UseHybridDynarec) { if (inst.NNN < SystemMemory.Size) { m_HybridDynarec.Execute(inst.NNN, m_CodeEngine); } else { Console.WriteLine("1802 Call is beyond memory bounds! (" + inst.NNN.ToString("X4") + ")"); } } else { Console.WriteLine("Syscall Emitter Disabled!"); } } else { Console.WriteLine("Warning: 0 opcode doing Nop!"); } } else { m_CodeEngine.Call(inst); } } }
void Ret(ChipInstruction inst) { if (Stack.Count > 0) { PC = Stack.Pop(); } else { PC = 512; } }
void Sknp(ChipInstruction inst) { if (VRegisters[inst.X] != PressedKey) { IncrementPC(); } else { //Console.WriteLine("Checked for unpressed key: " + VRegisters[inst.X].ToString()); } }
void Add_F(ChipInstruction inst) { if (((int)AddressRegister + (int)VRegisters[inst.X]) >= 0x1000) { AddressRegister = (ushort)Memory.Size; VRegisters[0xF] = 1; } else { AddressRegister += VRegisters[inst.X]; } }
public override void Call(ChipInstruction inst) { OpcodeHandler handler; if (m_MethodCallTable != null) { if (this.m_MethodCallTable.TryGetValue(inst.OpCode, out handler)) { handler.Invoke(inst); } } }
void Subn(ChipInstruction inst) { if (VRegisters[inst.Y] >= VRegisters[inst.X]) { VRegisters[0xF] = 1; } else { VRegisters[0xF] = 0; } VRegisters[inst.X] = (byte)(VRegisters[inst.Y] - VRegisters[inst.X]); }
void Sub(ChipInstruction inst) { if (VRegisters[inst.X] > VRegisters[inst.Y]) { VRegisters[0xF] = 1; } else { VRegisters[0xF] = 0; } VRegisters[inst.X] -= VRegisters[inst.Y]; }
void Shl(ChipInstruction inst) { if (((VRegisters[inst.X] & 0x80) >> 7) == 1) { VRegisters[0xF] = 1; } else { VRegisters[0xF] = 0; } VRegisters[inst.X] *= 2; }
void Shr(ChipInstruction inst) { if ((VRegisters[inst.X] & 1) == 1) { VRegisters[0xF] = 1; } else { VRegisters[0xF] = 0; } VRegisters[inst.X] /= 2; }
void Add_8(ChipInstruction inst) { int result = VRegisters[inst.X] + VRegisters[inst.Y]; if (result > (int)byte.MaxValue) { VRegisters[0xF] = 1; } else { VRegisters[0xF] = 0; } VRegisters[inst.X] = (byte)result; }
void Load_F0A(ChipInstruction inst) { OnWaitForKey(); VRegisters[inst.X] = PressedKey; }
private void ScrollDown(ChipInstruction inst) { OnPixelScroll(2, inst.N); }
private void Drw(ChipInstruction inst) { OnPixelSet(inst); }
private void Clr(ChipInstruction inst) { OnScreenClear(); }
void Load_F30(ChipInstruction inst) { AddressRegister = (ushort)(80 + (VRegisters[inst.X] * 10)); }
void Exit(ChipInstruction inst) { return; }
void ExtOff(ChipInstruction inst) { VideoInterface.Initialize(ChipMode.Chip8); }
void ExtOn(ChipInstruction inst) { VideoInterface.Initialize(ChipMode.SuperChip); }
void Load_DT(ChipInstruction inst) { OnSetDelayTimer(VRegisters[inst.X]); }
void Load_F29(ChipInstruction inst) { AddressRegister = (ushort)(VRegisters[inst.X] * 5); }
void Load_ST(ChipInstruction inst) { OnSetSoundTimer(VRegisters[inst.X]); }