From e2a37a2e0ce91c02a6a342de90b26100b1d54083 Mon Sep 17 00:00:00 2001 From: tudnai Date: Sun, 13 Nov 2022 16:31:08 -0800 Subject: [PATCH] Entering addresses to Memory and Disassembly --- A2Mac.xcodeproj/project.pbxproj | 12 ++ .../xcdebugger/Expressions.xcexplist | 3 + A2Mac/Base.lproj/Debugger.storyboard | 21 ++- A2Mac/DebuggerViewController.swift | 90 ++++++++--- A2Mac/DebuggerWindowController.swift | 2 + A2Mac/HexDigitFormatter.swift | 91 +++++++++++ A2Mac/String.swift | 16 ++ A2Mac/ViewController.swift | 148 ++++++++++-------- 8 files changed, 290 insertions(+), 93 deletions(-) create mode 100644 A2Mac/HexDigitFormatter.swift create mode 100644 A2Mac/String.swift diff --git a/A2Mac.xcodeproj/project.pbxproj b/A2Mac.xcodeproj/project.pbxproj index c6e34fa..ab9172c 100644 --- a/A2Mac.xcodeproj/project.pbxproj +++ b/A2Mac.xcodeproj/project.pbxproj @@ -230,6 +230,10 @@ 32D0897D291A44F200F2B486 /* 6502_bp.c in Sources */ = {isa = PBXBuildFile; fileRef = 32D0897B291A44F200F2B486 /* 6502_bp.c */; }; 32D089D8291E1BF800F2B486 /* DisassView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32D089D7291E1BF800F2B486 /* DisassView.swift */; }; 32D089D9291E1BF800F2B486 /* DisassView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32D089D7291E1BF800F2B486 /* DisassView.swift */; }; + 32D08A1429219C6B00F2B486 /* HexDigitFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32D08A1329219C6A00F2B486 /* HexDigitFormatter.swift */; }; + 32D08A1529219C6B00F2B486 /* HexDigitFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32D08A1329219C6A00F2B486 /* HexDigitFormatter.swift */; }; + 32D08A202921A8FA00F2B486 /* String.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32D08A1F2921A8F900F2B486 /* String.swift */; }; + 32D08A212921A8FA00F2B486 /* String.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32D08A1F2921A8F900F2B486 /* String.swift */; }; 32E3126624A7193700E61891 /* disk_ii_arm.sfx in Resources */ = {isa = PBXBuildFile; fileRef = 32E3126424A7193700E61891 /* disk_ii_arm.sfx */; }; 32E3126724A7194900E61891 /* disk_ii_arm.sfx in Copy SFX Files */ = {isa = PBXBuildFile; fileRef = 32E3126424A7193700E61891 /* disk_ii_arm.sfx */; }; 32E3126924A98B9300E61891 /* dsk2woz.c in Sources */ = {isa = PBXBuildFile; fileRef = 32E3126824A98B9300E61891 /* dsk2woz.c */; }; @@ -751,6 +755,8 @@ 32D08992291AF23500F2B486 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = A2Mac/Base.lproj/Debug.storyboard; sourceTree = ""; }; 32D089D7291E1BF800F2B486 /* DisassView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DisassView.swift; sourceTree = ""; }; 32D089EC291EE19200F2B486 /* UnfairLock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnfairLock.swift; sourceTree = ""; }; + 32D08A1329219C6A00F2B486 /* HexDigitFormatter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HexDigitFormatter.swift; sourceTree = ""; }; + 32D08A1F2921A8F900F2B486 /* String.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = String.swift; sourceTree = ""; }; 32DBF7632334657900DD50E7 /* HiRes.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HiRes.swift; sourceTree = ""; }; 32DBF76723373FB400DD50E7 /* disassembler.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = disassembler.h; sourceTree = ""; }; 32E21BE62491BF8B006C0C72 /* apple-rainbow.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "apple-rainbow.png"; sourceTree = ""; }; @@ -1177,6 +1183,7 @@ 32D089EC291EE19200F2B486 /* UnfairLock.swift */, 32BFFB5A22EACC630003B53F /* AppDelegate.swift */, 32B3778E291787CA0040845B /* NSLayoutConstraint.swift */, + 32D08A1F2921A8F900F2B486 /* String.swift */, 32100A8A2875387300D894EE /* CheatMenu.swift */, 32100A9E28753AAA00D894EE /* SubMenu.swift */, 32BFFB5C22EACC630003B53F /* ViewController.swift */, @@ -1186,6 +1193,7 @@ 323D042F24898AB70086A901 /* PreferencesViewController.swift */, 32D089D7291E1BF800F2B486 /* DisassView.swift */, 327B75D629064FDC00A86A71 /* DebuggerViewController.swift */, + 32D08A1329219C6A00F2B486 /* HexDigitFormatter.swift */, 32C823392908822E0018438F /* DebuggerWindowController.swift */, 323D04312489BFD80086A901 /* PreferencesWindowController.swift */, 32B18435233F10BC00DBB4AB /* Shaders.metal */, @@ -1661,6 +1669,7 @@ 32799F81264B1A5700255669 /* disk.c in Sources */, 3268B97B27DE7D6B003FBDCC /* disassembler.c in Sources */, 32C82360290888D10018438F /* CheatMenu.swift in Sources */, + 32D08A212921A8FA00F2B486 /* String.swift in Sources */, 32100AB52877AB8600D894EE /* scsi.c in Sources */, 32C6996727C548C900D0F25D /* Shaders.metal in Sources */, 32799F82264B1A5700255669 /* woz.c in Sources */, @@ -1677,6 +1686,7 @@ 327B75D829064FDC00A86A71 /* DebuggerViewController.swift in Sources */, 32799F88264B1A5700255669 /* RepeatingTimer.swift in Sources */, 32A6AAFA266AEDF50023257A /* mmio.c in Sources */, + 32D08A1529219C6B00F2B486 /* HexDigitFormatter.swift in Sources */, 32799F8A264B1A5700255669 /* MonitorView.swift in Sources */, 3277D7A4273C603600749544 /* DisplayScrollView.swift in Sources */, 32A6AB25266B19680023257A /* hires.c in Sources */, @@ -1698,8 +1708,10 @@ 32E3126924A98B9300E61891 /* dsk2woz.c in Sources */, 325B7611290A0C4100B29605 /* 6502_debugger.c in Sources */, 325EB63623F8F78300C6B4A4 /* disk.c in Sources */, + 32D08A1429219C6B00F2B486 /* HexDigitFormatter.swift in Sources */, 32100A8B2875387300D894EE /* CheatMenu.swift in Sources */, 3268B97A27DE7D6A003FBDCC /* disassembler.c in Sources */, + 32D08A202921A8FA00F2B486 /* String.swift in Sources */, 32D089D8291E1BF800F2B486 /* DisassView.swift in Sources */, 32C6995D27C548C800D0F25D /* Shaders.metal in Sources */, 325EB62F23F8856F00C6B4A4 /* woz.c in Sources */, 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 bf252e1..a8a8220 100644 --- a/A2Mac.xcodeproj/project.xcworkspace/xcuserdata/trudnai.xcuserdatad/xcdebugger/Expressions.xcexplist +++ b/A2Mac.xcodeproj/project.xcworkspace/xcuserdata/trudnai.xcuserdatad/xcdebugger/Expressions.xcexplist @@ -905,6 +905,9 @@ + + - + @@ -252,6 +252,9 @@ + + + @@ -323,7 +326,7 @@ - + @@ -422,7 +425,7 @@ C20D: 4C C5 FE JMP $FEC5
FEC5: 8D 06 C0 STA $C006 - + @@ -541,7 +544,7 @@ C20D: 4C C5 FE JMP $FEC5
FEC5: 8D 06 C0 STA $C006 - + @@ -565,7 +568,7 @@ C20D: 4C C5 FE JMP $FEC5
FEC5: 8D 06 C0 STA $C006 - + @@ -631,10 +634,13 @@ C20D: 4C C5 FE JMP $FEC5
FEC5: 8D 06 C0 STA $C006 - + + + + @@ -792,9 +798,12 @@ C20D: 4C C5 FE JMP $FEC5
FEC5: 8D 06 C0 STA $C006 + + + diff --git a/A2Mac/DebuggerViewController.swift b/A2Mac/DebuggerViewController.swift index d4fa42e..2477110 100644 --- a/A2Mac/DebuggerViewController.swift +++ b/A2Mac/DebuggerViewController.swift @@ -31,16 +31,20 @@ class DebuggerViewController: NSViewController { @IBOutlet var Mem1_Display: DisplayView! @IBOutlet var Disass_Scroll: DisplayScrollView! @IBOutlet var Disass_Display: DisplayView! + @IBOutlet weak var MemoryAddressField: NSTextField! + @IBOutlet weak var DisassAddressField: NSTextField! + @IBOutlet weak var DisassAddressPC: NSButton! + + + required init?(coder: NSCoder) { + super.init(coder: coder) + DebuggerViewController.shared = self + } - // required init?(coder: NSCoder) { -// super.init(coder: coder) -// DebuggerViewController.shared = self -// } override func viewDidLoad() { super.viewDidLoad() self.preferredContentSize = NSMakeSize(self.view.frame.size.width, self.view.frame.size.height) - DebuggerViewController.shared = self } @@ -55,6 +59,9 @@ class DebuggerViewController: NSViewController { if let debugger = DebuggerWindowController.shared { debugger.PauseButtonUpdate(needUpdateMainToolbar: false) } + + MemoryAddressField.formatter = HexDigitFormatter(maxLen: 4) + DisassAddressField.formatter = HexDigitFormatter(maxLen: 4) } @@ -174,9 +181,11 @@ N V - B D I Z C } + var mem_1_addr : UInt16 = 0x400 + func DisplayMemory() { var memory = "" - for i : UInt16 in stride(from: 0x400, to: 0x4FF, by: 16) { + for i : UInt16 in stride(from: mem_1_addr, to: mem_1_addr + 0xFF, by: 16) { memory += hexLine16(addr: i) + " " + textLine16(addr: i) + "\n" } @@ -227,11 +236,13 @@ N V - B D I Z C let disass_addr_min : UInt16 = 320 let disass_addr_max : UInt16 = 512 - var disass_addr : UInt16 = 0 + var disass_addr : UInt16 = 0 /// Address disassembled in the window + var disass_addr_pc : UInt16 = 0 /// Address to disassemble let disass_addr_pre : UInt16 = 20 let disass_addr_min_pre : UInt16 = 320 - 20 var line_number = 0 - var line_number_at_PC = 0 + var scroll_line_number = 0 + var highlighted_line_number = 0 var line_number_cursor = 0 let lines_to_disass = 300 @@ -375,7 +386,7 @@ N V - B D I Z C location.y = maxY - location.y + display.visibleRect.origin.y let line = getLine(inView: display, forY: location.y) - highlight(view: display, line: line_number_at_PC, attr: lineAttrAtPC) + highlight(view: display, line: highlighted_line_number, attr: lineAttrAtPC) remove_highlight(view: display, line: line_number_cursor) highlight(view: display, line: line, attr: lineAttrAtSelected) line_number_cursor = line @@ -431,22 +442,34 @@ N V - B D I Z C line_number = 0 - let highlighted = self.line_number_at_PC + let highlighted = self.highlighted_line_number + DispatchQueue.main.async { self.remove_highlight(view: self.Disass_Display, line: highlighted) } // TODO: Also check if memory area updated! - var need_disass = m6502.PC <= disass_addr || m6502.PC > disass_addr + disass_addr_max - line_number_at_PC = getLine(forAddr: m6502.PC) +// DispatchQueue.main.sync { + let addrpc = DisassAddressPC == nil || DisassAddressPC.state == .on + if addrpc { + disass_addr_pc = m6502.PC + } +// } + var need_disass = disass_addr_pc <= disass_addr || disass_addr_pc > disass_addr + disass_addr_max + scroll_line_number = getLine(forAddr: disass_addr_pc) + highlighted_line_number = getLine(forAddr: m6502.PC) -// if m6502.PC > disass_addr && m6502.PC < disass_addr + disass_addr_max { - if line_number_at_PC == 0 || need_disass { +// if disass_addr_pc > disass_addr && disass_addr_pc < disass_addr + disass_addr_max { + if scroll_line_number == 0 || need_disass { ViewController.shared?.UpdateSemaphore.wait() let m6502_saved = m6502 + if !addrpc { + m6502.PC = disass_addr_pc + } + need_disass = true addr_line.removeAll() @@ -478,7 +501,10 @@ N V - B D I Z C if isCurrentLine { // line = invertLine(line: line) - line_number_at_PC = line_number + highlighted_line_number = line_number + } + if m6502.PC == disass_addr_pc { + scroll_line_number = line_number } disass += line + "\n" @@ -495,24 +521,25 @@ N V - B D I Z C } let currentScrollLine = self.get_scroll_line(view: self.Disass_Display) + 1 - if self.line_number_at_PC <= currentScrollLine || self.line_number_at_PC > currentScrollLine + 35 { - self.scroll_to(view: self.Disass_Display, line: self.line_number_at_PC - 5) + if self.highlighted_line_number <= currentScrollLine || self.highlighted_line_number > currentScrollLine + 35 { if scrollY < 0 { + self.scroll_to(view: self.Disass_Display, line: self.scroll_line_number - 5) + // at the beginning it takes a while to fill up the buffer -- maybe allocation issue? - if currentScrollLine == 1 { - // so we need to scroll a bit later when the string is already populated - // DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { - self.scroll_to(view: self.Disass_Display, line: self.line_number_at_PC - 5) - // } - } +// if currentScrollLine == 1 { +// // so we need to scroll a bit later when the string is already populated +// // DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { +// self.scroll_to(view: self.Disass_Display, line: self.line_number_at_PC - 5) +// // } +// } } else { // caller wants a specific scroll location... self.Disass_Display.scroll(NSPoint(x: 0, y: scrollY)) } } - self.highlight(view: self.Disass_Display, line: self.line_number_at_PC, attr: self.lineAttrAtPC) + self.highlight(view: self.Disass_Display, line: self.highlighted_line_number, attr: self.lineAttrAtPC) } // DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { // your code here @@ -538,4 +565,19 @@ N V - B D I Z C } } + + @IBAction func MemoryAddressEntered(_ sender: NSTextFieldCell) { + NSLog("MemoryAddressEntered %@", sender.stringValue) + mem_1_addr = UInt16(sender.stringValue.hexValue()) + DisplayMemory() + } + + @IBAction func DisassAddressEntered(_ sender: NSTextFieldCell) { + NSLog("DisassAddressEntered %@", sender.stringValue) +// sender.stringValue = "4321" // MemoryAddressField.stringValue + DisassAddressPC.state = .off + disass_addr_pc = UInt16(sender.stringValue.hexValue()) + DisplayDisassembly() + } + } diff --git a/A2Mac/DebuggerWindowController.swift b/A2Mac/DebuggerWindowController.swift index ed58c3e..2e21ed2 100644 --- a/A2Mac/DebuggerWindowController.swift +++ b/A2Mac/DebuggerWindowController.swift @@ -48,11 +48,13 @@ class DebuggerWindowController: NSWindowController, NSWindowDelegate { func windowDidBecomeKey(_ notification: Notification) { // NSLog("windowDidBecomeKey") isKey = true + ViewController.shared?.keyEventsOff() } func windowDidResignKey(_ notification: Notification) { // NSLog("windowDidResignKey") isKey = false + ViewController.shared?.keyEventsOn() } func windowWillClose(_ notification: Notification) { diff --git a/A2Mac/HexDigitFormatter.swift b/A2Mac/HexDigitFormatter.swift new file mode 100644 index 0000000..005238d --- /dev/null +++ b/A2Mac/HexDigitFormatter.swift @@ -0,0 +1,91 @@ +// +// HexDigitFormatter.swift +// A2Mac +// +// Created by Tamas Rudnai on 11/13/22. +// Copyright © 2022 GameAlloy. All rights reserved. +// + +import Foundation + +class HexDigitFormatter: Formatter { + + let maxLength : Int + let wrongCharacterSet = CharacterSet(charactersIn: "0123456789ABCDEFabcdef").inverted + + init(maxLen : Int) { + maxLength = maxLen + super.init() + } + + required init?(coder: NSCoder) { + maxLength = 2 + super.init(coder: coder) + } + + override func isPartialStringValid(_ partialString: String, newEditingString newString: AutoreleasingUnsafeMutablePointer?, errorDescription error: AutoreleasingUnsafeMutablePointer?) -> Bool { + if partialString.count > maxLength { + return false + } + + if partialString.rangeOfCharacter(from: wrongCharacterSet) != nil { + return false + } + + return true + } + + + override func string(for obj: Any?) -> String? { + guard let string = obj as? String, + string.count <= maxLength + else { + return nil + } + + return string.uppercased() + } + + + override func getObjectValue( + _ obj: AutoreleasingUnsafeMutablePointer?, + for string: String, + errorDescription error: AutoreleasingUnsafeMutablePointer? + ) -> Bool { + + let hexValue: String + if string.starts(with: "#") { + hexValue = String(string.dropFirst()).uppercased() + } + else if string.starts(with: "0x") { + hexValue = String(string.dropFirst(2)).uppercased() + } + else { + hexValue = string.uppercased() + } + + obj?.pointee = hexValue as AnyObject + return true + } + +// override func attributedString(for obj: AnyObject, withDefaultAttributes attrs: [String : AnyObject]? = [:]) -> AttributedString? { +// let stringVal = string(for: obj) +// +// guard let string = stringVal else { return nil } +// +// return AttributedString(string: string, attributes: attributes) +// } + +// var attributes: [String: AnyObject] { +// let style = NSMutableParagraphStyle() +// style.minimumLineHeight = 100 +// style.maximumLineHeight = 100 +// style.paragraphSpacingBefore = 0 +// style.paragraphSpacing = 0 +// style.alignment = .center +// style.lineHeightMultiple = 1.0 +// style.lineBreakMode = .byTruncatingTail +// let droidSansMono = NSFont(name: "DroidSansMono", size: 70)! +// return [NSParagraphStyleAttributeName: style, NSFontAttributeName: droidSansMono, NSBaselineOffsetAttributeName: -60] +// } +} diff --git a/A2Mac/String.swift b/A2Mac/String.swift new file mode 100644 index 0000000..2c4053f --- /dev/null +++ b/A2Mac/String.swift @@ -0,0 +1,16 @@ +// +// String.swift +// A2Mac +// +// Created by Tamas Rudnai on 11/13/22. +// Copyright © 2022 GameAlloy. All rights reserved. +// + +import Foundation + +extension String { + func hexValue() -> UInt { + return UInt(lowercased(), radix: 16) ?? 0 + } +} + diff --git a/A2Mac/ViewController.swift b/A2Mac/ViewController.swift index aa1fec9..1f7109d 100644 --- a/A2Mac/ViewController.swift +++ b/A2Mac/ViewController.swift @@ -472,18 +472,17 @@ class ViewController: NSViewController { // AppleScript Keycodes - let leftArrowKey = 123 - let rightArrowKey = 124 - let upArrowKey = 126 - let downArrowKey = 125 + let leftArrowKey = 123 + let rightArrowKey = 124 + let upArrowKey = 126 + let downArrowKey = 125 - let F4FunctionKey = 118 - let F5FunctionKey = 96 - let F6FunctionKey = 97 - let F7FunctionKey = 98 - let F8FunctionKey = 100 + let F4FunctionKey = 118 + let F5FunctionKey = 96 + let F6FunctionKey = 97 + let F7FunctionKey = 98 + let F8FunctionKey = 100 - var ddd = 9; override var acceptsFirstResponder: Bool { get { @@ -645,12 +644,6 @@ class ViewController: NSViewController { // print("keyDown") -// for i in 0...65536 { -// ddd = Int(event.keyCode) + i -// } -// ddd = ddd * 2 - - // switch event.modifierFlags.intersection(.deviceIndependentFlagsMask) { // case [.command] where event.characters == "l", // [.command, .shift] where event.characters == "l": @@ -689,7 +682,7 @@ class ViewController: NSViewController { let keyCode = Int(event.keyCode) switch keyCode { case leftArrowKey: -// print("LEFT", ddd); +// print("LEFT"); if ( Keyboard2Joystick ) { // Keyboard 2 JoyStick (Game Controller / Paddle) pdl_valarr[0] = 0 @@ -1531,6 +1524,9 @@ class ViewController: NSViewController { @IBOutlet weak var disk2_closed: NSImageView! + var keyDownMonitor : Any? + var keyUpMonitor : Any? + func keyEventsOn() { // NSEvent.removeMonitor(NSEvent.EventType.flagsChanged) // NSEvent.addLocalMonitorForEvents(matching: .flagsChanged) { @@ -1538,13 +1534,20 @@ class ViewController: NSViewController { // return $0 // } -// NSEvent.removeMonitor(NSEvent.EventType.keyDown) - NSEvent.addLocalMonitorForEvents(matching: .keyDown) { + if let event = keyDownMonitor { + NSEvent.removeMonitor(event) + keyDownMonitor = nil + } + keyDownMonitor = NSEvent.addLocalMonitorForEvents(matching: .keyDown) { // print("keyDown event") self.keyDown(with: $0) return nil } - NSEvent.addLocalMonitorForEvents(matching: .keyUp) { + if let event = keyUpMonitor { + NSEvent.removeMonitor(event) + keyUpMonitor = nil + } + keyUpMonitor = NSEvent.addLocalMonitorForEvents(matching: .keyUp) { // print("keyUp event") self.keyUp(with: $0) return nil @@ -1552,6 +1555,19 @@ class ViewController: NSViewController { } + func keyEventsOff() { +// NSEvent.removeMonitor(NSEvent.EventType.flagsChanged) + if let event = keyDownMonitor { + NSEvent.removeMonitor(event) + keyDownMonitor = nil + } + if let event = keyUpMonitor { + NSEvent.removeMonitor(event) + keyUpMonitor = nil + } + } + + override func viewDidLoad() { super.viewDidLoad() @@ -1675,7 +1691,8 @@ class ViewController: NSViewController { // view.setBoundsSize(size) } - + + override func viewDidAppear() { // displayField.currentEditor()?.selectedRange = NSMakeRange(0, 0) // self.displayField.window?.makeFirstResponder(self) @@ -1684,6 +1701,51 @@ class ViewController: NSViewController { } + func setSpkrExtrabuf( freq : Double ) { + // TODO: Probably this is not the best way to deal with the problem: To make sound continous independent of FPS and Freq + +// spkr_extra_buf = Int32( 780 / fps ) + + switch freq { + case 0.25: + spkr_extra_buf = -65 + break + + case 0.5: + spkr_extra_buf = -140 + break + + case 1.5: + spkr_extra_buf = 175 + break + + case 2.0: +// 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 = 20 + spkr_extra_buf = 195 // 88 + break + + case 2.8: + spkr_extra_buf = 65 // 185 + break + + case 4.0: +// 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 = 45 + spkr_extra_buf = 25 // 90 // 80 // 20 + break + + default: +// 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 // 26 + break + } + + soundGapLabel.title = String( spkr_extra_buf ) + soundGapSlider.integerValue = Int(spkr_extra_buf) + } + + func setCPUClockSpeed( freq : Double ) { spkr_stopAll(); @@ -1691,48 +1753,8 @@ class ViewController: NSViewController { clk_6502_per_frm = UInt32( MHz_6502 * M / Double(fps) ) clk_6502_per_frm_set = clk_6502_per_frm - // TODO: Probably this is not the best way to deal with the problem: To make sound continous independent of FPS and Freq - -// spkr_extra_buf = Int32( 780 / fps ) - spkr_extra_buf = 0 // 26 - -// switch freq { -// case 0.25: -// spkr_extra_buf = -65 -// break -// -// case 0.5: -// spkr_extra_buf = -140 -// break -// -// case 1.5: -// spkr_extra_buf = 175 -// break -// -// case 2.0: -//// 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 = 20 -// spkr_extra_buf = 195 // 88 -// break -// -// case 2.8: -// spkr_extra_buf = 65 // 185 -// break -// -// case 4.0: -//// 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 = 45 -// spkr_extra_buf = 25 // 90 // 80 // 20 -// break -// -// default: -//// 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 // 26 -// break -// } - - soundGapLabel.title = String( spkr_extra_buf ) - soundGapSlider.integerValue = Int(spkr_extra_buf) + spkr_extra_buf = 0 +// setSpkrExtrabuf(freq: freq) }