diff --git a/zsnes/src/.cvsignore b/zsnes/src/.cvsignore index bfeb8395..5717fbf5 100644 --- a/zsnes/src/.cvsignore +++ b/zsnes/src/.cvsignore @@ -1,11 +1,12 @@ -config.log +.gdbinit Makefile aclocal.m4 -config.h -configure config.cache -.gdbinit +config.h +config.log config.status +configure parsegen zsnesd zsnes + diff --git a/zsnes/src/Makefile.in b/zsnes/src/Makefile.in index 1b2665d5..f9430176 100644 --- a/zsnes/src/Makefile.in +++ b/zsnes/src/Makefile.in @@ -115,13 +115,19 @@ ${PSR}: parsegen.cpp ALL: rm -f version.o -tools: minwhite extraext sec-test srccount nreplace +tools: cutrtype extraext minwhite nreplace sec-test srccount + +cutrtype: ${TOOLSOBJ} + @CXX@ @CFLAGS@ -o ${TOOLSDIR}/cutrtype ${TOOLSDIR}/cutrtype.cpp ${TOOLSOBJ} + +extraext: ${TOOLSOBJ} + @CXX@ @CFLAGS@ -o ${TOOLSDIR}/extraext ${TOOLSDIR}/extraext.cpp ${TOOLSOBJ} minwhite: ${TOOLSOBJ} @CXX@ @CFLAGS@ -o ${TOOLSDIR}/minwhite ${TOOLSDIR}/minwhite.cpp ${TOOLSDIR}/fileutil.o -extraext: ${TOOLSOBJ} - @CXX@ @CFLAGS@ -o ${TOOLSDIR}/extraext ${TOOLSDIR}/extraext.cpp ${TOOLSOBJ} +nreplace: ${TOOLSOBJ} + @CXX@ @CFLAGS@ -o ${TOOLSDIR}/nreplace ${TOOLSDIR}/nreplace.cpp ${TOOLSDIR}/fileutil.o sec-test: ${TOOLSOBJ} @CXX@ @CFLAGS@ -o ${TOOLSDIR}/sec-test ${TOOLSDIR}/sec-test.cpp ${TOOLSOBJ} @@ -129,9 +135,6 @@ sec-test: ${TOOLSOBJ} srccount: ${TOOLSOBJ} @CXX@ @CFLAGS@ -o ${TOOLSDIR}/srccount ${TOOLSDIR}/srccount.cpp ${TOOLSDIR}/fileutil.o -nreplace: ${TOOLSOBJ} - @CXX@ @CFLAGS@ -o ${TOOLSDIR}/nreplace ${TOOLSDIR}/nreplace.cpp ${TOOLSDIR}/fileutil.o - cfgload.o: cfgload.c macros.mac cfgparse.o: cfgparse.psr endmem.o: endmem.asm macros.mac @@ -140,7 +143,7 @@ initc.o: initc.c ${CPUDIR}/memtable.h ${JMADIR}/zsnesjma.h patch.o: patch.c ui.o: ui.asm macros.mac uic.o: uic.c -vcache.o:vcache.asm macros.mac +vcache.o: vcache.asm macros.mac version.o: version.c zloader.o: zloader.c zmovie.o: zmovie.c diff --git a/zsnes/src/tools/.cvsignore b/zsnes/src/tools/.cvsignore new file mode 100755 index 00000000..2dc425ef --- /dev/null +++ b/zsnes/src/tools/.cvsignore @@ -0,0 +1,6 @@ +cutrtype +extraext +minwhite +nreplace +sec-test +srccount diff --git a/zsnes/src/tools/compile.txt b/zsnes/src/tools/compile.txt index 3f6d3cb7..3eead28b 100644 --- a/zsnes/src/tools/compile.txt +++ b/zsnes/src/tools/compile.txt @@ -6,22 +6,24 @@ g++ -Wall -O3 -o fileutil.o -c fileutil.cpp g++ -Wall -O3 -o strutil.o -c strutil.cpp -Minimize Whitespace: -g++ -Wall -O3 -o minwhite.exe minwhite.cpp fileutil.o +Cut Redundant ASM Typecasts: +g++ -Wall -O3 -o cutrtype.exe cutrtype.cpp fileutil.o strutil.o Extra EXTSYMs: g++ -Wall -O3 -o extraext.exe extraext.cpp fileutil.o strutil.o +Minimize Whitespace: +g++ -Wall -O3 -o minwhite.exe minwhite.cpp fileutil.o + +Nach's Replacer: +g++ -Wall -O3 -o nreplace.exe nreplace.cpp fileutil.o + Section Tester: g++ -Wall -O3 -o sec-test.exe sec-test.cpp fileutil.o strutil.o Source Counter: g++ -Wall -O3 -o srccount.exe srccount.cpp fileutil.o - -Nach's Replacer: -g++ -Wall -O3 -o nreplace.exe nreplace.cpp fileutil.o - All the tools scan every compatible file they find from the directory they are in. It also scans all sub directories recursively. diff --git a/zsnes/src/tools/cutrtype.cpp b/zsnes/src/tools/cutrtype.cpp new file mode 100755 index 00000000..6c8a46bb --- /dev/null +++ b/zsnes/src/tools/cutrtype.cpp @@ -0,0 +1,158 @@ +/* +Copyright (C) 2005 Nach, grinvader ( http://www.zsnes.com ) + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either +version 2 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +/* +This is part of a toolkit used to assist in ZSNES development + +This program removes redundant typecasting in reg<->memory transfers +*/ + +#include +#include +using namespace std; + +#include "fileutil.h" +#include "strutil.h" + +#define LINE_LENGTH 2048 + +static unsigned char getsize(const string& token, const char mode) +{ + unsigned char val = 0; + + if (mode == 'r') + { + val = 0; + + if (token == "al" || token == "ah" || token == "bl" || token == "bh" || + token == "cl" || token == "ch" || token == "dl" || token == "dh" || + token == "di" || token == "si" || token == "bp") + { val = 1; } + else if (token == "ax" || token == "bx" || token == "cx" || token == "dx") + { val = 2; } + else if (token == "eax" || token == "ebx" || token == "ecx" || + token == "edx" || token == "edi" || token == "esi" || + token == "ebp") + { val = 4; } + } + + if (mode == 't') + { + val = 0xFF; + + if (token == "byte") { val = 1; } + if (token == "word") { val = 2; } + if (token == "dword") { val = 4; } + } + + return (val); +} + +static bool isredund(string& cheese, const vector& wine, const char bread) +{ + if (getsize(wine[bread],'t') == getsize(wine[(bread+2)%3], 'r')) + { + size_t loc = cheese.find(wine[bread]); + cheese.erase(loc, cheese.find(wine[bread+1])-loc-1); + return (true); // how are you gentlemen ? + } + + return (false); +} + +void handle_file(const char *filename, size_t orig_fsize) +{ + bool modify_file = false; + vector file_buffer; + + ifstream file(filename, ios::in); + if (file) + { + char line[LINE_LENGTH]; + + while (file.getline(line, LINE_LENGTH)) + { + vector tokens; + string mline(line); + char *p = line; + while (isspace(*p)) { p++; } + + if (!strncasecmp(p, "mov ", strlen("mov "))) + { + p += strlen("mov "); + while (isspace(*p)) { p++; } + Tokenize(p, tokens, ";"); + string not_commented = tokens[0]; + tokens.clear(); + Tokenize(not_commented, tokens, ", []"); + + if (tokens.size()>2) + { + modify_file |= isredund(mline, tokens, 0) || + isredund(mline, tokens, 1); + } + } + + file_buffer.push_back(mline); + } + + file.close(); + } + else + { + cerr << "Could not open " << filename << "." << endl; + } + + if (modify_file) + { + ofstream file(filename, ios::out); + if (file) + { + for (vector::iterator i = file_buffer.begin(); i != file_buffer.end(); i++) + { + file.write(i->data(), i->length()); + file << "\n"; + } + size_t cur_fsize = file.tellp(); + file.close(); + cout << "Trimmed " << filename << " of " << orig_fsize-cur_fsize + << " bytes." << endl; + } + else + { + cerr << filename + << " has redundant typecasts, but a trimmed copy can't be saved." + << endl; + } + } +} + +void cut_redund(const char *filename, struct stat& stat_buffer) +{ + if (is_asm_file(filename)) + { + handle_file(filename, stat_buffer.st_size); + } +} + +int main() +{ + parse_dir(".", cut_redund); + return(0); +}