         
     }
     
-    
-    func vram2ImageX() {
+
+    // lockFocusによるイメージ生成
+    func vram2ImageLF() {
         
         var screenImage = NSImage(size: NSSize(width: self.width * 8,height: self.height * 8))
 
         screenImage.lockFocus()
         
         for y in 0..<height {
+            let yp = (height - y) * 8
+//            NSLog("y:\(y) yp:\(yp)")
             for x in 0..<width {
                 
                 let c:UInt8 = vram[y][x]
 
-                let rect = NSRect(x: x * 8,y: (height - y) * 8, width: 8, height: 8)
+                let xp = x * 8
+                let rect = NSRect(x: xp, y: yp, width: 8, height: 8)
                 fontImage.drawInRect(rect,
-                    fromRect: fontRect(c),
+                    fromRect: fontRectX(c),
                     operation: NSCompositingOperation.CompositeDestinationOver, fraction: 1.0)
                 
             }

        let bytesPerRow = Int(4 * widthBits)
        let colorSpace = CGColorSpaceCreateDeviceRGB()
        let bitmapInfo = CGBitmapInfo(rawValue: CGImageAlphaInfo.PremultipliedLast.rawValue)
        
        

        
        let bitmapContext = CGBitmapContextCreate(nil, widthBits, heightBits, bitsPerComponent, bytesPerRow, colorSpace, bitmapInfo)!
        
        for y in 0..<height {
            for x in 0..<width {
                
                let c:UInt8 = vram[y][x]
                
                let rect = NSRect(x: x * 8, y: (height - y) * 8, width: 8, height: 8)

                let fontref = CGImageCreateWithImageInRect(image, fontRectX(c));

                CGContextDrawImage(bitmapContext, rect, CGImageCreateCopy( fontref))
                
            }
        }

        
        // ビットマップを NSImage に変換します。
        let newImageRef = CGBitmapContextCreateImage(bitmapContext)!
        let newImage = NSImage(CGImage: newImageRef, size: NSSize(width: widthBits, height: heightBits))

    private  override init() {
        width = SCREEN_CHARA_WIDTH
        height = SCREEN_CHARA_HEIGTH
        vram = [[UInt8]](count: height, repeatedValue: [UInt8](count: width, repeatedValue: 0x20))
        
        super.init()
        
        for y in 0 ..< height {
            for x in 0 ..< width {
                putChar( x, y: y, c: 0x20)
            }
        }

    }
    
    
