Beispiel #1
0
void lose_isr(void* context, alt_u32 id)
{
	// FIFO is 75% empty, need to fill it up
	int sample_counter;
	for (sample_counter = 0; sample_counter < SAMPLE_SIZE; sample_counter++)
	{
		// take 2 bytes at a time
		byte_data[0] = lose_data[sound_data_counter];
		byte_data[1] = lose_data[sound_data_counter+1];
		sound_data_counter += 2;

		// combine the two bytes and store into sample buffer
		sound_buff[sample_counter] = (byte_data[1] << 8) | byte_data[0];

		// if we finish reading our data buffer, then we loop back to start over
		if (sound_data_counter >= LOSE_SIZE)
		{
			sound_data_counter = 0;
			alt_up_audio_disable_write_interrupt(audio_dev);
		}
	}
	// finally, we write this sample data to the FIFO
	alt_up_audio_write_fifo(audio_dev, sound_buff, SAMPLE_SIZE, ALT_UP_AUDIO_LEFT);
	alt_up_audio_write_fifo(audio_dev, sound_buff, SAMPLE_SIZE, ALT_UP_AUDIO_RIGHT);
}
Beispiel #2
0
void disableSound()
{
	printf("disable\n");
	sound_data_counter = 0;
	alt_up_audio_disable_write_interrupt(audio_dev);
	alt_up_audio_reset_audio_core(audio_dev);
}
Beispiel #3
0
//initialize irq for audio write
void initialize_audio_irq()
{
	printf("Initializing Audio IRQ...\n");

	alt_up_audio_disable_read_interrupt(audio_dev);
	alt_up_audio_disable_write_interrupt(audio_dev);

	printf("Audio IRQ initialized...\n");
}
Beispiel #4
0
/* The audio task is responsible for continuously playing music
 * off the SD card.
 */
