/*
===============================================================================
 Name        : OptimallyPackedFallingShapes.c
 Author      : $YoToTheko
 Version     : 4May19
 Description : ForCrazyByCrazy
===============================================================================
*/
#include <stdlib.h>;

#define PCONP (*(volatile unsigned int*)0x400FC0C4) //POWERS!
#define PCLKSEL0 (*(volatile unsigned int*)0x400FC1A8) //CLOCKS!

#define PLL0CON (*(volatile unsigned int*)0x400FC080) // control register || bit 0 enabled when 1
#define PLL0CFG (*(volatile unsigned int*)0x400FC084) // configure the register
#define PLL0FEED (*(volatile unsigned int*)0x400FC08C) // Feed register (write only)
#define PLL0STAT (*(volatile unsigned int*)0x400FC088) // Status of PLL register (read only)
#define CLKSRCEL (*(volatile unsigned int*)0x400FC10C) // clock select register
#define CLKOUTCFG (*(volatile unsigned int*)0x400FC1C8) // clock out to a pin
#define CCLKCFG (*(volatile unsigned int*)0x400FC104) // configuration register to send the clock to a pin

#define S0SPCR (*(volatile unsigned int*)0x40020000) //SPI control register
#define S0SPSR (*(volatile unsigned int*)0x40020004) //SPI status register
#define S0SPDR (*(volatile unsigned int*)0x40020008) //SPI data register
#define S0SPCCR (*(volatile unsigned int*)0x4002000C) //SPI clock counter register

#define DACR (*(volatile unsigned int*)0x4008C000) //Digital to analog converter register

#define PINSEL0 (*(volatile unsigned int*)0x4002C000)//Pin configuration registers
#define PINSEL1 (*(volatile unsigned int*)0x4002C004)
#define PINSEL3 (*(volatile unsigned int*)0x4002C00C)
#define PINMODE4 (*(volatile unsigned int*)0x4002C050)

#define FIO0DIR (*(volatile unsigned int*)0x2009C000)//ports and bits
#define FIO1DIR (*(volatile unsigned int*)0x2009C020)
#define FIO2DIR (*(volatile unsigned int*)0x2009C040)
#define FIO0PIN (*(volatile unsigned int*)0x2009C014)
#define FIO2PIN (*(volatile unsigned int*)0x2009C054)

void clocks(void){ //Speeding up the clock to make the game faster

    int M = 40;
    int k = 36;
        PINSEL3 |= (1<<22); // this turns our output on || bit 22 set to 1
        CLKOUTCFG = 0x100; //clears any current issues

        //PLL STUFF
        //step 1 & 2
        PLL0CON &= ~(1<<1); //PLL0 disconnect
        PLL0FEED = 0xAA; //feeding the beast
        PLL0FEED = 0x55; ///with feeding sequence

        PLL0CON &= ~(1<<0); //PLL0 disable
        PLL0FEED = 0xAA; //feeding the beast
        PLL0FEED = 0x55; ///with feeding sequence

        //step 3
        //CCLKCFG = 0; //we don't want to change N

        //Step 4: Clock Source Selection register - using default
        CLKSRCEL &= ~(3);

        //Step 5: (m-1 value) write to the PLL0CFG & make it effective with one feed sequence
        PLL0CFG = (M-1); //M = 45 N = 0
        PLL0FEED = 0xAA; //feeding the beast
        PLL0FEED = 0x55; ///with feeding sequence

        //Step 6: Enable PLL0 with one feed sequence.
        PLL0CON |= 1; //PLL0 enable.
        PLL0FEED = 0xAA; //feeding the beast
        PLL0FEED = 0x55; ///with feeding sequence

        //Step 8: Wait for PLL0 to achieve lock by monitoring the PLOCK0 bit in the PLL0STAT register,
        //or using the PLOCK0 interrupt, or wait for a fixed time when the input clock to PLL0 is slow (i.e. 32 kHz).

        while  (((PLL0STAT >> 26) & 1 )==0){} //while PLL bit 26 is set to 0 hold, essentially hold this until a lock is established

        //Step 7: (k-1 value) Change the CPU Clock Divider setting for the operation with PLL0. It is critical to do
        //this before connecting PLL0.

        CCLKCFG = (k-1); // k value this divides by 40 (convert this to hex)

        PLL0CON |= 3; // sets bit one & two after lock is established
        //Step 9: Connect PLL0 with one feed sequence.
        PLL0FEED = 0xAA; //feeding the beast
        PLL0FEED = 0x55; ///with feeding sequence

        }

void LCDreset (void){ //resets the LCD screen
    FIO0PIN &= ~(1<<23);
    FIO0PIN |= (1<<23);
}

void wait_ticks (int count){ // sets up our wait function
       volatile int ticks = count;
       while (ticks > 0)
           ticks--;
}

void LCDwriteReg(int x, int y){ //Uses the micro-controller SPI subsystem to talk to the LCD
    FIO0PIN &= ~(1<<16); //Asserts slave select
    FIO0PIN &= ~(1<<24);
    S0SPDR = x>>8;
        while(((S0SPSR>>7)&1)==0){}
    S0SPDR = x;
        while(((S0SPSR>>7)&1)==0){}
    FIO0PIN |= (1<<24);
    S0SPDR = y>>8;
        while(((S0SPSR>>7)&1)==0){}
    S0SPDR = y;
        while(((S0SPSR>>7)&1)==0){}
    FIO0PIN |= (1<<16); //de-asserts slave select
}

void SPIInit(){ //this processes initializes the SPI settings on the microcontroller
    PCONP |= (1<<8); //This selects the SPI subsystem in the LPC
    PCLKSEL0 |= (1<<16); //This selects the SPI clock for the master's setting I think???
    S0SPCCR = (1<<3);// sending an '8' to the SPI clock counter register which is lowest possible value
    S0SPCR = (1<<5);//initiates our
    FIO0DIR |= (1<<16);  // sets our slave select as an output
    FIO0DIR |= (1<<23);  // Sets our reset pin as an output
    FIO0DIR |= (1<<24);
    PINSEL1 |= (3<<4);  //MOSI as an output
    PINSEL0 |= (3<<30);  //SCK as an output
}

void LCDinit(void){ //initializes the LCD ILI9225B appropriately

  LCDreset();
  LCDwriteReg(0x01, 0x011C); //Driver output control, 220 lines
  LCDwriteReg(0x02, 0x0100); //LCD AC Driving Control, line inversion, 1 field interlace
  LCDwriteReg(0x03, 0x1030); //Entry Mode, BGR mode, left-right, top-bottom
  LCDwriteReg(0x08, 0x0100); //Blank Period Control 1, 8 line front/back porch
  LCDwriteReg(0x0b, 0x1100); //Frame cycle control
  LCDwriteReg(0x0c, 0x0001); //Interface Control, 16bpp
  LCDwriteReg(0x0f, 0x0A01); //Oscillation Control this would select 83 Hz i believe as opposed to the other value, which didnt make sense (0x1401)
  //LCDwriteReg(0x15, 0x0000); //VCI Recycling - CANT FIND THIS REGISTER IN MATERIAL
  LCDwriteReg(0x20, 0x0000); //RAM Address Set 1 (LSB)
  LCDwriteReg(0x21, 0x0000); //RAM Address Set 2 (MSB)

  wait_ticks(6000);

  LCDwriteReg(0x10, 0x0800); //Power Control 1
  LCDwriteReg(0x11, 0x1f3f); //Power Control 2

  wait_ticks(6000);

  LCDwriteReg(0x12, 0x0121); //Power Control 3
  LCDwriteReg(0x13, 0x006f); //Power Control 4
  LCDwriteReg(0x14, 0x4349); //Power Control 5

  LCDwriteReg(0x30, 0x0000); //Gate Scan Control
  LCDwriteReg(0x31, 0x00db); //Vertical Scroll Control 1
  LCDwriteReg(0x32, 0x0000); //Vertical Scroll Control 2
  LCDwriteReg(0x33, 0x0000); //Vertical Scroll Control 3
  LCDwriteReg(0x34, 0x00db); //Partial Driving Position 1
  LCDwriteReg(0x35, 0x0000); //Partial Driving Position 2
  LCDwriteReg(0x36, 0x00AF); //Horizontal Window Address end
  LCDwriteReg(0x37, 0x0000); //Horizontal Window Address start
  LCDwriteReg(0x38, 0x00DB); //Vertical Window Address end
  LCDwriteReg(0x39, 0x0000); //Vertical Window Address start

  LCDwriteReg(0x50, 0x0001); //Gamma Control 1
  LCDwriteReg(0x51, 0x200b); //Gamma Control 2
  LCDwriteReg(0x52, 0x0000); //Gamma Control 3
  LCDwriteReg(0x53, 0x0404); //Gamma Control 4
  LCDwriteReg(0x54, 0x0c0c); //Gamma Control 5
  LCDwriteReg(0x55, 0x000c); //Gamma Control 6
  LCDwriteReg(0x56, 0x0101); //Gamma Control 7
  LCDwriteReg(0x57, 0x0400); //Gamma Control 8
  LCDwriteReg(0x58, 0x1108); //Gamma Control 9
  LCDwriteReg(0x59, 0x050c); //Gamma Control 10

  wait_ticks(6000);

  LCDwriteReg(0x07, 0x1017); //Display Control 1

  LCDwriteReg(0x20, 0x0000); //RAM Address Set 1 (LSB)
  LCDwriteReg(0x21, 0x0000);
  int j;
  for (j=38720; j>0; j--){

  //RAM Address Set 2 (MSB)
  LCDwriteReg(0x22,0xFFFF);

  }
}

/// Array's for rolling 'round with my homies
int BackGroundCol[16] = {0x0000, 0x000A, 0x00015, 0x0020, 0x002B, 0x0036, 0x0041, 0x004C, 0x0057, 0x0062, 0x006D, 0x0078, 0x0083, 0x008E, 0x0099, 0x00A4};
int BackGroundRow[20] = {0x0000, 0x000A, 0x00015, 0x0020, 0x002B, 0x0036, 0x0041, 0x004C, 0x0057, 0x0062, 0x006D, 0x0078, 0x0083, 0x008E, 0x0099, 0x00A4, 0x00AF, 0x00BA, 0x00C5, 0x00D0};
int PlayFieldCol[10] = {0x0026, 0x0030, 0x003A, 0x0044, 0x004E, 0x0058, 0x0062, 0x006c, 0x0076, 0x0080};
int PlayFieldRow[20] = {0x000A, 0x0014, 0x001E, 0x0028, 0x0032, 0x003C, 0x0046, 0x0050, 0x005A, 0x0064, 0x006E, 0x0078, 0x0082, 0x008C, 0x0096, 0x00A0, 0x00AA, 0x00B4, 0x00BE, 0x00C8};
int PlayFieldStat[20][10];

/// colors used in the code

int F = 0xF808; //Fandango;
int P = 0xFBD3; //Pink;
int S = 0xF462; //Scarlet;
int C = 0xFDED; //Coral;
int M = 0xCE00; //Mustard;
int Y = 0xFFCA;  //Yellow;
int G = 0x1DC0; //Green
int K = 0xA7F2; //kelly
int T = 0x0772; //Teal;
int A = 0x9FFC; //Aqua;
int B = 0x03DD; //Blue;
int N = 0x85BE; //Navy;
int L = 0xE41F; //Lavender;
int V = 0xA01A; //Violet

void ColorTest(){ //used this to tweek colors and compare them to each other, isnt actually used in final game

    big(BackGroundCol[0],BackGroundRow[2],F);
    big(BackGroundCol[8],BackGroundRow[2],P);
    big(BackGroundCol[0],BackGroundRow[4],S);
    big(BackGroundCol[8],BackGroundRow[4],C);
    big(BackGroundCol[0],BackGroundRow[6],M);
    big(BackGroundCol[8],BackGroundRow[6],Y);
    big(BackGroundCol[0],BackGroundRow[8],G);
    big(BackGroundCol[8],BackGroundRow[8],K);
    big(BackGroundCol[0],BackGroundRow[10],T);
    big(BackGroundCol[8],BackGroundRow[10],A);
    big(BackGroundCol[0],BackGroundRow[12],B);
    big(BackGroundCol[8],BackGroundRow[12],N);
    big(BackGroundCol[0],BackGroundRow[14],V);
    big(BackGroundCol[8],BackGroundRow[14],L);
}

///building blocks of the program

void big(int x1, int y1, int z){ //creates an 88 x 22 big block of color 'z' for design helps
int x2;
int y2;

x2 = x1+87;
y2= y1+21;

  LCDwriteReg(0x36, x2); //Horizontal Window Address 1
  LCDwriteReg(0x37, x1); //Horizontal Window Address 2
  LCDwriteReg(0x38, y2); //Vertical Window Address 1
  LCDwriteReg(0x39, y1); //Vertical Window Address 2

  wait_ticks(6000);

  LCDwriteReg(0x07, 0x1017); //Display Control 1

  LCDwriteReg(0x20, x2); //RAM Address Set 1 (LSB)
  LCDwriteReg(0x21, y2); //RAM Address Set 2 (MSB)
  int j;
        for (j=1936; j>0; j--){
            LCDwriteReg(0x22,z);
        }

}

void pin(int x1, int y1, int z){ //creates a small 2x2 pixel block of color 'z' for lettering and numbers
int x2;
int y2;

x2 = x1+1;
y2= y1+1;

  LCDwriteReg(0x36, x2); //Horizontal Window Address 1
  LCDwriteReg(0x37, x1); //Horizontal Window Address 2
  LCDwriteReg(0x38, y2); //Vertical Window Address 1
  LCDwriteReg(0x39, y1); //Vertical Window Address 2

  wait_ticks(6000);

  LCDwriteReg(0x07, 0x1017); //Display Control 1

  LCDwriteReg(0x20, x2); //RAM Address Set 1 (LSB)
  LCDwriteReg(0x21, y2); //RAM Address Set 2 (MSB)
  int j;
        for (j=4; j>0; j--){
            LCDwriteReg(0x22,z);
        }

}

void Brick(int x1, int y1, int z1, int z2){ //creates an 11x11 multicolored brick for decorations with colors z1, z2 and white
int x2;
int y2;
int x3;
int y3;
int x4;
int y4;
int x5;
int y5;
int x6;
int y6;

x2 = x1+10;
y2= y1+10;

x3 = x1+2;
y3 = y1+2;
x4 = x1+8;
y4 = y1+8;

x5 = x1+4;
y5 = y1+4;
x6 = x1+6;
y6 = y1+6;

  LCDwriteReg(0x36, x2); //Horizontal Window Address 1
  LCDwriteReg(0x37, x1); //Horizontal Window Address 2
  LCDwriteReg(0x38, y2); //Vertical Window Address 1
  LCDwriteReg(0x39, y1); //Vertical Window Address 2

  wait_ticks(6000);

  LCDwriteReg(0x07, 0x1017); //Display Control 1

  LCDwriteReg(0x20, x2); //RAM Address Set 1 (LSB)
  LCDwriteReg(0x21, y2); //RAM Address Set 2 (MSB)
  int j;
        for (j=121; j>0; j--){
            LCDwriteReg(0x22,z2);
        }

  LCDwriteReg(0x36, x4); //Horizontal Window Address 1
  LCDwriteReg(0x37, x3); //Horizontal Window Address 2
  LCDwriteReg(0x38, y4); //Vertical Window Address 1
  LCDwriteReg(0x39, y3); //Vertical Window Address 2

  wait_ticks(6000);

  LCDwriteReg(0x07, 0x1017); //Display Control 1

  LCDwriteReg(0x20, x3); //RAM Address Set 1 (LSB)
  LCDwriteReg(0x21, y3); //RAM Address Set 2 (MSB)
  int i;
        for (i=49; i>0; i--){
            LCDwriteReg(0x22,z1);
        }

        LCDwriteReg(0x36, x6); //Horizontal Window Address 1
        LCDwriteReg(0x37, x5); //Horizontal Window Address 2
        LCDwriteReg(0x38, y6); //Vertical Window Address 1
        LCDwriteReg(0x39, y5); //Vertical Window Address 2

        wait_ticks(6000);

        LCDwriteReg(0x07, 0x1017); //Display Control 1

        LCDwriteReg(0x20, x5); //RAM Address Set 1 (LSB)
        LCDwriteReg(0x21, y5); //RAM Address Set 2 (MSB)
        int k;
              for (k=9; k>0; k--){
                  LCDwriteReg(0x22,0xFFFF);
              }
}

void Block(int x1, int y1, int z){ //creates a 10x10 pixel white block containing an 8x8 block of color 'z'
int x2;
int y2;
int x3;
int y3;
int x4;
int y4;
x2 = x1+9;
y2= y1+9;
x3 = x1+1;
y3 = y1+1;
x4 = x3+7;
y4 = y3+7;

  LCDwriteReg(0x36, x2); //Horizontal Window Address 1
  LCDwriteReg(0x37, x1); //Horizontal Window Address 2
  LCDwriteReg(0x38, y2); //Vertical Window Address 1
  LCDwriteReg(0x39, y1); //Vertical Window Address 2

  wait_ticks(6000);

  LCDwriteReg(0x07, 0x1017); //Display Control 1

  LCDwriteReg(0x20, x2); //RAM Address Set 1 (LSB)
  LCDwriteReg(0x21, y2); //RAM Address Set 2 (MSB)
  int j;
        for (j=100; j>0; j--){
            LCDwriteReg(0x22,0xFFFF);
        }

  LCDwriteReg(0x36, x4); //Horizontal Window Address 1
  LCDwriteReg(0x37, x3); //Horizontal Window Address 2
  LCDwriteReg(0x38, y4); //Vertical Window Address 1
  LCDwriteReg(0x39, y3); //Vertical Window Address 2

  wait_ticks(6000);

  LCDwriteReg(0x07, 0x1017); //Display Control 1

  LCDwriteReg(0x20, x3); //RAM Address Set 1 (LSB)
  LCDwriteReg(0x21, y3); //RAM Address Set 2 (MSB)
  int i;
        for (i=64; i>0; i--){
            LCDwriteReg(0x22,z);
        }
}

void Erase (int x1, int y1){ //creates a "not a block" 10x10 black pixels to match background

int x2;
int y2;

x2 = x1+9;
y2= y1+9;

  LCDwriteReg(0x36, x2); //Horizontal Window Address 1
  LCDwriteReg(0x37, x1); //Horizontal Window Address 2
  LCDwriteReg(0x38, y2); //Vertical Window Address 1
  LCDwriteReg(0x39, y1); //Vertical Window Address 2

  wait_ticks(6000);

  LCDwriteReg(0x07, 0x1017); //Display Control 1

  LCDwriteReg(0x20, x2); //RAM Address Set 1 (LSB)
  LCDwriteReg(0x21, y2); //RAM Address Set 2 (MSB)
  int j;
        for (j=100; j>0; j--){
            LCDwriteReg(0x22,0x0000);
              }
}

// screens and back grounds

void BG(void){
    int j;
    int i;

    for (j=0; j<16; j++){
        for (i=0;i<20;i++){
            int k;
            k=(((j*10)+i)%7);
        switch(k){
        case 0:    Brick(BackGroundCol[j],BackGroundRow[i],P,F);
                break;
        case 1:    Brick(BackGroundCol[j],BackGroundRow[i],C,S);
                break;
        case 2:    Brick(BackGroundCol[j],BackGroundRow[i],Y,M);
                break;
        case 3:    Brick(BackGroundCol[j],BackGroundRow[i],K,G);
                break;
        case 4:    Brick(BackGroundCol[j],BackGroundRow[i],A,T);
                break;
        case 5:    Brick(BackGroundCol[j],BackGroundRow[i],B,N);
                break;
        case 6:    Brick(BackGroundCol[j],BackGroundRow[i],L,V);
                break;
        }
    }
}
}

void LetterField(void){ //creates the background to write letters on

      LCDwriteReg(0x36, BackGroundCol[15]); //Horizontal Window Address 1 end
      LCDwriteReg(0x37, BackGroundCol[1]); //Horizontal Window Address 2 start
      LCDwriteReg(0x38, BackGroundRow[19]); //Vertical Window Address 1 end
      LCDwriteReg(0x39, BackGroundRow[1]); //Vertical Window Address 2 start

      wait_ticks(6000);
      LCDwriteReg(0x07, 0x1017); //Display Control 1

      LCDwriteReg(0x20, BackGroundRow[19]); //Horizontal RAM Address Set 1 (LSB)
      LCDwriteReg(0x21, BackGroundRow[1]); //Vertical RAM Address Set 2 (MSB)
      int i;
      for (i=30492; i>0; i--){

      LCDwriteReg(0x22,0x0000);
      }
    }

void Welcome(void){
    BG();
    LetterField();
        LetterO((BackGroundCol[2]-7), BackGroundRow[4], P, F);
        LetterP((BackGroundCol[4]-11), BackGroundRow[4], C, S);
        LetterT((BackGroundCol[5]-7), BackGroundRow[4], Y, M);
        LetterI((BackGroundCol[7]-9), BackGroundRow[4], K, G);
        LetterM((BackGroundCol[8]-9), BackGroundRow[4], A, T);
        LetterA((BackGroundCol[10]-9), BackGroundRow[4], B, N);
        LetterL((BackGroundCol[12]-10), BackGroundRow[4], L, V);
        LetterL((BackGroundCol[14]-16), BackGroundRow[4], P, F);
        LetterY((BackGroundCol[15]-16), BackGroundRow[4], C, S);

        LetterP((BackGroundCol[2]), BackGroundRow[7], Y, M);
        LetterA((BackGroundCol[4]), BackGroundRow[7], K, G);
        LetterC((BackGroundCol[6]), BackGroundRow[7], A, T);
        LetterK((BackGroundCol[8]), BackGroundRow[7], B, N);
        LetterE((BackGroundCol[10]), BackGroundRow[7], L, V);
        LetterD((BackGroundCol[12]), BackGroundRow[7], P, F);

        LetterF((BackGroundCol[2]), BackGroundRow[10], C, S);
        LetterA((BackGroundCol[4]-3), BackGroundRow[10], Y, M);
        LetterL((BackGroundCol[6]-5), BackGroundRow[10], K, G);
        LetterL((BackGroundCol[8]-8), BackGroundRow[10], A, T);
        LetterI((BackGroundCol[10]-10), BackGroundRow[10], B, N);
        LetterN((BackGroundCol[12]-12), BackGroundRow[10], L, V);
        LetterG((BackGroundCol[14]-12), BackGroundRow[10], P, F);

        LetterS((BackGroundCol[2]), BackGroundRow[13], C, S);
        LetterH((BackGroundCol[4]), BackGroundRow[13], Y, M);
        LetterA((BackGroundCol[6]), BackGroundRow[13], K, G);
        LetterP((BackGroundCol[8]), BackGroundRow[13], A, T);
        LetterE((BackGroundCol[10]), BackGroundRow[13], B, N);
        LetterS((BackGroundCol[12]), BackGroundRow[13], L, V);
}

void PlayField(void){ //creates the game background
    BG();

  LCDwriteReg(0x36, 0x008D); //Horizontal Window Address end
  LCDwriteReg(0x37, 0x0022); //Horizontal Window Address start
  LCDwriteReg(0x38, 0x00D8); //Vertical Window Address end
  LCDwriteReg(0x39, 0x0006); //Vertical Window Address start

  wait_ticks(6000);

  LCDwriteReg(0x07, 0x1017); //Display Control 1

  LCDwriteReg(0x20, 0x0022); //Horizontal RAM Address Set 1 (LSB)
  LCDwriteReg(0x21, 0x0006); //vertical RAM Address Set 2 (MSB)
  int j;
  for (j=21516; j>0; j--){

  LCDwriteReg(0x22,0xFFFF);
  }

  LCDwriteReg(0x36, 0x0089); //Horizontal Window Address 1 end
  LCDwriteReg(0x37, 0x0026); //Horizontal Window Address 2 start
  LCDwriteReg(0x38, 0x00D1); //Vertical Window Address 1 end
  LCDwriteReg(0x39, 0x000A); //Vertical Window Address 2 start

  wait_ticks(6000);

  LCDwriteReg(0x07, 0x1017); //Display Control 1

  LCDwriteReg(0x20, 0x0026); //Horizontal RAM Address Set 1 (LSB)
  LCDwriteReg(0x21, 0x000A); //Vertical RAM Address Set 2 (MSB)
  int i;
  for (i=20000; i>0; i--){

  LCDwriteReg(0x22,0x0000);
  }

}

void GameOver(int Score){
    int first;
    int second;

    BG();
    LetterField();
    LetterG((BackGroundCol[2]), BackGroundRow[4], P, F);
    LetterA((BackGroundCol[4]), BackGroundRow[4], C, S);
    LetterM((BackGroundCol[6]), BackGroundRow[4], Y, M);
    LetterE((BackGroundCol[8]), BackGroundRow[4], K, G);

    LetterO((BackGroundCol[6]), BackGroundRow[7], A, T);
    LetterU((BackGroundCol[8]), BackGroundRow[7], B, N);
    LetterE((BackGroundCol[10]), BackGroundRow[7], L, V);
    LetterR((BackGroundCol[12]), BackGroundRow[7], P, F);

    LetterY((BackGroundCol[4]), BackGroundRow[11], C, S);
    LetterO((BackGroundCol[6]), BackGroundRow[11], Y, M);
    LetterU((BackGroundCol[8]), BackGroundRow[11], K, G);
    LetterR((BackGroundCol[10]), BackGroundRow[11], A, T);

    LetterS((BackGroundCol[3]), BackGroundRow[13], B, N);
    LetterC((BackGroundCol[5]), BackGroundRow[13], L, V);
    LetterO((BackGroundCol[7]), BackGroundRow[13], P, F);
    LetterR((BackGroundCol[9]), BackGroundRow[13], C, S);
    LetterE((BackGroundCol[11]), BackGroundRow[13], Y, M);

    first = Score/10;
    second = Score%10;
    FirstNumber(first);
    SecondNumber(second);

    music();

}

////some global variable and other such needs

char KeyPad[16] = {'1', '2', '3', 'A', '4', '5', '6', 'B', '7', '8', '9', 'C', '*', '0', '#', 'D'};
int Score;

///tables for scores

void FirstNumber(int i){ //this is called to display the first digit of a score
    switch(i){
    case 0: Number0(BackGroundCol[6], BackGroundRow[16],F); break;
    case 1: Number1(BackGroundCol[6], BackGroundRow[16],S); break;
    case 2: Number2(BackGroundCol[6], BackGroundRow[16],M); break;
    case 3: Number3(BackGroundCol[6], BackGroundRow[16],G); break;
    case 4: Number4(BackGroundCol[6], BackGroundRow[16],T); break;
    case 5: Number5(BackGroundCol[6], BackGroundRow[16],N); break;
    case 6: Number6(BackGroundCol[6], BackGroundRow[16],V); break;
    case 7: Number7(BackGroundCol[6], BackGroundRow[16],F); break;
    case 8: Number8(BackGroundCol[6], BackGroundRow[16],S); break;
    case 9: Number9(BackGroundCol[6], BackGroundRow[16],M); break;
    }
}

void SecondNumber(int i){//this is called to display the second digit of a score
    switch(i){
    case 0: Number0(BackGroundCol[9], BackGroundRow[16],F); break;
    case 1: Number1(BackGroundCol[9], BackGroundRow[16],S); break;
    case 2: Number2(BackGroundCol[9], BackGroundRow[16],M); break;
    case 3: Number3(BackGroundCol[9], BackGroundRow[16],G); break;
    case 4: Number4(BackGroundCol[9], BackGroundRow[16],T); break;
    case 5: Number5(BackGroundCol[9], BackGroundRow[16],N); break;
    case 6: Number6(BackGroundCol[9], BackGroundRow[16],V); break;
    case 7: Number7(BackGroundCol[9], BackGroundRow[16],F); break;
    case 8: Number8(BackGroundCol[9], BackGroundRow[16],S); break;
    case 9: Number9(BackGroundCol[9], BackGroundRow[16],M); break;
    }
}

//Oblock needs

void Oblock (int a, int b){

    Block ((a-10),(b-10), F);
    Block (a,(b-10), F);
    Block ((a-10),b, F);
    Block (a,b, F);
    }

void OblockSave (int i, int j){

    PlayFieldStat[i-1][j-1]=F;
    PlayFieldStat[i-1][j]=F;
    PlayFieldStat[i][j-1]=F;
    PlayFieldStat[i][j]=F;
    }

void OblockErase (int a, int b){

    Erase ((a-10),(b-10));
    Erase (a,(b-10));
    Erase ((a-10),b);
    Erase (a,b);
    }

int OblockDetectLeft(int i, int j){
    if((PlayFieldStat[i-1][j-2]==0)&&(PlayFieldStat[i][j-2]==0)&&((j-2)>-1)){
        return 0;
        }
        else {
            return 1;
            }
}

int OblockDetectRight(int i, int j){
    if((PlayFieldStat[i-1][j+1]==0)&&(PlayFieldStat[i][j+1]==0)&&((j+1)<10)){
        return 0;
        }
        else {
            return 1;
            }
}

int OblockDetectBelow(int i, int j){
    if((PlayFieldStat[i+1][j-1]==0)&&(PlayFieldStat[i+1][j]==0)){
        return 0;
        }
        else {
            return 1;
            }
}

//Iblock needs

void Iblock (int a, int b, int c){
    int d;
    d = c%2;

    switch (d){
        case 0: Block ((a-20), b, C); Block ((a-10),b, C); Block (a,b, C); Block ((a+9),b, C); break;
        case 1: Block (a, b, C); Block (a,(b-10), C); Block (a,(b-20), C); Block (a,(b-30), C); break;

    }
}

void IblockSave (int i, int j, int c){
    int d;
    d = c%2;

    switch (d){
        case 0: PlayFieldStat[i][j-2]=C;PlayFieldStat[i][j-1]=C;PlayFieldStat[i][j]=C;PlayFieldStat[i][j+1]=C;break;
        case 1: PlayFieldStat[i-3][j]=C;PlayFieldStat[i-2][j]=C;PlayFieldStat[i-1][j]=C;PlayFieldStat[i][j]=C;break;

    }
}

void IblockErase (int a, int b, int c){
    int d;
    d = c%2;

    switch (d){
        case 0: Erase((a-20), b); Erase((a-10),b); Erase(a,b); Erase((a+9),b); break;
        case 1: Erase (a, b); Erase(a,(b-10)); Erase(a,(b-20)); Erase(a,(b-30)); break;
        }
}

int IblockDetectLeft(int i, int j, int c){
    int d;
    d = c%2;

    switch(d){
        case 0:
            if ((PlayFieldStat[i][j-3]==0)&&((j-3)>-1)){
                return 0;
                }
            else {
                return 1;
                }
            break;

        case 1:
            if  ((PlayFieldStat[i][j-1]==0)&&(PlayFieldStat[i-1][j-1]==0)&&(PlayFieldStat[i-2][j-1]==0)&&(PlayFieldStat[i-3][j-1]==0)&&((j-1)>-1)){
                return 0;
                }
            else {
                return 1;
                }
            break;
        }
}

int IblockDetectRight(int i, int j, int c){
    int d;
    d = c%2;

    switch(d){
        case 0:
            if ((PlayFieldStat[i][j+2]==0)&&((j+2)<10)){
                return 0;
                }
            else {
                return 1;
                }
            break;

        case 1:
            if ((PlayFieldStat[i][j+1]==0)&&(PlayFieldStat[i-1][j+1]==0)&&(PlayFieldStat[i-2][j+1]==0)&&(PlayFieldStat[i-3][j+1]==0)&&((j+1)<10)){
                return 0;
                }
            else {
                return 1;
                }
            break;
        }
}

int IblockDetectBelow(int i, int j, int c){
    int d;
    d = c%2;

    switch(d){
        case 0:
            if ((PlayFieldStat[i+1][j-2]==0)&&(PlayFieldStat[i+1][j-1]==0)&&(PlayFieldStat[i+1][j]==0)&&(PlayFieldStat[i+1][j+1]==0)){
                return 0;
                }
            else {
                return 1;
                }
            break;

        case 1:
            if (PlayFieldStat[i+1][j]==0){
                return 0;
                }
            else {
                return 1;
                }
            break;
    }
}

int IblockDetectSpin(int i, int j, int c){
    int d;
    d = c%2;

    switch(d){
        case 0:
            if((PlayFieldStat[i-3][j]==0)&&(PlayFieldStat[i-2][j]==0)&&(PlayFieldStat[i-1][j]==0)&&(j>-1)&&(j<10)) {
                return 0;
                }
            else {
                return 1;
                }
            break;

        case 1:
            if ((PlayFieldStat[i][j-2]==0)&&(PlayFieldStat[i][j-1]==0)&&(PlayFieldStat[i][j+1]==0)&&((j-2)>-1)&&((j+1)<10)){
                return 0;
                }
            else {
                return 1;
                }
            break;
    }
}

// Sblock needs

void Sblock (int a, int b, int c){
    int d;
    d = c%2;

    switch (d){
        case 0:  Block (a, (b-10), Y); Block ((a+9),(b-10), Y); Block ((a-10),b, Y); Block (a,b, Y); break;
        case 1: Block ((a-10), (b-20), Y); Block ((a-10),(b-10), Y); Block (a,(b-10), Y); Block (a,b, Y); break;
    }
}

void SblockSave (int i, int j, int c){
    int d;
    d = c%2;

    switch (d){
        case 0: PlayFieldStat[i-1][j]=Y;PlayFieldStat[i-1][j+1]=Y;PlayFieldStat[i][j-1]=Y;PlayFieldStat[i][j]=Y;break;
        case 1: PlayFieldStat[i-2][j-1]=Y;PlayFieldStat[i-1][j-1]=Y;PlayFieldStat[i-1][j]=Y;PlayFieldStat[i][j]=Y;break;

    }
}

void SblockErase (int a, int b, int c){
    int d;
    d = c%2;

    switch (d){
        case 0:  Erase(a,(b-10)); Erase((a+9),(b-10)); Erase((a-10),b); Erase(a,b); break;
        case 1: Erase((a-10),(b-20)); Erase((a-10),(b-10)); Erase(a,(b-10)); Erase(a,b); break;
    }
}

int SblockDetectLeft(int i, int j, int c){
    int d;
    d = c%2;

    switch(d){
        case 0:
            if ((PlayFieldStat[i-1][j-1]==0)&&(PlayFieldStat[i][j-2]==0)&&((j-2)>-1)){
                return 0;
                }
            else {
                return 1;
                }
            break;

        case 1:
            if ((PlayFieldStat[i][j-1]==0)&&(PlayFieldStat[i-1][j-2]==0)&&(PlayFieldStat[i-2][j-2]==0)&&((j-2)>-1)){
                return 0;
                }
            else {
                return 1;
                }
            break;
        }
}

int SblockDetectRight(int i, int j, int c){
    int d;
    d = c%2;

    switch(d){
        case 0:
            if ((PlayFieldStat[i-1][j+2]==0)&&(PlayFieldStat[i][j+1]==0)&&((j+2)<10)){
                return 0;
                }
            else {
                return 1;
                }
            break;

        case 1:
            if ((PlayFieldStat[i-2][j]==0)&&(PlayFieldStat[i-1][j+1]==0)&&(PlayFieldStat[i][j+1]==0)&&((j+1)<10)){
                return 0;
                }
            else {
                return 1;
                }
            break;
        }
}

int SblockDetectBelow(int i, int j, int c){
    int d;
    d = c%2;

    switch(d){
        case 0:
            if ((PlayFieldStat[i+1][j-1]==0)&&(PlayFieldStat[i+1][j]==0)&&(PlayFieldStat[i][j+1]==0)){
                return 0;
                }
            else {
                return 1;
                }
            break;

        case 1:
            if ((PlayFieldStat[i][j-1]==0)&&(PlayFieldStat[i+1][j]==0)){
                return 0;
                }
            else {
                return 1;
                }
            break;
        }
}

