Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- # This program accepts as input the files apple1.rom and cassette.rom,
- # which should be 256-byte binary files of Apple 1 firmware, and generates
- # nibble-wide files suitable for MAME. It also writes to standard output
- # the ROM_LOAD_NIB_xxx directives that should be used in the MESS
- # src/mess/drivers/apple1.c source file.
- # Copyright 2011 Eric Smith <eric@brouhaha.com>
- #
- # This program is free software; you can redistribute and/or modify it
- # under the terms of the GNU General Public License version 3 as
- # published by the Free Software Foundation.
- #
- # This program is distributed in the hope that it will be useful, but
- # WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- # General Public License for more details.
- #
- # The text of the license may be found online at:
- # http://www.brouhaha.com/~eric/software/GPLv3
- # or:
- # http://www.gnu.org/licenses/gpl-3.0.txt
- import hashlib
- import zlib
- def crc_str (data):
- crc32 = zlib.crc32 (data) & 0xffffffff
- return "%08x" % crc32
- def sha1_str (data):
- h = hashlib.new ('sha1')
- h.update (data)
- return h.hexdigest ()
- def splitrom (byte_fn, addr, low_fn, high_fn):
- with open (byte_fn, 'rb') as byte_f:
- data = byte_f.read ()
- low = ''
- high = ''
- for i in range (len (data)):
- low += chr (ord (data [i]) & 0x0f)
- high += chr (ord (data [i]) >> 4)
- print '\tROM_LOAD_NIB_HIGH( "%s", 0x%04x, 0x%04x, CRC(%s) SHA1(%s))' % (high_fn, addr, len (high), crc_str (high), sha1_str (high))
- print '\tROM_LOAD_NIB_LOW( "%s", 0x%04x, 0x%04x, CRC(%s) SHA1(%s))' % (low_fn, addr, len (low), crc_str (low), sha1_str (low))
- with open (low_fn, 'wb') as low_f:
- low_f.write (low)
- with open (high_fn, 'wb') as high_f:
- high_f.write (high)
- splitrom ('apple1.rom',
- 0xff00,
- 'apple-a1.a1', # low nibble
- 'apple-a2.a2') # high nibble
- splitrom ('cassette.rom',
- 0xc100,
- 'apple-a4.4', # low nibble
- 'apple-a3.3') # high nibble
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement