Skip to content

Instantly share code, notes, and snippets.

@SergioFLS
Last active July 1, 2018 22:46
Show Gist options
  • Save SergioFLS/fc10941d672ff6084991c2aed175e941 to your computer and use it in GitHub Desktop.
Save SergioFLS/fc10941d672ff6084991c2aed175e941 to your computer and use it in GitHub Desktop.
.gb/.gbc converter tool to text game boy file extension (.tgb)
# gb2tgb by SergioFLS
# made for https://scratch.mit.edu/discuss/topic/60460/?page=1
# NOTE: this was only tested on Python 3.6.5. 3.x versions might work, but probably 2.x won't.
'''
links that helped me:
https://stackoverflow.com/questions/3964245/convert-file-to-hex-string-python
https://stackoverflow.com/questions/606191/convert-bytes-to-a-string
https://stackoverflow.com/questions/23766383/python-error-typeerror-function-takes-exactly-1-argument-5-given
https://stackoverflow.com/questions/9210525/how-do-i-convert-hex-to-decimal-in-python
http://www.pythonforbeginners.com/files/reading-and-writing-files-in-python
https://scratch.mit.edu/projects/34791164/ (the shoo**'s comment)
'''
import binascii
print("gb2tgb by SergioFLS\nInsert file name:")
filename = input()
out = open("output.tgb","w")
with open(filename, 'rb') as f:
content = f.read()
romfile = binascii.hexlify(content)
romfile_dec = romfile.decode("utf-8")
i1 = 0
for i in range(0,len(romfile_dec)//2):
romchar = romfile_dec[i1] + romfile_dec[i1+1]
out.write(str(int(romchar,16)) + "\n")
i1+=2
print("ROM converted sucessfully")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment