From a98bea0f343ccd483021e9b7f7a08ef2d8517be4 Mon Sep 17 00:00:00 2001 From: Luigi Thirty Date: Sun, 30 Jul 2017 02:32:53 -0400 Subject: [PATCH] thing --- FruitMachine.xcodeproj/project.pbxproj | 12 ++++++---- FruitMachine/AppleI/AppleI.swift | 4 ++-- ...legate.swift => AppleIBitmapDisplay.swift} | 16 ++++++------- FruitMachine/AppleI/AppleIMetalView.swift | 24 +++++++++++++++++++ .../AppleI/Video/CharacterGenerator.swift | 2 +- FruitMachine/MainViewController.swift | 2 +- 6 files changed, 44 insertions(+), 16 deletions(-) rename FruitMachine/AppleI/{AppleScreenViewDelegate.swift => AppleIBitmapDisplay.swift} (77%) create mode 100644 FruitMachine/AppleI/AppleIMetalView.swift diff --git a/FruitMachine.xcodeproj/project.pbxproj b/FruitMachine.xcodeproj/project.pbxproj index 2d6f43e..4f1f0ed 100644 --- a/FruitMachine.xcodeproj/project.pbxproj +++ b/FruitMachine.xcodeproj/project.pbxproj @@ -11,11 +11,12 @@ 2A22EBFB1F21A7A700A36A61 /* IntegerExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A22EBFA1F21A7A700A36A61 /* IntegerExtensions.swift */; }; 2A5BC5191F29A28D008C03BE /* AppleScreenView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A5BC5181F29A28D008C03BE /* AppleScreenView.swift */; }; 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 */; }; 2AA8B5F81F2A8889002B350F /* AppleI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2AA8B5F71F2A8889002B350F /* AppleI.swift */; }; 2AA8B5FC1F2A8EAD002B350F /* Terminal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2AA8B5FB1F2A8EAD002B350F /* Terminal.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 */; }; 2AD458D01F205EB700F05121 /* DebuggerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2AD458CF1F205EB700F05121 /* DebuggerViewController.swift */; }; 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 = ""; }; 2A5BC5181F29A28D008C03BE /* AppleScreenView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppleScreenView.swift; sourceTree = ""; }; 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 = ""; }; + 2A5BC51D1F29A4C3008C03BE /* AppleIBitmapDisplay.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppleIBitmapDisplay.swift; sourceTree = ""; }; 2A60851D1F2AFAE900E05B64 /* PIA.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PIA.swift; sourceTree = ""; }; 2AA8B5F71F2A8889002B350F /* AppleI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppleI.swift; sourceTree = ""; }; 2AA8B5FB1F2A8EAD002B350F /* Terminal.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Terminal.swift; sourceTree = ""; }; 2AA8B5FD1F2A942C002B350F /* PIAOverrides.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PIAOverrides.swift; sourceTree = ""; }; + 2AB815E61F2DA25E000BCE7D /* AppleIMetalView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppleIMetalView.swift; sourceTree = ""; }; 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 = ""; }; 2AD458CF1F205EB700F05121 /* DebuggerViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DebuggerViewController.swift; sourceTree = ""; }; @@ -92,8 +94,9 @@ children = ( 2AE42E411F28663600C4900E /* Video */, 2A5BC5181F29A28D008C03BE /* AppleScreenView.swift */, - 2A5BC51D1F29A4C3008C03BE /* AppleScreenViewDelegate.swift */, + 2A5BC51D1F29A4C3008C03BE /* AppleIBitmapDisplay.swift */, 2AA8B5F71F2A8889002B350F /* AppleI.swift */, + 2AB815E61F2DA25E000BCE7D /* AppleIMetalView.swift */, 2A60851D1F2AFAE900E05B64 /* PIA.swift */, ); path = AppleI; @@ -270,11 +273,12 @@ 2AD458E31F20661300F05121 /* CPUInstructions.swift in Sources */, 2AD458D01F205EB700F05121 /* DebuggerViewController.swift in Sources */, 2AA8B5FC1F2A8EAD002B350F /* Terminal.swift in Sources */, - 2A5BC51E1F29A4C3008C03BE /* AppleScreenViewDelegate.swift in Sources */, + 2A5BC51E1F29A4C3008C03BE /* AppleIBitmapDisplay.swift in Sources */, 2AD458CE1F205EB700F05121 /* AppDelegate.swift in Sources */, 2AE42E431F28665300C4900E /* CharacterGenerator.swift in Sources */, 2AE42E0C1F28522D00C4900E /* MemoryOverride.swift in Sources */, 2A22EBFB1F21A7A700A36A61 /* IntegerExtensions.swift in Sources */, + 2AB815E71F2DA25E000BCE7D /* AppleIMetalView.swift in Sources */, 2AD6D5841F26E6BF008F3CF5 /* DebuggerCommands.swift in Sources */, 2AE5BA041F23DE4400FAA343 /* Disassembly.swift in Sources */, 2AE42E3A1F28628300C4900E /* MainViewController.swift in Sources */, diff --git a/FruitMachine/AppleI/AppleI.swift b/FruitMachine/AppleI/AppleI.swift index 550916d..42f034a 100644 --- a/FruitMachine/AppleI/AppleI.swift +++ b/FruitMachine/AppleI/AppleI.swift @@ -22,9 +22,10 @@ class AppleI: NSObject { "display": PIA() ] - let emulatorViewDelegate = AppleScreenViewDelegate() + let emulatorViewDelegate = AppleIBitmapDisplay() let emulatorView = AppleScreenView(frame: NSMakeRect(0, 0, 640, 384)) let emuScreenLayer = CALayer() + let emuMetalLayer = CAMetalLayer() static let CPU_FREQUENCY = 1000000 static let FRAMES_PER_SECOND = 60 @@ -37,7 +38,6 @@ class AppleI: NSObject { emuScreenLayer.delegate = emulatorViewDelegate emuScreenLayer.frame = emulatorView.bounds - //emulatorView.layer = emuScreenLayer emulatorView.wantsLayer = true emuScreenLayer.setNeedsDisplay() diff --git a/FruitMachine/AppleI/AppleScreenViewDelegate.swift b/FruitMachine/AppleI/AppleIBitmapDisplay.swift similarity index 77% rename from FruitMachine/AppleI/AppleScreenViewDelegate.swift rename to FruitMachine/AppleI/AppleIBitmapDisplay.swift index e11eaec..7912daf 100644 --- a/FruitMachine/AppleI/AppleScreenViewDelegate.swift +++ b/FruitMachine/AppleI/AppleIBitmapDisplay.swift @@ -8,7 +8,7 @@ import Cocoa -class AppleScreenViewDelegate: NSObject, CALayerDelegate { +class AppleIBitmapDisplay: NSObject, CALayerDelegate { static let PIXEL_WIDTH = 320 static let PIXEL_HEIGHT = 192 @@ -29,11 +29,11 @@ class AppleScreenViewDelegate: NSObject, CALayerDelegate { var indexedPixels: [UInt8] 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() { - 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[1] = PixelData(a: 0, r: 200, g: 200, b: 200 ) @@ -49,12 +49,12 @@ class AppleScreenViewDelegate: NSObject, CALayerDelegate { func putCharacterPixels(charPixels: [UInt8], pixelPosition: CGPoint) { //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.. 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) let pixelProvider = CGDataProvider(data: NSData(bytes: &pixels, length: pixels.count * MemoryLayout.size)) - let renderedImage = CGImage(width: AppleScreenViewDelegate.PIXEL_WIDTH, - height: AppleScreenViewDelegate.PIXEL_HEIGHT, + let renderedImage = CGImage(width: AppleIBitmapDisplay.PIXEL_WIDTH, + height: AppleIBitmapDisplay.PIXEL_HEIGHT, bitsPerComponent: Int(bitsPerComponent), bitsPerPixel: Int(bitsPerPixel), - bytesPerRow: AppleScreenViewDelegate.PIXEL_WIDTH * Int(MemoryLayout.size), + bytesPerRow: AppleIBitmapDisplay.PIXEL_WIDTH * Int(MemoryLayout.size), space: colorSpace, bitmapInfo: bitmapInfo, provider: pixelProvider!, diff --git a/FruitMachine/AppleI/AppleIMetalView.swift b/FruitMachine/AppleI/AppleIMetalView.swift new file mode 100644 index 0000000..95aa91b --- /dev/null +++ b/FruitMachine/AppleI/AppleIMetalView.swift @@ -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() + } +} diff --git a/FruitMachine/AppleI/Video/CharacterGenerator.swift b/FruitMachine/AppleI/Video/CharacterGenerator.swift index 754383c..095d087 100644 --- a/FruitMachine/AppleI/Video/CharacterGenerator.swift +++ b/FruitMachine/AppleI/Video/CharacterGenerator.swift @@ -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. */ - var convertedCharIndex = (charIndex & 0x1f) | (((charIndex ^ 0x40) & 0x40) >> 1) + let convertedCharIndex = (charIndex & 0x1f) | (((charIndex ^ 0x40) & 0x40) >> 1) for scanlineIndex in 0.. Character?{