mirror of
https://github.com/TomHarte/CLK.git
synced 2025-08-15 14:27:29 +00:00
Tidy up slightly, ahead of a final push to getting complete test success.
After which I can start undoing style errors.
This commit is contained in:
@@ -16,18 +16,8 @@ namespace {
|
|||||||
|
|
||||||
/// @returns The @c AddressingMode given the specified mode and reg, subject to potential
|
/// @returns The @c AddressingMode given the specified mode and reg, subject to potential
|
||||||
/// aliasing on the '020+ as described above the @c AddressingMode enum.
|
/// aliasing on the '020+ as described above the @c AddressingMode enum.
|
||||||
template <
|
constexpr AddressingMode combined_mode(int raw_mode, int reg) {
|
||||||
bool allow_An = true, bool allow_post_inc = true
|
const auto mode = AddressingMode(raw_mode);
|
||||||
> constexpr AddressingMode combined_mode(int raw_mode, int reg) {
|
|
||||||
auto mode = AddressingMode(raw_mode);
|
|
||||||
|
|
||||||
if(!allow_An && mode == AddressingMode::AddressRegisterDirect) {
|
|
||||||
mode = AddressingMode::DataRegisterDirect;
|
|
||||||
}
|
|
||||||
if(!allow_post_inc && mode == AddressingMode::AddressRegisterIndirectWithPostincrement) {
|
|
||||||
mode = AddressingMode::AddressRegisterIndirect;
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr AddressingMode extended_modes[] = {
|
constexpr AddressingMode extended_modes[] = {
|
||||||
AddressingMode::AbsoluteShort,
|
AddressingMode::AbsoluteShort,
|
||||||
AddressingMode::AbsoluteLong,
|
AddressingMode::AbsoluteLong,
|
||||||
@@ -468,29 +458,18 @@ template <uint8_t op, bool validate> Preinstruction Predecoder<model>::decode(ui
|
|||||||
//
|
//
|
||||||
case OpT(Operation::ADDb): case OpT(Operation::ADDw): case OpT(Operation::ADDl):
|
case OpT(Operation::ADDb): case OpT(Operation::ADDw): case OpT(Operation::ADDl):
|
||||||
case OpT(Operation::SUBb): case OpT(Operation::SUBw): case OpT(Operation::SUBl):
|
case OpT(Operation::SUBb): case OpT(Operation::SUBw): case OpT(Operation::SUBl):
|
||||||
case OpT(Operation::ADDAw): case OpT(Operation::ADDAl):
|
|
||||||
case OpT(Operation::SUBAw): case OpT(Operation::SUBAl):
|
|
||||||
case OpT(Operation::CMPAw): case OpT(Operation::CMPAl):
|
|
||||||
case OpT(Operation::CMPb): case OpT(Operation::CMPw): case OpT(Operation::CMPl):
|
|
||||||
case OpT(Operation::ANDb): case OpT(Operation::ANDw): case OpT(Operation::ANDl):
|
case OpT(Operation::ANDb): case OpT(Operation::ANDw): case OpT(Operation::ANDl):
|
||||||
case OpT(Operation::ORb): case OpT(Operation::ORw): case OpT(Operation::ORl):
|
case OpT(Operation::ORb): case OpT(Operation::ORw): case OpT(Operation::ORl): {
|
||||||
case OpT(Operation::EORb): case OpT(Operation::EORw): case OpT(Operation::EORl): {
|
|
||||||
|
|
||||||
constexpr bool is_address_operation =
|
|
||||||
op == OpT(Operation::ADDAw) || op == OpT(Operation::ADDAl) ||
|
|
||||||
op == OpT(Operation::SUBAw) || op == OpT(Operation::SUBAl) ||
|
|
||||||
op == OpT(Operation::CMPAw) || op == OpT(Operation::CMPAl);
|
|
||||||
constexpr auto register_addressing_mode = is_address_operation
|
|
||||||
? AddressingMode::AddressRegisterDirect : AddressingMode::DataRegisterDirect;
|
|
||||||
|
|
||||||
const auto ea_combined_mode = combined_mode(ea_mode, ea_register);
|
const auto ea_combined_mode = combined_mode(ea_mode, ea_register);
|
||||||
|
|
||||||
if(!is_address_operation && (opmode & 4)) {
|
// TODO: make this decision outside of this function.
|
||||||
|
if(opmode & 4) {
|
||||||
// Dn Λ < ea > → < ea >
|
// Dn Λ < ea > → < ea >
|
||||||
|
|
||||||
return validated<op, validate>(
|
return validated<op, validate>(
|
||||||
Preinstruction(operation,
|
Preinstruction(operation,
|
||||||
register_addressing_mode, data_register,
|
AddressingMode::DataRegisterDirect, data_register,
|
||||||
ea_combined_mode, ea_register));
|
ea_combined_mode, ea_register));
|
||||||
} else {
|
} else {
|
||||||
// < ea > Λ Dn → Dn
|
// < ea > Λ Dn → Dn
|
||||||
@@ -498,12 +477,32 @@ template <uint8_t op, bool validate> Preinstruction Predecoder<model>::decode(ui
|
|||||||
return validated<op, validate>(
|
return validated<op, validate>(
|
||||||
Preinstruction(operation,
|
Preinstruction(operation,
|
||||||
ea_combined_mode, ea_register,
|
ea_combined_mode, ea_register,
|
||||||
register_addressing_mode, data_register));
|
AddressingMode::DataRegisterDirect, data_register));
|
||||||
}
|
}
|
||||||
|
|
||||||
return Preinstruction();
|
return Preinstruction();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case OpT(Operation::CMPb): case OpT(Operation::CMPw): case OpT(Operation::CMPl):
|
||||||
|
return validated<op, validate>(
|
||||||
|
Preinstruction(operation,
|
||||||
|
combined_mode(ea_mode, ea_register), ea_register,
|
||||||
|
AddressingMode::DataRegisterDirect, data_register));
|
||||||
|
|
||||||
|
case OpT(Operation::EORb): case OpT(Operation::EORw): case OpT(Operation::EORl):
|
||||||
|
return validated<op, validate>(
|
||||||
|
Preinstruction(operation,
|
||||||
|
AddressingMode::DataRegisterDirect, data_register,
|
||||||
|
combined_mode(ea_mode, ea_register), ea_register));
|
||||||
|
|
||||||
|
case OpT(Operation::ADDAw): case OpT(Operation::ADDAl):
|
||||||
|
case OpT(Operation::SUBAw): case OpT(Operation::SUBAl):
|
||||||
|
case OpT(Operation::CMPAw): case OpT(Operation::CMPAl):
|
||||||
|
return validated<op, validate>(
|
||||||
|
Preinstruction(operation,
|
||||||
|
combined_mode(ea_mode, ea_register), ea_register,
|
||||||
|
AddressingMode::AddressRegisterDirect, data_register));
|
||||||
|
|
||||||
//
|
//
|
||||||
// MARK: EORI, ORI, ANDI, SUBI, ADDI, CMPI, B[TST/CHG/CLR/SET]I
|
// MARK: EORI, ORI, ANDI, SUBI, ADDI, CMPI, B[TST/CHG/CLR/SET]I
|
||||||
//
|
//
|
||||||
@@ -591,6 +590,7 @@ template <uint8_t op, bool validate> Preinstruction Predecoder<model>::decode(ui
|
|||||||
AddressingMode::DataRegisterDirect, data_register,
|
AddressingMode::DataRegisterDirect, data_register,
|
||||||
AddressingMode::AddressRegisterDirect, ea_register));
|
AddressingMode::AddressRegisterDirect, ea_register));
|
||||||
}
|
}
|
||||||
|
// TODO: remove conditional from in here.
|
||||||
|
|
||||||
//
|
//
|
||||||
// MARK: MULU, MULS, DIVU, DIVS.
|
// MARK: MULU, MULS, DIVU, DIVS.
|
||||||
|
@@ -228,10 +228,10 @@ template <int index> NSString *operand(Preinstruction instruction, uint16_t opco
|
|||||||
// case Operation::ANDb: instruction = @"AND.b"; break;
|
// case Operation::ANDb: instruction = @"AND.b"; break;
|
||||||
// case Operation::ANDw: instruction = @"AND.w"; break;
|
// case Operation::ANDw: instruction = @"AND.w"; break;
|
||||||
// case Operation::ANDl: instruction = @"AND.l"; break;
|
// case Operation::ANDl: instruction = @"AND.l"; break;
|
||||||
//
|
|
||||||
// case Operation::EORb: instruction = @"EOR.b"; break;
|
case Operation::EORb: instruction = @"EOR.b"; break;
|
||||||
// case Operation::EORw: instruction = @"EOR.w"; break;
|
case Operation::EORw: instruction = @"EOR.w"; break;
|
||||||
// case Operation::EORl: instruction = @"EOR.l"; break;
|
case Operation::EORl: instruction = @"EOR.l"; break;
|
||||||
|
|
||||||
case Operation::NOTb: instruction = @"NOT.b"; break;
|
case Operation::NOTb: instruction = @"NOT.b"; break;
|
||||||
case Operation::NOTw: instruction = @"NOT.w"; break;
|
case Operation::NOTw: instruction = @"NOT.w"; break;
|
||||||
@@ -279,12 +279,6 @@ template <int index> NSString *operand(Preinstruction instruction, uint16_t opco
|
|||||||
if(operand1.length) instruction = [instruction stringByAppendingFormat:@" %@", operand1];
|
if(operand1.length) instruction = [instruction stringByAppendingFormat:@" %@", operand1];
|
||||||
if(operand2.length) instruction = [instruction stringByAppendingFormat:@", %@", operand2];
|
if(operand2.length) instruction = [instruction stringByAppendingFormat:@", %@", operand2];
|
||||||
|
|
||||||
// Quick decoding not yet supported. TODO.
|
|
||||||
// if(found.mode<0>() == AddressingMode::Quick || found.mode<1>() == AddressingMode::Quick) {
|
|
||||||
// ++skipped;
|
|
||||||
// continue;
|
|
||||||
// }
|
|
||||||
|
|
||||||
XCTAssertFalse(found.mode<0>() == AddressingMode::None && found.mode<1>() != AddressingMode::None, @"Decoding of %@ provided a second operand but not a first", instrName);
|
XCTAssertFalse(found.mode<0>() == AddressingMode::None && found.mode<1>() != AddressingMode::None, @"Decoding of %@ provided a second operand but not a first", instrName);
|
||||||
XCTAssertEqualObjects(instruction, expected, "%@ should decode as %@; got %@", instrName, expected, instruction);
|
XCTAssertEqualObjects(instruction, expected, "%@ should decode as %@; got %@", instrName, expected, instruction);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user