From f5ea13eb867cbca7db38de1c98e38717c4bc4cb9 Mon Sep 17 00:00:00 2001 From: Tamas Rudnai Date: Sun, 8 Sep 2019 19:55:19 -0700 Subject: [PATCH] Display Text Memory --- A2Mac/Base.lproj/Main.storyboard | 21 ++++---- A2Mac/ViewController.swift | 60 +++++++++++++++++++--- A2Mac/instructions/6502_instr_load_store.h | 1 + 3 files changed, 63 insertions(+), 19 deletions(-) diff --git a/A2Mac/Base.lproj/Main.storyboard b/A2Mac/Base.lproj/Main.storyboard index 89198fa..0f86f92 100644 --- a/A2Mac/Base.lproj/Main.storyboard +++ b/A2Mac/Base.lproj/Main.storyboard @@ -686,8 +686,7 @@ - - + @@ -706,16 +705,16 @@ - - + + - - - - - - - + + + + + + + diff --git a/A2Mac/ViewController.swift b/A2Mac/ViewController.swift index 712f611..b1d8dd3 100644 --- a/A2Mac/ViewController.swift +++ b/A2Mac/ViewController.swift @@ -12,14 +12,54 @@ class ViewController: NSViewController { @IBOutlet weak var display: NSTextFieldCell! - func check() { - let textBufferPointer = UnsafeRawBufferPointer(start: &RAM+0x400, count: 0x400) -// let string = String(bytes: ram, encoding: .utf8) -// print(string) + static let charConvStr : String = + "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_ !\"#$%&'()*+,-./0123456789:;<=>?" + + "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_ !\"#$%&'()*+,-./0123456789:;<=>?" + + "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_ !\"#$%&'()*+,-./0123456789:;<=>?" + + "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~?" + + static let charConvTbl = Array( charConvStr ) + + let textLineOfs : [Int] = [ + 0x000, 0x080, 0x100, 0x180, 0x200, 0x280, 0x300, 0x380, 0x028, 0x0A8, 0x128, 0x1A8, + 0x228, 0x2A8, 0x328, 0x3A8, 0x050, 0x0D0, 0x150, 0x1D0, 0x250, 0x2D0, 0x350, 0x3D0 + ] + + func update() { - for (index, byte) in textBufferPointer.enumerated() { - print("byte \(index): \(byte)") + while true { + usleep(33333) // 1/30 sec + + let textBaseAddr = 0x400 + let textLines = 24 + let textCols = 40 + + var txt : String = "|" + + for y in 0...textLines-1 { + let textAddr = textBaseAddr + textLineOfs[y] + let textBufferPointer = UnsafeRawBufferPointer(start: &RAM + textAddr, count: textCols) + + for (index, byte) in textBufferPointer.enumerated() { + let idx = Int(byte); + let chr = ViewController.charConvTbl[idx] + // print("byte \(index): \(chr)") + txt = txt + [chr] + } + + txt = txt + "|\n|" + } + + + DispatchQueue.main.async { + self.display.stringValue = txt; + } } + +// DispatchQueue.main.asyncAfter(deadline: .now() + 1/30, execute: { +// self.update() +// }) + } @@ -67,10 +107,14 @@ class ViewController: NSViewController { // } -// DispatchQueue.main.asyncAfter(deadline: .now() + 5.0, execute: { -// self.check() +// DispatchQueue.main.asyncAfter(deadline: .now() + 1/30, execute: { +// self.update() // }) + DispatchQueue.global(qos: .background).async { + self.update() + } + } override var representedObject: Any? { diff --git a/A2Mac/instructions/6502_instr_load_store.h b/A2Mac/instructions/6502_instr_load_store.h index d325a54..2096af0 100644 --- a/A2Mac/instructions/6502_instr_load_store.h +++ b/A2Mac/instructions/6502_instr_load_store.h @@ -98,6 +98,7 @@ static inline void STR( uint8_t * dst, uint8_t imm ) { // if (( imm > ' ' ) && ( c < 0x7F )) // printf("%04X: t:%02X '%c'\n", v, imm, isprint(c) ? c : ' '); // } + } /**