Sync source edition with VCC Plus 3.7.0 build 63
This commit is contained in:
1 parent
c652a5276d
commit
b2ecec4d87
86 files changed
+10519
-472
No files matched your search
@@ -5,7 +5,7 @@ import CryptoKit
|
||||
/// A bounded interpretation of catalog data, not executable host instructions.
|
||||
/// Preparation reads only the installed Working tree and never changes the machine.
|
||||
struct SoftwareLibraryLaunchPlan: Sendable {
|
||||
enum Profile: String, Sendable { case diskBasic = "disk-basic", romCartridge = "rom-cartridge", cocoSDC = "coco-sdc" }
|
||||
enum Profile: String, Sendable { case diskBasic = "disk-basic", hardDriveBasic = "hard-drive-basic", romCartridge = "rom-cartridge", cocoSDC = "coco-sdc" }
|
||||
enum CartridgeDevice: String, Sendable { case rom, orchestra90 }
|
||||
struct Candidate: Identifiable, Equatable, Sendable {
|
||||
let path: String
|
||||
@@ -37,6 +37,7 @@ struct SoftwareLibraryLaunchPlan: Sendable {
|
||||
let controllerSlot: Int
|
||||
let cartridgeDevice: CartridgeDevice
|
||||
let floppyURLs: [Int: URL]
|
||||
let hardDiskURLs: [Int: URL]
|
||||
let cassetteURL: URL?
|
||||
let cartridgeURL: URL?
|
||||
let sdcFolderURL: URL?
|
||||
@@ -46,13 +47,14 @@ struct SoftwareLibraryLaunchPlan: Sendable {
|
||||
let manualInstructions: String
|
||||
let compatibilityNotes: [String]
|
||||
let automaticallyStarts: Bool
|
||||
let offersPlay: Bool
|
||||
let controls: LibraryJSON
|
||||
private let curatedStartup: SoftwareLibraryOwnedGame?
|
||||
var usesCuratedStartup: Bool { curatedStartup != nil }
|
||||
|
||||
private static func supportsDisk(_ ext: String, profile: Profile) -> Bool {
|
||||
switch profile {
|
||||
case .diskBasic: return DiskFiles.extensions.contains(ext)
|
||||
case .diskBasic, .hardDriveBasic: return DiskFiles.extensions.contains(ext)
|
||||
case .cocoSDC: return ["dsk", "jvc", "os9"].contains(ext)
|
||||
case .romCartridge: return false
|
||||
}
|
||||
@@ -61,27 +63,43 @@ struct SoftwareLibraryLaunchPlan: Sendable {
|
||||
/// Presentation only: downloaded files still undergo full preparation before
|
||||
/// a restart is offered. Missing or ambiguous startup media remains Set Up.
|
||||
static func hasAutomaticStartup(for release: SoftwareLibraryRelease) -> Bool {
|
||||
guard let profile = assignedMediaProfile(for: release) else { return false }
|
||||
return profile == .romCartridge || decodeCommands(release.setup.command)?.contains(where: startsSoftware) == true
|
||||
}
|
||||
|
||||
/// Play opens a reviewed personal setup even when loading remains manual.
|
||||
/// This does not claim that a guest program will start automatically.
|
||||
static func hasPlayAction(for release: SoftwareLibraryRelease) -> Bool {
|
||||
guard assignedMediaProfile(for: release) != nil else { return false }
|
||||
return hasAutomaticStartup(for: release) || (release.isPersonal &&
|
||||
release.setup.configuration["personal_reviewed_setup"] == .bool(true))
|
||||
}
|
||||
|
||||
private static func assignedMediaProfile(for release: SoftwareLibraryRelease) -> Profile? {
|
||||
guard let name = release.setup.configuration["profile"].string,
|
||||
let profile = Profile(rawValue: name),
|
||||
case .array(let members) = release.setup.selectedMembers,
|
||||
!members.isEmpty, members.count <= 4 else { return false }
|
||||
guard (try? recommendedCartridgeDevice(release.setup.configuration, profile: profile)) != nil else { return false }
|
||||
!members.isEmpty, members.count <= 4 else { return nil }
|
||||
guard (try? recommendedCartridgeDevice(release.setup.configuration, profile: profile)) != nil else { return nil }
|
||||
var targets = Set<String>()
|
||||
for member in members {
|
||||
guard let path = member["path"].string, validRelative(path),
|
||||
let target = member["target"].string, targets.insert(target).inserted else { return false }
|
||||
let target = member["target"].string, targets.insert(target).inserted else { return nil }
|
||||
let ext = (path as NSString).pathExtension.lowercased()
|
||||
switch profile {
|
||||
case .romCartridge:
|
||||
guard members.count == 1, target == "cartridge", ["ccc", "rom"].contains(ext) else { return false }
|
||||
guard members.count == 1, target == "cartridge", ["ccc", "rom"].contains(ext) else { return nil }
|
||||
case .hardDriveBasic:
|
||||
guard (["hard0", "hard1"].contains(target) && ["vhd", "os9", "img"].contains(ext)) ||
|
||||
(["disk0", "disk1", "disk2", "disk3"].contains(target) && Self.supportsDisk(ext, profile: profile)) else { return nil }
|
||||
case .diskBasic:
|
||||
guard (target == "media" && ["cas", "wav"].contains(ext)) ||
|
||||
(["disk0", "disk1", "disk2", "disk3"].contains(target) && Self.supportsDisk(ext, profile: profile)) else { return false }
|
||||
(["disk0", "disk1", "disk2", "disk3"].contains(target) && Self.supportsDisk(ext, profile: profile)) else { return nil }
|
||||
case .cocoSDC:
|
||||
guard ["disk0", "disk1"].contains(target), Self.supportsDisk(ext, profile: profile) else { return false }
|
||||
guard ["disk0", "disk1"].contains(target), Self.supportsDisk(ext, profile: profile) else { return nil }
|
||||
}
|
||||
}
|
||||
return profile == .romCartridge || decodeCommands(release.setup.command)?.contains(where: startsSoftware) == true
|
||||
return profile
|
||||
}
|
||||
|
||||
static func prepare(release: SoftwareLibraryRelease, receipt: SoftwareLibraryInstallationReceipt,
|
||||
@@ -136,9 +154,10 @@ struct SoftwareLibraryLaunchPlan: Sendable {
|
||||
let ext = (path as NSString).pathExtension.lowercased()
|
||||
let type: String?
|
||||
switch release.mediaType {
|
||||
case "cartridge": type = ext == "ccc" ? "cartridge" : nil
|
||||
case "cartridge": type = ["ccc", "rom"].contains(ext) ? "cartridge" : nil
|
||||
case "cassette": type = ["cas", "wav"].contains(ext) ? "cassette" : nil
|
||||
case "disk", "sdc": type = Self.supportsDisk(ext, profile: profile) ? "disk" : nil
|
||||
case "hard-disk": type = profile == .hardDriveBasic && ["vhd", "os9", "img"].contains(ext) ? "hard-disk" : nil
|
||||
default: type = nil
|
||||
}
|
||||
return type.map { Candidate(path: path, mediaType: $0) }
|
||||
@@ -150,10 +169,10 @@ struct SoftwareLibraryLaunchPlan: Sendable {
|
||||
} else if candidates.count == 1 { choice = candidates[0] }
|
||||
else if !candidates.isEmpty { throw Failure.needsSelection(candidates) }
|
||||
else { throw Failure.unsupported("No supported startup media has been identified for this edition. Open its installed files and use the loading notes to configure it manually.") }
|
||||
selected = [(choice.mediaType == "cartridge" ? "cartridge" : choice.mediaType == "cassette" ? "media" : "disk0", choice.path)]
|
||||
selected = [(choice.mediaType == "cartridge" ? "cartridge" : choice.mediaType == "cassette" ? "media" : choice.mediaType == "hard-disk" ? "hard0" : "disk0", choice.path)]
|
||||
} else if selectedMember != nil { throw Failure.invalidRecipe("This edition already identifies its startup media.") }
|
||||
guard selected.count <= 4, Set(selected.map(\.target)).count == selected.count else { throw Failure.invalidRecipe("Conflicting startup media assignments.") }
|
||||
var floppies: [Int: URL] = [:]
|
||||
guard selected.count <= (release.isPersonal ? 8 : 4), Set(selected.map(\.target)).count == selected.count else { throw Failure.invalidRecipe("Conflicting startup media assignments.") }
|
||||
var floppies: [Int: URL] = [:], hardDisks: [Int: URL] = [:]
|
||||
var cassette: URL?, cartridge: URL?
|
||||
var selectedSDC: [Int: URL] = [:]
|
||||
for member in selected {
|
||||
@@ -166,6 +185,12 @@ struct SoftwareLibraryLaunchPlan: Sendable {
|
||||
case "media":
|
||||
guard profile == .diskBasic, ["cas", "wav"].contains(ext) else { throw Failure.invalidRecipe("The selected file is not a supported cassette.") }
|
||||
cassette = url
|
||||
case "hard0", "hard1":
|
||||
guard profile == .hardDriveBasic, ["vhd", "os9", "img"].contains(ext), let drive = Int(member.target.suffix(1)) else {
|
||||
throw Failure.invalidRecipe("Choose a supported raw hard-disk image for HD0 or HD1.")
|
||||
}
|
||||
_ = try HardDiskFiles.readImage(url)
|
||||
hardDisks[drive] = url
|
||||
case "disk0", "disk1", "disk2", "disk3":
|
||||
guard Self.supportsDisk(ext, profile: profile),
|
||||
let drive = Int(member.target.suffix(1)) else { throw Failure.invalidRecipe("Unsupported disk assignment.") }
|
||||
@@ -197,7 +222,8 @@ struct SoftwareLibraryLaunchPlan: Sendable {
|
||||
}
|
||||
let decoded = members.isEmpty ? nil : decodeCommands(release.setup.command)
|
||||
let canStart = cartridge != nil || (decoded?.contains(where: startsSoftware) == true)
|
||||
var commands = canStart ? (decoded ?? []) : []
|
||||
let offersPlay = canStart || Self.hasPlayAction(for: release)
|
||||
var commands = offersPlay ? (decoded ?? []) : []
|
||||
// Mounting an image is separate from executing its program. Manual SDC
|
||||
// editions still get their chosen image mounted before guidance appears.
|
||||
if sdcFolder != nil {
|
||||
@@ -205,16 +231,16 @@ struct SoftwareLibraryLaunchPlan: Sendable {
|
||||
}
|
||||
var instructions = release.setup.instructions.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
if instructions.isEmpty { instructions = "The selected media is mounted. Follow its manual or directory listing to choose a program; no startup command has been established." }
|
||||
if !canStart, let command = release.setup.command, !command.isEmpty {
|
||||
if !canStart && (!offersPlay || decoded == nil), let command = release.setup.command, !command.isEmpty {
|
||||
instructions += "\n\nThe catalog’s loading sequence needs manual entry. Review it before typing: " + command.replacingOccurrences(of: "\\r", with: " → ")
|
||||
}
|
||||
return Self(workingDirectory: root, canonicalWorkingDirectory: root.resolvingSymlinksInPath(), releaseID: release.id, title: release.metadata["title"].string ?? release.name,
|
||||
profile: profile, use6309: cpu == "6309", ramKiB: ram, ramIndex: ramIndex,
|
||||
videoOutput: video, controllerSlot: slot, cartridgeDevice: cartridgeDevice, floppyURLs: floppies, cassetteURL: cassette,
|
||||
videoOutput: video, controllerSlot: slot, cartridgeDevice: cartridgeDevice, floppyURLs: floppies, hardDiskURLs: hardDisks, cassetteURL: cassette,
|
||||
cartridgeURL: cartridge, sdcFolderURL: sdcFolder, sdcInitialImages: sdcNames,
|
||||
commands: commands, manualInstructions: instructions,
|
||||
compatibilityNotes: release.setup.compatibilityNotes + release.setup.configurationRequirements,
|
||||
automaticallyStarts: canStart, controls: release.setup.controls,
|
||||
automaticallyStarts: canStart, offersPlay: offersPlay, controls: release.setup.controls,
|
||||
curatedStartup: release.ownedGame.flatMap { $0.firstPlayColdDOS ? $0 : nil })
|
||||
}
|
||||
|
||||
@@ -241,7 +267,7 @@ struct SoftwareLibraryLaunchPlan: Sendable {
|
||||
throw Failure.invalidRecipe("The original game disk no longer matches its verified startup recipe. Your working files are kept.")
|
||||
}
|
||||
}
|
||||
for url in Array(floppyURLs.values) + [cassetteURL, cartridgeURL].compactMap({ $0 }) {
|
||||
for url in Array(floppyURLs.values) + Array(hardDiskURLs.values) + [cassetteURL, cartridgeURL].compactMap({ $0 }) {
|
||||
guard url.path.hasPrefix(workingDirectory.path + "/") else { throw Failure.unsafeMedia(url.lastPathComponent) }
|
||||
_ = try Self.file(String(url.path.dropFirst(workingDirectory.path.count + 1)), root: workingDirectory)
|
||||
}
|
||||
@@ -323,8 +349,14 @@ struct SoftwareLibraryLaunchPlan: Sendable {
|
||||
guard let parts = statements(line) else { return false }
|
||||
let number = "(?:[0-9]+|&H[0-9A-F]+)"
|
||||
let filename = "\\\"[^\\\"\\\\]{1,64}\\\""
|
||||
// Disk BASIC's ordinary LOAD replaces the BASIC program and discards
|
||||
// the rest of that command line. RUN must be delivered on a new line.
|
||||
let programLoad = "LOAD *" + filename
|
||||
guard !parts.dropLast().contains(where: {
|
||||
$0.range(of: "^(?:" + programLoad + ")$", options: [.regularExpression, .caseInsensitive]) != nil
|
||||
}) else { return false }
|
||||
let patterns = ["(?:CLOADM?|RUN)(?: *" + filename + ")?", "LOADM *" + filename,
|
||||
"LOAD *" + filename + " *, *R", "LOAD +CHR\\$\\(42\\) *, *R",
|
||||
programLoad + "(?: *, *R)?", "LOAD +CHR\\$\\(42\\) *, *R",
|
||||
"EXEC(?: *" + number + ")?", "DOS(?: +[0-9]+)?", "DIR(?: +[0-3])?",
|
||||
"PCLEAR *[0-9]+", "CLEAR *" + number + "(?: *, *" + number + ")?",
|
||||
"POKE *" + number + " *, *" + number, "NEW"]
|
||||
|
||||
Reference in new issue
Block a user