mirror of
https://github.com/libretro/bsnes-libretro.git
synced 2024-11-27 02:50:32 +00:00
559a6585ef
byuu says: First 32 instructions implemented in the TLCS900H disassembler. Only 992 to go! I removed the use of anonymous namespaces in nall. It was something I rarely used, because it rarely did what I wanted. I updated all nested namespaces to use C++17-style namespace Foo::Bar {} syntax instead of classic C++-style namespace Foo { namespace Bar {}}. I updated ruby::Video::acquire() to return a struct, so we can use C++17 structured bindings. Long term, I want to get away from all functions that take references for output only. Even though C++ botched structured bindings by not allowing you to bind to existing variables, it's even worse to have function calls that take arguments by reference and then write to them. From the caller side, you can't tell the value is being written, nor that the value passed in doesn't matter, which is terrible.
56 lines
1.0 KiB
C++
56 lines
1.0 KiB
C++
#pragma once
|
|
|
|
#include <nall/hash/hash.hpp>
|
|
|
|
namespace nall::Hash {
|
|
|
|
struct CRC64 : Hash {
|
|
using Hash::input;
|
|
|
|
CRC64(array_view<uint8_t> buffer = {}) {
|
|
reset();
|
|
input(buffer);
|
|
}
|
|
|
|
auto reset() -> void override {
|
|
checksum = ~0;
|
|
}
|
|
|
|
auto input(uint8_t value) -> void override {
|
|
checksum = (checksum >> 8) ^ table(checksum ^ value);
|
|
}
|
|
|
|
auto output() const -> vector<uint8_t> {
|
|
vector<uint8_t> result;
|
|
for(auto n : reverse(range(8))) result.append(~checksum >> n * 8);
|
|
return result;
|
|
}
|
|
|
|
auto value() const -> uint64_t {
|
|
return ~checksum;
|
|
}
|
|
|
|
private:
|
|
static auto table(uint8_t index) -> uint64_t {
|
|
static uint64_t table[256] = {0};
|
|
static bool initialized = false;
|
|
|
|
if(!initialized) {
|
|
initialized = true;
|
|
for(auto index : range(256)) {
|
|
uint64_t crc = index;
|
|
for(auto bit : range(8)) {
|
|
crc = (crc >> 1) ^ (crc & 1 ? 0xc96c'5795'd787'0f42 : 0);
|
|
}
|
|
table[index] = crc;
|
|
}
|
|
}
|
|
|
|
return table[index];
|
|
}
|
|
|
|
uint64_t checksum = 0;
|
|
};
|
|
|
|
}
|