Advertisement
brouhaha

splitroms.py

Jul 17th, 2011
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. # This program accepts as input the files apple1.rom and cassette.rom,
  4. # which should be 256-byte binary files of Apple 1 firmware, and generates
  5. # nibble-wide files suitable for MAME. It also writes to standard output
  6. # the ROM_LOAD_NIB_xxx directives that should be used in the MESS
  7. # src/mess/drivers/apple1.c source file.
  8.  
  9. # Copyright 2011 Eric Smith <eric@brouhaha.com>
  10. #
  11. # This program is free software; you can redistribute and/or modify it
  12. # under the terms of the GNU General Public License version 3 as
  13. # published by the Free Software Foundation.
  14. #
  15. # This program is distributed in the hope that it will be useful, but
  16. # WITHOUT ANY WARRANTY; without even the implied warranty of
  17. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. # General Public License for more details.
  19. #
  20. # The text of the license may be found online at:
  21. # http://www.brouhaha.com/~eric/software/GPLv3
  22. # or:
  23. # http://www.gnu.org/licenses/gpl-3.0.txt
  24.  
  25. import hashlib
  26. import zlib
  27.  
  28. def crc_str (data):
  29. crc32 = zlib.crc32 (data) & 0xffffffff
  30. return "%08x" % crc32
  31.  
  32. def sha1_str (data):
  33. h = hashlib.new ('sha1')
  34. h.update (data)
  35. return h.hexdigest ()
  36.  
  37. def splitrom (byte_fn, addr, low_fn, high_fn):
  38. with open (byte_fn, 'rb') as byte_f:
  39. data = byte_f.read ()
  40. low = ''
  41. high = ''
  42. for i in range (len (data)):
  43. low += chr (ord (data [i]) & 0x0f)
  44. high += chr (ord (data [i]) >> 4)
  45. 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))
  46. 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))
  47. with open (low_fn, 'wb') as low_f:
  48. low_f.write (low)
  49. with open (high_fn, 'wb') as high_f:
  50. high_f.write (high)
  51.  
  52. splitrom ('apple1.rom',
  53. 0xff00,
  54. 'apple-a1.a1', # low nibble
  55. 'apple-a2.a2') # high nibble
  56.  
  57. splitrom ('cassette.rom',
  58. 0xc100,
  59. 'apple-a4.4', # low nibble
  60. 'apple-a3.3') # high nibble
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement