mirror of
https://github.com/TomHarte/CLK.git
synced 2025-01-27 06:35:04 +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);
|
||||
}
|
||||
|
||||
- (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
|
||||
|
||||
- (void)decode:(const std::initializer_list<uint8_t> &)stream {
|
||||
@ -312,12 +318,19 @@ namespace {
|
||||
0x83, 0x2f, 0x09, // subw $0x9,(%bx)
|
||||
}];
|
||||
|
||||
// 68 instructions are expected.
|
||||
XCTAssertEqual(instructions.size(), 3);
|
||||
|
||||
[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[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
|
||||
|
@ -585,7 +585,9 @@ std::pair<int, Instruction> Decoder::decode(const uint8_t *source, size_t length
|
||||
operand_ |= (operand_ & 0x80) ? 0xff00 : 0x0000;
|
||||
}
|
||||
break;
|
||||
case 4: displacement_size_ = 2; [[fallthrough]];
|
||||
case 2: operand_ = inward_data_ >> 48; inward_data_ <<= 16; break;
|
||||
break;
|
||||
}
|
||||
switch(displacement_size_) {
|
||||
default: displacement_ = 0; break;
|
||||
|
@ -37,10 +37,11 @@ enum class Operation: uint8_t {
|
||||
ADD,
|
||||
/// And; source, destination, operand and displacement will be populated appropriately.
|
||||
AND,
|
||||
/// Far call; followed by a 32-bit operand.
|
||||
/// Far call; see the segment() and offset() fields.
|
||||
CALLF,
|
||||
/// Displacement call; followed by a 16-bit operand providing a call offset.
|
||||
CALLD,
|
||||
/// Near call.
|
||||
CALLN,
|
||||
/// Convert byte into word; source will be AL, destination will be AH.
|
||||
CBW,
|
||||
@ -155,6 +156,7 @@ class Instruction {
|
||||
Size operation_size() const { return Size(repetition_size_ >> 2); }
|
||||
|
||||
uint16_t segment() const { return uint16_t(operand_); }
|
||||
uint16_t offset() const { return uint16_t(displacement_); }
|
||||
|
||||
int16_t displacement() const { return displacement_; }
|
||||
uint16_t operand() const { return operand_; }
|
||||
|
Loading…
x
Reference in New Issue
Block a user