summaryrefslogtreecommitdiffstats
path: root/uisimulator/x11/lcd-x11.c
blob: 1ee15f9169d0c1984cd3361a1801c3d990f1d107 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
/***************************************************************************
 *             __________               __   ___.                  
 *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___  
 *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /  
 *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <   
 *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \  
 *                     \/            \/     \/    \/            \/ 
 * $Id$
 *
 * Copyright (C) 2002 by Daniel Stenberg <daniel@haxx.se>
 *
 * All files in this archive are subject to the GNU General Public License.
 * See the file COPYING in the source tree root for full license agreement.
 *
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
 * KIND, either express or implied.
 *
 ****************************************************************************/

#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <stdlib.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

#include <errno.h>
#include <ctype.h>
#include <time.h>

#include "screenhack.h"
#include "config.h"

/*
 * Specific implementations for X11, using the generic LCD API and data.
 */

#include "lcd-x11.h"
#include "lcd-playersim.h"

extern unsigned char lcd_framebuffer[LCD_HEIGHT/8][LCD_WIDTH];
extern void screen_resized(int width, int height);

#ifdef HAVE_LCD_BITMAP
unsigned char lcd_framebuffer_copy[LCD_HEIGHT/8][LCD_WIDTH];

void lcd_update (void)
{
    int x, y;
    int p=0;
    int bit;
    struct coordinate points[LCD_WIDTH * LCD_HEIGHT];
    int cp=0;
    struct coordinate clearpoints[LCD_WIDTH * LCD_HEIGHT];

    for(y=0; y<LCD_HEIGHT; y+=8) {
        for(x=0; x<LCD_WIDTH; x++) {
            if(lcd_framebuffer[y/8][x] || lcd_framebuffer_copy[y/8][x]) {
                /* one or more bits/pixels are changed */
                unsigned char diff =
                    lcd_framebuffer[y/8][x] ^ lcd_framebuffer_copy[y/8][x];

                for(bit=0; bit<8; bit++) {
                    if(lcd_framebuffer[y/8][x]&(1<<bit)) {
                        /* set a dot */
                        points[p].x = x + MARGIN_X;
                        points[p].y = y+bit + MARGIN_Y;
                        p++; /* increase the point counter */
                    }
                    else if(diff &(1<<bit)) {
                        /* clear a dot */
                        clearpoints[cp].x = x + MARGIN_X;
                        clearpoints[cp].y = y+bit + MARGIN_Y;
                        cp++; /* increase the point counter */
                    }
                }
            }
        }
    }

    /* copy a huge block */
    memcpy(lcd_framebuffer_copy, lcd_framebuffer, sizeof(lcd_framebuffer));

    drawdots(0, &clearpoints[0], cp);
    drawdots(1, &points[0], p);
    /* printf("lcd_update: Draws %d pixels, clears %d pixels (max %d/%d)\n",
       p, cp, p+cp, LCD_HEIGHT*LCD_WIDTH); */
    XtAppLock(app);
    XSync(dpy,False);
    XtAppUnlock(app);
}

void lcd_update_rect(int x_start, int y_start,
                     int width, int height)
{
    int x;
    int yline=y_start;
    int y;
    int p=0;
    int bit;
    int cp=0;
    int xmax;
    int ymax;
    struct coordinate points[LCD_WIDTH * LCD_HEIGHT];
    struct coordinate clearpoints[LCD_WIDTH * LCD_HEIGHT];

#if 0
    fprintf(stderr, "%04d: lcd_update_rect(%d, %d, %d, %d)\n",
            counter++, x_start, y_start, width, height);
#endif
    /* The Y coordinates have to work on even 8 pixel rows */
    ymax = (yline + height)/8;
    yline /= 8;

    xmax = x_start + width;

    if(xmax > LCD_WIDTH)
        xmax = LCD_WIDTH;
    if(ymax >= LCD_HEIGHT/8)
        ymax = LCD_HEIGHT/8-1;

    for(; yline<=ymax; yline++) {
        y = yline * 8;
        for(x=x_start; x<xmax; x++) {
            if(lcd_framebuffer[yline][x] || lcd_framebuffer_copy[yline][x]) {
                /* one or more bits/pixels are changed */
                unsigned char diff =
                  lcd_framebuffer[yline][x] ^ lcd_framebuffer_copy[yline][x];

                for(bit=0; bit<8; bit++) {
                    if(lcd_framebuffer[yline][x]&(1<<bit)) {
                        /* set a dot */
                        points[p].x = x + MARGIN_X;
                        points[p].y = y+bit + MARGIN_Y;
                        p++; /* increase the point counter */
                    }
                    else if(diff &(1<<bit)) {
                        /* clear a dot */
                        clearpoints[cp].x = x + MARGIN_X;
                        clearpoints[cp].y = y+bit + MARGIN_Y;
                        cp++; /* increase the point counter */
                    }
                }

                /* update the copy */
                lcd_framebuffer_copy[yline][x] = lcd_framebuffer[yline][x];
            }
        }
    }

    drawdots(0, &clearpoints[0], cp);
    drawdots(1, &points[0], p);
    /* printf("lcd_update_rect: Draws %d pixels, clears %d pixels\n", p, cp);*/
    XtAppLock(app);
    XSync(dpy,False);
    XtAppUnlock(app);
}

#ifdef LCD_REMOTE_HEIGHT
extern unsigned char lcd_remote_framebuffer[LCD_REMOTE_HEIGHT/8][LCD_REMOTE_WIDTH];
unsigned char lcd_remote_framebuffer_copy[LCD_REMOTE_HEIGHT/8][LCD_REMOTE_WIDTH];

