mirror of
https://github.com/libretro/bsnes-libretro.git
synced 2024-11-30 12:30:51 +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.
45 lines
935 B
C++
45 lines
935 B
C++
#pragma once
|
|
|
|
namespace nall::Decode {
|
|
|
|
template<uint S = 1, uint M = 4 / S> //S = word size; M = match length
|
|
inline auto RLE(array_view<uint8_t> input) -> vector<uint8_t> {
|
|
vector<uint8_t> output;
|
|
|
|
auto load = [&]() -> uint8_t {
|
|
return input ? *input++ : 0;
|
|
};
|
|
|
|
uint base = 0;
|
|
uint64_t size = 0;
|
|
for(uint byte : range(8)) size |= load() << byte * 8;
|
|
output.resize(size);
|
|
|
|
auto read = [&]() -> uint64_t {
|
|
uint64_t value = 0;
|
|
for(uint byte : range(S)) value |= load() << byte * 8;
|
|
return value;
|
|
};
|
|
|
|
auto write = [&](uint64_t value) -> void {
|
|
if(base >= size) return;
|
|
for(uint byte : range(S)) output[base++] = value >> byte * 8;
|
|
};
|
|
|
|
while(base < size) {
|
|
auto byte = load();
|
|
if(byte < 128) {
|
|
byte++;
|
|
while(byte--) write(read());
|
|
} else {
|
|
auto value = read();
|
|
byte = (byte & 127) + M;
|
|
while(byte--) write(value);
|
|
}
|
|
}
|
|
|
|
return output;
|
|
}
|
|
|
|
}
|