summaryrefslogtreecommitdiff
path: root/uisimulator/sdl/lcd-charcell.c
diff options
context:
space:
mode:
Diffstat (limited to 'uisimulator/sdl/lcd-charcell.c')
-rw-r--r--uisimulator/sdl/lcd-charcell.c89
1 files changed, 88 insertions, 1 deletions
diff --git a/uisimulator/sdl/lcd-charcell.c b/uisimulator/sdl/lcd-charcell.c
index 89c46f7738..9cc53381c6 100644
--- a/uisimulator/sdl/lcd-charcell.c
+++ b/uisimulator/sdl/lcd-charcell.c
@@ -17,11 +17,20 @@
17 * 17 *
18 ****************************************************************************/ 18 ****************************************************************************/
19 19
20#include "debug.h"
20#include "lcd.h" 21#include "lcd.h"
22#include "misc.h"
23#include <string.h>
24
21#include "lcd-playersim.h" 25#include "lcd-playersim.h"
22#include "uisdl.h" 26#include "uisdl.h"
23#include "lcd-sdl.h" 27#include "lcd-sdl.h"
24 28
29/* extern functions, needed for screendump() */
30extern int sim_creat(const char *name, mode_t mode);
31extern ssize_t write(int fd, const void *buf, size_t count);
32extern int close(int fd);
33
25SDL_Surface* lcd_surface; 34SDL_Surface* lcd_surface;
26SDL_Color lcd_color_zero = {UI_LCD_BGCOLOR, 0}; 35SDL_Color lcd_color_zero = {UI_LCD_BGCOLOR, 0};
27SDL_Color lcd_backlight_color_zero = {UI_LCD_BGCOLORLIGHT, 0}; 36SDL_Color lcd_backlight_color_zero = {UI_LCD_BGCOLORLIGHT, 0};
@@ -126,7 +135,85 @@ void sim_lcd_init(void)
126 lcd_surface = SDL_CreateRGBSurface(SDL_SWSURFACE, LCD_WIDTH * display_zoom, 135 lcd_surface = SDL_CreateRGBSurface(SDL_SWSURFACE, LCD_WIDTH * display_zoom,
127 LCD_HEIGHT * display_zoom, 8, 0, 0, 0, 0); 136 LCD_HEIGHT * display_zoom, 8, 0, 0, 0, 0);
128 137
129 sdl_set_gradient(lcd_surface, &lcd_backlight_color_zero, &lcd_color_max, 138 sdl_set_gradient(lcd_surface, &lcd_backlight_color_zero, &lcd_color_max,
130 0, (1<<LCD_DEPTH)); 139 0, (1<<LCD_DEPTH));
131} 140}
132 141
142#define BMP_COMPRESSION 0 /* BI_RGB */
143#define BMP_NUMCOLORS (1 << LCD_DEPTH)
144#define BMP_BPP 1
145#define BMP_LINESIZE (((LCD_WIDTH + 31) / 32) * 4)
146
147#define BMP_HEADERSIZE (54 + 4 * BMP_NUMCOLORS)
148#define BMP_DATASIZE (BMP_LINESIZE * LCD_HEIGHT)
149#define BMP_TOTALSIZE (BMP_HEADERSIZE + BMP_DATASIZE)
150
151#define LE16_CONST(x) (x)&0xff, ((x)>>8)&0xff
152#define LE32_CONST(x) (x)&0xff, ((x)>>8)&0xff, ((x)>>16)&0xff, ((x)>>24)&0xff
153
154static const unsigned char bmpheader[] =
155{
156 0x42, 0x4d, /* 'BM' */
157 LE32_CONST(BMP_TOTALSIZE), /* Total file size */
158 0x00, 0x00, 0x00, 0x00, /* Reserved */
159 LE32_CONST(BMP_HEADERSIZE), /* Offset to start of pixel data */
160
161 0x28, 0x00, 0x00, 0x00, /* Size of (2nd) header */
162 LE32_CONST(LCD_WIDTH), /* Width in pixels */
163 LE32_CONST(LCD_HEIGHT), /* Height in pixels */
164 0x01, 0x00, /* Number of planes (always 1) */
165 LE16_CONST(BMP_BPP), /* Bits per pixel 1/4/8/16/24 */
166 LE32_CONST(BMP_COMPRESSION),/* Compression mode */
167 LE32_CONST(BMP_DATASIZE), /* Size of bitmap data */
168 0xc4, 0x0e, 0x00, 0x00, /* Horizontal resolution (pixels/meter) */
169 0xc4, 0x0e, 0x00, 0x00, /* Vertical resolution (pixels/meter) */
170 LE32_CONST(BMP_NUMCOLORS), /* Number of used colours */
171 LE32_CONST(BMP_NUMCOLORS), /* Number of important colours */
172
173 0x90, 0xee, 0x90, 0x00, /* Colour #0 */
174 0x00, 0x00, 0x00, 0x00 /* Colour #1 */
175};
176
177void screen_dump(void)
178{
179 int fd;
180 char filename[MAX_PATH];
181 int x, y;
182 static unsigned char line[BMP_LINESIZE];
183
184 create_numbered_filename(filename, "", "dump_", ".bmp", 4);
185 DEBUGF("screen_dump\n");
186
187 fd = sim_creat(filename, 1 /*O_WRONLY*/);
188 if (fd < 0)
189 return;
190
191 write(fd, bmpheader, sizeof(bmpheader));
192 SDL_LockSurface(lcd_surface);
193
194 /* BMP image goes bottom up */
195 for (y = LCD_HEIGHT - 1; y >= 0; y--)
196 {
197 Uint8 *src = (Uint8 *)lcd_surface->pixels
198 + y * LCD_WIDTH * display_zoom * display_zoom;
199 unsigned char *dst = line;
200 unsigned dst_mask = 0x80;
201
202 memset(line, 0, sizeof(line));
203 for (x = LCD_WIDTH; x > 0; x--)
204 {
205 if (*src)
206 *dst |= dst_mask;
207 src += display_zoom;
208 dst_mask >>= 1;
209 if (dst_mask == 0)
210 {
211 dst++;
212 dst_mask = 0x80;
213 }
214 }
215 write(fd, line, sizeof(line));
216 }
217 SDL_UnlockSurface(lcd_surface);
218 close(fd);
219}