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,28 +1,26 @@
#!/usr/bin/python #!/usr/bin/python
import sys import sys
bits = 32
try: try:
if 'x' in sys.argv[1] or 'X' in sys.argv[1]: if 'x' in sys.argv[1] or 'X' in sys.argv[1]:
v = int(sys.argv[1],16) v = int(sys.argv[1], 16)
else: else:
v = int(sys.argv[1]) v = int(sys.argv[1])
except: except:
print "%s NUM" % sys.argv[0] print "%s NUM" % sys.argv[0]
sys.exit(-1) sys.exit(-1)
bits = 32
sys.stdout.write("0b") sys.stdout.write("0b")
for i in range(bits-1,-1,-1): for i in range(bits - 1, -1, -1):
s = 1<<i s = 1 << i
if v & s: if v & s:
sys.stdout.write("1") sys.stdout.write("1")
else: else:
sys.stdout.write("0") sys.stdout.write("0")
if i and not i%8: if i and not i % 8:
sys.stdout.write(" ") sys.stdout.write(" ")
print print
print "0x%x"% v print "0x%x" % v
print v print v

View File

@ -1,32 +1,38 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import binascii import binascii
import os import os
import sys
import time
import glob import glob
import zlib import zlib
TARGET="/Users/david/Dropbox/Tech/Quickdev16/roms/08" TARGET = "/Users/david/Dropbox/Tech/Quickdev16/roms/08"
count = 0 count = 0
total_zip_len = 0 total_zip_len = 0
total_comp_len = 0 total_comp_len = 0
g = glob.glob(os.path.join(TARGET,"*")) g = glob.glob(os.path.join(TARGET, "*"))
for name in g: for name in g:
count +=1 count += 1
data = open(name,'r').read() data = open(name, 'r').read()
data_len = len(data) data_len = len(data)
comp = binascii.rlecode_hqx(data) comp = binascii.rlecode_hqx(data)
comp_len = len(comp) comp_len = len(comp)
comp_pre = comp_len / ( data_len / 100 ) comp_pre = comp_len / (data_len / 100)
total_comp_len += comp_pre total_comp_len += comp_pre
zip_data = zlib.compress(data) zip_data = zlib.compress(data)
zip_len = len(zip_data) zip_len = len(zip_data)
zip_pre = zip_len / ( data_len / 100 ) zip_pre = zip_len / (data_len / 100)
total_zip_len += zip_pre 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 ) print "%2.2f %2.2f" % (total_zip_len / count, total_comp_len / count)

View File

