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()
|
||||
|
||||
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/basic.bin", offset: 0xE000, length: 0x1000)
|
||||
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.readKBDCR)
|
||||
|
||||
}
|
||||
|
||||
func runFrame() {
|
||||
let startTime = CFAbsoluteTimeGetCurrent()
|
||||
|
||||
|
||||
CPU.sharedInstance.cycles = 0
|
||||
CPU.sharedInstance.cyclesInBatch = AppleI.CYCLES_PER_BATCH
|
||||
CPU.sharedInstance.runCyclesBatch()
|
||||
|
||||
//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() {
|
||||
emulatorViewDelegate.putCharacterPixels(charPixels: cg.getCharacterPixels(charIndex: character),
|
||||
emulatorViewDelegate.putCharacterPixels(buffer: buf,
|
||||
charPixels: cg.getCharacterPixels(charIndex: character),
|
||||
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.display()
|
||||
|
||||
let timeElapsed = CFAbsoluteTimeGetCurrent() - startTime
|
||||
print("Time elapsed for runFrame: \(timeElapsed) s.")
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,8 @@ class AppleIBitmapDisplay: NSObject, CALayerDelegate {
|
||||
|
||||
var renderedImage: CGImage?
|
||||
|
||||
var scanlineOffsets: [Int]
|
||||
|
||||
override init() {
|
||||
_ = CVPixelBufferCreate(kCFAllocatorDefault, AppleIBitmapDisplay.PIXEL_WIDTH, AppleIBitmapDisplay.PIXEL_HEIGHT, OSType(k16BE555PixelFormat), nil, &pixels)
|
||||
|
||||
@ -31,25 +33,26 @@ class AppleIBitmapDisplay: NSObject, CALayerDelegate {
|
||||
bufferHeight = CVPixelBufferGetHeight(pixels!)
|
||||
|
||||
renderedImage = nil
|
||||
|
||||
scanlineOffsets = [Int]()
|
||||
for i in 0..<AppleIBitmapDisplay.PIXEL_HEIGHT {
|
||||
scanlineOffsets.append(i * AppleIBitmapDisplay.PIXEL_WIDTH)
|
||||
}
|
||||
}
|
||||
|
||||
func putCharacterPixels(charPixels: [UInt8], pixelPosition: CGPoint) {
|
||||
CVPixelBufferLockBaseAddress(pixels!, CVPixelBufferLockFlags(rawValue: 0))
|
||||
let pixelBase = CVPixelBufferGetBaseAddress(pixels!)
|
||||
let buf = pixelBase?.assumingMemoryBound(to: BitmapPixelsBE555.PixelData.self)
|
||||
func putCharacterPixels(buffer: UnsafeMutablePointer<BitmapPixelsBE555.PixelData>?, charPixels: [UInt8], pixelPosition: CGPoint) {
|
||||
//You better have locked the buffer before getting here...
|
||||
|
||||
//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 {
|
||||
let offsetY = AppleIBitmapDisplay.PIXEL_WIDTH * charY
|
||||
|
||||
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 {
|
||||
|
Loading…
Reference in New Issue
Block a user