Daniel Stenberg | d20e6ee | 2002-03-26 10:06:28 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
| 8 | * $Id$ |
| 9 | * |
| 10 | * Copyright (C) 2002 by Daniel Stenberg <daniel@haxx.se> |
| 11 | * |
| 12 | * All files in this archive are subject to the GNU General Public License. |
| 13 | * See the file COPYING in the source tree root for full license agreement. |
| 14 | * |
| 15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 16 | * KIND, either express or implied. |
| 17 | * |
| 18 | ****************************************************************************/ |
| 19 | |
Daniel Stenberg | 319d1f3 | 2002-03-26 10:59:39 +0000 | [diff] [blame] | 20 | #include <stdio.h> |
| 21 | #include <string.h> |
| 22 | #include <stdarg.h> |
| 23 | #include <stdlib.h> |
| 24 | #include <ctype.h> |
| 25 | #include <sys/types.h> |
| 26 | #include <sys/stat.h> |
| 27 | #include <fcntl.h> |
| 28 | |
| 29 | #include <errno.h> |
| 30 | #include <ctype.h> |
| 31 | #include <time.h> |
| 32 | |
| 33 | #include "screenhack.h" |
Björn Stenberg | 8b69504 | 2004-09-16 14:36:08 +0000 | [diff] [blame] | 34 | #include "config.h" |
Daniel Stenberg | 319d1f3 | 2002-03-26 10:59:39 +0000 | [diff] [blame] | 35 | |
Daniel Stenberg | d20e6ee | 2002-03-26 10:06:28 +0000 | [diff] [blame] | 36 | /* |
Daniel Stenberg | 319d1f3 | 2002-03-26 10:59:39 +0000 | [diff] [blame] | 37 | * Specific implementations for X11, using the generic LCD API and data. |
Daniel Stenberg | d20e6ee | 2002-03-26 10:06:28 +0000 | [diff] [blame] | 38 | */ |
| 39 | |
Daniel Stenberg | a1fd255 | 2002-03-26 14:27:03 +0000 | [diff] [blame] | 40 | #include "lcd-x11.h" |
Kjell Ericson | f7a4b2b | 2002-10-28 20:08:40 +0000 | [diff] [blame] | 41 | #include "lcd-playersim.h" |
Daniel Stenberg | 319d1f3 | 2002-03-26 10:59:39 +0000 | [diff] [blame] | 42 | |
Jens Arnold | f894a4c | 2005-07-06 22:58:02 +0000 | [diff] [blame] | 43 | #if LCD_DEPTH == 2 |
| 44 | #define YBLOCK 4 |
Daniel Stenberg | 9872813 | 2005-07-14 10:02:04 +0000 | [diff] [blame] | 45 | #define ANDBIT 3 /* AND with this to get the color number */ |
Jens Arnold | f894a4c | 2005-07-06 22:58:02 +0000 | [diff] [blame] | 46 | #else |
| 47 | #define YBLOCK 8 |
Daniel Stenberg | 9872813 | 2005-07-14 10:02:04 +0000 | [diff] [blame] | 48 | #define ANDBIT 1 |
Jens Arnold | f894a4c | 2005-07-06 22:58:02 +0000 | [diff] [blame] | 49 | #endif |
| 50 | |
Björn Stenberg | f9429cc | 2002-04-19 12:55:12 +0000 | [diff] [blame] | 51 | extern void screen_resized(int width, int height); |
Jens Arnold | 48be8e6 | 2005-10-23 23:49:46 +0000 | [diff] [blame] | 52 | extern bool lcd_display_redraw; |
Daniel Stenberg | 319d1f3 | 2002-03-26 10:59:39 +0000 | [diff] [blame] | 53 | |
Kjell Ericson | f7a4b2b | 2002-10-28 20:08:40 +0000 | [diff] [blame] | 54 | #ifdef HAVE_LCD_BITMAP |
Dave Chapman | fca0113 | 2005-11-14 02:11:26 +0000 | [diff] [blame] | 55 | #if LCD_DEPTH==16 |
Daniel Stenberg | 95c0032 | 2005-11-17 07:17:03 +0000 | [diff] [blame^] | 56 | fb_data lcd_framebuffer_copy[LCD_HEIGHT][LCD_WIDTH*2]; |
Dave Chapman | fca0113 | 2005-11-14 02:11:26 +0000 | [diff] [blame] | 57 | #else |
Daniel Stenberg | 95c0032 | 2005-11-17 07:17:03 +0000 | [diff] [blame^] | 58 | fb_data lcd_framebuffer_copy[LCD_HEIGHT/YBLOCK][LCD_WIDTH]; |
Dave Chapman | fca0113 | 2005-11-14 02:11:26 +0000 | [diff] [blame] | 59 | #endif |
Daniel Stenberg | c154351 | 2002-04-27 23:41:41 +0000 | [diff] [blame] | 60 | |
Daniel Stenberg | 319d1f3 | 2002-03-26 10:59:39 +0000 | [diff] [blame] | 61 | void lcd_update (void) |
| 62 | { |
Daniel Stenberg | 9872813 | 2005-07-14 10:02:04 +0000 | [diff] [blame] | 63 | /* update a full screen rect */ |
| 64 | lcd_update_rect(0, 0, LCD_WIDTH, LCD_HEIGHT); |
Daniel Stenberg | cd86407 | 2002-09-10 07:07:44 +0000 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | void lcd_update_rect(int x_start, int y_start, |
| 68 | int width, int height) |
| 69 | { |
| 70 | int x; |
| 71 | int yline=y_start; |
| 72 | int y; |
| 73 | int p=0; |
| 74 | int bit; |
Daniel Stenberg | cd86407 | 2002-09-10 07:07:44 +0000 | [diff] [blame] | 75 | int xmax; |
| 76 | int ymax; |
Daniel Stenberg | 9872813 | 2005-07-14 10:02:04 +0000 | [diff] [blame] | 77 | int colors[LCD_WIDTH * LCD_HEIGHT]; |
Kjell Ericson | f7a4b2b | 2002-10-28 20:08:40 +0000 | [diff] [blame] | 78 | struct coordinate points[LCD_WIDTH * LCD_HEIGHT]; |
Jens Arnold | 48be8e6 | 2005-10-23 23:49:46 +0000 | [diff] [blame] | 79 | unsigned force_mask = lcd_display_redraw ? 0xFF : 0; |
Daniel Stenberg | cd86407 | 2002-09-10 07:07:44 +0000 | [diff] [blame] | 80 | |
Daniel Stenberg | 4ccffb6 | 2003-04-23 18:49:24 +0000 | [diff] [blame] | 81 | #if 0 |
Daniel Stenberg | ae26233 | 2003-02-07 09:42:57 +0000 | [diff] [blame] | 82 | fprintf(stderr, "%04d: lcd_update_rect(%d, %d, %d, %d)\n", |
| 83 | counter++, x_start, y_start, width, height); |
Daniel Stenberg | 4ccffb6 | 2003-04-23 18:49:24 +0000 | [diff] [blame] | 84 | #endif |
Jens Arnold | f894a4c | 2005-07-06 22:58:02 +0000 | [diff] [blame] | 85 | /* The Y coordinates have to work on even YBLOCK pixel rows */ |
| 86 | ymax = (yline + height)/YBLOCK; |
| 87 | yline /= YBLOCK; |
Jens Arnold | 74b731e | 2005-03-18 23:51:52 +0000 | [diff] [blame] | 88 | |
Daniel Stenberg | cd86407 | 2002-09-10 07:07:44 +0000 | [diff] [blame] | 89 | xmax = x_start + width; |
| 90 | |
| 91 | if(xmax > LCD_WIDTH) |
| 92 | xmax = LCD_WIDTH; |
Jens Arnold | f894a4c | 2005-07-06 22:58:02 +0000 | [diff] [blame] | 93 | if(ymax >= LCD_HEIGHT/YBLOCK) |
| 94 | ymax = LCD_HEIGHT/YBLOCK-1; |
Daniel Stenberg | cd86407 | 2002-09-10 07:07:44 +0000 | [diff] [blame] | 95 | |
Jens Arnold | 48be8e6 | 2005-10-23 23:49:46 +0000 | [diff] [blame] | 96 | for(; yline <= ymax; yline++) { |
Jens Arnold | f894a4c | 2005-07-06 22:58:02 +0000 | [diff] [blame] | 97 | y = yline * YBLOCK; |
Jens Arnold | 48be8e6 | 2005-10-23 23:49:46 +0000 | [diff] [blame] | 98 | for(x = x_start; x < xmax; x++) { |
| 99 | unsigned char diff = (lcd_framebuffer[yline][x] |
| 100 | ^ lcd_framebuffer_copy[yline][x]) |
| 101 | | force_mask; |
| 102 | if(diff) { |
Daniel Stenberg | cd86407 | 2002-09-10 07:07:44 +0000 | [diff] [blame] | 103 | /* one or more bits/pixels are changed */ |
Jens Arnold | 48be8e6 | 2005-10-23 23:49:46 +0000 | [diff] [blame] | 104 | unsigned char mask = ANDBIT; |
| 105 | for(bit = 0; bit < YBLOCK; bit++) { |
| 106 | if(diff & mask) { |
| 107 | /* pixel has changed */ |
| 108 | unsigned int col = lcd_framebuffer[yline][x] & mask; |
Daniel Stenberg | 9872813 | 2005-07-14 10:02:04 +0000 | [diff] [blame] | 109 | #if LCD_DEPTH == 2 |
Jens Arnold | 48be8e6 | 2005-10-23 23:49:46 +0000 | [diff] [blame] | 110 | colors[p] = col >> (bit * LCD_DEPTH); |
Daniel Stenberg | 9872813 | 2005-07-14 10:02:04 +0000 | [diff] [blame] | 111 | #else |
Jens Arnold | 48be8e6 | 2005-10-23 23:49:46 +0000 | [diff] [blame] | 112 | colors[p] = col ? 3 : 0; |
Daniel Stenberg | 9872813 | 2005-07-14 10:02:04 +0000 | [diff] [blame] | 113 | #endif |
Jens Arnold | 48be8e6 | 2005-10-23 23:49:46 +0000 | [diff] [blame] | 114 | points[p].x = x + MARGIN_X; |
| 115 | points[p].y = y + bit + MARGIN_Y; |
| 116 | p++; /* increase the point counter */ |
| 117 | } |
| 118 | mask <<= LCD_DEPTH; |
Daniel Stenberg | cd86407 | 2002-09-10 07:07:44 +0000 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | /* update the copy */ |
Jörg Hohensohn | 5040cc5 | 2003-12-23 23:41:45 +0000 | [diff] [blame] | 122 | lcd_framebuffer_copy[yline][x] = lcd_framebuffer[yline][x]; |
Daniel Stenberg | cd86407 | 2002-09-10 07:07:44 +0000 | [diff] [blame] | 123 | } |
| 124 | } |
| 125 | } |
Daniel Stenberg | c154351 | 2002-04-27 23:41:41 +0000 | [diff] [blame] | 126 | |
Daniel Stenberg | 9872813 | 2005-07-14 10:02:04 +0000 | [diff] [blame] | 127 | dots(colors, &points[0], p); |
Jens Arnold | 74b731e | 2005-03-18 23:51:52 +0000 | [diff] [blame] | 128 | /* printf("lcd_update_rect: Draws %d pixels, clears %d pixels\n", p, cp);*/ |
| 129 | XtAppLock(app); |
Björn Stenberg | f9429cc | 2002-04-19 12:55:12 +0000 | [diff] [blame] | 130 | XSync(dpy,False); |
Jens Arnold | 74b731e | 2005-03-18 23:51:52 +0000 | [diff] [blame] | 131 | XtAppUnlock(app); |
Jens Arnold | 48be8e6 | 2005-10-23 23:49:46 +0000 | [diff] [blame] | 132 | lcd_display_redraw=false; |
Daniel Stenberg | 319d1f3 | 2002-03-26 10:59:39 +0000 | [diff] [blame] | 133 | } |
Daniel Stenberg | ac31e6a | 2005-05-23 16:23:25 +0000 | [diff] [blame] | 134 | |
| 135 | #ifdef LCD_REMOTE_HEIGHT |
| 136 | extern unsigned char lcd_remote_framebuffer[LCD_REMOTE_HEIGHT/8][LCD_REMOTE_WIDTH]; |
| 137 | unsigned char lcd_remote_framebuffer_copy[LCD_REMOTE_HEIGHT/8][LCD_REMOTE_WIDTH]; |
| 138 | |
Jens Arnold | fc03c8e | 2005-10-23 13:06:25 +0000 | [diff] [blame] | 139 | #define REMOTE_START_Y (LCD_HEIGHT + 2*MARGIN_Y) |
Daniel Stenberg | ac31e6a | 2005-05-23 16:23:25 +0000 | [diff] [blame] | 140 | |
| 141 | void lcd_remote_update (void) |
| 142 | { |
Daniel Stenberg | 9872813 | 2005-07-14 10:02:04 +0000 | [diff] [blame] | 143 | lcd_remote_update_rect(0, 0, LCD_REMOTE_WIDTH, LCD_REMOTE_HEIGHT); |
Daniel Stenberg | ac31e6a | 2005-05-23 16:23:25 +0000 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | void lcd_remote_update_rect(int x_start, int y_start, |
| 147 | int width, int height) |
| 148 | { |
| 149 | int x; |
| 150 | int yline=y_start; |
| 151 | int y; |
| 152 | int p=0; |
| 153 | int bit; |
Daniel Stenberg | ac31e6a | 2005-05-23 16:23:25 +0000 | [diff] [blame] | 154 | int xmax; |
| 155 | int ymax; |
Jens Arnold | 48be8e6 | 2005-10-23 23:49:46 +0000 | [diff] [blame] | 156 | struct coordinate points[LCD_REMOTE_WIDTH * LCD_REMOTE_HEIGHT]; |
| 157 | int colors[LCD_REMOTE_WIDTH * LCD_REMOTE_HEIGHT]; |
| 158 | unsigned force_mask = lcd_display_redraw ? 0xFF : 0; |
Daniel Stenberg | ac31e6a | 2005-05-23 16:23:25 +0000 | [diff] [blame] | 159 | |
| 160 | #if 0 |
| 161 | fprintf(stderr, "%04d: lcd_update_rect(%d, %d, %d, %d)\n", |
| 162 | counter++, x_start, y_start, width, height); |
| 163 | #endif |
| 164 | /* The Y coordinates have to work on even 8 pixel rows */ |
| 165 | ymax = (yline + height)/8; |
| 166 | yline /= 8; |
| 167 | |
| 168 | xmax = x_start + width; |
| 169 | |
| 170 | if(xmax > LCD_REMOTE_WIDTH) |
| 171 | xmax = LCD_REMOTE_WIDTH; |
| 172 | if(ymax >= LCD_REMOTE_HEIGHT/8) |
| 173 | ymax = LCD_REMOTE_HEIGHT/8-1; |
| 174 | |
Jens Arnold | 48be8e6 | 2005-10-23 23:49:46 +0000 | [diff] [blame] | 175 | for(; yline <= ymax; yline++) { |
Daniel Stenberg | ac31e6a | 2005-05-23 16:23:25 +0000 | [diff] [blame] | 176 | y = yline * 8; |
Jens Arnold | 48be8e6 | 2005-10-23 23:49:46 +0000 | [diff] [blame] | 177 | for(x = x_start; x < xmax; x++) { |
| 178 | unsigned char diff = (lcd_remote_framebuffer[yline][x] |
| 179 | ^ lcd_remote_framebuffer_copy[yline][x]) |
| 180 | | force_mask; |
| 181 | if(diff) { |
| 182 | unsigned char mask = 1; |
| 183 | for(bit = 0; bit < 8; bit++) { |
| 184 | if(diff & mask) { |
| 185 | unsigned int col = lcd_remote_framebuffer[yline][x] & mask; |
| 186 | colors[p] = col ? 3 : 0; |
Jens Arnold | fc03c8e | 2005-10-23 13:06:25 +0000 | [diff] [blame] | 187 | points[p].x = x + MARGIN_X; |
Jens Arnold | 48be8e6 | 2005-10-23 23:49:46 +0000 | [diff] [blame] | 188 | points[p].y = y + bit + (REMOTE_START_Y + MARGIN_Y); |
Daniel Stenberg | ac31e6a | 2005-05-23 16:23:25 +0000 | [diff] [blame] | 189 | p++; /* increase the point counter */ |
| 190 | } |
Jens Arnold | 48be8e6 | 2005-10-23 23:49:46 +0000 | [diff] [blame] | 191 | mask <<= 1; |
Daniel Stenberg | ac31e6a | 2005-05-23 16:23:25 +0000 | [diff] [blame] | 192 | } |
Daniel Stenberg | 9872813 | 2005-07-14 10:02:04 +0000 | [diff] [blame] | 193 | |
Daniel Stenberg | ac31e6a | 2005-05-23 16:23:25 +0000 | [diff] [blame] | 194 | /* update the copy */ |
| 195 | lcd_remote_framebuffer_copy[yline][x] = |
| 196 | lcd_remote_framebuffer[yline][x]; |
| 197 | } |
| 198 | } |
| 199 | } |
| 200 | |
Daniel Stenberg | 9872813 | 2005-07-14 10:02:04 +0000 | [diff] [blame] | 201 | dots(colors, &points[0], p); |
Daniel Stenberg | ac31e6a | 2005-05-23 16:23:25 +0000 | [diff] [blame] | 202 | /* printf("lcd_update_rect: Draws %d pixels, clears %d pixels\n", p, cp);*/ |
| 203 | XtAppLock(app); |
| 204 | XSync(dpy,False); |
| 205 | XtAppUnlock(app); |
Jens Arnold | 48be8e6 | 2005-10-23 23:49:46 +0000 | [diff] [blame] | 206 | lcd_display_redraw=false; |
Daniel Stenberg | ac31e6a | 2005-05-23 16:23:25 +0000 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | |
| 210 | #endif |
| 211 | |
Kjell Ericson | f7a4b2b | 2002-10-28 20:08:40 +0000 | [diff] [blame] | 212 | #endif |
| 213 | #ifdef HAVE_LCD_CHARCELLS |
Daniel Stenberg | cd86407 | 2002-09-10 07:07:44 +0000 | [diff] [blame] | 214 | |
Kjell Ericson | f7a4b2b | 2002-10-28 20:08:40 +0000 | [diff] [blame] | 215 | /* Defined in lcd-playersim.c */ |
| 216 | extern void lcd_print_char(int x, int y); |
| 217 | extern unsigned char lcd_buffer[2][11]; |
| 218 | extern void drawrect(int color, int x1, int y1, int x2, int y2); |
Kjell Ericson | f7a4b2b | 2002-10-28 20:08:40 +0000 | [diff] [blame] | 219 | |
Kjell Ericson | 1cb8061 | 2003-01-10 10:03:07 +0000 | [diff] [blame] | 220 | extern unsigned char hardware_buffer_lcd[11][2]; |
| 221 | static unsigned char lcd_buffer_copy[11][2]; |
Kjell Ericson | f7a4b2b | 2002-10-28 20:08:40 +0000 | [diff] [blame] | 222 | |
| 223 | void lcd_update (void) |
| 224 | { |
Jens Arnold | 31b28f5 | 2005-03-18 00:03:22 +0000 | [diff] [blame] | 225 | bool changed=false; |
| 226 | int x, y; |
| 227 | for (y=0; y<2; y++) { |
| 228 | for (x=0; x<11; x++) { |
| 229 | if (lcd_display_redraw || |
| 230 | lcd_buffer_copy[x][y] != hardware_buffer_lcd[x][y]) { |
| 231 | lcd_buffer_copy[x][y] = hardware_buffer_lcd[x][y]; |
| 232 | lcd_print_char(x, y); |
| 233 | changed=true; |
| 234 | } |
| 235 | } |
Kjell Ericson | f7a4b2b | 2002-10-28 20:08:40 +0000 | [diff] [blame] | 236 | } |
Jens Arnold | 31b28f5 | 2005-03-18 00:03:22 +0000 | [diff] [blame] | 237 | if (changed) |
Jens Arnold | 74b731e | 2005-03-18 23:51:52 +0000 | [diff] [blame] | 238 | { |
| 239 | XtAppLock(app); |
Jens Arnold | 31b28f5 | 2005-03-18 00:03:22 +0000 | [diff] [blame] | 240 | XSync(dpy,False); |
Jens Arnold | 74b731e | 2005-03-18 23:51:52 +0000 | [diff] [blame] | 241 | XtAppUnlock(app); |
| 242 | } |
Jens Arnold | 31b28f5 | 2005-03-18 00:03:22 +0000 | [diff] [blame] | 243 | lcd_display_redraw=false; |
Kjell Ericson | f7a4b2b | 2002-10-28 20:08:40 +0000 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | #endif |