2019-07-26 05:51:36 +00:00
|
|
|
|
//
|
|
|
|
|
// ViewController.swift
|
|
|
|
|
// A2Mac
|
|
|
|
|
//
|
|
|
|
|
// Created by Tamas Rudnai on 7/25/19.
|
|
|
|
|
// Copyright © 2019 GameAlloy. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
|
2020-01-28 06:54:03 +00:00
|
|
|
|
|
2019-07-26 05:51:36 +00:00
|
|
|
|
import Cocoa
|
2020-02-07 08:40:31 +00:00
|
|
|
|
import AVFoundation
|
|
|
|
|
|
2019-07-26 05:51:36 +00:00
|
|
|
|
|
2020-01-28 06:54:03 +00:00
|
|
|
|
let K : Double = 1000.0
|
|
|
|
|
let M : Double = (K * K)
|
|
|
|
|
let G : Double = (M * K)
|
|
|
|
|
let T : Double = (G * K)
|
|
|
|
|
|
|
|
|
|
let KB : Double = 1024.0
|
|
|
|
|
let MB : Double = (KB * KB)
|
|
|
|
|
let GB : Double = (MB * KB)
|
|
|
|
|
let TB : Double = (GB * KB)
|
|
|
|
|
|
|
|
|
|
|
2020-02-07 08:40:31 +00:00
|
|
|
|
var spk_up: AVAudioPlayer?
|
|
|
|
|
var spk_dn: AVAudioPlayer?
|
|
|
|
|
|
|
|
|
|
@_cdecl("ViewController_spk_up_play")
|
|
|
|
|
func spk_up_play() {
|
|
|
|
|
spk_up?.stop()
|
|
|
|
|
spk_dn?.stop()
|
|
|
|
|
spk_up?.play()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@_cdecl("ViewController_spk_dn_play")
|
|
|
|
|
func spk_dn_play() {
|
|
|
|
|
spk_up?.stop()
|
|
|
|
|
spk_dn?.stop()
|
|
|
|
|
spk_dn?.play()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2019-11-28 04:27:32 +00:00
|
|
|
|
#if METAL_YES
|
|
|
|
|
import Metal
|
|
|
|
|
#endif
|
|
|
|
|
|
2020-04-27 14:26:04 +00:00
|
|
|
|
class ViewController: NSViewController {
|
2019-07-26 05:51:36 +00:00
|
|
|
|
|
2019-09-19 09:27:56 +00:00
|
|
|
|
@IBOutlet weak var displayField: NSTextField!
|
2019-07-30 08:05:21 +00:00
|
|
|
|
@IBOutlet weak var display: NSTextFieldCell!
|
2019-09-17 09:12:05 +00:00
|
|
|
|
@IBOutlet weak var speedometer: NSTextFieldCell!
|
2020-05-29 15:50:47 +00:00
|
|
|
|
@IBOutlet weak var lores: LoRes!
|
2019-11-28 04:27:32 +00:00
|
|
|
|
@IBOutlet weak var hires: HiRes!
|
2020-06-11 02:11:27 +00:00
|
|
|
|
@IBOutlet weak var splashScreen: NSView!
|
2020-06-17 16:46:17 +00:00
|
|
|
|
@IBOutlet weak var scanLines: NSImageView!
|
2019-11-28 04:27:32 +00:00
|
|
|
|
|
2020-06-17 16:46:17 +00:00
|
|
|
|
var CRTMonitor = false
|
2020-06-02 17:10:18 +00:00
|
|
|
|
var Keyboard2Joystick = true
|
|
|
|
|
var Mouse2Joystick = false
|
|
|
|
|
var MouseInterface = true
|
|
|
|
|
|
2019-09-17 09:12:05 +00:00
|
|
|
|
|
2019-09-10 07:00:00 +00:00
|
|
|
|
// static let charConvStr : String =
|
|
|
|
|
// "@🄰🄱🄲🄳🄴🄵🄶🄷🄸🄹🄺🄻🄼🄽🄾🄿🅀🅁🅂🅃🅄🅅🅆🅇🅈🅉[\\]^_ !\"#$%&'()*+,-./0123456789:;<=>?" +
|
|
|
|
|
// "@🅰🅱🅲🅳🅴🅵🅶🅷🅸🅹🅺🅻🅼🅽🅾🅿🆀🆁🆂🆃🆄🆅🆆🆇🆈🆉[\\]^_⬛︎!\"#$%&'()*+,-./0123456789:;<=>?" + // FL
|
|
|
|
|
// "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_ !\"#$%&'()*+,-./0123456789:;<=>?" +
|
|
|
|
|
// "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~?"
|
|
|
|
|
|
2019-09-19 09:27:56 +00:00
|
|
|
|
// static let charConvStr : String =
|
|
|
|
|
// "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_ !\"#$%&'()*+,-./0123456789:;<=>?" +
|
|
|
|
|
// "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_░!\"#$%&'()*+,-./0123456789:;<=>?" + // FL
|
|
|
|
|
// "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_\u{E0A0}!\"#$%&'()*+,-./0123456789:;<=>?" +
|
|
|
|
|
// "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~?"
|
|
|
|
|
|
|
|
|
|
// static let charConvStr : String =
|
|
|
|
|
// "\u{E140}\u{E141}\u{E142}\u{E143}\u{E144}\u{E145}\u{E146}\u{E147}\u{E148}\u{E149}\u{E14A}\u{E14B}\u{E14C}\u{E14D}\u{E14E}\u{E14F}\u{E150}\u{E151}\u{E152}\u{E153}\u{E154}\u{E155}\u{E156}\u{E157}\u{E158}\u{E159}\u{E15A}\u{E15B}\u{E15C}\u{E15D}\u{E15E}\u{E15F}\u{E120}\u{E121}\u{E122}\u{E123}\u{E124}\u{E125}\u{E126}\u{E127}\u{E128}\u{E129}\u{E12A}\u{E12B}\u{E12C}\u{E12D}\u{E12E}\u{E12F}\u{E130}\u{E131}\u{E132}\u{E133}\u{E134}\u{E135}\u{E136}\u{E137}\u{E138}\u{E139}\u{E13A}\u{E13B}\u{E13C}\u{E13D}\u{E13E}\u{E13F}" +
|
|
|
|
|
// "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_░!\"#$%&'()*+,-./0123456789:;<=>?" + // FL
|
|
|
|
|
// "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_\u{E0A0}!\"#$%&'()*+,-./0123456789:;<=>?" +
|
|
|
|
|
// "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~?"
|
2019-09-09 02:55:19 +00:00
|
|
|
|
|
2019-09-19 09:27:56 +00:00
|
|
|
|
static let charConvStrFlashOff : String =
|
|
|
|
|
"\u{E140}\u{E141}\u{E142}\u{E143}\u{E144}\u{E145}\u{E146}\u{E147}\u{E148}\u{E149}\u{E14A}\u{E14B}\u{E14C}\u{E14D}\u{E14E}\u{E14F}\u{E150}\u{E151}\u{E152}\u{E153}\u{E154}\u{E155}\u{E156}\u{E157}\u{E158}\u{E159}\u{E15A}\u{E15B}\u{E15C}\u{E15D}\u{E15E}\u{E15F}\u{E120}\u{E121}\u{E122}\u{E123}\u{E124}\u{E125}\u{E126}\u{E127}\u{E128}\u{E129}\u{E12A}\u{E12B}\u{E12C}\u{E12D}\u{E12E}\u{E12F}\u{E130}\u{E131}\u{E132}\u{E133}\u{E134}\u{E135}\u{E136}\u{E137}\u{E138}\u{E139}\u{E13A}\u{E13B}\u{E13C}\u{E13D}\u{E13E}\u{E13F}" +
|
2020-04-26 04:28:18 +00:00
|
|
|
|
|
2019-09-19 09:27:56 +00:00
|
|
|
|
"@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_ !\"#$%&'()*+,-./0123456789:;<=>?" + // FL
|
2020-04-26 04:28:18 +00:00
|
|
|
|
|
2019-09-22 08:31:09 +00:00
|
|
|
|
"@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_ !\"#$%&'()*+,-./0123456789:;<=>?" +
|
2020-04-26 04:28:18 +00:00
|
|
|
|
|
|
|
|
|
"@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\u{007F}"
|
2019-09-19 09:27:56 +00:00
|
|
|
|
|
|
|
|
|
static let charConvStrFlashOn : String =
|
|
|
|
|
"\u{E140}\u{E141}\u{E142}\u{E143}\u{E144}\u{E145}\u{E146}\u{E147}\u{E148}\u{E149}\u{E14A}\u{E14B}\u{E14C}\u{E14D}\u{E14E}\u{E14F}\u{E150}\u{E151}\u{E152}\u{E153}\u{E154}\u{E155}\u{E156}\u{E157}\u{E158}\u{E159}\u{E15A}\u{E15B}\u{E15C}\u{E15D}\u{E15E}\u{E15F}\u{E120}\u{E121}\u{E122}\u{E123}\u{E124}\u{E125}\u{E126}\u{E127}\u{E128}\u{E129}\u{E12A}\u{E12B}\u{E12C}\u{E12D}\u{E12E}\u{E12F}\u{E130}\u{E131}\u{E132}\u{E133}\u{E134}\u{E135}\u{E136}\u{E137}\u{E138}\u{E139}\u{E13A}\u{E13B}\u{E13C}\u{E13D}\u{E13E}\u{E13F}" +
|
|
|
|
|
"\u{E140}\u{E141}\u{E142}\u{E143}\u{E144}\u{E145}\u{E146}\u{E147}\u{E148}\u{E149}\u{E14A}\u{E14B}\u{E14C}\u{E14D}\u{E14E}\u{E14F}\u{E150}\u{E151}\u{E152}\u{E153}\u{E154}\u{E155}\u{E156}\u{E157}\u{E158}\u{E159}\u{E15A}\u{E15B}\u{E15C}\u{E15D}\u{E15E}\u{E15F}\u{E120}\u{E121}\u{E122}\u{E123}\u{E124}\u{E125}\u{E126}\u{E127}\u{E128}\u{E129}\u{E12A}\u{E12B}\u{E12C}\u{E12D}\u{E12E}\u{E12F}\u{E130}\u{E131}\u{E132}\u{E133}\u{E134}\u{E135}\u{E136}\u{E137}\u{E138}\u{E139}\u{E13A}\u{E13B}\u{E13C}\u{E13D}\u{E13E}\u{E13F}" +
|
2020-04-26 04:28:18 +00:00
|
|
|
|
|
2019-09-22 08:31:09 +00:00
|
|
|
|
"@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_ !\"#$%&'()*+,-./0123456789:;<=>?" +
|
2020-04-26 04:28:18 +00:00
|
|
|
|
|
|
|
|
|
"@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\u{007F}"
|
2019-09-19 09:27:56 +00:00
|
|
|
|
|
2019-09-22 08:31:09 +00:00
|
|
|
|
static let charConvTblFlashOn = Array( charConvStrFlashOn )
|
|
|
|
|
static let charConvTblFlashOff = Array( charConvStrFlashOff )
|
|
|
|
|
|
|
|
|
|
static var charConvTbl = charConvTblFlashOn
|
2020-04-26 07:23:05 +00:00
|
|
|
|
|
2020-06-06 20:19:29 +00:00
|
|
|
|
static var romFileName = "Apple2e_Enhanced.rom";
|
2019-09-09 02:55:19 +00:00
|
|
|
|
|
2020-05-29 15:50:47 +00:00
|
|
|
|
static let textLineOfs : [Int] = [
|
2019-09-09 02:55:19 +00:00
|
|
|
|
0x000, 0x080, 0x100, 0x180, 0x200, 0x280, 0x300, 0x380, 0x028, 0x0A8, 0x128, 0x1A8,
|
|
|
|
|
0x228, 0x2A8, 0x328, 0x3A8, 0x050, 0x0D0, 0x150, 0x1D0, 0x250, 0x2D0, 0x350, 0x3D0
|
|
|
|
|
]
|
|
|
|
|
|
2020-06-04 18:37:35 +00:00
|
|
|
|
|
|
|
|
|
func dialogOK(title: String, text: String) {
|
|
|
|
|
let alert = NSAlert()
|
|
|
|
|
alert.messageText = title
|
|
|
|
|
alert.informativeText = text
|
|
|
|
|
alert.alertStyle = .warning
|
|
|
|
|
alert.addButton(withTitle: "OK")
|
|
|
|
|
alert.runModal()
|
|
|
|
|
// return alert.runModal() == .alertFirstButtonReturn
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@objc func chk_woz_load(err : Int32) {
|
|
|
|
|
switch (err) {
|
|
|
|
|
case WOZ_ERR_OK:
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
case WOZ_ERR_FILE_NOT_FOUND:
|
|
|
|
|
dialogOK(title: "Error Loading Disk Image", text: "File Not Found!")
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
case WOZ_ERR_NOT_WOZ_FILE:
|
|
|
|
|
dialogOK(title: "Error Loading Disk Image", text: "File is not a WOZ image!")
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
case WOZ_ERR_BAD_CHUNK_HDR, WOZ_ERR_BAD_DATA:
|
|
|
|
|
dialogOK(title: "Error Loading Disk Image", text: "Malformed WOZ image!")
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
dialogOK(title: "Error Loading Disk Image", text: "Unknown Error! (\(err))" )
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2019-09-12 01:36:30 +00:00
|
|
|
|
var workItem : DispatchWorkItem? = nil;
|
2019-09-09 07:27:31 +00:00
|
|
|
|
@IBAction func Power(_ sender: Any) {
|
2020-05-09 21:40:42 +00:00
|
|
|
|
|
|
|
|
|
upd.suspend()
|
2020-06-17 16:46:17 +00:00
|
|
|
|
cpuState = cpuState_inited;
|
2020-05-09 10:39:55 +00:00
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------
|
|
|
|
|
// Animated Splash Screen fade out and (Text) Monitor fade in
|
|
|
|
|
|
2020-05-09 21:40:42 +00:00
|
|
|
|
hires.isHidden = true
|
2020-05-09 10:39:55 +00:00
|
|
|
|
displayField.alphaValue = 0
|
|
|
|
|
displayField.isHidden = false
|
|
|
|
|
splashScreen.alphaValue = 1
|
|
|
|
|
splashScreen.isHidden = false
|
|
|
|
|
|
2020-05-09 21:40:42 +00:00
|
|
|
|
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
|
2020-05-09 10:39:55 +00:00
|
|
|
|
NSAnimationContext.runAnimationGroup({ (context) in
|
2020-05-09 21:40:42 +00:00
|
|
|
|
context.duration = 0.5
|
2020-05-09 10:39:55 +00:00
|
|
|
|
// Use the value you want to animate to (NOT the starting value)
|
|
|
|
|
self.displayField.animator().alphaValue = 1
|
|
|
|
|
self.splashScreen.animator().alphaValue = 0
|
|
|
|
|
},
|
|
|
|
|
completionHandler:{ () -> Void in
|
|
|
|
|
self.displayField.alphaValue = 1
|
|
|
|
|
self.splashScreen.isHidden = true
|
|
|
|
|
})
|
2020-05-09 21:40:42 +00:00
|
|
|
|
|
|
|
|
|
m6502_ColdReset( Bundle.main.resourcePath, ViewController.romFileName )
|
|
|
|
|
|
2020-06-17 16:46:17 +00:00
|
|
|
|
cpuState = cpuState_running;
|
2020-05-09 21:40:42 +00:00
|
|
|
|
self.upd.resume()
|
2020-05-09 10:39:55 +00:00
|
|
|
|
}
|
|
|
|
|
//------------------------------------------------------------
|
2020-02-07 08:40:31 +00:00
|
|
|
|
|
2019-09-19 09:27:56 +00:00
|
|
|
|
#if SPEEDTEST
|
|
|
|
|
if ( workItem != nil ) {
|
|
|
|
|
workItem!.cancel();
|
|
|
|
|
workItem = nil;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
workItem = DispatchWorkItem {
|
|
|
|
|
DispatchQueue.global(qos: .userInteractive).async {
|
|
|
|
|
// DispatchQueue.global(qos: .userInitiated).async {
|
|
|
|
|
// DispatchQueue.global(qos: .background).async {
|
|
|
|
|
tst6502()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
DispatchQueue.global().async(execute: workItem!);
|
|
|
|
|
}
|
|
|
|
|
#else
|
2020-04-30 14:26:46 +00:00
|
|
|
|
|
2020-05-09 21:40:42 +00:00
|
|
|
|
|
2019-09-19 09:27:56 +00:00
|
|
|
|
#endif
|
2019-09-09 07:27:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@IBAction func Reset(_ sender: Any) {
|
2020-05-03 05:39:54 +00:00
|
|
|
|
// m6502.interrupt = SOFTRESET;
|
2020-05-03 05:35:59 +00:00
|
|
|
|
|
2020-05-03 05:39:54 +00:00
|
|
|
|
// let saved_frm_set = clk_6502_per_frm_set;
|
|
|
|
|
// clk_6502_per_frm_set = 0
|
|
|
|
|
// clk_6502_per_frm_max = 0
|
|
|
|
|
// // wait for 1 ms to allow the simulation to halt
|
|
|
|
|
// usleep(10000);
|
2020-05-03 05:35:59 +00:00
|
|
|
|
|
|
|
|
|
softReset()
|
|
|
|
|
|
2020-05-03 05:39:54 +00:00
|
|
|
|
// clk_6502_per_frm_set = saved_frm_set
|
2019-09-09 07:27:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2020-05-25 04:04:34 +00:00
|
|
|
|
static let textPage1Addr = 0x400
|
|
|
|
|
static let textPage2Addr = 0x800
|
2020-02-23 00:37:54 +00:00
|
|
|
|
static let textBufferSize = 0x400
|
2020-04-27 14:26:04 +00:00
|
|
|
|
|
|
|
|
|
// static only needed to be able to initialize things
|
|
|
|
|
static let textLines = 24
|
|
|
|
|
static let textCols = 40
|
|
|
|
|
static let lineEndChars = 1
|
|
|
|
|
|
|
|
|
|
// these are needed to be able to easy access to these constants from instances
|
|
|
|
|
let textLines = ViewController.textLines
|
|
|
|
|
let textCols = ViewController.textCols
|
|
|
|
|
let lineEndChars = ViewController.lineEndChars
|
|
|
|
|
|
2020-02-23 00:37:54 +00:00
|
|
|
|
var frameCnt = 0
|
|
|
|
|
// let spaceChar : Character = "\u{E17F}"
|
|
|
|
|
// let blockChar : Character = "\u{E07F}"
|
2020-04-27 14:26:04 +00:00
|
|
|
|
// static let spaceChar : Character = " "
|
|
|
|
|
// static let blockChar : Character = "░"
|
|
|
|
|
// static var flashingSpace : Character = " "
|
2020-02-23 00:37:54 +00:00
|
|
|
|
|
2020-05-01 21:43:41 +00:00
|
|
|
|
let ramBufferPointer = UnsafeRawBufferPointer(start: MEM, count: 64 * 1024)
|
2020-05-27 04:13:31 +00:00
|
|
|
|
static let textPage1Pointer = UnsafeRawBufferPointer(start: MEM + textPage1Addr, count: textBufferSize)
|
|
|
|
|
static let textPage2Pointer = UnsafeRawBufferPointer(start: MEM + textPage2Addr, count: textBufferSize)
|
|
|
|
|
static let textIntBufferPointer = UnsafeRawBufferPointer(start: RAM + textPage1Addr, count: textBufferSize)
|
|
|
|
|
static let textAuxBufferPointer = UnsafeRawBufferPointer(start: AUX + textPage1Addr, count: textBufferSize)
|
|
|
|
|
|
2020-05-29 15:50:47 +00:00
|
|
|
|
// TODO: Render text screen in native C
|
|
|
|
|
// static let textScreen = UnsafeMutableRawPointer(mutating: testText)
|
|
|
|
|
|
|
|
|
|
|
2020-05-25 04:04:34 +00:00
|
|
|
|
var textBufferPointer = textPage1Pointer
|
2020-04-27 14:26:04 +00:00
|
|
|
|
|
|
|
|
|
static let textArraySize = textLines * (textCols + lineEndChars) + textCols * 2
|
|
|
|
|
|
|
|
|
|
var txtClear = [Character](repeating: " ", count: textArraySize * 2)
|
|
|
|
|
var txtArr = [Character](repeating: " ", count: textArraySize * 2)
|
2020-02-23 00:37:54 +00:00
|
|
|
|
|
|
|
|
|
var s = String()
|
|
|
|
|
|
|
|
|
|
func HexDump() {
|
|
|
|
|
var txt : String = ""
|
|
|
|
|
|
|
|
|
|
for y in 0...textLines - 1 {
|
|
|
|
|
txt += String(format: "%04X: ", y * 16)
|
|
|
|
|
for x in 0...15 {
|
|
|
|
|
let byte = ramBufferPointer[ y * 16 + x ]
|
|
|
|
|
let chr = String(format: "%02X ", byte)
|
|
|
|
|
txt += chr
|
|
|
|
|
}
|
|
|
|
|
txt += "\n"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DispatchQueue.main.async {
|
|
|
|
|
self.display.stringValue = txt
|
|
|
|
|
self.speedometer.stringValue = String(format: "%0.3lf MHz", mhz);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2019-09-22 08:31:09 +00:00
|
|
|
|
// AppleScript Keycodes
|
|
|
|
|
let leftArrowKey = 123
|
|
|
|
|
let rightArrowKey = 124
|
|
|
|
|
let upArrowKey = 126
|
|
|
|
|
let downArrowKey = 125
|
2020-02-23 00:37:54 +00:00
|
|
|
|
|
|
|
|
|
var ddd = 9;
|
2019-09-22 08:31:09 +00:00
|
|
|
|
|
2020-04-27 14:26:04 +00:00
|
|
|
|
override var acceptsFirstResponder: Bool {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-09 07:27:31 +00:00
|
|
|
|
override func keyDown(with event: NSEvent) {
|
2020-06-17 16:46:17 +00:00
|
|
|
|
|
|
|
|
|
if ( cpuMode == cpuMode_eco ) {
|
|
|
|
|
cpuState = cpuState_running;
|
2020-06-18 22:14:54 +00:00
|
|
|
|
upd.resume()
|
2020-06-17 16:46:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-06-06 06:16:17 +00:00
|
|
|
|
// print("keyDown")
|
2020-02-23 00:37:54 +00:00
|
|
|
|
|
2020-04-23 02:18:28 +00:00
|
|
|
|
// for i in 0...65536 {
|
|
|
|
|
// ddd = Int(event.keyCode) + i
|
|
|
|
|
// }
|
|
|
|
|
// ddd = ddd * 2
|
|
|
|
|
|
|
|
|
|
|
2019-09-15 11:02:22 +00:00
|
|
|
|
// switch event.modifierFlags.intersection(.deviceIndependentFlagsMask) {
|
|
|
|
|
// case [.command] where event.characters == "l",
|
|
|
|
|
// [.command, .shift] where event.characters == "l":
|
|
|
|
|
// print("command-l or command-shift-l")
|
|
|
|
|
// default:
|
|
|
|
|
// break
|
|
|
|
|
// }
|
|
|
|
|
// print( "key = " + (event.charactersIgnoringModifiers ?? ""))
|
|
|
|
|
// print( "\ncharacter = " + (event.characters ?? ""))
|
2019-09-09 07:27:31 +00:00
|
|
|
|
|
2020-04-23 02:18:28 +00:00
|
|
|
|
|
|
|
|
|
if event.modifierFlags.contains(.command) { // .shift, .option, .control ...
|
|
|
|
|
if let chars = event.charactersIgnoringModifiers {
|
|
|
|
|
switch chars {
|
|
|
|
|
case "v":
|
|
|
|
|
print("CMD + V")
|
|
|
|
|
|
|
|
|
|
let pasteBoard = NSPasteboard.general
|
|
|
|
|
if let str = pasteBoard.string( forType: .string ) {
|
|
|
|
|
print("PASTED:", str)
|
|
|
|
|
|
|
|
|
|
DispatchQueue.global(qos: .background).async {
|
|
|
|
|
for char in str.uppercased() {
|
|
|
|
|
if let ascii = char.asciiValue {
|
|
|
|
|
kbdInput(ascii)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
default:
|
2020-06-03 17:23:55 +00:00
|
|
|
|
super.keyDown(with: event)
|
2020-04-23 02:18:28 +00:00
|
|
|
|
break
|
2019-09-09 07:27:31 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-04-23 02:18:28 +00:00
|
|
|
|
else {
|
|
|
|
|
#if FUNCTIONTEST
|
|
|
|
|
#else
|
|
|
|
|
let keyCode = Int(event.keyCode)
|
|
|
|
|
switch keyCode {
|
|
|
|
|
case leftArrowKey:
|
2020-06-06 06:16:17 +00:00
|
|
|
|
// print("LEFT", ddd);
|
2020-06-02 17:10:18 +00:00
|
|
|
|
if ( Keyboard2Joystick ) {
|
|
|
|
|
// Keyboard 2 JoyStick (Game Controller / Paddle)
|
|
|
|
|
pdl_valarr[0] = 0
|
|
|
|
|
}
|
|
|
|
|
kbdInput(0x08)
|
2020-05-24 19:14:09 +00:00
|
|
|
|
|
|
|
|
|
|
2020-04-23 02:18:28 +00:00
|
|
|
|
case rightArrowKey:
|
2020-06-06 06:16:17 +00:00
|
|
|
|
// print("RIGHT")
|
2020-05-24 19:14:09 +00:00
|
|
|
|
// Keyboard 2 JoyStick (Game Controller / Paddle)
|
2020-06-02 17:10:18 +00:00
|
|
|
|
if ( Keyboard2Joystick ) {
|
|
|
|
|
pdl_valarr[0] = 1
|
|
|
|
|
}
|
|
|
|
|
kbdInput(0x15)
|
|
|
|
|
|
2020-04-23 02:18:28 +00:00
|
|
|
|
case downArrowKey:
|
2020-06-06 06:16:17 +00:00
|
|
|
|
// print("DOWN")
|
2020-05-24 19:14:09 +00:00
|
|
|
|
// Keyboard 2 JoyStick (Game Controller / Paddle)
|
2020-06-02 17:10:18 +00:00
|
|
|
|
if ( Keyboard2Joystick ) {
|
|
|
|
|
pdl_valarr[1] = 1
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
kbdInput(0x0B)
|
|
|
|
|
}
|
2020-04-23 02:18:28 +00:00
|
|
|
|
case upArrowKey:
|
2020-06-06 06:16:17 +00:00
|
|
|
|
// print("UP")
|
2020-05-24 19:14:09 +00:00
|
|
|
|
// Keyboard 2 JoyStick (Game Controller / Paddle)
|
2020-06-02 17:10:18 +00:00
|
|
|
|
if ( Keyboard2Joystick ) {
|
|
|
|
|
pdl_valarr[1] = 0
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
kbdInput(0x0A)
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-23 02:18:28 +00:00
|
|
|
|
default:
|
|
|
|
|
// print("keycode: %d", keyCode)
|
|
|
|
|
if let chars = event.characters {
|
|
|
|
|
let char = chars.uppercased()[chars.startIndex]
|
|
|
|
|
if let ascii = char.asciiValue {
|
|
|
|
|
kbdInput(ascii)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
}
|
2020-04-27 14:26:04 +00:00
|
|
|
|
|
2019-09-09 07:27:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-06 06:03:36 +00:00
|
|
|
|
|
|
|
|
|
var savedVideoMode = videoMode_t.init()
|
|
|
|
|
|
|
|
|
|
|
2020-02-23 00:37:54 +00:00
|
|
|
|
override func keyUp(with event: NSEvent) {
|
2020-06-06 06:16:17 +00:00
|
|
|
|
// print("keyUp")
|
2020-02-23 00:37:54 +00:00
|
|
|
|
// switch event.modifierFlags.intersection(.deviceIndependentFlagsMask) {
|
|
|
|
|
// case [.command] where event.characters == "l",
|
|
|
|
|
// [.command, .shift] where event.characters == "l":
|
|
|
|
|
// print("command-l or command-shift-l")
|
|
|
|
|
// default:
|
|
|
|
|
// break
|
|
|
|
|
// }
|
|
|
|
|
// print( "key = " + (event.charactersIgnoringModifiers ?? ""))
|
|
|
|
|
// print( "\ncharacter = " + (event.characters ?? ""))
|
|
|
|
|
|
|
|
|
|
#if FUNCTIONTEST
|
|
|
|
|
#else
|
|
|
|
|
let keyCode = Int(event.keyCode)
|
|
|
|
|
switch keyCode {
|
|
|
|
|
case leftArrowKey:
|
|
|
|
|
// kbdInput(0x08)
|
2020-05-24 19:14:09 +00:00
|
|
|
|
// setIO(0xC064, 127);
|
2020-06-06 06:16:17 +00:00
|
|
|
|
// print("left")
|
2020-05-24 19:14:09 +00:00
|
|
|
|
// Keyboard 2 JoyStick (Game Controller / Paddle)
|
|
|
|
|
pdl_valarr[0] = 0.5
|
|
|
|
|
|
2020-02-23 00:37:54 +00:00
|
|
|
|
case rightArrowKey:
|
|
|
|
|
// kbdInput(0x15)
|
2020-05-24 19:14:09 +00:00
|
|
|
|
// setIO(0xC064, 128);
|
2020-06-06 06:16:17 +00:00
|
|
|
|
// print("right")
|
2020-05-24 19:14:09 +00:00
|
|
|
|
// Keyboard 2 JoyStick (Game Controller / Paddle)
|
|
|
|
|
pdl_valarr[0] = 0.5
|
|
|
|
|
|
2020-02-23 00:37:54 +00:00
|
|
|
|
case downArrowKey:
|
|
|
|
|
// kbdInput(0x0B)
|
2020-05-24 19:14:09 +00:00
|
|
|
|
// setIO(0xC065, 127);
|
2020-06-06 06:16:17 +00:00
|
|
|
|
// print("down")
|
2020-05-24 19:14:09 +00:00
|
|
|
|
// Keyboard 2 JoyStick (Game Controller / Paddle)
|
|
|
|
|
pdl_valarr[1] = 0.5
|
|
|
|
|
|
2020-02-23 00:37:54 +00:00
|
|
|
|
case upArrowKey:
|
|
|
|
|
// kbdInput(0x0A)
|
2020-05-24 19:14:09 +00:00
|
|
|
|
// setIO(0xC065, 128);
|
2020-06-06 06:16:17 +00:00
|
|
|
|
// print("up")
|
2020-05-24 19:14:09 +00:00
|
|
|
|
// Keyboard 2 JoyStick (Game Controller / Paddle)
|
|
|
|
|
pdl_valarr[1] = 0.5
|
|
|
|
|
|
2020-02-23 00:37:54 +00:00
|
|
|
|
default:
|
|
|
|
|
// print("keycode: %d", keyCode)
|
|
|
|
|
// if let chars = event.characters {
|
|
|
|
|
// let char = chars.uppercased()[chars.startIndex]
|
|
|
|
|
// if let ascii = char.asciiValue {
|
|
|
|
|
// kbdInput(ascii)
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2020-05-05 15:35:57 +00:00
|
|
|
|
kbdUp()
|
|
|
|
|
|
2020-02-23 00:37:54 +00:00
|
|
|
|
}
|
2020-05-21 05:22:44 +00:00
|
|
|
|
|
|
|
|
|
override func flagsChanged(with event: NSEvent) {
|
|
|
|
|
switch event.modifierFlags.intersection(.deviceIndependentFlagsMask) {
|
|
|
|
|
case [.shift]:
|
2020-05-28 16:19:07 +00:00
|
|
|
|
setIO(0xC061, 0);
|
|
|
|
|
setIO(0xC062, 0);
|
2020-05-28 16:35:17 +00:00
|
|
|
|
setIO(0xC063, 0); // inverted (bit 7: not pressed)
|
2020-06-06 06:16:17 +00:00
|
|
|
|
// print("shift key is pressed")
|
|
|
|
|
// case [.control]:
|
|
|
|
|
// print("control key is pressed")
|
2020-05-21 05:22:44 +00:00
|
|
|
|
case [.option] :
|
|
|
|
|
setIO(0xC061, 1 << 7);
|
2020-05-28 16:19:07 +00:00
|
|
|
|
setIO(0xC062, 0);
|
2020-05-28 16:35:17 +00:00
|
|
|
|
setIO(0xC063, 1 << 7); // inverted (bit 7: not pressed)
|
2020-06-06 06:16:17 +00:00
|
|
|
|
// print("option key is pressed")
|
2020-05-21 05:22:44 +00:00
|
|
|
|
case [.command]:
|
2020-06-06 06:16:17 +00:00
|
|
|
|
// print("Command key is pressed")
|
2020-05-28 16:19:07 +00:00
|
|
|
|
setIO(0xC061, 0);
|
2020-05-21 05:22:44 +00:00
|
|
|
|
setIO(0xC062, 1 << 7);
|
2020-05-28 16:35:17 +00:00
|
|
|
|
setIO(0xC063, 1 << 7); // inverted (bit 7: not pressed)
|
2020-06-06 06:16:17 +00:00
|
|
|
|
// case [.control, .shift]:
|
|
|
|
|
// print("control-shift keys are pressed")
|
2020-05-21 05:22:44 +00:00
|
|
|
|
case [.option, .shift]:
|
2020-05-28 16:19:07 +00:00
|
|
|
|
setIO(0xC061, 1 << 7);
|
|
|
|
|
setIO(0xC062, 0);
|
2020-05-28 16:35:17 +00:00
|
|
|
|
setIO(0xC063, 0); // inverted (bit 7: not pressed)
|
2020-06-06 06:16:17 +00:00
|
|
|
|
// print("option-shift keys are pressed")
|
2020-05-21 05:22:44 +00:00
|
|
|
|
case [.command, .shift]:
|
2020-05-28 16:19:07 +00:00
|
|
|
|
setIO(0xC061, 0);
|
|
|
|
|
setIO(0xC062, 1 << 7);
|
2020-05-28 16:35:17 +00:00
|
|
|
|
setIO(0xC063, 0); // inverted (bit 7: not pressed)
|
2020-06-06 06:16:17 +00:00
|
|
|
|
// print("command-shift keys are pressed")
|
|
|
|
|
// case [.control, .option]:
|
|
|
|
|
// print("control-option keys are pressed")
|
|
|
|
|
// case [.control, .command]:
|
|
|
|
|
// print("control-command keys are pressed")
|
2020-05-21 05:22:44 +00:00
|
|
|
|
case [.option, .command]:
|
2020-05-28 16:19:07 +00:00
|
|
|
|
setIO(0xC061, 1 << 7);
|
|
|
|
|
setIO(0xC062, 1 << 7);
|
2020-05-28 16:35:17 +00:00
|
|
|
|
setIO(0xC063, 1 << 7); // inverted (bit 7: not pressed)
|
2020-06-06 06:16:17 +00:00
|
|
|
|
// print("option-command keys are pressed")
|
|
|
|
|
// case [.shift, .control, .option]:
|
|
|
|
|
// print("shift-control-option keys are pressed")
|
|
|
|
|
// case [.shift, .control, .command]:
|
|
|
|
|
// print("shift-control-command keys are pressed")
|
|
|
|
|
// case [.control, .option, .command]:
|
|
|
|
|
// print("control-option-command keys are pressed")
|
2020-05-21 05:22:44 +00:00
|
|
|
|
case [.shift, .command, .option]:
|
2020-05-28 16:19:07 +00:00
|
|
|
|
setIO(0xC061, 1 << 7);
|
|
|
|
|
setIO(0xC062, 1 << 7);
|
2020-05-28 16:35:17 +00:00
|
|
|
|
setIO(0xC063, 0); // inverted (bit 7: not pressed)
|
2020-06-06 06:16:17 +00:00
|
|
|
|
// print("shift-command-option keys are pressed")
|
|
|
|
|
// case [.shift, .control, .option, .command]:
|
|
|
|
|
// print("shift-control-option-command keys are pressed")
|
|
|
|
|
// case [.function]:
|
|
|
|
|
// print("function key is pressed")
|
|
|
|
|
// case [.capsLock]:
|
|
|
|
|
// print("capsLock key is pressed")
|
2020-05-21 05:22:44 +00:00
|
|
|
|
default:
|
|
|
|
|
setIO(0xC061, 0);
|
|
|
|
|
setIO(0xC062, 0);
|
2020-05-28 16:35:17 +00:00
|
|
|
|
setIO(0xC063, 1 << 7); // inverted (bit 7: not pressed)
|
2020-06-06 06:16:17 +00:00
|
|
|
|
// print("no modifier keys are pressed")
|
2020-05-21 05:22:44 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-09-09 07:27:31 +00:00
|
|
|
|
|
2020-02-23 00:37:54 +00:00
|
|
|
|
|
2019-09-19 09:27:56 +00:00
|
|
|
|
|
2019-11-28 04:27:32 +00:00
|
|
|
|
|
|
|
|
|
var was = 0;
|
|
|
|
|
|
2020-04-27 14:26:04 +00:00
|
|
|
|
var currentVideoMode = videoMode
|
2020-04-29 22:35:54 +00:00
|
|
|
|
var lastFrameTime = CACurrentMediaTime() as Double
|
2020-05-06 16:56:21 +00:00
|
|
|
|
var frameCounter : UInt32 = 0
|
2020-04-29 22:35:54 +00:00
|
|
|
|
var clkCounter : Double = 0
|
2020-05-06 16:56:21 +00:00
|
|
|
|
let fpsHalf = fps / 2
|
2020-04-27 14:26:04 +00:00
|
|
|
|
|
2020-05-21 05:22:44 +00:00
|
|
|
|
var mouseLocation = NSPoint.zero
|
|
|
|
|
|
2020-05-24 19:14:09 +00:00
|
|
|
|
var shadowTxt : String = ""
|
|
|
|
|
|
2020-06-11 00:48:37 +00:00
|
|
|
|
|
|
|
|
|
func Render() {
|
2019-09-17 09:12:05 +00:00
|
|
|
|
|
|
|
|
|
frameCnt += 1
|
2020-05-02 02:10:44 +00:00
|
|
|
|
|
2020-05-06 16:56:21 +00:00
|
|
|
|
if ( frameCnt == fpsHalf ) {
|
2020-06-11 00:48:37 +00:00
|
|
|
|
// flashingSpace = blockChar
|
2019-09-22 08:31:09 +00:00
|
|
|
|
ViewController.charConvTbl = ViewController.charConvTblFlashOn
|
2019-09-17 09:12:05 +00:00
|
|
|
|
}
|
2019-09-22 08:31:09 +00:00
|
|
|
|
else if ( frameCnt >= fps ) {
|
2020-06-11 00:48:37 +00:00
|
|
|
|
// flashingSpace = spaceChar
|
2019-09-22 08:31:09 +00:00
|
|
|
|
ViewController.charConvTbl = ViewController.charConvTblFlashOff
|
2019-09-17 09:12:05 +00:00
|
|
|
|
frameCnt = 0
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-02 02:10:44 +00:00
|
|
|
|
// Rendering is happening in the main thread, which has two implications:
|
|
|
|
|
// 1. We can update UI elements
|
|
|
|
|
// 2. it is independent of the simulation, de that is running in the background thread while we are busy with rendering...
|
2020-05-27 04:13:31 +00:00
|
|
|
|
DispatchQueue.main.sync {
|
2020-05-02 02:10:44 +00:00
|
|
|
|
var txt : String = ""
|
2020-06-11 00:48:37 +00:00
|
|
|
|
|
2020-05-02 02:10:44 +00:00
|
|
|
|
var fromLines = 0
|
|
|
|
|
var toLines = self.textLines
|
2020-06-11 00:48:37 +00:00
|
|
|
|
|
2020-05-02 02:10:44 +00:00
|
|
|
|
if videoMode.text == 0 {
|
|
|
|
|
if videoMode.mixed == 1 {
|
|
|
|
|
fromLines = toLines - 4
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
toLines = 0
|
|
|
|
|
}
|
2020-02-23 00:37:54 +00:00
|
|
|
|
}
|
2020-06-11 00:48:37 +00:00
|
|
|
|
|
2020-05-02 02:10:44 +00:00
|
|
|
|
self.txtArr = self.txtClear
|
2020-06-11 00:48:37 +00:00
|
|
|
|
|
2020-05-02 02:10:44 +00:00
|
|
|
|
// render an empty space to eiminate displaying text portion of the screen covered by graphics
|
2020-05-06 16:56:21 +00:00
|
|
|
|
let charDisposition = videoMode.col80 == 0 ? 1 : 2
|
2020-05-02 02:10:44 +00:00
|
|
|
|
for y in 0 ..< fromLines {
|
2020-05-07 20:20:46 +00:00
|
|
|
|
self.txtArr[ y * (self.textCols * charDisposition + self.lineEndChars) + self.textCols * charDisposition] = "\n"
|
2020-05-02 02:10:44 +00:00
|
|
|
|
}
|
2020-06-11 00:48:37 +00:00
|
|
|
|
|
|
|
|
|
|
2020-05-06 16:56:21 +00:00
|
|
|
|
// 40 col
|
|
|
|
|
if videoMode.col80 == 0 {
|
2020-05-25 04:04:34 +00:00
|
|
|
|
if MEMcfg.txt_page_2 == 0 {
|
|
|
|
|
self.textBufferPointer = ViewController.textPage1Pointer
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
self.textBufferPointer = ViewController.textPage2Pointer
|
|
|
|
|
}
|
2020-05-06 16:56:21 +00:00
|
|
|
|
// render the rest of the text screen
|
|
|
|
|
for y in fromLines ..< toLines {
|
|
|
|
|
for x in 0 ..< self.textCols {
|
2020-05-29 15:50:47 +00:00
|
|
|
|
let byte = self.textBufferPointer[ ViewController.textLineOfs[y] + x ]
|
2020-05-02 02:10:44 +00:00
|
|
|
|
let idx = Int(byte);
|
|
|
|
|
let chr = ViewController.charConvTbl[idx]
|
|
|
|
|
|
2020-05-06 16:56:21 +00:00
|
|
|
|
self.txtArr[ y * (self.textCols + self.lineEndChars) + x ] = chr
|
2020-05-02 02:10:44 +00:00
|
|
|
|
}
|
2020-05-06 16:56:21 +00:00
|
|
|
|
|
2020-05-02 02:10:44 +00:00
|
|
|
|
self.txtArr[ y * (self.textCols + self.lineEndChars) + self.textCols ] = "\n"
|
|
|
|
|
}
|
2020-05-06 16:56:21 +00:00
|
|
|
|
}
|
2020-06-11 00:48:37 +00:00
|
|
|
|
// 80 col
|
2020-05-06 16:56:21 +00:00
|
|
|
|
else {
|
2020-05-27 04:13:31 +00:00
|
|
|
|
let auxPage = ( MEMcfg.is_80STORE == 1 ) && ( MEMcfg.txt_page_2 == 1 )
|
|
|
|
|
|
|
|
|
|
let textIntBuffer = auxPage ? ViewController.textIntBufferPointer : ViewController.textPage1Pointer
|
|
|
|
|
let textAuxBuffer = auxPage ? ViewController.textPage1Pointer : ViewController.textAuxBufferPointer
|
|
|
|
|
|
2020-05-06 16:56:21 +00:00
|
|
|
|
// render the rest of the text screen
|
|
|
|
|
for y in fromLines ..< toLines {
|
|
|
|
|
for x in 0 ..< self.textCols {
|
2020-05-29 15:50:47 +00:00
|
|
|
|
let byte = textIntBuffer[ ViewController.textLineOfs[y] + x ]
|
2020-05-06 16:56:21 +00:00
|
|
|
|
let idx = Int(byte);
|
|
|
|
|
let chr = ViewController.charConvTbl[idx]
|
|
|
|
|
|
|
|
|
|
self.txtArr[ y * (self.textCols * 2 + self.lineEndChars) + x * 2 + 1] = chr
|
|
|
|
|
|
2020-05-29 15:50:47 +00:00
|
|
|
|
let byte2 = textAuxBuffer[ ViewController.textLineOfs[y] + x ]
|
2020-05-06 16:56:21 +00:00
|
|
|
|
let idx2 = Int(byte2);
|
|
|
|
|
let chr2 = ViewController.charConvTbl[idx2]
|
|
|
|
|
|
|
|
|
|
self.txtArr[ y * (self.textCols * 2 + self.lineEndChars) + x * 2] = chr2
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-02 02:10:44 +00:00
|
|
|
|
self.txtArr[ y * (self.textCols * 2 + self.lineEndChars) + self.textCols * 2] = "\n"
|
2020-04-27 14:26:04 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-06-11 00:48:37 +00:00
|
|
|
|
|
|
|
|
|
|
2020-05-02 02:10:44 +00:00
|
|
|
|
txt = String(self.txtArr)
|
2020-06-11 00:48:37 +00:00
|
|
|
|
|
2020-05-29 15:50:47 +00:00
|
|
|
|
// TODO: Render text Screen in native C
|
2020-06-11 00:48:37 +00:00
|
|
|
|
// txt = String(bytesNoCopy: ViewController.textScreen!, length: 10, encoding: .ascii, freeWhenDone: false) ?? "HMM"
|
|
|
|
|
|
2020-04-27 14:26:04 +00:00
|
|
|
|
if videoMode.col80 != self.currentVideoMode.col80 {
|
|
|
|
|
self.currentVideoMode.col80 = videoMode.col80
|
|
|
|
|
|
|
|
|
|
if let fontSize = self.display.font?.pointSize {
|
|
|
|
|
if videoMode.col80 == 1 {
|
|
|
|
|
self.display.font = NSFont(name: "PRNumber3", size: fontSize)
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
self.display.font = NSFont(name: "PrintChar21", size: fontSize)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-24 19:14:09 +00:00
|
|
|
|
if ( self.shadowTxt != txt ) {
|
|
|
|
|
self.shadowTxt = txt
|
|
|
|
|
self.display.stringValue = txt
|
|
|
|
|
}
|
2020-06-11 00:48:37 +00:00
|
|
|
|
// self.display.stringValue = "testing\nit\nout"
|
|
|
|
|
|
2020-04-29 22:35:54 +00:00
|
|
|
|
if ( (mhz < 1.5) && (mhz != floor(mhz)) ) {
|
2019-09-22 08:31:09 +00:00
|
|
|
|
self.speedometer.stringValue = String(format: "%0.3lf MHz", mhz);
|
|
|
|
|
}
|
|
|
|
|
else {
|
2020-04-29 22:35:54 +00:00
|
|
|
|
self.speedometer.stringValue = String(format: "%0.1lf MHz", mhz);
|
2019-09-22 08:31:09 +00:00
|
|
|
|
}
|
2020-06-11 00:48:37 +00:00
|
|
|
|
// else {
|
|
|
|
|
// self.speedometer.stringValue = String(format: "%.0lf MHz", mhz);
|
|
|
|
|
// }
|
2019-09-22 08:31:09 +00:00
|
|
|
|
|
2019-11-28 04:27:32 +00:00
|
|
|
|
#if HIRES
|
2020-06-11 00:48:37 +00:00
|
|
|
|
|
2020-05-19 04:17:19 +00:00
|
|
|
|
// only refresh graphics view when needed (aka not in text mode)
|
|
|
|
|
if ( videoMode.text == 0 ) {
|
2020-05-29 15:50:47 +00:00
|
|
|
|
if ( videoMode.hires == 0 ) {
|
|
|
|
|
// when we change video mode, buffer needs to be cleared to avoid artifacts
|
|
|
|
|
if ( self.savedVideoMode.text == 1 )
|
2020-06-11 00:48:37 +00:00
|
|
|
|
|| ( self.savedVideoMode.mixed != videoMode.mixed )
|
|
|
|
|
|| ( self.savedVideoMode.hires != videoMode.hires )
|
2020-05-29 15:50:47 +00:00
|
|
|
|
{
|
|
|
|
|
self.lores.clearScreen()
|
|
|
|
|
self.lores.isHidden = false
|
|
|
|
|
self.hires.isHidden = true
|
|
|
|
|
}
|
2020-06-11 00:48:37 +00:00
|
|
|
|
|
2020-05-29 15:50:47 +00:00
|
|
|
|
self.lores.Update()
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
// when we change video mode, buffer needs to be cleared to avoid artifacts
|
|
|
|
|
if ( self.savedVideoMode.text == 1 )
|
2020-06-11 00:48:37 +00:00
|
|
|
|
|| ( self.savedVideoMode.mixed != videoMode.mixed )
|
|
|
|
|
|| ( self.savedVideoMode.hires != videoMode.hires )
|
2020-05-29 15:50:47 +00:00
|
|
|
|
{
|
|
|
|
|
self.hires.clearScreen()
|
|
|
|
|
self.hires.isHidden = false
|
|
|
|
|
self.lores.isHidden = true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
self.hires.Update()
|
|
|
|
|
}
|
2020-05-04 20:53:36 +00:00
|
|
|
|
}
|
2020-05-19 04:17:19 +00:00
|
|
|
|
else if ( self.savedVideoMode.text == 0 ) {
|
|
|
|
|
// we just switched from grahics to text
|
2020-05-29 15:50:47 +00:00
|
|
|
|
self.lores.isHidden = true
|
2020-05-19 04:17:19 +00:00
|
|
|
|
self.hires.isHidden = true
|
|
|
|
|
}
|
2020-06-11 00:48:37 +00:00
|
|
|
|
|
2020-05-19 04:17:19 +00:00
|
|
|
|
self.savedVideoMode = videoMode
|
2020-06-11 00:48:37 +00:00
|
|
|
|
|
2019-11-28 04:27:32 +00:00
|
|
|
|
#endif
|
2020-06-11 00:48:37 +00:00
|
|
|
|
|
2020-05-17 14:49:05 +00:00
|
|
|
|
// stream speaker from a separate thread from the simulation
|
|
|
|
|
// TODO: Do we need to do this from here?
|
2020-06-11 00:48:37 +00:00
|
|
|
|
// spkr_update()
|
|
|
|
|
|
2020-05-28 16:35:17 +00:00
|
|
|
|
// Mouse 2 JoyStick (Game Controller / Paddle)
|
|
|
|
|
mouseLocation = view.window!.mouseLocationOutsideOfEventStream
|
2020-05-29 15:50:47 +00:00
|
|
|
|
|
2020-06-02 17:10:18 +00:00
|
|
|
|
if ( Mouse2Joystick ) {
|
|
|
|
|
pdl_prevarr[0] = pdl_valarr[0]
|
|
|
|
|
pdl_valarr[0] = Double(mouseLocation.x / (displayField.frame.width) )
|
|
|
|
|
pdl_diffarr[0] = pdl_valarr[0] - pdl_prevarr[0]
|
|
|
|
|
|
|
|
|
|
pdl_prevarr[1] = pdl_valarr[1]
|
|
|
|
|
pdl_valarr[1] = 1 - Double(mouseLocation.y / (displayField.frame.height) )
|
|
|
|
|
pdl_diffarr[1] = pdl_valarr[1] - pdl_prevarr[1]
|
|
|
|
|
}
|
2020-05-29 15:50:47 +00:00
|
|
|
|
|
2020-06-02 17:10:18 +00:00
|
|
|
|
if ( MouseInterface ) {
|
|
|
|
|
pdl_prevarr[2] = pdl_valarr[2]
|
|
|
|
|
pdl_valarr[2] = Double(mouseLocation.x / (displayField.frame.width) )
|
|
|
|
|
pdl_diffarr[2] = pdl_valarr[2] - pdl_prevarr[2]
|
|
|
|
|
|
|
|
|
|
pdl_prevarr[3] = pdl_valarr[3]
|
|
|
|
|
pdl_valarr[3] = 1 - Double(mouseLocation.y / (displayField.frame.height) )
|
|
|
|
|
pdl_diffarr[3] = pdl_valarr[3] - pdl_prevarr[3]
|
|
|
|
|
}
|
2020-05-29 15:50:47 +00:00
|
|
|
|
}
|
2020-06-11 00:48:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2020-06-17 16:46:17 +00:00
|
|
|
|
func Input() {
|
|
|
|
|
// Mouse 2 JoyStick (Game Controller / Paddle)
|
|
|
|
|
mouseLocation = view.window!.mouseLocationOutsideOfEventStream
|
2020-06-11 00:48:37 +00:00
|
|
|
|
|
2020-06-17 16:46:17 +00:00
|
|
|
|
if ( Mouse2Joystick ) {
|
|
|
|
|
pdl_prevarr[0] = pdl_valarr[0]
|
|
|
|
|
pdl_valarr[0] = Double(mouseLocation.x / (displayField.frame.width) )
|
|
|
|
|
pdl_diffarr[0] = pdl_valarr[0] - pdl_prevarr[0]
|
|
|
|
|
|
|
|
|
|
pdl_prevarr[1] = pdl_valarr[1]
|
|
|
|
|
pdl_valarr[1] = 1 - Double(mouseLocation.y / (displayField.frame.height) )
|
|
|
|
|
pdl_diffarr[1] = pdl_valarr[1] - pdl_prevarr[1]
|
2020-04-30 14:26:46 +00:00
|
|
|
|
}
|
2020-04-29 22:35:54 +00:00
|
|
|
|
|
2020-06-17 16:46:17 +00:00
|
|
|
|
if ( MouseInterface ) {
|
|
|
|
|
pdl_prevarr[2] = pdl_valarr[2]
|
|
|
|
|
pdl_valarr[2] = Double(mouseLocation.x / (displayField.frame.width) )
|
|
|
|
|
pdl_diffarr[2] = pdl_valarr[2] - pdl_prevarr[2]
|
|
|
|
|
|
|
|
|
|
pdl_prevarr[3] = pdl_valarr[3]
|
|
|
|
|
pdl_valarr[3] = 1 - Double(mouseLocation.y / (displayField.frame.height) )
|
|
|
|
|
pdl_diffarr[3] = pdl_valarr[3] - pdl_prevarr[3]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func Update() {
|
|
|
|
|
switch cpuState {
|
|
|
|
|
case cpuState_running:
|
|
|
|
|
clkCounter += Double(clkfrm)
|
|
|
|
|
// we start a new frame from here, so CPU is running even while rendering
|
|
|
|
|
clkfrm = 0
|
|
|
|
|
|
|
|
|
|
frameCounter += 1
|
|
|
|
|
|
|
|
|
|
if ( frameCounter % fps == 0 ) {
|
|
|
|
|
let currentTime = CACurrentMediaTime() as Double
|
|
|
|
|
let elpasedTime = currentTime - lastFrameTime
|
|
|
|
|
lastFrameTime = currentTime
|
|
|
|
|
mhz = Double( clkCounter ) / (elpasedTime * M);
|
|
|
|
|
clkCounter = 0
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#if SPEEDTEST
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
|
|
// poll input devices like mouse and joystick
|
|
|
|
|
Input()
|
|
|
|
|
|
|
|
|
|
// run some code
|
|
|
|
|
m6502_Run()
|
|
|
|
|
|
|
|
|
|
// video rendering
|
|
|
|
|
// if ( frameCounter % 5 == 0 ) {
|
|
|
|
|
Render()
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
case cpuState_halting:
|
|
|
|
|
cpuState = cpuState_halted
|
|
|
|
|
|
|
|
|
|
// clkCounter += Double(clkfrm)
|
|
|
|
|
// // we start a new frame from here, so CPU is running even while rendering
|
|
|
|
|
// clkfrm = 0
|
|
|
|
|
//
|
|
|
|
|
// frameCounter += 1
|
|
|
|
|
//
|
|
|
|
|
// if ( frameCounter % fps == 0 ) {
|
|
|
|
|
// let currentTime = CACurrentMediaTime() as Double
|
|
|
|
|
// let elpasedTime = currentTime - lastFrameTime
|
|
|
|
|
// lastFrameTime = currentTime
|
|
|
|
|
// mhz = Double( clkCounter ) / (elpasedTime * M);
|
|
|
|
|
// clkCounter = 0
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// #if SPEEDTEST
|
|
|
|
|
// #else
|
|
|
|
|
//
|
|
|
|
|
// // poll input devices like mouse and joystick
|
|
|
|
|
// Input()
|
|
|
|
|
//
|
|
|
|
|
// // run some code
|
|
|
|
|
// m6502_Run()
|
|
|
|
|
//
|
|
|
|
|
// video rendering
|
|
|
|
|
// if ( frameCounter % 5 == 0 ) {
|
|
|
|
|
Render()
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// #endif
|
|
|
|
|
|
|
|
|
|
break
|
2020-06-18 22:14:54 +00:00
|
|
|
|
|
|
|
|
|
case cpuState_halted:
|
|
|
|
|
upd.suspend()
|
|
|
|
|
break
|
2020-06-17 16:46:17 +00:00
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-07 23:18:05 +00:00
|
|
|
|
}
|
2019-09-15 11:02:22 +00:00
|
|
|
|
|
2019-09-07 23:18:05 +00:00
|
|
|
|
|
|
|
|
|
// func FromBuf(ptr: UnsafeMutablePointer<UInt8>, length len: Int) -> String? {
|
|
|
|
|
// // convert the bytes using the UTF8 encoding
|
|
|
|
|
// if let theString = NSString(bytes: ptr, length: len, encoding: NSUTF8StringEncoding) {
|
|
|
|
|
// return theString as String
|
|
|
|
|
// } else {
|
|
|
|
|
// return nil // the bytes aren't valid UTF8
|
|
|
|
|
// }
|
|
|
|
|
// }
|
2019-11-28 04:27:32 +00:00
|
|
|
|
|
2019-09-15 11:02:22 +00:00
|
|
|
|
|
2019-09-22 08:31:09 +00:00
|
|
|
|
let upd = RepeatingTimer(timeInterval: 1/Double(fps))
|
2020-04-30 14:26:46 +00:00
|
|
|
|
|
2020-06-04 18:37:35 +00:00
|
|
|
|
static var current : ViewController? = nil
|
2020-02-07 08:40:31 +00:00
|
|
|
|
|
2019-07-26 05:51:36 +00:00
|
|
|
|
override func viewDidLoad() {
|
|
|
|
|
super.viewDidLoad()
|
2019-09-19 09:27:56 +00:00
|
|
|
|
|
2020-06-03 17:23:55 +00:00
|
|
|
|
ViewController.current = self
|
|
|
|
|
|
2020-05-09 10:39:55 +00:00
|
|
|
|
hires.clearScreen();
|
2020-05-05 15:35:57 +00:00
|
|
|
|
|
2020-06-12 01:29:26 +00:00
|
|
|
|
spkr_load_sfx( Bundle.main.resourcePath! )
|
|
|
|
|
|
2020-06-04 18:37:35 +00:00
|
|
|
|
let woz_err = woz_loadFile( Bundle.main.resourcePath! + "/Apple DOS 3.3 January 1983.woz" )
|
|
|
|
|
chk_woz_load(err: woz_err)
|
|
|
|
|
|
2019-11-28 04:27:32 +00:00
|
|
|
|
//view.frame = CGRect(origin: CGPoint(), size: NSScreen.main!.visibleFrame.size)
|
|
|
|
|
|
|
|
|
|
// createHiRes()
|
|
|
|
|
|
2019-09-22 08:31:09 +00:00
|
|
|
|
self.displayField.scaleUnitSquare(to: NSSize(width: 1, height: 1))
|
|
|
|
|
|
|
|
|
|
// NSEvent.removeMonitor(NSEvent.EventType.flagsChanged)
|
|
|
|
|
// NSEvent.addLocalMonitorForEvents(matching: .flagsChanged) {
|
|
|
|
|
// self.flagsChanged(with: $0)
|
|
|
|
|
// return $0
|
|
|
|
|
// }
|
2019-11-28 04:27:32 +00:00
|
|
|
|
|
2020-04-27 14:26:04 +00:00
|
|
|
|
// NSEvent.removeMonitor(NSEvent.EventType.keyDown)
|
|
|
|
|
NSEvent.addLocalMonitorForEvents(matching: .keyDown) {
|
|
|
|
|
// print("keyDown event")
|
|
|
|
|
self.keyDown(with: $0)
|
|
|
|
|
return nil
|
2019-11-28 04:27:32 +00:00
|
|
|
|
// return $0
|
2020-04-27 14:26:04 +00:00
|
|
|
|
}
|
|
|
|
|
NSEvent.addLocalMonitorForEvents(matching: .keyUp) {
|
|
|
|
|
// print("keyUp event")
|
|
|
|
|
self.keyUp(with: $0)
|
|
|
|
|
return nil
|
|
|
|
|
// return $0
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-19 09:27:56 +00:00
|
|
|
|
displayField.maximumNumberOfLines = textLines
|
|
|
|
|
displayField.preferredMaxLayoutWidth = displayField.frame.width
|
2019-09-07 23:18:05 +00:00
|
|
|
|
|
2019-09-22 08:31:09 +00:00
|
|
|
|
// DispatchQueue.main.asyncAfter(deadline: .now() + 1/fps, execute: {
|
2019-09-09 02:55:19 +00:00
|
|
|
|
// self.update()
|
2019-09-08 21:52:52 +00:00
|
|
|
|
// })
|
2019-09-15 11:02:22 +00:00
|
|
|
|
|
2019-09-17 09:12:05 +00:00
|
|
|
|
// #if FUNCTIONTEST
|
|
|
|
|
// #else
|
2019-09-15 11:02:22 +00:00
|
|
|
|
// DispatchQueue.global(qos: .background).async {
|
|
|
|
|
// self.update()
|
|
|
|
|
// }
|
2019-09-07 23:18:05 +00:00
|
|
|
|
|
2019-09-15 11:02:22 +00:00
|
|
|
|
upd.eventHandler = {
|
2019-09-17 09:12:05 +00:00
|
|
|
|
self.Update()
|
2019-09-09 02:55:19 +00:00
|
|
|
|
}
|
2019-09-15 11:02:22 +00:00
|
|
|
|
upd.resume()
|
2019-09-17 09:12:05 +00:00
|
|
|
|
// #endif
|
2019-07-26 05:51:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-01-28 06:54:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func setCPUClockSpeed( freq : Double ) {
|
2020-06-14 03:13:20 +00:00
|
|
|
|
MHz_6502 = freq
|
|
|
|
|
clk_6502_per_frm = UInt64( MHz_6502 * M / Double(fps) )
|
2020-02-17 07:09:29 +00:00
|
|
|
|
clk_6502_per_frm_set = clk_6502_per_frm
|
2019-07-26 05:51:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-01-28 06:54:03 +00:00
|
|
|
|
@IBAction func speedSelected(_ sender: NSButton) {
|
2020-04-29 22:35:54 +00:00
|
|
|
|
if ( sender.title == "MAX" ) {
|
2020-05-09 02:47:19 +00:00
|
|
|
|
setCPUClockSpeed(freq: 1600)
|
2020-01-28 06:54:03 +00:00
|
|
|
|
}
|
|
|
|
|
else if let freq = Double( sender.title ) {
|
|
|
|
|
setCPUClockSpeed(freq: freq)
|
2020-05-28 02:12:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: Probably this is not the best way to deal with the problem: To make sound continous independent of FPS and Freq
|
|
|
|
|
|
2020-06-14 03:13:20 +00:00
|
|
|
|
// spkr_extra_buf = Int32( 780 / fps )
|
|
|
|
|
spkr_extra_buf = 0
|
2020-05-28 02:12:28 +00:00
|
|
|
|
|
|
|
|
|
switch freq {
|
|
|
|
|
case 2.0:
|
2020-06-14 03:13:20 +00:00
|
|
|
|
// spkr_extra_buf = Int32( Double(spkr_extra_buf) * 2.961538461538462 ) // normally it should come up as 77, but this way it is calculated with FPS
|
|
|
|
|
spkr_extra_buf = 50
|
2020-05-28 02:12:28 +00:00
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
case 4.0:
|
2020-06-14 03:13:20 +00:00
|
|
|
|
// spkr_extra_buf = Int32( Double(spkr_extra_buf) * 1.346153846153846 ) // normally it should come up as 35, but this way it is calculated with FPS
|
|
|
|
|
spkr_extra_buf = 8
|
2020-05-28 02:12:28 +00:00
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
default:
|
2020-06-14 03:13:20 +00:00
|
|
|
|
// spkr_extra_buf = Int32( 780 / fps ) // normally it should come up as 26, but this way it is calculated with FPS
|
|
|
|
|
spkr_extra_buf = 0
|
2020-05-28 02:12:28 +00:00
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SoundGap.integerValue = Int(spkr_extra_buf)
|
2020-01-28 06:54:03 +00:00
|
|
|
|
}
|
2020-05-28 02:12:28 +00:00
|
|
|
|
|
2020-01-28 06:54:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-06-17 16:46:17 +00:00
|
|
|
|
@IBAction func setCPUMode(_ sender: NSButton) {
|
|
|
|
|
switch ( sender.title ) {
|
|
|
|
|
case "Eco":
|
|
|
|
|
cpuMode = cpuMode_eco
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
case "Game":
|
|
|
|
|
cpuMode = cpuMode_game
|
|
|
|
|
cpuState = cpuState_running
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
cpuMode = cpuMode_normal
|
|
|
|
|
cpuState = cpuState_running
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-01-28 06:54:03 +00:00
|
|
|
|
|
2020-05-17 14:49:05 +00:00
|
|
|
|
@IBOutlet weak var SoundGap: NSTextFieldCell!
|
|
|
|
|
|
|
|
|
|
@IBAction func SoundGapChanged(_ sender: NSStepper) {
|
|
|
|
|
SoundGap.integerValue = sender.integerValue
|
2020-06-14 03:13:20 +00:00
|
|
|
|
spkr_extra_buf = Int32( sender.integerValue )
|
2020-05-17 14:49:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-06-17 16:46:17 +00:00
|
|
|
|
@IBAction func CRTMonitorOnOff(_ sender: NSButton) {
|
|
|
|
|
CRTMonitor = sender.state == .on
|
|
|
|
|
scanLines.isHidden = !CRTMonitor
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-02 17:10:18 +00:00
|
|
|
|
@IBAction func Keyboard2JoystickOnOff(_ sender: NSButton) {
|
|
|
|
|
Keyboard2Joystick = sender.state == .on
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@IBAction func Mouse2JoystickOnOff(_ sender: NSButton) {
|
|
|
|
|
Mouse2Joystick = sender.state == .on
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@IBAction func MouseOnOff(_ sender: NSButton) {
|
|
|
|
|
MouseInterface = sender.state == .on
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-28 02:12:28 +00:00
|
|
|
|
@IBAction func QuickDisk(_ sender: NSButton) {
|
|
|
|
|
if sender.state == .on {
|
2020-06-12 05:44:53 +00:00
|
|
|
|
diskAccelerator_enabled = 1;
|
2020-05-28 02:12:28 +00:00
|
|
|
|
}
|
|
|
|
|
else {
|
2020-06-12 05:44:53 +00:00
|
|
|
|
diskAccelerator_enabled = 0;
|
2020-05-28 02:12:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-06-12 06:16:26 +00:00
|
|
|
|
|
|
|
|
|
@IBAction func DiskSound(_ sender: NSButton) {
|
|
|
|
|
if sender.state == .on {
|
|
|
|
|
disk_sfx_enabled = 1;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
disk_sfx_enabled = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-03 17:23:55 +00:00
|
|
|
|
|
|
|
|
|
@objc func openDiskImage() {
|
|
|
|
|
let openPanel = NSOpenPanel()
|
|
|
|
|
openPanel.title = "Disk Image"
|
|
|
|
|
openPanel.allowsMultipleSelection = false
|
|
|
|
|
openPanel.canChooseDirectories = false
|
|
|
|
|
openPanel.canCreateDirectories = false
|
|
|
|
|
openPanel.canChooseFiles = true
|
|
|
|
|
openPanel.allowedFileTypes = ["dsk","do","po","nib", "woz"]
|
|
|
|
|
|
|
|
|
|
openPanel.begin { (result) -> Void in
|
|
|
|
|
if result == NSApplication.ModalResponse.OK {
|
|
|
|
|
print("file:", openPanel.url!.path)
|
|
|
|
|
//Do what you will
|
|
|
|
|
//If there's only one URL, surely 'openPanel.URL'
|
|
|
|
|
//but otherwise a for loop works
|
|
|
|
|
|
|
|
|
|
if let filePath = openPanel.url?.path {
|
2020-06-04 18:37:35 +00:00
|
|
|
|
let woz_err = woz_loadFile( filePath )
|
|
|
|
|
|
|
|
|
|
if woz_err == WOZ_ERR_OK {
|
|
|
|
|
NSDocumentController.shared.noteNewRecentDocumentURL(URL(fileURLWithPath: filePath))
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
self.chk_woz_load(err: woz_err)
|
|
|
|
|
}
|
2020-06-03 17:23:55 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@IBAction func openDocument(_ sender: Any?) {
|
|
|
|
|
openDiskImage()
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-19 22:16:27 +00:00
|
|
|
|
@IBAction func traceEnable(_ sender: NSButton) {
|
|
|
|
|
switch sender.state {
|
|
|
|
|
case .on:
|
|
|
|
|
m6502.dbgLevel.trace = 1
|
|
|
|
|
openLog()
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
m6502.dbgLevel.trace = 0
|
|
|
|
|
closeLog()
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-05-28 02:12:28 +00:00
|
|
|
|
|
2019-07-26 05:51:36 +00:00
|
|
|
|
}
|
|
|
|
|
|