//video gen and sound //D.5 is sync:1000 ohm + diode to 75 ohm resistor //D.6 is video:330 ohm + diode to 75 ohm resistor //B.3 is sound and should have a 10k resistor to gnd #pragma regalloc- //I allocate the registers myself #pragma optsize- //optimize for speed #include #include #include #include #include //cycles = 63.625 * 16 Note NTSC is 63.55 //but this line duration makes each frame exactly 1/60 sec //which is nice for keeping a realtime clock #define lineTime 1018 #define begin { #define end } #define ScreenTop 30 #define ScreenBot 230 #define int2fix(a) (((int)(a))<<8) #define float2fix(a) ((int)((a)*256.0)) #define multfixSLOW(a,b) ((int)(((long)(a)*((long)(b)))>>8)) #define addfix(a,b) (int)(a) + (int)(b) #define subfix(a,b) (int)(a) - (int)(b) void you_win(void); void you_die(void); void game_over(void); void draw_block(char x, char y, char c); void draw_i(char x, char y, char c, char rotation); //draws I block void draw_o(char x, char y, char c, char rotation); //draws O block void draw_j(char x, char y, char c, char rotation); //draws J block void draw_z(char x, char y, char c, char rotation); //draws Z block void draw_t(char x, char y, char c, char rotation); //draws T block void draw_l(char x, char y, char c, char rotation); //draws L block void draw_s(char x, char y, char c, char rotation); //draws S block void check_bottom(void); //checks if block should stop moving downwards void move_left(void); //checks if block can move left void move_right(void); //checks if block can move right void move_down(void); //moves block down void draw_next(char x, char y); //draws what next block will be void check_can_rotate(char posx, char posy, char mod_rand, char next); //checks if block can rotate void check_block(char x, char y); //checks if a square can be in a certain place void next_game(void); //clears screen and restarts game void clear_on_next(void); //help to clear screen void move_line_down(void); //moves screen down when line is completed //NOTE that v1 to v8 and i must be in registers! register char v1 @4; register char v2 @5; register char v3 @6; register char v4 @7; register char v5 @8; register char v6 @9; register char v7 @10; register char v8 @11; register int i @12; #pragma regalloc+ char syncON, syncOFF; char xchar,ychar; int LineCount; int time; char changed; char prev; //animation int donevx, donevy; char screen[1600], t, ts[10], blob[10], blob2[10], blob3[10]; char cu1[]="TETRIS"; char cu2[]="LOSER"; char bottoms, sides, top; char posy;//,prev_posy; char posx; char bottom_x[4],bottom_y[4]; //char bottom_adder; char random_block; //char action,drop; // =0 for no action =1 for rotate =2 for move =3 for rotate and move //char at_bottom; char left_sidex[4], right_sidex[4]; char left_sidey[4], right_sidey[4]; char lefts,rights; char next_rand, mod_rand,starting; char cannot_rotate; char move_down_counter, start_clear, lines_to_move; char count_frames,next,count_lose; char fall_speed, standard_fall_speed; int counter1,counter2; char s,r,cw,lose; char line_to_clear[4], lines; char slam_down; char prev_drawx, prev_drawy, prev_drawchanged; char hold_on_next; char start_offset; char total_lines_cleared; //int fuel; //char fuel_display; char slam_counter, reg_speed; int stime; long ltime; char clear_from; char result,clears_left; char button, prev_changed; //char shipnum; char reset; //char level, prev_level; char speed; //float move; char pushed1, pushed2, pushed3, pushed4, pushed5, pushed6, pushed7; unsigned char Ain ; //raw A to D number //float sineTable[13] = {-1.0000,-0.9659,-0.8660,-0.7071,-0.5000,-0.2588,0,0.2588,0.5000,0.7071,0.8660,0.9659,1.0000}; //@0x100; //need loc to avoid glitch //float cosineTable[13] = {0,0.2588,0.5000,0.7071,0.8660,0.9659,1.0000,0.9659,0.8660,0.7071,0.5000,0.2588,0}; //@0x //Musical note values //C below middle C to C above middle C //zeros are rests //flash char notes[] = {239,213,189,179,159,142,126, // 120,106,94,90,80,71,63,60,0,0,0,0}; //char note, musicT; //Point plot lookup table //One bit masks flash char pos[8]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01}; //define some character bitmaps //5x7 characters flash char bitmap[65][7]={ //0 0b01110000, 0b10001000, 0b10011000, 0b10101000, 0b11001000, 0b10001000, 0b01110000, //1 0b00100000, 0b01100000, 0b00100000, 0b00100000, 0b00100000, 0b00100000, 0b01110000, //2 0b01110000, 0b10001000, 0b00001000, 0b00010000, 0b00100000, 0b01000000, 0b11111000, //3 0b11111000, 0b00010000, 0b00100000, 0b00010000, 0b00001000, 0b10001000, 0b01110000, //4 0b00010000, 0b00110000, 0b01010000, 0b10010000, 0b11111000, 0b00010000, 0b00010000, //5 0b11111000, 0b10000000, 0b11110000, 0b00001000, 0b00001000, 0b10001000, 0b01110000, //6 0b01000000, 0b10000000, 0b10000000, 0b11110000, 0b10001000, 0b10001000, 0b01110000, //7 0b11111000, 0b00001000, 0b00010000, 0b00100000, 0b01000000, 0b10000000, 0b10000000, //8 0b01110000, 0b10001000, 0b10001000, 0b01110000, 0b10001000, 0b10001000, 0b01110000, //9 0b01110000, 0b10001000, 0b10001000, 0b01111000, 0b00001000, 0b00001000, 0b00010000, //A 0b01110000, 0b10001000, 0b10001000, 0b10001000, 0b11111000, 0b10001000, 0b10001000, //B 0b11110000, 0b10001000, 0b10001000, 0b11110000, 0b10001000, 0b10001000, 0b11110000, //C 0b01110000, 0b10001000, 0b10000000, 0b10000000, 0b10000000, 0b10001000, 0b01110000, //D 0b11110000, 0b10001000, 0b10001000, 0b10001000, 0b10001000, 0b10001000, 0b11110000, //E 0b11111000, 0b10000000, 0b10000000, 0b11111000, 0b10000000, 0b10000000, 0b11111000, //F 0b11111000, 0b10000000, 0b10000000, 0b11111000, 0b10000000, 0b10000000, 0b10000000, //G 0b01110000, 0b10001000, 0b10000000, 0b10011000, 0b10001000, 0b10001000, 0b01110000, //H 0b10001000, 0b10001000, 0b10001000, 0b11111000, 0b10001000, 0b10001000, 0b10001000, //I 0b01110000, 0b00100000, 0b00100000, 0b00100000, 0b00100000, 0b00100000, 0b01110000, //J 0b00111000, 0b00010000, 0b00010000, 0b00010000, 0b00010000, 0b10010000, 0b01100000, //K 0b10001000, 0b10010000, 0b10100000, 0b11000000, 0b10100000, 0b10010000, 0b10001000, //L 0b10000000, 0b10000000, 0b10000000, 0b10000000, 0b10000000, 0b10000000, 0b11111000, //M 0b10001000, 0b11011000, 0b10101000, 0b10101000, 0b10001000, 0b10001000, 0b10001000, //N 0b10001000, 0b10001000, 0b11001000, 0b10101000, 0b10011000, 0b10001000, 0b10001000, //O 0b01110000, 0b10001000, 0b10001000, 0b10001000, 0b10001000, 0b10001000, 0b01110000, //P 0b11110000, 0b10001000, 0b10001000, 0b11110000, 0b10000000, 0b10000000, 0b10000000, //Q 0b01110000, 0b10001000, 0b10001000, 0b10001000, 0b10101000, 0b10010000, 0b01101000, //R 0b11110000, 0b10001000, 0b10001000, 0b11110000, 0b10100000, 0b10010000, 0b10001000, //S 0b01111000, 0b10000000, 0b10000000, 0b01110000, 0b00001000, 0b00001000, 0b11110000, //T 0b11111000, 0b00100000, 0b00100000, 0b00100000, 0b00100000, 0b00100000, 0b00100000, //U 0b10001000, 0b10001000, 0b10001000, 0b10001000, 0b10001000, 0b10001000, 0b01110000, //V 0b10001000, 0b10001000, 0b10001000, 0b10001000, 0b10001000, 0b01010000, 0b00100000, //W 0b10001000, 0b10001000, 0b10001000, 0b10101000, 0b10101000, 0b10101000, 0b01010000, //X 0b10001000, 0b10001000, 0b01010000, 0b00100000, 0b01010000, 0b10001000, 0b10001000, //Y 0b10001000, 0b10001000, 0b10001000, 0b01010000, 0b00100000, 0b00100000, 0b00100000, //Z 0b11111000, 0b00001000, 0b00010000, 0b00100000, 0b01000000, 0b10000000, 0b11111000, //figure1 0b01110000, 0b00100000, 0b01110000, 0b10101000, 0b00100000, 0b01010000, 0b10001000, //figure2 0b01110000, 0b10101000, 0b01110000, 0b00100000, 0b00100000, 0b01010000, 0b10001000, //Spaceship moving left 0b00100000, 0b00100000, 0b01110000, 0b01110000, 0b01010000, 0b11111000, 0b00101000, //Normal Spaceship 0b00100000, 0b00100000, 0b01110000, 0b01110000, 0b01010000, 0b11111000, 0b01010000, //Spaceship moving right 0b00100000, 0b00100000, 0b01110000, 0b01110000, 0b01010000, 0b11111000, 0b10100000, //Anti-Spaceship 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, //fuel bar graphics //put in large bitmap //full 0b11100000, 0b11100000, 0b11100000, 0b11100000, 0b11100000, 0b11100000, 0b11100000, //6/7 0b00000000, 0b11100000, 0b11100000, 0b11100000, 0b11100000, 0b11100000, 0b11100000, //5/7 0b00000000, 0b00000000, 0b11100000, 0b11100000, 0b11100000, 0b11100000, 0b11100000, //4/7 0b00000000, 0b00000000, 0b00000000, 0b11100000, 0b11100000, 0b11100000, 0b11100000, //3/7 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b11100000, 0b11100000, 0b11100000, //2/7 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b11100000, 0b11100000, //1/7 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b11100000, //Empty 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b11110000, 0b11111000, 0b11110000, 0b11110000, 0b11111000, 0b11110000, 0b00000000, 0b11110000, 0b11111000, 0b11110000, 0b11110000, 0b11111000, 0b11110000, 0b00000000, 0b11110000, 0b11110000, 0b11111000, 0b11110000, 0b11111000, 0b11110000, 0b00000000, 0b11110000, 0b11110000, 0b11110000, 0b11111000, 0b11110000, 0b11111000, 0b00000000, 0b11110000, 0b11110000, 0b11110000, 0b11110000, 0b11111000, 0b11110000, 0b00010000, 0b11110000, 0b11110000, 0b11110000, 0b11110000, 0b11110000, 0b11111000, 0b00100000, 0b11110000, 0b11110000, 0b11110000, 0b11110000, 0b11110000, 0b11110000, 0b01010000, 0b01111000, 0b01111000, 0b01111000, 0b01111000, 0b01111000, 0b01111000, 0b00110000, 0b01111000, 0b01111000, 0b01111000, 0b01111000, 0b01111000, 0b01111000, 0b01010000, 0b01111000, 0b01111000, 0b01111000, 0b01111000, 0b01111000, 0b11111000, 0b00100000, 0b01111000, 0b01111000, 0b01111000, 0b01111000, 0b11111000, 0b01111000, 0b01000000, 0b01111000, 0b01111000, 0b01111000, 0b11111000, 0b01111000, 0b11111000, 0b00000000, 0b01111000, 0b01111000, 0b11111000, 0b01111000, 0b11111000, 0b01111000, 0b00000000, 0b01111000, 0b11111000, 0b01111000, 0b01111000, 0b11111000, 0b01111000, 0b00000000, 0b11111000, 0b01111000, 0b01111000, 0b11111000, 0b01111000, 0b01111000, 0b00000000 }; //================================ //3x5 font numbers, then letters //packed two per definition for fast //copy to the screen at x-position divisible by 4 flash char smallbitmap[39][5]={ //0 0b11101110, 0b10101010, 0b10101010, 0b10101010, 0b11101110, //1 0b01000100, 0b11001100, 0b01000100, 0b01000100, 0b11101110, //2 0b11101110, 0b00100010, 0b11101110, 0b10001000, 0b11101110, //3 0b11101110, 0b00100010, 0b11101110, 0b00100010, 0b11101110, //4 0b10101010, 0b10101010, 0b11101110, 0b00100010, 0b00100010, //5 0b11101110, 0b10001000, 0b11101110, 0b00100010, 0b11101110, //6 0b11001100, 0b10001000, 0b11101110, 0b10101010, 0b11101110, //7 0b11101110, 0b00100010, 0b01000100, 0b10001000, 0b10001000, //8 0b11101110, 0b10101010, 0b11101110, 0b10101010, 0b11101110, //9 0b11101110, 0b10101010, 0b11101110, 0b00100010, 0b01100110, //: 0b00000000, 0b01000100, 0b00000000, 0b01000100, 0b00000000, //= 0b00000000, 0b11101110, 0b00000000, 0b11101110, 0b00000000, //blank 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, //A 0b11101110, 0b10101010, 0b11101110, 0b10101010, 0b10101010, //B 0b11001100, 0b10101010, 0b11101110, 0b10101010, 0b11001100, //C 0b11101110, 0b10001000, 0b10001000, 0b10001000, 0b11101110, //D 0b11001100, 0b10101010, 0b10101010, 0b10101010, 0b11001100, //E 0b11101110, 0b10001000, 0b11101110, 0b10001000, 0b11101110, //F 0b11101110, 0b10001000, 0b11101110, 0b10001000, 0b10001000, //G 0b11101110, 0b10001000, 0b10001000, 0b10101010, 0b11101110, //H 0b10101010, 0b10101010, 0b11101110, 0b10101010, 0b10101010, //I 0b11101110, 0b01000100, 0b01000100, 0b01000100, 0b11101110, //J 0b00100010, 0b00100010, 0b00100010, 0b10101010, 0b11101110, //K 0b10001000, 0b10101010, 0b11001100, 0b11001100, 0b10101010, //L 0b10001000, 0b10001000, 0b10001000, 0b10001000, 0b11101110, //M 0b10101010, 0b11101110, 0b11101110, 0b10101010, 0b10101010, //N 0b00000000, 0b11001100, 0b10101010, 0b10101010, 0b10101010, //O 0b01000100, 0b10101010, 0b10101010, 0b10101010, 0b01000100, //P 0b11101110, 0b10101010, 0b11101110, 0b10001000, 0b10001000, //Q 0b01000100, 0b10101010, 0b10101010, 0b11101110, 0b01100110, //R 0b11101110, 0b10101010, 0b11001100, 0b11101110, 0b10101010, //S 0b11101110, 0b10001000, 0b11101110, 0b00100010, 0b11101110, //T 0b11101110, 0b01000100, 0b01000100, 0b01000100, 0b01000100, //U 0b10101010, 0b10101010, 0b10101010, 0b10101010, 0b11101110, //V 0b10101010, 0b10101010, 0b10101010, 0b10101010, 0b01000100, //W 0b10101010, 0b10101010, 0b11101110, 0b11101110, 0b10101010, //X 0b00000000, 0b10101010, 0b01000100, 0b01000100, 0b10101010, //Y 0b10101010, 0b10101010, 0b01000100, 0b01000100, 0b01000100, //Z 0b11101110, 0b00100010, 0b01000100, 0b10001000, 0b11101110 }; //================================== //This is the sync generator and raster generator. It MUST be entered from //sleep mode to get accurate timing of the sync pulses #pragma warn- interrupt [TIM1_COMPA] void t1_cmpA(void) { //start the Horizontal sync pulse PORTD = syncON; //update the curent scanline number LineCount ++ ; //{ inverted (Vertical) synch after line 247 if (LineCount==248) { syncON = 0b00100000; syncOFF = 0; } //back to regular sync after line 250 if (LineCount==251) { syncON = 0; syncOFF = 0b00100000; } //start new frame after line 262 if (LineCount==263) { LineCount = 1; } delay_us(2); //adjust to make 5 us pulses //} sync pulse PORTD = syncOFF; if (LineCount=ScreenTop) { //compute byte index for beginning of the next line //left-shift 4 would be individual lines // <<3 means line-double the pixels //The 0xfff8 truncates the odd line bit //i=(LineCount-ScreenTop)<<3 & 0xfff8; // #asm push r16 lds r12, _LineCount lds r13, _Linecount+1 ldi r16, 30 sub r12, r16 ldi r16,0 sbc r13, r16 lsl r12 rol r13 lsl r12 rol r13 lsl r12 rol r13 mov r16,r12 andi r16,0xf0 mov r12,r16 pop r16 #endasm //load 16 registers with screen info #asm push r14 push r15 push r16 push r17 push r18 push r19 push r26 push r27 ldi r26,low(_screen) ;base address of screen ldi r27,high(_screen) add r26,r12 ;offset into screen (add i) adc r27,r13 ld r4,x+ ;load 16 registers and inc pointer ld r5,x+ ld r6,x+ ld r7,x+ ld r8,x+ ld r9,x+ ld r10,x+ ld r11,x+ ld r12,x+ ld r13,x+ ld r14,x+ ld r15,x+ ld r16,x+ ld r17,x+ ld r18,x+ ld r19,x pop r27 pop r26 #endasm delay_us(4); //adjust to center image on screen //blast 16 bytes to the screen #asm ;but first a macro to make the code shorter ;the macro takes a register number as a parameter ;and dumps its bits serially to portD.6 ;the nop can be eliminated to make the display narrower .macro videobits ;regnum BST @0,7 IN R30,0x12 BLD R30,6 nop OUT 0x12,R30 BST @0,6 IN R30,0x12 BLD R30,6 nop OUT 0x12,R30 BST @0,5 IN R30,0x12 BLD R30,6 nop OUT 0x12,R30 BST @0,4 IN R30,0x12 BLD R30,6 nop OUT 0x12,R30 BST @0,3 IN R30,0x12 BLD R30,6 nop OUT 0x12,R30 BST @0,2 IN R30,0x12 BLD R30,6 nop OUT 0x12,R30 BST @0,1 IN R30,0x12 BLD R30,6 nop OUT 0x12,R30 BST @0,0 IN R30,0x12 BLD R30,6 nop OUT 0x12,R30 .endm videobits r4 ;video line -- byte 1 videobits r5 ;byte 2 videobits r6 ;byte 3 videobits r7 ;byte 4 videobits r8 ;byte 5 videobits r9 ;byte 6 videobits r10 ;byte 7 videobits r11 ;byte 8 videobits r12 ;byte 9 videobits r13 ;byte 10 videobits r14 ;byte 11 videobits r15 ;byte 12 videobits r16 ;byte 13 videobits r17 ;byte 14 videobits r18 ;byte 15 videobits r19 ;byte 16 clt ;clear video after the last pixel on the line IN R30,0x12 BLD R30,6 OUT 0x12,R30 pop r19 pop r18 pop r17 pop r16 pop r15 pop r14 #endasm } } #pragma warn+ //================================== //plot one point //at x,y with color 1=white 0=black 2=invert #pragma warn- void video_pt(char x, char y, char c) { #asm ; i=(x>>3) + ((int)y<<4) ; the byte with the pixel in it push r16 ldd r30,y+2 ;get x lsr r30 lsr r30 lsr r30 ;divide x by 8 ldd r12,y+1 ;get y lsl r12 ;mult y by 16 clr r13 lsl r12 rol r13 lsl r12 rol r13 lsl r12 rol r13 add r12, r30 ;add in x/8 ;v2 = screen[i]; r5 ;v3 = pos[x & 7]; r6 ;v4 = c r7 ldi r30,low(_screen) ldi r31,high(_screen) add r30, r12 adc r31, r13 ld r5,Z ;get screen byte ldd r26,y+2 ;get x ldi r27,0 andi r26,0x07 ;form x & 7 ldi r30,low(_pos*2) ldi r31,high(_pos*2) add r30,r26 adc r31,r27 lpm r6,Z ld r16,y ;get c ;if (v4==1) screen[i] = v2 | v3 ; ;if (v4==0) screen[i] = v2 & ~v3; ;if (v4==2) screen[i] = v2 ^ v3 ; cpi r16,1 brne tst0 or r5,r6 tst0: cpi r16,0 brne tst2 com r6 and r5,r6 tst2: cpi r16,2 brne writescrn eor r5,r6 writescrn: ldi r30,low(_screen) ldi r31,high(_screen) add r30, r12 adc r31, r13 st Z, r5 ;write the byte back to the screen pop r16 #endasm } #pragma warn+ //================================== // put a big character on the screen // c is index into bitmap void video_putchar(char x, char y, char c) { v7 = x; for (v6=0;v6<7;v6++) { v1 = bitmap[c][v6]; v8 = y+v6; video_pt(v7, v8, (v1 & 0x80)==0x80); video_pt(v7+1, v8, (v1 & 0x40)==0x40); video_pt(v7+2, v8, (v1 & 0x20)==0x20); video_pt(v7+3, v8, (v1 & 0x10)==0x10); video_pt(v7+4, v8, (v1 & 0x08)==0x08); } } //================================== // put a string of big characters on the screen void video_puts(char x, char y, char *str) { char i ; for (i=0; str[i]!=0; i++) { if (str[i]>=0x30 && str[i]<=0x3a) video_putchar(x,y,str[i]-0x30); else video_putchar(x,y,str[i]-0x40+9); x = x+6; } } //================================== // put a small character on the screen // x-cood must be on divisible by 4 // c is index into bitmap void video_smallchar(char x, char y, char c) { char mask; i=((int)x>>3) + ((int)y<<4) ; if (x == (x & 0xf8)) mask = 0x0f; //f8 else mask = 0xf0; screen[i] = (screen[i] & mask) | (smallbitmap[c][0] & ~mask); screen[i+16] = (screen[i+16] & mask) | (smallbitmap[c][1] & ~mask); screen[i+32] = (screen[i+32] & mask) | (smallbitmap[c][2] & ~mask); screen[i+48] = (screen[i+48] & mask) | (smallbitmap[c][3] & ~mask); screen[i+64] = (screen[i+64] & mask) | (smallbitmap[c][4] & ~mask); } //================================== // put a string of small characters on the screen // x-cood must be on divisible by 4 void video_putsmalls(char x, char y, char *str) { char i ; for (i=0; str[i]!=0; i++) { if (str[i]>=0x30 && str[i]<=0x3a) video_smallchar(x,y,str[i]-0x30); else video_smallchar(x,y,str[i]-0x40+12); x = x+4; } } //================================== //plot a line //at x1,y1 to x2,y2 with color 1=white 0=black 2=invert //NOTE: this function requires signed chars //Code is from David Rodgers, //"Procedural Elements of Computer Graphics",1985 void video_line(char x1, char y1, char x2, char y2, char c) { int e; signed char dx,dy,j, temp; signed char s1,s2, xchange; signed char x,y; x = x1; y = y1; dx = cabs(x2-x1); dy = cabs(y2-y1); s1 = csign(x2-x1); s2 = csign(y2-y1); xchange = 0; if (dy>dx) { temp = dx; dx = dy; dy = temp; xchange = 1; } e = ((int)dy<<1) - dx; for (j=0; j<=dx; j++) { video_pt(x,y,c) ; if (e>=0) { if (xchange==1) x = x + s1; else y = y + s2; e = e - ((int)dx<<1); } if (xchange==1) y = y + s2; else x = x + s1; e = e + ((int)dy<<1); } } //================================== //return the value of one point //at x,y with color nonzero=white 0=black char video_set(char x, char y) { //The following construction //detects exactly one bit at the x,y location i=((int)x>>3) + ((int)y<<4) ; return ( screen[i] & 1<<(7-(x & 0x7))); } //********************************* void you_win(void) { game_over(); } //************************************* void you_die(void) { game_over(); } //************************************** void game_over(void) { if(result == 1) { //video_puts(35,55,cu3); // video_puts(65,55,cu5); } if(result == 2) { //video_puts(35,55,cu3); //video_puts(65,55,cu4); //video_putchar(xchar,ychar,'A'); } if(reset == 1) { } } //********************************* //================================== // set up the ports and timers void main(void) { //init timer 1 to generate sync OCR1A = lineTime; //One NTSC line TCCR1B = 9; //full speed; clear-on-match TCCR1A = 0x00; //turn off pwm and oc lines TIMSK = 0x10; //enable interrupt T1 cmp //init ports DDRD = 0xf0; //video out and switches //D.5 is sync:1000 ohm + diode to 75 ohm resistor //D.6 is video:330 ohm + diode to 75 ohm resistor DDRC = 0x00; //inputs //sets up ports to be input buttons or inputs from the receiver pushed1 = 0; pushed2 = 0; //initialize synch constants LineCount = 1; syncON = 0b00000000; syncOFF = 0b00100000; video_puts(10,30,cu1); //FOR DISPLAYING TITLE // video_puts(65,3,cu2); //side lines #define width 126 video_line(0,0,0,99,1); video_line(width,0,width,99,1); video_line(49,0,49,99,1); //main game sidelines video_line(100,0,100,99,1); //top line & bottom lines video_line(0,0,49,0,1); video_line(100,0,width,0,1); video_line(0,99,width,99,1); //init software timer t=0; time=0; //video_putchar((char)(x>>8),(char)(y>>8),39); //init musical scale //note = 0; //musicT = 0; //use OC0 (pin B.3) for music //DDRB.3 = 1 ; //init the A to D converter //channel zero/ left adj /EXTERNAL Aref //!!!CONNECT Aref jumper!!!! ADMUX = 0b00100000; //enable ADC and set prescaler to 1/128*16MHz=125,000 //and clear interupt enable //and start a conversion ADCSR = 0b11000111; //enable sleep mode MCUCR = 0b10000000; #asm ("sei"); //standard_fall_speed = 5; //fall_speed = 5; fall_speed = 0; //selects current fall speed - set to zero at bottom standard_fall_speed = 0; //sets standard fall speed lose = 1; //used to set losing mode or to start a new game starting = 1; //used only at initial startup //hold_on_next_block = 1; posy = 4; //sets initial y position of the first block //prev_posy = 4; posx = 75; //sets initial x position of the first block move_down_counter = 127; //used in moving down all other blocks during a line clear //bottom_adder = 5; speed = 30; //sets current speed, is used to compare to the number of screen refreshes for moving blocks down reg_speed = 30; //sets normal speed ltime = 5; //time(); // stime = (unsigned) ltime/2; // srand(stime); //used to seed the randomizer for which block comes up next_rand = rand()%7; //randomizes next block random_block = rand()%7+1; //randomizes initial current block mod_rand = random_block%7; //used for mod on randomize function draw_next(25,50); //draws next block prev_drawx = 20; prev_drawy = 75; //The following loop executes once/video line during lines //1-230, then does all of the frame-} processing while(1) { //stall here until next line starts //sleep enable; mode=idle //use sleep to make entry into sync ISR uniform time #asm ("sleep"); //The following code executes during the vertical blanking //Code here can be as long as //a total of 60 lines x 63.5 uSec/line x 8 cycles/uSec button = ~PINC; //sets the variable button the value on PINC /////////////////////// ////////////////////// ALL BUTTONS BELOW USE THE SAME FORMAT OF FLAGS TO AVOID READING ONE PRESS MULTIPLE TIMES /////////////////////// //////////////////////// if(button == 0x01) //if first button is pressed/if port C0 has a value { if(pushed1 == 0) //set pushed flag { if(lose == 1) //if game is over, used to reset game lose = 2; //srand(count_frames); if(changed != 3) //changed = rotation { next = changed +1; //check for rotate clockwise until reaching 3 } else { next = 0; //check for when position 3 is reached, go back to 0 } cw = 1; //clockwise = 1 check_can_rotate(posx,posy,mod_rand, next); //check if it is safe to rotate to new position if(cannot_rotate == 0) //if safe { pushed1 = 1; //set button flag //if(action == 0) //action = 1; //else //action = 3; if(changed != 3) //rotate clockwise until hitting 3 { prev_changed = changed; //store previous rotation orientation changed = changed +1; //increase rotation } else { changed = 0; //rolls over rotation prev_changed = 3; //rolls over previous position } } else cannot_rotate = 0; //if it couldn't rotate, set var back to 0 } } else pushed1 = 0; //set button flag to avoid multiple reads of same push if(button == 0x02) { if(pushed2 == 0) { if(lose == 1) lose = 2; //restart after loss if(changed != 0) //changed = rotation //used to determine if rotation safe { next = changed -1; //rotate counter clockwise } else { next = 3; //roll over rotate variable } cw = 0; check_can_rotate(posx,posy,mod_rand, next); //check if safe to rotate if(cannot_rotate == 0) { pushed2 = 1; if(changed != 0) //changed = rotation { prev_changed = changed; changed = changed -1; //change rotation } else { changed = 3; prev_changed = 0; //roll over rotation } } else cannot_rotate = 0; } } else pushed2 = 0; if(button == 0x04) { if(pushed3 == 0) { if(lose == 1) //reset after loss lose = 2; move_right(); //check if safe to move right pushed3 = 1; } } else pushed3 = 0; if(button == 0x08) { if(pushed4 == 0) { if(lose == 1) //reset after loss lose = 2; move_left(); //check if safe to move left pushed4 = 1; } } else pushed4 = 0; if(button == 0x10) { if(pushed5 == 0) { if(lose == 1) //reset after loss lose = 2; //speed = speed - 10; //speed = reg_speed; speed = 1; //speeds up block when thrown down slam_down = 1; //sets flage for slam down mode pushed5 = 1; } } else pushed5 = 0; if(button == 0x03) { if(pushed6 == 0) { hold_on_next = ~hold_on_next; //pauses the game remotely pushed6 = 1; } } else pushed6 = 0; if(button == 0x0C) { if(pushed7 == 0) //resets the game remotely { lose = 2; posx = 75; posy = 4; hold_on_next = 0; //allows for resetting while paused next_game(); pushed7 = 1; } } else pushed7 = 0; //////////////////////////////////////////////////// if (LineCount==231) { next_game(); //used to check for loss and starting next game //clear_on_next(); move_line_down(); //used to move lines down after completing a line count_frames++; //counts number of frames since block last moved down if(count_frames >= speed) //sets how fast block moves down { slam_counter++; if((slam_down == 1) && (slam_counter > 20)) //used to slam the block down { speed = reg_speed; slam_down = 0; //resets speed to normal slam_counter = 0; } check_bottom(); //checks if block should stop moving downwards //if((posy+20) < 100) //{ // prev_posy = posy; if(hold_on_next == 0) //checks to make sure not paused { if((posy + fall_speed) < 100) posy = posy + fall_speed; //moves block down by fall speed each time (usually 5) } count_frames = 0; //resets frame counter for moving block down // drop = 1; //} } // /if(fall_speed == 0) // { // at_bottom = 0; // } fall_speed = standard_fall_speed; //resets block fallspeed to 5 after it has stopped at bottom //get the sample //Ain = ADCH; //start another conversion //ADCSR.6=1; //move = 0; //Play a note //TCCR0 bits: //bit 7 no force: //bit 3 CTC on: //bit 5,4 toggle OC0 pin //bit 6 no PWM //bit 2-0 prescaler 256 so 1 tick is 16 microsec // // if((musicT++) > 15) //each note 1/4 second // { // musicT = 0; // TCCR0 = 0; // if (notes[note]>0) TCCR0 = 0b00011100 ; //not a rest // OCR0 = notes[note++] ; // if (note>18) note = 0; //test for } of scale // } //update the second clock if ((++t>59) && (result == 0)) //displays a running clock on the screen { t=0; if((hold_on_next == 0) && (starting == 0)) //stops clock if game is paused time = time + 1; sprintf(ts,"%04d",time); video_putsmalls(104,93,ts); } //sprintf(blob,"%05u",fuel); //sprintf(blob,"%05u",bottom_y[0]); //video_putsmalls(104,20,blob); sprintf(blob2,"%04u",(posy)); //displays y position of blocks video_putsmalls(104,40,blob2); //sprintf(blob3,"%04u",(r)); //video_putsmalls(104,60,blob3); //s = video_set((char)(x>>8),(char)(y>>8) + 8); //mod_rand = 1; //used for selecting specific block for testing purposes if((hold_on_next == 0) && (starting == 0)) //checks if game is paused or just starting { if(mod_rand == 0) //draws I block if randomly selected { draw_i(prev_drawx, prev_drawy, 0, prev_drawchanged); //erases previous block prev_drawx = posx; //updates x position of next previous block prev_drawy = posy; //updates y position of next previous block prev_drawchanged = changed; //updates orientation of next previous block draw_i(posx, posy, 1, changed); //draws block } else if(mod_rand == 1) //draws O block if selected { draw_o(prev_drawx, prev_drawy, 0, prev_drawchanged); prev_drawx = posx; prev_drawy = posy; prev_drawchanged = changed; draw_o(posx, posy, 1, changed); } else if(mod_rand == 2) //draws J block if selected { draw_j(prev_drawx, prev_drawy, 0, prev_drawchanged); prev_drawx = posx; prev_drawy = posy; prev_drawchanged = changed; draw_j(posx, posy, 1, changed); } else if(mod_rand == 3) //draws Z block if selected { draw_z(prev_drawx, prev_drawy, 0, prev_drawchanged); prev_drawx = posx; prev_drawy = posy; prev_drawchanged = changed; draw_z(posx, posy, 1, changed); } else if(mod_rand == 4) //draws T block if selected { draw_t(prev_drawx, prev_drawy, 0, prev_drawchanged); prev_drawx = posx; prev_drawy = posy; prev_drawchanged = changed; draw_t(posx, posy, 1, changed); } else if(mod_rand == 5) //draws L block if selected { draw_l(prev_drawx, prev_drawy, 0, prev_drawchanged); prev_drawx = posx; prev_drawy = posy; prev_drawchanged = changed; draw_l(posx, posy, 1, changed); } else if(mod_rand == 6) //draws S block if selected { draw_s(prev_drawx, prev_drawy, 0, prev_drawchanged); prev_drawx = posx; prev_drawy = posy; prev_drawchanged = changed; draw_s(posx, posy, 1, changed); } } if(count_frames == 10) //used to draw next block draw_next(25,50); } //line 231 } //while } //main void check_can_rotate(char x, char y, char block_num, char next_rot) //checks if a block can rotate { switch(block_num) //checks what kind of block it is { case 0: switch(next_rot) //checks what orientation block is in { case 0: //FLAT case 2: check_block(x, y ); //checks position of blocks //check_block(x+5, y ); check_block(x+10, y ); check_block(x+15, y ); break; case 1: case 3: check_block(x+5, y-5 ); //checks position of blocks //check_block(x+5, y ); check_block(x+5, y+5 ); check_block(x+5, y+10 ); break; } break; case 1: //O switch(next_rot) { //check_block(x, y ); //check_block(x, y+5 ); //O block doesn't rotate //check_block(x+5, y ); //check_block(x+5, y+5 ); } break; case 2: //J switch(next_rot) { case 0: check_block(x, y ); // check_block(x, y+5 ); ////////// //check_block(x+5, y+5 ); check_block(x+10, y+5 ); //checks position of blocks break; case 1: check_block(x+5, y ); //// //check_block(x+5, y+5 ); // check_block(x+5, y+10 ); // check_block(x+10, y ); break; case 2: check_block(x+10, y+10 ); check_block(x, y+5 ); //check_block(x+5, y+5 ); /////// //checks position of blocks check_block(x+10, y+5 ); // break; case 3: check_block(x+5, y ); // //check_block(x+5, y+5 ); // check_block(x+5, y+10 ); // check_block(x, y+10 ); //// break; } break; case 3: //Z switch(next_rot) { case 0: case 2: check_block(x, y ); //check_block(x+5, y ); ////// //check_block(x+5, y+5 ); ////// check_block(x+10, y+5 ); break; case 1: case 3: // //check_block(x+5, y ); // //checks position of blocks //check_block(x+5, y+5 ); //// check_block(x, y+5 ); // check_block(x, y+10 ); // break; } break; case 4: //T switch(next_rot) { case 0: if(cw == 1) check_block(x, y+5); //check_block(x+5, y+5 ); if(cw == 0) ////// check_block(x+10, y+5 ); // //check_block(x+5, y+10 ); break; case 1: if(cw == 1) check_block(x+5, y ); // //check_block(x, y+5 ); //// //checks position of blocks //check_block(x+5, y+5 ); // if(cw == 0) check_block(x+5, y+10 ); break; case 2: //check_block(x+5, y ); // if(cw == 0) ////// check_block(x, y+5 ); //check_block(x+5, y+5 ); if(cw == 1) check_block(x+10, y+5 ); //////////CHECK THESE case 3: if(cw == 0) check_block(x+5, y ); // //check_block(x+5, y+5 ); //// if(cw == 1) // check_block(x+5, y+10 ); //check_block(x+10, y+5 ); break; } break; case 5: switch(next_rot) //L { case 0: check_block(x, y+10 ); check_block(x, y+5 ); ////////// ///////////////////////// //check_block(x+5, y+5 ); // check_block(x+10, y+5 ); //////////////////////// break; case 1: check_block(x+5, y ); //// /////////////////////// //check_block(x+5, y+5 ); // //checks position of blocks check_block(x+5, y+10 ); // ////////////////// check_block(x, y ); break; case 2: check_block(x+10, y ); check_block(x, y+5 ); // /////////////////// //check_block(x+5, y+5 ); /////// check_block(x+10, y+5 ); ///////////////////// break; case 3: check_block(x+5, y ); // ////////////////////////// //check_block(x+5, y+5 ); // check_block(x+5, y+10 ); // ////////////////////////// check_block(x+10, y+10 ); //// break; } break; case 6: //s switch(next_rot) { case 0: case 2: check_block(x+10, y ); check_block(x+5, y ); ///// //check_block(x+5, y+5 ); ///// //checks position of blocks //check_block(x, y+5 ); break; case 1: case 3: // check_block(x, y ); // //check_block(x+5, y+5 ); //// //check_block(x, y+5 ); // check_block(x+5, y+10 ); // break; } break; } } void check_block(char x, char y) { //checks a specfic square that makes up the blocks //to see if it will be drawn over an //already existing block or line if(video_set(x,y)>0) { cannot_rotate = 1; } } void move_right() { for(counter2 = 0; counter20) r = 1; } if((posx + 5) > 99) { r = 1; } if(r==0) { posx = posx + 5; //if able to, moves block right } r = 0; //for(counter1 = 0; counter10) r = 1; } //sprintf(blob3,"%04u",(r)); //video_putsmalls(104,60,blob3); //if((posx-5)<49) //{ // r = 1; //} if(r==0) { posx = posx - 5; //if possible, moves block left } r = 0; //for(counter1 = 0; counter1= 0) // { // for (counter1 = 50; counter1<100; counter1 = counter1 + 5) // { // draw_block(counter1, line_to_clear[clears_left]+10, 0); // } // // clears_left--; // } // if(clears_left == -1) // { // // // // // clears_left = -2; // } // } // void move_line_down() //moves lines down { start_clear = line_to_clear[lines-1-lines_to_move];// + start_offset;//+5; //stores position of line to clear if(move_down_counter == 125) move_down_counter = start_clear; if((move_down_counter <= start_clear) && (move_down_counter > 9) && lines_to_move >= 0) //if still lines to move down //if(move_down_counter > 9) { hold_on_next = 1; for (counter1 = 50; counter1<100; counter1 = counter1 + 5) { //r = r & video_set(counter2, counter1); if(video_set(counter1,(move_down_counter-5)) != 0) //if there is a block in line above { draw_block(counter1,move_down_counter,1); //draw block in current line //r = 0; } else //if there is no block in line above { draw_block(counter1,move_down_counter,0); //draw a blank block } } move_down_counter = move_down_counter-5; //decrease counter for line to draw on if(lines_to_move == 0) //if all lines that need to be moved have been { counter2++; //lines_to_move--; if(move_down_counter<=posy+5) hold_on_next = 0; //unpauses blocks //posx = 5; //posy = 95; //prev_drawx = 75; //prev_drawy = 44; //move_down_counter = 127; } } if((lines_to_move > 0) && (move_down_counter<= 9)) //if there are still lines to move { move_down_counter = 125; lines_to_move--; start_offset = start_offset + 5; //if(lines_to_move == -1) // lines_to_move = 0; } //else if (lines_to_move <= 0) //{ // move_down_counter = 0; // lines_to_move = -1; //hold_on_next = 0; //} // //for (counter1 = 6; counter1<13; counter1++) screen[1568+counter1] = screen[480+counter1-6]; // // for (counter1 = 1584;/*(line_to_clear[lines-1]<<4);*/ counter1>80; counter1 = counter1 - 16) //changed 1400 to line_to_clear[lines-1]<<4 // { // for (counter2 = 6; counter2<12; counter2++) // { // //draw_block(counter1, line_to_clear[clears_left], 0); // screen[counter1+counter2] = screen[counter1 + counter2 - 80]; // } // } } void next_game() //used for when player loses or resets game, //clears the screen over multiple passes to prevent artifacts //then redraws the lines { if(starting == 1) { //stime = (unsigned) t/2; //mod_rand= (rand() / t)%5; //do randomizing stuff } starting = 0; if (lose == 2) //if button has been pressed after a game over { for(counter1 = 0; counter1 < 1600; counter1++) { screen[counter1] = 0; } } if(lose == 3) //draws part of the lines this cycle { //top line & bottom lines video_line(0,0,49,0,1); video_line(100,0,width,0,1); video_line(0,99,width,99,1); } if(lose == 4) //draws more of the lines this cycle { video_line(0,0,0,99,1); video_line(width,0,width,99,1); video_line(49,0,49,99,1); //main game sidelines } if(lose == 5) //finishes up drawing screen { video_line(100,0,100,99,1); lose = 0; fall_speed = 5; standard_fall_speed = 5; video_puts(10,30,cu1); } if(lose == 4) lose = 5; if(lose == 3) lose = 4; if(lose == 2) lose = 3; } void check_bottom() //check to see if bottom of block has hit bottom of screen //or is sitting on top of another block { for(counter1 = 0; counter10) //if there is another block at the bottom s = 1; } //sprintf(blob3,"%04u",(s)); //video_putsmalls(104,60,blob3); if(s>0) { if(move_down_counter != 125) //if not trying to move lines down { fall_speed = 0; //stop next block form falling s = 0; if(posy < 5) //checks for loss { fall_speed = 0; standard_fall_speed = 0; //sprintf(blob3,"%04",("lose")); // video_putsmalls(104,60,blob3); //video_putchar(104,60, 'L'); video_putsmalls(104,60,cu2); lose = 1; } posx = 75; //initializes position of next block posy = 4; //prev_posy = 4; //bottom_adder = 0; //at_bottom = 1; speed = reg_speed; //resets speed slam_down = 0; slam_counter = 0; prev_drawx = 20; //resets previous block prev_drawy = 80; prev_drawchanged = 0; if(lose == 0) { random_block = next_rand; //sets new block to previous next mod_rand = random_block % 7; //randomizes new next block next_rand = rand() % 7; } check_line(); //checks to see if line has been completed draw_next(25,50); //draws what block will be next on the side } } } void draw_next(char x, char y) //draws what will be next block on the side of the screen { switch(prev) //erases previous block { case 0: draw_i(x, y, 0,1); break; case 1: draw_o(x, y, 0, 1); break; case 2: draw_j(x, y, 0, 1); break; case 3: draw_z(x, y, 0, 1); break; case 4: draw_t(x, y, 0, 1); break; case 5: draw_l(x, y, 0, 1); break; case 6: draw_s(x, y, 0, 1); break; } switch(next_rand%7) //draws next block { case 0: draw_i(x, y, 1, 1); break; case 1: draw_o(x, y, 1, 1); break; case 2: draw_j(x, y, 1, 1); break; case 3: draw_z(x, y, 1, 1); break; case 4: draw_t(x, y, 1, 1); break; case 5: draw_l(x, y, 1, 1); break; case 6: draw_s(x, y, 1, 1); break; } prev = next_rand%7; } void draw_block(char x, char y, char c) //draws a square at any x,y location //if c = 1 draws the block //if c = 0 erases the block { v7 = x; v8 = y; video_pt(v7, v8, c); video_pt(v7+1, v8, c); video_pt(v7+2, v8, c); video_pt(v7+3, v8, c); video_pt(v7+4, v8, c); video_pt(v7, v8+1, c); video_pt(v7+4, v8+1, c); video_pt(v7, v8+2, c); video_pt(v7+4, v8+2, c); video_pt(v7, v8+3, c); video_pt(v7+4, v8+3, c); video_pt(v7, v8+4, c); video_pt(v7+1, v8+4, c); video_pt(v7+2, v8+4, c); video_pt(v7+3, v8+4, c); video_pt(v7+4, v8+4, c); // for (v6=0;v6<5;v6++) // { // v8 = y+v6; // video_pt(v7, v8, c); // video_pt(v7+1, v8, c); // video_pt(v7+2, v8, c); // video_pt(v7+3, v8, c); // video_pt(v7+4, v8, c); // } } void draw_i(char x, char y, char c, char rotation) //defines the I block { switch(rotation) { case 0: //FLAT case 2: draw_block(x, y, c); //draws the block draw_block(x+5, y, c); draw_block(x+10, y, c); draw_block(x+15, y, c); if(c==1) { bottom_x[0] = x+1; //defines locations of the bottom of the block bottom_x[1] = x+6; bottom_x[2] = x+11; bottom_x[3] = x+16; bottom_y[0] = y+5; bottom_y[1] = y+5; bottom_y[2] = y+5; bottom_y[3] = y+5; bottoms = 4; //defines number of bottom blocks to check left_sidex[0] = x; //defines left side of block left_sidey[0] = y; left_sidex[1] = x; //defines left side of block left_sidey[1] = y+2; lefts = 2; right_sidex[0] = x+20; //defines right side of block right_sidey[0] = y; right_sidex[1] = x+20; //defines right side of block right_sidey[1] = y+2; rights = 2; top = y; } break; case 1: //defines same block in a different orientation case 3: draw_block(x+5, y-5, c); draw_block(x+5, y, c); draw_block(x+5, y+5, c); draw_block(x+5, y+10, c); if(c==1) { bottom_x[0] = x+6; bottom_y[0] = y+15; bottom_x[1] = x + 8; bottom_y[1] = y + 15; bottoms = 2; left_sidex[0] = x+5; left_sidex[1] = x+5; left_sidex[2] = x+5; left_sidex[3] = x+5; left_sidey[0] = y-5; left_sidey[1] = y; left_sidey[2] = y+5; left_sidey[3] = y+10; lefts = 4; right_sidex[0] = x+10; right_sidex[1] = x+10; right_sidex[2] = x+10; right_sidex[3] = x+10; right_sidey[0] = y-5; right_sidey[1] = y; right_sidey[2] = y+5; right_sidey[3] = y+10; rights = 4; top = y-5; } break; } } void draw_o(char x, char y, char c, char rotation) { draw_block(x, y, c); draw_block(x, y+5, c); draw_block(x+5, y, c); draw_block(x+5, y+5, c); if(c==1) { bottom_x[0] = x+1; bottom_x[1] = x+5; bottom_y[0] = y+10; bottom_y[1] = y+10; bottoms = 2; left_sidex[0] = x; left_sidex[1] = x; left_sidey[0] = y; left_sidey[1] = y+5; lefts = 2; right_sidex[0] = x+10; right_sidex[1] = x+10; right_sidey[0] = y; right_sidey[1] = y+5; rights = 2; top = y; } }void draw_j(char x, char y, char c, char rotation) { switch(rotation) { case 0: draw_block(x, y, c); // draw_block(x, y+5, c); ////////// draw_block(x+5, y+5, c); draw_block(x+10, y+5, c); if(c==1) { bottom_x[0] = x; bottom_y[0] = y+10; bottom_x[1] = x+5; bottom_y[1] = y+10; bottom_x[2] = x+10; bottom_y[2] = y+10; bottoms = 3; left_sidex[0] = x; left_sidex[1] = x; left_sidey[0] = y; left_sidey[1] = y+5; lefts = 2; right_sidex[0] = x+15; right_sidey[0] = y+5; right_sidex[1] = x+5; right_sidey[1] = y; right_sidex[2] = x+5; right_sidey[2] = y+2; rights = 3; top = y; } break; case 1: draw_block(x+5, y, c); //// draw_block(x+5, y+5, c); // draw_block(x+5, y+10, c); // draw_block(x+10, y, c); if(c==1) { bottom_x[0] = x+6; bottom_y[0] = y+15; bottom_x[1] = x+11; bottom_y[1] = y+5; bottom_x[2] = x+8; bottom_y[2] = y+15; bottoms = 3; left_sidex[0] = x+5; left_sidex[1] = x+5; left_sidex[2] = x+5; left_sidey[0] = y; left_sidey[1] = y+5; left_sidey[2] = y+10; lefts = 3; right_sidex[0] = x+15; right_sidey[0] = y; right_sidex[1] = x+10; right_sidey[1] = y+5; right_sidex[2] = x+10; right_sidey[2] = y+10; right_sidex[3] = x+15; right_sidey[3] = y+2; rights = 4; top = y; } break; case 2: draw_block(x+10, y+10, c); draw_block(x, y+5, c); draw_block(x+5, y+5, c); /////// draw_block(x+10, y+5, c); // if(c==1) { bottom_x[0] = x+10; bottom_y[0] = y+15; bottom_x[1] = x; bottom_y[1] = y+10; bottom_x[2] = x+5; bottom_y[2] = y+10; bottom_x[3] = x+12; bottom_y[3] = y+15; bottoms = 4; left_sidex[0] = x; left_sidey[0] = y+5; left_sidex[1] = x+10; left_sidey[1] = y+10; left_sidex[2] = x; left_sidey[2] = y+7; lefts = 3; right_sidex[0] = x+15; right_sidey[0] = y+5; right_sidex[1] = x+15; right_sidey[1] = y+10; rights = 2; top = y+5; } break; case 3: draw_block(x+5, y, c); // draw_block(x+5, y+5, c); // draw_block(x+5, y+10, c); // draw_block(x, y+10, c); //// if(c==1) { bottom_x[0] = x; bottom_y[0] = y+15; bottom_x[1] = x+5; bottom_y[1] = y+15; bottoms = 2; left_sidex[0] = x; left_sidey[0] = y+10; left_sidex[1] = x+5; left_sidey[1] = y; left_sidex[2] = x+5; left_sidey[2] = y+5; left_sidex[3] = x; left_sidey[3] = y+12; lefts = 4; right_sidex[0] = x+10; right_sidey[0] = y; right_sidex[1] = x+10; right_sidey[1] = y+5; right_sidex[2] = x+10; right_sidey[2] = y+10; rights = 3; top = y; } break; } } void draw_z(char x, char y, char c, char rotation) { switch(rotation) { case 0: case 2: draw_block(x, y, c); draw_block(x+5, y, c); ////// draw_block(x+5, y+5, c); ////// draw_block(x+10, y+5, c); if(c==1) { bottom_x[0] = x+1; bottom_y[0] = y+5; bottom_x[1] = x+6; bottom_y[1] = y+10; bottom_x[2] = x+11; bottom_y[2] = y+10; bottoms = 3; left_sidex[0] = x; left_sidex[1] = x+5; left_sidex[2] = x; left_sidey[0] = y; left_sidey[1] = y+5; left_sidey[2] = y+2; lefts = 3; right_sidex[0] = x+10; right_sidey[0] = y; right_sidex[1] = x+15; right_sidey[1] = y+5; right_sidex[1] = x+15; right_sidey[1] = y+7; rights = 3; top = y; } break; case 1: case 3: // draw_block(x+5, y, c); // draw_block(x+5, y+5, c); //// draw_block(x, y+5, c); // draw_block(x, y+10, c); // if(c==1) { bottom_x[0] = x+6; bottom_y[0] = y+10; bottom_x[1] = x+1; bottom_y[1] = y+15; bottom_x[2] = x+3; bottom_y[2] = y+15; bottoms = 3; left_sidex[0] = x+5; left_sidex[1] = x; left_sidex[2] = x; left_sidey[0] = y; left_sidey[1] = y+5; left_sidey[2] = y+10; lefts = 3; right_sidex[0] = x+10; right_sidey[0] = y; right_sidex[1] = x+10; right_sidey[1] = y+5; right_sidex[2] = x+5; right_sidey[2] = y+10; rights = 3; top = y; } break; } } void draw_t(char x, char y, char c, char rotation) { switch(rotation) { case 0: draw_block(x, y+5, c); draw_block(x+5, y+5, c); ////// draw_block(x+10, y+5, c); // draw_block(x+5, y+10, c); if(c==1) { bottom_x[0] = x+1; bottom_y[0] = y+10; bottom_x[1] = x+6; bottom_y[1] = y+15; bottom_x[2] = x+11; bottom_y[2] = y+10; bottom_x[3] = x+8; bottom_y[3] = y+15; bottoms = 4; left_sidex[0] = x; left_sidex[1] = x+5; left_sidey[0] = y+5; left_sidey[1] = y+10; lefts = 2; right_sidex[0] = x+10; right_sidey[0] = y+10; right_sidex[1] = x+15; right_sidey[1] = y+5; rights = 2; top = y +5; } break; case 1: draw_block(x+5, y, c); // draw_block(x, y+5, c); //// draw_block(x+5, y+5, c); // draw_block(x+5, y+10, c); if(c==1) { bottom_x[0] = x+1; bottom_y[0] = y+10; bottom_x[1] = x+6; bottom_y[1] = y+15; bottom_x[2] = x+8; bottom_y[2] = y+15; bottom_x[3] = x+3; bottom_y[3] = y+10; bottoms = 4; left_sidex[0] = x+5; left_sidex[1] = x; left_sidex[2] = x+5; left_sidey[0] = y; left_sidey[1] = y+5; left_sidey[2] = y+10; lefts = 3; right_sidex[0] = x+10; right_sidey[0] = y; right_sidex[1] = x+10; right_sidey[1] = y+5; right_sidex[2] = x+10; right_sidey[2] = y+10; rights = 3; top = y; } break; case 2: draw_block(x+5, y, c); // draw_block(x, y+5, c); ////// draw_block(x+5, y+5, c); draw_block(x+10, y+5, c); if(c==1) { bottom_x[0] = x+1; bottom_y[0] = y+10; bottom_x[1] = x+6; bottom_y[1] = y+10; bottom_x[2] = x+11; bottom_y[2] = y+10; bottoms = 3; left_sidex[0] = x+5; left_sidex[1] = x; left_sidey[0] = y; left_sidey[1] = y+5; lefts = 2; right_sidex[0] = x+10; right_sidey[0] = y; right_sidex[1] = x+15; right_sidey[1] = y+5; rights = 2; top = y; } break; case 3: draw_block(x+5, y, c); // draw_block(x+5, y+5, c); //// draw_block(x+5, y+10, c); // draw_block(x+10, y+5, c); if(c==1) { bottom_x[0] = x+6; bottom_y[0] = y+15; bottom_x[1] = x+11; bottom_y[1] = y+10; bottom_x[2] = x+8; bottom_y[2] = y+15; bottoms = 3; left_sidex[0] = x+5; left_sidex[1] = x+5; left_sidex[2] = x+5; left_sidey[0] = y; left_sidey[1] = y+5; left_sidey[2] = y+10; lefts = 3; right_sidex[0] = x+10; right_sidey[0] = y; right_sidex[1] = x+15; right_sidey[1] = y+5; right_sidex[2] = x+10; right_sidey[2] = y+10; rights = 3; top = y; } break; } } void draw_l(char x, char y, char c, char rotation) { switch(rotation) { case 0: draw_block(x, y+10, c); draw_block(x, y+5, c); ////////// draw_block(x+5, y+5, c); // draw_block(x+10, y+5, c); if(c==1) { bottom_x[0] = x+1; bottom_y[0] = y+15; bottom_x[1] = x+5; bottom_y[1] = y+10; bottom_x[2] = x+10; bottom_y[2] = y+10; bottom_x[3] = x+3; bottom_y[3] = y+15; bottoms = 4; left_sidex[0] = x; left_sidex[1] = x; left_sidey[0] = y+10; left_sidey[1] = y+5; lefts = 2; right_sidex[0] = x+15; right_sidey[0] = y+5; right_sidex[1] = x+5; right_sidey[1] = y+10; right_sidex[2] = x+15; right_sidey[2] = y+7; rights = 3; top = y + 5; } break; case 1: draw_block(x+5, y, c); //// draw_block(x+5, y+5, c); // draw_block(x+5, y+10, c); // draw_block(x, y, c); if(c==1) { bottom_x[0] = x+6; bottom_y[0] = y+15; bottom_x[1] = x+1; bottom_y[1] = y+5; bottom_x[2] = x+8; bottom_y[2] = y+15; bottoms = 3; left_sidex[0] = x; left_sidex[1] = x+5; left_sidex[2] = x+5; left_sidex[3] = x; left_sidey[0] = y; left_sidey[1] = y+5; left_sidey[2] = y+10; left_sidey[3] = y+2; lefts = 4; right_sidex[0] = x+10; right_sidey[0] = y; right_sidex[1] = x+10; right_sidey[1] = y+5; right_sidex[2] = x+10; right_sidey[2] = y+10; rights = 3; top = y; } break; case 2: draw_block(x+10, y, c); draw_block(x, y+5, c); // draw_block(x+5, y+5, c); /////// draw_block(x+10, y+5, c); if(c==1) { bottom_x[0] = x+10; bottom_y[0] = y+10; bottom_x[1] = x; bottom_y[1] = y+10; bottom_x[2] = x+5; bottom_y[2] = y+10; bottoms = 3; left_sidex[0] = x; left_sidey[0] = y+5; left_sidex[1] = x+10; left_sidey[1] = y; left_sidex[2] = x; left_sidey[2] = y+7; lefts = 3; right_sidex[0] = x+15; right_sidey[0] = y+5; right_sidex[1] = x+15; right_sidey[1] = y; rights = 2; top = y; } break; case 3: draw_block(x+5, y, c); // draw_block(x+5, y+5, c); // draw_block(x+5, y+10, c); // draw_block(x+10, y+10, c); //// if(c==1) { bottom_x[0] = x+11; bottom_y[0] = y+15; bottom_x[1] = x+6; bottom_y[1] = y+15; bottoms = 2; left_sidex[0] = x+5; left_sidey[0] = y+10; left_sidex[1] = x+5; left_sidey[1] = y; left_sidex[2] = x+5; left_sidey[2] = y+5; lefts = 3; right_sidex[0] = x+10; right_sidey[0] = y; right_sidex[1] = x+10; right_sidey[1] = y+5; right_sidex[2] = x+15; right_sidey[2] = y+10; right_sidex[3] = x+15; right_sidey[3] = y+12; rights = 4; top = y; } break; } } void draw_s(char x, char y, char c, char rotation) { switch(rotation) { case 0: case 2: draw_block(x+10, y, c); draw_block(x+5, y, c); ///// draw_block(x+5, y+5, c); ///// draw_block(x, y+5, c); if(c==1) { bottom_x[0] = x+1; bottom_y[0] = y+10; bottom_x[1] = x+6; bottom_y[1] = y+10; bottom_x[2] = x+11; bottom_y[2] = y+5; bottoms = 3; left_sidex[0] = x; left_sidex[1] = x+5; left_sidex[2] = x; left_sidey[0] = y+5; left_sidey[1] = y; left_sidey[2] = y+2; lefts = 3; right_sidex[0] = x+10; right_sidey[0] = y+5; right_sidex[1] = x+15; right_sidey[1] = y; right_sidex[2] = x+15; right_sidey[2] = y+2; rights = 3; top = y; } break; case 1: case 3: // draw_block(x, y, c); // draw_block(x+5, y+5, c); //// draw_block(x, y+5, c); // draw_block(x+5, y+10, c); // if(c==1) { bottom_x[0] = x+1; bottom_y[0] = y+10; bottom_x[1] = x+6; bottom_y[1] = y+15; bottom_x[2] = x+8; bottom_y[2] = y+15; bottoms = 3; left_sidex[0] = x; left_sidex[1] = x; left_sidex[2] = x+5; left_sidey[0] = y; left_sidey[1] = y+5; left_sidey[2] = y+10; lefts = 3; right_sidex[0] = x+5; right_sidey[0] = y; right_sidex[1] = x+10; right_sidey[1] = y+5; right_sidex[2] = x+10; right_sidey[2] = y+10; rights = 3; top = y; } break; } }