int SblockDetectSpin(int i, int j, int c){
    int d;
    d = c%2;

    switch(d){
        case 0:
            if ((PlayFieldStat[i-2][j-1]==0)&&(PlayFieldStat[i-1][j-1]==0)&&((j-1)>-1)&&((j-1)<10)){
                return 0;
                }
            else {
                return 1;
                }
            break;

        case 1:
            if ((PlayFieldStat[i][j-1]==0)&&(PlayFieldStat[i-1][j+1]==0)&&((j-1)>-1)&&((j+1)<10)){
                return 0;
                }
            else {
                return 1;
                }
            break;
    }
}

//Zblock needs

void Zblock (int a, int b, int c){
    int d;
    d = c%2;

    switch (d){
        case 0:  Block ((a-20), (b-10),K); Block ((a-10),(b-10), K); Block ((a-10),b, K); Block (a,b,K); break;
        case 1: Block (a, (b-20), K); Block ((a-10),(b-10), K); Block (a,(b-10), K); Block ((a-10),b, K); break;
    }
}

void ZblockSave (int i, int j, int c){
    int d;
    d = c%2;

    switch (d){
        case 0: PlayFieldStat[i-1][j-2]=K;PlayFieldStat[i-1][j-1]=K;PlayFieldStat[i][j-1]=K;PlayFieldStat[i][j]=K;break;
        case 1: PlayFieldStat[i-2][j]=K;PlayFieldStat[i-1][j-1]=K;PlayFieldStat[i-1][j]=K;PlayFieldStat[i][j-1]=K;break;

    }
}

void ZblockErase (int a, int b, int c){
    int d;
    d = c%2;

    switch (d){
        case 0:  Erase((a-20), (b-10)); Erase((a-10),(b-10));Erase((a-10),b); Erase(a,b); break;
        case 1: Erase(a, (b-20)); Erase((a-10),(b-10)); Erase(a,(b-10)); Erase((a-10),b); break;
    }
}

int ZblockDetectLeft(int i, int j, int c){
    int d;
    d = c%2;

    switch(d){
        case 0:
            if ((PlayFieldStat[i-1][j-3]==0)&&(PlayFieldStat[i][j-2]==0)&&((j-3)>-1)){
                return 0;
                }
            else {
                return 1;
                }
            break;

        case 1:
            if ((PlayFieldStat[i][j-2]==0)&&(PlayFieldStat[i-1][j-2]==0)&&(PlayFieldStat[i-2][j-1]==0)&&((j-2)>-1)){
                return 0;
                }
            else {
                return 1;
                }
            break;
        }
}

int ZblockDetectRight(int i, int j, int c){
    int d;
    d = c%2;

    switch(d){
        case 0:
            if ((PlayFieldStat[i-1][j]==0)&&(PlayFieldStat[i][j+1]==0)&&((j+1)<10)){
                return 0;
                }
            else {
                return 1;
                }
            break;

        case 1:
            if ((PlayFieldStat[i-2][j+1]==0)&&(PlayFieldStat[i-1][j+1]==0)&&(PlayFieldStat[i][j]==0)&&((j+1)<10)){
                return 0;
                }
            else {
                return 1;
                }
            break;
        }
}

int ZblockDetectBelow(int i, int j, int c){
    int d;
    d = c%2;

    switch(d){
        case 0:
            if ((PlayFieldStat[i][j-2]==0)&&(PlayFieldStat[i+1][j-1]==0)&&(PlayFieldStat[i+1][j]==0)){
                return 0;
                }
            else {
                return 1;
                }
            break;

        case 1:
            if ((PlayFieldStat[i+1][j-1]==0)&&(PlayFieldStat[i][j]==0)){
                return 0;
                }
            else {
                return 1;
                }
            break;
        }
}

int ZblockDetectSpin(int i, int j, int c){
    int d;
    d = c%2;

    switch(d){
        case 0:
            if ((PlayFieldStat[i-2][j]==0)&&(PlayFieldStat[i-1][j]==0)&&(j>-1)&&(j<10)){
                return 0;
                }
            else {
                return 1;
                }
            break;

        case 1:
            if ((PlayFieldStat[i-1][j-2]==0)&&(PlayFieldStat[i][j]==0)&&((j-2)>-1)&&(j<10)){
                return 0;
                }
            else {
                return 1;
                }
            break;
    }
}

//LBlock needs

void Lblock (int a, int b, int c){
    int d;
    d = c%4;

    switch (d){
        case 0: Block (a, b, T); Block ((a-10),b, T); Block ((a-10),(b-10), T); Block ((a-10),(b-20), T); break;
        case 1: Block ((a-10), b, T); Block ((a-10),(b-10), T); Block (a,(b-10), T); Block ((a+9),(b-10), T); break;
        case 2: Block (a, b, T); Block (a,(b-10), T); Block (a,(b-20), T);  Block ((a-10),(b-20), T); break;
        case 3: Block (a, b, T); Block (a,(b-10), T); Block ((a-10),b, T); Block ((a-19),b, T); break;
    }
}

void LblockSave (int i, int j, int c){
    int d;
    d = c%4;

    switch (d){
        case 0: PlayFieldStat[i-2][j-1]=T;PlayFieldStat[i-1][j-1]=T;PlayFieldStat[i][j-1]=T;PlayFieldStat[i][j]=T;break;
        case 1: PlayFieldStat[i-1][j-1]=T;PlayFieldStat[i-1][j]=T;PlayFieldStat[i-1][j+1]=T;PlayFieldStat[i][j-1]=T;break;
        case 2: PlayFieldStat[i-2][j-1]=T;PlayFieldStat[i-2][j]=T;PlayFieldStat[i-1][j]=T;PlayFieldStat[i][j]=T;break;
        case 3: PlayFieldStat[i-1][j]=T;PlayFieldStat[i][j-2]=T;PlayFieldStat[i][j-1]=T;PlayFieldStat[i][j]=T;break;
    }
}

void LblockErase (int a, int b, int c){
    int d;
    d = c%4;

    switch (d){
        case 0: Erase(a, b); Erase((a-10),b); Erase((a-10),(b-10)); Erase((a-10),(b-20)); break;
        case 1: Erase((a-10), b); Erase((a-10),(b-10)); Erase(a,(b-10)); Erase ((a+9),(b-10)); break;
        case 2: Erase(a, b); Erase(a,(b-10)); Erase(a,(b-20));  Erase((a-10),(b-20)); break;
        case 3: Erase(a, b); Erase(a,(b-10)); Erase((a-10),b);  Erase((a-19),b); break;
    }
}

int LblockDetectLeft(int i, int j, int c){
    int d;
    d = c%4;

    switch(d){
        case 0:
            if ((PlayFieldStat[i-2][j-2]==0)&&(PlayFieldStat[i-1][j-2]==0)&&(PlayFieldStat[i][j-2]==0)&&((j-2)>-1)){
                return 0;
                }
            else {
                return 1;
                }
            break;

        case 1:
            if ((PlayFieldStat[i-1][j-2]==0)&&(PlayFieldStat[i][j-2]==0)&&((j-2)>-1)){
                return 0;
                }
            else {
                return 1;
                }
            break;
        case 2:
            if ((PlayFieldStat[i-2][j-2]==0)&&(PlayFieldStat[i-1][j-1]==0)&&(PlayFieldStat[i][j-1]==0)&&((j-2)>-1)){
                return 0;
                }
            else {
                return 1;
                }
            break;

        case 3:
            if ((PlayFieldStat[i][j-3]==0)&& (PlayFieldStat[i-1][j-1]==0)&&((j-3)>-1)){
                return 0;
                }
            else {
                return 1;
                }
            break;
        }
}

int LblockDetectRight(int i, int j, int c){
    int d;
    d = c%4;

    switch(d){
        case 0:
            if ((PlayFieldStat[i-2][j]==0)&&(PlayFieldStat[i-1][j]==0)&&(PlayFieldStat[i][j+1]==0)&&((j+1)<10)){
                return 0;
                }
            else {
                return 1;
                }
            break;

        case 1:
            if ((PlayFieldStat[i-1][j+2]==0)&&(PlayFieldStat[i][j]==0)&&((j+2)<10)){
                return 0;
                }
            else {
                return 1;
                }
            break;
        case 2:
            if ((PlayFieldStat[i-2][j+1]==0)&&(PlayFieldStat[i-1][j+1]==0)&&(PlayFieldStat[i][j+1]==0)&&((j+1)<10)){
                return 0;
                }
            else {
                return 1;
                }
            break;

        case 3:
            if ((PlayFieldStat[i-1][j+1]==0)&& (PlayFieldStat[i][j+1]==0)&&((j+1)<10)){
                return 0;
                }
            else {
                return 1;
                }
            break;
        }
}

int LblockDetectBelow(int i, int j, int c){
    int d;
    d = c%4;

    switch(d){
        case 0:
            if ((PlayFieldStat[i+1][j-1]==0)&&(PlayFieldStat[i+1][j]==0)){
                return 0;
                }
            else {
                return 1;
                }
            break;

        case 1:
            if ((PlayFieldStat[i+1][j-1]==0)&&(PlayFieldStat[i][j]==0)&&(PlayFieldStat[i][j+1]==0)){
                return 0;
                }
            else {
                return 1;
                }
            break;
        case 2:
            if ((PlayFieldStat[i-1][j-1]==0)&&(PlayFieldStat[i+1][j]==0)){
                return 0;
                }
            else {
                return 1;
                }
            break;

        case 3:
            if ((PlayFieldStat[i+1][j-2]==0)&&(PlayFieldStat[i+1][j-1]==0)&&(PlayFieldStat[i+1][j]==0)){
                return 0;
                }
            else {
                return 1;
                }
            break;
        }
}

int LblockDetectSpin(int i, int j, int c){
    int d;
    d = c%2;

    switch(d){
        case 0:
            if ((PlayFieldStat[i-1][j]==0)&&(PlayFieldStat[i-1][j+1]==0)&&(j>-1)&&((j+1)<10)){
                return 0;
                }
            else {
                return 1;
                }
            break;

        case 1:
            if ((PlayFieldStat[i-2][j-1]==0)&&(PlayFieldStat[i-2][j]==0)&&(PlayFieldStat[i][j]==0)&&((j-1)>-1)&&(j<10)){
                return 0;
                }
            else {
                return 1;
                }
            break;
        case 2:
            if ((PlayFieldStat[i][j-2]==0)&&(PlayFieldStat[i][j-1]==0)&&((j-2)>-1)&&((j-1)<10)){
                return 0;
                }
            else {
                return 1;
                }
            break;

        case 3:
            if ((PlayFieldStat[i-2][j-1]==0)&&(PlayFieldStat[i-1][j-1]==0)){
                return 0;
                }
            else {
                return 1;
                }
            break;
    }
}

//Jblock needs

void Jblock (int a, int b, int c){
    int d;
    d = c%4;

    switch (d){
        case 0: Block (a, b, B); Block ((a-10),b, B); Block (a,(b-10), B); Block ((a),(b-20), B); break;
        case 1: Block ((a-10), (b-10), B); Block ((a-10),b, B); Block (a,b, B); Block ((a+9),b, B); break;
        case 2: Block ((a-10), (b-20), B); Block (a,(b-20), B); Block ((a-10),(b-10), B); Block((a-10),b, B); break;
        case 3: Block (a, b, B); Block (a,(b-10), B); Block ((a-10),(b-10), B); Block ((a-20),(b-10), B); break;
    }
}

void JblockSave (int i, int j, int c){
    int d;
    d = c%4;

    switch (d){
        case 0: PlayFieldStat[i-2][j]=B;PlayFieldStat[i-1][j]=B;PlayFieldStat[i][j-1]=B;PlayFieldStat[i][j]=B;break;
        case 1: PlayFieldStat[i-1][j-1]=B;PlayFieldStat[i][j-1]=B;PlayFieldStat[i][j]=B;PlayFieldStat[i][j+1]=B;break;
        case 2: PlayFieldStat[i-2][j-1]=B;PlayFieldStat[i-2][j]=B;PlayFieldStat[i-1][j-1]=B;PlayFieldStat[i][j-1]=B;break;
        case 3: PlayFieldStat[i-1][j-2]=B;PlayFieldStat[i-1][j-1]=B;PlayFieldStat[i-1][j]=B;PlayFieldStat[i][j]=B;break;
    }
}

void JblockErase (int a, int b, int c){
    int d;
    d = c%4;

    switch (d){
        case 0: Erase (a, b); Erase ((a-10),b); Erase (a,(b-10)); Erase ((a),(b-20)); break;
        case 1: Erase ((a-10), (b-10)); Erase ((a-10),b);Erase (a,b); Erase ((a+9),b); break;
        case 2: Erase ((a-10), (b-20)); Erase (a,(b-20)); Erase ((a-10),(b-10)); Erase((a-10),b); break;
        case 3: Erase (a, b); Erase(a,(b-10));Erase((a-10),(b-10)); Erase((a-20),(b-10)); break;
    }
}

int JblockDetectLeft(int i, int j, int c){
    int d;
    d = c%4;

    switch(d){
        case 0:
            if ((PlayFieldStat[i-2][j-1]==0)&&(PlayFieldStat[i-1][j-1]==0)&&(PlayFieldStat[i][j-2]==0)&&((j-2)>-1)){
                return 0;
                }
            else {
                return 1;
                }
            break;

        case 1:
            if ((PlayFieldStat[i-1][j-2]==0)&&(PlayFieldStat[i][j-2]==0)&&((j-2)>-1)){
                return 0;
                }
            else {
                return 1;
                }
            break;
        case 2:
            if ((PlayFieldStat[i-2][j-2]==0)&&(PlayFieldStat[i-1][j-2]==0)&&(PlayFieldStat[i][j-2]==0)&&((j-2)>-1)){
                return 0;
                }
            else {
                return 1;
                }
            break;

        case 3:
            if ((PlayFieldStat[i-1][j-3]==0)&& (PlayFieldStat[i][j-1]==0)&&((j-3)>-1)){
                return 0;
                }
            else {
                return 1;
                }
            break;
        }
}

int JblockDetectRight(int i, int j, int c){
    int d;
    d = c%4;

    switch(d){
        case 0:
            if ((PlayFieldStat[i-2][j+1]==0)&&(PlayFieldStat[i-1][j+1]==0)&&(PlayFieldStat[i][j+1]==0)&&((j+1)<10)){
                return 0;
                }
            else {
                return 1;
                }
            break;

        case 1:
            if ((PlayFieldStat[i-1][j]==0)&&(PlayFieldStat[i][j+2]==0)&&((j+2)<10)){
                return 0;
                }
            else {
                return 1;
                }
            break;
        case 2:
            if ((PlayFieldStat[i-2][j+1]==0)&&(PlayFieldStat[i-1][j]==0)&&(PlayFieldStat[i][j]==0)&&((j+1)<10)){
                return 0;
                }
            else {
                return 1;
                }
            break;

        case 3:
            if ((PlayFieldStat[i-1][j+1]==0)&& (PlayFieldStat[i][j+1]==0)&&((j+1)<10)){
                return 0;
                }
            else {
                return 1;
                }
            break;
        }
}

int JblockDetectBelow(int i, int j, int c){
    int d;
    d = c%4;

    switch(d){
        case 0:
            if ((PlayFieldStat[i+1][j-1]==0)&&(PlayFieldStat[i+1][j]==0)){
                return 0;
                }
            else {
                return 1;
                }
            break;

        case 1:
            if ((PlayFieldStat[i+1][j-1]==0)&&(PlayFieldStat[i+1][j]==0)&&(PlayFieldStat[i+1][j+1]==0)){
                return 0;
                }
            else {
                return 1;
                }
            break;
        case 2:
            if ((PlayFieldStat[i+1][j-1]==0)&&(PlayFieldStat[i-1][j]==0)){
                return 0;
                }
            else {
                return 1;
                }
            break;

        case 3:
            if ((PlayFieldStat[i][j-2]==0)&&(PlayFieldStat[i][j-1]==0)&&(PlayFieldStat[i+1][j]==0)){
                return 0;
                }
            else {
                return 1;
                }
            break;
        }
}

int JblockDetectSpin(int i, int j, int c){
    int d;
    d = c%2;

    switch(d){
        case 0:
            if ((PlayFieldStat[i-1][j-1]==0)&&(PlayFieldStat[i][j+1]==0)&&((j-1)>-1)&&((j+1)<10)){
                return 0;
                }
            else {
                return 1;
                }
            break;

        case 1:
            if ((PlayFieldStat[i-2][j-1]==0)&&(PlayFieldStat[i-2][j-1]==0)&&((j-1)>-1)&&((j-1)<10)){
                return 0;
                }
            else {
                return 1;
                }
            break;
        case 2:
            if ((PlayFieldStat[i-1][j-1]==0)&&(PlayFieldStat[i-1][j]==0)&&(PlayFieldStat[i][j]==0)&&((j-1)>-1)&&(j<10)){
                return 0;
                }
            else {
                return 1;
                }
            break;

        case 3:
            if ((PlayFieldStat[i-2][j]==0)&&(PlayFieldStat[i][j-1]==0)&&((j-1)>-1)&&(j<10)){
                return 0;
                }
            else {
                return 1;
                }
            break;
    }
}

//Tblock needs

void Tblock (int a, int b, int c){
    int d;
    d = c%4;

    switch (d){
        case 0: Block ((a-10), (b-10), L); Block (a,(b-10), L); Block ((a+9),(b-10), L); Block (a,b, L); break;
        case 1: Block ((a),(b-20), L);  Block (a,(b-10), L); Block ((a-10),(b-10), L); Block (a, b, L); break;
        case 2: Block ((a-10), b, L); Block (a,(b-10), L); Block (a,b, L); Block ((a+9),b, L); break;
        case 3: Block ((a),(b-20), L);  Block (a,(b-10), L); Block ((a+9),(b-10), L); Block (a, b, L); break;
    }
}

void TblockSave (int i, int j, int c){
    int d;
    d = c%4;

    switch (d){
        case 0: PlayFieldStat[i-1][j-1]=L;PlayFieldStat[i-1][j]=L;PlayFieldStat[i-1][j+1]=L;PlayFieldStat[i][j]=L;break;
        case 1: PlayFieldStat[i-2][j]=L;PlayFieldStat[i-1][j-1]=L;PlayFieldStat[i-1][j]=L;PlayFieldStat[i][j]=L;break;
        case 2: PlayFieldStat[i-1][j]=L;PlayFieldStat[i][j-1]=L;PlayFieldStat[i][j]=L;PlayFieldStat[i][j+1]=L;break;
        case 3: PlayFieldStat[i-2][j]=L;PlayFieldStat[i-1][j]=L;PlayFieldStat[i-1][j+1]=L;PlayFieldStat[i][j]=L;break;
    }
}

void TblockErase (int a, int b, int c){
    int d;
    d = c%4;

    switch (d){
        case 0: Erase ((a-10), (b-10)); Erase (a,(b-10)); Erase ((a+9),(b-10)); Erase (a,b); break;
        case 1: Erase ((a),(b-20));  Erase (a,(b-10)); Erase ((a-10),(b-10)); Erase (a, b); break;
        case 2: Erase ((a-10), b); Erase (a,(b-10)); Erase (a,b); Erase ((a+9),b); break;
        case 3: Erase ((a),(b-20));  Erase (a,(b-10)); Erase((a+9),(b-10)); Erase (a, b); break;
    }
}

int TblockDetectLeft(int i, int j, int c){
    int d;
    d = c%4;

    switch(d){
        case 0:
            if ((PlayFieldStat[i-1][j-2]==0)&&(PlayFieldStat[i][j-1]==0)&&((j-2)>-1)){
                return 0;
                }
            else {
                return 1;
                }
            break;

        case 1:
            if ((PlayFieldStat[i-2][j-1]==0)&&(PlayFieldStat[i-1][j-2]==0)&&(PlayFieldStat[i][j-1]==0)&&((j-2)>-1)){
                return 0;
                }
            else {
                return 1;
                }
            break;
        case 2:
            if ((PlayFieldStat[i-1][j-1]==0)&&(PlayFieldStat[i][j-2]==0)&&((j-2)>-1)){
                return 0;
                }
            else {
                return 1;
                }
            break;

        case 3:
            if ((PlayFieldStat[i-2][j-1]==0)&&(PlayFieldStat[i-1][j-1]==0)&&(PlayFieldStat[i][j-1]==0)&&((j-1)>-1)){
                return 0;
                }
            else {
                return 1;
                }
            break;
        }
}

int TblockDetectRight(int i, int j, int c){
    int d;
    d = c%4;

    switch(d){
        case 0:
            if ((PlayFieldStat[i-1][j+2]==0)&&(PlayFieldStat[i][j+1]==0)&&((j+2)<10)){
                return 0;
                }
            else {
                return 1;
                }
            break;

        case 1:
            if ((PlayFieldStat[i-2][j+1]==0)&&(PlayFieldStat[i-1][j+1]==0)&&(PlayFieldStat[i][j+1]==0)&&((j+1)<10)){
                return 0;
                }
            else {
                return 1;
                }
            break;
        case 2:
            if ((PlayFieldStat[i-1][j+1]==0)&&(PlayFieldStat[i][j+2]==0)&&((j+2)<10)){
                return 0;
                }
            else {
                return 1;
                }
            break;

        case 3:
            if ((PlayFieldStat[i-2][j+1]==0)&&(PlayFieldStat[i-1][j+2]==0)&&(PlayFieldStat[i][j+1]==0)&&((j+2)<10)){
                return 0;
                }
            else {
                return 1;
                }
            break;
        }
}

int TblockDetectBelow(int i, int j, int c){
    int d;
    d = c%4;

    switch(d){
        case 0:
            if ((PlayFieldStat[i][j-1]==0)&&(PlayFieldStat[i+1][j]==0)&&(PlayFieldStat[i][j+1]==0)){
                return 0;
                }
            else {
                return 1;
                }
            break;

        case 1:
            if ((PlayFieldStat[i][j-1]==0)&&(PlayFieldStat[i+1][j]==0)){
                return 0;
                }
            else {
                return 1;
                }
            break;
        case 2:
            if ((PlayFieldStat[i+1][j-1]==0)&&(PlayFieldStat[i+1][j]==0)&&(PlayFieldStat[i+1][j+1]==0)){
                return 0;
                }
            else {
                return 1;
                }
            break;

        case 3:
            if ((PlayFieldStat[i+1][j]==0)&& (PlayFieldStat[i][j+1]==0)){
                return 0;
                }
            else {
                return 1;
                }
            break;
        }
}

int TblockDetectSpin(int i, int j, int c){
    int d;
    d = c%2;

    switch(d){
        case 0:
            if ((PlayFieldStat[i-2][j]==0)&&(j>-1)&&(j<10)){
                return 0;
                }
            else {
                return 1;
                }
            break;

        case 1:
            if ((PlayFieldStat[i][j-1]==0)&&(PlayFieldStat[i][j+1]==0)&&((j-1)>-1)&&((j+1)<10)){
                return 0;
                }
            else {
                return 1;
                }
            break;
        case 2:
            if ((PlayFieldStat[i-2][j]==0)&&(PlayFieldStat[i-1][j+1]==0)&&(j>-1)&&((j+1)<10)){
                return 0;
                }
            else {
                return 1;
                }
            break;

        case 3:
            if ((PlayFieldStat[i-2][j-1]==0)&&((j-1)>-1)&&((j-1)<10)){
                return 0;
                }
            else {
                return 1;
                }
            break;
    }
}

////letters and numbers needs

void LetterA(int a, int b, int c1, int c2){

    pin(a, b, c2);
    pin(a, (b-2), c2);

    pin((a+2), (b-6), c2);
    pin((a+2), (b-4), c2);
    pin((a+2), (b-2), c1);
    pin((a+2), b, c1);

    pin((a+4), (b-10), c2);
    pin((a+4), (b-8), c2);
    pin((a+4), (b-6), c1);
    pin((a+4), (b-4), c1);
    pin((a+4), (b-2), c1);
    pin((a+4), b, c1);

    pin((a+6), (b-14), c2);
    pin((a+6), (b-12), c2);
    pin((a+6), (b-10), c1);
    pin((a+6), (b-8), c1);
    pin((a+6), (b-6), c1);
    pin((a+6), (b-4), c1);
    pin((a+6), (b-2), c1);
    pin((a+6), b, c1);

    pin((a+8), (b-14), c1);
    pin((a+8), (b-12), c1);
    pin((a+8), (b-10), c1);
    pin((a+8), (b-8), c1);
    pin((a+8), (b-6), c1);
    pin((a+8), (b-4), c1);

    pin((a+10), (b-14), c1);
    pin((a+10), (b-12), c1);
    pin((a+10), (b-10), c1);
    pin((a+10), (b-8), c2);
    pin((a+10), (b-6), c1);
    pin((a+10), (b-4), c1);
    pin((a+10), (b-2), c2);
    pin((a+10), b, c2);

    pin((a+12), (b-14), c1);
    pin((a+12), (b-12), c1);
    pin((a+12), (b-10), c1);
    pin((a+12), (b-8), c1);
    pin((a+12), (b-6), c1);
    pin((a+12), (b-4), c1);
    pin((a+12), (b-2), c1);
    pin((a+12), b, c1);

    pin((a+14), (b-14), c1);
    pin((a+14), (b-12), c1);
    pin((a+14), (b-10), c1);
    pin((a+14), (b-8), c1);
    pin((a+14), (b-6), c1);
    pin((a+14), (b-4), c1);
    pin((a+14), (b-2), c1);
    pin((a+14), b, c1);

    pin((a+16), (b-2), c1);
    pin((a+16), b, c1);

}

void LetterB(int a, int b, int c1, int c2){
    pin(a, (b-14), c2);
    pin(a, (b-12), c2);
    pin(a, (b-2), c2);
    pin(a, b, c2);

    pin((a+2), (b-14), c1);
    pin((a+2), (b-12), c1);
    pin((a+2), (b-10), c2);
    pin((a+2), (b-8), c2);
    pin((a+2), (b-6), c2);
    pin((a+2), (b-4), c2);
    pin((a+2), (b-2), c1);
    pin((a+2), b, c1);

    pin((a+4), (b-14), c1);
    pin((a+4), (b-12), c1);
    pin((a+4), (b-10), c1);
    pin((a+4), (b-8), c1);
    pin((a+4), (b-6), c1);
    pin((a+4), (b-4), c1);
    pin((a+4), (b-2), c1);
    pin((a+4), b, c1);

    pin((a+6), (b-14), c1);
    pin((a+6), (b-12), c1);
    pin((a+6), (b-10), c1);
    pin((a+6), (b-8), c1);
    pin((a+6), (b-6), c1);
    pin((a+6), (b-4), c1);
    pin((a+6), (b-2), c1);
    pin((a+6), b, c1);

    pin((a+8), (b-14), c1);
    pin((a+8), (b-12), c1);
    pin((a+8), (b-10), c2);
    pin((a+8), (b-8), c1);
    pin((a+8), (b-6), c1);
    pin((a+8), (b-4), c2);
    pin((a+8), (b-2), c1);
    pin((a+8), b, c1);

    pin((a+10), (b-14), c1);
    pin((a+10), (b-12), c1);
    pin((a+10), (b-10), c1);
    pin((a+10), (b-8), c1);
    pin((a+10), (b-6), c1);
    pin((a+10), (b-4), c1);
    pin((a+10), (b-2), c1);
    pin((a+10), b, c1);

    pin((a+12), (b-12), c1);
    pin((a+12), (b-10), c1);
    pin((a+12), (b-8), c1);
    pin((a+12), (b-6), c1);
    pin((a+12), (b-4), c1);
    pin((a+12), (b-2), c1);
    pin((a+12), b, c1);

    pin((a+14), (b-6), c1);
    pin((a+14), (b-4), c1);
    pin((a+14), (b-2), c1);

}

void LetterC(int a, int b, int c1, int c2){

    pin(a, (b-10), c2);
    pin(a, (b-8), c2);
    pin(a, (b-6), c2);
    pin(a, (b-4), c2);

    pin((a+2), (b-12), c2);
    pin((a+2), (b-10), c1);
    pin((a+2), (b-8), c1);
    pin((a+2), (b-6), c1);
    pin((a+2), (b-4), c1);
    pin((a+2), (b-2), c2);

    pin((a+4), (b-14), c2);
    pin((a+4), (b-12), c1);
    pin((a+4), (b-10), c1);
    pin((a+4), (b-8), c1);
    pin((a+4), (b-6), c1);
    pin((a+4), (b-4), c1);
    pin((a+4), (b-2), c1);
    pin((a+4), b, c2);

    pin((a+6), (b-14), c1);
    pin((a+6), (b-12), c1);
    pin((a+6), (b-10), c1);
    pin((a+6), (b-8), c1);
    pin((a+6), (b-6), c1);
    pin((a+6), (b-4), c1);
    pin((a+6), (b-2), c1);
    pin((a+6), b, c1);

    pin((a+8), (b-14), c1);
    pin((a+8), (b-12), c1);
    pin((a+8), (b-10), c1);
    pin((a+8), (b-4), c1);
    pin((a+8), (b-2), c1);
    pin((a+8), b, c1);

    pin((a+10), (b-14), c1);
    pin((a+10), (b-12), c1);
    pin((a+10), (b-10), c2);
    pin((a+10), (b-4), c1);
    pin((a+10), (b-2), c1);
    pin((a+10), b, c1);

    pin((a+12), (b-14), c1);
    pin((a+12), (b-12), c1);
    pin((a+12), (b-10), c1);
    pin((a+12), (b-4), c1);
    pin((a+12), (b-2), c1);
    pin((a+12), b, c1);

    pin((a+14), (b-12), c1);
    pin((a+14), (b-10), c1);
    pin((a+14), (b-4), c1);
    pin((a+14), (b-2), c1);
}

void LetterD(int a, int b, int c1, int c2){
    pin(a, (b-14), c2);
    pin(a, (b-12), c2);
    pin(a, (b-2), c2);
    pin(a, b, c2);

    pin((a+2), (b-14), c1);
    pin((a+2), (b-12), c1);
    pin((a+2), (b-10), c2);
    pin((a+2), (b-8), c2);
    pin((a+2), (b-6), c2);
    pin((a+2), (b-4), c2);
    pin((a+2), (b-2), c1);
    pin((a+2), b, c1);

    pin((a+4), (b-14), c1);
    pin((a+4), (b-12), c1);
    pin((a+4), (b-10), c1);
    pin((a+4), (b-8), c1);
    pin((a+4), (b-6), c1);
    pin((a+4), (b-4), c1);
    pin((a+4), (b-2), c1);
    pin((a+4), b, c1);

    pin((a+6), (b-14), c1);
    pin((a+6), (b-12), c1);
    pin((a+6), (b-10), c1);
    pin((a+6), (b-8), c1);
    pin((a+6), (b-6), c1);
    pin((a+6), (b-4), c1);
    pin((a+6), (b-2), c1);
    pin((a+6), b, c1);

    pin((a+8), (b-14), c1);
    pin((a+8), (b-12), c1);
    pin((a+8), (b-10), c2);
    pin((a+8), (b-8), c2);
    pin((a+8), (b-6), c2);
    pin((a+8), (b-4), c2);
    pin((a+8), (b-2), c1);
    pin((a+8), b, c1);

    pin((a+10), (b-14), c1);
    pin((a+10), (b-12), c1);
    pin((a+10), (b-10), c1);
    pin((a+10), (b-8), c1);
    pin((a+10), (b-6), c1);
    pin((a+10), (b-4), c1);
    pin((a+10), (b-2), c1);
    pin((a+10), b, c1);

    pin((a+12), (b-14), c1);
    pin((a+12), (b-12), c1);
    pin((a+12), (b-10), c1);
    pin((a+12), (b-8), c1);
    pin((a+12), (b-6), c1);
    pin((a+12), (b-4), c1);
    pin((a+12), (b-2), c1);
    pin((a+12), b, c1);

    pin((a+14), (b-12), c1);
    pin((a+14), (b-10), c1);
    pin((a+14), (b-8), c1);
    pin((a+14), (b-6), c1);
    pin((a+14), (b-4), c1);
    pin((a+14), (b-2), c1);

}

void LetterE(int a, int b, int c1, int c2){

    pin(a, (b-14), c2);
    pin(a, (b-12), c2);
    pin(a, (b-2), c2);
    pin(a, b, c2);

    pin((a+2), (b-14), c1);
    pin((a+2), (b-12), c1);
    pin((a+2), (b-10), c2);
    pin((a+2), (b-8), c2);
    pin((a+2), (b-6), c2);
    pin((a+2), (b-4), c2);
    pin((a+2), (b-2), c1);
    pin((a+2), b, c1);

    pin((a+4), (b-14), c1);
    pin((a+4), (b-12), c1);
    pin((a+4), (b-10), c1);
    pin((a+4), (b-8), c1);
    pin((a+4), (b-6), c1);
    pin((a+4), (b-4), c1);
    pin((a+4), (b-2), c1);
    pin((a+4), b, c1);

    pin((a+6), (b-14), c1);
    pin((a+6), (b-12), c1);
    pin((a+6), (b-10), c1);
    pin((a+6), (b-8), c1);
    pin((a+6), (b-6), c1);
    pin((a+6), (b-4), c1);
    pin((a+6), (b-2), c1);
    pin((a+6), b, c1);

    pin((a+8), (b-14), c1);
    pin((a+8), (b-12), c1);
    pin((a+8), (b-8), c1);
    pin((a+8), (b-6), c1);
    pin((a+8), (b-2), c1);
    pin((a+8), b, c1);

    pin((a+10), (b-14), c1);
    pin((a+10), (b-12), c1);
    pin((a+10), (b-8), c1);
    pin((a+10), (b-6), c1);
    pin((a+10), (b-2), c1);
    pin((a+10), b, c1);

    pin((a+10), (b-14), c1);
    pin((a+10), (b-12), c1);
    pin((a+10), (b-2), c1);
    pin((a+10), b, c1);

}

void LetterF(int a, int b, int c1, int c2){

    pin(a, (b-14), c2);
    pin(a, (b-12), c2);

    pin((a+2), (b-14), c1);
    pin((a+2), (b-12), c1);
    pin((a+2), (b-10), c2);
    pin((a+2), (b-8), c2);
    pin((a+2), (b-6), c2);
    pin((a+2), (b-4), c2);
    pin((a+2), (b-2), c2);
    pin((a+2), b, c2);

    pin((a+4), (b-14), c1);
    pin((a+4), (b-12), c1);
    pin((a+4), (b-10), c1);
    pin((a+4), (b-8), c1);
    pin((a+4), (b-6), c1);
    pin((a+4), (b-4), c1);
    pin((a+4), (b-2), c1);
    pin((a+4), b, c1);

    pin((a+6), (b-14), c1);
    pin((a+6), (b-12), c1);
    pin((a+6), (b-10), c1);
    pin((a+6), (b-8), c1);
    pin((a+6), (b-6), c1);
    pin((a+6), (b-4), c1);
    pin((a+6), (b-2), c1);
    pin((a+6), b, c1);

    pin((a+8), (b-14), c1);
    pin((a+8), (b-12), c1);
    pin((a+8), (b-8), c1);
    pin((a+8), (b-6), c1);

    pin((a+10), (b-14), c1);
    pin((a+10), (b-12), c1);
    pin((a+10), (b-8), c1);
    pin((a+10), (b-6), c1);

    pin((a+10), (b-14), c1);
    pin((a+10), (b-12), c1);

}

void LetterG(int a, int b, int c1, int c2){

    pin(a, (b-10), c2);
    pin(a, (b-8), c2);
    pin(a, (b-6), c2);
    pin(a, (b-4), c2);

    pin((a+2), (b-12), c2);
    pin((a+2), (b-10), c1);
    pin((a+2), (b-8), c1);
    pin((a+2), (b-6), c1);
    pin((a+2), (b-4), c1);
    pin((a+2), (b-2), c2);

    pin((a+4), (b-14), c2);
    pin((a+4), (b-12), c1);
    pin((a+4), (b-10), c1);
    pin((a+4), (b-8), c1);
    pin((a+4), (b-6), c1);
    pin((a+4), (b-4), c1);
    pin((a+4), (b-2), c1);
    pin((a+4), b, c2);

    pin((a+6), (b-14), c1);
    pin((a+6), (b-12), c1);
    pin((a+6), (b-10), c1);
    pin((a+6), (b-8), c1);
    pin((a+6), (b-6), c1);
    pin((a+6), (b-4), c1);
    pin((a+6), (b-2), c1);
    pin((a+6), b, c1);

    pin((a+8), (b-14), c1);
    pin((a+8), (b-12), c1);
    pin((a+8), (b-10), c1);
    pin((a+8), (b-6), c2);
    pin((a+8), (b-4), c1);
    pin((a+8), (b-2), c1);
    pin((a+8), b, c1);

    pin((a+10), (b-14), c1);
    pin((a+10), (b-12), c1);
    pin((a+10), (b-10), c2);
    pin((a+10), (b-6), c1);
    pin((a+10), (b-4), c1);
    pin((a+10), (b-2), c1);
    pin((a+10), b, c1);

    pin((a+12), (b-14), c1);
    pin((a+12), (b-12), c1);
    pin((a+12), (b-10), c1);
    pin((a+12), (b-6), c1);
    pin((a+12), (b-4), c1);
    pin((a+12), (b-2), c1);
    pin((a+12), b, c2);

    pin((a+14), (b-12), c1);
    pin((a+14), (b-10), c1);
    pin((a+14), (b-6), c1);
    pin((a+14), (b-4), c1);
    pin((a+14), (b-2), c1);
    pin((a+14), b, c1);
}

void LetterH(int a, int b, int c1, int c2){
    pin(a, (b-14), c2);
    pin(a, (b-12), c2);
    pin(a, (b-10), c2);
    pin(a, (b-8), c2);
    pin(a, (b-6), c2);
    pin(a, (b-4), c2);
    pin(a, (b-2), c2);
    pin(a, b, c2);

    pin((a+2), (b-14), c1);
    pin((a+2), (b-12), c1);
    pin((a+2), (b-10), c1);
    pin((a+2), (b-8), c1);
    pin((a+2), (b-6), c1);
    pin((a+2), (b-4), c1);
    pin((a+2), (b-2), c1);
    pin((a+2), b, c1);

    pin((a+4), (b-14), c1);
    pin((a+4), (b-12), c1);
    pin((a+4), (b-10), c1);
    pin((a+4), (b-8), c1);
    pin((a+4), (b-6), c1);
    pin((a+4), (b-4), c1);
    pin((a+4), (b-2), c1);
    pin((a+4), b, c1);

    pin((a+6), (b-14), c1);
    pin((a+6), (b-12), c1);
    pin((a+6), (b-10), c1);
    pin((a+6), (b-8), c1);
    pin((a+6), (b-6), c1);
    pin((a+6), (b-4), c1);
    pin((a+6), (b-2), c1);
    pin((a+6), b, c1);

    pin((a+8), (b-8), c1);
    pin((a+8), (b-6), c1);

    pin((a+10), (b-14), c2);
    pin((a+10), (b-12), c2);
    pin((a+10), (b-10), c2);
    pin((a+10), (b-8), c1);
    pin((a+10), (b-6), c1);
    pin((a+10), (b-4), c2);
    pin((a+10), (b-2), c2);
    pin((a+10), b, c2);

    pin((a+12), (b-14), c1);
    pin((a+12), (b-12), c1);
    pin((a+12), (b-10), c1);
    pin((a+12), (b-8), c1);
    pin((a+12), (b-6), c1);
    pin((a+12), (b-4), c1);
    pin((a+12), (b-2), c1);
    pin((a+12), b, c1);

    pin((a+14), (b-14), c1);
    pin((a+14), (b-12), c1);
    pin((a+14), (b-10), c1);
    pin((a+14), (b-8), c1);
    pin((a+14), (b-6), c1);
    pin((a+14), (b-4), c1);
    pin((a+14), (b-2), c1);
    pin((a+14), b, c1);
}

void LetterI(int a, int b, int c1, int c2){
    pin(a, (b-14), c2);
    pin(a, (b-12), c2);
    pin(a, (b-10), c2);
    pin(a, (b-8), c2);
    pin(a, (b-6), c2);
    pin(a, (b-4), c2);
    pin(a, (b-2), c2);
    pin(a, b, c2);

    pin((a+2), (b-14), c1);
    pin((a+2), (b-12), c1);
    pin((a+2), (b-10), c1);
    pin((a+2), (b-8), c1);
    pin((a+2), (b-6), c1);
    pin((a+2), (b-4), c1);
    pin((a+2), (b-2), c1);
    pin((a+2), b, c1);

    pin((a+4), (b-14), c1);
    pin((a+4), (b-12), c1);
    pin((a+4), (b-10), c1);
    pin((a+4), (b-8), c1);
    pin((a+4), (b-6), c1);
    pin((a+4), (b-4), c1);
    pin((a+4), (b-2), c1);
    pin((a+4), b, c1);

    pin((a+6), (b-14), c1);
    pin((a+6), (b-12), c1);
    pin((a+6), (b-10), c1);
    pin((a+6), (b-8), c1);
    pin((a+6), (b-6), c1);
    pin((a+6), (b-4), c1);
    pin((a+6), (b-2), c1);
    pin((a+6), b, c1);
}

void LetterJ(int a, int b, int c1, int c2){

    pin(a, (b-4), c2);
    pin(a, (b-2), c2);

    pin((a+2), (b-4), c1);
    pin((a+2), (b-2), c1);
    pin((a+2), b, c2);

    pin((a+4), (b-4), c1);
    pin((a+4), (b-2), c1);
    pin((a+4), b, c1);

    pin((a+6), (b-14), c2);
    pin((a+6), (b-12), c2);
    pin((a+6), (b-10), c2);
    pin((a+6), (b-8), c2);
    pin((a+6), (b-6), c2);
    pin((a+6), (b-4), c2);
    pin((a+6), (b-2), c1);
    pin((a+6), b, c1);

    pin((a+8), (b-14), c1);
    pin((a+8), (b-12), c1);
    pin((a+8), (b-10), c1);
    pin((a+8), (b-8), c1);
    pin((a+8), (b-6), c1);
    pin((a+8), (b-4), c1);
    pin((a+8), (b-2), c1);
    pin((a+8), b, c1);

    pin((a+10), (b-14), c1);
    pin((a+10), (b-12), c1);
    pin((a+10), (b-10), c1);
    pin((a+10), (b-8), c1);
    pin((a+10), (b-6), c1);
    pin((a+10), (b-4), c1);
    pin((a+10), (b-2), c1);
    pin((a+10), b, c1);

    pin((a+12), (b-14), c1);
    pin((a+12), (b-12), c1);
    pin((a+12), (b-10), c1);
    pin((a+12), (b-8), c1);
    pin((a+12), (b-6), c1);
    pin((a+12), (b-4), c1);
    pin((a+12), (b-2), c1);

}

void LetterK(int a, int b, int c1, int c2){
    pin(a, (b-14), c2);
    pin(a, (b-12), c2);
    pin(a, (b-10), c2);
    pin(a, (b-8), c2);
    pin(a, (b-6), c2);
    pin(a, (b-4), c2);
    pin(a, (b-2), c2);
    pin(a, b, c2);

    pin((a+2), (b-14), c1);
    pin((a+2), (b-12), c1);
    pin((a+2), (b-10), c1);
    pin((a+2), (b-8), c1);
    pin((a+2), (b-6), c1);
    pin((a+2), (b-4), c1);
    pin((a+2), (b-2), c1);
    pin((a+2), b, c1);

    pin((a+4), (b-14), c1);
    pin((a+4), (b-12), c1);
    pin((a+4), (b-10), c1);
    pin((a+4), (b-8), c1);
    pin((a+4), (b-6), c1);
    pin((a+4), (b-4), c1);
    pin((a+4), (b-2), c1);
    pin((a+4), b, c1);

    pin((a+6), (b-14), c1);
    pin((a+6), (b-12), c1);
    pin((a+6), (b-10), c1);
    pin((a+6), (b-8), c1);
    pin((a+6), (b-6), c1);
    pin((a+6), (b-4), c1);
    pin((a+6), (b-2), c1);
    pin((a+6), b, c1);

    pin((a+8), (b-12), c2);
    pin((a+8), (b-10), c2);
    pin((a+8), (b-8), c1);
    pin((a+8), (b-6), c1);
    pin((a+8), (b-4), c2);
    pin((a+8), (b-2), c2);

    pin((a+10), (b-14), c2);
    pin((a+10), (b-12), c1);
    pin((a+10), (b-10), c1);
    pin((a+10), (b-8), c1);
    pin((a+10), (b-6), c1);
    pin((a+10), (b-4), c1);
    pin((a+10), (b-2), c1);
    pin((a+10), b, c2);

    pin((a+12), (b-14), c1);
    pin((a+12), (b-12), c1);
    pin((a+12), (b-10), c1);
    pin((a+12), (b-8), c1);
    pin((a+12), (b-6), c1);
    pin((a+12), (b-4), c1);
    pin((a+12), (b-2), c1);
    pin((a+12), b, c1);

    pin((a+14), (b-14), c1);
    pin((a+14), (b-12), c1);
    pin((a+14), (b-10), c1);
    pin((a+14), (b-6), c1);
    pin((a+14), (b-4), c1);
    pin((a+14), (b-2), c1);
    pin((a+14), b, c1);

    pin((a+16), (b-14), c1);
    pin((a+16), (b-12), c1);
    pin((a+16), (b-4), c1);
    pin((a+16), (b-2), c1);
    pin((a+16), b, c1);

}

void LetterL(int a, int b, int c1, int c2){
    pin(a, (b-14), c2);
    pin(a, (b-12), c2);
    pin(a, (b-10), c2);
    pin(a, (b-8), c2);
    pin(a, (b-6), c2);
    pin(a, (b-4), c2);
    pin(a, (b-2), c2);
    pin(a, b, c2);

    pin((a+2), (b-14), c1);
    pin((a+2), (b-12), c1);
    pin((a+2), (b-10), c1);
    pin((a+2), (b-8), c1);
    pin((a+2), (b-6), c1);
    pin((a+2), (b-4), c1);
    pin((a+2), (b-2), c1);
    pin((a+2), b, c1);

    pin((a+4), (b-14), c1);
    pin((a+4), (b-12), c1);
    pin((a+4), (b-10), c1);
    pin((a+4), (b-8), c1);
    pin((a+4), (b-6), c1);
    pin((a+4), (b-4), c1);
    pin((a+4), (b-2), c1);
    pin((a+4), b, c1);

    pin((a+6), (b-14), c1);
    pin((a+6), (b-12), c1);
    pin((a+6), (b-10), c1);
    pin((a+6), (b-8), c1);
    pin((a+6), (b-6), c1);
    pin((a+6), (b-4), c1);
    pin((a+6), (b-2), c1);
    pin((a+6), b, c1);

    pin((a+8), (b-4), c1);
    pin((a+8), (b-2), c1);
    pin((a+8), b, c1);

    pin((a+10), (b-4), c1);
    pin((a+10), (b-2), c1);
    pin((a+10), b, c1);

}

void LetterM(int a, int b, int c1, int c2){
    pin(a, (b-14), c2);
    pin(a, (b-12), c2);
    pin(a, (b-10), c2);
    pin(a, (b-8), c2);
    pin(a, (b-6), c2);
    pin(a, (b-4), c2);
    pin(a, (b-2), c2);
    pin(a, b, c2);

    pin((a+2), (b-14), c1);
    pin((a+2), (b-12), c1);
    pin((a+2), (b-10), c1);
    pin((a+2), (b-8), c1);
    pin((a+2), (b-6), c1);
    pin((a+2), (b-4), c1);
    pin((a+2), (b-2), c1);
    pin((a+2), b, c1);

    pin((a+4), (b-14), c1);
    pin((a+4), (b-12), c1);
    pin((a+4), (b-10), c1);
    pin((a+4), (b-8), c1);
    pin((a+4), (b-6), c1);
    pin((a+4), (b-4), c1);
    pin((a+4), (b-2), c1);
    pin((a+4), b, c1);

    pin((a+6), (b-14), c1);
    pin((a+6), (b-12), c1);
    pin((a+6), (b-10), c1);
    pin((a+6), (b-8), c1);
    pin((a+6), (b-6), c1);
    pin((a+6), (b-4), c1);
    pin((a+6), (b-2), c1);
    pin((a+6), b, c1);

    pin((a+8), (b-12), c1);
    pin((a+8), (b-10), c1);
    pin((a+8), (b-8), c1);
    pin((a+8), (b-6), c2);

    pin((a+10), (b-12), c2);
    pin((a+10), (b-10), c1);
    pin((a+10), (b-8), c1);
    pin((a+10), (b-6), c1);

    pin((a+12), (b-14), c2);
    pin((a+12), (b-12), c1);
    pin((a+12), (b-10), c1);
    pin((a+12), (b-8), c1);
    pin((a+12), (b-6), c2);
    pin((a+12), (b-4), c2);
    pin((a+12), (b-2), c2);
    pin((a+12), b, c2);

    pin((a+14), (b-14), c1);
    pin((a+14), (b-12), c1);
    pin((a+14), (b-10), c1);
    pin((a+14), (b-8), c1);
    pin((a+14), (b-6), c1);
    pin((a+14), (b-4), c1);
    pin((a+14), (b-2), c1);
    pin((a+14), b, c1);

    pin((a+16), (b-14), c1);
    pin((a+16), (b-12), c1);
    pin((a+16), (b-10), c1);
    pin((a+16), (b-8), c1);
    pin((a+16), (b-6), c1);
    pin((a+16), (b-4), c1);
    pin((a+16), (b-2), c1);
    pin((a+16), b, c1);

    pin((a+18), (b-14), c1);
    pin((a+18), (b-12), c1);
    pin((a+18), (b-10), c1);
    pin((a+18), (b-8), c1);
    pin((a+18), (b-6), c1);
    pin((a+18), (b-4), c1);
    pin((a+18), (b-2), c1);
    pin((a+18), b, c1);

}

void LetterN(int a, int b, int c1, int c2){
    pin(a, (b-14), c2);
    pin(a, (b-12), c2);
    pin(a, (b-10), c2);
    pin(a, (b-8), c2);
    pin(a, (b-6), c2);
    pin(a, (b-4), c2);
    pin(a, (b-2), c2);
    pin(a, b, c2);

    pin((a+2), (b-14), c1);
    pin((a+2), (b-12), c1);
    pin((a+2), (b-10), c1);
    pin((a+2), (b-8), c1);
    pin((a+2), (b-6), c1);
    pin((a+2), (b-4), c1);
    pin((a+2), (b-2), c1);
    pin((a+2), b, c1);

    pin((a+4), (b-14), c1);
    pin((a+4), (b-12), c1);
    pin((a+4), (b-10), c1);
    pin((a+4), (b-8), c1);
    pin((a+4), (b-6), c1);
    pin((a+4), (b-4), c1);
    pin((a+4), (b-2), c1);
    pin((a+4), b, c1);

    pin((a+6), (b-14), c1);
    pin((a+6), (b-12), c1);
    pin((a+6), (b-10), c1);
    pin((a+6), (b-8), c1);
    pin((a+6), (b-6), c1);
    pin((a+6), (b-4), c1);
    pin((a+6), (b-2), c1);
    pin((a+6), b, c1);

    pin((a+8), (b-14), c1);
    pin((a+8), (b-12), c1);
    pin((a+8), (b-10), c1);
    pin((a+8), (b-8), c2);
    pin((a+8), (b-6), c2);
    pin((a+8), (b-4), c2);
    pin((a+8), (b-2), c2);
    pin((a+8), b, c2);

    pin((a+10), (b-14), c1);
    pin((a+10), (b-12), c1);
    pin((a+10), (b-10), c1);
    pin((a+10), (b-8), c1);
    pin((a+10), (b-6), c1);
    pin((a+10), (b-4), c1);
    pin((a+10), (b-2), c1);
    pin((a+10), b, c1);

    pin((a+12), (b-14), c1);
    pin((a+12), (b-12), c1);
    pin((a+12), (b-10), c1);
    pin((a+12), (b-8), c1);
    pin((a+12), (b-6), c1);
    pin((a+12), (b-4), c1);
    pin((a+12), (b-2), c1);
    pin((a+12), b, c1);

    pin((a+14), (b-12), c1);
    pin((a+14), (b-10), c1);
    pin((a+14), (b-8), c1);
    pin((a+14), (b-6), c1);
    pin((a+14), (b-4), c1);
    pin((a+14), (b-2), c1);
    pin((a+14), b, c1);

}

void LetterO(int a, int b, int c1, int c2){

    pin(a, (b-12), c2);
    pin(a, (b-10), c2);
    pin(a, (b-8), c2);
    pin(a, (b-6), c2);
    pin(a, (b-4), c2);
    pin(a, (b-2), c2);

    pin((a+2), (b-14), c2);
    pin((a+2), (b-12), c1);
    pin((a+2), (b-10), c1);
    pin((a+2), (b-8), c1);
    pin((a+2), (b-6), c1);
    pin((a+2), (b-4), c1);
    pin((a+2), (b-2), c1);
    pin((a+2), b, c2);

    pin((a+4), (b-14), c1);
    pin((a+4), (b-12), c1);
    pin((a+4), (b-10), c1);
    pin((a+4), (b-8), c1);
    pin((a+4), (b-6), c1);
    pin((a+4), (b-4), c1);
    pin((a+4), (b-2), c1);
    pin((a+4), b, c1);

    pin((a+6), (b-14), c1);
    pin((a+6), (b-12), c1);
    pin((a+6), (b-10), c1);
    pin((a+6), (b-8), c1);
    pin((a+6), (b-6), c1);
    pin((a+6), (b-4), c1);
    pin((a+6), (b-2), c1);
    pin((a+6), b, c1);

    pin((a+8), (b-14), c1);
    pin((a+8), (b-12), c1);
    pin((a+8), (b-10), c2);
    pin((a+8), (b-8), c2);
    pin((a+8), (b-6), c2);
    pin((a+8), (b-4), c2);
    pin((a+8), (b-2), c1);
    pin((a+8), b, c1);

    pin((a+10), (b-14), c1);
    pin((a+10), (b-12), c1);
    pin((a+10), (b-10), c1);
    pin((a+10), (b-8), c1);
    pin((a+10), (b-6), c1);
    pin((a+10), (b-4), c1);
    pin((a+10), (b-2), c1);
    pin((a+10), b, c1);

    pin((a+12), (b-14), c1);
    pin((a+12), (b-12), c1);
    pin((a+12), (b-10), c1);
    pin((a+12), (b-8), c1);
    pin((a+12), (b-6), c1);
    pin((a+12), (b-4), c1);
    pin((a+12), (b-2), c1);
    pin((a+12), b, c1);

    pin((a+14), (b-12), c1);
    pin((a+14), (b-10), c1);
    pin((a+14), (b-8), c1);
    pin((a+14), (b-6), c1);
    pin((a+14), (b-4), c1);
    pin((a+14), (b-2), c1);

}

void LetterP(int a, int b, int c1, int c2){

    pin(a, (b-14), c2);
    pin(a, (b-12), c2);

    pin((a+2), (b-14), c1);
    pin((a+2), (b-12), c1);
    pin((a+2), (b-10), c2);
    pin((a+2), (b-8), c2);
    pin((a+2), (b-6), c2);
    pin((a+2), (b-4), c2);
    pin((a+2), (b-2), c2);
    pin((a+2), b, c2);

    pin((a+4), (b-14), c1);
    pin((a+4), (b-12), c1);
    pin((a+4), (b-10), c1);
    pin((a+4), (b-8), c1);
    pin((a+4), (b-6), c1);
    pin((a+4), (b-4), c1);
    pin((a+4), (b-2), c1);
    pin((a+4), b, c1);

    pin((a+6), (b-14), c1);
    pin((a+6), (b-12), c1);
    pin((a+6), (b-10), c1);
    pin((a+6), (b-8), c1);
    pin((a+6), (b-6), c1);
    pin((a+6), (b-4), c1);
    pin((a+6), (b-2), c1);
    pin((a+6), b, c1);

    pin((a+8), (b-14), c1);
    pin((a+8), (b-12), c1);
    pin((a+8), (b-10), c2);
    pin((a+8), (b-8), c2);
    pin((a+8), (b-6), c1);
    pin((a+8), (b-4), c1);

    pin((a+10), (b-14), c1);
    pin((a+10), (b-12), c1);
    pin((a+10), (b-10), c1);
    pin((a+10), (b-8), c1);
    pin((a+10), (b-6), c1);
    pin((a+10), (b-4), c1);

    pin((a+12), (b-12), c1);
    pin((a+12), (b-10), c1);
    pin((a+12), (b-8), c1);
    pin((a+12), (b-6), c1);
    pin((a+12), (b-4), c1);

    pin((a+14), (b-12), c1);
    pin((a+14), (b-10), c1);
    pin((a+14), (b-8), c1);
    pin((a+14), (b-6), c1);
}

void LetterR(int a, int b, int c1, int c2){

    pin(a, (b-14), c2);
    pin(a, (b-12), c2);

    pin((a+2), (b-14), c1);
    pin((a+2), (b-12), c1);
    pin((a+2), (b-10), c2);
    pin((a+2), (b-8), c2);
    pin((a+2), (b-6), c2);
    pin((a+2), (b-4), c2);
    pin((a+2), (b-2), c2);
    pin((a+2), b, c2);

    pin((a+4), (b-14), c1);
    pin((a+4), (b-12), c1);
    pin((a+4), (b-10), c1);
    pin((a+4), (b-8), c1);
    pin((a+4), (b-6), c1);
    pin((a+4), (b-4), c1);
    pin((a+4), (b-2), c1);
    pin((a+4), b, c1);

    pin((a+6), (b-14), c1);
    pin((a+6), (b-12), c1);
    pin((a+6), (b-10), c1);
    pin((a+6), (b-8), c1);
    pin((a+6), (b-6), c1);
    pin((a+6), (b-4), c1);
    pin((a+6), (b-2), c1);
    pin((a+6), b, c1);

    pin((a+8), (b-14), c1);
    pin((a+8), (b-12), c1);
    pin((a+8), (b-10), c2);
    pin((a+8), (b-8), c2);
    pin((a+8), (b-6), c1);
    pin((a+8), (b-4), c1);
    pin((a+8), (b-2), c2);

    pin((a+10), (b-14), c1);
    pin((a+10), (b-12), c1);
    pin((a+10), (b-10), c1);
    pin((a+10), (b-8), c1);
    pin((a+10), (b-6), c1);
    pin((a+10), (b-4), c1);
    pin((a+10), (b-2), c1);
    pin((a+10), b, c2);

    pin((a+12), (b-14), c1);
    pin((a+12), (b-12), c1);
    pin((a+12), (b-10), c1);
    pin((a+12), (b-8), c1);
    pin((a+12), (b-6), c1);
    pin((a+12), (b-4), c1);
    pin((a+12), (b-2), c1);
    pin((a+12), b, c1);

    pin((a+14), (b-12), c1);
    pin((a+14), (b-10), c1);
    pin((a+14), (b-8), c1);
    pin((a+14), (b-4), c1);
    pin((a+14), (b-2), c1);
    pin((a+14), b, c1);
}

void LetterS(int a, int b, int c1, int c2){

    pin(a, (b-12), c2);
    pin(a, (b-10), c2);
    pin(a, (b-4), c2);
    pin(a, (b-2), c2);

    pin((a+2), (b-14), c2);
    pin((a+2), (b-12), c1);
    pin((a+2), (b-10), c1);
    pin((a+2), (b-8), c2);
    pin((a+2), (b-4), c1);
    pin((a+2), (b-2), c1);
    pin((a+2), b, c2);

    pin((a+4), (b-14), c1);
    pin((a+4), (b-12), c1);
    pin((a+4), (b-10), c1);
    pin((a+4), (b-8), c1);
    pin((a+4), (b-6), c2);
    pin((a+4), (b-4), c1);
    pin((a+4), (b-2), c1);
    pin((a+4), b, c1);

    pin((a+6), (b-14), c1);
    pin((a+6), (b-12), c1);
    pin((a+6), (b-10), c2);
    pin((a+6), (b-8), c1);
    pin((a+6), (b-6), c1);
    pin((a+6), (b-4), c1);
    pin((a+6), (b-2), c1);
    pin((a+6), b, c1);

    pin((a+8), (b-14), c1);
    pin((a+8), (b-12), c1);
    pin((a+8), (b-10), c2);
    pin((a+8), (b-8), c1);
    pin((a+8), (b-6), c1);
    pin((a+8), (b-4), c1);
    pin((a+8), (b-2), c1);
    pin((a+8), b, c1);

    pin((a+10), (b-14), c1);
    pin((a+10), (b-12), c1);
    pin((a+10), (b-10), c1);
    pin((a+10), (b-8), c2);
    pin((a+10), (b-6), c1);
    pin((a+10), (b-4), c1);
    pin((a+10), (b-2), c1);
    pin((a+10), b, c1);

    pin((a+12), (b-14), c1);
    pin((a+12), (b-12), c1);
    pin((a+12), (b-10), c1);
    pin((a+12), (b-8), c1);
    pin((a+12), (b-6), c1);
    pin((a+12), (b-4), c1);
    pin((a+12), (b-2), c1);
    pin((a+12), b, c1);

    pin((a+14), (b-12), c1);
    pin((a+14), (b-10), c1);
    pin((a+14), (b-6), c1);
    pin((a+14), (b-4), c1);
    pin((a+14), (b-2), c1);

}

void LetterT(int a, int b, int c1, int c2){

    pin(a, (b-14), c2);
    pin(a, (b-12), c2);

    pin((a+2), (b-14), c1);
    pin((a+2), (b-12), c1);

    pin((a+4), (b-14), c1);
    pin((a+4), (b-12), c1);
    pin((a+4), (b-10), c2);
    pin((a+4), (b-8), c2);
    pin((a+4), (b-6), c2);
    pin((a+4), (b-4), c2);
    pin((a+4), (b-2), c2);
    pin((a+4), b, c2);

    pin((a+6), (b-14), c1);
    pin((a+6), (b-12), c1);
    pin((a+6), (b-10), c1);
    pin((a+6), (b-8), c1);
    pin((a+6), (b-6), c1);
    pin((a+6), (b-4), c1);
    pin((a+6), (b-2), c1);
    pin((a+6), b, c1);

    pin((a+8), (b-14), c1);
    pin((a+8), (b-12), c1);
    pin((a+8), (b-10), c1);
    pin((a+8), (b-8), c1);
    pin((a+8), (b-6), c1);
    pin((a+8), (b-4), c1);
    pin((a+8), (b-2), c1);
    pin((a+8), b, c1);

    pin((a+10), (b-14), c1);
    pin((a+10), (b-12), c1);
    pin((a+10), (b-8), c1);
    pin((a+10), (b-6), c1);
    pin((a+10), (b-6), c1);
    pin((a+10), (b-4), c1);
    pin((a+10), (b-2), c1);
    pin((a+10), b, c1);

    pin((a+12), (b-14), c1);
    pin((a+12), (b-12), c1);

    pin((a+14), (b-14), c1);
    pin((a+14), (b-12), c1);

}

void LetterU(int a, int b, int c1, int c2){

    pin(a, (b-14), c2);
    pin(a, (b-12), c2);
    pin(a, (b-10), c2);
    pin(a, (b-8), c2);
    pin(a, (b-6), c2);
    pin(a, (b-4), c2);
    pin(a, (b-2), c2);

    pin((a+2), (b-14), c1);
    pin((a+2), (b-12), c1);
    pin((a+2), (b-10), c1);
    pin((a+2), (b-8), c1);
    pin((a+2), (b-6), c1);
    pin((a+2), (b-4), c1);
    pin((a+2), (b-2), c1);
    pin((a+2), b, c2);

    pin((a+4), (b-14), c1);
    pin((a+4), (b-12), c1);
    pin((a+4), (b-10), c1);
    pin((a+4), (b-8), c1);
    pin((a+4), (b-6), c1);
    pin((a+4), (b-4), c1);
    pin((a+4), (b-2), c1);
    pin((a+4), b, c1);

    pin((a+6), (b-14), c1);
    pin((a+6), (b-12), c1);
    pin((a+6), (b-10), c1);
    pin((a+6), (b-8), c1);
    pin((a+6), (b-6), c1);
    pin((a+6), (b-4), c1);
    pin((a+6), (b-2), c1);
    pin((a+6), b, c1);

    pin((a+8), (b-14), c2);
    pin((a+8), (b-12), c2);
    pin((a+8), (b-10), c2);
    pin((a+8), (b-8), c2);
    pin((a+8), (b-6), c2);
    pin((a+8), (b-4), c2);
    pin((a+8), (b-2), c1);
    pin((a+8), b, c1);

    pin((a+10), (b-14), c1);
    pin((a+10), (b-12), c1);
    pin((a+10), (b-10), c1);
    pin((a+10), (b-8), c1);
    pin((a+10), (b-6), c1);
    pin((a+10), (b-4), c1);
    pin((a+10), (b-2), c1);
    pin((a+10), b, c1);

    pin((a+12), (b-14), c1);
    pin((a+12), (b-12), c1);
    pin((a+12), (b-10), c1);
    pin((a+12), (b-8), c1);
    pin((a+12), (b-6), c1);
    pin((a+12), (b-4), c1);
    pin((a+12), (b-2), c1);

}

void LetterY(int a, int b, int c1, int c2){

    pin(a, (b-14), c2);
    pin(a, (b-12), c2);
    pin(a, (b-10), c2);

    pin((a+2), (b-14), c1);
    pin((a+2), (b-12), c1);
    pin((a+2), (b-10), c1);
    pin((a+2), (b-8), c2);

    pin((a+4), (b-14), c1);
    pin((a+4), (b-12), c1);
    pin((a+4), (b-10), c1);
    pin((a+4), (b-8), c1);
    pin((a+4), (b-6), c2);
    pin((a+4), (b-4), c2);
    pin((a+4), (b-2), c2);
    pin((a+4), b, c2);

    pin((a+6), (b-14), c1);
    pin((a+6), (b-12), c1);
    pin((a+6), (b-10), c1);
    pin((a+6), (b-8), c1);
    pin((a+6), (b-6), c1);
    pin((a+6), (b-4), c1);
    pin((a+6), (b-2), c1);
    pin((a+6), b, c1);

    pin((a+8), (b-14), c2);
    pin((a+8), (b-12), c2);
    pin((a+8), (b-10), c2);
    pin((a+8), (b-8), c1);
    pin((a+8), (b-6), c1);
    pin((a+8), (b-4), c1);
    pin((a+8), (b-2), c1);
    pin((a+8), b, c1);

    pin((a+10), (b-14), c1);
    pin((a+10), (b-12), c1);
    pin((a+10), (b-10), c1);
    pin((a+10), (b-8), c1);
    pin((a+10), (b-6), c1);
    pin((a+10), (b-4), c1);
    pin((a+10), (b-2), c1);
    pin((a+10), b, c1);

    pin((a+12), (b-14), c1);
    pin((a+12), (b-12), c1);
    pin((a+12), (b-10), c1);
    pin((a+12), (b-8), c1);

    pin((a+14), (b-14), c1);
    pin((a+14), (b-12), c1);
    pin((a+14), (b-10), c1);
}

void Number0(int a, int b, int c){
        pin(a, (b-12), c);
        pin(a, (b-10), c);
        pin(a, (b-8), c);
        pin(a, (b-6), c);
        pin(a, (b-4), c);
        pin(a, (b-2), c);

        pin((a+2), (b-14), c);
        pin((a+2), (b-12), c);
        pin((a+2), (b-10), c);
        pin((a+2), (b-8), c);
        pin((a+2), (b-6), c);
        pin((a+2), (b-4), c);
        pin((a+2), (b-2), c);
        pin((a+2), b, c);

        pin((a+4), (b-14), c);
        pin((a+4), (b-12), c);
        pin((a+4), (b-2), c);
        pin((a+4), b, c);

        pin((a+6), (b-14), c);
        pin((a+6), (b-12), c);
        pin((a+6), (b-2), c);
        pin((a+6), b, c);

        pin((a+8), (b-14), c);
        pin((a+8), (b-12), c);
        pin((a+8), (b-10), c);
        pin((a+8), (b-8), c);
        pin((a+8), (b-6), c);
        pin((a+8), (b-4), c);
        pin((a+8), (b-2), c);
        pin((a+8), b, c);

        pin((a+10), (b-12), c);
        pin((a+10), (b-10), c);
        pin((a+10), (b-8), c);
        pin((a+10), (b-6), c);
        pin((a+10), (b-4), c);
        pin((a+10), (b-2), c);
}

void Number1(int a, int b, int c){
        pin(a, (b-14), c);
        pin(a, (b-12), c);

        pin((a+2), (b-14), c);
        pin((a+2), (b-12), c);
        pin((a+2), (b-10), c);
        pin((a+2), (b-8), c);
        pin((a+2), (b-6), c);
        pin((a+2), (b-4), c);
        pin((a+2), (b-2), c);
        pin((a+2), b, c);

        pin((a+4), (b-14), c);
        pin((a+4), (b-12), c);
        pin((a+4), (b-10), c);
        pin((a+4), (b-8), c);
        pin((a+4), (b-6), c);
        pin((a+4), (b-4), c);
        pin((a+4), (b-2), c);
        pin((a+4), b, c);

}

void Number2(int a, int b, int c){
        pin(a, (b-14), c);
        pin(a, (b-12), c);
        pin(a, (b-8), c);
        pin(a, (b-6), c);
        pin(a, (b-4), c);
        pin(a, (b-2), c);
        pin(a, b, c);

        pin((a+2), (b-14), c);
        pin((a+2), (b-12), c);
        pin((a+2), (b-8), c);
        pin((a+2), (b-6), c);
        pin((a+2), (b-4), c);
        pin((a+2), (b-2), c);
        pin((a+2), b, c);

        pin((a+4), (b-14), c);
        pin((a+4), (b-12), c);
        pin((a+4), (b-8), c);
        pin((a+4), (b-6), c);
        pin((a+4), (b-2), c);
        pin((a+4), b, c);

        pin((a+6), (b-14), c);
        pin((a+6), (b-12), c);
        pin((a+6), (b-8), c);
        pin((a+6), (b-6), c);
        pin((a+6), (b-2), c);
        pin((a+6), b, c);

        pin((a+8), (b-14), c);
        pin((a+8), (b-12), c);
        pin((a+8), (b-8), c);
        pin((a+8), (b-6), c);
        pin((a+8), (b-2), c);
        pin((a+8), b, c);

        pin((a+10), (b-14), c);
        pin((a+10), (b-12), c);
        pin((a+10), (b-10), c);
        pin((a+10), (b-8), c);
        pin((a+10), (b-6), c);
        pin((a+10), (b-2), c);
        pin((a+10), b, c);

        pin((a+12), (b-14), c);
        pin((a+12), (b-12), c);
        pin((a+12), (b-10), c);
        pin((a+12), (b-8), c);
        pin((a+12), (b-6), c);
        pin((a+12), (b-2), c);
        pin((a+12), b, c);
}

void Number3(int a, int b, int c){
        pin(a, (b-14), c);
        pin(a, (b-12), c);
        pin(a, (b-8), c);
        pin(a, (b-6), c);
        pin(a, (b-2), c);
        pin(a, b, c);

        pin((a+2), (b-14), c);
        pin((a+2), (b-12), c);
        pin((a+2), (b-8), c);
        pin((a+2), (b-6), c);
        pin((a+2), (b-2), c);
        pin((a+2), b, c);

        pin((a+4), (b-14), c);
        pin((a+4), (b-12), c);
        pin((a+4), (b-8), c);
        pin((a+4), (b-6), c);
        pin((a+4), (b-2), c);
        pin((a+4), b, c);

        pin((a+6), (b-14), c);
        pin((a+6), (b-12), c);
        pin((a+6), (b-8), c);
        pin((a+6), (b-6), c);
        pin((a+6), (b-2), c);
        pin((a+6), b, c);

        pin((a+8), (b-14), c);
        pin((a+8), (b-12), c);
        pin((a+8), (b-10), c);
        pin((a+8), (b-8), c);
        pin((a+8), (b-6), c);
        pin((a+8), (b-4), c);
        pin((a+8), (b-2), c);
        pin((a+8), b, c);

        pin((a+10), (b-14), c);
        pin((a+10), (b-12), c);
        pin((a+10), (b-10), c);
        pin((a+10), (b-8), c);
        pin((a+10), (b-6), c);
        pin((a+10), (b-4), c);
        pin((a+10), (b-2), c);
        pin((a+10), b, c);
}

void Number4(int a, int b, int c){
        pin(a, (b-14), c);
        pin(a, (b-12), c);
        pin(a, (b-10), c);
        pin(a, (b-8), c);
        pin(a, (b-6), c);

        pin((a+2), (b-14), c);
        pin((a+2), (b-12), c);
        pin((a+2), (b-10), c);
        pin((a+2), (b-8), c);
        pin((a+2), (b-6), c);

        pin((a+4), (b-8), c);
        pin((a+4), (b-6), c);

        pin((a+6), (b-8), c);
        pin((a+6), (b-6), c);

        pin((a+8), (b-14), c);
        pin((a+8), (b-12), c);
        pin((a+8), (b-10), c);
        pin((a+8), (b-8), c);
        pin((a+8), (b-6), c);
        pin((a+8), (b-4), c);
        pin((a+8), (b-2), c);
        pin((a+8), b, c);

        pin((a+10), (b-14), c);
        pin((a+10), (b-12), c);
        pin((a+10), (b-10), c);
        pin((a+10), (b-8), c);
        pin((a+10), (b-6), c);
        pin((a+10), (b-2), c);
        pin((a+10), (b-2), c);
        pin((a+10), b, c);

}

void Number5(int a, int b, int c){
        pin(a, (b-14), c);
        pin(a, (b-12), c);
        pin(a, (b-10), c);
        pin(a, (b-8), c);
        pin(a, (b-6), c);
        pin(a, (b-2), c);
        pin(a, b, c);

        pin((a+2), (b-14), c);
        pin((a+2), (b-12), c);
        pin((a+2), (b-10), c);
        pin((a+2), (b-8), c);
        pin((a+2), (b-6), c);
        pin((a+2), (b-2), c);
        pin((a+2), b, c);

        pin((a+4), (b-14), c);
        pin((a+4), (b-12), c);
        pin((a+4), (b-8), c);
        pin((a+4), (b-6), c);
        pin((a+4), (b-2), c);
        pin((a+4), b, c);

        pin((a+6), (b-14), c);
        pin((a+6), (b-12), c);
        pin((a+6), (b-8), c);
        pin((a+6), (b-6), c);
        pin((a+6), (b-2), c);
        pin((a+6), b, c);

        pin((a+8), (b-14), c);
        pin((a+8), (b-12), c);
        pin((a+8), (b-8), c);
        pin((a+8), (b-6), c);
        pin((a+8), (b-2), c);
        pin((a+8), b, c);

        pin((a+10), (b-14), c);
        pin((a+10), (b-12), c);

        pin((a+10), (b-8), c);
        pin((a+10), (b-6), c);
        pin((a+10), (b-4), c);
        pin((a+10), (b-2), c);
        pin((a+10), b, c);

        pin((a+12), (b-14), c);
        pin((a+12), (b-12), c);
        pin((a+12), (b-8), c);
        pin((a+12), (b-6), c);
        pin((a+12), (b-4), c);
        pin((a+12), (b-2), c);
        pin((a+12), b, c);
}

void Number6(int a, int b, int c){
        pin(a, (b-14), c);
        pin(a, (b-12), c);
        pin(a, (b-10), c);
        pin(a, (b-8), c);
        pin(a, (b-6), c);
        pin(a, (b-4), c);
        pin(a, (b-2), c);
        pin(a, b, c);

        pin((a+2), (b-14), c);
        pin((a+2), (b-12), c);
        pin((a+2), (b-10), c);
        pin((a+2), (b-8), c);
        pin((a+2), (b-6), c);
        pin((a+2), (b-4), c);
        pin((a+2), (b-2), c);
        pin((a+2), b, c);

        pin((a+4), (b-14), c);
        pin((a+4), (b-12), c);
        pin((a+4), (b-8), c);
        pin((a+4), (b-6), c);
        pin((a+4), (b-2), c);
        pin((a+4), b, c);

        pin((a+6), (b-14), c);
        pin((a+6), (b-12), c);
        pin((a+6), (b-8), c);
        pin((a+6), (b-6), c);
        pin((a+6), (b-2), c);
        pin((a+6), b, c);

        pin((a+8), (b-14), c);
        pin((a+8), (b-12), c);
        pin((a+8), (b-8), c);
        pin((a+8), (b-6), c);
        pin((a+8), (b-4), c);
        pin((a+8), (b-2), c);
        pin((a+8), b, c);

        pin((a+10), (b-14), c);
        pin((a+10), (b-12), c);
        pin((a+10), (b-8), c);
        pin((a+10), (b-6), c);
        pin((a+10), (b-4), c);
        pin((a+10), (b-2), c);
        pin((a+10), b, c);

}

void Number7(int a, int b, int c){
        pin(a, (b-14), c);
        pin(a, (b-12), c);

        pin((a+2), (b-14), c);
        pin((a+2), (b-12), c);

        pin((a+4), (b-14), c);
        pin((a+4), (b-12), c);

        pin((a+6), (b-14), c);
        pin((a+6), (b-12), c);

        pin((a+8), (b-14), c);
        pin((a+8), (b-12), c);
        pin((a+8), (b-10), c);
        pin((a+8), (b-8), c);
        pin((a+8), (b-6), c);
        pin((a+8), (b-4), c);
        pin((a+8), (b-2), c);
        pin((a+8), b, c);

        pin((a+10), (b-14), c);
        pin((a+10), (b-12), c);
        pin((a+10), (b-10), c);
        pin((a+10), (b-8), c);
        pin((a+10), (b-6), c);
        pin((a+10), (b-4), c);
        pin((a+10), (b-2), c);
        pin((a+10), b, c);
}

void Number8(int a, int b, int c){
        pin(a, (b-14), c);
        pin(a, (b-12), c);
        pin(a, (b-10), c);
        pin(a, (b-8), c);
        pin(a, (b-6), c);
        pin(a, (b-4), c);
        pin(a, (b-2), c);
        pin(a, b, c);

        pin((a+2), (b-14), c);
        pin((a+2), (b-12), c);
        pin((a+2), (b-10), c);
        pin((a+2), (b-8), c);
        pin((a+2), (b-6), c);
        pin((a+2), (b-4), c);
        pin((a+2), (b-2), c);
        pin((a+2), b, c);

        pin((a+4), (b-14), c);
        pin((a+4), (b-12), c);
        pin((a+4), (b-8), c);
        pin((a+4), (b-6), c);
        pin((a+4), (b-2), c);
        pin((a+4), b, c);

        pin((a+6), (b-14), c);
        pin((a+6), (b-12), c);
        pin((a+6), (b-8), c);
        pin((a+6), (b-6), c);
        pin((a+6), (b-2), c);
        pin((a+6), b, c);

        pin((a+8), (b-14), c);
        pin((a+8), (b-12), c);
        pin((a+8), (b-10), c);
        pin((a+8), (b-8), c);
        pin((a+8), (b-6), c);
        pin((a+8), (b-4), c);
        pin((a+8), (b-2), c);
        pin((a+8), b, c);

        pin((a+10), (b-14), c);
        pin((a+10), (b-12), c);
        pin((a+10), (b-10), c);
        pin((a+10), (b-8), c);
        pin((a+10), (b-6), c);
        pin((a+10), (b-4), c);
        pin((a+10), (b-2), c);
        pin((a+10), b, c);
}

void Number9(int a, int b, int c){
        pin(a, (b-14), c);
        pin(a, (b-12), c);
        pin(a, (b-10), c);
        pin(a, (b-8), c);
        pin(a, (b-6), c);

        pin((a+2), (b-14), c);
        pin((a+2), (b-12), c);
        pin((a+2), (b-10), c);
        pin((a+2), (b-8), c);
        pin((a+2), (b-6), c);

        pin((a+4), (b-14), c);
        pin((a+4), (b-12), c);
        pin((a+4), (b-8), c);
        pin((a+4), (b-6), c);

        pin((a+6), (b-14), c);
        pin((a+6), (b-12), c);
        pin((a+6), (b-8), c);
        pin((a+6), (b-6), c);

        pin((a+8), (b-14), c);
        pin((a+8), (b-12), c);
        pin((a+8), (b-10), c);
        pin((a+8), (b-8), c);
        pin((a+8), (b-6), c);
        pin((a+8), (b-4), c);
        pin((a+8), (b-2), c);
        pin((a+8), b, c);

        pin((a+10), (b-14), c);
        pin((a+10), (b-12), c);
        pin((a+10), (b-10), c);
        pin((a+10), (b-8), c);
        pin((a+10), (b-6), c);
        pin((a+10), (b-4), c);
        pin((a+10), (b-2), c);
        pin((a+10), b, c);
}

/////music things!

void NoteA1(int time){ //440Hz
    int i;
    while(1){
        for (i=time; i>0; i--){
            DACR = (400<<6);
            wait_ticks(454);//wait_ticks will count down
            DACR = 0;
            wait_ticks(454);//wait_ticks will count down
        }
    return 0;
    }
}

void NoteB(int time){ //494Hz
    int i;
    while(1){
        for (i=time; i>0; i--){
            DACR = (400<<6);
            wait_ticks(404);//wait_ticks will count down
            DACR = 0;
            wait_ticks(404);//wait_ticks will count down
        }
    return 0;
    }
}

void NoteC(int time){ //520Hz
    int i;
    while(1){
        for (i=time; i>0; i--){
            DACR = (400<<6);
            wait_ticks(381);//wait_ticks will count down
            DACR = 0;
            wait_ticks(381);//wait_ticks will count down
        }
    return 0;
    }
}

void NoteD(int time){ //587Hz
    int i;
    while(1){
        for (i=time; i>0; i--){
            DACR = (400<<6);
            wait_ticks(339);//wait_ticks will count down
            DACR = 0;
            wait_ticks(339);//wait_ticks will count down
        }
    return 0;
    }
}

void NoteE(int time){ //659Hz
    int i;
    while(1){
        for (i=time; i>0; i--){
            DACR = (400<<6);
            wait_ticks(301);//wait_ticks will count down
            DACR = 0;
            wait_ticks(301);//wait_ticks will count down
        }
    return 0;
    }
}

void NoteF(int time){ //699Hz
    int i;
    while(1){
        for (i=time; i>0; i--){
            DACR = (400<<6);
            wait_ticks(284);//wait_ticks will count down
            DACR = 0;
            wait_ticks(284);//wait_ticks will count down
        }
    return 0;
    }
}

void NoteG(int time){ //784Hz
    int i;
    while(1){
        for (i=time; i>0; i--){
            DACR = (400<<6);
            wait_ticks(252);//wait_ticks will count down
            DACR = 0;
            wait_ticks(252);//wait_ticks will count down
        }
    return 0;
    }
}

void NoteA2(int time){ //880Hz
    int i;
    while(1){
        for (i=time; i>0; i--){
            DACR = (400<<6);
            wait_ticks(225);//wait_ticks will count down
            DACR = 0;
            wait_ticks(225);//wait_ticks will count down
        }
    return 0;
    }
}

void music(){

    PINSEL1 |= (1<<21);//using PINSEL to select AOUT function
    PINSEL1 &= ~(1<<20);//using PINSEL to select AOUT function

    int eight = 300;
    int quart = 600;
    int quartAndEight = 900;
    int half = 1200;
    int rest = 17000;

    while(1){

    NoteE(quart);//measure 1
    NoteB(eight);
    NoteC(eight);
    NoteD(quart);
    NoteC(eight);
    NoteB(eight);
    NoteA1(quart);//measure 2
    wait_ticks (rest);
    NoteA1(eight);
    NoteC(eight);
    NoteE(quart);
    NoteD(eight);
    NoteC(eight);
    NoteB(quart);//measure 3
    wait_ticks (rest);
    NoteB(eight);
    NoteC(eight);
    NoteD(quart);
    NoteE(quart);
    NoteC(quart); //measure 4
    NoteA1(quart);
    wait_ticks (rest);
    NoteA1(half);
    NoteD(quartAndEight);//measure 5
    NoteF(eight);
    NoteA2(quart);
    NoteG(eight);
    NoteF(eight);
    NoteE(quartAndEight);//measure 6
    NoteC(eight);
    NoteE(quart);
    NoteD(eight);
    NoteC(eight);
    NoteB(quart);//measure 7
    wait_ticks (rest);
    NoteB(eight);
    NoteC(eight);
    NoteD(quart);
    NoteE(quart);
    NoteC(quart); // measure 8
    NoteA1(quart);
    wait_ticks (rest);
    NoteA1(half);
    }
}

//initialize keypad and keypad functions

void KeyboardInit(){

    FIO2DIR &= ~(1<<4); //button pins set as inputs
    FIO2DIR &= ~(1<<5);
    FIO2DIR &= ~(1<<6);
    FIO2DIR &= ~(1<<7);

}

void SelectRow(int row){

    FIO2PIN |= (0b1111<<0);
    FIO2PIN &= ~(1<<row);
    FIO2DIR &= ~(0b1111<<0);
    FIO2DIR |= (1<<row);

}

int ReadColumn(void){
    int col;
    for(col=0; col<4; col++){
            if(((FIO2PIN>>(4+col))&1)==0){
                return col;
            }
    }
    return -1;
}

char ReadKeypad(void){

    int row, col;
    for (row =0; row<4; row++){
        SelectRow(row);
        wait_ticks(300);
        col = ReadColumn();

        if(col>=0){
            return KeyPad[((row*4)+col)];
        }
    }
    return 0;
}

////Block runs

void OblockRun (){
    int j = 5;
    int i;

    for (i=2; i<20; i++){

        int x = ReadKeypad();
            if (x==56){
                    if (OblockDetectBelow(i, j)==0){
                        i++;
                        if (i>19){i=19;}
                        }
                    }
            if (x==52){
                if (OblockDetectLeft(i, j)==0){
                    j--;
                    }
                }

            if (x==54){
                if (OblockDetectRight(i, j)==0){
                    j++;
                    }
                }

            Oblock(PlayFieldCol[j], PlayFieldRow[i]);

            if (OblockDetectBelow(i,j)==1){
                OblockSave(i,j);
                i=-1;
                break;
                }

            if (i==19){
                OblockSave(i,j);
                    }

            wait_ticks(300000);

            if ((i>0)&&(i<19)){
                OblockErase(PlayFieldCol[j], PlayFieldRow[i]);
            }

        }
}

void IblockRun (){
    int j = 5;
    int c = 0;
    int i;

    for (i=2; i<20; i++){

        int x = ReadKeypad();
            if (x==56){
                if (IblockDetectBelow(i, j, c)==0){
                    i++;
                    if (i>19){i=19;}
                    }
                }

            if (x==52){
                if (IblockDetectLeft(i, j, c)==0){
                    j--;
                    }
                }

            if (x==54){
                if (IblockDetectRight(i, j, c)==0){
                    j++;
                    }
                }

            if (x==53){
                if (IblockDetectSpin(i, j, c)==0){
                    c++;
                    }
                }

            Iblock(PlayFieldCol[j], PlayFieldRow[i], c);

            if (IblockDetectBelow(i,j,c)==1){
                IblockSave(i,j,c);
                i=-1;
                break;
                }

            if (i==19){
                IblockSave(i,j,c);
                    }

            wait_ticks(300000);

            if ((i>0)&&(i<19)){
                IblockErase(PlayFieldCol[j], PlayFieldRow[i], c);
            }

        }
}

void SblockRun (){
    int j = 5;
    int c = 0;
    int i;

    for (i=2; i<20; i++){

        int x = ReadKeypad();
            if (x==56){
                if (SblockDetectBelow(i, j, c)==0){
                    i++;
                    if (i>19){i=19;}
                    }
                }

            if (x==52){
                if (SblockDetectLeft(i, j, c)==0){
                    j--;
                    }
                }

            if (x==54){
                if (SblockDetectRight(i, j, c)==0){
                    j++;
                    }
                }

            if (x==53){
                if (SblockDetectSpin(i, j, c)==0){
                    c++;
                    }
                }

            Sblock(PlayFieldCol[j], PlayFieldRow[i], c);

            if (SblockDetectBelow(i,j,c)==1){
                SblockSave(i,j,c);
                i=-1;
                break;
                }

            if (i==19){
                    SblockSave(i,j,c);
                    }

            wait_ticks(300000);

            if ((i>0)&&(i<19)){
                SblockErase(PlayFieldCol[j], PlayFieldRow[i], c);
            }

        }
}

void ZblockRun (){
    int j = 5;
    int c = 0;
    int i;

    for (i=2; i<20; i++){

        int x = ReadKeypad();
            if (x==56){
                if (ZblockDetectBelow(i, j, c)==0){
                    i++;
                    if (i>19){i=19;}
                    }
                }

            if (x==52){
                if (ZblockDetectLeft(i, j, c)==0){
                    j--;
                    }
                }

            if (x==54){
                if (ZblockDetectRight(i, j, c)==0){
                    j++;
                    }
                }

            if (x==53){
                if (ZblockDetectSpin(i, j, c)==0){
                    c++;
                    }
                }

            Zblock(PlayFieldCol[j], PlayFieldRow[i], c);

            if (ZblockDetectBelow(i,j,c)==1){
                ZblockSave(i,j,c);
                i=-1;
                break;
                }

            if (i==19){
                ZblockSave(i,j,c);
                    }

            wait_ticks(300000);

            if ((i>0)&&(i<19)){
                ZblockErase(PlayFieldCol[j], PlayFieldRow[i], c);
            }

        }
}

void LblockRun (){
    int j = 5;
    int c = 0;
    int i;

    for (i=2; i<20; i++){

        int x = ReadKeypad();
            if (x==56){
                if (LblockDetectBelow(i, j, c)==0){
                    i++;
                    if (i>19){i=19;}
                    }
                }

            if (x==52){
                if (LblockDetectLeft(i, j, c)==0){
                    j--;
                    }
                }

            if (x==54){
                if (LblockDetectRight(i, j, c)==0){
                    j++;
                    }
                }

            if (x==53){
                if (LblockDetectSpin(i, j, c)==0){
                    c++;
                    }
                }

            Lblock(PlayFieldCol[j], PlayFieldRow[i], c);

            if (LblockDetectBelow(i,j,c)==1){
                LblockSave(i,j,c);
                i=-1;
                break;
                }

            if (i==19){
                    LblockSave(i,j,c);
                    }

            wait_ticks(300000);

            if ((i>0)&&(i<19)){
                LblockErase(PlayFieldCol[j], PlayFieldRow[i], c);
            }

        }
}

void JblockRun (){
    int j = 5;
    int c = 0;
    int i;

    for (i=2; i<20; i++){

        int x = ReadKeypad();
            if (x==56){
                if (JblockDetectBelow(i, j, c)==0){
                    i++;
                    if (i>19){i=20;}
                    }
                }

            if (x==52){
                if (JblockDetectLeft(i, j, c)==0){
                    j--;
                    }
                }

            if (x==54){
                if (JblockDetectRight(i, j, c)==0){
                    j++;
                    }
                }

            if (x==53){
                if (JblockDetectSpin(i, j, c)==0){
                    c++;
                    }
                }

            Jblock(PlayFieldCol[j], PlayFieldRow[i], c);

            if (JblockDetectBelow(i,j,c)==1){
                JblockSave(i,j,c);
                i=-1;
                break;
                }

            if (i==19){
                JblockSave(i,j,c);
            }

            wait_ticks(300000);

            if ((i>0)&&(i<19)){
                JblockErase(PlayFieldCol[j], PlayFieldRow[i], c);
            }

        }
}

void TblockRun (){
    int j = 5;
    int c = 0;
    int i;

    for (i=2; i<20; i++){

        int x = ReadKeypad();
            if (x==56){
                if (TblockDetectBelow(i, j,c)==0){
                    i++;
                    if (i>19){i=20;}
                    }
                }

            if (x==52){
                if (TblockDetectLeft(i, j, c)==0){
                    j--;
                    }
                }

            if (x==54){
                if (TblockDetectRight(i, j, c)==0){
                    j++;
                    }
                }

            if (x==53){
                if (TblockDetectSpin(i, j, c)==0){
                    c++;
                    }
                }

            Tblock(PlayFieldCol[j], PlayFieldRow[i], c);

            if (TblockDetectBelow(i,j,c)==1){
                TblockSave(i,j,c);
                i=-1;
                break;
                }

            if (i==19){
                TblockSave(i,j,c);
                    }

            wait_ticks(300000);

            if ((i>0)&&(i<19)){
                TblockErase(PlayFieldCol[j], PlayFieldRow[i], c);
            }

        }
}

///Game score and status update needs

int DetectLine (void){
    if ((!(PlayFieldStat[19][0]==0))&&(!(PlayFieldStat[19][1]==0))&&(!(PlayFieldStat[19][2]==0))&&(!(PlayFieldStat[19][3]==0))&&(!(PlayFieldStat[19][4]==0))&&(!(PlayFieldStat[19][5]==0))&&(!(PlayFieldStat[19][6]==0))&&(!(PlayFieldStat[19][7]==0))&&(!(PlayFieldStat[19][8]==0))&&(!(PlayFieldStat[19][9]==0))){
        return 19;
        }
    if ((!(PlayFieldStat[18][0]==0))&&(!(PlayFieldStat[18][1]==0))&&(!(PlayFieldStat[18][2]==0))&&(!(PlayFieldStat[18][3]==0))&&(!(PlayFieldStat[18][4]==0))&&(!(PlayFieldStat[18][5]==0))&&(!(PlayFieldStat[18][6]==0))&&(!(PlayFieldStat[18][7]==0))&&(!(PlayFieldStat[18][8]==0))&&(!(PlayFieldStat[18][9]==0))){
        return 18;
        }
    if ((!(PlayFieldStat[17][0]==0))&&(!(PlayFieldStat[17][1]==0))&&(!(PlayFieldStat[17][2]==0))&&(!(PlayFieldStat[17][3]==0))&&(!(PlayFieldStat[17][4]==0))&&(!(PlayFieldStat[17][5]==0))&&(!(PlayFieldStat[17][6]==0))&&(!(PlayFieldStat[17][7]==0))&&(!(PlayFieldStat[17][8]==0))&&(!(PlayFieldStat[17][9]==0))){
        return 17;
        }
    if ((!(PlayFieldStat[16][0]==0))&&(!(PlayFieldStat[16][1]==0))&&(!(PlayFieldStat[16][2]==0))&&(!(PlayFieldStat[16][3]==0))&&(!(PlayFieldStat[16][4]==0))&&(!(PlayFieldStat[16][5]==0))&&(!(PlayFieldStat[16][6]==0))&&(!(PlayFieldStat[16][7]==0))&&(!(PlayFieldStat[16][8]==0))&&(!(PlayFieldStat[16][9]==0))){
        return 16;
        }
    if ((!(PlayFieldStat[15][0]==0))&&(!(PlayFieldStat[15][1]==0))&&(!(PlayFieldStat[15][2]==0))&&(!(PlayFieldStat[15][3]==0))&&(!(PlayFieldStat[15][4]==0))&&(!(PlayFieldStat[15][5]==0))&&(!(PlayFieldStat[15][6]==0))&&(!(PlayFieldStat[15][7]==0))&&(!(PlayFieldStat[15][8]==0))&&(!(PlayFieldStat[15][9]==0))){
        return 15;
        }
    if ((!(PlayFieldStat[14][0]==0))&&(!(PlayFieldStat[14][1]==0))&&(!(PlayFieldStat[14][2]==0))&&(!(PlayFieldStat[14][3]==0))&&(!(PlayFieldStat[14][4]==0))&&(!(PlayFieldStat[14][5]==0))&&(!(PlayFieldStat[14][6]==0))&&(!(PlayFieldStat[14][7]==0))&&(!(PlayFieldStat[14][8]==0))&&(!(PlayFieldStat[14][9]==0))){
        return 14;
        }
    if ((!(PlayFieldStat[13][0]==0))&&(!(PlayFieldStat[13][1]==0))&&(!(PlayFieldStat[13][2]==0))&&(!(PlayFieldStat[13][3]==0))&&(!(PlayFieldStat[13][4]==0))&&(!(PlayFieldStat[13][5]==0))&&(!(PlayFieldStat[13][6]==0))&&(!(PlayFieldStat[13][7]==0))&&(!(PlayFieldStat[13][8]==0))&&(!(PlayFieldStat[13][9]==0))){
        return 13;
        }
    if ((!(PlayFieldStat[12][0]==0))&&(!(PlayFieldStat[12][1]==0))&&(!(PlayFieldStat[12][2]==0))&&(!(PlayFieldStat[12][3]==0))&&(!(PlayFieldStat[12][4]==0))&&(!(PlayFieldStat[12][5]==0))&&(!(PlayFieldStat[12][6]==0))&&(!(PlayFieldStat[12][7]==0))&&(!(PlayFieldStat[12][8]==0))&&(!(PlayFieldStat[12][9]==0))){
        return 12;
        }
    if ((!(PlayFieldStat[11][0]==0))&&(!(PlayFieldStat[11][1]==0))&&(!(PlayFieldStat[11][2]==0))&&(!(PlayFieldStat[11][3]==0))&&(!(PlayFieldStat[11][4]==0))&&(!(PlayFieldStat[11][5]==0))&&(!(PlayFieldStat[11][6]==0))&&(!(PlayFieldStat[11][7]==0))&&(!(PlayFieldStat[11][8]==0))&&(!(PlayFieldStat[11][9]==0))){
        return 11;
        }
    if ((!(PlayFieldStat[10][0]==0))&&(!(PlayFieldStat[10][1]==0))&&(!(PlayFieldStat[10][2]==0))&&(!(PlayFieldStat[10][3]==0))&&(!(PlayFieldStat[10][4]==0))&&(!(PlayFieldStat[10][5]==0))&&(!(PlayFieldStat[10][6]==0))&&(!(PlayFieldStat[10][7]==0))&&(!(PlayFieldStat[10][8]==0))&&(!(PlayFieldStat[10][9]==0))){
        return 10;
        }
    if ((!(PlayFieldStat[9][0]==0))&&(!(PlayFieldStat[9][1]==0))&&(!(PlayFieldStat[9][2]==0))&&(!(PlayFieldStat[9][3]==0))&&(!(PlayFieldStat[9][4]==0))&&(!(PlayFieldStat[9][5]==0))&&(!(PlayFieldStat[9][6]==0))&&(!(PlayFieldStat[9][7]==0))&&(!(PlayFieldStat[9][8]==0))&&(!(PlayFieldStat[9][9]==0))){
        return 9;
        }
    if ((!(PlayFieldStat[8][0]==0))&&(!(PlayFieldStat[8][1]==0))&&(!(PlayFieldStat[8][2]==0))&&(!(PlayFieldStat[8][3]==0))&&(!(PlayFieldStat[8][4]==0))&&(!(PlayFieldStat[8][5]==0))&&(!(PlayFieldStat[8][6]==0))&&(!(PlayFieldStat[8][7]==0))&&(!(PlayFieldStat[8][8]==0))&&(!(PlayFieldStat[8][9]==0))){
        return 8;
        }
    if ((!(PlayFieldStat[7][0]==0))&&(!(PlayFieldStat[7][1]==0))&&(!(PlayFieldStat[7][2]==0))&&(!(PlayFieldStat[7][3]==0))&&(!(PlayFieldStat[7][4]==0))&&(!(PlayFieldStat[7][5]==0))&&(!(PlayFieldStat[7][6]==0))&&(!(PlayFieldStat[7][7]==0))&&(!(PlayFieldStat[7][8]==0))&&(!(PlayFieldStat[7][9]==0))){
        return 7;
        }
    if ((!(PlayFieldStat[6][0]==0))&&(!(PlayFieldStat[6][1]==0))&&(!(PlayFieldStat[6][2]==0))&&(!(PlayFieldStat[6][3]==0))&&(!(PlayFieldStat[6][4]==0))&&(!(PlayFieldStat[6][5]==0))&&(!(PlayFieldStat[6][6]==0))&&(!(PlayFieldStat[6][7]==0))&&(!(PlayFieldStat[6][8]==0))&&(!(PlayFieldStat[6][9]==0))){
        return 6;
        }
    if ((!(PlayFieldStat[5][0]==0))&&(!(PlayFieldStat[5][1]==0))&&(!(PlayFieldStat[5][2]==0))&&(!(PlayFieldStat[5][3]==0))&&(!(PlayFieldStat[5][4]==0))&&(!(PlayFieldStat[5][5]==0))&&(!(PlayFieldStat[5][6]==0))&&(!(PlayFieldStat[5][7]==0))&&(!(PlayFieldStat[5][8]==0))&&(!(PlayFieldStat[5][9]==0))){
        return 5;
        }
    if ((!(PlayFieldStat[4][0]==0))&&(!(PlayFieldStat[4][1]==0))&&(!(PlayFieldStat[4][2]==0))&&(!(PlayFieldStat[4][3]==0))&&(!(PlayFieldStat[4][4]==0))&&(!(PlayFieldStat[4][5]==0))&&(!(PlayFieldStat[4][6]==0))&&(!(PlayFieldStat[4][7]==0))&&(!(PlayFieldStat[4][8]==0))&&(!(PlayFieldStat[4][9]==0))){
        return 4;
        }
    if ((!(PlayFieldStat[3][0]==0))&&(!(PlayFieldStat[3][1]==0))&&(!(PlayFieldStat[3][2]==0))&&(!(PlayFieldStat[3][3]==0))&&(!(PlayFieldStat[3][4]==0))&&(!(PlayFieldStat[3][5]==0))&&(!(PlayFieldStat[3][6]==0))&&(!(PlayFieldStat[3][7]==0))&&(!(PlayFieldStat[3][8]==0))&&(!(PlayFieldStat[3][9]==0))){
        return 3;
        }
    if ((!(PlayFieldStat[2][0]==0))&&(!(PlayFieldStat[2][1]==0))&&(!(PlayFieldStat[2][2]==0))&&(!(PlayFieldStat[2][3]==0))&&(!(PlayFieldStat[2][4]==0))&&(!(PlayFieldStat[2][5]==0))&&(!(PlayFieldStat[2][6]==0))&&(!(PlayFieldStat[2][7]==0))&&(!(PlayFieldStat[2][8]==0))&&(!(PlayFieldStat[2][9]==0))){
        return 2;
        }
    if ((!(PlayFieldStat[1][0]==0))&&(!(PlayFieldStat[1][1]==0))&&(!(PlayFieldStat[1][2]==0))&&(!(PlayFieldStat[1][3]==0))&&(!(PlayFieldStat[1][4]==0))&&(!(PlayFieldStat[1][5]==0))&&(!(PlayFieldStat[1][6]==0))&&(!(PlayFieldStat[1][7]==0))&&(!(PlayFieldStat[1][8]==0))&&(!(PlayFieldStat[1][9]==0))){
        return 1;
        }
    else {
        return 0;
    }
}

int DetectLose (void){
    if ((!(PlayFieldStat[0][0]==0))||(!(PlayFieldStat[0][1]==0))||(!(PlayFieldStat[0][2]==0))||(!(PlayFieldStat[0][3]==0))||(!(PlayFieldStat[0][4]==0))||(!(PlayFieldStat[0][5]==0))||(!(PlayFieldStat[0][6]==0))||(!(PlayFieldStat[0][7]==0))||(!(PlayFieldStat[0][8]==0))||(!(PlayFieldStat[0][9]==0))){
        return 1;
        }
    else {
        return 0;
        }
}

void EraseLine (int b){
    int i;
    for (i=0; i<10; i++){
    Erase(PlayFieldCol[i],PlayFieldRow[b]);
    }
}

void DeleteLine (int i){
    int j;
    for (j=0; j<10; j++){
    PlayFieldStat[i][j]=0;
    }
}

void UpdateScreen(int r){
    int i;
    int j;
    int k;

        for (i=r; i>1; i--){
            for(j=0; j<10; j++){
                if (!(PlayFieldStat[i-1][j]==0)){
                Block(PlayFieldCol[j], PlayFieldRow[i], PlayFieldStat[i-1][j]);

                }

            else{
                Erase(PlayFieldCol[j], PlayFieldRow[i]);
                }

            PlayFieldStat[i][j]=PlayFieldStat[i-1][j];
            }

        for(k=0; k<10 ; k++){
            Erase(PlayFieldCol[j], PlayFieldRow[0]);
            }
        }
}

void DetectDelete(){
    int l = DetectLine();
        if (l>0){
            DeleteLine(l);
            EraseLine(l);
            UpdateScreen(l);
            Score++;
        int m = DetectLine();
            if (m>0){
                DeleteLine(m);
                EraseLine(m);
                UpdateScreen(m);
                Score=Score+2;
            int n = DetectLine();
                if (n>0){
                    DeleteLine(n);
                    EraseLine(n);
                    UpdateScreen(n);
                    Score=Score+2;
                int o = DetectLine();
                    if (o>0){
                        DeleteLine(o);
                        EraseLine(o);
                        UpdateScreen(o);
                        Score=Score+6;
                        }
                    }
                }
        }
}

//Game!

int main (void){
    clocks();
    SPIInit();
    LCDinit();
    KeyboardInit();

// ColorTest();
    Welcome();
    PlayField();

    int blk=0;
    int i;
    for (i=0;i<100;i++){
        blk = rand()%7;
        if (blk==0){
            OblockRun();
            DetectDelete();
                if(DetectLose()==1){
                    GameOver(Score);
                    break;
                    }
            }
        if (blk==1){
                IblockRun();
                DetectDelete();
                    if(DetectLose()==1){
                        GameOver(Score);
                        break;
                        }
                }
        if (blk==2){
                SblockRun();
                DetectDelete();
                    if(DetectLose()==1){
                        GameOver(Score);
                        break;
                        }
                }
        if (blk==3){
                    ZblockRun();
                    DetectDelete();
                        if(DetectLose()==1){
                            GameOver(Score);
                            break;
                            }
        		}
        if (blk==4){
                    LblockRun();
                    DetectDelete();
                        if(DetectLose()==1){
                            GameOver(Score);
                            break;
                            }
                    }
        if (blk==5){
                    JblockRun();
                    DetectDelete();
                        if(DetectLose()==1){
                            GameOver(Score);
                            break;
                            }
                    }
        if (blk==6){
                    TblockRun();
                    DetectDelete();
                        if(DetectLose()==1){
                            GameOver(Score);
                            break;
                            }
                    }
            }
    }

