Remove the full url path from links to the wiki and display the wiki name only instea...
[Rockbox.git] / uisimulator / sdl / lcd-charcells.c
blob722933f0028c6ac70c9d4bf93b53b46f975aa246
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 "lcd.h"
22 #include "lcd-charcell.h"
23 #include "misc.h"
24 #include <string.h>
25 #include <unistd.h>
26 #include <fcntl.h>
28 #include "lcd-playersim.h"
29 #include "uisdl.h"
30 #include "lcd-sdl.h"
32 /* extern functions, needed for screendump() */
33 extern int sim_creat(const char *name);
35 SDL_Surface* lcd_surface;
36 SDL_Color lcd_color_zero = {UI_LCD_BGCOLOR, 0};
37 SDL_Color lcd_backlight_color_zero = {UI_LCD_BGCOLORLIGHT, 0};
38 SDL_Color lcd_color_max = {0, 0, 0, 0};
41 static unsigned long get_lcd_pixel(int x, int y)
43 return sim_lcd_framebuffer[y][x];
46 void sim_lcd_update_rect(int x_start, int y_start, int width, int height)
48 sdl_update_rect(lcd_surface, x_start, y_start, width, height,
49 SIM_LCD_WIDTH, SIM_LCD_HEIGHT, get_lcd_pixel);
50 sdl_gui_update(lcd_surface, x_start, y_start, width, height,
51 SIM_LCD_WIDTH, SIM_LCD_HEIGHT,
52 background ? UI_LCD_POSX : 0, background ? UI_LCD_POSY : 0);
55 void lcd_update(void)
57 int x, y;
59 for (y = 0; y < lcd_pattern_count; y++)
60 if (lcd_patterns[y].count > 0)
61 sim_lcd_define_pattern(y, lcd_patterns[y].pattern);
63 for (y = 0; y < LCD_HEIGHT; y++)
64 for (x = 0; x < LCD_WIDTH; x++)
65 lcd_print_char(x, y, lcd_charbuffer[y][x]);
67 if (lcd_cursor.visible)
68 lcd_print_char(lcd_cursor.x, lcd_cursor.y, lcd_cursor.hw_char);
70 sim_lcd_update_rect(0, ICON_HEIGHT, SIM_LCD_WIDTH,
71 LCD_HEIGHT*CHAR_HEIGHT*CHAR_PIXEL);
74 #ifdef HAVE_BACKLIGHT
75 void sim_backlight(int value)
77 if (value > 0) {
78 sdl_set_gradient(lcd_surface, &lcd_backlight_color_zero, &lcd_color_max,
79 0, (1<<LCD_DEPTH));
80 } else {
81 sdl_set_gradient(lcd_surface, &lcd_color_zero, &lcd_color_max,
82 0, (1<<LCD_DEPTH));
85 sim_lcd_update_rect(0, 0, SIM_LCD_WIDTH, SIM_LCD_HEIGHT);
87 #endif
89 /* initialise simulator lcd driver */
90 void sim_lcd_init(void)
92 lcd_surface = SDL_CreateRGBSurface(SDL_SWSURFACE,
93 SIM_LCD_WIDTH * display_zoom,
94 SIM_LCD_HEIGHT * display_zoom,
95 8, 0, 0, 0, 0);
97 sdl_set_gradient(lcd_surface, &lcd_backlight_color_zero, &lcd_color_max,
98 0, (1<<LCD_DEPTH));
101 #define BMP_COMPRESSION 0 /* BI_RGB */
102 #define BMP_NUMCOLORS (1 << LCD_DEPTH)
103 #define BMP_BPP 1
104 #define BMP_LINESIZE (((SIM_LCD_WIDTH + 31) / 32) * 4)
106 #define BMP_HEADERSIZE (54 + 4 * BMP_NUMCOLORS)
107 #define BMP_DATASIZE (BMP_LINESIZE * SIM_LCD_HEIGHT)
108 #define BMP_TOTALSIZE (BMP_HEADERSIZE + BMP_DATASIZE)
110 #define LE16_CONST(x) (x)&0xff, ((x)>>8)&0xff
111 #define LE32_CONST(x) (x)&0xff, ((x)>>8)&0xff, ((x)>>16)&0xff, ((x)>>24)&0xff
113 static const unsigned char bmpheader[] =
115 0x42, 0x4d, /* 'BM' */
116 LE32_CONST(BMP_TOTALSIZE), /* Total file size */
117 0x00, 0x00, 0x00, 0x00, /* Reserved */
118 LE32_CONST(BMP_HEADERSIZE), /* Offset to start of pixel data */
120 0x28, 0x00, 0x00, 0x00, /* Size of (2nd) header */
121 LE32_CONST(SIM_LCD_WIDTH), /* Width in pixels */
122 LE32_CONST(SIM_LCD_HEIGHT), /* Height in pixels */
123 0x01, 0x00, /* Number of planes (always 1) */
124 LE16_CONST(BMP_BPP), /* Bits per pixel 1/4/8/16/24 */
125 LE32_CONST(BMP_COMPRESSION),/* Compression mode */
126 LE32_CONST(BMP_DATASIZE), /* Size of bitmap data */
127 0xc4, 0x0e, 0x00, 0x00, /* Horizontal resolution (pixels/meter) */
128 0xc4, 0x0e, 0x00, 0x00, /* Vertical resolution (pixels/meter) */
129 LE32_CONST(BMP_NUMCOLORS), /* Number of used colours */
130 LE32_CONST(BMP_NUMCOLORS), /* Number of important colours */
132 0x90, 0xee, 0x90, 0x00, /* Colour #0 */
133 0x00, 0x00, 0x00, 0x00 /* Colour #1 */
136 void screen_dump(void)
138 int fd;
139 char filename[MAX_PATH];
140 int x, y;
141 static unsigned char line[BMP_LINESIZE];
143 create_numbered_filename(filename, "", "dump_", ".bmp", 4
144 IF_CNFN_NUM_(, NULL));
145 DEBUGF("screen_dump\n");
147 fd = sim_creat(filename);
148 if (fd < 0)
149 return;
151 write(fd, bmpheader, sizeof(bmpheader));
152 SDL_LockSurface(lcd_surface);
154 /* BMP image goes bottom up */
155 for (y = SIM_LCD_HEIGHT - 1; y >= 0; y--)
157 Uint8 *src = (Uint8 *)lcd_surface->pixels
158 + y * SIM_LCD_WIDTH * display_zoom * display_zoom;
159 unsigned char *dst = line;
160 unsigned dst_mask = 0x80;
162 memset(line, 0, sizeof(line));
163 for (x = SIM_LCD_WIDTH; x > 0; x--)
165 if (*src)
166 *dst |= dst_mask;
167 src += display_zoom;
168 dst_mask >>= 1;
169 if (dst_mask == 0)
171 dst++;
172 dst_mask = 0x80;
175 write(fd, line, sizeof(line));
177 SDL_UnlockSurface(lcd_surface);
178 close(fd);