@ -1,30 +1,30 @@
import ctypes import ctypes
import sys import sys
import os import os
def crc_xmodem_update(crc,data):
def crc_xmodem_update(crc, data):
crc = ctypes.c_uint16(crc.value ^ data.value << 8) crc = ctypes.c_uint16(crc.value ^ data.value << 8)
for i in range(0,8): for i in range(0, 8):
if crc.value & 0x8000: if crc.value & 0x8000:
crc = ctypes.c_uint16((crc.value << 1) ^ 0x1021); crc = ctypes.c_uint16((crc.value << 1) ^ 0x1021)
else: else:
crc = ctypes.c_uint16(crc.value << 1); crc = ctypes.c_uint16(crc.value << 1)
return crc return crc
def do_crc(data): def do_crc(data):
crc = ctypes.c_uint16(0) crc = ctypes.c_uint16(0)
for idx,char in enumerate(data): for idx, char in enumerate(data):
crc = crc_xmodem_update(crc,ctypes.c_uint8(ord(char))) crc = crc_xmodem_update(crc, ctypes.c_uint8(ord(char)))
return crc.value return crc.value
def test_performance(): def test_performance():
data=str() data = str()
fd = open("/dev/urandom") fd = open("/dev/urandom")
for i in range(0,256): for i in range(0, 256):
data+= fd.read(1024) data += fd.read(1024)
sys.stdout.write("*") sys.stdout.write("*")
sys.stdout.flush() sys.stdout.flush()
print print
@ -33,16 +33,14 @@ def test_performance():
def test_algo(): def test_algo():
data='david' data = 'david'
data='da' data = 'da'
print "%x" % do_crc(data) print "%x" % do_crc(data)
def main(): def main():
#import cProfile
#cProfile.run('test_performance()')
if sys.argv[1].endswith(".smc"): if sys.argv[1].endswith(".smc"):
copy_header= True copy_header = True
size = os.stat(sys.argv[1])[6] size = os.stat(sys.argv[1])[6]
fd = open(sys.argv[1]) fd = open(sys.argv[1])
@ -52,7 +50,7 @@ def main():
size = size - 512 size = size - 512
addr = 0x0000 addr = 0x0000
step = 2**15 step = 2 ** 15
result = [] result = []
while addr < size: while addr < size:
try: try:
@ -62,12 +60,10 @@ def main():
print "Done" print "Done"
break break
crc = do_crc(block) crc = do_crc(block)
print "Bank: 0x%02x Addr: 0x%06x Block: 0x%04x CRC 0x%04x" % (addr/(2**15),addr,addr/512, ctypes.c_uint16(crc).value) print "Bank: 0x%02x Addr: 0x%06x Block: 0x%04x CRC 0x%04x" % (addr / (2 ** 15), addr, addr / 512, ctypes.c_uint16(crc).value)
result.append(hex(ctypes.c_uint16(crc).value)) result.append(hex(ctypes.c_uint16(crc).value))
#print result # print result
if __name__ == '__main__': if __name__ == '__main__':
#test_algo() # test_algo()
main() 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,46 +1,32 @@
import sqlite3 import sqlite3
import os import os
import re
import string
import stat
import popen2
import glob
import sys import sys
import os
import pprint
import base64
import getpass import getpass
import os
import socket import socket
import sys
import traceback import traceback
import paramiko import paramiko
import socket
from subprocess import Popen
def distance(a,b): def distance(a, b):
c = {} c = {}
n = len(a); m = len(b) n = len(a)
m = len(b)
for i in range(0,n+1): for i in range(0, n + 1):
c[i,0] = i c[i, 0] = i
for j in range(0,m+1): for j in range(0, m + 1):
c[0,j] = j c[0, j] = j
for i in range(1,n+1): for i in range(1, n + 1):
for j in range(1,m+1): for j in range(1, m + 1):
x = c[i-1,j]+1 x = c[i - 1, j] + 1
y = c[i,j-1]+1 y = c[i, j - 1] + 1
if a[i-1] == b[j-1]: if a[i - 1] == b[j - 1]:
z = c[i-1,j-1] z = c[i - 1, j - 1]
else: else:
z = c[i-1,j-1]+1 z = c[i - 1, j - 1] + 1
c[i,j] = min(x,y,z) c[i, j] = min(x, y, z)
return c[n,m] return c[n, m]
paramiko.util.log_to_file('rom_sftp.log') paramiko.util.log_to_file('rom_sftp.log')
@ -54,16 +40,20 @@ elif socket.gethostname() == 'box':
hostname = "burst" hostname = "burst"
else: else:
sys.exit() sys.exit()
def shellquote(s): def shellquote(s):
return "'" + s.replace("'", "'\\''") + "'" return "'" + s.replace("'", "'\\''") + "'"
def main(): def main():
port = 22 port = 22
password = getpass.getpass('Password for %s@%s: ' % (username, hostname)) password = getpass.getpass('Password for %s@%s: ' % (username, hostname))
hostkeytype = None hostkeytype = None
hostkey = 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): if host_keys.has_key(hostname):
hostkeytype = host_keys[hostname].keys()[0] hostkeytype = host_keys[hostname].keys()[0]
hostkey = host_keys[hostname][hostkeytype] hostkey = host_keys[hostname][hostkeytype]
@ -78,11 +68,10 @@ def main():
dirlist = sftp.listdir('.') dirlist = sftp.listdir('.')
print "Dirlist:", dirlist print "Dirlist:", dirlist
conn = sqlite3.connect('roms_cleanup.sqlite3') conn = sqlite3.connect('roms_cleanup.sqlite3')
c = conn.cursor() c = conn.cursor()
for i in [(1,),(2,),(4,),(8,),(16,)]: for i in [(1,), (2,), (4,), (8,), (16,)]:
dirname = os.path.join(path,"%02i" % i) dirname = os.path.join(path, "%02i" % i)
if not os.path.isdir(dirname): if not os.path.isdir(dirname):
os.mkdir(dirname) os.mkdir(dirname)
print "#" * 60 print "#" * 60
@ -105,21 +94,22 @@ def main():
AND AND
rom_region like "Europe%" rom_region like "Europe%"
ORDER BY file_name ORDER BY file_name
''',i) ''', i)
last_name = str() last_name = str()
for row in c: for row in c:
name,size,filename = row 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: if d < 7:
print "Skip ",filename print "Skip ", filename
continue continue
filename_dst = os.path.join(dirname,os.path.basename(filename)) filename_dst = os.path.join(
print "Remote: %s -> %s" % ( filename,filename_dst) dirname, os.path.basename(filename))
print "Remote: %s -> %s" % (filename, filename_dst)
last_name = filename last_name = filename
try: try:
sftp.get(filename,filename_dst) sftp.get(filename, filename_dst)
except Exception, e: except Exception, e:
print '*** Caught exception: %s: %s' % (e.__class__, e) print '*** Caught exception: %s: %s' % (e.__class__, e)
traceback.print_exc() traceback.print_exc()
@ -138,10 +128,3 @@ def main():
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View File

