Alexander Eickhoff wrote at least two accepted patches that went in during 2003
[kugel-rb.git] / uisimulator / sdl / lcd-bitmap.c
blobda6acce1bcf7cc0bc779ead2b91cd47df65351b3
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2006 Dan Everton
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.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
20 #include "debug.h"
21 #include "uisdl.h"
22 #include "lcd-sdl.h"
24 SDL_Surface* lcd_surface;
25 int lcd_backlight_val;
27 #if LCD_DEPTH <= 8
28 #ifdef HAVE_BACKLIGHT
29 SDL_Color lcd_backlight_color_zero = {UI_LCD_BGCOLORLIGHT, 0};
30 #endif
31 SDL_Color lcd_color_zero = {UI_LCD_BGCOLOR, 0};
32 SDL_Color lcd_color_max = {0, 0, 0, 0};
33 #endif
35 #if LCD_DEPTH < 8
36 int lcd_ex_shades = 0;
37 unsigned long (*lcd_ex_getpixel)(int, int) = NULL;
38 #endif
40 static unsigned long get_lcd_pixel(int x, int y)
42 #if LCD_DEPTH == 1
43 return ((lcd_framebuffer[y/8][x] >> (y & 7)) & 1);
44 #elif LCD_DEPTH == 2
45 #if LCD_PIXELFORMAT == HORIZONTAL_PACKING
46 return ((lcd_framebuffer[y][x/4] >> (2 * (~x & 3))) & 3);
47 #else
48 return ((lcd_framebuffer[y/4][x] >> (2 * (y & 3))) & 3);
49 #endif
50 #elif LCD_DEPTH == 16
51 #if LCD_PIXELFORMAT == RGB565SWAPPED
52 unsigned bits = lcd_framebuffer[y][x];
53 return (bits >> 8) | (bits << 8);
54 #else
55 return lcd_framebuffer[y][x];
56 #endif
57 #endif
60 void lcd_update(void)
62 /* update a full screen rect */
63 lcd_update_rect(0, 0, LCD_WIDTH, LCD_HEIGHT);
66 void lcd_update_rect(int x_start, int y_start, int width, int height)
68 sdl_update_rect(lcd_surface, x_start, y_start, width, height, LCD_WIDTH,
69 LCD_HEIGHT, get_lcd_pixel);
70 sdl_gui_update(lcd_surface, x_start, y_start, width, height, LCD_WIDTH,
71 LCD_HEIGHT, background ? UI_LCD_POSX : 0, background? UI_LCD_POSY : 0);
74 #ifdef HAVE_BACKLIGHT
75 void sim_backlight(int value)
77 lcd_backlight_val = value;
79 #if LCD_DEPTH <= 8
80 if (value > 0) {
81 sdl_set_gradient(lcd_surface, &lcd_backlight_color_zero,
82 &lcd_color_max, 0, (1<<LCD_DEPTH));
83 } else {
84 sdl_set_gradient(lcd_surface, &lcd_color_zero, &lcd_color_max,
85 0, (1<<LCD_DEPTH));
87 #if LCD_DEPTH < 8
88 if (lcd_ex_shades) {
89 if (value > 0) {
90 sdl_set_gradient(lcd_surface, &lcd_color_max,
91 &lcd_backlight_color_zero, (1<<LCD_DEPTH),
92 lcd_ex_shades);
93 } else {
94 sdl_set_gradient(lcd_surface, &lcd_color_max, &lcd_color_zero,
95 (1<<LCD_DEPTH), lcd_ex_shades);
98 #endif
100 sdl_gui_update(lcd_surface, 0, 0, LCD_WIDTH, LCD_HEIGHT, LCD_WIDTH,
101 LCD_HEIGHT, background ? UI_LCD_POSX : 0, background? UI_LCD_POSY : 0);
103 #endif
105 #endif
107 /* initialise simulator lcd driver */
108 void sim_lcd_init(void)
110 #if LCD_DEPTH == 16
111 lcd_surface = SDL_CreateRGBSurface(SDL_SWSURFACE, LCD_WIDTH * display_zoom,
112 LCD_HEIGHT * display_zoom, LCD_DEPTH, 0, 0, 0, 0);
113 #else
114 lcd_surface = SDL_CreateRGBSurface(SDL_SWSURFACE, LCD_WIDTH * display_zoom,
115 LCD_HEIGHT * display_zoom, 8, 0, 0, 0, 0);
116 #endif
118 #if LCD_DEPTH <= 8
119 #ifdef HAVE_BACKLIGHT
120 sdl_set_gradient(lcd_surface, &lcd_backlight_color_zero, &lcd_color_max,
121 0, (1<<LCD_DEPTH));
122 #else
123 sdl_set_gradient(lcd_surface, &lcd_color_zero, &lcd_color_max, 0,
124 (1<<LCD_DEPTH));
125 #endif
126 #endif
129 #if LCD_DEPTH < 8
130 void sim_lcd_ex_init(int shades, unsigned long (*getpixel)(int, int))
132 lcd_ex_shades = shades;
133 lcd_ex_getpixel = getpixel;
134 if (shades) {
135 #ifdef HAVE_BACKLIGHT
136 if (lcd_backlight_val > 0) {
137 sdl_set_gradient(lcd_surface, &lcd_color_max,
138 &lcd_backlight_color_zero, (1<<LCD_DEPTH),
139 shades);
141 else
142 #endif
144 sdl_set_gradient(lcd_surface, &lcd_color_max, &lcd_color_zero,
145 (1<<LCD_DEPTH), shades);
150 void sim_lcd_ex_update_rect(int x_start, int y_start, int width, int height)
152 if (lcd_ex_getpixel) {
153 sdl_update_rect(lcd_surface, x_start, y_start, width, height,
154 LCD_WIDTH, LCD_HEIGHT, lcd_ex_getpixel);
155 sdl_gui_update(lcd_surface, x_start, y_start, width, height, LCD_WIDTH,
156 LCD_HEIGHT, background ? UI_LCD_POSX : 0,
157 background? UI_LCD_POSY : 0);
160 #endif