/*
===============================================================================
 Name        : OptimallyPackedFallingShapes.c
 Author      : $YoToTheko
 Version     : 4May19
 Description : ForCrazyByCrazy
===============================================================================
*/
#include <stdlib.h>;

#define PCONP (*(volatile unsigned int*)0x400FC0C4) //POWERS!
#define PCLKSEL0 (*(volatile unsigned int*)0x400FC1A8) //CLOCKS!

#define PLL0CON (*(volatile unsigned int*)0x400FC080) // control register || bit 0 enabled when 1
#define PLL0CFG (*(volatile unsigned int*)0x400FC084) // configure the register
#define PLL0FEED (*(volatile unsigned int*)0x400FC08C) // Feed register (write only)
#define PLL0STAT (*(volatile unsigned int*)0x400FC088) // Status of PLL register (read only)
#define CLKSRCEL (*(volatile unsigned int*)0x400FC10C) // clock select register
#define CLKOUTCFG (*(volatile unsigned int*)0x400FC1C8) // clock out to a pin
#define CCLKCFG (*(volatile unsigned int*)0x400FC104) // configuration register to send the clock to a pin

#define S0SPCR (*(volatile unsigned int*)0x40020000) //SPI control register
#define S0SPSR (*(volatile unsigned int*)0x40020004) //SPI status register
#define S0SPDR (*(volatile unsigned int*)0x40020008) //SPI data register
#define S0SPCCR (*(volatile unsigned int*)0x4002000C) //SPI clock counter register

#define DACR (*(volatile unsigned int*)0x4008C000) //Digital to analog converter register

#define PINSEL0 (*(volatile unsigned int*)0x4002C000)//Pin configuration registers
#define PINSEL1 (*(volatile unsigned int*)0x4002C004)
#define PINSEL3 (*(volatile unsigned int*)0x4002C00C)
#define PINMODE4 (*(volatile unsigned int*)0x4002C050)

#define FIO0DIR (*(volatile unsigned int*)0x2009C000)//ports and bits
#define FIO1DIR (*(volatile unsigned int*)0x2009C020)
#define FIO2DIR (*(volatile unsigned int*)0x2009C040)
#define FIO0PIN (*(volatile unsigned int*)0x2009C014)
#define FIO2PIN (*(volatile unsigned int*)0x2009C054)

void clocks(void){ //Speeding up the clock to make the game faster

    int M = 40;
    int k = 36;
        PINSEL3 |= (1<<22); // this turns our output on || bit 22 set to 1
        CLKOUTCFG = 0x100; //clears any current issues

        //PLL STUFF
        //step 1 & 2
        PLL0CON &= ~(1<<1); //PLL0 disconnect
        PLL0FEED = 0xAA; //feeding the beast
        PLL0FEED = 0x55; ///with feeding sequence

        PLL0CON &= ~(1<<0); //PLL0 disable
        PLL0FEED = 0xAA; //feeding the beast
        PLL0FEED = 0x55; ///with feeding sequence

        //step 3
        //CCLKCFG = 0; //we don't want to change N

        //Step 4: Clock Source Selection register - using default
        CLKSRCEL &= ~(3);

        //Step 5: (m-1 value) write to the PLL0CFG & make it effective with one feed sequence
        PLL0CFG = (M-1); //M = 45 N = 0
        PLL0FEED = 0xAA; //feeding the beast
        PLL0FEED = 0x55; ///with feeding sequence

        //Step 6: Enable PLL0 with one feed sequence.
        PLL0CON |= 1; //PLL0 enable.
        PLL0FEED = 0xAA; //feeding the beast
        PLL0FEED = 0x55; ///with feeding sequence

        //Step 8: Wait for PLL0 to achieve lock by monitoring the PLOCK0 bit in the PLL0STAT register,
        //or using the PLOCK0 interrupt, or wait for a fixed time when the input clock to PLL0 is slow (i.e. 32 kHz).

        while  (((PLL0STAT >> 26) & 1 )==0){} //while PLL bit 26 is set to 0 hold, essentially hold this until a lock is established

        //Step 7: (k-1 value) Change the CPU Clock Divider setting for the operation with PLL0. It is critical to do
        //this before connecting PLL0.

        CCLKCFG = (k-1); // k value this divides by 40 (convert this to hex)

        PLL0CON |= 3; // sets bit one & two after lock is established
        //Step 9: Connect PLL0 with one feed sequence.
        PLL0FEED = 0xAA; //feeding the beast
        PLL0FEED = 0x55; ///with feeding sequence

        }

void LCDreset (void){ //resets the LCD screen
    FIO0PIN &= ~(1<<23);
    FIO0PIN |= (1<<23);
}

void wait_ticks (int count){ // sets up our wait function
       volatile int ticks = count;
       while (ticks > 0)
           ticks--;
}

void LCDwriteReg(int x, int y){ //Uses the micro-controller SPI subsystem to talk to the LCD
    FIO0PIN &= ~(1<<16); //Asserts slave select
    FIO0PIN &= ~(1<<24);
    S0SPDR = x>>8;
        while(((S0SPSR>>7)&1)==0){}
    S0SPDR = x;
        while(((S0SPSR>>7)&1)==0){}
    FIO0PIN |= (1<<24);
    S0SPDR = y>>8;
        while(((S0SPSR>>7)&1)==0){}
    S0SPDR = y;
        while(((S0SPSR>>7)&1)==0){}
    FIO0PIN |= (1<<16); //de-asserts slave select
}

void SPIInit(){ //this processes initializes the SPI settings on the microcontroller
    PCONP |= (1<<8); //This selects the SPI subsystem in the LPC
    PCLKSEL0 |= (1<<16); //This selects the SPI clock for the master's setting I think???
    S0SPCCR = (1<<3);// sending an '8' to the SPI clock counter register which is lowest possible value
    S0SPCR = (1<<5);//initiates our
    FIO0DIR |= (1<<16);  // sets our slave select as an output
    FIO0DIR |= (1<<23);  // Sets our reset pin as an output
    FIO0DIR |= (1<<24);
    PINSEL1 |= (3<<4);  //MOSI as an output
    PINSEL0 |= (3<<30);  //SCK as an output
}

void LCDinit(void){ //initializes the LCD ILI9225B appropriately

  LCDreset();
  LCDwriteReg(0x01, 0x011C); //Driver output control, 220 lines
  LCDwriteReg(0x02, 0x0100); //LCD AC Driving Control, line inversion, 1 field interlace
  LCDwriteReg(0x03, 0x1030); //Entry Mode, BGR mode, left-right, top-bottom
  LCDwriteReg(0x08, 0x0100); //Blank Period Control 1, 8 line front/back porch
  LCDwriteReg(0x0b, 0x1100); //Frame cycle control
  LCDwriteReg(0x0c, 0x0001); //Interface Control, 16bpp
  LCDwriteReg(0x0f, 0x0A01); //Oscillation Control this would select 83 Hz i believe as opposed to the other value, which didnt make sense (0x1401)
  //LCDwriteReg(0x15, 0x0000); //VCI Recycling - CANT FIND THIS REGISTER IN MATERIAL
  LCDwriteReg(0x20, 0x0000); //RAM Address Set 1 (LSB)
  LCDwriteReg(0x21, 0x0000); //RAM Address Set 2 (MSB)

  wait_ticks(6000);

  LCDwriteReg(0x10, 0x0800); //Power Control 1
  LCDwriteReg(0x11, 0x1f3f); //Power Control 2

  wait_ticks(6000);

  LCDwriteReg(0x12, 0x0121); //Power Control 3
  LCDwriteReg(0x13, 0x006f); //Power Control 4
  LCDwriteReg(0x14, 0x4349); //Power Control 5

  LCDwriteReg(0x30, 0x0000); //Gate Scan Control
  LCDwriteReg(0x31, 0x00db); //Vertical Scroll Control 1
  LCDwriteReg(0x32, 0x0000); //Vertical Scroll Control 2
  LCDwriteReg(0x33, 0x0000); //Vertical Scroll Control 3
  LCDwriteReg(0x34, 0x00db); //Partial Driving Position 1
  LCDwriteReg(0x35, 0x0000); //Partial Driving Position 2
  LCDwriteReg(0x36, 0x00AF); //Horizontal Window Address end
  LCDwriteReg(0x37, 0x0000); //Horizontal Window Address start
  LCDwriteReg(0x38, 0x00DB); //Vertical Window Address end
  LCDwriteReg(0x39, 0x0000); //Vertical Window Address start

  LCDwriteReg(0x50, 0x0001); //Gamma Control 1
  LCDwriteReg(0x51, 0x200b); //Gamma Control 2
  LCDwriteReg(0x52, 0x0000); //Gamma Control 3
  LCDwriteReg(0x53, 0x0404); //Gamma Control 4
  LCDwriteReg(0x54, 0x0c0c); //Gamma Control 5
  LCDwriteReg(0x55, 0x000c); //Gamma Control 6
  LCDwriteReg(0x56, 0x0101); //Gamma Control 7
  LCDwriteReg(0x57, 0x0400); //Gamma Control 8
  LCDwriteReg(0x58, 0x1108); //Gamma Control 9
  LCDwriteReg(0x59, 0x050c); //Gamma Control 10

  wait_ticks(6000);

  LCDwriteReg(0x07, 0x1017); //Display Control 1

  LCDwriteReg(0x20, 0x0000); //RAM Address Set 1 (LSB)
  LCDwriteReg(0x21, 0x0000);
  int j;
  for (j=38720; j>0; j--){

  //RAM Address Set 2 (MSB)
  LCDwriteReg(0x22,0xFFFF);

  }
}

/// Array's for rolling 'round with my homies
int BackGroundCol[16] = {0x0000, 0x000A, 0x00015, 0x0020, 0x002B, 0x0036, 0x0041, 0x004C, 0x0057, 0x0062, 0x006D, 0x0078, 0x0083, 0x008E, 0x0099, 0x00A4};
int BackGroundRow[20] = {0x0000, 0x000A, 0x00015, 0x0020, 0x002B, 0x0036, 0x0041, 0x004C, 0x0057, 0x0062, 0x006D, 0x0078, 0x0083, 0x008E, 0x0099, 0x00A4, 0x00AF, 0x00BA, 0x00C5, 0x00D0};
int PlayFieldCol[10] = {0x0026, 0x0030, 0x003A, 0x0044, 0x004E, 0x0058, 0x0062, 0x006c, 0x0076, 0x0080};
int PlayFieldRow[20] = {0x000A, 0x0014, 0x001E, 0x0028, 0x0032, 0x003C, 0x0046, 0x0050, 0x005A, 0x0064, 0x006E, 0x0078, 0x0082, 0x008C, 0x0096, 0x00A0, 0x00AA, 0x00B4, 0x00BE, 0x00C8};
int PlayFieldStat[20][10];

/// colors used in the code

int F = 0xF808; //Fandango;
int P = 0xFBD3; //Pink;
int S = 0xF462; //Scarlet;
int C = 0xFDED; //Coral;
int M = 0xCE00; //Mustard;
int Y = 0xFFCA;  //Yellow;
int G = 0x1DC0; //Green
int K = 0xA7F2; //kelly
int T = 0x0772; //Teal;
int A = 0x9FFC; //Aqua;
int B = 0x03DD; //Blue;
int N = 0x85BE; //Navy;
int L = 0xE41F; //Lavender;
int V = 0xA01A; //Violet

void ColorTest(){ //used this to tweek colors and compare them to each other, isnt actually used in final game

    big(BackGroundCol[0],BackGroundRow[2],F);
    big(BackGroundCol[8],BackGroundRow[2],P);
    big(BackGroundCol[0],BackGroundRow[4],S);
    big(BackGroundCol[8],BackGroundRow[4],C);
    big(BackGroundCol[0],BackGroundRow[6],M);
    big(BackGroundCol[8],BackGroundRow[6],Y);
    big(BackGroundCol[0],BackGroundRow[8],G);
    big(BackGroundCol[8],BackGroundRow[8],K);
    big(BackGroundCol[0],BackGroundRow[10],T);
    big(BackGroundCol[8],BackGroundRow[10],A);
    big(BackGroundCol[0],BackGroundRow[12],B);
    big(BackGroundCol[8],BackGroundRow[12],N);
    big(BackGroundCol[0],BackGroundRow[14],V);
    big(BackGroundCol[8],BackGroundRow[14],L);
}

///building blocks of the program

void big(int x1, int y1, int z){ //creates an 88 x 22 big block of color 'z' for design helps
int x2;
int y2;

x2 = x1+87;
y2= y1+21;

  LCDwriteReg(0x36, x2); //Horizontal Window Address 1
  LCDwriteReg(0x37, x1); //Horizontal Window Address 2
  LCDwriteReg(0x38, y2); //Vertical Window Address 1
  LCDwriteReg(0x39, y1); //Vertical Window Address 2

  wait_ticks(6000);

  LCDwriteReg(0x07, 0x1017); //Display Control 1

  LCDwriteReg(0x20, x2); //RAM Address Set 1 (LSB)
  LCDwriteReg(0x21, y2); //RAM Address Set 2 (MSB)
  int j;
        for (j=1936; j>0; j--){
            LCDwriteReg(0x22,z);
        }

}

void pin(int x1, int y1, int z){ //creates a small 2x2 pixel block of color 'z' for lettering and numbers
int x2;
int y2;

x2 = x1+1;
y2= y1+1;

  LCDwriteReg(0x36, x2); //Horizontal Window Address 1
  LCDwriteReg(0x37, x1); //Horizontal Window Address 2
  LCDwriteReg(0x38, y2); //Vertical Window Address 1
  LCDwriteReg(0x39, y1); //Vertical Window Address 2

  wait_ticks(6000);

  LCDwriteReg(0x07, 0x1017); //Display Control 1

  LCDwriteReg(0x20, x2); //RAM Address Set 1 (LSB)
  LCDwriteReg(0x21, y2); //RAM Address Set 2 (MSB)
  int j;
        for (j=4; j>0; j--){
            LCDwriteReg(0x22,z);
        }

}

void Brick(int x1, int y1, int z1, int z2){ //creates an 11x11 multicolored brick for decorations with colors z1, z2 and white
int x2;
int y2;
int x3;
int y3;
int x4;
int y4;
int x5;
int y5;
int x6;
int y6;

x2 = x1+10;
y2= y1+10;

x3 = x1+2;
y3 = y1+2;
x4 = x1+8;
y4 = y1+8;

x5 = x1+4;
y5 = y1+4;
x6 = x1+6;
y6 = y1+6;

  LCDwriteReg(0x36, x2); //Horizontal Window Address 1
  LCDwriteReg(0x37, x1); //Horizontal Window Address 2
  LCDwriteReg(0x38, y2); //Vertical Window Address 1
  LCDwriteReg(0x39, y1); //Vertical Window Address 2

  wait_ticks(6000);

  LCDwriteReg(0x07, 0x1017); //Display Control 1

  LCDwriteReg(0x20, x2); //RAM Address Set 1 (LSB)
  LCDwriteReg(0x21, y2); //RAM Address Set 2 (MSB)
  int j;
        for (j=121; j>0; j--){
            LCDwriteReg(0x22,z2);
        }

  LCDwriteReg(0x36, x4); //Horizontal Window Address 1
  LCDwriteReg(0x37, x3); //Horizontal Window Address 2
  LCDwriteReg(0x38, y4); //Vertical Window Address 1
  LCDwriteReg(0x39, y3); //Vertical Window Address 2

  wait_ticks(6000);

  LCDwriteReg(0x07, 0x1017); //Display Control 1

  LCDwriteReg(0x20, x3); //RAM Address Set 1 (LSB)
  LCDwriteReg(0x21, y3); //RAM Address Set 2 (MSB)
  int i;
        for (i=49; i>0; i--){
            LCDwriteReg(0x22,z1);
        }

        LCDwriteReg(0x36, x6); //Horizontal Window Address 1
        LCDwriteReg(0x37, x5); //Horizontal Window Address 2
        LCDwriteReg(0x38, y6); //Vertical Window Address 1
        LCDwriteReg(0x39, y5); //Vertical Window Address 2

        wait_ticks(6000);

        LCDwriteReg(0x07, 0x1017); //Display Control 1

        LCDwriteReg(0x20, x5); //RAM Address Set 1 (LSB)
        LCDwriteReg(0x21, y5); //RAM Address Set 2 (MSB)
        int k;
              for (k=9; k>0; k--){
                  LCDwriteReg(0x22,0xFFFF);
              }
}

void Block(int x1, int y1, int z){ //creates a 10x10 pixel white block containing an 8x8 block of color 'z'
int x2;
int y2;
int x3;
int y3;
int x4;
int y4;
x2 = x1+9;
y2= y1+9;
x3 = x1+1;
y3 = y1+1;
x4 = x3+7;
y4 = y3+7;

  LCDwriteReg(0x36, x2); //Horizontal Window Address 1
  LCDwriteReg(0x37, x1); //Horizontal Window Address 2
  LCDwriteReg(0x38, y2); //Vertical Window Address 1
  LCDwriteReg(0x39, y1); //Vertical Window Address 2

  wait_ticks(6000);

  LCDwriteReg(0x07, 0x1017); //Display Control 1

  LCDwriteReg(0x20, x2); //RAM Address Set 1 (LSB)
  LCDwriteReg(0x21, y2); //RAM Address Set 2 (MSB)
  int j;
        for (j=100; j>0; j--){
            LCDwriteReg(0x22,0xFFFF);
        }

  LCDwriteReg(0x36, x4); //Horizontal Window Address 1
  LCDwriteReg(0x37, x3); //Horizontal Window Address 2
  LCDwriteReg(0x38, y4); //Vertical Window Address 1
  LCDwriteReg(0x39, y3); //Vertical Window Address 2

  wait_ticks(6000);

  LCDwriteReg(0x07, 0x1017); //Display Control 1

  LCDwriteReg(0x20, x3); //RAM Address Set 1 (LSB)
  LCDwriteReg(0x21, y3); //RAM Address Set 2 (MSB)
  int i;
        for (i=64; i>0; i--){
            LCDwriteReg(0x22,z);
        }
}

void Erase (int x1, int y1){ //creates a "not a block" 10x10 black pixels to match background

int x2;
int y2;

x2 = x1+9;
y2= y1+9;

  LCDwriteReg(0x36, x2); //Horizontal Window Address 1
  LCDwriteReg(0x37, x1); //Horizontal Window Address 2
  LCDwriteReg(0x38, y2); //Vertical Window Address 1
  LCDwriteReg(0x39, y1); //Vertical Window Address 2

  wait_ticks(6000);

  LCDwriteReg(0x07, 0x1017); //Display Control 1

  LCDwriteReg(0x20, x2); //RAM Address Set 1 (LSB)
  LCDwriteReg(0x21, y2); //RAM Address Set 2 (MSB)
  int j;
        for (j=100; j>0; j--){
            LCDwriteReg(0x22,0x0000);
              }
}

// screens and back grounds

void BG(void){
    int j;
    int i;

    for (j=0; j<16; j++){
        for (i=0;i<20;i++){
            int k;
            k=(((j*10)+i)%7);
        switch(k){
        case 0:    Brick(BackGroundCol[j],BackGroundRow[i],P,F);
                break;
        case 1:    Brick(BackGroundCol[j],BackGroundRow[i],C,S);
                break;
        case 2:    Brick(BackGroundCol[j],BackGroundRow[i],Y,M);
                break;
        case 3:    Brick(BackGroundCol[j],BackGroundRow[i],K,G);
                break;
        case 4:    Brick(BackGroundCol[j],BackGroundRow[i],A,T);
                break;
        case 5:    Brick(BackGroundCol[j],BackGroundRow[i],B,N);
                break;
        case 6:    Brick(BackGroundCol[j],BackGroundRow[i],L,V);
                break;
        }
    }
}
}

void LetterField(void){ //creates the background to write letters on

      LCDwriteReg(0x36, BackGroundCol[15]); //Horizontal Window Address 1 end
      LCDwriteReg(0x37, BackGroundCol[1]); //Horizontal Window Address 2 start
      LCDwriteReg(0x38, BackGroundRow[19]); //Vertical Window Address 1 end
      LCDwriteReg(0x39, BackGroundRow[1]); //Vertical Window Address 2 start

      wait_ticks(6000);
      LCDwriteReg(0x07, 0x1017); //Display Control 1

      LCDwriteReg(0x20, BackGroundRow[19]); //Horizontal RAM Address Set 1 (LSB)
      LCDwriteReg(0x21, BackGroundRow[1]); //Vertical RAM Address Set 2 (MSB)
      int i;
      for (i=30492; i>0; i--){

      LCDwriteReg(0x22,0x0000);
      }
    }

void Welcome(void){
    BG();
    LetterField();
        LetterO((BackGroundCol[2]-7), BackGroundRow[4], P, F);
        LetterP((BackGroundCol[4]-11), BackGroundRow[4], C, S);
        LetterT((BackGroundCol[5]-7), BackGroundRow[4], Y, M);
        LetterI((BackGroundCol[7]-9), BackGroundRow[4], K, G);
        LetterM((BackGroundCol[8]-9), BackGroundRow[4], A, T);
        LetterA((BackGroundCol[10]-9), BackGroundRow[4], B, N);
        LetterL((BackGroundCol[12]-10), BackGroundRow[4], L, V);
        LetterL((BackGroundCol[14]-16), BackGroundRow[4], P, F);
        LetterY((BackGroundCol[15]-16), BackGroundRow[4], C, S);

        LetterP((BackGroundCol[2]), BackGroundRow[7], Y, M);
        LetterA((BackGroundCol[4]), BackGroundRow[7], K, G);
        LetterC((BackGroundCol[6]), BackGroundRow[7], A, T);
        LetterK((BackGroundCol[8]), BackGroundRow[7], B, N);
        LetterE((BackGroundCol[10]), BackGroundRow[7], L, V);
        LetterD((BackGroundCol[12]), BackGroundRow[7], P, F);

        LetterF((BackGroundCol[2]), BackGroundRow[10], C, S);
        LetterA((BackGroundCol[4]-3), BackGroundRow[10], Y, M);
        LetterL((BackGroundCol[6]-5), BackGroundRow[10], K, G);
        LetterL((BackGroundCol[8]-8), BackGroundRow[10], A, T);
        LetterI((BackGroundCol[10]-10), BackGroundRow[10], B, N);
        LetterN((BackGroundCol[12]-12), BackGroundRow[10], L, V);
        LetterG((BackGroundCol[14]-12), BackGroundRow[10], P, F);

        LetterS((BackGroundCol[2]), BackGroundRow[13], C, S);
        LetterH((BackGroundCol[4]), BackGroundRow[13], Y, M);
        LetterA((BackGroundCol[6]), BackGroundRow[13], K, G);
        LetterP((BackGroundCol[8]), BackGroundRow[13], A, T);
        LetterE((BackGroundCol[10]), BackGroundRow[13], B, N);
        LetterS((BackGroundCol[12]), BackGroundRow[13], L, V);
}

void PlayField(void){ //creates the game background
    BG();

  LCDwriteReg(0x36, 0x008D); //Horizontal Window Address end
  LCDwriteReg(0x37, 0x0022); //Horizontal Window Address start
  LCDwriteReg(0x38, 0x00D8); //Vertical Window Address end
  LCDwriteReg(0x39, 0x0006); //Vertical Window Address start

  wait_ticks(6000);

  LCDwriteReg(0x07, 0x1017); //Display Control 1

  LCDwriteReg(0x20, 0x0022); //Horizontal RAM Address Set 1 (LSB)
  LCDwriteReg(0x21, 0x0006); //vertical RAM Address Set 2 (MSB)
  int j;
  for (j=21516; j>0; j--){

  LCDwriteReg(0x22,0xFFFF);
  }

  LCDwriteReg(0x36, 0x0089); //Horizontal Window Address 1 end
  LCDwriteReg(0x37, 0x0026); //Horizontal Window Address 2 start
  LCDwriteReg(0x38, 0x00D1); //Vertical Window Address 1 end
  LCDwriteReg(0x39, 0x000A); //Vertical Window Address 2 start

  wait_ticks(6000);

  LCDwriteReg(0x07, 0x1017); //Display Control 1

  LCDwriteReg(0x20, 0x0026); //Horizontal RAM Address Set 1 (LSB)
  LCDwriteReg(0x21, 0x000A); //Vertical RAM Address Set 2 (MSB)
  int i;
  for (i=20000; i>0; i--){

  LCDwriteReg(0x22,0x0000);
  }

}

void GameOver(int Score){
    int first;
    int second;

    BG();
    LetterField();
    LetterG((BackGroundCol[2]), BackGroundRow[4], P, F);
    LetterA((BackGroundCol[4]), BackGroundRow[4], C, S);
    LetterM((BackGroundCol[6]), BackGroundRow[4], Y, M);
    LetterE((BackGroundCol[8]), BackGroundRow[4], K, G);

    LetterO((BackGroundCol[6]), BackGroundRow[7], A, T);
    LetterU((BackGroundCol[8]), BackGroundRow[7], B, N);
    LetterE((BackGroundCol[10]), BackGroundRow[7], L, V);
    LetterR((BackGroundCol[12]), BackGroundRow[7], P, F);

    LetterY((BackGroundCol[4]), BackGroundRow[11], C, S);
    LetterO((BackGroundCol[6]), BackGroundRow[11], Y, M);
    LetterU((BackGroundCol[8]), BackGroundRow[11], K, G);
    LetterR((BackGroundCol[10]), BackGroundRow[11], A, T);

    LetterS((BackGroundCol[3]), BackGroundRow[13], B, N);
    LetterC((BackGroundCol[5]), BackGroundRow[13], L, V);
    LetterO((BackGroundCol[7]), BackGroundRow[13], P, F);
    LetterR((BackGroundCol[9]), BackGroundRow[13], C, S);
    LetterE((BackGroundCol[11]), BackGroundRow[13], Y, M);

    first = Score/10;
    second = Score%10;
    FirstNumber(first);
    SecondNumber(second);

    music();

}

////some global variable and other such needs

char KeyPad[16] = {'1', '2', '3', 'A', '4', '5', '6', 'B', '7', '8', '9', 'C', '*', '0', '#', 'D'};
int Score;

///tables for scores

void FirstNumber(int i){ //this is called to display the first digit of a score
    switch(i){
    case 0: Number0(BackGroundCol[6], BackGroundRow[16],F); break;
    case 1: Number1(BackGroundCol[6], BackGroundRow[16],S); break;
    case 2: Number2(BackGroundCol[6], BackGroundRow[16],M); break;
    case 3: Number3(BackGroundCol[6], BackGroundRow[16],G); break;
    case 4: Number4(BackGroundCol[6], BackGroundRow[16],T); break;
    case 5: Number5(BackGroundCol[6], BackGroundRow[16],N); break;
    case 6: Number6(BackGroundCol[6], BackGroundRow[16],V); break;
    case 7: Number7(BackGroundCol[6], BackGroundRow[16],F); break;
    case 8: Number8(BackGroundCol[6], BackGroundRow[16],S); break;
    case 9: Number9(BackGroundCol[6], BackGroundRow[16],M); break;
    }
}

void SecondNumber(int i){//this is called to display the second digit of a score
    switch(i){
    case 0: Number0(BackGroundCol[9], BackGroundRow[16],F); break;
    case 1: Number1(BackGroundCol[9], BackGroundRow[16],S); break;
    case 2: Number2(BackGroundCol[9], BackGroundRow[16],M); break;
    case 3: Number3(BackGroundCol[9], BackGroundRow[16],G); break;
    case 4: Number4(BackGroundCol[9], BackGroundRow[16],T); break;
    case 5: Number5(BackGroundCol[9], BackGroundRow[16],N); break;
    case 6: Number6(BackGroundCol[9], BackGroundRow[16],V); break;
    case 7: Number7(BackGroundCol[9], BackGroundRow[16],F); break;
    case 8: Number8(BackGroundCol[9], BackGroundRow[16],S); break;
    case 9: Number9(BackGroundCol[9], BackGroundRow[16],M); break;
    }
}

//Oblock needs

void Oblock (int a, int b){

    Block ((a-10),(b-10), F);
    Block (a,(b-10), F);
    Block ((a-10),b, F);
    Block (a,b, F);
    }

void OblockSave (int i, int j){

    PlayFieldStat[i-1][j-1]=F;
    PlayFieldStat[i-1][j]=F;
    PlayFieldStat[i][j-1]=F;
    PlayFieldStat[i][j]=F;
    }

void OblockErase (int a, int b){

    Erase ((a-10),(b-10));
    Erase (a,(b-10));
    Erase ((a-10),b);
    Erase (a,b);
    }

int OblockDetectLeft(int i, int j){
    if((PlayFieldStat[i-1][j-2]==0)&&(PlayFieldStat[i][j-2]==0)&&((j-2)>-1)){
        return 0;
        }
        else {
            return 1;
            }
}

int OblockDetectRight(int i, int j){
    if((PlayFieldStat[i-1][j+1]==0)&&(PlayFieldStat[i][j+1]==0)&&((j+1)<10)){
        return 0;
        }
        else {
            return 1;
            }
}

int OblockDetectBelow(int i, int j){
    if((PlayFieldStat[i+1][j-1]==0)&&(PlayFieldStat[i+1][j]==0)){
        return 0;
        }
        else {
            return 1;
            }
}

//Iblock needs

void Iblock (int a, int b, int c){
    int d;
    d = c%2;

    switch (d){
        case 0: Block ((a-20), b, C); Block ((a-10),b, C); Block (a,b, C); Block ((a+9),b, C); break;
        case 1: Block (a, b, C); Block (a,(b-10), C); Block (a,(b-20), C); Block (a,(b-30), C); break;

    }
}

void IblockSave (int i, int j, int c){
    int d;
    d = c%2;

    switch (d){
        case 0: PlayFieldStat[i][j-2]=C;PlayFieldStat[i][j-1]=C;PlayFieldStat[i][j]=C;PlayFieldStat[i][j+1]=C;break;
        case 1: PlayFieldStat[i-3][j]=C;PlayFieldStat[i-2][j]=C;PlayFieldStat[i-1][j]=C;PlayFieldStat[i][j]=C;break;

    }
}

void IblockErase (int a, int b, int c){
    int d;
    d = c%2;

    switch (d){
        case 0: Erase((a-20), b); Erase((a-10),b); Erase(a,b); Erase((a+9),b); break;
        case 1: Erase (a, b); Erase(a,(b-10)); Erase(a,(b-20)); Erase(a,(b-30)); break;
        }
}

int IblockDetectLeft(int i, int j, int c){
    int d;
    d = c%2;

    switch(d){
        case 0:
            if ((PlayFieldStat[i][j-3]==0)&&((j-3)>-1)){
                return 0;
                }
            else {
                return 1;
                }
            break;

        case 1:
            if  ((PlayFieldStat[i][j-1]==0)&&(PlayFieldStat[i-1][j-1]==0)&&(PlayFieldStat[i-2][j-1]==0)&&(PlayFieldStat[i-3][j-1]==0)&&((j-1)>-1)){
                return 0;
                }
            else {
                return 1;
                }
            break;
        }
}

int IblockDetectRight(int i, int j, int c){
    int d;
    d = c%2;

    switch(d){
        case 0:
            if ((PlayFieldStat[i][j+2]==0)&&((j+2)<10)){
                return 0;
                }
            else {
                return 1;
                }
            break;

        case 1:
            if ((PlayFieldStat[i][j+1]==0)&&(PlayFieldStat[i-1][j+1]==0)&&(PlayFieldStat[i-2][j+1]==0)&&(PlayFieldStat[i-3][j+1]==0)&&((j+1)<10)){
                return 0;
                }
            else {
                return 1;
                }
            break;
        }
}

int IblockDetectBelow(int i, int j, int c){
    int d;
    d = c%2;

    switch(d){
        case 0:
            if ((PlayFieldStat[i+1][j-2]==0)&&(PlayFieldStat[i+1][j-1]==0)&&(PlayFieldStat[i+1][j]==0)&&(PlayFieldStat[i+1][j+1]==0)){
                return 0;
                }
            else {
                return 1;
                }
            break;

        case 1:
            if (PlayFieldStat[i+1][j]==0){
                return 0;
                }
            else {
                return 1;
                }
            break;
    }
}

int IblockDetectSpin(int i, int j, int c){
    int d;
    d = c%2;

    switch(d){
        case 0:
            if((PlayFieldStat[i-3][j]==0)&&(PlayFieldStat[i-2][j]==0)&&(PlayFieldStat[i-1][j]==0)&&(j>-1)&&(j<10)) {
                return 0;
                }
            else {
                return 1;
                }
            break;

        case 1:
            if ((PlayFieldStat[i][j-2]==0)&&(PlayFieldStat[i][j-1]==0)&&(PlayFieldStat[i][j+1]==0)&&((j-2)>-1)&&((j+1)<10)){
                return 0;
                }
            else {
                return 1;
                }
            break;
    }
}

// Sblock needs

void Sblock (int a, int b, int c){
    int d;
    d = c%2;

    switch (d){
        case 0:  Block (a, (b-10), Y); Block ((a+9),(b-10), Y); Block ((a-10),b, Y); Block (a,b, Y); break;
        case 1: Block ((a-10), (b-20), Y); Block ((a-10),(b-10), Y); Block (a,(b-10), Y); Block (a,b, Y); break;
    }
}

void SblockSave (int i, int j, int c){
    int d;
    d = c%2;

    switch (d){
        case 0: PlayFieldStat[i-1][j]=Y;PlayFieldStat[i-1][j+1]=Y;PlayFieldStat[i][j-1]=Y;PlayFieldStat[i][j]=Y;break;
        case 1: PlayFieldStat[i-2][j-1]=Y;PlayFieldStat[i-1][j-1]=Y;PlayFieldStat[i-1][j]=Y;PlayFieldStat[i][j]=Y;break;

    }
}

void SblockErase (int a, int b, int c){
    int d;
    d = c%2;

    switch (d){
        case 0:  Erase(a,(b-10)); Erase((a+9),(b-10)); Erase((a-10),b); Erase(a,b); break;
        case 1: Erase((a-10),(b-20)); Erase((a-10),(b-10)); Erase(a,(b-10)); Erase(a,b); break;
    }
}

int SblockDetectLeft(int i, int j, int c){
    int d;
    d = c%2;

    switch(d){
        case 0:
            if ((PlayFieldStat[i-1][j-1]==0)&&(PlayFieldStat[i][j-2]==0)&&((j-2)>-1)){
                return 0;
                }
            else {
                return 1;
                }
            break;

        case 1:
            if ((PlayFieldStat[i][j-1]==0)&&(PlayFieldStat[i-1][j-2]==0)&&(PlayFieldStat[i-2][j-2]==0)&&((j-2)>-1)){
                return 0;
                }
            else {
                return 1;
                }
            break;
        }
}

int SblockDetectRight(int i, int j, int c){
    int d;
    d = c%2;

    switch(d){
        case 0:
            if ((PlayFieldStat[i-1][j+2]==0)&&(PlayFieldStat[i][j+1]==0)&&((j+2)<10)){
                return 0;
                }
            else {
                return 1;
                }
            break;

        case 1:
            if ((PlayFieldStat[i-2][j]==0)&&(PlayFieldStat[i-1][j+1]==0)&&(PlayFieldStat[i][j+1]==0)&&((j+1)<10)){
                return 0;
                }
            else {
                return 1;
                }
            break;
        }
}

int SblockDetectBelow(int i, int j, int c){
    int d;
    d = c%2;

    switch(d){
        case 0:
            if ((PlayFieldStat[i+1][j-1]==0)&&(PlayFieldStat[i+1][j]==0)&&(PlayFieldStat[i][j+1]==0)){
                return 0;
                }
            else {
                return 1;
                }
            break;

        case 1:
            if ((PlayFieldStat[i][j-1]==0)&&(PlayFieldStat[i+1][j]==0)){
                return 0;
                }
            else {
                return 1;
                }
            break;
        }
}

