Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- # -*- coding: latin-1 -*-
- import struct
- def readBits(bits, currentByte, bitCount, file):
- num = 0
- for i in range(0, bits):
- if bitCount > 7:
- currentByte = struct.unpack('B', file.read(1))[0]
- bitCount = 0
- newBit = (currentByte >> (7 - bitCount)) & 1
- bitCount += 1
- num = (num << 1) + newBit
- return num, currentByte, bitCount
- def numberToLetter(num):
- return {
- 0x00: ' ',
- 0x01: '?',
- 0x02: 'A',
- 0x03: 'B',
- 0x04: 'C',
- 0x05: 'D',
- 0x06: 'E',
- 0x07: 'F',
- 0x08: 'G',
- 0x09: 'H',
- 0x0A: 'I',
- 0x0B: 'J',
- 0x0C: 'K',
- 0x0D: 'L',
- 0x0E: 'M',
- 0x0F: 'N',
- 0x10: 'O',
- 0x11: 'P',
- 0x12: 'Q',
- 0x13: 'R',
- 0x14: 'S',
- 0x15: 'T',
- 0x16: 'U',
- 0x17: 'V',
- 0x18: 'W',
- 0x19: 'X',
- 0x1A: 'Y',
- 0x1B: 'Z',
- 0x1C: '?',
- 0x1D: '0',
- 0x1E: '1',
- 0x1F: '2',
- 0x20: '3',
- 0x21: '4',
- 0x22: '5',
- 0x23: '6',
- 0x24: '7',
- 0x25: '8',
- 0x26: '9',
- 0x27: '!',
- 0x28: ',',
- 0x29: '.',
- 0x2A: "'",
- 0x2F: unichr(0x00C4), #Ä
- 0x30: unichr(0x00C8), #È
- 0x31: unichr(0x00C2), #Â
- 0x32: unichr(0x00DF), #ß
- 0x33: '-',
- 0x34: unichr(0x00C9), #É
- 0x35: unichr(0x00D1), #Ñ
- 0x36: unichr(0x00C0), #À
- 0x37: unichr(0x00D6), #Ö
- 0x38: unichr(0x00DC), #Ü
- 0x39: unichr(0x00CA), #Ê
- 0x3A: unichr(0x00BF), #¿
- 0x3B: unichr(0x00A1), #¡
- }.get(num, '?')
- def dumpTable(num, infile, outfile):
- if num > 3:
- bank = 0xC
- else:
- bank = 0x3
- infile.seek(0xC026 + 2*num)
- pointer = struct.unpack('H', infile.read(2))[0]
- infile.seek(pointer + 0x4000 * (bank - 1))
- currentByte = 0
- bitCount = 8
- for i in range(0, 256):
- wordLength, currentByte, bitCount = readBits(5, currentByte, bitCount, infile)
- word = ""
- for j in range(0, wordLength):
- letter, currentByte, bitCount = readBits(6, currentByte, bitCount, infile)
- word += numberToLetter(letter)
- outfile.write(word.encode('UTF-8') + "\n")
- # open rom file
- with open("rom.gb", "rb") as rom:
- #words = open("table.txt", "wb")
- for i in range(0, 5):
- with open("table"+str(i)+".txt", "wb") as words:
- dumpTable(i, rom, words)
Add Comment
Please, Sign In to add comment