summaryrefslogtreecommitdiff
path: root/uisimulator/sdl/lcd-x11.c
diff options
context:
space:
mode:
Diffstat (limited to 'uisimulator/sdl/lcd-x11.c')
-rw-r--r--uisimulator/sdl/lcd-x11.c210
1 files changed, 210 insertions, 0 deletions
diff --git a/uisimulator/sdl/lcd-x11.c b/uisimulator/sdl/lcd-x11.c
new file mode 100644
index 0000000000..3ab5bc0e16
--- /dev/null
+++ b/uisimulator/sdl/lcd-x11.c
@@ -0,0 +1,210 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 by Daniel Stenberg <daniel@haxx.se>
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19
20#include <stdio.h>
21#include <string.h>
22#include <stdarg.h>
23#include <stdlib.h>
24#include <ctype.h>
25#include <sys/types.h>
26#include <sys/stat.h>
27#include <fcntl.h>
28
29#include <errno.h>
30#include <ctype.h>
31#include <time.h>
32
33#include "screenhack.h"
34#include "config.h"
35
36/*
37 * Specific implementations for X11, using the generic LCD API and data.
38 */
39
40#include "lcd-x11.h"
41#include "lcd-playersim.h"
42
43#include <SDL.h>
44
45extern SDL_Surface *surface;
46
47extern void screen_resized(int width, int height);
48extern bool lcd_display_redraw;
49
50#ifdef HAVE_LCD_BITMAP
51#if LCD_DEPTH==16
52fb_data lcd_framebuffer_copy[LCD_HEIGHT][LCD_WIDTH*2];
53#else
54fb_data lcd_framebuffer_copy[LCD_HEIGHT][LCD_WIDTH];
55#endif
56
57void lcd_update (void)
58{
59 /* update a full screen rect */
60 lcd_update_rect(0, 0, LCD_WIDTH, LCD_HEIGHT);
61}
62
63void lcd_update_rect(int x_start, int y_start,
64 int width, int height)
65{
66 int x;
67 int y;
68 int p=0;
69 int xmax;
70 int ymax;
71 int colors[LCD_WIDTH * LCD_HEIGHT];
72 struct coordinate points[LCD_WIDTH * LCD_HEIGHT];
73
74#if 0
75 fprintf(stderr, "%04d: lcd_update_rect(%d, %d, %d, %d)\n",
76 counter++, x_start, y_start, width, height);
77#endif
78 ymax = y_start + height;
79 xmax = x_start + width;
80
81 if(xmax > LCD_WIDTH)
82 xmax = LCD_WIDTH;
83 if(ymax >= LCD_HEIGHT)
84 ymax = LCD_HEIGHT;
85
86 for (x = x_start; x < xmax; x++)
87 for (y = y_start; y < ymax; y++)
88 {
89#if LCD_DEPTH == 1
90 Uint32 sdl_white = SDL_MapRGB(surface->format, 255, 255, 255);
91 Uint32 sdl_black = SDL_MapRGB(surface->format, 0, 0, 0);
92 points[p].x = x + MARGIN_X;
93 points[p].y = y + MARGIN_Y;
94 colors[p] = ((lcd_framebuffer[y/8][x] >> (y & 7)) & 1) ? sdl_black : sdl_white;
95#elif LCD_DEPTH == 2
96 unsigned gray = ((lcd_framebuffer[y/4][x] >> (2 * (y & 3))) & 3) << 6;
97 points[p].x = x + MARGIN_X;
98 points[p].y = y + MARGIN_Y;
99 colors[p] = SDL_MapRGB(surface->format, 255-gray, 255-gray, 255-gray);
100#elif LCD_DEPTH == 16
101#if LCD_PIXELFORMAT == RGB565SWAPPED
102 unsigned b = ((lcd_framebuffer[y][x] >> 11) & 0x1f) << 3;
103 unsigned g = ((lcd_framebuffer[y][x] >> 5) & 0x3f) << 2;
104 unsigned r = ((lcd_framebuffer[y][x]) & 0x1f) << 3;
105 points[p].x = x + MARGIN_X;
106 points[p].y = y + MARGIN_Y;
107 colors[p] = SDL_MapRGB(surface->format, r, g, b);
108#else
109 unsigned r = ((lcd_framebuffer[y][x] >> 11) & 0x1f) << 3;
110 unsigned g = ((lcd_framebuffer[y][x] >> 5) & 0x3f) << 2;
111 unsigned b = ((lcd_framebuffer[y][x]) & 0x1f) << 3;
112 points[p].x = x + MARGIN_X;
113 points[p].y = y + MARGIN_Y;
114 colors[p] = SDL_MapRGB(surface->format, r, g, b);
115#endif
116#endif
117 p++;
118 }
119
120 dots(colors, &points[0], p);
121 /* printf("lcd_update_rect: Draws %d pixels, clears %d pixels\n", p, cp);*/
122 SDL_UpdateRect(surface, 0, 0, 0, 0);
123 lcd_display_redraw=false;
124}
125
126#ifdef LCD_REMOTE_HEIGHT
127extern unsigned char lcd_remote_framebuffer[LCD_REMOTE_HEIGHT/8][LCD_REMOTE_WIDTH];
128unsigned char lcd_remote_framebuffer_copy[LCD_REMOTE_HEIGHT/8][LCD_REMOTE_WIDTH];
129
130#define REMOTE_START_Y (LCD_HEIGHT + 2*MARGIN_Y)
131
132void lcd_remote_update (void)
133{
134 lcd_remote_update_rect(0, 0, LCD_REMOTE_WIDTH, LCD_REMOTE_HEIGHT);
135}
136
137void lcd_remote_update_rect(int x_start, int y_start,
138 int width, int height)
139{
140 int x;
141 int y;
142 int p=0;
143 int xmax;
144 int ymax;
145 struct coordinate points[LCD_REMOTE_WIDTH * LCD_REMOTE_HEIGHT];
146 int colors[LCD_REMOTE_WIDTH * LCD_REMOTE_HEIGHT];
147 Uint32 sdl_white = SDL_MapRGB(surface->format, 255, 255, 255);
148 Uint32 sdl_black = SDL_MapRGB(surface->format, 0, 0, 0);
149
150#if 0
151 fprintf(stderr, "%04d: lcd_update_rect(%d, %d, %d, %d)\n",
152 counter++, x_start, y_start, width, height);
153#endif
154 ymax = y_start + height;
155 xmax = x_start + width;
156
157 if(xmax > LCD_REMOTE_WIDTH)
158 xmax = LCD_REMOTE_WIDTH;
159 if(ymax >= LCD_REMOTE_HEIGHT)
160 ymax = LCD_REMOTE_HEIGHT;
161
162 for (x = x_start; x < xmax; x++)
163 for (y = y_start; y < ymax; y++) {
164 colors[p] = ((lcd_remote_framebuffer[y/8][x] >> (y & 7)) & 1) ? sdl_black : sdl_white;
165 points[p].x = x + MARGIN_X;
166 points[p].y = y + MARGIN_Y + REMOTE_START_Y;
167 p++;
168 }
169
170 dots(colors, &points[0], p);
171 /* printf("lcd_update_rect: Draws %d pixels, clears %d pixels\n", p, cp);*/
172 SDL_UpdateRect(surface, 0, 0, 0, 0);
173 lcd_display_redraw=false;
174}
175
176
177#endif
178
179#endif
180#ifdef HAVE_LCD_CHARCELLS
181
182/* Defined in lcd-playersim.c */
183extern void lcd_print_char(int x, int y);
184extern unsigned char lcd_buffer[2][11];
185
186extern unsigned char hardware_buffer_lcd[11][2];
187static unsigned char lcd_buffer_copy[11][2];
188
189void lcd_update (void)
190{
191 bool changed=false;
192 int x, y;
193 for (y=0; y<2; y++) {
194 for (x=0; x<11; x++) {
195 if (lcd_display_redraw ||
196 lcd_buffer_copy[x][y] != hardware_buffer_lcd[x][y]) {
197 lcd_buffer_copy[x][y] = hardware_buffer_lcd[x][y];
198 lcd_print_char(x, y);
199 changed=true;
200 }
201 }
202 }
203 if (changed)
204 {
205 SDL_UpdateRect(surface, 0, 0, 0, 0);
206 }
207 lcd_display_redraw=false;
208}
209
210#endif