summaryrefslogtreecommitdiffstats
path: root/uisimulator/win32/lcd-win32.c
blob: a50fbd11f6dbb9ad8761c61072a5206d9f3a4647 (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
/***************************************************************************
 *             __________               __   ___.
 *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
 *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
 *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
 *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
 *                     \/            \/     \/    \/            \/
 * $Id$
 *
 * Copyright (C) 2002 by Felix Arends
 *
 * 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 <windows.h>
#include <process.h>
#include "uisw32.h"
#include "lcd.h"
#include "lcd-playersim.h"

#if LCD_DEPTH == 16
unsigned short bitmap[LCD_HEIGHT][LCD_WIDTH]; /* the ui display */

BITMAPINFO256 bmi =
{
  {sizeof (BITMAPINFOHEADER),
   LCD_WIDTH, -LCD_HEIGHT, 1, 16,
   BI_BITFIELDS, 0, 0, 0, 3, 3,
  }, /* bitfield masks (RGB565) */
  {{0x00, 0xf8, 0, 0}, {0xe0, 0x07, 0, 0}, {0x1f, 0x00, 0, 0}}
}; /* bitmap information */
#else
unsigned char bitmap[LCD_HEIGHT][LCD_WIDTH]; /* the ui display */
RGBQUAD color_zero = {UI_LCD_BGCOLORLIGHT, 0};
RGBQUAD color_max  = {0, 0, 0, 0};

BITMAPINFO256 bmi =
{
  {sizeof (BITMAPINFOHEADER),
   LCD_WIDTH, -LCD_HEIGHT, 1, 8,
   BI_RGB, 0, 0, 0, 2, 2,
  },
  {} /* colour lookup table gets filled later */
}; /* bitmap information */
#endif

#ifdef HAVE_LCD_BITMAP

#ifdef HAVE_REMOTE_LCD
unsigned char remote_bitmap[LCD_REMOTE_HEIGHT][LCD_REMOTE_WIDTH];
RGBQUAD remote_color_zero = {UI_REMOTE_BGCOLORLIGHT, 0};
RGBQUAD remote_color_max  = {0, 0, 0, 0};

BITMAPINFO256 remote_bmi =
{
  {sizeof (BITMAPINFOHEADER),
   LCD_REMOTE_WIDTH, -LCD_REMOTE_HEIGHT, 1, 8,
   BI_RGB, 0, 0, 0, 2, 2,
  },
  {} /* colour lookup table gets filled later */
};
#endif

void lcd_update(void)
{
    lcd_update_rect(0, 0, LCD_WIDTH, LCD_HEIGHT);
}

void lcd_update_rect(int x_start, int y_start,
                     int width, int height)
{
    int x, y;
    int xmax, ymax;
    RECT r;

    ymax = y_start + height;
    xmax = x_start + width;
    
    if (hGUIWnd == NULL)
        _endthread ();

    if(xmax > LCD_WIDTH)
        xmax = LCD_WIDTH;
    if(ymax >= LCD_HEIGHT)
        ymax = LCD_HEIGHT;

    for (x = x_start; x < xmax; x++)
        for (y = y_start; y < ymax; y++)
        {
#if LCD_DEPTH == 1
            bitmap[y][x] = ((lcd_framebuffer[y/8][x] >> (y & 7)) & 1);
#elif LCD_DEPTH == 2
#if LCD_PIXELFORMAT == HORIZONTAL_PACKING
            bitmap[y][x] = ((lcd_framebuffer[y][x/4] >> (2 * (x & 3))) & 3);
#else
            bitmap[y][x] = ((lcd_framebuffer[y/4][x] >> (2 * (y & 3))) & 3);
#endif
#elif LCD_DEPTH == 16
#if LCD_PIXELFORMAT == RGB565SWAPPED
            unsigned bits = lcd_framebuffer[y][x];
            bitmap[y][x] = (bits >> 8) | (bits << 8);
#else
            bitmap[y][x] = lcd_framebuffer[y][x];
#endif
#endif
        }

    /* Invalidate only the window part that actually did change */
    GetClientRect (hGUIWnd, &r);
    r.left   = (UI_LCD_POSX + (UI_LCD_WIDTH * x_start / LCD_WIDTH)) 
               * r.right / UI_WIDTH;
    r.top    = (UI_LCD_POSY + (UI_LCD_HEIGHT * y_start / LCD_HEIGHT))
               * r.bottom / UI_HEIGHT;
    r.right  = (UI_LCD_POSX + (UI_LCD_WIDTH * xmax / LCD_WIDTH))
               * r.right / UI_WIDTH;
    r.bottom = (UI_LCD_POSY + (UI_LCD_HEIGHT * ymax / LCD_HEIGHT))
               * r.bottom / UI_HEIGHT;
    InvalidateRect (hGUIWnd, &r, FALSE);
}

#ifdef HAVE_REMOTE_LCD

extern unsigned char lcd_remote_framebuffer[LCD_REMOTE_HEIGHT/8][LCD_REMOTE_WIDTH];

void lcd_remote_update (void)
{
    lcd_remote_update_rect(0, 0, LCD_REMOTE_WIDTH, LCD_REMOTE_HEIGHT);
}

void lcd_remote_update_rect(int x_start, int y_start,
                           int width, int height)
{
    int x, y;
    int xmax, ymax;
    RECT r;

    ymax = y_start + height;
    xmax = x_start + width;
    
    if (hGUIWnd == NULL)
        _endthread ();

    if(xmax > LCD_REMOTE_WIDTH)
        xmax = LCD_REMOTE_WIDTH;
    if(ymax >= LCD_REMOTE_HEIGHT)
        ymax = LCD_REMOTE_HEIGHT;

    for (x = x_start; x < xmax; x++)
        for (y = y_start; y < ymax; y++)
            remote_bitmap[y][x] = ((lcd_remote_framebuffer[y/8][x] >> (y & 7)) & 1);

    /* Invalidate only the window part that actually did change */
    GetClientRect (hGUIWnd, &r);
    r.left   = (UI_REMOTE_POSX + (UI_REMOTE_WIDTH * x_start / LCD_REMOTE_WIDTH))
               * r.right / UI_WIDTH;
    r.top    = (UI_REMOTE_POSY + (UI_REMOTE_HEIGHT * y_start / LCD_REMOTE_HEIGHT))
               * r.bottom / UI_HEIGHT;
    r.right  = (UI_REMOTE_POSX + (UI_REMOTE_WIDTH * xmax / LCD_REMOTE_WIDTH))
               * r.right / UI_WIDTH;
    r.bottom = (UI_REMOTE_POSY + (UI_REMOTE_HEIGHT * ymax / LCD_REMOTE_HEIGHT))
               * r.bottom / UI_HEIGHT;
    InvalidateRect (hGUIWnd, &r, FALSE);
}

#endif /* HAVE_REMOTE_LCD */
#endif /* HAVE_LCD_BITMAP */

#ifdef HAVE_LCD_CHARCELLS
/* Defined in lcd-playersim.c */
extern void lcd_print_char(int x, int y);
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)
{
    int x, y;
    bool changed = false;
    RECT r;

    if (hGUIWnd == NULL)
        _endthread ();

    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)
    {
        /* Invalidate only the window part that actually did change */
        GetClientRect (hGUIWnd, &r);
        r.left = UI_LCD_POSX * r.right / UI_WIDTH;
        r.top = UI_LCD_POSY * r.bottom / UI_HEIGHT;
        r.right = (UI_LCD_POSX + UI_LCD_WIDTH) * r.right / UI_WIDTH;
        r.bottom = (UI_LCD_POSY + UI_LCD_HEIGHT) * r.bottom / UI_HEIGHT;
        InvalidateRect (hGUIWnd, &r, FALSE);
    }
    lcd_display_redraw = false;
}

