2016-01-07 08:14:33 +00:00
|
|
|
#pragma once
|
2011-08-18 13:58:27 +00:00
|
|
|
|
|
|
|
#include <nall/file.hpp>
|
|
|
|
#include <nall/filemap.hpp>
|
|
|
|
#include <nall/stdint.hpp>
|
|
|
|
#include <nall/string.hpp>
|
|
|
|
|
|
|
|
namespace nall {
|
|
|
|
|
|
|
|
struct bpslinear {
|
2015-12-14 09:41:06 +00:00
|
|
|
inline auto source(const uint8* data, uint size) -> void;
|
|
|
|
inline auto target(const uint8* data, uint size) -> void;
|
2011-08-20 14:40:44 +00:00
|
|
|
|
2015-12-14 09:41:06 +00:00
|
|
|
inline auto source(const string& filename) -> bool;
|
|
|
|
inline auto target(const string& filename) -> bool;
|
|
|
|
inline auto create(const string& filename, const string& metadata = "") -> bool;
|
2011-08-18 13:58:27 +00:00
|
|
|
|
|
|
|
protected:
|
2015-12-14 09:41:06 +00:00
|
|
|
enum : uint { SourceRead, TargetRead, SourceCopy, TargetCopy };
|
|
|
|
enum : uint { Granularity = 1 };
|
2011-08-18 13:58:27 +00:00
|
|
|
|
|
|
|
filemap sourceFile;
|
2015-12-14 09:41:06 +00:00
|
|
|
const uint8* sourceData;
|
|
|
|
uint sourceSize;
|
2011-08-18 13:58:27 +00:00
|
|
|
|
|
|
|
filemap targetFile;
|
2015-12-14 09:41:06 +00:00
|
|
|
const uint8* targetData;
|
|
|
|
uint targetSize;
|
2011-08-18 13:58:27 +00:00
|
|
|
};
|
|
|
|
|
2015-12-14 09:41:06 +00:00
|
|
|
auto bpslinear::source(const uint8* data, uint size) -> void {
|
2011-08-20 14:40:44 +00:00
|
|
|
sourceData = data;
|
|
|
|
sourceSize = size;
|
|
|
|
}
|
|
|
|
|
2015-12-14 09:41:06 +00:00
|
|
|
auto bpslinear::target(const uint8* data, uint size) -> void {
|
2011-08-20 14:40:44 +00:00
|
|
|
targetData = data;
|
|
|
|
targetSize = size;
|
|
|
|
}
|
|
|
|
|
2015-12-14 09:41:06 +00:00
|
|
|
auto bpslinear::source(const string& filename) -> bool {
|
2011-08-18 13:58:27 +00:00
|
|
|
if(sourceFile.open(filename, filemap::mode::read) == false) return false;
|
2011-08-20 14:40:44 +00:00
|
|
|
source(sourceFile.data(), sourceFile.size());
|
2011-08-18 13:58:27 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-12-14 09:41:06 +00:00
|
|
|
auto bpslinear::target(const string& filename) -> bool {
|
2011-08-18 13:58:27 +00:00
|
|
|
if(targetFile.open(filename, filemap::mode::read) == false) return false;
|
2011-08-20 14:40:44 +00:00
|
|
|
target(targetFile.data(), targetFile.size());
|
2011-08-18 13:58:27 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-12-14 09:41:06 +00:00
|
|
|
auto bpslinear::create(const string& filename, const string& metadata) -> bool {
|
2011-08-18 13:58:27 +00:00
|
|
|
file modifyFile;
|
|
|
|
if(modifyFile.open(filename, file::mode::write) == false) return false;
|
|
|
|
|
Update to v094r09 release.
byuu says:
This will easily be the biggest diff in the history of higan. And not in
a good way.
* target-higan and target-loki have been blown away completely
* nall and ruby massively updated
* phoenix replaced with hiro (pretty near a total rewrite)
* target-higan restarted using hiro (just a window for now)
* all emulation cores updated to compile again
* installation changed to not require root privileges (installs locally)
For the foreseeable future (maybe even permanently?), the new higan UI
will only build under Linux/BSD with GTK+ 2.20+. Probably the most
likely route for Windows/OS X will be to try and figure out how to build
hiro/GTK on those platforms, as awful as that would be. The other
alternative would be to produce new UIs for those platforms ... which
would actually be a good opportunity to make something much more user
friendly.
Being that I just started on this a few hours ago, that means that for
at least a few weeks, don't expect to be able to actually play any
games. Right now, you can pretty much just compile the binary and that's
it. It's quite possible that some nall changes didn't produce
compilation errors, but will produce runtime errors. So until the UI can
actually load games, we won't know if anything is broken. But we should
mostly be okay. It was mostly just trim<1> -> trim changes, moving to
Hash::SHA256 (much cleaner), and patching some reckless memory copy
functions enough to compile.
Progress isn't going to be like it was before: I'm now dividing my time
much thinner between studying and other hobbies.
My aim this time is not to produce a binary for everyone to play games
on. Rather, it's to keep the emulator alive. I want to be able to apply
critical patches again. And I would also like the base of the emulator
to live on, for use in other emulator frontends that utilize higan.
2015-02-26 10:10:46 +00:00
|
|
|
Hash::CRC32 modifyChecksum;
|
2015-12-14 09:41:06 +00:00
|
|
|
uint targetRelativeOffset = 0, outputOffset = 0;
|
2011-08-18 13:58:27 +00:00
|
|
|
|
2015-12-14 09:41:06 +00:00
|
|
|
auto write = [&](uint8 data) {
|
2011-08-18 13:58:27 +00:00
|
|
|
modifyFile.write(data);
|
Update to v094r09 release.
byuu says:
This will easily be the biggest diff in the history of higan. And not in
a good way.
* target-higan and target-loki have been blown away completely
* nall and ruby massively updated
* phoenix replaced with hiro (pretty near a total rewrite)
* target-higan restarted using hiro (just a window for now)
* all emulation cores updated to compile again
* installation changed to not require root privileges (installs locally)
For the foreseeable future (maybe even permanently?), the new higan UI
will only build under Linux/BSD with GTK+ 2.20+. Probably the most
likely route for Windows/OS X will be to try and figure out how to build
hiro/GTK on those platforms, as awful as that would be. The other
alternative would be to produce new UIs for those platforms ... which
would actually be a good opportunity to make something much more user
friendly.
Being that I just started on this a few hours ago, that means that for
at least a few weeks, don't expect to be able to actually play any
games. Right now, you can pretty much just compile the binary and that's
it. It's quite possible that some nall changes didn't produce
compilation errors, but will produce runtime errors. So until the UI can
actually load games, we won't know if anything is broken. But we should
mostly be okay. It was mostly just trim<1> -> trim changes, moving to
Hash::SHA256 (much cleaner), and patching some reckless memory copy
functions enough to compile.
Progress isn't going to be like it was before: I'm now dividing my time
much thinner between studying and other hobbies.
My aim this time is not to produce a binary for everyone to play games
on. Rather, it's to keep the emulator alive. I want to be able to apply
critical patches again. And I would also like the base of the emulator
to live on, for use in other emulator frontends that utilize higan.
2015-02-26 10:10:46 +00:00
|
|
|
modifyChecksum.data(data);
|
2011-08-18 13:58:27 +00:00
|
|
|
};
|
|
|
|
|
2015-12-14 09:41:06 +00:00
|
|
|
auto encode = [&](uint64 data) {
|
2011-08-18 13:58:27 +00:00
|
|
|
while(true) {
|
2015-12-14 09:41:06 +00:00
|
|
|
uint64 x = data & 0x7f;
|
2011-08-18 13:58:27 +00:00
|
|
|
data >>= 7;
|
|
|
|
if(data == 0) {
|
|
|
|
write(0x80 | x);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
write(x);
|
|
|
|
data--;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-12-14 09:41:06 +00:00
|
|
|
uint targetReadLength = 0;
|
2011-08-18 13:58:27 +00:00
|
|
|
|
|
|
|
auto targetReadFlush = [&]() {
|
|
|
|
if(targetReadLength) {
|
|
|
|
encode(TargetRead | ((targetReadLength - 1) << 2));
|
2015-12-14 09:41:06 +00:00
|
|
|
uint offset = outputOffset - targetReadLength;
|
2011-08-18 13:58:27 +00:00
|
|
|
while(targetReadLength) write(targetData[offset++]), targetReadLength--;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
write('B');
|
|
|
|
write('P');
|
|
|
|
write('S');
|
|
|
|
write('1');
|
|
|
|
|
|
|
|
encode(sourceSize);
|
|
|
|
encode(targetSize);
|
|
|
|
|
2015-12-14 09:41:06 +00:00
|
|
|
uint markupSize = metadata.length();
|
2011-08-18 13:58:27 +00:00
|
|
|
encode(markupSize);
|
2015-12-14 09:41:06 +00:00
|
|
|
for(uint n = 0; n < markupSize; n++) write(metadata[n]);
|
2011-08-18 13:58:27 +00:00
|
|
|
|
|
|
|
while(outputOffset < targetSize) {
|
2015-12-14 09:41:06 +00:00
|
|
|
uint sourceLength = 0;
|
|
|
|
for(uint n = 0; outputOffset + n < min(sourceSize, targetSize); n++) {
|
2011-08-18 13:58:27 +00:00
|
|
|
if(sourceData[outputOffset + n] != targetData[outputOffset + n]) break;
|
|
|
|
sourceLength++;
|
|
|
|
}
|
|
|
|
|
2015-12-14 09:41:06 +00:00
|
|
|
uint rleLength = 0;
|
|
|
|
for(uint n = 1; outputOffset + n < targetSize; n++) {
|
2011-08-18 13:58:27 +00:00
|
|
|
if(targetData[outputOffset] != targetData[outputOffset + n]) break;
|
|
|
|
rleLength++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(rleLength >= 4) {
|
|
|
|
//write byte to repeat
|
|
|
|
targetReadLength++;
|
|
|
|
outputOffset++;
|
|
|
|
targetReadFlush();
|
|
|
|
|
|
|
|
//copy starting from repetition byte
|
|
|
|
encode(TargetCopy | ((rleLength - 1) << 2));
|
2015-12-14 09:41:06 +00:00
|
|
|
uint relativeOffset = (outputOffset - 1) - targetRelativeOffset;
|
2011-08-18 13:58:27 +00:00
|
|
|
encode(relativeOffset << 1);
|
|
|
|
outputOffset += rleLength;
|
|
|
|
targetRelativeOffset = outputOffset - 1;
|
|
|
|
} else if(sourceLength >= 4) {
|
|
|
|
targetReadFlush();
|
|
|
|
encode(SourceRead | ((sourceLength - 1) << 2));
|
|
|
|
outputOffset += sourceLength;
|
|
|
|
} else {
|
|
|
|
targetReadLength += Granularity;
|
|
|
|
outputOffset += Granularity;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
targetReadFlush();
|
|
|
|
|
2015-12-14 09:41:06 +00:00
|
|
|
uint32 sourceChecksum = Hash::CRC32(sourceData, sourceSize).value();
|
|
|
|
for(uint n = 0; n < 32; n += 8) write(sourceChecksum >> n);
|
|
|
|
uint32 targetChecksum = Hash::CRC32(targetData, targetSize).value();
|
|
|
|
for(uint n = 0; n < 32; n += 8) write(targetChecksum >> n);
|
|
|
|
uint32 outputChecksum = modifyChecksum.value();
|
|
|
|
for(uint n = 0; n < 32; n += 8) write(outputChecksum >> n);
|
2011-08-18 13:58:27 +00:00
|
|
|
|
|
|
|
modifyFile.close();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|