0
mirror of https://github.com/sampletext32/ParkanPlayground.git synced 2025-06-20 08:18:36 +03:00

nice big refactor

This commit is contained in:
bird_egop
2025-04-13 23:06:52 +03:00
parent 59df064ca4
commit 11a2cfada4
92 changed files with 981 additions and 1509 deletions

View File

@ -56,19 +56,10 @@ public class DivRm32Handler : InstructionHandler
}
// Read the ModR/M byte
byte modRM = CodeBuffer[position++];
Decoder.SetPosition(position);
// Extract the fields from the ModR/M byte
byte mod = (byte)((modRM & 0xC0) >> 6);
byte reg = (byte)((modRM & 0x38) >> 3); // Should be 6 for DIV
byte rm = (byte)(modRM & 0x07);
// Decode the operand
string operand = ModRMDecoder.DecodeModRM(mod, rm, false);
var (mod, reg, rm, destOperand) = ModRMDecoder.ReadModRM();
// Set the operands
instruction.Operands = operand;
instruction.Operands = destOperand;
return true;
}

View File

@ -56,19 +56,10 @@ public class IdivRm32Handler : InstructionHandler
}
// Read the ModR/M byte
byte modRM = CodeBuffer[position++];
Decoder.SetPosition(position);
// Extract the fields from the ModR/M byte
byte mod = (byte)((modRM & 0xC0) >> 6);
byte reg = (byte)((modRM & 0x38) >> 3); // Should be 7 for IDIV
byte rm = (byte)(modRM & 0x07);
// Decode the operand
string operand = ModRMDecoder.DecodeModRM(mod, rm, false);
var (mod, reg, rm, destOperand) = ModRMDecoder.ReadModRM();
// Set the operands
instruction.Operands = operand;
instruction.Operands = destOperand;
return true;
}

View File

@ -56,19 +56,10 @@ public class ImulRm32Handler : InstructionHandler
}
// Read the ModR/M byte
byte modRM = CodeBuffer[position++];
Decoder.SetPosition(position);
// Extract the fields from the ModR/M byte
byte mod = (byte)((modRM & 0xC0) >> 6);
byte reg = (byte)((modRM & 0x38) >> 3); // Should be 5 for IMUL
byte rm = (byte)(modRM & 0x07);
// Decode the operand
string operand = ModRMDecoder.DecodeModRM(mod, rm, false);
var (mod, reg, rm, destOperand) = ModRMDecoder.ReadModRM();
// Set the operands
instruction.Operands = operand;
instruction.Operands = destOperand;
return true;
}

View File

@ -56,19 +56,10 @@ public class MulRm32Handler : InstructionHandler
}
// Read the ModR/M byte
byte modRM = CodeBuffer[position++];
Decoder.SetPosition(position);
// Extract the fields from the ModR/M byte
byte mod = (byte)((modRM & 0xC0) >> 6);
byte reg = (byte)((modRM & 0x38) >> 3); // Should be 4 for MUL
byte rm = (byte)(modRM & 0x07);
// Decode the operand
string operand = ModRMDecoder.DecodeModRM(mod, rm, false);
var (mod, reg, rm, destOperand) = ModRMDecoder.ReadModRM();
// Set the operands
instruction.Operands = operand;
instruction.Operands = destOperand;
return true;
}

View File

@ -56,19 +56,10 @@ public class NegRm32Handler : InstructionHandler
}
// Read the ModR/M byte
byte modRM = CodeBuffer[position++];
Decoder.SetPosition(position);
// Extract the fields from the ModR/M byte
byte mod = (byte)((modRM & 0xC0) >> 6);
byte reg = (byte)((modRM & 0x38) >> 3); // Should be 3 for NEG
byte rm = (byte)(modRM & 0x07);
// Decode the operand
string operand = ModRMDecoder.DecodeModRM(mod, rm, false);
var (mod, reg, rm, destOperand) = ModRMDecoder.ReadModRM();
// Set the operands
instruction.Operands = operand;
instruction.Operands = destOperand;
return true;
}

View File

@ -54,15 +54,10 @@ public class NotRm32Handler : InstructionHandler
}
// Read the ModR/M byte
byte modRM = CodeBuffer[position++];
// Extract the fields from the ModR/M byte
byte mod = (byte)((modRM & 0xC0) >> 6);
byte reg = (byte)((modRM & 0x38) >> 3); // Should be 2 for NOT
byte rm = (byte)(modRM & 0x07);
var (mod, reg, rm, destOperand) = ModRMDecoder.ReadModRM();
// Verify this is a NOT instruction
if (reg != 2)
if (reg != RegisterIndex.C)
{
return false;
}
@ -73,19 +68,13 @@ public class NotRm32Handler : InstructionHandler
Decoder.SetPosition(position);
// For direct register addressing (mod == 3), the r/m field specifies a register
string operand;
if (mod == 3)
{
operand = GetRegister32(rm);
}
else
{
// Use the ModR/M decoder for memory addressing
operand = ModRMDecoder.DecodeModRM(mod, rm, false);
destOperand = ModRMDecoder.GetRegisterName(rm, 32);
}
// Set the operands
instruction.Operands = operand;
instruction.Operands = destOperand;
return true;
}