public static ushort GetInstructionValue(Cpu8086 cpu, OpCodeManager.OpCodeFlag flag, Register segmentPrefix, int instruction, int instructionValue, int instructionDisplacement) { switch (instruction) { case (int)Register.AX: case (int)Register.CX: case (int)Register.DX: case (int)Register.BX: case (int)Register.SP: case (int)Register.BP: case (int)Register.SI: case (int)Register.DI: case (int)Register.IP: case (int)Register.CS: case (int)Register.DS: case (int)Register.ES: case (int)Register.SS: return(cpu.GetRegister((Register)instruction)); case OpCodeManager.ARG_BYTE_REGISTER: return(cpu.GetRegisterU8((Register)instructionValue)); case OpCodeManager.ARG_DEREFERENCE: case OpCodeManager.ARG_MEMORY: var address = GetInstructionRealAddress(cpu, segmentPrefix, instruction, instructionValue, instructionDisplacement); return(flag.Has(OpCodeManager.OpCodeFlag.Size8) ? cpu.ReadU8(address) : cpu.ReadU16(address)); case OpCodeManager.ARG_CONSTANT: return((ushort)instructionValue); default: throw new NotImplementedException(); } }
public static uint GetInstructionRealAddress(Cpu8086 cpu, Register segmentPrefix, int instruction, int instructionValue, int instructionDisplacement) { switch (instruction) { case OpCodeManager.ARG_DEREFERENCE: if (segmentPrefix == Register.Invalid) { segmentPrefix = instructionValue == 6 ? Register.SS : Register.DS; // BP needs SS segment } var addr = GetInstructionAddress(cpu, instruction, instructionValue, instructionDisplacement); return(SegmentToAddress(cpu.GetRegister(segmentPrefix), addr)); case OpCodeManager.ARG_MEMORY: if (segmentPrefix == Register.Invalid) { segmentPrefix = Register.DS; } var address = GetInstructionAddress(cpu, instruction, instructionValue, instructionDisplacement); return(SegmentToAddress(cpu.GetRegister(segmentPrefix), address)); default: throw new NotImplementedException(); } }
public static ushort GetInstructionAddress(Cpu8086 cpu, int instruction, int instructionValue, int instructionDisplacement) { switch (instruction) { case OpCodeManager.ARG_DEREFERENCE: ushort address; switch (instructionValue) { case 0: address = (ushort)(cpu.GetRegister(Register.BX) + cpu.GetRegister(Register.SI)); break; case 1: address = (ushort)(cpu.GetRegister(Register.BX) + cpu.GetRegister(Register.DI)); break; case 2: address = (ushort)(cpu.GetRegister(Register.BP) + cpu.GetRegister(Register.SI)); break; case 3: address = (ushort)(cpu.GetRegister(Register.BP) + cpu.GetRegister(Register.DI)); break; case 4: address = cpu.GetRegister(Register.SI); break; case 5: address = cpu.GetRegister(Register.DI); break; case 6: address = cpu.GetRegister(Register.BP); break; case 7: address = cpu.GetRegister(Register.BX); break; default: throw new NotImplementedException(); } return((ushort)(address + instructionDisplacement)); case OpCodeManager.ARG_MEMORY: return((ushort)instructionValue); default: throw new NotImplementedException(); } }