@ -18,43 +18,40 @@ import pprint
# 4 ROM, RAM and DSP1 chip # 4 ROM, RAM and DSP1 chip
# 5 ROM, Save RAM and DSP1 chip # 5 ROM, Save RAM and DSP1 chip
# 19 ROM and Super FX chip # 19 ROM and Super FX chip
#227 ROM, RAM and GameBoy data # 227 ROM, RAM and GameBoy data
#246 ROM and DSP2 chip # 246 ROM and DSP2 chip
#Process /Users/david/Devel/arch/snes/roms/Teenage Mutant Ninja Turtles IV - Turtles in Time (U) [!].smc # Process /Users/david/Devel/arch/snes/roms/Teenage Mutant Ninja Turtles IV - Turtles in Time (U) [!].smc
#0 uCON64 2.0.0 Apple (PPC) 1999-2005 # 0 uCON64 2.0.0 Apple (PPC) 1999-2005
#1 Uses code from various people. See 'developers.html' for more! # 1 Uses code from various people. See 'developers.html' for more!
#2 This may be freely redistributed under the terms of the GNU Public License # 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 # 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 # 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 # 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 ......|... # 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 # 12 Super Nintendo Entertainment System/SNES/Super Famicom
#13 T.M.N.T. 4 # 13 T.M.N.T. 4
#14 Konami # 14 Konami
#15 U.S.A. # 15 U.S.A.
#16 1048576 Bytes (8.0000 Mb) # 16 1048576 Bytes (8.0000 Mb)
#18 Padded: Maybe, 105 Bytes (0.0008 Mb) # 18 Padded: Maybe, 105 Bytes (0.0008 Mb)
#19 Interleaved/Swapped: No # 19 Interleaved/Swapped: No
#20 Backup unit/emulator header: No # 20 Backup unit/emulator header: No
#21 HiROM: No # 21 HiROM: No
#22 Internal size: 8 Mb # 22 Internal size: 8 Mb
#23 ROM type: (0) ROM # 23 ROM type: (0) ROM
#24 ROM speed: 200 ns (SlowROM) # 24 ROM speed: 200 ns (SlowROM)
#25 SRAM: No # 25 SRAM: No
#26 Version: 1.0 # 26 Version: 1.0
#27 Checksum: Ok, 0x1683 (calculated) == 0x1683 (internal) # 27 Checksum: Ok, 0x1683 (calculated) == 0x1683 (internal)
#28 Inverse checksum: Ok, 0xe97c (calculated) == 0xe97c (internal) # 28 Inverse checksum: Ok, 0xe97c (calculated) == 0xe97c (internal)
#29 Checksum (CRC32): 0x5940bd99 # 29 Checksum (CRC32): 0x5940bd99
#31 This ROM has no backup unit header # 31 This ROM has no backup unit header
swc_header_tpl = '''
swc_header_tpl='''
Backup unit header info (SWC) Backup unit header info (SWC)
00000000 20 00 0c 00 00 00 00 00 aa bb 04 00 00 00 00 00 ............... 00000000 20 00 0c 00 00 00 00 00 aa bb 04 00 00 00 00 00 ...............
@ -72,8 +69,6 @@ Backup unit header info (SWC)
''' '''
def createdb(): def createdb():
try: try:
os.unlink("roms.sqlite3") os.unlink("roms.sqlite3")
@ -109,10 +104,11 @@ def createdb():
swc_sram_size text swc_sram_size text
)''') )''')
return conn,c return conn, c
def process(conn,c,file_name,out):
file_ext = os.path.splitext(file_name)[1].replace(".",'') 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] file_size = os.stat(file_name)[stat.ST_SIZE]
rom_size = 0 rom_size = 0
rom_mb = 0 rom_mb = 0
@ -146,49 +142,58 @@ def process(conn,c,file_name,out):
try: try:
rom_size = int(out[16].split(" ")[0]) 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: except:
print "Broken..." print "Broken..."
return return
if not "No" in out[18]: 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): for idx, line in enumerate(out):
if line is None: if line is None:
continue continue
if "Backup unit/emulator header: Yes" in line: 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: 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: if "HiROM: Yes" in line:
rom_hirom = 1 rom_hirom = 1
if "Internal size:" in line: 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: if "ROM type:" in line:
try: try:
rom_type = int(re.compile("([\d]+)").search(line).groups()[0]) rom_type = int(
re.compile("([\d]+)").search(line).groups()[0])
except: except:
pass pass
if "ROM speed:" in line: 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: 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: 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: if "Checksum: Ok" in line:
rom_chk = 1 rom_chk = 1
except: except:
for idx,line in enumerate(out): for idx, line in enumerate(out):
if line is None: if line is None:
continue continue
print idx,line print idx, line
sys.exit() sys.exit()
query = """INSERT INTO roms query = """INSERT INTO roms
@ -225,7 +230,7 @@ def process(conn,c,file_name,out):
swc_dram_mode, swc_dram_mode,
swc_sram_size) swc_sram_size)
c.execute(query,data) c.execute(query, data)
conn.commit() conn.commit()
@ -238,29 +243,31 @@ def ucon64_info(filename):
e.close() e.close()
w.close() w.close()
if len(err): if len(err):
return False,err return False, err
return out,err return out, err
def clean(s): def clean(s):
s = s.replace("\n","") s = s.replace("\n", "")
if not len(s): if not len(s):
return None return None
return s return s
def main(): def main():
conn,c = createdb() conn, c = createdb()
path = sys.argv[1] path = sys.argv[1]
files = glob.glob(path + "/*") files = glob.glob(path + "/*")
for filename in files: for filename in files:
try: try:
r,err = ucon64_info(filename) r, err = ucon64_info(filename)
if not r: if not r:
print err print err
continue continue
r = map(clean,r) r = map(clean, r)
process(conn,c,filename,r) process(conn, c, filename, r)
except (KeyboardInterrupt, SystemExit): except (KeyboardInterrupt, SystemExit):
print "Saving DB..." print "Saving DB..."
c.close() c.close()
@ -273,7 +280,3 @@ def main():
if __name__ == "__main__": if __name__ == "__main__":
main() main()