int SblockDetectSpin(int i, int j, int c){
    int d;
    d = c%2;

    switch(d){
        case 0:
            if ((PlayFieldStat[i-2][j-1]==0)&&(PlayFieldStat[i-1][j-1]==0)&&((j-1)>-1)&&((j-1)<10)){
                return 0;
                }
            else {
                return 1;
                }
            break;

        case 1:
            if ((PlayFieldStat[i][j-1]==0)&&(PlayFieldStat[i-1][j+1]==0)&&((j-1)>-1)&&((j+1)<10)){
                return 0;
                }
            else {
                return 1;
                }
            break;
    }
}

//Zblock needs

void Zblock (int a, int b, int c){
    int d;
    d = c%2;

    switch (d){
        case 0:  Block ((a-20), (b-10),K); Block ((a-10),(b-10), K); Block ((a-10),b, K); Block (a,b,K); break;
        case 1: Block (a, (b-20), K); Block ((a-10),(b-10), K); Block (a,(b-10), K); Block ((a-10),b, K); break;
    }
}

void ZblockSave (int i, int j, int c){
    int d;
    d = c%2;

    switch (d){
        case 0: PlayFieldStat[i-1][j-2]=K;PlayFieldStat[i-1][j-1]=K;PlayFieldStat[i][j-1]=K;PlayFieldStat[i][j]=K;break;
        case 1: PlayFieldStat[i-2][j]=K;PlayFieldStat[i-1][j-1]=K;PlayFieldStat[i-1][j]=K;PlayFieldStat[i][j-1]=K;break;

    }
}

void ZblockErase (int a, int b, int c){
    int d;
    d = c%2;

    switch (d){
        case 0:  Erase((a-20), (b-10)); Erase((a-10),(b-10));Erase((a-10),b); Erase(a,b); break;
        case 1: Erase(a, (b-20)); Erase((a-10),(b-10)); Erase(a,(b-10)); Erase((a-10),b); break;
    }
}

int ZblockDetectLeft(int i, int j, int c){
    int d;
    d = c%2;

    switch(d){
        case 0:
            if ((PlayFieldStat[i-1][j-3]==0)&&(PlayFieldStat[i][j-2]==0)&&((j-3)>-1)){
                return 0;
                }
            else {
                return 1;
                }
            break;

        case 1:
            if ((PlayFieldStat[i][j-2]==0)&&(PlayFieldStat[i-1][j-2]==0)&&(PlayFieldStat[i-2][j-1]==0)&&((j-2)>-1)){
                return 0;
                }
            else {
                return 1;
                }
            break;
        }
}

int ZblockDetectRight(int i, int j, int c){
    int d;
    d = c%2;

    switch(d){
        case 0:
            if ((PlayFieldStat[i-1][j]==0)&&(PlayFieldStat[i][j+1]==0)&&((j+1)<10)){
                return 0;
                }
            else {
                return 1;
                }
            break;

        case 1:
            if ((PlayFieldStat[i-2][j+1]==0)&&(PlayFieldStat[i-1][j+1]==0)&&(PlayFieldStat[i][j]==0)&&((j+1)<10)){
                return 0;
                }
            else {
                return 1;
                }
            break;
        }
}

int ZblockDetectBelow(int i, int j, int c){
    int d;
    d = c%2;

    switch(d){
        case 0:
            if ((PlayFieldStat[i][j-2]==0)&&(PlayFieldStat[i+1][j-1]==0)&&(PlayFieldStat[i+1][j]==0)){
                return 0;
                }
            else {
                return 1;
                }
            break;

        case 1:
            if ((PlayFieldStat[i+1][j-1]==0)&&(PlayFieldStat[i][j]==0)){
                return 0;
                }
            else {
                return 1;
                }
            break;
        }
}

int ZblockDetectSpin(int i, int j, int c){
    int d;
    d = c%2;

    switch(d){
        case 0:
            if ((PlayFieldStat[i-2][j]==0)&&(PlayFieldStat[i-1][j]==0)&&(j>-1)&&(j<10)){
                return 0;
                }
            else {
                return 1;
                }
            break;

        case 1:
            if ((PlayFieldStat[i-1][j-2]==0)&&(PlayFieldStat[i][j]==0)&&((j-2)>-1)&&(j<10)){
                return 0;
                }
            else {
                return 1;
                }
            break;
    }
}

//LBlock needs

void Lblock (int a, int b, int c){
    int d;
    d = c%4;

    switch (d){
        case 0: Block (a, b, T); Block ((a-10),b, T); Block ((a-10),(b-10), T); Block ((a-10),(b-20), T); break;
        case 1: Block ((a-10), b, T); Block ((a-10),(b-10), T); Block (a,(b-10), T); Block ((a+9),(b-10), T); break;
        case 2: Block (a, b, T); Block (a,(b-10), T); Block (a,(b-20), T);  Block ((a-10),(b-20), T); break;
        case 3: Block (a, b, T); Block (a,(b-10), T); Block ((a-10),b, T); Block ((a-19),b, T); break;
    }
}

void LblockSave (int i, int j, int c){
    int d;
    d = c%4;

    switch (d){
        case 0: PlayFieldStat[i-2][j-1]=T;PlayFieldStat[i-1][j-1]=T;PlayFieldStat[i][j-1]=T;PlayFieldStat[i][j]=T;break;
        case 1: PlayFieldStat[i-1][j-1]=T;PlayFieldStat[i-1][j]=T;PlayFieldStat[i-1][j+1]=T;PlayFieldStat[i][j-1]=T;break;
        case 2: PlayFieldStat[i-2][j-1]=T;PlayFieldStat[i-2][j]=T;PlayFieldStat[i-1][j]=T;PlayFieldStat[i][j]=T;break;
        case 3: PlayFieldStat[i-1][j]=T;PlayFieldStat[i][j-2]=T;PlayFieldStat[i][j-1]=T;PlayFieldStat[i][j]=T;break;
    }
}

void LblockErase (int a, int b, int c){
    int d;
    d = c%4;

    switch (d){
        case 0: Erase(a, b); Erase((a-10),b); Erase((a-10),(b-10)); Erase((a-10),(b-20)); break;
        case 1: Erase((a-10), b); Erase((a-10),(b-10)); Erase(a,(b-10)); Erase ((a+9),(b-10)); break;
        case 2: Erase(a, b); Erase(a,(b-10)); Erase(a,(b-20));  Erase((a-10),(b-20)); break;
        case 3: Erase(a, b); Erase(a,(b-10)); Erase((a-10),b);  Erase((a-19),b); break;
    }
}

int LblockDetectLeft(int i, int j, int c){
    int d;
    d = c%4;

    switch(d){
        case 0:
            if ((PlayFieldStat[i-2][j-2]==0)&&(PlayFieldStat[i-1][j-2]==0)&&(PlayFieldStat[i][j-2]==0)&&((j-2)>-1)){
                return 0;
                }
            else {
                return 1;
                }
            break;

        case 1:
            if ((PlayFieldStat[i-1][j-2]==0)&&(PlayFieldStat[i][j-2]==0)&&((j-2)>-1)){
                return 0;
                }
            else {
                return 1;
                }
            break;
        case 2:
            if ((PlayFieldStat[i-2][j-2]==0)&&(PlayFieldStat[i-1][j-1]==0)&&(PlayFieldStat[i][j-1]==0)&&((j-2)>-1)){
                return 0;
                }
            else {
                return 1;
                }
            break;

        case 3:
            if ((PlayFieldStat[i][j-3]==0)&& (PlayFieldStat[i-1][j-1]==0)&&((j-3)>-1)){
                return 0;
                }
            else {
                return 1;
                }
            break;
        }
}

int LblockDetectRight(int i, int j, int c){
    int d;
    d = c%4;

    switch(d){
        case 0:
            if ((PlayFieldStat[i-2][j]==0)&&(PlayFieldStat[i-1][j]==0)&&(PlayFieldStat[i][j+1]==0)&&((j+1)<10)){
                return 0;
                }
            else {
                return 1;
                }
            break;

        case 1:
            if ((PlayFieldStat[i-1][j+2]==0)&&(PlayFieldStat[i][j]==0)&&((j+2)<10)){
                return 0;
                }
            else {
                return 1;
                }
            break;
        case 2:
            if ((PlayFieldStat[i-2][j+1]==0)&&(PlayFieldStat[i-1][j+1]==0)&&(PlayFieldStat[i][j+1]==0)&&((j+1)<10)){
                return 0;
                }
            else {
                return 1;
                }
            break;

        case 3:
            if ((PlayFieldStat[i-1][j+1]==0)&& (PlayFieldStat[i][j+1]==0)&&((j+1)<10)){
                return 0;
                }
            else {
                return 1;
                }
            break;
        }
}

int LblockDetectBelow(int i, int j, int c){
    int d;
    d = c%4;

    switch(d){
        case 0:
            if ((PlayFieldStat[i+1][j-1]==0)&&(PlayFieldStat[i+1][j]==0)){
                return 0;
                }
            else {
                return 1;
                }
            break;

        case 1:
            if ((PlayFieldStat[i+1][j-1]==0)&&(PlayFieldStat[i][j]==0)&&(PlayFieldStat[i][j+1]==0)){
                return 0;
                }
            else {
                return 1;
                }
            break;
        case 2:
            if ((PlayFieldStat[i-1][j-1]==0)&&(PlayFieldStat[i+1][j]==0)){
                return 0;
                }
            else {
                return 1;
                }
            break;

        case 3:
            if ((PlayFieldStat[i+1][j-2]==0)&&(PlayFieldStat[i+1][j-1]==0)&&(PlayFieldStat[i+1][j]==0)){
                return 0;
                }
            else {
                return 1;
                }
            break;
        }
}

int LblockDetectSpin(int i, int j, int c){
    int d;
    d = c%2;

    switch(d){
        case 0:
            if ((PlayFieldStat[i-1][j]==0)&&(PlayFieldStat[i-1][j+1]==0)&&(j>-1)&&((j+1)<10)){
                return 0;
                }
            else {
                return 1;
                }
            break;

        case 1:
            if ((PlayFieldStat[i-2][j-1]==0)&&(PlayFieldStat[i-2][j]==0)&&(PlayFieldStat[i][j]==0)&&((j-1)>-1)&&(j<10)){
                return 0;
                }
            else {
                return 1;
                }
            break;
        case 2:
            if ((PlayFieldStat[i][j-2]==0)&&(PlayFieldStat[i][j-1]==0)&&((j-2)>-1)&&((j-1)<10)){
                return 0;
                }
            else {
                return 1;
                }
            break;

        case 3:
            if ((PlayFieldStat[i-2][j-1]==0)&&(PlayFieldStat[i-1][j-1]==0)){
                return 0;
                }
            else {
                return 1;
                }
            break;
    }
}

//Jblock needs

void Jblock (int a, int b, int c){
    int d;
    d = c%4;

    switch (d){
        case 0: Block (a, b, B); Block ((a-10),b, B); Block (a,(b-10), B); Block ((a),(b-20), B); break;
        case 1: Block ((a-10), (b-10), B); Block ((a-10),b, B); Block (a,b, B); Block ((a+9),b, B); break;
        case 2: Block ((a-10), (b-20), B); Block (a,(b-20), B); Block ((a-10),(b-10), B); Block((a-10),b, B); break;
        case 3: Block (a, b, B); Block (a,(b-10), B); Block ((a-10),(b-10), B); Block ((a-20),(b-10), B); break;
    }
}

void JblockSave (int i, int j, int c){
    int d;
    d = c%4;

    switch (d){
        case 0: PlayFieldStat[i-2][j]=B;PlayFieldStat[i-1][j]=B;PlayFieldStat[i][j-1]=B;PlayFieldStat[i][j]=B;break;
        case 1: PlayFieldStat[i-1][j-1]=B;PlayFieldStat[i][j-1]=B;PlayFieldStat[i][j]=B;PlayFieldStat[i][j+1]=B;break;
        case 2: PlayFieldStat[i-2][j-1]=B;PlayFieldStat[i-2][j]=B;PlayFieldStat[i-1][j-1]=B;PlayFieldStat[i][j-1]=B;break;
        case 3: PlayFieldStat[i-1][j-2]=B;PlayFieldStat[i-1][j-1]=B;PlayFieldStat[i-1][j]=B;PlayFieldStat[i][j]=B;break;
    }
}

void JblockErase (int a, int b, int c){
    int d;
    d = c%4;

    switch (d){
        case 0: Erase (a, b); Erase ((a-10),b); Erase (a,(b-10)); Erase ((a),(b-20)); break;
        case 1: Erase ((a-10), (b-10)); Erase ((a-10),b);Erase (a,b); Erase ((a+9),b); break;
        case 2: Erase ((a-10), (b-20)); Erase (a,(b-20)); Erase ((a-10),(b-10)); Erase((a-10),b); break;
        case 3: Erase (a, b); Erase(a,(b-10));Erase((a-10),(b-10)); Erase((a-20),(b-10)); break;
    }
}

int JblockDetectLeft(int i, int j, int c){
    int d;
    d = c%4;

    switch(d){
        case 0:
            if ((PlayFieldStat[i-2][j-1]==0)&&(PlayFieldStat[i-1][j-1]==0)&&(PlayFieldStat[i][j-2]==0)&&((j-2)>-1)){
                return 0;
                }
            else {
                return 1;
                }
            break;

        case 1:
            if ((PlayFieldStat[i-1][j-2]==0)&&(PlayFieldStat[i][j-2]==0)&&((j-2)>-1)){
                return 0;
                }
            else {
                return 1;
                }
            break;
        case 2:
            if ((PlayFieldStat[i-2][j-2]==0)&&(PlayFieldStat[i-1][j-2]==0)&&(PlayFieldStat[i][j-2]==0)&&((j-2)>-1)){
                return 0;
                }
            else {
                return 1;
                }
            break;

        case 3:
            if ((PlayFieldStat[i-1][j-3]==0)&& (PlayFieldStat[i][j-1]==0)&&((j-3)>-1)){
                return 0;
                }
            else {
                return 1;
                }
            break;
        }
}

int JblockDetectRight(int i, int j, int c){
    int d;
    d = c%4;

    switch(d){
        case 0:
            if ((PlayFieldStat[i-2][j+1]==0)&&(PlayFieldStat[i-1][j+1]==0)&&(PlayFieldStat[i][j+1]==0)&&((j+1)<10)){
                return 0;
                }
            else {
                return 1;
                }
            break;

        case 1:
            if ((PlayFieldStat[i-1][j]==0)&&(PlayFieldStat[i][j+2]==0)&&((j+2)<10)){
                return 0;
                }
            else {
                return 1;
                }
            break;
        case 2:
            if ((PlayFieldStat[i-2][j+1]==0)&&(PlayFieldStat[i-1][j]==0)&&(PlayFieldStat[i][j]==0)&&((j+1)<10)){
                return 0;
                }
            else {
                return 1;
                }
            break;

        case 3:
            if ((PlayFieldStat[i-1][j+1]==0)&& (PlayFieldStat[i][j+1]==0)&&((j+1)<10)){
                return 0;
                }
            else {
                return 1;
                }
            break;
        }
}

int JblockDetectBelow(int i, int j, int c){
    int d;
    d = c%4;

    switch(d){
        case 0:
            if ((PlayFieldStat[i+1][j-1]==0)&&(PlayFieldStat[i+1][j]==0)){
                return 0;
                }
            else {
                return 1;
                }
            break;

        case 1:
            if ((PlayFieldStat[i+1][j-1]==0)&&(PlayFieldStat[i+1][j]==0)&&(PlayFieldStat[i+1][j+1]==0)){
                return 0;
                }
            else {
                return 1;
                }
            break;
        case 2:
            if ((PlayFieldStat[i+1][j-1]==0)&&(PlayFieldStat[i-1][j]==0)){
                return 0;
                }
            else {
                return 1;
                }
            break;

        case 3:
            if ((PlayFieldStat[i][j-2]==0)&&(PlayFieldStat[i][j-1]==0)&&(PlayFieldStat[i+1][j]==0)){
                return 0;
                }
            else {
                return 1;
                }
            break;
        }
}

int JblockDetectSpin(int i, int j, int c){
    int d;
    d = c%2;

    switch(d){
        case 0:
            if ((PlayFieldStat[i-1][j-1]==0)&&(PlayFieldStat[i][j+1]==0)&&((j-1)>-1)&&((j+1)<10)){
                return 0;
                }
            else {
                return 1;
                }
            break;

        case 1:
            if ((PlayFieldStat[i-2][j-1]==0)&&(PlayFieldStat[i-2][j-1]==0)&&((j-1)>-1)&&((j-1)<10)){
                return 0;
                }
            else {
                return 1;
                }
            break;
        case 2:
            if ((PlayFieldStat[i-1][j-1]==0)&&(PlayFieldStat[i-1][j]==0)&&(PlayFieldStat[i][j]==0)&&((j-1)>-1)&&(j<10)){
                return 0;
                }
            else {
                return 1;
                }
            break;

        case 3:
            if ((PlayFieldStat[i-2][j]==0)&&(PlayFieldStat[i][j-1]==0)&&((j-1)>-1)&&(j<10)){
                return 0;
                }
            else {
                return 1;
                }
            break;
    }
}

//Tblock needs

void Tblock (int a, int b, int c){
    int d;
    d = c%4;

    switch (d){
        case 0: Block ((a-10), (b-10), L); Block (a,(b-10), L); Block ((a+9),(b-10), L); Block (a,b, L); break;
        case 1: Block ((a),(b-20), L);  Block (a,(b-10), L); Block ((a-10),(b-10), L); Block (a, b, L); break;
        case 2: Block ((a-10), b, L); Block (a,(b-10), L); Block (a,b, L); Block ((a+9),b, L); break;
        case 3: Block ((a),(b-20), L);  Block (a,(b-10), L); Block ((a+9),(b-10), L); Block (a, b, L); break;
    }
}

void TblockSave (int i, int j, int c){
    int d;
    d = c%4;

    switch (d){
        case 0: PlayFieldStat[i-1][j-1]=L;PlayFieldStat[i-1][j]=L;PlayFieldStat[i-1][j+1]=L;PlayFieldStat[i][j]=L;break;
        case 1: PlayFieldStat[i-2][j]=L;PlayFieldStat[i-1][j-1]=L;PlayFieldStat[i-1][j]=L;PlayFieldStat[i][j]=L;break;
        case 2: PlayFieldStat[i-1][j]=L;PlayFieldStat[i][j-1]=L;PlayFieldStat[i][j]=L;PlayFieldStat[i][j+1]=L;break;
        case 3: PlayFieldStat[i-2][j]=L;PlayFieldStat[i-1][j]=L;PlayFieldStat[i-1][j+1]=L;PlayFieldStat[i][j]=L;break;
    }
}

void TblockErase (int a, int b, int c){
    int d;
    d = c%4;

    switch (d){
        case 0: Erase ((a-10), (b-10)); Erase (a,(b-10)); Erase ((a+9),(b-10)); Erase (a,b); break;
        case 1: Erase ((a),(b-20));  Erase (a,(b-10)); Erase ((a-10),(b-10)); Erase (a, b); break;
        case 2: Erase ((a-10), b); Erase (a,(b-10)); Erase (a,b); Erase ((a+9),b); break;
        case 3: Erase ((a),(b-20));  Erase (a,(b-10)); Erase((a+9),(b-10)); Erase (a, b); break;
    }
}

int TblockDetectLeft(int i, int j, int c){
    int d;
    d = c%4;

    switch(d){
        case 0:
            if ((PlayFieldStat[i-1][j-2]==0)&&(PlayFieldStat[i][j-1]==0)&&((j-2)>-1)){
                return 0;
                }
            else {
                return 1;
                }
            break;

        case 1:
            if ((PlayFieldStat[i-2][j-1]==0)&&(PlayFieldStat[i-1][j-2]==0)&&(PlayFieldStat[i][j-1]==0)&&((j-2)>-1)){
                return 0;
                }
            else {
                return 1;
                }
            break;
        case 2:
            if ((PlayFieldStat[i-1][j-1]==0)&&(PlayFieldStat[i][j-2]==0)&&((j-2)>-1)){
                return 0;
                }
            else {
                return 1;
                }
            break;

        case 3:
            if ((PlayFieldStat[i-2][j-1]==0)&&(PlayFieldStat[i-1][j-1]==0)&&(PlayFieldStat[i][j-1]==0)&&((j-1)>-1)){
                return 0;
                }
            else {
                return 1;
                }
            break;
        }
}

int TblockDetectRight(int i, int j, int c){
    int d;
    d = c%4;

    switch(d){
        case 0:
            if ((PlayFieldStat[i-1][j+2]==0)&&(PlayFieldStat[i][j+1]==0)&&((j+2)<10)){
                return 0;
                }
            else {
                return 1;
                }
            break;

        case 1:
            if ((PlayFieldStat[i-2][j+1]==0)&&(PlayFieldStat[i-1][j+1]==0)&&(PlayFieldStat[i][j+1]==0)&&((j+1)<10)){
                return 0;
                }
            else {
                return 1;
                }
            break;
        case 2:
            if ((PlayFieldStat[i-1][j+1]==0)&&(PlayFieldStat[i][j+2]==0)&&((j+2)<10)){
                return 0;
                }
            else {
                return 1;
                }
            break;

        case 3:
            if ((PlayFieldStat[i-2][j+1]==0)&&(PlayFieldStat[i-1][j+2]==0)&&(PlayFieldStat[i][j+1]==0)&&((j+2)<10)){
                return 0;
                }
            else {
                return 1;
                }
            break;
        }
}

int TblockDetectBelow(int i, int j, int c){
    int d;
    d = c%4;

    switch(d){
        case 0:
            if ((PlayFieldStat[i][j-1]==0)&&(PlayFieldStat[i+1][j]==0)&&(PlayFieldStat[i][j+1]==0)){
                return 0;
                }
            else {
                return 1;
                }
            break;

        case 1:
            if ((PlayFieldStat[i][j-1]==0)&&(PlayFieldStat[i+1][j]==0)){
                return 0;
                }
            else {
                return 1;
                }
            break;
        case 2:
            if ((PlayFieldStat[i+1][j-1]==0)&&(PlayFieldStat[i+1][j]==0)&&(PlayFieldStat[i+1][j+1]==0)){
                return 0;
                }
            else {
                return 1;
                }
            break;

        case 3:
            if ((PlayFieldStat[i+1][j]==0)&& (PlayFieldStat[i][j+1]==0)){
                return 0;
                }
            else {
                return 1;
                }
            break;
        }
}

int TblockDetectSpin(int i, int j, int c){
    int d;
    d = c%2;

    switch(d){
        case 0:
            if ((PlayFieldStat[i-2][j]==0)&&(j>-1)&&(j<10)){
                return 0;
                }
            else {
                return 1;
                }
            break;

        case 1:
            if ((PlayFieldStat[i][j-1]==0)&&(PlayFieldStat[i][j+1]==0)&&((j-1)>-1)&&((j+1)<10)){
                return 0;
                }
            else {
                return 1;
                }
            break;
        case 2:
            if ((PlayFieldStat[i-2][j]==0)&&(PlayFieldStat[i-1][j+1]==0)&&(j>-1)&&((j+1)<10)){
                return 0;
                }
            else {
                return 1;
                }
            break;

        case 3:
            if ((PlayFieldStat[i-2][j-1]==0)&&((j-1)>-1)&&((j-1)<10)){
                return 0;
                }
            else {
                return 1;
                }
            break;
    }
}

////letters and numbers needs

void LetterA(int a, int b, int c1, int c2){

    pin(a, b, c2);
    pin(a, (b-2), c2);

    pin((a+2), (b-6), c2);
    pin((a+2), (b-4), c2);
    pin((a+2), (b-2), c1);
    pin((a+2), b, c1);

    pin((a+4), (b-10), c2);
    pin((a+4), (b-8), c2);
    pin((a+4), (b-6), c1);
    pin((a+4), (b-4), c1);
    pin((a+4), (b-2), c1);
    pin((a+4), b, c1);

    pin((a+6), (b-14), c2);
    pin((a+6), (b-12), c2);
    pin((a+6), (b-10), c1);
    pin((a+6), (b-8), c1);
    pin((a+6), (b-6), c1);
    pin((a+6), (b-4), c1);
    pin((a+6), (b-2), c1);
    pin((a+6), b, c1);

    pin((a+8), (b-14), c1);
    pin((a+8), (b-12), c1);
    pin((a+8), (b-10), c1);
    pin((a+8), (b-8), c1);
    pin((a+8), (b-6), c1);
    pin((a+8), (b-4), c1);

    pin((a+10), (b-14), c1);
    pin((a+10), (b-12), c1);
    pin((a+10), (b-10), c1);
    pin((a+10), (b-8), c2);
    pin((a+10), (b-6), c1);
    pin((a+10), (b-4), c1);
    pin((a+10), (b-2), c2);
    pin((a+10), b, c2);

    pin((a+12), (b-14), c1);
    pin((a+12), (b-12), c1);
    pin((a+12), (b-10), c1);
    pin((a+12), (b-8), c1);
    pin((a+12), (b-6), c1);
    pin((a+12), (b-4), c1);
    pin((a+12), (b-2), c1);
    pin((a+12), b, c1);

    pin((a+14), (b-14), c1);
    pin((a+14), (b-12), c1);
    pin((a+14), (b-10), c1);
    pin((a+14), (b-8), c1);
    pin((a+14), (b-6), c1);
    pin((a+14), (b-4), c1);
    pin((a+14), (b-2), c1);
    pin((a+14), b, c1);

    pin((a+16), (b-2), c1);
    pin((a+16), b, c1);

}

void LetterB(int a, int b, int c1, int c2){
    pin(a, (b-14), c2);
    pin(a, (b-12), c2);
    pin(a, (b-2), c2);
    pin(a, b, c2);

    pin((a+2), (b-14), c1);
    pin((a+2), (b-12), c1);
    pin((a+2), (b-10), c2);
    pin((a+2), (b-8), c2);
    pin((a+2), (b-6), c2);
    pin((a+2), (b-4), c2);
    pin((a+2), (b-2), c1);
    pin((a+2), b, c1);

    pin((a+4), (b-14), c1);
    pin((a+4), (b-12), c1);
    pin((a+4), (b-10), c1);
    pin((a+4), (b-8), c1);
    pin((a+4), (b-6), c1);
    pin((a+4), (b-4), c1);
    pin((a+4), (b-2), c1);
    pin((a+4), b, c1);

    pin((a+6), (b-14), c1);
    pin((a+6), (b-12), c1);
    pin((a+6), (b-10), c1);
    pin((a+6), (b-8), c1);
    pin((a+6), (b-6), c1);
    pin((a+6), (b-4), c1);
    pin((a+6), (b-2), c1);
    pin((a+6), b, c1);

    pin((a+8), (b-14), c1);
    pin((a+8), (b-12), c1);
    pin((a+8), (b-10), c2);
    pin((a+8), (b-8), c1);
    pin((a+8), (b-6), c1);
    pin((a+8), (b-4), c2);
    pin((a+8), (b-2), c1);
    pin((a+8), b, c1);

    pin((a+10), (b-14), c1);
    pin((a+10), (b-12), c1);
    pin((a+10), (b-10), c1);
    pin((a+10), (b-8), c1);
    pin((a+10), (b-6), c1);
    pin((a+10), (b-4), c1);
    pin((a+10), (b-2), c1);
    pin((a+10), b, c1);

    pin((a+12), (b-12), c1);
    pin((a+12), (b-10), c1);
    pin((a+12), (b-8), c1);
    pin((a+12), (b-6), c1);
    pin((a+12), (b-4), c1);
    pin((a+12), (b-2), c1);
    pin((a+12), b, c1);

    pin((a+14), (b-6), c1);
    pin((a+14), (b-4), c1);
    pin((a+14), (b-2), c1);

}

void LetterC(int a, int b, int c1, int c2){

    pin(a, (b-10), c2);
    pin(a, (b-8), c2);
    pin(a, (b-6), c2);
    pin(a, (b-4), c2);

    pin((a+2), (b-12), c2);
    pin((a+2), (b-10), c1);
    pin((a+2), (b-8), c1);
    pin((a+2), (b-6), c1);
    pin((a+2), (b-4), c1);
    pin((a+2), (b-2), c2);

    pin((a+4), (b-14), c2);
    pin((a+4), (b-12), c1);
    pin((a+4), (b-10), c1);
    pin((a+4), (b-8), c1);
    pin((a+4), (b-6), c1);
    pin((a+4), (b-4), c1);
    pin((a+4), (b-2), c1);
    pin((a+4), b, c2);

    pin((a+6), (b-14), c1);
    pin((a+6), (b-12), c1);
    pin((a+6), (b-10), c1);
    pin((a+6), (b-8), c1);
    pin((a+6), (b-6), c1);
    pin((a+6), (b-4), c1);
    pin((a+6), (b-2), c1);
    pin((a+6), b, c1);

    pin((a+8), (b-14), c1);
    pin((a+8), (b-12), c1);
    pin((a+8), (b-10), c1);
    pin((a+8), (b-4), c1);
    pin((a+8), (b-2), c1);
    pin((a+8), b, c1);

    pin((a+10), (b-14), c1);
    pin((a+10), (b-12), c1);
    pin((a+10), (b-10), c2);
    pin((a+10), (b-4), c1);
    pin((a+10), (b-2), c1);
    pin((a+10), b, c1);

    pin((a+12), (b-14), c1);
    pin((a+12), (b-12), c1);
    pin((a+12), (b-10), c1);
    pin((a+12), (b-4), c1);
    pin((a+12), (b-2), c1);
    pin((a+12), b, c1);

    pin((a+14), (b-12), c1);
    pin((a+14), (b-10), c1);
    pin((a+14), (b-4), c1);
    pin((a+14), (b-2), c1);
}

void LetterD(int a, int b, int c1, int c2){
    pin(a, (b-14), c2);
    pin(a, (b-12), c2);
    pin(a, (b-2), c2);
    pin(a, b, c2);

    pin((a+2), (b-14), c1);
    pin((a+2), (b-12), c1);
    pin((a+2), (b-10), c2);
    pin((a+2), (b-8), c2);
    pin((a+2), (b-6), c2);
    pin((a+2), (b-4), c2);
    pin((a+2), (b-2), c1);
    pin((a+2), b, c1);

    pin((a+4), (b-14), c1);
    pin((a+4), (b-12), c1);
    pin((a+4), (b-10), c1);
    pin((a+4), (b-8), c1);
    pin((a+4), (b-6), c1);
    pin((a+4), (b-4), c1);
    pin((a+4), (b-2), c1);
    pin((a+4), b, c1);

    pin((a+6), (b-14), c1);
    pin((a+6), (b-12), c1);
    pin((a+6), (b-10), c1);
    pin((a+6), (b-8), c1);
    pin((a+6), (b-6), c1);
    pin((a+6), (b-4), c1);
    pin((a+6), (b-2), c1);
    pin((a+6), b, c1);

    pin((a+8), (b-14), c1);
    pin((a+8), (b-12), c1);
    pin((a+8), (b-10), c2);
    pin((a+8), (b-8), c2);
    pin((a+8), (b-6), c2);
    pin((a+8), (b-4), c2);
    pin((a+8), (b-2), c1);
    pin((a+8), b, c1);

    pin((a+10), (b-14), c1);
    pin((a+10), (b-12), c1);
    pin((a+10), (b-10), c1);
    pin((a+10), (b-8), c1);
    pin((a+10), (b-6), c1);
    pin((a+10), (b-4), c1);
    pin((a+10), (b-2), c1);
    pin((a+10), b, c1);

    pin((a+12), (b-14), c1);
    pin((a+12), (b-12), c1);
    pin((a+12), (b-10), c1);
    pin((a+12), (b-8), c1);
    pin((a+12), (b-6), c1);
    pin((a+12), (b-4), c1);
    pin((a+12), (b-2), c1);
    pin((a+12), b, c1);

    pin((a+14), (b-12), c1);
    pin((a+14), (b-10), c1);
    pin((a+14), (b-8), c1);
    pin((a+14), (b-6), c1);
    pin((a+14), (b-4), c1);
    pin((a+14), (b-2), c1);

}

void LetterE(int a, int b, int c1, int c2){

    pin(a, (b-14), c2);
    pin(a, (b-12), c2);
    pin(a, (b-2), c2);
    pin(a, b, c2);

    pin((a+2), (b-14), c1);
    pin((a+2), (b-12), c1);
    pin((a+2), (b-10), c2);
    pin((a+2), (b-8), c2);
    pin((a+2), (b-6), c2);
    pin((a+2), (b-4), c2);
    pin((a+2), (b-2), c1);
    pin((a+2), b, c1);

    pin((a+4), (b-14), c1);
    pin((a+4), (b-12), c1);
    pin((a+4), (b-10), c1);
    pin((a+4), (b-8), c1);
    pin((a+4), (b-6), c1);
    pin((a+4), (b-4), c1);
    pin((a+4), (b-2), c1);
    pin((a+4), b, c1);

    pin((a+6), (b-14), c1);
    pin((a+6), (b-12), c1);
    pin((a+6), (b-10), c1);
    pin((a+6), (b-8), c1);
    pin((a+6), (b-6), c1);
    pin((a+6), (b-4), c1);
    pin((a+6), (b-2), c1);
    pin((a+6), b, c1);

    pin((a+8), (b-14), c1);
    pin((a+8), (b-12), c1);
    pin((a+8), (b-8), c1);
    pin((a+8), (b-6), c1);
    pin((a+8), (b-2), c1);
    pin((a+8), b, c1);

    pin((a+10), (b-14), c1);
    pin((a+10), (b-12), c1);
    pin((a+10), (b-8), c1);
    pin((a+10), (b-6), c1);
    pin((a+10), (b-2), c1);
    pin((a+10), b, c1);

    pin((a+10), (b-14), c1);
    pin((a+10), (b-12), c1);
    pin((a+10), (b-2), c1);
    pin((a+10), b, c1);

}

void LetterF(int a, int b, int c1, int c2){

    pin(a, (b-14), c2);
    pin(a, (b-12), c2);

    pin((a+2), (b-14), c1);
    pin((a+2), (b-12), c1);
    pin((a+2), (b-10), c2);
    pin((a+2), (b-8), c2);
    pin((a+2), (b-6), c2);
    pin((a+2), (b-4), c2);
    pin((a+2), (b-2), c2);
    pin((a+2), b, c2);

    pin((a+4), (b-14), c1);
    pin((a+4), (b-12), c1);
    pin((a+4), (b-10), c1);
    pin((a+4), (b-8), c1);
    pin((a+4), (b-6), c1);
    pin((a+4), (b-4), c1);
    pin((a+4), (b-2), c1);
    pin((a+4), b, c1);

    pin((a+6), (b-14), c1);
    pin((a+6), (b-12), c1);
    pin((a+6), (b-10), c1);
    pin((a+6), (b-8), c1);
    pin((a+6), (b-6), c1);
    pin((a+6), (b-4), c1);
    pin((a+6), (b-2), c1);
    pin((a+6), b, c1);

    pin((a+8), (b-14), c1);
    pin((a+8), (b-12), c1);
    pin((a+8), (b-8), c1);
    pin((a+8), (b-6), c1);

    pin((a+10), (b-14), c1);
    pin((a+10), (b-12), c1);
    pin((a+10), (b-8), c1);
    pin((a+10), (b-6), c1);

    pin((a+10), (b-14), c1);
    pin((a+10), (b-12), c1);

}

