change from ARGB32 to BE555

This commit is contained in:
Luigi Thirty 2017-07-31 16:33:42 -04:00
parent 2045435cf4
commit acdefbb4fb
5 changed files with 41 additions and 19 deletions

View File

@ -63,6 +63,8 @@ class AppleI: NSObject {
} }
func runFrame() { func runFrame() {
let startTime = CFAbsoluteTimeGetCurrent()
CPU.sharedInstance.cycles = 0 CPU.sharedInstance.cycles = 0
CPU.sharedInstance.cyclesInBatch = AppleI.CYCLES_PER_BATCH CPU.sharedInstance.cyclesInBatch = AppleI.CYCLES_PER_BATCH
CPU.sharedInstance.runCyclesBatch() CPU.sharedInstance.runCyclesBatch()
@ -76,7 +78,7 @@ class AppleI: NSObject {
emulatorView.setNeedsDisplay(emulatorView.frame) emulatorView.setNeedsDisplay(emulatorView.frame)
emulatorView.display() emulatorView.display()
//emuGLView.setNeedsDisplay(emuGLView.frame) let timeElapsed = CFAbsoluteTimeGetCurrent() - startTime
//emuGLView.display() print("Time elapsed for runFrame: \(timeElapsed) s.")
} }
} }

View File

