//define all the functions here #include #include #include int rightBoundary = 31; //contains the right/left boundary. assigned dynamically from the main function int leftBoundary = 0; // default values are set as 31st column for right and 0th column for left boundary int gameOverRow = 12; //shapes will only stack up to this row. can be changed as per the need //arrays below store the different orientations of Shapes namely line,L,T,Z and Square _Bool Shape_Line[2][3][3] = { {{1,0,0},{1,0,0},{1,0,0}}, {{1,1,1},{0,0,0},{0,0,0}} }; _Bool shape_L[4][3][3] = { {{1,0,0},{1,0,0},{1,1,0}}, //L {{1,1,1},{1,0,0},{0,0,0}}, //L 90 degree clockwise {{0,1,0},{0,1,0},{1,1,0}}, //L 180 degree clockwise {{1,0,0},{1,1,1},{0,0,0}} //L 270 degree clockwise }; _Bool shape_T[4][3][3] = { {{1,1,1},{0,1,0},{0,0,0}}, //T {{0,1,0},{1,1,0},{0,1,0}}, //T 90 degree clockwise {{0,1,0},{1,1,1},{0,0,0}}, //T 180 degree clockwise {{1,0,0},{1,1,0},{1,0,0}} //T 270 degree clockwise }; _Bool shape_Z[2][3][3] = { {{1,1,0},{0,1,1},{0,0,0}}, //Z {{0,1,0},{1,1,0},{1,0,0}}, //Z 90 degree clockwise }; _Bool shape_S[1][3][3] = {{{1,1,0},{1,1,0},{0,0,0}}}; //scoreDisp array stores the patterns of numbers from 0 to 9. each number is stored in a 5by4 array _Bool scoreDisp[10][5][4] = { {{1,1,1,0},{1,0,1,0},{1,0,1,0},{1,0,1,0},{1,1,1,0}}, //0 {{0,0,1,0},{0,1,1,0},{0,0,1,0},{0,0,1,0},{0,1,1,1}}, //1 {{1,1,1,0},{0,0,1,0},{1,1,1,0},{1,0,0,0},{1,1,1,0}}, //2 {{1,1,1,0},{0,0,1,0},{0,1,1,0},{0,0,1,0},{1,1,1,0}}, //3 {{1,0,1,0},{1,0,1,0},{1,1,1,0},{0,0,1,0},{0,0,1,0}}, //4 {{1,1,1,0},{1,0,0,0},{1,1,1,0},{0,0,1,0},{1,1,1,0}}, //5 {{1,1,1,0},{1,0,0,0},{1,1,1,0},{1,0,1,0},{1,1,1,0}}, //6 {{1,1,1,0},{1,0,1,0},{0,1,1,1},{0,0,1,0},{0,0,1,0}}, //7 {{1,1,1,0},{1,0,1,0},{1,1,1,0},{1,0,1,0},{1,1,1,0}}, //8 {{1,1,1,0},{1,0,1,0},{1,1,1,0},{0,0,1,0},{1,1,1,0}} //9 }; //color array below stores the color information for each pixel. The values change during the gameplay. //initially all values have been set to 0 which corresponds to OFF state. int color[32][32] = {{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, //row0 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, //row1 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, //row2 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, //row3 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, //row4 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, //row5 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, //row6 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, //row7 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, //row8 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, //row9 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, //row10 {0,0,0,0,0,0,0,0,0,0,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, //row25 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, //row26 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, //row27 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, //row28 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, //row29 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, //row30 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} //row31 }; //main_matrix array below stores which LED needs to be lit on the display in form of 1s and 0s //1 - LED should glow along with the color information. 0 - LED at that address should remain OFF. //all values have been initialized to zero. the values change during the gameplay _Bool main_matrix[32][32] = {{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, //row0 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, //row1 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, //row2 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, //row3 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, //row4 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, //row5 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, //row6 {0,0,0,0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,0,0,0,0,0,0}, //row21 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, //row22 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, //row23 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, //row24 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, //row25 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, //row26 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, //row27 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, //row28 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, //row29 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, //row30 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} //row31 }; //Game_Over array below stores the text "GAME OVER! SCORE XX" which is displayed at the end of the game // values XX are written at the end of the game via "updateGOmatrixWithScore(int score)" function _Bool Game_Over[32][32] = {{1,0,0,0,0,0,1,1,1,0,0,0,0,1,1,1,0,1,0,0,0,1,0,1,1,1,1,1,0,0,0,1}, //row0 {1,0,0,0,0,1,0,0,0,1,0,0,1,0,0,1,0,1,1,0,1,1,0,1,0,0,0,0,0,0,0,1}, //row1 {1,0,0,0,0,1,0,0,0,0,0,1,0,0,0,1,0,1,0,1,0,1,0,1,0,0,0,0,0,0,0,1}, //row2 {1,0,0,0,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0,0,1,0,1,0,0,0,0,1}, //row17 {1,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1,0,0,0,0,1}, //row18 {1,0,0,1,1,1,0,0,1,0,0,0,0,0,1,0,0,0,1,0,1,1,1,1,0,0,1,1,1,0,0,1}, //row19 {1,0,0,0,0,0,1,0,1,0,0,0,0,0,1,0,0,0,1,0,1,0,1,0,0,0,1,0,0,0,0,1}, //row20 {1,0,1,0,0,0,1,0,1,0,0,0,1,0,1,0,0,0,1,0,1,0,0,1,0,0,1,0,0,0,0,1}, //row21 {1,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,1,0,0,0,1,0,1,1,1,1,0,1}, //row22 {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, //row23 {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, //row24 {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, //row25 {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, //row26 {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, //row27 {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, //row28 {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, //row29 {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, //row30 {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1} //row31 }; //arrays below store addresses for rowselect function int addressSET[16] = {0x00000000,0x10000000,0x20000000,0x30000000,0x40000000,0x50000000,0x60000000,0x70000000 ,0x80000000,0x90000000,0xA0000000,0xB0000000,0xC0000000,0xD0000000,0xE0000000,0xF0000000}; int addressCLR[16] = {0xF0000000,0xE0000000,0xD0000000,0xC0000000,0xB0000000,0xA0000000,0x90000000,0x80000000 ,0x70000000,0x60000000,0x50000000,0x40000000,0x30000000,0x20000000,0x10000000,0x00000000}; //--------------------------FUNCTIONS----------------------------------------------------------------------// /************************************************************************************ * Function: void delay(unsigned int count) * Input : integer * Output : void * Procedure: genereates "count" milliseconds of delay ************************************************************************************/ void delay(unsigned int count) { count = count * 10; T0PR=0x02; //prescale register to make PCLK = 15MHz/3 = 5MHz T0CTCR = 0x00; // timer mode T0TCR = 0x02; //timer counter and prescale counter have been reset T0TCR = 0x01; //both counter and prescale set while(T0TC0) { x--; } } /************************************************************************************ * Function: beepOnce * Input : void * Output : void * Procedure: makes the buzzer beep once. used in main.c after every collision ************************************************************************************/ void beepOnce(void) { FIO0SET |= 0x00200000; //beep on delay_beep(1); FIO0CLR |= 0x00200000; //beep off delay_beep(1); } /************************************************************************************ * Function: beepGameOver * Input : void * Output : void * Procedure: makes the buzzer beep in a different pattern to signify GAME OVER ************************************************************************************/ void beepGameOver(void) { FIO0SET |= 0x00200000; //beep on delay_beep(300); FIO0CLR |= 0x00200000; //beep off delay_beep(1); } /***************************************************************************************** * Function: disable(char control_type[3]) * Input : STB or CLK or OE * Output : void * Procedure: puts a logic LOW on the pins depending upon the type of argument passed. * (STB-Strobe, CLK-CLock, OE-Output Enable) ************************************************************************************/ void disable(char control_type[3]) { if (strcmp(control_type,"STB")==0) { FIO0CLR |=1<<5;//code } if(strcmp(control_type,"CLK")==0) { FIO0CLR |=1<<4;//code } if(strcmp(control_type,"OE")==0) { FIO0CLR |=1<<6;//code } } /***************************************************************************************** * Function: enable * Input : STB or CLK or OE * Output : void * Procedure: puts a logic HIGH on the pins depending upon the type of argument passed. * (STB-Strobe, CLK-CLock, OE-Output Enable) ************************************************************************************/ void enable(char control_type[3]) { if (strcmp(control_type,"STB")==0) { FIO0SET |= 1<<5;//code } if(strcmp(control_type,"CLK")==0) { FIO0SET |= 1<<4;//code } if(strcmp(control_type,"OE")==0) { FIO0SET |= 1<<6;//code } } /************************************************************************************ * Function: selectRow * Input : integers from 0 to 15 * Output : void * Procedure: Writes binary equvivalent of the input given to the pins DCBA of HUB75 ************************************************************************************/ void selectRow(int address_in_decimal) //address decoder function { //example - passing 0 as argument selects row 0 and row 15th switch(address_in_decimal) // passing "n" will select "nth" and "(n+15)th" row { case 0: { FIO0CLR |= addressCLR[0]; //DCBA = 0000 FIO0SET |= addressSET[0]; //DCBA = XXXX //code for selectton break; } case 1: { FIO0CLR |= addressCLR[1]; //DCBA = 000X FIO0SET |= addressSET[1]; //DCBA = XXX1 //code for selectton break; } case 2: { FIO0CLR |= addressCLR[2]; //DCBA = 00X0 FIO0SET |= addressSET[2]; //DCBA = XX1X //code for selectton break; } case 3: { FIO0CLR |= addressCLR[3]; //DCBA = 00XX FIO0SET |= addressSET[3]; //DCBA = XX11 //code for selectton break; } case 4: { FIO0CLR |= addressCLR[4]; //DCBA = 0X00 FIO0SET |= addressSET[4]; //DCBA = X1XX //code for selectton break; } case 5: { FIO0CLR |= addressCLR[5]; //DCBA = 0X0X FIO0SET |= addressSET[5]; //DCBA = X1X1 //code for selectton break; } case 6: { FIO0CLR |= addressCLR[6]; //DCBA = 0XX0 FIO0SET |= addressSET[6]; //DCBA = X11X //code for selectton break; } case 7: { FIO0CLR |= addressCLR[7]; //DCBA = 0XXX FIO0SET |= addressSET[7]; //DCBA = X111 //code for selectton break; } case 8: { FIO0CLR |= addressCLR[8]; //DCBA = X000 FIO0SET |= addressSET[8]; //DCBA = 1XXX //code for selectton break; } case 9: { FIO0CLR |= addressCLR[9]; //DCBA = X00X FIO0SET |= addressSET[9]; //DCBA = 1XX1 //code for selectton break; } case 10: { FIO0SET |= 0xA0000000; FIO0CLR |= 0x50000000; break; } case 11: { FIO0CLR |= addressCLR[11]; //DCBA = X00X FIO0SET |= addressSET[11]; //DCBA = 1XX1 //code for selectton break; } case 12: { FIO0CLR |= addressCLR[12]; //DCBA = XX00 FIO0SET |= addressSET[12]; //DCBA = 11XX //code for selectton break; } case 13: { FIO0CLR |= addressCLR[13]; //DCBA = XX0X FIO0SET |= addressSET[13]; //DCBA = 11X1 //code for selectton break; } case 14: { FIO0CLR |= addressCLR[14]; //DCBA = XXX0 FIO0SET |= addressSET[14]; //DCBA = 111X //code for selectton break; } case 15: { FIO0CLR |= addressCLR[15]; //DCBA = XXXX FIO0SET |= addressSET[15]; //DCBA = 1111 //code for selectton break; } default: { break; } } } /************************************************************************************ * Function: Initialize_GPIO * Input : void * Output : void * Procedure: sets the IO pins as FAST GPIO. also sets the pin's mode to INPUT/OUTPUT ************************************************************************************/ void Initialize_GPIO(void) //self explanatory { SCS = 0x03; //Initialise the Fast mode FIO0DIR = 0xF00E1670; //setting req pins as output and switches as inputs FIO0DIR |= 1<<21; //buzzer as output } /************************************************************************************ * Function: feedRGB0 * Input : 0-7 decimal digit which corresponds to 8 different combinations of R0,G0,B0 bits * Output : void * Procedure: sets the color of LED in Upper half depending upon the input. ************************************************************************************/ void feedRGB0(int RGB) //passing arguments as 000 witll turn off the LED and 111 will make it glow white { switch(RGB) { case 0: { FIO0CLR |= 1<<17 | 1<<18 | 1<<19; //clears the pins R0,G0 and B0 FIO0SET |= 0<<17 | 0<<18 | 0<<19; break; } case 1: { FIO0CLR |= 1<<17 | 1<<18 | 0<<19; //clears the pins R0,G0 FIO0SET |= 0<<17 | 0<<18 | 1<<19; //sets the pin B0 break; } case 2: { FIO0CLR |= 1<<17 | 0<<18 | 1<<19; //clears the pins R0 and B0 FIO0SET |= 0<<17 | 1<<18 | 0<<19; //sets the pin B0 break; } case 3: { FIO0CLR |= 1<<17 | 0<<18 | 0<<19; //clears the pin R0 FIO0SET |= 0<<17 | 1<<18 | 1<<19; //sets the pin G0 and B0 break; } case 4: { FIO0CLR |= 0<<17 | 1<<18 | 1<<19; //clears the pins G0 and B0 FIO0SET |= 1<<17 | 0<<18 | 0<<19; //sets the pin R0 break; } case 5: { FIO0CLR |= 0<<17 | 1<<18 | 0<<19; //clears the pin G0 FIO0SET |= 1<<17 | 0<<18 | 1<<19; //sets the pins R0 and B0 break; } case 6: { FIO0CLR |= 0<<17 | 0<<18 | 1<<19; //clears the pin B0 FIO0SET |= 1<<17 | 1<<18 | 0<<19; //sets the pin R0,G0 break; } case 7: { FIO0CLR |= 0<<17 | 0<<18 | 0<<19; FIO0SET |= 1<<17 | 1<<18 | 1<<19; //sets the pin R0,G0 and B0 break; } } } /************************************************************************************ * Function: feedRGB1 * Input : 0-7 decimal digit which corresponds to 8 different combinations of R1,G1,B1 bits * Output : * Procedure: sets the color of LED in Lower half depending upon the input. ************************************************************************************/ void feedRGB1(int RGB) //passing arguments as 000 witll turn off the LED and 111 will make it glow white { switch(RGB) { case 0: { FIO0CLR |= 1<<9 | 1<<10 | 1<<12; // Clears R1,G1,B1 FIO0SET |= 0<<9 | 0<<10 | 0<<12; break; } case 1: { FIO0CLR |= 1<<9 | 1<<10 | 0<<12; // Clears R1,G1 FIO0SET |= 0<<9 | 0<<10 | 1<<12; // Sets B1 break; } case 2: { FIO0CLR |= 1<<9 | 0<<10 | 1<<12; // Clears R1,B1 FIO0SET |= 0<<9 | 1<<10 | 0<<12; // Sets G1 break; } case 3: { FIO0CLR |= 1<<9 | 0<<10 | 0<<12; // Clears R1 FIO0SET |= 0<<9 | 1<<10 | 1<<12; // Sets G1,B1 break; } case 4: { FIO0CLR |= 0<<9 | 1<<10 | 1<<12; // Clears G1,B1 FIO0SET |= 1<<9 | 0<<10 | 0<<12; // Sets R1 break; } case 5: { FIO0CLR |= 0<<9 | 1<<10 | 0<<12; // Clears G1 FIO0SET |= 1<<9 | 0<<10 | 1<<12; // Sets R1,B1 break; } case 6: { FIO0CLR |= 0<<9 | 0<<10 | 1<<12; // Clears B1 FIO0SET |= 1<<9 | 1<<10 | 0<<12; // Sets R1,G1 break; } case 7: { FIO0CLR |= 0<<9 | 0<<10 | 0<<12; FIO0SET |= 1<<9 | 1<<10 | 1<<12; // Sets R1,G1,B1 break; } } } /************************************************************************************ * Function: clk * Input : void * Output : void * Procedure: generates a clock transition from LOW to High and then back to low ************************************************************************************/ void clk() //clock LOW-HIGH-LOW { FIO0CLR |=1<<4; delay(1);//put1 FIO0SET |=1<<4; delay(1);//put1 FIO0CLR |=1<<4; } /************************************************************************************ * Function: showDataOnHUB32x32 * Input : void * Output : void * Procedure: takes the data from main_matrix and color matrix and puts it on the HUB75 Display ************************************************************************************/ void showDataOnHUB32x32(void) { for(int row=0;row<=15;row++) { disable("OE"); disable("STB"); for(int clknumber = 0; clknumber<=31;clknumber++) //feed 32bit data in one row { if(main_matrix[row][clknumber]==0) //feed RBG for Nth row as per the values in main_matrix {feedRGB0(0);} // feed OFF i.e no color when bit is 0 in main_matrix else {feedRGB0(color[row][clknumber]);} //feed the color info if bit in main_matrix is 1 if(main_matrix[row+16][clknumber]==0) //feed RBG for (N+16)th row as per the values in main_matrix {feedRGB1(0);} else {feedRGB1(color[row+16][clknumber]);} clk(); //one clock shifts data by 1bit. Providing 32 clocks will shift the data by 32bits. } selectRow(row); //selects "row" and "row+16" row enable("STB");enable("OE"); //once row has been selected then Strobe pin is made high to load the data to the //Output registers. Then OE is made HIGH to display the 32bit data on rows selected } } /************************************************************************************ * Function: showGameOver * Input : void * Output : void * Procedure: shows "GAME OVER! SCORE XX" text at the end of the game ************************************************************************************/ void showGameOver(void) { for(int row=0;row<=15;row++) { disable("OE"); disable("STB"); for(int clknumber = 0; clknumber<=31;clknumber++) { if(Game_Over[row][clknumber]==0) {feedRGB0(0);} else {feedRGB0(2);} if(Game_Over[row+16][clknumber]==0) {feedRGB1(0);} else {feedRGB1(2);} clk(); } selectRow(row); enable("STB");enable("OE"); } } /************************************************************************************ * Function: * Input : * Output : * Procedure: ************************************************************************************/ void delay2(unsigned int count) { count = count * 1000; T0PR=0xE; //prescale register to make PCLK = 15MHz/15 = 1MHz (1uSec) T0CTCR = 0x00; // timer mode T0TCR = 0x02; //timer counter and prescale counter have been reset T0TCR = 0x01; //both counter and prescale set while(T0TC3) {shapeOrientation=0;} break; } case 'T': { shapeOrientation++; if(shapeOrientation>3) {shapeOrientation=0;} break; } case 'Z': { shapeOrientation++; if(shapeOrientation>1) {shapeOrientation=0;} break; } default: { return 0; //break; } } return shapeOrientation; } /************************************************************************************ * Function: shiftdown * Input : integer, row number to be removed * Output : void * Procedure: takes a row number, removes it and shifts the whole stack above it down. * used when a row full of 1s is detected. ************************************************************************************/ void shiftdown(int rownumber) { for(int row = rownumber ; row > 1 ; row--) { for(int col = 1; col<31 ; col++) { main_matrix[row][col] = main_matrix[row-1][col]; color[row][col] = main_matrix[row-1][col]; } } } /************************************************************************************ * Function: checkRowForOnes * Input : void * Output : Boolean, returns true when a row is found and removed. this "true" is used for updating score in main.c * Procedure: when called, scans the whole 32by32 matrix and finds a row containing all 1s and removes it ************************************************************************************/ _Bool checkRowForOnes() { for(int row = 31; row > 10; row--) { for(int col = leftBoundary+1; col