summaryrefslogtreecommitdiff
path: root/uisimulator/x11/lcd-x11.c
blob: bbec13fc75e2cc497f526afa23fd51db6a2b8698 (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
/***************************************************************************
 *             __________               __   ___.                  
 *   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"

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

#include "lcd-x11.h"

extern unsigned char display[LCD_WIDTH][LCD_HEIGHT/8];
extern void screen_resized(int width, int height);
extern Display *dpy;

unsigned char display_copy[LCD_WIDTH][LCD_HEIGHT/8];

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

#if 0
    screen_resized(LCD_WIDTH, LCD_HEIGHT);

    for(y=0; y<LCD_HEIGHT; y+=8) {
        for(x=0; x<LCD_WIDTH; x++) {
            if(display[x][y/8]) {
                /* one or more bits/pixels are set */
                for(bit=0; bit<8; bit++) {
                    if(display[x][y/8]&(1<<bit)) {
                        points[p].x = x + MARGIN_X;
                        points[p].y = y+bit + MARGIN_Y;
                        p++; /* increase the point counter */
                    }
                }
            }
        }
    }
#else
    for(y=0; y<LCD_HEIGHT; y+=8) {
        for(x=0; x<LCD_WIDTH; x++) {
            if(display[x][y/8] || display_copy[x][y/8]) {
                /* one or more bits/pixels are changed */
                unsigned char diff =
                  display[x][y/8] ^ display_copy[x][y/8];

                for(bit=0; bit<8; bit++) {
                    if(display[x][y/8]&(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(display_copy, display, sizeof(display));

#endif

    drawdots(0, &clearpoints[0], cp);
    drawdots(1, &points[0], p);
/*    Logf("lcd_update: Draws %d pixels, clears %d pixels", p, cp);*/
    XSync(dpy,False);
}

#ifdef HAVE_LCD_CHARCELLS
/* simulation layer for charcells */
void lcd_clear_display(void)
{
    sim_lcd_clear_display();
}

void lcd_puts(int x, int y, char *string)
{
    char buffer[12];
    strncpy(buffer, string, 11);
    buffer[11]=0;

    sim_lcd_puts(x, y, buffer, 0);
    lcd_update();
}
#endif