static void rep(int flagval) {
        /* Handles rep- and repnz- prefixes. flagval is the value of ZF for the
         loop  to continue for CMPS and SCAS instructions. */

        /*unsigned*/ int next = FETCHOP();
        /*unsigned*/
        int count = I.regs.w[CW];

        switch (next) {
            /*TODO*///    	case 0x26:  /* ES: */
    /*TODO*///			I.seg_prefix=TRUE;
    /*TODO*///			I.prefix_base=I.base[ES];
    /*TODO*///			nec_ICount-=2;
    /*TODO*///			rep(flagval);
    /*TODO*///			break;
            case 0x2e:  /* CS: */

                I.seg_prefix = 1;
                I.prefix_base = I.base[CS];
                nec_ICount[0] -= 2;
                if (neclog != null) {
                    fprintf(neclog, "i_rep_0x2e :PC:%d,I.ip:%d,AW:%d,CW:%d,DW:%d,BW:%d,SP:%d,BP:%d,IX:%d,IY:%d,b1:%d,b2:%d,b3:%d,b4:%d,s1:%d,s2:%d,s3:%d,s4:%d,A:%d,O:%d,S:%d,Z:%d,C:%d,P:%d,T:%d,I:%d,D:%d,M:%d,v:%d,irq:%d,ns:%d,is:%d,pb:%d,pre:%d,EA:%d\n", cpu_get_pc(), I.ip, I.regs.w[AW], I.regs.w[CW], I.regs.w[DW], I.regs.w[BW], I.regs.w[SP], I.regs.w[BP], I.regs.w[IX], I.regs.w[IY], I.base[0], I.base[1], I.base[2], I.base[3], I.sregs[0], I.sregs[1], I.sregs[2], I.sregs[3], I.AuxVal, I.OverVal, I.SignVal, I.ZeroVal, I.CarryVal, I.ParityVal, I.TF, I.IF, I.DF, I.MF, I.int_vector, I.pending_irq, I.nmi_state, I.irq_state, I.prefix_base, I.seg_prefix, EA);
                }
                rep(flagval);
                break;
            /*TODO*///    case 0x36:  /* SS: */
    /*TODO*///        I.seg_prefix=TRUE;
    /*TODO*///	I.prefix_base=I.base[SS];
    /*TODO*///	nec_ICount-=2;
    /*TODO*///	rep(flagval);
    /*TODO*///	break;
    /*TODO*///    case 0x3e:  /* DS: */
    /*TODO*///        I.seg_prefix=TRUE;
    /*TODO*///	I.prefix_base=I.base[DS];
    /*TODO*///	nec_ICount-=2;
    /*TODO*///	rep(flagval);
    /*TODO*///	break;
    /*TODO*///    case 0x6c:  /* REP INSB */
    /*TODO*///	nec_ICount-=9-count;
    /*TODO*///	for (; count > 0; count--)
    /*TODO*///        	i_insb();
    /*TODO*///	I.regs.w[CW]=count;
    /*TODO*///	break;
    /*TODO*///    case 0x6d:  /* REP INSW */
    /*TODO*///	nec_ICount-=9-count;
    /*TODO*///	for (; count > 0; count--)
    /*TODO*///        	i_insw();
    /*TODO*///	I.regs.w[CW]=count;
    /*TODO*///	break;
    /*TODO*///    case 0x6e:  /* REP OUTSB */
    /*TODO*///	nec_ICount-=9-count;
    /*TODO*///	for (; count > 0; count--)
    /*TODO*///           i_outsb();
    /*TODO*///	I.regs.w[CW]=count;
    /*TODO*///	break;
    /*TODO*///    case 0x6f:  /* REP OUTSW */
    /*TODO*///	nec_ICount-=9-count;
    /*TODO*///	for (; count > 0; count--)
    /*TODO*///            i_outsw();
    /*TODO*///	I.regs.w[CW]=count;
    /*TODO*///	break;
            case 0xa4:  /* REP MOVSB */

                nec_ICount[0] -= 9 - count;
                for (; count > 0; count--) {
                    i_movsb.handler();
                }
                I.regs.SetW(CW, count);
                if (neclog != null) {
                    fprintf(neclog, "i_rep_0xa4 :PC:%d,I.ip:%d,AW:%d,CW:%d,DW:%d,BW:%d,SP:%d,BP:%d,IX:%d,IY:%d,b1:%d,b2:%d,b3:%d,b4:%d,s1:%d,s2:%d,s3:%d,s4:%d,A:%d,O:%d,S:%d,Z:%d,C:%d,P:%d,T:%d,I:%d,D:%d,M:%d,v:%d,irq:%d,ns:%d,is:%d,pb:%d,pre:%d,EA:%d\n", cpu_get_pc(), I.ip, I.regs.w[AW], I.regs.w[CW], I.regs.w[DW], I.regs.w[BW], I.regs.w[SP], I.regs.w[BP], I.regs.w[IX], I.regs.w[IY], I.base[0], I.base[1], I.base[2], I.base[3], I.sregs[0], I.sregs[1], I.sregs[2], I.sregs[3], I.AuxVal, I.OverVal, I.SignVal, I.ZeroVal, I.CarryVal, I.ParityVal, I.TF, I.IF, I.DF, I.MF, I.int_vector, I.pending_irq, I.nmi_state, I.irq_state, I.prefix_base, I.seg_prefix, EA);
                }
                break;
            case 0xa5:  /* REP MOVSW */

                nec_ICount[0] -= 9 - count;
                for (; count > 0; count--) {
                    i_movsw.handler();
                }
                I.regs.SetW(CW, count);
                if (neclog != null) {
                    fprintf(neclog, "i_rep_0xa5 :PC:%d,I.ip:%d,AW:%d,CW:%d,DW:%d,BW:%d,SP:%d,BP:%d,IX:%d,IY:%d,b1:%d,b2:%d,b3:%d,b4:%d,s1:%d,s2:%d,s3:%d,s4:%d,A:%d,O:%d,S:%d,Z:%d,C:%d,P:%d,T:%d,I:%d,D:%d,M:%d,v:%d,irq:%d,ns:%d,is:%d,pb:%d,pre:%d,EA:%d\n", cpu_get_pc(), I.ip, I.regs.w[AW], I.regs.w[CW], I.regs.w[DW], I.regs.w[BW], I.regs.w[SP], I.regs.w[BP], I.regs.w[IX], I.regs.w[IY], I.base[0], I.base[1], I.base[2], I.base[3], I.sregs[0], I.sregs[1], I.sregs[2], I.sregs[3], I.AuxVal, I.OverVal, I.SignVal, I.ZeroVal, I.CarryVal, I.ParityVal, I.TF, I.IF, I.DF, I.MF, I.int_vector, I.pending_irq, I.nmi_state, I.irq_state, I.prefix_base, I.seg_prefix, EA);
                }
                break;
            case 0xa6:  /* REP(N)E CMPSB */

                nec_ICount[0] -= 9;
                for (I.ZeroVal = NOT(flagval); (ZF() == flagval) && (count > 0); count--) {
                    i_cmpsb.handler();
                }
                I.regs.SetW(CW, count);
                if (neclog != null) {
                    fprintf(neclog, "i_rep_0xa6 :PC:%d,I.ip:%d,AW:%d,CW:%d,DW:%d,BW:%d,SP:%d,BP:%d,IX:%d,IY:%d,b1:%d,b2:%d,b3:%d,b4:%d,s1:%d,s2:%d,s3:%d,s4:%d,A:%d,O:%d,S:%d,Z:%d,C:%d,P:%d,T:%d,I:%d,D:%d,M:%d,v:%d,irq:%d,ns:%d,is:%d,pb:%d,pre:%d,EA:%d\n", cpu_get_pc(), I.ip, I.regs.w[AW], I.regs.w[CW], I.regs.w[DW], I.regs.w[BW], I.regs.w[SP], I.regs.w[BP], I.regs.w[IX], I.regs.w[IY], I.base[0], I.base[1], I.base[2], I.base[3], I.sregs[0], I.sregs[1], I.sregs[2], I.sregs[3], I.AuxVal, I.OverVal, I.SignVal, I.ZeroVal, I.CarryVal, I.ParityVal, I.TF, I.IF, I.DF, I.MF, I.int_vector, I.pending_irq, I.nmi_state, I.irq_state, I.prefix_base, I.seg_prefix, EA);
                }
                break;
            /*TODO*///    case 0xa7:  /* REP(N)E CMPSW */
    /*TODO*///	nec_ICount-=9;
    /*TODO*///	for (I.ZeroVal = !flagval; (ZF == flagval) && (count > 0); count--)
    /*TODO*///		i_cmpsw();
    /*TODO*///	I.regs.w[CW]=count;
    /*TODO*///	break;
            case 0xaa:  /* REP STOSB */

                nec_ICount[0] -= 9 - count;
                for (; count > 0; count--) {
                    i_stosb.handler();
                }
                I.regs.SetW(CW, count);
                if (neclog != null) {
                    fprintf(neclog, "i_rep_0xaa :PC:%d,I.ip:%d,AW:%d,CW:%d,DW:%d,BW:%d,SP:%d,BP:%d,IX:%d,IY:%d,b1:%d,b2:%d,b3:%d,b4:%d,s1:%d,s2:%d,s3:%d,s4:%d,A:%d,O:%d,S:%d,Z:%d,C:%d,P:%d,T:%d,I:%d,D:%d,M:%d,v:%d,irq:%d,ns:%d,is:%d,pb:%d,pre:%d,EA:%d\n", cpu_get_pc(), I.ip, I.regs.w[AW], I.regs.w[CW], I.regs.w[DW], I.regs.w[BW], I.regs.w[SP], I.regs.w[BP], I.regs.w[IX], I.regs.w[IY], I.base[0], I.base[1], I.base[2], I.base[3], I.sregs[0], I.sregs[1], I.sregs[2], I.sregs[3], I.AuxVal, I.OverVal, I.SignVal, I.ZeroVal, I.CarryVal, I.ParityVal, I.TF, I.IF, I.DF, I.MF, I.int_vector, I.pending_irq, I.nmi_state, I.irq_state, I.prefix_base, I.seg_prefix, EA);
                }
                break;
            case 0xab:  /* REP STOSW */

                nec_ICount[0] -= 9 - count;
                for (; count > 0; count--) {
                    i_stosw.handler();
                }
                I.regs.SetW(CW, count);
                if (neclog != null) {
                    fprintf(neclog, "i_rep_0xab :PC:%d,I.ip:%d,AW:%d,CW:%d,DW:%d,BW:%d,SP:%d,BP:%d,IX:%d,IY:%d,b1:%d,b2:%d,b3:%d,b4:%d,s1:%d,s2:%d,s3:%d,s4:%d,A:%d,O:%d,S:%d,Z:%d,C:%d,P:%d,T:%d,I:%d,D:%d,M:%d,v:%d,irq:%d,ns:%d,is:%d,pb:%d,pre:%d,EA:%d\n", cpu_get_pc(), I.ip, I.regs.w[AW], I.regs.w[CW], I.regs.w[DW], I.regs.w[BW], I.regs.w[SP], I.regs.w[BP], I.regs.w[IX], I.regs.w[IY], I.base[0], I.base[1], I.base[2], I.base[3], I.sregs[0], I.sregs[1], I.sregs[2], I.sregs[3], I.AuxVal, I.OverVal, I.SignVal, I.ZeroVal, I.CarryVal, I.ParityVal, I.TF, I.IF, I.DF, I.MF, I.int_vector, I.pending_irq, I.nmi_state, I.irq_state, I.prefix_base, I.seg_prefix, EA);
                }
                break;
            /*TODO*///    case 0xac:  /* REP LODSB */
    /*TODO*///	nec_ICount-=9;
    /*TODO*///	for (; count > 0; count--)
    /*TODO*///		i_lodsb();
    /*TODO*///	I.regs.w[CW]=count;
    /*TODO*///	break;
    /*TODO*///    case 0xad:  /* REP LODSW */
    /*TODO*///	nec_ICount-=9;
    /*TODO*///	for (; count > 0; count--)
    /*TODO*///		i_lodsw();
    /*TODO*///	I.regs.w[CW]=count;
    /*TODO*///	break;
            case 0xae:  /* REP(N)E SCASB */

                nec_ICount[0] -= 9;
                for (I.ZeroVal = NOT(flagval); (ZF() == flagval) && (count > 0); count--) {
                    i_scasb.handler();
                }
                I.regs.SetW(CW, count);
                if (neclog != null) {
                    fprintf(neclog, "i_rep_0xae :PC:%d,I.ip:%d,AW:%d,CW:%d,DW:%d,BW:%d,SP:%d,BP:%d,IX:%d,IY:%d,b1:%d,b2:%d,b3:%d,b4:%d,s1:%d,s2:%d,s3:%d,s4:%d,A:%d,O:%d,S:%d,Z:%d,C:%d,P:%d,T:%d,I:%d,D:%d,M:%d,v:%d,irq:%d,ns:%d,is:%d,pb:%d,pre:%d,EA:%d\n", cpu_get_pc(), I.ip, I.regs.w[AW], I.regs.w[CW], I.regs.w[DW], I.regs.w[BW], I.regs.w[SP], I.regs.w[BP], I.regs.w[IX], I.regs.w[IY], I.base[0], I.base[1], I.base[2], I.base[3], I.sregs[0], I.sregs[1], I.sregs[2], I.sregs[3], I.AuxVal, I.OverVal, I.SignVal, I.ZeroVal, I.CarryVal, I.ParityVal, I.TF, I.IF, I.DF, I.MF, I.int_vector, I.pending_irq, I.nmi_state, I.irq_state, I.prefix_base, I.seg_prefix, EA);
                }
                break;
            case 0xaf:  /* REP(N)E SCASW */

                nec_ICount[0] -= 9;
                for (I.ZeroVal = NOT(flagval); (ZF() == flagval) && (count > 0); count--) {
                    i_scasw.handler();
                }
                I.regs.SetW(CW, count);
                if (neclog != null) {
                    fprintf(neclog, "i_rep_0xaf :PC:%d,I.ip:%d,AW:%d,CW:%d,DW:%d,BW:%d,SP:%d,BP:%d,IX:%d,IY:%d,b1:%d,b2:%d,b3:%d,b4:%d,s1:%d,s2:%d,s3:%d,s4:%d,A:%d,O:%d,S:%d,Z:%d,C:%d,P:%d,T:%d,I:%d,D:%d,M:%d,v:%d,irq:%d,ns:%d,is:%d,pb:%d,pre:%d,EA:%d\n", cpu_get_pc(), I.ip, I.regs.w[AW], I.regs.w[CW], I.regs.w[DW], I.regs.w[BW], I.regs.w[SP], I.regs.w[BP], I.regs.w[IX], I.regs.w[IY], I.base[0], I.base[1], I.base[2], I.base[3], I.sregs[0], I.sregs[1], I.sregs[2], I.sregs[3], I.AuxVal, I.OverVal, I.SignVal, I.ZeroVal, I.CarryVal, I.ParityVal, I.TF, I.IF, I.DF, I.MF, I.int_vector, I.pending_irq, I.nmi_state, I.irq_state, I.prefix_base, I.seg_prefix, EA);
                }
                break;
            default:
                System.out.println("(neednext) rep 0x" + Integer.toHexString(next));
            //nec_instruction[next].handler();
        }
    }