int main()
{

    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);

#define gc getchar()

    while (scanf("%d %d", &n, &b)  != EOF)
    {

        gc;
        RST(p, l, r);
        RST(ky, sz);
        root = total = ans = d = 0;
        Insert(INF), ky[0] = INF;
        int t;
        DO(n)
        {

            char cmd = gc;
            gc; //scanf(" %c", &cmd);
            RD(t);
            switch (cmd)
            {
            case 'I':
                Insert(t);
                break;
            case 'A':
                d -= t;
                break;
            case 'S':
                d += t, Splay(Search());
                ans += sz[l[root]], sz[root] -= sz[l[root]], l[root] = 0;
                break;
            default:
                if (t >= sz[root]) puts("-1");
                else printf("%d\n", ky[Select(sz[root] - t)] + b - d);
            }
        }
        printf("%d\n", ans);
    }
}
Пример #2
0
int
main(int argc, char **argv)
{
  struct layer *head,*tcp;
  struct TCPSocket ts;
  struct MAC imac,dmac;
  uint32_t ip,dip,gip;
  uint16_t eport;
  int n;

  if(argc < 6)
	usage(*argv);
  if(if_menu(&imac) < 0)
	exit(1);
  
  str_to_ip(argv[1],&ip);
  str_to_ip(argv[2],&dip);
  str_to_ip(argv[5],&gip);

  if( ARPRequest(&imac,&dmac,ip,gip,5) < 0 ){
	fprintf(stderr,"error: no route to host.\n");
	exit(1);
  }
  ARPReply(&imac,ip,&dmac,gip);
  eport = atoi(argv[4]);	
  createSocket(&ts,&imac,&dmac,ip,dip,atoi(argv[3]),atoi(argv[3]));
  filterDatalink("tcp");
  head = NULL;
  while(!kbhit()){
	if(ts.hostport++ < eport)
	      SYN(&ts);
	if( ( head = recvlayers(&n) ) == NULL)
		continue;		
	if( (tcp = findlayer(head,LT_TCP) ) != NULL ){ 
		struct tcphdr *t;				
		t = (xtcp)tcp->proto;
		if( ( ( t->th_flags & TH_SYN ) == TH_SYN)  && ( ( t->th_flags & TH_ACK ) == TH_ACK) ){
			printf("recv: SYN-ACK from port %d\n",ntohs(t->th_sport));
			printlayers(tcp);
			RST(&ts);			
		}
	}
	rmlayers(head);
  }
  closeDatalink();
  exit(0);
}
Пример #3
0
int
main(int argc, char **argv)
{

	struct layer *proto;
	struct MAC localmac,gwmac,cli_mac;
	uint32_t real_ip,spoof_ip,gw_ip,client_ip,server_ip,dly,
		dly_serv;
	struct TCPSocket ts;
	struct datalink icmp_dl,dl;
	uint16_t start_port,end_port,server_port,
		ip_id_a,ip_id_b,ip_id_d;
	unsigned long i;
	unsigned short guess_port,min_delta=-1;
	unsigned long guess_serv_seq,serv_seq=0;
	uint32_t start_guess,end_guess;
	int guess_inc;
	char icmp_filter[256];
	if( argc < 9 )
		usage(*argv);
	if( argc >=  10){
		errno = 0;
		serv_seq = strtoul(argv[9],NULL,10);
		if(errno)
			serv_seq =0;
	}

	srand(time(NULL));
	memset(&dl,0,sizeof(dl));
	if( if_openbyname(&dl,argv[1]) < 0 ){
		fprintf(stderr,"open_link_byname failed\n");
		return 1;
	}

	memset(&icmp_dl,0,sizeof(dl));
	if( if_openbyname(&icmp_dl,argv[1]) < 0 ){
		fprintf(stderr,"open_link_byname failed\n");
		return 1;
	}
	guess_port = start_port;
	str_to_ip(argv[2],&real_ip);	
	str_to_ip(argv[3],&gw_ip);	
	str_to_ip(argv[4],&spoof_ip);	
	str_to_ip(argv[5],&server_ip);	
	memcpy(&localmac.mac,dl.dl_mac,6);

	snprintf(icmp_filter,sizeof(icmp_filter),"icmp and icmp[0] = 0 and "
		"((src %s and dst %s) or (src %s and dst %s))",
		argv[4],argv[2],argv[5],argv[2]);
	filterDatalink(&icmp_dl,icmp_filter);
	if( dl.dl_pcap->linktype == DLT_EN10MB ){
		if( ARPRequest(&dl,&localmac,&gwmac,real_ip,server_ip,5) < 0 ){
			fprintf(stderr,"lan gateway did not reply arp\n");
		exit(1);
		}



		if( ARPRequest(&dl,&localmac,&cli_mac,real_ip,spoof_ip,5) < 0 ){
			fprintf(stderr,"lan gateway did not reply arp\n");
		exit(1);
		}

	}
	start_port = atoi(argv[6]);
	end_port = atoi(argv[7]);
	server_port = atoi(argv[8]);
	createSocket(&ts,&localmac,&gwmac,spoof_ip,
		server_ip,start_port,server_port);
	ts.rcvwin = 0;
	
	ip_id_a = ip_id_b = ip_id_d = 0;
	echo_get_id(&icmp_dl,&localmac,&gwmac,real_ip,server_ip,
		&dly,&ip_id_a);
	printf("delay to server= %lu\n",dly_serv);		

	echo_get_id(&icmp_dl,&localmac,&cli_mac,real_ip,spoof_ip,
		&dly,&ip_id_a);
	printf("delay = %lu\n",dly);		
	for( i = start_port; i<= end_port; i++ ){

		SYN(&ts,&dl);
		
		usleep((dly+dly_serv));
                echo_get_id(&icmp_dl,&localmac,&cli_mac,real_ip,spoof_ip,
                &dly,&ip_id_b);

		ip_id_d = ip_id_b - ip_id_a;
		ip_id_a = ip_id_b;
		if(ip_id_d < min_delta){
			min_delta = ip_id_d;
			guess_port = i;
		}

		printf("for port %d ip_id delta = %x\n",ts.port,ip_id_d);			if(ip_id_d == 0 ){
			printf( " the client port is: %d\n",ts.port);	exit(0);
		}

		ts.port++;
		ts.seq++;
	}
	printf("guessed port is %d\n",guess_port);
	ts.ip = server_ip;
	ts.port = server_port;
	ts.hostip = spoof_ip;
	ts.hostport = guess_port;

	printf("finding serv.seq using 16k window\n");
	min_delta = -1;
if(serv_seq != 0 ){
	ts.seq = serv_seq+65536;
	ts.gatewaymac = cli_mac;

	echo_get_id(&icmp_dl,&localmac,&gwmac,real_ip,spoof_ip,
		
		&dly,&ip_id_a);


	ts.ack = 0;
	ACK(&ts,&dl);
 	//ts.ack = 2<<30;
	//ACK(&ts,&dl);
		
        echo_get_id(&icmp_dl,&localmac,&gwmac,real_ip,spoof_ip,
                &dly,&ip_id_b);

	ip_id_d = ip_id_b - ip_id_a;

	printf("for seq %lu delta = %d\n",serv_seq,ip_id_d);



	ts.seq = serv_seq;

	echo_get_id(&icmp_dl,&localmac,&gwmac,real_ip,spoof_ip,
		
		&dly,&ip_id_a);


	ts.ack = 0;
	ACK(&ts,&dl);
 	//ts.ack = 2<<30;
	//ACK(&ts,&dl);
		
        echo_get_id(&icmp_dl,&localmac,&gwmac,real_ip,spoof_ip,
                &dly,&ip_id_b);

	ip_id_d = ip_id_b - ip_id_a;

	printf("for seq %lu delta = %d\n",serv_seq+65536,ip_id_d);
	closeDatalink(&dl);
	closeDatalink(&icmp_dl);
	exit(0);
}
	ip_id_a = ip_id_b = ip_id_d = 0;

	ts.gatewaymac = cli_mac;
	echo_get_id(&icmp_dl,&localmac,&gwmac,real_ip,spoof_ip,
		
		&dly,&ip_id_a);
	start_guess = 0xffffffff;
	end_guess = 16385;
	guess_inc = -16384;
	for( i = start_guess; abs(end_guess-i)>=0 ; i +=guess_inc ){


		ts.ack = 0;
		ts.seq = i;
		ACK(&ts,&dl);
	 	//ts.ack = 2<<30;
		//ts.seq=i;
		ACK(&ts,&dl);
		
                echo_get_id(&icmp_dl,&localmac,&gwmac,real_ip,spoof_ip,
                &dly,&ip_id_b);

		ip_id_d = ip_id_b - ip_id_a;
		ip_id_a = ip_id_b;
		if(ip_id_d < min_delta){
			min_delta = ip_id_d;
			guess_serv_seq = i;
			if(min_delta == 1)
			{

			printf("for seq %lu ip_id delta = %x\n",ts.seq,ip_id_d);		

			RST(&ts,&dl);	
			exit(0);
			}

		}

		printf("for seq %lu ip_id delta = %x\n",ts.seq,ip_id_d);		

	}

	printf("guessed sequence = %lu\n",guess_serv_seq);

	ts.seq = guess_serv_seq;
	
	RST(&ts,&dl);	
	closeDatalink(&dl);
	closeDatalink(&icmp_dl);
	return 0;
}
Пример #4
0
int main()
{
    Point r1[3] = { Point(20,15), Point(25,5), Point(30,15) };
    //Point s1[3] = { Point(40,15), Point(40,5) };
    Point t1[3] = { Point(20,10), Point(30,10), Point(25, 15) };

    std::list<std::pair<Point*,Point*> > polylines;
    polylines.push_back(std::make_pair(r1+0, r1+3));
    //polylines.push_back(std::make_pair(s1+0, s1+2));
    polylines.push_back(std::make_pair(t1+0, t1+3));


    Nef_polyhedron RST(polylines.begin(), polylines.end(), Nef_polyhedron::POLYLINES);

    std::cout << RST << std::endl;

    Explorer explorer = RST.explorer();


    // The first face is the infinite one. It has no outer face cycle but only holes

    Face_const_iterator fit = explorer.faces_begin();
    std::cout << "explorer.mark(explorer.faces_begin()) "  << ((explorer.mark(fit))? "is part of polygon" :  "is not part of polygon") << std::endl;
    for(Hole_const_iterator hit = explorer.holes_begin(fit); hit != explorer.holes_end(fit); hit++) {
        std::cout << " A hole" << std::endl;
        Halfedge_around_face_const_circulator hafc(hit), done(hit);
        do {
            Vertex_const_handle vh = explorer.target(hafc);
            std::cout << explorer.point(vh) << " [" << explorer.point(vh).x().exact() << " | " << explorer.point(vh).y().exact() << "],  " ;
            hafc++;
        } while(hafc != done);
        std::cout << std::endl;
    }


    // The other faces have outer face cycles, and they may have holes
    for( fit++;
            fit != explorer.faces_end();
            fit++) {

        Halfedge_around_face_const_circulator hafc = explorer.face_cycle(fit), done(hafc);
        std::cout << "face: " << ((explorer.mark(fit))? "is part of polygon" :  "is not part of polygon") << std::endl;
        do {
            Vertex_const_handle vh = explorer.target(hafc);
            std::cout << explorer.point(vh) << " [" << explorer.point(vh).x().exact() << " | " << explorer.point(vh).y().exact() << "],  " ;
            hafc++;
        } while(hafc != done);
        std::cout << std::endl;

        for(Hole_const_iterator hit = explorer.holes_begin(fit); hit != explorer.holes_end(fit); hit++) {
            std::cout << " A hole" << std::endl;
            Halfedge_around_face_const_circulator hafc(hit), done(hit);
            do {
                Vertex_const_handle vh = explorer.target(hafc);
                std::cout << explorer.point(vh) << " [" << explorer.point(vh).x().exact() << " | " << explorer.point(vh).y().exact() << "],  " ;
                hafc++;
            } while(hafc != done);
            std::cout << std::endl;
        }

    }


    return 0;
}
Пример #5
0
int cpu::cpu_emulate(int ciclos){
	UINT8 op,b,cbop;
	UINT32 i;
	UINT32 clen = 10;
	UINT16 w;
	static cpuReg acc;

	i = ciclos;
	
	
//next:
	while((!CPU->IME) && i > 0){
	mt.lock();
	op = FETCH;
	ciclos = cycles_table[op];

	switch(op)
	{
	case 0x00: /* NOP */
	case 0x40: /* LD B,B */
	case 0x49: /* LD C,C */
	case 0x52: /* LD D,D */
	case 0x5B: /* LD E,E */
	case 0x64: /* LD H,H */
	case 0x6D: /* LD L,L */
	case 0x7F: /* LD A,A */
		break;
	case 0x41: /* LD B,C */
		B = C; break;
	case 0x42: /* LD B,D */
		B = D; break;
	case 0x43: /* LD B,E */
		B = E; break;
	case 0x44: /* LD B,H */
		B = H; break;
	case 0x45: /* LD B,L */
		B = L; break;
	case 0x46: /* LD B,(HL) */
		B = memoria::readByte(xHL); break;
	case 0x47: /* LD B,A */
		B = A; break;

	case 0x48: /* LD C,B */
		C = B; break;
	case 0x4A: /* LD C,D */
		C = D; break;
	case 0x4B: /* LD C,E */
		C = E; break;
	case 0x4C: /* LD C,H */
		C = H; break;
	case 0x4D: /* LD C,L */
		C = L; break;
	case 0x4E: /* LD C,(HL) */
		C = memoria::readByte(xHL); break;
	case 0x4F: /* LD C,A */
		C = A; break;


	case 0x50: /* LD D,B */
		D = B; break;
	case 0x51: /* LD D,C */
		D = C; break;
	case 0x53: /* LD D,E */
		D = E; break;
	case 0x54: /* LD D,H */
		D = H; break;
	case 0x55: /* LD D,L */
		D = L; break;
	case 0x56: /* LD D,(HL) */
		D = memoria::readByte(xHL); break;
	case 0x57: /* LD D,A */
		D = A; break;


	case 0x58: /* LD E,B */
		E = B; break;
	case 0x59: /* LD E,C */
		E = C; break;
	case 0x5A: /* LD E,D */
		E = D; break;
	case 0x5C: /* LD E,H */
		E = H; break;
	case 0x5D: /* LD E,L */
		E = L; break;
	case 0x5E: /* LD E,(HL) */
		E = memoria::readByte(xHL); break;
	case 0x5F: /* LD E,A */
		E = A; break;

	case 0x60: /* LD H,B */
		H = B; break;
	case 0x61: /* LD H,C */
		H = C; break;
	case 0x62: /* LD H,D */
		H = D; break;
	case 0x63: /* LD H,E */
		H = E; break;
	case 0x65: /* LD H,L */
		H = L; break;
	case 0x66: /* LD H,(HL) */
		H = memoria::readByte(xHL); break;
	case 0x67: /* LD H,A */
		H = A; break;

	case 0x68: /* LD L,B */
		L = B; break;
	case 0x69: /* LD L,C */
		L = C; break;
	case 0x6A: /* LD L,D */
		L = D; break;
	case 0x6B: /* LD L,E */
		L = E; break;
	case 0x6C: /* LD L,H */
		L = H; break;
	case 0x6E: /* LD L,(HL) */
		L = memoria::readByte(xHL); break;
	case 0x6F: /* LD L,A */
		L = A; break;

	case 0x70: /* LD (HL),B */
		b = B; goto __LD_HL;
	case 0x71: /* LD (HL),C */
		b = C; goto __LD_HL;
	case 0x72: /* LD (HL),D */
		b = D; goto __LD_HL;
	case 0x73: /* LD (HL),E */
		b = E; goto __LD_HL;
	case 0x74: /* LD (HL),H */
		b = H; goto __LD_HL;
	case 0x75: /* LD (HL),L */
		b = L; goto __LD_HL;
	case 0x77: /* LD (HL),A */
		b = A;
__LD_HL:
		memoria::writeByte(xHL,b);
		break;

	case 0x78: /* LD A,B */
		A = B; break;
	case 0x79: /* LD A,C */
		A = C; break;
	case 0x7A: /* LD A,D */
		A = D; break;
	case 0x7B: /* LD A,E */
		A = E; break;
	case 0x7C: /* LD A,H */
		A = H; break;
	case 0x7D: /* LD A,L */
		A = L; break;
	case 0x7E: /* LD A,(HL) */
		A = memoria::readByte(xHL); break;

	case 0x01: /* LD BC,imm */
		CPU->BC.w = memoria::readWord(xPC); CPU->PC += 2; break;
	case 0x11: /* LD DE,imm */
		CPU->DE.w = memoria::readWord(xPC); CPU->PC += 2; break;
	case 0x21: /* LD HL,imm */
		CPU->HL.w = memoria::readWord(xPC); CPU->PC += 2; break;
	case 0x31: /* LD SP,imm */
		CPU->SP = memoria::readWord(xPC); CPU->PC += 2; break;

	case 0x02: /* LD (BC),A */
		memoria::writeByte(CPU->BC.w, A); break;
	case 0x0A: /* LD A,(BC) */
		A = memoria::readByte(CPU->BC.w); break;
	case 0x12: /* LD (DE),A */
		memoria::writeByte(CPU->BC.w, A); break;
	case 0x1A: /* LD A,(DE) */
		A = memoria::readByte(CPU->DE.w); break;

	case 0x22: /* LDI (HL),A */
		memoria::writeByte(xHL, A); CPU->HL.w++; break;
	case 0x2A: /* LDI A,(HL) */
		A = memoria::readByte(xHL); CPU->HL.w++; break;
	case 0x32: /* LDD (HL),A */
		memoria::writeByte(xHL, A); CPU->HL.w--; break;
	case 0x3A: /* LDD A,(HL) */
		A = memoria::readByte(xHL); CPU->HL.w--; break;

	case 0x06: /* LD B,imm */
		B = FETCH; break;
	case 0x0E: /* LD C,imm */
		C = FETCH; break;
	case 0x16: /* LD D,imm */
		D = FETCH; break;
	case 0x1E: /* LD E,imm */
		E = FETCH; break;
	case 0x26: /* LD H,imm */
		H = FETCH; break;
	case 0x2E: /* LD L,imm */
		L = FETCH; break;
	case 0x36: /* LD (HL),imm */
		b = FETCH; memoria::writeByte(xHL, b); break;
	case 0x3E: /* LD A,imm */
		A = FETCH; break;


	case 0x08: /* LD (imm),CPU->SP */
		memoria::writeWord(memoria::readWord(xPC), CPU->SP); CPU->PC += 2; break;
	case 0xEA: /* LD (imm),A */
		memoria::writeByte(memoria::readWord(xPC), A); CPU->PC += 2; break;

	case 0xF8: /* LD HL,CPU->SP+imm */
		b = FETCH; LDHLSP(b); break;
	case 0xF9: /* LD CPU->SP,HL */
		CPU->SP = CPU->HL.w; break;
	case 0xFA: /* LD A,(imm) */
		A = memoria::readByte(memoria::readWord(xPC)); CPU->PC += 2; break;

		ALU_CASES(0x80, 0xC6, ADD, __ADD)
			ALU_CASES(0x88, 0xCE, ADC, __ADC)
			ALU_CASES(0x90, 0xD6, SUB, __SUB)
			ALU_CASES(0x98, 0xDE, SBC, __SBC)
			ALU_CASES(0xA0, 0xE6, AND, __AND)
			ALU_CASES(0xA8, 0xEE, XOR, __XOR)
			ALU_CASES(0xB0, 0xF6, OR, __OR)
			ALU_CASES(0xB8, 0xFE, CP, __CP)

	case 0x09: /* ADD HL,BC */
		w = CPU->BC.w; goto __ADDW;
	case 0x19: /* ADD HL,DE */
		w = CPU->DE.w; goto __ADDW;
	case 0x39: /* ADD HL,CPU->SP */
		w = CPU->SP; goto __ADDW;
	case 0x29: /* ADD HL,HL */
		w = CPU->HL.w;
__ADDW:
		ADDW(w);
		break;

	case 0x04: /* INC B */
		INC(B); break;
	case 0x0C: /* INC C */
		INC(C); break;
	case 0x14: /* INC D */
		INC(D); break;
	case 0x1C: /* INC E */
		INC(E); break;
	case 0x24: /* INC H */
		INC(H); break;
	case 0x2C: /* INC L */
		INC(L); break;
	case 0x34: /* INC (HL) */
		b = memoria::readByte(xHL);
		INC(b);
		memoria::writeByte(xHL, b);
		break;
	case 0x3C: /* INC A */
		INC(A); break;

	case 0x03: /* INC BC */
		INCW(CPU->BC.w); break;
	case 0x13: /* INC DE */
		INCW(CPU->DE.w); break;
	case 0x23: /* INC HL */
		INCW(CPU->HL.w); break;
	case 0x33: /* INC CPU->SP */
		INCW(CPU->SP); break;

	case 0x05: /* DEC B */
		DEC(B); break;
	case 0x0D: /* DEC C */
		DEC(C); break;
	case 0x15: /* DEC D */
		DEC(D); break;
	case 0x1D: /* DEC E */
		DEC(E); break;
	case 0x25: /* DEC H */
		DEC(H); break;
	case 0x2D: /* DEC L */
		DEC(L); break;
	case 0x35: /* DEC (HL) */
		b = memoria::readByte(xHL);
		DEC(b);
		memoria::writeByte(xHL, b);
		break;
	case 0x3D: /* DEC A */
		DEC(A); break;


	case 0x0B: /* DEC BC */
		DECW(CPU->BC.w); break;
	case 0x1B: /* DEC DE */
		DECW(CPU->DE.w); break;
	case 0x2B: /* DEC HL */
		DECW(CPU->HL.w); break;
	case 0x3B: /* DEC CPU->SP */
		DECW(CPU->SP); break;

	case 0x07: /* RLCA */
		RLCA(A); break;
	case 0x0F: /* RRCA */
		RRCA(A); break;
	case 0x17: /* RLA */
		RLA(A); break;
	case 0x1F: /* RRA */
		RRA(A); break;

	case 0x27: /* DAA */
		DAA; break;
	case 0x2F: /* CPL */
		CPL(A); break;

	case 0x18: /* JR */
__JR:
		JR; break;
	case 0x20: /* JR NZ */
		if (!(F&FZ)) goto __JR; NOJR; break;
	case 0x28: /* JR Z */
		if (F&FZ) goto __JR; NOJR; break;
	case 0x30: /* JR NC */
		if (!(F&FC)) goto __JR; NOJR; break;
	case 0x38: /* JR C */
		if (F&FC) goto __JR; NOJR; break;

	case 0xC3: /* JP */
__JP:
		JP; break;
	case 0xC2: /* JP NZ */
		if (!(F&FZ)) goto __JP; NOJP; break;
	case 0xCA: /* JP Z */
		if (F&FZ) goto __JP; NOJP; break;
	case 0xD2: /* JP NC */
		if (!(F&FC)) goto __JP; NOJP; break;
	case 0xDA: /* JP C */
		if (F&FC) goto __JP; NOJP; break;
	case 0xE9: /* JP HL */
		CPU->PC = CPU->HL.w; break;

	case 0xC9: /* RET */
__RET:
		RET; break;
	case 0xC0: /* RET NZ */
		if (!(F&FZ)) goto __RET; NORET; break;
	case 0xC8: /* RET Z */
		if (F&FZ) goto __RET; NORET; break;
	case 0xD0: /* RET NC */
		if (!(F&FC)) goto __RET; NORET; break;
	case 0xD8: /* RET C */
		if (F&FC) goto __RET; NORET; break;
	case 0xD9: /* RETI */
		CPU->IME = CPU->IMA = 1; goto __RET;

	case 0xCD: /* CALL */
__CALL:
		CALL; break;
	case 0xC4: /* CALL NZ */
		if (!(F&FZ)) goto __CALL; NOCALL; break;
	case 0xCC: /* CALL Z */
		if (F&FZ) goto __CALL; NOCALL; break;
	case 0xD4: /* CALL NC */
		if (!(F&FC)) goto __CALL; NOCALL; break;
	case 0xDC: /* CALL C */
		if (F&FC) goto __CALL; NOCALL; break;

	case 0xC7: /* RST 0 */
		b = 0x00; goto __RST;
	case 0xCF: /* RST 8 */
		b = 0x08; goto __RST;
	case 0xD7: /* RST 10 */
		b = 0x10; goto __RST;
	case 0xDF: /* RST 18 */
		b = 0x18; goto __RST;
	case 0xE7: /* RST 20 */
		b = 0x20; goto __RST;
	case 0xEF: /* RST 28 */
		b = 0x28; goto __RST;
	case 0xF7: /* RST 30 */
		b = 0x30; goto __RST;
	case 0xFF: /* RST 38 */
		b = 0x38;
__RST:
		RST(b); break;

	case 0xC1: /* POP BC */
		POP(CPU->BC.w); break;
	case 0xC5: /* PUSH BC */
		PUSH(CPU->BC.w); break;
	case 0xD1: /* POP DE */
		POP(CPU->DE.w); break;
	case 0xD5: /* PUSH DE */
		PUSH(CPU->DE.w); break;
	case 0xE1: /* POP HL */
		POP(CPU->HL.w); break;
	case 0xE5: /* PUSH HL */
		PUSH(CPU->HL.w); break;
	case 0xF1: /* POP AF */
		POP(CPU->AF.w); break;
	case 0xF5: /* PUSH AF */
		PUSH(CPU->AF.w); break;

	case 0xE8: /* ADD CPU->SP,imm */
		b = FETCH; ADDSP(b); break;

	case 0xF3: /* DI */
		DI; break;
	case 0xFB: /* EI */
		EI; break;

	case 0x37: /* SCF */
		SCF; break;
	case 0x3F: /* CCF */
		CCF; break;

	case 0x10: /* STOP */
		break; //to do//

	case 0x76: /* HALT */
		CPU->halt = 1;
		break;

	case 0xCB: /* CB prefix */
		cbop = FETCH;
		clen = cb_cycles_table[cbop];
		switch (cbop)
		{
			CB_REG_CASES(B, 0);
			CB_REG_CASES(C, 1);
			CB_REG_CASES(D, 2);
			CB_REG_CASES(E, 3);
			CB_REG_CASES(H, 4);
			CB_REG_CASES(L, 5);
			CB_REG_CASES(A, 7);
		default:
			b = memoria::readByte(xHL);
			switch(cbop)
			{
				CB_REG_CASES(b, 6);
			}
			if ((cbop & 0xC0) != 0x40) /* exclude BIT */
				memoria::writeByte(xHL, b);
			break;
		}
		break;
	default:
		printf("erro"); break;
	}

	clen <<= 1;
	i -= clen;
	emit onEndProcess((UINT32)op);
	mt.unlock();
	//msleep(600);
	}
	//if(i >0) goto next;
	wt.wait(&mt);
	return ciclos-i;
}
Пример #6
0
void input(FILE *fd, void (*cb)(struct message *), struct message *p)
{
	int c;

#define ST(X) do { p->status = (X); } while(0)
#define MK(X) do { p->X = p->p; } while(0)
#define RST() do { \
	ST(AT_BOM); \
	p->p = p->buffer; \
	p->sz = p->argc = 0; \
	p->org = p->cmd = NULL; \
} while (0)
#define ADDCH(X) do { \
	*p->p++ = X; p->sz++; \
	if (p->sz >= (sizeof p->buffer)-1) \
		RST(); \
} while (0)
#define ADDARG(s) do { \
	assert(p->argc < MAX_ARGS); \
	p->argv[p->argc] = s; \
	if (s) p->argc++; \
} while (0)

	RST();
	while ((c = fgetc(fd)) != EOF) {
		switch (p->status) {
		case AT_BOM:
			switch (c) {
			case ':': ST(IN_ORG); MK(org); break;
			case ' ': break; /* ignored */
			case '\r': ST(IN_EOL); break;
			case '\n': RST(); break;
			default: ST(IN_CMD); MK(cmd); ADDCH(c); break;
			} break;
		case IN_ORG:
			switch(c) {
			case ' ': ST(IN_SPC0); ADDCH(0); break;
			case '\r': ST(IN_EOL); ADDCH(0); break;
			case '\n': RST(); break;
			case ':': /* NO BREAK HERE, valid char */
			default: ADDCH(c); break;
			} break;
		case IN_SPC0:
			switch(c) {
			case ' ': break; /* ignore extra */
			case '\r': ST(IN_EOL); break;
			case '\n': RST(); break;
			default: ST(IN_CMD); MK(cmd); ADDCH(c); break;
			} break;
		case IN_CMD:
			switch(c) {
			case ' ': ST(IN_SPC1); ADDCH(0); break;
			case '\r': ST(IN_EOL); ADDCH(0); break;
			case '\n': ADDARG(NULL); cb(p); RST(); break;
			case ':': /* NO BREAK HERE, valid char */
			default: ADDCH(c); break;
			} break;
		case IN_SPC1:
			switch(c) {
			case ' ': break; /* ignore */
			case '\r': ST(IN_EOL); break;
			case '\n': ADDARG(NULL); cb(p); RST(); break;
			case ':': ST(IN_ARGN); ADDARG(p->p); break;
			default: ST(IN_ARG); ADDARG(p->p); ADDCH(c); break;
			} break;
		case IN_ARG:
			switch (c) {
			case ' ': ST(IN_SPC1); ADDCH(0); break;
			case '\r': ST(IN_EOL); ADDCH(0); break;
			case '\n': ADDARG(NULL); cb(p); RST(); break;
			case ':':
			default: ADDCH(c); break;
			} break;
		case IN_ARGN:
			switch (c) {
			case '\r': ST(IN_EOL); ADDCH(0); break;
			case '\n': ADDARG(NULL); cb(p); RST(); break;
			default: ADDCH(c); break;
			} break;
		case IN_EOL:
			switch (c) {
			case '\r': break;
			case '\n': ADDARG(NULL); cb(p); RST(); break;
			case ':': RST(); ST(IN_ORG); break;
			default: RST(); break;
			} break;
		} /* switch */
	} /* while */
} /* input */
template<class T> inline void RST(T &A0, T &A1, T &A2)
{
    RST(A0), RST(A1), RST(A2);
}
Пример #8
0
/*RST 0x38*/
static void op_0xff(Z80EX_CONTEXT *cpu)
{
	RST(0x38, /*wr*/5,8);
	T_WAIT_UNTIL(11);
	return;
}