This commit is contained in:
Luigi Thirty 2017-07-30 02:32:53 -04:00
parent 447b39a2d0
commit a98bea0f34
6 changed files with 44 additions and 16 deletions

View File

@ -11,11 +11,12 @@
2A22EBFB1F21A7A700A36A61 /* IntegerExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A22EBFA1F21A7A700A36A61 /* IntegerExtensions.swift */; }; 2A22EBFB1F21A7A700A36A61 /* IntegerExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A22EBFA1F21A7A700A36A61 /* IntegerExtensions.swift */; };
2A5BC5191F29A28D008C03BE /* AppleScreenView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A5BC5181F29A28D008C03BE /* AppleScreenView.swift */; }; 2A5BC5191F29A28D008C03BE /* AppleScreenView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A5BC5181F29A28D008C03BE /* AppleScreenView.swift */; };
2A5BC51C1F29A2EB008C03BE /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2A5BC51B1F29A2EB008C03BE /* QuartzCore.framework */; }; 2A5BC51C1F29A2EB008C03BE /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2A5BC51B1F29A2EB008C03BE /* QuartzCore.framework */; };
2A5BC51E1F29A4C3008C03BE /* AppleScreenViewDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A5BC51D1F29A4C3008C03BE /* AppleScreenViewDelegate.swift */; }; 2A5BC51E1F29A4C3008C03BE /* AppleIBitmapDisplay.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A5BC51D1F29A4C3008C03BE /* AppleIBitmapDisplay.swift */; };
2A60851E1F2AFAE900E05B64 /* PIA.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A60851D1F2AFAE900E05B64 /* PIA.swift */; }; 2A60851E1F2AFAE900E05B64 /* PIA.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A60851D1F2AFAE900E05B64 /* PIA.swift */; };
2AA8B5F81F2A8889002B350F /* AppleI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2AA8B5F71F2A8889002B350F /* AppleI.swift */; }; 2AA8B5F81F2A8889002B350F /* AppleI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2AA8B5F71F2A8889002B350F /* AppleI.swift */; };
2AA8B5FC1F2A8EAD002B350F /* Terminal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2AA8B5FB1F2A8EAD002B350F /* Terminal.swift */; }; 2AA8B5FC1F2A8EAD002B350F /* Terminal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2AA8B5FB1F2A8EAD002B350F /* Terminal.swift */; };
2AA8B5FE1F2A942C002B350F /* PIAOverrides.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2AA8B5FD1F2A942C002B350F /* PIAOverrides.swift */; }; 2AA8B5FE1F2A942C002B350F /* PIAOverrides.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2AA8B5FD1F2A942C002B350F /* PIAOverrides.swift */; };
2AB815E71F2DA25E000BCE7D /* AppleIMetalView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2AB815E61F2DA25E000BCE7D /* AppleIMetalView.swift */; };
2AD458CE1F205EB700F05121 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2AD458CD1F205EB700F05121 /* AppDelegate.swift */; }; 2AD458CE1F205EB700F05121 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2AD458CD1F205EB700F05121 /* AppDelegate.swift */; };
2AD458D01F205EB700F05121 /* DebuggerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2AD458CF1F205EB700F05121 /* DebuggerViewController.swift */; }; 2AD458D01F205EB700F05121 /* DebuggerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2AD458CF1F205EB700F05121 /* DebuggerViewController.swift */; };
2AD458D21F205EB700F05121 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 2AD458D11F205EB700F05121 /* Assets.xcassets */; }; 2AD458D21F205EB700F05121 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 2AD458D11F205EB700F05121 /* Assets.xcassets */; };
@ -40,11 +41,12 @@
2A22EBFA1F21A7A700A36A61 /* IntegerExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IntegerExtensions.swift; sourceTree = "<group>"; }; 2A22EBFA1F21A7A700A36A61 /* IntegerExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IntegerExtensions.swift; sourceTree = "<group>"; };
2A5BC5181F29A28D008C03BE /* AppleScreenView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppleScreenView.swift; sourceTree = "<group>"; }; 2A5BC5181F29A28D008C03BE /* AppleScreenView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppleScreenView.swift; sourceTree = "<group>"; };
2A5BC51B1F29A2EB008C03BE /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; }; 2A5BC51B1F29A2EB008C03BE /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
2A5BC51D1F29A4C3008C03BE /* AppleScreenViewDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppleScreenViewDelegate.swift; sourceTree = "<group>"; }; 2A5BC51D1F29A4C3008C03BE /* AppleIBitmapDisplay.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppleIBitmapDisplay.swift; sourceTree = "<group>"; };
2A60851D1F2AFAE900E05B64 /* PIA.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PIA.swift; sourceTree = "<group>"; }; 2A60851D1F2AFAE900E05B64 /* PIA.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PIA.swift; sourceTree = "<group>"; };
2AA8B5F71F2A8889002B350F /* AppleI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppleI.swift; sourceTree = "<group>"; }; 2AA8B5F71F2A8889002B350F /* AppleI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppleI.swift; sourceTree = "<group>"; };
2AA8B5FB1F2A8EAD002B350F /* Terminal.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Terminal.swift; sourceTree = "<group>"; }; 2AA8B5FB1F2A8EAD002B350F /* Terminal.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Terminal.swift; sourceTree = "<group>"; };
2AA8B5FD1F2A942C002B350F /* PIAOverrides.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PIAOverrides.swift; sourceTree = "<group>"; }; 2AA8B5FD1F2A942C002B350F /* PIAOverrides.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PIAOverrides.swift; sourceTree = "<group>"; };
2AB815E61F2DA25E000BCE7D /* AppleIMetalView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppleIMetalView.swift; sourceTree = "<group>"; };
2AD458CA1F205EB700F05121 /* FruitMachine.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = FruitMachine.app; sourceTree = BUILT_PRODUCTS_DIR; }; 2AD458CA1F205EB700F05121 /* FruitMachine.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = FruitMachine.app; sourceTree = BUILT_PRODUCTS_DIR; };
2AD458CD1F205EB700F05121 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; }; 2AD458CD1F205EB700F05121 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
2AD458CF1F205EB700F05121 /* DebuggerViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DebuggerViewController.swift; sourceTree = "<group>"; }; 2AD458CF1F205EB700F05121 /* DebuggerViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DebuggerViewController.swift; sourceTree = "<group>"; };
@ -92,8 +94,9 @@
children = ( children = (
2AE42E411F28663600C4900E /* Video */, 2AE42E411F28663600C4900E /* Video */,
2A5BC5181F29A28D008C03BE /* AppleScreenView.swift */, 2A5BC5181F29A28D008C03BE /* AppleScreenView.swift */,
2A5BC51D1F29A4C3008C03BE /* AppleScreenViewDelegate.swift */, 2A5BC51D1F29A4C3008C03BE /* AppleIBitmapDisplay.swift */,
2AA8B5F71F2A8889002B350F /* AppleI.swift */, 2AA8B5F71F2A8889002B350F /* AppleI.swift */,
2AB815E61F2DA25E000BCE7D /* AppleIMetalView.swift */,
2A60851D1F2AFAE900E05B64 /* PIA.swift */, 2A60851D1F2AFAE900E05B64 /* PIA.swift */,
); );
path = AppleI; path = AppleI;
@ -270,11 +273,12 @@
2AD458E31F20661300F05121 /* CPUInstructions.swift in Sources */, 2AD458E31F20661300F05121 /* CPUInstructions.swift in Sources */,
2AD458D01F205EB700F05121 /* DebuggerViewController.swift in Sources */, 2AD458D01F205EB700F05121 /* DebuggerViewController.swift in Sources */,
2AA8B5FC1F2A8EAD002B350F /* Terminal.swift in Sources */, 2AA8B5FC1F2A8EAD002B350F /* Terminal.swift in Sources */,
2A5BC51E1F29A4C3008C03BE /* AppleScreenViewDelegate.swift in Sources */, 2A5BC51E1F29A4C3008C03BE /* AppleIBitmapDisplay.swift in Sources */,
2AD458CE1F205EB700F05121 /* AppDelegate.swift in Sources */, 2AD458CE1F205EB700F05121 /* AppDelegate.swift in Sources */,
2AE42E431F28665300C4900E /* CharacterGenerator.swift in Sources */, 2AE42E431F28665300C4900E /* CharacterGenerator.swift in Sources */,
2AE42E0C1F28522D00C4900E /* MemoryOverride.swift in Sources */, 2AE42E0C1F28522D00C4900E /* MemoryOverride.swift in Sources */,
2A22EBFB1F21A7A700A36A61 /* IntegerExtensions.swift in Sources */, 2A22EBFB1F21A7A700A36A61 /* IntegerExtensions.swift in Sources */,
2AB815E71F2DA25E000BCE7D /* AppleIMetalView.swift in Sources */,
2AD6D5841F26E6BF008F3CF5 /* DebuggerCommands.swift in Sources */, 2AD6D5841F26E6BF008F3CF5 /* DebuggerCommands.swift in Sources */,
2AE5BA041F23DE4400FAA343 /* Disassembly.swift in Sources */, 2AE5BA041F23DE4400FAA343 /* Disassembly.swift in Sources */,
2AE42E3A1F28628300C4900E /* MainViewController.swift in Sources */, 2AE42E3A1F28628300C4900E /* MainViewController.swift in Sources */,