View File

@ -3,6 +3,7 @@ import os
import sys import sys
import struct import struct
def usage(): def usage():
print "%s <rom> <code> <addr>" % sys.argv[0] print "%s <rom> <code> <addr>" % sys.argv[0]
sys.exit(0) sys.exit(0)
@ -12,10 +13,9 @@ def error(msg):
print "ERROR: %s" % msg print "ERROR: %s" % msg
sys.exit(-1) sys.exit(-1)
def main(): def main():
if len(sys.argv) != 4: if len(sys.argv) != 4:
usage() usage()
if not os.path.isfile(sys.argv[1]): if not os.path.isfile(sys.argv[1]):
@ -23,10 +23,10 @@ def main():
if not os.path.isfile(sys.argv[2]): if not os.path.isfile(sys.argv[2]):
error("Can't open %s file" % sys.argv[2]) error("Can't open %s file" % sys.argv[2])
rom = open(sys.argv[1],"r").read() rom = open(sys.argv[1], "r").read()
code = open(sys.argv[2],"r").read() code = open(sys.argv[2], "r").read()
out_filename = sys.argv[1].split(".")[0] + ".inject" out_filename = sys.argv[1].split(".")[0] + ".inject"
out = open(out_filename,"w") out = open(out_filename, "w")
irq_vector = 0x7FE0 irq_vector = 0x7FE0
bank_size = 1 << 15 bank_size = 1 << 15
@ -34,32 +34,31 @@ def main():
rom_len = len(rom) rom_len = len(rom)
bank_cnt = rom_len / bank_size bank_cnt = rom_len / bank_size
try: try:
addr = int(sys.argv[3],16) addr = int(sys.argv[3], 16)
except: except:
error("Expect %s in hex" % sys.argv[3]) error("Expect %s in hex" % sys.argv[3])
addr_patch = struct.pack(">H",addr) addr_patch = struct.pack(">H", addr)
if addr > bank_size: if addr > bank_size:
error("Addr 0x%04x is not within first bank" % addr) error("Addr 0x%04x is not within first bank" % addr)
if addr + code_len > ( bank_size - 256 ): 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 "Rom size: 0x%08x (%i)" % (rom_len, rom_len)
print "Code size: 0x%04x (%i)" % (code_len,code_len) print "Code size: 0x%04x (%i)" % (code_len, code_len)
print "Banks: 0x%04x (%i)" % (bank_cnt,bank_cnt) print "Banks: 0x%04x (%i)" % (bank_cnt, bank_cnt)
print "Patch addr: 0x%08x" % addr print "Patch addr: 0x%08x" % addr
print "IRQ addr: 0x%08x" % irq_vector print "IRQ addr: 0x%08x" % irq_vector
out.write(rom[:addr]) out.write(rom[:addr])
out.write(code) out.write(code)
out.write(rom[addr+code_len:irq_vector]) out.write(rom[addr + code_len:irq_vector])
out.write(addr_patch) out.write(addr_patch)
out.write(rom[irq_vector+2:]) out.write(rom[irq_vector + 2:])
print "%i Bytes written to %s" % (out.tell(),out_filename) print "%i Bytes written to %s" % (out.tell(), out_filename)
out.close() out.close()
print "Apply checksum fix" print "Apply checksum fix"
cmd = "ucon64 -snes -chk %s 2>&1 > /dev/null" % out_filename cmd = "ucon64 -snes -chk %s 2>&1 > /dev/null" % out_filename
@ -68,4 +67,3 @@ def main():
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View File

