|
|
|
@ -1,5 +1,6 @@
|
|
|
|
|
#include <fmt/format.h>
|
|
|
|
|
#include <span.hpp>
|
|
|
|
|
#include <hex.hpp>
|
|
|
|
|
|
|
|
|
|
const static constexpr char ascii_map[256] = {
|
|
|
|
|
'.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.',
|
|
|
|
@ -71,6 +72,22 @@ inline __attribute__((always_inline)) void print_exact(const char (&ar)[N])
|
|
|
|
|
fwrite(ar, N, 1, stdout);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline static void u64_to_hex(std::uint64_t num, char* s)
|
|
|
|
|
{
|
|
|
|
|
hv::lookup_hex_string(num, s);
|
|
|
|
|
#if 0
|
|
|
|
|
std::uint64_t x = num;
|
|
|
|
|
x = ((x & 0xFFFF) << 32) | ((x & 0xFFFF0000) >> 16);
|
|
|
|
|
x = ((x & 0x0000FF000000FF00) >> 8) | (x & 0x000000FF000000FF) << 16;
|
|
|
|
|
x = ((x & 0x00F000F000F000F0) >> 4) | (x & 0x000F000F000F000F) << 8;
|
|
|
|
|
|
|
|
|
|
uint64_t mask = ((x + 0x0606060606060606) >> 4) & 0x0101010101010101;
|
|
|
|
|
x += 0x27 * mask;
|
|
|
|
|
|
|
|
|
|
*(uint64_t *)s = x;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
namespace hv {
|
|
|
|
|
void print_screen(const span<unsigned char> memory, unsigned long offset)
|
|
|
|
|
{
|
|
|
|
@ -82,7 +99,17 @@ namespace hv {
|
|
|
|
|
#define S
|
|
|
|
|
#define P_EX(n, buf) print_exact(buf)
|
|
|
|
|
#endif
|
|
|
|
|
fmt::print("0x{:016x} ", offset);
|
|
|
|
|
char posbuf[3 + 16 + 2] = { '0' };
|
|
|
|
|
posbuf[0] = '\n';
|
|
|
|
|
posbuf[1] = '0';
|
|
|
|
|
posbuf[2] = 'x';
|
|
|
|
|
|
|
|
|
|
posbuf[3 + 16] = ' ';
|
|
|
|
|
posbuf[3 + 16 + 1] = ' ';
|
|
|
|
|
|
|
|
|
|
u64_to_hex(offset, posbuf+3);
|
|
|
|
|
prints(posbuf+1);
|
|
|
|
|
|
|
|
|
|
char hxbuf[3];
|
|
|
|
|
std::size_t i=0;
|
|
|
|
|
char r_ascii[2 + ROW_SZ];
|
|
|
|
@ -94,11 +121,14 @@ namespace hv {
|
|
|
|
|
for(;i<memory.size();i++) {
|
|
|
|
|
if (i && i % ROW_SZ == 0) { //TODO: Change to i +=16 so we don't have to branch here on every byte. Make sure to not overrun buffer tho
|
|
|
|
|
P_EX(S, r_ascii);
|
|
|
|
|
fmt::print("\n0x{:016x} ", i+offset); //TODO: Implement this manually then write the buffer with `print_exact`
|
|
|
|
|
|
|
|
|
|
u64_to_hex(i+offset, posbuf+3);
|
|
|
|
|
print_exact(posbuf);
|
|
|
|
|
}
|
|
|
|
|
unsigned char idx = memory[i];
|
|
|
|
|
hex02(idx, hxbuf);
|
|
|
|
|
print_exact(hxbuf);
|
|
|
|
|
|
|
|
|
|
ascii[i%ROW_SZ] = ascii_map[idx];
|
|
|
|
|
}
|
|
|
|
|
if (memory.size() % ROW_SZ != 0)
|
|
|
|
|