summaryrefslogtreecommitdiff
path: root/firmware/target/hosted/sdl/lcd-charcells.c
diff options
context:
space:
mode:
authorThomas Martitz <kugel@rockbox.org>2010-05-15 21:02:47 +0000
committerThomas Martitz <kugel@rockbox.org>2010-05-15 21:02:47 +0000
commit3d0cee8abbaf764958743e8a7851eee94e60a913 (patch)
treea96b1ec825003a71643a7da4707c300f64824f82 /firmware/target/hosted/sdl/lcd-charcells.c
parentdcf442e61f21fb2aef5ce7de0547f733557b156e (diff)
downloadrockbox-3d0cee8abbaf764958743e8a7851eee94e60a913.tar.gz
rockbox-3d0cee8abbaf764958743e8a7851eee94e60a913.zip
- Move uisimulator/sdl/*.[ch] into the target tree, under firmware/target/hosted/sdl, uisdl.c is split up across button-sdl.c and system-sdl.c.
- Refactor the program startup. main() is now in main.c like on target, and the implicit application thread will now act as our main thread (previously a separate one was created for this in thread initialization). This is part of Rockbox as an application and is the first step to make an application port from the uisimulator. In a further step the sim bits from the sdl build will be separated out. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26065 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/target/hosted/sdl/lcd-charcells.c')
-rw-r--r--firmware/target/hosted/sdl/lcd-charcells.c198
1 files changed, 198 insertions, 0 deletions
diff --git a/firmware/target/hosted/sdl/lcd-charcells.c b/firmware/target/hosted/sdl/lcd-charcells.c
new file mode 100644
index 0000000000..900cbb04dd
--- /dev/null
+++ b/firmware/target/hosted/sdl/lcd-charcells.c
@@ -0,0 +1,198 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2006 Dan Everton
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include <string.h>
23#include <unistd.h>
24#include <fcntl.h>
25#include "system.h"
26#include "debug.h"
27#include "lcd.h"
28#include "lcd-charcell.h"
29#include "screendump.h"
30#include "general.h"
31
32#include "lcd-playersim.h"
33#include "sim-ui-defines.h"
34#include "lcd-sdl.h"
35
36/* can't include file.h here */
37#ifndef MAX_PATH
38#define MAX_PATH 260
39#endif
40
41/* extern functions, needed for screendump() */
42extern int sim_creat(const char *name, mode_t mode);
43
44SDL_Surface* lcd_surface;
45
46SDL_Color lcd_bl_color_dark = {RED_CMP(LCD_BL_DARKCOLOR),
47 GREEN_CMP(LCD_BL_DARKCOLOR),
48 BLUE_CMP(LCD_BL_DARKCOLOR), 0};
49SDL_Color lcd_bl_color_bright = {RED_CMP(LCD_BL_BRIGHTCOLOR),
50 GREEN_CMP(LCD_BL_BRIGHTCOLOR),
51 BLUE_CMP(LCD_BL_BRIGHTCOLOR), 0};
52SDL_Color lcd_color_dark = {RED_CMP(LCD_DARKCOLOR),
53 GREEN_CMP(LCD_DARKCOLOR),
54 BLUE_CMP(LCD_DARKCOLOR), 0};
55SDL_Color lcd_color_bright = {RED_CMP(LCD_BRIGHTCOLOR),
56 GREEN_CMP(LCD_BRIGHTCOLOR),
57 BLUE_CMP(LCD_BRIGHTCOLOR), 0};
58
59
60static unsigned long get_lcd_pixel(int x, int y)
61{
62 return sim_lcd_framebuffer[y][x];
63}
64
65void sim_lcd_update_rect(int x_start, int y_start, int width, int height)
66{
67 sdl_update_rect(lcd_surface, x_start, y_start, width, height,
68 SIM_LCD_WIDTH, SIM_LCD_HEIGHT, get_lcd_pixel);
69 sdl_gui_update(lcd_surface, x_start, y_start, width, height,
70 SIM_LCD_WIDTH, SIM_LCD_HEIGHT,
71 background ? UI_LCD_POSX : 0, background ? UI_LCD_POSY : 0);
72}
73
74void lcd_update(void)
75{
76 int x, y;
77
78 for (y = 0; y < lcd_pattern_count; y++)
79 if (lcd_patterns[y].count > 0)
80 sim_lcd_define_pattern(y, lcd_patterns[y].pattern);
81
82 for (y = 0; y < LCD_HEIGHT; y++)
83 for (x = 0; x < LCD_WIDTH; x++)
84 lcd_print_char(x, y, lcd_charbuffer[y][x]);
85
86 if (lcd_cursor.visible)
87 lcd_print_char(lcd_cursor.x, lcd_cursor.y, lcd_cursor.hw_char);
88
89 sim_lcd_update_rect(0, ICON_HEIGHT, SIM_LCD_WIDTH,
90 LCD_HEIGHT*CHAR_HEIGHT*CHAR_PIXEL);
91}
92
93#ifdef HAVE_BACKLIGHT
94void sim_backlight(int value)
95{
96 if (value > 0) {
97 sdl_set_gradient(lcd_surface, &lcd_bl_color_bright,
98 &lcd_bl_color_dark, 0, (1<<LCD_DEPTH));
99 } else {
100 sdl_set_gradient(lcd_surface, &lcd_color_bright,
101 &lcd_color_dark, 0, (1<<LCD_DEPTH));
102 }
103
104 sim_lcd_update_rect(0, 0, SIM_LCD_WIDTH, SIM_LCD_HEIGHT);
105}
106#endif
107
108/* initialise simulator lcd driver */
109void sim_lcd_init(void)
110{
111 lcd_surface = SDL_CreateRGBSurface(SDL_SWSURFACE,
112 SIM_LCD_WIDTH * display_zoom,
113 SIM_LCD_HEIGHT * display_zoom,
114 8, 0, 0, 0, 0);
115
116 sdl_set_gradient(lcd_surface, &lcd_bl_color_bright,
117 &lcd_bl_color_dark, 0, (1<<LCD_DEPTH));
118}
119
120#define BMP_COMPRESSION 0 /* BI_RGB */
121#define BMP_NUMCOLORS (1 << LCD_DEPTH)
122#define BMP_BPP 1
123#define BMP_LINESIZE (((SIM_LCD_WIDTH + 31) / 32) * 4)
124
125#define BMP_HEADERSIZE (54 + 4 * BMP_NUMCOLORS)
126#define BMP_DATASIZE (BMP_LINESIZE * SIM_LCD_HEIGHT)
127#define BMP_TOTALSIZE (BMP_HEADERSIZE + BMP_DATASIZE)
128
129#define LE16_CONST(x) (x)&0xff, ((x)>>8)&0xff
130#define LE32_CONST(x) (x)&0xff, ((x)>>8)&0xff, ((x)>>16)&0xff, ((x)>>24)&0xff
131
132static const unsigned char bmpheader[] =
133{
134 0x42, 0x4d, /* 'BM' */
135 LE32_CONST(BMP_TOTALSIZE), /* Total file size */
136 0x00, 0x00, 0x00, 0x00, /* Reserved */
137 LE32_CONST(BMP_HEADERSIZE), /* Offset to start of pixel data */
138
139 0x28, 0x00, 0x00, 0x00, /* Size of (2nd) header */
140 LE32_CONST(SIM_LCD_WIDTH), /* Width in pixels */
141 LE32_CONST(SIM_LCD_HEIGHT), /* Height in pixels */
142 0x01, 0x00, /* Number of planes (always 1) */
143 LE16_CONST(BMP_BPP), /* Bits per pixel 1/4/8/16/24 */
144 LE32_CONST(BMP_COMPRESSION),/* Compression mode */
145 LE32_CONST(BMP_DATASIZE), /* Size of bitmap data */
146 0xc4, 0x0e, 0x00, 0x00, /* Horizontal resolution (pixels/meter) */
147 0xc4, 0x0e, 0x00, 0x00, /* Vertical resolution (pixels/meter) */
148 LE32_CONST(BMP_NUMCOLORS), /* Number of used colours */
149 LE32_CONST(BMP_NUMCOLORS), /* Number of important colours */
150
151 BMP_COLOR(LCD_BL_BRIGHTCOLOR),
152 BMP_COLOR(LCD_BL_DARKCOLOR)
153};
154
155void screen_dump(void)
156{
157 int fd;
158 char filename[MAX_PATH];
159 int x, y;
160 static unsigned char line[BMP_LINESIZE];
161
162 create_numbered_filename(filename, "", "dump_", ".bmp", 4
163 IF_CNFN_NUM_(, NULL));
164 DEBUGF("screen_dump\n");
165
166 fd = sim_creat(filename, 0666);
167 if (fd < 0)
168 return;
169
170 write(fd, bmpheader, sizeof(bmpheader));
171 SDL_LockSurface(lcd_surface);
172
173 /* BMP image goes bottom up */
174 for (y = SIM_LCD_HEIGHT - 1; y >= 0; y--)
175 {
176 Uint8 *src = (Uint8 *)lcd_surface->pixels
177 + y * SIM_LCD_WIDTH * display_zoom * display_zoom;
178 unsigned char *dst = line;
179 unsigned dst_mask = 0x80;
180
181 memset(line, 0, sizeof(line));
182 for (x = SIM_LCD_WIDTH; x > 0; x--)
183 {
184 if (*src)
185 *dst |= dst_mask;
186 src += display_zoom;
187 dst_mask >>= 1;
188 if (dst_mask == 0)
189 {
190 dst++;
191 dst_mask = 0x80;
192 }
193 }
194 write(fd, line, sizeof(line));
195 }
196 SDL_UnlockSurface(lcd_surface);
197 close(fd);
198}