Update the API version too.
[kugel-rb.git] / uisimulator / sdl / lcd-charcells.c
blob6f098587175a63c1be3f9265508eb6db997c0280
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 "misc.h"
26 #include <string.h>
27 #include <unistd.h>
28 #include <fcntl.h>
30 #include "lcd-playersim.h"
31 #include "uisdl.h"
32 #include "lcd-sdl.h"
34 /* extern functions, needed for screendump() */
35 extern int sim_creat(const char *name);
37 SDL_Surface* lcd_surface;
38 SDL_Color lcd_color_zero = {UI_LCD_BGCOLOR, 0};
39 SDL_Color lcd_backlight_color_zero = {UI_LCD_BGCOLORLIGHT, 0};
40 SDL_Color lcd_color_max = {UI_LCD_FGCOLOR, 0};
41 SDL_Color lcd_backlight_color_max = {UI_LCD_FGCOLORLIGHT, 0};
44 static unsigned long get_lcd_pixel(int x, int y)
46 return sim_lcd_framebuffer[y][x];
49 void sim_lcd_update_rect(int x_start, int y_start, int width, int height)
51 sdl_update_rect(lcd_surface, x_start, y_start, width, height,
52 SIM_LCD_WIDTH, SIM_LCD_HEIGHT, get_lcd_pixel);
53 sdl_gui_update(lcd_surface, x_start, y_start, width, height,
54 SIM_LCD_WIDTH, SIM_LCD_HEIGHT,
55 background ? UI_LCD_POSX : 0, background ? UI_LCD_POSY : 0);
58 void lcd_update(void)
60 int x, y;
62 for (y = 0; y < lcd_pattern_count; y++)
63 if (lcd_patterns[y].count > 0)
64 sim_lcd_define_pattern(y, lcd_patterns[y].pattern);
66 for (y = 0; y < LCD_HEIGHT; y++)
67 for (x = 0; x < LCD_WIDTH; x++)
68 lcd_print_char(x, y, lcd_charbuffer[y][x]);
70 if (lcd_cursor.visible)
71 lcd_print_char(lcd_cursor.x, lcd_cursor.y, lcd_cursor.hw_char);
73 sim_lcd_update_rect(0, ICON_HEIGHT, SIM_LCD_WIDTH,
74 LCD_HEIGHT*CHAR_HEIGHT*CHAR_PIXEL);
77 #ifdef HAVE_BACKLIGHT
78 void sim_backlight(int value)
80 if (value > 0) {
81 sdl_set_gradient(lcd_surface, &lcd_backlight_color_zero,
82 &lcd_backlight_color_max,
83 0, (1<<LCD_DEPTH));
84 } else {
85 sdl_set_gradient(lcd_surface, &lcd_color_zero, &lcd_color_max,
86 0, (1<<LCD_DEPTH));
89 sim_lcd_update_rect(0, 0, SIM_LCD_WIDTH, SIM_LCD_HEIGHT);
91 #endif
93 /* initialise simulator lcd driver */
94 void sim_lcd_init(void)
96 lcd_surface = SDL_CreateRGBSurface(SDL_SWSURFACE,
97 SIM_LCD_WIDTH * display_zoom,
98 SIM_LCD_HEIGHT * display_zoom,
99 8, 0, 0, 0, 0);
101 sdl_set_gradient(lcd_surface, &lcd_backlight_color_zero, &lcd_color_max,
102 0, (1<<LCD_DEPTH));
105 #define BMP_COMPRESSION 0 /* BI_RGB */
106 #define BMP_NUMCOLORS (1 << LCD_DEPTH)
107 #define BMP_BPP 1
108 #define BMP_LINESIZE (((SIM_LCD_WIDTH + 31) / 32) * 4)
110 #define BMP_HEADERSIZE (54 + 4 * BMP_NUMCOLORS)
111 #define BMP_DATASIZE (BMP_LINESIZE * SIM_LCD_HEIGHT)
112 #define BMP_TOTALSIZE (BMP_HEADERSIZE + BMP_DATASIZE)
114 #define LE16_CONST(x) (x)&0xff, ((x)>>8)&0xff
115 #define LE32_CONST(x) (x)&0xff, ((x)>>8)&0xff, ((x)>>16)&0xff, ((x)>>24)&0xff
117 static const unsigned char bmpheader[] =
119 0x42, 0x4d, /* 'BM' */
120 LE32_CONST(BMP_TOTALSIZE), /* Total file size */
121 0x00, 0x00, 0x00, 0x00, /* Reserved */
122 LE32_CONST(BMP_HEADERSIZE), /* Offset to start of pixel data */
124 0x28, 0x00, 0x00, 0x00, /* Size of (2nd) header */
125 LE32_CONST(SIM_LCD_WIDTH), /* Width in pixels */
126 LE32_CONST(SIM_LCD_HEIGHT), /* Height in pixels */
127 0x01, 0x00, /* Number of planes (always 1) */
128 LE16_CONST(BMP_BPP), /* Bits per pixel 1/4/8/16/24 */
129 LE32_CONST(BMP_COMPRESSION),/* Compression mode */
130 LE32_CONST(BMP_DATASIZE), /* Size of bitmap data */
131 0xc4, 0x0e, 0x00, 0x00, /* Horizontal resolution (pixels/meter) */
132 0xc4, 0x0e, 0x00, 0x00, /* Vertical resolution (pixels/meter) */
133 LE32_CONST(BMP_NUMCOLORS), /* Number of used colours */
134 LE32_CONST(BMP_NUMCOLORS), /* Number of important colours */
136 0x90, 0xee, 0x90, 0x00, /* Colour #0 */
137 0x00, 0x00, 0x00, 0x00 /* Colour #1 */
140 void screen_dump(void)
142 int fd;
143 char filename[MAX_PATH];
144 int x, y;
145 static unsigned char line[BMP_LINESIZE];
147 create_numbered_filename(filename, "", "dump_", ".bmp", 4
148 IF_CNFN_NUM_(, NULL));
149 DEBUGF("screen_dump\n");
151 fd = sim_creat(filename);
152 if (fd < 0)
153 return;
155 write(fd, bmpheader, sizeof(bmpheader));
156 SDL_LockSurface(lcd_surface);
158 /* BMP image goes bottom up */
159 for (y = SIM_LCD_HEIGHT - 1; y >= 0; y--)
161 Uint8 *src = (Uint8 *)lcd_surface->pixels
162 + y * SIM_LCD_WIDTH * display_zoom * display_zoom;
163 unsigned char *dst = line;
164 unsigned dst_mask = 0x80;
166 memset(line, 0, sizeof(line));
167 for (x = SIM_LCD_WIDTH; x > 0; x--)
169 if (*src)
170 *dst |= dst_mask;
171 src += display_zoom;
172 dst_mask >>= 1;
173 if (dst_mask == 0)
175 dst++;
176 dst_mask = 0x80;
179 write(fd, line, sizeof(line));
181 SDL_UnlockSurface(lcd_surface);
182 close(fd);