From 2045435cf41dae03402efe9c5a34028d52302eb7 Mon Sep 17 00:00:00 2001 From: Luigi Thirty Date: Mon, 31 Jul 2017 03:03:14 -0400 Subject: [PATCH] adding a preferences screen and stuff --- FruitMachine.xcodeproj/project.pbxproj | 12 +- FruitMachine/AppDelegate.swift | 5 + FruitMachine/AppleI/AppleGLDisplay.swift | 83 --- FruitMachine/AppleI/AppleI.swift | 6 - FruitMachine/FruitMachine.storyboard | 526 +----------------- FruitMachine/MainViewController.swift | 18 +- FruitMachine/PreferencesWindow.xib | 135 +++++ .../PreferencesWindowController.swift | 43 ++ 8 files changed, 218 insertions(+), 610 deletions(-) delete mode 100644 FruitMachine/AppleI/AppleGLDisplay.swift create mode 100644 FruitMachine/PreferencesWindow.xib create mode 100644 FruitMachine/PreferencesWindowController.swift diff --git a/FruitMachine.xcodeproj/project.pbxproj b/FruitMachine.xcodeproj/project.pbxproj index fdff203..641aeb8 100644 --- a/FruitMachine.xcodeproj/project.pbxproj +++ b/FruitMachine.xcodeproj/project.pbxproj @@ -13,7 +13,8 @@ 2A5BC51C1F29A2EB008C03BE /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2A5BC51B1F29A2EB008C03BE /* QuartzCore.framework */; }; 2A5BC51E1F29A4C3008C03BE /* AppleIBitmapDisplay.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A5BC51D1F29A4C3008C03BE /* AppleIBitmapDisplay.swift */; }; 2A60851E1F2AFAE900E05B64 /* PIA.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A60851D1F2AFAE900E05B64 /* PIA.swift */; }; - 2A6D3BF21F2E6222001CBEFB /* AppleGLDisplay.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A6D3BF11F2E6222001CBEFB /* AppleGLDisplay.swift */; }; + 2A7665781F2F05F600135518 /* PreferencesWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A7665761F2F05F600135518 /* PreferencesWindowController.swift */; }; + 2A7665791F2F05F600135518 /* PreferencesWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 2A7665771F2F05F600135518 /* PreferencesWindow.xib */; }; 2A91852A1F2EA84D00A9E5BE /* BitmapPixels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A9185291F2EA84D00A9E5BE /* BitmapPixels.swift */; }; 2AA8B5F81F2A8889002B350F /* AppleI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2AA8B5F71F2A8889002B350F /* AppleI.swift */; }; 2AA8B5FC1F2A8EAD002B350F /* Terminal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2AA8B5FB1F2A8EAD002B350F /* Terminal.swift */; }; @@ -44,7 +45,8 @@ 2A5BC51B1F29A2EB008C03BE /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; }; 2A5BC51D1F29A4C3008C03BE /* AppleIBitmapDisplay.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppleIBitmapDisplay.swift; sourceTree = ""; }; 2A60851D1F2AFAE900E05B64 /* PIA.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PIA.swift; sourceTree = ""; }; - 2A6D3BF11F2E6222001CBEFB /* AppleGLDisplay.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppleGLDisplay.swift; sourceTree = ""; }; + 2A7665761F2F05F600135518 /* PreferencesWindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreferencesWindowController.swift; sourceTree = ""; }; + 2A7665771F2F05F600135518 /* PreferencesWindow.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = PreferencesWindow.xib; sourceTree = ""; }; 2A9185291F2EA84D00A9E5BE /* BitmapPixels.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BitmapPixels.swift; sourceTree = ""; }; 2AA8B5F71F2A8889002B350F /* AppleI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppleI.swift; sourceTree = ""; }; 2AA8B5FB1F2A8EAD002B350F /* Terminal.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Terminal.swift; sourceTree = ""; }; @@ -99,7 +101,6 @@ 2A5BC51D1F29A4C3008C03BE /* AppleIBitmapDisplay.swift */, 2AA8B5F71F2A8889002B350F /* AppleI.swift */, 2A60851D1F2AFAE900E05B64 /* PIA.swift */, - 2A6D3BF11F2E6222001CBEFB /* AppleGLDisplay.swift */, ); path = AppleI; sourceTree = ""; @@ -129,6 +130,8 @@ 2AD458CD1F205EB700F05121 /* AppDelegate.swift */, 2AE42E381F28628300C4900E /* MainViewController.swift */, 2AE42E3F1F28638100C4900E /* FruitMachine.storyboard */, + 2A7665761F2F05F600135518 /* PreferencesWindowController.swift */, + 2A7665771F2F05F600135518 /* PreferencesWindow.xib */, 2AD458D11F205EB700F05121 /* Assets.xcassets */, 2AD458D61F205EB700F05121 /* Info.plist */, 2AD458D71F205EB700F05121 /* FruitMachine.entitlements */, @@ -258,6 +261,7 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + 2A7665791F2F05F600135518 /* PreferencesWindow.xib in Resources */, 2AD458D21F205EB700F05121 /* Assets.xcassets in Resources */, 2AE42E401F28638100C4900E /* FruitMachine.storyboard in Resources */, 2AD458D51F205EB700F05121 /* Debugger.storyboard in Resources */, @@ -275,6 +279,7 @@ 2A2126841F2A9FA300E43DC1 /* DebuggerWindowController.swift in Sources */, 2AD458E31F20661300F05121 /* CPUInstructions.swift in Sources */, 2AD458D01F205EB700F05121 /* DebuggerViewController.swift in Sources */, + 2A7665781F2F05F600135518 /* PreferencesWindowController.swift in Sources */, 2AA8B5FC1F2A8EAD002B350F /* Terminal.swift in Sources */, 2A5BC51E1F29A4C3008C03BE /* AppleIBitmapDisplay.swift in Sources */, 2AD458CE1F205EB700F05121 /* AppDelegate.swift in Sources */, @@ -291,7 +296,6 @@ 2AE5BA061F2469EB00FAA343 /* AddressConversions.swift in Sources */, 2AE42E0A1F28521E00C4900E /* WriteOverride.swift in Sources */, 2A5BC5191F29A28D008C03BE /* AppleScreenView.swift in Sources */, - 2A6D3BF21F2E6222001CBEFB /* AppleGLDisplay.swift in Sources */, 2AD458E11F2064CB00F05121 /* MemoryInterface.swift in Sources */, 2AA8B5F81F2A8889002B350F /* AppleI.swift in Sources */, 2AD458DF1F205F4500F05121 /* CPU.swift in Sources */, diff --git a/FruitMachine/AppDelegate.swift b/FruitMachine/AppDelegate.swift index 1f9b1ca..6824a87 100644 --- a/FruitMachine/AppDelegate.swift +++ b/FruitMachine/AppDelegate.swift @@ -27,5 +27,10 @@ class AppDelegate: NSObject, NSApplicationDelegate { @IBAction func view_scale_2x(_ sender: Any) { NotificationCenter.default.post(Notification(name: AppleScreenNotifications, object: "scaleFactor", userInfo: ["scaleFactor": 2])) } + + func applicationShouldTerminateAfterLastWindowClosed (_ theApplication: NSApplication) -> Bool { + return true + } + } diff --git a/FruitMachine/AppleI/AppleGLDisplay.swift b/FruitMachine/AppleI/AppleGLDisplay.swift deleted file mode 100644 index 35e2b94..0000000 --- a/FruitMachine/AppleI/AppleGLDisplay.swift +++ /dev/null @@ -1,83 +0,0 @@ -// -// AppleGLDisplay.swift -// FruitMachine -// -// Created by Christopher Rohl on 7/30/17. -// Copyright © 2017 Christopher Rohl. All rights reserved. -// - -import Cocoa -import OpenGL -import GLKit - -class AppleGLDisplay: NSOpenGLView { - - var displayLink: CVDisplayLink? - - override func draw(_ dirtyRect: NSRect) { - super.draw(dirtyRect) - - // Drawing code here. - renderFrame() - - } - - func doSetup() { - let attr = [ - NSOpenGLPixelFormatAttribute(NSOpenGLPFAOpenGLProfile), - NSOpenGLPixelFormatAttribute(NSOpenGLProfileVersion3_2Core), - NSOpenGLPixelFormatAttribute(NSOpenGLPFAColorSize), 24, - NSOpenGLPixelFormatAttribute(NSOpenGLPFAAlphaSize), 8, - NSOpenGLPixelFormatAttribute(NSOpenGLPFADoubleBuffer), - NSOpenGLPixelFormatAttribute(NSOpenGLPFADepthSize), 32, - 0 - ] - - self.pixelFormat = NSOpenGLPixelFormat(attributes: attr) - self.openGLContext = NSOpenGLContext(format: pixelFormat!, share: nil) - } - - override func prepareOpenGL() { - - func displayLinkOutputCallback(displayLink: CVDisplayLink, _ now: UnsafePointer, _ outputTime: UnsafePointer, _ flagsIn: CVOptionFlags, _ flagsOut: UnsafeMutablePointer, _ displayLinkContext: UnsafeMutableRawPointer?) -> CVReturn { - unsafeBitCast(displayLinkContext, to: AppleGLDisplay.self).renderFrame() - return kCVReturnSuccess - } - - CVDisplayLinkCreateWithActiveCGDisplays(&displayLink) - CVDisplayLinkSetOutputCallback(displayLink!, displayLinkOutputCallback, UnsafeMutableRawPointer(Unmanaged.passUnretained(self).toOpaque())) - CVDisplayLinkStart(displayLink!) - } - - func renderFrame() { - CGLLockContext((self.openGLContext?.cglContextObj!)!) - CGLSetCurrentContext((self.openGLContext?.cglContextObj!)!) - - // Draw something... - glClearColor(0.0, 0.0, 0.0, 0.0); - glClear(GLbitfield(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)); - - let vertices = [GLfloat]([-1, -1, 0, - -1, 1, 0, - 1, 1, 0, - 1, -1, 0]) - - let indices = [GLubyte]([0, 1, 2, - 0, 2, 3]) - - glEnableVertexAttribArray(0) - - let ptr = UnsafePointer(vertices) - glVertexAttribPointer(0, 3, GLenum(GL_FLOAT), GLboolean(GL_FALSE), GLsizei(MemoryLayout.size), ptr) - - glDrawElements(GLenum(GL_TRIANGLES), 6, GLenum(GL_UNSIGNED_BYTE), indices) - - CGLFlushDrawable((self.openGLContext?.cglContextObj!)!) - CGLUnlockContext((self.openGLContext?.cglContextObj!)!) - } - - deinit { - CVDisplayLinkStop(displayLink!) - } - -} diff --git a/FruitMachine/AppleI/AppleI.swift b/FruitMachine/AppleI/AppleI.swift index 383a595..5d3cde3 100644 --- a/FruitMachine/AppleI/AppleI.swift +++ b/FruitMachine/AppleI/AppleI.swift @@ -23,9 +23,6 @@ class AppleI: NSObject { let emulatorView = AppleScreenView(frame: NSMakeRect(0, 0, 640, 384)) let emuScreenLayer = CALayer() - //OpenGL - let emuGLView = AppleGLDisplay() - static let CPU_FREQUENCY = 1000000 static let FRAMES_PER_SECOND = 60 static let CYCLES_PER_BATCH = CPU_FREQUENCY / FRAMES_PER_SECOND @@ -42,9 +39,6 @@ class AppleI: NSObject { emuScreenLayer.setNeedsDisplay() emulatorView.layer?.addSublayer(emuScreenLayer) - //GL - emuGLView.frame = emulatorView.bounds - installOverrides() for (cellNum, character) in terminal.characters.enumerated() { diff --git a/FruitMachine/FruitMachine.storyboard b/FruitMachine/FruitMachine.storyboard index 187096c..ba8a136 100644 --- a/FruitMachine/FruitMachine.storyboard +++ b/FruitMachine/FruitMachine.storyboard @@ -119,517 +119,10 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Default - - - - - - - Left to Right - - - - - - - Right to Left - - - - - - - - - - - Default - - - - - - - Left to Right - - - - - - - Right to Left - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -643,6 +136,19 @@ + + + + + + + + + + + + + @@ -697,9 +203,11 @@ - + + + @@ -710,7 +218,7 @@ - + diff --git a/FruitMachine/MainViewController.swift b/FruitMachine/MainViewController.swift index 37699bf..ac182c9 100644 --- a/FruitMachine/MainViewController.swift +++ b/FruitMachine/MainViewController.swift @@ -15,23 +15,20 @@ class MainViewController: NSViewController { let computer = AppleI.sharedInstance var debuggerWindowController: DebuggerWindowController! + var preferencesWindowController: PreferencesWindowController! var isPaused = false var frameTimer: Timer? override func viewDidLoad() { super.viewDidLoad() - - let debuggerStoryboard = NSStoryboard(name: NSStoryboard.Name(rawValue: "Debugger"), bundle: nil) - debuggerWindowController = debuggerStoryboard.instantiateInitialController() as! DebuggerWindowController - debuggerWindowController.showWindow(self) + + preferencesWindowController = PreferencesWindowController() + preferencesWindowController.loadWindow() // Do view setup here. self.view.addSubview(computer.emulatorView) - //computer.emuGLView.doSetup() - //self.view.addSubview(computer.emuGLView) - self.frameTimer = Timer.scheduledTimer(timeInterval: 1/60, target: self, selector: #selector(runEmulation), @@ -64,7 +61,12 @@ class MainViewController: NSViewController { } return nil } - + + @IBAction func showDebugger(_ sender: Any) { + let debuggerStoryboard = NSStoryboard(name: NSStoryboard.Name(rawValue: "Debugger"), bundle: nil) + debuggerWindowController = debuggerStoryboard.instantiateInitialController() as! DebuggerWindowController + debuggerWindowController.showWindow(self) + } } extension Character { diff --git a/FruitMachine/PreferencesWindow.xib b/FruitMachine/PreferencesWindow.xib new file mode 100644 index 0000000..1f61b04 --- /dev/null +++ b/FruitMachine/PreferencesWindow.xib @@ -0,0 +1,135 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/FruitMachine/PreferencesWindowController.swift b/FruitMachine/PreferencesWindowController.swift new file mode 100644 index 0000000..9adb100 --- /dev/null +++ b/FruitMachine/PreferencesWindowController.swift @@ -0,0 +1,43 @@ +// +// PreferencesWindow.swift +// FruitMachine +// +// Created by Christopher Rohl on 7/31/17. +// Copyright © 2017 Christopher Rohl. All rights reserved. +// + +import Cocoa + +class PreferencesWindowController: NSWindowController { + @IBOutlet weak var path_ROMMonitor: NSTextField! + @IBOutlet weak var path_ROMCharacter: NSTextField! + @IBOutlet weak var path_ROMBasic: NSTextField! + + let defaults = UserDefaults.standard + + override func windowDidLoad() { + super.windowDidLoad() + + // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file. + let monitorPath = defaults.string(forKey: "path_ROMMonitor") + let characterPath = defaults.string(forKey: "path_ROMCharacter") + let basicPath = defaults.string(forKey: "path_ROMBasic") + + if (monitorPath != nil) { + path_ROMMonitor.stringValue = monitorPath! + } + + if (characterPath != nil) { + path_ROMCharacter.stringValue = characterPath! + } + + if (basicPath != nil) { + path_ROMBasic.stringValue = basicPath! + } + } + + override var windowNibName : NSNib.Name? { + return NSNib.Name(rawValue: "PreferencesWindow") + } + +}