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"); } } }
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"); } } }
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; }
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; }
/** * Initialises the system timestamp timer, and * sets the static Timer vars. */ int Timer_initTimestampTimer() { /* * NOTE: If this receives an error where is is not recognized, * the issue is that you must manually go into the bsp editor * and set sys_clk_timer to use none, and timestamp_timer to timer_0. * The bsp must then be re-generated. */ int tsStatus = alt_timestamp_start(); if (tsStatus != 0) { printf("Timestamp timer failed with status %d.\n", tsStatus); } else { printf("Timestamp timer initialised.\n"); s_timestampTimerFreq = (double)alt_timestamp_freq(); printf("Timer freq: %0.1f Hz\n", s_timestampTimerFreq); } s_timestampTimerStatus = tsStatus; return tsStatus; }
// 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"); }
/* * 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; }
/* * 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); } }
void setup() { #ifdef DEBUG printf("Config Starting \n"); #endif ANTUART = fopen("/dev/uart_0", "r+"); //ANTUART = open("/dev/uart_0" ,O_NONBLOCK | O_RDWR); if(ANTUART){;}else{ #ifdef DEBUG printf("Cannot open ANTUART"); #endif } // if(alt_timestamp_start() <= 0){ // printf("Timestamp init no working \n"); // } #ifdef DEBUG printf("Ticks Per Second: %i \n", alt_timestamp_freq()); #endif //alt_avalon_timer_sc_init (0x04011040, 2, 2, 1); // Reset sendPacket(MESG_SYSTEM_RESET_ID, 1, 0); if (checkReturn() == 0) errorHandler(errDefault); delay(1000); // Assign Channel // Channel: 0 // Channel Type: for Receive Channel // Network Number: 0 for Public Network sendPacket(MESG_ASSIGN_CHANNEL_ID, 3, ANT_CHAN, 0, ANT_NET); if (checkReturn() == 0) errorHandler(errDefault); // Set Channel ID // Channel Number: 0 // Device Number LSB: 0 for a slave to match any device // Device Number MSB: 0 for a slave to match any device // Device Type: bit 7 0 for pairing request bit 6..0 for device type // Transmission Type: 0 to match any transmission type sendPacket(MESG_CHANNEL_ID_ID, 5, ANT_CHAN, 0, 0, ANT_DEVICETYPE, 0); if (checkReturn() == 0) errorHandler(errDefault); // Set Network Key // Network Number // Key sendPacket(MESG_NETWORK_KEY_ID, 9, ANT_NET, antNetKey[0], antNetKey[1], antNetKey[2], antNetKey[3], antNetKey[4], antNetKey[5], antNetKey[6], antNetKey[7]); if (checkReturn() == 0) errorHandler(errDefault); // Set Channel Search Timeout // Channel // Timeout: time for timeout in 2.5 sec increments sendPacket(MESG_CHANNEL_SEARCH_TIMEOUT_ID, 2, ANT_CHAN, ANT_TIMEOUT); if (checkReturn() == 0) errorHandler(errDefault); //ANT_send(1+2, MESG_CHANNEL_RADIO_FREQ_ID, CHAN0, FREQ); // Set Channel RF Frequency // Channel // Frequency = 2400 MHz + (FREQ * 1 MHz) (See page 59 of ANT MPaU) 0x39 = 2457 MHz sendPacket(MESG_CHANNEL_RADIO_FREQ_ID, 2, ANT_CHAN, ANT_FREQ); if (checkReturn() == 0) errorHandler(errDefault); // Set Channel Period sendPacket(MESG_CHANNEL_MESG_PERIOD_ID, 3, ANT_CHAN, (ANT_PERIOD & 0x00FF), ((ANT_PERIOD & 0xFF00) >> 8)); if (checkReturn() == 0) errorHandler(errDefault); //Open Channel sendPacket(MESG_OPEN_CHANNEL_ID, 1, ANT_CHAN); if (checkReturn() == 0) errorHandler(errDefault); #ifdef DEBUG printf("Config Done"); #endif }
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(); } }