summaryrefslogtreecommitdiff
path: root/uisimulator/sdl/lcd-bitmap.c
diff options
context:
space:
mode:
Diffstat (limited to 'uisimulator/sdl/lcd-bitmap.c')
-rw-r--r--uisimulator/sdl/lcd-bitmap.c230
1 files changed, 94 insertions, 136 deletions
diff --git a/uisimulator/sdl/lcd-bitmap.c b/uisimulator/sdl/lcd-bitmap.c
index bc2a4c46f4..6faa5eb0b2 100644
--- a/uisimulator/sdl/lcd-bitmap.c
+++ b/uisimulator/sdl/lcd-bitmap.c
@@ -22,45 +22,74 @@
22#include "debug.h" 22#include "debug.h"
23#include "uisdl.h" 23#include "uisdl.h"
24#include "lcd-sdl.h" 24#include "lcd-sdl.h"
25#include "misc.h"
25 26
26SDL_Surface* lcd_surface; 27SDL_Surface* lcd_surface;
27#ifdef UI_LCD_SPLIT
28SDL_Surface* lcd_real_surface; /* the surface which represents the real screen */
29#endif
30int lcd_backlight_val;
31 28
32#if LCD_DEPTH <= 8 29#if LCD_DEPTH <= 8
33#ifdef HAVE_BACKLIGHT 30#ifdef HAVE_BACKLIGHT
34SDL_Color lcd_backlight_color_zero = {UI_LCD_BGCOLORLIGHT, 0}; 31SDL_Color lcd_bl_color_dark = {RED_CMP(LCD_BL_DARKCOLOR),
35SDL_Color lcd_backlight_color_max = {UI_LCD_FGCOLORLIGHT, 0}; 32 GREEN_CMP(LCD_BL_DARKCOLOR),
36#ifdef UI_LCD_SPLIT 33 BLUE_CMP(LCD_BL_DARKCOLOR), 0};
37SDL_Color lcd_backlight_color_split= {UI_LCD_SPLIT_FGCOLORLIGHT, 0}; 34SDL_Color lcd_bl_color_bright = {RED_CMP(LCD_BL_BRIGHTCOLOR),
38#endif 35 GREEN_CMP(LCD_BL_BRIGHTCOLOR),
39#endif 36 BLUE_CMP(LCD_BL_BRIGHTCOLOR), 0};
40SDL_Color lcd_color_zero = {UI_LCD_BGCOLOR, 0}; 37#ifdef HAVE_LCD_SPLIT
41SDL_Color lcd_color_max = {UI_LCD_FGCOLOR, 0}; 38SDL_Color lcd_bl_color2_dark = {RED_CMP(LCD_BL_DARKCOLOR_2),
42#ifdef UI_LCD_SPLIT 39 GREEN_CMP(LCD_BL_DARKCOLOR_2),
43SDL_Color lcd_color_split= {UI_LCD_SPLIT_FGCOLOR, 0}; 40 BLUE_CMP(LCD_BL_DARKCOLOR_2), 0};
44#endif 41SDL_Color lcd_bl_color2_bright = {RED_CMP(LCD_BL_BRIGHTCOLOR_2),
42 GREEN_CMP(LCD_BL_BRIGHTCOLOR_2),
43 BLUE_CMP(LCD_BL_BRIGHTCOLOR_2), 0};
44#endif
45#endif /* HAVE_BACKLIGHT */
46SDL_Color lcd_color_dark = {RED_CMP(LCD_DARKCOLOR),
47 GREEN_CMP(LCD_DARKCOLOR),
48 BLUE_CMP(LCD_DARKCOLOR), 0};
49SDL_Color lcd_color_bright = {RED_CMP(LCD_BRIGHTCOLOR),
50 GREEN_CMP(LCD_BRIGHTCOLOR),
51 BLUE_CMP(LCD_BRIGHTCOLOR), 0};
52#ifdef HAVE_LCD_SPLIT
53SDL_Color lcd_color2_dark = {RED_CMP(LCD_DARKCOLOR_2),
54 GREEN_CMP(LCD_DARKCOLOR_2),
55 BLUE_CMP(LCD_DARKCOLOR_2), 0};
56SDL_Color lcd_color2_bright = {RED_CMP(LCD_BRIGHTCOLOR_2),
57 GREEN_CMP(LCD_BRIGHTCOLOR_2),
58 BLUE_CMP(LCD_BRIGHTCOLOR_2), 0};
59#endif
60
61#ifdef HAVE_LCD_SPLIT
62#define GRADIENT_MAX 127
63#else
64#define GRADIENT_MAX 128
45#endif 65#endif
66#endif /* LCD_DEPTH <= 8 */
46 67
47#if LCD_DEPTH < 8 68#if LCD_DEPTH < 8
48int lcd_ex_shades = 0;
49unsigned long (*lcd_ex_getpixel)(int, int) = NULL; 69unsigned long (*lcd_ex_getpixel)(int, int) = NULL;
70#endif /* LCD_DEPTH < 8 */
71
72#if LCD_DEPTH == 2
73/* Only defined for positive, non-split LCD for now */
74static const unsigned char colorindex[4] = {128, 85, 43, 0};
50#endif 75#endif
51 76
52static unsigned long get_lcd_pixel(int x, int y) 77static unsigned long get_lcd_pixel(int x, int y)
53{ 78{
54#if LCD_DEPTH == 1 79#if LCD_DEPTH == 1
55 return ((lcd_framebuffer[y/8][x] >> (y & 7)) & 1); 80#ifdef HAVE_NEGATIVE_LCD
81 return (lcd_framebuffer[y/8][x] & (1 << (y & 7))) ? GRADIENT_MAX : 0;
82#else
83 return (lcd_framebuffer[y/8][x] & (1 << (y & 7))) ? 0 : GRADIENT_MAX;
84#endif
56#elif LCD_DEPTH == 2 85#elif LCD_DEPTH == 2
57#if LCD_PIXELFORMAT == HORIZONTAL_PACKING 86#if LCD_PIXELFORMAT == HORIZONTAL_PACKING
58 return ((lcd_framebuffer[y][x/4] >> (2 * (~x & 3))) & 3); 87 return colorindex[(lcd_framebuffer[y][x/4] >> (2 * (~x & 3))) & 3];
59#elif LCD_PIXELFORMAT == VERTICAL_PACKING 88#elif LCD_PIXELFORMAT == VERTICAL_PACKING
60 return ((lcd_framebuffer[y/4][x] >> (2 * (y & 3))) & 3); 89 return colorindex[(lcd_framebuffer[y/4][x] >> (2 * (y & 3))) & 3];
61#elif LCD_PIXELFORMAT == VERTICAL_INTERLEAVED 90#elif LCD_PIXELFORMAT == VERTICAL_INTERLEAVED
62 unsigned bits = (lcd_framebuffer[y/8][x] >> (y & 7)) & 0x0101; 91 unsigned bits = (lcd_framebuffer[y/8][x] >> (y & 7)) & 0x0101;
63 return (bits | (bits >> 7)) & 3; 92 return colorindex[(bits | (bits >> 7)) & 3];
64#endif 93#endif
65#elif LCD_DEPTH == 16 94#elif LCD_DEPTH == 16
66#if LCD_PIXELFORMAT == RGB565SWAPPED 95#if LCD_PIXELFORMAT == RGB565SWAPPED
@@ -80,148 +109,77 @@ void lcd_update(void)
80 109
81void lcd_update_rect(int x_start, int y_start, int width, int height) 110void lcd_update_rect(int x_start, int y_start, int width, int height)
82{ 111{
83 sdl_update_rect(lcd_surface, x_start, y_start, width, height, LCD_WIDTH, 112 sdl_update_rect(lcd_surface, x_start, y_start, width, height,
84 LCD_HEIGHT, get_lcd_pixel); 113 LCD_WIDTH, LCD_HEIGHT, get_lcd_pixel);
85 sdl_gui_update(lcd_surface, IFSPLIT(lcd_real_surface,) x_start, y_start, 114 sdl_gui_update(lcd_surface, x_start, y_start, width,
86 width, height, LCD_WIDTH, LCD_HEIGHT, 115 height + LCD_SPLIT_LINES, SIM_LCD_WIDTH, SIM_LCD_HEIGHT,
87 background ? UI_LCD_POSX : 0, background? UI_LCD_POSY : 0); 116 background ? UI_LCD_POSX : 0, background? UI_LCD_POSY : 0);
88} 117}
89 118
90#ifdef HAVE_BACKLIGHT 119#ifdef HAVE_BACKLIGHT
91void sim_backlight(int value) 120void sim_backlight(int value)
92{ 121{
93 lcd_backlight_val = value;
94
95#if LCD_DEPTH <= 8 122#if LCD_DEPTH <= 8
96 if (value > 0) { 123 if (value > 0) {
97#ifdef UI_LCD_SPLIT 124 sdl_set_gradient(lcd_surface, &lcd_bl_color_dark,
98 sdl_set_gradient(lcd_real_surface, &lcd_backlight_color_zero, 125 &lcd_bl_color_bright, 0, GRADIENT_MAX+1);
99 &lcd_backlight_color_max, &lcd_backlight_color_zero, 126#ifdef HAVE_LCD_SPLIT
100 &lcd_backlight_color_split, 0, (1<<LCD_DEPTH)); 127 sdl_set_gradient(lcd_surface, &lcd_bl_color2_dark,
101#else 128 &lcd_bl_color2_bright, GRADIENT_MAX+1, GRADIENT_MAX+1);
102 sdl_set_gradient(lcd_surface, &lcd_backlight_color_zero,
103 &lcd_backlight_color_max, 0, (1<<LCD_DEPTH));
104#endif 129#endif
105 } else { 130 } else {
106#ifdef UI_LCD_SPLIT 131 sdl_set_gradient(lcd_surface, &lcd_color_dark,
107 sdl_set_gradient(lcd_real_surface, &lcd_color_zero, &lcd_color_max, 132 &lcd_color_bright, 0, GRADIENT_MAX+1);
108 &lcd_color_zero, &lcd_color_split, 0, (1<<LCD_DEPTH)); 133#ifdef HAVE_LCD_SPLIT
109#else 134 sdl_set_gradient(lcd_surface, &lcd_color2_dark,
110 sdl_set_gradient(lcd_surface, &lcd_color_zero, &lcd_color_max, 0, 135 &lcd_color2_bright, GRADIENT_MAX+1, GRADIENT_MAX+1);
111 (1<<LCD_DEPTH));
112#endif
113 }
114#if LCD_DEPTH < 8
115 if (lcd_ex_shades) {
116 if (value > 0) {
117#ifdef UI_LCD_SPLIT
118 sdl_set_gradient(lcd_real_surface, &lcd_backlight_color_max,
119 &lcd_backlight_color_zero, &lcd_backlight_color_split,
120 &lcd_backlight_color_zero,
121 (1<<LCD_DEPTH), lcd_ex_shades);
122#elif defined MROBE_100
123 /* quick fix, a proper fix needs to compare brightnesses */
124 sdl_set_gradient(lcd_surface, &lcd_backlight_color_zero,
125 &lcd_backlight_color_max, (1<<LCD_DEPTH), lcd_ex_shades);
126#else
127 sdl_set_gradient(lcd_surface, &lcd_backlight_color_max,
128 &lcd_backlight_color_zero, (1<<LCD_DEPTH), lcd_ex_shades);
129#endif 136#endif
130 } else {
131#ifdef UI_LCD_SPLIT
132 sdl_set_gradient(lcd_real_surface, &lcd_color_max, &lcd_color_zero,
133 &lcd_color_split, &lcd_color_zero, (1<<LCD_DEPTH),
134 lcd_ex_shades);
135#elif defined MROBE_100
136 /* quick fix, a proper fix needs to compare brightnesses */
137 sdl_set_gradient(lcd_surface, &lcd_color_zero, &lcd_color_max,
138 (1<<LCD_DEPTH), lcd_ex_shades);
139#else
140 sdl_set_gradient(lcd_surface, &lcd_color_max, &lcd_color_zero,
141 (1<<LCD_DEPTH), lcd_ex_shades);
142#endif
143 }
144 } 137 }
145#endif 138 sdl_gui_update(lcd_surface, 0, 0, SIM_LCD_WIDTH, SIM_LCD_HEIGHT,
146 139 SIM_LCD_WIDTH, SIM_LCD_HEIGHT,
147 sdl_gui_update(lcd_surface, IFSPLIT(lcd_real_surface,) 0, 0, LCD_WIDTH,
148 LCD_HEIGHT, LCD_WIDTH, LCD_HEIGHT,
149 background ? UI_LCD_POSX : 0, background? UI_LCD_POSY : 0); 140 background ? UI_LCD_POSX : 0, background? UI_LCD_POSY : 0);
150 141#endif /* LCD_DEPTH <= 8 */
151#endif
152} 142}
153#endif 143#endif /* HAVE_BACKLIGHT */
154 144
155/* initialise simulator lcd driver */ 145/* initialise simulator lcd driver */
156void sim_lcd_init(void) 146void sim_lcd_init(void)
157{ 147{
158#if LCD_DEPTH == 16 148#if LCD_DEPTH == 16
159 lcd_surface = SDL_CreateRGBSurface(SDL_SWSURFACE, LCD_WIDTH * display_zoom, 149 lcd_surface = SDL_CreateRGBSurface(SDL_SWSURFACE,
160 LCD_HEIGHT * display_zoom, LCD_DEPTH, 0, 0, 0, 0); 150 SIM_LCD_WIDTH * display_zoom,
151 SIM_LCD_HEIGHT * display_zoom,
152 LCD_DEPTH, 0, 0, 0, 0);
161#else 153#else
162 lcd_surface = SDL_CreateRGBSurface(SDL_SWSURFACE, LCD_WIDTH * display_zoom, 154 lcd_surface = SDL_CreateRGBSurface(SDL_SWSURFACE,
163 LCD_HEIGHT * display_zoom, 8, 0, 0, 0, 0); 155 SIM_LCD_WIDTH * display_zoom,
164#ifdef UI_LCD_SPLIT 156 SIM_LCD_HEIGHT * display_zoom,
165 lcd_real_surface = SDL_CreateRGBSurface(SDL_SWSURFACE, 157 8, 0, 0, 0, 0);
166 LCD_WIDTH * display_zoom,
167 (LCD_HEIGHT+UI_LCD_SPLIT_BLACK_LINES) * display_zoom, 8, 0, 0, 0, 0);
168#endif
169#endif 158#endif
170 159
171#if LCD_DEPTH <= 8 160#if LCD_DEPTH <= 8
172#ifdef HAVE_BACKLIGHT 161#ifdef HAVE_BACKLIGHT
173#ifdef UI_LCD_SPLIT 162 sdl_set_gradient(lcd_surface, &lcd_bl_color_dark,
174 sdl_set_gradient(lcd_real_surface, &lcd_backlight_color_zero, 163 &lcd_bl_color_bright, 0, GRADIENT_MAX+1);
175 &lcd_backlight_color_max, &lcd_backlight_color_zero, 164#ifdef HAVE_LCD_SPLIT
176 &lcd_backlight_color_split, 0, (1<<LCD_DEPTH)); 165 sdl_set_gradient(lcd_surface, &lcd_bl_color2_dark,
177#else 166 &lcd_bl_color2_bright, GRADIENT_MAX+1, GRADIENT_MAX+1);
178 sdl_set_gradient(lcd_surface, &lcd_backlight_color_zero, 167#endif
179 &lcd_backlight_color_max, 0, (1<<LCD_DEPTH)); 168#else /* !HAVE_BACKLIGHT */
180#endif 169 sdl_set_gradient(lcd_surface, &lcd_color_dark,
181#else 170 &lcd_color_bright, 0, GRADIENT_MAX+1);
182 sdl_set_gradient(lcd_surface, &lcd_color_zero, &lcd_color_max, 0, 171#ifdef HAVE_LCD_SPLIT
183 (1<<LCD_DEPTH)); 172 sdl_set_gradient(lcd_surface, &lcd_color2_dark,
184#endif 173 &lcd_color2_bright, GRADIENT_MAX+1, GRADIENT_MAX+1);
185#endif 174#endif
175#endif /* !HAVE_BACKLIGHT */
176#endif /* LCD_DEPTH < 8 */
186} 177}
187 178
188#if LCD_DEPTH < 8 179#if LCD_DEPTH < 8
189void sim_lcd_ex_init(int shades, unsigned long (*getpixel)(int, int)) 180void sim_lcd_ex_init(unsigned long (*getpixel)(int, int))
190{ 181{
191 lcd_ex_shades = shades;
192 lcd_ex_getpixel = getpixel; 182 lcd_ex_getpixel = getpixel;
193 if (shades) {
194#ifdef HAVE_BACKLIGHT
195 if (lcd_backlight_val > 0) {
196#ifdef UI_LCD_SPLIT
197 sdl_set_gradient(lcd_real_surface, &lcd_backlight_color_max,
198 &lcd_backlight_color_zero, &lcd_backlight_color_split,
199 &lcd_backlight_color_zero, (1<<LCD_DEPTH), shades);
200#elif defined MROBE_100
201 /* quick fix, a proper fix needs to compare brightnesses */
202 sdl_set_gradient(lcd_surface, &lcd_backlight_color_zero,
203 &lcd_backlight_color_max, (1<<LCD_DEPTH), shades);
204#else
205 sdl_set_gradient(lcd_surface, &lcd_backlight_color_max,
206 &lcd_backlight_color_zero, (1<<LCD_DEPTH), shades);
207#endif
208 }
209 else
210#endif
211 {
212#ifdef UI_LCD_SPLIT
213 sdl_set_gradient(lcd_real_surface, &lcd_color_max, &lcd_color_zero,
214 &lcd_color_split, &lcd_color_zero, (1<<LCD_DEPTH), shades);
215#elif defined MROBE_100
216 /* quick fix, a proper fix needs to compare brightnesses */
217 sdl_set_gradient(lcd_surface, &lcd_color_zero, &lcd_color_max,
218 (1<<LCD_DEPTH), shades);
219#else
220 sdl_set_gradient(lcd_surface, &lcd_color_max, &lcd_color_zero,
221 (1<<LCD_DEPTH), shades);
222#endif
223 }
224 }
225} 183}
226 184
227void sim_lcd_ex_update_rect(int x_start, int y_start, int width, int height) 185void sim_lcd_ex_update_rect(int x_start, int y_start, int width, int height)
@@ -229,10 +187,10 @@ void sim_lcd_ex_update_rect(int x_start, int y_start, int width, int height)
229 if (lcd_ex_getpixel) { 187 if (lcd_ex_getpixel) {
230 sdl_update_rect(lcd_surface, x_start, y_start, width, height, 188 sdl_update_rect(lcd_surface, x_start, y_start, width, height,
231 LCD_WIDTH, LCD_HEIGHT, lcd_ex_getpixel); 189 LCD_WIDTH, LCD_HEIGHT, lcd_ex_getpixel);
232 sdl_gui_update(lcd_surface, IFSPLIT(lcd_real_surface,) x_start, y_start, 190 sdl_gui_update(lcd_surface, x_start, y_start, width,
233 width, height, LCD_WIDTH, LCD_HEIGHT, 191 height + LCD_SPLIT_LINES, SIM_LCD_WIDTH, SIM_LCD_HEIGHT,
234 background ? UI_LCD_POSX : 0, 192 background ? UI_LCD_POSX : 0,
235 background? UI_LCD_POSY : 0); 193 background ? UI_LCD_POSY : 0);
236 } 194 }
237} 195}
238#endif 196#endif