void audio_task(void *pdata) {
	int err = 0;

	err += alt_up_av_config_write_audio_cfg_register(av_dev, AUDIO_REG_ACTIVE_CTRL, 0x00);
	err += alt_up_av_config_write_audio_cfg_register(av_dev, AUDIO_REG_LEFT_LINE_IN, 0x97);
	err += alt_up_av_config_write_audio_cfg_register(av_dev, AUDIO_REG_RIGHT_LINE_IN, 0x97);
	err += alt_up_av_config_write_audio_cfg_register(av_dev, AUDIO_REG_LEFT_HEADPHONE_OUT, 0x79);
	err += alt_up_av_config_write_audio_cfg_register(av_dev, AUDIO_REG_RIGHT_HEADPHONE_OUT, 0x79);
	err += alt_up_av_config_write_audio_cfg_register(av_dev, AUDIO_REG_ANALOG_AUDIO_PATH_CTRL, 0x12);
	err += alt_up_av_config_write_audio_cfg_register(av_dev, AUDIO_REG_DIGITAL_AUDIO_PATH_CTRL, 0x05);
	err += alt_up_av_config_write_audio_cfg_register(av_dev, AUDIO_REG_POWER_DOWN_CTRL, 0x07);
	err += alt_up_av_config_write_audio_cfg_register(av_dev, AUDIO_REG_AUDIO_DIGITAL_INTERFACE, 0x42);
	err += alt_up_av_config_write_audio_cfg_register(av_dev, AUDIO_REG_SAMPLING_CTRL, 0x22);
	err += alt_up_av_config_write_audio_cfg_register(av_dev, AUDIO_REG_ACTIVE_CTRL, 0x01);
	err += audio_set_headphone_volume(av_dev, DEFAULT_VOLUME);

	if(err < 0)
		printf("Audio Configuration Failed\n");

	alt_up_audio_reset_audio_core(audio_dev);
	alt_up_audio_disable_read_interrupt(audio_dev);
	alt_up_audio_disable_write_interrupt(audio_dev);

	char fileName[10] = {"class.wav\0"};
	if (file_fopen(&readFile, &efsl.myFs, fileName, 'r') != 0)
		printf("Error:\tCould not open file\n");

	int readSize = 0;
	euint32 currentSize = 44;

	euint8 buf[AUDIO_BUF_SIZE];
	int i;

	/* The task is suspended so that it can be played by another task. */
	OSTaskSuspend(AUDIO_TASK_PRIORITY);
	while(1) {
		if (currentSize < readFile.FileSize) {
			int fifospace = alt_up_audio_write_fifo_space(audio_dev, ALT_UP_AUDIO_LEFT);
			if (fifospace > WORD_COUNT) {
				readSize = file_fread(&readFile, currentSize, AUDIO_BUF_SIZE, buf);
				currentSize += readSize;
				i = 0;
				while(i < AUDIO_BUF_SIZE) {
					IOWR_ALT_UP_AUDIO_LEFTDATA(audio_dev->base, (buf[i+1]<<8)|buf[i]);
					IOWR_ALT_UP_AUDIO_RIGHTDATA(audio_dev->base, (buf[i+3]<<8)|buf[i+2]);

					i+=4;
				}
			}
		} else {
			currentSize = 44;
		}
	}

	file_fclose(&readFile);
}
Beispiel #5
0
void game_reset(master* m) {
	alt_up_audio_disable_write_interrupt(m->ab->audio_dev);
	IOWR_16DIRECT(TIMER_0_BASE, 4, 1 << 3);
	IOWR_16DIRECT(TIMER_1_BASE, 4, 1 << 3);
	IOWR_16DIRECT(TIMER_2_BASE, 4, 1 << 3);


	sd_fclose(m->ab->wav);
	reset_audio_buffer(m->ab);
	alt_up_audio_reset_audio_core(m->ab->audio_dev);
}
Beispiel #6
0
int set_audio_interrupt(alt_up_audio_dev *audio, volatile int edge_capture_thing)
{
    // Need to disable both audio interrupts before setting them up
    // otherwise you get stuck in them when they are setup
    alt_up_audio_disable_read_interrupt(audio);
    alt_up_audio_disable_write_interrupt(audio);

    void *edge_pointer = (void*)&edge_capture_thing;
	#ifdef ALT_ENHANCED_INTERRUPT_API_PRESENT
	return alt_ic_isr_register(AUDIO_CORE_IRQ_INTERRUPT_CONTROLLER_ID,
			AUDIO_CORE_IRQ, playMusicISR, edge_pointer, 0x0);
	#else
	return alt_irq_register(AUDIO_CORE_IRQ, edge_pointer, playMusicISR);
	#endif
}
Beispiel #7
0
int loadMusic(char* audioFile, unsigned short loop, float volumeFactor)
{
	int i = 0;
	unsigned int *sample;

	alt_up_audio_disable_write_interrupt(audio);

	printf("Opening file\n");

	file_handle fileHandle = open_file(audioFile, false);

	if (fileHandle < 0) {
		printf("Reading file failed \n");
		return AUDIO_ERROR;
	}

	int fileLength = findWavSize(fileHandle);

	// Discard header-- we are making an assumption about
	// how the data is stored to make it easier to
	// add sound to the music.
	for (i = 0; i < 32; i++) read_file(fileHandle);

	// Allocate the main music buffer to be the size of the file.
	if (interruptMusicBuffer != 0) free(interruptMusicBuffer);
	musicLoop = loop;
	musicDone = 0;
	interruptMusicBuffer = (int*) malloc((fileLength-32) * 2);

	interruptBufSize = (fileLength-32)/2;
	interruptSample = 0;

	if (volumeFactor <= 0) volumeFactor = 1;

	for (i = 0; i < interruptBufSize; i++)
	{
		// Extract data and store in the buf.
		char firstByte = read_file(fileHandle);
		char secondByte = read_file(fileHandle);
		short val = ( (unsigned char) secondByte << 8) | (unsigned char) firstByte;

		val = val * volumeFactor;
		interruptMusicBuffer[i] = val;
	}

	alt_up_sd_card_fclose(fileHandle);

	unsigned int space = alt_up_audio_write_fifo_space(audio, ALT_UP_AUDIO_RIGHT);

	if (space > interruptBufSize - interruptSample)
	{
		// Don't need to fully fill the rest of the buffer.
		space = interruptBufSize - interruptSample;
	}

	if (space > 0)
	{
		sample = &(interruptMusicBuffer[interruptSample]);
		alt_up_audio_write_fifo(audio, sample, space, ALT_UP_AUDIO_LEFT);
		alt_up_audio_write_fifo(audio, sample, space, ALT_UP_AUDIO_RIGHT);
		interruptSample += space;
	}

	if (interruptSample >= interruptBufSize)
	{
		if (musicLoop)
		{
			interruptSample = 0;
			alt_up_audio_enable_write_interrupt(audio);
		}
	}
	else
	{
		// Enable the write interrupt
		alt_up_audio_enable_write_interrupt(audio);
	}

	return 0;
}
Beispiel #8
0
static void playMusicISR (void* context, alt_u32 id)
#endif
{
	/* Interrupt for writing*/
	unsigned int space = alt_up_audio_write_fifo_space(audio, ALT_UP_AUDIO_RIGHT);
	unsigned int* sample;
	int i;

	if (space > interruptBufSize - interruptSample)
	{
		// Don't need to fully fill the rest of the buffer.
		space = interruptBufSize - interruptSample;
	}

	if (space > 0)
	{
		if (addSound)
		{
			/* Add a sound in-- must add word by word. */
			for (i = 0; i < space; i++)
			{
				int currentWord = interruptMusicBuffer[interruptSample++];
				if (soundBufferSample < soundBufSize)
				{
					currentWord += soundBuffer[soundBufferSample++];
				}
				else
				{
					removeSound();
				}

				alt_up_audio_write_fifo(audio, &currentWord, 1, ALT_UP_AUDIO_LEFT);
				alt_up_audio_write_fifo(audio, &currentWord, 1, ALT_UP_AUDIO_RIGHT);
			}
		}
		else
		{
			sample = &(interruptMusicBuffer[interruptSample]);

			alt_up_audio_write_fifo(audio, sample, space, ALT_UP_AUDIO_LEFT);
			alt_up_audio_write_fifo(audio, sample, space, ALT_UP_AUDIO_RIGHT);
			interruptSample += space;
		}
	}

	if (interruptSample >= interruptBufSize)
	{
		if (musicLoop)
		{
			interruptSample = 0;
		}
		else
		{
			musicDone = 1;
			alt_up_audio_disable_write_interrupt(audio);

			if (bufSizeSwap != 0)
			{
				swapOutSound();
			}
		}
	}
}
Beispiel #9
0
void pauseMusic(void)
{
	// Stops writing to the audio buffer.
	alt_up_audio_disable_write_interrupt(audio);
}
Beispiel #10
0
//Audio interrupt function, plays sound effects and/or loops audio
//REQ: audmode->id must point to correct id
void audio_isr(audisr * audmode, alt_u32 irq_id) {
	int i;
	unsigned int ** temp;
	unsigned int * second;

	if (audmode->resetmix == true) {
		audmode->resetmix = false;
		audio_isr_2 = 0;
	}
	//if (audmode->mode == 0) {
	if (audmode->id != audmode->oldid) {
		audio_isr_k = 0;
		seek = 0;
		init_copy(audmode->id, audmode->oldid);
		audmode->oldid = audmode->id;
	}
	if (audmode->id2 != audmode->oldid2) {
		audio_isr_2 = 0;
		audmode->oldid2 = audmode->id2;
	}
	if (audio_isr_k == 0) {
		copy_bgm(audmode->id);
		alt_up_rs232_write_data(uart, 0x6);
		alt_up_rs232_write_data(uart, (int)audiosecs[audmode->id]);
	}
	audio_log.bgmin = copyarr[audio_isr_k];

	//Mode 0, loop music
	if (audmode->mode == 0) {
		for (i = 0; i < 96; i++) {
			audio_log.bgmin[i] = volume_adjust(audio_log.bgmin[i], audmode->newvolume);
		}
	}
	else if (audmode->mode == 1) {
		temp = arr[audmode->id2];
		second = temp[audio_isr_2];
		for (i = 0; i < 96; i++) {
			unsigned int tempmix = audio_log.bgmin[i];
			audio_log.bgmin[i] = mix_adjust(tempmix,second[i],5);
		}
		audio_isr_2++;
		if (audio_isr_2 > audiosize[audmode->id2]) {
			audio_isr_2 = 0;
			audmode->mode = 0;
		}
	}
	if (alt_up_audio_write_interrupt_pending(audio) == 1) {
		alt_up_audio_write_fifo(audio, audio_log.bgmin, 96, ALT_UP_AUDIO_LEFT);
		alt_up_audio_write_fifo(audio, audio_log.bgmin, 96, ALT_UP_AUDIO_RIGHT);
		if (audmode->loop == true){
			audio_isr_k = (audio_isr_k + 1) % audiosize[audmode->id];
			seek = (seek + 1) % 333;
			if (seek == 0) {
				//alt_up_rs232_write_data(uart, 0x0A);
			}
			if (audio_isr_k == 0) {
				alt_up_rs232_write_data(uart, 0x3);
			}
		}
		else
		{
			if(audio_isr_k <= audiosize[audmode->id])
			{
				audio_isr_k += 1;
				seek = (seek + 1) % 333;
				if (seek == 0) {
					//alt_up_rs232_write_data(uart, 0x0A);
				}
			}
			else
			{
				seek = 0;
				audmode->mode = 0;
				audio_isr_2 = 0;
				audio_isr_k = 0;
				//alt_up_rs232_write_data(uart, 0x3);
				alt_up_rs232_write_data(uart, 0x4);
				wait();
				if (audmode->shuffle == false) {
					audmode->id += 1;
					if ((audmode->id >= audmode->files) && (audmode->listloop == true)) {
						audmode->id = 0;
						//printf("Restarting songs\n");
					}
					else if((audmode->id >= audmode->files) && (audmode->listloop == false)) {
						printf("End of Playlist\n");
						audmode->id = 0;
						alt_up_audio_disable_write_interrupt(audio);
					}
				}
				else {
					/*
					do {
						while(rs_flag == false);
						alt_up_rs232_read_data(uart, &data, &parity);
					}while((int)data == 0);
					 */
					wait();
					alt_up_rs232_read_data(uart, &data, &parity);
					int nextindex = (int)data;
					nextindex -= 4;
					//printf("Next Index: %d\n", nextindex);
					if ((nextindex < 0) || (nextindex > audmode->files)) {
						nextindex = 0;
						printf("Error, next Index: %d\n", nextindex);
					}
					audmode->id = nextindex;
				}
			}
		}
	}
	//}
	/*
	else if (audmode->mode == 1) {

		if (audmode->id != audmode->oldid) {
			//TEMP
			audmode->id2 = audmode->id++;
			if (audmode->id2 >= audmode->files) {
				audmode->id2 = 0;
			}
			if (audiosize[audmode->id] > audiosize[audmode->id2]) {
				audmode->large = audmode->id;
			}
			else {
				audmode->large = audmode->id2;
			}
			//
			audio_isr_k = 0;
			init_copy(audmode->large, audmode->oldid);
			audmode->oldid = audmode->id;
		}
		if (audio_isr_k == 0) {
			copy_bgm(audmode->large);
			alt_up_rs232_write_data(uart, 0x6);
		}
		audio_log.bgmin = copyarr[audio_isr_k];

		for (i = 0; i < 96; i++) {
			//audio_log.bgmin[i] = mix_adjust(audio_log.bgmin[i],  ,audmode->newvolume);
		}

		if (alt_up_audio_write_interrupt_pending(audio) == 1) {


			audio_isr_k = 0;
			audmode->id += 1;
			alt_up_rs232_write_data(uart, 0x3);
			if ((audmode->id >= audmode->files) && (audmode->listloop == true)) {
				audmode->id = 0;
				printf("Restarting songs\n");
			}
			else if((audmode->id >= audmode->files) && (audmode->listloop == false)) {
				printf("End of Playlist\n");
				audmode->id = 0;
				alt_up_audio_disable_write_interrupt(audio);
			}
		}

	}
	 */
}
Beispiel #11
0
//DE2 waits for command from Android/middleman
void listen(char * soundfiles[], int numwavfiles, audisr * audmode)
{
	printf("Listening\n");
	int volume_index_up = 10;
	int volume_index_down = 10;
	int func;
	bool headerfound = false;
	int volume;

	clear_fifo();

	//stop_timer();
	start_timer();
	while(1)
	{
		if(rs_flag == true) {
			if (headerfound == false) {

				//Loop check header
				if (rs_flag == true) {
					alt_up_rs232_read_data(uart, &data, &parity);
					if ((int)data == 1) {
						headerfound = true;
						while((int)data == 1) {
							alt_up_rs232_read_data(uart, &data, &parity);
						}
					}
				}
			}

			else {

				//Function get
				alt_up_rs232_read_data(uart, &data, &parity);
				func = (int)data;

				if (func == QUEUE) {
					alt_up_audio_disable_write_interrupt(audio);
					audmode->id = get_fnames(soundfiles,numwavfiles);
					//alt_up_audio_enable_write_interrupt(audio);
					headerfound = false;
					alt_up_rs232_write_data(uart, ACK);
				}
				else if (func == PLAY) {
					alt_up_audio_enable_write_interrupt(audio);
					headerfound = false;
					alt_up_rs232_write_data(uart, ACK);
				}
				else if (func == STOP) {
					alt_up_audio_disable_write_interrupt(audio);
					audio_isr_k = 0;
					headerfound = false;
					alt_up_rs232_write_data(uart, ACK);
				}
				else if (func == PAUSE) {
					alt_up_audio_disable_write_interrupt(audio);
					headerfound = false;
					alt_up_rs232_write_data(uart, ACK);
				}
				/*
				else if (func == VOLUME) {
					int volumetemp;

					do {
						while(rs_flag == false);
						alt_up_rs232_read_data(uart, &data, &parity);
						volumetemp = (int)data;
					}while((volumetemp == VOLUME) || (volumetemp == 0));

					//	alt_up_rs232_read_data(uart, &data, &parity);
					volume = volumetemp;

					if (volume == VOL_UP) {
						volume_index_up += 3;
						if (volume_index_up > 127) {
							volume_index_up = 127;
						}
						printf("Up %d\n", volume_index_up);
						audmode->newvolume = volume_index_up;
						volume_index_down = 10;
					}
					else if (volume == VOL_DOWN) {
						volume_index_down--;
						if (volume_index_down < 1) {
							volume_index_down = 1;
						}
						printf("Down %d\n", volume_index_down);
						audmode->newvolume = volume_index_down;
						volume_index_up = 10;
					}
					else {
						printf("Error, unknown volume value %d\n", volume);

					}
					headerfound = false;

					alt_up_rs232_write_data(uart, ACK);

				}
				 */
				else if (func == VOL_UP) {
					volume_index_up += 5;
					if (volume_index_up > 127) {
						volume_index_up = 127;
					}
					printf("Up %d\n", volume_index_up);
					audmode->newvolume = volume_index_up;
					volume_index_down = 10;
					headerfound = false;
					alt_up_rs232_write_data(uart, ACK);
				}
				else if (func == VOL_DOWN) {
					volume_index_down--;
					if (volume_index_down < 1) {
						volume_index_down = 1;
					}
					printf("Down %d\n", volume_index_down);
					audmode->newvolume = volume_index_down;
					volume_index_up = 10;
					headerfound = false;
					alt_up_rs232_write_data(uart, ACK);
				}
				else if (func == SELECT) {
					int index = 0;
					do {
						if (rs_flag == true)
							alt_up_rs232_read_data(uart, &data, &parity);
					}while((int)data == SELECT);
					index = (int)data;
					if ((index < 0) || (index >= numwavfiles)) {
						printf("Error, index out of bounds, playing index 0\n");
						index = 0;
					}
					alt_up_audio_disable_write_interrupt(audio);
					audmode->id = index;
					printf("Changing to song: %s, Id: %d\n", soundfiles[audmode->id], audmode->id);
					alt_up_audio_enable_write_interrupt(audio);
					headerfound = false;
					alt_up_rs232_write_data(uart, ACK);
				}
				else if (func == S_LOOP) {
					printf("Loop song\n");
					audmode->loop = true;
					audmode->listloop = false;
					headerfound = false;
					alt_up_rs232_write_data(uart, ACK);
				}
				else if (func == Q_LOOP) {
					printf("List loop\n");
					audmode->listloop = true;
					audmode->loop = false;
					headerfound = false;
					alt_up_rs232_write_data(uart, ACK);
				}
				else if (func == C_LOOP) {
					printf("Cancel loops\n");
					audmode->listloop = false;
					audmode->loop = false;
					headerfound = false;
					alt_up_rs232_write_data(uart, ACK);
				}
				else if (func == SEND) {
					send_fnames(soundfiles, numwavfiles);
					alt_up_rs232_write_data(uart, ACK);
				}
				else if (func == NEXT) {
					alt_up_audio_disable_write_interrupt(audio);
					audmode->id += 1;
					if(audmode->id >= numwavfiles) {
						audmode->id = numwavfiles - 1;
					}
					printf("Changing to song Id: %d\n", audmode->id);
					alt_up_audio_enable_write_interrupt(audio);

					headerfound = false;
					alt_up_rs232_write_data(uart, ACK);
				}
				else if (func == PREVIOUS) {
					alt_up_audio_disable_write_interrupt(audio);
					audmode->id -= 1;
					if(audmode->id < 0) {
						audmode->id = 0;
					}
					printf("Changing to song Id: %d\n", audmode->id);
					alt_up_audio_enable_write_interrupt(audio);
					headerfound = false;
					alt_up_rs232_write_data(uart, ACK);
				}
				else if (func == MIX) {
					audmode->mode = 1;
					headerfound = false;
					alt_up_rs232_write_data(uart, ACK);
				}
				else if (func == SHUFFLE) {
					if(audmode->shuffle == true) {
						audmode->shuffle = false;
					}
					else {
						audmode->shuffle = true;
					}
					headerfound = false;
					alt_up_rs232_write_data(uart, ACK);
				}
				else if (func == VISUALON) {
					visualflag = !visualflag;
					headerfound = false;
					alt_up_rs232_write_data(uart, ACK);
				}
				else if ((func != 1) && (func != 0)) {
					printf("Error, Function %d not implemented yet, or invalid\n", (int)data);
					headerfound = false;
					alt_up_rs232_write_data(uart, ACK);
				}
			}
		}
	}
	stop_timer();
}
Beispiel #12
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();
	}
}