diff --git a/A2Mac.xcodeproj/project.pbxproj b/A2Mac.xcodeproj/project.pbxproj index ecd410f..72ea7ce 100644 --- a/A2Mac.xcodeproj/project.pbxproj +++ b/A2Mac.xcodeproj/project.pbxproj @@ -1899,7 +1899,7 @@ "$(inherited)", "@executable_path/../Frameworks", ); - MACOSX_DEPLOYMENT_TARGET = 10.11; + MACOSX_DEPLOYMENT_TARGET = 10.12; MARKETING_VERSION = 0.85; OTHER_CFLAGS = ( "-DDISASSEMBLER", @@ -1942,7 +1942,7 @@ "@executable_path/../Frameworks", ); LLVM_LTO = YES_THIN; - MACOSX_DEPLOYMENT_TARGET = 10.11; + MACOSX_DEPLOYMENT_TARGET = 10.12; MARKETING_VERSION = 0.85; OTHER_CFLAGS = ( "-DDISASSEMBLER", @@ -2096,7 +2096,7 @@ "$(inherited)", "@executable_path/../Frameworks", ); - MACOSX_DEPLOYMENT_TARGET = 10.11; + MACOSX_DEPLOYMENT_TARGET = 10.12; MARKETING_VERSION = 0.86; OTHER_CFLAGS = ( "-D_NO_DISASSEMBLER", @@ -2138,7 +2138,7 @@ "@executable_path/../Frameworks", ); LLVM_LTO = YES_THIN; - MACOSX_DEPLOYMENT_TARGET = 10.11; + MACOSX_DEPLOYMENT_TARGET = 10.12; MARKETING_VERSION = 0.86; OTHER_CFLAGS = ( "-D_NO_DISASSEMBLER", diff --git a/A2Mac.xcodeproj/project.xcworkspace/xcuserdata/trudnai.xcuserdatad/xcdebugger/Expressions.xcexplist b/A2Mac.xcodeproj/project.xcworkspace/xcuserdata/trudnai.xcuserdatad/xcdebugger/Expressions.xcexplist index 96dfe07..dcde6a3 100644 --- a/A2Mac.xcodeproj/project.xcworkspace/xcuserdata/trudnai.xcuserdatad/xcdebugger/Expressions.xcexplist +++ b/A2Mac.xcodeproj/project.xcworkspace/xcuserdata/trudnai.xcuserdatad/xcdebugger/Expressions.xcexplist @@ -45,7 +45,7 @@ contextName = "spkr_toggle:speaker.c"> + value = "( (spkr_clk + m6502.clkfrm) / ( default_MHz_6502 * 1000 * 1000 / spkr_sample_rate)) * 2"> @@ -63,7 +63,7 @@ value = "(int)spkr_sample_idx_diff"> + value = "spkr_samples[spkr_sample_last_idx]"> @@ -152,7 +152,7 @@ contextName = "closure #1 in ViewController.Update():ViewController.swift"> + value = "txtArr"> @@ -161,10 +161,10 @@ value = "txt"> + value = "MEMcfg.txt_page_2"> + value = "MEMcfg.is_80STORE"> @@ -238,6 +238,20 @@ + + + + + + + + + + @@ -270,7 +284,7 @@ contextName = "LoRes.Update():LoRes.swift"> + value = "blockChanged[ screenIdx ]"> @@ -279,7 +293,7 @@ value = "UInt8(block & 4)"> + value = "UInt8( (block >> 4) & 0x0F )"> @@ -547,13 +561,13 @@ contextName = "HiRes.compute():HiRes.swift"> + value = "computePipelineState.maxTotalThreadsPerThreadgroup"> + value = "UnsafeRawBufferPointer(result)"> @@ -612,7 +626,7 @@ value = "new"> + value = "WOZwrite.shift16"> @@ -624,7 +638,7 @@ value = "(1 << i) - 1"> + value = "WOZtmp.shift16"> @@ -773,10 +787,10 @@ contextName = "set_flags_NZC:common.h"> + value = "(unsigned)test "> + value = "(unsigned)0xFF"> @@ -784,10 +798,10 @@ contextName = "HiRes.draw(_:):HiRes.swift"> + value = "linAddr"> + value = "ctx?.bitsPerComponent"> @@ -804,6 +818,9 @@ + + @@ -814,10 +831,7 @@ value = "ctx?.height"> - - + value = "ctx?.data"> @@ -841,6 +855,9 @@ + + @@ -853,9 +870,6 @@ - - + value = "m6502.PC"> + value = "Apple2_64K_RAM + 0x3600"> + value = "(void*)Apple2_64K_RAM"> @@ -978,6 +992,17 @@ + + + + + + + + @@ -988,7 +1013,7 @@ value = "pdl_value[pdl]"> + value = "normalized_time >= pdl_value[pdl] ? 255 : 0"> @@ -1000,7 +1025,7 @@ value = "1 * 512 * (1 - ( 3300 / 3300.0 ))"> + value = "normalized_time"> @@ -1071,10 +1096,10 @@ value = "Apple2_64K_AUX + 0xC600"> + value = "(void*)rom"> + value = "Apple2_64K_RAM + 0xC600"> diff --git a/A2Mac/Base.lproj/Main.storyboard b/A2Mac/Base.lproj/Main.storyboard index b896f25..31382b1 100644 --- a/A2Mac/Base.lproj/Main.storyboard +++ b/A2Mac/Base.lproj/Main.storyboard @@ -1439,7 +1439,7 @@ - + @@ -1682,6 +1682,7 @@ + @@ -1853,7 +1854,7 @@ - + @@ -1887,7 +1888,7 @@ - + @@ -138916,7 +138917,7 @@ BQB9EQcAfREJAH0RCwB9ERQAfREZAH0RHwB9EScAfREpAH0RKwB9ES0AfREvAH0imwB9IqAAfSKtAH0i sAB9Ir0AfSLCAH0iygB9Is0AfSLSAH0i2gAAAAAAAAQBAAAAAAAAAFAAAAAAAAAAAAAAAAAAfSLdA - + YnBsaXN0MDDUAQIDBAUGBwpYJHZlcnNpb25ZJGFyY2hpdmVyVCR0b3BYJG9iamVjdHMSAAGGoF8QD05T S2V5ZWRBcmNoaXZlctEICVRyb290gAGvEBcLDBkaIRQmKisyNTo9PkNGR0pUXF1hZFUkbnVsbNYNDg8Q diff --git a/A2Mac/DisplayView.swift b/A2Mac/DisplayView.swift index c24b26d..b7e4140 100644 --- a/A2Mac/DisplayView.swift +++ b/A2Mac/DisplayView.swift @@ -16,6 +16,28 @@ class DisplayView: NSTextView { // } // } + var trackingArea: NSTrackingArea? + + /// Install tracking area if window is set, remove previous one if needed. + func installTrackingArea() { + guard let window = window else { return } + window.acceptsMouseMovedEvents = true + if trackingArea != nil { removeTrackingArea(trackingArea!) } + let trackingOptions : NSTrackingArea.Options = [.activeAlways, .mouseEnteredAndExited, .mouseMoved] + trackingArea = NSTrackingArea(rect: bounds, + options: trackingOptions, + owner: self, userInfo: nil) + self.addTrackingArea(trackingArea!) + } + + + // Called when layout is modified + override func updateTrackingAreas() { + super.updateTrackingAreas() + installTrackingArea() + } + + override func acceptsFirstMouse(for event: NSEvent?) -> Bool { return true } diff --git a/A2Mac/ToolBarController.swift b/A2Mac/ToolBarController.swift index 20fad9b..4bf8af3 100644 --- a/A2Mac/ToolBarController.swift +++ b/A2Mac/ToolBarController.swift @@ -26,6 +26,13 @@ import Cocoa class ToolBarController: NSWindowController, NSWindowDelegate { + static var current : ToolBarController? = nil + + required init?(coder: NSCoder) { + super.init(coder: coder) + ToolBarController.current = self + } + func window(_ window: NSWindow, willUseFullScreenPresentationOptions proposedOptions: NSApplication.PresentationOptions = []) -> NSApplication.PresentationOptions { return [.autoHideToolbar, .autoHideMenuBar, .fullScreen] } @@ -260,6 +267,16 @@ class ToolBarController: NSWindowController, NSWindowDelegate { if let state = ViewController.current?.Mouse2Joystick { ViewController.current?.Mouse2Joystick = !state sender.selectedItem?.state = state ? .off : .on + + if !state { +// NSCursor.hide() + ViewController.current?.mouseCursorJoystickEmulation.set() + } + else { + NSCursor.unhide() +// NSCursor.arrow.set() + } + } break @@ -275,6 +292,8 @@ class ToolBarController: NSWindowController, NSWindowDelegate { } } + @IBOutlet weak var MouseToJoystickMenuItem: NSMenuItem! + @IBAction func DiskOptions(_ sender: NSPopUpButton) { switch sender.selectedItem?.tag { case 1: // "Quick Disk" diff --git a/A2Mac/ViewController.swift b/A2Mac/ViewController.swift index 181e964..38012cf 100644 --- a/A2Mac/ViewController.swift +++ b/A2Mac/ViewController.swift @@ -462,31 +462,84 @@ class ViewController: NSViewController { } } + let mouseCursorJoystickEmulation = NSCursor.crosshair + + func getScreenWithMouse() -> NSScreen? { + let mouseLocation = NSEvent.mouseLocation + let screens = NSScreen.screens + let screenWithMouse = (screens.first { NSMouseInRect(mouseLocation, $0.frame, false) }) + + return screenWithMouse + } + + + func convertPoint(toCG : NSPoint) -> CGPoint { + /// Cocoa and Core Graphics (a.k.a. Quartz) use different coordinate systems. In Cocoa, the origin is at the lower left of the primary screen and y increases as you go up. In Core Graphics, the origin is at the top left of the primary screen and y increases as you go down. + /// Need to convert coordinates from Cocoa to Core Graphics + var CGPoint = view.window!.convertPoint(toScreen: toCG) + if let screen = getScreenWithMouse() { + CGPoint.y = NSHeight(screen.frame) - CGPoint.y; + } + return CGPoint + } + + override func mouseMoved(with event: NSEvent) { // print(#function) - mouseLocation = event.locationInWindow + var location = event.locationInWindow +// displayOrigin = textDisplayScroller.frame.origin. +// print("mx:", location.x, " my:", location.y) + + var mouseCursorNeedsReplace = false + if location.x < 8 { + mouseCursorNeedsReplace = true + location.x = 8 + } + if location.x >= textDisplay.frame.width - 7 { + mouseCursorNeedsReplace = true + location.x = textDisplay.frame.width - 8 + } + if location.y < 8 { + mouseCursorNeedsReplace = true + location.y = 8 + } + if location.y >= textDisplay.frame.height - 7 { + mouseCursorNeedsReplace = true + location.y = textDisplay.frame.height - 8 + } + if ( Mouse2Joystick ) { + mouseCursorJoystickEmulation.set() + + if mouseCursorNeedsReplace { + CGWarpMouseCursorPosition(convertPoint(toCG: location)) + } + pdl_prevarr[0] = pdl_valarr[0] - pdl_valarr[0] = Double(mouseLocation.x / (textDisplayScroller.frame.width) ) + pdl_valarr[0] = Double(location.x / (textDisplay.frame.width) ) pdl_diffarr[0] = pdl_valarr[0] - pdl_prevarr[0] pdl_prevarr[1] = pdl_valarr[1] - pdl_valarr[1] = 1 - Double(mouseLocation.y / (textDisplayScroller.frame.height) ) + pdl_valarr[1] = 1 - Double(location.y / (textDisplay.frame.height) ) pdl_diffarr[1] = pdl_valarr[1] - pdl_prevarr[1] } + else { + NSCursor.arrow.set() + } if ( MouseInterface ) { pdl_prevarr[2] = pdl_valarr[2] - pdl_valarr[2] = Double(mouseLocation.x / (textDisplayScroller.frame.width) ) + pdl_valarr[2] = Double(location.x / (textDisplay.frame.width) ) pdl_diffarr[2] = pdl_valarr[2] - pdl_prevarr[2] pdl_prevarr[3] = pdl_valarr[3] - pdl_valarr[3] = 1 - Double(mouseLocation.y / (textDisplayScroller.frame.height) ) + pdl_valarr[3] = 1 - Double(location.y / (textDisplay.frame.height) ) pdl_diffarr[3] = pdl_valarr[3] - pdl_prevarr[3] } } + override func keyDown(with event: NSEvent) { if ( cpuMode == cpuMode_eco ) { @@ -734,8 +787,6 @@ class ViewController: NSViewController { var frameCounter : UInt32 = 0 var clkCounter : Double = 0 - var mouseLocation = NSPoint.zero - var shadowTxt : String = "" var unicodeTextString : String = "" @@ -977,9 +1028,27 @@ class ViewController: NSViewController { override func mouseDown(with event: NSEvent) { // print(#function) + + switch event.modifierFlags.intersection(.deviceIndependentFlagsMask) { + case [.control, .command, .option]: + Mouse2Joystick = !Mouse2Joystick + + if Mouse2Joystick { + ToolBarController.current?.MouseToJoystickMenuItem.state = .on + mouseCursorJoystickEmulation.set() + } + else { + ToolBarController.current?.MouseToJoystickMenuItem.state = .off + NSCursor.arrow.set() + } + default: + break + } + if ( Mouse2Joystick ) { setIO(0xC061, 1 << 7) } + } override func mouseUp(with event: NSEvent) {