Ejemplo n.º 1
0
void swapInSound(int* buf, int len)
{
	if (bufSizeSwap == 0)
	{
		musicSwapBuffer = interruptMusicBuffer;
		bufSizeSwap = interruptBufSize;
		swapSample = interruptSample;
		swapLoop = musicLoop;
		swapDone = musicDone;

		interruptMusicBuffer = buf;
		interruptBufSize = len;
		interruptSample = 0;
		musicLoop = 0;
		musicDone = 0;

		unsigned int space = alt_up_audio_write_fifo_space(audio, ALT_UP_AUDIO_RIGHT);
		unsigned int* sample;

		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
		{
			printf("Enabling interrupt.");
			// Enable the write interrupt
			alt_up_audio_enable_write_interrupt(audio);
		}
	}
}
Ejemplo n.º 2
0
void game_start(master* m, bmp* bg, char* level_to_read, char* bg_music) {
	p_shift = 0;
	first_platform = true;
	inc = 0;
	//background drawing
	clear_loc(pixel_buffer,0,0,319,239,bg);
	alt_up_pixel_buffer_dma_swap_buffers(pixel_buffer);
	while (alt_up_pixel_buffer_dma_check_swap_buffers_status(pixel_buffer));
	clear_loc(pixel_buffer,0,0,319,239,bg);
	alt_up_pixel_buffer_dma_swap_buffers(pixel_buffer);
	while (alt_up_pixel_buffer_dma_check_swap_buffers_status(pixel_buffer));



	m->ab->wav = init_read_wav(bg_music); //reads wav file into buffer
	fill_buffer(m->ab);

	sd_read_level(level_to_read, m->l);
	object_spawn_init(m);
	init_char_update(m);

	//start timer
	IOWR_16DIRECT(TIMER_0_BASE, 4, 0x5); //start timer

	//enable audio interrupt
	alt_up_audio_enable_write_interrupt(m->ab->audio_dev);

	//enable character interrupt
	IOWR_16DIRECT(TIMER_2_BASE, 4, 0x5);

	//enable object spawning interrupt
	IOWR_16DIRECT(TIMER_1_BASE, 4, 0x5);
}
Ejemplo n.º 3
0
/***************************************************************************************
 * Pushbutton - Interrupt Service Routine                                
 *                                                                          
 * This ISR checks which KEY has been pressed. If KEY1, then it enables audio-in
 * interrupts (recording). If KEY2, it enables audio-out interrupts (playback).
****************************************************************************************/
void pushbutton_ISR(struct alt_up_dev *up_dev, unsigned int id)
{
	alt_up_audio_dev *audio_dev;
	audio_dev = up_dev->audio_dev;
	
	int KEY_value;

	/* read the pushbutton interrupt register */
	KEY_value = alt_up_parallel_port_read_edge_capture (up_dev->KEY_dev);
	alt_up_parallel_port_clear_edge_capture (up_dev->KEY_dev);	// clear the interrupt

	if (KEY_value == 0x2)										// check KEY1
	{
		// reset the buffer index for recording
		buf_index_record = 0;
		// clear audio FIFOs
		alt_up_audio_reset_audio_core (audio_dev);
		// enable audio-in interrupts
		alt_up_audio_enable_read_interrupt (audio_dev);
	}
	else if (KEY_value == 0x4)									// check KEY2
	{
		// reset counter to start playback
		buf_index_play = 0;
		// clear audio FIFOs
		alt_up_audio_reset_audio_core (audio_dev);
		// enable audio-out interrupts
		alt_up_audio_enable_write_interrupt (audio_dev);
	}
	return;
}
Ejemplo n.º 4
0
void playCongrat()
{
	// register isr
	sound_data_counter = 0;
	alt_irq_register(AUDIO_IRQ, 0x0, congrat_isr);
	// enable interrupt
	alt_irq_enable(AUDIO_IRQ);
	alt_up_audio_enable_write_interrupt(audio_dev);
}
Ejemplo n.º 5
0
int initAudioCore(alt_up_audio_dev* audio) {

	alt_up_audio_reset_audio_core(audio);

	if (audio == NULL) {
		return AUDIO_ERROR;
	}


	alt_up_audio_enable_write_interrupt(audio);

	return 0;
}
Ejemplo n.º 6
0
void swapOutSound(void)
{
	interruptMusicBuffer = musicSwapBuffer;
	interruptBufSize = bufSizeSwap;
	musicLoop = swapLoop;
	interruptSample = swapSample;
	musicDone = swapDone;

	swapSample = 0;
	swapLoop = 0;
	bufSizeSwap = 0;
	musicSwapBuffer = 0;
	swapDone = 0;

	if (!musicDone)
	{
		alt_up_audio_enable_write_interrupt(audio);
	}
}
Ejemplo n.º 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;
}
Ejemplo n.º 8
0
void restartMusic(void)
{
	interruptSample = 0;
	alt_up_audio_enable_write_interrupt(audio);
}
Ejemplo n.º 9
0
void resumeMusic(void)
{
	alt_up_audio_enable_write_interrupt(audio);
}
Ejemplo n.º 10
0
int main()
{
	arr = (unsigned int**)malloc(4377 * sizeof(unsigned int));
	psController ps;
	int velocity = 0;
	int angle = 0;
	long ii = 0;
	int** collisionMatrix;
	int ee;
	int numfiles;
	char * filenames[MAXFILES];

	//init_VGA_Pixel();
	initVGA(); //pixel
	init_VGA_Char();
	av_config_setup();
	numfiles = init_sd(filenames);
	init_wav(arr);
	printf("timing audio\n");
	//time_of_sound = time_audio(arr);
	printf("looping audio\n");

	audio_isr_k = 0;
	alt_irq_register(AUDIO_IRQ, NULL, &audio_isr);
	alt_up_audio_enable_write_interrupt(audio);


	//====INITIALIZE AND DRAW TERRAIN USING BMP ===========================//
		short int fd;

		terrain background;
		fd = alt_up_sd_card_fopen("bg.bmp", false);
		initTerrain(fd, &background);
		drawBackground(background);
		alt_up_sd_card_fclose(fd);


		terrain terrain;
		fd = alt_up_sd_card_fopen("tr.bmp", false);
		initTerrain(fd, &terrain);
		drawTerrain(terrain);
		alt_up_sd_card_fclose(fd);

	//====INITIALIZE AND DRAW USER TANK USING BMP ===========================//
		fd = alt_up_sd_card_fopen("tank.bmp", false);
		tank user;
		initUserTank(&user, fd);
		drawTank(&user, background);
		alt_up_sd_card_fclose(fd);
	//====INITIALIZE AND DRAW ENEMY TANK USING BMP ===========================//
		tank enemy;
		fd = alt_up_sd_card_fopen("tk.bmp", false);
		initEnemyTank1(&enemy, fd);
		drawTank(&enemy,background);
		alt_up_sd_card_fclose(fd);
	//====SWAP BUFFERS =======================================================//
		updateVGA();
		drawBackground(background);
		drawTerrain(terrain);
		drawTank(&enemy, background);
		for(ee=0;ee < 20;ee++)
		{
			moveTank(&user, RIGHT, 1);
			drawTank(&user,background);
			updateVGA();
			drawTank(&user,background);
			//delay();
		}
	//for(ii = 0; ii < 300000; ii++);

	collisionMatrix = init_CollisionMatrix(XMAXSCREEN_RESOLUTION + 1, XMAXSCREEN_RESOLUTION + 1);

	//alt_up_pixel_buffer_dma_draw_box(pixel_buffer, 0, 120, 340, 240, 0x7E0 , 0); //draw terrain

	set_CollisionAtRectArea(collisionMatrix, 0 , 0, 340, 240, EMPTY);
	set_CollisionAtRectArea(collisionMatrix, 0 , 161, 340, 240, TERRAIN_COLOR);//set the rectangular area drawn by terrain to filled with terrain
	while(1){
		//angle = 0;
		velocity = 0;
		set_UserTank(&angle, &velocity, ps, &user, &enemy, background); //reads controller to set angle, power, and shoot
		shoot_Missile(angle, velocity,( user.x + user.t_VGA.width) - 1 , (240 - user.y + user.t_VGA.height) - 7, collisionMatrix, background);

	}
	clean_audio(arr);
	return 0;
}
Ejemplo n.º 11
0
//Audio selection screen and volume control
void select_bgm(char ** soundfiles, int numfiles)
{
	int init_y;
	int i;
	int y_index = 4;
	int temp,temp2;
	char ptr[] = "->";
	int cross;
	int crossptr = 36;

	if (onetime > 0)
	{
		free(bgm);	//If called again, clean up original file name for audio file
	}

	bgm = (char *)malloc(sizeof(char) * (MAX_NAME_LEN + direct_len));
	char vol_display[3];
	temp2 = sprintf(vol_display, "%d", ((int)(VOL_SET * 10)));

	alt_up_char_buffer_string(char_buffer, "Select BGM file",33, y_index);
	alt_up_char_buffer_string(char_buffer, "Use D-pad to scroll",31, 6);
	alt_up_char_buffer_string(char_buffer, "Use Left & Right to scroll to volume",25, 7);
	alt_up_char_buffer_string(char_buffer, "Press 'X' to select",31, 8);
	alt_up_char_buffer_string(char_buffer, "Volume Control",62, 21);
	alt_up_char_buffer_string(char_buffer, "+", 68, 26);
	alt_up_char_buffer_string(char_buffer, vol_display, 68, 30);
	alt_up_char_buffer_string(char_buffer, "-", 68, 34);

	y_index = 27;
	temp = numfiles;
	while (temp > 0) {
		y_index -= 2;
		temp--;
	}
	for(i = 0; i < numfiles; i++) {
		if (soundfiles[i] != NULL) {
			y_index += 3;					//Display soundfiles
			alt_up_char_buffer_string(char_buffer, soundfiles[i],36, y_index);
			if (i == 0) {
				arrow_y = y_index;
				init_y = arrow_y;
				if (arrow_x == 0) {
					alt_up_char_buffer_string(char_buffer, ptr,33, arrow_y);
				}
				else if (arrow_x == 1){
					arrow_y = 30;
					alt_up_char_buffer_string(char_buffer,"->",65, arrow_y);


				}
			}
		}
	}

	arrow_index = 0;

	while(1) {
		if(*keys == 7)
		{
			usleep(150000);
			if (((arrow_index) > 0) && (arrow_x == 0)) {
				alt_up_char_buffer_string(char_buffer,"  ",33, arrow_y);
				arrow_y -= 3;
				alt_up_char_buffer_string(char_buffer,ptr,33, arrow_y);
				arrow_index--;
			}
			else if (arrow_x == 1) {
				alt_up_char_buffer_string(char_buffer, " ", 68, 30);
				VOL_SET = VOL_SET + 0.1;		//Volume precision
				if (VOL_SET >= 2.0)
					VOL_SET = 2.0;	//Max volume
				temp2 = sprintf(vol_display, "%d", ((int)(VOL_SET * 10)));
				alt_up_char_buffer_string(char_buffer, vol_display, 68, 30);
			}
		}
		if(*keys == 11)
		{
			usleep(150000);
			if (((arrow_index) < (numfiles - 1)) && (arrow_x == 0)) {
				alt_up_char_buffer_string(char_buffer,"  ",33, arrow_y);
				arrow_y += 3;
				alt_up_char_buffer_string(char_buffer,ptr,33, arrow_y);
				arrow_index++;
			}
			else if (arrow_x == 1) {
				alt_up_char_buffer_string(char_buffer, "  ", 68, 30);
				VOL_SET = VOL_SET - 0.1;
				if (VOL_SET <= 0.0)
					VOL_SET = 0.0;
				temp2 = sprintf(vol_display, "%d", ((int)(VOL_SET * 10)));
				alt_up_char_buffer_string(char_buffer, vol_display, 68, 30);
			}
		}

		//Select button
		if(*switches == 1)
		{
			usleep(150000);
			if (arrow_x == 0) {
				cross = strlen(soundfiles[arrow_index]);
				for (i = 0; i < cross; i++) {
					alt_up_char_buffer_string(char_buffer,"-",crossptr, arrow_y);
					crossptr++;
				}
				strcpy(bgm, AUD_DIRECT);
				strcat(bgm, soundfiles[arrow_index]);
				alt_up_char_buffer_clear(char_buffer);
				alt_up_char_buffer_string(char_buffer,"Loading, Please Wait",31, 25);
				init_wav(bgm, VOL_SET, 0);
				alt_up_audio_enable_write_interrupt(audio);		//Resume audio
				alt_up_char_buffer_clear(char_buffer);
				return;
			}
		}
		if(*keys == 13)
		{
			usleep(150000);
			if (arrow_x == 0) {
				arrow_x = 1;
				alt_up_char_buffer_string(char_buffer,"  ",33, arrow_y);
				arrow_y = 30;
				alt_up_char_buffer_string(char_buffer,"->",65, arrow_y);
			}
		}
		if (arrow_x == 1) {
			arrow_x = 0;
			alt_up_char_buffer_string(char_buffer,"  ",65, arrow_y);
			arrow_y = init_y;
			alt_up_char_buffer_string(char_buffer,"->",33, arrow_y);
			arrow_index = 0;
		}

		/*
		else if (ps.b.sel == 1) {
			usleep(150000);
			alt_up_audio_enable_write_interrupt(audio);
			alt_up_char_buffer_clear(char_buffer);
			return;

		}
		 */
		usleep(150000);
	}

}
Ejemplo n.º 12
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();
}
Ejemplo n.º 13
0
int main(void) {

	device_reference = alt_up_sd_card_open_dev("/dev/SD_Card");

	if (device_reference != NULL) {
		while(1) {
			if ((connected == 0) && (alt_up_sd_card_is_Present())) {
			printf("Card connected.\n");
				if (alt_up_sd_card_is_FAT16()) {
					printf("FAT16 file system detected.\n");

					//Print out the list in the sd card
					handler = alt_up_sd_card_find_first("", buffer_name);
					printf("%s \n", buffer_name);

					//Read a file in SD card -needs to speed up(10 sec?) - needs array of int
					sd_fileh = alt_up_sd_card_fopen("TEST.WAV", false);
					if (sd_fileh < 0)
						printf("Problem reading file. Error %i\n", sd_fileh);
					else
					{
						printf("Reading file...\n");
						audio_dev = alt_up_audio_open_dev (AUDIO_NAME);
							if ( audio_dev == NULL){
								return;
							}
							av_config = alt_up_av_config_open_dev(AUDIO_AND_VIDEO_CONFIG_NAME);
							while(!alt_up_av_config_read_ready(av_config));

							alt_up_audio_disable_read_interrupt(audio_dev);
							alt_up_audio_enable_write_interrupt(audio_dev);
						/*
						// Get information of number of channels
						//count = 0;
						char a, b;
						int d;
						short c;
						int index = 0;
						while (buffer_name[index] != "\0"){
							a = alt_up_sd_card_read(sd_fileh);
							b = alt_up_sd_card_read(sd_fileh);
							c = ((unsigned char) a <<8) | (unsigned char) b;

							d = c;
							d = alt_up_audio_write_fifo(device_reference,d,)
							index++;
						}
*/

						/*
						//					printf("NumChannels ");
						byte1 = 0;byte2 = 0;total = 0;
						byte1 = alt_up_sd_card_read(sd_fileh);
						byte2 = alt_up_sd_card_read(sd_fileh);
						total = (byte1 & 0x00ff) | (byte2 << 8);
						NumChannels = total;
						//					printf("%d\n",total);
						//					printf("SampleRate ");
						byte1 = 0;byte2 = 0;byte3 = 0;byte4 = 0;long_total = 0;
						byte1 = alt_up_sd_card_read(sd_fileh);
						byte2 = alt_up_sd_card_read(sd_fileh);
						byte3 = alt_up_sd_card_read(sd_fileh);
						byte4 = alt_up_sd_card_read(sd_fileh);
						long_total = (byte4 << 24) | (byte3 << 16) | (byte2 << 8) | ( byte1 & 0x000000ff);
						sampleRate = long_total;
						//					printf("%ld\n",long_total);
*/
/*
						count = 0;
						while (count < 16) // 44-byte header
						{
							alt_up_sd_card_read(sd_fileh);
							count++;
						}
*/
					}

					//find next file
					while ((handler = alt_up_sd_card_find_next(buffer_name)) != -1)
						printf("%s \n", buffer_name);



				}else{
					printf("Unknown file system.\n");
				}
				connected = 1;
			} else if ((connected == 1) && (alt_up_sd_card_is_Present() == false)) {
				printf("Card disconnected.\n");
				connected = 0;
			}
		}
	}
	return 0;
}
Ejemplo n.º 14
0
void load_song(){
	song_size = 0;

	if (openFileinSD(SONG_ONE, &music_file) == 0){
		char a;
		char b;
		char *data_str = "data";
		int i, j;

		for (i = 0; i < 45; i++) {
			a = (char) alt_up_sd_card_read(music_file);
			printf("%c\n", a);
			if (a == data_str[j]) {
				j++;
				if (j == 3) {
					printf("File size found.\n");
					alt_up_sd_card_read(music_file); // letter A
					char byte_0 = (char) alt_up_sd_card_read(music_file);
					char byte_1 = (char) alt_up_sd_card_read(music_file);
					char byte_2 = (char) alt_up_sd_card_read(music_file);
					char byte_3 = (char) alt_up_sd_card_read(music_file);
					file_size = ((unsigned char) byte_3 << 24)
							| ((unsigned char) byte_2 << 16)
							| ((unsigned char) byte_1 << 8)
							| (unsigned char) byte_0;
					printf("Music file size: %lu\n", file_size);
				}
			} else {
				j = 0;
				printf("we are in else\n");
			}
		}

		printf("Allocating memory space.\n");
		unsigned int WHY[file_size];
		audio_stream = WHY;
		if (audio_stream == NULL) {
			printf("*** Failed to allocate left audio stream!");
			exit(1);
		}

		printf("Reading music file.\n");
		short converter;
		while (song_size < file_size / 2) {
			b = (char) alt_up_sd_card_read(music_file);
			a = (char) alt_up_sd_card_read(music_file);
			converter = ((unsigned char) a << 8) | (unsigned char) b;
			converter = converter/2;
			audio_stream[song_size] = converter;
			song_size++;
		}

		printf("Starting music. \n");

		printf("Song Size: %lu, byte: 0x%08x\n", song_size,
				audio_stream[song_size - 41]);

		alt_irq_register(AUDIO_0_IRQ, 0, audio_ISR);
		//alt_irq_enable(AUDIO_0_IRQ);
		alt_up_audio_enable_write_interrupt(audio);

	}
	printf("*** Error Loading Song.\n");
	return;
}
Ejemplo n.º 15
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();
	}
}