2018-08-21 03:17:12 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <nall/suffix-array.hpp>
|
|
|
|
#include <nall/encode/bwt.hpp>
|
|
|
|
#include <nall/encode/huffman.hpp>
|
|
|
|
#include <nall/encode/mtf.hpp>
|
|
|
|
#include <nall/encode/rle.hpp>
|
|
|
|
|
2019-01-16 00:46:42 +00:00
|
|
|
namespace nall::Encode {
|
2018-08-21 03:17:12 +00:00
|
|
|
|
Update to v106r59 release.
byuu says:
Changelog:
- fixed bug in Emulator::Game::Memory::operator bool()
- nall: renamed view<string> back to `string_view`
- nall:: implemented `array_view`
- Game Boy: split cartridge-specific input mappings (rumble,
accelerometer) to their own separate ports
- Game Boy: fixed MBC7 accelerometer x-axis
- icarus: Game Boy, Super Famicom, Mega Drive cores output internal
header game titles to heuristics manifests
- higan, icarus, hiro/gtk: improve viewport geometry configuration;
fixed higan crashing bug with XShm driver
- higan: connect Video::poll(),update() functionality
- hiro, ruby: several compilation / bugfixes, should get the macOS
port compiling again, hopefully [Sintendo]
- ruby/video/xshm: fix crashing bug on window resize
- a bit hacky; it's throwing BadAccess Xlib warnings, but they're
not fatal, so I am catching and ignoring them
- bsnes: removed Application::Windows::onModalChange hook that's no
longer needed [Screwtape]
2018-08-26 06:49:54 +00:00
|
|
|
inline auto LZSA(array_view<uint8_t> input) -> vector<uint8_t> {
|
2018-08-21 03:17:12 +00:00
|
|
|
vector<uint8_t> output;
|
Update to v106r59 release.
byuu says:
Changelog:
- fixed bug in Emulator::Game::Memory::operator bool()
- nall: renamed view<string> back to `string_view`
- nall:: implemented `array_view`
- Game Boy: split cartridge-specific input mappings (rumble,
accelerometer) to their own separate ports
- Game Boy: fixed MBC7 accelerometer x-axis
- icarus: Game Boy, Super Famicom, Mega Drive cores output internal
header game titles to heuristics manifests
- higan, icarus, hiro/gtk: improve viewport geometry configuration;
fixed higan crashing bug with XShm driver
- higan: connect Video::poll(),update() functionality
- hiro, ruby: several compilation / bugfixes, should get the macOS
port compiling again, hopefully [Sintendo]
- ruby/video/xshm: fix crashing bug on window resize
- a bit hacky; it's throwing BadAccess Xlib warnings, but they're
not fatal, so I am catching and ignoring them
- bsnes: removed Application::Windows::onModalChange hook that's no
longer needed [Screwtape]
2018-08-26 06:49:54 +00:00
|
|
|
for(uint byte : range(8)) output.append(input.size() >> byte * 8);
|
2018-08-21 03:17:12 +00:00
|
|
|
|
Update to v106r59 release.
byuu says:
Changelog:
- fixed bug in Emulator::Game::Memory::operator bool()
- nall: renamed view<string> back to `string_view`
- nall:: implemented `array_view`
- Game Boy: split cartridge-specific input mappings (rumble,
accelerometer) to their own separate ports
- Game Boy: fixed MBC7 accelerometer x-axis
- icarus: Game Boy, Super Famicom, Mega Drive cores output internal
header game titles to heuristics manifests
- higan, icarus, hiro/gtk: improve viewport geometry configuration;
fixed higan crashing bug with XShm driver
- higan: connect Video::poll(),update() functionality
- hiro, ruby: several compilation / bugfixes, should get the macOS
port compiling again, hopefully [Sintendo]
- ruby/video/xshm: fix crashing bug on window resize
- a bit hacky; it's throwing BadAccess Xlib warnings, but they're
not fatal, so I am catching and ignoring them
- bsnes: removed Application::Windows::onModalChange hook that's no
longer needed [Screwtape]
2018-08-26 06:49:54 +00:00
|
|
|
auto suffixArray = SuffixArray(input).lpf();
|
2018-08-21 03:17:12 +00:00
|
|
|
uint index = 0;
|
|
|
|
vector<uint8_t> flags;
|
|
|
|
vector<uint8_t> literals;
|
|
|
|
vector<uint8_t> stringLengths;
|
|
|
|
vector<uint8_t> stringOffsets;
|
|
|
|
|
|
|
|
uint byte = 0, bits = 0;
|
|
|
|
auto flagWrite = [&](bool bit) {
|
|
|
|
byte = byte << 1 | bit;
|
|
|
|
if(++bits == 8) flags.append(byte), bits = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
auto literalWrite = [&](uint8_t literal) {
|
|
|
|
literals.append(literal);
|
|
|
|
};
|
|
|
|
|
|
|
|
auto lengthWrite = [&](uint64_t length) {
|
|
|
|
if(length < 1 << 7) length = length << 1 | 0b1;
|
|
|
|
else if(length < 1 << 14) length = length << 2 | 0b10;
|
|
|
|
else if(length < 1 << 21) length = length << 3 | 0b100;
|
|
|
|
else if(length < 1 << 28) length = length << 4 | 0b1000;
|
|
|
|
else /*length < 1 << 35*/length = length << 5 | 0b10000;
|
|
|
|
while(length) stringLengths.append(length), length >>= 8;
|
|
|
|
};
|
|
|
|
|
|
|
|
auto offsetWrite = [&](uint offset) {
|
|
|
|
stringOffsets.append(offset >> 0); if(index < 1 << 8) return;
|
|
|
|
stringOffsets.append(offset >> 8); if(index < 1 << 16) return;
|
|
|
|
stringOffsets.append(offset >> 16); if(index < 1 << 24) return;
|
|
|
|
stringOffsets.append(offset >> 24);
|
|
|
|
};
|
|
|
|
|
Update to v106r59 release.
byuu says:
Changelog:
- fixed bug in Emulator::Game::Memory::operator bool()
- nall: renamed view<string> back to `string_view`
- nall:: implemented `array_view`
- Game Boy: split cartridge-specific input mappings (rumble,
accelerometer) to their own separate ports
- Game Boy: fixed MBC7 accelerometer x-axis
- icarus: Game Boy, Super Famicom, Mega Drive cores output internal
header game titles to heuristics manifests
- higan, icarus, hiro/gtk: improve viewport geometry configuration;
fixed higan crashing bug with XShm driver
- higan: connect Video::poll(),update() functionality
- hiro, ruby: several compilation / bugfixes, should get the macOS
port compiling again, hopefully [Sintendo]
- ruby/video/xshm: fix crashing bug on window resize
- a bit hacky; it's throwing BadAccess Xlib warnings, but they're
not fatal, so I am catching and ignoring them
- bsnes: removed Application::Windows::onModalChange hook that's no
longer needed [Screwtape]
2018-08-26 06:49:54 +00:00
|
|
|
while(index < input.size()) {
|
|
|
|
int length, offset;
|
|
|
|
suffixArray.previous(length, offset, index);
|
2018-08-21 03:17:12 +00:00
|
|
|
|
2018-10-04 10:11:23 +00:00
|
|
|
/* for(uint ahead = 1; ahead <= 2; ahead++) {
|
Update to v106r59 release.
byuu says:
Changelog:
- fixed bug in Emulator::Game::Memory::operator bool()
- nall: renamed view<string> back to `string_view`
- nall:: implemented `array_view`
- Game Boy: split cartridge-specific input mappings (rumble,
accelerometer) to their own separate ports
- Game Boy: fixed MBC7 accelerometer x-axis
- icarus: Game Boy, Super Famicom, Mega Drive cores output internal
header game titles to heuristics manifests
- higan, icarus, hiro/gtk: improve viewport geometry configuration;
fixed higan crashing bug with XShm driver
- higan: connect Video::poll(),update() functionality
- hiro, ruby: several compilation / bugfixes, should get the macOS
port compiling again, hopefully [Sintendo]
- ruby/video/xshm: fix crashing bug on window resize
- a bit hacky; it's throwing BadAccess Xlib warnings, but they're
not fatal, so I am catching and ignoring them
- bsnes: removed Application::Windows::onModalChange hook that's no
longer needed [Screwtape]
2018-08-26 06:49:54 +00:00
|
|
|
int aheadLength, aheadOffset;
|
|
|
|
suffixArray.previous(aheadLength, aheadOffset, index + ahead);
|
2018-08-21 03:17:12 +00:00
|
|
|
if(aheadLength > length && aheadOffset >= 0) {
|
|
|
|
length = 0;
|
|
|
|
break;
|
|
|
|
}
|
2018-10-04 10:11:23 +00:00
|
|
|
} */
|
2018-08-21 03:17:12 +00:00
|
|
|
|
|
|
|
if(length < 6 || offset < 0) {
|
|
|
|
flagWrite(0);
|
|
|
|
literalWrite(input[index++]);
|
|
|
|
} else {
|
|
|
|
flagWrite(1);
|
|
|
|
lengthWrite(length - 6);
|
|
|
|
offsetWrite(index - offset);
|
|
|
|
index += length;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while(bits) flagWrite(0);
|
|
|
|
|
|
|
|
auto save = [&](const vector<uint8_t>& buffer) {
|
|
|
|
for(uint byte : range(8)) output.append(buffer.size() >> byte * 8);
|
|
|
|
output.append(buffer);
|
|
|
|
};
|
|
|
|
|
|
|
|
save(Encode::Huffman(flags));
|
|
|
|
save(Encode::Huffman(literals));
|
|
|
|
save(Encode::Huffman(stringLengths));
|
|
|
|
save(Encode::Huffman(stringOffsets));
|
|
|
|
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
2019-01-16 00:46:42 +00:00
|
|
|
}
|