//Dawn Banks and Evan Tanner //ECE 476 Final Project //April 2003 //Professor Bruce Land #pragma regalloc- #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 ScreenTop 30 #define ScreenBot 230 #define T0reload 256-60 //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; //required to make sync pulse int LineCount; //line count on television unsigned char windD; //direction of wind, 0 to 15 unsigned char sailD; //direction you're sailing in, 0 to 15 unsigned char pirate; //which pirate is active? 0 to 3, 0=pirate dead int pirx, piry; //pirate ship location in 498x350 grid unsigned char pscreenx, pscreeny; //last ship position on TV screen unsigned char pirsailD; //sailing direction of pirate, 0 to 15 int ptimer; //how far along pirate is on his route unsigned char pcannonD; //pirate's cannonball direction unsigned char pcantimer; //length of pirate's cannon shot int pcanposx, pcanposy; //pirate's cannonball positions unsigned char pxscrloc, pyscrloc; //screen positions of p.cannonball bit pcannon; //is pirate cannonball active? unsigned char pspeed; //pirate speed counter, 0 to 32 unsigned char pcannontime; //length of pirate's cannon shot unsigned char scannonD; //cannonball direction unsigned char scantimer; //length of cannon shot int scanposx, scanposy; //cannonball positions unsigned char cscrlocx, cscrlocy; //screen positions of your cannonball bit scannon; //is your cannonball active? unsigned char cannontime; //length of your cannon shot bit newmap; //just changed the map unsigned char magt, magtB, magx; unsigned char windM; //inputted wind magnitude, 0 to 2 unsigned char sailM; //inputted sail magnitude, 0 to 2 unsigned char rudder; //inputted rudder turn, 0 to 4 unsigned char shipspeed; //player's ship's speed, 0 to 32 unsigned char xscrloc, yscrloc; //last ship position on TV screen unsigned char gamescreen; //which screen for calculations or rules int shipx, shipy; //player's ship location in 498x350 grid unsigned char lastB; //last check of port B bit mapon, fire; //show map? fire cannon? bit mapping; //high if currently displaying screen char timer, cleary; //mapping timer and variable for clearing screen char looper; //rudder timer unsigned char bleh; //timer for checking buttons unsigned char score; //Total score unsigned char treasout, foundtreas; //Treasure available and treasure found unsigned char map, shipmap; //current or previous screen char screen[1600]; //words/phrases commonly used in screens throughout game flash char cu27[]="LOOT:"; flash char cu2[]="HIGH SEAS MAP"; flash char cu3[]="WELCOME TO"; flash char cu4[]="TREASURE HUNT"; flash char cu5[]="OF THE"; flash char cu6[]="HIGH"; flash char cu28[]="SEAS"; flash char cu7[]="1 FOR RULES"; flash char cu8[]="2 TO SAIL"; flash char cu29[]="PRESS"; flash char cu9[]="INDICATORS"; flash char cu10[]="SAIL HEIGHT:"; flash char cu11[]="DOWN HALF"; flash char cu35[]="FULL"; flash char cu12[]="WIND MAGNITUDE"; flash char cu36[]="AND"; flash char cu13[]="DIRECTION:"; flash char cu37[]="NONE"; flash char cu14[]="L LIGHT"; flash char cu15[]="H HEAVY"; flash char cu16[]="SAILING RULES"; flash char cu17[]="WATCH WIND"; flash char cu18[]="FIND TREASURE"; flash char cu19[]="SINK PIRATES"; flash char cu20[]="CONTROLS"; flash char cu21[]="RUDDER:1 RIGHT"; flash char cu30[]="2 LEFT"; flash char cu22[]="SAIL:3 UP"; flash char cu31[]="4 DOWN"; flash char cu23[]="5 FIRE CANNON"; flash char cu32[]="6 MAP"; flash char cu24[]="WIND:7 INC"; flash char cu34[]="DEC"; flash char cu26[]="1 TO CONTINUE"; flash char cu60[]="HULL BREACH"; flash char cu61[]="GAME OVER"; flash char cu62[]="YOU FOUND ALL"; flash char cu63[]="OF THE LOOT"; //Point plot lookup table flash char pos[8]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01}; //character bitmaps including text and figures, 5x7 characters flash char bitmap[54][7]={ 0b01110000, 0b10001000, 0b10011000, 0b10101000, 0b11001000, 0b10001000, 0b01110000, //0 0b00100000, 0b01100000, 0b00100000, 0b00100000, 0b00100000, 0b00100000, 0b01110000, //1 0b01110000, 0b10001000, 0b00001000, 0b00010000, 0b00100000, 0b01000000, 0b11111000, //2 0b11111000, 0b00010000, 0b00100000, 0b00010000, 0b00001000, 0b10001000, 0b01110000, //3 0b00010000, 0b00110000, 0b01010000, 0b10010000, 0b11111000, 0b00010000, 0b00010000, //4 0b11111000, 0b10000000, 0b11110000, 0b00001000, 0b00001000, 0b10001000, 0b01110000, //5 0b01000000, 0b10000000, 0b10000000, 0b11110000, 0b10001000, 0b10001000, 0b01110000, //6 0b11111000, 0b00001000, 0b00010000, 0b00100000, 0b01000000, 0b10000000, 0b10000000, //7 0b01110000, 0b10001000, 0b10001000, 0b01110000, 0b10001000, 0b10001000, 0b01110000, //8 0b01110000, 0b10001000, 0b10001000, 0b01111000, 0b00001000, 0b00001000, 0b00010000, //9 0b01110000, 0b10001000, 0b10001000, 0b10001000, 0b11111000, 0b10001000, 0b10001000, //A 0b11110000, 0b10001000, 0b10001000, 0b11110000, 0b10001000, 0b10001000, 0b11110000, //B 0b01110000, 0b10001000, 0b10000000, 0b10000000, 0b10000000, 0b10001000, 0b01110000, //C 0b11110000, 0b10001000, 0b10001000, 0b10001000, 0b10001000, 0b10001000, 0b11110000, //D 0b11111000, 0b10000000, 0b10000000, 0b11111000, 0b10000000, 0b10000000, 0b11111000, //E 0b11111000, 0b10000000, 0b10000000, 0b11111000, 0b10000000, 0b10000000, 0b10000000, //F 0b01110000, 0b10001000, 0b10000000, 0b10011000, 0b10001000, 0b10001000, 0b01110000, //G 0b10001000, 0b10001000, 0b10001000, 0b11111000, 0b10001000, 0b10001000, 0b10001000, //H 0b01110000, 0b00100000, 0b00100000, 0b00100000, 0b00100000, 0b00100000, 0b01110000, //I 0b00111000, 0b00010000, 0b00010000, 0b00010000, 0b00010000, 0b10010000, 0b01100000, //J 0b10001000, 0b10010000, 0b10100000, 0b11000000, 0b10100000, 0b10010000, 0b10001000, //K 0b10000000, 0b10000000, 0b10000000, 0b10000000, 0b10000000, 0b10000000, 0b11111000, //L 0b10001000, 0b11011000, 0b10101000, 0b10101000, 0b10001000, 0b10001000, 0b10001000, //M 0b10001000, 0b10001000, 0b11001000, 0b10101000, 0b10011000, 0b10001000, 0b10001000, //N 0b01110000, 0b10001000, 0b10001000, 0b10001000, 0b10001000, 0b10001000, 0b01110000, //O 0b11110000, 0b10001000, 0b10001000, 0b11110000, 0b10000000, 0b10000000, 0b10000000, //P 0b01110000, 0b10001000, 0b10001000, 0b10001000, 0b10101000, 0b10010000, 0b01101000, //Q 0b11110000, 0b10001000, 0b10001000, 0b11110000, 0b10100000, 0b10010000, 0b10001000, //R 0b01111000, 0b10000000, 0b10000000, 0b01110000, 0b00001000, 0b00001000, 0b11110000, //S 0b11111000, 0b00100000, 0b00100000, 0b00100000, 0b00100000, 0b00100000, 0b00100000, //T 0b10001000, 0b10001000, 0b10001000, 0b10001000, 0b10001000, 0b10001000, 0b01110000, //U 0b10001000, 0b10001000, 0b10001000, 0b10001000, 0b10001000, 0b01010000, 0b00100000, //V 0b10001000, 0b10001000, 0b10001000, 0b10101000, 0b10101000, 0b10101000, 0b01010000, //W 0b10001000, 0b10001000, 0b01010000, 0b00100000, 0b01010000, 0b10001000, 0b10001000, //X 0b10001000, 0b10001000, 0b10001000, 0b01010000, 0b00100000, 0b00100000, 0b00100000, //Y 0b11111000, 0b00001000, 0b00010000, 0b00100000, 0b01000000, 0b10000000, 0b11111000, //Z //Sail Down, Sail Half, Sail Full // 1111 1111 1111 // 1 1 1 1 1111 // 1 1 1 1 1111 // 1 1 1111 1111 // 1 1 1111 1111 // 1111 1111 1111 //Sail Down Indicator 0b00000000, 0b11110000, 0b10010000, 0b10010000, 0b10010000, 0b10010000, 0b11110000, //Sail Half Indicator 0b00000000, 0b11110000, 0b10010000, 0b10010000, 0b11110000, 0b11110000, 0b11110000, //Sail Full Indicator 0b00000000, 0b11110000, 0b11110000, 0b11110000, 0b11110000, 0b11110000, 0b11110000, //North, NorthEast, East, SouthEast, South, SouthWest, West, NorthWest // 11 11 1 11 1 11 // 1111 1111 1 11 11 11 1 1111 // 11 111 1 11 11 11 1 111 // 11 11 11111 11 11 11 11111 11 // 11 11 1 111 11 111 1 11 // 11 11 1 1111 1111 1111 1 11 // 11 1 11 11 11 1 //North Arrow 0b00110000, 0b01111000, 0b00110000, 0b00110000, 0b00110000, 0b00110000, 0b00110000, //NorthEast Arrow 0b00011000, 0b01111000, 0b00111000, 0b01100000, 0b11000000, 0b11000000, 0b10000000, //East Arrow 0b00000000, 0b00100000, 0b00010000, 0b11111000, 0b00010000, 0b00100000, 0b00000000, //SouthEast Arrow 0b10000000, 0b11000000, 0b11000000, 0b01100000, 0b00111000, 0b01111000, 0b00011000, //South Arrow 0b00110000, 0b00110000, 0b00110000, 0b00110000, 0b00110000, 0b01111000, 0b00110000, //SouthWest Arrow 0b00001000, 0b00011000, 0b00011000, 0b00110000, 0b11100000, 0b11110000, 0b11000000, //West Arrow 0b00000000, 0b00100000, 0b01000000, 0b11111000, 0b01000000, 0b00100000, 0b00000000, //NorthWest Arrow 0b11000000, 0b11110000, 0b11100000, 0b00110000, 0b00011000, 0b00011000, 0b00001000, //Blank 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, //: 0b00000000, 0b00110000, 0b00110000, 0b00000000, 0b00110000, 0b00110000, 0b00000000, //Rudder Far Left, Left, Straight, Right, Far Right // 1 1 1 1 1 // 1 1 1 // 1 1 1 1 1 // 1 1 1 // 1 1 1 1 1 //Rudder Far Left 0b00000000, 0b00001000, 0b00010000, 0b00100000, 0b01000000, 0b10000000, 0b00000000, //Rudder Left 0b00000000, 0b00010000, 0b00000000, 0b00100000, 0b00000000, 0b01000000, 0b00000000, //Rudder Straight 0b00000000, 0b00100000, 0b00100000, 0b00100000, 0b00100000, 0b00100000, 0b00000000, //Rudder Right 0b00000000, 0b01000000, 0b00000000, 0b00100000, 0b00000000, 0b00010000, 0b00000000, //Rudder Far Right 0b00000000, 0b10000000, 0b01000000, 0b00100000, 0b00010000, 0b00001000, 0b00000000}; //character bitmaps for sailboat and pirate ships, 5x5 characters flash char shipbitmap[12][5]={ //North, NorthEast, East, SouthEast, South, SouthWest, West, NorthWest // 1 11 1 1 1 11 // 1 1 1 1 111 111 111 111 111 1 1 // 1 1 1 1 11 1 1 1 1 1 1 1 1 11 1 1 // 111 111 111 1 1 1 1 1 1 111 111 // 1 1 11 1 11 1 0b00100000, 0b01010000, 0b01010000, 0b01110000, 0b00100000, //North 0b00110000, 0b01010000, 0b10010000, 0b11100000, 0b10000000, //NorthEast 0b00000000, 0b01110000, 0b11001000, 0b01110000, 0b00000000, //East 0b10000000, 0b11100000, 0b10010000, 0b01010000, 0b00110000, //SouthEast 0b00100000, 0b01110000, 0b01010000, 0b01010000, 0b00100000, //South 0b00001000, 0b00111000, 0b01001000, 0b01010000, 0b01100000, //SouthWest 0b00000000, 0b01110000, 0b10011000, 0b01110000, 0b00000000, //West 0b01100000, 0b01010000, 0b01001000, 0b00111000, 0b00001000, //NorthWest 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, //Blank //Treasure 1, Treasure 2, Treasure 3 // 111 1 1 1 1 // 1 1 1 1 1 // 11 11 1 1 // 1 1 1 1 1 1 1 // 111 1 1 111 0b01110000, 0b10101000, 0b11011000, 0b10101000, 0b01110000, //Treasure Fig 1 0b10001000, 0b01010000, 0b00100000, 0b01010000, 0b10001000, //Treasure Fig 2 0b01010000, 0b00000000, 0b00100000, 0b10001000, 0b01110000};//Treasure Fig 3 //================================== //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; //count timer 0 at 1/usec TCNT0 = 0; //update the curent scanline number LineCount++; //begin 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 //end 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 } //end if } //end interrupt [TIM1_COMPA] #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 } //end video_pt #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); } //end for } //end video_putchar //================================== // put a SHIP character on the screen, c is index into bitmap void video_putshipchar(char x, char y, char c) { v7 = x; for (v6=0; v6<5; v6++) { v1 = shipbitmap[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 for } //end video_putshipchar //================================== // put a string of big characters on the screen void video_puts(char x, char y, flash 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 switch (str[i]) { case 0x3a: video_putchar(x,y,48); //: break; case 0x20: video_putchar(x,y,47); //space break; default: video_putchar(x,y,str[i]-0x40+9); } //end switch x = x + 6; } //end for } //end video_puts //================================== //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); } //end if if (xchange==1) y = y + s2; else x = x + s1; e = e + ((int)dy<<1); } //end for } //end video_line //================================== //return the value of one point at x,y with color 1=white 0=black 2=invert 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))); } //end video_set //================================== //Displays map onto TV depending on where sailboat is located or option //selected. Can only display up to 14 characters or ~four lines in one frame. //Commented numbers after video_puts is how many characters in string. void mapdisplay(void) { if (timer<50) //must clear screen before displaying another { cleary = timer*2; video_line(0,cleary,63,cleary,0); video_line(0,cleary+1,63,cleary+1,0); video_line(63,cleary,126,cleary,0); video_line(63,cleary+1,126,cleary+1,0); } else switch (map) { case 4: //NorthWest Corner Map switch (timer) { case 50: //side lines video_line(0,0,0,99,1); video_line(126,0,126,99,1); //top line & bottom lines and indicator video_line(0,0,126,0,1); video_line(0,99,126,99,1); break; case 51: video_line(0,89,126,89,1); video_puts(72,91,cu27);//5 if (treasout==1) video_putshipchar(23,13,9);//1 break; case 52: video_line(16,89,16,82,1); video_line(16,82,4,70,1); video_line(4,70,4,20,1); video_putchar(108,91,score); //Display score break; case 53: video_line(4,20,20,6,1); video_line(20,6,70,2,1); video_line(70,2,126,24,1); video_line(126,40,120,40,1); break; case 54: video_line(120,40,106,34,1); video_line(106,34,104,42,1); video_line(104,42,118,64,1); video_line(118,64,126,60,1); timer=0; mapping=0; break; } //end switch break; case 5: //NorthEast Corner Map switch (timer) { case 50: //side lines video_line(0,0,0,99,1); video_line(126,0,126,99,1); //top line & bottom lines and indicator video_line(0,0,126,0,1); video_line(0,99,126,99,1); break; case 51: video_line(0,89,126,89,1); video_puts(72,91,cu27);//5 if (treasout==2) video_putshipchar(18,32,9);//1 if (treasout==5) video_putshipchar(108,78,11);//1 video_putchar(108,91,score); //Display Score break; case 52: video_line(46,28,40,50,1); video_line(0,40,30,40,1); video_line(30,40,42,28,1); break; case 53: video_line(42,28,46,28,1); video_line(40,50,0,60,1); video_line(0,24,30,24,1); break; case 54: video_line(30,24,80,2,1); video_line(80,2,124,10,1); video_line(124,10,124,80,1); video_line(124,80,120,89,1); timer=0; mapping=0; break; } //end switch break; case 6: //SouthWest Corner Map switch (timer) { case 50: //side lines video_line(0,0,0,99,1); video_line(126,0,126,99,1); //top line & bottom lines with indicator video_line(0,0,126,0,1); video_line(0,99,126,99,1); break; case 51: video_line(0,89,126,89,1); video_puts(72,91,cu27);//5 video_putchar(108,91,score); //Display Score if (treasout==6) video_putshipchar(108,48,10); break; case 52: video_line(16,0,6,16,1); video_line(6,16,4,50,1); video_line(4,50,8,74,1); video_line(8,74,2,78,1); break; case 53: video_line(2,78,4,86,1); video_line(4,86,70,82,1); video_line(70,82,120,88,1); video_line(120,88,126,88,1); timer=0; mapping=0; break; } //end switch break; case 7: //SouthEast Corner Map switch (timer) { case 50: //side lines video_line(0,0,0,99,1); video_line(126,0,126,99,1); //top line & bottom lines with indicator video_line(0,0,126,0,1); video_line(0,99,126,99,1); break; case 51: video_line(0,89,126,89,1); video_line(0,88,116,88,1); video_puts(72,91,cu27);//5 video_putchar(108,91,score); //Display Score if (treasout==3) video_putshipchar(58,38,9);//1 if (treasout==4) video_putshipchar(98,38,10);//1 break; case 52: video_line(116,88,120,86,1); video_line(120,86,124,60,1); video_line(124,60,124,22,1); video_line(124,22,100,22,1); break; case 53: video_line(100,22,42,40,1); video_line(42,40,56,56,1); video_line(56,56,100,56,1); video_line(100,56,110,60,1); break; case 54: video_line(110,60,80,66,1); video_line(80,66,56,72,1); video_line(56,72,40,64,1); video_line(40,64,36,54,1); break; case 55: video_line(36,54,28,38,1); video_line(28,38,32,16,1); video_line(32,16,76,12,1); video_line(76,12,120,0,1); timer=0; mapping=0; break; } //end switch break; case 3: //Overall Map with starting position displayed switch (timer) { case 50: video_line(0,0,0,99,1); video_line(126,0,126,99,1); //top line & bottom lines with indicator video_line(0,0,126,0,1); video_line(0,99,126,99,1); break; case 51: video_puts(24,40,cu2);//13 if (windM==1) video_putchar(22,91,21);//1 Current Wind Magnitude else if (windM==2) video_putchar(22,91,17);//1 break; case 52: video_puts(10,50,cu29);//5 video_puts(72,91,cu27);//5 video_putchar(30,91,rudder+49);//1 Current Rudder Position video_putchar(6,91,sailM+36);//1 Current Sail Height video_putchar(108,91,score); break; case 53: video_puts(12,60,cu26);//13 video_putchar(14,91,39+(windD>>1));//1 Current Wind Direction break; case 54: video_line(0,89,126,89,1); video_putshipchar(6,82,1); //Display starting position //NW Corner video_line(8,45,8,41,1); video_line(8,41,2,35,1); break; case 55: video_line(2,35,2,10,1); video_line(2,10,10,3,1); video_line(10,3,35,1,1); video_line(35,1,63,12,1); break; case 56: video_line(63,20,60,20,1); video_line(60,20,53,17,1); video_line(53,17,52,21,1); video_line(52,21,59,32,1); break; case 57: video_line(59,32,63,30,1); //NE Corner video_line(63,20,78,20,1); video_line(78,20,84,14,1); video_line(84,14,86,14,1); break; case 58: video_line(86,14,83,25,1); video_line(83,25,63,30,1); video_line(63,12,78,12,1); video_line(78,12,103,1,1); break; case 59: video_line(103,1,125,5,1); video_line(125,5,125,40,1); video_line(125,40,123,45,1); //SW Corner video_line(8,45,3,53,1); break; case 60: video_line(3,53,2,70,1); video_line(2,70,4,82,1); video_line(4,82,1,84,1); video_line(1,84,2,88,1); break; case 61: video_line(2,88,35,86,1); video_line(35,86,60,89,1); video_line(60,89,63,89,1); //SE Corner video_line(63,89,121,89,1); break; case 62: video_line(121,89,123,88,1); video_line(123,88,125,75,1); video_line(125,75,125,56,1); video_line(125,56,113,56,1); break; case 63: video_line(113,56,84,65,1); video_line(84,65,91,73,1); video_line(91,73,113,73,1); video_line(113,73,118,75,1); break; case 64: video_line(118,75,103,78,1); video_line(103,78,91,81,1); video_line(91,81,83,77,1); video_line(83,77,81,72,1); break; case 65: video_line(81,72,77,64,1); video_line(77,64,79,53,1); video_line(79,53,101,51,1); video_line(101,51,123,45,1); timer=0; mapping=0; break; } //end switch break; case 1: //Rules of Sailing Screen switch (timer) { case 50: video_puts(15,0,cu16);//13 break; case 51: video_puts(42,40,cu20);//8 video_puts(90,49,cu30);//6 break; case 52: video_puts(2,49,cu21);//14 break; case 53: video_puts(2,58,cu22);//9 video_puts(2,88,cu29);//5 break; case 54: video_puts(2,67,cu23);//13 break; case 55: video_puts(2,76,cu24);//10 video_putchar(66,76,8); break; case 56: video_puts(60,58,cu31);//6 video_puts(84,67,cu32);//6 break; case 57: video_puts(2,9,cu17);//10 video_puts(78,76,cu34);//3 break; case 58: video_puts(2,18,cu18);//13 break; case 59: video_puts(2,27,cu19);//12 break; case 60: video_puts(38,88,cu26);//13 timer=0; mapping=0; break; } //end switch break; case 2: //Indicators Definition Screen switch (timer) { case 50: video_puts(33,0,cu9);//10 video_puts(86,19,cu35);//4 break; case 51: video_puts(6,10,cu10);//12 break; case 52: video_puts(0,19,cu11);//11 video_puts(96,37,cu36);//3 break; case 53: video_puts(6,37,cu12);//14 break; case 54: video_puts(18,46,cu13);//10 video_putchar(14,91,39); //Example of Wind Direction video_putchar(70,19,37); break; case 55: video_puts(12,55,cu14);//7 video_putchar(6,91,37); //Example of Sail Height video_putchar(112,19,38); video_putchar(22,91,21); //Example of Wind Magnitude video_putchar(30,91,52); //Example of Rudder Position break; case 56: video_puts(42,80,cu8);//9 video_putchar(28,19,36); break; case 57: video_puts(72,91,cu27);//5 video_puts(6,80,cu29);//5 break; case 58: video_puts(96,46,cu37);//4 video_puts(66,55,cu15);//7 break; case 59: video_line(0,89,0,99,1); video_line(126,89,126,99,1); video_line(0,89,126,89,1); video_line(0,99,126,99,1); timer=0; mapping=0; } //end switch break; case 0: //Introduction Screen switch (timer) { case 50: video_puts(33,8,cu3);//10 break; case 51: video_puts(24,30,cu4);//13 break; case 52: video_puts(45,40,cu5);//6 video_puts(36,50,cu6);//4 video_puts(66,50,cu28);//4 break; case 53: video_puts(6,72,cu29);//5 video_puts(6,84,cu29);//5 break; case 54: video_puts(42,72,cu7);//11 break; case 55: video_puts(42,84,cu8);//9 timer=0; mapping=0; break; } //end switch break; } //end switch } //end mapdisplay //================================== //Checks to see if sailboat collides with an area of land or cannonball void collision(void) { if ((video_set(xscrloc,yscrloc)||video_set(xscrloc+2,yscrloc)|| video_set(xscrloc+4,yscrloc)||video_set(xscrloc,yscrloc+2)|| video_set(xscrloc+4,yscrloc+2)||video_set(xscrloc,yscrloc+4)|| video_set(xscrloc+2,yscrloc+4)||video_set(xscrloc+4,yscrloc+4))) gamescreen=5; } //end collision //================================== //Algorithm to display treasure when ship passes over specific spots of map //and update of score when ship sails over treasure void treasure(void) { switch (map) { case 4: if ((treasout==0) && (xscrloc<50 && xscrloc>30) && (yscrloc<70 && yscrloc>50)) { video_putshipchar(42,91,9); video_putchar(54,91,28); video_putchar(60,91,14); treasout = 3; //Trip spot to make treasure 3 available } if ((treasout==0) && (xscrloc<120 && xscrloc>100) && (yscrloc<40 && yscrloc>20)) { video_putshipchar(42,92,11); video_putchar(54,91,14); treasout = 5; //Trip spot to make treasure 5 available } if ((treasout==1) && (xscrloc<28 && xscrloc>18) && (yscrloc<18 && yscrloc>8)) { foundtreas = 1; treasout=0; video_putshipchar(23,13,8); //erase treasure } break; case 5: if ((treasout==0) && (xscrloc<120 && xscrloc>110) && (yscrloc<40 && yscrloc>20)) { video_putshipchar(42,92,9); video_putchar(54,91,32); treasout = 1; //Trip spot to make treasure 1 available } if ((treasout==0) && (xscrloc<45 && xscrloc>25) && (yscrloc<80 && yscrloc>60)) { video_putshipchar(42,92,10); video_putchar(54,91,28); video_putchar(60,91,32); treasout = 6; //Trip spot to make treasure 6 available } if ((treasout==2) && (xscrloc<23 && xscrloc>13) && (yscrloc<37 && yscrloc>27)) { foundtreas = 2; treasout=0; video_putshipchar(18,32,8); //erase treasure } if ((treasout==5) && (xscrloc<113 && xscrloc>103) && (yscrloc<83 && yscrloc>73)) { foundtreas = 5; treasout=0; video_putshipchar(108,78,8); //erase treasure } break; case 6: if ((treasout==0) && (xscrloc<110 && xscrloc>90) && (yscrloc<80 && yscrloc>60)) { video_putshipchar(42,92,9); video_putchar(54,91,23); video_putchar(60,91,14); treasout = 2; //Trip spot to make treasure 2 available } if ((treasout==0) && (xscrloc<25 && xscrloc>5) && (yscrloc<40 && yscrloc>20)) { video_putshipchar(42,92,10); video_putchar(54,91,14); treasout = 4; //Trip spot to make treasure 4 available } if ((treasout==6) && (xscrloc<113 && xscrloc>103) && (yscrloc<53 && yscrloc>43)) { foundtreas = 6; treasout=0; video_putshipchar(108,48,8); //erase treasure } break; case 7: if ((treasout==3) && (xscrloc<63 && xscrloc>53) && (yscrloc<43 && yscrloc>34)) { foundtreas = 3; treasout=0; video_putshipchar(58,38,8); //erase treasure } if ((treasout==4) && (xscrloc<103 && xscrloc>93) && (yscrloc<43 && yscrloc>34)) { foundtreas = 4; treasout=0; video_putshipchar(98,38,8); //erase treasure } break; } //end switch } //end treasure void shipcannon(void) { //***************************************************** //Calculations for cannon if (scannon) { scantimer--; switch (scannonD) //move cannonball based on its direction { case 0: //N scanposy-=2; break; case 2: //NE scanposx+=2; scanposy-=2; break; case 4: //E scanposx+=2; break; case 6: //SE scanposx+=2; scanposy+=2; break; case 8: //S scanposy+=2; break; case 10: //SW scanposx-=2; scanposy+=2; break; case 12: //W scanposx-=2; break; case 14: //NW scanposx-=2; scanposy-=2; break; } //end switch (scannonD) video_pt(cscrlocx,cscrlocy,0); //erase last cannonball // ******************* //draw the cannonball if (scantimer>1); cscrlocy = (char)((scanposy-8)>>1); if (pirate==1) { if ((cscrlocx>=pscreenx)&&(cscrlocx<=pscreenx+4)&&(cscrlocy>=pscreeny)&&(cscrlocy<=pscreeny+4)) pirate=0; if (pcannon) video_pt(pxscrloc,pyscrloc,0); //erase last cannonball video_putshipchar(pscreenx,pscreeny,8); } if (video_set(cscrlocx,cscrlocy)) //cannonball hit something { scannon=0; fire=0; cscrlocx=1; cscrlocy=1; } else video_pt(cscrlocx,cscrlocy,1); } if ((scanposy>175)&&(shipy>175)) //SW quadrant { cscrlocx = (char)((scanposx+2)>>1); cscrlocy = (char)((scanposy-174)>>1); if (video_set(cscrlocx,cscrlocy)) //cannonball hit something { scannon=0; fire=0; cscrlocx=1; cscrlocy=1; } else video_pt(cscrlocx,cscrlocy,1); } } //end if ((scanposx<250)&&(shipx<250)) if ((scanposx>249)&&(shipx>249)) //Eastern half of map { if ((scanposy<176)&&(shipy<176)) //NE quadrant { cscrlocx = (char)((scanposx-240)>>1); cscrlocy = (char)((scanposy-8)>>1); if (pirate==2) { if ((cscrlocx>=pscreenx)&&(cscrlocx<=pscreenx+4)&&(cscrlocy>=pscreeny)&&(cscrlocy<=pscreeny+4)) pirate=0; if (pcannon) video_pt(pxscrloc,pyscrloc,0); //erase last cannonball video_putshipchar(pscreenx,pscreeny,8); } if (video_set(cscrlocx,cscrlocy)) //cannonball hit something { scannon=0; fire=0; cscrlocx=1; cscrlocy=1; } else video_pt(cscrlocx,cscrlocy,1); } if ((scanposy>175)&&(shipy>175)) //SE quadrant { cscrlocx = (char)((scanposx-240)>>1); cscrlocy = (char)((scanposy-174)>>1); if (pirate==3) { if ((cscrlocx>=pscreenx)&&(cscrlocx<=pscreenx+4)&&(cscrlocy>=pscreeny)&&(cscrlocy<=pscreeny+4)) pirate=0; if (pcannon) video_pt(pxscrloc,pyscrloc,0); //erase last cannonball video_putshipchar(pscreenx,pscreeny,8); } if (video_set(cscrlocx,cscrlocy)) //cannonball hit something { scannon=0; fire=0; cscrlocx=1; cscrlocy=1; } else video_pt(cscrlocx,cscrlocy,1); } }//end if ((scanposx>249)&&(shipx>249)) } //end if (scantimer>1) { case 0: //ship headed N if (pirxshipy) //pirate S of W { if ((shipx-pirx)>(piry-shipy)) scannonD = 14; //fire NW else scannonD = 6; //fire SE } else scannonD = 14; //fire NW } else //pirate to E { if (piry(shipy-piry)) scannonD = 10; //fire SW else scannonD = 2; //fire NE } else scannonD = 10; //fire SW } else //pirate to E { if (piry>shipy) //pirate S of E { if ((pirx-shipx)<(piry-shipy)) scannonD = 10; //fire SW else scannonD = 2; //fire NE } else scannonD = 2; //fire NE } break; case 4: //ship headed S if (pirxshipy) //pirate S of W { if ((shipx-pirx)>(piry-shipy)) scannonD = 14; else scannonD = 6; //fire SE } else scannonD = 14; //fire NW } else //pirate to E { if (piry(shipy-piry)) scannonD = 10; else scannonD = 2; //fire NE } else scannonD = 10; //fire SW } else //pirate to E { if (piry>shipy) //pirate S of E { if ((pirx-shipx)<(piry-shipy)) scannonD = 10; else scannonD = 2; //fire NE } else scannonD = 2; //fire NE } break; } //end switch (sailD>>1) scanposx = shipx; scanposy = shipy; scannon = 1; scantimer = cannontime; } //end if (fire&&(!scannon)) } void pircannon(void) { //***************************************************** //Calculations for cannon if (pirate==0) pcannon=0; if (pcannon) { pcantimer--; switch (pcannonD) { case 0: //N pcanposy-=2; break; case 2: //NE pcanposx+=2; pcanposy-=2; break; case 4: //E pcanposx+=2; break; case 6: //SE pcanposx+=2; pcanposy+=2; break; case 8: //S pcanposy+=2; break; case 10: //SW pcanposx-=2; pcanposy+=2; break; case 12: //W pcanposx-=2; break; case 14: //NW pcanposx-=2; pcanposy-=2; break; } //end switch (scannonD) video_pt(pxscrloc,pyscrloc,0); //erase last cannonball // ******************* if ((pcanposx<250)&&(shipx<250)) //Western half of map { if ((pcanposy<176)&&(shipy<176)) //NW quadrant { pxscrloc = (char)((pcanposx+2)>>1); pyscrloc = (char)((pcanposy-8)>>1); if (video_set(pxscrloc,pyscrloc)) pcannon=0; //cannonball hit something if ((pcannon)&&(pirate==1)&&(pxscrloc>=xscrloc)&&(pxscrloc<=xscrloc+4)&& (pyscrloc>=yscrloc)&&(pyscrloc<=yscrloc+4)) gamescreen=5; video_pt(pxscrloc,pyscrloc,1); } } if ((pcanposx>249)&&(shipx>249)) //Eastern half of map { if ((pcanposy<176)&&(shipy<176)) //NE quadrant { pxscrloc = (char)((pcanposx-240)>>1); //-248 pyscrloc = (char)((pcanposy-8)>>1); //+2 if (video_set(pxscrloc,pyscrloc)) pcannon=0; //cannonball hit something if ((pcannon)&&(pirate==2)&&(pxscrloc>=xscrloc)&&(pxscrloc<=xscrloc+4)&& (pyscrloc>=yscrloc)&&(pyscrloc<=yscrloc+4)) gamescreen=5; video_pt(pxscrloc,pyscrloc,1); } if ((pcanposy>175)&&(shipy>175)) //SE quadrant { pxscrloc = (char)((pcanposx-240)>>1); pyscrloc = (char)((pcanposy-174)>>1); if (video_set(pxscrloc,pyscrloc)) pcannon=0; //cannonball hit something if ((pcannon)&&(pirate==3)&&(pxscrloc>=xscrloc)&&(pxscrloc<=xscrloc+4)&& (pyscrloc>=yscrloc)&&(pyscrloc<=yscrloc+4)) gamescreen=5; video_pt(pxscrloc,pyscrloc,1); } } //end if ((pcanposx>249)&&(shipx>249)) if (pcantimer==0) //cannonball lands in water { pcannon = 0; video_pt(pxscrloc,pyscrloc,0); } } //end if (pcannon) // *************************** pirate fires if your ship is close enough if (((shipx+shipy-20)<(pirx+piry))&&((shipx+shipy+20)>(pirx+piry))&&(!pcannon)) { switch (pirsailD>>1) { case 0: //pirate headed N if (shipxpiry) //ship S of W { if ((pirx-shipx)>(shipy-piry)) pcannonD = 14; //fire NW else pcannonD = 6; //fire SE } else pcannonD = 14; //fire NW } else //ship to E { if (shipy(piry-shipy)) pcannonD = 10; //fire SW else pcannonD = 2; //fire NE } else pcannonD = 10; //fire SW } else //ship to E { if (shipy>piry) //ship S of E { if ((shipx-pirx)<(shipy-piry)) pcannonD = 10; //fire SW else pcannonD = 2; //fire NE } else pcannonD = 2; //fire NE } break; case 4: //pirate headed S if (shipxpiry) //ship S of W { if ((pirx-shipx)>(shipy-piry)) pcannonD = 14; else pcannonD = 6; //fire SE } else pcannonD = 14; //fire NW } else //ship to E { if (shipy(piry-shipy)) pcannonD = 10; else pcannonD = 2; //fire NE } else pcannonD = 10; //fire SW } else //ship to E { if (shipy>piry) //ship S of E { if ((shipx-pirx)<(shipy-piry)) pcannonD = 10; else pcannonD = 2; //fire NE } else pcannonD = 2; //fire NE } break; } //end switch (sailD>>1) pcanposx = pirx; pcanposy = piry; pxscrloc = 1; pyscrloc = 1; pcannon = 1; pcantimer = pcannontime; } //end if (lots of stuff&&(!pcannon)) } //================================== //Algorithms for ship movement involving rudder direction, wind magnitude //and direction, sail height, and all other factors void shipmovement(void) { if (bleh==3) //run 20 times/sec { bleh = 0; if ((((~PINC)&0x01)==0x01) && (~lastB&0x01) && rudder<4) { rudder++; magx = 1; } if ((((~PINC)&0x02)==0x02) && (~lastB&0x02) && rudder>0) { rudder--; magx = 1; } if ((((~PINC)&0x04)==0x04) && (((~lastB)&0x04)&0x04) && sailM<2) sailM++; if ((((~PINC)&0x08)==0x08) && (((~lastB)&0x08)&0x08) && sailM>0) sailM--; if ((((~PINC)&0x10)==0x10)) fire=1; mapon = (((~PINC)&0x20)==0x20); if ((((~PINC)&0x40)==0x40) && (((~lastB)&0x40)&0x40) && windM<2) windM++; if ((((~PINC)&0x80)==0x80) && (((~lastB)&0x80)&0x80) && windM>0) windM--; lastB = ~PINC; switch (~PINA&0x0f) //check lasers { //if no or 3+ lasers tripped, we assume last wind direction case 1: windD=0; //North break; case 2: windD=8; //South break; case 4: windD=4; //East break; case 5: windD=2; //Northeast break; case 6: windD=6; //Southeast break; case 8: windD=12; //West break; case 9: windD=14; //Northwest break; case 10: windD=10; //Southwest break; } //end switch (~PINA&0x0f) } //end if (bleh==3) continue with else else bleh++; shipspeed--; if (shipspeed==1) //display the indicators when not busy with calculations { video_putchar(30,91,47); video_putchar(30,91,rudder+49); video_putchar(6,91,47); video_putchar(6,91,sailM+36); video_putchar(22,91,47); if (windM==1) video_putchar(22,91,21); else if (windM==2) video_putchar(22,91,17); video_putchar(14,91,47); video_putchar(14,91,39+(windD>>1)); } //end if (shipspeed==1) if (shipspeed==0) { //*****make calculations for future frames looper--; if (looper==0) //change the ship direction as often as looper { sailD+=rudder-2; sailD=sailD&0x0f; } //end if (looper==0) magt = (windD-sailD)&0x0f; //magt is however far apart on the magtB = (sailD-windD)&0x0f; //compass that sailD and windD are if (magtB>1); yscrloc=(char)((shipy-8)>>1); if (map!=4) { map = 4; mapping = 1; newmap=1; } else { treasure(); if (foundtreas == 0) collision(); else gamescreen=6; video_putshipchar(xscrloc,yscrloc,sailD>>1);//draws new ship } } else //SW quadrant { video_putshipchar(xscrloc,yscrloc,8);//clears old position xscrloc = (char)((shipx+2)>>1); yscrloc = (char)((shipy-174)>>1); if (map!=6) { map = 6; mapping = 1; newmap=1; } else { treasure(); if (foundtreas == 0) collision(); else gamescreen=6; video_putshipchar(xscrloc,yscrloc,sailD>>1);//draws new ship } } //end else SW quadrant } else //Eastern half of map { if (shipy<176) //NE quadrant { video_putshipchar(xscrloc,yscrloc,8);//clears old position xscrloc = (char)((shipx-240)>>1); yscrloc = (char)((shipy-8)>>1); if (map!=5) { map = 5; mapping = 1; newmap=1; } else { treasure(); if (foundtreas == 0) collision(); else gamescreen=6; video_putshipchar(xscrloc,yscrloc,sailD>>1);//draws new ship } } else //SE quadrant { video_putshipchar(xscrloc,yscrloc,8);//clears old position xscrloc = (char)((shipx-240)>>1); yscrloc = (char)((shipy-174)>>1); if (map!=7) { map = 7; mapping = 1; newmap=1; } else { treasure(); if (foundtreas == 0) collision(); else gamescreen=6; video_putshipchar(xscrloc,yscrloc,sailD>>1);//draws new ship } } //end else } //end else } //end shipmovement void piratemove(void) { pircannon(); // *********************************************** pspeed--; if ((pspeed==0)&&(pirate>0)) { if (pirate==1) //pirate in NW corner of map { if (ptimer==0) { pirx=40; piry=72; } else if (ptimer<10) pirsailD=2; else if (ptimer<60) pirsailD=4; else if (ptimer<103) pirsailD=7; else if (ptimer<146) pirsailD=15; else if (ptimer<196) pirsailD=12; else if (ptimer<206) pirsailD=10; ptimer++; if (ptimer==205) ptimer=0; } //end if (pirate==1) if (pirate==2) //pirate in NE corner of map { if (ptimer==0) { pirx=424; piry=30; } else if (ptimer<30) pirsailD=7; else if (ptimer<80) pirsailD=11; else if (ptimer<130) pirsailD=3; else if (ptimer<160) pirsailD=15; ptimer++; if (ptimer==159) ptimer=0; } //end if (pirate==2) if (pirate==3) //pirate in SE corner of map { if (ptimer==0) { pirx=266; piry=316; } else if (ptimer<15) pirsailD=2; else if (ptimer<30) pirsailD=10; ptimer++; if (ptimer==30) ptimer=0; } //end if (pirate==3) //**********move pirate based on his direction switch (pirsailD) { case 0: //N piry-=2; break; case 1: //NNE pirx++; piry-=2; break; case 2: //NE pirx+=2; piry-=2; break; case 3: //ENE pirx+=2; piry--; break; case 4: //E pirx+=2; break; case 5: //ESE pirx+=2; piry++; break; case 6: //SE pirx+=2; piry+=2; break; case 7: //SSE pirx++; piry+=2; break; case 8: //S piry+=2; break; case 9: //SSW pirx--; piry+=2; break; case 10: //SW pirx-=2; piry+=2; break; case 11: //WSW pirx-=2; piry++; break; case 12: //W pirx-=2; break; case 13: //WNW pirx-=2; piry--; break; case 14: //NW pirx-=2; piry-=2; break; case 15: //NNW pirx--; piry-=2; break; } //end switch magt = (windD-pirsailD)&0x0f; //magt is however far apart on the magtB = (pirsailD-windD)&0x0f; //compass that sailD and windD are if (magtB>1); pscreeny=(char)((piry-8)>>1); if (pirate>0) video_putshipchar(pscreenx,pscreeny,pirsailD>>1); } if (pirate==2) { video_putshipchar(pscreenx,pscreeny,8); pscreenx=(char)((pirx-240)>>1); pscreeny=(char)((piry-8)>>1); if (pirate>0) video_putshipchar(pscreenx,pscreeny,pirsailD>>1); } if (pirate==3) { video_putshipchar(pscreenx,pscreeny,8); pscreenx=(char)((pirx-240)>>1); pscreeny=(char)((piry-174)>>1); if (pirate>0) video_putshipchar(pscreenx,pscreeny,pirsailD>>1); } if (pirate>0) if ((pscreenx>=xscrloc)&&(pscreenx<=xscrloc+4)&& (pscreeny>=yscrloc)&&(pscreeny<=yscrloc+4)) gamescreen=5; //**********done drawing pirate } //end piratemove //================================== void main(void) { // set up the ports and timers //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 DDRC = 0x00; //set to input DDRD = 0xf0; //video out DDRA = 0x00; //input from lasers //D.5 is sync:1000 ohm + diode to 75 ohm resistor //D.6 is video:330 ohm + diode to 75 ohm resistor //init timer 0 to 1/uSec TCCR0 = 2; //initialize synch constants LineCount = 1; syncON = 0b00000000; syncOFF = 0b00100000; bleh = 3; windM = 2; //wind starts heavy sailM = 2; //sails start half-mast rudder = 2; //rudder starts centered shipx = 18; //initial coordinates in the SW quadrant shipy = 326; pirx = 0; piry = 10; pscreenx=1; pscreeny=1; windD = 2; //wind initially toward the northeast sailD = 2; //initial sailing direction is northeast magx = 0; lastB = 0; xscrloc = shipx; yscrloc = shipy; cscrlocx = 1; cscrlocy = 1; pxscrloc = 1; pyscrloc = 1; //Variables for displaying screen timer = 50; mapping = 1; map = 0; gamescreen = 0; looper = 10; scannon = 0; ptimer = 0; pspeed = 1; cannontime = 20; pcannontime = 20; treasout = 0; //No treasure is currently available foundtreas = 0; score = 0; newmap= 0; //enable sleep mode MCUCR = 0b10000000; #asm ("sei"); //The following loop executes once/video line during lines //1-230, then does all of the frame-end 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 if (LineCount==231) { if (mapping) { mapdisplay(); if (mapping) timer++; } //end if (mapping) else { switch (gamescreen) { //0-welcome //1-rules //2-rules2 //3-viewmap //4-shipmovement case 4: //Ship sailing mode if (mapon) { shipmap = map; map = 3; mapping = 1; gamescreen = 3; } else if (newmap) { video_putshipchar(xscrloc,yscrloc,sailD>>1);//draws new ship when new map if (map==4) pirate=1; if (map==5) pirate=2; if (map==6) pirate=0; if (map==7) pirate=3; ptimer=0; pcantimer=pcannontime; pspeed=1; pscreenx=1; pscreeny=1; newmap=0; } else { shipmovement(); piratemove(); } break; case 3: //Map mode if (~PINC==0x01) { gamescreen = 4; mapping = 1; map = shipmap; mapon = 0; } break; case 0: //Welcome Screen mode if (~PINC==0x01) { mapping = 1; map = 1; gamescreen = 1; } if (~PINC==0x02) { mapping = 1; map = 6; gamescreen = 4; } break; case 1: //Rules Screen Mode if (~PINC==0x01) { mapping = 1; map = 2; gamescreen = 2; } break; case 2: //Indicators Screen Mode if (~PINC==0x02) { mapping = 1; map = 6; gamescreen = 4; } break; case 5: //Collision if (timer==0) video_puts(30,25,cu60); else if (timer==1) video_puts(36,45,cu61); timer++; break; case 6: //Calculate Loot and display in corner score++; video_putchar(108,91,47); video_putchar(108,91,score); if (score == 6) gamescreen=7; else gamescreen = 4; foundtreas = 0; break; case 7: //Won the game if (timer==0) { video_puts(24,25,cu62);//13 video_putshipchar(43,65,9); } else if (timer==1) { video_puts(30,45,cu63);//11 video_putshipchar(54,65,11); video_putshipchar(65,65,10); } timer++; break; } //end switch } //end if (mapping) else } //line 231 } //while } //main