Entering addresses to Memory and Disassembly

This commit is contained in:
tudnai 2022-11-13 16:31:08 -08:00
parent 4ae8bfe658
commit e2a37a2e0c
8 changed files with 290 additions and 93 deletions

View File

@ -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 = "<group>"; };
32D089D7291E1BF800F2B486 /* DisassView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DisassView.swift; sourceTree = "<group>"; };
32D089EC291EE19200F2B486 /* UnfairLock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnfairLock.swift; sourceTree = "<group>"; };
32D08A1329219C6A00F2B486 /* HexDigitFormatter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HexDigitFormatter.swift; sourceTree = "<group>"; };
32D08A1F2921A8F900F2B486 /* String.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = String.swift; sourceTree = "<group>"; };
32DBF7632334657900DD50E7 /* HiRes.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HiRes.swift; sourceTree = "<group>"; };
32DBF76723373FB400DD50E7 /* disassembler.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = disassembler.h; sourceTree = "<group>"; };
32E21BE62491BF8B006C0C72 /* apple-rainbow.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "apple-rainbow.png"; sourceTree = "<group>"; };
@ -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 */,

View File

@ -905,6 +905,9 @@
<PersistentString
value = "disass_addr">
</PersistentString>
<PersistentString
value = "scroll_line_number">
</PersistentString>
</PersistentStrings>
</ContextState>
<ContextState

View File

