//Receive.c //video gen with fixed pint animationi //D.5 is sync:1000 ohm + diode to 75 ohm resistor //D.6 is video:330 ohm + diode to 75 ohm resistor #pragma regalloc- //I allocate the registers myself #pragma optsize- //optimize for speed //Includes #include #include #include #include #include<.\txrx.c> //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 Release 0 #define Debounce 1 #define Endchar 2 #define Still_Pressed 3 #define Debounce_Release 4 #define Done 5 char PushState; //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+ //definitions #define MAX_RX_LENGTH 32 #define data_buffer 32 #define threshold 2000 //declarations char my_rx_data[MAX_RX_LENGTH]; unsigned int time; char done, length, j, k, current_line, last_replaced; char seen_ids[4]; char gotfirstbyteflag, donereceiving; char syncON, syncOFF; int LineCount; char screen[1600]; int score, penalty; //test to display at top of screen char cu1[]="SCORE"; char cu2[]="PENALTY"; char cu3[]="WIN"; char cu4[]="LOSE"; char cu5[]="PUNCH TO PLAY"; //Point plot lookup table //One bit masks flash char pos[8]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01}; //=============================================== // Full ascii 5x7 char set // Designed by: David Perez de la Cruz,and Ed Lau // see: http://instruct1.cit.cornell.edu/courses/ee476/FinalProjects/s2005/dp93/index.html flash char ascii[128][7] = { //0 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, //1 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, //2 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, //3 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, //4 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, //5 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, //6 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, //7 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, //8 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, //9 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, //10 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, //11 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, //12 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, //13 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, //14 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, //15 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, //16 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, //17 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, //18 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, //19 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, //20 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, //21 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, //22 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, //23 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, //24 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, //25 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, //26 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, //27 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, //28 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, //29 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, //30 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, //31 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, //32 Space 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, //33 Exclamation ! 0b01100000, 0b01100000, 0b01100000, 0b01100000, 0b00000000, 0b00000000, 0b01100000, //34 Quotes " 0b01010000, 0b01010000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, //35 Number # 0b00000000, 0b01010000, 0b11111000, 0b01010000, 0b11111000, 0b01010000, 0b00000000, //36 Dollars $ 0b01110000, 0b10100000, 0b10100000, 0b01110000, 0b00101000, 0b00101000, 0b01110000, //37 Percent % 0b01000000, 0b10101000, 0b01010000, 0b00100000, 0b01010000, 0b10101000, 0b00010000, //38 Ampersand & 0b00100000, 0b01010000, 0b10100000, 0b01000000, 0b10101000, 0b10010000, 0b01101000, //39 Single Quote ' 0b01000000, 0b01000000, 0b01000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, //40 Left Parenthesis ( 0b00010000, 0b00100000, 0b01000000, 0b01000000, 0b01000000, 0b00100000, 0b00010000, //41 Right Parenthesis ) 0b01000000, 0b00100000, 0b00010000, 0b00010000, 0b00010000, 0b00100000, 0b01000000, //42 Star * 0b00010000, 0b00111000, 0b00010000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, //43 Plus + 0b00000000, 0b00100000, 0b00100000, 0b11111000, 0b00100000, 0b00100000, 0b00000000, //44 Comma , 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00010000, 0b00010000, //45 Minus - 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b11111000, 0b00000000, 0b00000000, //46 Period . 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00010000, // 47 Backslahs / 0b00000000, 0b00001000, 0b00010000, 0b00100000, 0b01000000, 0b10000000, 0b00000000, // 48 Zero 0b01110000, 0b10001000, 0b10011000, 0b10101000, 0b11001000, 0b10001000, 0b01110000, //49 One 0b00100000, 0b01100000, 0b00100000, 0b00100000, 0b00100000, 0b00100000, 0b01110000, //50 two 0b01110000, 0b10001000, 0b00001000, 0b00010000, 0b00100000, 0b01000000, 0b11111000, //51 Three 0b11111000, 0b00010000, 0b00100000, 0b00010000, 0b00001000, 0b10001000, 0b01110000, //52 Four 0b00010000, 0b00110000, 0b01010000, 0b10010000, 0b11111000, 0b00010000, 0b00010000, //53 Five 0b11111000, 0b10000000, 0b11110000, 0b00001000, 0b00001000, 0b10001000, 0b01110000, //54 Six 0b01000000, 0b10000000, 0b10000000, 0b11110000, 0b10001000, 0b10001000, 0b01110000, //55 Seven 0b11111000, 0b00001000, 0b00010000, 0b00100000, 0b01000000, 0b10000000, 0b10000000, //56 Eight 0b01110000, 0b10001000, 0b10001000, 0b01110000, 0b10001000, 0b10001000, 0b01110000, //57 Nine 0b01110000, 0b10001000, 0b10001000, 0b01111000, 0b00001000, 0b00001000, 0b00010000, //58 : 0b00000000, 0b00000000, 0b00100000, 0b00000000, 0b00000000, 0b00000000, 0b00100000, //59 ; 0b00000000, 0b00000000, 0b00100000, 0b00000000, 0b00000000, 0b00100000, 0b00100000, //60 < 0b00000000, 0b00011000, 0b01100000, 0b10000000, 0b01100000, 0b00011000, 0b00000000, //61 = 0b00000000, 0b00000000, 0b01111000, 0b00000000, 0b01111000, 0b00000000, 0b00000000, //62 > 0b00000000, 0b11000000, 0b00110000, 0b00001000, 0b00110000, 0b11000000, 0b00000000, //63 ? 0b00110000, 0b01001000, 0b00010000, 0b00100000, 0b00100000, 0b00000000, 0b00100000, //64 @ 0b01110000, 0b10001000, 0b10111000, 0b10101000, 0b10010000, 0b10001000, 0b01110000, //65 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, //91 [ 0b11100000, 0b10000000, 0b10000000, 0b10000000, 0b10000000, 0b10000000, 0b11100000, //92 \ 0b00000000, 0b10000000, 0b01000000, 0b00100000, 0b00010000, 0b00001000, 0b00000000, //93 ] 0b00111000, 0b00001000, 0b00001000, 0b00001000, 0b00001000, 0b00001000, 0b00111000, //94 ^ 0b00100000, 0b01010000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, //95 _ 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b11111000, //96 ` 0b10000000, 0b01000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, //97 a 0b00000000, 0b01100000, 0b00010000, 0b01110000, 0b10010000, 0b01100000, 0b00000000, //98 b 0b10000000, 0b10000000, 0b11100000, 0b10010000, 0b10010000, 0b11100000, 0b00000000, //99 c 0b00000000, 0b00000000, 0b01110000, 0b10000000, 0b10000000, 0b01110000, 0b00000000, // 100 d 0b00010000, 0b00010000, 0b01110000, 0b10010000, 0b10010000, 0b01110000, 0b00000000, //101 e 0b00000000, 0b01100000, 0b10010000, 0b11110000, 0b10000000, 0b01110000, 0b00000000, //102 f 0b00110000, 0b01000000, 0b11100000, 0b01000000, 0b01000000, 0b01000000, 0b00000000, //103 g 0b00000000, 0b01100000, 0b10010000, 0b01110000, 0b00010000, 0b00010000, 0b01100000, //104 h 0b10000000, 0b10000000, 0b11100000, 0b10010000, 0b10010000, 0b10010000, 0b00000000, //105 i 0b00000000, 0b00100000, 0b00000000, 0b00100000, 0b00100000, 0b00100000, 0b00000000, //106 j 0b00000000, 0b00010000, 0b00000000, 0b00010000, 0b00010000, 0b00010000, 0b01100000, //107 k 0b10000000, 0b10010000, 0b10100000, 0b11000000, 0b10100000, 0b10010000, 0b00000000, //108 l 0b00100000, 0b00100000, 0b00100000, 0b00100000, 0b00100000, 0b00100000, 0b00000000, //109 m 0b00000000, 0b00000000, 0b01010000, 0b10101000, 0b10101000, 0b10101000, 0b00000000, //110 n 0b00000000, 0b00000000, 0b01100000, 0b10010000, 0b10010000, 0b10010000, 0b00000000, //111 o 0b00000000, 0b00000000, 0b01100000, 0b10010000, 0b10010000, 0b01100000, 0b00000000, //112 p 0b00000000, 0b00000000, 0b01100000, 0b10010000, 0b11110000, 0b10000000, 0b10000000, //113 q 0b00000000, 0b00000000, 0b01100000, 0b10010000, 0b11110000, 0b00010000, 0b00010000, //114 r 0b00000000, 0b00000000, 0b10111000, 0b01000000, 0b01000000, 0b01000000, 0b00000000, //115 s 0b00000000, 0b00000000, 0b01110000, 0b01000000, 0b00010000, 0b01110000, 0b00000000, //116 t 0b01000000, 0b01000000, 0b11100000, 0b01000000, 0b01000000, 0b01000000, 0b00000000, // 117u 0b00000000, 0b00000000, 0b10010000, 0b10010000, 0b10010000, 0b01100000, 0b00000000, //118 v 0b00000000, 0b00000000, 0b10001000, 0b10001000, 0b01010000, 0b00100000, 0b00000000, //119 w 0b00000000, 0b00000000, 0b10101000, 0b10101000, 0b01010000, 0b01010000, 0b00000000, //120 x 0b00000000, 0b00000000, 0b10010000, 0b01100000, 0b01100000, 0b10010000, 0b00000000, //121 y 0b00000000, 0b00000000, 0b10010000, 0b10010000, 0b01100000, 0b01000000, 0b10000000, //122z 0b00000000, 0b00000000, 0b11110000, 0b00100000, 0b01000000, 0b11110000, 0b00000000, //123 { 0b00100000, 0b01000000, 0b01000000, 0b10000000, 0b01000000, 0b01000000, 0b00100000, //124 | 0b00100000, 0b00100000, 0b00100000, 0b00100000, 0b00100000, 0b00100000, 0b00100000, //125 } 0b00100000, 0b00010000, 0b00010000, 0b00001000, 0b00010000, 0b00010000, 0b00100000, //126 ~ 0b00000000, 0b00000000, 0b01000000, 0b10101000, 0b00010000, 0b00000000, 0b00000000, //127 DEL 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000}; //================================== //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) begin //start the Horizontal sync pulse PORTD = syncON; //update the curent scanline number LineCount ++ ; //begin inverted (Vertical) synch after line 247 if (LineCount==248) begin syncON = 0b00100000; syncOFF = 0; end //back to regular sync after line 250 if (LineCount==251) begin syncON = 0; syncOFF = 0b00100000; end //start new frame after line 262 if (LineCount==263) begin LineCount = 1; end delay_us(2); //adjust to make 5 us pulses //end sync pulse PORTD = syncOFF; if (LineCount=ScreenTop) begin //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 end end #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) begin #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 end #pragma warn+ //================================== // put a big character on the screen // c is index into bitmap void video_putchar(char x, char y, char c) begin v7 = x; for (v6=0;v6<7;v6++) begin v1 = ascii[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); end end //================================== // put a string of big characters on the screen void video_puts(char x, char y, char *str) begin char i ; for (i=0; str[i]!=0; i++) begin video_putchar(x,y,str[i]); x = x+6; end end //================================== //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) begin 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) begin temp = dx; dx = dy; dy = temp; xchange = 1; end e = ((int)dy<<1) - dx; for (j=0; j<=dx; j++) begin video_pt(x,y,c) ; if (e>=0) begin if (xchange==1) x = x + s1; else y = y + s2; e = e - ((int)dx<<1); end if (xchange==1) y = y + s2; else x = x + s1; e = e + ((int)dy<<1); end end //================================== //return the value of one point //at x,y with color 1=white 0=black 2=invert char video_set(char x, char y) begin //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))); end //================================== //Used to debounce the pushbuttons for penalties void debounce(void) { switch(PushState) { case Release: if(PINB.0 & PINB.1) { PushState = Release; } else { PushState = Debounce; } break; case Debounce: if(~PINB.0 || ~PINB.1) { PushState = Endchar; } else { PushState = Release; } break; case Endchar: PushState = Still_Pressed; switch(penalty) { case 0: begin //erase penalty = 0 video_line(77,30,105,30,0); video_line(77,30,77,80,0); video_line(105,30,105,80,0); video_line(77,80,105,80,0); //penalty = 1 video_line(87,35,92,30,1); video_line(92,30,92,80,1); penalty++; break; end case 1: begin //erase penalty = 1 video_line(87,35,92,30,0); video_line(92,30,92,80,0); //penalty = 2 video_line(77,30,105,30,1); video_line(105,30,105,55,1); video_line(105,55,77,55,1); video_line(77,55,77,80,1); video_line(77,80,105,80,1); video_puts(80,20,cu4); penalty++; break; end } break; case Still_Pressed: if(~PINB.0 || ~PINB.1) { PushState = Still_Pressed; } else { PushState = Debounce_Release; } break; case Debounce_Release: if(~PINB.0 || ~PINB.1) { PushState = Still_Pressed; } else { PushState = Release; } break; case Done: PushState = Done; break; } } //********************************************************** //initialization void init() begin //TXRX init txrx_init(0,1,249,1);//RX only - 4000 baud - led on rx_reset(MAX_RX_LENGTH); //initialize variables seen_ids[0] = 0; seen_ids[1] = 0; seen_ids[2] = 0; seen_ids[3] = 0; time=0; done=0; current_line=0; last_replaced=1; score = 0; penalty = 0; //initialize flags gotfirstbyteflag = 0; TIMSK = 0x00; //Print "SCORE" video_puts(15,3,cu1); //print "PENALTY" video_puts(74,3,cu2); //Print score of 0 video_line(15,30,43,30,1); video_line(15,30,15,80,1); video_line(43,30,43,80,1); video_line(15,80,43,80,1); //Print penalty of 0 video_line(77,30,105,30,1); video_line(77,30,77,80,1); video_line(105,30,105,80,1); video_line(77,80,105,80,1); //side lines #define width 126 video_line(0,0,0,99,1); video_line(width,0,width,99,1); //top line & bottom lines & middle line video_line(0,0,width,0,1); video_line(0,99,width,99,1); video_line(0,11,width,11,1); video_line(60,0,60,99,1); TIMSK = 0x10; end //================================== // set up the ports and timers void main(void) begin //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 = 0x12; //enable interrupt T1 cmp OCR0 = 250; //set the compare re to 250 time ticks //prescalar to 64 and turn on clear-on-match TCCR0=0b00001011; DDRB=0x00; //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 //initialize synch constants LineCount = 1; syncON = 0b00000000; syncOFF = 0b00100000; //enable sleep mode MCUCR = 0b10000000; #asm ("sei"); init(); //The following loop executes once/video line during lines //1-230, then does all of the frame-end processing while(1) begin //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 if (LineCount==231) begin debounce(); if(rxdone()==1) { // 0 - 170 // 1 - start_char // 2 - ID // 3 - length // 4 - number // 5 to x - payload rx_reset(MAX_RX_LENGTH); k=0; init_getrx(); while(rx_empty()!=1) { my_rx_data[k] = get_next_rx_data(); k++; } if(my_rx_data[5]==100) { TIMSK=0x00; //Turn on Hack switch(score) { case 0: begin //erase score = 0 video_line(15,30,43,30,0); video_line(15,30,15,80,0); video_line(43,30,43,80,0); video_line(15,80,43,80,0); //score = 1 video_line(25,35,30,30,1); video_line(30,30,30,80,1); score++; break; end case 1: begin //erase score = 1 video_line(25,35,30,30,0); video_line(30,30,30,80,0); //score = 2 video_line(15,30,43,30,1); video_line(43,30,43,55,1); video_line(43,55,15,55,1); video_line(15,55,15,80,1); video_line(15,80,43,80,1); score++; break; end case 2: begin //erase score = 2 video_line(15,30,43,30,0); video_line(43,30,43,55,0); video_line(43,55,15,55,0); video_line(15,55,15,80,0); video_line(15,80,43,80,0); //score = 3 video_line(15,30,43,30,1); video_line(43,30,43,80,1); video_line(43,55,15,55,1); video_line(15,80,43,80,1); score++; break; end case 3: begin //erase score = 3 video_line(15,30,43,30,0); video_line(43,30,43,80,0); video_line(43,55,15,55,0); video_line(15,80,43,80,0); //score = 4 video_line(20,30,15,55,1); video_line(15,55,43,55,1); video_line(40,30,40,80,1); score++; break; end case 4: begin //erase score = 4 video_line(20,30,15,55,0); video_line(15,55,43,55,0); video_line(40,30,40,80,0); //score = 5 video_line(15,30,43,30,1); video_line(15,30,15,55,1); video_line(43,55,15,55,1); video_line(43,55,43,80,1); video_line(15,80,43,80,1); score++; break; end case 5: begin //erase score = 5 video_line(15,30,43,30,0); video_line(15,30,15,55,0); video_line(43,55,15,55,0); video_line(43,55,43,80,0); video_line(15,80,43,80,0); //score = 6 video_line(15,30,43,30,1); video_line(15,30,15,80,1); video_line(43,55,15,55,1); video_line(43,55,43,80,1); video_line(15,80,43,80,1); score++; break; end case 6: begin //erase score = 6 video_line(15,30,43,30,0); video_line(15,30,15,80,0); video_line(43,55,15,55,0); video_line(43,55,43,80,0); video_line(15,80,43,80,0); //score = 7 video_line(15,30,43,30,1); video_line(43,30,30,80,1); score++; break; end case 7: begin //erase score = 7 video_line(15,30,43,30,0); video_line(43,30,30,80,0); //score = 8 video_line(15,30,43,30,1); video_line(15,30,15,80,1); video_line(43,55,15,55,1); video_line(43,30,43,80,1); video_line(15,80,43,80,1); score++; break; end case 8: begin //erase score = 8 video_line(15,30,43,30,0); video_line(15,30,15,80,0); video_line(43,55,15,55,0); video_line(43,30,43,80,0); video_line(15,80,43,80,0); //score = 9 video_line(15,30,43,30,1); video_line(43,30,43,80,1); video_line(15,30,15,55,1); video_line(15,55,43,55,1); video_line(15,80,43,80,1); score++; break; end case 9: begin //erase score = 9 video_line(15,30,43,30,0); video_line(43,30,43,80,0); video_line(15,30,15,55,0); video_line(15,55,43,55,0); video_line(15,80,43,80,0); //score = 10 video_line(7,35,12,30,1); video_line(12,30,12,80,1); video_line(22,30,50,30,1); video_line(22,30,22,80,1); video_line(50,30,50,80,1); video_line(22,80,50,80,1); score++; break; end case 10: begin //erase score = 10 video_line(7,35,12,30,0); video_line(12,30,12,80,0); video_line(22,30,50,30,0); video_line(22,30,22,80,0); video_line(50,30,50,80,0); video_line(22,80,50,80,0); //score = 11 video_line(7,35,12,30,1); video_line(12,30,12,80,1); video_line(50,30,50,80,1); video_line(45,35,50,30,1); score++; break; end case 11: begin //erase score = 11 video_line(7,35,12,30,0); video_line(12,30,12,80,0); video_line(50,30,50,80,0); video_line(45,35,50,30,0); //score = 12 video_line(7,35,12,30,1); video_line(12,30,12,80,1); video_line(22,30,50,30,1); video_line(50,30,50,55,1); video_line(50,55,22,55,1); video_line(22,55,22,80,1); video_line(22,80,50,80,1); video_puts(20,20,cu3); score++; break; end } TIMSK=0x10; //Turn off hack } } end //line 231 end //while end //main