Update to v094r38 release.

byuu says:

I'll post more detailed changes later, but basically:
- fixed Baldur's Gate bug
- guess if no flash ROM ID present (fixes Magical Vacation, many many
  others)
- nall cleanups
- sfc/cartridge major cleanups
- bsxcartridge/"bsx" renamed to mcc/"mcc" after the logic chip it uses
  (consistency with SGB/ICD2)
- ... and more!
This commit is contained in:
Tim Allen
2015-08-02 16:23:13 +10:00
parent 092cac9073
commit 1b0b54a690
81 changed files with 1191 additions and 1256 deletions

70
nall/encode/base64.hpp Normal file
View File

@@ -0,0 +1,70 @@
#ifndef NALL_ENCODE_BASE64_HPP
#define NALL_ENCODE_BASE64_HPP
namespace nall { namespace Encode {
inline auto Base64(const uint8_t* data, unsigned size, const string& format = "MIME") -> string {
vector<uint8_t> result;
char lookup[65];
for(unsigned n = 0; n < 26; n++) lookup[ 0 + n] = 'A' + n;
for(unsigned n = 0; n < 26; n++) lookup[26 + n] = 'a' + n;
for(unsigned n = 0; n < 10; n++) lookup[52 + n] = '0' + n;
if(format == "MIME") {
lookup[62] = '+';
lookup[63] = '/';
lookup[64] = '=';
} else if(format == "URI") {
lookup[62] = '-';
lookup[63] = '_';
lookup[64] = 0;
} else return "";
unsigned overflow = (3 - (size % 3)) % 3; //bytes to round to nearest multiple of 3
uint8_t buffer;
for(unsigned i = 0; i < size; i++) {
switch(i % 3) {
case 0:
buffer = data[i] >> 2;
result.append(lookup[buffer]);
buffer = (data[i] & 3) << 4;
result.append(lookup[buffer]);
break;
case 1:
buffer |= data[i] >> 4;
result.last() = lookup[buffer];
buffer = (data[i] & 15) << 2;
result.append(lookup[buffer]);
break;
case 2:
buffer |= data[i] >> 6;
result.last() = lookup[buffer];
buffer = (data[i] & 63);
result.append(lookup[buffer]);
break;
}
}
if(lookup[64]) {
if(overflow >= 1) result.append(lookup[64]);
if(overflow >= 2) result.append(lookup[64]);
}
return result;
}
inline auto Base64(const vector<uint8_t>& buffer, const string& format = "MIME") -> string {
return Base64(buffer.data(), buffer.size(), format);
}
inline auto Base64(const string& text, const string& format = "MIME") -> string {
return Base64(text.binary(), text.size(), format);
}
}}
#endif

49
nall/encode/bmp.hpp Normal file
View File

@@ -0,0 +1,49 @@
#ifndef NALL_ENCODE_BMP_HPP
#define NALL_ENCODE_BMP_HPP
namespace nall { namespace Encode {
struct BMP {
static auto create(const string& filename, const uint32_t* data, unsigned width, unsigned height, bool alpha) -> bool {
file fp{filename, file::mode::write};
if(!fp) return false;
unsigned bitsPerPixel = alpha ? 32 : 24;
unsigned bytesPerPixel = bitsPerPixel / 8;
unsigned alignedWidth = width * bytesPerPixel;
unsigned paddingLength = 0;
unsigned imageSize = alignedWidth * height;
unsigned fileSize = 0x36 + imageSize;
while(alignedWidth % 4) alignedWidth++, paddingLength++;
fp.writel(0x4d42, 2); //signature
fp.writel(fileSize, 4); //file size
fp.writel(0, 2); //reserved
fp.writel(0, 2); //reserved
fp.writel(0x36, 4); //offset
fp.writel(40, 4); //DIB size
fp.writel(width, 4); //width
fp.writel(-height, 4); //height
fp.writel(1, 2); //color planes
fp.writel(bitsPerPixel, 2); //bits per pixel
fp.writel(0, 4); //compression method (BI_RGB)
fp.writel(imageSize, 4); //image data size
fp.writel(3780, 4); //horizontal resolution
fp.writel(3780, 4); //vertical resolution
fp.writel(0, 4); //palette size
fp.writel(0, 4); //important color count
for(auto y : range(height)) {
const uint32_t* p = data + y * width;
for(auto x : range(width)) fp.writel(*p++, bytesPerPixel);
if(paddingLength) fp.writel(0, paddingLength);
}
return true;
}
};
}}
#endif

View File

@@ -1,5 +1,5 @@
#ifndef NALL_ZIP_HPP
#define NALL_ZIP_HPP
#ifndef NALL_ENCODE_ZIP_HPP
#define NALL_ENCODE_ZIP_HPP
//creates uncompressed ZIP archives
@@ -19,7 +19,7 @@ struct ZIP {
//append path: append("path/");
//append file: append("path/file", data, size);
void append(string filename, const uint8_t* data = nullptr, unsigned size = 0u) {
auto append(string filename, const uint8_t* data = nullptr, unsigned size = 0u) -> void {
filename.transform("\\", "/");
uint32_t checksum = Hash::CRC32(data, size).value();
directory.append({filename, checksum, size, fp.offset()});