Fixed view and rendering issues

This commit is contained in:
tudnai 2022-02-14 18:41:59 +01:00
parent 6bc297ca85
commit d011bb7f96
8 changed files with 378 additions and 124 deletions

View File

@ -66,7 +66,11 @@ class AppDelegate: NSObject, NSApplicationDelegate {
ViewController.current?.openDiskImage(url: URL(fileURLWithPath: filename))
return true;
}
@IBAction func openFile(_ sender: NSMenuItem) {
ViewController.current?.openDiskImageDialog()
}
@IBAction func saveFile(_ sender: NSMenuItem) {
ViewController.current?.saveFile()
}

View File

@ -71,7 +71,7 @@
</menuItem>
<menuItem title="Open…" keyEquivalent="o" id="IAo-SY-fd9">
<connections>
<action selector="openDocument:" target="Ady-hI-5gd" id="bVn-NM-KNZ"/>
<action selector="openFile:" target="Voe-Tx-rLC" id="XVo-Up-FHJ"/>
</connections>
</menuItem>
<menuItem title="Open Recent" id="tXI-mr-wws">
@ -1703,12 +1703,12 @@
<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="ccC-Wu-3za" userLabel="Display" customClass="DisplayView" customModule="Steve___" customModuleProvider="target">
<rect key="frame" x="0.0" y="-224" width="1131" height="768"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<rect key="frame" x="0.0" y="267" width="1131" height="768"/>
<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="textBackgroundColor" catalog="System" colorSpace="catalog"/>
<size key="minSize" width="1131" height="768"/>
<size key="maxSize" width="3840" height="2160"/>
<size key="maxSize" width="3840" height="58101"/>
<attributedString key="textStorage">
<fragment>
<mutableString key="content">01234567890123456789012345678901234567891@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@2@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@3@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@4@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@5@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@6@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@7@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@8@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@9@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@10@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@11@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@12@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@13@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@14@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@15@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@16@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@17@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@18@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@19@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@20@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@21@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@22@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@23@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@</mutableString>
@ -1794,8 +1794,8 @@
</textFieldCell>
</textField>
<textField focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="bUo-E1-CYC">
<rect key="frame" x="861" y="16" width="246" height="13"/>
<textFieldCell key="cell" lineBreakMode="clipping" refusesFirstResponder="YES" focusRingType="none" title="© by Tamas Rudnai, 2020" id="tm6-Cq-r7H">
<rect key="frame" x="809" y="16" width="298" height="13"/>
<textFieldCell key="cell" lineBreakMode="clipping" refusesFirstResponder="YES" focusRingType="none" title="© by Tamas Rudnai, 2019-2022" id="tm6-Cq-r7H">
<font key="font" size="12" name="PrintChar21"/>
<color key="textColor" red="0.18823529411764706" green="0.83529411764705885" blue="0.84705882352941175" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
@ -2113,6 +2113,8 @@
<constraint firstItem="LlM-EV-ruZ" firstAttribute="leading" secondItem="ss1-M1-nGn" secondAttribute="leading" constant="5" id="zkY-0O-xcA"/>
</constraints>
<connections>
<outlet property="clipView" destination="1wa-ZE-lex" id="MHH-OC-OYI"/>
<outlet property="scanlinesView" destination="dGn-a4-c1t" id="eqJ-YB-9cU"/>
<outlet property="textDisplay" destination="ccC-Wu-3za" id="PB1-X7-azr"/>
</connections>
</view>

View File

