Add fastlz

This commit is contained in:
optixx
2016-02-21 16:32:43 +01:00
parent dad06d8ae9
commit b30acd54d2
14 changed files with 3960 additions and 2150 deletions

101
scripts/conv_fastlz.py Normal file
View File

@@ -0,0 +1,101 @@
import os
import sys
import time
import shutil
LEN = 2 ** 16
huffman = False
TARGET = os.getcwd()
SOURCE = sys.argv[1]
NAME = os.path.basename(sys.argv[1])
COMPRESSED = NAME + ".fastlz"
LOC = os.path.dirname(os.path.realpath(__file__))
FASTLZ = os.path.join(LOC, "..", "tools", "fastlz", "pack")
os.system("%s %s %s" % (FASTLZ, SOURCE, COMPRESSED))
data = open(COMPRESSED).read()
os.unlink(COMPRESSED)
fastlz_size = len(data)
cfile = open("/tmp/loader.c", "w")
hfile = open("/tmp/loader.h", "w")
parts = []
cnt = len(data) / ((2 ** 15) - 1)
r = len(data) - (cnt * ((2 ** 15) - 1))
for i in range(0, cnt):
parts.append(((2 ** 15) - 1))
parts.append(r)
hfile.write('''/*
File: %s
Time: %s
*/
#ifndef __FIFO_H__
#define __FIFO_H__
#define LOADER_NAME "%s"
#define LOADER_COMPRESS "FASTLZ"
#define ROM_FASTLZ_SIZE %i
#define ROM_BUFFER_CNT %i
''' % (
os.path.basename(SOURCE),
time.strftime("%a, %d %b %Y %H:%M:%S", time.localtime()),
NAME,
fastlz_size,
len(parts)
))
for idx, val in enumerate(parts):
hfile.write('#define ROM_BUFFER_SIZE%02i %i\n' % (idx + 1, val))
hfile.write('\n#endif\n')
hfile.close()
cfile.write('''/*
File: %s
Time: %s
*/
#include <avr/pgmspace.h>
#include <loader.h>
''')
addr = 0
for idx, val in enumerate(parts):
cfile.write('''
const char _rom%02i[ROM_BUFFER_SIZE%02i] PROGMEM = {
''' % (idx + 1, idx + 1))
l = addr
h = addr + parts[idx]
addr += parts[idx]
for idx, c in enumerate(data[l:h]):
c = ord(c)
if idx < len(data) - 1:
cfile.write("0x%02x," % c)
else:
cfile.write("0x%02x" % c)
if idx and idx % 16 == 0:
cfile.write("\n")
cfile.write('''
};
''')
cfile.write('PGM_VOID_P _rom[ROM_BUFFER_CNT]= {')
for idx, val in enumerate(parts):
if idx < len(parts) - 1:
cfile.write('''&_rom%02i,''' % (idx + 1))
else:
cfile.write('''&_rom%02i''' % (idx + 1))
cfile.write('''};
''')
cfile.write('const int _rom_size[ROM_BUFFER_CNT] = {')
for idx, val in enumerate(parts):
if idx < len(parts) - 1:
cfile.write('''%i,''' % (val))
else:
cfile.write('''%i''' % (val))
cfile.write('''};
''')
cfile.close()
shutil.copy("/tmp/loader.c", os.path.join(TARGET, "loader.c"))
shutil.copy("/tmp/loader.h", os.path.join(TARGET, "loader.h"))
print "Copy loader.h and loader.c to %s" % TARGET

View File

@@ -5,11 +5,10 @@ import time
import shutil
LEN = 2 ** 16
huffman = False
TARGET = os.getcwd()
SOURCE = sys.argv[1]
NAME = os.path.basename(sys.argv[1])
LOC = os.path.dirname(os.path.realpath(__file__))
HUFFMAN_ENCODER = os.path.join(LOC, "..", "tools", "huffman", "huffman-encode")
data = open(SOURCE, "r").read()
print "Load %s, %i bytes" % (SOURCE, len(data))
@@ -19,22 +18,6 @@ data = binascii.rlecode_hqx(data)
print "RLE crunch (%i) bytes" % (len(data))
rle_size = len(data)
huffman_size = 0
if huffman:
binfile = open("/tmp/loader.rle", "w")
binfile.write(data)
binfile.close()
cmd = "%s /tmp/loader.rle" % HUFFMAN_ENCODER
print cmd
os.system(cmd)
data = open("/tmp/loader.rle.hfm", "r").read()
print "HUFFMAN crunch (%i) bytes" % (len(data))
huffman_size = len(data)
os.unlink("/tmp/loader.rle")
os.unlink("/tmp/loader.rle.hfm")
cfile = open("/tmp/loader.c", "w")
hfile = open("/tmp/loader.h", "w")
parts = []
@@ -50,14 +33,15 @@ Time: %s
#ifndef __FIFO_H__
#define __FIFO_H__
#define ROM_HUFFMAN_SIZE %i
#define LOADER_NAME "%s"
#define LOADER_COMPRESS "RLE"
#define ROM_RLE_SIZE %i
#define ROM_BUFFER_CNT %i
''' % (
os.path.basename(SOURCE),
time.strftime("%a, %d %b %Y %H:%M:%S", time.localtime()),
huffman_size,
NAME,
rle_size,
len(parts)
))

View File

@@ -4,10 +4,10 @@ import time
import shutil
LEN = 2 ** 16
huffman = False
TARGET = os.getcwd()
SOURCE = sys.argv[1]
DEFLATE = os.path.basename(sys.argv[1]) + ".deflate"
NAME = os.path.basename(sys.argv[1])
DEFLATE = NAME + ".deflate"
PATH = os.path.dirname(os.path.realpath(__file__))
WINE = "wine"
KZIP = os.path.join(PATH, "kzip.exe")
@@ -44,12 +44,15 @@ Time: %s
#ifndef __FIFO_H__
#define __FIFO_H__
#define LOADER_NAME "qd16boot02.smc"
#define LOADER_COMPRESS "ZIP"
#define ROM_ZIP_SIZE %i
#define ROM_BUFFER_CNT %i
''' % (
os.path.basename(SOURCE),
time.strftime("%a, %d %b %Y %H:%M:%S", time.localtime()),
NAME,
zip_size,
len(parts)
))