int main()
{
    const int idx[] = {2, 0, 4, 1, 3};
    double v[] = {1., 3., 0., 4., 2.};
    boost::compose_property_map<double*, const int*> cpm(v, idx);

    for (int i = 0; i < 5; ++i)
        std::cout << get(cpm, i) << " ";
    std::cout << std::endl;

    for (int i = 0; i < 5; ++i)
        ++cpm[i];

    for (int i = 0; i < 5; ++i)
        std::cout << get(cpm, i) << " ";
    std::cout << std::endl;

    for (int i = 0; i < 5; ++i)
        put(cpm, i, 42.);

    for (int i = 0; i < 5; ++i)
        std::cout << get(cpm, i) << " ";
    std::cout << std::endl;

    return 0;
}
Ejemplo n.º 2
0
pass2()
{
	int saved[12] ;
	int i ;
	char line[LINELEN] ;
	char *tail, *arg, *temp, *temp2, *temp3 ;

	/* start pass 3 */
	switch_down(1) ;

	saved[0] = saved[1] = saved[2] = saved[3] = 0 ;
	saved[4] = saved[5] = saved[6] = saved[7] = saved[8] = 0 ;
	saved[9] = saved[10] = saved[11] = 0 ;

	ln1 = alloc(LINELEN) ;
	ln2 = alloc(LINELEN) ;
	ln3 = alloc(LINELEN) ;
	ln4 = alloc(LINELEN) ;
	ln5 = alloc(LINELEN) ;
	ln6 = alloc(LINELEN) ;

	p_read(ln1) ;
	p_read(ln2) ;
	p_read(ln3) ;
	p_read(ln4) ;
	p_read(ln5) ;

	while ( p_read(ln6) ) {

		/* inc or dec top or second on stack */
		if ( strcmp(Ldhl0,ln1) == 0 ||
			 strcmp(Ldhl2,ln1) == 0 ||
			 strcmp(Ldhl4,ln1) == 0 ||
			 strcmp(Ldhl6,ln1) == 0 ) {

			if ( strcmp("\tADD HL,SP",ln2) == 0 &&
				 strcmp(Pushhl,ln3) == 0 &&
				 strcmp("\tCALL ccgint",ln4) == 0 &&
				 (strcmp(Inchl,ln5) == 0 || strcmp(Dechl,ln5) == 0) &&
				 strcmp("\tCALL ccpint",ln6) == 0 ) {

				if ( strcmp(Ldhl6,ln1) == 0 ) {
					c_write(Popix);
					c_write(Popde);
					c_write(Popbc);
				}
				else if ( strcmp(Ldhl4,ln1) == 0 ) {
					c_write(Popde);
					c_write(Popbc);
				}
				else if ( strcmp(Ldhl2,ln1) == 0 ) {
					c_write(Popbc);
				}
				c_write(Pophl);
				c_write(ln5);
				if ( strcmp(Ldhl6,ln1) == 0 ) {
					c_write(Pushhl);
					c_write(Pushbc);
					c_write(Pushde);
					strcpy(ln1,Pushix);
					++saved[3];
				}
				else if ( strcmp(Ldhl4,ln1) == 0 ) {
					c_write(Pushhl);
					c_write(Pushbc);
					strcpy(ln1,Pushde);
					++saved[2];
				}
				else if ( strcmp(Ldhl2,ln1) == 0 ) {
					c_write(Pushhl);
					strcpy(ln1,Pushbc);
					++saved[1];
				}
				else {
					strcpy(ln1,Pushhl);
					++saved[0] ;
				}
				p_read(ln2);
				p_read(ln3);
				p_read(ln4);
				p_read(ln5);
				p_read(ln6);
			}
		}

		/* check for comparison against small constant and jump */
		if ( strcmp(Exdehl, ln1) == 0 &&
			 (arg=match(Ldhl, ln2)) && 
			(strcmp("\tCALL cceq",ln3) == 0 || strcmp("\tCALL ccne",ln3) == 0) )

		  if ( strcmp("\tLD A,H", ln4) == 0 &&
			 strcmp("\tOR L", ln5) == 0 &&
			((tail=match("\tJP NZ,",ln6)) || (tail=match("\tJP Z,",ln6)))) {

			  if ( (i=chk_arg(arg)) != 0 ) {
				if ( strcmp("\tCALL cceq",ln3) == 0 ) {
					if ( match("\tJP NZ,",ln6 ) ) {
						strcpy(line, "\tJP Z,") ;
					}
					else {
						strcpy(line, "\tJP NZ,") ;
					}
					strcat(line, tail) ;
					strcpy(ln6, line) ;
				}
				temp = ln1 ;
				temp2 = ln2 ;
				temp3 = ln3 ;
				ln1 = ln4 ;
				ln2 = ln5 ;
				ln3 = ln6 ;
				ln4 = temp ;
				ln5 = temp2 ;
				ln6 = temp3 ;
				p_read(ln4) ;
				p_read(ln5) ;
				p_read(ln6) ;
				++saved[3+i] ;
			}
		}

		/* lh hl,0 after test has ensured hl is zero */
		if ( strcmp("\tLD A,H", ln1) == 0 ) {
		  if ( strcmp("\tOR L", ln2) == 0 ) {
			if ( match("\tJP NZ,", ln3) ) {
			  if ( strcmp(Ldhl0, ln4) == 0 ) {
				temp = ln4 ;
				ln4 = ln5 ;
				ln5 = ln6 ;
				ln6 = temp ;
				p_read(ln6) ;
				++saved[9] ;
			  }
			}
		  }
		}

		/* return TOS, one item on stack */
		if ( strcmp(Pophl, ln3) == 0 ) {
		  if ( strcmp(Pushhl, ln4) == 0 ) {
			if ( strcmp(Popbc, ln5) == 0 ) {
			  if ( strcmp(Ret, ln6) == 0 ) {
				strcpy(ln4, Ret) ;
				p_read(ln5) ;
				p_read(ln6) ;
				++saved[10] ;
			  }
			}
		  }
		}

		/* return TOS, two items on stack */
		if ( strcmp(Pophl, ln2) == 0 ) {
		  if ( strcmp(Pushhl, ln3) == 0 ) {
			if ( strcmp(Popbc, ln4) == 0 ) {
			  if ( strcmp(Popbc, ln5) == 0 ) {
				if ( strcmp(Ret, ln6) == 0 ) {
				  strcpy(ln3, Popbc) ;
				  strcpy(ln4, Ret) ;
				  p_read(ln5) ;
				  p_read(ln6) ;
				  ++saved[11] ;
				}
			  }
			}
		  }
		}

		c_write(ln1);	
		temp = ln1;
		ln1 = ln2;
		ln2 = ln3;
		ln3 = ln4;
		ln4 = ln5;
		ln5 = ln6;
		ln6 = temp;
		if (cpm(CONIN, 255) == CTRLC) exit() ;
	}
	c_write(ln1);
	c_write(ln2);
	c_write(ln3);
	c_write(ln4);
	c_write(ln5);

	puts("INC or DEC top of stack       "); putdec(saved[0]) ;
	putchar('\n') ;
	puts("INC or DEC 2nd top of stack   "); putdec(saved[1]) ;
	putchar('\n') ;
	puts("INC or DEC 3rd top of stack   "); putdec(saved[2]) ;
	putchar('\n') ;
	puts("INC or DEC 4th top of stack   "); putdec(saved[3]) ;
	putchar('\n') ;
	puts("Test for == or != zero        "); putdec(saved[4]) ;
	putchar('\n') ;
	puts("Test for == or != +/-1        "); putdec(saved[5]) ;
	putchar('\n') ;
	puts("Test for == or != +/-2        "); putdec(saved[6]) ;
	putchar('\n') ;
	puts("Test for == or != +/-3        "); putdec(saved[7]) ;
	putchar('\n') ;
	puts("Test for == or != constant    "); putdec(saved[8]) ;
	putchar('\n') ;
	puts("LD HL,0 when HL is zero       "); putdec(saved[9]) ;
	putchar('\n') ;
	puts("Return TOS, one item on stack "); putdec(saved[10]) ;
	putchar('\n') ;
	puts("Return TOS, two on stack      "); putdec(saved[11]) ;
	putchar('\n') ;
	putchar('\n') ;
	i = saved[0]*9 + saved[1]*7  + saved[2]*5 + saved[3] ;
	i += saved[4]*7 + saved[5]*6 + saved[6]*5 + saved[7]*4 ;
	i += saved[8]*3 + saved[9]*3 + saved[10]*2 + saved[11]*2 ;
	pr_total(i);

	Total += i ;
}
Ejemplo n.º 3
0
bool parseInput(char instr[])
{
	LONG    lLastError = ERROR_SUCCESS;

	// Make instr lower.
	_strlwr_s(instr,INPUT_BUFFER_SIZE);

	if (strcmp(instr,"exit")==0) return false; // If exit, exit.
	else if (strcmp(instr,"go")==0)
	{
		// Download program.
		if (hf.isValid())
			printf("GO!\n");
		else 
			printf("Un-GO!\n");

		// First connect
		scp.open();
		//serialSetConnected(true);
		// download program
		downloadStart(&scp,&hf);

	}
	else if (strcmp(instr,"load debug")==0)
	{
		// Load debug app.
	}
	else if (strcmp(instr,"load")==0)
	{
		// load regular app.
		if (hf.loadHex(FILEPATH1,true)) { printf("File %s loaded sucessfully!\n",hf.filepath); printf("File size: %lu, upper addr: %lu, lower addr: %lu\n",hf.getLength(),hf.getAddrUpper(),hf.getAddrLower()); }
		else { printf(hf.lastError); }

	}
	/*
	else if (strcmp(instr,"put")==0)
	{
		// Put dummy packet

		unsigned char canmsg[17];
		canmsg[0]=253;
		canmsg[16]=250;
		if (isConnected())
			{
			lLastError = serial.Write(canmsg,17);
			if (lLastError != ERROR_SUCCESS)
			{
				printf("Unable to send data\n");
			}
		} else { printf("Err! No connected to serial port.\n"); }
	}
*/

	else if (strcmp(instr,"conn")==0)
	{
		// Connect to serial port.

		if (isConnected()) { printf("Err! Alredy connected to serial port.\n"); }
		else { serialSetConnected(true); }
	}
	else if (strcmp(instr,"diss")==0)
	{		
		// Dissconnect from serial port.

		if (!isConnected()) { printf("Err! Not connected to serial port.\n"); }
		else { serialSetConnected(false); }
	}
	else if (strcmp(instr,"test2")==0)
	{
		//serialReaderStart(&serial);
	}
	else if (strcmp(instr,"test2 stop")==0)
	{
		//serialReaderStop();
	}
	else if (strcmp(instr,"test3")==0)
	{
		DCB dcb;
		HANDLE hCom;
		bool fSuccess;


	   hCom = ::CreateFile(_T("COM2"),
						GENERIC_READ | GENERIC_WRITE,
						0,    // must be opened with exclusive-access
						0, // no security attributes
						OPEN_EXISTING, // must use OPEN_EXISTING
						FILE_FLAG_OVERLAPPED,    // not overlapped I/O
						0  // hTemplate must be NULL for comm devices
						);

	   if (hCom == INVALID_HANDLE_VALUE) 
	   {
		   // Handle the error.
		   printf ("Err: %d.\n",GetLastError());
	   }


		// Build on the current configuration, and skip setting the size
	   // of the input and output buffers with SetupComm.

	   fSuccess = GetCommState(hCom, &dcb);

	   if (!fSuccess) 
	   {
		  // Handle the error.
		  printf ("GetCommState failed with error %d.\n", GetLastError());
	   }

		// Fill in DCB: 57,600 bps, 8 data bits, no parity, and 1 stop bit.

	   dcb.BaudRate = CBR_57600;     // set the baud rate
	   dcb.ByteSize = 8;             // data size, xmit, and rcv
	   dcb.Parity = NOPARITY;        // no parity bit
	   dcb.StopBits = ONESTOPBIT;    // one stop bit

	   fSuccess = SetCommState(hCom, &dcb);

	   if (!fSuccess) 
	   {
		  // Handle the error.
		  printf ("SetCommState failed with error %d.\n", GetLastError());
	   }

	   printf ("Serial port successfully reconfigured.\n");
		


	}
	else if (strcmp(instr,"test4")==0)
	{

		scp.open();
	
		char data[] = "hej";
		unsigned char data2[17];

		CanProtoMessage cpm(0x01,0x01,0x01,0x01,1,(unsigned char *)data);
		
		cpm.getBytes(data2);

		scp.write(data2,17);

		//serialReaderStartSerCon(&scp);

		//scp.close();
	}
	else if(strcmp(instr,"tick")==0)
	{ 
      printf ("actual:%ld\n", GetTickCount());

	}
	else if (strcmp(instr,"test")==0)
	{
		// Debug for testing canProtoMessage

		unsigned char dat[8];
		
		for (int i=0;i<8;i++) dat[i]=0x10+i*2;
		
		unsigned char dat2[17];

		CanProtoMessage cpm1(0x07,0x91,0x10,0x87,8,&dat[0]);
		
		cpm1.getBytes(&dat2[0]);
	

		CanProtoMessage cpm2(&dat2[0],1);
	
		if (cpm1.equals(&cpm2)) printf("OK!\n"); else printf("Not OK!\n");

	}
	else
	{
		printf("Command not found.\n");
	}

	printf("Main: ");

	return true;
}