void LetterG(int a, int b, int c1, int c2){

    pin(a, (b-10), c2);
    pin(a, (b-8), c2);
    pin(a, (b-6), c2);
    pin(a, (b-4), c2);

    pin((a+2), (b-12), c2);
    pin((a+2), (b-10), c1);
    pin((a+2), (b-8), c1);
    pin((a+2), (b-6), c1);
    pin((a+2), (b-4), c1);
    pin((a+2), (b-2), c2);

    pin((a+4), (b-14), c2);
    pin((a+4), (b-12), c1);
    pin((a+4), (b-10), c1);
    pin((a+4), (b-8), c1);
    pin((a+4), (b-6), c1);
    pin((a+4), (b-4), c1);
    pin((a+4), (b-2), c1);
    pin((a+4), b, c2);

    pin((a+6), (b-14), c1);
    pin((a+6), (b-12), c1);
    pin((a+6), (b-10), c1);
    pin((a+6), (b-8), c1);
    pin((a+6), (b-6), c1);
    pin((a+6), (b-4), c1);
    pin((a+6), (b-2), c1);
    pin((a+6), b, c1);

    pin((a+8), (b-14), c1);
    pin((a+8), (b-12), c1);
    pin((a+8), (b-10), c1);
    pin((a+8), (b-6), c2);
    pin((a+8), (b-4), c1);
    pin((a+8), (b-2), c1);
    pin((a+8), b, c1);

    pin((a+10), (b-14), c1);
    pin((a+10), (b-12), c1);
    pin((a+10), (b-10), c2);
    pin((a+10), (b-6), c1);
    pin((a+10), (b-4), c1);
    pin((a+10), (b-2), c1);
    pin((a+10), b, c1);

    pin((a+12), (b-14), c1);
    pin((a+12), (b-12), c1);
    pin((a+12), (b-10), c1);
    pin((a+12), (b-6), c1);
    pin((a+12), (b-4), c1);
    pin((a+12), (b-2), c1);
    pin((a+12), b, c2);

    pin((a+14), (b-12), c1);
    pin((a+14), (b-10), c1);
    pin((a+14), (b-6), c1);
    pin((a+14), (b-4), c1);
    pin((a+14), (b-2), c1);
    pin((a+14), b, c1);
}

void LetterH(int a, int b, int c1, int c2){
    pin(a, (b-14), c2);
    pin(a, (b-12), c2);
    pin(a, (b-10), c2);
    pin(a, (b-8), c2);
    pin(a, (b-6), c2);
    pin(a, (b-4), c2);
    pin(a, (b-2), c2);
    pin(a, b, c2);

    pin((a+2), (b-14), c1);
    pin((a+2), (b-12), c1);
    pin((a+2), (b-10), c1);
    pin((a+2), (b-8), c1);
    pin((a+2), (b-6), c1);
    pin((a+2), (b-4), c1);
    pin((a+2), (b-2), c1);
    pin((a+2), b, c1);

    pin((a+4), (b-14), c1);
    pin((a+4), (b-12), c1);
    pin((a+4), (b-10), c1);
    pin((a+4), (b-8), c1);
    pin((a+4), (b-6), c1);
    pin((a+4), (b-4), c1);
    pin((a+4), (b-2), c1);
    pin((a+4), b, c1);

    pin((a+6), (b-14), c1);
    pin((a+6), (b-12), c1);
    pin((a+6), (b-10), c1);
    pin((a+6), (b-8), c1);
    pin((a+6), (b-6), c1);
    pin((a+6), (b-4), c1);
    pin((a+6), (b-2), c1);
    pin((a+6), b, c1);

    pin((a+8), (b-8), c1);
    pin((a+8), (b-6), c1);

    pin((a+10), (b-14), c2);
    pin((a+10), (b-12), c2);
    pin((a+10), (b-10), c2);
    pin((a+10), (b-8), c1);
    pin((a+10), (b-6), c1);
    pin((a+10), (b-4), c2);
    pin((a+10), (b-2), c2);
    pin((a+10), b, c2);

    pin((a+12), (b-14), c1);
    pin((a+12), (b-12), c1);
    pin((a+12), (b-10), c1);
    pin((a+12), (b-8), c1);
    pin((a+12), (b-6), c1);
    pin((a+12), (b-4), c1);
    pin((a+12), (b-2), c1);
    pin((a+12), b, c1);

    pin((a+14), (b-14), c1);
    pin((a+14), (b-12), c1);
    pin((a+14), (b-10), c1);
    pin((a+14), (b-8), c1);
    pin((a+14), (b-6), c1);
    pin((a+14), (b-4), c1);
    pin((a+14), (b-2), c1);
    pin((a+14), b, c1);
}

void LetterI(int a, int b, int c1, int c2){
    pin(a, (b-14), c2);
    pin(a, (b-12), c2);
    pin(a, (b-10), c2);
    pin(a, (b-8), c2);
    pin(a, (b-6), c2);
    pin(a, (b-4), c2);
    pin(a, (b-2), c2);
    pin(a, b, c2);

    pin((a+2), (b-14), c1);
    pin((a+2), (b-12), c1);
    pin((a+2), (b-10), c1);
    pin((a+2), (b-8), c1);
    pin((a+2), (b-6), c1);
    pin((a+2), (b-4), c1);
    pin((a+2), (b-2), c1);
    pin((a+2), b, c1);

    pin((a+4), (b-14), c1);
    pin((a+4), (b-12), c1);
    pin((a+4), (b-10), c1);
    pin((a+4), (b-8), c1);
    pin((a+4), (b-6), c1);
    pin((a+4), (b-4), c1);
    pin((a+4), (b-2), c1);
    pin((a+4), b, c1);

    pin((a+6), (b-14), c1);
    pin((a+6), (b-12), c1);
    pin((a+6), (b-10), c1);
    pin((a+6), (b-8), c1);
    pin((a+6), (b-6), c1);
    pin((a+6), (b-4), c1);
    pin((a+6), (b-2), c1);
    pin((a+6), b, c1);
}

void LetterJ(int a, int b, int c1, int c2){

    pin(a, (b-4), c2);
    pin(a, (b-2), c2);

    pin((a+2), (b-4), c1);
    pin((a+2), (b-2), c1);
    pin((a+2), b, c2);

    pin((a+4), (b-4), c1);
    pin((a+4), (b-2), c1);
    pin((a+4), b, c1);

    pin((a+6), (b-14), c2);
    pin((a+6), (b-12), c2);
    pin((a+6), (b-10), c2);
    pin((a+6), (b-8), c2);
    pin((a+6), (b-6), c2);
    pin((a+6), (b-4), c2);
    pin((a+6), (b-2), c1);
    pin((a+6), b, c1);

    pin((a+8), (b-14), c1);
    pin((a+8), (b-12), c1);
    pin((a+8), (b-10), c1);
    pin((a+8), (b-8), c1);
    pin((a+8), (b-6), c1);
    pin((a+8), (b-4), c1);
    pin((a+8), (b-2), c1);
    pin((a+8), b, c1);

    pin((a+10), (b-14), c1);
    pin((a+10), (b-12), c1);
    pin((a+10), (b-10), c1);
    pin((a+10), (b-8), c1);
    pin((a+10), (b-6), c1);
    pin((a+10), (b-4), c1);
    pin((a+10), (b-2), c1);
    pin((a+10), b, c1);

    pin((a+12), (b-14), c1);
    pin((a+12), (b-12), c1);
    pin((a+12), (b-10), c1);
    pin((a+12), (b-8), c1);
    pin((a+12), (b-6), c1);
    pin((a+12), (b-4), c1);
    pin((a+12), (b-2), c1);

}

void LetterK(int a, int b, int c1, int c2){
    pin(a, (b-14), c2);
    pin(a, (b-12), c2);
    pin(a, (b-10), c2);
    pin(a, (b-8), c2);
    pin(a, (b-6), c2);
    pin(a, (b-4), c2);
    pin(a, (b-2), c2);
    pin(a, b, c2);

    pin((a+2), (b-14), c1);
    pin((a+2), (b-12), c1);
    pin((a+2), (b-10), c1);
    pin((a+2), (b-8), c1);
    pin((a+2), (b-6), c1);
    pin((a+2), (b-4), c1);
    pin((a+2), (b-2), c1);
    pin((a+2), b, c1);

    pin((a+4), (b-14), c1);
    pin((a+4), (b-12), c1);
    pin((a+4), (b-10), c1);
    pin((a+4), (b-8), c1);
    pin((a+4), (b-6), c1);
    pin((a+4), (b-4), c1);
    pin((a+4), (b-2), c1);
    pin((a+4), b, c1);

    pin((a+6), (b-14), c1);
    pin((a+6), (b-12), c1);
    pin((a+6), (b-10), c1);
    pin((a+6), (b-8), c1);
    pin((a+6), (b-6), c1);
    pin((a+6), (b-4), c1);
    pin((a+6), (b-2), c1);
    pin((a+6), b, c1);

    pin((a+8), (b-12), c2);
    pin((a+8), (b-10), c2);
    pin((a+8), (b-8), c1);
    pin((a+8), (b-6), c1);
    pin((a+8), (b-4), c2);
    pin((a+8), (b-2), c2);

    pin((a+10), (b-14), c2);
    pin((a+10), (b-12), c1);
    pin((a+10), (b-10), c1);
    pin((a+10), (b-8), c1);
    pin((a+10), (b-6), c1);
    pin((a+10), (b-4), c1);
    pin((a+10), (b-2), c1);
    pin((a+10), b, c2);

    pin((a+12), (b-14), c1);
    pin((a+12), (b-12), c1);
    pin((a+12), (b-10), c1);
    pin((a+12), (b-8), c1);
    pin((a+12), (b-6), c1);
    pin((a+12), (b-4), c1);
    pin((a+12), (b-2), c1);
    pin((a+12), b, c1);

    pin((a+14), (b-14), c1);
    pin((a+14), (b-12), c1);
    pin((a+14), (b-10), c1);
    pin((a+14), (b-6), c1);
    pin((a+14), (b-4), c1);
    pin((a+14), (b-2), c1);
    pin((a+14), b, c1);

    pin((a+16), (b-14), c1);
    pin((a+16), (b-12), c1);
    pin((a+16), (b-4), c1);
    pin((a+16), (b-2), c1);
    pin((a+16), b, c1);

}

void LetterL(int a, int b, int c1, int c2){
    pin(a, (b-14), c2);
    pin(a, (b-12), c2);
    pin(a, (b-10), c2);
    pin(a, (b-8), c2);
    pin(a, (b-6), c2);
    pin(a, (b-4), c2);
    pin(a, (b-2), c2);
    pin(a, b, c2);

    pin((a+2), (b-14), c1);
    pin((a+2), (b-12), c1);
    pin((a+2), (b-10), c1);
    pin((a+2), (b-8), c1);
    pin((a+2), (b-6), c1);
    pin((a+2), (b-4), c1);
    pin((a+2), (b-2), c1);
    pin((a+2), b, c1);

    pin((a+4), (b-14), c1);
    pin((a+4), (b-12), c1);
    pin((a+4), (b-10), c1);
    pin((a+4), (b-8), c1);
    pin((a+4), (b-6), c1);
    pin((a+4), (b-4), c1);
    pin((a+4), (b-2), c1);
    pin((a+4), b, c1);

    pin((a+6), (b-14), c1);
    pin((a+6), (b-12), c1);
    pin((a+6), (b-10), c1);
    pin((a+6), (b-8), c1);
    pin((a+6), (b-6), c1);
    pin((a+6), (b-4), c1);
    pin((a+6), (b-2), c1);
    pin((a+6), b, c1);

    pin((a+8), (b-4), c1);
    pin((a+8), (b-2), c1);
    pin((a+8), b, c1);

    pin((a+10), (b-4), c1);
    pin((a+10), (b-2), c1);
    pin((a+10), b, c1);

}

void LetterM(int a, int b, int c1, int c2){
    pin(a, (b-14), c2);
    pin(a, (b-12), c2);
    pin(a, (b-10), c2);
    pin(a, (b-8), c2);
    pin(a, (b-6), c2);
    pin(a, (b-4), c2);
    pin(a, (b-2), c2);
    pin(a, b, c2);

    pin((a+2), (b-14), c1);
    pin((a+2), (b-12), c1);
    pin((a+2), (b-10), c1);
    pin((a+2), (b-8), c1);
    pin((a+2), (b-6), c1);
    pin((a+2), (b-4), c1);
    pin((a+2), (b-2), c1);
    pin((a+2), b, c1);

    pin((a+4), (b-14), c1);
    pin((a+4), (b-12), c1);
    pin((a+4), (b-10), c1);
    pin((a+4), (b-8), c1);
    pin((a+4), (b-6), c1);
    pin((a+4), (b-4), c1);
    pin((a+4), (b-2), c1);
    pin((a+4), b, c1);

    pin((a+6), (b-14), c1);
    pin((a+6), (b-12), c1);
    pin((a+6), (b-10), c1);
    pin((a+6), (b-8), c1);
    pin((a+6), (b-6), c1);
    pin((a+6), (b-4), c1);
    pin((a+6), (b-2), c1);
    pin((a+6), b, c1);

    pin((a+8), (b-12), c1);
    pin((a+8), (b-10), c1);
    pin((a+8), (b-8), c1);
    pin((a+8), (b-6), c2);

    pin((a+10), (b-12), c2);
    pin((a+10), (b-10), c1);
    pin((a+10), (b-8), c1);
    pin((a+10), (b-6), c1);

    pin((a+12), (b-14), c2);
    pin((a+12), (b-12), c1);
    pin((a+12), (b-10), c1);
    pin((a+12), (b-8), c1);
    pin((a+12), (b-6), c2);
    pin((a+12), (b-4), c2);
    pin((a+12), (b-2), c2);
    pin((a+12), b, c2);

    pin((a+14), (b-14), c1);
    pin((a+14), (b-12), c1);
    pin((a+14), (b-10), c1);
    pin((a+14), (b-8), c1);
    pin((a+14), (b-6), c1);
    pin((a+14), (b-4), c1);
    pin((a+14), (b-2), c1);
    pin((a+14), b, c1);

    pin((a+16), (b-14), c1);
    pin((a+16), (b-12), c1);
    pin((a+16), (b-10), c1);
    pin((a+16), (b-8), c1);
    pin((a+16), (b-6), c1);
    pin((a+16), (b-4), c1);
    pin((a+16), (b-2), c1);
    pin((a+16), b, c1);

    pin((a+18), (b-14), c1);
    pin((a+18), (b-12), c1);
    pin((a+18), (b-10), c1);
    pin((a+18), (b-8), c1);
    pin((a+18), (b-6), c1);
    pin((a+18), (b-4), c1);
    pin((a+18), (b-2), c1);
    pin((a+18), b, c1);

}

void LetterN(int a, int b, int c1, int c2){
    pin(a, (b-14), c2);
    pin(a, (b-12), c2);
    pin(a, (b-10), c2);
    pin(a, (b-8), c2);
    pin(a, (b-6), c2);
    pin(a, (b-4), c2);
    pin(a, (b-2), c2);
    pin(a, b, c2);

    pin((a+2), (b-14), c1);
    pin((a+2), (b-12), c1);
    pin((a+2), (b-10), c1);
    pin((a+2), (b-8), c1);
    pin((a+2), (b-6), c1);
    pin((a+2), (b-4), c1);
    pin((a+2), (b-2), c1);
    pin((a+2), b, c1);

    pin((a+4), (b-14), c1);
    pin((a+4), (b-12), c1);
    pin((a+4), (b-10), c1);
    pin((a+4), (b-8), c1);
    pin((a+4), (b-6), c1);
    pin((a+4), (b-4), c1);
    pin((a+4), (b-2), c1);
    pin((a+4), b, c1);

    pin((a+6), (b-14), c1);
    pin((a+6), (b-12), c1);
    pin((a+6), (b-10), c1);
    pin((a+6), (b-8), c1);
    pin((a+6), (b-6), c1);
    pin((a+6), (b-4), c1);
    pin((a+6), (b-2), c1);
    pin((a+6), b, c1);

    pin((a+8), (b-14), c1);
    pin((a+8), (b-12), c1);
    pin((a+8), (b-10), c1);
    pin((a+8), (b-8), c2);
    pin((a+8), (b-6), c2);
    pin((a+8), (b-4), c2);
    pin((a+8), (b-2), c2);
    pin((a+8), b, c2);

    pin((a+10), (b-14), c1);
    pin((a+10), (b-12), c1);
    pin((a+10), (b-10), c1);
    pin((a+10), (b-8), c1);
    pin((a+10), (b-6), c1);
    pin((a+10), (b-4), c1);
    pin((a+10), (b-2), c1);
    pin((a+10), b, c1);

    pin((a+12), (b-14), c1);
    pin((a+12), (b-12), c1);
    pin((a+12), (b-10), c1);
    pin((a+12), (b-8), c1);
    pin((a+12), (b-6), c1);
    pin((a+12), (b-4), c1);
    pin((a+12), (b-2), c1);
    pin((a+12), b, c1);

    pin((a+14), (b-12), c1);
    pin((a+14), (b-10), c1);
    pin((a+14), (b-8), c1);
    pin((a+14), (b-6), c1);
    pin((a+14), (b-4), c1);
    pin((a+14), (b-2), c1);
    pin((a+14), b, c1);

}

void LetterO(int a, int b, int c1, int c2){

    pin(a, (b-12), c2);
    pin(a, (b-10), c2);
    pin(a, (b-8), c2);
    pin(a, (b-6), c2);
    pin(a, (b-4), c2);
    pin(a, (b-2), c2);

    pin((a+2), (b-14), c2);
    pin((a+2), (b-12), c1);
    pin((a+2), (b-10), c1);
    pin((a+2), (b-8), c1);
    pin((a+2), (b-6), c1);
    pin((a+2), (b-4), c1);
    pin((a+2), (b-2), c1);
    pin((a+2), b, c2);

    pin((a+4), (b-14), c1);
    pin((a+4), (b-12), c1);
    pin((a+4), (b-10), c1);
    pin((a+4), (b-8), c1);
    pin((a+4), (b-6), c1);
    pin((a+4), (b-4), c1);
    pin((a+4), (b-2), c1);
    pin((a+4), b, c1);

    pin((a+6), (b-14), c1);
    pin((a+6), (b-12), c1);
    pin((a+6), (b-10), c1);
    pin((a+6), (b-8), c1);
    pin((a+6), (b-6), c1);
    pin((a+6), (b-4), c1);
    pin((a+6), (b-2), c1);
    pin((a+6), b, c1);

    pin((a+8), (b-14), c1);
    pin((a+8), (b-12), c1);
    pin((a+8), (b-10), c2);
    pin((a+8), (b-8), c2);
    pin((a+8), (b-6), c2);
    pin((a+8), (b-4), c2);
    pin((a+8), (b-2), c1);
    pin((a+8), b, c1);

    pin((a+10), (b-14), c1);
    pin((a+10), (b-12), c1);
    pin((a+10), (b-10), c1);
    pin((a+10), (b-8), c1);
    pin((a+10), (b-6), c1);
    pin((a+10), (b-4), c1);
    pin((a+10), (b-2), c1);
    pin((a+10), b, c1);

    pin((a+12), (b-14), c1);
    pin((a+12), (b-12), c1);
    pin((a+12), (b-10), c1);
    pin((a+12), (b-8), c1);
    pin((a+12), (b-6), c1);
    pin((a+12), (b-4), c1);
    pin((a+12), (b-2), c1);
    pin((a+12), b, c1);

    pin((a+14), (b-12), c1);
    pin((a+14), (b-10), c1);
    pin((a+14), (b-8), c1);
    pin((a+14), (b-6), c1);
    pin((a+14), (b-4), c1);
    pin((a+14), (b-2), c1);

}

void LetterP(int a, int b, int c1, int c2){

    pin(a, (b-14), c2);
    pin(a, (b-12), c2);

    pin((a+2), (b-14), c1);
    pin((a+2), (b-12), c1);
    pin((a+2), (b-10), c2);
    pin((a+2), (b-8), c2);
    pin((a+2), (b-6), c2);
    pin((a+2), (b-4), c2);
    pin((a+2), (b-2), c2);
    pin((a+2), b, c2);

    pin((a+4), (b-14), c1);
    pin((a+4), (b-12), c1);
    pin((a+4), (b-10), c1);
    pin((a+4), (b-8), c1);
    pin((a+4), (b-6), c1);
    pin((a+4), (b-4), c1);
    pin((a+4), (b-2), c1);
    pin((a+4), b, c1);

    pin((a+6), (b-14), c1);
    pin((a+6), (b-12), c1);
    pin((a+6), (b-10), c1);
    pin((a+6), (b-8), c1);
    pin((a+6), (b-6), c1);
    pin((a+6), (b-4), c1);
    pin((a+6), (b-2), c1);
    pin((a+6), b, c1);

    pin((a+8), (b-14), c1);
    pin((a+8), (b-12), c1);
    pin((a+8), (b-10), c2);
    pin((a+8), (b-8), c2);
    pin((a+8), (b-6), c1);
    pin((a+8), (b-4), c1);

    pin((a+10), (b-14), c1);
    pin((a+10), (b-12), c1);
    pin((a+10), (b-10), c1);
    pin((a+10), (b-8), c1);
    pin((a+10), (b-6), c1);
    pin((a+10), (b-4), c1);

    pin((a+12), (b-12), c1);
    pin((a+12), (b-10), c1);
    pin((a+12), (b-8), c1);
    pin((a+12), (b-6), c1);
    pin((a+12), (b-4), c1);

    pin((a+14), (b-12), c1);
    pin((a+14), (b-10), c1);
    pin((a+14), (b-8), c1);
    pin((a+14), (b-6), c1);
}

void LetterR(int a, int b, int c1, int c2){

    pin(a, (b-14), c2);
    pin(a, (b-12), c2);

    pin((a+2), (b-14), c1);
    pin((a+2), (b-12), c1);
    pin((a+2), (b-10), c2);
    pin((a+2), (b-8), c2);
    pin((a+2), (b-6), c2);
    pin((a+2), (b-4), c2);
    pin((a+2), (b-2), c2);
    pin((a+2), b, c2);

    pin((a+4), (b-14), c1);
    pin((a+4), (b-12), c1);
    pin((a+4), (b-10), c1);
    pin((a+4), (b-8), c1);
    pin((a+4), (b-6), c1);
    pin((a+4), (b-4), c1);
    pin((a+4), (b-2), c1);
    pin((a+4), b, c1);

    pin((a+6), (b-14), c1);
    pin((a+6), (b-12), c1);
    pin((a+6), (b-10), c1);
    pin((a+6), (b-8), c1);
    pin((a+6), (b-6), c1);
    pin((a+6), (b-4), c1);
    pin((a+6), (b-2), c1);
    pin((a+6), b, c1);

    pin((a+8), (b-14), c1);
    pin((a+8), (b-12), c1);
    pin((a+8), (b-10), c2);
    pin((a+8), (b-8), c2);
    pin((a+8), (b-6), c1);
    pin((a+8), (b-4), c1);
    pin((a+8), (b-2), c2);

    pin((a+10), (b-14), c1);
    pin((a+10), (b-12), c1);
    pin((a+10), (b-10), c1);
    pin((a+10), (b-8), c1);
    pin((a+10), (b-6), c1);
    pin((a+10), (b-4), c1);
    pin((a+10), (b-2), c1);
    pin((a+10), b, c2);

    pin((a+12), (b-14), c1);
    pin((a+12), (b-12), c1);
    pin((a+12), (b-10), c1);
    pin((a+12), (b-8), c1);
    pin((a+12), (b-6), c1);
    pin((a+12), (b-4), c1);
    pin((a+12), (b-2), c1);
    pin((a+12), b, c1);

    pin((a+14), (b-12), c1);
    pin((a+14), (b-10), c1);
    pin((a+14), (b-8), c1);
    pin((a+14), (b-4), c1);
    pin((a+14), (b-2), c1);
    pin((a+14), b, c1);
}

void LetterS(int a, int b, int c1, int c2){

    pin(a, (b-12), c2);
    pin(a, (b-10), c2);
    pin(a, (b-4), c2);
    pin(a, (b-2), c2);

    pin((a+2), (b-14), c2);
    pin((a+2), (b-12), c1);
    pin((a+2), (b-10), c1);
    pin((a+2), (b-8), c2);
    pin((a+2), (b-4), c1);
    pin((a+2), (b-2), c1);
    pin((a+2), b, c2);

    pin((a+4), (b-14), c1);
    pin((a+4), (b-12), c1);
    pin((a+4), (b-10), c1);
    pin((a+4), (b-8), c1);
    pin((a+4), (b-6), c2);
    pin((a+4), (b-4), c1);
    pin((a+4), (b-2), c1);
    pin((a+4), b, c1);

    pin((a+6), (b-14), c1);
    pin((a+6), (b-12), c1);
    pin((a+6), (b-10), c2);
    pin((a+6), (b-8), c1);
    pin((a+6), (b-6), c1);
    pin((a+6), (b-4), c1);
    pin((a+6), (b-2), c1);
    pin((a+6), b, c1);

    pin((a+8), (b-14), c1);
    pin((a+8), (b-12), c1);
    pin((a+8), (b-10), c2);
    pin((a+8), (b-8), c1);
    pin((a+8), (b-6), c1);
    pin((a+8), (b-4), c1);
    pin((a+8), (b-2), c1);
    pin((a+8), b, c1);

    pin((a+10), (b-14), c1);
    pin((a+10), (b-12), c1);
    pin((a+10), (b-10), c1);
    pin((a+10), (b-8), c2);
    pin((a+10), (b-6), c1);
    pin((a+10), (b-4), c1);
    pin((a+10), (b-2), c1);
    pin((a+10), b, c1);

    pin((a+12), (b-14), c1);
    pin((a+12), (b-12), c1);
    pin((a+12), (b-10), c1);
    pin((a+12), (b-8), c1);
    pin((a+12), (b-6), c1);
    pin((a+12), (b-4), c1);
    pin((a+12), (b-2), c1);
    pin((a+12), b, c1);

    pin((a+14), (b-12), c1);
    pin((a+14), (b-10), c1);
    pin((a+14), (b-6), c1);
    pin((a+14), (b-4), c1);
    pin((a+14), (b-2), c1);

}

void LetterT(int a, int b, int c1, int c2){

    pin(a, (b-14), c2);
    pin(a, (b-12), c2);

    pin((a+2), (b-14), c1);
    pin((a+2), (b-12), c1);

    pin((a+4), (b-14), c1);
    pin((a+4), (b-12), c1);
    pin((a+4), (b-10), c2);
    pin((a+4), (b-8), c2);
    pin((a+4), (b-6), c2);
    pin((a+4), (b-4), c2);
    pin((a+4), (b-2), c2);
    pin((a+4), b, c2);

    pin((a+6), (b-14), c1);
    pin((a+6), (b-12), c1);
    pin((a+6), (b-10), c1);
    pin((a+6), (b-8), c1);
    pin((a+6), (b-6), c1);
    pin((a+6), (b-4), c1);
    pin((a+6), (b-2), c1);
    pin((a+6), b, c1);

    pin((a+8), (b-14), c1);
    pin((a+8), (b-12), c1);
    pin((a+8), (b-10), c1);
    pin((a+8), (b-8), c1);
    pin((a+8), (b-6), c1);
    pin((a+8), (b-4), c1);
    pin((a+8), (b-2), c1);
    pin((a+8), b, c1);

    pin((a+10), (b-14), c1);
    pin((a+10), (b-12), c1);
    pin((a+10), (b-8), c1);
    pin((a+10), (b-6), c1);
    pin((a+10), (b-6), c1);
    pin((a+10), (b-4), c1);
    pin((a+10), (b-2), c1);
    pin((a+10), b, c1);

    pin((a+12), (b-14), c1);
    pin((a+12), (b-12), c1);

    pin((a+14), (b-14), c1);
    pin((a+14), (b-12), c1);

}

void LetterU(int a, int b, int c1, int c2){

    pin(a, (b-14), c2);
    pin(a, (b-12), c2);
    pin(a, (b-10), c2);
    pin(a, (b-8), c2);
    pin(a, (b-6), c2);
    pin(a, (b-4), c2);
    pin(a, (b-2), c2);

    pin((a+2), (b-14), c1);
    pin((a+2), (b-12), c1);
    pin((a+2), (b-10), c1);
    pin((a+2), (b-8), c1);
    pin((a+2), (b-6), c1);
    pin((a+2), (b-4), c1);
    pin((a+2), (b-2), c1);
    pin((a+2), b, c2);

    pin((a+4), (b-14), c1);
    pin((a+4), (b-12), c1);
    pin((a+4), (b-10), c1);
    pin((a+4), (b-8), c1);
    pin((a+4), (b-6), c1);
    pin((a+4), (b-4), c1);
    pin((a+4), (b-2), c1);
    pin((a+4), b, c1);

    pin((a+6), (b-14), c1);
    pin((a+6), (b-12), c1);
    pin((a+6), (b-10), c1);
    pin((a+6), (b-8), c1);
    pin((a+6), (b-6), c1);
    pin((a+6), (b-4), c1);
    pin((a+6), (b-2), c1);
    pin((a+6), b, c1);

    pin((a+8), (b-14), c2);
    pin((a+8), (b-12), c2);
    pin((a+8), (b-10), c2);
    pin((a+8), (b-8), c2);
    pin((a+8), (b-6), c2);
    pin((a+8), (b-4), c2);
    pin((a+8), (b-2), c1);
    pin((a+8), b, c1);

    pin((a+10), (b-14), c1);
    pin((a+10), (b-12), c1);
    pin((a+10), (b-10), c1);
    pin((a+10), (b-8), c1);
    pin((a+10), (b-6), c1);
    pin((a+10), (b-4), c1);
    pin((a+10), (b-2), c1);
    pin((a+10), b, c1);

    pin((a+12), (b-14), c1);
    pin((a+12), (b-12), c1);
    pin((a+12), (b-10), c1);
    pin((a+12), (b-8), c1);
    pin((a+12), (b-6), c1);
    pin((a+12), (b-4), c1);
    pin((a+12), (b-2), c1);

}

void LetterY(int a, int b, int c1, int c2){

    pin(a, (b-14), c2);
    pin(a, (b-12), c2);
    pin(a, (b-10), c2);

    pin((a+2), (b-14), c1);
    pin((a+2), (b-12), c1);
    pin((a+2), (b-10), c1);
    pin((a+2), (b-8), c2);

    pin((a+4), (b-14), c1);
    pin((a+4), (b-12), c1);
    pin((a+4), (b-10), c1);
    pin((a+4), (b-8), c1);
    pin((a+4), (b-6), c2);
    pin((a+4), (b-4), c2);
    pin((a+4), (b-2), c2);
    pin((a+4), b, c2);

    pin((a+6), (b-14), c1);
    pin((a+6), (b-12), c1);
    pin((a+6), (b-10), c1);
    pin((a+6), (b-8), c1);
    pin((a+6), (b-6), c1);
    pin((a+6), (b-4), c1);
    pin((a+6), (b-2), c1);
    pin((a+6), b, c1);

    pin((a+8), (b-14), c2);
    pin((a+8), (b-12), c2);
    pin((a+8), (b-10), c2);
    pin((a+8), (b-8), c1);
    pin((a+8), (b-6), c1);
    pin((a+8), (b-4), c1);
    pin((a+8), (b-2), c1);
    pin((a+8), b, c1);

    pin((a+10), (b-14), c1);
    pin((a+10), (b-12), c1);
    pin((a+10), (b-10), c1);
    pin((a+10), (b-8), c1);
    pin((a+10), (b-6), c1);
    pin((a+10), (b-4), c1);
    pin((a+10), (b-2), c1);
    pin((a+10), b, c1);

    pin((a+12), (b-14), c1);
    pin((a+12), (b-12), c1);
    pin((a+12), (b-10), c1);
    pin((a+12), (b-8), c1);

    pin((a+14), (b-14), c1);
    pin((a+14), (b-12), c1);
    pin((a+14), (b-10), c1);
}

void Number0(int a, int b, int c){
        pin(a, (b-12), c);
        pin(a, (b-10), c);
        pin(a, (b-8), c);
        pin(a, (b-6), c);
        pin(a, (b-4), c);
        pin(a, (b-2), c);

        pin((a+2), (b-14), c);
        pin((a+2), (b-12), c);
        pin((a+2), (b-10), c);
        pin((a+2), (b-8), c);
        pin((a+2), (b-6), c);
        pin((a+2), (b-4), c);
        pin((a+2), (b-2), c);
        pin((a+2), b, c);

        pin((a+4), (b-14), c);
        pin((a+4), (b-12), c);
        pin((a+4), (b-2), c);
        pin((a+4), b, c);

        pin((a+6), (b-14), c);
        pin((a+6), (b-12), c);
        pin((a+6), (b-2), c);
        pin((a+6), b, c);

        pin((a+8), (b-14), c);
        pin((a+8), (b-12), c);
        pin((a+8), (b-10), c);
        pin((a+8), (b-8), c);
        pin((a+8), (b-6), c);
        pin((a+8), (b-4), c);
        pin((a+8), (b-2), c);
        pin((a+8), b, c);

        pin((a+10), (b-12), c);
        pin((a+10), (b-10), c);
        pin((a+10), (b-8), c);
        pin((a+10), (b-6), c);
        pin((a+10), (b-4), c);
        pin((a+10), (b-2), c);
}

void Number1(int a, int b, int c){
        pin(a, (b-14), c);
        pin(a, (b-12), c);

        pin((a+2), (b-14), c);
        pin((a+2), (b-12), c);
        pin((a+2), (b-10), c);
        pin((a+2), (b-8), c);
        pin((a+2), (b-6), c);
        pin((a+2), (b-4), c);
        pin((a+2), (b-2), c);
        pin((a+2), b, c);

        pin((a+4), (b-14), c);
        pin((a+4), (b-12), c);
        pin((a+4), (b-10), c);
        pin((a+4), (b-8), c);
        pin((a+4), (b-6), c);
        pin((a+4), (b-4), c);
        pin((a+4), (b-2), c);
        pin((a+4), b, c);

}

void Number2(int a, int b, int c){
        pin(a, (b-14), c);
        pin(a, (b-12), c);
        pin(a, (b-8), c);
        pin(a, (b-6), c);
        pin(a, (b-4), c);
        pin(a, (b-2), c);
        pin(a, b, c);

        pin((a+2), (b-14), c);
        pin((a+2), (b-12), c);
        pin((a+2), (b-8), c);
        pin((a+2), (b-6), c);
        pin((a+2), (b-4), c);
        pin((a+2), (b-2), c);
        pin((a+2), b, c);

        pin((a+4), (b-14), c);
        pin((a+4), (b-12), c);
        pin((a+4), (b-8), c);
        pin((a+4), (b-6), c);
        pin((a+4), (b-2), c);
        pin((a+4), b, c);

        pin((a+6), (b-14), c);
        pin((a+6), (b-12), c);
        pin((a+6), (b-8), c);
        pin((a+6), (b-6), c);
        pin((a+6), (b-2), c);
        pin((a+6), b, c);

        pin((a+8), (b-14), c);
        pin((a+8), (b-12), c);
        pin((a+8), (b-8), c);
        pin((a+8), (b-6), c);
        pin((a+8), (b-2), c);
        pin((a+8), b, c);

        pin((a+10), (b-14), c);
        pin((a+10), (b-12), c);
        pin((a+10), (b-10), c);
        pin((a+10), (b-8), c);
        pin((a+10), (b-6), c);
        pin((a+10), (b-2), c);
        pin((a+10), b, c);

        pin((a+12), (b-14), c);
        pin((a+12), (b-12), c);
        pin((a+12), (b-10), c);
        pin((a+12), (b-8), c);
        pin((a+12), (b-6), c);
        pin((a+12), (b-2), c);
        pin((a+12), b, c);
}

