Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

We’re showing branches in this repository, but you can also compare across forks.

...
  • 1 commit
  • 3 files changed
  • 0 commit comments
  • 1 contributor
Commits on Mar 04, 2010
Dataman dataman Bulk of the InvaderChron changes are in the Anim.C file.
This is the initial code hack for InvaderChron,
A modification to the MonoChron to display a popular game animation.

Anim.C: Hack & Slash InvaderChron Patch
This is where the animation takes place.
I hacked and slashed a lot of code here.
Probably a lot better methods, but was going for simplicity.
Replace three files and go...

glcd.c: Bug Fix
Modification uses glcdWriteCharGr() function from glcd.c to display invaders marching across the screen.
This function greatly simplified coding, but was initially buggy, so I fixed it.

fontgr.h: Add Font
Modification stores custom font in fontgr.h as was intended by the glcd.c
84d5780
Showing with 149 additions and 730 deletions.
  1. +135 −727 firmware/anim.c
  2. +10 −2 firmware/fontgr.h
  3. +4 −1 firmware/glcd.c
862 firmware/anim.c
View
@@ -14,6 +14,32 @@
#include "glcd.h"
#include "font5x7.h"
+// InvaderChron: Space Invaders modification
+// Pretty sweeping replacement.
+// CRJones aka Dataman
+// InvaderChron@crjones.com
+// Revision History
+//
+// 2010-03-03 First Version
+// Requires: Patch to glcd.c routine glcdWriteCharGr(u08 grCharIdx)
+// Font data in fontgr.h
+//
+#define InvaderTimer 5 // Smaller to make them move faster
+void WriteInvaders(void); // Displays Invaders
+void WritePlayer(void);
+void WriteDigits(uint8_t, uint8_t); // Displays a Set of Digits
+void WriteTime(uint8_t);
+uint8_t pPlayer = 61; // Player Position
+uint8_t pPlayerPrevious = 62; // Previous Player Position
+uint8_t pPlayerDirection = -1; // Player Direction 1=Right, -1=Left
+uint8_t pInvaders=1; // Invader's X Position
+uint8_t pInvadersPrevious=0; // Previous Invader's Position
+int8_t pInvadersDirection=1; // Invader's Direction 1=Right, -1=Left
+uint8_t Frame=0; // Current Animation Frame 0/1
+uint8_t Timer = InvaderTimer; // Count down timer so they don't move rediculously fast
+uint8_t left_score2, right_score2; // Storage for player2 score
+// End Space Invaders Mod 1
+
extern volatile uint8_t time_s, time_m, time_h;
extern volatile uint8_t old_m, old_h;
extern volatile uint8_t date_m, date_d, date_y;
@@ -24,13 +50,6 @@ extern volatile uint8_t score_mode;
uint8_t left_score, right_score;
-float ball_x, ball_y;
-float oldball_x, oldball_y;
-float ball_dx, ball_dy;
-
-int8_t rightpaddle_y, leftpaddle_y;
-uint8_t oldleftpaddle_y, oldrightpaddle_y;
-int8_t rightpaddle_dy, leftpaddle_dy;
extern volatile uint8_t minute_changed, hour_changed;
@@ -112,12 +131,22 @@ void setscore(void)
if(score_mode != last_score_mode) {
redraw_time = 1;
last_score_mode = score_mode;
+ // Default left and right displays
+ left_score = time_h;
+ right_score = time_m;
+ if((region == REGION_US)||(region == DOW_REGION_US)) {
+ left_score2 = date_m;
+ right_score2 = date_d;
+ } else {
+ left_score2 = date_d;
+ right_score2 = date_m;
+ }
}
switch(score_mode) {
case SCORE_MODE_DOW:
break;
case SCORE_MODE_DATELONG:
- right_score = date_d;
+ right_score2 = date_d;
break;
case SCORE_MODE_TIME:
if(alarming && (minute_changed || hour_changed)) {
@@ -133,23 +162,25 @@ void setscore(void)
}
break;
case SCORE_MODE_DATE:
- if((region == REGION_US)||(region == DOW_REGION_US)) {
- left_score = date_m;
- right_score = date_d;
- } else {
- left_score = date_d;
- right_score = date_m;
- }
+ // we defaulted to this
+ //if((region == REGION_US)||(region == DOW_REGION_US)) {
+ // left_score2 = date_m;
+ // right_score2 = date_d;
+ //} else {
+ // left_score2 = date_d;
+ // right_score2 = date_m;
+ //}
break;
case SCORE_MODE_YEAR:
- left_score = 20;
- right_score = date_y;
+ left_score2 = 20;
+ right_score2 = date_y;
break;
case SCORE_MODE_ALARM:
- left_score = alarm_h;
- right_score = alarm_m;
+ left_score2 = alarm_h;
+ right_score2 = alarm_m;
break;
}
+ if (time_format == TIME_12H && left_score>12) {left_score = left_score % 12;}
}
void initanim(void) {
@@ -159,507 +190,111 @@ void initanim(void) {
DEBUG(uart_putw_dec(GLCD_YPIXELS));
DEBUG(putstring_nl(""));
- leftpaddle_y = 25;
- rightpaddle_y = 25;
-
- ball_x = (SCREEN_W / 2) - 1;
- ball_y = (SCREEN_H / 2) - 1;
- float angle = random_angle_rads();
- ball_dx = MAX_BALL_SPEED * cos(angle);
- ball_dy = MAX_BALL_SPEED * sin(angle);
+ pPlayer = 61;
+ pPlayerPrevious = 62;
+ pPlayerDirection = -1;
+ pInvaders = 1;
+ pInvadersPrevious=0;
+
}
void initdisplay(uint8_t inverted) {
-
+ // clear screen
glcdFillRectangle(0, 0, GLCD_XPIXELS, GLCD_YPIXELS, inverted);
+ // get time & display
+ last_score_mode = 99;
+ setscore();
+ WriteTime(inverted);
+ // display players
+ WriteInvaders();
+ WritePlayer();
+ // Show the bases, 1 time only
+ uint8_t i;
+ for (i=0;i<4;i++)
+ {
+ glcdSetAddress(20 + (i*24), 7);
+ glcdWriteCharGr(6);
+ }
- // draw top 'line'
- glcdFillRectangle(0, 0, GLCD_XPIXELS, 2, ! inverted);
-
- // bottom line
- glcdFillRectangle(0, GLCD_YPIXELS - 2, GLCD_XPIXELS, 2, ! inverted);
-
- // left paddle
- glcdFillRectangle(LEFTPADDLE_X, leftpaddle_y, PADDLE_W, PADDLE_H, ! inverted);
- // right paddle
- glcdFillRectangle(RIGHTPADDLE_X, rightpaddle_y, PADDLE_W, PADDLE_H, ! inverted);
-
- //left_score = time_h;
- //right_score = time_m;
- setscore();
-
- // time
- if ((time_format == TIME_12H) && ((score_mode == SCORE_MODE_TIME) || (score_mode == SCORE_MODE_ALARM)))
- drawbigdigit(DISPLAY_H10_X, DISPLAY_TIME_Y, ((left_score + 23)%12 + 1)/10, inverted);
- else
- drawbigdigit(DISPLAY_H10_X, DISPLAY_TIME_Y, left_score/10, inverted);
-
- if ((time_format == TIME_12H) && ((score_mode == SCORE_MODE_TIME) || (score_mode == SCORE_MODE_ALARM)))
- drawbigdigit(DISPLAY_H1_X, DISPLAY_TIME_Y, ((left_score + 23)%12 + 1)%10, inverted);
- else
- drawbigdigit(DISPLAY_H1_X, DISPLAY_TIME_Y, left_score%10, inverted);
-
- drawbigdigit(DISPLAY_M10_X, DISPLAY_TIME_Y, right_score/10, inverted);
- drawbigdigit(DISPLAY_M1_X, DISPLAY_TIME_Y, right_score%10, inverted);
-
- drawmidline(inverted);
}
-
-void step(void) {
- // The keepout is used to know where to -not- put the paddle
- // the 'bouncepos' is where we expect the ball's y-coord to be when
- // it intersects with the paddle area
- static uint8_t right_keepout_top, right_keepout_bot, right_bouncepos, right_endpos;
- static uint8_t left_keepout_top, left_keepout_bot, left_bouncepos, left_endpos;
- static int8_t right_dest, left_dest, ticksremaining;
-
- // Save old ball location so we can do some vector stuff
- oldball_x = ball_x;
- oldball_y = ball_y;
-
- // move ball according to the vector
- ball_x += ball_dx;
- ball_y += ball_dy;
-
-
- /************************************* TOP & BOTTOM WALLS */
- // bouncing off bottom wall, reverse direction
- if (ball_y > (SCREEN_H - ball_radius*2 - BOTBAR_H)) {
- //DEBUG(putstring_nl("bottom wall bounce"));
- ball_y = SCREEN_H - ball_radius*2 - BOTBAR_H;
- ball_dy *= -1;
- }
-
- // bouncing off top wall, reverse direction
- if (ball_y < TOPBAR_H) {
- //DEBUG(putstring_nl("top wall bounce"));
- ball_y = TOPBAR_H;
- ball_dy *= -1;
- }
-
- // For debugging, print the ball location
- DEBUG(putstring("ball @ ("));
- DEBUG(uart_putw_dec(ball_x));
- DEBUG(putstring(", "));
- DEBUG(uart_putw_dec(ball_y));
- DEBUG(putstring_nl(")"));
-
- /************************************* LEFT & RIGHT WALLS */
- // the ball hits either wall, the ball resets location & angle
- if ((ball_x > (SCREEN_W - ball_radius*2)) || ((int8_t)ball_x <= 0)) {
- if(DEBUGGING) {
- if ((int8_t)ball_x <= 0) {
- putstring("Left wall collide");
- if (! minute_changed) {
- putstring_nl("...on accident");
- } else {
- putstring_nl("...on purpose");
- }
- } else {
- putstring("Right wall collide");
- if (! hour_changed) {
- putstring_nl("...on accident");
- } else {
- putstring_nl("...on purpose");
- }
- }
- }
-
- // place ball in the middle of the screen
- ball_x = (SCREEN_W / 2) - 1;
- ball_y = (SCREEN_H / 2) - 1;
-
- float angle = random_angle_rads();
- ball_dx = MAX_BALL_SPEED * cos(angle);
- ball_dy = MAX_BALL_SPEED * sin(angle);
-
- glcdFillRectangle(LEFTPADDLE_X, left_keepout_top, PADDLE_W, left_keepout_bot - left_keepout_top, 0);
- glcdFillRectangle(RIGHTPADDLE_X, right_keepout_top, PADDLE_W, right_keepout_bot - right_keepout_top, 0);
-
- right_keepout_top = right_keepout_bot = 0;
- left_keepout_top = left_keepout_bot = 0;
- redraw_time = 1;
- minute_changed = hour_changed = 0;
-
- //left_score = time_h;
- //right_score = time_m;
- setscore();
- }
-
-
-
- // save old paddle position
- oldleftpaddle_y = leftpaddle_y;
- oldrightpaddle_y = rightpaddle_y;
-
- /************************************* RIGHT PADDLE */
- // check if we are bouncing off right paddle
- if (ball_dx > 0) {
- if ((((int8_t)ball_x + ball_radius*2) >= RIGHTPADDLE_X) &&
- ((int8_t)oldball_x + ball_radius*2 <= RIGHTPADDLE_X)) {
- // check if we collided
- DEBUG(putstring_nl("coll?"));
- // determine the exact position at which it would collide
- float dx = RIGHTPADDLE_X - (oldball_x + ball_radius*2);
- // now figure out what fraction that is of the motion and multiply that by the dy
- float dy = (dx / ball_dx) * ball_dy;
-
- if (intersectrect((oldball_x + dx), (oldball_y + dy), ball_radius*2, ball_radius*2,
- RIGHTPADDLE_X, rightpaddle_y, PADDLE_W, PADDLE_H)) {
- if(DEBUGGING) {
- putstring_nl("nosect");
- if (hour_changed) {
- // uh oh
- putstring_nl("FAILED to miss");
- }
-
-
- putstring("RCOLLISION ball @ ("); uart_putw_dec(oldball_x + dx); putstring(", "); uart_putw_dec(oldball_y + dy);
- putstring(") & paddle @ [");
- uart_putw_dec(RIGHTPADDLE_X); putstring(", "); uart_putw_dec(rightpaddle_y); putstring("]");
- }
-
- // set the ball right up against the paddle
- ball_x = oldball_x + dx;
- ball_y = oldball_y + dy;
- // bounce it
- ball_dx *= -1;
-
- right_bouncepos = right_dest = right_keepout_top = right_keepout_bot = 0;
- left_bouncepos = left_dest = left_keepout_top = left_keepout_bot = 0;
- }
- // otherwise, it didn't bounce...will probably hit the right wall
- DEBUG(putstring(" tix = ")); DEBUG(uart_putw_dec(ticksremaining)); DEBUG(putstring_nl(""));
- }
+void WriteInvaders(void)
+{
+ uint8_t j;
+ uint8_t i;
+ // Clear Previous
+ if (pInvadersPrevious > pInvaders) {i=pInvaders+96;}
+ else {i=pInvaders-1;}
+ glcdFillRectangle(i, 8, 1, 48, 0);
+ // Draw Current
+ for (i=0;i<6;i++){
+ for (j=0;j<6;j++){
+ glcdSetAddress(pInvaders + (j*16), 1+i);
+ glcdWriteCharGr((i/2)+(Frame*3));
+ }
+ }
+}
- if ((ball_dx > 0) && ((ball_x+ball_radius*2) < RIGHTPADDLE_X)) {
- // ball is coming towards the right paddle
-
- if (right_keepout_top == 0 ) {
- ticksremaining = calculate_keepout(ball_x, ball_y, ball_dx, ball_dy, &right_bouncepos, &right_endpos);
- if(DEBUGGING) {
- putstring("Expect bounce @ "); uart_putw_dec(right_bouncepos);
- putstring("-> thru to "); uart_putw_dec(right_endpos); putstring("\n\r");
- }
- if (right_bouncepos > right_endpos) {
- right_keepout_top = right_endpos;
- right_keepout_bot = right_bouncepos + ball_radius*2;
- } else {
- right_keepout_top = right_bouncepos;
- right_keepout_bot = right_endpos + ball_radius*2;
- }
- if(DEBUGGING) {
- //putstring("Keepout from "); uart_putw_dec(right_keepout_top);
- //putstring(" to "); uart_putw_dec(right_keepout_bot); putstring_nl("");
- }
-
- // Now we can calculate where the paddle should go
- if (!hour_changed) {
- // we want to hit the ball, so make it centered.
- right_dest = right_bouncepos + ball_radius - PADDLE_H/2;
- if(DEBUGGING)
- putstring("R -> "); uart_putw_dec(right_dest); putstring_nl("");
- } else {
- // we lost the round so make sure we -dont- hit the ball
- if (right_keepout_top <= (TOPBAR_H + PADDLE_H)) {
- // the ball is near the top so make sure it ends up right below it
- // DEBUG(putstring_nl("at the top"));
- right_dest = right_keepout_bot + 1;
- } else if (right_keepout_bot >= (SCREEN_H - BOTBAR_H - PADDLE_H - 1)) {
- // the ball is near the bottom so make sure it ends up right above it
- //DEBUG(putstring_nl("at the bottom"));
- right_dest = right_keepout_top - PADDLE_H - 1;
- } else {
- //DEBUG(putstring_nl("in the middle"));
- if ( ((uint8_t)crand(2)) & 0x1)
- right_dest = right_keepout_top - PADDLE_H - 1;
- else
- right_dest = right_keepout_bot + 1;
- }
- }
- } else {
- ticksremaining--;
- }
-
- // draw the keepout area (for debugging
- //glcdRectangle(RIGHTPADDLE_X, right_keepout_top, PADDLE_W, right_keepout_bot - right_keepout_top);
-
- int8_t distance = rightpaddle_y - right_dest;
-
- /*if(DEBUGGING) {
- putstring("dest dist: "); uart_putw_dec(abs(distance));
- putstring("\n\rtix: "); uart_putw_dec(ticksremaining);
- putstring("\n\rmax travel: "); uart_putw_dec(ticksremaining * MAX_PADDLE_SPEED);
- putstring_nl("");
- }*/
-
- // if we have just enough time, move the paddle!
- if (abs(distance) > (ticksremaining-1) * MAX_PADDLE_SPEED) {
- distance = abs(distance);
- if (right_dest > rightpaddle_y ) {
- if (distance > MAX_PADDLE_SPEED)
- rightpaddle_y += MAX_PADDLE_SPEED;
- else
- rightpaddle_y += distance;
- }
- if ( right_dest < rightpaddle_y ) {
- if (distance > MAX_PADDLE_SPEED)
- rightpaddle_y -= MAX_PADDLE_SPEED;
- else
- rightpaddle_y -= distance;
- }
- }
- }
- } else {
- /************************************* LEFT PADDLE */
- // check if we are bouncing off left paddle
- if ((((int8_t)ball_x) <= (LEFTPADDLE_X + PADDLE_W)) &&
- (((int8_t)oldball_x) >= (LEFTPADDLE_X + PADDLE_W))) {
- // check if we collided
- // determine the exact position at which it would collide
- float dx = (LEFTPADDLE_X + PADDLE_W) - oldball_x;
- // now figure out what fraction that is of the motion and multiply that by the dy
- float dy = (dx / ball_dx) * ball_dy;
-
- if (intersectrect((oldball_x + dx), (oldball_y + dy), ball_radius*2, ball_radius*2,
- LEFTPADDLE_X, leftpaddle_y, PADDLE_W, PADDLE_H)) {
- if(DEBUGGING) {
- if (minute_changed) {
- // uh oh
- putstring_nl("FAILED to miss");
- }
- putstring("LCOLLISION ball @ ("); uart_putw_dec(oldball_x + dx); putstring(", "); uart_putw_dec(oldball_y + dy);
- putstring(") & paddle @ [");
- uart_putw_dec(LEFTPADDLE_X); putstring(", "); uart_putw_dec(leftpaddle_y); putstring("]");
- }
-
- // bounce it
- ball_dx *= -1;
-
- if ((uint8_t)ball_x != LEFTPADDLE_X + PADDLE_W) {
- // set the ball right up against the paddle
- ball_x = oldball_x + dx;
- ball_y = oldball_y + dy;
- }
- left_bouncepos = left_dest = left_keepout_top = left_keepout_bot = 0;
- }
- if(DEBUGGING) { putstring(" tix = "); uart_putw_dec(ticksremaining); putstring_nl("");}
- // otherwise, it didn't bounce...will probably hit the left wall
- }
+void WritePlayer(void)
+{
+ return; // looks bad, skip it for now.
+ uint8_t j;
+ uint8_t i;
+ // Clear Previous
+ if (pPlayerPrevious > pPlayer) {i=pPlayer+6; j=pPlayer+4;}
+ else {i=pPlayer-1; j=pPlayer+2;}
+ glcdFillRectangle(j, 61, 1, 1, 0); // clear nub
+ glcdFillRectangle(i, 62, 1, 2, 0); // clear end of panel
+ glcdFillRectangle(pPlayer+3, 61, 1, 1, 1); //draw padel
+ glcdFillRectangle(pPlayer, 62, 5, 2, 1); // draw nub
+ }
- if ((ball_dx < 0) && (ball_x > (LEFTPADDLE_X + ball_radius*2))) {
- // ball is coming towards the left paddle
-
- if (left_keepout_top == 0 ) {
- ticksremaining = calculate_keepout(ball_x, ball_y, ball_dx, ball_dy, &left_bouncepos, &left_endpos);
- if(DEBUGGING) {
- putstring("Expect bounce @ "); uart_putw_dec(left_bouncepos);
- putstring("-> thru to "); uart_putw_dec(left_endpos); putstring("\n\r");
- }
-
- if (left_bouncepos > left_endpos) {
- left_keepout_top = left_endpos;
- left_keepout_bot = left_bouncepos + ball_radius*2;
- } else {
- left_keepout_top = left_bouncepos;
- left_keepout_bot = left_endpos + ball_radius*2;
- }
- // if(DEBUGGING) {
- // putstring("Keepout from "); uart_putw_dec(left_keepout_top);
- //putstring(" to "); uart_putw_dec(left_keepout_bot); putstring_nl("");
- // }
-
- // Now we can calculate where the paddle should go
- if (!minute_changed) {
- // we want to hit the ball, so make it centered.
- left_dest = left_bouncepos + ball_radius - PADDLE_H/2;
- if(DEBUGGING) { putstring("hitL -> "); uart_putw_dec(left_dest); putstring_nl(""); }
- } else {
- // we lost the round so make sure we -dont- hit the ball
- if (left_keepout_top <= (TOPBAR_H + PADDLE_H)) {
- // the ball is near the top so make sure it ends up right below it
- DEBUG(putstring_nl("at the top"));
- left_dest = left_keepout_bot + 1;
- } else if (left_keepout_bot >= (SCREEN_H - BOTBAR_H - PADDLE_H - 1)) {
- // the ball is near the bottom so make sure it ends up right above it
- DEBUG(putstring_nl("at the bottom"));
- left_dest = left_keepout_top - PADDLE_H - 1;
- } else {
- DEBUG(putstring_nl("in the middle"));
- if ( ((uint8_t)crand(2)) & 0x1)
- left_dest = left_keepout_top - PADDLE_H - 1;
- else
- left_dest = left_keepout_bot + 1;
- }
- if(DEBUGGING) {putstring("missL -> "); uart_putw_dec(left_dest); putstring_nl(""); }
- }
- } else {
- ticksremaining--;
- }
- // draw the keepout area (for debugging
- //glcdRectangle(LEFTPADDLE_X, left_keepout_top, PADDLE_W, left_keepout_bot - left_keepout_top);
-
- int8_t distance = abs(leftpaddle_y - left_dest);
-
- /*if(DEBUGGING) {
- putstring("\n\rdest dist: "); uart_putw_dec(abs(distance));
- putstring("\n\rtix: "); uart_putw_dec(ticksremaining);
-
- putstring("\n\rmax travel: "); uart_putw_dec(ticksremaining * MAX_PADDLE_SPEED);
- putstring_nl("");
- }*/
-
- //if(DEBUGGING){putstring("\n\rleft paddle @ "); uart_putw_dec(leftpaddle_y); putstring_nl("");}
-
- // if we have just enough time, move the paddle!
- if (distance > ((ticksremaining-1) * MAX_PADDLE_SPEED)) {
- if (left_dest > leftpaddle_y ) {
- if (distance > MAX_PADDLE_SPEED)
- leftpaddle_y += MAX_PADDLE_SPEED;
- else
- leftpaddle_y += distance;
- }
- if (left_dest < leftpaddle_y ) {
- if (distance > MAX_PADDLE_SPEED)
- leftpaddle_y -= MAX_PADDLE_SPEED;
- else
- leftpaddle_y -= distance;
- }
- }
- }
+void step(void) {
+ if (--Timer==0)
+ {
+ Timer=InvaderTimer;
+ pInvadersPrevious = pInvaders;
+ pInvaders += pInvadersDirection;
+ if (pInvaders > 31) {pInvadersDirection=-1;}
+ if (pInvaders < 1) {pInvadersDirection=1;}
+ Frame = !Frame;
+ pPlayerPrevious = pPlayer;
+ pPlayer += pPlayerDirection;
+ if (pPlayer > 63) {pPlayerDirection=-1;}
+ if (pPlayer < 1) {pPlayerDirection=1;}
}
-
- // make sure the paddles dont hit the top or bottom
- if (leftpaddle_y < TOPBAR_H +1)
- leftpaddle_y = TOPBAR_H + 1;
- if (rightpaddle_y < TOPBAR_H + 1)
- rightpaddle_y = TOPBAR_H + 1;
-
- if (leftpaddle_y > (SCREEN_H - PADDLE_H - BOTBAR_H - 1))
- leftpaddle_y = (SCREEN_H - PADDLE_H - BOTBAR_H - 1);
- if (rightpaddle_y > (SCREEN_H - PADDLE_H - BOTBAR_H - 1))
- rightpaddle_y = (SCREEN_H - PADDLE_H - BOTBAR_H - 1);
}
-void drawmidline(uint8_t inverted) {
- uint8_t i;
- for (i=0; i < (SCREEN_H/8 - 1); i++) {
- glcdSetAddress((SCREEN_W-MIDLINE_W)/2, i);
- if (inverted) {
- glcdDataWrite(0xF0);
- } else {
- glcdDataWrite(0x0F);
- }
- }
- glcdSetAddress((SCREEN_W-MIDLINE_W)/2, i);
- if (inverted) {
- glcdDataWrite(0x20);
- } else {
- glcdDataWrite(0xCF);
- }
+void WriteTime(uint8_t inverted) {
+ glcdSetAddress(0,0);
+ WriteDigits(left_score,inverted);
+ WriteDigits(right_score,inverted);
+ glcdSetAddress(102,0);
+ WriteDigits(left_score2,inverted);
+ WriteDigits(right_score2,inverted);
}
-void draw(uint8_t inverted) {
-
- // erase old ball
- glcdFillRectangle(oldball_x, oldball_y, ball_radius*2, ball_radius*2, inverted);
-
- // draw new ball
- glcdFillRectangle(ball_x, ball_y, ball_radius*2, ball_radius*2, ! inverted);
-
- // draw middle lines around where the ball may have intersected it?
- if (intersectrect(oldball_x, oldball_y, ball_radius*2, ball_radius*2,
- SCREEN_W/2-MIDLINE_W, 0, MIDLINE_W, SCREEN_H)) {
- // redraw it since we had an intersection
- drawmidline(inverted);
- }
-
-
-
-
- if (oldleftpaddle_y != leftpaddle_y) {
- // clear left paddle
- glcdFillRectangle(LEFTPADDLE_X, oldleftpaddle_y, PADDLE_W, PADDLE_H, inverted);
- // draw left paddle
- glcdFillRectangle(LEFTPADDLE_X, leftpaddle_y, PADDLE_W, PADDLE_H, !inverted);
- }
-
- if (oldrightpaddle_y != rightpaddle_y) {
- // clear right paddle
- glcdFillRectangle(RIGHTPADDLE_X, oldrightpaddle_y, PADDLE_W, PADDLE_H, inverted);
- // draw right paddle
- glcdFillRectangle(RIGHTPADDLE_X, rightpaddle_y, PADDLE_W, PADDLE_H, !inverted);
- }
-
- if (intersectrect(oldball_x, oldball_y, ball_radius*2, ball_radius*2, RIGHTPADDLE_X, rightpaddle_y, PADDLE_W, PADDLE_H)) {
- glcdFillRectangle(RIGHTPADDLE_X, rightpaddle_y, PADDLE_W, PADDLE_H, !inverted);
- }
- // draw time
- uint8_t redraw_digits;
- TIMSK2 = 0; //Disable Timer 2 interrupt, to prevent a race condition.
- if(redraw_time)
- {
- redraw_digits = 1;
- redraw_time = 0;
- }
- TIMSK2 = _BV(TOIE2); //Race issue gone, renable.
-
- draw_score(redraw_digits,inverted);
-
- redraw_digits = 0;
- // print 'alarm'
- /*
- if (intersectrect(oldball_x, oldball_y, ball_radius*2, ball_radius*2,
- ALARMBOX_X, ALARMBOX_Y, ALARMBOX_W, ALARMBOX_H)) {
-
- glcdFillRectangle(ALARMBOX_X+2, ALARMBOX_Y+2, ALARMBOX_W-4, ALARMBOX_H-4, OFF);
-
- glcdFillRectangle(ALARMBOX_X, ALARMBOX_Y, 2, ALARMBOX_H, ON);
- glcdFillRectangle(ALARMBOX_X+ALARMBOX_W, ALARMBOX_Y, 2, ALARMBOX_H, ON);
- }
+void WriteDigits(uint8_t t, uint8_t inverted)
+{
+ glcdWriteChar(48 + (t/10),inverted);
+ glcdWriteChar(48 + (t%10),inverted);
+}
- if (!intersectrect(ball_x, ball_y, ball_radius*2, ball_radius*2,
- ALARMBOX_X, ALARMBOX_Y, ALARMBOX_W, ALARMBOX_H)) {
- */
- //}
+void draw(uint8_t inverted) {
+ WriteInvaders();
+ WritePlayer();
+ setscore();
+ //if (minute_changed || hour_changed || alarming || redraw_time)
+ //{
+ redraw_time = 0;
+ WriteTime(inverted);
+ //}
+ return;
}
-uint8_t intersectrect(uint8_t x1, uint8_t y1, uint8_t w1, uint8_t h1,
- uint8_t x2, uint8_t y2, uint8_t w2, uint8_t h2) {
- // yer everyday intersection tester
- // check x coord first
- if (x1+w1 < x2)
- return 0;
- if (x2+w2 < x1)
- return 0;
-
- // check the y coord second
- if (y1+h1 < y2)
- return 0;
- if (y2+h2 < y1)
- return 0;
-
- return 1;
-}
-
-// 8 pixels high
-static unsigned char __attribute__ ((progmem)) BigFont[] = {
- 0xFF, 0x81, 0x81, 0xFF,// 0
- 0x00, 0x00, 0x00, 0xFF,// 1
- 0x9F, 0x91, 0x91, 0xF1,// 2
- 0x91, 0x91, 0x91, 0xFF,// 3
- 0xF0, 0x10, 0x10, 0xFF,// 4
- 0xF1, 0x91, 0x91, 0x9F,// 5
- 0xFF, 0x91, 0x91, 0x9F,// 6
- 0x80, 0x80, 0x80, 0xFF,// 7
- 0xFF, 0x91, 0x91, 0xFF,// 8
- 0xF1, 0x91, 0x91, 0xFF,// 9
- 0x00, 0x00, 0x00, 0x00,// SPACE
-};
static unsigned char __attribute__ ((progmem)) MonthText[] = {
0,0,0,
@@ -702,235 +337,8 @@ uint8_t dotw(uint8_t mon, uint8_t day, uint8_t yr)
return (day + (2 * month) + (6 * (month+1)/10) + year + (year/4) - (year/100) + (year/400) + 1) % 7;
}
-void draw_score(uint8_t redraw_digits, uint8_t inverted) {
- static uint8_t prev_mode;
- if(score_mode==SCORE_MODE_DOW) {
- if(prev_mode != SCORE_MODE_DOW)
- {
- drawbigdigit(DISPLAY_H10_X, DISPLAY_TIME_Y, 10, inverted);
- drawbigdigit(DISPLAY_H1_X, DISPLAY_TIME_Y, 10, inverted);
- drawbigdigit(DISPLAY_M10_X, DISPLAY_TIME_Y, 10, inverted);
- drawbigdigit(DISPLAY_M1_X, DISPLAY_TIME_Y, 10, inverted);
- glcdFillRectangle(ball_x, ball_y, ball_radius*2, ball_radius*2, ! inverted);
- prev_mode = SCORE_MODE_DOW;
- }
-
- if(redraw_digits || intersectrect(oldball_x, oldball_y, ball_radius*2, ball_radius*2,
- DISPLAY_DOW1_X, DISPLAY_TIME_Y, DISPLAY_DIGITW, DISPLAY_DIGITH)) {
- drawbigfont(DISPLAY_DOW1_X, DISPLAY_TIME_Y, pgm_read_byte(DOWText+(dotw(date_m,date_d,date_y)*3)+0), inverted);
- }
- if(redraw_digits || intersectrect(oldball_x, oldball_y, ball_radius*2, ball_radius*2,
- DISPLAY_DOW2_X, DISPLAY_TIME_Y, DISPLAY_DIGITW, DISPLAY_DIGITH)) {
- drawbigfont(DISPLAY_DOW2_X, DISPLAY_TIME_Y, pgm_read_byte(DOWText+(dotw(date_m,date_d,date_y)*3)+1), inverted);
- }
- if(redraw_digits || intersectrect(oldball_x, oldball_y, ball_radius*2, ball_radius*2,
- DISPLAY_DOW3_X, DISPLAY_TIME_Y, DISPLAY_DIGITW, DISPLAY_DIGITH)) {
- drawbigfont(DISPLAY_DOW3_X, DISPLAY_TIME_Y, pgm_read_byte(DOWText+(dotw(date_m,date_d,date_y)*3)+2), inverted);
- }
- }
- else if (score_mode==SCORE_MODE_DATELONG) {
- if(prev_mode != SCORE_MODE_DATELONG)
- {
- if(prev_mode == SCORE_MODE_DOW) {
- drawbigfont(DISPLAY_DOW1_X, DISPLAY_TIME_Y, ' ', inverted);
- drawbigfont(DISPLAY_DOW2_X, DISPLAY_TIME_Y, ' ', inverted);
- drawbigfont(DISPLAY_DOW3_X, DISPLAY_TIME_Y, ' ', inverted);
- }
- if(prev_mode == SCORE_MODE_TIME) {
- drawbigdigit(DISPLAY_H10_X, DISPLAY_TIME_Y, 10, inverted);
- drawbigdigit(DISPLAY_H1_X, DISPLAY_TIME_Y, 10, inverted);
- drawbigdigit(DISPLAY_M10_X, DISPLAY_TIME_Y, 10, inverted);
- drawbigdigit(DISPLAY_M1_X, DISPLAY_TIME_Y, 10, inverted);
- }
- glcdFillRectangle(ball_x, ball_y, ball_radius*2, ball_radius*2, ! inverted);
- prev_mode = SCORE_MODE_DATELONG;
- }
- if(redraw_digits || intersectrect(oldball_x, oldball_y, ball_radius*2, ball_radius*2,
- DISPLAY_MON1_X, DISPLAY_TIME_Y, DISPLAY_DIGITW, DISPLAY_DIGITH)) {
- drawbigfont(DISPLAY_MON1_X, DISPLAY_TIME_Y, pgm_read_byte(MonthText+(date_m*3)+0), inverted);
- }
- if(redraw_digits || intersectrect(oldball_x, oldball_y, ball_radius*2, ball_radius*2,
- DISPLAY_MON2_X, DISPLAY_TIME_Y, DISPLAY_DIGITW, DISPLAY_DIGITH)) {
- drawbigfont(DISPLAY_MON2_X, DISPLAY_TIME_Y, pgm_read_byte(MonthText+(date_m*3)+1), inverted);
- }
- if(redraw_digits || intersectrect(oldball_x, oldball_y, ball_radius*2, ball_radius*2,
- DISPLAY_MON3_X, DISPLAY_TIME_Y, DISPLAY_DIGITW, DISPLAY_DIGITH)) {
- drawbigfont(DISPLAY_MON3_X, DISPLAY_TIME_Y, pgm_read_byte(MonthText+(date_m*3)+2), inverted);
- }
- if (redraw_digits || intersectrect(oldball_x, oldball_y, ball_radius*2, ball_radius*2,
- DISPLAY_DAY10_X, DISPLAY_TIME_Y, DISPLAY_DIGITW, DISPLAY_DIGITH)) {
- drawbigdigit(DISPLAY_DAY10_X, DISPLAY_TIME_Y, right_score/10, inverted);
- }
- if (redraw_digits || intersectrect(oldball_x, oldball_y, ball_radius*2, ball_radius*2,
- DISPLAY_DAY1_X, DISPLAY_TIME_Y, DISPLAY_DIGITW, DISPLAY_DIGITH)) {
- drawbigdigit(DISPLAY_DAY1_X, DISPLAY_TIME_Y, right_score%10, inverted);
- }
- }
- else {
- if((prev_mode == SCORE_MODE_DOW) || (prev_mode == SCORE_MODE_DATELONG))
- {
- if(prev_mode == SCORE_MODE_DATELONG) {
- drawbigfont(DISPLAY_MON1_X, DISPLAY_TIME_Y, ' ', inverted);
- drawbigfont(DISPLAY_MON2_X, DISPLAY_TIME_Y, ' ', inverted);
- drawbigfont(DISPLAY_MON3_X, DISPLAY_TIME_Y, ' ', inverted);
- drawbigdigit(DISPLAY_DAY10_X, DISPLAY_TIME_Y, 10, inverted);
- drawbigdigit(DISPLAY_DAY1_X, DISPLAY_TIME_Y, 10, inverted);
- }
- if(prev_mode == SCORE_MODE_DOW) {
- drawbigfont(DISPLAY_DOW1_X, DISPLAY_TIME_Y, ' ', inverted);
- drawbigfont(DISPLAY_DOW2_X, DISPLAY_TIME_Y, ' ', inverted);
- drawbigfont(DISPLAY_DOW3_X, DISPLAY_TIME_Y, ' ', inverted);
- }
- if(prev_mode == SCORE_MODE_TIME) {
- drawbigdigit(DISPLAY_H10_X, DISPLAY_TIME_Y, 10, inverted);
- drawbigdigit(DISPLAY_H1_X, DISPLAY_TIME_Y, 10, inverted);
- drawbigdigit(DISPLAY_M10_X, DISPLAY_TIME_Y, 10, inverted);
- drawbigdigit(DISPLAY_M1_X, DISPLAY_TIME_Y, 10, inverted);
- }
- glcdFillRectangle(ball_x, ball_y, ball_radius*2, ball_radius*2, ! inverted);
- prev_mode = SCORE_MODE_TIME;
- }
- if (redraw_digits || intersectrect(oldball_x, oldball_y, ball_radius*2, ball_radius*2,
- DISPLAY_H10_X, DISPLAY_TIME_Y, DISPLAY_DIGITW, DISPLAY_DIGITH)) {
-
- if ((time_format == TIME_12H) && ((score_mode == SCORE_MODE_TIME) || (score_mode == SCORE_MODE_ALARM)))
- drawbigdigit(DISPLAY_H10_X, DISPLAY_TIME_Y, ((left_score + 23)%12 + 1)/10, inverted);
- else
- drawbigdigit(DISPLAY_H10_X, DISPLAY_TIME_Y, left_score/10, inverted);
- }
-
- // redraw 1's of hours
- if (redraw_digits || intersectrect(oldball_x, oldball_y, ball_radius*2, ball_radius*2,
- DISPLAY_H1_X, DISPLAY_TIME_Y, DISPLAY_DIGITW, DISPLAY_DIGITH)) {
- if ((time_format == TIME_12H) && ((score_mode == SCORE_MODE_TIME) || (score_mode == SCORE_MODE_ALARM)))
- drawbigdigit(DISPLAY_H1_X, DISPLAY_TIME_Y, ((left_score + 23)%12 + 1)%10, inverted);
- else
- drawbigdigit(DISPLAY_H1_X, DISPLAY_TIME_Y, left_score%10, inverted);
- }
- if (redraw_digits || intersectrect(oldball_x, oldball_y, ball_radius*2, ball_radius*2,
- DISPLAY_M10_X, DISPLAY_TIME_Y, DISPLAY_DIGITW, DISPLAY_DIGITH)) {
- drawbigdigit(DISPLAY_M10_X, DISPLAY_TIME_Y, right_score/10, inverted);
- }
- if (redraw_digits || intersectrect(oldball_x, oldball_y, ball_radius*2, ball_radius*2,
- DISPLAY_M1_X, DISPLAY_TIME_Y, DISPLAY_DIGITW, DISPLAY_DIGITH)) {
- drawbigdigit(DISPLAY_M1_X, DISPLAY_TIME_Y, right_score%10, inverted);
- }
- }
-}
-void drawbigdigit(uint8_t x, uint8_t y, uint8_t n, uint8_t inverted) {
- uint8_t i, j;
-
- for (i = 0; i < 4; i++) {
- uint8_t d = pgm_read_byte(BigFont+(n*4)+i);
- for (j=0; j<8; j++) {
- if (d & _BV(7-j)) {
- glcdFillRectangle(x+i*2, y+j*2, 2, 2, !inverted);
- } else {
- glcdFillRectangle(x+i*2, y+j*2, 2, 2, inverted);
- }
- }
- }
-}
-void drawbigfont(uint8_t x, uint8_t y, uint8_t n, uint8_t inverted) {
- uint8_t i, j;
-
- for (i = 0; i < 5; i++) {
- uint8_t d = pgm_read_byte(Font5x7+((n-0x20)*5)+i);
- for (j=0; j<7; j++) {
- if (d & _BV(j)) {
- glcdFillRectangle(x+i*2, y+j*2, 2, 2, !inverted);
- } else {
- glcdFillRectangle(x+i*2, y+j*2, 2, 2, inverted);
- }
- }
- }
-}
-
-float random_angle_rads(void) {
- // create random vector MEME seed it ok???
- float angle = crand(0);
-
- //angle = 31930; // MEME DEBUG
- if(DEBUGGING){putstring("\n\rrand = "); uart_putw_dec(angle);}
- angle = (angle * (90.0 - MIN_BALL_ANGLE*2) / RAND_MAX) + MIN_BALL_ANGLE;
-
- //pick the quadrant
- uint8_t quadrant = (crand(1)) % 4;
- //quadrant = 2; // MEME DEBUG
-
- if(DEBUGGING){putstring(" quad = "); uart_putw_dec(quadrant);}
- angle += quadrant * 90;
- if(DEBUGGING){putstring(" new ejection angle = "); uart_putw_dec(angle); putstring_nl("");}
-
- angle *= 3.1415;
- angle /= 180;
- return angle;
-}
-
-uint8_t calculate_keepout(float theball_x, float theball_y, float theball_dx, float theball_dy, uint8_t *keepout1, uint8_t *keepout2) {
- // "simulate" the ball bounce...its not optimized (yet)
- float sim_ball_y = theball_y;
- float sim_ball_x = theball_x;
- float sim_ball_dy = theball_dy;
- float sim_ball_dx = theball_dx;
-
- uint8_t tix = 0, collided = 0;
-
- while ((sim_ball_x < (RIGHTPADDLE_X + PADDLE_W)) && ((sim_ball_x + ball_radius*2) > LEFTPADDLE_X)) {
- float old_sim_ball_x = sim_ball_x;
- float old_sim_ball_y = sim_ball_y;
- sim_ball_y += sim_ball_dy;
- sim_ball_x += sim_ball_dx;
-
- if (sim_ball_y > (int8_t)(SCREEN_H - ball_radius*2 - BOTBAR_H)) {
- sim_ball_y = SCREEN_H - ball_radius*2 - BOTBAR_H;
- sim_ball_dy *= -1;
- }
-
- if (sim_ball_y < TOPBAR_H) {
- sim_ball_y = TOPBAR_H;
- sim_ball_dy *= -1;
- }
-
- if ((((int8_t)sim_ball_x + ball_radius*2) >= RIGHTPADDLE_X) &&
- ((old_sim_ball_x + ball_radius*2) < RIGHTPADDLE_X)) {
- // check if we collided with the right paddle
-
- // first determine the exact position at which it would collide
- float dx = RIGHTPADDLE_X - (old_sim_ball_x + ball_radius*2);
- // now figure out what fraction that is of the motion and multiply that by the dy
- float dy = (dx / sim_ball_dx) * sim_ball_dy;
-
- if(DEBUGGING){putstring("RCOLL@ ("); uart_putw_dec(old_sim_ball_x + dx); putstring(", "); uart_putw_dec(old_sim_ball_y + dy);}
-
- *keepout1 = old_sim_ball_y + dy;
- collided = 1;
- } else if (((int8_t)sim_ball_x <= (LEFTPADDLE_X + PADDLE_W)) &&
- (old_sim_ball_x > (LEFTPADDLE_X + PADDLE_W))) {
- // check if we collided with the left paddle
-
- // first determine the exact position at which it would collide
- float dx = (LEFTPADDLE_X + PADDLE_W) - old_sim_ball_x;
- // now figure out what fraction that is of the motion and multiply that by the dy
- float dy = (dx / sim_ball_dx) * sim_ball_dy;
-
- //if(DEBUGGING){putstring("LCOLL@ ("); uart_putw_dec(old_sim_ball_x + dx); putstring(", "); uart_putw_dec(old_sim_ball_y + dy);}
-
- *keepout1 = old_sim_ball_y + dy;
- collided = 1;
- }
- if (!collided) {
- tix++;
- }
-
- //if(DEBUGGING){putstring("\tSIMball @ ["); uart_putw_dec(sim_ball_x); putstring(", "); uart_putw_dec(sim_ball_y); putstring_nl("]");}
- }
- *keepout2 = sim_ball_y;
-
- return tix;
-}
12 firmware/fontgr.h
View
@@ -24,8 +24,16 @@ static unsigned char __attribute__ ((progmem)) FontGr[] =
{
// format is one character per line:
// length, byte array[length]
- 0x0B,0x3E,0x41,0x41,0x41,0x41,0x42,0x42,0x42,0x42,0x3C,0x00,// 0. Folder Icon
- 0x06,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF // 1. Solid 6x8 block
+ //0x0B,0x3E,0x41,0x41,0x41,0x41,0x42,0x42,0x42,0x42,0x3C,0x00,// 0. Folder Icon
+ //0x06,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF // 1. Solid 6x8 block
+
+16, 88, 188, 28, 22, 22, 63, 63, 22, 22, 28, 188, 88, 0, 0, 0, 0, // 0 = Triangle Up
+16, 30, 184, 125, 54, 60, 60, 60, 60, 54, 125, 184, 30, 0, 0, 0, 0,// 1 = Square Up
+16, 156, 158, 94, 118, 55, 95, 95, 55, 118, 94, 158, 156, 0, 0, 0, 0, // 2 = Circle Up
+16, 24, 28, 156, 86, 182, 95, 95, 182, 86, 156, 28, 24, 0, 0, 0, 0, // 3 = Triangle Down
+16, 112, 24, 125, 182, 188, 60, 60, 188, 182, 125, 24, 112, 0, 0, 0, 0, // 4 = Square Down
+16, 28, 94, 254, 182, 55, 95, 95, 55, 182, 254, 94, 28, 0, 0, 0, 0, // 5 = Circle Down
+12, 248, 252, 254, 254, 63, 31, 31, 63, 254, 254, 252, 248 // 6 = Base
};
#endif
5 firmware/glcd.c
View
@@ -304,7 +304,10 @@ void glcdWriteCharGr(u08 grCharIdx)
{
// add this graphic's length to the startIdx
// to get the startIdx of the next one
- grStartIdx += pgm_read_byte(FontGr+grStartIdx);
+ // 2010-03-03 BUG Dataman/CRJONES There's a bug here: Have to add 1 for the byte-cout.
+ // grStartIdx += pgm_read_byte(FontGr+grStartIdx);
+ grStartIdx += pgm_read_byte(FontGr+grStartIdx)+1;
+
}
grLength = pgm_read_byte(FontGr+grStartIdx);

No commit comments for this range

Something went wrong with that request. Please try again.