float game2(void){ uint32_t x_data, y_data; uint32_t xMiddle, yMiddle; uint32_t i; float ticks; float mHz = 50000000; int seconds = 0; bool top_square = 1; bool left_square = 1; bool right_square = 1; bool bottom_square = 1; int square_curr_page = 4; int col = 0; int square_curr_col = 49; TIMER0_Type *gp_timer; gp_timer = (TIMER0_Type *) TIMER1_BASE; init_squares = 4; squares_caught = 0; xMiddle = (readingX/0x28); yMiddle = (readingY/0x1a2); // display welcome screen lcd_write_string_10pts(0,"Game 2!"); lcd_write_string_10pts(1, "Touch"); lcd_write_string_10pts(2, "Stick to"); lcd_write_string_10pts(3, "Move!"); for(i = 0; i < 10000000; i++){}; // place squares lcd_clear(); square(1,13); square(7, 73); square(1, 97); square(6, 1); square_out(square_curr_page, square_curr_col); // start game timer f14_timer1_Init(1); while(1){ if(sendPackets){ sendPackets = false; if(wireless_send_32(false,false,0) != NRF24L01_TX_SUCCESS){ packetsDropped++; } } WATCHDOG0->ICR = 0; x_data = xMiddle; y_data = yMiddle; if(matrixWrite){ matrixWrite = false; ledMatrixWriteData(I2C_I2C_BASE, col, Led_LUT[4-squares_caught][col]); col++; col = col % 5; } if(gp_timer->RIS == 1){ gp_timer->ICR = 1; seconds++; } if(joyStickUpdate){ x_data = (readingX/0x28); y_data = (readingY/0x1a2); joyStickUpdate = false; } if(x_data < xMiddle){ rm_square(square_curr_page,square_curr_col); if(square_curr_col == 97){ square_curr_col = 1; } else{ square_curr_col+=12; } square_out(square_curr_page,square_curr_col); } if(x_data > xMiddle){ rm_square(square_curr_page,square_curr_col); if(square_curr_col == 1){ square_curr_col = 97; } else{ square_curr_col-=12; } square_out(square_curr_page,square_curr_col); } if(y_data < yMiddle){ rm_square(square_curr_page,square_curr_col); if(square_curr_page == 7){ square_curr_page = 0; } else{ square_curr_page++; } square_out(square_curr_page,square_curr_col); } if(y_data > yMiddle){ rm_square(square_curr_page,square_curr_col); if(square_curr_page == 0){ square_curr_page = 7; } else{ square_curr_page--; } square_out(square_curr_page,square_curr_col); } if((square_curr_page == 1) && (square_curr_col == 13) && top_square){ squares_caught++; top_square = 0; } if((square_curr_page == 1) && square_curr_col == 97 && right_square){ squares_caught++; right_square = 0; } if((square_curr_page == 6) && square_curr_col == 1 && left_square){ squares_caught++; left_square = 0; } if((square_curr_page == 7) && square_curr_col == 73 && bottom_square){ squares_caught++; bottom_square = 0; } //printf("Squares caught: %i",squares_caught); if(squares_caught == 4){ ticks = f14_timer1_stop(); //stop timer, send and receive values, check for win/loss lcd_clear(); lcd_write_string_10pts(0,"Good job!"); lcd_write_string_10pts(1,"Time: "); lcd_write_string_10pts(2,"You win!"); for(i = 0; i < 10000000; i++){}; lcd_clear(); return (seconds+roundF(ticks/mHz)); } } }
static void basic_tests(void) { char string[] = "I am a string"; WCHAR wstring[] = {'I',' ','a','m',' ','a',' ','w','s','t','r','i','n','g', 0}; int f[5] = {1, 3, 0, -2, -4}; vector_t a = {1, 3, 7}; vector_t vec1 = {4, -2, 1}, vec2 = {-5, 2, 3}, *pvec2 = &vec2; pvectors_t pvecs = {&vec1, &pvec2}; sp_inner_t spi = {42}; sp_t sp = {-13, &spi}; aligns_t aligns; pints_t pints; ptypes_t ptypes; padded_t padded; padded_t padded2[2]; bogus_t bogus; int i1, i2, i3, *pi2, *pi3, **ppi3; double u, v; float s, t; LONG q, r; short h; char c; int x; str_struct_t ss = {string}; wstr_struct_t ws = {wstring}; str_t str; se_t se; renum_t re; ok(int_return() == INT_CODE, "RPC int_return\n"); ok(square(7) == 49, "RPC square\n"); ok(sum(23, -4) == 19, "RPC sum\n"); x = 0; square_out(11, &x); ok(x == 121, "RPC square_out\n"); x = 5; square_ref(&x); ok(x == 25, "RPC square_ref\n"); ok(str_length(string) == strlen(string), "RPC str_length\n"); ok(str_t_length(string) == strlen(string), "RPC str_length\n"); ok(dot_self(&a) == 59, "RPC dot_self\n"); ok(str_struct_len(&ss) == lstrlenA(string), "RPC str_struct_len\n"); ok(wstr_struct_len(&ws) == lstrlenW(wstring), "RPC str_struct_len\n"); v = 0.0; u = square_half(3.0, &v); ok(u == 9.0, "RPC square_half\n"); ok(v == 1.5, "RPC square_half\n"); t = 0.0f; s = square_half_float(3.0f, &t); ok(s == 9.0f, "RPC square_half_float\n"); ok(t == 1.5f, "RPC square_half_float\n"); r = 0; q = square_half_long(3, &r); ok(q == 9, "RPC square_half_long\n"); ok(r == 1, "RPC square_half_long\n"); i1 = 19; i2 = -3; i3 = -29; pi2 = &i2; pi3 = &i3; ppi3 = &pi3; pints.pi = &i1; pints.ppi = &pi2; pints.pppi = &ppi3; ok(pints_sum(&pints) == -13, "RPC pints_sum\n"); c = 10; h = 3; q = 14; s = -5.0f; u = 11.0; ptypes.pc = &c; ptypes.ps = &h; ptypes.pl = &q; ptypes.pf = &s; ptypes.pd = &u; ok(ptypes_sum(&ptypes) == 33.0, "RPC ptypes_sum\n"); ok(dot_pvectors(&pvecs) == -21, "RPC dot_pvectors\n"); ok(dot_copy_vectors(vec1, vec2) == -21, "RPC dot_copy_vectors\n"); ok(sum_fixed_array(f) == -2, "RPC sum_fixed_array\n"); ok(sum_sp(&sp) == 29, "RPC sum_sp\n"); ok(enum_ord(E1) == 1, "RPC enum_ord\n"); ok(enum_ord(E2) == 2, "RPC enum_ord\n"); ok(enum_ord(E3) == 3, "RPC enum_ord\n"); ok(enum_ord(E4) == 4, "RPC enum_ord\n"); se.f = E2; check_se2(&se); memset(&aligns, 0, sizeof(aligns)); aligns.c = 3; aligns.i = 4; aligns.s = 5; aligns.d = 6.0; ok(sum_aligns(&aligns) == 18.0, "RPC sum_aligns\n"); padded.i = -3; padded.c = 8; ok(sum_padded(&padded) == 5, "RPC sum_padded\n"); padded2[0].i = -5; padded2[0].c = 1; padded2[1].i = 3; padded2[1].c = 7; ok(sum_padded2(padded2) == 6, "RPC sum_padded2\n"); padded2[0].i = -5; padded2[0].c = 1; padded2[1].i = 3; padded2[1].c = 7; ok(sum_padded_conf(padded2, 2) == 6, "RPC sum_padded_conf\n"); i1 = 14; i2 = -7; i3 = -4; bogus.h.p1 = &i1; bogus.p2 = &i2; bogus.p3 = &i3; bogus.c = 9; ok(sum_bogus(&bogus) == 12, "RPC sum_bogus\n"); check_null(NULL); str = get_filename(); ok(!strcmp(str, __FILE__), "get_filename() returned %s instead of %s\n", str, __FILE__); midl_user_free(str); x = echo_ranged_int(0); ok(x == 0, "echo_ranged_int() returned %d instead of 0\n", x); x = echo_ranged_int(100); ok(x == 100, "echo_ranged_int() returned %d instead of 100\n", x); if (!old_windows_version) { get_ranged_enum(&re); ok(re == RE3, "get_ranged_enum() returned %d instead of RE3\n", re); } }
//******************************************* // Game 1. Move square using buttons to // collect the other squares. First one to // collect all four wins. //******************************************* float game1(void){ int i; int rand_page; int rand_col; float ticks; float time; float mHz = 50000000; int square_curr_page = 4; int square_curr_col = 49; bool top_square = 1; bool left_square = 1; bool right_square = 1; int seconds = 0; int col = 0; bool bottom_square = 1; TIMER0_Type *gp_timer; gp_timer = (TIMER0_Type *) TIMER1_BASE; init_squares = 4; squares_caught = 0; // print welcome screen lcd_write_string_10pts(0,"Game 1!"); lcd_write_string_10pts(1, "Press"); lcd_write_string_10pts(2, "Buttons to"); lcd_write_string_10pts(3, "Move!"); // besy wait for the screen to display for(i = 0; i < 10000000; i++){}; lcd_clear(); rand_page = (rand()%7); rand_col = (rand()%90); square(0,49); square(7, 61); square(3, 97); square(5, 13); square_out(square_curr_page, square_curr_col); //start the game timer f14_timer1_Init(1); //needs to start a count up timer right now. while(1){ if(sendPackets){ sendPackets = false; if(wireless_send_32(false,false,0) != NRF24L01_TX_SUCCESS){ packetsDropped++; } } WATCHDOG0->ICR = 0; if(matrixWrite){ matrixWrite = false; ledMatrixWriteData(I2C_I2C_BASE, col, Led_LUT[4-squares_caught][col]); col++; col = col % 5; } button = -1; if(AlertSysTick){ data = GPIOF->DATA; if( (data & PA1) == 0) { up++; if(up == 7) button = 0; } else up = 0; if( (data & PA4) == 0) { down++; if(down == 7) button = 3; } else down = 0; if( (data & PA2) == 0) { right++; if(right == 7) button = 1; } else right = 0; if( (data & PA3) == 0) { left++; if(left == 7) button = 2; } else left = 0; AlertSysTick = false; } //write to eeprom // for(i = 0; i < EEPROM_BYTES; i++){ // eeprom_byte_write(I2C_I2C_BASE,i,write_data[i]); // } if(gp_timer->RIS == 1){ gp_timer->ICR = 1; seconds++; } switch(button){ case 0: rm_square(square_curr_page,square_curr_col); if(square_curr_page == 0){ square_curr_page = 7; } else{ square_curr_page--; } square_out(square_curr_page,square_curr_col); break; case 1: rm_square(square_curr_page,square_curr_col); if(square_curr_col == 97){ square_curr_col = 1; } else{ square_curr_col+=12; } square_out(square_curr_page,square_curr_col); break; case 2: rm_square(square_curr_page,square_curr_col); if(square_curr_col == 1){ square_curr_col = 97; } else{ square_curr_col-=12; } square_out(square_curr_page,square_curr_col); break; case 3: rm_square(square_curr_page,square_curr_col); if(square_curr_page == 7){ square_curr_page = 0; } else{ square_curr_page++; } square_out(square_curr_page,square_curr_col); break; } if((square_curr_page == 0) && (square_curr_col == 49) && top_square){ squares_caught++; top_square = 0; } if((square_curr_page == 3) && square_curr_col == 97 && right_square){ squares_caught++; right_square = 0; } if((square_curr_page == 5) && square_curr_col == 13 && left_square){ squares_caught++; left_square = 0; } if((square_curr_page == 7) && square_curr_col == 61 && bottom_square){ squares_caught++; bottom_square = 0; } if(squares_caught == 4){ ticks = f14_timer1_stop(); time = (seconds+roundF(ticks/mHz)); lcd_clear(); lcd_write_string_10pts(0,"Good job!"); lcd_write_string_10pts(1,"Time: "); lcd_write_string_10pts(2,"You win!"); for(i = 0; i < 10000000; i++){}; lcd_clear(); return time; } } }