@Override
    public int execute(int cycles) {
      
    	m6502_ICount[0] = cycles;
    
    	change_pc16(m6502.pc.D);
    
    	do
    	{
    		int /*UINT8*/ op;
                m6502.ppc.SetD(m6502.pc.D);
    
    		//CALL_MAME_DEBUG;
    
    		op = RDOP();
    		/* if an irq is pending, take it now */
    		if( m6502.pending_irq!=0 && op == 0x78 )
    			take_irq();
    		m6502.insn[op].handler();
    
    		/* check if the I flag was just reset (interrupts enabled) */
    		if( m6502.after_cli!=0 )
    		{
    			if(m6502log!=null) fprintf(m6502log,"M6502#%d after_cli was >0", cpu_getactivecpu());
    			m6502.after_cli = 0;
    			if (m6502.irq_state != CLEAR_LINE)
    			{
    				if(m6502log!=null) fprintf(m6502log,": irq line is asserted: set pending IRQ\n");
    				m6502.pending_irq = 1;
    			}
    			else
    			{
    				if(m6502log!=null) fprintf(m6502log,": irq line is clear\n");
    			}
    		}
    		else
    		if( m6502.pending_irq!=0 )
    			take_irq();
    
    	} while (m6502_ICount[0] > 0);
    
    	return cycles - m6502_ICount[0];
    }