Cleanup
This commit is contained in:
parent
8a190c9f10
commit
d5560260b3
16
scripts/b.py
16
scripts/b.py
@ -1,28 +1,26 @@
|
||||
#!/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)
|
||||
v = int(sys.argv[1], 16)
|
||||
else:
|
||||
v = int(sys.argv[1])
|
||||
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
|
||||
for i in range(bits - 1, -1, -1):
|
||||
s = 1 << i
|
||||
if v & s:
|
||||
sys.stdout.write("1")
|
||||
else:
|
||||
sys.stdout.write("0")
|
||||
if i and not i%8:
|
||||
if i and not i % 8:
|
||||
sys.stdout.write(" ")
|
||||
|
||||
|
||||
|
||||
print
|
||||
print "0x%x"% v
|
||||
print "0x%x" % v
|
||||
print v
|
||||
|
||||
|
||||
@ -1,32 +1,38 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import binascii
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import glob
|
||||
import zlib
|
||||
|
||||
|
||||
TARGET="/Users/david/Dropbox/Tech/Quickdev16/roms/08"
|
||||
TARGET = "/Users/david/Dropbox/Tech/Quickdev16/roms/08"
|
||||
|
||||
count = 0
|
||||
total_zip_len = 0
|
||||
total_comp_len = 0
|
||||
|
||||
g = glob.glob(os.path.join(TARGET,"*"))
|
||||
g = glob.glob(os.path.join(TARGET, "*"))
|
||||
|
||||
for name in g:
|
||||
count +=1
|
||||
data = open(name,'r').read()
|
||||
count += 1
|
||||
data = open(name, 'r').read()
|
||||
data_len = len(data)
|
||||
comp = binascii.rlecode_hqx(data)
|
||||
comp_len = len(comp)
|
||||
comp_pre = comp_len / ( data_len / 100 )
|
||||
comp_pre = comp_len / (data_len / 100)
|
||||
total_comp_len += comp_pre
|
||||
|
||||
zip_data = zlib.compress(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
|
||||
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)
|
||||
|
||||
@ -1,30 +1,30 @@
|
||||
|
||||
import ctypes
|
||||
import sys
|
||||
import os
|
||||
|
||||
def crc_xmodem_update(crc,data):
|
||||
|
||||
def crc_xmodem_update(crc, data):
|
||||
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:
|
||||
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
|
||||
|
||||
|
||||
def do_crc(data):
|
||||
crc = ctypes.c_uint16(0)
|
||||
for idx,char in enumerate(data):
|
||||
crc = crc_xmodem_update(crc,ctypes.c_uint8(ord(char)))
|
||||
for idx, char in enumerate(data):
|
||||
crc = crc_xmodem_update(crc, ctypes.c_uint8(ord(char)))
|
||||
return crc.value
|
||||
|
||||
|
||||
def test_performance():
|
||||
data=str()
|
||||
data = str()
|
||||
fd = open("/dev/urandom")
|
||||
for i in range(0,256):
|
||||
data+= fd.read(1024)
|
||||
for i in range(0, 256):
|
||||
data += fd.read(1024)
|
||||
sys.stdout.write("*")
|
||||
sys.stdout.flush()
|
||||
print
|
||||
@ -33,16 +33,14 @@ def test_performance():
|
||||
|
||||
|
||||
def test_algo():
|
||||
data='david'
|
||||
data='da'
|
||||
data = 'david'
|
||||
data = 'da'
|
||||
print "%x" % do_crc(data)
|
||||
|
||||
|
||||
def main():
|
||||
#import cProfile
|
||||
#cProfile.run('test_performance()')
|
||||
if sys.argv[1].endswith(".smc"):
|
||||
copy_header= True
|
||||
copy_header = True
|
||||
|
||||
size = os.stat(sys.argv[1])[6]
|
||||
fd = open(sys.argv[1])
|
||||
@ -52,7 +50,7 @@ def main():
|
||||
size = size - 512
|
||||
|
||||
addr = 0x0000
|
||||
step = 2**15
|
||||
step = 2 ** 15
|
||||
result = []
|
||||
while addr < size:
|
||||
try:
|
||||
@ -62,12 +60,10 @@ def main():
|
||||
print "Done"
|
||||
break
|
||||
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))
|
||||
#print result
|
||||
# print result
|
||||
|
||||
if __name__ == '__main__':
|
||||
#test_algo()
|
||||
# test_algo()
|
||||
main()
|
||||
|
||||
|
||||
|
||||
@ -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()
|
||||
@ -1,2 +0,0 @@
|
||||
ln -s `pwd`/webpy/web .
|
||||
|
||||
@ -1,46 +1,32 @@
|
||||
|
||||
|
||||
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):
|
||||
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
|
||||
for j in range(0,m+1):
|
||||
c[0,j] = j
|
||||
for i in range(0, n + 1):
|
||||
c[i, 0] = i
|
||||
for j in range(0, m + 1):
|
||||
c[0, j] = j
|
||||
|
||||
for i in range(1,n+1):
|
||||
for j in range(1,m+1):
|
||||
x = c[i-1,j]+1
|
||||
y = c[i,j-1]+1
|
||||
if a[i-1] == b[j-1]:
|
||||
z = c[i-1,j-1]
|
||||
for i in range(1, n + 1):
|
||||
for j in range(1, m + 1):
|
||||
x = c[i - 1, j] + 1
|
||||
y = c[i, j - 1] + 1
|
||||
if a[i - 1] == b[j - 1]:
|
||||
z = c[i - 1, j - 1]
|
||||
else:
|
||||
z = c[i-1,j-1]+1
|
||||
c[i,j] = min(x,y,z)
|
||||
return c[n,m]
|
||||
z = c[i - 1, j - 1] + 1
|
||||
c[i, j] = min(x, y, z)
|
||||
return c[n, m]
|
||||
|
||||
paramiko.util.log_to_file('rom_sftp.log')
|
||||
|
||||
@ -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,11 +68,10 @@ 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,)]:
|
||||
dirname = os.path.join(path,"%02i" % i)
|
||||
for i in [(1,), (2,), (4,), (8,), (16,)]:
|
||||
dirname = os.path.join(path, "%02i" % i)
|
||||
if not os.path.isdir(dirname):
|
||||
os.mkdir(dirname)
|
||||
print "#" * 60
|
||||
@ -105,21 +94,22 @@ def main():
|
||||
AND
|
||||
rom_region like "Europe%"
|
||||
ORDER BY file_name
|
||||
''',i)
|
||||
|
||||
''', i)
|
||||
|
||||
last_name = str()
|
||||
for row in c:
|
||||
name,size,filename = row
|
||||
d = distance(os.path.basename(filename),os.path.basename(last_name))
|
||||
name, size, filename = row
|
||||
d = distance(
|
||||
os.path.basename(filename), os.path.basename(last_name))
|
||||
if d < 7:
|
||||
print "Skip ",filename
|
||||
print "Skip ", filename
|
||||
continue
|
||||
filename_dst = os.path.join(dirname,os.path.basename(filename))
|
||||
print "Remote: %s -> %s" % ( filename,filename_dst)
|
||||
filename_dst = os.path.join(
|
||||
dirname, os.path.basename(filename))
|
||||
print "Remote: %s -> %s" % (filename, filename_dst)
|
||||
last_name = filename
|
||||
try:
|
||||
sftp.get(filename,filename_dst)
|
||||
sftp.get(filename, filename_dst)
|
||||
except Exception, e:
|
||||
print '*** Caught exception: %s: %s' % (e.__class__, e)
|
||||
traceback.print_exc()
|
||||
@ -138,10 +128,3 @@ def main():
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
127
scripts/rom.py
127
scripts/rom.py
@ -18,43 +18,40 @@ import pprint
|
||||
# 4 ROM, RAM and DSP1 chip
|
||||
# 5 ROM, Save RAM and DSP1 chip
|
||||
# 19 ROM and Super FX chip
|
||||
#227 ROM, RAM and GameBoy data
|
||||
#246 ROM and DSP2 chip
|
||||
# 227 ROM, RAM and GameBoy data
|
||||
# 246 ROM and DSP2 chip
|
||||
|
||||
|
||||
#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
|
||||
#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
|
||||
#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 ................
|
||||
#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
|
||||
#13 T.M.N.T. 4
|
||||
#14 Konami
|
||||
#15 U.S.A.
|
||||
#16 1048576 Bytes (8.0000 Mb)
|
||||
#18 Padded: Maybe, 105 Bytes (0.0008 Mb)
|
||||
#19 Interleaved/Swapped: No
|
||||
#20 Backup unit/emulator header: No
|
||||
#21 HiROM: No
|
||||
#22 Internal size: 8 Mb
|
||||
#23 ROM type: (0) ROM
|
||||
#24 ROM speed: 200 ns (SlowROM)
|
||||
#25 SRAM: No
|
||||
#26 Version: 1.0
|
||||
#27 Checksum: Ok, 0x1683 (calculated) == 0x1683 (internal)
|
||||
#28 Inverse checksum: Ok, 0xe97c (calculated) == 0xe97c (internal)
|
||||
#29 Checksum (CRC32): 0x5940bd99
|
||||
#31 This ROM has no backup unit header
|
||||
# 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
|
||||
# 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
|
||||
# 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 ........
|
||||
# 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
|
||||
# 13 T.M.N.T. 4
|
||||
# 14 Konami
|
||||
# 15 U.S.A.
|
||||
# 16 1048576 Bytes (8.0000 Mb)
|
||||
# 18 Padded: Maybe, 105 Bytes (0.0008 Mb)
|
||||
# 19 Interleaved/Swapped: No
|
||||
# 20 Backup unit/emulator header: No
|
||||
# 21 HiROM: No
|
||||
# 22 Internal size: 8 Mb
|
||||
# 23 ROM type: (0) ROM
|
||||
# 24 ROM speed: 200 ns (SlowROM)
|
||||
# 25 SRAM: No
|
||||
# 26 Version: 1.0
|
||||
# 27 Checksum: Ok, 0x1683 (calculated) == 0x1683 (internal)
|
||||
# 28 Inverse checksum: Ok, 0xe97c (calculated) == 0xe97c (internal)
|
||||
# 29 Checksum (CRC32): 0x5940bd99
|
||||
# 31 This ROM has no backup unit header
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
swc_header_tpl='''
|
||||
swc_header_tpl = '''
|
||||
Backup unit header info (SWC)
|
||||
|
||||
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():
|
||||
try:
|
||||
os.unlink("roms.sqlite3")
|
||||
@ -109,10 +104,11 @@ def createdb():
|
||||
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]
|
||||
rom_size = 0
|
||||
rom_mb = 0
|
||||
@ -146,49 +142,58 @@ 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):
|
||||
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:
|
||||
for idx,line in enumerate(out):
|
||||
for idx, line in enumerate(out):
|
||||
if line is None:
|
||||
continue
|
||||
print idx,line
|
||||
print idx, line
|
||||
sys.exit()
|
||||
|
||||
query = """INSERT INTO roms
|
||||
@ -225,7 +230,7 @@ def process(conn,c,file_name,out):
|
||||
swc_dram_mode,
|
||||
swc_sram_size)
|
||||
|
||||
c.execute(query,data)
|
||||
c.execute(query, data)
|
||||
conn.commit()
|
||||
|
||||
|
||||
@ -238,29 +243,31 @@ def ucon64_info(filename):
|
||||
e.close()
|
||||
w.close()
|
||||
if len(err):
|
||||
return False,err
|
||||
return out,err
|
||||
return False, err
|
||||
return out, err
|
||||
|
||||
|
||||
def clean(s):
|
||||
s = s.replace("\n","")
|
||||
s = s.replace("\n", "")
|
||||
if not len(s):
|
||||
return None
|
||||
return s
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
conn,c = createdb()
|
||||
conn, c = createdb()
|
||||
|
||||
path = sys.argv[1]
|
||||
files = glob.glob(path + "/*")
|
||||
for filename in files:
|
||||
try:
|
||||
r,err = ucon64_info(filename)
|
||||
r, err = ucon64_info(filename)
|
||||
if not r:
|
||||
print err
|
||||
continue
|
||||
r = map(clean,r)
|
||||
process(conn,c,filename,r)
|
||||
r = map(clean, r)
|
||||
process(conn, c, filename, r)
|
||||
except (KeyboardInterrupt, SystemExit):
|
||||
print "Saving DB..."
|
||||
c.close()
|
||||
@ -273,7 +280,3 @@ def main():
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -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]):
|
||||
@ -23,10 +23,10 @@ def main():
|
||||
if not os.path.isfile(sys.argv[2]):
|
||||
error("Can't open %s file" % sys.argv[2])
|
||||
|
||||
rom = open(sys.argv[1],"r").read()
|
||||
code = open(sys.argv[2],"r").read()
|
||||
rom = open(sys.argv[1], "r").read()
|
||||
code = open(sys.argv[2], "r").read()
|
||||
out_filename = sys.argv[1].split(".")[0] + ".inject"
|
||||
out = open(out_filename,"w")
|
||||
out = open(out_filename, "w")
|
||||
|
||||
irq_vector = 0x7FE0
|
||||
bank_size = 1 << 15
|
||||
@ -34,32 +34,31 @@ def main():
|
||||
rom_len = len(rom)
|
||||
bank_cnt = rom_len / bank_size
|
||||
try:
|
||||
addr = int(sys.argv[3],16)
|
||||
addr = int(sys.argv[3], 16)
|
||||
except:
|
||||
error("Expect %s in hex" % sys.argv[3])
|
||||
|
||||
addr_patch = struct.pack(">H",addr)
|
||||
|
||||
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))
|
||||
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))
|
||||
|
||||
print "Rom size: 0x%08x (%i)" % (rom_len,rom_len)
|
||||
print "Code size: 0x%04x (%i)" % (code_len,code_len)
|
||||
print "Banks: 0x%04x (%i)" % (bank_cnt,bank_cnt)
|
||||
print "Rom size: 0x%08x (%i)" % (rom_len, rom_len)
|
||||
print "Code size: 0x%04x (%i)" % (code_len, code_len)
|
||||
print "Banks: 0x%04x (%i)" % (bank_cnt, bank_cnt)
|
||||
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])
|
||||
out.write(rom[addr + code_len:irq_vector])
|
||||
out.write(addr_patch)
|
||||
out.write(rom[irq_vector+2:])
|
||||
print "%i Bytes written to %s" % (out.tell(),out_filename)
|
||||
out.write(rom[irq_vector + 2:])
|
||||
print "%i Bytes written to %s" % (out.tell(), out_filename)
|
||||
out.close()
|
||||
print "Apply checksum fix"
|
||||
cmd = "ucon64 -snes -chk %s 2>&1 > /dev/null" % out_filename
|
||||
@ -68,4 +67,3 @@ def main():
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
bank_size = 2 ** 15
|
||||
@ -9,21 +9,19 @@ def main():
|
||||
bank_final = 32
|
||||
|
||||
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
|
||||
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.close()
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
|
||||
@ -1,14 +1,11 @@
|
||||
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
|
||||
def sine(val, r, scale, stepping):
|
||||
global M_PI, flip
|
||||
re = int(math.sin(val * (M_PI * scale) / r) * r) + r
|
||||
re = re & 0xff
|
||||
re = re * stepping
|
||||
return re
|
||||
@ -20,19 +17,12 @@ def main():
|
||||
upper = 0xff
|
||||
|
||||
s = "#define PWM_SINE_MAX %i\nuint8_t pwm_sine_table[] = {\n" % cnt
|
||||
for i in range(0,cnt):
|
||||
if i > 0 and i%16==0:
|
||||
s+="\n"
|
||||
s +="0x%02x," % sine(i,upper/2,(float(upper)/cnt),stepping)
|
||||
s=s[:-1]
|
||||
s+="\n};\n"
|
||||
for i in range(0, cnt):
|
||||
if i > 0 and i % 16 == 0:
|
||||
s += "\n"
|
||||
s += "0x%02x," % sine(i, upper / 2, (float(upper) / cnt), stepping)
|
||||
s = s[:-1]
|
||||
s += "\n};\n"
|
||||
print s
|
||||
|
||||
main()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -1 +0,0 @@
|
||||
Subproject commit 2a5acf5a834f9c2fd98d5c2be563429821feab3b
|
||||
Loading…
x
Reference in New Issue
Block a user