Browse Source

feat: convert RawCode to CommonCode

legacy
Dnomd343 2 years ago
parent
commit
9f0f2ff2c9
  1. 2
      src/main.cc
  2. 38
      src/raw_code/raw_code.cc
  3. 7
      src/raw_code/raw_code.h

2
src/main.cc

@ -130,5 +130,7 @@ int main() {
auto r = RawCode(0x0E58FC85FFEBC4DB);
printf("%016lX\n", r.unwrap());
std::cout << r.to_common_code().to_string() << std::endl;
return 0;
}

38
src/raw_code/raw_code.cc

@ -3,3 +3,41 @@
uint64_t RawCode::unwrap() const { // get raw uint64_t code
return code;
}
CommonCode RawCode::to_common_code() const {
uint32_t range = 0;
uint64_t raw_code = code;
uint32_t unfilled_num = 16;
uint64_t head = ((uint64_t)16 << 32); // using invalid address
for (int addr = 0; raw_code; ++addr, raw_code >>= 3) {
switch (raw_code & 0b111) { // get low 3-bits
case B_space:
range <<= 2; // add space block
break;
case B_1x2:
(range <<= 2) |= 0b01; // add 1x2 block
break;
case B_2x1:
(range <<= 2) |= 0b10; // add 2x1 block
break;
case B_1x1:
(range <<= 2) |= 0b11; // add 1x1 block
break;
case B_2x2:
head = (uint64_t)addr << 32; // 2x2 block address
default:
// TODO: should we throw an error?
continue; // unknown block type
}
--unfilled_num; // less unfilled block
}
// TODO: should we check the high 4-bits equal to zero?
// printf("head -> %09lX\n", head);
// printf("range -> %08X\n", range << 10);
// printf("unfilled -> %d\n", unfilled_num);
unfilled_num <<= 1; // aka unfilled_num *= 2
return CommonCode(head | (range << unfilled_num));
}

7
src/raw_code/raw_code.h

@ -3,6 +3,13 @@
#include <cstdint>
#include "common_code.h"
#define B_space 0x0
#define B_fill 0x7
#define B_1x2 0x1
#define B_2x1 0x2
#define B_1x1 0x3
#define B_2x2 0x4
class RawCode {
public:
uint64_t unwrap() const;

Loading…
Cancel
Save