This commit is contained in:
optixx 2016-07-16 17:15:16 +02:00
parent 8a190c9f10
commit d5560260b3
11 changed files with 325 additions and 396 deletions

View File

@ -1,5 +1,7 @@
#!/usr/bin/python
import sys
bits = 32
try:
if 'x' in sys.argv[1] or 'X' in sys.argv[1]:
v = int(sys.argv[1], 16)
@ -9,7 +11,6 @@ except:
print "%s NUM" % sys.argv[0]
sys.exit(-1)
bits = 32
sys.stdout.write("0b")
for i in range(bits - 1, -1, -1):
s = 1 << i
@ -20,9 +21,6 @@ for i in range(bits-1,-1,-1):
if i and not i % 8:
sys.stdout.write(" ")
print
print "0x%x" % v
print v

View File

@ -1,8 +1,6 @@
# -*- coding: utf-8 -*-
import binascii
import os
import sys
import time
import glob
import zlib
@ -14,6 +12,7 @@ total_zip_len = 0
total_comp_len = 0
g = glob.glob(os.path.join(TARGET, "*"))
for name in g:
count += 1
data = open(name, 'r').read()
@ -27,6 +26,13 @@ for name in g:
zip_len = len(zip_data)
zip_pre = zip_len / (data_len / 100)
total_zip_len += zip_pre
print "%30s %04i %04i %2.2f %04i %2.2f" % (os.path.basename(name)[:30],data_len / 1024 ,comp_len / 1024,comp_pre, zip_len / 1024, zip_pre )
print "%30s %04i %04i %2.2f %04i %2.2f" % (
os.path.basename(name)[:30],
data_len / 1024,
comp_len / 1024,
comp_pre,
zip_len / 1024,
zip_pre
)
print "%2.2f %2.2f" % (total_zip_len / count, total_comp_len / count)

View File

@ -1,15 +1,15 @@
import ctypes
import sys
import os
def crc_xmodem_update(crc, data):
crc = ctypes.c_uint16(crc.value ^ data.value << 8)
for i in range(0, 8):
if crc.value & 0x8000:
crc = ctypes.c_uint16((crc.value << 1) ^ 0x1021);
crc = ctypes.c_uint16((crc.value << 1) ^ 0x1021)
else:
crc = ctypes.c_uint16(crc.value << 1);
crc = ctypes.c_uint16(crc.value << 1)
return crc
@ -39,8 +39,6 @@ def test_algo():
def main():
#import cProfile
#cProfile.run('test_performance()')
if sys.argv[1].endswith(".smc"):
copy_header = True
@ -69,5 +67,3 @@ def main():
if __name__ == '__main__':
# test_algo()
main()

View File

@ -1,40 +0,0 @@
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()

View File

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

View File