void drawdots(int color, struct coordinate *points, int count)
{
    while (count--)
    {
        bitmap[points[count].y][points[count].x] = color;
    }
}

void drawrectangles(int color, struct rectangle *points, int count)
{
    while (count--)
    {
        int x;
        int y;
        int ix;
        int iy;

        for (x = points[count].x, ix = 0; ix < points[count].width; x++, ix++)
        {
            for (y = points[count].y, iy = 0; iy < points[count].height; y++, iy++)
            {
                bitmap[y][x] = color;
            }
        }
    }
}
#endif /* HAVE_LCD_CHARCELLS */

#if 0
/* set backlight state of lcd */
void lcd_backlight (bool on)
{
    if (on)
        color_zero = {UI_LCD_BGCOLORLIGHT, 0};
    else
        color_zero = {UI_LCD_BGCOLOR, 0};

    lcdcolors(0, (1<<LCD_DEPTH), &color_zero, &color_max);
    InvalidateRect (hGUIWnd, NULL, FALSE);
}
#endif

#if LCD_DEPTH <= 8
/* set a range of bitmap indices to a gradient from startcolour to endcolour */
void lcdcolors(int index, int count, RGBQUAD *start, RGBQUAD *end)
{
    int i;

    bmi.bmiHeader.biClrUsed = index + count;
    bmi.bmiHeader.biClrImportant = index + count;

    count--;
    for (i = 0; i <= count; i++)
    {
        bmi.bmiColors[i+index].rgbRed = start->rgbRed
                              + (end->rgbRed - start->rgbRed) * i / count;
        bmi.bmiColors[i+index].rgbGreen = start->rgbGreen
                              + (end->rgbGreen - start->rgbGreen) * i / count;
        bmi.bmiColors[i+index].rgbBlue = start->rgbBlue
                              + (end->rgbBlue - start->rgbBlue) * i / count;
    }
}
#endif

#ifdef HAVE_REMOTE_LCD
/* set a range of bitmap indices to a gradient from startcolour to endcolour */
void lcdremotecolors(int index, int count, RGBQUAD *start, RGBQUAD *end)
{
    int i;
    
    remote_bmi.bmiHeader.biClrUsed = index + count;
    remote_bmi.bmiHeader.biClrImportant = index + count;

    count--;
    for (i = 0; i <= count; i++)
    {
        remote_bmi.bmiColors[i+index].rgbRed = start->rgbRed
                              + (end->rgbRed - start->rgbRed) * i / count;
        remote_bmi.bmiColors[i+index].rgbGreen = start->rgbGreen
                              + (end->rgbGreen - start->rgbGreen) * i / count;
        remote_bmi.bmiColors[i+index].rgbBlue = start->rgbBlue
                              + (end->rgbBlue - start->rgbBlue) * i / count;
    }
}
#endif

/* initialise simulator lcd driver */
void simlcdinit(void)
{
#if LCD_DEPTH <= 8
    lcdcolors(0, (1<<LCD_DEPTH), &color_zero, &color_max);
#endif
#ifdef HAVE_REMOTE_LCD
    lcdremotecolors(0, (1<<LCD_REMOTE_DEPTH), &remote_color_zero, &remote_color_max);
#endif
}