Exemplo n.º 1
0
        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();
            }
        }
Exemplo n.º 2
0
 public static void CalculateSubFlags(Cpu8086 cpu, OpCodeManager.OpCodeFlag flag, ushort value1, ushort value2, int result)
 {
     if (flag.Has(OpCodeManager.OpCodeFlag.Size8))
     {
         CalculateSubFlags8Bit(cpu, (byte)value1, (byte)value2, result);
     }
     else
     {
         CalculateSubFlags16Bit(cpu, value1, value2, result);
     }
 }
Exemplo n.º 3
0
        public static string OutputArgument(Register segmentPrefix, OpCodeManager.OpCodeFlag flag, int argument, int argumentValue, int argumentDisplacement)
        {
            if (argument == OpCodeManager.ARG_NONE)
            {
                return(null);
            }
            switch (argument)
            {
            case (int)Register.AX:
                return("AX");

            case (int)Register.CX:
                return("CX");

            case (int)Register.DX:
                return("DX");

            case (int)Register.BX:
                return("BX");

            case (int)Register.SP:
                return("SP");

            case (int)Register.BP:
                return("BP");

            case (int)Register.SI:
                return("SI");

            case (int)Register.DI:
                return("DI");

            case (int)Register.IP:
                return("IP");

            case (int)Register.CS:
                return("CS");

            case (int)Register.DS:
                return("DS");

            case (int)Register.ES:
                return("ES");

            case (int)Register.SS:
                return("SS");

            case unchecked ((int)Register.FLAGS):
                return("FLAGS");

            case OpCodeManager.ARG_BYTE_REGISTER:
                switch ((Register)argumentValue)
                {
                case Register.AL:
                    return("AL");

                case Register.CL:
                    return("CL");

                case Register.DL:
                    return("DL");

                case Register.BL:
                    return("BL");

                case Register.AH:
                    return("AH");

                case Register.CH:
                    return("CH");

                case Register.DH:
                    return("DH");

                case Register.BH:
                    return("BH");

                default:
                    throw new NotImplementedException();
                }

            case OpCodeManager.ARG_DEREFERENCE:
                string value;
                switch (argumentValue)
                {
                case 0:
                    value = "BX+SI";
                    break;

                case 1:
                    value = "BX+DI";
                    break;

                case 2:
                    value = "BP+SI";
                    break;

                case 3:
                    value = "BP+DI";
                    break;

                case 4:
                    value = "SI";
                    break;

                case 5:
                    value = "DI";
                    break;

                case 6:
                    value = "BP";
                    break;

                case 7:
                    value = "BX";
                    break;

                default:
                    throw new NotImplementedException();
                }
                switch (segmentPrefix)
                {
                case Register.Invalid:
                    return(argumentDisplacement < 0 ? $"[{value}{argumentDisplacement}]" : $"[{value}+{argumentDisplacement}]");

                case Register.ES:
                    return(argumentDisplacement < 0 ? $"[ES:{value}{argumentDisplacement}]" : $"[ES:{value}+{argumentDisplacement}]");

                case Register.CS:
                    return(argumentDisplacement < 0 ? $"[CS:{value}{argumentDisplacement}]" : $"[CS:{value}+{argumentDisplacement}]");

                case Register.SS:
                    return(argumentDisplacement < 0 ? $"[SS:{value}{argumentDisplacement}]" : $"[SS:{value}+{argumentDisplacement}]");

                case Register.DS:
                    return(argumentDisplacement < 0 ? $"[DS:{value}{argumentDisplacement}]" : $"[DS:{value}+{argumentDisplacement}]");

                default:
                    throw new NotImplementedException();
                }

            case OpCodeManager.ARG_MEMORY:
                switch (segmentPrefix)
                {
                case Register.Invalid:
                    return($"[{argumentValue:X4}]");

                case Register.ES:
                    return($"[ES:{argumentValue:X4}]");

                case Register.CS:
                    return($"[CS:{argumentValue:X4}]");

                case Register.SS:
                    return($"[SS:{argumentValue:X4}]");

                case Register.DS:
                    return($"[DS:{argumentValue:X4}]");

                default:
                    throw new NotImplementedException();
                }

            case OpCodeManager.ARG_FAR_MEMORY:
                var segment = (uint)argumentValue >> 16;
                var address = argumentValue & 0xFFFF;
                return($"[{segment:X4}:{address:X4}]");

            case OpCodeManager.ARG_CONSTANT:
                return(flag.Has(OpCodeManager.OpCodeFlag.Size8) ? $"{argumentValue:X2}" : $"{argumentValue:X4}");

            default:
                throw new NotImplementedException();
            }
        }
Exemplo n.º 4
0
 public static bool Has(this OpCodeManager.OpCodeFlag flag, OpCodeManager.OpCodeFlag testFlag) =>
 (flag & testFlag) != 0;