@ -55,4 +55,56 @@ class DisplayScrollView : NSScrollView {
}
}
// override func viewDidEndLiveResize() {
// NSLog("DisplayScrollView:viewDidEndLiveResize")
// print( String(
// format: "DisplayScrollView fw:%.2f fh:%.2f bw:%.2f bh:%.2f",
// self.frame.size.width,
// self.frame.size.height,
// self.bounds.size.width,
// self.bounds.size.height
// ))
// }
//
// @objc func frameDidChange(notification: NSNotification) {
// NSLog("DisplayScrollView:frameDidChange")
// print( String(
// format: "DisplayScrollView fw:%.2f fh:%.2f bw:%.2f bh:%.2f",
// self.frame.size.width,
// self.frame.size.height,
// self.bounds.size.width,
// self.bounds.size.height
// ))
// }
//
// @objc func globalFrameDidChange(notification: NSNotification) {
// NSLog("DisplayScrollView:globalFrameDidChange")
// print( String(
// format: "DisplayScrollView fw:%.2f fh:%.2f bw:%.2f bh:%.2f",
// self.frame.size.width,
// self.frame.size.height,
// self.bounds.size.width,
// self.bounds.size.height
// ))
// }
//
// @objc func boundsDidChange(notification: NSNotification) {
// NSLog("DisplayScrollView:boundsDidChange")
// print( String(
// format: "DisplayScrollView fw:%.2f fh:%.2f bw:%.2f bh:%.2f",
// self.frame.size.width,
// self.frame.size.height,
// self.bounds.size.width,
// self.bounds.size.height
// ))
// }
//
// required init?(coder: NSCoder) {
// super.init(coder: coder)
//
// postsFrameChangedNotifications = true
// NotificationCenter.default.addObserver(self, selector: #selector(frameDidChange), name: NSView.frameDidChangeNotification, object: self)
// NotificationCenter.default.addObserver(self, selector: #selector(globalFrameDidChange), name: NSView.globalFrameDidChangeNotification, object: self)
// NotificationCenter.default.addObserver(self, selector: #selector(boundsDidChange), name: NSView.boundsDidChangeNotification, object: self)
// }
}

View File

@ -50,5 +50,112 @@ class DisplayView: NSTextView {
ViewController.current?.otherMouseUp(with: event)
}
// static let overscan_h = CGFloat(25)
// static let textViewBounds = NSSize(width: 280 * 4 + overscan_h, height: 192 * 4)
// let textDisplay_frameSize = NSSize(width: 1120 + overscan_h, height: 768)
//
// var textDisplay_width_diff : CGFloat?
// var textDisplay_height_diff : CGFloat?
//
// var locked = false
//
// func adjustTextDisplaySize() {
// var textFrameSize = frame.size
//
// if locked
// || frame.size.width > 8192
// || frame.size.width < 200
// || frame.size.height > 8192
// || frame.size.height < 200 {
// return
// }
//
// locked = true
//
// if textDisplay_width_diff == nil {
// textDisplay_width_diff = textFrameSize.width - textDisplay_frameSize.width
// textDisplay_height_diff = textFrameSize.height - textDisplay_frameSize.height
// }
//
// textFrameSize.width -= textDisplay_width_diff!
// textFrameSize.height -= textDisplay_height_diff!
//
//// print( String(
//// format: "DisplayView fw:%.2f fh:%.2f bw:%.2f bh:%.2f to fw:%.2f fh:%.2f bw:%.2f bh:%.2f",
//// frame.size.width,
//// frame.size.height,
//// textFrameSize.width,
//// textFrameSize.height,
//// bounds.size.width,
//// bounds.size.height,
//// MonitorView.textViewBounds.width,
//// MonitorView.textViewBounds.height
//// ))
//
// // BUGFIX: I am not sure why but if I do not adjust the frame and bounds size
// // couple of times, Cocoa miscalculates them
//// for _ in 0...15 {
//// self.setFrameSize(textFrameSize)
// self.setFrameSize(textDisplay_frameSize)
// self.setBoundsSize(MonitorView.textViewBounds)
//// }
//
// locked = false
// }
// override func viewDidEndLiveResize() {
// NSLog("DisplayView:viewDidEndLiveResize")
// print( String(
// format: "DisplayView fw:%.2f fh:%.2f bw:%.2f bh:%.2f",
// frame.size.width,
// frame.size.height,
// bounds.size.width,
// bounds.size.height
// ))
// }
//
// @objc func frameDidChange(notification: NSNotification) {
// NSLog("DisplayView:frameDidChange")
//// adjustTextDisplaySize()
// print( String(
// format: "DisplayView fw:%.2f fh:%.2f bw:%.2f bh:%.2f",
// frame.size.width,
// frame.size.height,
// bounds.size.width,
// bounds.size.height
// ))
// }
// @objc func globalFrameDidChange(notification: NSNotification) {
// NSLog("DisplayView:globalFrameDidChange")
// print( String(
// format: "DisplayView fw:%.2f fh:%.2f bw:%.2f bh:%.2f",
// self.frame.size.width,
// self.frame.size.height,
// self.bounds.size.width,
// self.bounds.size.height
// ))
// }
// @objc func boundsDidChange(notification: NSNotification) {
// NSLog("DisplayView:boundsDidChange")
// print( String(
// format: "DisplayView fw:%.2f fh:%.2f bw:%.2f bh:%.2f",
// self.frame.size.width,
// self.frame.size.height,
// self.bounds.size.width,
// self.bounds.size.height
// ))
// }
// required init?(coder: NSCoder) {
// super.init(coder: coder)
//
// postsFrameChangedNotifications = true
// NotificationCenter.default.addObserver(self, selector: #selector(frameDidChange), name: NSView.frameDidChangeNotification, object: self)
// NotificationCenter.default.addObserver(self, selector: #selector(globalFrameDidChange), name: NSView.globalFrameDidChangeNotification, object: self)
// NotificationCenter.default.addObserver(self, selector: #selector(boundsDidChange), name: NSView.boundsDidChangeNotification, object: self)
// }
}

