Correct 5-bit sign extension on the 6809 processor. Allows CLR 5-bit offset indexed disassembly to work correctly.

Signed-off-by: Adrian Conlon <Adrian.conlon@gmail.com>
This commit is contained in:
Adrian Conlon
2018-08-27 12:57:44 +01:00
parent 2f632cdaf5
commit dfc4c49454
4 changed files with 15 additions and 3 deletions

View File

@@ -31,3 +31,11 @@ int EightBit::Processor::run(const int limit) {
current += step();
return current;
}
// http://graphics.stanford.edu/~seander/bithacks.html#FixedSignExtend
int8_t EightBit::Processor::signExtend(int b, uint8_t x) {
const uint8_t m = 1 << (b - 1); // mask can be pre-computed if b is fixed
x = x & ((1 << b) - 1); // (Skip this if bits in x above position b are already zero.)
const auto result = (x ^ m) - m;
return result;
}