public void Dispatch(Cpu8086 cpu, OpCodeManager.Instruction instruction) { var al = cpu.GetRegisterU8(Register.AL); var flags = cpu.GetFlags(); if ((al & 0xF) > 9 || flags.Has(FlagsRegister.Auxiliary)) { var ah = cpu.GetRegisterU8(Register.AH); al = (byte)((al + 6) & 0x0F); ah++; cpu.SetRegisterU8(Register.AH, ah); flags |= FlagsRegister.Carry | FlagsRegister.Auxiliary; } else { al &= 0x0F; flags &= ~(FlagsRegister.Carry | FlagsRegister.Auxiliary); } flags &= ~(FlagsRegister.Parity | FlagsRegister.Zero | FlagsRegister.Sign); flags |= (InstructionHelper.ParityLookup[al] ? FlagsRegister.Parity : 0) | (al == 0 ? FlagsRegister.Zero : 0) | ((al & 0x80) != 0 ? FlagsRegister.Sign : 0); cpu.SetFlags(flags); cpu.SetRegisterU8(Register.AL, al); }
public void Dispatch(Cpu8086 cpu, OpCodeManager.Instruction instruction) { ushort value1; ushort value2; byte size; if (instruction.Flag.Has(OpCodeManager.OpCodeFlag.Size8)) { value1 = cpu.GetRegisterU8(Register.AL); value2 = cpu.ReadU8(InstructionHelper.SegmentToAddress(cpu.GetRegister(Register.ES), cpu.GetRegister(Register.DI))); size = 1; } else { value1 = cpu.GetRegister(Register.AX); value2 = cpu.ReadU16(InstructionHelper.SegmentToAddress(cpu.GetRegister(Register.ES), cpu.GetRegister(Register.DI))); size = 2; } var result = value1 - value2; InstructionHelper.CalculateSubFlags(cpu, instruction.Flag, value1, value2, result); if (!cpu.GetFlags().Has(FlagsRegister.Direction)) { cpu.IncRegister(Register.DI, size); } else { cpu.DecRegister(Register.DI, size); } }
public void Dispatch(Cpu8086 cpu, OpCodeManager.Instruction instruction) { var al = cpu.GetRegisterU8(Register.AL); var oldAl = al; var flags = cpu.GetFlags(); var oldCarry = flags.Has(FlagsRegister.Carry); flags &= ~FlagsRegister.Carry; if ((al & 0xF) > 9 || flags.Has(FlagsRegister.Auxiliary)) { al -= 6; if (oldCarry || (al > oldAl)) { flags |= FlagsRegister.Carry; } else { flags &= ~FlagsRegister.Carry; } flags |= FlagsRegister.Auxiliary; } else { flags &= ~FlagsRegister.Auxiliary; } if (oldAl > 0x99 || oldCarry) { al -= 0x60; flags |= FlagsRegister.Carry; } else { flags &= ~FlagsRegister.Carry; } flags &= ~(FlagsRegister.Parity | FlagsRegister.Zero | FlagsRegister.Sign); flags |= (InstructionHelper.ParityLookup[al] ? FlagsRegister.Parity : 0) | (al == 0 ? FlagsRegister.Zero : 0) | ((al & 0x80) != 0 ? FlagsRegister.Sign : 0); cpu.SetFlags(flags); cpu.SetRegister(Register.AL, al); }
private ushort ProcessExchangeSecond(Cpu8086 cpu, OpCodeManager.Instruction instruction, ushort value) { ushort tmp; switch (instruction.Argument2) { 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: tmp = cpu.GetRegister((Register)instruction.Argument2); cpu.SetRegister((Register)instruction.Argument2, (byte)value); break; case OpCodeManager.ARG_BYTE_REGISTER: tmp = cpu.GetRegisterU8((Register)instruction.Argument2Value); cpu.SetRegisterU8((Register)instruction.Argument2Value, (byte)value); break; case OpCodeManager.ARG_DEREFERENCE: case OpCodeManager.ARG_MEMORY: var address = InstructionHelper.GetInstructionRealAddress(cpu, instruction.SegmentPrefix, instruction.Argument2, instruction.Argument2Value, instruction.Argument2Displacement); tmp = cpu.ReadU16(address); cpu.WriteU16(address, value); break; default: throw new NotImplementedException(); } return(tmp); }
public void Dispatch(Cpu8086 cpu, OpCodeManager.Instruction instruction) { var address = InstructionHelper.SegmentToAddress(cpu.GetRegister(Register.DS), (ushort)(cpu.GetRegister(Register.BX) + cpu.GetRegisterU8(Register.AL))); cpu.SetRegisterU8(Register.AL, cpu.ReadU8(address)); }
public void Dispatch(Cpu8086 cpu, OpCodeManager.Instruction instruction) { cpu.SetRegister(Register.AX, (ushort)(sbyte)cpu.GetRegisterU8(Register.AL)); }
public void Dispatch(Cpu8086 cpu, OpCodeManager.Instruction instruction) { switch (instruction.Argument1) { 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: cpu.SetRegister((Register)instruction.Argument1, ProcessExchangeSecond(cpu, instruction, cpu.GetRegister((Register)instruction.Argument1))); break; case OpCodeManager.ARG_BYTE_REGISTER: cpu.SetRegister((Register)instruction.Argument1Value, (byte)ProcessExchangeSecond(cpu, instruction, cpu.GetRegisterU8((Register)instruction.Argument1Value))); break; default: throw new NotImplementedException(); } }