2006-02-09 21:49:28 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 Dan Everton
|
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2006-02-09 21:49:28 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2010-05-15 21:02:47 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include "system.h"
|
2006-05-23 07:48:43 +00:00
|
|
|
#include "debug.h"
|
2006-02-09 21:49:28 +00:00
|
|
|
#include "lcd.h"
|
2007-03-31 09:58:49 +00:00
|
|
|
#include "lcd-charcell.h"
|
2009-02-11 00:10:35 +00:00
|
|
|
#include "screendump.h"
|
2009-08-19 22:36:39 +00:00
|
|
|
#include "general.h"
|
2006-05-23 07:48:43 +00:00
|
|
|
|
2006-02-09 21:49:28 +00:00
|
|
|
#include "lcd-playersim.h"
|
2010-05-15 21:02:47 +00:00
|
|
|
#include "sim-ui-defines.h"
|
2006-02-09 21:49:28 +00:00
|
|
|
#include "lcd-sdl.h"
|
|
|
|
|
2009-08-19 22:36:39 +00:00
|
|
|
/* can't include file.h here */
|
|
|
|
#ifndef MAX_PATH
|
|
|
|
#define MAX_PATH 260
|
|
|
|
#endif
|
|
|
|
|
2006-05-23 07:48:43 +00:00
|
|
|
/* extern functions, needed for screendump() */
|
2010-05-06 17:35:04 +00:00
|
|
|
extern int sim_creat(const char *name, mode_t mode);
|
2006-05-23 07:48:43 +00:00
|
|
|
|
2006-02-09 21:49:28 +00:00
|
|
|
SDL_Surface* lcd_surface;
|
2009-02-09 00:32:59 +00:00
|
|
|
|
|
|
|
SDL_Color lcd_bl_color_dark = {RED_CMP(LCD_BL_DARKCOLOR),
|
|
|
|
GREEN_CMP(LCD_BL_DARKCOLOR),
|
|
|
|
BLUE_CMP(LCD_BL_DARKCOLOR), 0};
|
|
|
|
SDL_Color lcd_bl_color_bright = {RED_CMP(LCD_BL_BRIGHTCOLOR),
|
|
|
|
GREEN_CMP(LCD_BL_BRIGHTCOLOR),
|
|
|
|
BLUE_CMP(LCD_BL_BRIGHTCOLOR), 0};
|
|
|
|
SDL_Color lcd_color_dark = {RED_CMP(LCD_DARKCOLOR),
|
|
|
|
GREEN_CMP(LCD_DARKCOLOR),
|
|
|
|
BLUE_CMP(LCD_DARKCOLOR), 0};
|
|
|
|
SDL_Color lcd_color_bright = {RED_CMP(LCD_BRIGHTCOLOR),
|
|
|
|
GREEN_CMP(LCD_BRIGHTCOLOR),
|
|
|
|
BLUE_CMP(LCD_BRIGHTCOLOR), 0};
|
2006-02-09 21:49:28 +00:00
|
|
|
|
|
|
|
|
2007-03-31 09:58:49 +00:00
|
|
|
static unsigned long get_lcd_pixel(int x, int y)
|
2006-02-09 21:49:28 +00:00
|
|
|
{
|
2007-03-31 09:58:49 +00:00
|
|
|
return sim_lcd_framebuffer[y][x];
|
2006-02-09 21:49:28 +00:00
|
|
|
}
|
|
|
|
|
2007-03-31 09:58:49 +00:00
|
|
|
void sim_lcd_update_rect(int x_start, int y_start, int width, int height)
|
2006-02-09 21:49:28 +00:00
|
|
|
{
|
2007-03-31 09:58:49 +00:00
|
|
|
sdl_update_rect(lcd_surface, x_start, y_start, width, height,
|
|
|
|
SIM_LCD_WIDTH, SIM_LCD_HEIGHT, get_lcd_pixel);
|
|
|
|
sdl_gui_update(lcd_surface, x_start, y_start, width, height,
|
|
|
|
SIM_LCD_WIDTH, SIM_LCD_HEIGHT,
|
|
|
|
background ? UI_LCD_POSX : 0, background ? UI_LCD_POSY : 0);
|
2006-02-09 21:49:28 +00:00
|
|
|
}
|
|
|
|
|
2007-03-31 09:58:49 +00:00
|
|
|
void lcd_update(void)
|
2006-02-09 21:49:28 +00:00
|
|
|
{
|
2007-03-31 09:58:49 +00:00
|
|
|
int x, y;
|
2006-02-09 21:49:28 +00:00
|
|
|
|
2007-03-31 09:58:49 +00:00
|
|
|
for (y = 0; y < lcd_pattern_count; y++)
|
|
|
|
if (lcd_patterns[y].count > 0)
|
|
|
|
sim_lcd_define_pattern(y, lcd_patterns[y].pattern);
|
2006-02-09 21:49:28 +00:00
|
|
|
|
2007-03-31 09:58:49 +00:00
|
|
|
for (y = 0; y < LCD_HEIGHT; y++)
|
|
|
|
for (x = 0; x < LCD_WIDTH; x++)
|
|
|
|
lcd_print_char(x, y, lcd_charbuffer[y][x]);
|
2006-02-09 21:49:28 +00:00
|
|
|
|
2007-03-31 09:58:49 +00:00
|
|
|
if (lcd_cursor.visible)
|
|
|
|
lcd_print_char(lcd_cursor.x, lcd_cursor.y, lcd_cursor.hw_char);
|
|
|
|
|
|
|
|
sim_lcd_update_rect(0, ICON_HEIGHT, SIM_LCD_WIDTH,
|
|
|
|
LCD_HEIGHT*CHAR_HEIGHT*CHAR_PIXEL);
|
2006-02-09 21:49:28 +00:00
|
|
|
}
|
|
|
|
|
2007-04-12 22:12:13 +00:00
|
|
|
#ifdef HAVE_BACKLIGHT
|
2006-02-13 21:46:28 +00:00
|
|
|
void sim_backlight(int value)
|
|
|
|
{
|
|
|
|
if (value > 0) {
|
2009-02-09 00:32:59 +00:00
|
|
|
sdl_set_gradient(lcd_surface, &lcd_bl_color_bright,
|
|
|
|
&lcd_bl_color_dark, 0, (1<<LCD_DEPTH));
|
2006-02-13 21:46:28 +00:00
|
|
|
} else {
|
2009-02-09 00:32:59 +00:00
|
|
|
sdl_set_gradient(lcd_surface, &lcd_color_bright,
|
|
|
|
&lcd_color_dark, 0, (1<<LCD_DEPTH));
|
2006-02-13 21:46:28 +00:00
|
|
|
}
|
2007-03-31 09:58:49 +00:00
|
|
|
|
|
|
|
sim_lcd_update_rect(0, 0, SIM_LCD_WIDTH, SIM_LCD_HEIGHT);
|
2006-02-13 21:46:28 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2006-02-09 21:49:28 +00:00
|
|
|
/* initialise simulator lcd driver */
|
2010-05-18 12:27:20 +00:00
|
|
|
void lcd_init_device(void)
|
2006-02-09 21:49:28 +00:00
|
|
|
{
|
2007-03-26 07:52:13 +00:00
|
|
|
lcd_surface = SDL_CreateRGBSurface(SDL_SWSURFACE,
|
|
|
|
SIM_LCD_WIDTH * display_zoom,
|
|
|
|
SIM_LCD_HEIGHT * display_zoom,
|
|
|
|
8, 0, 0, 0, 0);
|
2006-02-09 21:49:28 +00:00
|
|
|
|
2009-02-09 00:32:59 +00:00
|
|
|
sdl_set_gradient(lcd_surface, &lcd_bl_color_bright,
|
|
|
|
&lcd_bl_color_dark, 0, (1<<LCD_DEPTH));
|
2006-02-09 21:49:28 +00:00
|
|
|
}
|
|
|
|
|
2006-05-23 07:48:43 +00:00
|
|
|
#define BMP_COMPRESSION 0 /* BI_RGB */
|
|
|
|
#define BMP_NUMCOLORS (1 << LCD_DEPTH)
|
|
|
|
#define BMP_BPP 1
|
2007-03-26 07:52:13 +00:00
|
|
|
#define BMP_LINESIZE (((SIM_LCD_WIDTH + 31) / 32) * 4)
|
2006-05-23 07:48:43 +00:00
|
|
|
|
|
|
|
#define BMP_HEADERSIZE (54 + 4 * BMP_NUMCOLORS)
|
2007-03-26 07:52:13 +00:00
|
|
|
#define BMP_DATASIZE (BMP_LINESIZE * SIM_LCD_HEIGHT)
|
2006-05-23 07:48:43 +00:00
|
|
|
#define BMP_TOTALSIZE (BMP_HEADERSIZE + BMP_DATASIZE)
|
|
|
|
|
|
|
|
#define LE16_CONST(x) (x)&0xff, ((x)>>8)&0xff
|
|
|
|
#define LE32_CONST(x) (x)&0xff, ((x)>>8)&0xff, ((x)>>16)&0xff, ((x)>>24)&0xff
|
|
|
|
|
|
|
|
static const unsigned char bmpheader[] =
|
|
|
|
{
|
|
|
|
0x42, 0x4d, /* 'BM' */
|
|
|
|
LE32_CONST(BMP_TOTALSIZE), /* Total file size */
|
|
|
|
0x00, 0x00, 0x00, 0x00, /* Reserved */
|
|
|
|
LE32_CONST(BMP_HEADERSIZE), /* Offset to start of pixel data */
|
|
|
|
|
|
|
|
0x28, 0x00, 0x00, 0x00, /* Size of (2nd) header */
|
2007-03-26 07:52:13 +00:00
|
|
|
LE32_CONST(SIM_LCD_WIDTH), /* Width in pixels */
|
|
|
|
LE32_CONST(SIM_LCD_HEIGHT), /* Height in pixels */
|
2006-05-23 07:48:43 +00:00
|
|
|
0x01, 0x00, /* Number of planes (always 1) */
|
|
|
|
LE16_CONST(BMP_BPP), /* Bits per pixel 1/4/8/16/24 */
|
|
|
|
LE32_CONST(BMP_COMPRESSION),/* Compression mode */
|
|
|
|
LE32_CONST(BMP_DATASIZE), /* Size of bitmap data */
|
|
|
|
0xc4, 0x0e, 0x00, 0x00, /* Horizontal resolution (pixels/meter) */
|
|
|
|
0xc4, 0x0e, 0x00, 0x00, /* Vertical resolution (pixels/meter) */
|
|
|
|
LE32_CONST(BMP_NUMCOLORS), /* Number of used colours */
|
|
|
|
LE32_CONST(BMP_NUMCOLORS), /* Number of important colours */
|
|
|
|
|
2009-02-09 00:32:59 +00:00
|
|
|
BMP_COLOR(LCD_BL_BRIGHTCOLOR),
|
|
|
|
BMP_COLOR(LCD_BL_DARKCOLOR)
|
2006-05-23 07:48:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void screen_dump(void)
|
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
char filename[MAX_PATH];
|
|
|
|
int x, y;
|
|
|
|
static unsigned char line[BMP_LINESIZE];
|
|
|
|
|
2006-11-06 18:36:10 +00:00
|
|
|
create_numbered_filename(filename, "", "dump_", ".bmp", 4
|
2006-11-06 18:07:30 +00:00
|
|
|
IF_CNFN_NUM_(, NULL));
|
2006-05-23 07:48:43 +00:00
|
|
|
DEBUGF("screen_dump\n");
|
|
|
|
|
2010-05-06 17:35:04 +00:00
|
|
|
fd = sim_creat(filename, 0666);
|
2006-05-23 07:48:43 +00:00
|
|
|
if (fd < 0)
|
|
|
|
return;
|
|
|
|
|
2012-04-03 18:59:11 +00:00
|
|
|
if(write(fd, bmpheader, sizeof(bmpheader)) != sizeof(bmpheader))
|
|
|
|
{
|
|
|
|
close(fd);
|
|
|
|
return;
|
|
|
|
}
|
2006-05-23 07:48:43 +00:00
|
|
|
SDL_LockSurface(lcd_surface);
|
|
|
|
|
|
|
|
/* BMP image goes bottom up */
|
2007-03-26 07:52:13 +00:00
|
|
|
for (y = SIM_LCD_HEIGHT - 1; y >= 0; y--)
|
2006-05-23 07:48:43 +00:00
|
|
|
{
|
|
|
|
Uint8 *src = (Uint8 *)lcd_surface->pixels
|
2007-03-26 07:52:13 +00:00
|
|
|
+ y * SIM_LCD_WIDTH * display_zoom * display_zoom;
|
2006-05-23 07:48:43 +00:00
|
|
|
unsigned char *dst = line;
|
|
|
|
unsigned dst_mask = 0x80;
|
|
|
|
|
|
|
|
memset(line, 0, sizeof(line));
|
2007-03-26 07:52:13 +00:00
|
|
|
for (x = SIM_LCD_WIDTH; x > 0; x--)
|
2006-05-23 07:48:43 +00:00
|
|
|
{
|
|
|
|
if (*src)
|
|
|
|
*dst |= dst_mask;
|
|
|
|
src += display_zoom;
|
|
|
|
dst_mask >>= 1;
|
|
|
|
if (dst_mask == 0)
|
|
|
|
{
|
|
|
|
dst++;
|
|
|
|
dst_mask = 0x80;
|
|
|
|
}
|
|
|
|
}
|
2012-04-03 18:59:11 +00:00
|
|
|
if(write(fd, line, sizeof(line)) != sizeof(line))
|
|
|
|
{
|
|
|
|
close(fd);
|
|
|
|
return;
|
|
|
|
}
|
2006-05-23 07:48:43 +00:00
|
|
|
}
|
|
|
|
SDL_UnlockSurface(lcd_surface);
|
|
|
|
close(fd);
|
|
|
|
}
|