int main() { int i; unsigned long sw_time_1, sw_time_2; //enable the temperature sensor temp_sensor_init(); //enable uCProbe communication ProbeCom_Init(); ProbeRS232_Init(0); ProbeRS232_RxIntEn(); // turn off the LEDS IOWR(LED_PIO_BASE,0,0xFF); printf("BeMicro SDK Lab1: \n"); printf("-----------------\n\n"); // Create the input data waveform printf("Creating buffer source data\n\n"); for(i = 0; i < DATA_BUFFER_SIZE; i++) { source_databuffer[i] = input_data[i%INPUT_LENGTH]; } // record the value of the high resolution time-stamp timer at the entry and exit points of the software filter if(alt_timestamp_start() < 0) { printf("Please add the high resolution timer to the timestamp timer setting in the syslib properties page.\n"); return 0; } printf("Software filter is operating (please be patient)\n"); sw_time_1 = alt_timestamp(); FIR_SW(source_databuffer, DATA_BUFFER_SIZE, sw_destination_databuffer, T, coefficients[0], coefficients[1], coefficients[2], coefficients[3], coefficients[4], coefficients[5], coefficients[6], coefficients[7], DIVIDER_ORDER); sw_time_2 = alt_timestamp(); printf("Software filter is done\n\n"); sw_proc_time = ((double)(sw_time_2-sw_time_1))/((double)alt_timestamp_freq()); printf("Software processing time was: %f seconds\n\n", sw_proc_time); printf("Processing time will also be reported by uC-Probe:\n"); return 1; }
void DYNAMIC_UTI(void* pdata) { INT8U err_tmr, err_tmr_start, i, err; int j, switch_status; Sem_DYNAMIC_UTI = OSSemCreate(0); printf("DYNAMIC_UTI Task created!\n"); SWTimer_DYNAMIC_UTI = OSTmrCreate(0, DYNAMIC_UTI_PERIOD, OS_TMR_OPT_PERIODIC , Tmr_Callback_DYNAMIC_UTI_Task, (void *)0,"DYNAMIC_UTI",&err_tmr); if(err_tmr == OS_ERR_NONE){ OSTmrStart(SWTimer_DYNAMIC_UTI, &err_tmr_start); if(DEBUG) printf("Timer for DYNAMIC_UTI is created and Started \n"); } else { printf("Error while creating DYNAMIC_UTI task timer \n"); } while(1) { switch_status = switches_pressed(); switch_status = switch_status & 1008; // Mask for SW4 - SW9 switch_status = switch_status >> 4; printf("Before loop : Time : %d, SwitchStatus : %d \n", alt_timestamp() / (alt_timestamp_freq()/1000), switch_status); //printf("switch_status : %d\n",switch_status); if(switch_status > 50) switch_status = 50; // Loop running for 6 unit of time // for Optimization Level Os : j = 4600000 ; // for No Optimization : j = 3444 for(i=0; i<switch_status; i++){ for(j=0; j<4600000; j++){ } } printf("After loop : Time : %d \n", alt_timestamp() / (alt_timestamp_freq()/1000)); OSSemPend(Sem_DYNAMIC_UTI, 0, &err); if(err == OS_ERR_NONE) { } else { printf("Sem_DYNAMIC_UTI Pend Error ------ \n"); } } }
int main(void){ //func1(); //Comment top and uncomment this from altera alt_u32 time1; alt_u32 time2; alt_u32 time3; int tamfiltro=5,modo=0,w,h,j; unsigned char** matriz; unsigned char** newmatriz; int filtro[24]; int ow,oh; matriz=pgmread(filename,&h,&w); if (tamfiltro > 0){ rellenar_filtro(filtro,tamfiltro,modo); ow=w-(tamfiltro-1); oh=h-(tamfiltro-1); newmatriz = calloc(ow, sizeof(unsigned char*)); for (j=0;j<ow;j++){ if (( newmatriz[j] = calloc(oh, sizeof(unsigned char))) == NULL){ printf("Memory allocation error. Exit program\n"); exit(1); } } printf("I ended creating the row %d \n", j); } if (alt_timestamp_start() < 0) { printf ("No timestamp device available\n"); } else { time1 = alt_timestamp(); aplicarfiltro(matriz,filtro,newmatriz,ow,oh,tamfiltro); time2 = alt_timestamp(); //func2(); /* second function to monitor */ //time3 = alt_timestamp(); printf ("time in func1 = %u ticks\n", (unsigned int) (time2 - time1)); pgmwrite(outname,ow,oh,newmatriz,"",1); pritnf("Image created successfully\n"); /*printf ("time in func2 = %u ticks\n", (unsigned int) (time3 - time2)); printf ("Number of ticks per second = %u\n", (unsigned int)alt_timestamp_freq()); }*/ return 0; } }
alt_u32 millis(){ #ifdef DEBUG //printf("Current System Time: %i \n", alt_timestamp()); #endif return (alt_timestamp()/TicksPerSecond)*1000; }
int time_audio(unsigned int **arr) { double timer,freq,total; int f = alt_timestamp_start(); play_wav(arr); timer = alt_timestamp(); freq = alt_timestamp_freq(); total = (int)((timer * 1000)/freq); return total; }
//Increments to next players turn void setPlayerTurn() { alt_timestamp_start(); start_time = (float) alt_timestamp() / (float) alt_timestamp_freq(); int playerStatus; do { turn = (turn + 1) % numPlayers; playerStatus = p[turn].alive; } while (playerStatus == DEAD); printf("turn %i\n", turn); p[turn].gas = 100; }
/* * This is the wrapper for the task that executes rendundantly on both cores * There is one VERY important thing to note. When the critical task begins executing * the value of the stack pointer MUST be the same on both cores. This means that * the wrapper must have the same number of variables declared within its scope (i.e. * onto its stack) before calling the critical task (pt() in this example) */ void preemption_task(void* pdata){ int done = 0; int first = 0; int t_os; CriticalFunctionPointers* cp = (CriticalFunctionPointers*) SHARED_MEMORY_BASE; pt = cp->task[1]; while(1){ // Get initial time, then wait for 2 ticks t_os = OSTimeGet(); OSTimeDly(2 - t_os); //This is a crude way of synchronizing the beginning of the task //on both cores while (done == 0) { altera_avalon_mutex_lock(mutex, 1); //Acquire the hardware mutex { if(first == 0){ cp->checkout[1] = 1; first = 1; } if( cp->checkout[0] == 1){ cp->checkout[0] = 0; done = 1; } } altera_avalon_mutex_unlock(mutex); } // Set default block size for fingerprinting fprint_set_block_size(cp->blocksize[1]); //Context switch is necessary to clear the callee saved registers long registers[8]; context_switch(registers); //Set the global pointer in case of compilation issues related //to global variables set_gp(); //call the critical task pt(cp->args[1]); //restore the original global pointer restore_gp(); //Restore the callee saved registers context_restore(registers); //Get the end time alt_u64 t = alt_timestamp(); //store the end time cp->core_time[1] = t; } }
int main(void){ //IOWR_32DIRECT(0x00800000, OFFSET*i, 1); //Direccion base de la memoria, desplazamiento y dato a escribir //IORD_32DIRECT(0x00000000, 0); //Direccion base de la memoria y desplazamiento (lectura) int pruebas=200; alt_u32 time1; alt_u32 time2; alt_u32 time3; alt_u32 time4; alt_u32 time5; alt_u32 time6; int i=0, j=0; alt_u8 OFFSET=sizeof(int); alt_u8 DESPI=0, DESPJ=0; if (alt_timestamp_start() < 0) { printf ("No timestamp device available\n"); } else { time1 = alt_timestamp(); //Podemos hacerlo asi o con puntero for(i=0; i<pruebas; i++){ //SRAM IOWR_32DIRECT(0x01000000, DESPI, 1); //Direccion base de la memoria, desplazamiento y dato a escribir DESPI+=OFFSET; } time2 = alt_timestamp(); for(j=0; j<pruebas; j++){ //SDRAM IOWR_32DIRECT(0x00100000, DESPJ, 1); //Direccion base de la memoria, desplazamiento y dato a escribir DESPJ+=OFFSET; } time3 = alt_timestamp(); DESPI=0; DESPJ=0; printf ("time in write SDRAM = %u ticks\n", (unsigned int) (time2 - time1)); printf ("time in write SRAM = %u ticks\n", (unsigned int) (time3 - time2)); //LECTURA time4 = alt_timestamp(); for(i=0; i<pruebas; i++){ IORD_32DIRECT(0x01000000, DESPI); //Direccion base de la memoria, desplazamiento y dato a escribir DESPI+=OFFSET; } time5 = alt_timestamp(); for(j=0; j<pruebas; j++){ IORD_32DIRECT(0x00100000, DESPJ); //Direccion base de la memoria, desplazamiento y dato a escribir DESPJ+=OFFSET; } time6 = alt_timestamp(); printf ("time in read SDRAM = %u ticks\n", (unsigned int) (time5 - time4)); printf ("time in read SRAM = %u ticks\n", (unsigned int) (time6 - time5)); } return 0; }
void usb_initialization(){ printf("USB Initialization\n"); alt_up_usb_dev * usb_dev; usb_dev = alt_up_usb_open_dev(USB_0_NAME); assert(usb_dev); usb_device_init(usb_dev, USB_0_IRQ); printf("Polling USB device. Run middleman now!\n"); alt_timestamp_start(); int clocks = 0; while (clocks < 50000000 * 10) { clocks = alt_timestamp(); usb_device_poll(); } printf("Done polling USB\n"); }
int main(void) { // Start the timestamp -- will be used for seeding the random number generator. alt_timestamp_start(); sdcard_handle *sd_dev = init_sdcard(); initAudio(); loadMusic("Title2.wav", 1, 0.25); // Set latch and clock to 0. IOWR_8DIRECT(controller_out, 0, 0x00); init_display(); clear_display(); if (sd_dev == NULL) return 1; printf("Card connected.\n"); ticks_per_sec = alt_ticks_per_second(); seed(alt_timestamp()); alt_u32 tickCount = alt_nticks(); num_ticks = ticks_per_sec / 60; //alt_alarm *update_alarm = malloc(sizeof(alt_alarm)); //alt_alarm_start(update_alarm, num_ticks, update, (void*)0); while (true) { if (alt_nticks() - tickCount >= num_ticks) { tickCount = alt_nticks(); update(0); } } return 0; }
int main(void) { /* Related object data */ system_t* system; player_t* player1; player_t* player2; alt_timestamp_start(); int start_time = alt_timestamp(); int wind; int restart = 0; /* initialize all hardware dev */ system = system_init(VIDEO_PIXEL_BUFFER_DMA_NAME, "/dev/video_character_buffer_with_dma_0", ALTERA_UP_SD_CARD_AVALON_INTERFACE_0_NAME, PS2_0_NAME); if (!alt_up_sd_card_is_Present()) { printf("SD card not present\n"); return -2; } else { printf("SD card detected.\n"); } if (!alt_up_sd_card_is_FAT16()) { printf("SD card is not FAT16.\n"); return -3; } else { printf("SD card is FAT 16.\n"); } fireSound = initSoundbank("shotgun.wav"); explosionSound = initSoundbank("big_bomb.wav"); printf("Done Initializing\n"); int end_time = alt_timestamp(); srand(end_time - start_time); clearScreen(system); printf("Press enter to start game"); restartGame(system); while (restart == 1) { /* initialize required objects */ player1 = makePlayer(1, "Lomash"); player2 = makePlayer(2, "TJ"); /* * Draw the screen for the first time. */ store_background_data(); draw_background(system); drawPlayers(system); draw_ground(system); draw_windbox(system); draw_player1GUI(system); draw_player2GUI(system); update_wind(system, wind); draw_health(player1, system); draw_health(player2, system); update_power(player1, system); update_power(player2, system); usleep(2000000); // sleep to wait for video buffer to load while (TRUE) { printf( "\n\n\n\n===========================================================\n"); printf("Player 1 Health = %d \t\t Player 2 Health = %d\n", player1->health, player2->health); wind = rand() % 11 - 5; draw_windbox(system); update_wind(system, wind); // Player 1's turn player_1_jump(system); player_1_jump(system); printf("Getting Player 1 Power.\n"); getKeyboardInput(1, player1, system); // Power skipOneEnter(system); printf("Getting Player 1 Angle.\n"); getKeyboardInput(2, player1, system); // Angle // Player 1 Animation printf("Starting animation\n"); clear_angle_drawer(system); animate_cannon1(system); playSound(fireSound, system->audio); switch (animateShooting(system, player1, wind)) { // different value for result case 1: { update_health(player2, system, -DAMAGE); printf( "Player 1 hit player 2.\n Remaining Health for Player 2: %d\n", player2->health); break; } case 2: { update_health(player1, system, -DAMAGE); printf( "Player 1 hit player 1.\n Remaining Health for Player 1: %d\n", player1->health); break; } default: { break; } } printf("Ended animation\n"); // Post-animation Calculation if (player1->health <= 0 || player2->health <= 0) { break; } // Player 2's turn wind = rand() % 11 - 5; draw_windbox(system); update_wind(system, wind); player_2_jump(system); player_2_jump(system); printf("Getting Player 2 Velocity.\n"); getKeyboardInput(1, player2, system); // Player 2 Angle-Selection skipOneEnter(system); printf("Getting Player 2 Angle.\n"); getKeyboardInput(2, player2, system); // Player 2 Animation printf("Starting animation\n"); clear_angle_drawer(system); animate_cannon2(system); playSound(fireSound, system->audio); // Post-animation Calculation switch (animateShooting(system, player2, wind)) { // different value for result case 1: { update_health(player1, system, -DAMAGE); printf( "Player 2 hit player 1.\n Remaining Health for Player 1: %d\n", player1->health); break; } case 2: { update_health(player2, system, -DAMAGE); printf( "Player 2 hit player 2.\n Remaining Health for Player 2: %d\n", player2->health); break; } default: { break; } } if (player1->health <= 0 || player2->health <= 0) { break; } }; /* * Find out who won. */ if (player1->health <= 0) { printf("Player 2 Wins!!! \n"); draw_P2WIN(system); } else if (player2->health <= 0) { printf("Player 1 Wins!!!\n"); draw_P1WIN(system); } else { printf("we shouldn't be here.\n"); } restart = restartGame(system); } return 0; // FIN }
// Test code from lab void timer_test(void) { int freq; int cycles; float duration; int ticks_start; int ticks_end; int ticks_per_s; int ticks_duration; int timer_period; int status; int done; printf("Timers\n"); printf(" Sys Clock Timer\n"); ticks_per_s = alt_ticks_per_second(); printf("Tick Freq: %d\n", ticks_per_s); printf(" Recording starting ticks\n"); ticks_start = alt_nticks(); printf(" Sleeping for 5 seconds\n"); usleep(5000000); printf(" Recording ending ticks\n"); ticks_end = alt_nticks(); ticks_duration = ticks_end -ticks_start; duration = (float) ticks_duration / (float) ticks_per_s; printf(" The program slept for %d ticks (%f seconds)\n\n", ticks_duration, duration); printf(" Timestamp Timer\n"); freq = alt_timestamp_freq(); printf(" CPU Freq: %d\n", freq); printf(" Resetting Timestamp timer\n"); alt_timestamp_start(); printf(" ...Timing the print of this statement...\n"); cycles = alt_timestamp(); duration = (float) cycles / (float) freq; printf(" It took %d cycles (%f seconds) to print the statement\n\n", cycles, duration); printf(" Hardware-Only Timer\n"); printf(" Setting timer period to 5 seconds.\n"); timer_period = 5 * CLOCK_FREQ; // Setting the period registers must be done in 2 steps as they are only 16 bits wide IOWR_16DIRECT(MY_HW_ONLY_TIMER_BASE, 8, timer_period & 0xFFFF); // less significant word IOWR_16DIRECT(MY_HW_ONLY_TIMER_BASE,12, timer_period >> 16); // more significant word printf(" Stopping Timer\n"); status = IORD_16DIRECT(MY_HW_ONLY_TIMER_BASE, 0); // read status registers // Write the control registers if(status & 0x2) { IOWR_16DIRECT(MY_HW_ONLY_TIMER_BASE, 4, 1 << 3); // stop the timer if it was started } printf(" Starting Timer\n"); IOWR_16DIRECT(MY_HW_ONLY_TIMER_BASE, 4, 1 << 2); // start the timer printf(" Waiting for timer to expire...\n"); done = 0; while(! done) { status = IORD_16DIRECT(MY_HW_ONLY_TIMER_BASE, 0); // read status registers done = status & 0x1; } printf(" 5 seconds timer is done\n"); }
void SensorDataManagerTask(void* pdata){ int8_t cnt = 0; int16_t rawData[9]; int8_t err = NO_ERR; INT8U os_err = OS_ERR_NONE; //start uint32_t start = alt_timestamp(); uint32_t stop = 0; if (alt_timestamp() == 0 && alt_timestamp_start() < 0) { printf("ERROR starting timer"); } while(1){ //Semaphore for periodic task OSSemPend(sensorDataManageTaskSem, 0, &os_err); start = alt_timestamp(); err = readSensorData(rawData); //get newRawData acclX[cnt] = rawData[0]; //fill arrays with new raw data acclY[cnt] = rawData[1]; acclZ[cnt] = rawData[2]; gyroX[cnt] = rawData[3] - gyroOffsets[0]; //sensor Offsets are only available for gyrodata gyroY[cnt] = rawData[4] - gyroOffsets[1]; gyroZ[cnt] = rawData[5] - gyroOffsets[2]; compX[cnt] = rawData[6]; compY[cnt] = rawData[7]; compZ[cnt] = rawData[8]; cnt++; if(cnt>=20){ err = avgAllArrays(); //measure sensor sampling time stop = alt_timestamp(); averagedDataDeltaT = (stop - start) / 50; //*1000/alt_ticks_per_second(); //calculate the time needed to get all sensordata in system Ticks/ micro seconds if (alt_timestamp() == 0 && alt_timestamp_start() < 0) { printf("ERROR starting timer"); } SDM_NEW_DATA_AVAILABLE = 1; //new data is available } cnt = cnt % VALUE_NUM; //cnt goes from 0 to VALUE_NUM and then starts with 0 again OSTimeDlyHMSM(0, 0, 0, 10); //uncomment if sensordata reading is to fast for the i2c interface -> set delay to appropriate value } }
void WatchDog(void* pdata) { INT8U err; printf("WatchDog Task created! : Ticks : %d\n",(int) alt_timestamp_freq() ); Sem_WDT_Signal = OSSemCreate(0); while(1) { OSSemPend(Sem_WDT_Signal, WatchDog_PERIOD, &err); if(err == OS_ERR_NONE){ //if(DEBUG_OLD) //printf(" OK \n"); } else { //printf("Pend Error\n"); if(err == OS_ERR_TIMEOUT) printf("------ Watchdog Timer ALERT : Over Load Detected ------- : %d \n",(int) (alt_timestamp() / (alt_timestamp_freq()/1000))); if(err == OS_ERR_PEND_LOCKED) printf("SEM got LOCKED \n\n"); } } }
/* * The task 'VehicleTask' updates the current velocity of the vehicle */ void VehicleTask(void* pdata) { INT8U err, err_tmr_1, err_tmr_start, err_sem; void* msg; INT8U* throttle; INT8S acceleration; /* Value between 40 and -20 (4.0 m/s^2 and -2.0 m/s^2) */ INT8S retardation; /* Value between 20 and -10 (2.0 m/s^2 and -1.0 m/s^2) */ INT16U position = 0; /* Value between 0 and 20000 (0.0 m and 2000.0 m) */ INT16S wind_factor; /* Value between -10 and 20 (2.0 m/s^2 and -1.0 m/s^2) */ Sem_VehicleTask = OSSemCreate(0); //OSSemPend(Sem_VehicleTask,0,&err_sem); printf("Vehicle task created!\n"); SWTimer_VehicleTask = OSTmrCreate(0, VEHICLE_PERIOD, OS_TMR_OPT_PERIODIC, Tmr_Callback_Vehicle_Task, (void *)0,"S/W Timer 2",&err_tmr_1); if(err_tmr_1 == OS_ERR_NONE){ if(DEBUG) printf("Timer for VECHICLE TASK is created\n"); OSTmrStart(SWTimer_VehicleTask, &err_tmr_start); if(err_tmr_start == OS_ERR_NONE){ if(DEBUG) printf("Timer started in VEHICLE TASK \n"); } else { printf("Problem starting timer in VEHICLE TASK \n"); } } else { printf("Error while creating Vehicle task timer \n"); if(err_tmr_1 == OS_ERR_TMR_INVALID_DLY) printf(" Delay INVALID : VEHICLE TASK\n"); } while(1) { // Wait for user inputs OSSemPend(Sem_SwitchIO_IP , 0, &err_sem); OSSemPend(Sem_ButtonIO_IP, 0, &err_sem); if((brake_pedal == on) && (CUR_VELOCITY > 0)){ CUR_VELOCITY = CUR_VELOCITY - 10; // if(CUR_VELOCITY < -200) // Max value for velocity //CUR_VELOCITY = -200; if(DEBUG_IO) printf("********** Brake brake_pedal : %d ********** \n", CUR_VELOCITY); } err = OSMboxPost(Mbox_Velocity, (void *) &CUR_VELOCITY); if(DEBUG) printf("Vehicle task Posted MBoxPost_Velocity \n"); if(DEBUG) printf("SEM ACCESS VEHICLE TASK\n\n"); OSSemPend(Sem_VehicleTask,0,&err_sem); /* Non-blocking read of mailbox: - message in mailbox: update throttle - no message: use old throttle */ if(DEBUG) printf("Vehicle task waiting for MBoxPost_Throttle for 1 unit time \n"); msg = OSMboxPend(Mbox_Throttle, 1, &err); if (err == OS_NO_ERR) throttle = (INT8U*) msg; if(DEBUG) printf("Vehicle task GOT MBoxPost_Throttle \n"); /* Retardation : Factor of Terrain and Wind Resistance */ if (CUR_VELOCITY > 0) wind_factor = CUR_VELOCITY * CUR_VELOCITY / 10000 + 1; else wind_factor = (-1) * CUR_VELOCITY * CUR_VELOCITY / 10000 + 1; if (position < 4000) retardation = wind_factor; // even ground else if (position < 8000) retardation = wind_factor + 15; // traveling uphill else if (position < 12000) retardation = wind_factor + 25; // traveling steep uphill else if (position < 16000) retardation = wind_factor; // even ground else if (position < 20000) retardation = wind_factor - 10; //traveling downhill else retardation = wind_factor - 5 ; // traveling steep downhill acceleration = *throttle / 2 - retardation; position = adjust_position(position, CUR_VELOCITY, acceleration, 300); CUR_VELOCITY = adjust_velocity(CUR_VELOCITY, acceleration, brake_pedal, 300); printf("Position: %dm\n", position / 10); printf("Velocity: %4.1fm/s\n", CUR_VELOCITY /10.0); printf("Throttle: %dV Time : %d \n\n", *throttle / 10, (int) (alt_timestamp() / (alt_timestamp_freq()/1000))); alt_timestamp_start(); /* INT32U stk_size; err = OSTaskStkChk(16, &stk_data); stk_size = stk_data.OSUsed; printf("Stack Used OverLoadDetection : %d \n", stk_size); err = OSTaskStkChk(14, &stk_data); stk_size = stk_data.OSUsed; printf("Stack Used DYNAMIV_UTI : %d \n", stk_size); err = OSTaskStkChk(12, &stk_data); stk_size = stk_data.OSUsed; printf("Stack Used CONTROLTASK: %d \n", stk_size); err = OSTaskStkChk(10, &stk_data); stk_size = stk_data.OSUsed; printf("Stack Used VehicleTask: %d \n", stk_size); err = OSTaskStkChk(8, &stk_data); stk_size = stk_data.OSUsed; printf("Stack Used SwitchIO: %d \n", stk_size); err = OSTaskStkChk(7, &stk_data); stk_size = stk_data.OSUsed; printf("Stack Used ButtonIO: %d \n", stk_size); err = OSTaskStkChk(6, &stk_data); stk_size = stk_data.OSUsed; printf("Stack Used WatchDog: %d \n", stk_size); err = OSTaskStkChk(5, &stk_data); stk_size = stk_data.OSUsed; printf("Stack Used Start Task: %d \n", stk_size); */ show_velocity_on_sevenseg((INT8S) (CUR_VELOCITY / 10)); show_active_signals(); show_position(position); // OSSemPend(Sem_VehicleTask,0,&err_sem); } }
int main() { char readBuffer[READ_BUFFER_SIZE]; int numRead = 0; alt_16 gyroAccelDATAToSend[NUM_SENSOR_VALUES*20] = {0}; int wantData = 0; //The time when we begin collecting the line alt_timestamp_type kalmanBeginTime; //The time when the line has been collected alt_timestamp_type kalmanEndTime; int numSend; int i; //Holds the timestamp that we send over float times[NUM_SENSOR_VALUES]; //Number of bytes that we sent over //The bluetooth file descriptor int fd; // File poiner to uart_0 phjones added FILE *fp; // Open file for read and write fp = fopen("/dev/uart_0", "r+"); /*------------------------------------------- Set input to be nonblocking -------------------------------------------*/ fd = fileno(fp); fcntl(fd, F_SETFL, O_NONBLOCK); //If the file could be opened print opened as well as the file descriptor if (fd != 0) { printf("new main opened file!=%d\n\r", fd); } //Otherwise it was not able to be opend else { printf("NOT opened :-( \n\r"); } //Start the timestamp alt_timestamp_start(); if (alt_timestamp_start() < 0) { printf("No timestamp device available\n"); } for(i = 0; i < 2000; i++){ gyroAccelDATAToSend[i] = i; } while(1){ while (wantData == 0) { /*------------------------------------------- Nonblocking read: returns 0 if nothing there -------------------------------------------*/ numRead = read(fd, readBuffer, READ_BUFFER_SIZE - 1); //If something is read if (numRead > 0) { //Print out what was read, if it was an a set wantData to true //so we leave this while loop printf("Read %c", readBuffer[0]); if (readBuffer[0] == 'a') { printf("Read a\n"); wantData = 1; } } } //Gather the data for NUM_SENSOR_VALUES times for (i = 0; i < NUM_SENSOR_VALUES; i++) { //printf("%d\n", currentHeliState.gyroX); //Set the timestamp to 0 kalmanBeginTime = alt_timestamp_start(); //If the timestamp is not available print this out if (kalmanBeginTime < 0) { printf("No timestamp device available\n"); } //Set the timestamp to 0 //kalmanBeginTime = alt_timestamp_start(); //If the timestamp is not available print this out //if (kalmanBeginTime < 0) { // printf("No timestamp device available\n"); //} /*------------------------------------------- Get IMU data -------------------------------------------*/ readUsefulIMU(); // phjones removed LWMULKEY ADDED /*------------------------------------------- Load the IMU data into the buffer to be sent away from board. -------------------------------------------*/ usleep(1000); gyroAccelDATAToSend[1 + i * 10] = currentHeliState.gyroX; gyroAccelDATAToSend[2 + i * 10] = currentHeliState.gyroY; gyroAccelDATAToSend[3 + i * 10] = currentHeliState.gyroZ; gyroAccelDATAToSend[4 + i * 10] = currentHeliState.accelX; gyroAccelDATAToSend[5 + i * 10] = currentHeliState.accelY; gyroAccelDATAToSend[6 + i * 10] = currentHeliState.accelZ; gyroAccelDATAToSend[7 + i * 10] = currentHeliState.magX; gyroAccelDATAToSend[8 + i * 10] = currentHeliState.magY; gyroAccelDATAToSend[9 + i * 10] = currentHeliState.magZ; /** This is for testing purposes gyroAccelDATAToSend[1 + i * 10] = i; gyroAccelDATAToSend[2 + i * 10] = i; gyroAccelDATAToSend[3system library properties + i * 10] = i; gyroAccelDATAToSend[4 + i * 10] = i; gyroAccelDATAToSend[5 + i * 10] = i; gyroAccelDATAToSend[6 + i * 10] = i; gyroAccelDATAToSend[7 + i * 10] = i; gyroAccelDATAToSend[8 + i * 10] = i; gyroAccelDATAToSend[9 + i * 10] = i;**/ //End the timestamp to get the end time //kalmanEndTime = alt_timestamp(); //The timestamp is taken in ms //my_stamp = ((kalmanEndTime - kalmanBeginTime) * 20.0)/ 1000000; // pjones ROOT CAUSE //times[i] = my_stamp; //gyroAccelDATAToSend[i*10] = //times[i] = i; //End the timestamp to get the end time kalmanEndTime = alt_timestamp(); //The timestamp is taken in ms times[i] = (((float) (kalmanEndTime - kalmanBeginTime) * 20)/ 1000000); //printf("%i %f\n",i, times[i]); } alt_8 *toSend_ptr; toSend_ptr = (alt_8 *) gyroAccelDATAToSend; alt_8 *toSend_ptr2 = (alt_8 *) times; int bytes = 0; int i; /*for(i=0; i < 400; i++){ printf("%x ",toSend_ptr2[i]); }*/ //numSend = 0; //Make sure that we send all of the values //It is times 2 since we send the accelerometer, gyroscope, and magnetometer data //seperately from the timestamp data //while (numSend != NUM_SENSOR_VALUES) { // printf("Waiting to send"); // //First we have to read an a or a b to know which piece of data we should be sending // numRead = read(fd, readBuffer, READ_BUFFER_SIZE - 1); // //if we read something, check to see if it is an a or a b // if (numRead > 0) { // //If we read an a send over the gyro, accel, and mag data // if (readBuffer[0] == 'a') { //printf("Trying to send"); //Write the data to bluetooth //if (readBuffer[0] == 'c') { int j; for(j = 0; j < 100000; j++){ bytes = fwrite(toSend_ptr, 2, 1, fp); toSend_ptr+=2; } printf("\n\n%i", bytes); //toSend_ptr = toSend_ptr + 2000; //numSend++; //} //printf("Sent = %d", numSent); //Increment the pointer and numSend // //Testing to see if this works /*bytes = 0; int j=0; for(j=0;j<400;j++){ bytes = fwrite(toSend_ptr2, 1, 1, fp); toSend_ptr2 += 1; if(bytes = 0){ printf("Lost Byte"); } }*/ // //Increment the pointer and numSend // printf("Finished sending"); // } // } // } wantData = 0; } return 0; }
/* * Main Game Loop */ int main() { // Use the name of your pixel buffer DMA core pixel_buffer =alt_up_pixel_buffer_dma_open_dev("/dev/pixel_buffer_dma_0"); initVGA(); usleep(5000000); ps2 = alt_up_ps2_open_dev("/dev/ps2_0"); ps2->timeout = 2000000; alt_up_ps2_clear_fifo(ps2); alt_up_ps2_init(ps2); unsigned char byte1; while(alt_up_ps2_read_data_byte(ps2, &byte1)!=0); char_lcd_dev = alt_up_character_lcd_open_dev ("/dev/character_lcd_0"); alt_up_character_lcd_init (char_lcd_dev); char_buffer = alt_up_char_buffer_open_dev("/dev/char_drawer"); alt_up_char_buffer_init(char_buffer); alt_up_sd_card_dev *device_reference = NULL; struct Env* p = initEnv(); initGameInfo(); struct Collidable* collisionChecker = initCollidable(); addCollisionToEnv(p, collisionChecker); promptSDcard(p, device_reference); usleep(1000); alt_up_char_buffer_string(char_buffer, "Loading ", 40, 30); unsigned end_time, start_time; int count = 0; lock = 0; struct animation* starAnimation = loadSDImageSeq("ST0.BMP", 2, 8); struct animation* star2Animation = loadSDImageSeq("ST00.BMP", 3, 7); struct animation* alien0 = loadSDImageSeq("A100.BMP", 2, 2); //2 images where first 2 characters are prefix struct animation* alien1 = loadSDImageSeq("A000.BMP", 2, 15); struct animation* ship0 = loadSDImageSeq("S00.BMP", 2, 16); struct animation* ship1 = loadSDImageSeq("S10.BMP", 2, 27); struct animation* bossAnimate = loadSDImageSeq("BO00.BMP", 2, 28); struct animation* ship2 = loadSDImageSeq("S20.BMP", 2, 35); struct animation* ship3 = loadSDImageSeq("S30.BMP", 2, 30); struct animation* ship4 = loadSDImageSeq("S40.BMP", 2, 10); struct animation* explode1 = initAnimation((int*)explode01, 1); addImage(explode1, initAnimation((int*)explode02, 0)); addImage(explode1, initAnimation((int*)explode03, 0)); addImage(explode1, initAnimation((int*)explode04, 0)); addImage(explode1, initAnimation((int*)explode05, 0)); struct animation** shipAnimationCollection = (struct animation**)malloc(sizeof(struct animation*)*5); shipAnimationCollection[0] = ship0; shipAnimationCollection[1] = ship1; shipAnimationCollection[2] = ship2; shipAnimationCollection[3] = ship3; shipAnimationCollection[4] = ship4; initWeapon(collisionChecker, p); struct Cursor* mouse = initCursor(p, collisionChecker); addToEnv(p, mouse->super); addObjToCollide(collisionChecker, mouse->super); setCursor(p, mouse); struct KeyController* keyController = initKeyController(); struct SwitchController* switchController = initSwitchController(); struct CursorController* ctrl = initCursorController(mouse->super, switchController, keyController); alt_up_char_buffer_string(char_buffer, "Loading Sounds ", 30, 30); audioController = initAudioController(); loadSound( audioController, LOOP_ONE ); loadSound( audioController, LASER_SOUND ); alt_irq_register(AUDIO_IRQ, audioController, (void*) audio_ISR); alt_irq_enable(AUDIO_IRQ); play_background_loop( audioController, LOOP_ONE ); enableAudioController( audioController ); printhex(info.score); mainMenu(mouse, ctrl, p); disableAudioController(audioController); stop_background_loop(audioController); unloadSoundById(audioController, LASER_SOUND); unloadSoundById(audioController, LOOP_ONE); alt_up_char_buffer_string(char_buffer, "Loading Sounds ", 30, 30); //loadSound(audioController, WIN_SOUND); //loadSound(audioController, LOSE_SOUND); loadSound( audioController, TOWER_UPGRADE_SOUND ); loadSound( audioController, LOOP_TWO ); play_background_loop(audioController, LOOP_TWO); enableAudioController( audioController ); alt_up_char_buffer_clear(char_buffer); //usleep(1000); struct Alien* testAlienCollection[60]; gameSetup(p, shipAnimationCollection, mouse, starAnimation, star2Animation); usleep(500000); //time delay for panel to be drawn // char LPS[50]; float lps_; int n = 0; for(n = 0; n < 20; n++) { testAlienCollection[n] =initAlien(n, 10*n, 10, alien0, explode1, "IdontKnow", 1.4, 150, 500, collisionChecker); addToEnvNR(p, testAlienCollection[n]->super); } for(n = 0; n < 20; n++) { testAlienCollection[n+20] =initAlien(10*n, n, 10, alien1, explode1, "whatName", 1.4, 190, 850, collisionChecker); addToEnvNR(p, testAlienCollection[n+20]->super); } for(n = 0; n < 20; n++) { testAlienCollection[n+40] =initAlien(10*n, n, 20, bossAnimate, explode1, "IamBoss", 1.6, 800, 1500, collisionChecker); testAlienCollection[n+40]->score = 300; addToEnvNR(p, testAlienCollection[n+40]->super); } int stage = 0; /* * Game Starts!!!!!! */ alt_alarm_start (&alarm,alt_ticks_per_second(),my_alarm_callback,(void*)p); int startTimer = 0; char second_row1[15]; alt_up_character_lcd_set_cursor_pos(char_lcd_dev, 0, 1); sprintf(second_row1, "wave# %d ", stage); alt_up_character_lcd_string(char_lcd_dev, second_row1); while(1) { alt_timestamp_start(); start_time = (unsigned)alt_timestamp(); /*-----------------------------------------------------------------------------------------------*/ checkCollision(collisionChecker); //a major function that check each collision happen between each object updateCursorController(ctrl, 1); count++; if (startTimer > count) info.startButton = false; else { if(stage == 7) info.isWin = true; else if(startTimer == count){ //play_background_loop(audioController, LOOP_TWO); enableAudioController( audioController ); } } if (info.startButton){ disableAudioController(audioController); //stop_background_loop(audioController); startTimer = count + 15000; checkStages(testAlienCollection, stage%7, collisionChecker); stage++; //if(stage > 6) stage = 0; info.startButton = false; alt_up_character_lcd_set_cursor_pos(char_lcd_dev, 0, 1); sprintf(second_row1, "wave# %d ", stage); alt_up_character_lcd_string(char_lcd_dev, second_row1); } if(info.isEnd || info.isWin) { disableAudioController(audioController); stop_background_loop(audioController); endGame(testAlienCollection, collisionChecker, p, mouse, ctrl, keyController); } /*-----------------------------------------------------------------------------------------------*/ end_time = (unsigned)alt_timestamp(); lps_ = (float)alt_timestamp_freq()/(float)(end_time - start_time); sprintf(LPS, "The current LPS is %.2f", lps_); alt_up_char_buffer_string(char_buffer, LPS, 3, 2); } return 0; }
// YOLOYOLO int main() { printf("\n\n\n----- STARTING A NEW GAME -----"); init(); printf("\nInitialization complete."); srand(alt_timestamp()); // TODO change in de2 env int i; int new_player_count = 2; bool first_game = true; GameState state = SETUP; for (;;) { switch (state) { case SETUP: printf("\n\n----- ENTERING SETUP STATE -----\n\n"); initialize_dealer(new_player_count); printf("Initialized dealer."); joining_period(); /* Move dealer chip to the next player */ if (dealer_chip == dealer->number_players-1) dealer_chip = 0; else dealer_chip++; state = DEAL_HANDS; break; case DEAL_HANDS: printf("\n\n ----- ENTERING DEAL_HANDS STATE -----\n\n"); deal_hands(); send_player_hands(); for (i=0; i<dealer->number_players; i++) { printf("\n\nDealt cards for Player %d: Suite %d, Value %d & Suite %d, Value %d", i, dealer->players[i].hand[0].suite, dealer->players[i].hand[0].value, dealer->players[i].hand[1].suite, dealer->players[i].hand[1].value); } state = ANTY_CALL; break; case FLOP: flop(); printf("\n\n----------------------------------------"); printf("\nFLOP (%s) (%s) (%s) \n", card_name(dealer->cards_on_table[0]), card_name(dealer->cards_on_table[1]), card_name(dealer->cards_on_table[2])); state = BET; break; case TURN: turn(); printf("\n\n----------------------------------------"); printf("\nTURN (%s) (%s) (%s) (%s) \n", card_name(dealer->cards_on_table[0]), card_name(dealer->cards_on_table[1]), card_name(dealer->cards_on_table[2]), card_name(dealer->cards_on_table[3])); state = BET; break; case RIVER: river(); printf("\n\n----------------------------------------"); printf("\nRIVER (%s) (%s) (%s) (%s) (%s) \n", card_name(dealer->cards_on_table[0]), card_name(dealer->cards_on_table[1]), card_name(dealer->cards_on_table[2]), card_name(dealer->cards_on_table[3]), card_name(dealer->cards_on_table[4])); state = BET; break; case ANTY_CALL: printf("\nCalling anty from all players"); get_bet_for_player(dealer_chip); if (dealer_chip == dealer->number_players-1) { for (i=0; i<dealer->number_players-1; i++) { if (dealer->players[i].active) { get_bet_for_player(i); if (dealer->number_active_players == 1) {state = GAME_OVER; goto HOTSTUFF;} } } } else { for (i=dealer_chip+1; i<dealer->number_players; i++) { if (dealer->players[i].active) { get_bet_for_player(i); if (dealer->number_active_players == 1) {state = GAME_OVER; goto HOTSTUFF;} } } for (i=0; i<dealer_chip; i++) { if (dealer->players[i].active) { get_bet_for_player(i); if (dealer->number_active_players == 1) {state = GAME_OVER; goto HOTSTUFF;} } } } /* Put bet money into the pot */ for (i=0; i<dealer->number_players; i++) { dealer->pot += dealer->players[i].money; dealer->players[i].money = 0; dealer->current_bet = 0; } printf("\n----------------------------------------\n"); printf("\nPOT %d", dealer->pot); printf("\n----------------------------------------\n"); state = BET; break; case BET: for (i=0; i<dealer->number_players; i++) { if (dealer->players[i].active && dealer->players[i].total_money > 0) sprintf(dealer->players[i].message, " "); } /* Betting Round 1 */ get_bet_for_player(dealer_chip); if (dealer_chip == dealer->number_players-1) { for (i=0; i<dealer->number_players-1; i++) { if (dealer->players[i].active) { get_bet_for_player(i); if (dealer->number_active_players == 1) {state = GAME_OVER; goto HOTSTUFF;} } } } else { for (i=dealer_chip+1; i<dealer->number_players; i++) { if (dealer->players[i].active) { get_bet_for_player(i); if (dealer->number_active_players == 1) {state = GAME_OVER; goto HOTSTUFF;} } } for (i=0; i<dealer_chip; i++) { if (dealer->players[i].active) { get_bet_for_player(i); if (dealer->number_active_players == 1) {state = GAME_OVER; goto HOTSTUFF;} } } } /* If still betting, continue that */ while (still_betting()) { for (i=dealer_chip; i<dealer->number_players; i++) { if (player_still_playing(i)) { get_bet_for_player(i); if (dealer->number_active_players == 1) {state = GAME_OVER; goto HOTSTUFF;} } } for (i=0; i<dealer_chip; i++) { if (player_still_playing(i)) { get_bet_for_player(i); if (dealer->number_active_players == 1) {state = GAME_OVER; goto HOTSTUFF;} } } } switch (dealer->number_cards_on_table) { case 0: state = FLOP; break; case 3: state = TURN; break; case 4: state = RIVER; break; case 5: state = GAME_OVER; break; } HOTSTUFF:; /* Put bet money into the pot */ for (i=0; i<dealer->number_players; i++) { dealer->pot += dealer->players[i].money; dealer->players[i].money = 0; dealer->current_bet = 0; } printf("\n----------------------------------------\n"); printf("\nPOT %d", dealer->pot); printf("\n----------------------------------------\n"); break; case GAME_OVER: if (dealer->number_active_players > 1) { rank_poker_hands(); split_pot(); } else { last_man_standing(); } send_game_results(); printf("\n\nWaiting for response from all players.\n"); receive_replay_status(); state = SETUP; free(dealer->deck); free(dealer->players); free(dealer); free(ph); break; } game_screen(); } return 0; }
int main() { // INIT COMS cd = (Comm_data*) malloc(sizeof(Comm_data)); uart = init_clear_uart(cd); alt_timestamp_start(); srand(alt_timestamp()); CardCtrl *cardCtrl = (CardCtrl*)malloc(sizeof(CardCtrl)); PlayerCtrl* playerCtrl = (PlayerCtrl*)malloc(sizeof(PlayerCtrl)); initCards(cardCtrl); printf("Waiting for players\n"); while(connected_count < 3) { receivedFromAndroid(); } printf("Got all players\n"); initPlayers(playerCtrl, connected_count); int y; for (y = 0; y < connected_count; y++) { if (pid_connected[y] == 1) { tell_user_pid_role(y, playerCtrl->players[y]); Message message = receivedFromAndroid(); if (message.type == ACKNOWLEDGE); } } int i, j; for (i = 0; i < connected_count; i++) { drawCardsForId(i, cardCtrl, 2, playerCtrl); } field = malloc(sizeof(Field)); alt_up_char_buffer_dev *charBuffer = initCharBuffer(); alt_up_pixel_buffer_dma_dev *pixelBuffer = initPixelBuffer(); initField(field, playerCtrl, cardCtrl, charBuffer); *leds = *switches; alt_timestamp_start(); srand(alt_timestamp()); Message message; tell_user_all_opponent_range_role(playerCtrl->turn, getPlayersInfoForId(playerCtrl, playerCtrl->turn)); message = receivedFromAndroid(); if (message.type == ACKNOWLEDGE); tell_user_all_opponent_blue_lives(playerCtrl->turn, getPlayersInfoForId(playerCtrl, playerCtrl->turn)); message = receivedFromAndroid(); if (message.type == ACKNOWLEDGE); tell_user_their_turn(0); while (1){ int listening = 1; while (listening) { Message message = receivedFromAndroid(); switch (message.type) { case DRAW_CARDS: drawCardsForId(message.fromId, cardCtrl, message.count, playerCtrl); tell_user_ok(message.fromId); break; case UPDATE_HAND: updateHandForId(playerCtrl, message.fromId, message.count, message.cards); break; case UPDATE_BLUE: updateBlueCardsForId(playerCtrl, message.fromId, message.count, message.cards); tell_user_ok(message.fromId); break; case UPDATE_LIVES: updateLivesForId(playerCtrl, message.fromId, message.count); break; case GATLING: startGatling(playerCtrl, message.fromId); tell_user_ok(message.fromId); break; case ALIENS: startAliens(playerCtrl, message.fromId); tell_user_ok(message.fromId); break; case BEER: { //TODO //updateLivesForId(playerCtrl, message.fromId, message.count); Message message = receivedFromAndroid(); if (message.type == UPDATE_LIVES) updateLivesForId(playerCtrl, message.fromId, message.count); updateHand(message.fromId, playerCtrl); break; } case GENERAL_STORE: startStore(playerCtrl, message.fromId, cardCtrl); break; case SALOON: startSaloon(playerCtrl, message.fromId); tell_user_ok(message.fromId); break; case ZAP: { startZap(playerCtrl, message.toId, message.fromId, message.self); if (message.self == 0) { tell_user_ok(message.fromId); } break; } case PANIC: startPanic(playerCtrl, message.toId, message.fromId, message.self); if (message.self == 0) { tell_user_ok(message.fromId); } break; case CAT_BALOU: startCatBalou(playerCtrl, message.toId, message.fromId, message.self); if (message.self == 0) { tell_user_ok(message.fromId); } break; case DUEL: startDuel(playerCtrl, message.toId, message.fromId, message.self); if (message.self == 0) { tell_user_ok(message.fromId); } break; case JAIL: //TODO tell_user_jail(message.toId, message.cards); break; case END_TURN: listening = 0; break; default: break; } alt_up_char_buffer_clear(charBuffer); runField(field, isGameEnd, winningPlayer); } endTurn(playerCtrl); tell_user_all_opponent_range_role(playerCtrl->turn, getPlayersInfoForId(playerCtrl, playerCtrl->turn)); message = receivedFromAndroid(); if (message.type == ACKNOWLEDGE); tell_user_all_opponent_blue_lives(playerCtrl->turn, getPlayersInfoForId(playerCtrl, playerCtrl->turn)); message = receivedFromAndroid(); if (message.type == ACKNOWLEDGE); int y; for (y = 0; y < MAX_CARDS; y++ ) { if (playerCtrl->players[playerCtrl->turn].blueCards[y] >= 72 && playerCtrl->players[playerCtrl->turn].blueCards[y] <= 74) { drawCardsForId(playerCtrl->turn, cardCtrl, 1, playerCtrl); break; } } tell_user_their_turn(playerCtrl->turn); alt_up_char_buffer_clear(charBuffer); runField(field, isGameEnd, winningPlayer); } return 0; }
int main(void) { while (1) { state = 0; int setTime = 15; numPlayers = 2; initScreen(); clearScreen(); initCharBuffer(); clean_up(); initKeyboard(); initState0(); initAI(); //Bypass the menu system for testing if (IORD(keys,0) == 8) { initPlayer(pOne, MARIO, "pOne", 50, 100, HUMAN); initPlayer(pTwo, LUIGI, "pTwo", 50, 100, COMPUTER); state = 2; } else { while (state == 0) { decode_scancode(ps2, &decode_mode, buf, &ascii); state_0(decode_mode, buf[0]); }; initState1(pOne); if(aOn)file_handle = initAudio(fname); if(aOn)alt_irq_register(AUDIO_0_IRQ, &ab, (alt_isr_func) write_fifo); if(aOn) alt_up_audio_enable_write_interrupt(ab->audio); while (state == 1) { decode_scancode(ps2, &decode_mode, buf, &ascii); state_1(decode_mode, buf[0], ascii); if(aOn)loop_audio(file_handle, fname, ab); }; } //clean_up(); clearCharBuffer(); clearScreen(); //enable keyboard IRQ void* keyboard_control_register_ptr = (void*) (KEYBOARD_BASE + 4); alt_irq_register(KEYBOARD_IRQ, keyboard_control_register_ptr, keyboard_ISR); alt_up_ps2_enable_read_interrupt(ps2); //Draw field and UI to both buffers initField(); updateField(); drawName(p[pOne].name, p[pTwo].name, p[pThree].name, p[pFour].name); drawGas(p[pOne].gas); drawHealth(p[pOne].hp, p[pTwo].hp, p[pThree].hp, p[pFour].hp); drawBullet(p[pOne].bulletType); //drawWindIndicator(1); updateScreen(); updateField(); drawName(p[pOne].name, p[pTwo].name, p[pThree].name, p[pFour].name); drawGas(p[pOne].gas); drawHealth(p[pOne].hp, p[pTwo].hp, p[pThree].hp, p[pFour].hp); drawBullet(p[pOne].bulletType); //drawWindIndicator(1); float time; alt_timestamp_start(); int start_timer_flag = 1; //printf("NUM PLAYERA %i\n", numPlayers); int i; while (state == 2) { int fallFlag = 1; //Checks to see if any players are falling while (fallFlag == 1) { fallFlag = 0; for (i = 0; i < numPlayers; i++) { if (p[i].alive) { if (p[i].y + TANK_HEIGHT >= SCREEN_HEIGHT-1) { p[i].hp = 0; p[i].alive = DEAD; } checkPlayerFalling(i); if (p[i].isFalling) { undrawPlayer(i); updatePlayer(i); fallFlag = 1; } } } if (fallFlag == 1) { updateScreen(); } } if(start_timer_flag){ start_time = (float) alt_timestamp() / (float) alt_timestamp_freq(); start_timer_flag = 0; } time = (float) alt_timestamp() / (float) alt_timestamp_freq()-start_time; if (time >= setTime) { setPlayerTurn(); } if (p[turn].type == HUMAN) { runGame(); } else { p[turn].deg = 0; aiMain(turn); setPlayerTurn(); } printTimer(setTime - time); int deadCount = 0; for (i = 0; i < numPlayers; i++) { if (p[i].alive == DEAD) deadCount++; } if (deadCount == numPlayers - 1) { usleep(500000); state = 3; } } alt_up_ps2_disable_read_interrupt(ps2); if(aOn)alt_up_audio_disable_write_interrupt(ab->audio); GameOverScreen(); } }