#define REMOTE_MARGIN_X 2
#define REMOTE_MARGIN_Y (LCD_HEIGHT + 2 + MARGIN_Y)

void lcd_remote_update (void)
{
    int x, y;
    int p=0;
    int bit;
    struct coordinate points[LCD_REMOTE_WIDTH * LCD_REMOTE_HEIGHT];
    int cp=0;
    struct coordinate clearpoints[LCD_REMOTE_WIDTH * LCD_REMOTE_HEIGHT];

    for(y=0; y<LCD_REMOTE_HEIGHT; y+=8) {
        for(x=0; x<LCD_REMOTE_WIDTH; x++) {
            if(lcd_remote_framebuffer[y/8][x] ||
               lcd_remote_framebuffer_copy[y/8][x]) {
                /* one or more bits/pixels are changed */
                unsigned char diff =
                    lcd_remote_framebuffer[y/8][x] ^
                    lcd_remote_framebuffer_copy[y/8][x];

                for(bit=0; bit<8; bit++) {
                    if(lcd_remote_framebuffer[y/8][x]&(1<<bit)) {
                        /* set a dot */
                        points[p].x = x + REMOTE_MARGIN_X;
                        points[p].y = y+bit + REMOTE_MARGIN_Y;
                        p++; /* increase the point counter */
                    }
                    else if(diff &(1<<bit)) {
                        /* clear a dot */
                        clearpoints[cp].x = x + REMOTE_MARGIN_X;
                        clearpoints[cp].y = y+bit + REMOTE_MARGIN_Y;
                        cp++; /* increase the point counter */
                    }
                }
            }
        }
    }

    /* copy a huge block */
    memcpy(lcd_remote_framebuffer_copy, lcd_remote_framebuffer,
           sizeof(lcd_remote_framebuffer));

    drawdots(0, &clearpoints[0], cp);
    drawdots(1, &points[0], p);
    /* printf("lcd_update: Draws %d pixels, clears %d pixels (max %d/%d)\n",
       p, cp, p+cp, LCD_HEIGHT*LCD_WIDTH); */
    XtAppLock(app);
    XSync(dpy,False);
    XtAppUnlock(app);
}

void lcd_remote_update_rect(int x_start, int y_start,
                            int width, int height)
{
    int x;
    int yline=y_start;
    int y;
    int p=0;
    int bit;
    int cp=0;
    int xmax;
    int ymax;
    struct coordinate points[LCD_WIDTH * LCD_HEIGHT];
    struct coordinate clearpoints[LCD_WIDTH * LCD_HEIGHT];

#if 0
    fprintf(stderr, "%04d: lcd_update_rect(%d, %d, %d, %d)\n",
            counter++, x_start, y_start, width, height);
#endif
    /* The Y coordinates have to work on even 8 pixel rows */
    ymax = (yline + height)/8;
    yline /= 8;

    xmax = x_start + width;

    if(xmax > LCD_REMOTE_WIDTH)
        xmax = LCD_REMOTE_WIDTH;
    if(ymax >= LCD_REMOTE_HEIGHT/8)
        ymax = LCD_REMOTE_HEIGHT/8-1;

    for(; yline<=ymax; yline++) {
        y = yline * 8;
        for(x=x_start; x<xmax; x++) {
            if(lcd_remote_framebuffer[yline][x] ||
               lcd_remote_framebuffer_copy[yline][x]) {
                /* one or more bits/pixels are changed */
                unsigned char diff =
                  lcd_remote_framebuffer[yline][x] ^
                    lcd_remote_framebuffer_copy[yline][x];

                for(bit=0; bit<8; bit++) {
                    if(lcd_remote_framebuffer[yline][x]&(1<<bit)) {
                        /* set a dot */
                        points[p].x = x + REMOTE_MARGIN_X;
                        points[p].y = y+bit + REMOTE_MARGIN_Y;
                        p++; /* increase the point counter */
                    }
                    else if(diff &(1<<bit)) {
                        /* clear a dot */
                        clearpoints[cp].x = x + REMOTE_MARGIN_X;
                        clearpoints[cp].y = y+bit + REMOTE_MARGIN_Y;
                        cp++; /* increase the point counter */
                    }
                }

                /* update the copy */
                lcd_remote_framebuffer_copy[yline][x] =
                    lcd_remote_framebuffer[yline][x];
            }
        }
    }

    drawdots(0, &clearpoints[0], cp);
    drawdots(1, &points[0], p);
    /* printf("lcd_update_rect: Draws %d pixels, clears %d pixels\n", p, cp);*/
    XtAppLock(app);
    XSync(dpy,False);
    XtAppUnlock(app);
}


#endif

#endif
#ifdef HAVE_LCD_CHARCELLS

/* Defined in lcd-playersim.c */
extern void lcd_print_char(int x, int y);
extern unsigned char lcd_buffer[2][11];
extern void drawrect(int color, int x1, int y1, int x2, int y2);
extern bool lcd_display_redraw;

extern unsigned char hardware_buffer_lcd[11][2];
static unsigned char lcd_buffer_copy[11][2];

void lcd_update (void)
{
    bool changed=false;
    int x, y;
    for (y=0; y<2; y++) {
        for (x=0; x<11; x++) {
            if (lcd_display_redraw ||
                lcd_buffer_copy[x][y] != hardware_buffer_lcd[x][y]) {
                lcd_buffer_copy[x][y] = hardware_buffer_lcd[x][y];
                lcd_print_char(x, y);
                changed=true;
            }
        }
    }
    if (changed)
    {
        XtAppLock(app);
        XSync(dpy,False);
        XtAppUnlock(app);
    }
    lcd_display_redraw=false;
}

#endif