void Number3(int a, int b, int c){
        pin(a, (b-14), c);
        pin(a, (b-12), c);
        pin(a, (b-8), c);
        pin(a, (b-6), c);
        pin(a, (b-2), c);
        pin(a, b, c);

        pin((a+2), (b-14), c);
        pin((a+2), (b-12), c);
        pin((a+2), (b-8), c);
        pin((a+2), (b-6), c);
        pin((a+2), (b-2), c);
        pin((a+2), b, c);

        pin((a+4), (b-14), c);
        pin((a+4), (b-12), c);
        pin((a+4), (b-8), c);
        pin((a+4), (b-6), c);
        pin((a+4), (b-2), c);
        pin((a+4), b, c);

        pin((a+6), (b-14), c);
        pin((a+6), (b-12), c);
        pin((a+6), (b-8), c);
        pin((a+6), (b-6), c);
        pin((a+6), (b-2), c);
        pin((a+6), b, c);

        pin((a+8), (b-14), c);
        pin((a+8), (b-12), c);
        pin((a+8), (b-10), c);
        pin((a+8), (b-8), c);
        pin((a+8), (b-6), c);
        pin((a+8), (b-4), c);
        pin((a+8), (b-2), c);
        pin((a+8), b, c);

        pin((a+10), (b-14), c);
        pin((a+10), (b-12), c);
        pin((a+10), (b-10), c);
        pin((a+10), (b-8), c);
        pin((a+10), (b-6), c);
        pin((a+10), (b-4), c);
        pin((a+10), (b-2), c);
        pin((a+10), b, c);
}

void Number4(int a, int b, int c){
        pin(a, (b-14), c);
        pin(a, (b-12), c);
        pin(a, (b-10), c);
        pin(a, (b-8), c);
        pin(a, (b-6), c);

        pin((a+2), (b-14), c);
        pin((a+2), (b-12), c);
        pin((a+2), (b-10), c);
        pin((a+2), (b-8), c);
        pin((a+2), (b-6), c);

        pin((a+4), (b-8), c);
        pin((a+4), (b-6), c);

        pin((a+6), (b-8), c);
        pin((a+6), (b-6), c);

        pin((a+8), (b-14), c);
        pin((a+8), (b-12), c);
        pin((a+8), (b-10), c);
        pin((a+8), (b-8), c);
        pin((a+8), (b-6), c);
        pin((a+8), (b-4), c);
        pin((a+8), (b-2), c);
        pin((a+8), b, c);

        pin((a+10), (b-14), c);
        pin((a+10), (b-12), c);
        pin((a+10), (b-10), c);
        pin((a+10), (b-8), c);
        pin((a+10), (b-6), c);
        pin((a+10), (b-2), c);
        pin((a+10), (b-2), c);
        pin((a+10), b, c);

}

void Number5(int a, int b, int c){
        pin(a, (b-14), c);
        pin(a, (b-12), c);
        pin(a, (b-10), c);
        pin(a, (b-8), c);
        pin(a, (b-6), c);
        pin(a, (b-2), c);
        pin(a, b, c);

        pin((a+2), (b-14), c);
        pin((a+2), (b-12), c);
        pin((a+2), (b-10), c);
        pin((a+2), (b-8), c);
        pin((a+2), (b-6), c);
        pin((a+2), (b-2), c);
        pin((a+2), b, c);

        pin((a+4), (b-14), c);
        pin((a+4), (b-12), c);
        pin((a+4), (b-8), c);
        pin((a+4), (b-6), c);
        pin((a+4), (b-2), c);
        pin((a+4), b, c);

        pin((a+6), (b-14), c);
        pin((a+6), (b-12), c);
        pin((a+6), (b-8), c);
        pin((a+6), (b-6), c);
        pin((a+6), (b-2), c);
        pin((a+6), b, c);

        pin((a+8), (b-14), c);
        pin((a+8), (b-12), c);
        pin((a+8), (b-8), c);
        pin((a+8), (b-6), c);
        pin((a+8), (b-2), c);
        pin((a+8), b, c);

        pin((a+10), (b-14), c);
        pin((a+10), (b-12), c);

        pin((a+10), (b-8), c);
        pin((a+10), (b-6), c);
        pin((a+10), (b-4), c);
        pin((a+10), (b-2), c);
        pin((a+10), b, c);

        pin((a+12), (b-14), c);
        pin((a+12), (b-12), c);
        pin((a+12), (b-8), c);
        pin((a+12), (b-6), c);
        pin((a+12), (b-4), c);
        pin((a+12), (b-2), c);
        pin((a+12), b, c);
}

void Number6(int a, int b, int c){
        pin(a, (b-14), c);
        pin(a, (b-12), c);
        pin(a, (b-10), c);
        pin(a, (b-8), c);
        pin(a, (b-6), c);
        pin(a, (b-4), c);
        pin(a, (b-2), c);
        pin(a, b, c);

        pin((a+2), (b-14), c);
        pin((a+2), (b-12), c);
        pin((a+2), (b-10), c);
        pin((a+2), (b-8), c);
        pin((a+2), (b-6), c);
        pin((a+2), (b-4), c);
        pin((a+2), (b-2), c);
        pin((a+2), b, c);

        pin((a+4), (b-14), c);
        pin((a+4), (b-12), c);
        pin((a+4), (b-8), c);
        pin((a+4), (b-6), c);
        pin((a+4), (b-2), c);
        pin((a+4), b, c);

        pin((a+6), (b-14), c);
        pin((a+6), (b-12), c);
        pin((a+6), (b-8), c);
        pin((a+6), (b-6), c);
        pin((a+6), (b-2), c);
        pin((a+6), b, c);

        pin((a+8), (b-14), c);
        pin((a+8), (b-12), c);
        pin((a+8), (b-8), c);
        pin((a+8), (b-6), c);
        pin((a+8), (b-4), c);
        pin((a+8), (b-2), c);
        pin((a+8), b, c);

        pin((a+10), (b-14), c);
        pin((a+10), (b-12), c);
        pin((a+10), (b-8), c);
        pin((a+10), (b-6), c);
        pin((a+10), (b-4), c);
        pin((a+10), (b-2), c);
        pin((a+10), b, c);

}

void Number7(int a, int b, int c){
        pin(a, (b-14), c);
        pin(a, (b-12), c);

        pin((a+2), (b-14), c);
        pin((a+2), (b-12), c);

        pin((a+4), (b-14), c);
        pin((a+4), (b-12), c);

        pin((a+6), (b-14), c);
        pin((a+6), (b-12), c);

        pin((a+8), (b-14), c);
        pin((a+8), (b-12), c);
        pin((a+8), (b-10), c);
        pin((a+8), (b-8), c);
        pin((a+8), (b-6), c);
        pin((a+8), (b-4), c);
        pin((a+8), (b-2), c);
        pin((a+8), b, c);

        pin((a+10), (b-14), c);
        pin((a+10), (b-12), c);
        pin((a+10), (b-10), c);
        pin((a+10), (b-8), c);
        pin((a+10), (b-6), c);
        pin((a+10), (b-4), c);
        pin((a+10), (b-2), c);
        pin((a+10), b, c);
}

void Number8(int a, int b, int c){
        pin(a, (b-14), c);
        pin(a, (b-12), c);
        pin(a, (b-10), c);
        pin(a, (b-8), c);
        pin(a, (b-6), c);
        pin(a, (b-4), c);
        pin(a, (b-2), c);
        pin(a, b, c);

        pin((a+2), (b-14), c);
        pin((a+2), (b-12), c);
        pin((a+2), (b-10), c);
        pin((a+2), (b-8), c);
        pin((a+2), (b-6), c);
        pin((a+2), (b-4), c);
        pin((a+2), (b-2), c);
        pin((a+2), b, c);

        pin((a+4), (b-14), c);
        pin((a+4), (b-12), c);
        pin((a+4), (b-8), c);
        pin((a+4), (b-6), c);
        pin((a+4), (b-2), c);
        pin((a+4), b, c);

        pin((a+6), (b-14), c);
        pin((a+6), (b-12), c);
        pin((a+6), (b-8), c);
        pin((a+6), (b-6), c);
        pin((a+6), (b-2), c);
        pin((a+6), b, c);

        pin((a+8), (b-14), c);
        pin((a+8), (b-12), c);
        pin((a+8), (b-10), c);
        pin((a+8), (b-8), c);
        pin((a+8), (b-6), c);
        pin((a+8), (b-4), c);
        pin((a+8), (b-2), c);
        pin((a+8), b, c);

        pin((a+10), (b-14), c);
        pin((a+10), (b-12), c);
        pin((a+10), (b-10), c);
        pin((a+10), (b-8), c);
        pin((a+10), (b-6), c);
        pin((a+10), (b-4), c);
        pin((a+10), (b-2), c);
        pin((a+10), b, c);
}

void Number9(int a, int b, int c){
        pin(a, (b-14), c);
        pin(a, (b-12), c);
        pin(a, (b-10), c);
        pin(a, (b-8), c);
        pin(a, (b-6), c);

        pin((a+2), (b-14), c);
        pin((a+2), (b-12), c);
        pin((a+2), (b-10), c);
        pin((a+2), (b-8), c);
        pin((a+2), (b-6), c);

        pin((a+4), (b-14), c);
        pin((a+4), (b-12), c);
        pin((a+4), (b-8), c);
        pin((a+4), (b-6), c);

        pin((a+6), (b-14), c);
        pin((a+6), (b-12), c);
        pin((a+6), (b-8), c);
        pin((a+6), (b-6), c);

        pin((a+8), (b-14), c);
        pin((a+8), (b-12), c);
        pin((a+8), (b-10), c);
        pin((a+8), (b-8), c);
        pin((a+8), (b-6), c);
        pin((a+8), (b-4), c);
        pin((a+8), (b-2), c);
        pin((a+8), b, c);

        pin((a+10), (b-14), c);
        pin((a+10), (b-12), c);
        pin((a+10), (b-10), c);
        pin((a+10), (b-8), c);
        pin((a+10), (b-6), c);
        pin((a+10), (b-4), c);
        pin((a+10), (b-2), c);
        pin((a+10), b, c);
}

/////music things!

void NoteA1(int time){ //440Hz
    int i;
    while(1){
        for (i=time; i>0; i--){
            DACR = (400<<6);
            wait_ticks(454);//wait_ticks will count down
            DACR = 0;
            wait_ticks(454);//wait_ticks will count down
        }
    return 0;
    }
}

void NoteB(int time){ //494Hz
    int i;
    while(1){
        for (i=time; i>0; i--){
            DACR = (400<<6);
            wait_ticks(404);//wait_ticks will count down
            DACR = 0;
            wait_ticks(404);//wait_ticks will count down
        }
    return 0;
    }
}

void NoteC(int time){ //520Hz
    int i;
    while(1){
        for (i=time; i>0; i--){
            DACR = (400<<6);
            wait_ticks(381);//wait_ticks will count down
            DACR = 0;
            wait_ticks(381);//wait_ticks will count down
        }
    return 0;
    }
}

void NoteD(int time){ //587Hz
    int i;
    while(1){
        for (i=time; i>0; i--){
            DACR = (400<<6);
            wait_ticks(339);//wait_ticks will count down
            DACR = 0;
            wait_ticks(339);//wait_ticks will count down
        }
    return 0;
    }
}

void NoteE(int time){ //659Hz
    int i;
    while(1){
        for (i=time; i>0; i--){
            DACR = (400<<6);
            wait_ticks(301);//wait_ticks will count down
            DACR = 0;
            wait_ticks(301);//wait_ticks will count down
        }
    return 0;
    }
}

void NoteF(int time){ //699Hz
    int i;
    while(1){
        for (i=time; i>0; i--){
            DACR = (400<<6);
            wait_ticks(284);//wait_ticks will count down
            DACR = 0;
            wait_ticks(284);//wait_ticks will count down
        }
    return 0;
    }
}

void NoteG(int time){ //784Hz
    int i;
    while(1){
        for (i=time; i>0; i--){
            DACR = (400<<6);
            wait_ticks(252);//wait_ticks will count down
            DACR = 0;
            wait_ticks(252);//wait_ticks will count down
        }
    return 0;
    }
}

void NoteA2(int time){ //880Hz
    int i;
    while(1){
        for (i=time; i>0; i--){
            DACR = (400<<6);
            wait_ticks(225);//wait_ticks will count down
            DACR = 0;
            wait_ticks(225);//wait_ticks will count down
        }
    return 0;
    }
}

void music(){

    PINSEL1 |= (1<<21);//using PINSEL to select AOUT function
    PINSEL1 &= ~(1<<20);//using PINSEL to select AOUT function

    int eight = 300;
    int quart = 600;
    int quartAndEight = 900;
    int half = 1200;
    int rest = 17000;

    while(1){

    NoteE(quart);//measure 1
    NoteB(eight);
    NoteC(eight);
    NoteD(quart);
    NoteC(eight);
    NoteB(eight);
    NoteA1(quart);//measure 2
    wait_ticks (rest);
    NoteA1(eight);
    NoteC(eight);
    NoteE(quart);
    NoteD(eight);
    NoteC(eight);
    NoteB(quart);//measure 3
    wait_ticks (rest);
    NoteB(eight);
    NoteC(eight);
    NoteD(quart);
    NoteE(quart);
    NoteC(quart); //measure 4
    NoteA1(quart);
    wait_ticks (rest);
    NoteA1(half);
    NoteD(quartAndEight);//measure 5
    NoteF(eight);
    NoteA2(quart);
    NoteG(eight);
    NoteF(eight);
    NoteE(quartAndEight);//measure 6
    NoteC(eight);
    NoteE(quart);
    NoteD(eight);
    NoteC(eight);
    NoteB(quart);//measure 7
    wait_ticks (rest);
    NoteB(eight);
    NoteC(eight);
    NoteD(quart);
    NoteE(quart);
    NoteC(quart); // measure 8
    NoteA1(quart);
    wait_ticks (rest);
    NoteA1(half);
    }
}

//initialize keypad and keypad functions

void KeyboardInit(){

    FIO2DIR &= ~(1<<4); //button pins set as inputs
    FIO2DIR &= ~(1<<5);
    FIO2DIR &= ~(1<<6);
    FIO2DIR &= ~(1<<7);

}

void SelectRow(int row){

    FIO2PIN |= (0b1111<<0);
    FIO2PIN &= ~(1<<row);
    FIO2DIR &= ~(0b1111<<0);
    FIO2DIR |= (1<<row);

}

int ReadColumn(void){
    int col;
    for(col=0; col<4; col++){
            if(((FIO2PIN>>(4+col))&1)==0){
                return col;
            }
    }
    return -1;
}

char ReadKeypad(void){

    int row, col;
    for (row =0; row<4; row++){
        SelectRow(row);
        wait_ticks(300);
        col = ReadColumn();

        if(col>=0){
            return KeyPad[((row*4)+col)];
        }
    }
    return 0;
}

////Block runs

void OblockRun (){
    int j = 5;
    int i;

    for (i=2; i<20; i++){

        int x = ReadKeypad();
            if (x==56){
                    if (OblockDetectBelow(i, j)==0){
                        i++;
                        if (i>19){i=19;}
                        }
                    }
            if (x==52){
                if (OblockDetectLeft(i, j)==0){
                    j--;
                    }
                }

            if (x==54){
                if (OblockDetectRight(i, j)==0){
                    j++;
                    }
                }

            Oblock(PlayFieldCol[j], PlayFieldRow[i]);

            if (OblockDetectBelow(i,j)==1){
                OblockSave(i,j);
                i=-1;
                break;
                }

            if (i==19){
                OblockSave(i,j);
                    }

            wait_ticks(300000);

            if ((i>0)&&(i<19)){
                OblockErase(PlayFieldCol[j], PlayFieldRow[i]);
            }

        }
}

void IblockRun (){
    int j = 5;
    int c = 0;
    int i;

    for (i=2; i<20; i++){

        int x = ReadKeypad();
            if (x==56){
                if (IblockDetectBelow(i, j, c)==0){
                    i++;
                    if (i>19){i=19;}
                    }
                }

            if (x==52){
                if (IblockDetectLeft(i, j, c)==0){
                    j--;
                    }
                }

            if (x==54){
                if (IblockDetectRight(i, j, c)==0){
                    j++;
                    }
                }

            if (x==53){
                if (IblockDetectSpin(i, j, c)==0){
                    c++;
                    }
                }

            Iblock(PlayFieldCol[j], PlayFieldRow[i], c);

            if (IblockDetectBelow(i,j,c)==1){
                IblockSave(i,j,c);
                i=-1;
                break;
                }

            if (i==19){
                IblockSave(i,j,c);
                    }

            wait_ticks(300000);

            if ((i>0)&&(i<19)){
                IblockErase(PlayFieldCol[j], PlayFieldRow[i], c);
            }

        }
}

void SblockRun (){
    int j = 5;
    int c = 0;
    int i;

    for (i=2; i<20; i++){

        int x = ReadKeypad();
            if (x==56){
                if (SblockDetectBelow(i, j, c)==0){
                    i++;
                    if (i>19){i=19;}
                    }
                }

            if (x==52){
                if (SblockDetectLeft(i, j, c)==0){
                    j--;
                    }
                }

            if (x==54){
                if (SblockDetectRight(i, j, c)==0){
                    j++;
                    }
                }

            if (x==53){
                if (SblockDetectSpin(i, j, c)==0){
                    c++;
                    }
                }

            Sblock(PlayFieldCol[j], PlayFieldRow[i], c);

            if (SblockDetectBelow(i,j,c)==1){
                SblockSave(i,j,c);
                i=-1;
                break;
                }

            if (i==19){
                    SblockSave(i,j,c);
                    }

            wait_ticks(300000);

            if ((i>0)&&(i<19)){
                SblockErase(PlayFieldCol[j], PlayFieldRow[i], c);
            }

        }
}

void ZblockRun (){
    int j = 5;
    int c = 0;
    int i;

    for (i=2; i<20; i++){

        int x = ReadKeypad();
            if (x==56){
                if (ZblockDetectBelow(i, j, c)==0){
                    i++;
                    if (i>19){i=19;}
                    }
                }

            if (x==52){
                if (ZblockDetectLeft(i, j, c)==0){
                    j--;
                    }
                }

            if (x==54){
                if (ZblockDetectRight(i, j, c)==0){
                    j++;
                    }
                }

            if (x==53){
                if (ZblockDetectSpin(i, j, c)==0){
                    c++;
                    }
                }

            Zblock(PlayFieldCol[j], PlayFieldRow[i], c);

            if (ZblockDetectBelow(i,j,c)==1){
                ZblockSave(i,j,c);
                i=-1;
                break;
                }

            if (i==19){
                ZblockSave(i,j,c);
                    }

            wait_ticks(300000);

            if ((i>0)&&(i<19)){
                ZblockErase(PlayFieldCol[j], PlayFieldRow[i], c);
            }

        }
}

void LblockRun (){
    int j = 5;
    int c = 0;
    int i;

    for (i=2; i<20; i++){

        int x = ReadKeypad();
            if (x==56){
                if (LblockDetectBelow(i, j, c)==0){
                    i++;
                    if (i>19){i=19;}
                    }
                }

            if (x==52){
                if (LblockDetectLeft(i, j, c)==0){
                    j--;
                    }
                }

            if (x==54){
                if (LblockDetectRight(i, j, c)==0){
                    j++;
                    }
                }

            if (x==53){
                if (LblockDetectSpin(i, j, c)==0){
                    c++;
                    }
                }

            Lblock(PlayFieldCol[j], PlayFieldRow[i], c);

            if (LblockDetectBelow(i,j,c)==1){
                LblockSave(i,j,c);
                i=-1;
                break;
                }

            if (i==19){
                    LblockSave(i,j,c);
                    }

            wait_ticks(300000);

            if ((i>0)&&(i<19)){
                LblockErase(PlayFieldCol[j], PlayFieldRow[i], c);
            }

        }
}

void JblockRun (){
    int j = 5;
    int c = 0;
    int i;

    for (i=2; i<20; i++){

        int x = ReadKeypad();
            if (x==56){
                if (JblockDetectBelow(i, j, c)==0){
                    i++;
                    if (i>19){i=20;}
                    }
                }

            if (x==52){
                if (JblockDetectLeft(i, j, c)==0){
                    j--;
                    }
                }

            if (x==54){
                if (JblockDetectRight(i, j, c)==0){
                    j++;
                    }
                }

            if (x==53){
                if (JblockDetectSpin(i, j, c)==0){
                    c++;
                    }
                }

            Jblock(PlayFieldCol[j], PlayFieldRow[i], c);

            if (JblockDetectBelow(i,j,c)==1){
                JblockSave(i,j,c);
                i=-1;
                break;
                }

            if (i==19){
                JblockSave(i,j,c);
            }

            wait_ticks(300000);

            if ((i>0)&&(i<19)){
                JblockErase(PlayFieldCol[j], PlayFieldRow[i], c);
            }

        }
}

void TblockRun (){
    int j = 5;
    int c = 0;
    int i;

    for (i=2; i<20; i++){

        int x = ReadKeypad();
            if (x==56){
                if (TblockDetectBelow(i, j,c)==0){
                    i++;
                    if (i>19){i=20;}
                    }
                }

            if (x==52){
                if (TblockDetectLeft(i, j, c)==0){
                    j--;
                    }
                }

            if (x==54){
                if (TblockDetectRight(i, j, c)==0){
                    j++;
                    }
                }

            if (x==53){
                if (TblockDetectSpin(i, j, c)==0){
                    c++;
                    }
                }

            Tblock(PlayFieldCol[j], PlayFieldRow[i], c);

            if (TblockDetectBelow(i,j,c)==1){
                TblockSave(i,j,c);
                i=-1;
                break;
                }

            if (i==19){
                TblockSave(i,j,c);
                    }

            wait_ticks(300000);

            if ((i>0)&&(i<19)){
                TblockErase(PlayFieldCol[j], PlayFieldRow[i], c);
            }

        }
}

///Game score and status update needs

int DetectLine (void){
    if ((!(PlayFieldStat[19][0]==0))&&(!(PlayFieldStat[19][1]==0))&&(!(PlayFieldStat[19][2]==0))&&(!(PlayFieldStat[19][3]==0))&&(!(PlayFieldStat[19][4]==0))&&(!(PlayFieldStat[19][5]==0))&&(!(PlayFieldStat[19][6]==0))&&(!(PlayFieldStat[19][7]==0))&&(!(PlayFieldStat[19][8]==0))&&(!(PlayFieldStat[19][9]==0))){
        return 19;
        }
    if ((!(PlayFieldStat[18][0]==0))&&(!(PlayFieldStat[18][1]==0))&&(!(PlayFieldStat[18][2]==0))&&(!(PlayFieldStat[18][3]==0))&&(!(PlayFieldStat[18][4]==0))&&(!(PlayFieldStat[18][5]==0))&&(!(PlayFieldStat[18][6]==0))&&(!(PlayFieldStat[18][7]==0))&&(!(PlayFieldStat[18][8]==0))&&(!(PlayFieldStat[18][9]==0))){
        return 18;
        }
    if ((!(PlayFieldStat[17][0]==0))&&(!(PlayFieldStat[17][1]==0))&&(!(PlayFieldStat[17][2]==0))&&(!(PlayFieldStat[17][3]==0))&&(!(PlayFieldStat[17][4]==0))&&(!(PlayFieldStat[17][5]==0))&&(!(PlayFieldStat[17][6]==0))&&(!(PlayFieldStat[17][7]==0))&&(!(PlayFieldStat[17][8]==0))&&(!(PlayFieldStat[17][9]==0))){
        return 17;
        }
    if ((!(PlayFieldStat[16][0]==0))&&(!(PlayFieldStat[16][1]==0))&&(!(PlayFieldStat[16][2]==0))&&(!(PlayFieldStat[16][3]==0))&&(!(PlayFieldStat[16][4]==0))&&(!(PlayFieldStat[16][5]==0))&&(!(PlayFieldStat[16][6]==0))&&(!(PlayFieldStat[16][7]==0))&&(!(PlayFieldStat[16][8]==0))&&(!(PlayFieldStat[16][9]==0))){
        return 16;
        }
    if ((!(PlayFieldStat[15][0]==0))&&(!(PlayFieldStat[15][1]==0))&&(!(PlayFieldStat[15][2]==0))&&(!(PlayFieldStat[15][3]==0))&&(!(PlayFieldStat[15][4]==0))&&(!(PlayFieldStat[15][5]==0))&&(!(PlayFieldStat[15][6]==0))&&(!(PlayFieldStat[15][7]==0))&&(!(PlayFieldStat[15][8]==0))&&(!(PlayFieldStat[15][9]==0))){
        return 15;
        }
    if ((!(PlayFieldStat[14][0]==0))&&(!(PlayFieldStat[14][1]==0))&&(!(PlayFieldStat[14][2]==0))&&(!(PlayFieldStat[14][3]==0))&&(!(PlayFieldStat[14][4]==0))&&(!(PlayFieldStat[14][5]==0))&&(!(PlayFieldStat[14][6]==0))&&(!(PlayFieldStat[14][7]==0))&&(!(PlayFieldStat[14][8]==0))&&(!(PlayFieldStat[14][9]==0))){
        return 14;
        }
    if ((!(PlayFieldStat[13][0]==0))&&(!(PlayFieldStat[13][1]==0))&&(!(PlayFieldStat[13][2]==0))&&(!(PlayFieldStat[13][3]==0))&&(!(PlayFieldStat[13][4]==0))&&(!(PlayFieldStat[13][5]==0))&&(!(PlayFieldStat[13][6]==0))&&(!(PlayFieldStat[13][7]==0))&&(!(PlayFieldStat[13][8]==0))&&(!(PlayFieldStat[13][9]==0))){
        return 13;
        }
    if ((!(PlayFieldStat[12][0]==0))&&(!(PlayFieldStat[12][1]==0))&&(!(PlayFieldStat[12][2]==0))&&(!(PlayFieldStat[12][3]==0))&&(!(PlayFieldStat[12][4]==0))&&(!(PlayFieldStat[12][5]==0))&&(!(PlayFieldStat[12][6]==0))&&(!(PlayFieldStat[12][7]==0))&&(!(PlayFieldStat[12][8]==0))&&(!(PlayFieldStat[12][9]==0))){
        return 12;
        }
    if ((!(PlayFieldStat[11][0]==0))&&(!(PlayFieldStat[11][1]==0))&&(!(PlayFieldStat[11][2]==0))&&(!(PlayFieldStat[11][3]==0))&&(!(PlayFieldStat[11][4]==0))&&(!(PlayFieldStat[11][5]==0))&&(!(PlayFieldStat[11][6]==0))&&(!(PlayFieldStat[11][7]==0))&&(!(PlayFieldStat[11][8]==0))&&(!(PlayFieldStat[11][9]==0))){
        return 11;
        }
    if ((!(PlayFieldStat[10][0]==0))&&(!(PlayFieldStat[10][1]==0))&&(!(PlayFieldStat[10][2]==0))&&(!(PlayFieldStat[10][3]==0))&&(!(PlayFieldStat[10][4]==0))&&(!(PlayFieldStat[10][5]==0))&&(!(PlayFieldStat[10][6]==0))&&(!(PlayFieldStat[10][7]==0))&&(!(PlayFieldStat[10][8]==0))&&(!(PlayFieldStat[10][9]==0))){
        return 10;
        }
    if ((!(PlayFieldStat[9][0]==0))&&(!(PlayFieldStat[9][1]==0))&&(!(PlayFieldStat[9][2]==0))&&(!(PlayFieldStat[9][3]==0))&&(!(PlayFieldStat[9][4]==0))&&(!(PlayFieldStat[9][5]==0))&&(!(PlayFieldStat[9][6]==0))&&(!(PlayFieldStat[9][7]==0))&&(!(PlayFieldStat[9][8]==0))&&(!(PlayFieldStat[9][9]==0))){
        return 9;
        }
    if ((!(PlayFieldStat[8][0]==0))&&(!(PlayFieldStat[8][1]==0))&&(!(PlayFieldStat[8][2]==0))&&(!(PlayFieldStat[8][3]==0))&&(!(PlayFieldStat[8][4]==0))&&(!(PlayFieldStat[8][5]==0))&&(!(PlayFieldStat[8][6]==0))&&(!(PlayFieldStat[8][7]==0))&&(!(PlayFieldStat[8][8]==0))&&(!(PlayFieldStat[8][9]==0))){
        return 8;
        }
    if ((!(PlayFieldStat[7][0]==0))&&(!(PlayFieldStat[7][1]==0))&&(!(PlayFieldStat[7][2]==0))&&(!(PlayFieldStat[7][3]==0))&&(!(PlayFieldStat[7][4]==0))&&(!(PlayFieldStat[7][5]==0))&&(!(PlayFieldStat[7][6]==0))&&(!(PlayFieldStat[7][7]==0))&&(!(PlayFieldStat[7][8]==0))&&(!(PlayFieldStat[7][9]==0))){
        return 7;
        }
    if ((!(PlayFieldStat[6][0]==0))&&(!(PlayFieldStat[6][1]==0))&&(!(PlayFieldStat[6][2]==0))&&(!(PlayFieldStat[6][3]==0))&&(!(PlayFieldStat[6][4]==0))&&(!(PlayFieldStat[6][5]==0))&&(!(PlayFieldStat[6][6]==0))&&(!(PlayFieldStat[6][7]==0))&&(!(PlayFieldStat[6][8]==0))&&(!(PlayFieldStat[6][9]==0))){
        return 6;
        }
    if ((!(PlayFieldStat[5][0]==0))&&(!(PlayFieldStat[5][1]==0))&&(!(PlayFieldStat[5][2]==0))&&(!(PlayFieldStat[5][3]==0))&&(!(PlayFieldStat[5][4]==0))&&(!(PlayFieldStat[5][5]==0))&&(!(PlayFieldStat[5][6]==0))&&(!(PlayFieldStat[5][7]==0))&&(!(PlayFieldStat[5][8]==0))&&(!(PlayFieldStat[5][9]==0))){
        return 5;
        }
    if ((!(PlayFieldStat[4][0]==0))&&(!(PlayFieldStat[4][1]==0))&&(!(PlayFieldStat[4][2]==0))&&(!(PlayFieldStat[4][3]==0))&&(!(PlayFieldStat[4][4]==0))&&(!(PlayFieldStat[4][5]==0))&&(!(PlayFieldStat[4][6]==0))&&(!(PlayFieldStat[4][7]==0))&&(!(PlayFieldStat[4][8]==0))&&(!(PlayFieldStat[4][9]==0))){
        return 4;
        }
    if ((!(PlayFieldStat[3][0]==0))&&(!(PlayFieldStat[3][1]==0))&&(!(PlayFieldStat[3][2]==0))&&(!(PlayFieldStat[3][3]==0))&&(!(PlayFieldStat[3][4]==0))&&(!(PlayFieldStat[3][5]==0))&&(!(PlayFieldStat[3][6]==0))&&(!(PlayFieldStat[3][7]==0))&&(!(PlayFieldStat[3][8]==0))&&(!(PlayFieldStat[3][9]==0))){
        return 3;
        }
    if ((!(PlayFieldStat[2][0]==0))&&(!(PlayFieldStat[2][1]==0))&&(!(PlayFieldStat[2][2]==0))&&(!(PlayFieldStat[2][3]==0))&&(!(PlayFieldStat[2][4]==0))&&(!(PlayFieldStat[2][5]==0))&&(!(PlayFieldStat[2][6]==0))&&(!(PlayFieldStat[2][7]==0))&&(!(PlayFieldStat[2][8]==0))&&(!(PlayFieldStat[2][9]==0))){
        return 2;
        }
    if ((!(PlayFieldStat[1][0]==0))&&(!(PlayFieldStat[1][1]==0))&&(!(PlayFieldStat[1][2]==0))&&(!(PlayFieldStat[1][3]==0))&&(!(PlayFieldStat[1][4]==0))&&(!(PlayFieldStat[1][5]==0))&&(!(PlayFieldStat[1][6]==0))&&(!(PlayFieldStat[1][7]==0))&&(!(PlayFieldStat[1][8]==0))&&(!(PlayFieldStat[1][9]==0))){
        return 1;
        }
    else {
        return 0;
    }
}

int DetectLose (void){
    if ((!(PlayFieldStat[0][0]==0))||(!(PlayFieldStat[0][1]==0))||(!(PlayFieldStat[0][2]==0))||(!(PlayFieldStat[0][3]==0))||(!(PlayFieldStat[0][4]==0))||(!(PlayFieldStat[0][5]==0))||(!(PlayFieldStat[0][6]==0))||(!(PlayFieldStat[0][7]==0))||(!(PlayFieldStat[0][8]==0))||(!(PlayFieldStat[0][9]==0))){
        return 1;
        }
    else {
        return 0;
        }
}

void EraseLine (int b){
    int i;
    for (i=0; i<10; i++){
    Erase(PlayFieldCol[i],PlayFieldRow[b]);
    }
}

void DeleteLine (int i){
    int j;
    for (j=0; j<10; j++){
    PlayFieldStat[i][j]=0;
    }
}

void UpdateScreen(int r){
    int i;
    int j;
    int k;

        for (i=r; i>1; i--){
            for(j=0; j<10; j++){
                if (!(PlayFieldStat[i-1][j]==0)){
                Block(PlayFieldCol[j], PlayFieldRow[i], PlayFieldStat[i-1][j]);

                }

            else{
                Erase(PlayFieldCol[j], PlayFieldRow[i]);
                }

            PlayFieldStat[i][j]=PlayFieldStat[i-1][j];
            }

        for(k=0; k<10 ; k++){
            Erase(PlayFieldCol[j], PlayFieldRow[0]);
            }
        }
}

void DetectDelete(){
    int l = DetectLine();
        if (l>0){
            DeleteLine(l);
            EraseLine(l);
            UpdateScreen(l);
            Score++;
        int m = DetectLine();
            if (m>0){
                DeleteLine(m);
                EraseLine(m);
                UpdateScreen(m);
                Score=Score+2;
            int n = DetectLine();
                if (n>0){
                    DeleteLine(n);
                    EraseLine(n);
                    UpdateScreen(n);
                    Score=Score+2;
                int o = DetectLine();
                    if (o>0){
                        DeleteLine(o);
                        EraseLine(o);
                        UpdateScreen(o);
                        Score=Score+6;
                        }
                    }
                }
        }
}

//Game!

int main (void){
    clocks();
    SPIInit();
    LCDinit();
    KeyboardInit();

// ColorTest();
    Welcome();
    PlayField();

    int blk=0;
    int i;
    for (i=0;i<100;i++){
        blk = rand()%7;
        if (blk==0){
            OblockRun();
            DetectDelete();
                if(DetectLose()==1){
                    GameOver(Score);
                    break;
                    }
            }
        if (blk==1){
                IblockRun();
                DetectDelete();
                    if(DetectLose()==1){
                        GameOver(Score);
                        break;
                        }
                }
        if (blk==2){
                SblockRun();
                DetectDelete();
                    if(DetectLose()==1){
                        GameOver(Score);
                        break;
                        }
                }
        if (blk==3){
                    ZblockRun();
                    DetectDelete();
                        if(DetectLose()==1){
                            GameOver(Score);
                            break;
                            }
        		}
        if (blk==4){
                    LblockRun();
                    DetectDelete();
                        if(DetectLose()==1){
                            GameOver(Score);
                            break;
                            }
                    }
        if (blk==5){
                    JblockRun();
                    DetectDelete();
                        if(DetectLose()==1){
                            GameOver(Score);
                            break;
                            }
                    }
        if (blk==6){
                    TblockRun();
                    DetectDelete();
                        if(DetectLose()==1){
                            GameOver(Score);
                            break;
                            }
                    }
            }
    }