$bootFile = "boot.bin" $gameFile = "game.bin" $adfFile = "giochino.adf" # Read Bootblock $bootBytes = [System.IO.File]::ReadAllBytes($bootFile) if ($bootBytes.Length -lt 1024) { $padding = New-Object byte[] (1024 - $bootBytes.Length) $bootBytes = $bootBytes + $padding } $bootBytes = [byte[]]$bootBytes # Calculate Checksum # Checksum is at offset 4 (4 bytes) # Clear it first $bootBytes[4] = 0 $bootBytes[5] = 0 $bootBytes[6] = 0 $bootBytes[7] = 0 $chk = [uint32]0 for ($i = 0; $i -lt 1024; $i += 4) { # Big Endian ULONG [uint32]$val = ([uint32]$bootBytes[$i] -shl 24) -bor ([uint32]$bootBytes[$i + 1] -shl 16) -bor ([uint32]$bootBytes[$i + 2] -shl 8) -bor [uint32]$bootBytes[$i + 3] # Add with carry handling [uint64]$temp = [uint64]$chk + [uint64]$val if ($temp -gt 4294967295) { $chk = [uint32](($temp -band 4294967295) + 1) } else { $chk = [uint32]$temp } } # NOT operation $chk = $chk -bxor 4294967295 Write-Host "Checksum: $("0x{0:X}" -f $chk)" # Write Checksum back (Big Endian) $bootBytes[4] = ($chk -shr 24) -band 0xFF $bootBytes[5] = ($chk -shr 16) -band 0xFF $bootBytes[6] = ($chk -shr 8) -band 0xFF $bootBytes[7] = $chk -band 0xFF # Read Game $gameBytes = [System.IO.File]::ReadAllBytes($gameFile) Write-Host "Game Size: $($gameBytes.Length) bytes" # Create ADF (880KB) $adfSize = 880 * 1024 $adfBytes = New-Object byte[] $adfSize # Copy Bootblock [System.Array]::Copy($bootBytes, 0, $adfBytes, 0, 1024) # Copy Game (Offset 1024) [System.Array]::Copy($gameBytes, 0, $adfBytes, 1024, $gameBytes.Length) # Save ADF [System.IO.File]::WriteAllBytes($adfFile, $adfBytes) Write-Host "Created $adfFile"