Guest User

Battle for Olympus Tabler Dumper

a guest
Feb 7th, 2015
313
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.30 KB | None | 0 0
  1. #!/usr/bin/python
  2. # -*- coding: latin-1 -*-
  3.  
  4. import struct
  5.  
  6. def readBits(bits, currentByte, bitCount, file):
  7.   num = 0
  8.   for i in range(0, bits):
  9.     if bitCount > 7:
  10.       currentByte = struct.unpack('B', file.read(1))[0]
  11.       bitCount = 0
  12.    
  13.     newBit = (currentByte >> (7 - bitCount)) & 1
  14.     bitCount += 1
  15.    
  16.     num = (num << 1) + newBit
  17.   return num, currentByte, bitCount
  18.  
  19. def numberToLetter(num):
  20.   return {
  21.     0x00: ' ',
  22.     0x01: '?',
  23.     0x02: 'A',
  24.     0x03: 'B',
  25.     0x04: 'C',
  26.     0x05: 'D',
  27.     0x06: 'E',
  28.     0x07: 'F',
  29.     0x08: 'G',
  30.     0x09: 'H',
  31.     0x0A: 'I',
  32.     0x0B: 'J',
  33.     0x0C: 'K',
  34.     0x0D: 'L',
  35.     0x0E: 'M',
  36.     0x0F: 'N',
  37.     0x10: 'O',
  38.     0x11: 'P',
  39.     0x12: 'Q',
  40.     0x13: 'R',
  41.     0x14: 'S',
  42.     0x15: 'T',
  43.     0x16: 'U',
  44.     0x17: 'V',
  45.     0x18: 'W',
  46.     0x19: 'X',
  47.     0x1A: 'Y',
  48.     0x1B: 'Z',
  49.     0x1C: '?',
  50.     0x1D: '0',
  51.     0x1E: '1',
  52.     0x1F: '2',
  53.     0x20: '3',
  54.     0x21: '4',
  55.     0x22: '5',
  56.     0x23: '6',
  57.     0x24: '7',
  58.     0x25: '8',
  59.     0x26: '9',
  60.     0x27: '!',
  61.     0x28: ',',
  62.     0x29: '.',
  63.     0x2A: "'",
  64.     0x2F: unichr(0x00C4),
  65.     0x30: unichr(0x00C8),
  66.     0x31: unichr(0x00C2),
  67.     0x32: unichr(0x00DF),
  68.     0x33: '-',
  69.     0x34: unichr(0x00C9),
  70.     0x35: unichr(0x00D1),
  71.     0x36: unichr(0x00C0),
  72.     0x37: unichr(0x00D6),
  73.     0x38: unichr(0x00DC),
  74.     0x39: unichr(0x00CA),
  75.     0x3A: unichr(0x00BF), #¿
  76.     0x3B: unichr(0x00A1),
  77.     }.get(num, '?')
  78.  
  79. def dumpTable(num, infile, outfile):
  80.   if num > 3:
  81.     bank = 0xC
  82.   else:
  83.     bank = 0x3
  84.        
  85.   infile.seek(0xC026 + 2*num)
  86.   pointer = struct.unpack('H', infile.read(2))[0]
  87.   infile.seek(pointer + 0x4000 * (bank - 1))
  88.  
  89.   currentByte = 0
  90.   bitCount = 8
  91.    
  92.   for i in range(0, 256):
  93.     wordLength, currentByte, bitCount = readBits(5, currentByte, bitCount, infile)
  94.     word = ""
  95.     for j in range(0, wordLength):
  96.       letter, currentByte, bitCount = readBits(6, currentByte, bitCount, infile)
  97.       word += numberToLetter(letter)
  98.  
  99.     outfile.write(word.encode('UTF-8') + "\n")
  100.  
  101. # open rom file
  102. with open("rom.gb", "rb") as rom:
  103.   #words = open("table.txt", "wb")
  104.   for i in range(0, 5):
  105.     with open("table"+str(i)+".txt", "wb") as words:
  106.       dumpTable(i, rom, words)
Add Comment
Please, Sign In to add comment