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 22424b3..377229b 100644
--- a/A2Mac.xcodeproj/project.xcworkspace/xcuserdata/trudnai.xcuserdatad/xcdebugger/Expressions.xcexplist
+++ b/A2Mac.xcodeproj/project.xcworkspace/xcuserdata/trudnai.xcuserdatad/xcdebugger/Expressions.xcexplist
@@ -3,28 +3,16 @@
version = "1.0">
+ contextName = "specialized closure #1 in DebuggerViewController.DisplayDisassembly():DebuggerViewController.swift">
+ value = "line_number">
+ value = "currentScrollLine">
-
-
-
-
-
-
-
-
+ value = "current_line_number">
@@ -32,41 +20,47 @@
contextName = "HiRes.compute():HiRes.swift">
+ value = "UnsafeRawBufferPointer(result)">
+ value = "computePipelineState.maxTotalThreadsPerThreadgroup">
+ contextName = "ViewController.mouseMoved(with:):ViewController.swift">
+ value = "oldLocation">
+
+
+
+
+ contextName = "closure #1 in ViewController.Update():ViewController.swift">
+ value = "MEMcfg.txt_page_2">
+ value = "self.shadowTxt">
+ value = "txt">
+ value = "MEMcfg.is_80STORE">
+ value = "txtArr">
@@ -90,6 +84,28 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -126,14 +142,17 @@
contextName = "HiRes.draw(_:):HiRes.swift">
+ value = "(blockH7 | ( block & bitMask ))">
+ value = "ctx?.data">
+
+
@@ -143,24 +162,21 @@
-
-
+
+
+
+
-
-
-
-
+ value = "disass_addr_min">
@@ -196,7 +212,24 @@
value = "m6502.PC">
+ value = "line_number">
+
+
+
+
+
+
+
+
+
+
+
+
@@ -208,6 +241,17 @@
+
+
+
+
+
+
+
+
@@ -224,6 +268,14 @@
+
+
+
+
+
+
@@ -241,6 +293,23 @@
+
+
+
+
+
+
+
+
+
+
+
+
@@ -269,56 +338,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -388,10 +407,10 @@
+ contextName = "_addr_zp_dbg:mmio.c">
+ value = "mem_wr_bp">
@@ -410,7 +429,12 @@
+ contextName = "m6502_Step:6502_std.h">
+
+
+
+
@@ -421,12 +445,7 @@
-
-
-
-
+ contextName = "LDA:6502_instr_load_store.h">
@@ -452,7 +471,7 @@
value = "textDisplay_height_diff">
+ value = "frame.size">
@@ -464,7 +483,7 @@
value = "textDisplay_width_diff">
+ value = "textDisplay.frame">
@@ -521,17 +540,6 @@
-
-
-
-
-
-
-
-
@@ -540,6 +548,17 @@
+
+
+
+
+
+
+
+
@@ -599,9 +618,6 @@
-
-
@@ -610,6 +626,9 @@
+
+
@@ -638,16 +657,16 @@
contextName = "ioRead:mmio.c">
+ value = "MEMcfg.int_Cx_ROM">
+ value = "m6502.clkfrm">
+ value = "(int)IOframe">
@@ -658,10 +677,10 @@
value = "Apple2_64K_AUX + 0xC600">
+ value = "Apple2_64K_RAM + 0xC600">
+ value = "(void*)rom">
@@ -785,16 +804,16 @@
contextName = "DisplayScrollView.scrollWheel(with:):DisplayScrollView.swift">
+ value = "textView.defaultParagraphStyle?.lineSpacing">
+ value = "subviews[1].subviews">
+ value = "documentView">
@@ -886,10 +905,10 @@
contextName = "_fetch_dbg:mmio.c">
+ value = "disassembly.pOpcode">
+ value = "memread8_low(m6502.PC)">
@@ -897,10 +916,13 @@
contextName = "m6502_dbg_bp_add:6502_bp.c">
+ value = "bp">
+ value = "bp_array">
+
+
@@ -971,11 +993,20 @@
+
+
+ value = "highlighted_line_number">
+
+
+
+
@@ -1091,7 +1122,7 @@
contextName = "LoRes.Update():LoRes.swift">
+ value = "UInt8( (block >> 4) & 0x0F )">
@@ -1100,7 +1131,7 @@
value = "UInt8(block & 4)">
+ value = "blockChanged[ screenIdx ]">
@@ -1157,10 +1188,10 @@
value = "m6502">
+ value = "Apple2_64K_AUX + 0x3600">
+ value = "m6502.clkfrm">
@@ -1169,10 +1200,10 @@
value = "m6502.PC">
+ value = "(void*)Apple2_64K_RAM">
+ value = "Apple2_64K_RAM + 0x3600">
@@ -1186,7 +1217,7 @@
value = "pdl_value[pdl]">
+ value = "normalized_time">
@@ -1198,7 +1229,15 @@
value = "1 * 512 * (1 - ( 3300 / 3300.0 ))">
+ value = "normalized_time >= pdl_value[pdl] ? 255 : 0">
+
+
+
+
+
+
@@ -1209,10 +1248,10 @@
contextName = "ToolBarController.GamePort(_:):ToolBarController.swift">
+ value = "ViewController.current?.mouseCursorHidden">
+ value = "ViewController.current?.mouseCursorJoystickEmulation">
@@ -1247,10 +1286,16 @@
+ contextName = "m6502_Debug:6502_dbg.c">
+ value = "m6502.PC">
+
+
+
+
@@ -1283,16 +1328,10 @@
+ contextName = "is_wr_enabled:mmio.c">
-
-
-
-
+ value = "MEMcfg.WR_RAM_cntr">
@@ -1435,7 +1474,7 @@
value = "m6502.PC">
+ value = "m6502.debugger.on">
@@ -1444,7 +1483,7 @@
value = "frameCounter">
+ value = "m6502.clkfrm">
@@ -1470,6 +1509,14 @@
+
+
+
+
+
+
@@ -1481,17 +1528,63 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ value = "m6502.debugger.SP">
+ value = "m6502.SP">
@@ -1502,7 +1595,7 @@
value = "default_MHz_6502 * 1000 * 1000 / spkr_sample_rate">
+ value = "( (spkr_clk + m6502.clkfrm) / ( default_MHz_6502 * 1000 * 1000 / spkr_sample_rate)) * 2">
@@ -1520,7 +1613,7 @@
value = "(spkr_clk + m6502.clkfrm)">
+ value = "( (spkr_clk + m6502.clkfrm) / ( 1024000 / spkr_sample_rate ) ) * 2">
@@ -1538,53 +1631,5 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/A2Mac.xcodeproj/xcshareddata/xcschemes/Debug.xcscheme b/A2Mac.xcodeproj/xcshareddata/xcschemes/Debug.xcscheme
index 0b1df9f..5f342a0 100644
--- a/A2Mac.xcodeproj/xcshareddata/xcschemes/Debug.xcscheme
+++ b/A2Mac.xcodeproj/xcshareddata/xcschemes/Debug.xcscheme
@@ -64,6 +64,7 @@
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
enableASanStackUseAfterReturn = "YES"
+ enableUBSanitizer = "YES"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
@@ -90,6 +91,13 @@
ReferencedContainer = "container:A2Mac.xcodeproj">
+
+
+
+
NSRange? {
+ func getLineRange_old(inView view: NSTextView, forLine: Int) -> NSRange? {
let layoutManager = view.layoutManager!
var numberOfLines = 0
let numberOfGlyphs = layoutManager.numberOfGlyphs
@@ -308,10 +333,22 @@ N V - B D I Z C
}
+ func getLineRange(_ lineRange : [LineRange_t], forLine: Int) -> NSRange? {
+// print("disassLineRange.count:", disassLineRange.count)
+ if 0 < forLine && forLine <= lineRange.count {
+ let disassRange = lineRange[forLine - 1]
+ return NSRange(location: disassRange.loc, length: disassRange.len)
+ }
+
+ // could not find line number
+ return nil
+ }
+
+
let lineFromTopToMiddle = 0
func scroll_to(view: NSTextView, line: Int) {
let line = line > 0 ? line : 0
- if let lineRange = getLineRange(inView: view, forLine: line + lineFromTopToMiddle) {
+ if let lineRange = getLineRange(disassLineRange, forLine: line + lineFromTopToMiddle) {
view.scrollRangeToVisible(lineRange)
}
}
@@ -328,11 +365,38 @@ N V - B D I Z C
]
- func remove_highlight(view: NSTextView, line: Int) {
+ func remove_highlight(view : NSTextView, lineRange : NSRange) {
+ DispatchQueue.main.async {
+ if let layoutManager = view.layoutManager {
+ layoutManager.removeTemporaryAttribute(NSAttributedString.Key.backgroundColor, forCharacterRange: lineRange)
+ layoutManager.removeTemporaryAttribute(NSAttributedString.Key.foregroundColor, forCharacterRange: lineRange)
+ }
+ }
+ }
+
+ func remove_highlight(view : NSTextView, line : Int) {
if line > 0 {
- if let lineRange = getLineRange(inView: view, forLine: line) {
- view.layoutManager?.removeTemporaryAttribute(NSAttributedString.Key.backgroundColor, forCharacterRange: lineRange)
- view.layoutManager?.removeTemporaryAttribute(NSAttributedString.Key.foregroundColor, forCharacterRange: lineRange)
+ if let lineRange = getLineRange(disassLineRange, forLine: line) {
+ remove_highlight(view: view, lineRange: lineRange)
+ }
+ }
+ }
+
+ func remove_highlight_(view: NSTextView) {
+ remove_highlight(view: view, line: highlighted_line_number)
+ highlighted_line_number = 0;
+ }
+
+
+ func remove_highlight(view: NSTextView) {
+ if highlighted_line_number > 0 {
+ if let lineRange = getLineRange(disassLineRange, forLine: highlighted_line_number) {
+ DispatchQueue.main.asyncAfter(deadline: .now() + 0.1, execute: {
+ if let layoutManager = view.layoutManager {
+ layoutManager.removeTemporaryAttribute(NSAttributedString.Key.backgroundColor, forCharacterRange: lineRange)
+ layoutManager.removeTemporaryAttribute(NSAttributedString.Key.foregroundColor, forCharacterRange: lineRange)
+ }
+ })
}
}
}
@@ -342,12 +406,10 @@ N V - B D I Z C
if line > 0 {
// remove old highlighted line
remove_highlight(view: view, line: line)
- if let lineRange = getLineRange(inView: view, forLine: line) {
- // view.selectedRange = lineRange
- // view.scrollRangeToVisible(lineRange)
-// remove_highlight(view: view, line: line_number_cursor)
-// line_number_cursor = 0
- view.layoutManager?.addTemporaryAttributes(attr, forCharacterRange: lineRange)
+ if let lineRange = getLineRange(disassLineRange, forLine: line) {
+ DispatchQueue.main.async {
+ view.layoutManager?.addTemporaryAttributes(attr, forCharacterRange: lineRange)
+ }
}
}
}
@@ -449,16 +511,22 @@ N V - B D I Z C
}
+ struct LineRange_t {
+ var loc : Int
+ var len : Int
+ }
+
+ var disassLineRange = [LineRange_t]()
+
func DisplayDisassembly( scrollY : CGFloat = -1 ) {
- var disass = ""
+ var disass = "" // String(repeating: "\n", count: 0x1800)
+ var loc = 0
+
+ remove_highlight(view: Disass_Display)
line_number = 0
- let highlighted = self.highlighted_line_number
-
- DispatchQueue.main.async {
- self.remove_highlight(view: self.Disass_Display, line: highlighted)
- }
+// let highlighted = self.highlighted_line_number
// TODO: Also check if memory area updated!
@@ -474,6 +542,7 @@ N V - B D I Z C
// if disass_addr_pc > disass_addr && disass_addr_pc < disass_addr + disass_addr_max {
if scroll_line_number < 0 || need_disass {
+ disassLineRange.removeAll()
ViewController.shared?.UpdateSemaphore.wait()
let m6502_saved = m6502
@@ -510,6 +579,11 @@ N V - B D I Z C
m6502_Disass_1_Instr()
let line = ASCII_to_Apple2( line: String(cString: disassemblyLine( isCurrentLine )!) )
+// print("disassLineLength:", disassLineLength)
+ let len = disassLineLength + 1
+ let lineRange = LineRange_t(loc: loc, len: len)
+ disassLineRange.append(lineRange)
+ loc += len
if isCurrentLine {
// line = invertLine(line: line)
@@ -529,11 +603,12 @@ N V - B D I Z C
DispatchQueue.main.async {
// let isEmpty = self.Disass_Display.string.isEmpty
if need_disass {
- self.Disass_Display.string = disass
+ self.Disass_Display.string = disass // + String(repeating: "\n", count: 0x8000)
+// self.testTextField(str: "")
}
let currentScrollLine = self.get_scroll_line(view: self.Disass_Display) + 1
- if self.highlighted_line_number <= currentScrollLine || self.highlighted_line_number > currentScrollLine + 35 {
+ if self.highlighted_line_number <= currentScrollLine || self.highlighted_line_number > currentScrollLine + 25 {
if scrollY < 0 {
self.scroll_to(view: self.Disass_Display, line: self.scroll_line_number - 5)
@@ -569,11 +644,13 @@ N V - B D I Z C
let UpdateSemaphore = DispatchSemaphore(value: 1)
func Update() {
- DispatchQueue.global().async {
- if self.UpdateSemaphore.wait(timeout: .now()) == .success {
- self.UpdateImmediately()
- self.UpdateSemaphore.signal()
+ if self.UpdateSemaphore.wait(timeout: .now()) == .success {
+ if Disass_Display != nil {
+ DispatchQueue.global().async {
+ self.UpdateImmediately()
+ }
}
+ self.UpdateSemaphore.signal()
}
}
diff --git a/A2Mac/ViewController.swift b/A2Mac/ViewController.swift
index 25c2d74..8dbb3be 100644
--- a/A2Mac/ViewController.swift
+++ b/A2Mac/ViewController.swift
@@ -1231,8 +1231,10 @@ class ViewController: NSViewController {
func diskButtonUpdate() {
DispatchQueue.main.async {
- // Disk Motor LED
+
if ( self.frameCounter % DEF_DRV_LED_DIV == 0 ) {
+
+ // Disk Motor LED
if spkr_is_disk_motor_playing() {
if self.disk1_led.isHidden {
self.disk1_led.isHidden = false
@@ -1243,10 +1245,8 @@ class ViewController: NSViewController {
self.disk1_led.isHidden = true
}
}
- }
- // Disk Loaded
- if ( self.frameCounter % DEF_DRV_LED_DIV == 0 ) {
+ // Disk Loaded
if woz_is_loaded() > 0 {
if self.disk1_closed.isHidden {
self.disk1_closed.isHidden = false
@@ -1257,6 +1257,7 @@ class ViewController: NSViewController {
self.disk1_closed.isHidden = true
}
}
+
}
}
}
@@ -1295,9 +1296,9 @@ class ViewController: NSViewController {
clkCounter += Double(m6502.clkfrm)
// we start a new frame from here, so CPU is running even while rendering
// m6502.clkfrm = 0
-
+
frameCounter += 1
-
+
if ( frameCounter % fps == 0 ) {
let currentTime = CACurrentMediaTime() as Double
let elpasedTime = currentTime - lastFrameTime
diff --git a/src/cpu/6502_dis_utils.c b/src/cpu/6502_dis_utils.c
index 207c603..48f1e02 100644
--- a/src/cpu/6502_dis_utils.c
+++ b/src/cpu/6502_dis_utils.c
@@ -173,6 +173,7 @@ void printDisassembly( FILE * f ) {
#endif // DISASS_TRACE
+size_t disassLineLength = 0;
const char * disassemblyLine(_Bool highlight) {
static char line[256];
@@ -191,6 +192,8 @@ const char * disassemblyLine(_Bool highlight) {
}
}
+ disassLineLength = strlen(line);
+
return line;
}
diff --git a/src/cpu/6502_dis_utils.h b/src/cpu/6502_dis_utils.h
index f25e8ab..73d756f 100644
--- a/src/cpu/6502_dis_utils.h
+++ b/src/cpu/6502_dis_utils.h
@@ -86,6 +86,7 @@ extern void printDisassembly( FILE * f );
#endif // DISASS_TRACE
+extern size_t disassLineLength;
extern const char * disassemblyLine(_Bool higlight);
diff --git a/src/dev/mem/mmio.c b/src/dev/mem/mmio.c
index dea97e9..6cf255b 100644
--- a/src/dev/mem/mmio.c
+++ b/src/dev/mem/mmio.c
@@ -1022,6 +1022,9 @@ INLINE uint8_t memread8( uint16_t addr ) {
**/
INLINE uint16_t memread16_low( uint16_t addr ) {
return * (uint16_t*) ( Apple2_64K_MEM + addr );
+
+ // avoid unaligned memory access
+// return (uint16_t)Apple2_64K_MEM[addr] | (uint16_t)Apple2_64K_MEM[addr+1] << 8;
}
//INLINE uint16_t memread16_high( uint16_t addr ) {
// return * (uint16_t*) ( RDHIMEM + addr );