summaryrefslogtreecommitdiff
path: root/uisimulator/x11/lcd-x11.c
diff options
context:
space:
mode:
Diffstat (limited to 'uisimulator/x11/lcd-x11.c')
-rw-r--r--uisimulator/x11/lcd-x11.c145
1 files changed, 31 insertions, 114 deletions
diff --git a/uisimulator/x11/lcd-x11.c b/uisimulator/x11/lcd-x11.c
index d538cee9df..3ad5a79ec7 100644
--- a/uisimulator/x11/lcd-x11.c
+++ b/uisimulator/x11/lcd-x11.c
@@ -43,9 +43,11 @@
43#if LCD_DEPTH == 2 43#if LCD_DEPTH == 2
44#define YBLOCK 4 44#define YBLOCK 4
45#define BITOFFS 1 /* take the MSB of each pixel */ 45#define BITOFFS 1 /* take the MSB of each pixel */
46#define ANDBIT 3 /* AND with this to get the color number */
46#else 47#else
47#define YBLOCK 8 48#define YBLOCK 8
48#define BITOFFS 0 49#define BITOFFS 0
50#define ANDBIT 1
49#endif 51#endif
50 52
51extern void screen_resized(int width, int height); 53extern void screen_resized(int width, int height);
@@ -56,48 +58,8 @@ unsigned char lcd_framebuffer_copy[LCD_HEIGHT/YBLOCK][LCD_WIDTH];
56 58
57void lcd_update (void) 59void lcd_update (void)
58{ 60{
59 int x, y; 61 /* update a full screen rect */
60 int p=0; 62 lcd_update_rect(0, 0, LCD_WIDTH, LCD_HEIGHT);
61 int bit;
62 struct coordinate points[LCD_WIDTH * LCD_HEIGHT];
63 int cp=0;
64 struct coordinate clearpoints[LCD_WIDTH * LCD_HEIGHT];
65
66 for(y=0; y<LCD_HEIGHT; y+=YBLOCK) {
67 for(x=0; x<LCD_WIDTH; x++) {
68 if(lcd_framebuffer[y/YBLOCK][x] || lcd_framebuffer_copy[y/YBLOCK][x]) {
69 /* one or more bits/pixels are changed */
70 unsigned char diff =
71 lcd_framebuffer[y/YBLOCK][x] ^ lcd_framebuffer_copy[y/YBLOCK][x];
72
73 for(bit=0; bit<YBLOCK; bit++) {
74 if(lcd_framebuffer[y/YBLOCK][x]&(1<<(bit*LCD_DEPTH+BITOFFS))) {
75 /* set a dot */
76 points[p].x = x + MARGIN_X;
77 points[p].y = y+bit + MARGIN_Y;
78 p++; /* increase the point counter */
79 }
80 else if(diff &(1<<(bit*LCD_DEPTH+BITOFFS))) {
81 /* clear a dot */
82 clearpoints[cp].x = x + MARGIN_X;
83 clearpoints[cp].y = y+bit + MARGIN_Y;
84 cp++; /* increase the point counter */
85 }
86 }
87 }
88 }
89 }
90
91 /* copy a huge block */
92 memcpy(lcd_framebuffer_copy, lcd_framebuffer, sizeof(lcd_framebuffer));
93
94 drawdots(0, &clearpoints[0], cp);
95 drawdots(1, &points[0], p);
96 /* printf("lcd_update: Draws %d pixels, clears %d pixels (max %d/%d)\n",
97 p, cp, p+cp, LCD_HEIGHT*LCD_WIDTH); */
98 XtAppLock(app);
99 XSync(dpy,False);
100 XtAppUnlock(app);
101} 63}
102 64
103void lcd_update_rect(int x_start, int y_start, 65void lcd_update_rect(int x_start, int y_start,
@@ -108,11 +70,10 @@ void lcd_update_rect(int x_start, int y_start,
108 int y; 70 int y;
109 int p=0; 71 int p=0;
110 int bit; 72 int bit;
111 int cp=0;
112 int xmax; 73 int xmax;
113 int ymax; 74 int ymax;
75 int colors[LCD_WIDTH * LCD_HEIGHT];
114 struct coordinate points[LCD_WIDTH * LCD_HEIGHT]; 76 struct coordinate points[LCD_WIDTH * LCD_HEIGHT];
115 struct coordinate clearpoints[LCD_WIDTH * LCD_HEIGHT];
116 77
117#if 0 78#if 0
118 fprintf(stderr, "%04d: lcd_update_rect(%d, %d, %d, %d)\n", 79 fprintf(stderr, "%04d: lcd_update_rect(%d, %d, %d, %d)\n",
@@ -132,24 +93,25 @@ void lcd_update_rect(int x_start, int y_start,
132 for(; yline<=ymax; yline++) { 93 for(; yline<=ymax; yline++) {
133 y = yline * YBLOCK; 94 y = yline * YBLOCK;
134 for(x=x_start; x<xmax; x++) { 95 for(x=x_start; x<xmax; x++) {
135 if(lcd_framebuffer[yline][x] || lcd_framebuffer_copy[yline][x]) { 96 if(lcd_framebuffer[yline][x] != lcd_framebuffer_copy[yline][x]) {
136 /* one or more bits/pixels are changed */ 97 /* one or more bits/pixels are changed */
137 unsigned char diff =
138 lcd_framebuffer[yline][x] ^ lcd_framebuffer_copy[yline][x];
139 98
140 for(bit=0; bit<YBLOCK; bit++) { 99 for(bit=0; bit<YBLOCK; bit++) {
141 if(lcd_framebuffer[yline][x]&(1<<(bit*LCD_DEPTH+BITOFFS))) { 100 unsigned int col;
142 /* set a dot */ 101 col = lcd_framebuffer[yline][x]&(ANDBIT<<(bit*LCD_DEPTH));
143 points[p].x = x + MARGIN_X; 102
144 points[p].y = y+bit + MARGIN_Y; 103#if LCD_DEPTH == 2
145 p++; /* increase the point counter */ 104 /* shift down the value to the lower bits */
146 } 105 col >>= (bit * LCD_DEPTH);
147 else if(diff &(1<<(bit*LCD_DEPTH+BITOFFS))) { 106
148 /* clear a dot */ 107 /* set a dot */
149 clearpoints[cp].x = x + MARGIN_X; 108 colors[p] = col;
150 clearpoints[cp].y = y+bit + MARGIN_Y; 109#else
151 cp++; /* increase the point counter */ 110 colors[p] = col?3:0;
152 } 111#endif
112 points[p].x = x + MARGIN_X;
113 points[p].y = y+bit + MARGIN_Y;
114 p++; /* increase the point counter */
153 } 115 }
154 116
155 /* update the copy */ 117 /* update the copy */
@@ -158,8 +120,7 @@ void lcd_update_rect(int x_start, int y_start,
158 } 120 }
159 } 121 }
160 122
161 drawdots(0, &clearpoints[0], cp); 123 dots(colors, &points[0], p);
162 drawdots(1, &points[0], p);
163 /* printf("lcd_update_rect: Draws %d pixels, clears %d pixels\n", p, cp);*/ 124 /* printf("lcd_update_rect: Draws %d pixels, clears %d pixels\n", p, cp);*/
164 XtAppLock(app); 125 XtAppLock(app);
165 XSync(dpy,False); 126 XSync(dpy,False);
@@ -175,51 +136,7 @@ unsigned char lcd_remote_framebuffer_copy[LCD_REMOTE_HEIGHT/8][LCD_REMOTE_WIDTH]
175 136
176void lcd_remote_update (void) 137void lcd_remote_update (void)
177{ 138{
178 int x, y; 139 lcd_remote_update_rect(0, 0, LCD_REMOTE_WIDTH, LCD_REMOTE_HEIGHT);
179 int p=0;
180 int bit;
181 struct coordinate points[LCD_REMOTE_WIDTH * LCD_REMOTE_HEIGHT];
182 int cp=0;
183 struct coordinate clearpoints[LCD_REMOTE_WIDTH * LCD_REMOTE_HEIGHT];
184
185 for(y=0; y<LCD_REMOTE_HEIGHT; y+=8) {
186 for(x=0; x<LCD_REMOTE_WIDTH; x++) {
187 if(lcd_remote_framebuffer[y/8][x] ||
188 lcd_remote_framebuffer_copy[y/8][x]) {
189 /* one or more bits/pixels are changed */
190 unsigned char diff =
191 lcd_remote_framebuffer[y/8][x] ^
192 lcd_remote_framebuffer_copy[y/8][x];
193
194 for(bit=0; bit<8; bit++) {
195 if(lcd_remote_framebuffer[y/8][x]&(1<<bit)) {
196 /* set a dot */
197 points[p].x = x + REMOTE_MARGIN_X;
198 points[p].y = y+bit + REMOTE_MARGIN_Y;
199 p++; /* increase the point counter */
200 }
201 else if(diff &(1<<bit)) {
202 /* clear a dot */
203 clearpoints[cp].x = x + REMOTE_MARGIN_X;
204 clearpoints[cp].y = y+bit + REMOTE_MARGIN_Y;
205 cp++; /* increase the point counter */
206 }
207 }
208 }
209 }
210 }
211
212 /* copy a huge block */
213 memcpy(lcd_remote_framebuffer_copy, lcd_remote_framebuffer,
214 sizeof(lcd_remote_framebuffer));
215
216 drawdots(0, &clearpoints[0], cp);
217 drawdots(1, &points[0], p);
218 /* printf("lcd_update: Draws %d pixels, clears %d pixels (max %d/%d)\n",
219 p, cp, p+cp, LCD_HEIGHT*LCD_WIDTH); */
220 XtAppLock(app);
221 XSync(dpy,False);
222 XtAppUnlock(app);
223} 140}
224 141
225void lcd_remote_update_rect(int x_start, int y_start, 142void lcd_remote_update_rect(int x_start, int y_start,
@@ -230,11 +147,10 @@ void lcd_remote_update_rect(int x_start, int y_start,
230 int y; 147 int y;
231 int p=0; 148 int p=0;
232 int bit; 149 int bit;
233 int cp=0;
234 int xmax; 150 int xmax;
235 int ymax; 151 int ymax;
236 struct coordinate points[LCD_WIDTH * LCD_HEIGHT]; 152 struct coordinate points[LCD_WIDTH * LCD_HEIGHT];
237 struct coordinate clearpoints[LCD_WIDTH * LCD_HEIGHT]; 153 int colors[LCD_WIDTH * LCD_HEIGHT];
238 154
239#if 0 155#if 0
240 fprintf(stderr, "%04d: lcd_update_rect(%d, %d, %d, %d)\n", 156 fprintf(stderr, "%04d: lcd_update_rect(%d, %d, %d, %d)\n",
@@ -264,18 +180,20 @@ void lcd_remote_update_rect(int x_start, int y_start,
264 for(bit=0; bit<8; bit++) { 180 for(bit=0; bit<8; bit++) {
265 if(lcd_remote_framebuffer[yline][x]&(1<<bit)) { 181 if(lcd_remote_framebuffer[yline][x]&(1<<bit)) {
266 /* set a dot */ 182 /* set a dot */
183 colors[p]=3;
267 points[p].x = x + REMOTE_MARGIN_X; 184 points[p].x = x + REMOTE_MARGIN_X;
268 points[p].y = y+bit + REMOTE_MARGIN_Y; 185 points[p].y = y+bit + REMOTE_MARGIN_Y;
269 p++; /* increase the point counter */ 186 p++; /* increase the point counter */
270 } 187 }
271 else if(diff &(1<<bit)) { 188 else if(diff &(1<<bit)) {
272 /* clear a dot */ 189 /* clear a dot */
273 clearpoints[cp].x = x + REMOTE_MARGIN_X; 190 colors[p]=0;
274 clearpoints[cp].y = y+bit + REMOTE_MARGIN_Y; 191 points[p].x = x + REMOTE_MARGIN_X;
275 cp++; /* increase the point counter */ 192 points[p].y = y+bit + REMOTE_MARGIN_Y;
193 p++; /* increase the point counter */
276 } 194 }
277 } 195 }
278 196
279 /* update the copy */ 197 /* update the copy */
280 lcd_remote_framebuffer_copy[yline][x] = 198 lcd_remote_framebuffer_copy[yline][x] =
281 lcd_remote_framebuffer[yline][x]; 199 lcd_remote_framebuffer[yline][x];
@@ -283,8 +201,7 @@ void lcd_remote_update_rect(int x_start, int y_start,
283 } 201 }
284 } 202 }
285 203
286 drawdots(0, &clearpoints[0], cp); 204 dots(colors, &points[0], p);
287 drawdots(1, &points[0], p);
288 /* printf("lcd_update_rect: Draws %d pixels, clears %d pixels\n", p, cp);*/ 205 /* printf("lcd_update_rect: Draws %d pixels, clears %d pixels\n", p, cp);*/
289 XtAppLock(app); 206 XtAppLock(app);
290 XSync(dpy,False); 207 XSync(dpy,False);