Amiga ADF Generator
From CiaransWiki
Python script to generate an ADF file for transfer to an Amiga, given some assembled binary code. See this post for more details.
A much improved version is discussed in this post and can be found in the git repository.
import struct
import sys
bootfile="boot.bin"
outfile="test.adf"
#Read our bootblock data...
print "Reading "+bootfile
f=open(bootfile,'rb')
bootblock=f.read()
f.close()
#Make sure it will fit...
if len(bootblock)>1024:
print("The bootblock is too large")
sys.exit(1)
#Pad the loaded bootblock data out to the correct length, i.e. 1024 bytes,
#which is 2 sectors...
while(len(bootblock)<1024):
bootblock+="\0"
#Calculate checksum of bootblock
checksum=0
for i in range(1024/4):
thislong=ord(bootblock[i*4])<<24
thislong+=ord(bootblock[i*4+1])<<16
thislong+=ord(bootblock[i*4+2])<<8
thislong+=ord(bootblock[i*4+3])
checksum+=thislong
if checksum>0xFFFFFFFF:
checksum-=0x100000000
checksum+=1
checksum^=0xFFFFFFFF
bootblock=bootblock[:4]+struct.pack('>L',checksum)+bootblock[8:]
#Write the ADF file, which is basically the entire disk's worth of data
#arranged sector by track for a total length of 901120 bytes...
of=open(outfile,'wb')
of.write(bootblock)
#Pad any unused disk space with 0's...
restofdisk=901120-len(bootblock)
for i in range(restofdisk):
of.write('\0')
of.close()
print "Generated "+outfile