/* * this function clear the screen and set up pixel buffers for graphics */ void initVGA() { // Set the background buffer address � Although we don�t use thebackground, // they only provide a function to change the background buffer address, so // we must set that, and then swap it to the foreground. unsigned int pixel_buffer_addr1 = PIXEL_BUFFER_BASE; unsigned int pixel_buffer_addr2 = PIXEL_BUFFER_BASE + (320*240*2); alt_up_pixel_buffer_dma_change_back_buffer_address(pixel_buffer,pixel_buffer_addr1); // Swap background and foreground buffers alt_up_pixel_buffer_dma_swap_buffers(pixel_buffer); // Wait for the swap to complete while(alt_up_pixel_buffer_dma_check_swap_buffers_status(pixel_buffer)); alt_up_pixel_buffer_dma_change_back_buffer_address(pixel_buffer,pixel_buffer_addr2); // Clear the screen alt_up_pixel_buffer_dma_clear_screen(pixel_buffer, 0); alt_up_pixel_buffer_dma_clear_screen(pixel_buffer, 1); // alt_up_pixel_buffer_dma_draw_line(pixel_buffer, 0, 0, 320, 240, 0xFFFF,1); //Swap background and foreground buffers alt_up_pixel_buffer_dma_swap_buffers(pixel_buffer); //Wait for the swap to complete while(alt_up_pixel_buffer_dma_check_swap_buffers_status(pixel_buffer)); // return pixel_buffer; }
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); }
/* * this function clear the screen and set up pixel buffers for graphics */ void initVGA() { // Use the name of your pixel buffer DMA core pixel_buffer =alt_up_pixel_buffer_dma_open_dev("/dev/pixel_buffer_dma_0"); //text on screen initialization char_buffer = alt_up_char_buffer_open_dev("/dev/char_drawer"); alt_up_char_buffer_init(char_buffer); // Set the background buffer address � Although we don�t use thebackground, // they only provide a function to change the background buffer address, so // we must set that, and then swap it to the foreground. unsigned int pixel_buffer_addr1 = PIXEL_BUFFER_BASE; unsigned int pixel_buffer_addr2 = PIXEL_BUFFER_BASE + (320*240*2); alt_up_pixel_buffer_dma_change_back_buffer_address(pixel_buffer,pixel_buffer_addr1); // Swap background and foreground buffers alt_up_pixel_buffer_dma_swap_buffers(pixel_buffer); // Wait for the swap to complete while(alt_up_pixel_buffer_dma_check_swap_buffers_status(pixel_buffer)); alt_up_pixel_buffer_dma_change_back_buffer_address(pixel_buffer,pixel_buffer_addr2); // Clear the screen alt_up_pixel_buffer_dma_clear_screen(pixel_buffer, 0); alt_up_pixel_buffer_dma_clear_screen(pixel_buffer, 1); //Swap background and foreground buffers alt_up_pixel_buffer_dma_swap_buffers(pixel_buffer); //Wait for the swap to complete while(alt_up_pixel_buffer_dma_check_swap_buffers_status(pixel_buffer)); }
int swapVGABuffer(void){ if (alt_up_pixel_buffer_dma_swap_buffers(pixel_buffer_dev)){ return 1; } while (alt_up_pixel_buffer_dma_check_swap_buffers_status(pixel_buffer_dev)); return 0; }
int main() { alt_up_pixel_buffer_dma_dev* pixel_buffer; pixel_buffer = alt_up_pixel_buffer_dma_open_dev("/dev/video_pixel_buffer_dma_0"); if (pixel_buffer == 0) { printf("error initializing pixel buffer (check name in alt_up_pixel_buffer_dma_open_dev)\n"); } alt_up_pixel_buffer_dma_change_back_buffer_address(pixel_buffer, PIXEL_BUFFER_BASE); alt_up_pixel_buffer_dma_swap_buffers(pixel_buffer); while (alt_up_pixel_buffer_dma_check_swap_buffers_status(pixel_buffer)); alt_up_pixel_buffer_dma_clear_screen(pixel_buffer, 0); int hw = 0; if (hw) { IOWR_32DIRECT(drawer_base,0,10); // Set x1 IOWR_32DIRECT(drawer_base,4,20); // Set y1 IOWR_32DIRECT(drawer_base,8,50); // Set x2 IOWR_32DIRECT(drawer_base,12,60); // Set y2 IOWR_32DIRECT(drawer_base,16,0xFFFF); // Set colour IOWR_32DIRECT(drawer_base,20,1); // Start drawing while(IORD_32DIRECT(drawer_base,20)==0); // wait until done } else { alt_up_pixel_buffer_dma_draw_box(pixel_buffer, 10,20,50,60,0xFFFF,0); } return 0; }
alt_up_pixel_buffer_dma_dev * initialise_pixel() // PURPOSE: to set up the VGA adapter // RETURNS: nothing { alt_up_pixel_buffer_dma_dev * pixel_buffer = alt_up_pixel_buffer_dma_open_dev("/dev/video_pixel_buffer_dma_0"); unsigned int pixel_buffer_addr1 = 0x80000; unsigned int pixel_buffer_addr2 = 0x80000 + (320 * 240 * 2); // Set the 1st buffer address alt_up_pixel_buffer_dma_change_back_buffer_address(pixel_buffer,pixel_buffer_addr1); // Swap buffers - we have to swap because there is only an API function // to set the address of the background buffer. alt_up_pixel_buffer_dma_swap_buffers(pixel_buffer); while (alt_up_pixel_buffer_dma_check_swap_buffers_status(pixel_buffer)); // Set the 2nd buffer address alt_up_pixel_buffer_dma_change_back_buffer_address(pixel_buffer,pixel_buffer_addr2); // Clear both buffers (this makes all pixels black) alt_up_pixel_buffer_dma_clear_screen(pixel_buffer, 0); alt_up_pixel_buffer_dma_clear_screen(pixel_buffer, 1); return pixel_buffer; }
//alt_up_pixel_buffer_dma_dev *pixel_buffer = init_pixel_stuff("/dev/pixel_buffer_dma"); alt_up_pixel_buffer_dma_dev *init_pixel_stuff(char *location){ //Pixel Buffer alt_up_pixel_buffer_dma_dev *pixel_buffer; //Opens the pixel buffer device specified by /dev/pixel_buffer_dma pixel_buffer = alt_up_pixel_buffer_dma_open_dev(location); unsigned int pixel_buffer_addr1 = PIXEL_BUFFER_BASE; unsigned int pixel_buffer_addr2 = PIXEL_BUFFER_BASE + PIXEL_BUFFER_SPAN / 2; //Change the 1st buffer's start address alt_up_pixel_buffer_dma_change_back_buffer_address(pixel_buffer, pixel_buffer_addr1); //Swap background and foreground buffers alt_up_pixel_buffer_dma_swap_buffers(pixel_buffer); //Wait for the swap to complete while(alt_up_pixel_buffer_dma_check_swap_buffers_status(pixel_buffer)); //Change the 1st buffer's start address alt_up_pixel_buffer_dma_change_back_buffer_address(pixel_buffer, pixel_buffer_addr2); //Clear the screen alt_up_pixel_buffer_dma_clear_screen(pixel_buffer, 0); alt_up_pixel_buffer_dma_clear_screen(pixel_buffer, 1); return pixel_buffer; }
/* Initializes all hardware before loading the game - VGA, LEDs, PS/2, etc. */ void initialize_hardware(void){ // Use the name of your pixel buffer DMA core pixel_buffer = alt_up_pixel_buffer_dma_open_dev(BUFFER_DMA_NAME); // Set the background buffer address – Although we don’t use the background, // they only provide a function to change the background buffer address, so // we must set that, and then swap it to the foreground. alt_up_pixel_buffer_dma_change_back_buffer_address(pixel_buffer, PIXEL_BUFFER_BASE); // Swap background and foreground buffers alt_up_pixel_buffer_dma_swap_buffers(pixel_buffer); // Wait for the swap to complete while (alt_up_pixel_buffer_dma_check_swap_buffers_status(pixel_buffer)); // Initialize character buffer char_buffer = alt_up_char_buffer_open_dev("/dev/character_buffer"); // Clear the screen alt_up_pixel_buffer_dma_clear_screen(pixel_buffer, 0); //Initialize the PS2 controller ps2_dev = alt_up_ps2_open_dev(PS2_0_NAME); }
int refresh(alt_up_pixel_buffer_dma_dev *pixel_buffer) { alt_up_pixel_buffer_dma_swap_buffers(pixel_buffer); while(alt_up_pixel_buffer_dma_check_swap_buffers_status(pixel_buffer)){ refreshSoundBG(sb); } //usleep(66666); return 1; }
void updateVGA() { // Swap background and foreground buffers alt_up_pixel_buffer_dma_swap_buffers(pixel_buffer); // Wait for the swap to complete while(alt_up_pixel_buffer_dma_check_swap_buffers_status(pixel_buffer)); }
void draw_nothing() { if(0) // Check if in waiting mode { bluebackground(v.pixel_buffer); alt_up_pixel_buffer_dma_swap_buffers(v.pixel_buffer); while (alt_up_pixel_buffer_dma_check_swap_buffers_status(v.pixel_buffer)); if(v.blank_flag == FALSE) { alt_up_char_buffer_clear(v.char_buffer); alt_up_char_buffer_string(v.char_buffer, "Waiting for user input...", 27, 30); v.blank_flag = TRUE; } } }
void display_score() { char* display_score_message[20]; if(m == displayscore) { bluebackground(v.pixel_buffer); // Swap buffers alt_up_pixel_buffer_dma_swap_buffers(v.pixel_buffer); while (alt_up_pixel_buffer_dma_check_swap_buffers_status(v.pixel_buffer)); alt_up_char_buffer_clear(v.char_buffer); sprintf( display_score_message, "FINAL SCORE: %d", rb.score ); alt_up_char_buffer_string(v.char_buffer, "GAME OVER.", 36, 20); alt_up_char_buffer_string(v.char_buffer, display_score_message, 32, 30); } }
/* Initialze the character and pixel buffers for writing */ void initBuffers(void) { // Use the name of your pixel buffer DMA core pixel_buffer = alt_up_pixel_buffer_dma_open_dev(PIXEL_BUFFER_DMA_NAME); unsigned int pixel_buffer_addr1 = PIXEL_BUFFER_BASE; unsigned int pixel_buffer_addr2 = PIXEL_BUFFER_BASE + (320 * 240 * 2); // Set the 1st buffer address alt_up_pixel_buffer_dma_change_back_buffer_address(pixel_buffer, pixel_buffer_addr1); // Swap buffers – we have to swap because there is only an API function // to set the address of the background buffer. alt_up_pixel_buffer_dma_swap_buffers(pixel_buffer); while (alt_up_pixel_buffer_dma_check_swap_buffers_status(pixel_buffer)); // Set the 2nd buffer address alt_up_pixel_buffer_dma_change_back_buffer_address(pixel_buffer, pixel_buffer_addr2); // Clear both buffers (this makes all pixels black) alt_up_pixel_buffer_dma_clear_screen(pixel_buffer, 0); alt_up_pixel_buffer_dma_clear_screen(pixel_buffer, 1); char_buffer = alt_up_char_buffer_open_dev("/dev/char_drawer"); alt_up_char_buffer_init(char_buffer); alt_up_char_buffer_clear(char_buffer); }
int main(){ printf("NEW GAME!\n\n"); volatile int old_game_state = 0; int doge = 0; //animation counter //buffer init stuff pixel_buffer = alt_up_pixel_buffer_dma_open_dev("/dev/pixel_buffer_dma"); char_buffer = alt_up_char_buffer_open_dev("/dev/char_drawer"); //phil's stuff master* m = master_init(); printf("NEW GAME!\n\n"); // Set the 1st buffer address alt_up_pixel_buffer_dma_change_back_buffer_address(pixel_buffer,pixel_buffer_addr1); // Swap buffers – we have to swap because there is only an API function // to set the address of the background buffer. alt_up_pixel_buffer_dma_swap_buffers(pixel_buffer); while (alt_up_pixel_buffer_dma_check_swap_buffers_status(pixel_buffer)); // Set the 2nd buffer address alt_up_pixel_buffer_dma_change_back_buffer_address(pixel_buffer,pixel_buffer_addr2); printf("NEW GAME!\n\n"); // Clear the screen alt_up_pixel_buffer_dma_clear_screen(pixel_buffer, 1); alt_up_pixel_buffer_dma_swap_buffers(pixel_buffer); while (alt_up_pixel_buffer_dma_check_swap_buffers_status(pixel_buffer)); alt_up_pixel_buffer_dma_clear_screen(pixel_buffer, 1); alt_up_pixel_buffer_dma_swap_buffers(pixel_buffer); while (alt_up_pixel_buffer_dma_check_swap_buffers_status(pixel_buffer)); alt_up_char_buffer_clear(char_buffer); //Write some text alt_up_char_buffer_string(char_buffer, "LOADING...", 0, 0); //load bitmap files title = read_bmp("title.bmp"); alt_up_char_buffer_string(char_buffer, "title.bmp", 0, 2); menu = read_bmp("menu.bmp"); alt_up_char_buffer_string(char_buffer, "MENU.BMP", 0, 3); selA = read_bmp("selA.bmp"); alt_up_char_buffer_string(char_buffer, "selA.bmp", 0, 4); selB = read_bmp("selB.bmp"); alt_up_char_buffer_string(char_buffer, "selB.bmp", 0, 5); selC = read_bmp("selC.bmp"); alt_up_char_buffer_string(char_buffer, "selC.bmp", 0, 6); dead = read_bmp("dead.bmp"); alt_up_char_buffer_string(char_buffer, "dead.bmp", 0, 7); bmp * b = read_bmp("para1.bmp"); alt_up_char_buffer_string(char_buffer, "para.bmp", 0, 8); bmp * doge0 = read_bmp("doge0.bmp"); alt_up_char_buffer_string(char_buffer, "doge0.bmp", 0, 9); bmp * doge1 = read_bmp("doge1.bmp"); alt_up_char_buffer_string(char_buffer, "doge1.bmp", 0, 10); bmp * doge2 = read_bmp("doge2.bmp"); alt_up_char_buffer_string(char_buffer, "doge2.bmp", 0, 11); bmp * doge3 = read_bmp("doge3.bmp"); alt_up_char_buffer_string(char_buffer, "doge3.bmp", 0, 12); bmp * flat = read_bmp("flat.bmp"); alt_up_char_buffer_string(char_buffer, "flat.bmp", 0, 13); bmp * coin = read_bmp("coin.bmp"); alt_up_char_buffer_string(char_buffer, "coin.bmp", 0, 14); bmp * spike = read_bmp("spike.bmp"); alt_up_char_buffer_string(char_buffer, "spike.bmp", 0, 15); bmp * box1 = read_bmp("box1.bmp"); alt_up_char_buffer_string(char_buffer, "box1.bmp", 0, 16); bmp * box3 = read_bmp("box3.bmp"); alt_up_char_buffer_string(char_buffer, "box3.bmp", 0, 17); bmp * low = read_bmp("low.bmp"); alt_up_char_buffer_string(char_buffer, "low.bmp", 0, 18); bmp * flatb = read_bmp("flatb.bmp"); alt_up_char_buffer_string(char_buffer, "flatb.bmp", 0, 19); bmp * flatr = read_bmp("flatr.bmp"); alt_up_char_buffer_string(char_buffer, "flatr.bmp", 0, 20); bmp * blue = read_bmp("bstar.bmp"); alt_up_char_buffer_string(char_buffer, "blue.bmp", 0, 21); bmp * red = read_bmp("rstar.bmp"); alt_up_char_buffer_string(char_buffer, "red.bmp", 0, 22); bmp * flag_img = read_bmp("flag.bmp"); alt_up_char_buffer_string(char_buffer, "flag.bmp", 0, 23); name = read_bmp("name.bmp"); alt_up_char_buffer_string(char_buffer, "name.bmp", 0, 24); instr = read_bmp("instr.bmp"); alt_up_char_buffer_string(char_buffer, "instr.bmp", 0, 25); dcol = read_bmp("dcol.bmp"); alt_up_char_buffer_string(char_buffer, "dcol.bmp", 0, 26); win = read_bmp("win.bmp"); alt_up_char_buffer_string(char_buffer, "win.bmp", 0,27); alt_up_char_buffer_clear(char_buffer); printf("NEW GAME!\n\n"); //interrupt init stuff (for object writing) //TIMERPERIOD int timer_period = 1 * 500000; IOWR_16DIRECT(TIMER_0_BASE, 8, timer_period & 0xFFFF); //writes the period to the hardware timer IOWR_16DIRECT(TIMER_0_BASE, 12, timer_period >> 16); IOWR_16DIRECT(TIMER_0_BASE, 4, 1 << 3); //stop timer alt_irq_register(TIMER_0_IRQ,NULL,(void*)handle_timer_interrupts);//registers function to a specific IRQ //IOWR_16DIRECT(TIMER_0_BASE, 4, 0x5); //start timer //SET UP KEYBOARD INTERRUPT// ps2 = alt_up_ps2_open_dev(KEYBOARD_NAME); alt_up_ps2_init(ps2); alt_up_ps2_clear_fifo(ps2); //void* keyboard_control_register_ptr = (void*) (PS2_0_BASE + 4); alt_irq_register(PS2_0_IRQ, m, keyboard_ISR); alt_up_ps2_enable_read_interrupt(ps2); char sw = 0; char p_sw = 0; ///////////////////////////////////////////////////////////////////////// printf("NEW GAME!\n\n"); //SUPERDUPERLOOP while (1){ printf("old state:%i\nnew state: %i\n\n",old_game_state, game_state); draw_menu(game_state); //update screen while (old_game_state == game_state); printf("old state:%i\nnew state: %i\n\n",old_game_state, game_state); //only when entering a new menu alt_up_char_buffer_clear(char_buffer); //ENTER GAME LOOP if (game_state == 5){ printf("START GAME! LEVEL: %i\n\n", highlighted_level); alt_up_char_buffer_string(char_buffer, playername, 10, 4); if (highlighted_level == 1) { free_bmp(b); b = read_bmp("para1.bmp"); game_start(m,b,"lvl/1.txt","song1.wav"); } else if (highlighted_level == 2) { free_bmp(b); b = read_bmp("bg2.bmp"); game_start(m,b,"lvl/2.txt","a/abcd.wav"); } else{ free_bmp(b); b = read_bmp("bg3.bmp"); game_start(m,b,"lvl/2.txt","a/nyan1.wav"); } //collision loop while(!m->c->collide && !m->c->win){ alt_up_char_buffer_string(char_buffer, "POINTS: ", 50, 4); char str[15]; sprintf(str, "%d", m->c->points); alt_up_char_buffer_string(char_buffer, str, 58, 4); sw = IORD_8DIRECT(SWITCHES_BASE,0); IOWR_8DIRECT(LEDS_BASE,0,sw); if(sw == 1 && p_sw == 0){ //m->ab->sfx_flag = 1; m->c->jump_pressed = 1; } p_sw = sw; //boxes int i; for( i= 0 ; i < OBJECT_SIZE ; i++) { if(m->o->color[i] == -1) draw_object(pixel_buffer, box, flat, i); else if(m->o->color[i] == 0) draw_object(pixel_buffer, box, flatb, i); else if(m->o->color[i] == 1) draw_object(pixel_buffer, box, flatr, i); draw_object(pixel_buffer, co, coin, i ); draw_object(pixel_buffer, spikes, spike, i); draw_object(pixel_buffer, box_3, box3, i); draw_object(pixel_buffer, box_1, box1, i); // if(m->color_gates->color[i] == 1) // draw_object(pixel_buffer,cgates, rgate,i); // else if (m->color_gates->color[i] == 0) // draw_object(pixel_buffer,cgates, bgate,i); } //draws the win flag draw_object(pixel_buffer, flag, flag_img, 0); //Draw Doge if (m->c->ducking) draw_bmp(pixel_buffer,m->c->x - m->c->width, m->c->y - m->c->height,low); else{ doge++; if(doge == 37) doge = 0; if( doge <9) draw_bmp(pixel_buffer,m->c->x - m->c->width, m->c->y - m->c->height,doge0); else if (doge <18) draw_bmp(pixel_buffer,m->c->x - m->c->width, m->c->y - m->c->height,doge1); else if (doge <27) draw_bmp(pixel_buffer,m->c->x - m->c->width, m->c->y - m->c->height,doge2); else draw_bmp(pixel_buffer,m->c->x - m->c->width, m->c->y - m->c->height,doge3); } //Draw Color Indicator if(m->c->color == 0) draw_bmp(pixel_buffer, m->c->x- m->c->width + 5, m->c->y - m->c->height - 10, blue); else draw_bmp(pixel_buffer,m->c->x- m->c->width + 5, m->c->y - m->c->height - 10, red); p_counter++; if(p_counter == 3){ p_shift++; alt_up_pixel_buffer_dma_swap_buffers(pixel_buffer); while(alt_up_pixel_buffer_dma_check_swap_buffers_status(pixel_buffer)) refill_buffer(m->ab, "a/abcd.wav");//refills the audio buffer unrolled_parallax_draw(pixel_buffer, b); }else if(p_counter == 4){ //if(p_counter == 1){ alt_up_pixel_buffer_dma_swap_buffers(pixel_buffer); while(alt_up_pixel_buffer_dma_check_swap_buffers_status(pixel_buffer)) refill_buffer(m->ab, "a/abcd.wav");//refills the audio buffer unrolled_parallax_draw(pixel_buffer, b); p_counter = 0; }else{ // alt_up_pixel_buffer_dma_swap_buffers(pixel_buffer); // while(alt_up_pixel_buffer_dma_check_swap_buffers_status(pixel_buffer)) // refill_buffer(m->ab, "a/abcd.wav");//refills the audio buffer // unrolled_parallax_draw(pixel_buffer, b); alt_up_pixel_buffer_dma_swap_buffers(pixel_buffer); while(alt_up_pixel_buffer_dma_check_swap_buffers_status(pixel_buffer)) refill_buffer(m->ab, "a/abcd.wav");//refills the audio buffer int j; for( j = 0 ; j < OBJECT_SIZE ; j++) { clear_object(pixel_buffer, box, b, j); clear_object(pixel_buffer, co, b, j); clear_object(pixel_buffer, spikes, b, j); clear_object(pixel_buffer, box_3, b, j); clear_object(pixel_buffer, box_1, b, j); } clear_object(pixel_buffer,flag,b,0); //clear doge clear_doge(pixel_buffer, m->c->x - m->c->width, m->c->y - m->c->height , b); //clear_loc(pixel_buffer,m->c->x- m->c->width + 5, m->c->y - m->c->height - 10,m->c->x- m->c->width + 5 - 10, m->c->y - m->c->height - 20,b); } } alt_up_char_buffer_string(char_buffer, "POINTS: ", 50, 4); char str[15]; sprintf(str, "%d", m->c->points); alt_up_char_buffer_string(char_buffer, str, 58, 4); printf("game exited\n"); if(m->c->win) game_state = 7; else game_state = 6; highlighted_item = 3; game_reset(m); } //exit game mode, restart superduperloop in main menu old_game_state = game_state; } return 0; }
int move(int x[][100], int y[][100], int z, int colour, int laser) { int i; // variable used in the for loops int down; unsigned int pixel_buffer_addr1 = PIXEL_BUFFER_BASE; unsigned int pixel_buffer_addr2 = PIXEL_BUFFER_BASE + (512 * 240 * 2); alt_up_pixel_buffer_dma_dev* pixel_buffer; pixel_buffer = alt_up_pixel_buffer_dma_open_dev( "/dev/video_pixel_buffer_dma_0"); // Set the 1st buffer address alt_up_pixel_buffer_dma_change_back_buffer_address(pixel_buffer, pixel_buffer_addr1); draw_alien_row(11, 19, x, y, 0); draw_alien_row(21, 29, x, y, 0); draw_alien_row(31, 39, x, y, 0); draw_alien_row(41, 49, x, y, 0); draw_alien_row(51, 59, x, y, 0); /* These embedded if statements allow us to dynamically move the aliens * further across the screen if a row or column is completely dead */ if (x[11][0] == 0 && x[21][0] == 0 && x[31][0] == 0 && x[41][0] == 0 && x[51][0] == 0) { //first column is gone if (x[12][0] == 0 && x[22][0] == 0 && x[32][0] == 0 && x[42][0] == 0 && x[52][0] == 0) { if (x[13][0] == 0 && x[23][0] == 0 && x[33][0] == 0 && x[43][0] == 0 && x[53][0] == 0) { if (x[14][0] == 0 && x[24][0] == 0 && x[34][0] == 0 && x[44][0] == 0 && x[54][0] == 0) { if (x[15][0] == 0 && x[25][0] == 0 && x[35][0] == 0 && x[45][0] == 0 && x[55][0] == 0) { if (x[16][0] == 0 && x[26][0] == 0 && x[36][0] == 0 && x[46][0] == 0 && x[56][0] == 0) { if (x[17][0] == 0 && x[27][0] == 0 && x[37][0] == 0 && x[47][0] == 0 && x[57][0] == 0) { if (x[18][1] < 10) { z = 1; if (x[51][0] == 0 && x[52][0] == 0 && x[53][0] == 0 && x[54][0] == 0 && x[55][0] == 0 && x[56][0] == 0 && x[57][0] == 0 && x[58][0] == 0) { // bottom row is gone if (x[41][0] == 0 && x[42][0] == 0 && x[43][0] == 0 && x[44][0] == 0 && x[45][0] == 0 && x[46][0] == 0 && x[47][0] == 0 && x[48][0] == 0) { if (x[31][0] == 0 && x[32][0] == 0 && x[33][0] == 0 && x[34][0] == 0 && x[35][0] == 0 && x[36][0] == 0 && x[37][0] == 0 && x[38][0] == 0) { if (x[21][0] == 0 && x[22][0] == 0 && x[23][0] == 0 && x[24][0] == 0 && x[25][0] == 0 && x[26][0] == 0 && x[27][0] == 0 && x[28][0] == 0) { if (y[51][2] < 255) down = 1; } if (y[51][2] < 235) down = 1; } if (y[51][2] < 215) down = 1; } if (y[51][2] < 195) down = 1; } } } else if (x[17][1] < 10) { z = 1; if (x[51][0] == 0 && x[52][0] == 0 && x[53][0] == 0 && x[54][0] == 0 && x[55][0] == 0 && x[56][0] == 0 && x[57][0] == 0 && x[58][0] == 0) { // bottom row is gone if (x[41][0] == 0 && x[42][0] == 0 && x[43][0] == 0 && x[44][0] == 0 && x[45][0] == 0 && x[46][0] == 0 && x[47][0] == 0 && x[48][0] == 0) { if (x[31][0] == 0 && x[32][0] == 0 && x[33][0] == 0 && x[34][0] == 0 && x[35][0] == 0 && x[36][0] == 0 && x[37][0] == 0 && x[38][0] == 0) { if (x[21][0] == 0 && x[22][0] == 0 && x[23][0] == 0 && x[24][0] == 0 && x[25][0] == 0 && x[26][0] == 0 && x[27][0] == 0 && x[28][0] == 0) { if (y[51][2] < 255) down = 1; } if (y[51][2] < 235) down = 1; } if (y[51][2] < 215) down = 1; } if (y[51][2] < 195) down = 1; } } } else if (x[16][1] < 10) { z = 1; if (x[51][0] == 0 && x[52][0] == 0 && x[53][0] == 0 && x[54][0] == 0 && x[55][0] == 0 && x[56][0] == 0 && x[57][0] == 0 && x[58][0] == 0) { // bottom row is gone if (x[41][0] == 0 && x[42][0] == 0 && x[43][0] == 0 && x[44][0] == 0 && x[45][0] == 0 && x[46][0] == 0 && x[47][0] == 0 && x[48][0] == 0) { if (x[31][0] == 0 && x[32][0] == 0 && x[33][0] == 0 && x[34][0] == 0 && x[35][0] == 0 && x[36][0] == 0 && x[37][0] == 0 && x[38][0] == 0) { if (x[21][0] == 0 && x[22][0] == 0 && x[23][0] == 0 && x[24][0] == 0 && x[25][0] == 0 && x[26][0] == 0 && x[27][0] == 0 && x[28][0] == 0) { if (y[51][2] < 255) down = 1; } if (y[51][2] < 235) down = 1; } if (y[51][2] < 215) down = 1; } if (y[51][2] < 195) down = 1; } } } else if (x[15][1] < 10) { z = 1; if (x[51][0] == 0 && x[52][0] == 0 && x[53][0] == 0 && x[54][0] == 0 && x[55][0] == 0 && x[56][0] == 0 && x[57][0] == 0 && x[58][0] == 0) { // bottom row is gone if (x[41][0] == 0 && x[42][0] == 0 && x[43][0] == 0 && x[44][0] == 0 && x[45][0] == 0 && x[46][0] == 0 && x[47][0] == 0 && x[48][0] == 0) { if (x[31][0] == 0 && x[32][0] == 0 && x[33][0] == 0 && x[34][0] == 0 && x[35][0] == 0 && x[36][0] == 0 && x[37][0] == 0 && x[38][0] == 0) { if (x[21][0] == 0 && x[22][0] == 0 && x[23][0] == 0 && x[24][0] == 0 && x[25][0] == 0 && x[26][0] == 0 && x[27][0] == 0 && x[28][0] == 0) { if (y[51][2] < 255) down = 1; } if (y[51][2] < 235) down = 1; } if (y[51][2] < 215) down = 1; } if (y[51][2] < 195) down = 1; } } } else if (x[14][1] < 10) { z = 1; if (x[51][0] == 0 && x[52][0] == 0 && x[53][0] == 0 && x[54][0] == 0 && x[55][0] == 0 && x[56][0] == 0 && x[57][0] == 0 && x[58][0] == 0) { // bottom row is gone if (x[41][0] == 0 && x[42][0] == 0 && x[43][0] == 0 && x[44][0] == 0 && x[45][0] == 0 && x[46][0] == 0 && x[47][0] == 0 && x[48][0] == 0) { if (x[31][0] == 0 && x[32][0] == 0 && x[33][0] == 0 && x[34][0] == 0 && x[35][0] == 0 && x[36][0] == 0 && x[37][0] == 0 && x[38][0] == 0) { if (x[21][0] == 0 && x[22][0] == 0 && x[23][0] == 0 && x[24][0] == 0 && x[25][0] == 0 && x[26][0] == 0 && x[27][0] == 0 && x[28][0] == 0) { if (y[51][2] < 255) down = 1; } if (y[51][2] < 235) down = 1; } if (y[51][2] < 215) down = 1; } if (y[51][2] < 195) down = 1; } } } else if (x[13][1] < 10) { z = 1; if (x[51][0] == 0 && x[52][0] == 0 && x[53][0] == 0 && x[54][0] == 0 && x[55][0] == 0 && x[56][0] == 0 && x[57][0] == 0 && x[58][0] == 0) { // bottom row is gone if (x[41][0] == 0 && x[42][0] == 0 && x[43][0] == 0 && x[44][0] == 0 && x[45][0] == 0 && x[46][0] == 0 && x[47][0] == 0 && x[48][0] == 0) { if (x[31][0] == 0 && x[32][0] == 0 && x[33][0] == 0 && x[34][0] == 0 && x[35][0] == 0 && x[36][0] == 0 && x[37][0] == 0 && x[38][0] == 0) { if (x[21][0] == 0 && x[22][0] == 0 && x[23][0] == 0 && x[24][0] == 0 && x[25][0] == 0 && x[26][0] == 0 && x[27][0] == 0 && x[28][0] == 0) { if (y[51][2] < 255) down = 1; } if (y[51][2] < 235) down = 1; } if (y[51][2] < 215) down = 1; } if (y[51][2] < 195) down = 1; } } } else if (x[12][1] < 10) { z = 1; if (x[51][0] == 0 && x[52][0] == 0 && x[53][0] == 0 && x[54][0] == 0 && x[55][0] == 0 && x[56][0] == 0 && x[57][0] == 0 && x[58][0] == 0) { // bottom row is gone if (x[41][0] == 0 && x[42][0] == 0 && x[43][0] == 0 && x[44][0] == 0 && x[45][0] == 0 && x[46][0] == 0 && x[47][0] == 0 && x[48][0] == 0) { if (x[31][0] == 0 && x[32][0] == 0 && x[33][0] == 0 && x[34][0] == 0 && x[35][0] == 0 && x[36][0] == 0 && x[37][0] == 0 && x[38][0] == 0) { if (x[21][0] == 0 && x[22][0] == 0 && x[23][0] == 0 && x[24][0] == 0 && x[25][0] == 0 && x[26][0] == 0 && x[27][0] == 0 && x[28][0] == 0) { if (y[51][2] < 255) down = 1; } if (y[51][2] < 235) down = 1; } if (y[51][2] < 215) down = 1; } if (y[51][2] < 195) down = 1; } } } else if (x[11][1] < 10) { z = 1; if (x[51][0] == 0 && x[52][0] == 0 && x[53][0] == 0 && x[54][0] == 0 && x[55][0] == 0 && x[56][0] == 0 && x[57][0] == 0 && x[58][0] == 0) { // bottom row is gone if (x[41][0] == 0 && x[42][0] == 0 && x[43][0] == 0 && x[44][0] == 0 && x[45][0] == 0 && x[46][0] == 0 && x[47][0] == 0 && x[48][0] == 0) { if (x[31][0] == 0 && x[32][0] == 0 && x[33][0] == 0 && x[34][0] == 0 && x[35][0] == 0 && x[36][0] == 0 && x[37][0] == 0 && x[38][0] == 0) { if (x[21][0] == 0 && x[22][0] == 0 && x[23][0] == 0 && x[24][0] == 0 && x[25][0] == 0 && x[26][0] == 0 && x[27][0] == 0 && x[28][0] == 0) { if (y[51][2] < 255) down = 1; } if (y[51][2] < 235) down = 1; } if (y[51][2] < 215) down = 1; } if (y[51][2] < 195) down = 1; } if (y[51][2] < 180) down = 1; } if (x[18][0] == 0 && x[28][0] == 0 && x[38][0] == 0 && x[48][0] == 0 && x[58][0] == 0) { if (x[17][0] == 0 && x[27][0] == 0 && x[37][0] == 0 && x[47][0] == 0 && x[57][0] == 0) { if (x[16][0] == 0 && x[26][0] == 0 && x[36][0] == 0 && x[46][0] == 0 && x[56][0] == 0) { if (x[15][0] == 0 && x[25][0] == 0 && x[35][0] == 0 && x[45][0] == 0 && x[55][0] == 0) { if (x[14][0] == 0 && x[24][0] == 0 && x[34][0] == 0 && x[44][0] == 0 && x[54][0] == 0) { if (x[13][0] == 0 && x[23][0] == 0 && x[33][0] == 0 && x[43][0] == 0 && x[53][0] == 0) { if (x[12][0] == 0 && x[22][0] == 0 && x[32][0] == 0 && x[42][0] == 0 && x[52][0] == 0) { if (x[11][2] > 300) { z = 0; } } else if (x[12][2] > 300) { z = 0; } } else if (x[13][2] > 300) { z = 0; } } else if (x[14][2] > 300) { z = 0; } } else if (x[15][2] > 300) { z = 0; } } else if (x[16][2] > 300) { z = 0; } } else if (x[17][2] > 300) { z = 0; } } else if (x[18][2] > 300) { z = 0; } if (z == 1) { x[11][1] += 2; x[11][2] += 2; } if (z == 0) { x[11][1] -= 2; x[11][2] -= 2; } if (down == 1) { y[11][1] += 10; y[11][2] += 10; y[21][1] += 10; y[21][2] += 10; y[31][1] += 10; y[31][2] += 10; y[41][1] += 10; y[41][2] += 10; y[51][1] += 10; y[51][2] += 10; down = 0; } // the first two clusters initiate the y values x[21][1] = x[11][1]; x[21][2] = x[11][2]; x[31][1] = x[11][1]; x[31][2] = x[11][2]; x[41][1] = x[11][1]; x[41][2] = x[11][2]; x[51][1] = x[11][1]; x[51][2] = x[11][2]; //switches aliens on/off before draw //aliens_alive(x, y); //changes the values of the x coordinates for the whole line change_line_xcoord(12, 19, x, y); change_line_xcoord(22, 29, x, y); change_line_xcoord(32, 39, x, y); change_line_xcoord(42, 49, x, y); change_line_xcoord(52, 59, x, y); // draws the boxes for the line draw_alien_row(11, 19, x, y, colour); draw_alien_row(21, 29, x, y, colour); draw_alien_row(31, 39, x, y, colour); draw_alien_row(41, 49, x, y, colour); draw_alien_row(51, 59, x, y, colour); alt_up_pixel_buffer_dma_swap_buffers(pixel_buffer); while (alt_up_pixel_buffer_dma_check_swap_buffers_status(pixel_buffer)) ; // Set the 2nd buffer address alt_up_pixel_buffer_dma_change_back_buffer_address(pixel_buffer, pixel_buffer_addr2); return z; //returns z to remember the direction of boxes }
void draw_sheetmusic() { // Symbolic constants int x_indent = 16; int y_indent = 100; int space_height = (240 - 2*y_indent)/4; // Declare variables int i; if(m == blank) { rb.background_flag = FALSE; if(v.blank_flag == FALSE) { alt_up_pixel_buffer_dma_draw_box(v.pixel_buffer, 0, 0, 319, 239, 0xFFFF, 1); // White box to fill the back buffer for(i=0; i<5; i++) // Draw 5 horizontal lines of the musical staff to the back buffer alt_up_pixel_buffer_dma_draw_hline(v.pixel_buffer, x_indent-2, 320-(x_indent-2), y_indent+space_height*i, 0x0000, 1); // Double bar line at the start alt_up_pixel_buffer_dma_draw_box(v.pixel_buffer, x_indent-4, y_indent, x_indent-2, 240-y_indent, 0x0000, 1); alt_up_pixel_buffer_dma_draw_vline(v.pixel_buffer, x_indent, y_indent, 240-y_indent, 0x0000, 1); // Double bar line at the end alt_up_pixel_buffer_dma_draw_box(v.pixel_buffer, 320-(x_indent-4), y_indent, 320-(x_indent-2), 240-y_indent, 0x0000, 1); alt_up_pixel_buffer_dma_draw_vline(v.pixel_buffer, 320-x_indent, y_indent, 240-y_indent, 0x0000, 1); // Three bar lines to divide the staff into four measures alt_up_pixel_buffer_dma_draw_vline(v.pixel_buffer, (160+x_indent)/2, y_indent, 240-y_indent, 0x0000, 1); alt_up_pixel_buffer_dma_draw_vline(v.pixel_buffer, 160, y_indent, 240-y_indent, 0x0000, 1); alt_up_pixel_buffer_dma_draw_vline(v.pixel_buffer, (480-x_indent)/2, y_indent, 240-y_indent, 0x0000, 1); // Draw some notes: C major scale draw_qnote_on_sheetmusic(v.pixel_buffer, 0, 0); draw_qnote_on_sheetmusic(v.pixel_buffer, 1, 1); draw_qnote_on_sheetmusic(v.pixel_buffer, 2, 2); draw_qnote_on_sheetmusic(v.pixel_buffer, 3, 3); draw_qnote_on_sheetmusic(v.pixel_buffer, 4, 4); draw_qnote_on_sheetmusic(v.pixel_buffer, 5, 5); draw_qnote_on_sheetmusic(v.pixel_buffer, 6, 6); draw_qnote_on_sheetmusic(v.pixel_buffer, 7, 7); draw_qnote_on_sheetmusic(v.pixel_buffer, 7, 8); draw_qnote_on_sheetmusic(v.pixel_buffer, 6, 9); draw_qnote_on_sheetmusic(v.pixel_buffer, 5, 10); draw_qnote_on_sheetmusic(v.pixel_buffer, 4, 11); draw_qnote_on_sheetmusic(v.pixel_buffer, 3, 12); draw_qnote_on_sheetmusic(v.pixel_buffer, 2, 13); draw_qnote_on_sheetmusic(v.pixel_buffer, 1, 14); draw_qnote_on_sheetmusic(v.pixel_buffer, 0, 15); // Blue box and message near top of the screen alt_up_pixel_buffer_dma_draw_box(v.pixel_buffer, 100, 26, 220, 40, 0x122B, 1); alt_up_char_buffer_clear(v.char_buffer); alt_up_char_buffer_string(v.char_buffer, "Waiting for user input...", 28, 8); v.blank_flag = TRUE; // Swap buffers alt_up_pixel_buffer_dma_swap_buffers(v.pixel_buffer); while (alt_up_pixel_buffer_dma_check_swap_buffers_status(v.pixel_buffer)); } } }
int update_eq_sinc(int amplitude, int green) // FUNCTION: Updates the equaliser for pretty graphics and swaps the pixel buffer // REQUIRES: Initialised pixel buffer // RETURNS: New green value { // Declare variables int i, j, red, blue, height, y_value, original_top, x_axis, x_value; float period = ((rand() % 200) + 600.0) / 100.0; // Randomly generate period between 6.0 and 8.0 uint16_t colour; int random_amplitude; float random_period; if(/* alt_timestamp()/(float) alt_timestamp_freq() > EQ_TIME_CONSTANT_S && */ m == eq) { v.blank_flag = FALSE; rb.background_flag = FALSE; alt_up_char_buffer_clear(v.char_buffer); random_amplitude = (rand() % 50) + 50; random_period = ((rand() % 200) + 600.0) / 100.0; printf("Random amplitude: %d\n", random_amplitude); if(rand() % 1 == 0) { if(green < 251) green += 5; } else if(green > 5) green -= 5; alt_up_pixel_buffer_dma_clear_screen(v.pixel_buffer, 1); // Clear back buffer x_axis = 190; original_top = x_axis - x_axis*amplitude/MAX_AMPLITUDE; for(x_value=0; x_value < 160; x_value++) // Draw two-sided sinc function, almost to each side of the screen { red = 255*(160-x_value)/160; // red will increase towards the middle of the screen // Calculate value of the sinc function for x-coordinate x_value if(x_value>0) height = (x_axis*amplitude/MAX_AMPLITUDE)*sin(x_value/period) /(x_value/period); else height = x_axis*amplitude/MAX_AMPLITUDE; y_value = x_axis - height; if(height>0) // This means the sinc function is above the x-axis { for(j=y_value; j<=x_axis; j++) // j is the y-coordinate { blue = 255*(j - original_top)/(x_axis*amplitude/MAX_AMPLITUDE); // blue will increase towards the x_axis of the screen colour = drawRGB24toRGB565(red, green, blue); i=160-x_value; // i is the x-coordinate alt_up_pixel_buffer_dma_draw(v.pixel_buffer, colour, i, j); i=160+x_value; // i is the x-coordinate alt_up_pixel_buffer_dma_draw(v.pixel_buffer, colour, i, j); } } else // This means the sinc function is on or below the x-axis { for(j=y_value; j>=x_axis; j--) // j is the y-coordinate { blue = 255*(2*x_axis-j - original_top)/(x_axis*amplitude/MAX_AMPLITUDE); // blue will increase towards the x_axis of the screen colour = drawRGB24toRGB565(red, green, blue); i=160-x_value; // i is the x-coordinate alt_up_pixel_buffer_dma_draw(v.pixel_buffer, colour, i, j); i=160+x_value; // i is the x-coordinate alt_up_pixel_buffer_dma_draw(v.pixel_buffer, colour, i, j); } } } // Swap buffers alt_up_pixel_buffer_dma_swap_buffers(v.pixel_buffer); while (alt_up_pixel_buffer_dma_check_swap_buffers_status(v.pixel_buffer)); // alt_timestamp_start(); } return green; }
void update_rb(int note_pressed) // FUNCTION: Updates the RB_data struct and displays the new data on the moniter. // REQUIRES: if no note has been pressed, note_pressed < 0 // if a note has been pressed, 0 <= note_pressed <= 11 // RETURNS: None { // Declare variables int i, j, difference; char* all_notes[12] = {"C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"}; if(m == notegame) // Check if in rockband mode { v.blank_flag = FALSE; if(rb.background_flag == FALSE) { // Clear char buffer alt_up_char_buffer_clear(v.char_buffer); for(j=0; j<12; j++) alt_up_char_buffer_string(v.char_buffer, all_notes[j], 10 + 5*j, 55 - rb.CORRECT_ZONE_HEIGHT/2); // Print the pitch at its corresponding location rb.background_flag = TRUE; } /* // Draw blue background and correct zone to back buffer bluebackground(v.pixel_buffer); alt_up_pixel_buffer_dma_draw_hline(v.pixel_buffer, 0, 319, 220-4*rb.CORRECT_ZONE_HEIGHT, 0x0000, 1); // Top of the correct zone alt_up_pixel_buffer_dma_draw_box(v.pixel_buffer, 0, 221-4*rb.CORRECT_ZONE_HEIGHT, 319, 219, 0xCCCC, 1); alt_up_pixel_buffer_dma_draw_hline(v.pixel_buffer, 0, 319, 220, 0x0000, 1); // Bottom of the correct zone // Swap buffers alt_up_pixel_buffer_dma_swap_buffers(v.pixel_buffer); while (alt_up_pixel_buffer_dma_check_swap_buffers_status(v.pixel_buffer)); */ // Draw blue background and correct zone to back buffer bluebackground(v.pixel_buffer); draw_correct_zone(v.pixel_buffer, rb.CORRECT_ZONE_HEIGHT); // Clear char buffer alt_up_char_buffer_clear(v.char_buffer); for(j=0; j<12; j++) alt_up_char_buffer_string(v.char_buffer, all_notes[j], 10 + 5*j, 55 - rb.CORRECT_ZONE_HEIGHT/2); // Print the pitch at its corresponding location // Clear char buffer // alt_up_char_buffer_clear(v.char_buffer); for(j=0; j<12; j++) rb.in_correct_zone[j] = FALSE; // Reset all entries at each update //rb.time = alt_timestamp() / (float) alt_timestamp_freq(); // Time represents the amount of time passed since the game started, in seconds rb.count = rb.time / rb.RB_TIME_CONSTANT_S; // Count represents the number of time constants that have passed since the game started rb.count_difference = rb.count - rb.old_count; // Count_difference represents the number of time constants that have passed since the last time update_rb was called rb.old_count = rb.count; // Old_count represents the number of time constants passed from the start of the game to the last time update_rb was called rb.index = rb.count / 10; // Index represents the number of notes that are active // printf("Index:%d\n", rb.index); if(rb.index > rb.n + 6) { rb.finished = TRUE; m = displayscore; } rb.bottom_index = -1; // Initialise. This will be changed at some point in the for loop below, or after the for loop for(i=0; i<rb.index; i++) { difference = rb.index - i; rb.y_locations[i] = /* 4 + */ difference*10 + rb.count%10; // Check if there exists a note to be displayed and it is within range to be displayed on the screen if(rb.notes[i] != -1 && rb.y_locations[i] < 66) { // alt_up_char_buffer_string(v.char_buffer, rb.notes_char[i], rb.x_locations[i], rb.y_locations[i]); // Print the pitch at its corresponding location // eraser_rb(v.pixel_buffer, rb.y_locations[i] - rb.count_difference - 1, rb.x_locations[i], rb.CORRECT_ZONE_HEIGHT); // Erase the old note draw_rb_note_at(v.pixel_buffer, rb.y_locations[i], rb.x_locations[i]); // Draw new note if(rb.y_locations[i] >= 56 - rb.CORRECT_ZONE_HEIGHT && rb.y_locations[i] <= 55) // Check if the location is within the correct range { rb.in_correct_zone[rb.notes[i]] = TRUE; // Record that the pitch of note i is in the correct zone rb.bottom_index = i; // Since note i is in the correct zone { if(note_pressed == rb.notes[i]) // Check if the note in the correct zone matches the most recent piano key press { if(rb.already_counted[i] == FALSE) { rb.score++; rb.already_counted[i] = TRUE; } draw_rb_correct_note_at(v.pixel_buffer, rb.y_locations[i], rb.x_locations[i]); } } } } } if(rb.bottom_index == -1) // This means there was no note within the correct zone { while(rb.y_locations[i] < 56 - rb.CORRECT_ZONE_HEIGHT) i--; rb.bottom_index = i+1; // Set bottom_index to the index of the note closest to, and on top of, the correct zone } if(note_pressed >= 0) // Check if there has been a note pressed { if(rb.in_correct_zone[note_pressed] == TRUE) // Check if the note pressed is in the correct zone { draw_rb_correct_note_at(v.pixel_buffer, rb.y_locations[rb.bottom_index], rb.x_locations[rb.bottom_index]); rb.score++; } else { draw_rb_incorrect_note_at(v.pixel_buffer, rb.y_locations[rb.bottom_index], rb.x_locations[rb.bottom_index]); rb.score--; } } // Swap buffers alt_up_pixel_buffer_dma_swap_buffers(v.pixel_buffer); while (alt_up_pixel_buffer_dma_check_swap_buffers_status(v.pixel_buffer)); // Draw blue background and correct zone to back buffer /* bluebackground(v.pixel_buffer); alt_up_pixel_buffer_dma_draw_hline(v.pixel_buffer, 0, 319, 220-4*rb.CORRECT_ZONE_HEIGHT, 0x0000, 1); // Top of the correct zone alt_up_pixel_buffer_dma_draw_box(v.pixel_buffer, 0, 221-4*rb.CORRECT_ZONE_HEIGHT, 319, 219, 0xCCCC, 1); alt_up_pixel_buffer_dma_draw_hline(v.pixel_buffer, 0, 319, 220, 0x0000, 1); // Bottom of the correct zone */ // for(;;); } }
/******************************************************************************** * This program demonstrates use of the character and pixel buffer HAL code for * the DE2 Media computer. It: * -- places a blue box on the VGA display, and places a text string inside the box. * -- draws a big A on the screen, for ALTERA * -- "bounces" a colored box around the screen ********************************************************************************/ int main(void) { alt_up_pixel_buffer_dma_dev *pixel_buffer_dev; alt_up_char_buffer_dev *char_buffer_dev; /* used for drawing coordinates */ int x1, y1, x2, y2, deltax_1, deltax_2, deltay_1, deltay_2, delay = 0; /* create a message to be displayed on the VGA display */ char text_top_row[40] = "Altera DE2\0"; char text_bottom_row[40] = "Media Computer\0"; /* initialize the pixel buffer HAL */ pixel_buffer_dev = alt_up_pixel_buffer_dma_open_dev ("/dev/VGA_Pixel_Buffer"); if ( pixel_buffer_dev == NULL) alt_printf ("Error: could not open VGA pixel buffer device\n"); else alt_printf ("Opened character VGA pixel buffer device\n"); /* clear the graphics screen */ alt_up_pixel_buffer_dma_clear_screen(pixel_buffer_dev, 0); /* output text message in the middle of the VGA monitor */ char_buffer_dev = alt_up_char_buffer_open_dev ("/dev/VGA_Char_Buffer"); if (char_buffer_dev == NULL) { alt_printf ("Error: could not open character buffer device\n"); return -1; } else alt_printf ("Opened character buffer device\n"); alt_up_char_buffer_string (char_buffer_dev, text_top_row, 35, 29); alt_up_char_buffer_string (char_buffer_dev, text_bottom_row, 35, 30); /* now draw a background box for the text */ alt_up_pixel_buffer_dma_draw_box(pixel_buffer_dev, 34*4, 28*4, 50*4, 32*4, 0x187F, 0); /* now draw a big A for ALTERA */ draw_big_A (pixel_buffer_dev); /* now draw a red rectangle with diagonal green lines */ x1 = 20; y1 = 20; x2 = 50; y2 = 50; alt_up_pixel_buffer_dma_draw_rectangle(pixel_buffer_dev, x1, y1, x2, y2, 0xF800, 0); alt_up_pixel_buffer_dma_draw_line(pixel_buffer_dev, x1, y1, x2, y2, 0x07e0, 0); alt_up_pixel_buffer_dma_draw_line(pixel_buffer_dev, x1, y2, x2, y1, 0x07e0, 0); alt_up_pixel_buffer_dma_swap_buffers(pixel_buffer_dev); /* set the direction in which the box will move */ deltax_1 = deltax_2 = deltay_1 = deltay_2 = 1; while(1) { if (alt_up_pixel_buffer_dma_check_swap_buffers_status(pixel_buffer_dev) == 0) { /* If the screen has been drawn completely then we can draw a new image. This * section of the code will only be entered once every 60th of a second, because * this is how long it take the VGA controller to copy the image from memory to * the screen. */ delay = 1 - delay; if (delay == 0) { /* The delay is inserted to slow down the animation from 60 frames per second * to 30. Every other refresh cycle the code below will execute. We first erase * the box with Erase Rectangle */ alt_up_pixel_buffer_dma_draw_rectangle(pixel_buffer_dev, x1, y1, x2, y2, 0, 0); alt_up_pixel_buffer_dma_draw_line(pixel_buffer_dev, x1, y1, x2, y2, 0, 0); alt_up_pixel_buffer_dma_draw_line(pixel_buffer_dev, x1, y2, x2, y1, 0, 0); // move the rectangle x1 = x1 + deltax_1; x2 = x2 + deltax_2; y1 = y1 + deltay_1; y2 = y2 + deltay_2; if ((deltax_1 > 0) && (x1 >= alt_up_pixel_buffer_dma_x_res(pixel_buffer_dev) - 1)) { x1 = alt_up_pixel_buffer_dma_x_res(pixel_buffer_dev) - 1; deltax_1 = -deltax_1; } else if ((deltax_1 < 0) && (x1 <= 0)) { x1 = 0; deltax_1 = -deltax_1; } if ((deltax_2 > 0) && (x2 >= alt_up_pixel_buffer_dma_x_res(pixel_buffer_dev) - 1)) { x2 = alt_up_pixel_buffer_dma_x_res(pixel_buffer_dev) - 1; deltax_2 = -deltax_2; } else if ((deltax_2 < 0) && (x2 <= 0)) { x2 = 0; deltax_2 = -deltax_2; } if ((deltay_1 > 0) && (y1 >= alt_up_pixel_buffer_dma_y_res(pixel_buffer_dev) - 1)) { y1 = alt_up_pixel_buffer_dma_y_res(pixel_buffer_dev) - 1; deltay_1 = -deltay_1; } else if ((deltay_1 < 0) && (y1 <= 0)) { y1 = 0; deltay_1 = -deltay_1; } if ((deltay_2 > 0) && (y2 >= alt_up_pixel_buffer_dma_y_res(pixel_buffer_dev) - 1)) { y2 = alt_up_pixel_buffer_dma_y_res(pixel_buffer_dev) - 1; deltay_2 = -deltay_2; } else if ((deltay_2 < 0) && (y2 <= 0)) { y2 = 0; deltay_2 = -deltay_2; } // redraw Rectangle with diagonal lines alt_up_pixel_buffer_dma_draw_rectangle(pixel_buffer_dev, x1, y1, x2, y2, 0xF800, 0); alt_up_pixel_buffer_dma_draw_line(pixel_buffer_dev, x1, y1, x2, y2, 0x07e0, 0); alt_up_pixel_buffer_dma_draw_line(pixel_buffer_dev, x1, y2, x2, y1, 0x07e0, 0); // redraw the box in the foreground alt_up_pixel_buffer_dma_draw_box(pixel_buffer_dev, 34*4, 28*4, 50*4, 32*4, 0x187F, 0); draw_big_A (pixel_buffer_dev); } /* Execute a swap buffer command. This will allow us to check if the screen has * been redrawn before generating a new animation frame. */ alt_up_pixel_buffer_dma_swap_buffers(pixel_buffer_dev); } } }
/** * @brief Check if swapping buffers has completed * * @param pixel_buffer -- the pointer to the VGA structure * * @return 0 if complete, 1 if still processing **/ int Video_bufferIsSwapping(VideoBuffer *video_buffer) { return alt_up_pixel_buffer_dma_check_swap_buffers_status(video_buffer -> pixel_buffer); }