mirror of
https://github.com/Luigi30/FruitMachine-Swift.git
synced 2024-11-23 02:33:00 +00:00
optimizing
This commit is contained in:
parent
acdefbb4fb
commit
b6a65d1eb7
@ -41,10 +41,6 @@ class AppleI: NSObject {
|
|||||||
|
|
||||||
installOverrides()
|
installOverrides()
|
||||||
|
|
||||||
for (cellNum, character) in terminal.characters.enumerated() {
|
|
||||||
emulatorViewDelegate.putCharacterPixels(charPixels: cg.getCharacterPixels(charIndex: character), pixelPosition: emulatorViewDelegate.getPixelOffset(charCellIndex: cellNum))
|
|
||||||
}
|
|
||||||
|
|
||||||
CPU.sharedInstance.memoryInterface.loadBinary(path: "/Users/luigi/apple1/apple1.rom", offset: 0xFF00, length: 0x100)
|
CPU.sharedInstance.memoryInterface.loadBinary(path: "/Users/luigi/apple1/apple1.rom", offset: 0xFF00, length: 0x100)
|
||||||
CPU.sharedInstance.memoryInterface.loadBinary(path: "/Users/luigi/apple1/basic.bin", offset: 0xE000, length: 0x1000)
|
CPU.sharedInstance.memoryInterface.loadBinary(path: "/Users/luigi/apple1/basic.bin", offset: 0xE000, length: 0x1000)
|
||||||
CPU.sharedInstance.performReset()
|
CPU.sharedInstance.performReset()
|
||||||
@ -59,26 +55,35 @@ class AppleI: NSObject {
|
|||||||
|
|
||||||
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() {
|
||||||
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()
|
||||||
|
|
||||||
//update the video display
|
//update the video display
|
||||||
|
CVPixelBufferLockBaseAddress(emulatorViewDelegate.pixels!, CVPixelBufferLockFlags(rawValue: 0))
|
||||||
|
let pixelBase = CVPixelBufferGetBaseAddress(emulatorViewDelegate.pixels!)
|
||||||
|
let buf = pixelBase?.assumingMemoryBound(to: BitmapPixelsBE555.PixelData.self)
|
||||||
|
|
||||||
|
let startTime = CFAbsoluteTimeGetCurrent()
|
||||||
|
|
||||||
for (cellNum, character) in terminal.characters.enumerated() {
|
for (cellNum, character) in terminal.characters.enumerated() {
|
||||||
emulatorViewDelegate.putCharacterPixels(charPixels: cg.getCharacterPixels(charIndex: character),
|
emulatorViewDelegate.putCharacterPixels(buffer: buf,
|
||||||
|
charPixels: cg.getCharacterPixels(charIndex: character),
|
||||||
pixelPosition: emulatorViewDelegate.getPixelOffset(charCellIndex: cellNum))
|
pixelPosition: emulatorViewDelegate.getPixelOffset(charCellIndex: cellNum))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let timeElapsed = CFAbsoluteTimeGetCurrent() - startTime
|
||||||
|
print("Time elapsed for runFrame: \(timeElapsed) s.")
|
||||||
|
|
||||||
|
CVPixelBufferUnlockBaseAddress(emulatorViewDelegate.pixels!, CVPixelBufferLockFlags(rawValue: 0))
|
||||||
|
|
||||||
emulatorView.setNeedsDisplay(emulatorView.frame)
|
emulatorView.setNeedsDisplay(emulatorView.frame)
|
||||||
emulatorView.display()
|
emulatorView.display()
|
||||||
|
|
||||||
let timeElapsed = CFAbsoluteTimeGetCurrent() - startTime
|
|
||||||
print("Time elapsed for runFrame: \(timeElapsed) s.")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,8 @@ class AppleIBitmapDisplay: NSObject, CALayerDelegate {
|
|||||||
|
|
||||||
var renderedImage: CGImage?
|
var renderedImage: CGImage?
|
||||||
|
|
||||||
|
var scanlineOffsets: [Int]
|
||||||
|
|
||||||
override init() {
|
override init() {
|
||||||
_ = CVPixelBufferCreate(kCFAllocatorDefault, AppleIBitmapDisplay.PIXEL_WIDTH, AppleIBitmapDisplay.PIXEL_HEIGHT, OSType(k16BE555PixelFormat), nil, &pixels)
|
_ = CVPixelBufferCreate(kCFAllocatorDefault, AppleIBitmapDisplay.PIXEL_WIDTH, AppleIBitmapDisplay.PIXEL_HEIGHT, OSType(k16BE555PixelFormat), nil, &pixels)
|
||||||
|
|
||||||
@ -31,25 +33,26 @@ class AppleIBitmapDisplay: NSObject, CALayerDelegate {
|
|||||||
bufferHeight = CVPixelBufferGetHeight(pixels!)
|
bufferHeight = CVPixelBufferGetHeight(pixels!)
|
||||||
|
|
||||||
renderedImage = nil
|
renderedImage = nil
|
||||||
|
|
||||||
|
scanlineOffsets = [Int]()
|
||||||
|
for i in 0..<AppleIBitmapDisplay.PIXEL_HEIGHT {
|
||||||
|
scanlineOffsets.append(i * AppleIBitmapDisplay.PIXEL_WIDTH)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func putCharacterPixels(charPixels: [UInt8], pixelPosition: CGPoint) {
|
func putCharacterPixels(buffer: UnsafeMutablePointer<BitmapPixelsBE555.PixelData>?, charPixels: [UInt8], pixelPosition: CGPoint) {
|
||||||
CVPixelBufferLockBaseAddress(pixels!, CVPixelBufferLockFlags(rawValue: 0))
|
//You better have locked the buffer before getting here...
|
||||||
let pixelBase = CVPixelBufferGetBaseAddress(pixels!)
|
|
||||||
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 = scanlineOffsets[Int(pixelPosition.y)] + Int(pixelPosition.x)
|
||||||
|
|
||||||
for charY in 0..<CharacterGenerator.CHAR_HEIGHT {
|
for charY in 0..<CharacterGenerator.CHAR_HEIGHT {
|
||||||
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 ? BitmapPixelsBE555.ARGBWhite : BitmapPixelsBE555.ARGBBlack
|
buffer![baseOffset + offsetY + 7 - charX] = (charPixels[charY] & UInt8(1 << charX)) > 0 ? BitmapPixelsBE555.ARGBWhite : BitmapPixelsBE555.ARGBBlack
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CVPixelBufferUnlockBaseAddress(pixels!, CVPixelBufferLockFlags(rawValue: 0))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getPixelOffset(charCellX: Int, charCellY: Int) -> CGPoint {
|
func getPixelOffset(charCellX: Int, charCellY: Int) -> CGPoint {
|
||||||
|
Loading…
Reference in New Issue
Block a user