mirror of
https://github.com/bsnes-emu/bsnes.git
synced 2025-02-23 22:52:34 +01:00
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.
152 lines
3.9 KiB
C++
152 lines
3.9 KiB
C++
#ifndef NALL_BEAT_LINEAR_HPP
|
|
#define NALL_BEAT_LINEAR_HPP
|
|
|
|
#include <nall/file.hpp>
|
|
#include <nall/filemap.hpp>
|
|
#include <nall/stdint.hpp>
|
|
#include <nall/string.hpp>
|
|
|
|
namespace nall {
|
|
|
|
struct bpslinear {
|
|
inline void source(const uint8_t* data, unsigned size);
|
|
inline void target(const uint8_t* data, unsigned size);
|
|
|
|
inline bool source(const string& filename);
|
|
inline bool target(const string& filename);
|
|
inline bool create(const string& filename, const string& metadata = "");
|
|
|
|
protected:
|
|
enum : unsigned { SourceRead, TargetRead, SourceCopy, TargetCopy };
|
|
enum : unsigned { Granularity = 1 };
|
|
|
|
filemap sourceFile;
|
|
const uint8_t* sourceData;
|
|
unsigned sourceSize;
|
|
|
|
filemap targetFile;
|
|
const uint8_t* targetData;
|
|
unsigned targetSize;
|
|
};
|
|
|
|
void bpslinear::source(const uint8_t* data, unsigned size) {
|
|
sourceData = data;
|
|
sourceSize = size;
|
|
}
|
|
|
|
void bpslinear::target(const uint8_t* data, unsigned size) {
|
|
targetData = data;
|
|
targetSize = size;
|
|
}
|
|
|
|
bool bpslinear::source(const string& filename) {
|
|
if(sourceFile.open(filename, filemap::mode::read) == false) return false;
|
|
source(sourceFile.data(), sourceFile.size());
|
|
return true;
|
|
}
|
|
|
|
bool bpslinear::target(const string& filename) {
|
|
if(targetFile.open(filename, filemap::mode::read) == false) return false;
|
|
target(targetFile.data(), targetFile.size());
|
|
return true;
|
|
}
|
|
|
|
bool bpslinear::create(const string& filename, const string& metadata) {
|
|
file modifyFile;
|
|
if(modifyFile.open(filename, file::mode::write) == false) return false;
|
|
|
|
Hash::CRC32 modifyChecksum;
|
|
unsigned targetRelativeOffset = 0, outputOffset = 0;
|
|
|
|
auto write = [&](uint8_t data) {
|
|
modifyFile.write(data);
|
|
modifyChecksum.data(data);
|
|
};
|
|
|
|
auto encode = [&](uint64_t data) {
|
|
while(true) {
|
|
uint64_t x = data & 0x7f;
|
|
data >>= 7;
|
|
if(data == 0) {
|
|
write(0x80 | x);
|
|
break;
|
|
}
|
|
write(x);
|
|
data--;
|
|
}
|
|
};
|
|
|
|
unsigned targetReadLength = 0;
|
|
|
|
auto targetReadFlush = [&]() {
|
|
if(targetReadLength) {
|
|
encode(TargetRead | ((targetReadLength - 1) << 2));
|
|
unsigned offset = outputOffset - targetReadLength;
|
|
while(targetReadLength) write(targetData[offset++]), targetReadLength--;
|
|
}
|
|
};
|
|
|
|
write('B');
|
|
write('P');
|
|
write('S');
|
|
write('1');
|
|
|
|
encode(sourceSize);
|
|
encode(targetSize);
|
|
|
|
unsigned markupSize = metadata.length();
|
|
encode(markupSize);
|
|
for(unsigned n = 0; n < markupSize; n++) write(metadata[n]);
|
|
|
|
while(outputOffset < targetSize) {
|
|
unsigned sourceLength = 0;
|
|
for(unsigned n = 0; outputOffset + n < min(sourceSize, targetSize); n++) {
|
|
if(sourceData[outputOffset + n] != targetData[outputOffset + n]) break;
|
|
sourceLength++;
|
|
}
|
|
|
|
unsigned rleLength = 0;
|
|
for(unsigned n = 1; outputOffset + n < targetSize; n++) {
|
|
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));
|
|
unsigned relativeOffset = (outputOffset - 1) - targetRelativeOffset;
|
|
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();
|
|
|
|
uint32_t sourceChecksum = Hash::CRC32(sourceData, sourceSize).value();
|
|
for(unsigned n = 0; n < 32; n += 8) write(sourceChecksum >> n);
|
|
uint32_t targetChecksum = Hash::CRC32(targetData, targetSize).value();
|
|
for(unsigned n = 0; n < 32; n += 8) write(targetChecksum >> n);
|
|
uint32_t outputChecksum = modifyChecksum.value();
|
|
for(unsigned n = 0; n < 32; n += 8) write(outputChecksum >> n);
|
|
|
|
modifyFile.close();
|
|
return true;
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|