@ -1,6 +1,6 @@
import os
import sys import sys
def main(): def main():
bank_size = 2 ** 15 bank_size = 2 ** 15
@ -9,21 +9,19 @@ def main():
bank_final = 32 bank_final = 32
offset_skip = bank_skip * bank_size offset_skip = bank_skip * bank_size
rom = open(sys.argv[1],"r").read() rom = open(sys.argv[1], "r").read()
out = open(sys.argv[1].replace(".smc",".pad"),"w") out = open(sys.argv[1].replace(".smc", ".pad"), "w")
out.write(rom[:( bank_skip * bank_size)]) out.write(rom[:(bank_skip * bank_size)])
for bank in range(bank_skip,bank_final): for bank in range(bank_skip, bank_final):
pattern = 55 + bank pattern = 55 + bank
print "Pad %i Bank with %02x" % (bank, pattern) print "Pad %i Bank with %02x" % (bank, pattern)
for i in range(0,bank_size): for i in range(0, bank_size):
out.write(chr(pattern)) out.write(chr(pattern))
out.close() out.close()
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View File

@ -1,14 +1,11 @@
import string
import math import math
import sys
M_PI = 3.14159265358979323846 M_PI = 3.14159265358979323846
def sine(val, r, scale, stepping):
def sine(val,r,scale,stepping): global M_PI, flip
global M_PI,flip re = int(math.sin(val * (M_PI * scale) / r) * r) + r
re = int(math.sin(val*(M_PI*scale)/r)*r) + r
re = re & 0xff re = re & 0xff
re = re * stepping re = re * stepping
return re return re
@ -20,19 +17,12 @@ def main():
upper = 0xff upper = 0xff
s = "#define PWM_SINE_MAX %i\nuint8_t pwm_sine_table[] = {\n" % cnt s = "#define PWM_SINE_MAX %i\nuint8_t pwm_sine_table[] = {\n" % cnt
for i in range(0,cnt): for i in range(0, cnt):
if i > 0 and i%16==0: if i > 0 and i % 16 == 0:
s+="\n" s += "\n"
s +="0x%02x," % sine(i,upper/2,(float(upper)/cnt),stepping) s += "0x%02x," % sine(i, upper / 2, (float(upper) / cnt), stepping)
s=s[:-1] s = s[:-1]
s+="\n};\n" s += "\n};\n"
print s print s
main() main()

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