@ -13,7 +13,7 @@ class AppleIBitmapDisplay: NSObject, CALayerDelegate {
static let PIXEL_HEIGHT = 192 static let PIXEL_HEIGHT = 192
/* Pixel data stuff. */ /* Pixel data stuff. */
let bitmapInfo: CGBitmapInfo = [.byteOrder32Big, CGBitmapInfo(rawValue: CGImageAlphaInfo.noneSkipFirst.rawValue)] let bitmapInfo: CGBitmapInfo = [.byteOrder16Big, CGBitmapInfo(rawValue: CGImageAlphaInfo.noneSkipFirst.rawValue)]
var pixels: CVPixelBuffer? var pixels: CVPixelBuffer?
@ -21,18 +21,22 @@ class AppleIBitmapDisplay: NSObject, CALayerDelegate {
let bufferWidth: Int let bufferWidth: Int
let bufferHeight: Int let bufferHeight: Int
var renderedImage: CGImage?
override init() { override init() {
_ = CVPixelBufferCreate(kCFAllocatorDefault, AppleIBitmapDisplay.PIXEL_WIDTH, AppleIBitmapDisplay.PIXEL_HEIGHT, OSType(k32ARGBPixelFormat), nil, &pixels) _ = CVPixelBufferCreate(kCFAllocatorDefault, AppleIBitmapDisplay.PIXEL_WIDTH, AppleIBitmapDisplay.PIXEL_HEIGHT, OSType(k16BE555PixelFormat), nil, &pixels)
sourceRowBytes = CVPixelBufferGetBytesPerRow(pixels!) sourceRowBytes = CVPixelBufferGetBytesPerRow(pixels!)
bufferWidth = CVPixelBufferGetWidth(pixels!) bufferWidth = CVPixelBufferGetWidth(pixels!)
bufferHeight = CVPixelBufferGetHeight(pixels!) bufferHeight = CVPixelBufferGetHeight(pixels!)
renderedImage = nil
} }
func putCharacterPixels(charPixels: [UInt8], pixelPosition: CGPoint) { func putCharacterPixels(charPixels: [UInt8], pixelPosition: CGPoint) {
CVPixelBufferLockBaseAddress(pixels!, CVPixelBufferLockFlags(rawValue: 0)) CVPixelBufferLockBaseAddress(pixels!, CVPixelBufferLockFlags(rawValue: 0))
let pixelBase = CVPixelBufferGetBaseAddress(pixels!) let pixelBase = CVPixelBufferGetBaseAddress(pixels!)
let buf = pixelBase?.assumingMemoryBound(to: BitmapPixelsARGB32.PixelData.self) let buf = pixelBase?.assumingMemoryBound(to: BitmapPixelsBE555.PixelData.self)
//Calculate the offset to reach the desired position. //Calculate the offset to reach the desired position.
let baseOffset = (Int(pixelPosition.y) * AppleIBitmapDisplay.PIXEL_WIDTH) + Int(pixelPosition.x) let baseOffset = (Int(pixelPosition.y) * AppleIBitmapDisplay.PIXEL_WIDTH) + Int(pixelPosition.x)
@ -41,7 +45,7 @@ class AppleIBitmapDisplay: NSObject, CALayerDelegate {
let offsetY = AppleIBitmapDisplay.PIXEL_WIDTH * charY let offsetY = AppleIBitmapDisplay.PIXEL_WIDTH * charY
for charX in 0..<8 { for charX in 0..<8 {
buf![baseOffset + offsetY + 7 - charX] = (charPixels[charY] & UInt8(1 << charX)) > 0 ? BitmapPixelsARGB32.ARGBWhite : BitmapPixelsARGB32.ARGBBlack buf![baseOffset + offsetY + 7 - charX] = (charPixels[charY] & UInt8(1 << charX)) > 0 ? BitmapPixelsBE555.ARGBWhite : BitmapPixelsBE555.ARGBBlack
} }
} }
@ -58,25 +62,23 @@ class AppleIBitmapDisplay: NSObject, CALayerDelegate {
/* Draw the screen. */ /* Draw the screen. */
func draw(_ layer: CALayer, in ctx: CGContext) { func draw(_ layer: CALayer, in ctx: CGContext) {
let bounds = layer.bounds
CVPixelBufferLockBaseAddress(pixels!, CVPixelBufferLockFlags.readOnly) CVPixelBufferLockBaseAddress(pixels!, CVPixelBufferLockFlags.readOnly)
let pixelBase = CVPixelBufferGetBaseAddress(pixels!) let pixelBase = CVPixelBufferGetBaseAddress(pixels!)
let pixelRef = CGDataProvider(dataInfo: nil, data: pixelBase!, size: sourceRowBytes * bufferHeight, releaseData: releaseMaskImagePixelData) let pixelRef = CGDataProvider(dataInfo: nil, data: pixelBase!, size: sourceRowBytes * bufferHeight, releaseData: releaseMaskImagePixelData)
let renderedImage = CGImage(width: AppleIBitmapDisplay.PIXEL_WIDTH, renderedImage = CGImage(width: AppleIBitmapDisplay.PIXEL_WIDTH,
height: AppleIBitmapDisplay.PIXEL_HEIGHT, height: AppleIBitmapDisplay.PIXEL_HEIGHT,
bitsPerComponent: Int(BitmapPixelsARGB32.bitsPerComponent), //8 bitsPerComponent: Int(BitmapPixelsBE555.bitsPerComponent), //5
bitsPerPixel: Int(BitmapPixelsARGB32.bitsPerPixel), //32 bitsPerPixel: Int(BitmapPixelsBE555.bitsPerPixel), //16
bytesPerRow: AppleIBitmapDisplay.PIXEL_WIDTH * Int(MemoryLayout<BitmapPixelsARGB32.PixelData>.size), bytesPerRow: AppleIBitmapDisplay.PIXEL_WIDTH * Int(MemoryLayout<BitmapPixelsBE555.PixelData>.size),
space: BitmapPixelsARGB32.colorSpace, //RGB space: BitmapPixelsBE555.colorSpace, //RGB
bitmapInfo: bitmapInfo, //ARGB32 bitmapInfo: bitmapInfo, //BE555
provider: pixelRef!, provider: pixelRef!,
decode: nil, decode: nil,
shouldInterpolate: false, shouldInterpolate: false,
intent: CGColorRenderingIntent.defaultIntent) intent: CGColorRenderingIntent.defaultIntent)
ctx.draw(renderedImage!, in: bounds) ctx.draw(renderedImage!, in: layer.bounds)
CVPixelBufferUnlockBaseAddress(pixels!, CVPixelBufferLockFlags(rawValue: 0)) CVPixelBufferUnlockBaseAddress(pixels!, CVPixelBufferLockFlags(rawValue: 0))
} }

View File

@ -37,3 +37,16 @@ class BitmapPixelsARGB32 : NSObject {
static let ARGBWhite = PixelData(a: 255, r: 200, g: 200, b: 200) static let ARGBWhite = PixelData(a: 255, r: 200, g: 200, b: 200)
static let ARGBBlack = PixelData(a: 255, r: 0, g: 0, b: 0) static let ARGBBlack = PixelData(a: 255, r: 0, g: 0, b: 0)
} }
class BitmapPixelsBE555 : NSObject {
struct PixelData {
var data: UInt16 = 0
}
static let bitsPerComponent: UInt8 = 5
static let bitsPerPixel: UInt = 16
static let colorSpace = CGColorSpaceCreateDeviceRGB()
static let ARGBWhite = PixelData(data: 0b1111111101111111)
static let ARGBBlack = PixelData(data: 0b0000000000000000)
}

View File

@ -23,7 +23,11 @@
</connections> </connections>
</menuItem> </menuItem>
<menuItem isSeparatorItem="YES" id="VOq-y0-SEH"/> <menuItem isSeparatorItem="YES" id="VOq-y0-SEH"/>
<menuItem title="Preferences…" keyEquivalent="," id="BOF-NM-1cW"/> <menuItem title="Preferences…" keyEquivalent="," id="BOF-NM-1cW">
<connections>
<action selector="showPreferences:" target="Ady-hI-5gd" id="cAp-1h-Tcj"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="wFC-TO-SCJ"/> <menuItem isSeparatorItem="YES" id="wFC-TO-SCJ"/>
<menuItem title="Services" id="NMo-om-nkz"> <menuItem title="Services" id="NMo-om-nkz">
<modifierMask key="keyEquivalentModifierMask"/> <modifierMask key="keyEquivalentModifierMask"/>

View File

@ -8,8 +8,6 @@
import Cocoa import Cocoa
import CoreGraphics import CoreGraphics
import OpenGL
import GLKit
class MainViewController: NSViewController { class MainViewController: NSViewController {
@ -24,7 +22,6 @@ class MainViewController: NSViewController {
super.viewDidLoad() super.viewDidLoad()
preferencesWindowController = PreferencesWindowController() preferencesWindowController = PreferencesWindowController()
preferencesWindowController.loadWindow()
// Do view setup here. // Do view setup here.
self.view.addSubview(computer.emulatorView) self.view.addSubview(computer.emulatorView)
@ -67,6 +64,10 @@ class MainViewController: NSViewController {
debuggerWindowController = debuggerStoryboard.instantiateInitialController() as! DebuggerWindowController debuggerWindowController = debuggerStoryboard.instantiateInitialController() as! DebuggerWindowController
debuggerWindowController.showWindow(self) debuggerWindowController.showWindow(self)
} }
@IBAction func showPreferences(_ sender: Any) {
preferencesWindowController.loadWindow()
}
} }
extension Character { extension Character {