Browse Source

feat: RawCode dump case

legacy
Dnomd343 2 years ago
parent
commit
a7b09056cc
  1. 12
      src/main.cc
  2. 41
      src/raw_code/raw_code.cc
  3. 3
      src/raw_code/raw_code.h

12
src/main.cc

@ -127,11 +127,15 @@ int main() {
// std::cout << CommonCode(0x6EC0F8800).to_short_code().to_string() << std::endl; // std::cout << CommonCode(0x6EC0F8800).to_short_code().to_string() << std::endl;
auto r = RawCode(0x0E58FC85FFEBC4DB); // auto r = RawCode(0x0E58FC85FFEBC4DB);
printf("%015lX\n", r.unwrap()); // printf("%015lX\n", r.unwrap());
//
// std::cout << r.to_common_code().to_string() << std::endl;
// printf("%015lX\n", RawCode(CommonCode(0x4FEA13400)).unwrap());
std::cout << r.to_common_code().to_string() << std::endl; // auto r = RawCode(0x0E58FC85FFEBC4DB);
printf("%015lX\n", RawCode(CommonCode(0x4FEA13400)).unwrap()); auto r = RawCode(0x0E58FC85FFEBC4DD);
std::cout << r.dump_case() << std::endl;
return 0; return 0;
} }

41
src/raw_code/raw_code.cc

@ -1,3 +1,4 @@
#include <string>
#include "common.h" #include "common.h"
#include "raw_code.h" #include "raw_code.h"
@ -67,3 +68,43 @@ RawCode::RawCode(const CommonCode &common_code) {
} }
} }
} }
std::string RawCode::dump_case() const {
// TODO: result reserve space -> result length
std::string result;
auto raw_code = code;
for (int addr = 0; raw_code; ++addr, raw_code >>= 3) {
switch (raw_code & 0b111) {
case B_space:
result.push_back('.');
break;
case B_fill:
result.push_back('+');
break;
case B_1x1:
result.push_back('*');
break;
case B_1x2:
result.push_back('~');
break;
case B_2x1:
result.push_back('|');
break;
case B_2x2:
result.push_back('@');
break;
default:
result.push_back('?');
}
if (addr % 4 == 3) {
result.push_back('\n');
} else {
result.push_back(' ');
}
}
return result;
}

3
src/raw_code/raw_code.h

@ -26,8 +26,7 @@ public:
std::string dump_case() const; std::string dump_case() const;
CommonCode to_common_code() const; CommonCode to_common_code() const;
RawCode(const CommonCode &common_code); explicit RawCode(const CommonCode &common_code);
explicit RawCode(uint64_t raw_code) : code(raw_code) {} explicit RawCode(uint64_t raw_code) : code(raw_code) {}
private: private:

Loading…
Cancel
Save