Created
December 6, 2012 19:12
-
-
Save anonymous/4227332 to your computer and use it in GitHub Desktop.
Proof of concept: Huffman unpacker for Battletoads & Double Dragon (NES)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include "Charmap.h" | |
#include "text.h" | |
#include "Tree_1.h" | |
#include "Tree_2.h" | |
int main() | |
{ | |
int i, j; | |
unsigned char offset = 0, chr, byte; | |
for (j = 0; j < text_size; j++) | |
{ | |
byte = text[j]; | |
for (i = 0; i < 8; i++){ | |
offset = byte & 0x80 ? Tree_2[offset] : Tree_1[offset]; | |
byte <<= 1; | |
if (offset >= 0x80){ | |
chr = Charmap [offset - 0x80]; | |
printf("%c", chr); | |
offset = 0; | |
} | |
} | |
} | |
getchar(); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
This file was autogenerated by raw2c. | |
Visit http://www.devkitpro.org | |
*/ | |
const unsigned char Charmap[] = { | |
0x20, 0x45, 0x54, 0x41, 0x4f, 0x53, 0x49, 0x4e, 0x52, 0x48, 0x4c, 0xa0, 0x55, 0x4d, 0x44, 0x42, | |
0x59, 0x43, 0x27, 0x21, 0x47, 0x57, 0x50, 0xfd, 0x46, 0x4b, 0x2c, 0x2e, 0x5a, 0x2d, 0x56, 0x2a, | |
0x80, 0xff, 0x82, 0x4a, 0x51, 0x3f, 0x92, 0x81, 0x58, 0x09, 0x06, 0xa9, 0xc0, 0x39, 0xc8, 0x85, | |
0xa3, 0xa1, 0x31, 0xa5, 0x40, 0xe0, 0xa8, 0xa4, 0x14, 0x22, 0xcc, 0x33, 0xd0, 0x0b, 0xd9, 0x08, | |
0xd2, 0xc7, 0xc5, 0xcd, 0xce | |
}; | |
const int Charmap_size = sizeof(Charmap); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
This file was autogenerated by raw2c. | |
Visit http://www.devkitpro.org | |
*/ | |
//--------------------------------------------------------------------------------- | |
#ifndef _Charmap_h_ | |
#define _Charmap_h_ | |
//--------------------------------------------------------------------------------- | |
extern const unsigned char Charmap[]; | |
extern const int Charmap_size; | |
//--------------------------------------------------------------------------------- | |
#endif //_Charmap_h_ | |
//--------------------------------------------------------------------------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# --- Project details ------------------------------------------------- | |
PROJ := bt_huffman | |
TARGET := $(PROJ) | |
COBJS := $(PROJ).o Charmap.o text.o Tree_1.o Tree_2.o | |
# --- Build defines --------------------------------------------------- | |
CC := gcc | |
LD := gcc | |
CFLAGS := -Os -s -Wall | |
CFDEBUG := -ggdb -O0 -Wall | |
.PHONY : build clean run | |
# --- Build ----------------------------------------------------------- | |
# Build process starts here! | |
build: $(TARGET).exe | |
# Compile (step 1) | |
$(PROJ).exe: $(COBJS) | |
$(CC) $^ $(CFLAGS) -o $@ | |
$(COBJS) : %.o : %.c | |
$(CC) $(CFLAGS) -c $< -o $@ | |
# --- Clean ----------------------------------------------------------- | |
clean : | |
@rm -fv *.exe | |
@rm -fv *.dll | |
@rm -fv *.wcx | |
@rm -fv *.o | |
# --- Run ----------------------------------------------------------- | |
# Run app | |
run: | |
@echo "Do nothing | |
#EOF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
This file was autogenerated by raw2c. | |
Visit http://www.devkitpro.org | |
*/ | |
const unsigned char text[] = { | |
0x81, 0x30, 0x9b, 0xe6, 0xe2, 0xdd, 0xec, 0x1a, 0xd6, 0x45, 0x06, 0xb1, 0x74, 0x4e, 0xfd, 0x90, | |
0xe7, 0x20, 0xfa, 0x9c, 0x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6b, 0xdf, 0xa9, 0x17, 0x70, 0x76, 0xb3, 0xf3, | |
0x2b, 0x56, 0x7c, 0xf7, 0xb9, 0x4d, 0x9c, 0xa4, 0x70, 0xfd, 0x91, 0xa6, 0x29, 0xf7, 0x08, 0x1d, | |
0xc5, 0x35, 0xf4, 0x2c, 0x5d, 0x1f, 0x7f, 0xca, 0x7e, 0xbf, 0xd7, 0x3a, 0x6b, 0xd8, 0x71, 0x7f, | |
0xab, 0x52, 0xa3, 0xbb, 0xcf, 0x9e, 0x75, 0xbd, 0xe8, 0xc2, 0xa3, 0x2a, 0xbf, 0xd9, 0x17, 0xd3 | |
}; | |
const int text_size = sizeof(text); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
This file was autogenerated by raw2c. | |
Visit http://www.devkitpro.org | |
*/ | |
//--------------------------------------------------------------------------------- | |
#ifndef _text_h_ | |
#define _text_h_ | |
//--------------------------------------------------------------------------------- | |
extern const unsigned char text[]; | |
extern const int text_size; | |
//--------------------------------------------------------------------------------- | |
#endif //_text_h_ | |
//--------------------------------------------------------------------------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
This file was autogenerated by raw2c. | |
Visit http://www.devkitpro.org | |
*/ | |
const unsigned char Tree_1[] = { | |
0x43, 0xc5, 0xc3, 0xc1, 0xbf, 0xbd, 0xbb, 0xb9, 0xb7, 0xb5, 0xb3, 0xb1, 0xaf, 0xad, 0xab, 0xa9, | |
0x0b, 0x09, 0x07, 0x05, 0x03, 0x01, 0xa7, 0x14, 0x12, 0x10, 0x0e, 0xa5, 0x15, 0xa2, 0x19, 0x17, | |
0x1b, 0xa1, 0x1e, 0xa0, 0x9e, 0x9c, 0x21, 0x22, 0x9a, 0x98, 0x97, 0x25, 0x26, 0x93, 0x27, 0x28, | |
0x8f, 0x8d, 0x8c, 0x2b, 0x2c, 0x8a, 0x2e, 0x87, 0x86, 0x31, 0x32, 0x84, 0x83, 0x35, 0x81, 0x38, | |
0x3a, 0x3c, 0x80, 0x3f, 0x41 | |
}; | |
const int Tree_1_size = sizeof(Tree_1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
This file was autogenerated by raw2c. | |
Visit http://www.devkitpro.org | |
*/ | |
//--------------------------------------------------------------------------------- | |
#ifndef _Tree_1_h_ | |
#define _Tree_1_h_ | |
//--------------------------------------------------------------------------------- | |
extern const unsigned char Tree_1[]; | |
extern const int Tree_1_size; | |
//--------------------------------------------------------------------------------- | |
#endif //_Tree_1_h_ | |
//--------------------------------------------------------------------------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
This file was autogenerated by raw2c. | |
Visit http://www.devkitpro.org | |
*/ | |
const unsigned char Tree_2[] = { | |
0x44, 0xc4, 0xc2, 0xc0, 0xbe, 0xbc, 0xba, 0xb8, 0xb6, 0xb4, 0xb2, 0xb0, 0xae, 0xac, 0xaa, 0x0c, | |
0x0a, 0x08, 0x06, 0x04, 0x02, 0xa8, 0xa6, 0x13, 0x11, 0x0f, 0x0d, 0xa4, 0xa3, 0x1a, 0x18, 0x16, | |
0x1c, 0x1f, 0x1d, 0x9f, 0x9d, 0x20, 0x9b, 0x23, 0x99, 0x24, 0x96, 0x95, 0x94, 0x92, 0x91, 0x90, | |
0x8e, 0x29, 0x2a, 0x8b, 0x2d, 0x89, 0x88, 0x2f, 0x30, 0x85, 0x33, 0x34, 0x82, 0x36, 0x37, 0x39, | |
0x3b, 0x3d, 0x3e, 0x40, 0x42 | |
}; | |
const int Tree_2_size = sizeof(Tree_2); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
This file was autogenerated by raw2c. | |
Visit http://www.devkitpro.org | |
*/ | |
//--------------------------------------------------------------------------------- | |
#ifndef _Tree_2_h_ | |
#define _Tree_2_h_ | |
//--------------------------------------------------------------------------------- | |
extern const unsigned char Tree_2[]; | |
extern const int Tree_2_size; | |
//--------------------------------------------------------------------------------- | |
#endif //_Tree_2_h_ | |
//--------------------------------------------------------------------------------- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment