the terminal works

This commit is contained in:
Luigi Thirty 2017-07-29 16:11:14 -04:00
parent 4b9aa3cd59
commit 76e8801611
5 changed files with 72 additions and 17 deletions

View File

@ -33,9 +33,13 @@ class AppleI: NSObject {
override init() {
super.init()
emulatorView.wantsLayer = true
emuScreenLayer.shouldRasterize = true
emuScreenLayer.delegate = emulatorViewDelegate
emuScreenLayer.frame = emulatorView.bounds
//emulatorView.layer = emuScreenLayer
emulatorView.wantsLayer = true
emuScreenLayer.setNeedsDisplay()
emulatorView.layer?.addSublayer(emuScreenLayer)
@ -54,8 +58,11 @@ class AppleI: NSObject {
CPU.sharedInstance.memoryInterface.write_overrides.append(PIAOverrides.writeDSP)
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.readKBDCR)
}
func runFrame() {
@ -68,6 +75,7 @@ class AppleI: NSObject {
emulatorViewDelegate.putCharacterPixels(charPixels: cg.getCharacterPixels(charIndex: character), pixelPosition: emulatorViewDelegate.getPixelOffset(charCellIndex: cellNum))
}
emulatorView.setNeedsDisplay(emulatorView.frame)
emulatorView.display()
}
}

View File

@ -10,9 +10,24 @@ import Cocoa
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) {
super.draw(dirtyRect)
// Drawing code here.
layer?.sublayers![0].setNeedsDisplay()
layer?.sublayers![0].display()
}
}

View File

@ -9,6 +9,11 @@
import Cocoa
class PIA: NSObject {
enum PIAMode {
case DDR
case Output
}
var data: UInt8
var control: UInt8
@ -16,5 +21,13 @@ class PIA: NSObject {
data = 0x00
control = 0x00
}
func getMode() -> PIAMode {
if((control & 0x04) == 0x04) {
return .Output
} else {
return .DDR
}
}
}

View File

@ -11,16 +11,25 @@ import Cocoa
class PIAOverrides: NSObject {
static let writeDSP = WriteOverride(start: 0xD012, end: 0xD012, writeAnyway: false, action: PIAOverrides.actionWriteDSP)
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
AppleI.sharedInstance.pia["display"]!.data = byte! | 0x80
//Output our character to the terminal
AppleI.sharedInstance.terminal.putCharacter(charIndex: byte!)
AppleI.sharedInstance.pia["display"]!.data = byte! & ~(0x80)
return nil;
if(pia.getMode() == .Output) {
//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!)
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)

View File

@ -26,24 +26,34 @@ class MainViewController: NSViewController {
// Do view setup here.
self.view.addSubview(computer.emulatorView)
computer.emulatorView.display()
self.frameTimer = Timer.scheduledTimer(timeInterval: 1/60, target: self, selector: #selector(runEmulation), userInfo: nil, repeats: true)
//runEmulation()
}
@objc func runEmulation() {
AppleI.sharedInstance.runFrame()
computer.emulatorView.setNeedsDisplay(computer.emulatorView.frame)
computer.emulatorView.layer!.setNeedsDisplay(computer.emulatorView.layer!.frame)
computer.emulatorView.display()
computer.runFrame()
}
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
}
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
}
}