]> hackdaworld.org Git - my-code/arm.git/commitdiff
basical alpha blending working (modulo minor pits)
authorhackbard <hackbard@staubsauger.localdomain>
Sun, 16 Sep 2007 00:06:57 +0000 (02:06 +0200)
committerhackbard <hackbard@staubsauger.localdomain>
Sun, 16 Sep 2007 00:06:57 +0000 (02:06 +0200)
betty/betty.c
betty/display.c
betty/display.h

index 427d32b57cdae5f118ce289165501ec137606fb2..8d7ce84be5c46cf6c29b59330b697ba7b88ce51e 100644 (file)
@@ -58,11 +58,11 @@ int main() {
 
        
        while(1) {
-               pause(0x05ffff);
+               pause(0x0fffff);
 
                /* button test! */
                if(button_get_event(&button)) {
-                       uart0_send_string(announce);
+                       //uart0_send_string(announce);
                        switch(button.key[0]) {
                                case BUTTON_POWER:
                                        display_logo((u8 *)default_logo);
@@ -101,10 +101,37 @@ int main() {
                                        break;
                                case BUTTON_3:
                                        display_draw_font(70,70,
-                                                         (u8 *)default_font+(0x33>>3),
+                                                         (u8 *)default_font+(0x33<<3),
                                                               DISPLAY_FILL_LG,
                                                               0xff);
                                        break;
+                               case BUTTON_4:
+                                       display_font_page(23,19,(u8 *)default_font+(0x34<<3),DISPLAY_FILL_B);
+                                       break;
+                               case BUTTON_5:
+                                       display_font_page(10,19,(u8 *)default_font+(0x35<<3),DISPLAY_FILL_DG);
+                                       break;
+                               case BUTTON_6:
+                                       display_font_page(2,19,(u8 *)default_font+(0x36<<3),DISPLAY_FILL_LG);
+                                       break;
+                               case BUTTON_7:
+                                       display_draw_rectangle(2,2,4,4,
+                                                              DISPLAY_FILL_B,
+                                                              0xff);
+                                       break;
+                               case BUTTON_8:
+                                       display_draw_rectangle(8,8,4,4,
+                                                              DISPLAY_FILL_DG,
+                                                              0xff);
+                                       break;
+                               case BUTTON_BETTY:
+                                       display_rectangle_page(80,15,16,2,DISPLAY_FILL_B,0x7f);
+                                       uart0_send_byte('b');
+                                       break;
+                               case BUTTON_EXIT:
+                                       display_rectangle_page(90,16,16,2,DISPLAY_FILL_LG,0x7f);
+                                       uart0_send_byte('e');
+                                       break;
                                default:
                                        display_clear_screen();
                                        break;
index a439fcdff09b4483953574e30d2a8d920300583e..bb742415ad3a22f81a9c44566e3da4bd6b08efca 100644 (file)
@@ -17,8 +17,8 @@
  */
 
 #include "display.h"
-#include "system.h"
-#include "default_logo.h"
+
+// debug
 #include "uart.h"
 
 /*
@@ -89,21 +89,16 @@ void display_init(void) {
        DISPLAY_SET_ON;
 }
 
-void display_load_logo(u8 *src) {
+void display_logo(u8 *src) {
 
-       u8 *s;
        u8 page,width;
 
-       s=src;
-       if(s==0)
-               s=default_logo;
-
        for(page=0;page<DISPLAY_PAGE_MAX;page++) {
                DISPLAY_SET_COL_ADDR(0);
                DISPLAY_SET_PAGE_ADDR(page);
                for(width=0;width<DISPLAY_DIMX;width++) {
-                       DISPLAY_DATA=*s++;
-                       DISPLAY_DATA=*s++;
+                       DISPLAY_DATA=*src++;
+                       DISPLAY_DATA=*src++;
                }
        }
 }
@@ -129,9 +124,10 @@ void display_draw_rectangle(u8 x,u8 y,u8 w,u8 h,u8 fill,u8 alpha) {
                        rmax=y+h;
                for(col=x;col<x+w;col++) {
                        DISPLAY_SET_COL_ADDR(col);
-                       d[0]=DISPLAY_DATA;              // dummy read (p.16)
+                       d[0]=DISPLAY_DATA; // dummy read (p.16)
                        d[0]=DISPLAY_DATA;
                        d[1]=DISPLAY_DATA;
+                       row=DISPLAY_DATA; // aligne
                        for(row=y;row<rmax;row++) {
                                // contribution of b: (255-alpha)*b
                                b=display_m2i(d,row);
@@ -146,17 +142,82 @@ void display_draw_rectangle(u8 x,u8 y,u8 w,u8 h,u8 fill,u8 alpha) {
                                d[1]|=(c&1)<<row;
                        }
                        DISPLAY_SET_COL_ADDR(col);
-                       DISPLAY_DATA=b[0];
-                       DISPLAY_DATA=b[1];
+                       DISPLAY_DATA=d[0];
+                       DISPLAY_DATA=d[1];
                }
                h-=(rmax-y);
                y=rmax;
        }
 }
 
+void display_rectangle_page(u8 x,u8 p,u8 w,u8 h,u8 fill,u8 alpha) {
+
+       u8 page,col,row;
+       u8 buf[2];
+       u8 b,c;
+
+       for(page=p;page<p+h;page++) {
+               DISPLAY_SET_PAGE_ADDR(page);
+               for(col=x;col<x+w;col++) {
+                       DISPLAY_SET_COL_ADDR(col);
+                       buf[0]=DISPLAY_DATA; // dummy read
+                       buf[0]=DISPLAY_DATA;
+                       buf[1]=DISPLAY_DATA;
+                       row=DISPLAY_DATA; // aligne dummy read
+                       for(row=0;row<8;row++) {
+                               b=display_m2i(buf,row);
+                               c=(b*(255-alpha)+fill*255)>>8;
+                               buf[0]&=~(1<<row);
+                               buf[1]&=~(1<<row);
+                               if(c&2)
+                                       buf[0]|=(1<<row);
+                               if(c&1)
+                                       buf[1]|=(1<<row);
+                       }
+                       DISPLAY_SET_COL_ADDR(col);
+                       DISPLAY_DATA=buf[0];
+                       DISPLAY_DATA=buf[1];
+               }
+       }
+}
+
+void display_font_page(u8 x,u8 page,u8 *font,u8 fill) {
+
+       /* this only draws page aligned fonts! */
+       u8 cnt,row;
+       u8 c[16];
+
+       /* set the page */
+       DISPLAY_SET_PAGE_ADDR(page);
+
+       /* read old content */
+       DISPLAY_SET_COL_ADDR(x);
+       c[0]=DISPLAY_DATA; // dummy read
+       for(cnt=0;cnt<16;cnt++) {
+               c[cnt++]=DISPLAY_DATA;
+               c[cnt]=DISPLAY_DATA;
+       }
+       cnt=DISPLAY_DATA; // 2 byte aligne dummy read
+
+       /* write new content */
+       DISPLAY_SET_COL_ADDR(x);
+       for(cnt=0;cnt<16;cnt++) {
+               for(row=0;row<8;row++) {
+                       if((font[cnt>>1]>>row)&1) {
+                               c[cnt]&=~(1<<row);
+                               c[cnt+1]&=~(1<<row);
+                               c[cnt]|=(((fill>>1)&1)<<row);
+                               c[cnt+1]|=((fill&1)<<row);
+                       }
+               }
+               DISPLAY_DATA=c[cnt++];
+               DISPLAY_DATA=c[cnt];
+       }
+}
+
 void display_draw_font(u8 x,u8 y,u8 *font,u8 fill,u8 alpha) {
 
-       u8 page,col,row,rmax,cnt,left;
+       u8 page,col,row,rmax,cnt,left,cf,rf;
        u8 d[2];
        int ca,cb;
        u8 a,b,c;                       // c = a over b
@@ -197,8 +258,8 @@ void display_draw_font(u8 x,u8 y,u8 *font,u8 fill,u8 alpha) {
                                rf+=1;
                        }
                        DISPLAY_SET_COL_ADDR(col);
-                       DISPLAY_DATA=b[0];
-                       DISPLAY_DATA=b[1];
+                       DISPLAY_DATA=d[0];
+                       DISPLAY_DATA=d[1];
                        cf+=1;
                }
                left-=(rmax-y);
@@ -206,26 +267,6 @@ void display_draw_font(u8 x,u8 y,u8 *font,u8 fill,u8 alpha) {
        }
 }
 
-void display_draw_buf(u8 x,u8 y,u8 w,u8 h,u8 *buf,u8 alpha) {
-
-       u8 page,col,row,rmax,cnt;
-       u8 d[2];
-       int ca,cb;
-       u8 a,b,c;
-
-       for(page=(y>>3);page<=((y+h)>>3);page++) {
-               DISPLAY_SET_PAGE_ADDR(page);
-               for(col=x;col<x+w;col++) {
-                       DISPLAY_SET_COL_ADDR(col);
-                       d[0]=DISPLAY_DATA;
-                       d[0]=DISPLAY_DATA;
-                       d[1]=DISPLAY_DATA;
-                       for(row=y;row<rmax;row++) {
-                       }
-               }
-       }
-}
-
 void display_bl_init(void) {
 
        IODIR0|=(1<<4);
index b10835a0fa560ef9d3ec75103cb7daf6900b2554..a4919c56c3e76fcea0fcf729445b23dfac749962 100644 (file)
 void display_fill_screen(u8 fill);
 void display_clear_screen(void);
 void display_init(void);
-void display_load_logo(u8 *src);
-void display_draw_rectangle(int x,int y,int w,int h,u8 fill,u8 alpha);
+void display_logo(u8 *src);
+void display_rectangle_page(u8 x,u8 p,u8 w,u8 h,u8 fill,u8 alpha);
+void display_draw_rectangle(u8 x,u8 y,u8 w,u8 h,u8 fill,u8 alpha);
+void display_font_page(u8 x,u8 page,u8 *font,u8 fill);
+void display_draw_font(u8 x,u8 y,u8 *font,u8 fill,u8 alpha);
 void display_bl_init(void);
 void display_bl_toggle(void);
 void display_bl_on(void);