Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import struct, sys
p = ("\x30\x42", "\x42\x30")
pnewdata = "\x56\x42"
penddata = "\x56\x30"
def add_kernel_byte(c):
s = pnewdata
c = ord(c)
csum = 1
for i in xrange(8):
bit = (c >> i) & 1
s += p[bit]
csum ^= bit
s += p[csum]
return s
def add_loader_byte(c):
s = ""
c = ord(c)
for i in xrange(8):
bit = (c >> i) & 1
s += "\x26\x58"[bit]
return s
def add_kernel_block(data, headersize, pausesize):
s = "\x30" * headersize
for c in data:
s += add_kernel_byte(c)
s += "\x30" * 0x301
for c in data.replace("\x89\x88\x87\x86\x85\x84\x83\x82\x81", "\x09\x08\x07\x06\x05\x04\x03\x02\x01"):
s += add_kernel_byte(c)
s += "\x00" + struct.pack("<I", pausesize)[0:3]
return s
def add_loader_block(data, pausesize):
s = ""
for i in xrange(32):
s += add_loader_byte("\x01")
s += "\x58"
for c in data:
s += add_loader_byte(c)
s += "\x00" + struct.pack("<I", pausesize)[0:3]
return s
f = open("P0001014.A44", "rb")
f.read(512)
tapdata = ""
datablocks = []
while True:
header = f.read(10)
if len(header) == 0:
break
dunno1, dunno2, dunno3, sz, dunno4 = struct.unpack(">HHHHH", header)
print "%x %x %x %x %x" % (dunno1, dunno2, dunno3, sz, dunno4)
if sz < 10:
print "TOO SMALL"
break
data = f.read(sz - 10)
datablocks.append(data)
tapdata = add_kernel_block(datablocks[0], 0x6a00, 320000)
tapdata += add_kernel_block(datablocks[1], 0x2000, 2280000)
tapdata += add_loader_block(datablocks[2], 2400000)
tapdata += add_loader_block(datablocks[3], 2380000)
tapdata += add_loader_block(datablocks[4], 2380000)
tapdata += add_loader_block(datablocks[5], 2380000)
tapdata += add_loader_block(datablocks[6], 9120000)
tapdata += add_kernel_block(datablocks[7], 0x2000, 320000)
tapdata += add_kernel_block(datablocks[8], 0x2000, 2300000)
tapdata += add_loader_block(datablocks[9], 2380000)
tapdata += add_loader_block(datablocks[10], 2380000)
tapdata += add_loader_block(datablocks[11], 4926240)
of = open("output.tap", "wb")
of.write("C64-TAPE-RAW\x01\x00\x00\x00" + struct.pack("<I", len(tapdata)) + tapdata)
of.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment