Fix %Sp expansion in wps
[kugel-rb.git] / uisimulator / sdl / lcd-charcells.c
blob5a06af53abe7c44ab946407d273877df0a07fff5
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2006 Dan Everton
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.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #include "debug.h"
23 #include "lcd.h"
24 #include "lcd-charcell.h"
25 #include "screendump.h"
26 #include "general.h"
27 #include <string.h>
28 #include <unistd.h>
29 #include <fcntl.h>
31 #include "lcd-playersim.h"
32 #include "uisdl.h"
33 #include "lcd-sdl.h"
35 /* can't include file.h here */
36 #ifndef MAX_PATH
37 #define MAX_PATH 260
38 #endif
40 /* extern functions, needed for screendump() */
41 extern int sim_creat(const char *name);
43 SDL_Surface* lcd_surface;
45 SDL_Color lcd_bl_color_dark = {RED_CMP(LCD_BL_DARKCOLOR),
46 GREEN_CMP(LCD_BL_DARKCOLOR),
47 BLUE_CMP(LCD_BL_DARKCOLOR), 0};
48 SDL_Color lcd_bl_color_bright = {RED_CMP(LCD_BL_BRIGHTCOLOR),
49 GREEN_CMP(LCD_BL_BRIGHTCOLOR),
50 BLUE_CMP(LCD_BL_BRIGHTCOLOR), 0};
51 SDL_Color lcd_color_dark = {RED_CMP(LCD_DARKCOLOR),
52 GREEN_CMP(LCD_DARKCOLOR),
53 BLUE_CMP(LCD_DARKCOLOR), 0};
54 SDL_Color lcd_color_bright = {RED_CMP(LCD_BRIGHTCOLOR),
55 GREEN_CMP(LCD_BRIGHTCOLOR),
56 BLUE_CMP(LCD_BRIGHTCOLOR), 0};
59 static unsigned long get_lcd_pixel(int x, int y)
61 return sim_lcd_framebuffer[y][x];
64 void sim_lcd_update_rect(int x_start, int y_start, int width, int height)
66 sdl_update_rect(lcd_surface, x_start, y_start, width, height,
67 SIM_LCD_WIDTH, SIM_LCD_HEIGHT, get_lcd_pixel);
68 sdl_gui_update(lcd_surface, x_start, y_start, width, height,
69 SIM_LCD_WIDTH, SIM_LCD_HEIGHT,
70 background ? UI_LCD_POSX : 0, background ? UI_LCD_POSY : 0);
73 void lcd_update(void)
75 int x, y;
77 for (y = 0; y < lcd_pattern_count; y++)
78 if (lcd_patterns[y].count > 0)
79 sim_lcd_define_pattern(y, lcd_patterns[y].pattern);
81 for (y = 0; y < LCD_HEIGHT; y++)
82 for (x = 0; x < LCD_WIDTH; x++)
83 lcd_print_char(x, y, lcd_charbuffer[y][x]);
85 if (lcd_cursor.visible)
86 lcd_print_char(lcd_cursor.x, lcd_cursor.y, lcd_cursor.hw_char);
88 sim_lcd_update_rect(0, ICON_HEIGHT, SIM_LCD_WIDTH,
89 LCD_HEIGHT*CHAR_HEIGHT*CHAR_PIXEL);
92 #ifdef HAVE_BACKLIGHT
93 void sim_backlight(int value)
95 if (value > 0) {
96 sdl_set_gradient(lcd_surface, &lcd_bl_color_bright,
97 &lcd_bl_color_dark, 0, (1<<LCD_DEPTH));
98 } else {
99 sdl_set_gradient(lcd_surface, &lcd_color_bright,
100 &lcd_color_dark, 0, (1<<LCD_DEPTH));
103 sim_lcd_update_rect(0, 0, SIM_LCD_WIDTH, SIM_LCD_HEIGHT);
105 #endif
107 /* initialise simulator lcd driver */
108 void sim_lcd_init(void)
110 lcd_surface = SDL_CreateRGBSurface(SDL_SWSURFACE,
111 SIM_LCD_WIDTH * display_zoom,
112 SIM_LCD_HEIGHT * display_zoom,
113 8, 0, 0, 0, 0);
115 sdl_set_gradient(lcd_surface, &lcd_bl_color_bright,
116 &lcd_bl_color_dark, 0, (1<<LCD_DEPTH));
119 #define BMP_COMPRESSION 0 /* BI_RGB */
120 #define BMP_NUMCOLORS (1 << LCD_DEPTH)
121 #define BMP_BPP 1
122 #define BMP_LINESIZE (((SIM_LCD_WIDTH + 31) / 32) * 4)
124 #define BMP_HEADERSIZE (54 + 4 * BMP_NUMCOLORS)
125 #define BMP_DATASIZE (BMP_LINESIZE * SIM_LCD_HEIGHT)
126 #define BMP_TOTALSIZE (BMP_HEADERSIZE + BMP_DATASIZE)
128 #define LE16_CONST(x) (x)&0xff, ((x)>>8)&0xff
129 #define LE32_CONST(x) (x)&0xff, ((x)>>8)&0xff, ((x)>>16)&0xff, ((x)>>24)&0xff
131 static const unsigned char bmpheader[] =
133 0x42, 0x4d, /* 'BM' */
134 LE32_CONST(BMP_TOTALSIZE), /* Total file size */
135 0x00, 0x00, 0x00, 0x00, /* Reserved */
136 LE32_CONST(BMP_HEADERSIZE), /* Offset to start of pixel data */
138 0x28, 0x00, 0x00, 0x00, /* Size of (2nd) header */
139 LE32_CONST(SIM_LCD_WIDTH), /* Width in pixels */
140 LE32_CONST(SIM_LCD_HEIGHT), /* Height in pixels */
141 0x01, 0x00, /* Number of planes (always 1) */
142 LE16_CONST(BMP_BPP), /* Bits per pixel 1/4/8/16/24 */
143 LE32_CONST(BMP_COMPRESSION),/* Compression mode */
144 LE32_CONST(BMP_DATASIZE), /* Size of bitmap data */
145 0xc4, 0x0e, 0x00, 0x00, /* Horizontal resolution (pixels/meter) */
146 0xc4, 0x0e, 0x00, 0x00, /* Vertical resolution (pixels/meter) */
147 LE32_CONST(BMP_NUMCOLORS), /* Number of used colours */
148 LE32_CONST(BMP_NUMCOLORS), /* Number of important colours */
150 BMP_COLOR(LCD_BL_BRIGHTCOLOR),
151 BMP_COLOR(LCD_BL_DARKCOLOR)
154 void screen_dump(void)
156 int fd;
157 char filename[MAX_PATH];
158 int x, y;
159 static unsigned char line[BMP_LINESIZE];
161 create_numbered_filename(filename, "", "dump_", ".bmp", 4
162 IF_CNFN_NUM_(, NULL));
163 DEBUGF("screen_dump\n");
165 fd = sim_creat(filename);
166 if (fd < 0)
167 return;
169 write(fd, bmpheader, sizeof(bmpheader));
170 SDL_LockSurface(lcd_surface);
172 /* BMP image goes bottom up */
173 for (y = SIM_LCD_HEIGHT - 1; y >= 0; y--)
175 Uint8 *src = (Uint8 *)lcd_surface->pixels
176 + y * SIM_LCD_WIDTH * display_zoom * display_zoom;
177 unsigned char *dst = line;
178 unsigned dst_mask = 0x80;
180 memset(line, 0, sizeof(line));
181 for (x = SIM_LCD_WIDTH; x > 0; x--)
183 if (*src)
184 *dst |= dst_mask;
185 src += display_zoom;
186 dst_mask >>= 1;
187 if (dst_mask == 0)
189 dst++;
190 dst_mask = 0x80;
193 write(fd, line, sizeof(line));
195 SDL_UnlockSurface(lcd_surface);
196 close(fd);