the terminal works
This commit is contained in:
parent
4b9aa3cd59
commit
76e8801611
|
@ -33,9 +33,13 @@ class AppleI: NSObject {
|
||||||
override init() {
|
override init() {
|
||||||
super.init()
|
super.init()
|
||||||
|
|
||||||
emulatorView.wantsLayer = true
|
emuScreenLayer.shouldRasterize = true
|
||||||
emuScreenLayer.delegate = emulatorViewDelegate
|
emuScreenLayer.delegate = emulatorViewDelegate
|
||||||
emuScreenLayer.frame = emulatorView.bounds
|
emuScreenLayer.frame = emulatorView.bounds
|
||||||
|
|
||||||
|
//emulatorView.layer = emuScreenLayer
|
||||||
|
emulatorView.wantsLayer = true
|
||||||
|
|
||||||
emuScreenLayer.setNeedsDisplay()
|
emuScreenLayer.setNeedsDisplay()
|
||||||
emulatorView.layer?.addSublayer(emuScreenLayer)
|
emulatorView.layer?.addSublayer(emuScreenLayer)
|
||||||
|
|
||||||
|
@ -54,8 +58,11 @@ class AppleI: NSObject {
|
||||||
CPU.sharedInstance.memoryInterface.write_overrides.append(PIAOverrides.writeDSP)
|
CPU.sharedInstance.memoryInterface.write_overrides.append(PIAOverrides.writeDSP)
|
||||||
CPU.sharedInstance.memoryInterface.read_overrides.append(PIAOverrides.readDSP)
|
CPU.sharedInstance.memoryInterface.read_overrides.append(PIAOverrides.readDSP)
|
||||||
|
|
||||||
|
CPU.sharedInstance.memoryInterface.write_overrides.append(PIAOverrides.writeDSPCR)
|
||||||
|
|
||||||
CPU.sharedInstance.memoryInterface.read_overrides.append(PIAOverrides.readKBD)
|
CPU.sharedInstance.memoryInterface.read_overrides.append(PIAOverrides.readKBD)
|
||||||
CPU.sharedInstance.memoryInterface.read_overrides.append(PIAOverrides.readKBDCR)
|
CPU.sharedInstance.memoryInterface.read_overrides.append(PIAOverrides.readKBDCR)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func runFrame() {
|
func runFrame() {
|
||||||
|
@ -68,6 +75,7 @@ class AppleI: NSObject {
|
||||||
emulatorViewDelegate.putCharacterPixels(charPixels: cg.getCharacterPixels(charIndex: character), pixelPosition: emulatorViewDelegate.getPixelOffset(charCellIndex: cellNum))
|
emulatorViewDelegate.putCharacterPixels(charPixels: cg.getCharacterPixels(charIndex: character), pixelPosition: emulatorViewDelegate.getPixelOffset(charCellIndex: cellNum))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
emulatorView.setNeedsDisplay(emulatorView.frame)
|
||||||
emulatorView.display()
|
emulatorView.display()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,9 +10,24 @@ import Cocoa
|
||||||
|
|
||||||
class AppleScreenView: NSView {
|
class AppleScreenView: NSView {
|
||||||
|
|
||||||
|
override var acceptsFirstResponder: Bool {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override func becomeFirstResponder() -> Bool {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override func resignFirstResponder() -> Bool {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
override func draw(_ dirtyRect: NSRect) {
|
override func draw(_ dirtyRect: NSRect) {
|
||||||
super.draw(dirtyRect)
|
super.draw(dirtyRect)
|
||||||
// Drawing code here.
|
// Drawing code here.
|
||||||
|
|
||||||
|
layer?.sublayers![0].setNeedsDisplay()
|
||||||
|
layer?.sublayers![0].display()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,11 @@
|
||||||
import Cocoa
|
import Cocoa
|
||||||
|
|
||||||
class PIA: NSObject {
|
class PIA: NSObject {
|
||||||
|
enum PIAMode {
|
||||||
|
case DDR
|
||||||
|
case Output
|
||||||
|
}
|
||||||
|
|
||||||
var data: UInt8
|
var data: UInt8
|
||||||
var control: UInt8
|
var control: UInt8
|
||||||
|
|
||||||
|
@ -16,5 +21,13 @@ class PIA: NSObject {
|
||||||
data = 0x00
|
data = 0x00
|
||||||
control = 0x00
|
control = 0x00
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getMode() -> PIAMode {
|
||||||
|
if((control & 0x04) == 0x04) {
|
||||||
|
return .Output
|
||||||
|
} else {
|
||||||
|
return .DDR
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,16 +11,25 @@ import Cocoa
|
||||||
class PIAOverrides: NSObject {
|
class PIAOverrides: NSObject {
|
||||||
static let writeDSP = WriteOverride(start: 0xD012, end: 0xD012, writeAnyway: false, action: PIAOverrides.actionWriteDSP)
|
static let writeDSP = WriteOverride(start: 0xD012, end: 0xD012, writeAnyway: false, action: PIAOverrides.actionWriteDSP)
|
||||||
static func actionWriteDSP(terminal: AnyObject, byte: UInt8?) -> UInt8? {
|
static func actionWriteDSP(terminal: AnyObject, byte: UInt8?) -> UInt8? {
|
||||||
//TODO: implement actual 6520 PIA behavior
|
|
||||||
|
let pia = AppleI.sharedInstance.pia["display"]!
|
||||||
|
|
||||||
//Writing to DSP sets DSP.7
|
if(pia.getMode() == .Output) {
|
||||||
AppleI.sharedInstance.pia["display"]!.data = byte! | 0x80
|
//Writing to DSP sets DSP.7
|
||||||
|
AppleI.sharedInstance.pia["display"]!.data = byte! | 0x80
|
||||||
//Output our character to the terminal
|
|
||||||
AppleI.sharedInstance.terminal.putCharacter(charIndex: byte!)
|
//Output our character to the terminal
|
||||||
|
AppleI.sharedInstance.terminal.putCharacter(charIndex: byte!)
|
||||||
AppleI.sharedInstance.pia["display"]!.data = byte! & ~(0x80)
|
|
||||||
return nil;
|
AppleI.sharedInstance.pia["display"]!.data = byte! & ~(0x80)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
static let writeDSPCR = WriteOverride(start: 0xD013, end: 0xD013, writeAnyway: false, action: PIAOverrides.actionWriteDSPCR)
|
||||||
|
static func actionWriteDSPCR(terminal: AnyObject, byte: UInt8?) -> UInt8? {
|
||||||
|
AppleI.sharedInstance.pia["display"]?.control = byte!
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
static let readDSP = ReadOverride(start: 0xD012, end: 0xD012, readAnyway: false, action: PIAOverrides.actionReadDSP)
|
static let readDSP = ReadOverride(start: 0xD012, end: 0xD012, readAnyway: false, action: PIAOverrides.actionReadDSP)
|
||||||
|
|
|
@ -26,24 +26,34 @@ class MainViewController: NSViewController {
|
||||||
|
|
||||||
// Do view setup here.
|
// Do view setup here.
|
||||||
self.view.addSubview(computer.emulatorView)
|
self.view.addSubview(computer.emulatorView)
|
||||||
computer.emulatorView.display()
|
|
||||||
|
|
||||||
self.frameTimer = Timer.scheduledTimer(timeInterval: 1/60, target: self, selector: #selector(runEmulation), userInfo: nil, repeats: true)
|
self.frameTimer = Timer.scheduledTimer(timeInterval: 1/60, target: self, selector: #selector(runEmulation), userInfo: nil, repeats: true)
|
||||||
//runEmulation()
|
//runEmulation()
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func runEmulation() {
|
@objc func runEmulation() {
|
||||||
AppleI.sharedInstance.runFrame()
|
computer.runFrame()
|
||||||
computer.emulatorView.setNeedsDisplay(computer.emulatorView.frame)
|
|
||||||
computer.emulatorView.layer!.setNeedsDisplay(computer.emulatorView.layer!.frame)
|
|
||||||
computer.emulatorView.display()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override func keyDown(with event: NSEvent) {
|
override func keyDown(with event: NSEvent) {
|
||||||
let character = event.characters?.first
|
let c = returnChar(theEvent: event)
|
||||||
|
|
||||||
computer.pia["keyboard"]?.data = 0x41
|
computer.pia["keyboard"]?.data = UInt8((c?.asciiValue)! & 0x000000FF)
|
||||||
computer.pia["keyboard"]?.control |= 0x80
|
computer.pia["keyboard"]?.control |= 0x80
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func returnChar(theEvent: NSEvent) -> Character?{
|
||||||
|
let s: String = theEvent.characters!
|
||||||
|
for char in s{
|
||||||
|
return char
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension Character {
|
||||||
|
var asciiValue: UInt32? {
|
||||||
|
return String(self).unicodeScalars.filter{$0.isASCII}.first?.value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue