add convert and webpy

This commit is contained in:
David Voswinkel 2009-08-02 16:30:01 +02:00
parent d1447db7b0
commit 570323f017
4 changed files with 99 additions and 0 deletions

56
scripts/conv_rle.py Normal file
View File

@ -0,0 +1,56 @@
import binascii
import os
import sys
import time
LEN = 2**16+8
TARGET="/Users/david/Devel/arch/avr/code/quickdev16/avr/usbload"
data = open(sys.argv[1],"r").read()
print "Load %s (%i) bytes" % (sys.argv[1],len(data))
data = data[:LEN]
print "Use (%i) bytes" % (len(data))
data = binascii.rlecode_hqx(data)
print "RLE crunch (%i) bytes" % (len(data))
binfile = open("/tmp/loader.rle","w")
binfile.write(data)
binfile.close()
cfile = open("/tmp/loader.c","w")
hfile = open("/tmp/loader.h","w")
hfile.write('''
#ifndef __FIFO_H__
#define __FIFO_H__
#define ROM_SIZE %i
#endif
''' % len(data))
cfile.write('''/*
File: %s
Time: %s
*/
#include <avr/pgmspace.h>
#include <loader.h>
const char _rom[ROM_SIZE] PROGMEM = {
''' % (sys.argv[1],time.strftime("%a, %d %b %Y %H:%M:%S", time.localtime())))
for idx,c in enumerate(data):
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.close()
os.rename("/tmp/loader.c", os.path.join(TARGET,"loader.c"))
os.rename("/tmp/loader.h", os.path.join(TARGET,"loader.h"))

40
scripts/dev_server.py Normal file
View File

@ -0,0 +1,40 @@
import web
from subprocess import *
urls = ('/upload', 'Upload')
class Upload:
def GET(self):
return """<html><head></head><body>
<form method="POST" enctype="multipart/form-data" action="">
<input type="file" name="myfile" />
<br/>
<input type="submit" />
</form>
</body></html>"""
def POST(self):
obj = web.input(myfile={})
filedir = '/Users/david/Devel/arch/avr/code/quickdev16/roms' # change this to the directory you want to store the file in.
if 'myfile' in obj:
web.debug("Upload file %s" % obj['myfile'].filename)
filepath = obj.myfile.filename.replace('\\','/')
filename = filepath.split('/')[-1]
foutname = filedir +'/'+ filename
web.debug("Write to %s" % foutname)
fout = open(foutname,'w')
fout.write( obj.myfile.file.read())
fout.close()
cmd = "ucon64 --port=usb --xsnesram %s " % foutname
web.debug("Execute: %s" % cmd)
p = Popen(cmd, shell=True, bufsize=128,
stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=True)
stdout,stderr = p.communicate()
return '''<html><head></head><body>Out: %s <br/>Err: %s</body></html>''' % (
stdout.replace("\n","<br/>").replace("\r","<br/>"),
stderr.replace("\n","<br/>"))
raise web.seeother('/upload')
if __name__ == "__main__":
app = web.application(urls, globals())
app.run()

2
scripts/link_webpy.sh Normal file
View File

@ -0,0 +1,2 @@
ln -s `pwd`/webpy/web .

1
scripts/webpy Submodule

@ -0,0 +1 @@
Subproject commit 2a5acf5a834f9c2fd98d5c2be563429821feab3b