diff -Nru bsnes-0.073/debian/changelog bsnes-0.073/debian/changelog --- bsnes-0.073/debian/changelog 2010-12-24 17:19:03.000000000 +0000 +++ bsnes-0.073/debian/changelog 2010-12-24 20:17:12.000000000 +0000 @@ -1,4 +1,4 @@ -bsnes (0.073-0ubuntu0~filthypants1) maverick; urgency=low +bsnes (0.073-0ubuntu0~filthypants2) maverick; urgency=low * added NEC uPD77C25 emulation core * added low-level emulation of the DSP-1, DSP-1B, DSP-2, DSP-3, DSP-4 coprocessors diff -Nru bsnes-0.073/snesfilter/2xsai/2xsai.cpp bsnes-0.073/snesfilter/2xsai/2xsai.cpp --- bsnes-0.073/snesfilter/2xsai/2xsai.cpp 2010-10-26 05:14:47.000000000 +0000 +++ bsnes-0.073/snesfilter/2xsai/2xsai.cpp 2010-04-14 05:02:39.000000000 +0000 @@ -1,32 +1,132 @@ -#include -#include -using namespace nall; +//2xSaI / Super 2xSaI / Super Eagle filter +//authors: kode54 and Kreed +//license: GPL +#include "2xsai.hpp" #include "implementation.cpp" -extern "C" { - void filter_size(unsigned&, unsigned&); - void filter_render(uint32_t*, uint32_t*, unsigned, const uint16_t*, unsigned, unsigned, unsigned); -}; - -uint32_t temp[512 * 480]; - -dllexport void filter_size(unsigned &width, unsigned &height) { - width *= 2; - height *= 2; +//===== +//2xSaI +//===== + +void _2xSaIFilter::size(unsigned &outwidth, unsigned &outheight, unsigned width, unsigned height) { + outwidth = width; + outheight = height; + + if(width <= 256 && height <= 240) { + outwidth *= 2; + outheight *= 2; + } +} + +void _2xSaIFilter::render( + uint32_t *output, unsigned outpitch, + const uint16_t *input, unsigned pitch, unsigned width, unsigned height +) { + if(width > 256 || height > 240) { + filter_direct.render(output, outpitch, input, pitch, width, height); + return; + } + + for(unsigned y = 0; y < height; y++) { + const uint16_t *line_in = (const uint16_t *) (((const uint8_t*)input) + pitch * y); + uint32_t *line_out = temp + y * 256; + for(unsigned x = 0; x < width; x++) { + line_out[x] = colortable[line_in[x]]; + } + } + + _2xSaI32( (unsigned char *) temp, 1024, 0, (unsigned char *) output, outpitch, width, height ); +} + +_2xSaIFilter::_2xSaIFilter() { + temp = new uint32_t[256*240]; +} + +_2xSaIFilter::~_2xSaIFilter() { + delete[] temp; } -dllexport void filter_render( - uint32_t *colortable, uint32_t *output, unsigned outpitch, - const uint16_t *input, unsigned pitch, unsigned width, unsigned height -) { - for(unsigned y = 0; y < height; y++) { - const uint16_t *line_in = (const uint16_t *) (((const uint8_t*)input) + pitch * y); - uint32_t *line_out = temp + y * width; - for(unsigned x = 0; x < width; x++) { - line_out[x] = colortable[line_in[x]]; - } - } - - _2xSaI32( (unsigned char *) temp, 2048, 0, (unsigned char *) output, outpitch, width, height ); +//=========== +//Super 2xSaI +//=========== + +void Super2xSaIFilter::size(unsigned &outwidth, unsigned &outheight, unsigned width, unsigned height) { + outwidth = width; + outheight = height; + + if(width <= 256 && height <= 240) { + outwidth *= 2; + outheight *= 2; + } +} + +void Super2xSaIFilter::render( + uint32_t *output, unsigned outpitch, + const uint16_t *input, unsigned pitch, unsigned width, unsigned height +) { + if(width > 256 || height > 240) { + filter_direct.render(output, outpitch, input, pitch, width, height); + return; + } + + for(unsigned y = 0; y < height; y++) { + const uint16_t *line_in = (const uint16_t *) (((const uint8_t*)input) + pitch * y); + uint32_t *line_out = temp + y * 256; + for(unsigned x = 0; x < width; x++) { + line_out[x] = colortable[line_in[x]]; + } + } + + Super2xSaI32( (unsigned char *) temp, 1024, 0, (unsigned char *) output, outpitch, width, height ); +} + +Super2xSaIFilter::Super2xSaIFilter() { + temp = new uint32_t[256*240]; +} + +Super2xSaIFilter::~Super2xSaIFilter() { + delete[] temp; +} + +//=========== +//Super Eagle +//=========== + +void SuperEagleFilter::size(unsigned &outwidth, unsigned &outheight, unsigned width, unsigned height) { + outwidth = width; + outheight = height; + + if(width <= 256 && height <= 240) { + outwidth *= 2; + outheight *= 2; + } +} + +void SuperEagleFilter::render( + uint32_t *output, unsigned outpitch, + const uint16_t *input, unsigned pitch, unsigned width, unsigned height +) { + if(width > 256 || height > 240) { + filter_direct.render(output, outpitch, input, pitch, width, height); + return; + } + + for(unsigned y = 0; y < height; y++) { + const uint16_t *line_in = (const uint16_t *) (((const uint8_t*)input) + pitch * y); + uint32_t *line_out = temp + y * 256; + for(unsigned x = 0; x < width; x++) { + line_out[x] = colortable[line_in[x]]; + } + } + + SuperEagle32( (unsigned char *) temp, 1024, 0, (unsigned char *) output, outpitch, width, height ); +} + +SuperEagleFilter::SuperEagleFilter() { + temp = new uint32_t[256*240]; +} + +SuperEagleFilter::~SuperEagleFilter() { + delete[] temp; } diff -Nru bsnes-0.073/snesfilter/2xsai/2xsai.hpp bsnes-0.073/snesfilter/2xsai/2xsai.hpp --- bsnes-0.073/snesfilter/2xsai/2xsai.hpp 1970-01-01 00:00:00.000000000 +0000 +++ bsnes-0.073/snesfilter/2xsai/2xsai.hpp 2010-04-14 05:02:02.000000000 +0000 @@ -0,0 +1,35 @@ +class _2xSaIFilter { +public: + void size(unsigned&, unsigned&, unsigned, unsigned); + void render(uint32_t*, unsigned, const uint16_t*, unsigned, unsigned, unsigned); + + _2xSaIFilter(); + ~_2xSaIFilter(); + +private: + uint32_t *temp; +} filter_2xsai; + +class Super2xSaIFilter { +public: + void size(unsigned&, unsigned&, unsigned, unsigned); + void render(uint32_t*, unsigned, const uint16_t*, unsigned, unsigned, unsigned); + + Super2xSaIFilter(); + ~Super2xSaIFilter(); + +private: + uint32_t *temp; +} filter_super2xsai; + +class SuperEagleFilter { +public: + void size(unsigned&, unsigned&, unsigned, unsigned); + void render(uint32_t*, unsigned, const uint16_t*, unsigned, unsigned, unsigned); + + SuperEagleFilter(); + ~SuperEagleFilter(); + +private: + uint32_t *temp; +} filter_supereagle; diff -Nru bsnes-0.073/snesfilter/2xsai/super-2xsai.cpp bsnes-0.073/snesfilter/2xsai/super-2xsai.cpp --- bsnes-0.073/snesfilter/2xsai/super-2xsai.cpp 2010-10-26 05:17:25.000000000 +0000 +++ bsnes-0.073/snesfilter/2xsai/super-2xsai.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,32 +0,0 @@ -#include -#include -using namespace nall; - -#include "implementation.cpp" - -extern "C" { - void filter_size(unsigned&, unsigned&); - void filter_render(uint32_t*, uint32_t*, unsigned, const uint16_t*, unsigned, unsigned, unsigned); -}; - -uint32_t temp[512 * 480]; - -dllexport void filter_size(unsigned &width, unsigned &height) { - width *= 2; - height *= 2; -} - -dllexport void filter_render( - uint32_t *colortable, uint32_t *output, unsigned outpitch, - const uint16_t *input, unsigned pitch, unsigned width, unsigned height -) { - for(unsigned y = 0; y < height; y++) { - const uint16_t *line_in = (const uint16_t *) (((const uint8_t*)input) + pitch * y); - uint32_t *line_out = temp + y * width; - for(unsigned x = 0; x < width; x++) { - line_out[x] = colortable[line_in[x]]; - } - } - - Super2xSaI32( (unsigned char *) temp, 2048, 0, (unsigned char *) output, outpitch, width, height ); -} diff -Nru bsnes-0.073/snesfilter/2xsai/super-eagle.cpp bsnes-0.073/snesfilter/2xsai/super-eagle.cpp --- bsnes-0.073/snesfilter/2xsai/super-eagle.cpp 2010-10-26 05:18:03.000000000 +0000 +++ bsnes-0.073/snesfilter/2xsai/super-eagle.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,32 +0,0 @@ -#include -#include -using namespace nall; - -#include "implementation.cpp" - -extern "C" { - void filter_size(unsigned&, unsigned&); - void filter_render(uint32_t*, uint32_t*, unsigned, const uint16_t*, unsigned, unsigned, unsigned); -}; - -uint32_t temp[512 * 480]; - -dllexport void filter_size(unsigned &width, unsigned &height) { - width *= 2; - height *= 2; -} - -dllexport void filter_render( - uint32_t *colortable, uint32_t *output, unsigned outpitch, - const uint16_t *input, unsigned pitch, unsigned width, unsigned height -) { - for(unsigned y = 0; y < height; y++) { - const uint16_t *line_in = (const uint16_t *) (((const uint8_t*)input) + pitch * y); - uint32_t *line_out = temp + y * width; - for(unsigned x = 0; x < width; x++) { - line_out[x] = colortable[line_in[x]]; - } - } - - SuperEagle32( (unsigned char *) temp, 2048, 0, (unsigned char *) output, outpitch, width, height ); -} diff -Nru bsnes-0.073/snesfilter/cc.bat bsnes-0.073/snesfilter/cc.bat --- bsnes-0.073/snesfilter/cc.bat 1970-01-01 00:00:00.000000000 +0000 +++ bsnes-0.073/snesfilter/cc.bat 2009-09-29 02:07:03.000000000 +0000 @@ -0,0 +1,2 @@ +@mingw32-make +@pause \ No newline at end of file diff -Nru bsnes-0.073/snesfilter/clean.bat bsnes-0.073/snesfilter/clean.bat --- bsnes-0.073/snesfilter/clean.bat 1970-01-01 00:00:00.000000000 +0000 +++ bsnes-0.073/snesfilter/clean.bat 2009-09-29 02:07:14.000000000 +0000 @@ -0,0 +1 @@ +@mingw32-make clean diff -Nru bsnes-0.073/snesfilter/direct/direct.cpp bsnes-0.073/snesfilter/direct/direct.cpp --- bsnes-0.073/snesfilter/direct/direct.cpp 1970-01-01 00:00:00.000000000 +0000 +++ bsnes-0.073/snesfilter/direct/direct.cpp 2010-04-14 04:37:02.000000000 +0000 @@ -0,0 +1,23 @@ +#include "direct.hpp" + +void DirectFilter::size(unsigned &outwidth, unsigned &outheight, unsigned width, unsigned height) { + outwidth = width; + outheight = height; +} + +void DirectFilter::render( + uint32_t *output, unsigned outpitch, const uint16_t *input, unsigned pitch, + unsigned width, unsigned height +) { + pitch >>= 1; + outpitch >>= 2; + + for(unsigned y = 0; y < height; y++) { + for(unsigned x = 0; x < width; x++) { + uint16_t p = *input++; + *output++ = colortable[p]; + } + input += pitch - width; + output += outpitch - width; + } +} diff -Nru bsnes-0.073/snesfilter/direct/direct.hpp bsnes-0.073/snesfilter/direct/direct.hpp --- bsnes-0.073/snesfilter/direct/direct.hpp 1970-01-01 00:00:00.000000000 +0000 +++ bsnes-0.073/snesfilter/direct/direct.hpp 2010-04-14 04:36:46.000000000 +0000 @@ -0,0 +1,5 @@ +class DirectFilter { +public: + void size(unsigned&, unsigned&, unsigned, unsigned); + void render(uint32_t*, unsigned, const uint16_t*, unsigned, unsigned, unsigned); +} filter_direct; diff -Nru bsnes-0.073/snesfilter/hq2x/hq2x.cpp bsnes-0.073/snesfilter/hq2x/hq2x.cpp --- bsnes-0.073/snesfilter/hq2x/hq2x.cpp 2010-10-26 03:39:16.000000000 +0000 +++ bsnes-0.073/snesfilter/hq2x/hq2x.cpp 2010-06-06 02:51:01.000000000 +0000 @@ -1,44 +1,82 @@ -#include -#include -using namespace nall; - -extern "C" { - void filter_size(unsigned&, unsigned&); - void filter_render(uint32_t*, uint32_t*, unsigned, const uint16_t*, unsigned, unsigned, unsigned); -}; +//HQ2x filter +//authors: byuu and blargg +//license: public domain +// +//note: this is a clean reimplementation of the original HQ2x filter, which was +//written by Maxim Stepin (MaxSt). it is not 100% identical, but very similar. + +#include "hq2x.hpp" + +void HQ2xFilter::size(unsigned &outwidth, unsigned &outheight, unsigned width, unsigned height) { + if(width > 256 || height > 240) return filter_direct.size(outwidth, outheight, width, height); + outwidth = width * 2; + outheight = height * 2; +} -enum { - diff_offset = (0x440 << 21) + (0x207 << 11) + 0x407, - diff_mask = (0x380 << 21) + (0x1f0 << 11) + 0x3f0, -}; +void HQ2xFilter::render( + uint32_t *output, unsigned outpitch, + const uint16_t *input, unsigned pitch, unsigned width, unsigned height +) { + if(width > 256 || height > 240) { + filter_direct.render(output, outpitch, input, pitch, width, height); + return; + } -uint32_t *yuvTable; -uint8_t rotate[256]; + pitch >>= 1; + outpitch >>= 2; -const uint8_t hqTable[256] = { - 4, 4, 6, 2, 4, 4, 6, 2, 5, 3, 15, 12, 5, 3, 17, 13, - 4, 4, 6, 18, 4, 4, 6, 18, 5, 3, 12, 12, 5, 3, 1, 12, - 4, 4, 6, 2, 4, 4, 6, 2, 5, 3, 17, 13, 5, 3, 16, 14, - 4, 4, 6, 18, 4, 4, 6, 18, 5, 3, 16, 12, 5, 3, 1, 14, - 4, 4, 6, 2, 4, 4, 6, 2, 5, 19, 12, 12, 5, 19, 16, 12, - 4, 4, 6, 2, 4, 4, 6, 2, 5, 3, 16, 12, 5, 3, 16, 12, - 4, 4, 6, 2, 4, 4, 6, 2, 5, 19, 1, 12, 5, 19, 1, 14, - 4, 4, 6, 2, 4, 4, 6, 18, 5, 3, 16, 12, 5, 19, 1, 14, - 4, 4, 6, 2, 4, 4, 6, 2, 5, 3, 15, 12, 5, 3, 17, 13, - 4, 4, 6, 2, 4, 4, 6, 2, 5, 3, 16, 12, 5, 3, 16, 12, - 4, 4, 6, 2, 4, 4, 6, 2, 5, 3, 17, 13, 5, 3, 16, 14, - 4, 4, 6, 2, 4, 4, 6, 2, 5, 3, 16, 13, 5, 3, 1, 14, - 4, 4, 6, 2, 4, 4, 6, 2, 5, 3, 16, 12, 5, 3, 16, 13, - 4, 4, 6, 2, 4, 4, 6, 2, 5, 3, 16, 12, 5, 3, 1, 12, - 4, 4, 6, 2, 4, 4, 6, 2, 5, 3, 16, 12, 5, 3, 1, 14, - 4, 4, 6, 2, 4, 4, 6, 2, 5, 3, 1, 12, 5, 3, 1, 14, -}; + #pragma omp parallel for + for(unsigned y = 0; y < height; y++) { + const uint16_t *in = input + y * pitch; + uint32_t *out0 = output + y * outpitch * 2; + uint32_t *out1 = output + y * outpitch * 2 + outpitch; + + int prevline = (y == 0 ? 0 : pitch); + int nextline = (y == height - 1 ? 0 : pitch); + + in++; + *out0++ = 0; *out0++ = 0; + *out1++ = 0; *out1++ = 0; -static void initialize() { - static bool initialized = false; - if(initialized == true) return; - initialized = true; + for(unsigned x = 1; x < 256 - 1; x++) { + uint16_t A = *(in - prevline - 1); + uint16_t B = *(in - prevline + 0); + uint16_t C = *(in - prevline + 1); + uint16_t D = *(in - 1); + uint16_t E = *(in + 0); + uint16_t F = *(in + 1); + uint16_t G = *(in + nextline - 1); + uint16_t H = *(in + nextline + 0); + uint16_t I = *(in + nextline + 1); + uint32_t e = yuvTable[E] + diff_offset; + + uint8_t pattern; + pattern = diff(e, A) << 0; + pattern |= diff(e, B) << 1; + pattern |= diff(e, C) << 2; + pattern |= diff(e, D) << 3; + pattern |= diff(e, F) << 4; + pattern |= diff(e, G) << 5; + pattern |= diff(e, H) << 6; + pattern |= diff(e, I) << 7; + + *(out0 + 0) = colortable[blend(hqTable[pattern], E, A, B, D, F, H)]; pattern = rotate[pattern]; + *(out0 + 1) = colortable[blend(hqTable[pattern], E, C, F, B, H, D)]; pattern = rotate[pattern]; + *(out1 + 1) = colortable[blend(hqTable[pattern], E, I, H, F, D, B)]; pattern = rotate[pattern]; + *(out1 + 0) = colortable[blend(hqTable[pattern], E, G, D, H, B, F)]; + + in++; + out0 += 2; + out1 += 2; + } + + in++; + *out0++ = 0; *out0++ = 0; + *out1++ = 0; *out1++ = 0; + } +} +HQ2xFilter::HQ2xFilter() { yuvTable = new uint32_t[32768]; for(unsigned i = 0; i < 32768; i++) { @@ -66,53 +104,53 @@ } } -static void terminate() { +HQ2xFilter::~HQ2xFilter() { delete[] yuvTable; } -static bool same(uint16_t x, uint16_t y) { +bool HQ2xFilter::same(uint16_t x, uint16_t y) { return !((yuvTable[x] - yuvTable[y] + diff_offset) & diff_mask); } -static bool diff(uint32_t x, uint16_t y) { +bool HQ2xFilter::diff(uint32_t x, uint16_t y) { return ((x - yuvTable[y]) & diff_mask); } -static void grow(uint32_t &n) { n |= n << 16; n &= 0x03e07c1f; } -static uint16_t pack(uint32_t n) { n &= 0x03e07c1f; return n | (n >> 16); } +void HQ2xFilter::grow(uint32_t &n) { n |= n << 16; n &= 0x03e07c1f; } +uint16_t HQ2xFilter::pack(uint32_t n) { n &= 0x03e07c1f; return n | (n >> 16); } -static uint16_t blend1(uint32_t A, uint32_t B) { +uint16_t HQ2xFilter::blend1(uint32_t A, uint32_t B) { grow(A); grow(B); A = (A * 3 + B) >> 2; return pack(A); } -static uint16_t blend2(uint32_t A, uint32_t B, uint32_t C) { +uint16_t HQ2xFilter::blend2(uint32_t A, uint32_t B, uint32_t C) { grow(A); grow(B); grow(C); return pack((A * 2 + B + C) >> 2); } -static uint16_t blend3(uint32_t A, uint32_t B, uint32_t C) { +uint16_t HQ2xFilter::blend3(uint32_t A, uint32_t B, uint32_t C) { grow(A); grow(B); grow(C); return pack((A * 5 + B * 2 + C) >> 3); } -static uint16_t blend4(uint32_t A, uint32_t B, uint32_t C) { +uint16_t HQ2xFilter::blend4(uint32_t A, uint32_t B, uint32_t C) { grow(A); grow(B); grow(C); return pack((A * 6 + B + C) >> 3); } -static uint16_t blend5(uint32_t A, uint32_t B, uint32_t C) { +uint16_t HQ2xFilter::blend5(uint32_t A, uint32_t B, uint32_t C) { grow(A); grow(B); grow(C); return pack((A * 2 + (B + C) * 3) >> 3); } -static uint16_t blend6(uint32_t A, uint32_t B, uint32_t C) { +uint16_t HQ2xFilter::blend6(uint32_t A, uint32_t B, uint32_t C) { grow(A); grow(B); grow(C); return pack((A * 14 + B + C) >> 4); } -static uint16_t blend(unsigned rule, uint16_t E, uint16_t A, uint16_t B, uint16_t D, uint16_t F, uint16_t H) { +uint16_t HQ2xFilter::blend(unsigned rule, uint16_t E, uint16_t A, uint16_t B, uint16_t D, uint16_t F, uint16_t H) { switch(rule) { default: case 0: return E; case 1: return blend1(E, A); @@ -137,67 +175,21 @@ } } -dllexport void filter_size(unsigned &width, unsigned &height) { - initialize(); - width *= 2; - height *= 2; -} - -dllexport void filter_render( - uint32_t *colortable, uint32_t *output, unsigned outpitch, - const uint16_t *input, unsigned pitch, unsigned width, unsigned height -) { - initialize(); - pitch >>= 1; - outpitch >>= 2; - -//#pragma omp parallel for - for(unsigned y = 0; y < height; y++) { - const uint16_t *in = input + y * pitch; - uint32_t *out0 = output + y * outpitch * 2; - uint32_t *out1 = output + y * outpitch * 2 + outpitch; - - int prevline = (y == 0 ? 0 : pitch); - int nextline = (y == height - 1 ? 0 : pitch); - - in++; - *out0++ = 0; *out0++ = 0; - *out1++ = 0; *out1++ = 0; - - for(unsigned x = 1; x < width - 1; x++) { - uint16_t A = *(in - prevline - 1); - uint16_t B = *(in - prevline + 0); - uint16_t C = *(in - prevline + 1); - uint16_t D = *(in - 1); - uint16_t E = *(in + 0); - uint16_t F = *(in + 1); - uint16_t G = *(in + nextline - 1); - uint16_t H = *(in + nextline + 0); - uint16_t I = *(in + nextline + 1); - uint32_t e = yuvTable[E] + diff_offset; - - uint8_t pattern; - pattern = diff(e, A) << 0; - pattern |= diff(e, B) << 1; - pattern |= diff(e, C) << 2; - pattern |= diff(e, D) << 3; - pattern |= diff(e, F) << 4; - pattern |= diff(e, G) << 5; - pattern |= diff(e, H) << 6; - pattern |= diff(e, I) << 7; - - *(out0 + 0) = colortable[blend(hqTable[pattern], E, A, B, D, F, H)]; pattern = rotate[pattern]; - *(out0 + 1) = colortable[blend(hqTable[pattern], E, C, F, B, H, D)]; pattern = rotate[pattern]; - *(out1 + 1) = colortable[blend(hqTable[pattern], E, I, H, F, D, B)]; pattern = rotate[pattern]; - *(out1 + 0) = colortable[blend(hqTable[pattern], E, G, D, H, B, F)]; - - in++; - out0 += 2; - out1 += 2; - } - - in++; - *out0++ = 0; *out0++ = 0; - *out1++ = 0; *out1++ = 0; - } -} +const uint8_t HQ2xFilter::hqTable[256] = { + 4, 4, 6, 2, 4, 4, 6, 2, 5, 3, 15, 12, 5, 3, 17, 13, + 4, 4, 6, 18, 4, 4, 6, 18, 5, 3, 12, 12, 5, 3, 1, 12, + 4, 4, 6, 2, 4, 4, 6, 2, 5, 3, 17, 13, 5, 3, 16, 14, + 4, 4, 6, 18, 4, 4, 6, 18, 5, 3, 16, 12, 5, 3, 1, 14, + 4, 4, 6, 2, 4, 4, 6, 2, 5, 19, 12, 12, 5, 19, 16, 12, + 4, 4, 6, 2, 4, 4, 6, 2, 5, 3, 16, 12, 5, 3, 16, 12, + 4, 4, 6, 2, 4, 4, 6, 2, 5, 19, 1, 12, 5, 19, 1, 14, + 4, 4, 6, 2, 4, 4, 6, 18, 5, 3, 16, 12, 5, 19, 1, 14, + 4, 4, 6, 2, 4, 4, 6, 2, 5, 3, 15, 12, 5, 3, 17, 13, + 4, 4, 6, 2, 4, 4, 6, 2, 5, 3, 16, 12, 5, 3, 16, 12, + 4, 4, 6, 2, 4, 4, 6, 2, 5, 3, 17, 13, 5, 3, 16, 14, + 4, 4, 6, 2, 4, 4, 6, 2, 5, 3, 16, 13, 5, 3, 1, 14, + 4, 4, 6, 2, 4, 4, 6, 2, 5, 3, 16, 12, 5, 3, 16, 13, + 4, 4, 6, 2, 4, 4, 6, 2, 5, 3, 16, 12, 5, 3, 1, 12, + 4, 4, 6, 2, 4, 4, 6, 2, 5, 3, 16, 12, 5, 3, 1, 14, + 4, 4, 6, 2, 4, 4, 6, 2, 5, 3, 1, 12, 5, 3, 1, 14, +}; diff -Nru bsnes-0.073/snesfilter/hq2x/hq2x.hpp bsnes-0.073/snesfilter/hq2x/hq2x.hpp --- bsnes-0.073/snesfilter/hq2x/hq2x.hpp 1970-01-01 00:00:00.000000000 +0000 +++ bsnes-0.073/snesfilter/hq2x/hq2x.hpp 2010-06-06 02:50:55.000000000 +0000 @@ -0,0 +1,30 @@ +class HQ2xFilter { +public: + void size(unsigned&, unsigned&, unsigned, unsigned); + void render(uint32_t*, unsigned, const uint16_t*, unsigned, unsigned, unsigned); + + HQ2xFilter(); + ~HQ2xFilter(); + +private: + enum { + diff_offset = (0x440 << 21) + (0x207 << 11) + 0x407, + diff_mask = (0x380 << 21) + (0x1f0 << 11) + 0x3f0, + }; + + static const uint8_t hqTable[256]; + uint32_t *yuvTable; + uint8_t rotate[256]; + + alwaysinline bool same(uint16_t x, uint16_t y); + alwaysinline bool diff(uint32_t x, uint16_t y); + alwaysinline void grow(uint32_t &n); + alwaysinline uint16_t pack(uint32_t n); + alwaysinline uint16_t blend1(uint32_t A, uint32_t B); + alwaysinline uint16_t blend2(uint32_t A, uint32_t B, uint32_t C); + alwaysinline uint16_t blend3(uint32_t A, uint32_t B, uint32_t C); + alwaysinline uint16_t blend4(uint32_t A, uint32_t B, uint32_t C); + alwaysinline uint16_t blend5(uint32_t A, uint32_t B, uint32_t C); + alwaysinline uint16_t blend6(uint32_t A, uint32_t B, uint32_t C); + alwaysinline uint16_t blend(unsigned rule, uint16_t E, uint16_t A, uint16_t B, uint16_t D, uint16_t F, uint16_t H); +} filter_hq2x; diff -Nru bsnes-0.073/snesfilter/lq2x/lq2x.cpp bsnes-0.073/snesfilter/lq2x/lq2x.cpp --- bsnes-0.073/snesfilter/lq2x/lq2x.cpp 2010-10-26 05:06:31.000000000 +0000 +++ bsnes-0.073/snesfilter/lq2x/lq2x.cpp 2010-04-14 04:45:21.000000000 +0000 @@ -1,21 +1,20 @@ -#include -#include -using namespace nall; - -extern "C" { - void filter_size(unsigned&, unsigned&); - void filter_render(uint32_t*, uint32_t*, unsigned, const uint16_t*, unsigned, unsigned, unsigned); -}; - -dllexport void filter_size(unsigned &width, unsigned &height) { - width *= 2; - height *= 2; +#include "lq2x.hpp" + +void LQ2xFilter::size(unsigned &outwidth, unsigned &outheight, unsigned width, unsigned height) { + if(width > 256 || height > 240) return filter_direct.size(outwidth, outheight, width, height); + outwidth = width * 2; + outheight = height * 2; } -dllexport void filter_render( - uint32_t *colortable, uint32_t *output, unsigned outpitch, +void LQ2xFilter::render( + uint32_t *output, unsigned outpitch, const uint16_t *input, unsigned pitch, unsigned width, unsigned height ) { + if(width > 256 || height > 240) { + filter_direct.render(output, outpitch, input, pitch, width, height); + return; + } + pitch >>= 1; outpitch >>= 2; @@ -28,9 +27,9 @@ for(unsigned x = 0; x < width; x++) { uint16_t A = *(input - prevline); - uint16_t B = (x > 0) ? *(input - 1) : *input; + uint16_t B = (x > 0) ? *(input - 1) : *input; uint16_t C = *input; - uint16_t D = (x < width - 1) ? *(input + 1) : *input; + uint16_t D = (x < 255) ? *(input + 1) : *input; uint16_t E = *(input++ + nextline); uint32_t c = colortable[C]; @@ -48,7 +47,7 @@ } input += pitch - width; - out0 += outpitch + outpitch - (width << 1); - out1 += outpitch + outpitch - (width << 1); + out0 += outpitch + outpitch - 512; + out1 += outpitch + outpitch - 512; } } diff -Nru bsnes-0.073/snesfilter/lq2x/lq2x.hpp bsnes-0.073/snesfilter/lq2x/lq2x.hpp --- bsnes-0.073/snesfilter/lq2x/lq2x.hpp 1970-01-01 00:00:00.000000000 +0000 +++ bsnes-0.073/snesfilter/lq2x/lq2x.hpp 2010-04-14 04:41:14.000000000 +0000 @@ -0,0 +1,5 @@ +class LQ2xFilter { +public: + void size(unsigned&, unsigned&, unsigned, unsigned); + void render(uint32_t*, unsigned, const uint16_t*, unsigned, unsigned, unsigned); +} filter_lq2x; diff -Nru bsnes-0.073/snesfilter/Makefile bsnes-0.073/snesfilter/Makefile --- bsnes-0.073/snesfilter/Makefile 2010-10-26 05:18:25.000000000 +0000 +++ bsnes-0.073/snesfilter/Makefile 2010-07-11 04:22:26.000000000 +0000 @@ -1,51 +1,89 @@ include nall/Makefile -c := $(compiler) -std=gnu99 -cpp := $(subst cc,++,$(compiler)) -std=gnu++0x -flags := -O3 -I. -Iobj -fomit-frame-pointer -fPIC -link := -s -objects := - -objects += out/pixellate2x.filter -objects += out/scanline-00.filter -objects += out/scanline-25.filter -objects += out/scanline-50.filter -objects += out/scanline-75.filter -objects += out/scale2x.filter -objects += out/2xsai.filter -objects += out/super-2xsai.filter -objects += out/super-eagle.filter -objects += out/lq2x.filter -objects += out/hq2x.filter -objects += out/ntsc-rf.filter -objects += out/ntsc-composite.filter -objects += out/ntsc-svideo.filter -objects += out/ntsc-rgb.filter +qtlibs := QtCore QtGui +include nall/qt/Makefile -compile = $(cpp) $(link) $(flags) -o $@ -shared $< +c := $(compiler) -std=gnu99 +cpp := $(subst cc,++,$(compiler)) -std=gnu++0x +flags := -O3 -I. -Iobj -fomit-frame-pointer $(qtinc) +link := + +ifeq ($(platform),x) + flags := -fPIC -fopenmp $(flags) + link += -s -fopenmp -lpthread -lgomp +else ifeq ($(platform),osx) + flags := -fPIC -fopenmp $(flags) + link += -fopenmp -lpthread -lgomp +else ifeq ($(platform),win) + flags := -fopenmp $(flags) + link += -fopenmp -lpthread +endif + +objects := snesfilter + +compile = \ + $(strip \ + $(if $(filter %.c,$<), \ + $(c) $(flags) $1 -c $< -o $@, \ + $(if $(filter %.cpp,$<), \ + $(cpp) $(flags) $1 -c $< -o $@ \ + ) \ + ) \ + ) -%.filter: $<; $(call compile) +%.o: $<; $(call compile) all: build; -out/pixellate2x.filter: pixellate2x/pixellate2x.cpp pixellate2x/* -out/scanline-00.filter: scanline/scanline-00.cpp scanline/* -out/scanline-25.filter: scanline/scanline-25.cpp scanline/* -out/scanline-50.filter: scanline/scanline-50.cpp scanline/* -out/scanline-75.filter: scanline/scanline-75.cpp scanline/* -out/scale2x.filter: scale2x/scale2x.cpp scale2x/* -out/2xsai.filter: 2xsai/2xsai.cpp 2xsai/* -out/super-2xsai.filter: 2xsai/super-2xsai.cpp 2xsai/* -out/super-eagle.filter: 2xsai/super-eagle.cpp 2xsai/* -out/lq2x.filter: lq2x/lq2x.cpp lq2x/* -out/hq2x.filter: hq2x/hq2x.cpp hq2x/* -out/ntsc-rf.filter: ntsc/ntsc-rf.cpp ntsc/* -out/ntsc-composite.filter: ntsc/ntsc-composite.cpp ntsc/* -out/ntsc-svideo.filter: ntsc/ntsc-svideo.cpp ntsc/* -out/ntsc-rgb.filter: ntsc/ntsc-rgb.cpp ntsc/* - -build: $(objects) +objects := $(patsubst %,obj/%.o,$(objects)) +moc_headers := $(call rwildcard,./,%.moc.hpp) +moc_objects := $(foreach f,$(moc_headers),obj/$(notdir $(patsubst %.moc.hpp,%.moc,$f))) + +# automatically run moc on all .moc.hpp (MOC header) files +%.moc: $<; $(moc) -i $< -o $@ + +# automatically generate %.moc build rules +__list = $(moc_headers) +$(foreach f,$(moc_objects), \ + $(eval __file = $(word 1,$(__list))) \ + $(eval __list = $(wordlist 2,$(words $(__list)),$(__list))) \ + $(eval $f: $(__file)) \ +) + +################## +### snesfilter ### +################## + +obj/snesfilter.o: snesfilter.cpp * + +############### +### targets ### +############### + +build: $(moc_objects) $(objects) +ifeq ($(platform),x) + ar rcs libsnesfilter.a $(objects) + $(cpp) $(link) -o libsnesfilter.so -shared -Wl,-soname,libsnesfilter.so.1 $(objects) $(qtlib) +else ifeq ($(platform),osx) + ar rcs libsnesfilter.a $(objects) + $(cpp) $(link) -o libsnesfilter.dylib -shared -dynamiclib $(objects) $(qtlib) +else ifeq ($(platform),win) + $(cpp) $(link) -o snesfilter.dll -shared -Wl,--out-implib,libsnesfilter.a $(objects) $(qtlib) +endif install: +ifeq ($(platform),x) + install -D -m 755 libsnesfilter.a $(DESTDIR)$(prefix)/lib + install -D -m 755 libsnesfilter.so $(DESTDIR)$(prefix)/lib + ldconfig -n $(DESTDIR)$(prefix)/lib +else ifeq ($(platform),osx) + cp libsnesfilter.dylib /usr/local/lib/libsnesfilter.dylib +endif clean: + -@$(call delete,obj/*.o) + -@$(call delete,obj/*.moc) + -@$(call delete,libsnesfilter.a) + -@$(call delete,libsnesfilter.so) + -@$(call delete,libsnesfilter.dylib) + -@$(call delete,snesfilter.dll) diff -Nru bsnes-0.073/snesfilter/nall/config.hpp bsnes-0.073/snesfilter/nall/config.hpp --- bsnes-0.073/snesfilter/nall/config.hpp 2010-10-26 02:36:25.000000000 +0000 +++ bsnes-0.073/snesfilter/nall/config.hpp 2010-03-29 06:30:57.000000000 +0000 @@ -49,7 +49,7 @@ case signed_t: *(signed*)data = strsigned(s); break; case unsigned_t: *(unsigned*)data = strunsigned(s); break; case double_t: *(double*)data = strdouble(s); break; - case string_t: s.trim("\""); *(string*)data = s; break; + case string_t: trim(s, "\""); *(string*)data = s; break; } } }; @@ -83,8 +83,8 @@ lstring part; part.qsplit(" = ", line[i]); - part[0].trim(); - part[1].trim(); + trim(part[0]); + trim(part[1]); for(unsigned n = 0; n < list.size(); n++) { if(part[0] == list[n].name) { @@ -102,7 +102,7 @@ virtual bool save(const char *filename) const { file fp; - if(fp.open(filename, file::mode::write)) { + if(fp.open(filename, file::mode_write)) { for(unsigned i = 0; i < list.size(); i++) { string output; output << list[i].name << " = " << list[i].get(); diff -Nru bsnes-0.073/snesfilter/nall/dictionary.hpp bsnes-0.073/snesfilter/nall/dictionary.hpp --- bsnes-0.073/snesfilter/nall/dictionary.hpp 2010-10-26 02:36:25.000000000 +0000 +++ bsnes-0.073/snesfilter/nall/dictionary.hpp 2010-03-29 06:31:06.000000000 +0000 @@ -27,7 +27,7 @@ bool import(const char *filename) { string data; if(data.readfile(filename) == false) return false; - data.ltrim<1>("\xef\xbb\xbf"); //remove UTF-8 marker, if it exists + ltrim_once(data, "\xef\xbb\xbf"); //remove UTF-8 marker, if it exists data.replace("\r", ""); lstring line; @@ -39,12 +39,12 @@ if(part.size() != 2) continue; //remove whitespace - part[0].trim(); - part[1].trim(); + trim(part[0]); + trim(part[1]); //remove quotes - part[0].trim<1>("\""); - part[1].trim<1>("\""); + trim_once(part[0], "\""); + trim_once(part[1], "\""); unsigned n = index_input.size(); index_input[n] = part[0]; diff -Nru bsnes-0.073/snesfilter/nall/directory.hpp bsnes-0.073/snesfilter/nall/directory.hpp --- bsnes-0.073/snesfilter/nall/directory.hpp 2010-10-26 02:36:25.000000000 +0000 +++ bsnes-0.073/snesfilter/nall/directory.hpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,151 +0,0 @@ -#ifndef NALL_DIRECTORY_HPP -#define NALL_DIRECTORY_HPP - -#include -#include -#include - -#if defined(_WIN32) - #include -#else - #include - #include - #include -#endif - -namespace nall { - -struct directory { - static bool exists(const string &pathname); - static lstring folders(const string &pathname, const string &pattern = "*"); - static lstring files(const string &pathname, const string &pattern = "*"); - static lstring contents(const string &pathname, const string &pattern = "*"); -}; - -#if defined(_WIN32) - inline bool directory::exists(const string &pathname) { - DWORD result = GetFileAttributes(utf16_t(pathname)); - if(result == INVALID_FILE_ATTRIBUTES) return false; - return (result & FILE_ATTRIBUTE_DIRECTORY); - } - - inline lstring directory::folders(const string &pathname, const string &pattern) { - lstring list; - string path = pathname; - path.transform("/", "\\"); - if(!strend(path, "\\")) path.append("\\"); - path.append("*"); - HANDLE handle; - WIN32_FIND_DATA data; - handle = FindFirstFile(utf16_t(path), &data); - if(handle != INVALID_HANDLE_VALUE) { - if(wcscmp(data.cFileName, L".") && wcscmp(data.cFileName, L"..")) { - if(data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { - string name = utf8_t(data.cFileName); - if(wildcard(name, pattern)) list.append(string(name, "/")); - } - } - while(FindNextFile(handle, &data) != false) { - if(wcscmp(data.cFileName, L".") && wcscmp(data.cFileName, L"..")) { - if(data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { - string name = utf8_t(data.cFileName); - if(wildcard(name, pattern)) list.append(string(name, "/")); - } - } - } - FindClose(handle); - } - if(list.size() > 0) sort(&list[0], list.size()); - return list; - } - - inline lstring directory::files(const string &pathname, const string &pattern) { - lstring list; - string path = pathname; - path.transform("/", "\\"); - if(!strend(path, "\\")) path.append("\\"); - path.append("*"); - HANDLE handle; - WIN32_FIND_DATA data; - handle = FindFirstFile(utf16_t(path), &data); - if(handle != INVALID_HANDLE_VALUE) { - if((data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0) { - string name = utf8_t(data.cFileName); - if(wildcard(name, pattern)) list.append(name); - } - while(FindNextFile(handle, &data) != false) { - if((data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0) { - string name = utf8_t(data.cFileName); - if(wildcard(name, pattern)) list.append(name); - } - } - FindClose(handle); - } - if(list.size() > 0) sort(&list[0], list.size()); - return list; - } - - inline lstring directory::contents(const string &pathname, const string &pattern) { - lstring folders = directory::folders(pathname); //pattern search of contents() should only filter files - lstring files = directory::files(pathname, pattern); - foreach(file, files) folders.append(file); - return folders; - } -#else - inline bool directory::exists(const string &pathname) { - DIR *dp = opendir(pathname); - if(!dp) return false; - closedir(dp); - return true; - } - - inline lstring directory::folders(const string &pathname, const string &pattern) { - lstring list; - DIR *dp; - struct dirent *ep; - dp = opendir(pathname); - if(dp) { - while(ep = readdir(dp)) { - if(!strcmp(ep->d_name, ".")) continue; - if(!strcmp(ep->d_name, "..")) continue; - if(ep->d_type & DT_DIR) { - if(wildcard(ep->d_name, pattern)) list.append(string(ep->d_name, "/")); - } - } - closedir(dp); - } - if(list.size() > 0) sort(&list[0], list.size()); - return list; - - } - - inline lstring directory::files(const string &pathname, const string &pattern) { - lstring list; - DIR *dp; - struct dirent *ep; - dp = opendir(pathname); - if(dp) { - while(ep = readdir(dp)) { - if(!strcmp(ep->d_name, ".")) continue; - if(!strcmp(ep->d_name, "..")) continue; - if((ep->d_type & DT_DIR) == 0) { - if(wildcard(ep->d_name, pattern)) list.append(ep->d_name); - } - } - closedir(dp); - } - if(list.size() > 0) sort(&list[0], list.size()); - return list; - } - - inline lstring directory::contents(const string &pathname, const string &pattern) { - lstring folders = directory::folders(pathname); //pattern search of contents() should only filter files - lstring files = directory::files(pathname, pattern); - foreach(file, files) folders.append(file); - return folders; - } -#endif - -} - -#endif diff -Nru bsnes-0.073/snesfilter/nall/dl.hpp bsnes-0.073/snesfilter/nall/dl.hpp --- bsnes-0.073/snesfilter/nall/dl.hpp 2010-10-26 02:36:25.000000000 +0000 +++ bsnes-0.073/snesfilter/nall/dl.hpp 2010-03-03 04:51:05.000000000 +0000 @@ -3,9 +3,9 @@ //dynamic linking support +#include #include #include -#include #include #if defined(PLATFORM_X) || defined(PLATFORM_OSX) @@ -18,7 +18,7 @@ namespace nall { struct library { bool opened() const { return handle; } - bool open(const char*, const char* = ""); + bool open(const char*); void* sym(const char*); void close(); @@ -33,10 +33,20 @@ }; #if defined(PLATFORM_X) - inline bool library::open(const char *name, const char *path) { + inline bool library::open(const char *name) { if(handle) close(); - handle = (uintptr_t)dlopen(string(path, *path && !strend(path, "/") ? "/" : "", "lib", name, ".so"), RTLD_LAZY); - if(!handle) handle = (uintptr_t)dlopen(string("/usr/local/lib/lib", name, ".so"), RTLD_LAZY); + char *t = new char[strlen(name) + 256]; + strcpy(t, "lib"); + strcat(t, name); + strcat(t, ".so"); + handle = (uintptr_t)dlopen(t, RTLD_LAZY); + if(!handle) { + strcpy(t, "/usr/local/lib/lib"); + strcat(t, name); + strcat(t, ".so"); + handle = (uintptr_t)dlopen(t, RTLD_LAZY); + } + delete[] t; return handle; } @@ -51,10 +61,20 @@ handle = 0; } #elif defined(PLATFORM_OSX) - inline bool library::open(const char *name, const char *path) { + inline bool library::open(const char *name) { if(handle) close(); - handle = (uintptr_t)dlopen(string(path, *path && !strend(path, "/") ? "/" : "", "lib", name, ".dylib"), RTLD_LAZY); - if(!handle) handle = (uintptr_t)dlopen(string("/usr/local/lib/lib", name, ".dylib"), RTLD_LAZY); + char *t = new char[strlen(name) + 256]; + strcpy(t, "lib"); + strcat(t, name); + strcat(t, ".dylib"); + handle = (uintptr_t)dlopen(t, RTLD_LAZY); + if(!handle) { + strcpy(t, "/usr/local/lib/lib"); + strcat(t, name); + strcat(t, ".dylib"); + handle = (uintptr_t)dlopen(t, RTLD_LAZY); + } + delete[] t; return handle; } @@ -69,10 +89,13 @@ handle = 0; } #elif defined(PLATFORM_WIN) - inline bool library::open(const char *name, const char *path) { + inline bool library::open(const char *name) { if(handle) close(); - string filepath(path, *path && !strend(path, "/") && !strend(path, "\\") ? "\\" : "", name, ".dll"); - handle = (uintptr_t)LoadLibraryW(utf16_t(filepath)); + char *t = new char[strlen(name) + 8]; + strcpy(t, name); + strcat(t, ".dll"); + handle = (uintptr_t)LoadLibraryW(utf16_t(t)); + delete[] t; return handle; } @@ -87,7 +110,7 @@ handle = 0; } #else - inline bool library::open(const char*, const char*) { return false; } + inline bool library::open(const char*) { return false; } inline void* library::sym(const char*) { return 0; } inline void library::close() {} #endif diff -Nru bsnes-0.073/snesfilter/nall/file.hpp bsnes-0.073/snesfilter/nall/file.hpp --- bsnes-0.073/snesfilter/nall/file.hpp 2010-10-26 02:36:25.000000000 +0000 +++ bsnes-0.073/snesfilter/nall/file.hpp 2010-03-03 04:52:11.000000000 +0000 @@ -11,7 +11,6 @@ #endif #include -#include #include #include @@ -26,12 +25,12 @@ class file { public: - enum class mode : unsigned { read, write, readwrite, writeread }; - enum class index : unsigned { absolute, relative }; + enum FileMode { mode_read, mode_write, mode_readwrite, mode_writeread }; + enum SeekMode { seek_absolute, seek_relative }; uint8_t read() { if(!fp) return 0xff; //file not open - if(file_mode == mode::write) return 0xff; //reads not permitted + if(file_mode == mode_write) return 0xff; //reads not permitted if(file_offset >= file_size) return 0xff; //cannot read past end of file buffer_sync(); return buffer[(file_offset++) & buffer_mask]; @@ -59,8 +58,8 @@ } void write(uint8_t data) { - if(!fp) return; //file not open - if(file_mode == mode::read) return; //writes not permitted + if(!fp) return; //file not open + if(file_mode == mode_read) return; //writes not permitted buffer_sync(); buffer[(file_offset++) & buffer_mask] = data; buffer_dirty = true; @@ -84,10 +83,9 @@ while(length--) write(*buffer++); } - template void print(Args... args) { - string data(args...); - const char *p = data; - while(*p) write(*p++); + void print(const char *string) { + if(!string) return; + while(*string) write(*string++); } void flush() { @@ -95,19 +93,19 @@ fflush(fp); } - void seek(int offset, index index_ = index::absolute) { + void seek(int offset, SeekMode mode = seek_absolute) { if(!fp) return; //file not open buffer_flush(); uintmax_t req_offset = file_offset; - switch(index_) { - case index::absolute: req_offset = offset; break; - case index::relative: req_offset += offset; break; + switch(mode) { + case seek_absolute: req_offset = offset; break; + case seek_relative: req_offset += offset; break; } if(req_offset < 0) req_offset = 0; //cannot seek before start of file if(req_offset > file_size) { - if(file_mode == mode::read) { //cannot seek past end of file + if(file_mode == mode_read) { //cannot seek past end of file req_offset = file_size; } else { //pad file to requested location file_offset = file_size; @@ -174,20 +172,20 @@ return fp; } - bool open(const char *fn, mode mode_) { + bool open(const char *fn, FileMode mode) { if(fp) return false; - switch(file_mode = mode_) { + switch(file_mode = mode) { #if !defined(_WIN32) - case mode::read: fp = fopen(fn, "rb"); break; - case mode::write: fp = fopen(fn, "wb+"); break; //need read permission for buffering - case mode::readwrite: fp = fopen(fn, "rb+"); break; - case mode::writeread: fp = fopen(fn, "wb+"); break; + case mode_read: fp = fopen(fn, "rb"); break; + case mode_write: fp = fopen(fn, "wb+"); break; //need read permission for buffering + case mode_readwrite: fp = fopen(fn, "rb+"); break; + case mode_writeread: fp = fopen(fn, "wb+"); break; #else - case mode::read: fp = _wfopen(utf16_t(fn), L"rb"); break; - case mode::write: fp = _wfopen(utf16_t(fn), L"wb+"); break; - case mode::readwrite: fp = _wfopen(utf16_t(fn), L"rb+"); break; - case mode::writeread: fp = _wfopen(utf16_t(fn), L"wb+"); break; + case mode_read: fp = _wfopen(utf16_t(fn), L"rb"); break; + case mode_write: fp = _wfopen(utf16_t(fn), L"wb+"); break; + case mode_readwrite: fp = _wfopen(utf16_t(fn), L"rb+"); break; + case mode_writeread: fp = _wfopen(utf16_t(fn), L"wb+"); break; #endif } if(!fp) return false; @@ -213,7 +211,7 @@ fp = 0; file_offset = 0; file_size = 0; - file_mode = mode::read; + file_mode = mode_read; } ~file() { @@ -231,7 +229,7 @@ FILE *fp; unsigned file_offset; unsigned file_size; - mode file_mode; + FileMode file_mode; void buffer_sync() { if(!fp) return; //file not open @@ -245,14 +243,14 @@ } void buffer_flush() { - if(!fp) return; //file not open - if(file_mode == mode::read) return; //buffer cannot be written to - if(buffer_offset < 0) return; //buffer unused - if(buffer_dirty == false) return; //buffer unmodified since read + if(!fp) return; //file not open + if(file_mode == mode_read) return; //buffer cannot be written to + if(buffer_offset < 0) return; //buffer unused + if(buffer_dirty == false) return; //buffer unmodified since read fseek(fp, buffer_offset, SEEK_SET); unsigned length = (buffer_offset + buffer_size) <= file_size ? buffer_size : (file_size & buffer_mask); if(length) unsigned unused = fwrite(buffer, 1, length, fp); - buffer_offset = -1; //invalidate buffer + buffer_offset = -1; //invalidate buffer buffer_dirty = false; } }; diff -Nru bsnes-0.073/snesfilter/nall/filemap.hpp bsnes-0.073/snesfilter/nall/filemap.hpp --- bsnes-0.073/snesfilter/nall/filemap.hpp 2010-10-26 02:36:25.000000000 +0000 +++ bsnes-0.073/snesfilter/nall/filemap.hpp 2009-01-25 04:39:08.000000000 +0000 @@ -19,16 +19,14 @@ namespace nall { class filemap { public: - enum class mode : unsigned { read, write, readwrite, writeread }; + enum filemode { mode_read, mode_write, mode_readwrite, mode_writeread }; - bool opened() const { return p_opened(); } - bool open(const char *filename, mode mode_) { return p_open(filename, mode_); } + bool open(const char *filename, filemode mode) { return p_open(filename, mode); } void close() { return p_close(); } unsigned size() const { return p_size; } - uint8_t* data() { return p_handle; } - const uint8_t* data() const { return p_handle; } + uint8_t* handle() { return p_handle; } + const uint8_t* handle() const { return p_handle; } filemap() : p_size(0), p_handle(0) { p_ctor(); } - filemap(const char *filename, mode mode_) : p_size(0), p_handle(0) { p_ctor(); p_open(filename, mode_); } ~filemap() { p_dtor(); } private: @@ -42,35 +40,31 @@ HANDLE p_filehandle, p_maphandle; - bool p_opened() const { - return p_handle; - } - - bool p_open(const char *filename, mode mode_) { + bool p_open(const char *filename, filemode mode) { int desired_access, creation_disposition, flprotect, map_access; - switch(mode_) { + switch(mode) { default: return false; - case mode::read: + case mode_read: desired_access = GENERIC_READ; creation_disposition = OPEN_EXISTING; flprotect = PAGE_READONLY; map_access = FILE_MAP_READ; break; - case mode::write: + case mode_write: //write access requires read access desired_access = GENERIC_WRITE; creation_disposition = CREATE_ALWAYS; flprotect = PAGE_READWRITE; map_access = FILE_MAP_ALL_ACCESS; break; - case mode::readwrite: + case mode_readwrite: desired_access = GENERIC_READ | GENERIC_WRITE; creation_disposition = OPEN_EXISTING; flprotect = PAGE_READWRITE; map_access = FILE_MAP_ALL_ACCESS; break; - case mode::writeread: + case mode_writeread: desired_access = GENERIC_READ | GENERIC_WRITE; creation_disposition = CREATE_NEW; flprotect = PAGE_READWRITE; @@ -128,34 +122,30 @@ int p_fd; - bool p_opened() const { - return p_handle; - } - - bool p_open(const char *filename, mode mode_) { + bool p_open(const char *filename, filemode mode) { int open_flags, mmap_flags; - switch(mode_) { + switch(mode) { default: return false; - case mode::read: + case mode_read: open_flags = O_RDONLY; mmap_flags = PROT_READ; break; - case mode::write: + case mode_write: open_flags = O_RDWR | O_CREAT; //mmap() requires read access mmap_flags = PROT_WRITE; break; - case mode::readwrite: + case mode_readwrite: open_flags = O_RDWR; mmap_flags = PROT_READ | PROT_WRITE; break; - case mode::writeread: + case mode_writeread: open_flags = O_RDWR | O_CREAT; mmap_flags = PROT_READ | PROT_WRITE; break; } - p_fd = ::open(filename, open_flags, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP); + p_fd = ::open(filename, open_flags); if(p_fd < 0) return false; struct stat p_stat; diff -Nru bsnes-0.073/snesfilter/nall/function.hpp bsnes-0.073/snesfilter/nall/function.hpp --- bsnes-0.073/snesfilter/nall/function.hpp 2010-10-26 02:36:25.000000000 +0000 +++ bsnes-0.073/snesfilter/nall/function.hpp 2010-04-12 04:29:02.000000000 +0000 @@ -1,59 +1,89 @@ #ifndef NALL_FUNCTION_HPP #define NALL_FUNCTION_HPP +#include +#include + namespace nall { template class function; - template class function { - struct container { - virtual R operator()(P... p) const = 0; - virtual container* copy() const = 0; - virtual ~container() {} - } *callback; - - struct global : container { - R (*function)(P...); - R operator()(P... p) const { return function(std::forward

