static public Instruction8bit Get8bitInstruction(byte code, byte op1, byte op2) { Instruction8bit instruction = GB8bitInstructions[code]; string operation = instruction.GetOperation(); int index; try { if (op1 > 0x00) { index = operation.IndexOf("*"); operation = operation.Remove(index, 1); operation = operation.Insert(index, BitConverter.ToString(new byte[] { op1 })); instruction = new Instruction8bit(code, operation, GB8bitInstructions[code].size, GB8bitInstructions[code].cycles); } // if op2 is not null or empty if (op2 > 0x00) { index = operation.IndexOf("*"); operation = operation.Remove(index, 1); operation = operation.Insert(index, BitConverter.ToString(new byte[] { op2 })); instruction = new Instruction8bit(code, operation, GB8bitInstructions[code].size, GB8bitInstructions[code].cycles); } } catch (Exception ex) { instruction = new Instruction8bit(code, $"Opcode not found", int.MaxValue, 0); } return(instruction); }
private Instruction8bit Get8bitInstruction(byte code) { int size = Instructions.GB8bitInstructions[code].size; byte op1; byte op2; switch (size) { case 2: if (code == 0xE2 || code == 0xF2 || code == 0x10) { op1 = 0x00; op2 = 0x00; } else { op1 = file[pc + 1]; op2 = 0x00; } break; case 3: // The Gameboy CPU is little endian, which means the least significant byte comes first op1 = file[pc + 2]; op2 = file[pc + 1]; break; default: op1 = 0x00; op2 = 0x00; break; } Instruction8bit instruction = Instructions.Get8bitInstruction(code, op1, op2); return(instruction); }