예제 #1
0
int main()
{ 
	alt_putstr("Hello from Nios II!\n");
	alt_putstr("Input the char you would like to send.\n");
	alt_putchar(*parallel_in);
	alt_putstr("\n");
	int c = alt_getchar();
	alt_putstr("\n");

	*transmit_enable = 0x0;
	*load = 0x0;
	*parallel_out = c;
	usleep(1000);
	*transmit_enable = 0x1;
	*load = 0x1;
	usleep(50);
	*load = 0x0;

	while (!*char_sent) {
	}
	*transmit_enable = 0x0;

	while (!*char_received) {
	}

	alt_putchar(*parallel_in);
	alt_putstr("\n");

	return 0;
}
예제 #2
0
파일: hello_world.c 프로젝트: madcowswe/DSD
int main()
{
	start_notch(
			_binary_beeth5_noise_bin_start,
			_binary_beeth5_noise_bin_end,
			_alt_partition_beethout_start
			);

	//The notch filtering will be conducted in the background.
	//Code to perform other useful tasks can be put here.
	while(notch_busy());

	//Read performance counter
	unsigned int performance = notch_performance();

	//Print time taken for filtering operation
	char buf[16];
	gcvt((float)performance/ALT_CPU_FREQ, 10, buf);
	alt_putstr(" proc time = "); alt_putstr(buf); alt_putstr(" seconds \n");

	//start_notch(
	//		_binary_beeth5_noise_bin_start,
	//		_binary_beeth5_noise_bin_end,
	//		PWM_0_BASE
	//		);

	while(1);
}
예제 #3
0
void transmitIfBufferNotEmpty(char** pTransmit, char* pBufferHead, char* pBuffer, int* write) {
	if(*load) {
		  *load = 0;
	  }

	  char c = '\0';
	  if(*write) {
		  c = readBuffer(pTransmit, pBufferHead, pBuffer);
		  if(c != '\0' && c != 0x60 ) {
			  alt_putstr("writing: ");
			  alt_putchar(c);
			  alt_putstr("\n");
			  *write = 0;
			  *data_bus_output = c;
			  usleep(1000);
			  *load = 1;
			  *transmit_enable = 1;
			  //alt_putchar(c);
			  *data_bus_LEDs = (*load) | (*transmit_enable << 1) | (*character_sent << 2) | (*character_received << 3);
			  //*data_bus_LEDs = c;
			  usleep(500);
		  }
	  }
	  if(*character_sent) {
		  alt_putstr("char sent\n");
		  *write = 1;
		  *transmit_enable = 0;
	  }
}
예제 #4
0
int main()
{
	printf("Task 2! \n");

	float x[N];
	float y;

	generateVector(x);

	// timing
	char buf[50];
	clock_t exec_t1, exec_t2;

	exec_t1 = times(NULL); // get system time before starting the process

	// code START
	y = sumVector (x, N);

	//code END

	exec_t2 = times(NULL); // get system time after finishing the process
	gcvt((exec_t2 - exec_t1), 10, buf);
	// gcvt convert a number to a string with decimal including a point, gcvt(value,number of digits,buffer)
	// buffer 8,9 character longer than number, this is the memory block that stores the number
	alt_putstr("proc time = "); 	alt_putstr(buf);	alt_putstr("ticks\n");
	//printf could be used if memory is enough
	int i;
	for (i=0; i<10; i++)
		y = y/2.0;
	gcvt((int)y, 10, buf);
	alt_putstr("Result (divided by 1014) = "); alt_putstr(buf);
	return 0;
}
예제 #5
0
int main()
{
	char a[50];
clock_t t1,t2;
float x[255001]={0};
int i=0;
int n=4*255001;
float result1=0;
float result2=0;
float result3=0;
float result4=0;
float result5=0;
float result6=0;
	for (i=0;i<255001;i++){
		x[i]=i*0.001;
	}
	printf("hello world\n");
	t1 = times(NULL);
	result1=ALT_CI_SUM_VECTOR_0((int)x,n);
	t2 = times(NULL);
	result2=ALT_CI_SUM_VECTOR_0((int)x,n);
	result3=ALT_CI_SUM_VECTOR_0((int)x,n);
	result4=ALT_CI_SUM_VECTOR_0((int)x,n);
	result5=ALT_CI_SUM_VECTOR_0((int)x,n);
	result6=ALT_CI_SUM_VECTOR_0((int)x,n);
	printf("%f\n",result1);
	printf("%f\n",result2);
	printf("%f\n",result3);
	printf("%f\n",result4);
	printf("%f\n",result5);
	gcvt(t2-t1, 10, a);
	alt_putstr("Time = "); alt_putstr(a); alt_putstr("; ");
  return 0;
}
예제 #6
0
 int main() {
	char input = 'A';
	int i;
	int j;
	*enable = 0x0F;
	while (input != 'E') {
		alt_putstr("\nTo READ type 'R' and press enter.\n");
		alt_putstr("\nTo WRITE type 'W' and press enter.\n");
		alt_putstr("\nTo exit the program, enter 'E'\n");
		input = alt_getchar();
		//scanf("%c", &input);
		// input = getchar();

		if (input == 'R') {
			*readWrite = 0x0F; // read
			*address = 0x0;
			for (j = 0; j < 127; j = j + 1) {
				*address += 1;
				*leds = *data;
			}
			//while (1) {
				//*leds = *data;
			//}
		} else if (input == 'W') {
			*readWrite = 0x0; // write
			*address = 0x0;
			for (i = 127; i > 0; i = i - 1) {
				*data = i;
				*address += 1;
			}
		}
	}

	return 0;
}
예제 #7
0
int main()
{
	clock_t t1, t2, t3, t4, t5, t6;
	char a[50], b[50], c[50];

	printf("Hi, v2.1\n");
	printf("Running algorithm for task: ");
	printf((task)?"4+\n":"1-3\n");
	printf("Dividing result by 1024 is: ");
	printf((div_1024)?"ON\n":"OFF\n");
	////////////////
	//test case 1 //
	////////////////
	printf("gen vector 1, ");
	generateVector(x1, N1, S1);
	printf("sum vector 1\n");
	float y1=0.0;
	if (task) {t1 = times(NULL); y1 = sumVector_cos_custom(x1, N1); t2 = times(NULL);}
	else {t1 = times(NULL); y1 = sumVector(x1, N1); t2 = times(NULL);}
	gcvt(t2-t1, 10, a);
	alt_putstr("Time = "); alt_putstr(a); alt_putstr("; ");
	printf("Result = %f\n", ((div_1024)?y1/1024:y1));

	/*/////////////
	//test case 2 //
	////////////////
	printf("gen vector 2, ");
	generateVector(x2, N2, S2);
	printf("sum vector 2\n");
	float y2=0.0;
	if (task) {t3 = times(NULL); y2 = sumVector_cos_custom(x2, N2); t4 = times(NULL);}
	else {t3 = times(NULL); y2 = sumVector(x2, N2); t4 = times(NULL);}
	gcvt(t4-t3, 10, b);
	alt_putstr("Time = "); alt_putstr(b); alt_putstr("; ");
	printf("Result = %f\n", ((div_1024)?y2/1024:y2));

	////////////////
	//test case 3 //
	////////////////
	printf("gen vector 3, ");
	generateVector(x3, N3, S3);
	printf("sum vector 3\n");
	float y3=0.0;
	if (task) {t5 = times(NULL); y3 = sumVector_cos_custom(x3, N3); t6 = times(NULL);}
	else {t5 = times(NULL); y3 = sumVector(x3, N3); t6 = times(NULL);}
	gcvt(t6-t5, 10, c);
	alt_putstr("Time = "); alt_putstr(c); alt_putstr("; ");
	printf("Result = %f\n", ((div_1024)?y3/1024:y3));
*/

	return 0;
}
예제 #8
0
int main(){
	alt_putstr("Hello from Nios II!\n");

	printf("Enter 'G' to begin...");

	char input = alt_getchar();

	while ('G' != input) {
		input = alt_getchar();
	}

	if (input == 'G') {
		printf("You're in!");
		/* Event loop never exits. */
		while (1){
			if (*switches & 0x01) {
				*leds = (~(*switches)) | ((*switches) & (0x01));
			}
			else {
				*leds = *switches;
			}
		}
	}
	return 0;
}
예제 #9
0
void playerOnePlay() {
	sendMissle();
	receiveHitResult();
	alt_putstr("Player 2's turn... ");
	receiveMissle();

}
예제 #10
0
void gameInit() {
	sramWrite(keepScore, 0);
	sramWrite(counter, 0);

	makeBoard();

	alt_putstr("Welcome to Battleship!\n");
}
예제 #11
0
int main()
{ 
  alt_putstr("Hello from Nios II!\n");

  unsigned char led = 0;
  volatile unsigned int i;

  unsigned char * wiz830_base = (unsigned char*)0x08000000;

  // SHAR(Source Hardware Address Register)
  *(wiz830_base + 0x0008) = 0x00;
  *(wiz830_base + 0x0009) = 0x08;
  *(wiz830_base + 0x000a) = 0xDC;
  *(wiz830_base + 0x000b) = 0x01;
  *(wiz830_base + 0x000c) = 0x02;
  *(wiz830_base + 0x000d) = 0x03;
  // GAR(Gateway IP Address Register)
  *(wiz830_base + 0x0010) = 10;
  *(wiz830_base + 0x0011) = 0;
  *(wiz830_base + 0x0012) = 0;
  *(wiz830_base + 0x0013) = 1;
  // SUBR(Subnet Mask Register)
  *(wiz830_base + 0x0014) = 255;
  *(wiz830_base + 0x0015) = 0;
  *(wiz830_base + 0x0016) = 0;
  *(wiz830_base + 0x0017) = 0;
  // SIPR(Source IP Register)
  *(wiz830_base + 0x0018) = 10;
  *(wiz830_base + 0x0019) = 0;
  *(wiz830_base + 0x001a) = 0;
  *(wiz830_base + 0x001b) = 2;

  printf("%02x\n", *(wiz830_base + 0x0010));
  printf("%02x\n", *(wiz830_base + 0x0011));
  printf("%02x\n", *(wiz830_base + 0x0012));
  printf("%02x\n", *(wiz830_base + 0x0013));
  printf("\n");

  printf("%02x\n", *(wiz830_base + 0x0014));
  printf("%02x\n", *(wiz830_base + 0x0015));
  printf("%02x\n", *(wiz830_base + 0x0016));
  printf("%02x\n", *(wiz830_base + 0x0017));
  printf("\n");

  printf("%02x\n", *(wiz830_base + 0x0018));
  printf("%02x\n", *(wiz830_base + 0x0019));
  printf("%02x\n", *(wiz830_base + 0x001a));
  printf("%02x\n", *(wiz830_base + 0x001b));

  /* Event loop never exits. */
  while (1){
	  for(i = 0; i < 20000; i++) ;
	  led++;
	  *((unsigned int*)0x00000030) = led;
  }

  return 0;
}
예제 #12
0
int getPlayerNum() {
	alt_putstr("Are you player 1 or player 2? \n");
	int num = alt_getchar();
	if (num == '\n') {
		num = alt_getchar();
	}

	return num;
}
예제 #13
0
void printBoard() {
	int i, j;
	alt_printf("  0 1 2 3 4 5 6 7 8 9\n"); // prints the top row of number
	for (i = 0; i < 10; i++) {
		alt_printf("%x ", i);
		for (j = 0; j < 10; j++) {
			alt_printf("%c ", sramRead(j + i * 10));
		}
		alt_putstr("\n");
	}
}
예제 #14
0
void print_array(volatile long* array, int size)
{

    int i = 0;
    for (i = 0; i < size; ++i) {
        alt_printf("0x%x ", array[i]);
    }

    alt_putstr("\n");

}
예제 #15
0
 int main() {
	int input = 'A';
	int i;

	while (input != 'E') {
		alt_putstr("\n");
		alt_putstr("\nTo READ type 'R' and press enter.\n");
		alt_putstr("\nTo WRITE type 'W' and press enter.\n");
		alt_putstr("\nTo exit the program, enter 'E'\n");
		input = alt_getchar();

		if (input == 'R') {
			*enable = 0x0;
			*readWrite = 0x1; // read
			for (i = 0; i < 128; i++) {
				IOWR_ALTERA_AVALON_PIO_DIRECTION(*data, 0xFF);
				(*address) = i;
				*leds = *data;
				alt_printf("%x \n", *data);
				usleep(1000);
			}
			input = 'A';
			alt_printf("Read complete\n");

		} else if (input == 'W') {
			*enable = 0x0;
			*readWrite = 0x0; // write
			IOWR_ALTERA_AVALON_PIO_DIRECTION(*data, 0x00000000);

			for (i = 0; i < 128; i++) {
				*address = i;
				*data = 0x00000000;
				*data = 127 - i;
				alt_printf("%x\n", *data);
			}
			input = 'A';
		}
	}

	return 0;
}
예제 #16
0
int main(void)
{
    alt_putstr("Hello from Nios II!\n");

    fill_arrays_with_random_values();

    PERF_RESET(PERFORMANCE_COUNTER_0_BASE);
    PERF_START_MEASURING(PERFORMANCE_COUNTER_0_BASE);


    PERF_BEGIN(PERFORMANCE_COUNTER_0_BASE, 1);
    shuffle_in_c(array_for_c, ARRAY_SIZE);
    PERF_END(PERFORMANCE_COUNTER_0_BASE, 1);

    PERF_BEGIN(PERFORMANCE_COUNTER_0_BASE, 2);
    shuffle_with_custom_instruction(array_for_custom_instr, ARRAY_SIZE);
    PERF_END(PERFORMANCE_COUNTER_0_BASE, 2);

    PERF_BEGIN(PERFORMANCE_COUNTER_0_BASE, 3);
    shuffle_with_accelerator(array_for_accelerator, ARRAY_SIZE);
    PERF_END(PERFORMANCE_COUNTER_0_BASE, 3);


    PERF_STOP_MEASURING(PERFORMANCE_COUNTER_0_BASE);
    perf_print_formatted_report((void *) PERFORMANCE_COUNTER_0_BASE, ALT_CPU_FREQ, 3, ""
    		"shuffle_with_c", "shuffle_with_custom_instruction", "shuffle_with_accelerator");

    //verify_arrays();

#ifdef SMALL_ARRAY
    alt_putstr("Shuffle with C:\t\t\t");
    print_array(array_for_c, ARRAY_SIZE);
    alt_putstr("Shuffle with custom instruction:\t");
    print_array(array_for_custom_instr, ARRAY_SIZE);
    alt_putstr("Shuffle with accelerator:\t\t");
    print_array(cache_bypass(array_for_accelerator), ARRAY_SIZE);
#endif

    return 0;
}
예제 #17
0
 int main() {
	char input = 'A';
	int i;
	int j;
	//*enable = 0x0F;
	while (input != 'E') {
		alt_putstr("\nTo READ type 'R' and press enter.\n");
		alt_putstr("\nTo WRITE type 'W' and press enter.\n");
		alt_putstr("\nTo exit the program, enter 'E'\n");
		input = alt_getchar();
		//scanf("%c", &input);
		// input = getchar();

		if (input == 'R') {
			*enable = 0x0F;
			*readWrite = 0x0F; // read
			for (j = 0; j < 127; j = j + 1) {
				usleep(100000);
				(*address) = j;
				*leds = *data;

				alt_printf("sad%h   ", *data);
			}


		} else if (input == 'W') {
			*enable = 0x00;
			*readWrite = 0x0; // write
			*address = 0x0;
			for (i = 127; i > 0; i = i - 1) {
				*data = i;
				(*address) += 1;
			}
		}
	}

	return 0;
}
예제 #18
0
int main()
{ 
	alt_putstr("Hello from Nios II!\n");
	//alt_putstr("Input the char you would like to send.\n");
	//alt_putchar(*parallel_in);
	//alt_putstr("\n");
	//int c = alt_getchar();
	//alt_putstr("\n");
	int i = 0;
	char hello[20] = "Hello, world! abc123";

	while (i < 20) {

		*transmit_enable = 0x0;
		*load = 0x0;
		//*parallel_out = c;
		*data_bus_output = (hello[i]);
		//getBits(*parallel_out);
		//alt_putstr("\n*parallel_out\n");
		//alt_putchar((*parallel_out >> 1));
		//alt_putchar(*parallel_out);
		*data_bus_output = setParity(*data_bus_output);
		//getBits(*parallel_out);
		//alt_putchar(getCharacter(*parallel_out));
		//alt_putstr("\ngetCharacter(*parallel_out)\n");
		//alt_putchar(getCharacter(*parallel_out));
		usleep(1000);
		*transmit_enable = 0x1;
		*load = 0x1;
		usleep(50);
		*load = 0x0;
		while (!*character_received) {
		}
		while (!*character_sent) {
		}
		*transmit_enable = 0x0;

		/*if (getParity(*parallel_in)) {
			alt_putstr("bad parity\n");
		} else {
			alt_putstr("good parity\n");
		}*/
		//getBits(*parallel_in);
		alt_putchar(getCharacter(*data_bus_input));
		//alt_putstr("\n");
		i++;
	}

	return 0;
}
예제 #19
0
int main()
{ 
  alt_putstr("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");

	char* xString = calloc(20, sizeof(char));
	int i;
	for(i = 0; i < 20; i++) {
		int j;
		for(j = 0; j < 20; j++) {
			if(i == j) {
				xString[j] = 0x58;
			} else {
				xString[j] = 0x20;
			}
		}
		//system("clear");
		//printf("\033c");
		alt_putstr("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
		/*printf("\033[2J");
		alt_putstr("\033[2J");
		alt_putstr("\033c");
		printf("\033c");
		system("clear");*/
		/*alt_putstr("[2J");
		alt_putstr("\033c[2J");
		alt_putstr("\033");*/
		//alt_putstr("\[2J");
		printf("%s", xString);
		usleep(500000);
	}
	
	
	//Event loop, never exits
	while(1);

  return 0;
}
예제 #20
0
void shuffle_with_accelerator(volatile long* array, int size)
{
    // Set Start address and array size
    IOWR_32DIRECT(ACCELERATOR_0_BASE, 0x0, (long ) array);
    IOWR_32DIRECT(ACCELERATOR_0_BASE, 0x4, ARRAY_SIZE);

    // Start
    IOWR_32DIRECT(ACCELERATOR_0_BASE, 0x8, 1);

    // Wait for Done
    while (IORD_32DIRECT(ACCELERATOR_0_BASE, 0xC) != 1) {
        alt_putstr("Waiting for accelerator\n");
    }

}
예제 #21
0
void verify_arrays(void)
{
    int i = 0;
    for (i = 0; i < ARRAY_SIZE; ++i) {
        if (array_for_c[i] != array_for_custom_instr[i]
                || array_for_custom_instr[i] != ((long*)cache_bypass(array_for_accelerator))[i]) {
            alt_printf("Verification failed for index 0x%x: 0x%x, 0x%x, 0x%x",
                    i, array_for_c[i], array_for_custom_instr[i],
                    array_for_accelerator[i]);
            while (1)
                ;
        }
    }

    alt_putstr("Verifying OK\n");
}
예제 #22
0
int main()
{ 
  alt_putstr("Hello from Nios II!\n");

  printf("Hello from Nios II!\n");
  int count = 0;
  int delay;
  while(1)
  {
	  IOWR_ALTERA_AVALON_PIO_DATA(PIO_BASE, count & 0x01);
	  delay = 0;
	  while(delay < 2000000){
		  delay++;
	  }
	  count++;
  }
  return 0;
}
int main(){ 
	alt_putstr("Hello from Nios II!\n");
	
	char input;
	
	input = alt_getchar();
	
	if (input == 'G') {	
		/* Event loop never exits. */
		while (1){
			if (*(switches & 0x01) == 0) {
				*leds = *switches;
			}
			else {
				*leds = ~*switches;				
			}
		}	
	}
  return 0;
}
예제 #24
0
int main()
{ 
	alt_putstr("Hello from Nios II!\n");

	char msg[26] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	int j;
	for (j = 0; j < strlen(msg); j++) {
		*transmit_enable = 0x0;
		*load = 0x0;
		*data_bus_output = setParity(msg[j]);
		usleep(1000);
		*load = 0x1;
		*transmit_enable = 0x1;
		usleep(50);
		*load = 0x0;
		while(!*character_sent);
		*transmit_enable = 0x0;
		usleep(25000);
	}
	return 0;
}
예제 #25
0
파일: main.c 프로젝트: iseroid/sopc_iic
int main( void )
{ 
    unsigned char buf[4];

    alt_putstr("Boot\n");

    // I2C Clock Setting
    IOWR( IIC_0_BASE, 1,  42 ); // 100kHz (50,000kHz / 100kHz / 12 = 41.6...)
//  IOWR( IIC_0_BASE, 1,  11 ); // 400kHz (50,000kHz / 400kHz / 12 = 10.4...)

    buf[0] = 0;
    iic_write( 0x1D, 1, buf );
    iic_read( 0x1D, 1, buf );
    alt_printf( "DEVID %x\n", buf[0] );

    /* Event loop never exits. */
    while( 1 ) {
        ;
    }

    return 0;
}
예제 #26
0
int main() {
	*transmit_enable = 0;
	*sram_we = 1;
	*sram_oe = 1;
	gameInit();
	int playerNum = getPlayerNum();
	printBoard();

	while (sramRead(keepScore) < 11) {

		switch (playerNum) {
		case '1':
			playerOnePlay();
			break;
		case '2':
			playerTwoPlay();
			break;
		}
	}

	alt_putstr("You win!");

	return 0;
}
예제 #27
0
int main()
{
	unsigned int row, col;
	unsigned int i = 0;
	unsigned int j = 0;
	pixbuf_t *pixbuf;

	graphics_init();
	pixbuf = graphics_get_final_buffer();

	alt_putstr("Restoring default palette\n");
	switch_palette(&palette_332);

	graphics_clear_screen();

	// Draw to edges of screen
	graphics_draw_rectangle(pixbuf, 0, 0, 640-1, 480-1, 0xE0);
	graphics_draw_rectangle(pixbuf, 1, 1, 640-2, 480-2, 0xFF);
	ALT_CI_CI_FRAME_DONE_0;

	// Draw the colors at the top of the screen
	for (i = 0; i < sizeof(color_array); i++)
	{
		graphics_draw_rectangle(pixbuf, i, 0, i, 0, color_array[i]);
	}

	// Cycle through a pattern
	for (i = 0; i < 256; i++)
	{
		graphics_draw_rectangle(pixbuf, 300, 50, 301, 127, color_array[i % sizeof(color_array)]);
		graphics_draw_rectangle(pixbuf, 201, 111, 400, 230, color_array[(i+4) % sizeof(color_array)]);
		graphics_draw_rectangle(pixbuf, 100, 200, 500, 430, color_array[(i+8) % sizeof(color_array)]);
		ALT_CI_CI_FRAME_DONE_0;
		for (j = 0; j < 10000; j++)
		{
			// Do nothing
		}
	}

	graphics_clear_screen();

	// Draw a geometric pattern in the most inefficient way possible...
	for (row = 0; row < 480; row++)
	{
		for (col = 0; col < 640; col++)
		{
			if (row == col) {
				graphics_draw_rectangle(pixbuf, col, row, col, row, 0xFF);
			}
			if (row == col - 160) {
				graphics_draw_rectangle(pixbuf, col, row, col, row, 0xFF);
			}
			if (480 - row - 1 == col) {
				graphics_draw_rectangle(pixbuf, col, row, col, row, 0xFF);
			}
			if (480 - row - 1 == col - 160) {
				graphics_draw_rectangle(pixbuf, col, row, col, row, 0xFF);
			}
		}
	}
	ALT_CI_CI_FRAME_DONE_0;
	for ( i = 0; i < 100000; i++)
	{
		//wait for a while
	}
	graphics_clear_screen();
	int genesis_value;
	while(1)
	{
		genesis_value = IORD_32DIRECT(GENESIS_0_BASE, 0);
		if ((genesis_value)& (1 << 4)){
			graphics_draw_rectangle(pixbuf, 100, 100, 150, 150, 0x1A);
			  }
		else
			graphics_draw_rectangle(pixbuf, 100, 100, 150, 150, 0x0);
			  if ((genesis_value)& (1 << 5)){
				  graphics_draw_rectangle(pixbuf, 200, 200, 250, 250, 0xE0);
			  }
			  else
				  graphics_draw_rectangle(pixbuf, 200, 200, 250, 250, 0x0);
			  if ((genesis_value)& (1 << 6)){
				  graphics_draw_rectangle(pixbuf, 300, 300, 350, 350, 0x03);
			  }
			  else
				  graphics_draw_rectangle(pixbuf, 300, 300, 350, 350, 0x0);

			  ALT_CI_CI_FRAME_DONE_0;
		// Do nothing
	}

	return 0;
}
예제 #28
0
int main()
{


    unsigned int row = 0;
    unsigned int col = 0;
    unsigned int delay = 0;

    unsigned int color;
    int i;



    // Clear the screen first.
    alt_putstr("Clear the screen\n");
    for (col = 0; col < FRAME_WIDTH; col = col + 4) {
        for (row = 0; row < FRAME_HEIGHT; ++row) {
            color = 0;
            IOWR_32DIRECT(SRAM_0_BASE, row * FRAME_WIDTH + col, color << 24 | color << 16 | color << 8 | color << 0);
        }
    }

    // Print first 16 elements of current palette
    print_palette(16);
    // Switch to EGA colour palette
    switch_palette(&palette_ega);
    print_palette(16);

    alt_putstr("Screen painting demo\n");

    // Cycle through the colours of the EGA colour palette
    for (i = 0; i < 16; i++) {
        for (delay = 0; delay < 700/*2000*/; delay++) {
            unsigned int tdelay = delay;
            for (tdelay; tdelay > 0; tdelay--) {}
        }

        for (row=0; row<480; row++) {
            for (col = 0; col < 640; col=col+4) {
                color = i;
                IOWR_32DIRECT(SRAM_0_BASE, row * 640 + col, color << 24 | color << 16 | color << 8 | color << 0);
            }

        }
    }



    alt_putstr("\nStarting Stephen Test Pattern\n");
    int p;
    for (p = 0; p < palette_count; p++)
    {
        switch_palette(palettes[p]);

        alt_putstr("Clear the screen\n");
        for (col = 0; col < FRAME_WIDTH; col = col + 4) {
            for (row = 0; row < FRAME_HEIGHT; row++) {
                color = 0;
                IOWR_32DIRECT(SRAM_0_BASE, row * FRAME_WIDTH + col, color << 24 | color << 16 | color << 8 | color << 0);
            }
        }


        //Now draw the test pattern
        for (row = 0; row < 480; row++)
        {
            for (col = 0; col < 640; col = col + 4)
            {
                color = ((row + col) % 256) << 0 | ((row + col) % 256) << 8 | ((row + col) % 256) << 16 | ((row + col) % 256) << 24;
                if (row == 0 || row == 479)
                {
                    IOWR_32DIRECT(SRAM_0_BASE, row * 640 + col, 0xFFFFFFFF);
                }
                else if (col == 0)
                {
                    IOWR_32DIRECT(SRAM_0_BASE, row * 640 + col, 0x000000FF | color);
                }
                else if (col == 636)
                {
                    IOWR_32DIRECT(SRAM_0_BASE, row * 640 + col, 0xFF000000 | color);
                }
                else
                {
                    IOWR_32DIRECT(SRAM_0_BASE, row * 640 + col, color);
                }
            }
        }
    }





    alt_putstr("Done.\n");


    return 0;
}
예제 #29
0
int main()
{ 
	//fcntl(STDIN_FILENO, F_SETFL, O_NONBLOCK);
	alt_putstr("Hello from Nios II!\n");
	*character_received = 0;
	char *msg = "Hello from a different Nios II!";
	int j;
	unsigned char incoming;
	while (1) {
		//msg = fcntl(STDIN_FILENO, F_SETFL, O_NONBLOCK);

		if (*character_received) {
			incoming = getCharacter(*data_bus_input);
			alt_printf("Incoming: %c \n", incoming);

			while(*character_received) {
			}
		}

	return 0;

		/*if (msg[0] == '#') {
			for (j = 0; j < 16; j++) {
				*transmit_enable = 0x0;
				*load = 0x0;
				*parallel_out = setParity(msg[j]);
				usleep(1000);
				*transmit_enable = 0x1;
				*load = 0x1;
				usleep(50);
				*load = 0x0;
				usleep(50);
			}

			msg = "#";
		}*/
	}
	
	
    //FOR NIOS
	//fcntl(STDIN_FILENO, F_SETFL, O_NONBLOCK);

    //Tests
    //sram_malloc_test();
    //sram_free_test();

    //Game Init
	/*setup_interrupt();
    initializeGame();
	
    pSramAliens = sram_malloc(sizeof(struct Alien) * (ALIEN_COLS * ALIEN_ROWS));
    int pSramBulletBuffer = sram_malloc((sizeof(struct Projectile) * (ALIEN_COLS * ALIEN_WIDTH * VOID_HEIGHT)) + sizeof(struct Projectile));

	
	
    //printf("%i\n", sizeof(struct Projectile) * (ALIEN_COLS * ALIEN_WIDTH * VOID_HEIGHT));
    //New Game
	gameOver = 0;
	unsigned int  gameStartTime = *game_time;
	unsigned int  previousUpdateBoard = *game_time;
	unsigned int  previousUpdateBullets = *game_time;
    
	initRandomAliens(pSramAliens);
	initProjectileBuffer(pSramBulletBuffer);
	pBuffer = calloc(TRANSMIT_BUFFER_SIZE, sizeof(char));
	pBufferHead = pBuffer;
	pTransmit = pBuffer;
	
	*data_bus_output = 0xAF;
	
	//while(1);
	
	char hello[20] = "Hello, world! abc123";
	int i;
	for(i = 0; i < 20; i++) {
		writeBuffer(hello[i]);
	}
	transmitIfBufferNotEmpty();
	
	//Game Event Loop
    while(1) {
		if(gameOver) {
			if(gameOver == 1) {
				printf("\nAliens Win!\n");
			} else if(gameOver ==2) {
				printf("\nGunner Win!\n");
			}
			return 0;
		}
		//gameOver =1;
		
		if(((*game_time) - previousUpdateBoard) > 10) {
			alienShift = ((*game_time) / 10) % 8;
			//alienShift = 2;
			//updateDisplay(pSramAliens, pSramBulletBuffer, gunnerX, (*game_time) % 2, alienShift);			
			previousUpdateBoard = (*game_time);
		}
		
		if(((*game_time) - previousUpdateBullets) > 5) {
			updateProjectileNodes();
			previousUpdateBullets = (*game_time);
		}
		
		moveGunnerLeft(&gunnerX);
		moveGunnerRight(&gunnerX);
		//shootGunner(&gunnerX);
		shootAliens();
	}
	
    return 0;*/
}
예제 #30
0
void playerTwoPlay() {
	alt_putstr("Player 1's turn... ");
	receiveMissle();
	sendMissle();
	receiveHitResult();
}