(p)...); } - container* copy() const { return new global(function); } - global(R (*function)(P...)) : function(function) {} - }; - - template struct member : container { - R (C::*function)(P...); - C *object; - R operator()(P... p) const { return (object->*function)(std::forward

(p)...); } - container* copy() const { return new member(function, object); } - member(R (C::*function)(P...), C *object) : function(function), object(object) {} - }; - - template struct lambda : container { - L object; - R operator()(P... p) const { return object(std::forward

(p)...); } - container* copy() const { return new lambda(object); } - lambda(const L& object) : object(object) {} - }; + template + class function { + private: + struct base1 { virtual void func1(P...) {} }; + struct base2 { virtual void func2(P...) {} }; + struct derived : base1, virtual base2 {}; + + struct data_t { + R (*callback)(const data_t&, P...); + union { + R (*callback_global)(P...); + struct { + R (derived::*callback_member)(P...); + void *object; + }; + }; + } data; - public: - operator bool() const { return callback; } - R operator()(P... p) const { return (*callback)(std::forward

(p)...); } - void reset() { if(callback) { delete callback; callback = 0; } } - - function& operator=(const function &source) { - if(this != &source) { - if(callback) { delete callback; callback = 0; } - if(source.callback) callback = source.callback->copy(); - } - return *this; + static R callback_global(const data_t &data, P... p) { + return data.callback_global(p...); } + template + static R callback_member(const data_t &data, P... p) { + return (((C*)data.object)->*((R (C::*&)(P...))data.callback_member))(p...); + } + + public: + R operator()(P... p) const { return data.callback(data, p...); } + operator bool() const { return data.callback; } + void reset() { data.callback = 0; } + + function& operator=(const function &source) { memcpy(&data, &source.data, sizeof(data_t)); return *this; } function(const function &source) { operator=(source); } - function() : callback(0) {} - function(void *function) : callback(0) { if(function) callback = new global((R (*)(P...))function); } - function(R (*function)(P...)) { callback = new global(function); } - template function(R (C::*function)(P...), C *object) { callback = new member(function, object); } - template function(R (C::*function)(P...) const, C *object) { callback = new member((R (C::*)(P...))function, object); } - template function(const L& object) { callback = new lambda(object); } - ~function() { if(callback) delete callback; } + + //no pointer + function() { + data.callback = 0; + } + + //symbolic link pointer (nall/dl.hpp::sym, etc) + function(void *callback) { + data.callback = callback ? &callback_global : 0; + data.callback_global = (R (*)(P...))callback; + } + + //global function pointer + function(R (*callback)(P...)) { + data.callback = &callback_global; + data.callback_global = callback; + } + + //member function pointer + template + function(R (C::*callback)(P...), C *object) { + static_assert(sizeof data.callback_member >= sizeof callback, "callback_member is too small"); + data.callback = &callback_member; + (R (C::*&)(P...))data.callback_member = callback; + data.object = object; + } + + //const member function pointer + template + function(R (C::*callback)(P...) const, C *object) { + static_assert(sizeof data.callback_member >= sizeof callback, "callback_member is too small"); + data.callback = &callback_member; + (R (C::*&)(P...))data.callback_member = (R (C::*&)(P...))callback; + data.object = object; + } + + //lambda function pointer + template + function(T callback) { + static_assert(std::is_same::type>::value, "lambda mismatch"); + data.callback = &callback_global; + data.callback_global = (R (*)(P...))callback; + } }; } diff -Nru bsnes-0.073/snesfilter/nall/input.hpp bsnes-0.073/snesfilter/nall/input.hpp --- bsnes-0.073/snesfilter/nall/input.hpp 2010-10-26 02:36:25.000000000 +0000 +++ bsnes-0.073/snesfilter/nall/input.hpp 2010-03-29 06:30:38.000000000 +0000 @@ -91,7 +91,7 @@ static uint16_t decode(const char *name) { string s(name); if(!strbegin(name, "KB")) return 0; - s.ltrim("KB"); + ltrim(s, "KB"); unsigned id = strunsigned(s); auto pos = strpos(s, "::"); if(!pos) return 0; @@ -188,7 +188,7 @@ static uint16_t decode(const char *name) { string s(name); if(!strbegin(name, "MS")) return 0; - s.ltrim("MS"); + ltrim(s, "MS"); unsigned id = strunsigned(s); auto pos = strpos(s, "::"); if(!pos) return 0; @@ -312,7 +312,7 @@ static uint16_t decode(const char *name) { string s(name); if(!strbegin(name, "JP")) return 0; - s.ltrim("JP"); + ltrim(s, "JP"); unsigned id = strunsigned(s); auto pos = strpos(s, "::"); if(!pos) return 0; diff -Nru bsnes-0.073/snesfilter/nall/Makefile bsnes-0.073/snesfilter/nall/Makefile --- bsnes-0.073/snesfilter/nall/Makefile 2010-10-26 02:36:25.000000000 +0000 +++ bsnes-0.073/snesfilter/nall/Makefile 2010-05-03 04:03:02.000000000 +0000 @@ -29,12 +29,10 @@ endif ifeq ($(compiler),) - ifeq ($(platform),win) - compiler := gcc - else ifeq ($(platform),osx) - compiler := gcc-mp-4.5 + ifeq ($(platform),osx) + compiler := gcc-mp-4.4 else - compiler := gcc-4.5 + compiler := gcc endif endif diff -Nru bsnes-0.073/snesfilter/nall/platform.hpp bsnes-0.073/snesfilter/nall/platform.hpp --- bsnes-0.073/snesfilter/nall/platform.hpp 2010-10-26 02:36:25.000000000 +0000 +++ bsnes-0.073/snesfilter/nall/platform.hpp 2010-01-25 04:07:34.000000000 +0000 @@ -23,12 +23,10 @@ #include #include #undef interface - #define dllexport __declspec(dllexport) #else #include #include #include - #define dllexport #endif //================== @@ -78,45 +76,5 @@ #define alwaysinline inline #endif -//========================= -//file system functionality -//========================= - -#if defined(_WIN32) - inline char* realpath(const char *filename, char *resolvedname) { - wchar_t fn[_MAX_PATH] = L""; - _wfullpath(fn, nall::utf16_t(filename), _MAX_PATH); - strcpy(resolvedname, nall::utf8_t(fn)); - return resolvedname; - } - - inline char* userpath(char *path) { - wchar_t fp[_MAX_PATH] = L""; - SHGetFolderPathW(0, CSIDL_APPDATA | CSIDL_FLAG_CREATE, 0, 0, fp); - strcpy(path, nall::utf8_t(fp)); - return path; - } - - inline char* getcwd(char *path) { - wchar_t fp[_MAX_PATH] = L""; - _wgetcwd(fp, _MAX_PATH); - strcpy(path, nall::utf8_t(fp)); - return path; - } -#else - //realpath() already exists - - inline char* userpath(char *path) { - *path = 0; - struct passwd *userinfo = getpwuid(getuid()); - if(userinfo) strcpy(path, userinfo->pw_dir); - return path; - } - - inline char *getcwd(char *path) { - return getcwd(path, PATH_MAX); - } -#endif - #endif diff -Nru bsnes-0.073/snesfilter/nall/qt/check-action.moc.hpp bsnes-0.073/snesfilter/nall/qt/check-action.moc.hpp --- bsnes-0.073/snesfilter/nall/qt/check-action.moc.hpp 1970-01-01 00:00:00.000000000 +0000 +++ bsnes-0.073/snesfilter/nall/qt/check-action.moc.hpp 2010-01-18 05:02:12.000000000 +0000 @@ -0,0 +1,41 @@ +#ifndef NALL_QT_CHECKACTION_HPP +#define NALL_QT_CHECKACTION_HPP + +namespace nall { + +class CheckAction : public QAction { + Q_OBJECT + +public: + bool isChecked() const; + void setChecked(bool); + void toggleChecked(); + CheckAction(const QString&, QObject*); + +protected slots: + +protected: + bool checked; +}; + +inline bool CheckAction::isChecked() const { + return checked; +} + +inline void CheckAction::setChecked(bool checked_) { + checked = checked_; + if(checked) setIcon(QIcon(":/16x16/item-check-on.png")); + else setIcon(QIcon(":/16x16/item-check-off.png")); +} + +inline void CheckAction::toggleChecked() { + setChecked(!isChecked()); +} + +inline CheckAction::CheckAction(const QString &text, QObject *parent) : QAction(text, parent) { + setChecked(false); +} + +} + +#endif diff -Nru bsnes-0.073/snesfilter/nall/qt/concept.hpp bsnes-0.073/snesfilter/nall/qt/concept.hpp --- bsnes-0.073/snesfilter/nall/qt/concept.hpp 1970-01-01 00:00:00.000000000 +0000 +++ bsnes-0.073/snesfilter/nall/qt/concept.hpp 2010-03-07 05:41:44.000000000 +0000 @@ -0,0 +1,10 @@ +#ifndef NALL_QT_CONCEPT_HPP +#define NALL_QT_CONCEPT_HPP + +#include + +namespace nall { + template struct has_count> { enum { value = true }; }; +} + +#endif diff -Nru bsnes-0.073/snesfilter/nall/qt/file-dialog.moc.hpp bsnes-0.073/snesfilter/nall/qt/file-dialog.moc.hpp --- bsnes-0.073/snesfilter/nall/qt/file-dialog.moc.hpp 1970-01-01 00:00:00.000000000 +0000 +++ bsnes-0.073/snesfilter/nall/qt/file-dialog.moc.hpp 2010-03-29 06:29:31.000000000 +0000 @@ -0,0 +1,392 @@ +#ifndef NALL_QT_FILEDIALOG_HPP +#define NALL_QT_FILEDIALOG_HPP + +#include +#include +#include + +namespace nall { + +class FileDialog; + +class NewFolderDialog : public Window { + Q_OBJECT + +public: + void show(); + NewFolderDialog(FileDialog*); + +protected slots: + void createFolderAction(); + +protected: + FileDialog *parent; + QVBoxLayout *layout; + QLineEdit *folderNameEdit; + QHBoxLayout *controlLayout; + QPushButton *okButton; + QPushButton *cancelButton; +}; + +class FileView : public QListView { + Q_OBJECT + +protected: + void keyPressEvent(QKeyEvent*); + +signals: + void changed(const QModelIndex&); + void browseUp(); + +protected slots: + void currentChanged(const QModelIndex&, const QModelIndex&); +}; + +class FileDialog : public Window { + Q_OBJECT + +public: + void showLoad(); + void showSave(); + void showFolder(); + + void setPath(string path); + void setNameFilters(const string &filters); + FileDialog(); + +signals: + void changed(const string&); + void activated(const string&); + void accepted(const string&); + void rejected(); + +protected slots: + void fileViewChange(const QModelIndex&); + void fileViewActivate(const QModelIndex&); + void pathBoxChanged(); + void filterBoxChanged(); + void createNewFolder(); + void browseUp(); + void acceptAction(); + void rejectAction(); + +protected: + NewFolderDialog *newFolderDialog; + QVBoxLayout *layout; + QHBoxLayout *navigationLayout; + QComboBox *pathBox; + QPushButton *newFolderButton; + QPushButton *upFolderButton; + QHBoxLayout *browseLayout; + QFileSystemModel *fileSystemModel; + FileView *fileView; + QGroupBox *previewFrame; + QLineEdit *fileNameEdit; + QHBoxLayout *controlLayout; + QComboBox *filterBox; + QPushButton *optionsButton; + QPushButton *acceptButton; + QPushButton *rejectButton; + bool lock; + void createFolderAction(const string &name); + void closeEvent(QCloseEvent*); + + friend class NewFolderDialog; +}; + +inline void NewFolderDialog::show() { + folderNameEdit->setText(""); + Window::show(); + folderNameEdit->setFocus(); +} + +inline void NewFolderDialog::createFolderAction() { + string name = folderNameEdit->text().toUtf8().constData(); + if(name == "") { + folderNameEdit->setFocus(); + } else { + parent->createFolderAction(name); + close(); + } +} + +inline NewFolderDialog::NewFolderDialog(FileDialog *fileDialog) : parent(fileDialog) { + setMinimumWidth(240); + setWindowTitle("Create New Folder"); + + layout = new QVBoxLayout; + layout->setAlignment(Qt::AlignTop); + layout->setMargin(5); + layout->setSpacing(5); + setLayout(layout); + + folderNameEdit = new QLineEdit; + layout->addWidget(folderNameEdit); + + controlLayout = new QHBoxLayout; + controlLayout->setAlignment(Qt::AlignRight); + layout->addLayout(controlLayout); + + okButton = new QPushButton("Ok"); + controlLayout->addWidget(okButton); + + cancelButton = new QPushButton("Cancel"); + controlLayout->addWidget(cancelButton); + + connect(folderNameEdit, SIGNAL(returnPressed()), this, SLOT(createFolderAction())); + connect(okButton, SIGNAL(released()), this, SLOT(createFolderAction())); + connect(cancelButton, SIGNAL(released()), this, SLOT(close())); +} + +inline void FileView::currentChanged(const QModelIndex ¤t, const QModelIndex &previous) { + QAbstractItemView::currentChanged(current, previous); + emit changed(current); +} + +inline void FileView::keyPressEvent(QKeyEvent *event) { + //enhance consistency: force OS X to act like Windows and Linux; enter = activate item + if(event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter) { + emit activated(currentIndex()); + return; + } + + //simulate popular file manager behavior; backspace = go up one directory + if(event->key() == Qt::Key_Backspace) { + emit browseUp(); + return; + } + + //fallback: unrecognized keypresses get handled by the widget itself + QListView::keyPressEvent(event); +} + +inline void FileDialog::showLoad() { + acceptButton->setText("Load"); + fileNameEdit->hide(); + filterBox->show(); + show(); +} + +inline void FileDialog::showSave() { + acceptButton->setText("Save"); + fileNameEdit->show(); + filterBox->show(); + show(); +} + +inline void FileDialog::showFolder() { + acceptButton->setText("Choose"); + fileNameEdit->hide(); + filterBox->hide(); + setNameFilters("Folders ()"); + show(); +} + +inline void FileDialog::fileViewChange(const QModelIndex &index) { + string path = fileSystemModel->filePath(index).toUtf8().constData(); + if(path == fileSystemModel->rootPath().toUtf8().constData()) path = ""; + fileNameEdit->setText(notdir(path)); + emit changed(path); +} + +inline void FileDialog::fileViewActivate(const QModelIndex &index) { + string path = fileSystemModel->filePath(index).toUtf8().constData(); + if(fileSystemModel->isDir(index)) { + emit activated(path); + setPath(path); + } else { + emit activated(path); + close(); + } +} + +inline void FileDialog::pathBoxChanged() { + if(lock) return; + setPath(pathBox->currentText().toUtf8().constData()); +} + +inline void FileDialog::filterBoxChanged() { + if(lock) return; + string filters = filterBox->currentText().toUtf8().constData(); + if(filters.length() == 0) { + fileSystemModel->setNameFilters(QStringList() << "*"); + } else { + filters = substr(filters, strpos(filters, "(")()); + ltrim(filters, "("); + rtrim(filters, ")"); + lstring part; + part.split(" ", filters); + QStringList list; + for(unsigned i = 0; i < part.size(); i++) list << part[i]; + fileSystemModel->setNameFilters(list); + } +} + +inline void FileDialog::createNewFolder() { + newFolderDialog->show(); +} + +inline void FileDialog::browseUp() { + if(pathBox->count() > 1) pathBox->setCurrentIndex(1); +} + +inline void FileDialog::setPath(string path) { + lock = true; + newFolderDialog->close(); + + if(QDir(path).exists()) { + newFolderButton->setEnabled(true); + } else { + newFolderButton->setEnabled(false); + path = ""; + } + + fileSystemModel->setRootPath(path); + fileView->setRootIndex(fileSystemModel->index(path)); + fileView->setCurrentIndex(fileView->rootIndex()); + fileView->setFocus(); + + pathBox->clear(); + if(path.length() > 0) { + QDir directory(path); + while(true) { + pathBox->addItem(directory.absolutePath()); + if(directory.isRoot()) break; + directory.cdUp(); + } + } + pathBox->addItem(""); + fileNameEdit->setText(""); + + lock = false; +} + +inline void FileDialog::setNameFilters(const string &filters) { + lock = true; + + lstring list; + list.split("\n", filters); + + filterBox->clear(); + for(unsigned i = 0; i < list.size(); i++) { + filterBox->addItem(list[i]); + } + + lock = false; + filterBoxChanged(); +} + +inline void FileDialog::acceptAction() { + string path = fileSystemModel->rootPath().toUtf8().constData(); + path << "/" << notdir(fileNameEdit->text().toUtf8().constData()); + rtrim(path, "/"); + if(QDir(path).exists()) { + emit accepted(path); + setPath(path); + } else { + emit accepted(path); + close(); + } +} + +inline void FileDialog::rejectAction() { + emit rejected(); + close(); +} + +inline void FileDialog::createFolderAction(const string &name) { + string path = fileSystemModel->rootPath().toUtf8().constData(); + path << "/" << notdir(name); + mkdir(path, 0755); +} + +inline void FileDialog::closeEvent(QCloseEvent *event) { + newFolderDialog->close(); + Window::closeEvent(event); +} + +inline FileDialog::FileDialog() { + newFolderDialog = new NewFolderDialog(this); + resize(640, 360); + + layout = new QVBoxLayout; + layout->setMargin(5); + layout->setSpacing(5); + setLayout(layout); + + navigationLayout = new QHBoxLayout; + layout->addLayout(navigationLayout); + + pathBox = new QComboBox; + pathBox->setEditable(true); + pathBox->setMinimumContentsLength(16); + pathBox->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLength); + pathBox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); + navigationLayout->addWidget(pathBox); + + newFolderButton = new QPushButton; + newFolderButton->setIconSize(QSize(16, 16)); + newFolderButton->setIcon(QIcon(":/16x16/folder-new.png")); + navigationLayout->addWidget(newFolderButton); + + upFolderButton = new QPushButton; + upFolderButton->setIconSize(QSize(16, 16)); + upFolderButton->setIcon(QIcon(":/16x16/go-up.png")); + navigationLayout->addWidget(upFolderButton); + + browseLayout = new QHBoxLayout; + layout->addLayout(browseLayout); + + fileSystemModel = new QFileSystemModel; + fileSystemModel->setFilter(QDir::AllDirs | QDir::Files | QDir::NoDotAndDotDot); + fileSystemModel->setNameFilterDisables(false); + + fileView = new FileView; + fileView->setMinimumWidth(320); + fileView->setModel(fileSystemModel); + fileView->setIconSize(QSize(16, 16)); + browseLayout->addWidget(fileView); + + previewFrame = new QGroupBox; + previewFrame->hide(); + browseLayout->addWidget(previewFrame); + + fileNameEdit = new QLineEdit; + layout->addWidget(fileNameEdit); + + controlLayout = new QHBoxLayout; + controlLayout->setAlignment(Qt::AlignRight); + layout->addLayout(controlLayout); + + filterBox = new QComboBox; + filterBox->setMinimumContentsLength(16); + filterBox->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLength); + filterBox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); + controlLayout->addWidget(filterBox); + + optionsButton = new QPushButton("Options"); + optionsButton->hide(); + controlLayout->addWidget(optionsButton); + + acceptButton = new QPushButton("Ok"); + controlLayout->addWidget(acceptButton); + + rejectButton = new QPushButton("Cancel"); + controlLayout->addWidget(rejectButton); + + lock = false; + connect(pathBox, SIGNAL(currentIndexChanged(int)), this, SLOT(pathBoxChanged())); + connect(newFolderButton, SIGNAL(released()), this, SLOT(createNewFolder())); + connect(upFolderButton, SIGNAL(released()), this, SLOT(browseUp())); + connect(fileView, SIGNAL(changed(const QModelIndex&)), this, SLOT(fileViewChange(const QModelIndex&))); + connect(fileView, SIGNAL(activated(const QModelIndex&)), this, SLOT(fileViewActivate(const QModelIndex&))); + connect(fileView, SIGNAL(browseUp()), this, SLOT(browseUp())); + connect(fileNameEdit, SIGNAL(returnPressed()), this, SLOT(acceptAction())); + connect(filterBox, SIGNAL(currentIndexChanged(int)), this, SLOT(filterBoxChanged())); + connect(acceptButton, SIGNAL(released()), this, SLOT(acceptAction())); + connect(rejectButton, SIGNAL(released()), this, SLOT(rejectAction())); +} + +} + +#endif diff -Nru bsnes-0.073/snesfilter/nall/qt/hex-editor.moc.hpp bsnes-0.073/snesfilter/nall/qt/hex-editor.moc.hpp --- bsnes-0.073/snesfilter/nall/qt/hex-editor.moc.hpp 1970-01-01 00:00:00.000000000 +0000 +++ bsnes-0.073/snesfilter/nall/qt/hex-editor.moc.hpp 2010-02-15 01:50:29.000000000 +0000 @@ -0,0 +1,173 @@ +#ifndef NALL_QT_HEXEDITOR_HPP +#define NALL_QT_HEXEDITOR_HPP + +#include +#include +#include + +namespace nall { + +class HexEditor : public QTextEdit { + Q_OBJECT + +public: + function reader; + function writer; + + void setColumns(unsigned columns); + void setRows(unsigned rows); + void setOffset(unsigned offset); + void setSize(unsigned size); + unsigned lineWidth() const; + void refresh(); + + HexEditor(); + +protected slots: + void scrolled(); + +protected: + QHBoxLayout *layout; + QScrollBar *scrollBar; + unsigned editorColumns; + unsigned editorRows; + unsigned editorOffset; + unsigned editorSize; + bool lock; + + void keyPressEvent(QKeyEvent*); +}; + +inline void HexEditor::keyPressEvent(QKeyEvent *event) { + QTextCursor cursor = textCursor(); + unsigned x = cursor.position() % lineWidth(); + unsigned y = cursor.position() / lineWidth(); + + int hexCode = -1; + switch(event->key()) { + case Qt::Key_0: hexCode = 0; break; + case Qt::Key_1: hexCode = 1; break; + case Qt::Key_2: hexCode = 2; break; + case Qt::Key_3: hexCode = 3; break; + case Qt::Key_4: hexCode = 4; break; + case Qt::Key_5: hexCode = 5; break; + case Qt::Key_6: hexCode = 6; break; + case Qt::Key_7: hexCode = 7; break; + case Qt::Key_8: hexCode = 8; break; + case Qt::Key_9: hexCode = 9; break; + case Qt::Key_A: hexCode = 10; break; + case Qt::Key_B: hexCode = 11; break; + case Qt::Key_C: hexCode = 12; break; + case Qt::Key_D: hexCode = 13; break; + case Qt::Key_E: hexCode = 14; break; + case Qt::Key_F: hexCode = 15; break; + } + + if(cursor.hasSelection() == false && hexCode != -1) { + bool cursorOffsetValid = (x >= 11 && ((x - 11) % 3) != 2); + if(cursorOffsetValid) { + bool nibble = (x - 11) % 3; //0 = top nibble, 1 = bottom nibble + unsigned cursorOffset = y * editorColumns + ((x - 11) / 3); + unsigned effectiveOffset = editorOffset + cursorOffset; + if(effectiveOffset >= editorSize) effectiveOffset %= editorSize; + + uint8_t data = reader ? reader(effectiveOffset) : 0x00; + data &= (nibble == 0 ? 0x0f : 0xf0); + data |= (nibble == 0 ? (hexCode << 4) : (hexCode << 0)); + if(writer) writer(effectiveOffset, data); + refresh(); + + cursor.setPosition(y * lineWidth() + x + 1); //advance cursor + setTextCursor(cursor); + } + } else { + //allow navigation keys to move cursor, but block text input + setTextInteractionFlags(Qt::TextSelectableByKeyboard | Qt::TextSelectableByMouse); + QTextEdit::keyPressEvent(event); + setTextInteractionFlags(Qt::TextEditorInteraction); + } +} + +inline void HexEditor::setColumns(unsigned columns) { + editorColumns = columns; +} + +inline void HexEditor::setRows(unsigned rows) { + editorRows = rows; + scrollBar->setPageStep(editorRows); +} + +inline void HexEditor::setOffset(unsigned offset) { + lock = true; + editorOffset = offset; + scrollBar->setSliderPosition(editorOffset / editorColumns); + lock = false; +} + +inline void HexEditor::setSize(unsigned size) { + editorSize = size; + bool indivisible = (editorSize % editorColumns) != 0; //add one for incomplete row + scrollBar->setRange(0, editorSize / editorColumns + indivisible - editorRows); +} + +inline unsigned HexEditor::lineWidth() const { + return 11 + 3 * editorColumns; +} + +inline void HexEditor::refresh() { + string output; + char temp[256]; + unsigned offset = editorOffset; + + for(unsigned y = 0; y < editorRows; y++) { + if(offset >= editorSize) break; + sprintf(temp, "%.4x:%.4x", (offset >> 16) & 0xffff, (offset >> 0) & 0xffff); + output << "" << temp << "  "; + + for(unsigned x = 0; x < editorColumns; x++) { + if(offset >= editorSize) break; + sprintf(temp, "%.2x", reader ? reader(offset) : 0x00); + offset++; + output << "" << temp << ""; + if(x != (editorColumns - 1)) output << " "; + } + + if(y != (editorRows - 1)) output << "
"; + } + + setHtml(output); +} + +inline void HexEditor::scrolled() { + if(lock) return; + unsigned offset = scrollBar->sliderPosition(); + editorOffset = offset * editorColumns; + refresh(); +} + +inline HexEditor::HexEditor() { + setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + + layout = new QHBoxLayout; + layout->setAlignment(Qt::AlignRight); + layout->setMargin(0); + layout->setSpacing(0); + setLayout(layout); + + scrollBar = new QScrollBar(Qt::Vertical); + scrollBar->setSingleStep(1); + layout->addWidget(scrollBar); + + lock = false; + connect(scrollBar, SIGNAL(actionTriggered(int)), this, SLOT(scrolled())); + + setColumns(16); + setRows(16); + setSize(0); + setOffset(0); +} + +} + +#endif diff -Nru bsnes-0.073/snesfilter/nall/qt/Makefile bsnes-0.073/snesfilter/nall/qt/Makefile --- bsnes-0.073/snesfilter/nall/qt/Makefile 1970-01-01 00:00:00.000000000 +0000 +++ bsnes-0.073/snesfilter/nall/qt/Makefile 2010-02-07 20:15:13.000000000 +0000 @@ -0,0 +1,55 @@ +# requires nall/Makefile + +# imports: +# $(qtlibs) -- list of Qt components to link against + +# exports the following symbols: +# $(moc) -- meta-object compiler +# $(rcc) -- resource compiler +# $(qtinc) -- includes for compiling +# $(qtlib) -- libraries for linking + +ifeq ($(moc),) +moc := moc +endif + +ifeq ($(rcc),) +rcc := rcc +endif + +ifeq ($(platform),x) + qtinc := `pkg-config --cflags $(qtlibs)` + qtlib := `pkg-config --libs $(qtlibs)` +else ifeq ($(platform),osx) + qtinc := $(foreach lib,$(qtlibs),-I/Library/Frameworks/$(lib).framework/Versions/4/Headers) + + qtlib := -L/Library/Frameworks + qtlib += $(foreach lib,$(qtlibs),-framework $(lib)) + qtlib += -framework Carbon + qtlib += -framework Cocoa + qtlib += -framework OpenGL + qtlib += -framework AppKit + qtlib += -framework ApplicationServices +else ifeq ($(platform),win) + ifeq ($(qtpath),) + # find Qt install directory from PATH environment variable + qtpath := $(foreach path,$(subst ;, ,$(PATH)),$(if $(wildcard $(path)/$(moc).exe),$(path))) + qtpath := $(strip $(qtpath)) + qtpath := $(subst \,/,$(qtpath)) + qtpath := $(patsubst %/bin,%,$(qtpath)) + endif + + qtinc := -I$(qtpath)/include + qtinc += $(foreach lib,$(qtlibs),-I$(qtpath)/include/$(lib)) + + qtlib := -L$(qtpath)/lib + qtlib += -L$(qtpath)/plugins/imageformats + + qtlib += $(foreach lib,$(qtlibs),-l$(lib)4) + qtlib += -lmingw32 -lqtmain -lcomdlg32 -loleaut32 -limm32 -lwinmm + qtlib += -lwinspool -lmsimg32 -lole32 -ladvapi32 -lws2_32 -luuid -lgdi32 + qtlib += $(foreach lib,$(qtlibs),-l$(lib)4) + + # optional image-file support: + # qtlib += -lqjpeg -lqmng +endif diff -Nru bsnes-0.073/snesfilter/nall/qt/radio-action.moc.hpp bsnes-0.073/snesfilter/nall/qt/radio-action.moc.hpp --- bsnes-0.073/snesfilter/nall/qt/radio-action.moc.hpp 1970-01-01 00:00:00.000000000 +0000 +++ bsnes-0.073/snesfilter/nall/qt/radio-action.moc.hpp 2010-01-18 04:58:30.000000000 +0000 @@ -0,0 +1,41 @@ +#ifndef NALL_QT_RADIOACTION_HPP +#define NALL_QT_RADIOACTION_HPP + +namespace nall { + +class RadioAction : public QAction { + Q_OBJECT + +public: + bool isChecked() const; + void setChecked(bool); + void toggleChecked(); + RadioAction(const QString&, QObject*); + +protected slots: + +protected: + bool checked; +}; + +inline bool RadioAction::isChecked() const { + return checked; +} + +inline void RadioAction::setChecked(bool checked_) { + checked = checked_; + if(checked) setIcon(QIcon(":/16x16/item-radio-on.png")); + else setIcon(QIcon(":/16x16/item-radio-off.png")); +} + +inline void RadioAction::toggleChecked() { + setChecked(!isChecked()); +} + +inline RadioAction::RadioAction(const QString &text, QObject *parent) : QAction(text, parent) { + setChecked(false); +} + +} + +#endif diff -Nru bsnes-0.073/snesfilter/nall/qt/window.moc.hpp bsnes-0.073/snesfilter/nall/qt/window.moc.hpp --- bsnes-0.073/snesfilter/nall/qt/window.moc.hpp 1970-01-01 00:00:00.000000000 +0000 +++ bsnes-0.073/snesfilter/nall/qt/window.moc.hpp 2010-01-18 06:16:44.000000000 +0000 @@ -0,0 +1,105 @@ +#ifndef NALL_QT_WINDOW_HPP +#define NALL_QT_WINDOW_HPP + +#include +#include + +namespace nall { + +class Window : public QWidget { + Q_OBJECT + +public: + void setGeometryString(string *geometryString); + void setCloseOnEscape(bool); + void show(); + void hide(); + void shrink(); + + Window(); + +protected slots: + +protected: + string *geometryString; + bool closeOnEscape; + void keyReleaseEvent(QKeyEvent *event); + void closeEvent(QCloseEvent *event); +}; + +inline void Window::setGeometryString(string *geometryString_) { + geometryString = geometryString_; + if(geometryString && isVisible() == false) { + uint8_t *data; + unsigned length; + base64::decode(data, length, *geometryString); + QByteArray array((const char*)data, length); + delete[] data; + restoreGeometry(array); + } +} + +inline void Window::setCloseOnEscape(bool value) { + closeOnEscape = value; +} + +inline void Window::show() { + if(geometryString && isVisible() == false) { + uint8_t *data; + unsigned length; + base64::decode(data, length, *geometryString); + QByteArray array((const char*)data, length); + delete[] data; + restoreGeometry(array); + } + QWidget::show(); + QApplication::processEvents(); + activateWindow(); + raise(); +} + +inline void Window::hide() { + if(geometryString && isVisible() == true) { + char *data; + QByteArray geometry = saveGeometry(); + base64::encode(data, (const uint8_t*)geometry.data(), geometry.length()); + *geometryString = data; + delete[] data; + } + QWidget::hide(); +} + +inline void Window::shrink() { + if(isFullScreen()) return; + + for(unsigned i = 0; i < 2; i++) { + resize(0, 0); + usleep(2000); + QApplication::processEvents(); + } +} + +inline void Window::keyReleaseEvent(QKeyEvent *event) { + if(closeOnEscape && (event->key() == Qt::Key_Escape)) close(); + QWidget::keyReleaseEvent(event); +} + +inline void Window::closeEvent(QCloseEvent *event) { + if(geometryString) { + char *data; + QByteArray geometry = saveGeometry(); + base64::encode(data, (const uint8_t*)geometry.data(), geometry.length()); + *geometryString = data; + delete[] data; + } + QWidget::closeEvent(event); +} + +inline Window::Window() { + geometryString = 0; + closeOnEscape = true; +} + +} + +#endif diff -Nru bsnes-0.073/snesfilter/nall/serial.hpp bsnes-0.073/snesfilter/nall/serial.hpp --- bsnes-0.073/snesfilter/nall/serial.hpp 2010-10-26 02:36:25.000000000 +0000 +++ bsnes-0.073/snesfilter/nall/serial.hpp 2009-01-10 17:34:32.000000000 +0000 @@ -23,7 +23,7 @@ return ::write(port, (void*)data, length); } - bool open(const char *portname, unsigned rate, bool flowcontrol) { + bool open(const char *portname, unsigned rate) { close(); port = ::open(portname, O_RDWR | O_NOCTTY | O_NDELAY | O_NONBLOCK); @@ -41,13 +41,8 @@ attr.c_iflag &=~ (BRKINT | PARMRK | INPCK | ISTRIP | INLCR | IGNCR | ICRNL | IXON | IXOFF | IXANY); attr.c_iflag |= (IGNBRK | IGNPAR); attr.c_oflag &=~ (OPOST); - attr.c_cflag &=~ (CSIZE | CSTOPB | PARENB | CLOCAL); - attr.c_cflag |= (CS8 | CREAD); - if(flowcontrol == false) { - attr.c_cflag &= ~CRTSCTS; - } else { - attr.c_cflag |= CRTSCTS; - } + attr.c_cflag &=~ (CSIZE | CSTOPB | PARENB); + attr.c_cflag |= (CS8 | CREAD | CLOCAL); attr.c_cc[VTIME] = attr.c_cc[VMIN] = 0; if(tcsetattr(port, TCSANOW, &attr) == -1) { close(); return false; } diff -Nru bsnes-0.073/snesfilter/nall/serializer.hpp bsnes-0.073/snesfilter/nall/serializer.hpp --- bsnes-0.073/snesfilter/nall/serializer.hpp 2010-10-26 02:36:25.000000000 +0000 +++ bsnes-0.073/snesfilter/nall/serializer.hpp 2010-03-18 04:43:40.000000000 +0000 @@ -112,7 +112,6 @@ imode = Size; idata = 0; isize = 0; - icapacity = 0; } serializer(unsigned capacity) { diff -Nru bsnes-0.073/snesfilter/nall/snes/info.hpp bsnes-0.073/snesfilter/nall/snes/info.hpp --- bsnes-0.073/snesfilter/nall/snes/info.hpp 2010-10-26 02:36:25.000000000 +0000 +++ bsnes-0.073/snesfilter/nall/snes/info.hpp 2010-06-27 02:04:19.000000000 +0000 @@ -9,7 +9,7 @@ inline snes_information(const uint8_t *data, unsigned size); -//private: +private: inline void read_header(const uint8_t *data, unsigned size); inline unsigned find_header(const uint8_t *data, unsigned size); inline unsigned score_header(const uint8_t *data, unsigned size, unsigned addr); @@ -558,11 +558,6 @@ } } - if(size < 32768) { - type = TypeUnknown; - return; - } - const unsigned index = find_header(data, size); const uint8_t mapperid = data[index + Mapper]; const uint8_t rom_type = data[index + RomType]; diff -Nru bsnes-0.073/snesfilter/nall/string/base.hpp bsnes-0.073/snesfilter/nall/string/base.hpp --- bsnes-0.073/snesfilter/nall/string/base.hpp 2010-10-26 02:36:26.000000000 +0000 +++ bsnes-0.073/snesfilter/nall/string/base.hpp 2010-06-05 16:03:27.000000000 +0000 @@ -17,43 +17,10 @@ class string { public: inline void reserve(unsigned); + inline unsigned length() const; inline string& assign(const char*); inline string& append(const char*); - inline string& append(bool); - inline string& append(signed int value); - inline string& append(unsigned int value); - inline string& append(double value); - - inline bool readfile(const char*); - - inline string& replace (const char*, const char*); - inline string& qreplace(const char*, const char*); - - inline unsigned length() const; - - inline bool equals(const char*) const; - inline bool iequals(const char*) const; - - inline bool wildcard(const char*) const; - inline bool iwildcard(const char*) const; - - inline bool beginswith(const char*) const; - inline bool ibeginswith(const char*) const; - inline bool endswith(const char*) const; - inline bool iendswith(const char*) const; - - inline string& lower(); - inline string& upper(); - inline string& transform(const char *before, const char *after); - - template inline string& ltrim(const char *key = " "); - template inline string& rtrim(const char *key = " "); - template inline string& trim (const char *key = " "); - - inline optional position(const char *key) const; - inline optional qposition(const char *key) const; - template inline string& operator= (T value); template inline string& operator<<(T value); @@ -71,11 +38,16 @@ inline string& operator=(const string&); inline string& operator=(string&&); - template inline string(Args&&... args); + inline string(); + inline string(const char*); inline string(const string&); inline string(string&&); inline ~string(); + inline bool readfile(const char*); + inline string& replace (const char*, const char*); + inline string& qreplace(const char*, const char*); + protected: char *data; unsigned size; @@ -90,9 +62,9 @@ public: template inline lstring& operator<<(T value); - inline optional find(const char*) const; - template inline void split (const char*, const char*); - template inline void qsplit(const char*, const char*); + inline int find(const char*); + inline void split (const char*, const char*, unsigned = 0); + inline void qsplit(const char*, const char*, unsigned = 0); lstring(); lstring(std::initializer_list); @@ -101,9 +73,7 @@ //compare.hpp inline char chrlower(char c); inline char chrupper(char c); - inline int stricmp(const char *str1, const char *str2); - inline bool wildcard(const char *str, const char *pattern); - inline bool iwildcard(const char *str, const char *pattern); + inline int stricmp(const char *dest, const char *src); inline bool strbegin (const char *str, const char *key); inline bool stribegin(const char *str, const char *key); inline bool strend (const char *str, const char *key); @@ -119,32 +89,38 @@ inline uintmax_t strbin (const char *str); inline double strdouble (const char *str); + //match.hpp + inline bool match(const char *pattern, const char *str); + //math.hpp inline bool strint (const char *str, int &result); inline bool strmath(const char *str, int &result); - //platform.hpp - inline string realpath(const char *name); - inline string userpath(); - inline string currentpath(); - //strl.hpp inline unsigned strlcpy(char *dest, const char *src, unsigned length); inline unsigned strlcat(char *dest, const char *src, unsigned length); - //strpos.hpp - inline optional strpos(const char *str, const char *key); - inline optional qstrpos(const char *str, const char *key); - //trim.hpp - template inline char* ltrim(char *str, const char *key = " "); - template inline char* rtrim(char *str, const char *key = " "); - template inline char* trim (char *str, const char *key = " "); + inline char* ltrim(char *str, const char *key = " "); + inline char* rtrim(char *str, const char *key = " "); + inline char* trim (char *str, const char *key = " "); + inline char* ltrim_once(char *str, const char *key = " "); + inline char* rtrim_once(char *str, const char *key = " "); + inline char* trim_once (char *str, const char *key = " "); //utility.hpp inline unsigned strlcpy(string &dest, const char *src, unsigned length); inline unsigned strlcat(string &dest, const char *src, unsigned length); inline string substr(const char *src, unsigned start = 0, unsigned length = 0); + inline string& strlower(string &str); + inline string& strupper(string &str); + inline string& strtr(string &dest, const char *before, const char *after); + inline string& ltrim(string &str, const char *key = " "); + inline string& rtrim(string &str, const char *key = " "); + inline string& trim (string &str, const char *key = " "); + inline string& ltrim_once(string &str, const char *key = " "); + inline string& rtrim_once(string &str, const char *key = " "); + inline string& trim_once (string &str, const char *key = " "); template inline string strhex(uintmax_t value); template inline string strsigned(intmax_t value); template inline string strunsigned(uintmax_t value); @@ -153,7 +129,8 @@ inline string strdouble(double value); //variadic.hpp - template inline void print(Args&&... args); + template inline string sprint(Args... args); + template inline void print(Args... args); }; #endif diff -Nru bsnes-0.073/snesfilter/nall/string/bsv.hpp bsnes-0.073/snesfilter/nall/string/bsv.hpp --- bsnes-0.073/snesfilter/nall/string/bsv.hpp 2010-10-26 02:36:26.000000000 +0000 +++ bsnes-0.073/snesfilter/nall/string/bsv.hpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,75 +0,0 @@ -#ifndef NALL_STRING_BSV_HPP -#define NALL_STRING_BSV_HPP - -//BSV parser -//version 0.01 - -namespace nall { - -inline string bsv_decode(const char *input) { - string output; - unsigned offset = 0; - while(*input) { - //illegal characters - if(*input == '}' ) return ""; - if(*input == '\r') return ""; - if(*input == '\n') return ""; - - //normal characters - if(*input != '{') { output[offset++] = *input++; continue; } - - //entities - if(strbegin(input, "{lf}")) { output[offset++] = '\n'; input += 4; continue; } - if(strbegin(input, "{lb}")) { output[offset++] = '{'; input += 4; continue; } - if(strbegin(input, "{rb}")) { output[offset++] = '}'; input += 4; continue; } - - //illegal entities - return ""; - } - output[offset] = 0; - return output; -} - -inline string bsv_encode(const char *input) { - string output; - unsigned offset = 0; - while(*input) { - //illegal characters - if(*input == '\r') return ""; - - if(*input == '\n') { - output[offset++] = '{'; - output[offset++] = 'l'; - output[offset++] = 'f'; - output[offset++] = '}'; - input++; - continue; - } - - if(*input == '{') { - output[offset++] = '{'; - output[offset++] = 'l'; - output[offset++] = 'b'; - output[offset++] = '}'; - input++; - continue; - } - - if(*input == '}') { - output[offset++] = '{'; - output[offset++] = 'r'; - output[offset++] = 'b'; - output[offset++] = '}'; - input++; - continue; - } - - output[offset++] = *input++; - } - output[offset] = 0; - return output; -} - -} - -#endif diff -Nru bsnes-0.073/snesfilter/nall/string/compare.hpp bsnes-0.073/snesfilter/nall/string/compare.hpp --- bsnes-0.073/snesfilter/nall/string/compare.hpp 2010-10-26 02:36:26.000000000 +0000 +++ bsnes-0.073/snesfilter/nall/string/compare.hpp 2010-03-29 05:03:00.000000000 +0000 @@ -11,52 +11,14 @@ return (c >= 'a' && c <= 'z') ? c - ('a' - 'A') : c; } -int stricmp(const char *str1, const char *str2) { - while(*str1) { - if(chrlower(*str1) != chrlower(*str2)) break; - str1++, str2++; +int stricmp(const char *dest, const char *src) { + while(*dest) { + if(chrlower(*dest) != chrlower(*src)) break; + dest++; + src++; } - return (int)chrlower(*str1) - (int)chrlower(*str2); -} -bool wildcard(const char *s, const char *p) { - const char *cp = 0, *mp = 0; - while(*s && *p != '*') { - if(*p != '?' && *s != *p) return false; - p++, s++; - } - while(*s) { - if(*p == '*') { - if(!*++p) return true; - mp = p, cp = s + 1; - } else if(*p == '?' || *p == *s) { - p++, s++; - } else { - p = mp, s = cp++; - } - } - while(*p == '*') p++; - return !*p; -} - -bool iwildcard(const char *s, const char *p) { - const char *cp = 0, *mp = 0; - while(*s && *p != '*') { - if(*p != '?' && chrlower(*s) != chrlower(*p)) return false; - p++, s++; - } - while(*s) { - if(*p == '*') { - if(!*++p) return true; - mp = p, cp = s + 1; - } else if(*p == '?' || chrlower(*p) == chrlower(*s)) { - p++, s++; - } else { - p = mp, s = cp++; - } - } - while(*p == '*') p++; - return !*p; + return (int)chrlower(*dest) - (int)chrlower(*src); } bool strbegin(const char *str, const char *key) { diff -Nru bsnes-0.073/snesfilter/nall/string/core.hpp bsnes-0.073/snesfilter/nall/string/core.hpp --- bsnes-0.073/snesfilter/nall/string/core.hpp 2010-10-26 02:36:26.000000000 +0000 +++ bsnes-0.073/snesfilter/nall/string/core.hpp 2010-03-29 05:53:17.000000000 +0000 @@ -11,6 +11,10 @@ } } +unsigned string::length() const { + return strlen(data); +} + string& string::assign(const char *s) { unsigned length = strlen(s); reserve(length); @@ -25,11 +29,6 @@ return *this; } -string& string::append(bool value) { append(value ? "true" : "false"); return *this; } -string& string::append(signed int value) { append(strsigned(value)); return *this; } -string& string::append(unsigned int value) { append(strunsigned(value)); return *this; } -string& string::append(double value) { append(strdouble(value)); return *this; } - string::operator const char*() const { return data; } @@ -64,20 +63,15 @@ return *this; } -static void istring(string &output) { -} - -template -static void istring(string &output, const T &value, Args&&... args) { - output.append(value); - istring(output, std::forward(args)...); -} - -template string::string(Args&&... args) { +string::string() { size = 64; data = (char*)malloc(size + 1); *data = 0; - istring(*this, std::forward(args)...); +} + +string::string(const char *value) { + size = strlen(value); + data = strdup(value); } string::string(const string &value) { @@ -92,7 +86,7 @@ } string::~string() { - if(data) free(data); + free(data); } bool string::readfile(const char *filename) { @@ -118,11 +112,11 @@ return true; } -optional lstring::find(const char *key) const { +int lstring::find(const char *key) { for(unsigned i = 0; i < size(); i++) { - if(operator[](i) == key) return { true, i }; + if(operator[](i) == key) return i; } - return { false, 0 }; + return -1; } inline lstring::lstring() { diff -Nru bsnes-0.073/snesfilter/nall/string/filename.hpp bsnes-0.073/snesfilter/nall/string/filename.hpp --- bsnes-0.073/snesfilter/nall/string/filename.hpp 2010-10-26 02:36:26.000000000 +0000 +++ bsnes-0.073/snesfilter/nall/string/filename.hpp 2010-03-23 02:03:13.000000000 +0000 @@ -3,9 +3,7 @@ namespace nall { -// "foo/bar.c" -> "foo/" -// "foo/" -> "foo/" -// "bar.c" -> "./" +// "foo/bar.c" -> "foo/", "bar.c" -> "./" inline string dir(char const *name) { string result = name; for(signed i = strlen(result); i >= 0; i--) { diff -Nru bsnes-0.073/snesfilter/nall/string/match.hpp bsnes-0.073/snesfilter/nall/string/match.hpp --- bsnes-0.073/snesfilter/nall/string/match.hpp 1970-01-01 00:00:00.000000000 +0000 +++ bsnes-0.073/snesfilter/nall/string/match.hpp 2010-03-23 01:57:33.000000000 +0000 @@ -0,0 +1,76 @@ +#ifndef NALL_STRING_MATCH_HPP +#define NALL_STRING_MATCH_HPP + +namespace nall { + +bool match(const char *p, const char *s) { + const char *p_ = 0, *s_ = 0; + + for(;;) { + if(!*s) { + while(*p == '*') p++; + return !*p; + } + + //wildcard match + if(*p == '*') { + p_ = p++, s_ = s; + continue; + } + + //any match + if(*p == '?') { + p++, s++; + continue; + } + + //ranged match + if(*p == '{') { + #define pattern(name_, rule_) \ + if(strbegin(p, name_)) { \ + if(rule_) { \ + p += sizeof(name_) - 1, s++; \ + continue; \ + } \ + goto failure; \ + } + + pattern("{alpha}", (*s >= 'A' && *s <= 'Z') || (*s >= 'a' && *s <= 'z')) + pattern("{alphanumeric}", (*s >= 'A' && *s <= 'Z') || (*s >= 'a' && *s <= 'z') || (*s >= '0' && *s <= '9')) + pattern("{binary}", (*s == '0' || *s == '1')) + pattern("{hex}", (*s >= '0' && *s <= '9') || (*s >= 'A' && *s <= 'F') || (*s >= 'a' && *s <= 'f')) + pattern("{lowercase}", (*s >= 'a' && *s <= 'z')) + pattern("{numeric}", (*s >= '0' && *s <= '9')) + pattern("{uppercase}", (*s >= 'A' && *s <= 'Z')) + pattern("{whitespace}", (*s == ' ' || *s == '\t')) + + #undef pattern + goto failure; + } + + //reserved character match + if(*p == '\\') { + p++; + //fallthrough + } + + //literal match + if(*p == *s) { + p++, *s++; + continue; + } + + //attempt wildcard rematch + failure: + if(p_) { + p = p_, s = s_ + 1; + continue; + } + + return false; + } +} + +} + +#endif diff -Nru bsnes-0.073/snesfilter/nall/string/platform.hpp bsnes-0.073/snesfilter/nall/string/platform.hpp --- bsnes-0.073/snesfilter/nall/string/platform.hpp 2010-10-26 02:36:26.000000000 +0000 +++ bsnes-0.073/snesfilter/nall/string/platform.hpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,41 +0,0 @@ -#ifndef NALL_STRING_PLATFORM_HPP -#define NALL_STRING_PLATFORM_HPP - -namespace nall { - -string realpath(const char *name) { - char path[PATH_MAX]; - if(::realpath(name, path)) { - string result(path); - result.transform("\\", "/"); - if(result.endswith("/") == false) result.append("/"); - return result; - } - return ""; -} - -string userpath() { - char path[PATH_MAX]; - if(::userpath(path)) { - string result(path); - result.transform("\\", "/"); - if(result.endswith("/") == false) result.append("/"); - return result; - } - return ""; -} - -string currentpath() { - char path[PATH_MAX]; - if(::getcwd(path)) { - string result(path); - result.transform("\\", "/"); - if(result.endswith("/") == false) result.append("/"); - return result; - } - return ""; -} - -} - -#endif diff -Nru bsnes-0.073/snesfilter/nall/string/split.hpp bsnes-0.073/snesfilter/nall/string/split.hpp --- bsnes-0.073/snesfilter/nall/string/split.hpp 2010-10-26 02:36:26.000000000 +0000 +++ bsnes-0.073/snesfilter/nall/string/split.hpp 2009-05-22 04:50:18.000000000 +0000 @@ -3,8 +3,7 @@ namespace nall { -template void lstring::split(const char *key, const char *src) { - unsigned limit = Limit; +void lstring::split(const char *key, const char *src, unsigned limit) { reset(); int ssl = strlen(src), ksl = strlen(key); @@ -22,8 +21,7 @@ operator[](split_count++) = src + lp; } -template void lstring::qsplit(const char *key, const char *src) { - unsigned limit = Limit; +void lstring::qsplit(const char *key, const char *src, unsigned limit) { reset(); int ssl = strlen(src), ksl = strlen(key); diff -Nru bsnes-0.073/snesfilter/nall/string/strpos.hpp bsnes-0.073/snesfilter/nall/string/strpos.hpp --- bsnes-0.073/snesfilter/nall/string/strpos.hpp 2010-10-26 02:36:26.000000000 +0000 +++ bsnes-0.073/snesfilter/nall/string/strpos.hpp 2010-03-31 01:46:33.000000000 +0000 @@ -7,7 +7,7 @@ namespace nall { -optional strpos(const char *str, const char *key) { +optional inline strpos(const char *str, const char *key) { unsigned ssl = strlen(str), ksl = strlen(key); if(ksl > ssl) return { false, 0 }; @@ -18,7 +18,7 @@ return { false, 0 }; } -optional qstrpos(const char *str, const char *key) { +optional inline qstrpos(const char *str, const char *key) { unsigned ssl = strlen(str), ksl = strlen(key); if(ksl > ssl) return { false, 0 }; diff -Nru bsnes-0.073/snesfilter/nall/string/trim.hpp bsnes-0.073/snesfilter/nall/string/trim.hpp --- bsnes-0.073/snesfilter/nall/string/trim.hpp 2010-10-26 02:36:26.000000000 +0000 +++ bsnes-0.073/snesfilter/nall/string/trim.hpp 2010-03-23 01:55:43.000000000 +0000 @@ -3,9 +3,7 @@ namespace nall { -//limit defaults to zero, which will underflow on first compare; equivalent to no limit -template char* ltrim(char *str, const char *key) { - unsigned limit = Limit; +char* ltrim(char *str, const char *key) { if(!key || !*key) return str; while(strbegin(str, key)) { char *dest = str, *src = str + strlen(key); @@ -14,23 +12,41 @@ if(!*dest) break; dest++; } - if(--limit == 0) break; } return str; } -template char* rtrim(char *str, const char *key) { - unsigned limit = Limit; +char* rtrim(char *str, const char *key) { if(!key || !*key) return str; - while(strend(str, key)) { - str[strlen(str) - strlen(key)] = 0; - if(--limit == 0) break; + while(strend(str, key)) str[strlen(str) - strlen(key)] = 0; + return str; +} + +char* trim(char *str, const char *key) { + return ltrim(rtrim(str, key), key); +} + +char* ltrim_once(char *str, const char *key) { + if(!key || !*key) return str; + if(strbegin(str, key)) { + char *dest = str, *src = str + strlen(key); + while(true) { + *dest = *src++; + if(!*dest) break; + dest++; + } } return str; } -template char* trim(char *str, const char *key) { - return ltrim(rtrim(str, key), key); +char* rtrim_once(char *str, const char *key) { + if(!key || !*key) return str; + if(strend(str, key)) str[strlen(str) - strlen(key)] = 0; + return str; +} + +char* trim_once(char *str, const char *key) { + return ltrim_once(rtrim_once(str, key), key); } } diff -Nru bsnes-0.073/snesfilter/nall/string/utility.hpp bsnes-0.073/snesfilter/nall/string/utility.hpp --- bsnes-0.073/snesfilter/nall/string/utility.hpp 2010-10-26 02:36:26.000000000 +0000 +++ bsnes-0.073/snesfilter/nall/string/utility.hpp 2010-03-23 02:07:06.000000000 +0000 @@ -25,6 +25,18 @@ return dest; } +/* very simplistic wrappers to return string& instead of char* type */ + +string& strlower(string &str) { strlower(str()); return str; } +string& strupper(string &str) { strupper(str()); return str; } +string& strtr(string &dest, const char *before, const char *after) { strtr(dest(), before, after); return dest; } +string& ltrim(string &str, const char *key) { ltrim(str(), key); return str; } +string& rtrim(string &str, const char *key) { rtrim(str(), key); return str; } +string& trim (string &str, const char *key) { trim (str(), key); return str; } +string& ltrim_once(string &str, const char *key) { ltrim_once(str(), key); return str; } +string& rtrim_once(string &str, const char *key) { rtrim_once(str(), key); return str; } +string& trim_once (string &str, const char *key) { trim_once (str(), key); return str; } + /* arithmetic <> string */ template string strhex(uintmax_t value) { diff -Nru bsnes-0.073/snesfilter/nall/string/variadic.hpp bsnes-0.073/snesfilter/nall/string/variadic.hpp --- bsnes-0.073/snesfilter/nall/string/variadic.hpp 2010-10-26 02:36:26.000000000 +0000 +++ bsnes-0.073/snesfilter/nall/string/variadic.hpp 2010-03-23 02:02:17.000000000 +0000 @@ -3,8 +3,23 @@ namespace nall { -template inline void print(Args&&... args) { - printf("%s", (const char*)string(std::forward(args)...)); +static void isprint(string &output) { +} + +template +static void isprint(string &output, T value, Args... args) { + output << to_string(value); + isprint(output, args...); +} + +template inline string sprint(Args... args) { + string output; + isprint(output, args...); + return output; +} + +template inline void print(Args... args) { + printf("%s", (const char*)sprint(args...)); } } diff -Nru bsnes-0.073/snesfilter/nall/string/wrapper.hpp bsnes-0.073/snesfilter/nall/string/wrapper.hpp --- bsnes-0.073/snesfilter/nall/string/wrapper.hpp 2010-10-26 02:36:26.000000000 +0000 +++ bsnes-0.073/snesfilter/nall/string/wrapper.hpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,33 +0,0 @@ -#ifndef NALL_STRING_WRAPPER_HPP -#define NALL_STRING_WRAPPER_HPP - -namespace nall { - -unsigned string::length() const { return strlen(data); } - -bool string::equals(const char *str) const { return !strcmp(data, str); } -bool string::iequals(const char *str) const { return !stricmp(data, str); } - -bool string::wildcard(const char *str) const { return nall::wildcard(data, str); } -bool string::iwildcard(const char *str) const { return nall::iwildcard(data, str); } - -bool string::beginswith(const char *str) const { return strbegin(data, str); } -bool string::ibeginswith(const char *str) const { return stribegin(data, str); } - -bool string::endswith(const char *str) const { return strend(data, str); } -bool string::iendswith(const char *str) const { return striend(data, str); } - -string& string::lower() { nall::strlower(data); return *this; } -string& string::upper() { nall::strupper(data); return *this; } -string& string::transform(const char *before, const char *after) { nall::strtr(data, before, after); return *this; } - -template string& string::ltrim(const char *key) { nall::ltrim(data, key); return *this; } -template string& string::rtrim(const char *key) { nall::rtrim(data, key); return *this; } -template string& string::trim (const char *key) { nall::trim (data, key); return *this; } - -optional string::position(const char *key) const { return strpos(data, key); } -optional string::qposition(const char *key) const { return qstrpos(data, key); } - -} - -#endif diff -Nru bsnes-0.073/snesfilter/nall/string/xml.hpp bsnes-0.073/snesfilter/nall/string/xml.hpp --- bsnes-0.073/snesfilter/nall/string/xml.hpp 2010-10-26 02:36:26.000000000 +0000 +++ bsnes-0.073/snesfilter/nall/string/xml.hpp 2010-06-06 02:44:37.000000000 +0000 @@ -75,12 +75,11 @@ if(strbegin(source, "")) { - if(pos() - 9 > 0) { - string cdata = substr(source, 9, pos() - 9); - data << cdata; - offset += strlen(cdata); - } - source += 9 + offset + 3; + string cdata = substr(source, 9, pos() - 9); + data << cdata; + offset += strlen(cdata); + + source += offset + 3; continue; } else { return ""; @@ -123,7 +122,7 @@ while(qstrpos(data, " ")) data.qreplace(" ", " "); data.qreplace(" =", "="); data.qreplace("= ", "="); - data.rtrim(); + rtrim(data); lstring part; part.qsplit(" ", data); @@ -139,8 +138,8 @@ xml_attribute attr; attr.name = side[0]; attr.content = side[1]; - if(strbegin(attr.content, "\"") && strend(attr.content, "\"")) attr.content.trim<1>("\""); - else if(strbegin(attr.content, "'") && strend(attr.content, "'")) attr.content.trim<1>("'"); + if(strbegin(attr.content, "\"") && strend(attr.content, "\"")) trim_once(attr.content, "\""); + else if(strbegin(attr.content, "'") && strend(attr.content, "'")) trim_once(attr.content, "'"); else throw "..."; attribute.append(attr); } @@ -186,10 +185,10 @@ if(strend(tag, "?") == true) { self_terminating = true; - tag.rtrim<1>("?"); + rtrim_once(tag, "?"); } else if(strend(tag, "/") == true) { self_terminating = true; - tag.rtrim<1>("/"); + rtrim_once(tag, "/"); } parse_head(tag); @@ -214,7 +213,7 @@ tag.replace("\r", " "); tag.replace("\n", " "); while(strpos(tag, " ")) tag.replace(" ", " "); - tag.rtrim(); + rtrim(tag); if(name != tag) throw "..."; return true; diff -Nru bsnes-0.073/snesfilter/nall/string.hpp bsnes-0.073/snesfilter/nall/string.hpp --- bsnes-0.073/snesfilter/nall/string.hpp 2010-10-26 02:36:26.000000000 +0000 +++ bsnes-0.073/snesfilter/nall/string.hpp 2010-03-31 01:45:14.000000000 +0000 @@ -2,18 +2,16 @@ #define NALL_STRING_HPP #include -#include #include #include -#include #include #include #include #include #include +#include #include -#include #include #include #include @@ -21,7 +19,6 @@ #include #include #include -#include #include namespace nall { diff -Nru bsnes-0.073/snesfilter/nall/ups.hpp bsnes-0.073/snesfilter/nall/ups.hpp --- bsnes-0.073/snesfilter/nall/ups.hpp 2010-10-26 02:36:26.000000000 +0000 +++ bsnes-0.073/snesfilter/nall/ups.hpp 2009-10-13 03:27:53.000000000 +0000 @@ -1,223 +1,190 @@ #ifndef NALL_UPS_HPP #define NALL_UPS_HPP +#include + +#include #include #include -#include #include namespace nall { + class ups { + public: + enum result { + ok, + patch_unreadable, + patch_unwritable, + patch_invalid, + input_invalid, + output_invalid, + patch_crc32_invalid, + input_crc32_invalid, + output_crc32_invalid, + }; + + ups::result create(const char *patch_fn, const uint8_t *x_data, unsigned x_size, const uint8_t *y_data, unsigned y_size) { + if(!fp.open(patch_fn, file::mode_write)) return patch_unwritable; + + crc32 = ~0; + uint32_t x_crc32 = crc32_calculate(x_data, x_size); + uint32_t y_crc32 = crc32_calculate(y_data, y_size); + + //header + write('U'); + write('P'); + write('S'); + write('1'); + encptr(x_size); + encptr(y_size); + + //body + unsigned max_size = max(x_size, y_size); + unsigned relative = 0; + for(unsigned i = 0; i < max_size;) { + uint8_t x = i < x_size ? x_data[i] : 0x00; + uint8_t y = i < y_size ? y_data[i] : 0x00; + + if(x == y) { + i++; + continue; + } -struct ups { - enum class result : unsigned { - unknown, - success, - patch_unwritable, - patch_invalid, - source_invalid, - target_invalid, - target_too_small, - patch_checksum_invalid, - source_checksum_invalid, - target_checksum_invalid, - }; + encptr(i++ - relative); + write(x ^ y); - function progress; + while(true) { + if(i >= max_size) { + write(0x00); + break; + } + + x = i < x_size ? x_data[i] : 0x00; + y = i < y_size ? y_data[i] : 0x00; + i++; + write(x ^ y); + if(x == y) break; + } - result create( - const uint8_t *sourcedata, unsigned sourcelength, - const uint8_t *targetdata, unsigned targetlength, - const char *patchfilename - ) { - source_data = (uint8_t*)sourcedata, target_data = (uint8_t*)targetdata; - source_length = sourcelength, target_length = targetlength; - source_offset = target_offset = 0; - source_checksum = target_checksum = patch_checksum = ~0; - - if(patch_file.open(patchfilename, file::mode::write) == false) return result::patch_unwritable; - - patch_write('U'); - patch_write('P'); - patch_write('S'); - patch_write('1'); - encode(source_length); - encode(target_length); - - unsigned output_length = source_length > target_length ? source_length : target_length; - unsigned relative = 0; - for(unsigned offset = 0; offset < output_length;) { - uint8_t x = source_read(); - uint8_t y = target_read(); - - if(x == y) { - offset++; - continue; + relative = i; } - encode(offset++ - relative); - patch_write(x ^ y); - - while(true) { - if(offset >= output_length) { - patch_write(0x00); - break; + //footer + for(unsigned i = 0; i < 4; i++) write(x_crc32 >> (i << 3)); + for(unsigned i = 0; i < 4; i++) write(y_crc32 >> (i << 3)); + uint32_t p_crc32 = ~crc32; + for(unsigned i = 0; i < 4; i++) write(p_crc32 >> (i << 3)); + + fp.close(); + return ok; + } + + ups::result apply(const uint8_t *p_data, unsigned p_size, const uint8_t *x_data, unsigned x_size, uint8_t *&y_data, unsigned &y_size) { + if(p_size < 18) return patch_invalid; + p_buffer = p_data; + + crc32 = ~0; + + //header + if(read() != 'U') return patch_invalid; + if(read() != 'P') return patch_invalid; + if(read() != 'S') return patch_invalid; + if(read() != '1') return patch_invalid; + + unsigned px_size = decptr(); + unsigned py_size = decptr(); + + //mirror + if(x_size != px_size && x_size != py_size) return input_invalid; + y_size = (x_size == px_size) ? py_size : px_size; + y_data = new uint8_t[y_size](); + + for(unsigned i = 0; i < x_size && i < y_size; i++) y_data[i] = x_data[i]; + for(unsigned i = x_size; i < y_size; i++) y_data[i] = 0x00; + + //body + unsigned relative = 0; + while(p_buffer < p_data + p_size - 12) { + relative += decptr(); + + while(true) { + uint8_t x = read(); + if(x && relative < y_size) { + uint8_t y = relative < x_size ? x_data[relative] : 0x00; + y_data[relative] = x ^ y; + } + relative++; + if(!x) break; } - - x = source_read(); - y = target_read(); - offset++; - patch_write(x ^ y); - if(x == y) break; } - relative = offset; - } - - source_checksum = ~source_checksum; - target_checksum = ~target_checksum; - for(unsigned i = 0; i < 4; i++) patch_write(source_checksum >> (i * 8)); - for(unsigned i = 0; i < 4; i++) patch_write(target_checksum >> (i * 8)); - uint32_t patch_result_checksum = ~patch_checksum; - for(unsigned i = 0; i < 4; i++) patch_write(patch_result_checksum >> (i * 8)); - - patch_file.close(); - return result::success; - } - - result apply( - const uint8_t *patchdata, unsigned patchlength, - const uint8_t *sourcedata, unsigned sourcelength, - uint8_t *targetdata, unsigned &targetlength - ) { - patch_data = (uint8_t*)patchdata, source_data = (uint8_t*)sourcedata, target_data = targetdata; - patch_length = patchlength, source_length = sourcelength, target_length = targetlength; - patch_offset = source_offset = target_offset = 0; - patch_checksum = source_checksum = target_checksum = ~0; - - if(patch_length < 18) return result::patch_invalid; - if(patch_read() != 'U') return result::patch_invalid; - if(patch_read() != 'P') return result::patch_invalid; - if(patch_read() != 'S') return result::patch_invalid; - if(patch_read() != '1') return result::patch_invalid; - - unsigned source_read_length = decode(); - unsigned target_read_length = decode(); - - if(source_length != source_read_length && source_length != target_read_length) return result::source_invalid; - targetlength = (source_length == source_read_length ? target_read_length : source_read_length); - if(target_length < targetlength) return result::target_too_small; - target_length = targetlength; - - while(patch_offset < patch_length - 12) { - unsigned length = decode(); - while(length--) target_write(source_read()); - while(true) { - uint8_t patch_xor = patch_read(); - target_write(patch_xor ^ source_read()); - if(patch_xor == 0) break; + //footer + unsigned px_crc32 = 0, py_crc32 = 0, pp_crc32 = 0; + for(unsigned i = 0; i < 4; i++) px_crc32 |= read() << (i << 3); + for(unsigned i = 0; i < 4; i++) py_crc32 |= read() << (i << 3); + uint32_t p_crc32 = ~crc32; + for(unsigned i = 0; i < 4; i++) pp_crc32 |= read() << (i << 3); + + uint32_t x_crc32 = crc32_calculate(x_data, x_size); + uint32_t y_crc32 = crc32_calculate(y_data, y_size); + + if(px_size != py_size) { + if(x_size == px_size && x_crc32 != px_crc32) return input_crc32_invalid; + if(x_size == py_size && x_crc32 != py_crc32) return input_crc32_invalid; + if(y_size == px_size && y_crc32 != px_crc32) return output_crc32_invalid; + if(y_size == py_size && y_crc32 != py_crc32) return output_crc32_invalid; + } else { + if(x_crc32 != px_crc32 && x_crc32 != py_crc32) return input_crc32_invalid; + if(y_crc32 != px_crc32 && y_crc32 != py_crc32) return output_crc32_invalid; + if(x_crc32 == y_crc32 && px_crc32 != py_crc32) return output_crc32_invalid; + if(x_crc32 != y_crc32 && px_crc32 == py_crc32) return output_crc32_invalid; } + + if(p_crc32 != pp_crc32) return patch_crc32_invalid; + return ok; } - while(source_offset < source_length) target_write(source_read()); - while(target_offset < target_length) target_write(source_read()); - uint32_t patch_read_checksum = 0, source_read_checksum = 0, target_read_checksum = 0; - for(unsigned i = 0; i < 4; i++) source_read_checksum |= patch_read() << (i * 8); - for(unsigned i = 0; i < 4; i++) target_read_checksum |= patch_read() << (i * 8); - uint32_t patch_result_checksum = ~patch_checksum; - source_checksum = ~source_checksum; - target_checksum = ~target_checksum; - for(unsigned i = 0; i < 4; i++) patch_read_checksum |= patch_read() << (i * 8); - - if(patch_result_checksum != patch_read_checksum) return result::patch_invalid; - if(source_checksum == source_read_checksum && source_length == source_read_length) { - if(target_checksum == target_read_checksum && target_length == target_read_length) return result::success; - return result::target_invalid; - } else if(source_checksum == target_read_checksum && source_length == target_read_length) { - if(target_checksum == source_read_checksum && target_length == source_read_length) return result::success; - return result::target_invalid; - } else { - return result::source_invalid; - } - } - -private: - uint8_t *patch_data, *source_data, *target_data; - unsigned patch_length, source_length, target_length; - unsigned patch_offset, source_offset, target_offset; - unsigned patch_checksum, source_checksum, target_checksum; - file patch_file; - - uint8_t patch_read() { - if(patch_offset < patch_length) { - uint8_t n = patch_data[patch_offset++]; - patch_checksum = crc32_adjust(patch_checksum, n); + private: + file fp; + uint32_t crc32; + const uint8_t *p_buffer; + + uint8_t read() { + uint8_t n = *p_buffer++; + crc32 = crc32_adjust(crc32, n); return n; } - return 0x00; - } - uint8_t source_read() { - if(source_offset < source_length) { - uint8_t n = source_data[source_offset++]; - source_checksum = crc32_adjust(source_checksum, n); - return n; + void write(uint8_t n) { + fp.write(n); + crc32 = crc32_adjust(crc32, n); } - return 0x00; - } - uint8_t target_read() { - uint8_t result = 0x00; - if(target_offset < target_length) { - result = target_data[target_offset]; - target_checksum = crc32_adjust(target_checksum, result); - } - if(((target_offset++ & 255) == 0) && progress) { - progress(target_offset, source_length > target_length ? source_length : target_length); - } - return result; - } - - void patch_write(uint8_t n) { - patch_file.write(n); - patch_checksum = crc32_adjust(patch_checksum, n); - } - - void target_write(uint8_t n) { - if(target_offset < target_length) { - target_data[target_offset] = n; - target_checksum = crc32_adjust(target_checksum, n); - } - if(((target_offset++ & 255) == 0) && progress) { - progress(target_offset, source_length > target_length ? source_length : target_length); - } - } - - void encode(uint64_t offset) { - while(true) { - uint64_t x = offset & 0x7f; - offset >>= 7; - if(offset == 0) { - patch_write(0x80 | x); - break; + void encptr(uint64_t offset) { + while(true) { + uint64_t x = offset & 0x7f; + offset >>= 7; + if(offset == 0) { + write(0x80 | x); + break; + } + write(x); + offset--; } - patch_write(x); - offset--; } - } - - uint64_t decode() { - uint64_t offset = 0, shift = 1; - while(true) { - uint8_t x = patch_read(); - offset += (x & 0x7f) * shift; - if(x & 0x80) break; - shift <<= 7; - offset += shift; - } - return offset; - } -}; + uint64_t decptr() { + uint64_t offset = 0, shift = 1; + while(true) { + uint8_t x = read(); + offset += (x & 0x7f) * shift; + if(x & 0x80) break; + shift <<= 7; + offset += shift; + } + return offset; + } + }; } #endif diff -Nru bsnes-0.073/snesfilter/nall/utf8.hpp bsnes-0.073/snesfilter/nall/utf8.hpp --- bsnes-0.073/snesfilter/nall/utf8.hpp 2010-10-26 02:36:26.000000000 +0000 +++ bsnes-0.073/snesfilter/nall/utf8.hpp 2009-10-13 03:24:18.000000000 +0000 @@ -6,11 +6,9 @@ #if defined(_WIN32) -#undef UNICODE #undef _WIN32_WINNT -#undef NOMINMAX -#define UNICODE #define _WIN32_WINNT 0x0501 +#undef NOMINMAX #define NOMINMAX #include #undef interface @@ -64,21 +62,9 @@ delete[] buffer; } - utf8_t(const utf8_t&) = delete; - utf8_t& operator=(const utf8_t&) = delete; - private: char *buffer; }; - - inline void utf8_args(int &argc, char **&argv) { - wchar_t **wargv = CommandLineToArgvW(GetCommandLineW(), &argc); - argv = new char*[argc]; - for(unsigned i = 0; i < argc; i++) { - argv[i] = new char[_MAX_PATH]; - strcpy(argv[i], nall::utf8_t(wargv[i])); - } - } } #endif //if defined(_WIN32) diff -Nru bsnes-0.073/snesfilter/nall/varint.hpp bsnes-0.073/snesfilter/nall/varint.hpp --- bsnes-0.073/snesfilter/nall/varint.hpp 2010-10-26 02:36:26.000000000 +0000 +++ bsnes-0.073/snesfilter/nall/varint.hpp 2009-01-10 17:38:13.000000000 +0000 @@ -1,9 +1,9 @@ #ifndef NALL_VARINT_HPP #define NALL_VARINT_HPP -#include #include #include +#include namespace nall { template class uint_t { @@ -22,7 +22,7 @@ >::type >::type >::type T; - static_assert(!std::is_same::value, ""); + static_assert::value> uint_assert; T data; public: @@ -63,7 +63,7 @@ >::type >::type >::type T; - static_assert(!std::is_same::value, ""); + static_assert::value> int_assert; T data; public: diff -Nru bsnes-0.073/snesfilter/ntsc/ntsc-composite.cpp bsnes-0.073/snesfilter/ntsc/ntsc-composite.cpp --- bsnes-0.073/snesfilter/ntsc/ntsc-composite.cpp 2010-10-26 03:54:56.000000000 +0000 +++ bsnes-0.073/snesfilter/ntsc/ntsc-composite.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,63 +0,0 @@ -#include -#include -using namespace nall; - -uint32_t *colortable; - -#include "snes_ntsc/snes_ntsc.h" -#include "snes_ntsc/snes_ntsc.c" - -extern "C" { - void filter_size(unsigned&, unsigned&); - void filter_render(uint32_t*, uint32_t*, unsigned, const uint16_t*, unsigned, unsigned, unsigned); -}; - - -struct snes_ntsc_t *ntsc; -snes_ntsc_setup_t setup; -int burst; -int burst_toggle; - -void initialize() { - static bool initialized = false; - if(initialized == true) return; - initialized = true; - - ntsc = (snes_ntsc_t*)malloc(sizeof *ntsc); - setup = snes_ntsc_composite; - setup.merge_fields = 1; - snes_ntsc_init(ntsc, &setup); - - burst = 0; - burst_toggle = (setup.merge_fields ? 0 : 1); -} - -void terminate() { - if(ntsc) free(ntsc); -} - -dllexport void filter_size(unsigned &width, unsigned &height) { - initialize(); - width = SNES_NTSC_OUT_WIDTH(256); - height = height; -} - -dllexport void filter_render( - uint32_t *colortable_, uint32_t *output, unsigned outpitch, - const uint16_t *input, unsigned pitch, unsigned width, unsigned height -) { - initialize(); - if(!ntsc) return; - colortable = colortable_; - - pitch >>= 1; - outpitch >>= 2; - - if(width <= 256) { - snes_ntsc_blit (ntsc, input, pitch, burst, width, height, output, outpitch << 2); - } else { - snes_ntsc_blit_hires(ntsc, input, pitch, burst, width, height, output, outpitch << 2); - } - - burst ^= burst_toggle; -} diff -Nru bsnes-0.073/snesfilter/ntsc/ntsc.cpp bsnes-0.073/snesfilter/ntsc/ntsc.cpp --- bsnes-0.073/snesfilter/ntsc/ntsc.cpp 1970-01-01 00:00:00.000000000 +0000 +++ bsnes-0.073/snesfilter/ntsc/ntsc.cpp 2010-04-14 05:06:52.000000000 +0000 @@ -0,0 +1,380 @@ +#include "snes_ntsc/snes_ntsc.h" +#include "snes_ntsc/snes_ntsc.c" + +#include "ntsc.moc.hpp" +#include "ntsc.moc" + +void NTSCFilter::bind(configuration &config) { + config.attach(hue = 0.0, "snesfilter.ntsc.hue"); + config.attach(saturation = 0.0, "snesfilter.ntsc.saturation"); + config.attach(contrast = 0.0, "snesfilter.ntsc.contrast"); + config.attach(brightness = 0.0, "snesfilter.ntsc.brightness"); + config.attach(sharpness = 0.0, "snesfilter.ntsc.sharpness"); + config.attach(gamma = 0.0, "snesfilter.ntsc.gamma"); + config.attach(resolution = 0.0, "snesfilter.ntsc.resolution"); + config.attach(artifacts = 0.0, "snesfilter.ntsc.artifacts"); + config.attach(fringing = 0.0, "snesfilter.ntsc.fringing"); + config.attach(bleed = 0.0, "snesfilter.ntsc.bleed"); + config.attach(mergeFields = true, "snesfilter.ntsc.mergeFields"); +} + +void NTSCFilter::size(unsigned &outwidth, unsigned &outheight, unsigned width, unsigned height) { + outwidth = SNES_NTSC_OUT_WIDTH(256); + outheight = height; +} + +void NTSCFilter::render( + uint32_t *output, unsigned outpitch, + const uint16_t *input, unsigned pitch, unsigned width, unsigned height +) { + if(!ntsc) return; + + pitch >>= 1; + outpitch >>= 2; + + if(width <= 256) { + snes_ntsc_blit (ntsc, input, pitch, burst, width, height, output, outpitch << 2); + } else { + snes_ntsc_blit_hires(ntsc, input, pitch, burst, width, height, output, outpitch << 2); + } + + burst ^= burst_toggle; +} + +QWidget* NTSCFilter::settings() { + if(!widget) { + widget = new QWidget; + widget->setWindowTitle("NTSC Filter Configuration"); + + layout = new QVBoxLayout; + layout->setAlignment(Qt::AlignTop); + widget->setLayout(layout); + + gridLayout = new QGridLayout; + layout->addLayout(gridLayout); + + basicSettings = new QLabel("Basic settings:"); + gridLayout->addWidget(basicSettings, 0, 0, 1, 3); + + hueLabel = new QLabel("Hue:"); + gridLayout->addWidget(hueLabel, 1, 0); + + hueValue = new QLabel; + hueValue->setMinimumWidth(hueValue->fontMetrics().width("-100.0")); + hueValue->setAlignment(Qt::AlignHCenter); + gridLayout->addWidget(hueValue, 1, 1); + + hueSlider = new QSlider(Qt::Horizontal); + hueSlider->setMinimum(-100); + hueSlider->setMaximum(+100); + gridLayout->addWidget(hueSlider, 1, 2); + + saturationLabel = new QLabel("Saturation:"); + gridLayout->addWidget(saturationLabel, 2, 0); + + saturationValue = new QLabel; + saturationValue->setAlignment(Qt::AlignHCenter); + gridLayout->addWidget(saturationValue, 2, 1); + + saturationSlider = new QSlider(Qt::Horizontal); + saturationSlider->setMinimum(-100); + saturationSlider->setMaximum(+100); + gridLayout->addWidget(saturationSlider, 2, 2); + + contrastLabel = new QLabel("Contrast:"); + gridLayout->addWidget(contrastLabel, 3, 0); + + contrastValue = new QLabel; + contrastValue->setAlignment(Qt::AlignHCenter); + gridLayout->addWidget(contrastValue, 3, 1); + + contrastSlider = new QSlider(Qt::Horizontal); + contrastSlider->setMinimum(-100); + contrastSlider->setMaximum(+100); + gridLayout->addWidget(contrastSlider, 3, 2); + + brightnessLabel = new QLabel("Brightness:"); + gridLayout->addWidget(brightnessLabel, 4, 0); + + brightnessValue = new QLabel; + brightnessValue->setAlignment(Qt::AlignHCenter); + gridLayout->addWidget(brightnessValue, 4, 1); + + brightnessSlider = new QSlider(Qt::Horizontal); + brightnessSlider->setMinimum(-100); + brightnessSlider->setMaximum(+100); + gridLayout->addWidget(brightnessSlider, 4, 2); + + sharpnessLabel = new QLabel("Sharpness:"); + gridLayout->addWidget(sharpnessLabel, 5, 0); + + sharpnessValue = new QLabel; + sharpnessValue->setAlignment(Qt::AlignHCenter); + gridLayout->addWidget(sharpnessValue, 5, 1); + + sharpnessSlider = new QSlider(Qt::Horizontal); + sharpnessSlider->setMinimum(-100); + sharpnessSlider->setMaximum(+100); + gridLayout->addWidget(sharpnessSlider, 5, 2); + + advancedSettings = new QLabel("Advanced settings:"); + gridLayout->addWidget(advancedSettings, 6, 0, 1, 3); + + gammaLabel = new QLabel("Gamma:"); + gridLayout->addWidget(gammaLabel, 7, 0); + + gammaValue = new QLabel; + gammaValue->setAlignment(Qt::AlignHCenter); + gridLayout->addWidget(gammaValue, 7, 1); + + gammaSlider = new QSlider(Qt::Horizontal); + gammaSlider->setMinimum(-100); + gammaSlider->setMaximum(+100); + gridLayout->addWidget(gammaSlider, 7, 2); + + resolutionLabel = new QLabel("Resolution:"); + gridLayout->addWidget(resolutionLabel, 8, 0); + + resolutionValue = new QLabel; + resolutionValue->setAlignment(Qt::AlignHCenter); + gridLayout->addWidget(resolutionValue, 8, 1); + + resolutionSlider = new QSlider(Qt::Horizontal); + resolutionSlider->setMinimum(-100); + resolutionSlider->setMaximum(+100); + gridLayout->addWidget(resolutionSlider, 8, 2); + + artifactsLabel = new QLabel("Artifacts:"); + gridLayout->addWidget(artifactsLabel, 9, 0); + + artifactsValue = new QLabel; + artifactsValue->setAlignment(Qt::AlignHCenter); + gridLayout->addWidget(artifactsValue, 9, 1); + + artifactsSlider = new QSlider(Qt::Horizontal); + artifactsSlider->setMinimum(-100); + artifactsSlider->setMaximum(+100); + gridLayout->addWidget(artifactsSlider, 9, 2); + + fringingLabel = new QLabel("Fringing:"); + gridLayout->addWidget(fringingLabel, 10, 0); + + fringingValue = new QLabel; + fringingValue->setAlignment(Qt::AlignHCenter); + gridLayout->addWidget(fringingValue, 10, 1); + + fringingSlider = new QSlider(Qt::Horizontal); + fringingSlider->setMinimum(-100); + fringingSlider->setMaximum(+100); + gridLayout->addWidget(fringingSlider, 10, 2); + + bleedLabel = new QLabel("Color bleed:"); + gridLayout->addWidget(bleedLabel, 11, 0); + + bleedValue = new QLabel; + bleedValue->setAlignment(Qt::AlignHCenter); + gridLayout->addWidget(bleedValue, 11, 1); + + bleedSlider = new QSlider(Qt::Horizontal); + bleedSlider->setMinimum(-100); + bleedSlider->setMaximum(+100); + gridLayout->addWidget(bleedSlider, 11, 2); + + mergeFieldsBox = new QCheckBox("Merge even and odd fields to reduce flicker"); + gridLayout->addWidget(mergeFieldsBox, 12, 0, 1, 3); + + presets = new QLabel("Presets:"); + gridLayout->addWidget(presets, 13, 0, 1, 3); + + controlLayout = new QHBoxLayout; + layout->addLayout(controlLayout); + + rfPreset = new QPushButton("RF"); + controlLayout->addWidget(rfPreset); + + compositePreset = new QPushButton("Composite"); + controlLayout->addWidget(compositePreset); + + svideoPreset = new QPushButton("S-Video"); + controlLayout->addWidget(svideoPreset); + + rgbPreset = new QPushButton("RGB"); + controlLayout->addWidget(rgbPreset); + + monoPreset = new QPushButton("Monochrome"); + controlLayout->addWidget(monoPreset); + + spacer = new QWidget; + spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); + spacer->setMinimumWidth(50); + controlLayout->addWidget(spacer); + + ok = new QPushButton("Ok"); + controlLayout->addWidget(ok); + + blockSignals = true; + loadSettingsFromConfig(); + syncUiToSettings(); + initialize(); + + connect(hueSlider, SIGNAL(valueChanged(int)), this, SLOT(syncSettingsToUi())); + connect(saturationSlider, SIGNAL(valueChanged(int)), this, SLOT(syncSettingsToUi())); + connect(contrastSlider, SIGNAL(valueChanged(int)), this, SLOT(syncSettingsToUi())); + connect(brightnessSlider, SIGNAL(valueChanged(int)), this, SLOT(syncSettingsToUi())); + connect(sharpnessSlider, SIGNAL(valueChanged(int)), this, SLOT(syncSettingsToUi())); + connect(gammaSlider, SIGNAL(valueChanged(int)), this, SLOT(syncSettingsToUi())); + connect(resolutionSlider, SIGNAL(valueChanged(int)), this, SLOT(syncSettingsToUi())); + connect(artifactsSlider, SIGNAL(valueChanged(int)), this, SLOT(syncSettingsToUi())); + connect(fringingSlider, SIGNAL(valueChanged(int)), this, SLOT(syncSettingsToUi())); + connect(bleedSlider, SIGNAL(valueChanged(int)), this, SLOT(syncSettingsToUi())); + connect(mergeFieldsBox, SIGNAL(stateChanged(int)), this, SLOT(syncSettingsToUi())); + connect(rfPreset, SIGNAL(released()), this, SLOT(setRfPreset())); + connect(compositePreset, SIGNAL(released()), this, SLOT(setCompositePreset())); + connect(svideoPreset, SIGNAL(released()), this, SLOT(setSvideoPreset())); + connect(rgbPreset, SIGNAL(released()), this, SLOT(setRgbPreset())); + connect(monoPreset, SIGNAL(released()), this, SLOT(setMonoPreset())); + connect(ok, SIGNAL(released()), widget, SLOT(hide())); + + blockSignals = false; + } + + return widget; +} + +void NTSCFilter::initialize() { + burst = 0; + burst_toggle = (setup.merge_fields ? 0 : 1); //don't toggle burst when fields are merged + snes_ntsc_init(ntsc, &setup); +} + +void NTSCFilter::loadSettingsFromConfig() { + setup.hue = hue; + setup.saturation = saturation; + setup.contrast = contrast; + setup.brightness = brightness; + setup.sharpness = sharpness; + + setup.gamma = gamma; + setup.resolution = resolution; + setup.artifacts = artifacts; + setup.fringing = fringing; + setup.bleed = bleed; + + setup.merge_fields = mergeFields; +} + +void NTSCFilter::syncUiToSettings() { + blockSignals = true; + + hue = setup.hue; + saturation = setup.saturation; + contrast = setup.contrast; + brightness = setup.brightness; + sharpness = setup.sharpness; + + gamma = setup.gamma; + resolution = setup.resolution; + artifacts = setup.artifacts; + fringing = setup.fringing; + bleed = setup.bleed; + + mergeFields = setup.merge_fields; + + hueValue->setText(string() << hue); + hueSlider->setSliderPosition(hue * 100); + + saturationValue->setText(string() << saturation); + saturationSlider->setSliderPosition(saturation * 100); + + contrastValue->setText(string() << contrast); + contrastSlider->setSliderPosition(contrast * 100); + + brightnessValue->setText(string() << brightness); + brightnessSlider->setSliderPosition(brightness * 100); + + sharpnessValue->setText(string() << sharpness); + sharpnessSlider->setSliderPosition(sharpness * 100); + + gammaValue->setText(string() << gamma); + gammaSlider->setSliderPosition(gamma * 100); + + resolutionValue->setText(string() << resolution); + resolutionSlider->setSliderPosition(resolution * 100); + + artifactsValue->setText(string() << artifacts); + artifactsSlider->setSliderPosition(artifacts * 100); + + fringingValue->setText(string() << fringing); + fringingSlider->setSliderPosition(fringing * 100); + + bleedValue->setText(string() << bleed); + bleedSlider->setSliderPosition(bleed * 100); + + mergeFieldsBox->setChecked(mergeFields); + + blockSignals = false; +} + +void NTSCFilter::syncSettingsToUi() { + if(blockSignals) return; + + hue = hueSlider->sliderPosition() / 100.0; + saturation = saturationSlider->sliderPosition() / 100.0; + contrast = contrastSlider->sliderPosition() / 100.0; + brightness = brightnessSlider->sliderPosition() / 100.0; + sharpness = sharpnessSlider->sliderPosition() / 100.0; + + gamma = gammaSlider->sliderPosition() / 100.0; + resolution = resolutionSlider->sliderPosition() / 100.0; + artifacts = artifactsSlider->sliderPosition() / 100.0; + fringing = fringingSlider->sliderPosition() / 100.0; + bleed = bleedSlider->sliderPosition() / 100.0; + + mergeFields = mergeFieldsBox->isChecked(); + + loadSettingsFromConfig(); + syncUiToSettings(); + initialize(); +} + +void NTSCFilter::setRfPreset() { + static snes_ntsc_setup_t defaults; + setup = defaults; + syncUiToSettings(); + initialize(); +} + +void NTSCFilter::setCompositePreset() { + setup = snes_ntsc_composite; + syncUiToSettings(); + initialize(); +} + +void NTSCFilter::setSvideoPreset() { + setup = snes_ntsc_svideo; + syncUiToSettings(); + initialize(); +} + +void NTSCFilter::setRgbPreset() { + setup = snes_ntsc_rgb; + syncUiToSettings(); + initialize(); +} + +void NTSCFilter::setMonoPreset() { + setup = snes_ntsc_monochrome; + syncUiToSettings(); + initialize(); +} + +NTSCFilter::NTSCFilter() : widget(0) { + ntsc = (snes_ntsc_t*)malloc(sizeof *ntsc); + static snes_ntsc_setup_t defaults; + setup = defaults; + initialize(); +} + +NTSCFilter::~NTSCFilter() { + if(ntsc) free(ntsc); +} diff -Nru bsnes-0.073/snesfilter/ntsc/ntsc.moc.hpp bsnes-0.073/snesfilter/ntsc/ntsc.moc.hpp --- bsnes-0.073/snesfilter/ntsc/ntsc.moc.hpp 1970-01-01 00:00:00.000000000 +0000 +++ bsnes-0.073/snesfilter/ntsc/ntsc.moc.hpp 2010-04-14 04:49:37.000000000 +0000 @@ -0,0 +1,91 @@ +class NTSCFilter : public QObject { + Q_OBJECT + +public: + void bind(configuration&); + void size(unsigned&, unsigned&, unsigned, unsigned); + void render(uint32_t*, unsigned, const uint16_t*, unsigned, unsigned, unsigned); + QWidget* settings(); + + NTSCFilter(); + ~NTSCFilter(); + +private: + void initialize(); + void loadSettingsFromConfig(); + void syncUiToSettings(); + +private slots: + void syncSettingsToUi(); + void setRfPreset(); + void setCompositePreset(); + void setSvideoPreset(); + void setRgbPreset(); + void setMonoPreset(); + +private: + QWidget *widget; + QVBoxLayout *layout; + QGridLayout *gridLayout; + QLabel *basicSettings; + QLabel *hueLabel; + QLabel *hueValue; + QSlider *hueSlider; + QLabel *saturationLabel; + QLabel *saturationValue; + QSlider *saturationSlider; + QLabel *contrastLabel; + QLabel *contrastValue; + QSlider *contrastSlider; + QLabel *brightnessLabel; + QLabel *brightnessValue; + QSlider *brightnessSlider; + QLabel *sharpnessLabel; + QLabel *sharpnessValue; + QSlider *sharpnessSlider; + QLabel *advancedSettings; + QLabel *gammaLabel; + QLabel *gammaValue; + QSlider *gammaSlider; + QLabel *resolutionLabel; + QLabel *resolutionValue; + QSlider *resolutionSlider; + QLabel *artifactsLabel; + QLabel *artifactsValue; + QSlider *artifactsSlider; + QLabel *fringingLabel; + QLabel *fringingValue; + QSlider *fringingSlider; + QLabel *bleedLabel; + QLabel *bleedValue; + QSlider *bleedSlider; + QCheckBox *mergeFieldsBox; + QLabel *presets; + QHBoxLayout *controlLayout; + QPushButton *rfPreset; + QPushButton *compositePreset; + QPushButton *svideoPreset; + QPushButton *rgbPreset; + QPushButton *monoPreset; + QWidget *spacer; + QPushButton *ok; + + bool blockSignals; + + struct snes_ntsc_t *ntsc; + snes_ntsc_setup_t setup; + int burst, burst_toggle; + + //settings + double hue; + double saturation; + double contrast; + double brightness; + double sharpness; + double gamma; + double resolution; + double artifacts; + double fringing; + double bleed; + bool mergeFields; +} filter_ntsc; diff -Nru bsnes-0.073/snesfilter/ntsc/ntsc-rf.cpp bsnes-0.073/snesfilter/ntsc/ntsc-rf.cpp --- bsnes-0.073/snesfilter/ntsc/ntsc-rf.cpp 2010-10-26 03:53:34.000000000 +0000 +++ bsnes-0.073/snesfilter/ntsc/ntsc-rf.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,63 +0,0 @@ -#include -#include -using namespace nall; - -uint32_t *colortable; - -#include "snes_ntsc/snes_ntsc.h" -#include "snes_ntsc/snes_ntsc.c" - -extern "C" { - void filter_size(unsigned&, unsigned&); - void filter_render(uint32_t*, uint32_t*, unsigned, const uint16_t*, unsigned, unsigned, unsigned); -}; - - -struct snes_ntsc_t *ntsc; -snes_ntsc_setup_t setup; -int burst; -int burst_toggle; - -void initialize() { - static bool initialized = false; - if(initialized == true) return; - initialized = true; - - ntsc = (snes_ntsc_t*)malloc(sizeof *ntsc); - setup = snes_ntsc_composite; - setup.merge_fields = 0; - snes_ntsc_init(ntsc, &setup); - - burst = 0; - burst_toggle = (setup.merge_fields ? 0 : 1); -} - -void terminate() { - if(ntsc) free(ntsc); -} - -dllexport void filter_size(unsigned &width, unsigned &height) { - initialize(); - width = SNES_NTSC_OUT_WIDTH(256); - height = height; -} - -dllexport void filter_render( - uint32_t *colortable_, uint32_t *output, unsigned outpitch, - const uint16_t *input, unsigned pitch, unsigned width, unsigned height -) { - initialize(); - if(!ntsc) return; - colortable = colortable_; - - pitch >>= 1; - outpitch >>= 2; - - if(width <= 256) { - snes_ntsc_blit (ntsc, input, pitch, burst, width, height, output, outpitch << 2); - } else { - snes_ntsc_blit_hires(ntsc, input, pitch, burst, width, height, output, outpitch << 2); - } - - burst ^= burst_toggle; -} diff -Nru bsnes-0.073/snesfilter/ntsc/ntsc-rgb.cpp bsnes-0.073/snesfilter/ntsc/ntsc-rgb.cpp --- bsnes-0.073/snesfilter/ntsc/ntsc-rgb.cpp 2010-10-26 03:55:19.000000000 +0000 +++ bsnes-0.073/snesfilter/ntsc/ntsc-rgb.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,63 +0,0 @@ -#include -#include -using namespace nall; - -uint32_t *colortable; - -#include "snes_ntsc/snes_ntsc.h" -#include "snes_ntsc/snes_ntsc.c" - -extern "C" { - void filter_size(unsigned&, unsigned&); - void filter_render(uint32_t*, uint32_t*, unsigned, const uint16_t*, unsigned, unsigned, unsigned); -}; - - -struct snes_ntsc_t *ntsc; -snes_ntsc_setup_t setup; -int burst; -int burst_toggle; - -void initialize() { - static bool initialized = false; - if(initialized == true) return; - initialized = true; - - ntsc = (snes_ntsc_t*)malloc(sizeof *ntsc); - setup = snes_ntsc_rgb; - setup.merge_fields = 1; - snes_ntsc_init(ntsc, &setup); - - burst = 0; - burst_toggle = (setup.merge_fields ? 0 : 1); -} - -void terminate() { - if(ntsc) free(ntsc); -} - -dllexport void filter_size(unsigned &width, unsigned &height) { - initialize(); - width = SNES_NTSC_OUT_WIDTH(256); - height = height; -} - -dllexport void filter_render( - uint32_t *colortable_, uint32_t *output, unsigned outpitch, - const uint16_t *input, unsigned pitch, unsigned width, unsigned height -) { - initialize(); - if(!ntsc) return; - colortable = colortable_; - - pitch >>= 1; - outpitch >>= 2; - - if(width <= 256) { - snes_ntsc_blit (ntsc, input, pitch, burst, width, height, output, outpitch << 2); - } else { - snes_ntsc_blit_hires(ntsc, input, pitch, burst, width, height, output, outpitch << 2); - } - - burst ^= burst_toggle; -} diff -Nru bsnes-0.073/snesfilter/ntsc/ntsc-svideo.cpp bsnes-0.073/snesfilter/ntsc/ntsc-svideo.cpp --- bsnes-0.073/snesfilter/ntsc/ntsc-svideo.cpp 2010-10-26 03:55:10.000000000 +0000 +++ bsnes-0.073/snesfilter/ntsc/ntsc-svideo.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,63 +0,0 @@ -#include -#include -using namespace nall; - -uint32_t *colortable; - -#include "snes_ntsc/snes_ntsc.h" -#include "snes_ntsc/snes_ntsc.c" - -extern "C" { - void filter_size(unsigned&, unsigned&); - void filter_render(uint32_t*, uint32_t*, unsigned, const uint16_t*, unsigned, unsigned, unsigned); -}; - - -struct snes_ntsc_t *ntsc; -snes_ntsc_setup_t setup; -int burst; -int burst_toggle; - -void initialize() { - static bool initialized = false; - if(initialized == true) return; - initialized = true; - - ntsc = (snes_ntsc_t*)malloc(sizeof *ntsc); - setup = snes_ntsc_svideo; - setup.merge_fields = 1; - snes_ntsc_init(ntsc, &setup); - - burst = 0; - burst_toggle = (setup.merge_fields ? 0 : 1); -} - -void terminate() { - if(ntsc) free(ntsc); -} - -dllexport void filter_size(unsigned &width, unsigned &height) { - initialize(); - width = SNES_NTSC_OUT_WIDTH(256); - height = height; -} - -dllexport void filter_render( - uint32_t *colortable_, uint32_t *output, unsigned outpitch, - const uint16_t *input, unsigned pitch, unsigned width, unsigned height -) { - initialize(); - if(!ntsc) return; - colortable = colortable_; - - pitch >>= 1; - outpitch >>= 2; - - if(width <= 256) { - snes_ntsc_blit (ntsc, input, pitch, burst, width, height, output, outpitch << 2); - } else { - snes_ntsc_blit_hires(ntsc, input, pitch, burst, width, height, output, outpitch << 2); - } - - burst ^= burst_toggle; -} diff -Nru bsnes-0.073/snesfilter/pixellate2x/pixellate2x.cpp bsnes-0.073/snesfilter/pixellate2x/pixellate2x.cpp --- bsnes-0.073/snesfilter/pixellate2x/pixellate2x.cpp 2010-10-26 05:09:36.000000000 +0000 +++ bsnes-0.073/snesfilter/pixellate2x/pixellate2x.cpp 2010-04-14 04:40:06.000000000 +0000 @@ -1,19 +1,12 @@ -#include -#include -using namespace nall; - -extern "C" { - void filter_size(unsigned&, unsigned&); - void filter_render(uint32_t*, uint32_t*, unsigned, const uint16_t*, unsigned, unsigned, unsigned); -}; - -dllexport void filter_size(unsigned &width, unsigned &height) { - width = (width <= 256) ? width * 2 : width; - height = (height <= 240) ? height * 2 : height; +#include "pixellate2x.hpp" + +void Pixellate2xFilter::size(unsigned &outwidth, unsigned &outheight, unsigned width, unsigned height) { + outwidth = (width <= 256) ? width * 2 : width; + outheight = (height <= 240) ? height * 2 : height; } -dllexport void filter_render( - uint32_t *colortable, uint32_t *output, unsigned outpitch, +void Pixellate2xFilter::render( + uint32_t *output, unsigned outpitch, const uint16_t *input, unsigned pitch, unsigned width, unsigned height ) { pitch >>= 1; diff -Nru bsnes-0.073/snesfilter/pixellate2x/pixellate2x.hpp bsnes-0.073/snesfilter/pixellate2x/pixellate2x.hpp --- bsnes-0.073/snesfilter/pixellate2x/pixellate2x.hpp 1970-01-01 00:00:00.000000000 +0000 +++ bsnes-0.073/snesfilter/pixellate2x/pixellate2x.hpp 2010-04-14 04:39:00.000000000 +0000 @@ -0,0 +1,5 @@ +class Pixellate2xFilter { +public: + void size(unsigned&, unsigned&, unsigned, unsigned); + void render(uint32_t*, unsigned, const uint16_t*, unsigned, unsigned, unsigned); +} filter_pixellate2x; diff -Nru bsnes-0.073/snesfilter/scale2x/scale2x.cpp bsnes-0.073/snesfilter/scale2x/scale2x.cpp --- bsnes-0.073/snesfilter/scale2x/scale2x.cpp 2010-10-26 02:51:58.000000000 +0000 +++ bsnes-0.073/snesfilter/scale2x/scale2x.cpp 2010-04-14 04:58:50.000000000 +0000 @@ -1,21 +1,20 @@ -#include -#include -using namespace nall; - -extern "C" { - void filter_size(unsigned&, unsigned&); - void filter_render(uint32_t*, uint32_t*, unsigned, const uint16_t*, unsigned, unsigned, unsigned); -}; - -dllexport void filter_size(unsigned &width, unsigned &height) { - width *= 2; - height *= 2; +#include "scale2x.hpp" + +void Scale2xFilter::size(unsigned &outwidth, unsigned &outheight, unsigned width, unsigned height) { + if(width > 256 || height > 240) return filter_direct.size(outwidth, outheight, width, height); + outwidth = width * 2; + outheight = height * 2; } -dllexport void filter_render( - uint32_t *colortable, uint32_t *output, unsigned outpitch, +void Scale2xFilter::render( + uint32_t *output, unsigned outpitch, const uint16_t *input, unsigned pitch, unsigned width, unsigned height ) { + if(width > 256 || height > 240) { + filter_direct.render(output, outpitch, input, pitch, width, height); + return; + } + pitch >>= 1; outpitch >>= 2; @@ -28,9 +27,9 @@ for(unsigned x = 0; x < width; x++) { uint16_t A = *(input - prevline); - uint16_t B = (x > 0) ? *(input - 1) : *input; + uint16_t B = (x > 0) ? *(input - 1) : *input; uint16_t C = *input; - uint16_t D = (x < width - 1) ? *(input + 1) : *input; + uint16_t D = (x < 255) ? *(input + 1) : *input; uint16_t E = *(input++ + nextline); uint32_t c = colortable[C]; @@ -48,7 +47,7 @@ } input += pitch - width; - out0 += outpitch + outpitch - (width << 1); - out1 += outpitch + outpitch - (width << 1); + out0 += outpitch + outpitch - 512; + out1 += outpitch + outpitch - 512; } } diff -Nru bsnes-0.073/snesfilter/scale2x/scale2x.hpp bsnes-0.073/snesfilter/scale2x/scale2x.hpp --- bsnes-0.073/snesfilter/scale2x/scale2x.hpp 1970-01-01 00:00:00.000000000 +0000 +++ bsnes-0.073/snesfilter/scale2x/scale2x.hpp 2010-04-14 04:57:38.000000000 +0000 @@ -0,0 +1,5 @@ +class Scale2xFilter { +public: + void size(unsigned&, unsigned&, unsigned, unsigned); + void render(uint32_t*, unsigned, const uint16_t*, unsigned, unsigned, unsigned); +} filter_scale2x; diff -Nru bsnes-0.073/snesfilter/scanline/scanline-00.cpp bsnes-0.073/snesfilter/scanline/scanline-00.cpp --- bsnes-0.073/snesfilter/scanline/scanline-00.cpp 2010-10-26 05:03:48.000000000 +0000 +++ bsnes-0.073/snesfilter/scanline/scanline-00.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,34 +0,0 @@ -#include -#include -using namespace nall; - -extern "C" { - void filter_size(unsigned&, unsigned&); - void filter_render(uint32_t*, uint32_t*, unsigned, const uint16_t*, unsigned, unsigned, unsigned); -}; - -dllexport void filter_size(unsigned &width, unsigned &height) { - height *= 2; -} - -dllexport void filter_render( - uint32_t *palette, uint32_t *output, unsigned outpitch, - const uint16_t *input, unsigned pitch, unsigned width, unsigned height -) { - pitch >>= 1; - outpitch >>= 2; - - uint32_t *out0 = output; - uint32_t *out1 = output + outpitch; - - for(unsigned y = 0; y < height; y++) { - const uint16_t *in = input + y * pitch; - uint32_t *out0 = output + y * outpitch * 2; - uint32_t *out1 = output + y * outpitch * 2 + outpitch; - - for(unsigned x = 0; x < width; x++) { - *out0++ = palette[*in++]; - *out1++ = 0; - } - } -} diff -Nru bsnes-0.073/snesfilter/scanline/scanline-25.cpp bsnes-0.073/snesfilter/scanline/scanline-25.cpp --- bsnes-0.073/snesfilter/scanline/scanline-25.cpp 2010-10-26 05:02:34.000000000 +0000 +++ bsnes-0.073/snesfilter/scanline/scanline-25.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,55 +0,0 @@ -#include -#include -using namespace nall; - -extern "C" { - void filter_size(unsigned&, unsigned&); - void filter_render(uint32_t*, uint32_t*, unsigned, const uint16_t*, unsigned, unsigned, unsigned); -}; - -uint16_t adjust[32768]; - -void initialize() { - static bool initialized = false; - if(initialized == true) return; - initialized = true; - - for(unsigned i = 0; i < 32768; i++) { - uint8_t r = (i >> 10) & 31; - uint8_t g = (i >> 5) & 31; - uint8_t b = (i >> 0) & 31; - r *= 0.25; - g *= 0.25; - b *= 0.25; - adjust[i] = (r << 10) + (g << 5) + (b << 0); - } -} - -dllexport void filter_size(unsigned &width, unsigned &height) { - initialize(); - height *= 2; -} - -dllexport void filter_render( - uint32_t *palette, uint32_t *output, unsigned outpitch, - const uint16_t *input, unsigned pitch, unsigned width, unsigned height -) { - initialize(); - pitch >>= 1; - outpitch >>= 2; - - uint32_t *out0 = output; - uint32_t *out1 = output + outpitch; - - for(unsigned y = 0; y < height; y++) { - const uint16_t *in = input + y * pitch; - uint32_t *out0 = output + y * outpitch * 2; - uint32_t *out1 = output + y * outpitch * 2 + outpitch; - - for(unsigned x = 0; x < width; x++) { - uint16_t color = *in++; - *out0++ = palette[color]; - *out1++ = palette[adjust[color]]; - } - } -} diff -Nru bsnes-0.073/snesfilter/scanline/scanline-50.cpp bsnes-0.073/snesfilter/scanline/scanline-50.cpp --- bsnes-0.073/snesfilter/scanline/scanline-50.cpp 2010-10-26 05:02:16.000000000 +0000 +++ bsnes-0.073/snesfilter/scanline/scanline-50.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,55 +0,0 @@ -#include -#include -using namespace nall; - -extern "C" { - void filter_size(unsigned&, unsigned&); - void filter_render(uint32_t*, uint32_t*, unsigned, const uint16_t*, unsigned, unsigned, unsigned); -}; - -uint16_t adjust[32768]; - -void initialize() { - static bool initialized = false; - if(initialized == true) return; - initialized = true; - - for(unsigned i = 0; i < 32768; i++) { - uint8_t r = (i >> 10) & 31; - uint8_t g = (i >> 5) & 31; - uint8_t b = (i >> 0) & 31; - r *= 0.50; - g *= 0.50; - b *= 0.50; - adjust[i] = (r << 10) + (g << 5) + (b << 0); - } -} - -dllexport void filter_size(unsigned &width, unsigned &height) { - initialize(); - height *= 2; -} - -dllexport void filter_render( - uint32_t *palette, uint32_t *output, unsigned outpitch, - const uint16_t *input, unsigned pitch, unsigned width, unsigned height -) { - initialize(); - pitch >>= 1; - outpitch >>= 2; - - uint32_t *out0 = output; - uint32_t *out1 = output + outpitch; - - for(unsigned y = 0; y < height; y++) { - const uint16_t *in = input + y * pitch; - uint32_t *out0 = output + y * outpitch * 2; - uint32_t *out1 = output + y * outpitch * 2 + outpitch; - - for(unsigned x = 0; x < width; x++) { - uint16_t color = *in++; - *out0++ = palette[color]; - *out1++ = palette[adjust[color]]; - } - } -} diff -Nru bsnes-0.073/snesfilter/scanline/scanline-75.cpp bsnes-0.073/snesfilter/scanline/scanline-75.cpp --- bsnes-0.073/snesfilter/scanline/scanline-75.cpp 2010-10-26 05:02:51.000000000 +0000 +++ bsnes-0.073/snesfilter/scanline/scanline-75.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,55 +0,0 @@ -#include -#include -using namespace nall; - -extern "C" { - void filter_size(unsigned&, unsigned&); - void filter_render(uint32_t*, uint32_t*, unsigned, const uint16_t*, unsigned, unsigned, unsigned); -}; - -uint16_t adjust[32768]; - -void initialize() { - static bool initialized = false; - if(initialized == true) return; - initialized = true; - - for(unsigned i = 0; i < 32768; i++) { - uint8_t r = (i >> 10) & 31; - uint8_t g = (i >> 5) & 31; - uint8_t b = (i >> 0) & 31; - r *= 0.75; - g *= 0.75; - b *= 0.75; - adjust[i] = (r << 10) + (g << 5) + (b << 0); - } -} - -dllexport void filter_size(unsigned &width, unsigned &height) { - initialize(); - height *= 2; -} - -dllexport void filter_render( - uint32_t *palette, uint32_t *output, unsigned outpitch, - const uint16_t *input, unsigned pitch, unsigned width, unsigned height -) { - initialize(); - pitch >>= 1; - outpitch >>= 2; - - uint32_t *out0 = output; - uint32_t *out1 = output + outpitch; - - for(unsigned y = 0; y < height; y++) { - const uint16_t *in = input + y * pitch; - uint32_t *out0 = output + y * outpitch * 2; - uint32_t *out1 = output + y * outpitch * 2 + outpitch; - - for(unsigned x = 0; x < width; x++) { - uint16_t color = *in++; - *out0++ = palette[color]; - *out1++ = palette[adjust[color]]; - } - } -} diff -Nru bsnes-0.073/snesfilter/snesfilter.cpp bsnes-0.073/snesfilter/snesfilter.cpp --- bsnes-0.073/snesfilter/snesfilter.cpp 1970-01-01 00:00:00.000000000 +0000 +++ bsnes-0.073/snesfilter/snesfilter.cpp 2010-06-06 02:51:18.000000000 +0000 @@ -0,0 +1,83 @@ +#include "snesfilter.hpp" + +#if defined(_WIN32) + #define dllexport __declspec(dllexport) +#else + #define dllexport +#endif + +#include +#include +#include + +#define QT_CORE_LIB +#include + +#include +#include +#include +using namespace nall; + +const uint32_t *colortable; +configuration *config; + +#include "direct/direct.cpp" +#include "pixellate2x/pixellate2x.cpp" +#include "scale2x/scale2x.cpp" +#include "2xsai/2xsai.cpp" +#include "lq2x/lq2x.cpp" +#include "hq2x/hq2x.cpp" +#include "ntsc/ntsc.cpp" + +dllexport const char* snesfilter_supported() { + return "Pixellate2x;Scale2x;2xSaI;Super 2xSaI;Super Eagle;LQ2x;HQ2x;NTSC"; +} + +dllexport void snesfilter_configuration(configuration &config_) { + config = &config_; + if(config) { + filter_ntsc.bind(*config); + } +} + +dllexport void snesfilter_colortable(const uint32_t *colortable_) { + colortable = colortable_; +} + +dllexport void snesfilter_size(unsigned filter, unsigned &outwidth, unsigned &outheight, unsigned width, unsigned height) { + switch(filter) { + default: return filter_direct.size(outwidth, outheight, width, height); + case 1: return filter_pixellate2x.size(outwidth, outheight, width, height); + case 2: return filter_scale2x.size(outwidth, outheight, width, height); + case 3: return filter_2xsai.size(outwidth, outheight, width, height); + case 4: return filter_super2xsai.size(outwidth, outheight, width, height); + case 5: return filter_supereagle.size(outwidth, outheight, width, height); + case 6: return filter_lq2x.size(outwidth, outheight, width, height); + case 7: return filter_hq2x.size(outwidth, outheight, width, height); + case 8: return filter_ntsc.size(outwidth, outheight, width, height); + } +} + +dllexport void snesfilter_render( + unsigned filter, uint32_t *output, unsigned outpitch, + const uint16_t *input, unsigned pitch, unsigned width, unsigned height +) { + switch(filter) { + default: return filter_direct.render(output, outpitch, input, pitch, width, height); + case 1: return filter_pixellate2x.render(output, outpitch, input, pitch, width, height); + case 2: return filter_scale2x.render(output, outpitch, input, pitch, width, height); + case 3: return filter_2xsai.render(output, outpitch, input, pitch, width, height); + case 4: return filter_super2xsai.render(output, outpitch, input, pitch, width, height); + case 5: return filter_supereagle.render(output, outpitch, input, pitch, width, height); + case 6: return filter_lq2x.render(output, outpitch, input, pitch, width, height); + case 7: return filter_hq2x.render(output, outpitch, input, pitch, width, height); + case 8: return filter_ntsc.render(output, outpitch, input, pitch, width, height); + } +} + +dllexport QWidget* snesfilter_settings(unsigned filter) { + switch(filter) { + default: return 0; + case 8: return filter_ntsc.settings(); + } +} diff -Nru bsnes-0.073/snesfilter/snesfilter.hpp bsnes-0.073/snesfilter/snesfilter.hpp --- bsnes-0.073/snesfilter/snesfilter.hpp 1970-01-01 00:00:00.000000000 +0000 +++ bsnes-0.073/snesfilter/snesfilter.hpp 2010-04-14 05:01:49.000000000 +0000 @@ -0,0 +1,12 @@ +#include +class QWidget; +namespace nall { class configuration; } + +extern "C" { + const char* snesfilter_supported(); + void snesfilter_configuration(nall::configuration&); + void snesfilter_colortable(const uint32_t*); + void snesfilter_size(unsigned, unsigned&, unsigned&, unsigned, unsigned); + void snesfilter_render(unsigned, uint32_t*, unsigned, const uint16_t*, unsigned, unsigned, unsigned); + QWidget* snesfilter_settings(unsigned); +} diff -Nru bsnes-0.073/snesfilter/sync.sh bsnes-0.073/snesfilter/sync.sh --- bsnes-0.073/snesfilter/sync.sh 2010-09-11 01:11:09.000000000 +0000 +++ bsnes-0.073/snesfilter/sync.sh 2009-10-14 03:53:21.000000000 +0000 @@ -1,8 +1,2 @@ -synchronize() { - if [ -d ../"$1" ]; then - test -d "$1" && rm -r "$1" - cp -r ../"$1" ./"$1" - fi -} - -synchronize "nall" +rm -r nall +cp -r ../nall ./nall