@Override
    public void reset(Object param) {
        Z80_DaisyChain[] daisy_chain = (Z80_DaisyChain[])param;
            
    	int i, p;
        
        int oldval, newval, val;
        int padd, padc, psub, psbc;
        padd = 0 * 256;
        padc = 256 * 256;
        psub = 0 * 256;
        psbc = 256 * 256;
        for (oldval = 0; oldval < 256; oldval++) 
        {
            for (newval = 0; newval < 256; newval++) 
            {
                /* add or adc w/o carry set */
                val = newval - oldval;
                if (newval != 0) {
                    if ((newval & 0x80) != 0) {
                        SZHVC_add[padd] = SF;
                    } else {
                        SZHVC_add[padd] = 0;
                    }
                } else {
                    SZHVC_add[padd] = ZF;
                }
                SZHVC_add[padd] |= (newval & (YF | XF)); /* undocumented flag bits 5+3 */
                
                 if ((newval & 0x0f) < (oldval & 0x0f)) {
                    SZHVC_add[padd] |= HF;
                }
                if (newval < oldval) {
                    SZHVC_add[padd] |= CF;
                }
                if (((val ^ oldval ^ 0x80) & (val ^ newval) & 0x80) != 0) {
                    SZHVC_add[padd] |= VF;
                }
                padd++;
                
                /* adc with carry set */
                val = newval - oldval - 1;
                if (newval != 0) {
                    if ((newval & 0x80) != 0) {
                        SZHVC_add[padc] = SF;
                    } else {
                        SZHVC_add[padc] = 0;
                    }
                } else {
                    SZHVC_add[padc] = ZF;
                }
                
                SZHVC_add[padc] |= (newval & (YF | XF)); /* undocumented flag bits 5+3 */
                if ((newval & 0x0f) <= (oldval & 0x0f)) {
                    SZHVC_add[padc] |= HF;
                }
                if (newval <= oldval) {
                    SZHVC_add[padc] |= CF;
                }
                if (((val ^ oldval ^ 0x80) & (val ^ newval) & 0x80) != 0) {
                    SZHVC_add[padc] |= VF;
                }
                padc++;
                
                /* cp, sub or sbc w/o carry set */
                val = oldval - newval;
                if (newval != 0) {
                    if ((newval & 0x80) != 0) {
                        SZHVC_sub[psub] = NF | SF;
                    } else {
                        SZHVC_sub[psub] = NF;
                    }
                } else {
                    SZHVC_sub[psub] = NF | ZF;
                }

                SZHVC_sub[psub] |= (newval & (YF | XF)); /* undocumented flag bits 5+3 */
                if ((newval & 0x0f) > (oldval & 0x0f)) {
                    SZHVC_sub[psub] |= HF;
                }
                if (newval > oldval) {
                    SZHVC_sub[psub] |= CF;
                }
                if (((val ^ oldval) & (oldval ^ newval) & 0x80) != 0) {
                    SZHVC_sub[psub] |= VF;
                }
                psub++;
 
                /* sbc with carry set */
                val = oldval - newval - 1;
                if (newval != 0) {
                    if ((newval & 0x80) != 0) {
                        SZHVC_sub[psbc] = NF | SF;
                    } else {
                        SZHVC_sub[psbc] = NF;
                    }
                } else {
                    SZHVC_sub[psbc] = NF | ZF;
                }

                SZHVC_sub[psbc] |= (newval & (YF | XF)); /* undocumented flag bits 5+3 */
                if ((newval & 0x0f) >= (oldval & 0x0f)) {
                    SZHVC_sub[psbc] |= HF;
                }
                if (newval >= oldval) {
                    SZHVC_sub[psbc] |= CF;
                }
                if (((val ^ oldval) & (oldval ^ newval) & 0x80) != 0) {
                    SZHVC_sub[psbc] |= VF;
                }
                psbc++;
            }
        }
    	for (i = 0; i < 256; i++)
    	{
            p = 0;
            if ((i & 0x01) != 0)  ++p;
            if ((i & 0x02) != 0)  ++p;
            if ((i & 0x04) != 0)  ++p;
            if ((i & 0x08) != 0)  ++p;
            if ((i & 0x10) != 0)  ++p;
            if ((i & 0x20) != 0)  ++p;
            if ((i & 0x40) != 0)  ++p;
            if ((i & 0x80) != 0)  ++p;
            
            SZ[i] = (i != 0) ? i & SF : ZF;
            SZ[i] |= (i & (YF | XF)); /* undocumented flag bits 5+3 */
            SZ_BIT[i] = (i != 0) ? i & SF : ZF | PF;
            SZ_BIT[i] |= (i & (YF | XF)); /* undocumented flag bits 5+3 */
            SZP[i] = SZ[i] | (((p & 1) != 0) ? 0 : PF);
            SZHV_inc[i] = SZ[i];
            if( i == 0x80 ) SZHV_inc[i] |= VF;
            if( (i & 0x0f) == 0x00 ) SZHV_inc[i] |= HF;
            SZHV_dec[i] = SZ[i] | NF;
            if( i == 0x7f ) SZHV_dec[i] |= VF;
            if( (i & 0x0f) == 0x0f ) SZHV_dec[i] |= HF;
        }
    	//memset(&Z80, 0, sizeof(Z80));
        Z80.PREPC.SetD(0);
        Z80.PC.SetD(0);    
        Z80.SP.SetD(0);    
        Z80.AF.SetD(0);    
        Z80.BC.SetD(0);    
        Z80.DE.SetD(0);    
        Z80.HL.SetD(0);    
        Z80.IX.SetD(0);    
        Z80.IY.SetD(0);    
        Z80.AF2.SetD(0);   
        Z80.BC2.SetD(0);   
        Z80.DE2.SetD(0);    
        Z80.HL2.SetD(0); 
        Z80.R=Z80.R2=Z80.IFF1=Z80.IFF2=Z80.HALT=Z80.IM=Z80.I=0;
        Z80.irq_max=0;         
        Z80.request_irq = -1;
        Z80.service_irq = -1;	
        Z80.nmi_state = CLEAR_LINE;	
        Z80.irq_state = CLEAR_LINE;	
        Z80.int_state = new int[Z80_MAXDAISY];
        Z80.irq = new Z80_DaisyChain[Z80_MAXDAISY];
        Z80.irq_callback=null;
        Z80.extra_cycles=0;
        Z80.IX.SetD(0xFFFF);//_IX = _IY = 0xffff;
        Z80.IY.SetD(0xFFFF); /* IX and IY are FFFF after a reset! */
        Z80.AF.SetL(ZF);//	_F = ZF;	/* Zero flag is set */

        if( daisy_chain!=null )
    	{
            throw new UnsupportedOperationException("Daisy Chain Not supported yet.");
    /*TODO*///		while( daisy_chain->irq_param != -1 && Z80.irq_max < Z80_MAXDAISY )
    /*TODO*///		{
    /*TODO*///            /* set callbackhandler after reti */
    /*TODO*///			Z80.irq[Z80.irq_max] = *daisy_chain;
    /*TODO*///            /* device reset */
    /*TODO*///			if( Z80.irq[Z80.irq_max].reset )
    /*TODO*///				Z80.irq[Z80.irq_max].reset(Z80.irq[Z80.irq_max].irq_param);
    /*TODO*///			Z80.irq_max++;
    /*TODO*///            daisy_chain++;
    /*TODO*///        }
        }
        
      change_pc(Z80.PC.D);           
    }
    
    /*TODO*///void z80_exit(void)
    /*TODO*///{
    /*TODO*///#if BIG_FLAGS_ARRAY
    /*TODO*///	if (SZHVC_add) free(SZHVC_add);
    /*TODO*///	SZHVC_add = NULL;
    /*TODO*///	if (SZHVC_sub) free(SZHVC_sub);
    /*TODO*///	SZHVC_sub = NULL;
    /*TODO*///#endif
    /*TODO*///}