@ -242,7 +242,7 @@
<stackView distribution="fill" orientation="horizontal" alignment="top" horizontalStackHuggingPriority="249.99998474121094" verticalStackHuggingPriority="249.99998474121094" detachesHiddenViews="YES" translatesAutoresizingMaskIntoConstraints="NO" id="lUp-Ww-thA">
<rect key="frame" x="0.0" y="484" width="233" height="20"/>
<subviews>
<textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="bwO-w1-hlg" userLabel="Memory Addr Field">
<textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="bwO-w1-hlg" userLabel="Disass Addr Field">
<rect key="frame" x="0.0" y="0.0" width="44" height="20"/>
<constraints>
<constraint firstAttribute="height" constant="20" identifier="Memory Addr Field.Height" id="XCd-Q5-6sX"/>
@ -252,6 +252,9 @@
<font key="font" size="10" name="PrintChar21"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
<connections>
<action selector="DisassAddressEntered:" target="R5e-co-cXs" id="olp-pH-tuA"/>
</connections>
</textFieldCell>
</textField>
<textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="lht-UO-OM3" userLabel="Middle Space">
@ -323,7 +326,7 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textView editable="NO" selectable="NO" drawsBackground="NO" importsGraphics="NO" richText="NO" horizontallyResizable="YES" verticallyResizable="YES" baseWritingDirection="leftToRight" findStyle="bar" allowsCharacterPickerTouchBarItem="NO" textCompletion="NO" id="Hwx-Gd-XW1" userLabel="Disass Display" customClass="DisassView" customModule="A2MacTests" customModuleProvider="target">
<rect key="frame" x="0.0" y="-195" width="349" height="1156"/>
<rect key="frame" x="0.0" y="-216" width="349" height="1155"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" widthSizable="YES" flexibleMaxX="YES" flexibleMinY="YES" heightSizable="YES" flexibleMaxY="YES"/>
<color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" red="0.12549019610000001" green="0.12549019610000001" blue="0.12549019610000001" alpha="0.0" colorSpace="custom" customColorSpace="sRGB"/>
@ -422,7 +425,7 @@ C20D: 4C C5 FE JMP $FEC5FEC5: 8D 06 C0 STA $C006</mutableString>
<rect key="frame" x="-100" y="-100" width="225" height="15"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
<scroller key="verticalScroller" verticalHuggingPriority="750" doubleValue="0.01466275659824047" horizontal="NO" id="8wE-fn-MQK">
<scroller key="verticalScroller" verticalHuggingPriority="750" horizontal="NO" id="8wE-fn-MQK">
<rect key="frame" x="350" y="1" width="15" height="474"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
@ -541,7 +544,7 @@ C20D: 4C C5 FE JMP $FEC5FEC5: 8D 06 C0 STA $C006</mutableString>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textView editable="NO" selectable="NO" drawsBackground="NO" importsGraphics="NO" richText="NO" horizontallyResizable="YES" verticallyResizable="YES" baseWritingDirection="leftToRight" findStyle="bar" allowsCharacterPickerTouchBarItem="NO" textCompletion="NO" id="BHr-Q4-rBI" userLabel="Stack Display" customClass="DisplayView" customModule="A2MacTests" customModuleProvider="target">
<rect key="frame" x="0.0" y="-232" width="334" height="165"/>
<rect key="frame" x="0.0" y="-239" width="334" height="165"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" widthSizable="YES" flexibleMaxX="YES" flexibleMinY="YES" heightSizable="YES" flexibleMaxY="YES"/>
<color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="windowBackgroundColor" catalog="System" colorSpace="catalog"/>
@ -565,7 +568,7 @@ C20D: 4C C5 FE JMP $FEC5FEC5: 8D 06 C0 STA $C006</mutableString>
<rect key="frame" x="-100" y="-100" width="349" height="15"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
<scroller key="verticalScroller" verticalHuggingPriority="750" doubleValue="0.2857142857142857" horizontal="NO" id="dcm-z5-VNG">
<scroller key="verticalScroller" verticalHuggingPriority="750" doubleValue="0.21428571428571427" horizontal="NO" id="dcm-z5-VNG">
<rect key="frame" x="335" y="1" width="15" height="158"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
@ -631,10 +634,13 @@ C20D: 4C C5 FE JMP $FEC5FEC5: 8D 06 C0 STA $C006</mutableString>
<constraint firstAttribute="width" constant="44" id="9xL-1J-8Hg"/>
<constraint firstAttribute="height" constant="20" identifier="Memory Addr Field.Height" id="bS5-Xb-qDz"/>
</constraints>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" borderStyle="bezel" placeholderString="Addr" drawsBackground="YES" usesSingleLineMode="YES" id="Eze-3w-9N2" userLabel="Memory Addr Field Cell">
<textFieldCell key="cell" lineBreakMode="truncatingTail" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" borderStyle="bezel" placeholderString="Addr" drawsBackground="YES" usesSingleLineMode="YES" id="Eze-3w-9N2" userLabel="Memory Addr Field Cell">
<font key="font" size="10" name="PrintChar21"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
<connections>
<action selector="MemoryAddressEntered:" target="R5e-co-cXs" id="wiF-B9-eF6"/>
</connections>
</textFieldCell>
</textField>
<textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="eCI-1T-iQB" userLabel="Middle Space">
@ -792,9 +798,12 @@ C20D: 4C C5 FE JMP $FEC5FEC5: 8D 06 C0 STA $C006</mutableString>
</view>
<connections>
<outlet property="CPU_Display" destination="Wrs-Qt-Kmd" id="SUW-Lc-Zv4"/>
<outlet property="DisassAddressField" destination="bwO-w1-hlg" id="tBp-cc-OcF"/>
<outlet property="DisassAddressPC" destination="zov-nz-fce" id="fhe-fN-yPd"/>
<outlet property="Disass_Display" destination="Hwx-Gd-XW1" id="XHS-dZ-gCR"/>
<outlet property="Disass_Scroll" destination="Pcn-4j-EEM" id="5w1-DZ-ypu"/>
<outlet property="Mem1_Display" destination="qqp-t0-j4i" id="85A-sB-M0p"/>
<outlet property="MemoryAddressField" destination="p3x-F3-IOa" id="9yv-2e-Lm7"/>
<outlet property="Stack_Display" destination="BHr-Q4-rBI" id="qlA-JC-xkW"/>
</connections>
</viewController>

View File

@ -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()
}
}

View File

@ -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) {

View File

@ -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<NSString?>?, errorDescription error: AutoreleasingUnsafeMutablePointer<NSString?>?) -> 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<AnyObject?>?,
for string: String,
errorDescription error: AutoreleasingUnsafeMutablePointer<NSString?>?
) -> 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]
// }
}

16
A2Mac/String.swift Normal file
View File

@ -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
}
}

View File

@ -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)
}