Skip to content

Instantly share code, notes, and snippets.

@Frank-Buss
Created September 25, 2019 04:19
Show Gist options
  • Save Frank-Buss/4e9b9ce0a58388a425c259cbc376d61c to your computer and use it in GitHub Desktop.
Save Frank-Buss/4e9b9ce0a58388a425c259cbc376d61c to your computer and use it in GitHub Desktop.
Converts a VGM file to BASIC POKEs
#!/usr/bin/python3
import argparse
# parse arguments
parser = argparse.ArgumentParser(formatter_class=argparse.RawTextHelpFormatter,
description='Converts a VGM file to BASIC POKEs.')
parser.add_argument('input', help='the input file name')
args = parser.parse_args()
# calculate absolute data offset
data = open(args.input, "rb").read()
i = data[0x34]
i = i + (data[0x35] << 8)
i = i + (data[0x36] << 16)
i = i + (data[0x37] << 24)
i = i + 0x34
print("absolute data offset: %04x" % i)
# read next byte
def next():
global i
d = data[i]
i = i + 1
return d
# print wait info
def wait(n):
print("wait %i frames" % n)
# start convert
line = 10
while i < len(data):
d = next()
if d == 0x54:
reg = next()
d = next()
print("%i POKE $9FE0, $%02X : POKE $9FE1, $%02X" % (line, reg, d))
line = line + 10
elif d == 0x61:
n = next()
n = n + (next() << 8)
wait(n)
elif d == 0x62:
wait(735)
elif d == 0x63:
wait(882)
elif d == 0x66:
break
elif d == 0xc0:
# Sega PCM
i = i + 3
elif d >= 0x70 and d <= 0x7f:
wait(d & 0xf)
else:
print("unknown command: %02x\n" % d);
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment