package io.github.applecommander.acx; import java.util.Arrays; import java.util.function.BiConsumer; import java.util.function.Function; import java.util.logging.Logger; import com.webcodepro.applecommander.storage.Disk; import com.webcodepro.applecommander.storage.DiskException; import com.webcodepro.applecommander.storage.FileEntry; import com.webcodepro.applecommander.storage.FormattedDisk; import com.webcodepro.applecommander.storage.os.dos33.DosFormatDisk; import io.github.applecommander.acx.fileutil.FileUtils; public enum SystemType { DOS(OrderType.DOS, SystemType::enforce140KbDisk, SystemType::copyDosSystemTracks), // OzdosFormatDisk is structured on top of ProDOS blocks in the implementation. OZDOS(OrderType.PRODOS, SystemType::enforce800KbDisk, SystemType::copyDosSystemTracks), // UnidosFormatDisk is structured on top of DOS track/sectors in the implementation. UNIDOS(OrderType.DOS, SystemType::enforce800KbDisk, SystemType::copyDosSystemTracks), PRODOS(OrderType.PRODOS, SystemType::enforce140KbOr800KbUpTo32MbDisk, SystemType::copyProdosSystemFiles), PASCAL(OrderType.PRODOS, SystemType::enforce140KbDisk, SystemType::copyPascalSystemFiles); static Logger LOG = Logger.getLogger(SystemType.class.getName()); private OrderType defaultOrderType; private Function enforceDiskSizeFn; private BiConsumer copySystemFn; private SystemType(OrderType defaultOrderType, Function enforceDiskSizeFn, BiConsumer copySystemFn) { this.defaultOrderType = defaultOrderType; this.enforceDiskSizeFn = enforceDiskSizeFn; this.copySystemFn = copySystemFn; } public OrderType defaultOrderType() { return defaultOrderType; } public int validateSize(int size) { return enforceDiskSizeFn.apply(size); } public void copySystem(FormattedDisk target, FormattedDisk source) { copySystemFn.accept(target, source); } static int enforce140KbDisk(int size) { if (size != Disk.APPLE_140KB_DISK) { LOG.warning("Setting image size to 140KB"); } return Disk.APPLE_140KB_DISK; } static int enforce800KbDisk(int size) { if (size != Disk.APPLE_800KB_DISK) { LOG.warning("Setting image size to 800KB."); } return Disk.APPLE_800KB_DISK; } static int enforce140KbOr800KbUpTo32MbDisk(int size) { if (size <= Disk.APPLE_140KB_DISK) { return enforce140KbDisk(size); } if (size <= Disk.APPLE_800KB_DISK) { return enforce800KbDisk(size); } if (size > Disk.APPLE_32MB_HARDDISK) { LOG.warning("Setting image size to 32MB."); return Disk.APPLE_32MB_HARDDISK; } return size; } static void copyDosSystemTracks(FormattedDisk targetDisk, FormattedDisk source) { DosFormatDisk target = (DosFormatDisk)targetDisk; // FIXME messing with the VTOC should be handled elsewhere byte[] vtoc = source.readSector(DosFormatDisk.CATALOG_TRACK, DosFormatDisk.VTOC_SECTOR); int sectorsPerTrack = vtoc[0x35]; // Note that this also patches T0 S0 for BOOT0 for (int t=0; t<3; t++) { for (int s=0; s