2016-06-05 01:43:50 +00:00
|
|
|
//
|
|
|
|
// Vic20Document.swift
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 04/06/2016.
|
|
|
|
// Copyright © 2016 Thomas Harte. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
|
|
|
|
class Vic20Document: MachineDocument {
|
|
|
|
|
2016-10-02 20:57:57 +00:00
|
|
|
/* fileprivate lazy var vic20 = CSVic20()
|
2016-06-24 01:09:34 +00:00
|
|
|
override var machine: CSMachine! {
|
|
|
|
get {
|
|
|
|
return vic20
|
|
|
|
}
|
2016-06-05 01:43:50 +00:00
|
|
|
}
|
2016-06-28 01:38:14 +00:00
|
|
|
override var name: String! {
|
|
|
|
get {
|
|
|
|
return "vic20"
|
|
|
|
}
|
|
|
|
}
|
2016-06-05 01:43:50 +00:00
|
|
|
|
|
|
|
// MARK: NSDocument overrides
|
|
|
|
override init() {
|
|
|
|
super.init()
|
2016-06-05 12:53:05 +00:00
|
|
|
|
2016-08-01 08:37:30 +00:00
|
|
|
if let drive = dataForResource("1540", ofType: "bin", inDirectory: "ROMImages/Commodore1540") {
|
2016-07-05 20:54:25 +00:00
|
|
|
vic20.setDriveROM(drive)
|
|
|
|
}
|
2016-08-08 01:48:09 +00:00
|
|
|
|
|
|
|
establishStoredOptions()
|
2016-06-05 01:43:50 +00:00
|
|
|
}
|
2016-06-05 01:49:03 +00:00
|
|
|
|
|
|
|
override class func autosavesInPlace() -> Bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
override var windowNibName: String? {
|
|
|
|
return "Vic20Document"
|
|
|
|
}
|
|
|
|
|
2016-06-05 12:53:05 +00:00
|
|
|
// MARK: machine setup
|
2016-09-16 02:12:12 +00:00
|
|
|
fileprivate func rom(_ name: String) -> Data? {
|
2016-06-05 12:53:05 +00:00
|
|
|
return dataForResource(name, ofType: "bin", inDirectory: "ROMImages/Vic20")
|
|
|
|
}
|
|
|
|
|
2016-08-14 17:53:14 +00:00
|
|
|
// MARK: automatic loading tick box
|
2016-08-08 01:48:09 +00:00
|
|
|
@IBOutlet var loadAutomaticallyButton: NSButton?
|
2016-08-06 21:39:27 +00:00
|
|
|
var autoloadingUserDefaultsKey: String {
|
|
|
|
get { return prefixedUserDefaultsKey("autoload") }
|
|
|
|
}
|
2016-08-14 17:53:14 +00:00
|
|
|
|
2016-09-16 02:12:12 +00:00
|
|
|
@IBAction func setShouldLoadAutomatically(_ sender: NSButton!) {
|
2016-08-06 21:39:27 +00:00
|
|
|
let loadAutomatically = sender.state == NSOnState
|
|
|
|
vic20.shouldLoadAutomatically = loadAutomatically
|
2016-09-16 02:12:12 +00:00
|
|
|
UserDefaults.standard.set(loadAutomatically, forKey: self.autoloadingUserDefaultsKey)
|
2016-08-06 21:39:27 +00:00
|
|
|
}
|
2016-08-14 17:53:14 +00:00
|
|
|
|
|
|
|
// MARK: country selector
|
|
|
|
@IBOutlet var countryButton: NSPopUpButton?
|
|
|
|
var countryUserDefaultsKey: String {
|
|
|
|
get { return prefixedUserDefaultsKey("country") }
|
|
|
|
}
|
|
|
|
|
2016-09-16 02:12:12 +00:00
|
|
|
@IBAction func setCountry(_ sender: NSPopUpButton!) {
|
|
|
|
UserDefaults.standard.set(sender.indexOfSelectedItem, forKey: self.countryUserDefaultsKey)
|
2016-08-14 18:00:08 +00:00
|
|
|
setCountry(sender.indexOfSelectedItem)
|
|
|
|
}
|
|
|
|
|
2016-09-16 02:12:12 +00:00
|
|
|
fileprivate func setCountry(_ countryID: Int) {
|
2016-08-14 18:23:08 +00:00
|
|
|
var charactersROM: String?
|
|
|
|
var kernelROM: String?
|
|
|
|
switch countryID {
|
|
|
|
case 0: // Danish
|
|
|
|
charactersROM = "characters-danish"
|
|
|
|
kernelROM = "kernel-danish"
|
|
|
|
vic20.region = .PAL
|
|
|
|
case 1: // European
|
|
|
|
charactersROM = "characters-english"
|
|
|
|
kernelROM = "kernel-pal"
|
|
|
|
vic20.region = .PAL
|
|
|
|
case 2: // Japanese
|
|
|
|
charactersROM = "characters-japanese"
|
|
|
|
kernelROM = "kernel-japanese"
|
|
|
|
vic20.region = .NTSC
|
|
|
|
case 3: // Swedish
|
|
|
|
charactersROM = "characters-swedish"
|
|
|
|
kernelROM = "kernel-swedish"
|
|
|
|
vic20.region = .PAL
|
|
|
|
case 4: // US
|
|
|
|
charactersROM = "characters-english"
|
|
|
|
kernelROM = "kernel-ntsc"
|
|
|
|
vic20.region = .NTSC
|
|
|
|
default: break
|
|
|
|
}
|
|
|
|
|
2016-09-16 02:12:12 +00:00
|
|
|
if let charactersROM = charactersROM, let kernelROM = kernelROM {
|
|
|
|
if let kernel = rom(kernelROM), let basic = rom("basic"), let characters = rom(charactersROM) {
|
2016-08-14 18:23:08 +00:00
|
|
|
vic20.setKernelROM(kernel)
|
|
|
|
vic20.setBASICROM(basic)
|
|
|
|
vic20.setCharactersROM(characters)
|
|
|
|
}
|
|
|
|
}
|
2016-08-14 17:53:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: memory model selector
|
|
|
|
@IBOutlet var memorySizeButton: NSPopUpButton?
|
|
|
|
var memorySizeUserDefaultsKey: String {
|
|
|
|
get { return prefixedUserDefaultsKey("memorySize") }
|
|
|
|
}
|
|
|
|
|
2016-09-16 02:12:12 +00:00
|
|
|
@IBAction func setMemorySize(_ sender: NSPopUpButton!) {
|
2016-08-14 18:00:08 +00:00
|
|
|
var selectedSize: Int?
|
|
|
|
switch sender.indexOfSelectedItem {
|
|
|
|
case 0: selectedSize = 5
|
|
|
|
case 1: selectedSize = 8
|
|
|
|
case 2: selectedSize = 32
|
|
|
|
default: break
|
|
|
|
}
|
|
|
|
if let selectedSize = selectedSize {
|
2016-09-16 02:12:12 +00:00
|
|
|
UserDefaults.standard.set(selectedSize, forKey: self.memorySizeUserDefaultsKey)
|
2016-08-14 18:23:08 +00:00
|
|
|
setMemorySize(sender.indexOfSelectedItem)
|
|
|
|
}
|
|
|
|
}
|
2016-09-16 02:12:12 +00:00
|
|
|
fileprivate func setMemorySize(_ sizeIndex: Int) {
|
2016-08-14 18:23:08 +00:00
|
|
|
switch sizeIndex {
|
2016-09-16 02:12:12 +00:00
|
|
|
case 2: vic20.memorySize = .size32Kb
|
|
|
|
case 1: vic20.memorySize = .size8Kb
|
|
|
|
default: vic20.memorySize = .size5Kb
|
2016-08-14 18:00:08 +00:00
|
|
|
}
|
2016-08-14 17:53:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: option restoration
|
2016-08-06 21:39:27 +00:00
|
|
|
override func establishStoredOptions() {
|
|
|
|
super.establishStoredOptions()
|
|
|
|
|
2016-09-16 02:12:12 +00:00
|
|
|
let standardUserDefaults = UserDefaults.standard
|
|
|
|
standardUserDefaults.register(defaults: [
|
2016-08-14 18:00:08 +00:00
|
|
|
self.autoloadingUserDefaultsKey: true,
|
|
|
|
self.memorySizeUserDefaultsKey: 5,
|
2016-08-14 20:20:24 +00:00
|
|
|
self.countryUserDefaultsKey: 1
|
2016-08-06 21:39:27 +00:00
|
|
|
])
|
|
|
|
|
2016-09-16 02:12:12 +00:00
|
|
|
let loadAutomatically = standardUserDefaults.bool(forKey: self.autoloadingUserDefaultsKey)
|
2016-08-06 21:39:27 +00:00
|
|
|
vic20.shouldLoadAutomatically = loadAutomatically
|
2016-08-08 01:48:09 +00:00
|
|
|
self.loadAutomaticallyButton?.state = loadAutomatically ? NSOnState : NSOffState
|
2016-08-14 18:00:08 +00:00
|
|
|
|
2016-09-08 11:38:34 +00:00
|
|
|
if !loadAutomatically {
|
2016-09-16 02:12:12 +00:00
|
|
|
let memorySize = standardUserDefaults.integer(forKey: self.memorySizeUserDefaultsKey)
|
2016-09-08 11:38:34 +00:00
|
|
|
var indexToSelect: Int?
|
|
|
|
switch memorySize {
|
|
|
|
case 32: indexToSelect = 2
|
|
|
|
case 8: indexToSelect = 1
|
|
|
|
default: indexToSelect = 0
|
|
|
|
}
|
|
|
|
if let indexToSelect = indexToSelect {
|
2016-09-16 02:12:12 +00:00
|
|
|
self.memorySizeButton?.selectItem(at: indexToSelect)
|
2016-09-08 11:38:34 +00:00
|
|
|
setMemorySize(indexToSelect)
|
|
|
|
}
|
2016-08-14 18:00:08 +00:00
|
|
|
}
|
|
|
|
|
2016-09-08 11:38:34 +00:00
|
|
|
// TODO: this should be part of the configuration
|
2016-09-16 02:12:12 +00:00
|
|
|
let country = standardUserDefaults.integer(forKey: self.countryUserDefaultsKey)
|
2016-08-14 18:00:08 +00:00
|
|
|
setCountry(country)
|
2016-09-16 02:12:12 +00:00
|
|
|
self.countryButton?.selectItem(at: country)
|
2016-10-02 20:57:57 +00:00
|
|
|
}*/
|
2016-06-05 01:43:50 +00:00
|
|
|
}
|