Пример #1
0
 public ModRmExecutor(Registers regs, FlagsRegister flags, byte[] mem, ModRMDecoder dec)
 {
     registers     = regs;
     flagsRegister = flags;
     memory        = mem;
     decoder       = dec;
 }
Пример #2
0
 public InterpretCpu(byte[] mem)
 {
     _memory            = mem;
     registers          = new Registers();
     IntHandlers        = new Dictionary <byte, Action>();
     flagsRegister      = new FlagsRegister();
     stack              = new Stack(registers, _memory);
     _decoder           = new ModRMDecoder(_memory, registers);
     executor8          = new ModRmExecutor8(registers, flagsRegister, _memory, _decoder);
     executor16         = new ModRmExecutor16(registers, flagsRegister, _memory, _decoder);
     executorSegment    = new ModRmExecutorSegment(registers, flagsRegister, _memory, _decoder);
     executorSegment32b = new ModRmExecutorSegment32b(registers, flagsRegister, _memory, _decoder);
 }
Пример #3
0
        private void Handle0X8X(RegisterType registerType, int immBytes, string instruction)
        {
            var modrm  = _memory[_ip + 1];
            var imm    = GetImm(immBytes);
            var opcode = ModRMDecoder.GetRegSegmentFromModRm(modrm);

            switch (opcode)
            {
            case 0x0:
                ModRm((r1, r2) => (uint)(r2 + imm), registerType, false);
                break;

            case 0x1:
                ModRm((r1, r2) => (uint)(r2 | imm), registerType, false);
                break;

            case 0x2:
                ModRm((r1, r2) => (uint)(r2 + imm + (flagsRegister.HasFlag(Flags.Carry) ? 1 : 0)), registerType,
                      false);
                break;

            case 0x3:
                ModRm((r1, r2) => (uint)(r2 - imm - (flagsRegister.HasFlag(Flags.Carry) ? 1 : 0)), registerType,
                      false);
                break;

            case 0x4:
                ModRm((r1, r2) => (uint)(r2 & imm), registerType, false);
                break;

            case 0x5:
                ModRm((r1, r2) => (uint)(r2 - imm), registerType, false);
                break;

            case 0x6:
                ModRm((r1, r2) => (uint)(r2 ^ imm), registerType, false);
                break;

            case 0x7:
                ModRmNoReturn((r1, r2) => (uint)(r2 - imm), registerType);
                break;

            default:
                throw new NotImplementedException($"{instruction} {opcode} not implemented");
            }

            _ip += 1 + immBytes;
        }