//public MediaStreamSource Video
        //{
        //    get { return _video; }
        //    set { _video = value; }
        //}


        public C64Display(C64 c64, UserInterface ui)
        {
            _ui = ui;
            _TheC64 = c64;

            CompositionTarget.Rendering += new EventHandler(CompositionTarget_Rendering);

            //_ui.ScreenImage.Source = _image;
        }
        public MOS6581(C64 c64)
        {
            the_c64 = c64;
            the_renderer = null;
            for (int i = 0; i < regs.Length; i++)
                regs[i] = 0;

            // Open the renderer
            open_close_renderer(SIDType.SIDTYPE_NONE, GlobalPrefs.ThePrefs.SIDType);
        }
        void UserInterface_Loaded(object sender, RoutedEventArgs e)
        {
            _c64 = new C64(this);

            // should probably be in C64Display which is where other Silverlight-specific stuff ended up
            HumanInput.AttachKeyboardEventHandlers();

            VideoDisplay.SetSource(_c64.Video);

            _c64.Run();
        }
        const bool BALow = false;       // used for the EmulateCycle.cs file to ignore this condition
        #endregion

        #region public methods

        public MOS6502_1541(C64 c64, Job1541 job, C64Display disp, Drive1541Ram Ram, Drive1541Rom Rom)
        {
            the_c64 = c64;
            the_job = job;
            the_display = disp;
            ram = Ram;
            rom = Rom;

            a = x = y = 0;
            sp = 0xff;
            n_flag = z_flag = 0;
            v_flag = d_flag = c_flag = false;
            i_flag = true;

            via1_t1c = via1_t1l = via1_t2c = via1_t2l = 0;
            via1_sr = 0;
            via2_t1c = via2_t1l = via2_t2c = via2_t2l = 0;
            via2_sr = 0;

            first_irq_cycle = 0;
            Idle = false;
        }
        public MOS6510(C64 c64, SystemRam ram, BasicRom basicRom, KernalRom kernelRom, CharacterRom charRom, ColorRam colorRam)
        {
            TheC64 = c64;
            _ram = ram;
            _basicRom = basicRom;
            _kernalRom = kernelRom;
            _characterRom = charRom;
            _colorRam = colorRam;

            a = x = y = 0;
            sp = 0xff;

            n_flag = z_flag = 0;
            v_flag = c_flag = d_flag = b_flag = i_flag = false;

            dfff_byte = 0x55;
            BALow = false;
            first_irq_cycle = first_nmi_cycle = 0;
#if DEBUG_INSTRUCTIONS
            debugLogger = new DebugLog(this, false);
#endif
        }
        UInt32 first_ba_cycle;		                // Cycle when BA first went low

        // END FRODO SC section

        #endregion




        #region Public methods

        public MOS6569(C64 c64, C64Display disp, MOS6510 CPU, SystemRam ram, CharacterRom characterRom, ColorRam colorRam)
        {
            _c64 = c64;
            _display = disp;
            _cpu = CPU;
            _ram = ram;
            _characterRom = characterRom;
            _colorRam = colorRam;

            int i;

            matrix_base = 0;
            char_base = 0;
            bitmap_base = 0;

            // Allocate GC Handles, to pin buffers
           // AllocateHandles();

            // Get bitmap info
            //unsafe
            //{
            //    chunky_ptr = chunky_line_start = _display.BitmapBase;
            //}

            _chunkyLineStartIndex = 0;
            _chunkyIndex = 0;



            xmod = disp.BitmapXMod;

            // Initialize VIC registers
            mx8 = 0;
            ctrl1 = ctrl2 = 0;
            lpx = lpy = 0;
            me = mxe = mye = mdp = mmc = 0;
            vbase = irq_flag = irq_mask = 0;
            clx_spr = clx_bgr = 0;
            cia_vabase = 0;
            ec = b0c = b1c = b2c = b3c = mm0 = mm1 = 0;

            // already 0 for .NET
            //for (i = 0; i < 8; i++) mx[i] = my[i] = sc[i] = 0;

            // Initialize other variables
            raster_y = unchecked((UInt32)(TOTAL_RASTERS - 1));
            rc = 7;
            irq_raster = vc = vc_base = x_scroll = y_scroll = 0;
            dy_start = ROW24_YSTART;
            dy_stop = ROW24_YSTOP;
            ml_index = 0;

            cycle = 1;
            display_idx = 0;
            display_state = false;
            border_on = ud_border_on = vblanking = false;
            lp_triggered = draw_this_line = false;

            spr_dma_on = spr_disp_on = 0;
            for (i = 0; i < 8; i++)
            {
                mc[i] = 63;
                spr_ptr[i] = 0;
            }

            frame_skipped = false;
            skip_counter = 1;

            // Preset colors
            disp.InitColors(colors);

            // default to black
            ec_color = b0c_color = b1c_color = b2c_color = b3c_color = mm0_color = mm1_color = colors[0];
            for (i = 0; i < spr_color.Length; i++) spr_color[i] = colors[0];

        }