diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..412eeda --- /dev/null +++ b/.gitattributes @@ -0,0 +1,22 @@ +# Auto detect text files and perform LF normalization +* text=auto + +# Custom for Visual Studio +*.cs diff=csharp +*.sln merge=union +*.csproj merge=union +*.vbproj merge=union +*.fsproj merge=union +*.dbproj merge=union + +# Standard to msysgit +*.doc diff=astextplain +*.DOC diff=astextplain +*.docx diff=astextplain +*.DOCX diff=astextplain +*.dot diff=astextplain +*.DOT diff=astextplain +*.pdf diff=astextplain +*.PDF diff=astextplain +*.rtf diff=astextplain +*.RTF diff=astextplain diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fc6ddd7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,219 @@ +*.bin +*.exe +*.o + +################# +## Eclipse +################# + +*.pydevproject +.project +.metadata +bin/ +tmp/ +*.tmp +*.bak +*.swp +*~.nib +local.properties +.classpath +.settings/ +.loadpath + +# External tool builders +.externalToolBuilders/ + +# Locally stored "Eclipse launch configurations" +*.launch + +# CDT-specific +.cproject + +# PDT-specific +.buildpath + + +################# +## Visual Studio +################# + +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.sln.docstates + +# Build results + +[Dd]ebug/ +[Rr]elease/ +x64/ +build/ +[Bb]in/ +[Oo]bj/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +*_i.c +*_p.c +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.log +*.scc + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opensdf +*.sdf +*.cachefile + +# Visual Studio profiler +*.psess +*.vsp +*.vspx + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +*.ncrunch* +.*crunch*.local.xml + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.Publish.xml +*.pubxml + +# NuGet Packages Directory +## TODO: If you have NuGet Package Restore enabled, uncomment the next line +#packages/ + +# Windows Azure Build Output +csx +*.build.csdef + +# Windows Store app package directory +AppPackages/ + +# Others +sql/ +*.Cache +ClientBin/ +[Ss]tyle[Cc]op.* +~$* +*~ +*.dbmdl +*.[Pp]ublish.xml +*.pfx +*.publishsettings + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file to a newer +# Visual Studio version. Backup files are not needed, because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +App_Data/*.mdf +App_Data/*.ldf + +############# +## Windows detritus +############# + +# Windows image file caches +Thumbs.db +ehthumbs.db + +# Folder config file +Desktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Mac crap +.DS_Store + + +############# +## Python +############# + +*.py[co] + +# Packages +*.egg +*.egg-info +dist/ +build/ +eggs/ +parts/ +var/ +sdist/ +develop-eggs/ +.installed.cfg + +# Installer logs +pip-log.txt + +# Unit test / coverage reports +.coverage +.tox + +#Translations +*.mo + +#Mr Developer +.mr.developer.cfg diff --git a/README.md b/README.md deleted file mode 100644 index 7b62402..0000000 --- a/README.md +++ /dev/null @@ -1,4 +0,0 @@ -exhal -===== - -Compression and decompression tools for NES, SNES, and Game Boy games by HAL Laboratory diff --git a/README.txt b/README.txt index 3104868..3ea045e 100644 --- a/README.txt +++ b/README.txt @@ -81,4 +81,5 @@ Special thanks to: - andlabs for helping me make the list of supported games - BMF54123 for naming the programs + - Tiiffi for misc. Mac OS X build fixes - You for downloading (and using?) my software \ No newline at end of file diff --git a/compress.c b/compress.c index 4e77bb8..2d24f2a 100644 --- a/compress.c +++ b/compress.c @@ -3,10 +3,11 @@ by Devin Acker This code is released under the terms of the MIT license. - See copying.txt for details. + See COPYING.txt for details. */ #include +#include #include "compress.h" #ifdef DEBUG_OUT @@ -121,27 +122,28 @@ size_t unpack(uint8_t *packed, uint8_t *unpacked) { switch (command) { // write uncompressed bytes case 0: - for (int i = 0; i < length; i++) - unpacked[outpos++] = packed[inpos++]; + memcpy(&unpacked[outpos], &packed[inpos], length); + outpos += length; + inpos += length; break; // 8-bit RLE case 1: - for (int i = 0; i < length; i++) - unpacked[outpos++] = packed[inpos]; + unpacked[outpos] = packed[inpos++]; + memcpy(&unpacked[outpos + 1], &unpacked[outpos], length - 1); - inpos++; + outpos += length; break; // 16-bit RLE case 2: - for (int i = 0; i < length; i++) { - unpacked[outpos++] = packed[inpos]; - unpacked[outpos++] = packed[inpos+1]; - } + unpacked[outpos] = packed[inpos]; + unpacked[outpos + 1] = packed[inpos + 1]; + memcpy(&unpacked[outpos + 2], &unpacked[outpos], 2 * (length - 1)); - inpos += 2; + outpos += (length * 2); + inpos += 2; break; // 8-bit increasing sequence @@ -156,13 +158,16 @@ size_t unpack(uint8_t *packed, uint8_t *unpacked) { // (offset is big-endian) case 4: case 7: + // 7 isn't a real method number, but it behaves the same as 4 due to a quirk in how + // the original decompression routine is programmed. (one of Parasyte's docs confirms + // this for GB games as well). let's handle it anyway command = 4; offset = (packed[inpos] << 8) | packed[inpos+1]; - for (int i = 0; i < length; i++) - unpacked[outpos++] = unpacked[offset + i]; + memcpy(&unpacked[outpos], &unpacked[offset], length); - inpos += 2; + outpos += length; + inpos += 2; break; // backref with bit rotation @@ -241,7 +246,7 @@ rle_t rle_check (uint8_t *start, uint8_t *current, uint32_t insize, int fast) { if (current[size] != current[0]) break; // if this is better than the current candidate, use it - if (size > LONG_RUN_SIZE) size = LONG_RUN_SIZE; + //if (size > LONG_RUN_SIZE) size = LONG_RUN_SIZE; if (size > 2 && size > candidate.size) { candidate.size = size; @@ -259,7 +264,7 @@ rle_t rle_check (uint8_t *start, uint8_t *current, uint32_t insize, int fast) { } // if this is better than the current candidate, use it - if (size > LONG_RUN_SIZE) size = LONG_RUN_SIZE; + //if (size > LONG_RUN_SIZE) size = LONG_RUN_SIZE; if (size > 2 && size > candidate.size) { candidate.size = size; @@ -277,7 +282,7 @@ rle_t rle_check (uint8_t *start, uint8_t *current, uint32_t insize, int fast) { if (current[size] != (current[0] + size)) break; // if this is better than the current candidate, use it - if (size > LONG_RUN_SIZE) size = LONG_RUN_SIZE; + //if (size > LONG_RUN_SIZE) size = LONG_RUN_SIZE; if (size > 2 && size > candidate.size) { candidate.size = size; @@ -304,7 +309,7 @@ backref_t ref_search (uint8_t *start, uint8_t *current, uint32_t insize, int fas if (pos[size] != current[size]) break; // if this is better than the current candidate, use it - if (size > LONG_RUN_SIZE) size = LONG_RUN_SIZE; + //if (size > LONG_RUN_SIZE) size = LONG_RUN_SIZE; if (size > 3 && size > candidate.size) { candidate.size = size; @@ -322,7 +327,7 @@ backref_t ref_search (uint8_t *start, uint8_t *current, uint32_t insize, int fas if (pos[size] != rotate(current[size])) break; // if this is better than the current candidate, use it - if (size > LONG_RUN_SIZE) size = LONG_RUN_SIZE; + //if (size > LONG_RUN_SIZE) size = LONG_RUN_SIZE; if (size > 3 && size > candidate.size) { candidate.size = size; @@ -337,7 +342,7 @@ backref_t ref_search (uint8_t *start, uint8_t *current, uint32_t insize, int fas if (start[pos - start - size] != current[size]) break; // if this is better than the current candidate, use it - if (size > LONG_RUN_SIZE) size = LONG_RUN_SIZE; + //if (size > LONG_RUN_SIZE) size = LONG_RUN_SIZE; if (size > 3 && size > candidate.size) { candidate.size = size; @@ -456,8 +461,7 @@ uint16_t write_raw (uint8_t *out, uint16_t outpos, uint8_t *in, uint16_t insize) } // write data - for (int i = 0; i < insize; i++) - out[outpos++] = in[i]; - + memcpy(&out[outpos], in, insize); + return outsize; } diff --git a/compress.h b/compress.h index 7825036..504625e 100644 --- a/compress.h +++ b/compress.h @@ -3,7 +3,7 @@ by Devin Acker This code is released under the terms of the MIT license. - See copying.txt for details. + See COPYING.txt for details. */ #ifndef _COMPRESS_H diff --git a/exhal.c b/exhal.c index 850ba31..88ae94a 100644 --- a/exhal.c +++ b/exhal.c @@ -6,7 +6,7 @@ exhal romfile offset outfile This code is released under the terms of the MIT license. - See copying.txt for details. + See COPYING.txt for details. */ #include diff --git a/inhal.c b/inhal.c index c5539aa..fe09a5d 100644 --- a/inhal.c +++ b/inhal.c @@ -7,7 +7,7 @@ inhal -n infile outfile This code is released under the terms of the MIT license. - See copying.txt for details. + See COPYING.txt for details. */ #include diff --git a/makefile b/makefile index a148f23..06eeb41 100644 --- a/makefile +++ b/makefile @@ -17,15 +17,15 @@ DEFINES += -DEXTRA_OUT # Uncomment this line to enable debug output #DEFINES += -DDEBUG_OUT -all: inhal$(EXT) exhal$(EXT) +all: inhal exhal clean: $(DELETE) inhal$(EXT) exhal$(EXT) compress.o -inhal$(EXT): inhal.c compress.o +inhal: inhal.c compress.o $(CC) $(DEFINES) $(FLAGS) -o inhal$(EXT) inhal.c compress.o -exhal$(EXT): exhal.c compress.o +exhal: exhal.c compress.o $(CC) $(DEFINES) $(FLAGS) -o exhal$(EXT) exhal.c compress.o compress.o: compress.c