blob: 6f098587175a63c1be3f9265508eb6db997c0280 [file] [log] [blame]
Dan Evertonb585e872006-02-09 21:49:28 +00001/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2006 Dan Everton
11 *
Daniel Stenberg2acc0ac2008-06-28 18:10:04 +000012 * 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.
Dan Evertonb585e872006-02-09 21:49:28 +000016 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
Jens Arnold8325e0b2006-05-23 07:48:43 +000022#include "debug.h"
Dan Evertonb585e872006-02-09 21:49:28 +000023#include "lcd.h"
Jens Arnold54ea2e42007-03-31 09:58:49 +000024#include "lcd-charcell.h"
Jens Arnold8325e0b2006-05-23 07:48:43 +000025#include "misc.h"
26#include <string.h>
Jens Arnold25f38602006-05-23 10:00:11 +000027#include <unistd.h>
28#include <fcntl.h>
Jens Arnold8325e0b2006-05-23 07:48:43 +000029
Dan Evertonb585e872006-02-09 21:49:28 +000030#include "lcd-playersim.h"
31#include "uisdl.h"
32#include "lcd-sdl.h"
33
Jens Arnold8325e0b2006-05-23 07:48:43 +000034/* extern functions, needed for screendump() */
Jens Arnold67eb1542007-02-01 23:08:15 +000035extern int sim_creat(const char *name);
Jens Arnold8325e0b2006-05-23 07:48:43 +000036
Dan Evertonb585e872006-02-09 21:49:28 +000037SDL_Surface* lcd_surface;
Dan Everton3ba00602006-02-13 21:46:28 +000038SDL_Color lcd_color_zero = {UI_LCD_BGCOLOR, 0};
39SDL_Color lcd_backlight_color_zero = {UI_LCD_BGCOLORLIGHT, 0};
Robert Kukla3e3e1d52008-03-02 21:28:26 +000040SDL_Color lcd_color_max = {UI_LCD_FGCOLOR, 0};
41SDL_Color lcd_backlight_color_max = {UI_LCD_FGCOLORLIGHT, 0};
Dan Evertonb585e872006-02-09 21:49:28 +000042
Jens Arnold54ea2e42007-03-31 09:58:49 +000043
44static unsigned long get_lcd_pixel(int x, int y)
45{
46 return sim_lcd_framebuffer[y][x];
47}
48
49void sim_lcd_update_rect(int x_start, int y_start, int width, int height)
50{
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);
56}
Dan Evertonb585e872006-02-09 21:49:28 +000057
58void lcd_update(void)
59{
60 int x, y;
Dan Evertonb585e872006-02-09 21:49:28 +000061
Jens Arnold54ea2e42007-03-31 09:58:49 +000062 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);
Dan Evertonb585e872006-02-09 21:49:28 +000065
Jens Arnold54ea2e42007-03-31 09:58:49 +000066 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]);
Dan Evertonb585e872006-02-09 21:49:28 +000069
Jens Arnold54ea2e42007-03-31 09:58:49 +000070 if (lcd_cursor.visible)
71 lcd_print_char(lcd_cursor.x, lcd_cursor.y, lcd_cursor.hw_char);
72
73 sim_lcd_update_rect(0, ICON_HEIGHT, SIM_LCD_WIDTH,
74 LCD_HEIGHT*CHAR_HEIGHT*CHAR_PIXEL);
Dan Evertonb585e872006-02-09 21:49:28 +000075}
76
Jens Arnold47bf6c52007-04-12 22:12:13 +000077#ifdef HAVE_BACKLIGHT
Dan Everton3ba00602006-02-13 21:46:28 +000078void sim_backlight(int value)
79{
80 if (value > 0) {
Robert Kukla3e3e1d52008-03-02 21:28:26 +000081 sdl_set_gradient(lcd_surface, &lcd_backlight_color_zero,
82 &lcd_backlight_color_max,
Jens Arnold6a972e02006-02-26 13:37:42 +000083 0, (1<<LCD_DEPTH));
Dan Everton3ba00602006-02-13 21:46:28 +000084 } else {
Jens Arnold6a972e02006-02-26 13:37:42 +000085 sdl_set_gradient(lcd_surface, &lcd_color_zero, &lcd_color_max,
86 0, (1<<LCD_DEPTH));
Dan Everton3ba00602006-02-13 21:46:28 +000087 }
Jens Arnold54ea2e42007-03-31 09:58:49 +000088
89 sim_lcd_update_rect(0, 0, SIM_LCD_WIDTH, SIM_LCD_HEIGHT);
Dan Everton3ba00602006-02-13 21:46:28 +000090}
91#endif
92
Dan Evertonb585e872006-02-09 21:49:28 +000093/* initialise simulator lcd driver */
94void sim_lcd_init(void)
95{
Jens Arnoldad4e3d62007-03-26 07:52:13 +000096 lcd_surface = SDL_CreateRGBSurface(SDL_SWSURFACE,
97 SIM_LCD_WIDTH * display_zoom,
98 SIM_LCD_HEIGHT * display_zoom,
99 8, 0, 0, 0, 0);
Dan Evertonb585e872006-02-09 21:49:28 +0000100
Jens Arnold8325e0b2006-05-23 07:48:43 +0000101 sdl_set_gradient(lcd_surface, &lcd_backlight_color_zero, &lcd_color_max,
Jens Arnold6a972e02006-02-26 13:37:42 +0000102 0, (1<<LCD_DEPTH));
Dan Evertonb585e872006-02-09 21:49:28 +0000103}
104
Jens Arnold8325e0b2006-05-23 07:48:43 +0000105#define BMP_COMPRESSION 0 /* BI_RGB */
106#define BMP_NUMCOLORS (1 << LCD_DEPTH)
107#define BMP_BPP 1
Jens Arnoldad4e3d62007-03-26 07:52:13 +0000108#define BMP_LINESIZE (((SIM_LCD_WIDTH + 31) / 32) * 4)
Jens Arnold8325e0b2006-05-23 07:48:43 +0000109
110#define BMP_HEADERSIZE (54 + 4 * BMP_NUMCOLORS)
Jens Arnoldad4e3d62007-03-26 07:52:13 +0000111#define BMP_DATASIZE (BMP_LINESIZE * SIM_LCD_HEIGHT)
Jens Arnold8325e0b2006-05-23 07:48:43 +0000112#define BMP_TOTALSIZE (BMP_HEADERSIZE + BMP_DATASIZE)
113
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
116
117static const unsigned char bmpheader[] =
118{
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 */
123
124 0x28, 0x00, 0x00, 0x00, /* Size of (2nd) header */
Jens Arnoldad4e3d62007-03-26 07:52:13 +0000125 LE32_CONST(SIM_LCD_WIDTH), /* Width in pixels */
126 LE32_CONST(SIM_LCD_HEIGHT), /* Height in pixels */
Jens Arnold8325e0b2006-05-23 07:48:43 +0000127 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 */
135
136 0x90, 0xee, 0x90, 0x00, /* Colour #0 */
137 0x00, 0x00, 0x00, 0x00 /* Colour #1 */
138};
139
140void screen_dump(void)
141{
142 int fd;
143 char filename[MAX_PATH];
144 int x, y;
145 static unsigned char line[BMP_LINESIZE];
146
Michael Sevakis4aa01ed2006-11-06 18:36:10 +0000147 create_numbered_filename(filename, "", "dump_", ".bmp", 4
Michael Sevakis0f5cb942006-11-06 18:07:30 +0000148 IF_CNFN_NUM_(, NULL));
Jens Arnold8325e0b2006-05-23 07:48:43 +0000149 DEBUGF("screen_dump\n");
150
Jens Arnold67eb1542007-02-01 23:08:15 +0000151 fd = sim_creat(filename);
Jens Arnold8325e0b2006-05-23 07:48:43 +0000152 if (fd < 0)
153 return;
154
155 write(fd, bmpheader, sizeof(bmpheader));
156 SDL_LockSurface(lcd_surface);
157
158 /* BMP image goes bottom up */
Jens Arnoldad4e3d62007-03-26 07:52:13 +0000159 for (y = SIM_LCD_HEIGHT - 1; y >= 0; y--)
Jens Arnold8325e0b2006-05-23 07:48:43 +0000160 {
161 Uint8 *src = (Uint8 *)lcd_surface->pixels
Jens Arnoldad4e3d62007-03-26 07:52:13 +0000162 + y * SIM_LCD_WIDTH * display_zoom * display_zoom;
Jens Arnold8325e0b2006-05-23 07:48:43 +0000163 unsigned char *dst = line;
164 unsigned dst_mask = 0x80;
165
166 memset(line, 0, sizeof(line));
Jens Arnoldad4e3d62007-03-26 07:52:13 +0000167 for (x = SIM_LCD_WIDTH; x > 0; x--)
Jens Arnold8325e0b2006-05-23 07:48:43 +0000168 {
169 if (*src)
170 *dst |= dst_mask;
171 src += display_zoom;
172 dst_mask >>= 1;
173 if (dst_mask == 0)
174 {
175 dst++;
176 dst_mask = 0x80;
177 }
178 }
179 write(fd, line, sizeof(line));
180 }
181 SDL_UnlockSurface(lcd_surface);
182 close(fd);
183}