diff options
author | Jens Arnold <amiconn@rockbox.org> | 2007-03-31 09:58:49 +0000 |
---|---|---|
committer | Jens Arnold <amiconn@rockbox.org> | 2007-03-31 09:58:49 +0000 |
commit | 54ea2e435e1a5688de4e4dcf551a1fc9c1db323f (patch) | |
tree | e8ee4e55a20c872a6c0deff554734038c35dc661 /uisimulator/sdl/lcd-charcells.c | |
parent | 6186b556bdbe97bc3c50dd8feb970590bec2053c (diff) | |
download | rockbox-54ea2e435e1a5688de4e4dcf551a1fc9c1db323f.tar.gz rockbox-54ea2e435e1a5688de4e4dcf551a1fc9c1db323f.zip |
Charcell lcd driver: Preparations for switching to non-immediate LCD updates, using lcd_update() like on bitmap targets. * Added proper clipping. * Simplified simulator code.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@12979 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'uisimulator/sdl/lcd-charcells.c')
-rw-r--r-- | uisimulator/sdl/lcd-charcells.c | 179 |
1 files changed, 179 insertions, 0 deletions
diff --git a/uisimulator/sdl/lcd-charcells.c b/uisimulator/sdl/lcd-charcells.c new file mode 100644 index 0000000000..5a08179232 --- /dev/null +++ b/uisimulator/sdl/lcd-charcells.c | |||
@@ -0,0 +1,179 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2006 Dan Everton | ||
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 "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> | ||
27 | |||
28 | #include "lcd-playersim.h" | ||
29 | #include "uisdl.h" | ||
30 | #include "lcd-sdl.h" | ||
31 | |||
32 | /* extern functions, needed for screendump() */ | ||
33 | extern int sim_creat(const char *name); | ||
34 | |||
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}; | ||
39 | |||
40 | |||
41 | static unsigned long get_lcd_pixel(int x, int y) | ||
42 | { | ||
43 | return sim_lcd_framebuffer[y][x]; | ||
44 | } | ||
45 | |||
46 | void sim_lcd_update_rect(int x_start, int y_start, int width, int height) | ||
47 | { | ||
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); | ||
53 | } | ||
54 | |||
55 | void lcd_update(void) | ||
56 | { | ||
57 | int x, y; | ||
58 | |||
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); | ||
62 | |||
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]); | ||
66 | |||
67 | if (lcd_cursor.visible) | ||
68 | lcd_print_char(lcd_cursor.x, lcd_cursor.y, lcd_cursor.hw_char); | ||
69 | |||
70 | sim_lcd_update_rect(0, ICON_HEIGHT, SIM_LCD_WIDTH, | ||
71 | LCD_HEIGHT*CHAR_HEIGHT*CHAR_PIXEL); | ||
72 | } | ||
73 | |||
74 | #if CONFIG_BACKLIGHT | ||
75 | void sim_backlight(int value) | ||
76 | { | ||
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)); | ||
83 | } | ||
84 | |||
85 | sim_lcd_update_rect(0, 0, SIM_LCD_WIDTH, SIM_LCD_HEIGHT); | ||
86 | } | ||
87 | #endif | ||
88 | |||
89 | /* initialise simulator lcd driver */ | ||
90 | void sim_lcd_init(void) | ||
91 | { | ||
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); | ||
96 | |||
97 | sdl_set_gradient(lcd_surface, &lcd_backlight_color_zero, &lcd_color_max, | ||
98 | 0, (1<<LCD_DEPTH)); | ||
99 | } | ||
100 | |||
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) | ||
105 | |||
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) | ||
109 | |||
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 | ||
112 | |||
113 | static const unsigned char bmpheader[] = | ||
114 | { | ||
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 */ | ||
119 | |||
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 */ | ||
131 | |||
132 | 0x90, 0xee, 0x90, 0x00, /* Colour #0 */ | ||
133 | 0x00, 0x00, 0x00, 0x00 /* Colour #1 */ | ||
134 | }; | ||
135 | |||
136 | void screen_dump(void) | ||
137 | { | ||
138 | int fd; | ||
139 | char filename[MAX_PATH]; | ||
140 | int x, y; | ||
141 | static unsigned char line[BMP_LINESIZE]; | ||
142 | |||
143 | create_numbered_filename(filename, "", "dump_", ".bmp", 4 | ||
144 | IF_CNFN_NUM_(, NULL)); | ||
145 | DEBUGF("screen_dump\n"); | ||
146 | |||
147 | fd = sim_creat(filename); | ||
148 | if (fd < 0) | ||
149 | return; | ||
150 | |||
151 | write(fd, bmpheader, sizeof(bmpheader)); | ||
152 | SDL_LockSurface(lcd_surface); | ||
153 | |||
154 | /* BMP image goes bottom up */ | ||
155 | for (y = SIM_LCD_HEIGHT - 1; y >= 0; y--) | ||
156 | { | ||
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; | ||
161 | |||
162 | memset(line, 0, sizeof(line)); | ||
163 | for (x = SIM_LCD_WIDTH; x > 0; x--) | ||
164 | { | ||
165 | if (*src) | ||
166 | *dst |= dst_mask; | ||
167 | src += display_zoom; | ||
168 | dst_mask >>= 1; | ||
169 | if (dst_mask == 0) | ||
170 | { | ||
171 | dst++; | ||
172 | dst_mask = 0x80; | ||
173 | } | ||
174 | } | ||
175 | write(fd, line, sizeof(line)); | ||
176 | } | ||
177 | SDL_UnlockSurface(lcd_surface); | ||
178 | close(fd); | ||
179 | } | ||