mirror of
https://github.com/TomHarte/CLK.git
synced 2024-09-04 06:29:47 +00:00
Introduces 'far' test, fixes parsing.
This commit is contained in:
parent
2c72a77a25
commit
ca94e9038e
@ -95,6 +95,12 @@ namespace {
|
|||||||
XCTAssertEqual(instruction.displacement(), 0);
|
XCTAssertEqual(instruction.displacement(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)assert:(Instruction &)instruction operation:(Operation)operation segment:(uint16_t)segment offset:(uint16_t)offset {
|
||||||
|
XCTAssertEqual(instruction.operation, operation);
|
||||||
|
XCTAssertEqual(instruction.segment(), segment);
|
||||||
|
XCTAssertEqual(instruction.offset(), offset);
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: - Decoder
|
// MARK: - Decoder
|
||||||
|
|
||||||
- (void)decode:(const std::initializer_list<uint8_t> &)stream {
|
- (void)decode:(const std::initializer_list<uint8_t> &)stream {
|
||||||
@ -312,12 +318,19 @@ namespace {
|
|||||||
0x83, 0x2f, 0x09, // subw $0x9,(%bx)
|
0x83, 0x2f, 0x09, // subw $0x9,(%bx)
|
||||||
}];
|
}];
|
||||||
|
|
||||||
// 68 instructions are expected.
|
|
||||||
XCTAssertEqual(instructions.size(), 3);
|
XCTAssertEqual(instructions.size(), 3);
|
||||||
|
|
||||||
[self assert:instructions[0] operation:Operation::ADC size:2 source:Source::Immediate destination:Source::IndBXPlusSI operand:0xff80];
|
[self assert:instructions[0] operation:Operation::ADC size:2 source:Source::Immediate destination:Source::IndBXPlusSI operand:0xff80];
|
||||||
[self assert:instructions[1] operation:Operation::CMP size:2 source:Source::Immediate destination:Source::IndBPPlusDI operand:0x4];
|
[self assert:instructions[1] operation:Operation::CMP size:2 source:Source::Immediate destination:Source::IndBPPlusDI operand:0x4];
|
||||||
[self assert:instructions[2] operation:Operation::SUB size:2 source:Source::Immediate destination:Source::IndBX operand:0x9];
|
[self assert:instructions[2] operation:Operation::SUB size:2 source:Source::Immediate destination:Source::IndBX operand:0x9];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)testFar {
|
||||||
|
[self decode:{
|
||||||
|
0x9a, 0x12, 0x34, 0x56, 0x78, // lcall 0x7856, 0x3412
|
||||||
|
}];
|
||||||
|
|
||||||
|
XCTAssertEqual(instructions.size(), 1);
|
||||||
|
[self assert:instructions[0] operation:Operation::CALLF segment:0x7856 offset:0x3412];
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
@ -585,7 +585,9 @@ std::pair<int, Instruction> Decoder::decode(const uint8_t *source, size_t length
|
|||||||
operand_ |= (operand_ & 0x80) ? 0xff00 : 0x0000;
|
operand_ |= (operand_ & 0x80) ? 0xff00 : 0x0000;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case 4: displacement_size_ = 2; [[fallthrough]];
|
||||||
case 2: operand_ = inward_data_ >> 48; inward_data_ <<= 16; break;
|
case 2: operand_ = inward_data_ >> 48; inward_data_ <<= 16; break;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
switch(displacement_size_) {
|
switch(displacement_size_) {
|
||||||
default: displacement_ = 0; break;
|
default: displacement_ = 0; break;
|
||||||
|
@ -37,10 +37,11 @@ enum class Operation: uint8_t {
|
|||||||
ADD,
|
ADD,
|
||||||
/// And; source, destination, operand and displacement will be populated appropriately.
|
/// And; source, destination, operand and displacement will be populated appropriately.
|
||||||
AND,
|
AND,
|
||||||
/// Far call; followed by a 32-bit operand.
|
/// Far call; see the segment() and offset() fields.
|
||||||
CALLF,
|
CALLF,
|
||||||
/// Displacement call; followed by a 16-bit operand providing a call offset.
|
/// Displacement call; followed by a 16-bit operand providing a call offset.
|
||||||
CALLD,
|
CALLD,
|
||||||
|
/// Near call.
|
||||||
CALLN,
|
CALLN,
|
||||||
/// Convert byte into word; source will be AL, destination will be AH.
|
/// Convert byte into word; source will be AL, destination will be AH.
|
||||||
CBW,
|
CBW,
|
||||||
@ -155,6 +156,7 @@ class Instruction {
|
|||||||
Size operation_size() const { return Size(repetition_size_ >> 2); }
|
Size operation_size() const { return Size(repetition_size_ >> 2); }
|
||||||
|
|
||||||
uint16_t segment() const { return uint16_t(operand_); }
|
uint16_t segment() const { return uint16_t(operand_); }
|
||||||
|
uint16_t offset() const { return uint16_t(displacement_); }
|
||||||
|
|
||||||
int16_t displacement() const { return displacement_; }
|
int16_t displacement() const { return displacement_; }
|
||||||
uint16_t operand() const { return operand_; }
|
uint16_t operand() const { return operand_; }
|
||||||
|
Loading…
Reference in New Issue
Block a user