Browse Source

feat: RawCode init base on CommonCode

legacy
Dnomd343 2 years ago
parent
commit
3ad88a53dc
  1. 3
      src/main.cc
  2. 2
      src/raw_code/CMakeLists.txt
  3. 26
      src/raw_code/raw_code.cc
  4. 22
      src/raw_code/raw_code.h

3
src/main.cc

@ -128,9 +128,10 @@ int main() {
auto r = RawCode(0x0E58FC85FFEBC4DB);
printf("%016lX\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());
return 0;
}

2
src/raw_code/CMakeLists.txt

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.0)
add_library(raw_code raw_code.cc)
target_link_libraries(raw_code common_code)
target_link_libraries(raw_code common common_code)

26
src/raw_code/raw_code.cc

@ -1,3 +1,4 @@
#include "common.h"
#include "raw_code.h"
uint64_t RawCode::unwrap() const { // get raw uint64_t code
@ -41,3 +42,28 @@ CommonCode RawCode::to_common_code() const {
unfilled_num <<= 1; // aka unfilled_num *= 2
return CommonCode(head | (range << unfilled_num));
}
RawCode::RawCode(const CommonCode &common_code) {
auto common_code_raw = common_code.unwrap(); // common code with uint64_t format
code = C_2x2 << (common_code_raw >> 32) * 3; // flag for 2x2 block
auto range = Common::range_reverse((uint32_t)common_code_raw); // load reversed range
for (int addr = 0; range; range >>= 2) {
while (0b111 & code >> addr) { // check low 3-bits -> until empty address
addr += 3; // found available address
}
switch (range & 0b11) { // match low 2-bits
case 0x1:
code |= C_1x2 << addr; // add 1x2 block
break;
case 0x2:
code |= C_2x1 << addr; // add 2x1 block
break;
case 0x3:
code |= C_1x1 << addr; // add 1x1 block
break;
case 0x0:
addr += 3; // next address
}
}
}

22
src/raw_code/raw_code.h

@ -3,12 +3,22 @@
#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
#define B_space 0b000
#define B_fill 0b111
#define B_1x2 0b001
#define B_2x1 0b010
#define B_1x1 0b011
#define B_2x2 0b100
#define C_1x1 (uint64_t)0x3
#define C_1x2 (uint64_t)0x39
#define C_2x1 (uint64_t)0x7002
#define C_2x2 (uint64_t)0x3F03C
//#define F_1x1 uint64_t(0x7)
//#define F_1x2 uint64_t(0x3F)
//#define F_2x1 uint64_t(0x7007)
//#define F_2x2 uint64_t(0x3F03F)
class RawCode {
public:

Loading…
Cancel
Save