summaryrefslogtreecommitdiffstats
path: root/uisimulator/win32/lcd-win32.c
blob: 243e83dd2e97150341b33886b35876447bbc06e9 (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
/***************************************************************************
 *             __________               __   ___.
 *   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"

unsigned char lcd_framebuffer[LCD_HEIGHT/8][LCD_WIDTH]; /* the display */
char bitmap[LCD_HEIGHT][LCD_WIDTH]; /* the ui display */

BITMAPINFO2 bmi =
{
  {sizeof (BITMAPINFOHEADER),
   LCD_WIDTH, -LCD_HEIGHT, 1, 8,
   BI_RGB, 0, 0, 0, 2, 2,
  },
  {
    //{UI_LCD_BGCOLOR, 0}, /* green background color */
    {UI_LCD_BGCOLORLIGHT, 0}, /* green background color */
    {UI_LCD_BLACK, 0}    /* black color */
  }
  
}; /* bitmap information */

#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];
#endif 

void lcd_set_invert_display(bool invert)
{
    (void)invert;
}

/* lcd_update()
   update lcd */
void lcd_update()
{
    int x, y;
    if (hGUIWnd == NULL)
        _endthread ();

#ifdef HAVE_LCD_CHARCELLS
    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);
            }
        }
    }

    lcd_display_redraw = false;
#endif

    for (x = 0; x < LCD_WIDTH; x++)
        for (y = 0; y < LCD_HEIGHT; y++)
            bitmap[y][x] = ((lcd_framebuffer[y/8][x] >> (y & 7)) & 1);

    InvalidateRect (hGUIWnd, NULL, FALSE);

    /* natural sleep :) Bagder: why is this here? */
    //Sleep (50);
}

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

    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++)
            bitmap[y][x] = ((lcd_framebuffer[y/8][x] >> (y & 7)) & 1);

    /* Bagder: If I only knew how, I would make this call only invalidate
       the actual rectangle we want updated here, this NULL thing here will
       make the full rectangle updated! */
    InvalidateRect (hGUIWnd, NULL, FALSE);
}

/* lcd_backlight()
   set backlight state of lcd */
void lcd_backlight (bool on)
{
    if (on)
    {
        RGBQUAD blon = {UI_LCD_BGCOLORLIGHT, 0};
        bmi.bmiColors[0] = blon;
    }
    else
    {
        RGBQUAD blon = {UI_LCD_BGCOLOR, 0};
        bmi.bmiColors[0] = blon;
    }

    InvalidateRect (hGUIWnd, NULL, FALSE);
}

void drawdots(int color, struct coordinate *points, int count)
{
    while (count--)
    {
        if (color)
        {
            DRAW_PIXEL(points[count].x, points[count].y);
        }
        else
        {
            CLEAR_PIXEL(points[count].x, points[count].y);
        }
    }
}

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].width; y++, iy++)
            {
                if (color)
                {
                    DRAW_PIXEL(x, y);
                }
                else
                {
                    CLEAR_PIXEL(x, y);
                }
            }
        }
    }
}