Source

pebble / mario / src / anim.c

Diff from to

File mario/src/anim.c

 // MarioChron: Mario Themed Clock Face
 // Initial work based on InvaderChron by Dataman
 // By: techninja (James T) & Super-Awesome Sylvia
+// Ported to Pebble by Trammell Hudson <hudson@osresearch.net>
 //
 // Originally created for Sylvia's Super-Awesome Mini Maker Show Episode S02E03
 // sylviashow.com/monochron
 
 // == EASILY HACKABLE DEFINES ==================================================
+// MonoChron as 128x64, Pebble as 144x168.
+// Initial version does not change anything
 
 #define GROUND_Y 58    // Ground Position
 
 
 // ^^ EASILY HACKABLE DEFINES ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
-#include <avr/io.h>      // this contains all the IO port definitions
-#include <avr/interrupt.h>
-#include <util/delay.h>
-#include <avr/pgmspace.h>
-#include <avr/eeprom.h>
-#include <avr/wdt.h>
+#include <pebble_os.h>
 #include <string.h>
 #include <stdlib.h>
+#include <stdint.h>
 #include <math.h>
 
-#include "util.h"
-#include "ratt.h"
-#include "ks0108.h"
-#include "glcd.h"
 #include "font5x7.h"
 
+typedef uint8_t u08;
+#define GLCD_XPIXELS 128
+#define GLCD_YPIXELS 64
+
+static GContext * ctx;
+
+static inline void
+glcdRectangle(
+	int x,
+	int y,
+	int w,
+	int h
+)
+{
+	graphics_context_set_stroke_color(ctx, GColorBlack);
+	graphics_draw_round_rect(ctx, GRect(x,y,w,h), 0);
+}
+
+static inline void
+glcdFillRectangle(
+	int x,
+	int y,
+	int w,
+	int h,
+	int draw_white
+)
+{
+	graphics_context_set_fill_color(ctx, draw_white ? GColorWhite : GColorBlack);
+	graphics_fill_rect(ctx, GRect(x, y, w, h), 0, GCornerNone);
+}
+
+
+static inline void
+glcdClearDot(
+	int x,
+	int y
+)
+{
+	graphics_context_set_fill_color(ctx, GColorWhite);
+	graphics_draw_pixel(ctx, GPoint(x,y));
+}
+
+static inline void
+glcdSetDot(
+	int x,
+	int y
+)
+{
+	graphics_context_set_fill_color(ctx, GColorBlack);
+	graphics_draw_pixel(ctx, GPoint(x,y));
+}
+
 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;
 uint16_t crand(uint8_t type) {
   if((type==0)||(type>2))
   {
-    wdt_reset();
+    //wdt_reset();
     encipher();
     return (rval[0]^rval[1])&RAND_MAX;
   } else if (type==1) {
     // Default left and right displays
     left_score = time_h;
     right_score = time_m;
-    if((region == REGION_US)||(region == DOW_REGION_US)) {
+    //if((region == REGION_US)||(region == DOW_REGION_US))
+    if (1) {
       left_score2 = date_m;
       right_score2 = date_d;
     } else {
     }
   }
 
+#if 0
   switch(score_mode) {
   	case SCORE_MODE_DOW:
   	  break;
 	      right_score = old_m;
 	    }
       } else {
+#endif
         left_score = time_h;
         right_score = time_m;
+#if 0
       }
       break;
     case SCORE_MODE_DATE:
       right_score2 = alarm_m;
       break;
   }
+
   if (time_format == TIME_12H && left_score>12) {left_score = left_score % 12;}
+#endif
 }
 
 void initanim(void) {
+#if 0
   DEBUG(putstring("screen width: "));
   DEBUG(uart_putw_dec(GLCD_XPIXELS));
   DEBUG(putstring("\n\rscreen height: "));
   DEBUG(uart_putw_dec(GLCD_YPIXELS));
   DEBUG(putstring_nl(""));
+#endif
 }
 
 void initdisplay(uint8_t inverted) {
   last_score_mode = 99; // ???
   setscore();
 
+#if 0
   // Write "WORLD" in the top left corner
   glcdSetAddress(0,0);
   write_font = 77;
     glcdWriteChar('R', inverted);glcdWriteChar('L', inverted);
     glcdWriteChar('D', inverted);
   write_font = 57;
+#endif
 
   // Add the coin and draw the time
   draw_coin(80, 0);
 
   // TODO: Allow for object overlap without unsetting background pixels
 
+#if 0
   _delay_ms(20); // ~16 FPS (not guaranteeable unless animation payload is measured)
+#endif
 }
 
 void animate_mario(void){
 void WriteTime(uint8_t inverted) {
   write_font = 77;
 
+#if 0
   // Draw Date
   glcdSetAddress(1,1);
   WriteDigits(left_score2,inverted);
   glcdWriteChar('x', inverted);
   WriteDigits(left_score,inverted);
   WriteDigits(right_score,inverted);
+#endif
 
   write_font = 57;
 }
 
 void WriteDigits(uint8_t t, uint8_t inverted)
 {
+#if 0
 	glcdWriteChar(48 + (t/10),inverted);
 	glcdWriteChar(48 + (t%10),inverted);
+#endif
 }
 
 
-void draw(uint8_t inverted) {
+void draw(GContext * gctx)
+{
+   ctx = gctx;
+
   // Animation Loop + delay
   animation_loop();
   setscore();
 
+#if 0
   if (redraw_time){
     redraw_time = 0;
     WriteTime(inverted);
   }
+#endif
   return;
 }
 
 
-static unsigned char __attribute__ ((progmem)) MonthText[] = {
+static unsigned char MonthText[] = {
 	0,0,0,
 	'J','A','N',
 	'F','E','B',
 	'D','E','C',
 };
 
-static unsigned char __attribute__ ((progmem)) DOWText[] = {
+static unsigned char DOWText[] = {
 	'S','U','N',
 	'M','O','N',
 	'T','U','E',
     }
     return (day + (2 * month) + (6 * (month+1)/10) + year + (year/4) - (year/100) + (year/400) + 1) % 7;
 }
-
-
-
-
-
-