first commit
This commit is contained in:
48
make_adf.py
Normal file
48
make_adf.py
Normal file
@@ -0,0 +1,48 @@
|
||||
#!/usr/bin/env python3
|
||||
import struct
|
||||
|
||||
def calc_bootblock_checksum(data):
|
||||
"""Calculate Amiga bootblock checksum"""
|
||||
# Clear checksum field first
|
||||
data = bytearray(data)
|
||||
struct.pack_into('>I', data, 4, 0)
|
||||
|
||||
# Sum all longwords with carry
|
||||
chksum = 0
|
||||
for i in range(0, 1024, 4):
|
||||
val = struct.unpack_from('>I', data, i)[0]
|
||||
chksum += val
|
||||
if chksum > 0xFFFFFFFF:
|
||||
chksum = (chksum & 0xFFFFFFFF) + 1
|
||||
|
||||
# Return NOT of sum
|
||||
chksum = (~chksum) & 0xFFFFFFFF
|
||||
return chksum
|
||||
|
||||
# Read files
|
||||
with open('boot.bin', 'rb') as f:
|
||||
boot = bytearray(f.read())
|
||||
|
||||
with open('game.bin', 'rb') as f:
|
||||
game = f.read()
|
||||
|
||||
# Pad bootblock to 1024 bytes
|
||||
if len(boot) < 1024:
|
||||
boot += b'\x00' * (1024 - len(boot))
|
||||
|
||||
# Calculate and set checksum
|
||||
chksum = calc_bootblock_checksum(boot)
|
||||
struct.pack_into('>I', boot, 4, chksum)
|
||||
print(f"Bootblock checksum: 0x{chksum:08X}")
|
||||
|
||||
# Create ADF
|
||||
adf = bytearray(880 * 1024)
|
||||
adf[0:1024] = boot
|
||||
adf[1024:1024+len(game)] = game
|
||||
|
||||
# Write ADF
|
||||
with open('giochino.adf', 'wb') as f:
|
||||
f.write(adf)
|
||||
|
||||
print(f"Created giochino.adf ({len(adf)} bytes)")
|
||||
print(f"Game size: {len(game)} bytes")
|
||||
Reference in New Issue
Block a user