@ -1,30 +1,16 @@
import sqlite3
import os
import re
import string
import stat
import popen2
import glob
import sys
import os
import pprint
import base64
import getpass
import os
import socket
import sys
import traceback
import paramiko
import socket
from subprocess import Popen
def distance(a, b):
c = {}
n = len(a); m = len(b)
n = len(a)
m = len(b)
for i in range(0, n + 1):
c[i, 0] = i
@ -54,16 +40,20 @@ elif socket.gethostname() == 'box':
hostname = "burst"
else:
sys.exit()
def shellquote(s):
return "'" + s.replace("'", "'\\''") + "'"
def main():
port = 22
password = getpass.getpass('Password for %s@%s: ' % (username, hostname))
hostkeytype = None
hostkey = None
host_keys = paramiko.util.load_host_keys(os.path.expanduser('~/.ssh/known_hosts'))
host_keys = paramiko.util.load_host_keys(
os.path.expanduser('~/.ssh/known_hosts'))
if host_keys.has_key(hostname):
hostkeytype = host_keys[hostname].keys()[0]
hostkey = host_keys[hostname][hostkeytype]
@ -78,7 +68,6 @@ def main():
dirlist = sftp.listdir('.')
print "Dirlist:", dirlist
conn = sqlite3.connect('roms_cleanup.sqlite3')
c = conn.cursor()
for i in [(1,), (2,), (4,), (8,), (16,)]:
@ -107,15 +96,16 @@ def main():
ORDER BY file_name
''', i)
last_name = str()
for row in c:
name, size, filename = row
d = distance(os.path.basename(filename),os.path.basename(last_name))
d = distance(
os.path.basename(filename), os.path.basename(last_name))
if d < 7:
print "Skip ", filename
continue
filename_dst = os.path.join(dirname,os.path.basename(filename))
filename_dst = os.path.join(
dirname, os.path.basename(filename))
print "Remote: %s -> %s" % (filename, filename_dst)
last_name = filename
try:
@ -138,10 +128,3 @@ def main():
if __name__ == '__main__':
main()

View File

@ -28,7 +28,7 @@ import pprint
# 2 This may be freely redistributed under the terms of the GNU Public License
# 4 /Users/david/Devel/arch/snes/roms/Teenage Mutant Ninja Turtles IV - Turtles in Time (U) [!].smc
# 6 Multi Game Doctor (2)/Multi Game Hunter/MGH
#8 00007fb0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
# 8 00007fb0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ........
# 9 00007fc0 54 2e 4d 2e 4e 2e 54 2e 20 34 20 20 20 20 20 20 T.M.N.T. 4
# 10 00007fd0 20 20 20 20 20 20 00 0a 00 01 a4 00 7c e9 83 16 ......|...
# 12 Super Nintendo Entertainment System/SNES/Super Famicom
@ -51,9 +51,6 @@ import pprint
# 31 This ROM has no backup unit header
swc_header_tpl = '''
Backup unit header info (SWC)
@ -72,8 +69,6 @@ Backup unit header info (SWC)
'''
def createdb():
try:
os.unlink("roms.sqlite3")
@ -111,6 +106,7 @@ def createdb():
)''')
return conn, c
def process(conn, c, file_name, out):
file_ext = os.path.splitext(file_name)[1].replace(".", '')
file_size = os.stat(file_name)[stat.ST_SIZE]
@ -146,42 +142,51 @@ def process(conn,c,file_name,out):
try:
rom_size = int(out[16].split(" ")[0])
rom_mb = float(re.compile("([\d.]+) Mb").search(out[16]).groups()[0])
rom_mb = float(
re.compile("([\d.]+) Mb").search(out[16]).groups()[0])
except:
print "Broken..."
return
if not "No" in out[18]:
rom_padded = int(re.compile("([\d.]+) Bytes").search(out[18]).groups()[0])
rom_padded = int(
re.compile("([\d.]+) Bytes").search(out[18]).groups()[0])
for idx, line in enumerate(out):
if line is None:
continue
if "Backup unit/emulator header: Yes" in line:
rom_backup = int(re.compile("([\d.]+) Bytes").search(line).groups()[0])
rom_backup = int(
re.compile("([\d.]+) Bytes").search(line).groups()[0])
if "Intro/Trainer:" in line:
rom_trainer = int(re.compile("([\d.]+) Bytes").search(line).groups()[0])
rom_trainer = int(
re.compile("([\d.]+) Bytes").search(line).groups()[0])
if "HiROM: Yes" in line:
rom_hirom = 1
if "Internal size:" in line:
rom_internalsize = int(re.compile("([\d.]+) Mb").search(line).groups()[0])
rom_internalsize = int(
re.compile("([\d.]+) Mb").search(line).groups()[0])
if "ROM type:" in line:
try:
rom_type = int(re.compile("([\d]+)").search(line).groups()[0])
rom_type = int(
re.compile("([\d]+)").search(line).groups()[0])
except:
pass
if "ROM speed:" in line:
rom_speed = int(re.compile("([\d]+) ns").search(line).groups()[0])
rom_speed = int(
re.compile("([\d]+) ns").search(line).groups()[0])
if "SRAM: Yes" in line:
rom_sram = int(re.compile("([\d]+) kBytes").search(line).groups()[0])
rom_sram = int(
re.compile("([\d]+) kBytes").search(line).groups()[0])
if "Version:" in line:
rom_version = float(re.compile("([\d.]+)").search(line).groups()[0])
rom_version = float(
re.compile("([\d.]+)").search(line).groups()[0])
if "Checksum: Ok" in line:
rom_chk = 1
except:
@ -241,12 +246,14 @@ def ucon64_info(filename):
return False, err
return out, err
def clean(s):
s = s.replace("\n", "")
if not len(s):
return None
return s
def main():
conn, c = createdb()
@ -273,7 +280,3 @@ def main():
if __name__ == "__main__":
main()

View File

@ -3,6 +3,7 @@ import os
import sys
import struct
def usage():
print "%s <rom> <code> <addr>" % sys.argv[0]
sys.exit(0)
@ -12,10 +13,9 @@ def error(msg):
print "ERROR: %s" % msg
sys.exit(-1)
def main():
if len(sys.argv) != 4:
usage()
if not os.path.isfile(sys.argv[1]):
@ -40,12 +40,12 @@ def main():
addr_patch = struct.pack(">H", addr)
if addr > bank_size:
error("Addr 0x%04x is not within first bank" % addr)
if addr + code_len > (bank_size - 256):
error("Code is %s bytes, and so too big to fit from 0x%04x into first bank" % (code_len,addr))
error("Code is %s bytes, and so too big to fit from 0x%04x into first bank" % (
code_len, addr))
print "Rom size: 0x%08x (%i)" % (rom_len, rom_len)
print "Code size: 0x%04x (%i)" % (code_len, code_len)
@ -53,7 +53,6 @@ def main():
print "Patch addr: 0x%08x" % addr
print "IRQ addr: 0x%08x" % irq_vector
out.write(rom[:addr])
out.write(code)
out.write(rom[addr + code_len:irq_vector])
@ -68,4 +67,3 @@ def main():
if __name__ == '__main__':
main()

View File

@ -1,6 +1,6 @@
import os
import sys
def main():
bank_size = 2 ** 15
@ -23,7 +23,5 @@ def main():
out.close()
if __name__ == '__main__':
main()

View File

@ -1,11 +1,8 @@
import string
import math
import sys
M_PI = 3.14159265358979323846
def sine(val, r, scale, stepping):
global M_PI, flip
re = int(math.sin(val * (M_PI * scale) / r) * r) + r
@ -29,10 +26,3 @@ def main():
print s
main()

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