blob: 5f08b4440b089fbbd3dbab07d2fa28011fd346eb [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
Thomas Martitz3d0cee82010-05-15 21:02:47 +000022#include "sim-ui-defines.h"
Dan Evertonb585e872006-02-09 21:49:28 +000023#include "lcd-sdl.h"
Jens Arnold05ddd9a2006-07-28 07:35:45 +000024#include "lcd-remote-bitmap.h"
Jens Arnold11ad7b42009-02-10 23:43:37 +000025#include "screendump.h"
Thomas Martitz3d0cee82010-05-15 21:02:47 +000026#include "system.h" /* background */
Dan Evertonb585e872006-02-09 21:49:28 +000027
Steve Bavinb341f5d2009-10-26 09:58:39 +000028SDL_Surface *remote_surface = 0;
Dan Evertonb585e872006-02-09 21:49:28 +000029
Jens Arnold0d935ce2009-02-09 00:32:59 +000030SDL_Color remote_bl_color_dark = {RED_CMP(LCD_REMOTE_BL_DARKCOLOR),
31 GREEN_CMP(LCD_REMOTE_BL_DARKCOLOR),
32 BLUE_CMP(LCD_REMOTE_BL_DARKCOLOR), 0};
33SDL_Color remote_bl_color_bright = {RED_CMP(LCD_REMOTE_BL_BRIGHTCOLOR),
34 GREEN_CMP(LCD_REMOTE_BL_BRIGHTCOLOR),
35 BLUE_CMP(LCD_REMOTE_BL_BRIGHTCOLOR), 0};
36SDL_Color remote_color_dark = {RED_CMP(LCD_REMOTE_DARKCOLOR),
37 GREEN_CMP(LCD_REMOTE_DARKCOLOR),
38 BLUE_CMP(LCD_REMOTE_DARKCOLOR), 0};
39SDL_Color remote_color_bright = {RED_CMP(LCD_REMOTE_BRIGHTCOLOR),
40 GREEN_CMP(LCD_REMOTE_BRIGHTCOLOR),
41 BLUE_CMP(LCD_REMOTE_BRIGHTCOLOR), 0};
Dan Evertonb585e872006-02-09 21:49:28 +000042
Jens Arnold11ad7b42009-02-10 23:43:37 +000043#define NUM_SHADES 129
Jens Arnold0d935ce2009-02-09 00:32:59 +000044
45#if LCD_REMOTE_DEPTH == 2
46/* Only defined for positive, non-split LCD for now */
47static const unsigned char colorindex[4] = {128, 85, 43, 0};
48#endif
49
50static unsigned long get_lcd_remote_pixel(int x, int y)
51{
Jens Arnold05ddd9a2006-07-28 07:35:45 +000052#if LCD_REMOTE_DEPTH == 1
Jonathan Gordonb37e6bc2012-02-22 21:18:05 +110053 return *FBREMOTEADDR(x, y/8) & (1 << (y & 7)) ? 0 : (NUM_SHADES-1);
Jens Arnold05ddd9a2006-07-28 07:35:45 +000054#elif LCD_REMOTE_DEPTH == 2
55#if LCD_REMOTE_PIXELFORMAT == VERTICAL_INTERLEAVED
Jonathan Gordonb37e6bc2012-02-22 21:18:05 +110056 unsigned bits = (*FBREMOTEADDR(x, y/8) >> (y & 7)) & 0x0101;
Jens Arnold0d935ce2009-02-09 00:32:59 +000057 return colorindex[(bits | (bits >> 7)) & 3];
Jens Arnold05ddd9a2006-07-28 07:35:45 +000058#endif
59#endif
Dan Evertonb585e872006-02-09 21:49:28 +000060}
61
62void lcd_remote_update (void)
63{
64 lcd_remote_update_rect(0, 0, LCD_REMOTE_WIDTH, LCD_REMOTE_HEIGHT);
65}
66
67void lcd_remote_update_rect(int x_start, int y_start, int width, int height)
68{
Steve Bavinb341f5d2009-10-26 09:58:39 +000069 if (remote_surface)
70 {
71 sdl_update_rect(remote_surface, x_start, y_start, width, height,
72 LCD_REMOTE_WIDTH, LCD_REMOTE_HEIGHT, get_lcd_remote_pixel);
73 sdl_gui_update(remote_surface, x_start, y_start, width, height,
74 LCD_REMOTE_WIDTH, LCD_REMOTE_HEIGHT, background ? UI_REMOTE_POSX : 0,
75 background ? UI_REMOTE_POSY : LCD_HEIGHT);
76 }
Dan Evertonb585e872006-02-09 21:49:28 +000077}
78
Dan Everton3ba00602006-02-13 21:46:28 +000079void sim_remote_backlight(int value)
80{
Steve Bavinb341f5d2009-10-26 09:58:39 +000081 if (remote_surface)
82 {
83 if (value > 0)
84 {
85 sdl_set_gradient(remote_surface, &remote_bl_color_dark,
86 &remote_bl_color_bright, 0, NUM_SHADES);
87 }
88 else
89 {
90 sdl_set_gradient(remote_surface, &remote_color_dark,
91 &remote_color_bright, 0, NUM_SHADES);
92 }
93 sdl_gui_update(remote_surface, 0, 0, LCD_REMOTE_WIDTH, LCD_REMOTE_HEIGHT,
94 LCD_REMOTE_WIDTH, LCD_REMOTE_HEIGHT,
95 background ? UI_REMOTE_POSX : 0,
96 background? UI_REMOTE_POSY : LCD_HEIGHT);
Dan Everton3ba00602006-02-13 21:46:28 +000097 }
98}
99
Dan Evertonb585e872006-02-09 21:49:28 +0000100/* initialise simulator lcd remote driver */
Thomas Martitz6cbc7012010-05-18 12:27:20 +0000101void lcd_remote_init_device(void)
Dan Evertonb585e872006-02-09 21:49:28 +0000102{
Thomas Martitz6cbc7012010-05-18 12:27:20 +0000103 if (!showremote)
104 return;
Dan Evertonb585e872006-02-09 21:49:28 +0000105 remote_surface = SDL_CreateRGBSurface(SDL_SWSURFACE,
Jens Arnold0d935ce2009-02-09 00:32:59 +0000106 LCD_REMOTE_WIDTH * display_zoom,
107 LCD_REMOTE_HEIGHT * display_zoom,
108 8, 0, 0, 0, 0);
Dan Evertonb585e872006-02-09 21:49:28 +0000109
Jens Arnold0d935ce2009-02-09 00:32:59 +0000110 sdl_set_gradient(remote_surface, &remote_bl_color_dark,
Jens Arnold11ad7b42009-02-10 23:43:37 +0000111 &remote_bl_color_bright, 0, NUM_SHADES);
Dan Evertonb585e872006-02-09 21:49:28 +0000112}
113