Publish VCC Plus OSS source distribution for 3.6.2 build 60

This commit is contained in:
Brian Holman committed 2026-11-13 00:14:03 -07:00
commit c652a5276d
1192 files changed
+272368

No files matched your search

+29
View File
@@ -0,0 +1,29 @@
// SPDX-License-Identifier: GPL-3.0-or-later
import Foundation
enum ROMImage {
enum Failure: LocalizedError {
case notFile, size, resetVector
var errorDescription: String? {
switch self {
case .notFile: return "Choose a regular CoCo 3 ROM file."
case .size: return "Choose a 32 KiB CoCo 3 system ROM. This file has a different size."
case .resetVector: return "This file does not have a valid CoCo 3 ROM reset address."
}
}
}
static func validate(_ bytes: Data) throws {
guard bytes.count == 32768 else { throw Failure.size }
let start = Int(bytes[bytes.startIndex + 32766]) * 256 + Int(bytes[bytes.startIndex + 32767])
guard (0x8000...0xfeff).contains(start) else { throw Failure.resetVector }
}
static func read(_ url: URL) throws -> Data {
guard try url.resourceValues(forKeys: [.isRegularFileKey]).isRegularFile == true else { throw Failure.notFile }
let file = try FileHandle(forReadingFrom: url)
defer { try? file.close() }
// Read at most the allowed size plus one byte, even for huge input files.
let bytes = try file.read(upToCount: 32769) ?? Data()
try validate(bytes)
return bytes
}
}