Correct some comments (no functional changes)
[kugel-rb.git] / uisimulator / sdl / lcd-charcells.c
blob25611c90db17732344531567c3bbcfe813209edd
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 /* extern functions, needed for screendump() */
36 extern int sim_creat(const char *name);
38 SDL_Surface* lcd_surface;
40 SDL_Color lcd_bl_color_dark = {RED_CMP(LCD_BL_DARKCOLOR),
41 GREEN_CMP(LCD_BL_DARKCOLOR),
42 BLUE_CMP(LCD_BL_DARKCOLOR), 0};
43 SDL_Color lcd_bl_color_bright = {RED_CMP(LCD_BL_BRIGHTCOLOR),
44 GREEN_CMP(LCD_BL_BRIGHTCOLOR),
45 BLUE_CMP(LCD_BL_BRIGHTCOLOR), 0};
46 SDL_Color lcd_color_dark = {RED_CMP(LCD_DARKCOLOR),
47 GREEN_CMP(LCD_DARKCOLOR),
48 BLUE_CMP(LCD_DARKCOLOR), 0};
49 SDL_Color lcd_color_bright = {RED_CMP(LCD_BRIGHTCOLOR),
50 GREEN_CMP(LCD_BRIGHTCOLOR),
51 BLUE_CMP(LCD_BRIGHTCOLOR), 0};
54 static unsigned long get_lcd_pixel(int x, int y)
56 return sim_lcd_framebuffer[y][x];
59 void sim_lcd_update_rect(int x_start, int y_start, int width, int height)
61 sdl_update_rect(lcd_surface, x_start, y_start, width, height,
62 SIM_LCD_WIDTH, SIM_LCD_HEIGHT, get_lcd_pixel);
63 sdl_gui_update(lcd_surface, x_start, y_start, width, height,
64 SIM_LCD_WIDTH, SIM_LCD_HEIGHT,
65 background ? UI_LCD_POSX : 0, background ? UI_LCD_POSY : 0);
68 void lcd_update(void)
70 int x, y;
72 for (y = 0; y < lcd_pattern_count; y++)
73 if (lcd_patterns[y].count > 0)
74 sim_lcd_define_pattern(y, lcd_patterns[y].pattern);
76 for (y = 0; y < LCD_HEIGHT; y++)
77 for (x = 0; x < LCD_WIDTH; x++)
78 lcd_print_char(x, y, lcd_charbuffer[y][x]);
80 if (lcd_cursor.visible)
81 lcd_print_char(lcd_cursor.x, lcd_cursor.y, lcd_cursor.hw_char);
83 sim_lcd_update_rect(0, ICON_HEIGHT, SIM_LCD_WIDTH,
84 LCD_HEIGHT*CHAR_HEIGHT*CHAR_PIXEL);
87 #ifdef HAVE_BACKLIGHT
88 void sim_backlight(int value)
90 if (value > 0) {
91 sdl_set_gradient(lcd_surface, &lcd_bl_color_bright,
92 &lcd_bl_color_dark, 0, (1<<LCD_DEPTH));
93 } else {
94 sdl_set_gradient(lcd_surface, &lcd_color_bright,
95 &lcd_color_dark, 0, (1<<LCD_DEPTH));
98 sim_lcd_update_rect(0, 0, SIM_LCD_WIDTH, SIM_LCD_HEIGHT);
100 #endif
102 /* initialise simulator lcd driver */
103 void sim_lcd_init(void)
105 lcd_surface = SDL_CreateRGBSurface(SDL_SWSURFACE,
106 SIM_LCD_WIDTH * display_zoom,
107 SIM_LCD_HEIGHT * display_zoom,
108 8, 0, 0, 0, 0);
110 sdl_set_gradient(lcd_surface, &lcd_bl_color_bright,
111 &lcd_bl_color_dark, 0, (1<<LCD_DEPTH));
114 #define BMP_COMPRESSION 0 /* BI_RGB */
115 #define BMP_NUMCOLORS (1 << LCD_DEPTH)
116 #define BMP_BPP 1
117 #define BMP_LINESIZE (((SIM_LCD_WIDTH + 31) / 32) * 4)
119 #define BMP_HEADERSIZE (54 + 4 * BMP_NUMCOLORS)
120 #define BMP_DATASIZE (BMP_LINESIZE * SIM_LCD_HEIGHT)
121 #define BMP_TOTALSIZE (BMP_HEADERSIZE + BMP_DATASIZE)
123 #define LE16_CONST(x) (x)&0xff, ((x)>>8)&0xff
124 #define LE32_CONST(x) (x)&0xff, ((x)>>8)&0xff, ((x)>>16)&0xff, ((x)>>24)&0xff
126 static const unsigned char bmpheader[] =
128 0x42, 0x4d, /* 'BM' */
129 LE32_CONST(BMP_TOTALSIZE), /* Total file size */
130 0x00, 0x00, 0x00, 0x00, /* Reserved */
131 LE32_CONST(BMP_HEADERSIZE), /* Offset to start of pixel data */
133 0x28, 0x00, 0x00, 0x00, /* Size of (2nd) header */
134 LE32_CONST(SIM_LCD_WIDTH), /* Width in pixels */
135 LE32_CONST(SIM_LCD_HEIGHT), /* Height in pixels */
136 0x01, 0x00, /* Number of planes (always 1) */
137 LE16_CONST(BMP_BPP), /* Bits per pixel 1/4/8/16/24 */
138 LE32_CONST(BMP_COMPRESSION),/* Compression mode */
139 LE32_CONST(BMP_DATASIZE), /* Size of bitmap data */
140 0xc4, 0x0e, 0x00, 0x00, /* Horizontal resolution (pixels/meter) */
141 0xc4, 0x0e, 0x00, 0x00, /* Vertical resolution (pixels/meter) */
142 LE32_CONST(BMP_NUMCOLORS), /* Number of used colours */
143 LE32_CONST(BMP_NUMCOLORS), /* Number of important colours */
145 BMP_COLOR(LCD_BL_BRIGHTCOLOR),
146 BMP_COLOR(LCD_BL_DARKCOLOR)
149 void screen_dump(void)
151 int fd;
152 char filename[MAX_PATH];
153 int x, y;
154 static unsigned char line[BMP_LINESIZE];
156 create_numbered_filename(filename, "", "dump_", ".bmp", 4
157 IF_CNFN_NUM_(, NULL));
158 DEBUGF("screen_dump\n");
160 fd = sim_creat(filename);
161 if (fd < 0)
162 return;
164 write(fd, bmpheader, sizeof(bmpheader));
165 SDL_LockSurface(lcd_surface);
167 /* BMP image goes bottom up */
168 for (y = SIM_LCD_HEIGHT - 1; y >= 0; y--)
170 Uint8 *src = (Uint8 *)lcd_surface->pixels
171 + y * SIM_LCD_WIDTH * display_zoom * display_zoom;
172 unsigned char *dst = line;
173 unsigned dst_mask = 0x80;
175 memset(line, 0, sizeof(line));
176 for (x = SIM_LCD_WIDTH; x > 0; x--)
178 if (*src)
179 *dst |= dst_mask;
180 src += display_zoom;
181 dst_mask >>= 1;
182 if (dst_mask == 0)
184 dst++;
185 dst_mask = 0x80;
188 write(fd, line, sizeof(line));
190 SDL_UnlockSurface(lcd_surface);
191 close(fd);