View File

@ -191,7 +191,7 @@ class HiRes: NSView {
func refreshChanged( blockSize : Int ) {
// refresh changed block only
let screenBlockMargin = 14 / blockSize
let screenBlockMargin = 16 / blockSize
let blockScreenWidth = CGFloat(frame.width) / CGFloat(HiRes.blockCols) * CGFloat(blockSize)
let blockScreenHeigth = CGFloat(frame.height) / CGFloat(HiRes.blockRows)
@ -281,21 +281,21 @@ class HiRes: NSView {
if (block & bitMask) != 0 {
pixelsSRGB[pixelAddr] = monoColor;
}
else if ( ViewController.current?.CRTMonitor ?? false ) {
var srgb = pixelsSRGB[pixelAddr]
let s = srgb >> 24 & 0xFF
let r = srgb >> 16 & 0xFF
let g = srgb >> 8 & 0xFF
let b = srgb >> 0 & 0xFF
srgb = UInt32(Double(s) / pixelTrail) << 24
| UInt32(Double(r) / pixelTrail) << 16
| UInt32(Double(g) / pixelTrail) << 8
| UInt32(Double(b) / pixelTrail)
pixelsSRGB[pixelAddr] = srgb;
}
// else if ( ViewController.current?.CRTMonitor ?? false ) {
// var srgb = pixelsSRGB[pixelAddr]
//
// let s = srgb >> 24 & 0xFF
// let r = srgb >> 16 & 0xFF
// let g = srgb >> 8 & 0xFF
// let b = srgb >> 0 & 0xFF
//
// srgb = UInt32(Double(s) / pixelTrail) << 24
// | UInt32(Double(r) / pixelTrail) << 16
// | UInt32(Double(g) / pixelTrail) << 8
// | UInt32(Double(b) / pixelTrail)
//
// pixelsSRGB[pixelAddr] = srgb;
// }
else {
pixelsSRGB[pixelAddr] = color_black;
}

View File

@ -26,50 +26,126 @@ import Cocoa
class MonitorView: NSView {
@IBOutlet var textDisplay: DisplayView!
@IBOutlet weak var clipView: NSClipView!
@IBOutlet weak var scanlinesView: NSImageView!
static let textViewBounds = NSSize(width: 280 * 4, height: 192 * 4)
var textDisplay_boundsSize = NSSize()
static let overscan_h = CGFloat(25)
static let overscan_v = CGFloat(60)
static let textViewBounds = NSSize(width: 280 * 4 + overscan_h, height: 192 * 4)
var textDisplay_width_diff : CGFloat?
var textDisplay_height_diff : CGFloat?
let monitorView_textViewBounds = NSSize(width: 1120, height: 768)
let textDisplay_frameSize = NSSize(width: 1120 + overscan_h, height: 768 + overscan_v)
override func viewDidMoveToWindow() {
print("Added to NEW window")
}
func adjustTextDisplaySize() {
var textFrameSize = frame.size
// textFrameSize.width += 1
if textDisplay_width_diff == nil {
textDisplay_width_diff = textFrameSize.width - textDisplay.frame.width
textDisplay_height_diff = textFrameSize.height - textDisplay.frame.height
textDisplay_boundsSize = textDisplay.bounds.size
textDisplay_width_diff = textFrameSize.width - textDisplay_frameSize.width
textDisplay_height_diff = textFrameSize.height - textDisplay_frameSize.height
}
textFrameSize.width -= textDisplay_width_diff!
textFrameSize.height -= textDisplay_height_diff!
// textFrameSize.height -= textDisplay_height_diff!
textFrameSize.height = scanlinesView.frame.size.height
// print( String(
// format: "MonitorView fw:%.2f fh:%.2f bw:%.2f bh:%.2f to fw:%.2f fh:%.2f bw:%.2f bh:%.2f",
// textDisplay.frame.size.width,
// textDisplay.frame.size.height,
// textFrameSize.width,
// textFrameSize.height,
// textDisplay.bounds.size.width,
// textDisplay.bounds.size.height,
// MonitorView.textViewBounds.width,
// MonitorView.textViewBounds.height
// ))
// print( String(
// format: "scrollView fw:%.2f fh:%.2f bw:%.2f bh:%.2f",
// scrollView.frame.size.width,
// scrollView.frame.size.height,
// scrollView.bounds.size.width,
// scrollView.bounds.size.height
// ))
// print( String(
// format: "hiresView fw:%.2f fh:%.2f bw:%.2f bh:%.2f",
// hiresView.frame.size.width,
// hiresView.frame.size.height,
// hiresView.bounds.size.width,
// hiresView.bounds.size.height
// ))
// print( String(
// format: "scanlinesView fw:%.2f fh:%.2f bw:%.2f bh:%.2f",
// scanlinesView.frame.size.width,
// scanlinesView.frame.size.height,
// scanlinesView.bounds.size.width,
// scanlinesView.bounds.size.height
// ))
// BUGFIX: I am not sure why but if I do not adjust the frame and bounds size
// couple of times, Cocoa miscalculates them
for _ in 0...5 {
for _ in 0...15 {
textDisplay.setFrameSize(textFrameSize)
// textDisplay.setBoundsSize(MonitorView.textViewBounds)
// textDisplay.setFrameSize(scanlinesView.frame.size)
textDisplay.setBoundsSize(MonitorView.textViewBounds)
}
}
@objc func frameDidChange(notification: NSNotification) {
// NSLog("MonitorView:frameDidChange")
adjustTextDisplaySize()
}
// @objc func globalFrameDidChange(notification: NSNotification) {
// NSLog("MonitorView:globalFrameDidChange")
// adjustTextDisplaySize()
// }
//
// @objc func boundsDidChange(notification: NSNotification) {
// NSLog("MonitorView:boundsDidChange")
// adjustTextDisplaySize()
// }
required init?(coder: NSCoder) {
super.init(coder: coder)
postsFrameChangedNotifications = true
NotificationCenter.default.addObserver(self, selector: #selector(frameDidChange), name: NSView.frameDidChangeNotification, object: self)
// NotificationCenter.default.addObserver(self, selector: #selector(globalFrameDidChange), name: NSView.globalFrameDidChangeNotification, object: self)
// NotificationCenter.default.addObserver(self, selector: #selector(boundsDidChange), name: NSView.boundsDidChangeNotification, object: self)
}
override func viewDidEndLiveResize() {
// NSLog("MonitorView:viewDidEndLiveResize")
adjustTextDisplaySize()
// print( String(
// format: "MonitorView1 fw:%.2f fh:%.2f bw:%.2f bh:%.2f",
// textDisplay.frame.size.width,
// textDisplay.frame.size.height,
// textDisplay.bounds.size.width,
// textDisplay.bounds.size.height
// ))
// DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
// print( String(
// format: "MonitorView2 fw:%.2f fh:%.2f bw:%.2f bh:%.2f",
// self.textDisplay.frame.size.width,
// self.textDisplay.frame.size.height,
// self.textDisplay.bounds.size.width,
// self.textDisplay.bounds.size.height
// ))
// }
}
override func viewDidChangeEffectiveAppearance() {
// NSLog("StringviewDidChangeEffectiveAppearance")
postsFrameChangedNotifications = true
}

View File

@ -86,7 +86,7 @@ class ToolBarController: NSWindowController, NSWindowDelegate {
leading: 11,
trailing: -11,
top: 16,
bottom: 16,
bottom: -16,
sidePanelSize: 136,
sidePanelHidden: false
)

View File

@ -61,9 +61,9 @@ func spk_dn_play() {
}
//#if METAL_YES
//import Metal
//#endif
#if METAL_YES
import Metal
#endif
class ViewController: NSViewController {
@ -310,7 +310,9 @@ class ViewController: NSViewController {
static let textPage2Pointer = UnsafeRawBufferPointer(start: MEM + textPage2Addr, count: textBufferSize)
static let textIntBufferPointer = UnsafeRawBufferPointer(start: RAM + textPage1Addr, count: textBufferSize)
static let textAuxBufferPointer = UnsafeRawBufferPointer(start: AUX + textPage1Addr, count: textBufferSize)
static let textPageShadowBuffer = UnsafeMutableRawBufferPointer.allocate(byteCount: textBufferSize, alignment: 1)
// TODO: Render text screen in native C
// static let textScreen = UnsafeMutableRawPointer(mutating: testText)
@ -479,8 +481,7 @@ class ViewController: NSViewController {
// Keyboard 2 JoyStick (Game Controller / Paddle)
pdl_valarr[0] = 0
}
kbdInput(0x08)
kbdInput(0x88)
case rightArrowKey:
// print("RIGHT")
@ -488,8 +489,8 @@ class ViewController: NSViewController {
if ( Keyboard2Joystick ) {
pdl_valarr[0] = 1
}
kbdInput(0x15)
kbdInput(0x95)
case downArrowKey:
// print("DOWN")
// Keyboard 2 JoyStick (Game Controller / Paddle)
@ -497,8 +498,9 @@ class ViewController: NSViewController {
pdl_valarr[1] = 1
}
else {
kbdInput(0x0B)
kbdInput(0x8A)
}
case upArrowKey:
// print("UP")
// Keyboard 2 JoyStick (Game Controller / Paddle)
@ -506,9 +508,9 @@ class ViewController: NSViewController {
pdl_valarr[1] = 0
}
else {
kbdInput(0x0A)
kbdInput(0x8B)
}
default:
// print("keycode: %d", keyCode)
if let chars = event.characters {
@ -667,51 +669,59 @@ class ViewController: NSViewController {
var mouseLocation = NSPoint.zero
var shadowTxt : String = ""
var unicodeTextString : String = ""
func Render() {
// DispatchQueue.global(qos: .background).async {
self.frameCnt += 1
self.frameCnt += 1
if ( self.frameCnt == fps / 2 ) {
if ( self.frameCnt == fps / video_fps_divider / 2 ) {
ViewController.charConvTbl = ViewController.charConvTblFlashOn
}
else if ( self.frameCnt >= fps ) {
else if ( self.frameCnt >= fps / video_fps_divider ) {
self.frameCnt = 0
ViewController.charConvTbl = ViewController.charConvTblFlashOff
self.frameCnt = 0
}
var textNeedRender = false
var fromLines = 0
var toLines = self.textLines
if videoMode.text == 0 {
if videoMode.mixed == 1 {
fromLines = toLines - 4
}
else {
toLines = 0
}
}
var unicodeTextString : String = ""
var fromLines = 0
var toLines = self.textLines
if videoMode.text == 0 {
if videoMode.mixed == 1 {
fromLines = toLines - 4
}
else {
toLines = 0
}
self.unicodeTextArray = NSArray(array: self.txtClear, copyItems: true) as! [Character]
// render an empty space to eiminate displaying text portion of the screen covered by graphics
let charDisposition = videoMode.col80 == 0 ? 1 : 2
for y in 0 ..< fromLines {
self.unicodeTextArray[ y * (self.textCols * charDisposition + self.lineEndChars) + self.textCols * charDisposition] = "\n"
}
// 40 col
if videoMode.col80 == 0 {
if MEMcfg.txt_page_2 == 0 {
self.textBufferPointer = ViewController.textPage1Pointer
}
else {
self.textBufferPointer = ViewController.textPage2Pointer
}
self.unicodeTextArray = NSArray(array: self.txtClear, copyItems: true) as! [Character]
// render an empty space to eiminate displaying text portion of the screen covered by graphics
let charDisposition = videoMode.col80 == 0 ? 1 : 2
for y in 0 ..< fromLines {
self.unicodeTextArray[ y * (self.textCols * charDisposition + self.lineEndChars) + self.textCols * charDisposition] = "\n"
if self.textBufferPointer.elementsEqual(ViewController.textPageShadowBuffer) {
}
// 40 col
if videoMode.col80 == 0 {
if MEMcfg.txt_page_2 == 0 {
self.textBufferPointer = ViewController.textPage1Pointer
}
else {
self.textBufferPointer = ViewController.textPage2Pointer
}
else {
ViewController.textPage1Pointer.copyBytes(to: ViewController.textPageShadowBuffer)
textNeedRender = true
// render the rest of the text screen
for y in fromLines ..< toLines {
for x in 0 ..< self.textCols {
@ -724,41 +734,44 @@ class ViewController: NSViewController {
self.unicodeTextArray[ y * (self.textCols + self.lineEndChars) + self.textCols ] = "\n"
}
unicodeTextString = String(self.unicodeTextArray)
}
// 80 col
else {
let auxPage = ( MEMcfg.is_80STORE == 1 ) && ( MEMcfg.txt_page_2 == 1 )
let textIntBuffer = auxPage ? ViewController.textIntBufferPointer : ViewController.textPage1Pointer
let textAuxBuffer = auxPage ? ViewController.textPage1Pointer : ViewController.textAuxBufferPointer
// render the rest of the text screen
for y in fromLines ..< toLines {
for x in 0 ..< self.textCols {
let byte = textIntBuffer[ ViewController.textLineOfs[y] + x ]
let idx = Int(byte);
let chr = ViewController.charConvTbl[idx]
self.unicodeTextArray[ y * (self.textCols * 2 + self.lineEndChars) + x * 2 + 1] = chr
let byte2 = textAuxBuffer[ ViewController.textLineOfs[y] + x ]
let idx2 = Int(byte2);
let chr2 = ViewController.charConvTbl[idx2]
self.unicodeTextArray[ y * (self.textCols * 2 + self.lineEndChars) + x * 2] = chr2
}
self.unicodeTextArray[ y * (self.textCols * 2 + self.lineEndChars) + self.textCols * 2] = "\n"
}
}
}
// 80 col
else {
let auxPage = ( MEMcfg.is_80STORE == 1 ) && ( MEMcfg.txt_page_2 == 1 )
let textIntBuffer = auxPage ? ViewController.textIntBufferPointer : ViewController.textPage1Pointer
let textAuxBuffer = auxPage ? ViewController.textPage1Pointer : ViewController.textAuxBufferPointer
// render the rest of the text screen
for y in fromLines ..< toLines {
for x in 0 ..< self.textCols {
let byte = textIntBuffer[ ViewController.textLineOfs[y] + x ]
let idx = Int(byte);
let chr = ViewController.charConvTbl[idx]
self.unicodeTextArray[ y * (self.textCols * 2 + self.lineEndChars) + x * 2 + 1] = chr
let byte2 = textAuxBuffer[ ViewController.textLineOfs[y] + x ]
let idx2 = Int(byte2);
let chr2 = ViewController.charConvTbl[idx2]
self.unicodeTextArray[ y * (self.textCols * 2 + self.lineEndChars) + x * 2] = chr2
}
self.unicodeTextArray[ y * (self.textCols * 2 + self.lineEndChars) + self.textCols * 2] = "\n"
}
unicodeTextString = String(self.unicodeTextArray)
// Rendering is happening in the main thread, which has two implications:
// 1. We can update UI elements
// 2. it is independent of the simulation, de that is running in the background thread while we are busy with rendering...
DispatchQueue.main.sync {
}
// Rendering is happening in the main thread, which has two implications:
// 1. We can update UI elements
// 2. it is independent of the simulation, de that is running in the background thread while we are busy with rendering...
DispatchQueue.main.sync {
// TODO: Render text Screen in native C
// txt = String(bytesNoCopy: ViewController.textScreen!, length: 10, encoding: .ascii, freeWhenDone: false) ?? "HMM"
@ -770,22 +783,22 @@ class ViewController: NSViewController {
self.textDisplay.font = NSFont(name: "PRNumber3", size: fontSize)
}
else {
self.textDisplay.font = NSFont(name: "PrintChar21", size: fontSize)
}
self.textDisplay.font = NSFont(name: "PrintChar21", size: fontSize)
}
}
if ( self.shadowTxt != unicodeTextString ) {
self.shadowTxt = unicodeTextString
}
if textNeedRender || self.shadowTxt != unicodeTextString {
self.shadowTxt = unicodeTextString
// self.display.stringValue = unicodeTextString
let selectedRange = self.textDisplay.selectedRange()
self.textDisplay.string = unicodeTextString
self.textDisplay.setSelectedRange(selectedRange)
let selectedRange = self.textDisplay.selectedRange()
self.textDisplay.string = unicodeTextString
self.textDisplay.setSelectedRange(selectedRange)
// let bold14 = NSFont.boldSystemFont(ofSize: 14.0)
// let textColor = NSColor.red
// let attribs = [NSAttributedString.Key.font:bold14,NSAttributedString.Key.foregroundColor:textColor,NSAttributedString.Key.paragraphStyle:textParagraph]
// let textParagraph = NSMutableParagraphStyle()
// textParagraph.lineSpacing = 0
// textParagraph.minimumLineHeight = 32.0
@ -796,17 +809,14 @@ class ViewController: NSViewController {
// self.display.attributedStringValue = attrString
}
// self.display.stringValue = "testing\nit\nout"
if ( (mhz < 1.5) && (mhz != floor(mhz)) ) {
self.speedometer.stringValue = String(format: "%0.3lf MHz", mhz);
}
else {
self.speedometer.stringValue = String(format: "%0.1lf MHz", mhz);
}
// else {
// self.speedometer.stringValue = String(format: "%.0lf MHz", mhz);
// }
#if HIRES
// only refresh graphics view when needed (aka not in text mode)
@ -820,6 +830,7 @@ class ViewController: NSViewController {
self.lores.clearScreen()
self.lores.isHidden = false
self.hires.isHidden = true
unicodeTextString = String(self.unicodeTextArray)
}
self.lores.Render()
@ -833,15 +844,17 @@ class ViewController: NSViewController {
self.hires.clearScreen()
self.hires.isHidden = false
self.lores.isHidden = true
unicodeTextString = String(self.unicodeTextArray)
}
self.hires.Render()
self.hires.Render()
}
}
else if ( self.savedVideoMode.text == 0 ) {
// we just switched from grahics to text
self.lores.isHidden = true
self.hires.isHidden = true
unicodeTextString = String(self.unicodeTextArray)
}
self.savedVideoMode = videoMode
@ -851,7 +864,7 @@ class ViewController: NSViewController {
// stream speaker from a separate thread from the simulation
// TODO: Do we need to do this from here?
// spkr_update()
}
// }
}
@ -1176,7 +1189,7 @@ class ViewController: NSViewController {
spkr_fps_divider = fps / spkr_fps
spkr_play_timeout = SPKR_PLAY_TIMEOUT * spkr_fps_divider
pixelTrail = pow(256, 1 / Double(fps / video_fps_divider / 3) )
// pixelTrail = pow(256, 1 / Double(fps / video_fps_divider / 3) )
// spkr_buf_size = spkr_sample_rate * 2 / spkr_fps
newUpdateTimer( timeInterval: 1 / Double(fps) )