View File

@ -22,9 +22,10 @@ class AppleI: NSObject {
"display": PIA() "display": PIA()
] ]
let emulatorViewDelegate = AppleScreenViewDelegate() let emulatorViewDelegate = AppleIBitmapDisplay()
let emulatorView = AppleScreenView(frame: NSMakeRect(0, 0, 640, 384)) let emulatorView = AppleScreenView(frame: NSMakeRect(0, 0, 640, 384))
let emuScreenLayer = CALayer() let emuScreenLayer = CALayer()
let emuMetalLayer = CAMetalLayer()
static let CPU_FREQUENCY = 1000000 static let CPU_FREQUENCY = 1000000
static let FRAMES_PER_SECOND = 60 static let FRAMES_PER_SECOND = 60
@ -37,7 +38,6 @@ class AppleI: NSObject {
emuScreenLayer.delegate = emulatorViewDelegate emuScreenLayer.delegate = emulatorViewDelegate
emuScreenLayer.frame = emulatorView.bounds emuScreenLayer.frame = emulatorView.bounds
//emulatorView.layer = emuScreenLayer
emulatorView.wantsLayer = true emulatorView.wantsLayer = true
emuScreenLayer.setNeedsDisplay() emuScreenLayer.setNeedsDisplay()

View File

@ -8,7 +8,7 @@
import Cocoa import Cocoa
class AppleScreenViewDelegate: NSObject, CALayerDelegate { class AppleIBitmapDisplay: NSObject, CALayerDelegate {
static let PIXEL_WIDTH = 320 static let PIXEL_WIDTH = 320
static let PIXEL_HEIGHT = 192 static let PIXEL_HEIGHT = 192
@ -29,11 +29,11 @@ class AppleScreenViewDelegate: NSObject, CALayerDelegate {
var indexedPixels: [UInt8] var indexedPixels: [UInt8]
var colorValues: [PixelData] var colorValues: [PixelData]
var rgbPixels = [PixelData](repeating: PixelData(a: 255, r: 0, g: 0, b: 0), count: AppleScreenViewDelegate.PIXEL_WIDTH*AppleScreenViewDelegate.PIXEL_HEIGHT) var rgbPixels = [PixelData](repeating: PixelData(a: 255, r: 0, g: 0, b: 0), count: AppleIBitmapDisplay.PIXEL_WIDTH*AppleIBitmapDisplay.PIXEL_HEIGHT)
override init() override init()
{ {
indexedPixels = [UInt8](repeating: 0x00, count: AppleScreenViewDelegate.PIXEL_WIDTH*AppleScreenViewDelegate.PIXEL_HEIGHT) indexedPixels = [UInt8](repeating: 0x00, count: AppleIBitmapDisplay.PIXEL_WIDTH*AppleIBitmapDisplay.PIXEL_HEIGHT)
colorValues = [PixelData](repeating: PixelData(a: 255, r: 0, g: 0, b: 0), count: 256) colorValues = [PixelData](repeating: PixelData(a: 255, r: 0, g: 0, b: 0), count: 256)
colorValues[1] = PixelData(a: 0, r: 200, g: 200, b: 200 colorValues[1] = PixelData(a: 0, r: 200, g: 200, b: 200
) )
@ -49,12 +49,12 @@ class AppleScreenViewDelegate: NSObject, CALayerDelegate {
func putCharacterPixels(charPixels: [UInt8], pixelPosition: CGPoint) { func putCharacterPixels(charPixels: [UInt8], pixelPosition: CGPoint) {
//Calculate the offset to reach the desired position. //Calculate the offset to reach the desired position.
let baseOffset = (Int(pixelPosition.y) * AppleScreenViewDelegate.PIXEL_WIDTH) + Int(pixelPosition.x) let baseOffset = (Int(pixelPosition.y) * AppleIBitmapDisplay.PIXEL_WIDTH) + Int(pixelPosition.x)
for charY in 0..<CharacterGenerator.CHAR_HEIGHT { for charY in 0..<CharacterGenerator.CHAR_HEIGHT {
//for charX in 0..<CharacterGenerator.CHAR_WIDTH { //for charX in 0..<CharacterGenerator.CHAR_WIDTH {
for charX in 0..<8 { for charX in 0..<8 {
indexedPixels[baseOffset + (AppleScreenViewDelegate.PIXEL_WIDTH * charY) + 7 - charX] = (charPixels[charY] & UInt8(1 << charX)) > 0 ? 1 : 0 indexedPixels[baseOffset + (AppleIBitmapDisplay.PIXEL_WIDTH * charY) + 7 - charX] = (charPixels[charY] & UInt8(1 << charX)) > 0 ? 1 : 0
} }
} }
} }
@ -74,11 +74,11 @@ class AppleScreenViewDelegate: NSObject, CALayerDelegate {
var pixels = convertIndexedPixelsToRGB(pixels: indexedPixels) var pixels = convertIndexedPixelsToRGB(pixels: indexedPixels)
let pixelProvider = CGDataProvider(data: NSData(bytes: &pixels, length: pixels.count * MemoryLayout<PixelData>.size)) let pixelProvider = CGDataProvider(data: NSData(bytes: &pixels, length: pixels.count * MemoryLayout<PixelData>.size))
let renderedImage = CGImage(width: AppleScreenViewDelegate.PIXEL_WIDTH, let renderedImage = CGImage(width: AppleIBitmapDisplay.PIXEL_WIDTH,
height: AppleScreenViewDelegate.PIXEL_HEIGHT, height: AppleIBitmapDisplay.PIXEL_HEIGHT,
bitsPerComponent: Int(bitsPerComponent), bitsPerComponent: Int(bitsPerComponent),
bitsPerPixel: Int(bitsPerPixel), bitsPerPixel: Int(bitsPerPixel),
bytesPerRow: AppleScreenViewDelegate.PIXEL_WIDTH * Int(MemoryLayout<PixelData>.size), bytesPerRow: AppleIBitmapDisplay.PIXEL_WIDTH * Int(MemoryLayout<PixelData>.size),
space: colorSpace, space: colorSpace,
bitmapInfo: bitmapInfo, bitmapInfo: bitmapInfo,
provider: pixelProvider!, provider: pixelProvider!,

View File

@ -0,0 +1,24 @@
//
// AppleIMetalView.swift
// FruitMachine
//
// Created by Christopher Rohl on 7/30/17.
// Copyright © 2017 Christopher Rohl. All rights reserved.
//
import Cocoa
import Metal
import MetalKit
class AppleIMetalView: MTKView {
var commandQueue: MTLCommandQueue?
var renderPipelineState: MTLRenderPipelineState?
var depthStencilState: MTLDepthStencilState?
required init(coder: NSCoder) {
super.init(coder: coder)
// Device
device = MTLCreateSystemDefaultDevice()
}
}

View File

@ -38,7 +38,7 @@ class CharacterGenerator: NSObject {
/* Instead of ignoring ASCII bit b6, we ignore bit b5. At the same time ASCII bit b6 must be inverted before it is fed to the character ROM. This way the entire character range from $40 to $7F will end up in the range $00 to $1F (twice of course). Now lower case characters are automatically translated into their corresponding upper case bit maps. /* Instead of ignoring ASCII bit b6, we ignore bit b5. At the same time ASCII bit b6 must be inverted before it is fed to the character ROM. This way the entire character range from $40 to $7F will end up in the range $00 to $1F (twice of course). Now lower case characters are automatically translated into their corresponding upper case bit maps.
*/ */
var convertedCharIndex = (charIndex & 0x1f) | (((charIndex ^ 0x40) & 0x40) >> 1) let convertedCharIndex = (charIndex & 0x1f) | (((charIndex ^ 0x40) & 0x40) >> 1)
for scanlineIndex in 0..<CharacterGenerator.CHAR_HEIGHT { for scanlineIndex in 0..<CharacterGenerator.CHAR_HEIGHT {
pixelArray[scanlineIndex] = ROM[scanlineIndex + (Int(convertedCharIndex) * CharacterGenerator.CHAR_HEIGHT)] pixelArray[scanlineIndex] = ROM[scanlineIndex + (Int(convertedCharIndex) * CharacterGenerator.CHAR_HEIGHT)]

View File

@ -8,6 +8,7 @@
import Cocoa import Cocoa
import CoreGraphics import CoreGraphics
import MetalKit
class MainViewController: NSViewController { class MainViewController: NSViewController {
@ -46,7 +47,6 @@ class MainViewController: NSViewController {
computer.pia["keyboard"]?.data = UInt8(ascii32 & 0x000000FF) computer.pia["keyboard"]?.data = UInt8(ascii32 & 0x000000FF)
computer.pia["keyboard"]?.control |= 0x80 computer.pia["keyboard"]?.control |= 0x80
} }
private func returnChar(theEvent: NSEvent) -> Character?{ private func returnChar(theEvent: NSEvent) -> Character?{