summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--uisimulator/common/lcd-playersim.c2
-rw-r--r--uisimulator/sdl/SOURCES8
-rw-r--r--uisimulator/sdl/lcd-bitmap.c79
-rw-r--r--uisimulator/sdl/lcd-bitmap.h29
-rw-r--r--uisimulator/sdl/lcd-charcell.c115
-rw-r--r--uisimulator/sdl/lcd-charcell.h29
-rw-r--r--uisimulator/sdl/lcd-remote.c57
-rw-r--r--uisimulator/sdl/lcd-remote.h29
-rw-r--r--uisimulator/sdl/lcd-sdl.c297
-rw-r--r--uisimulator/sdl/lcd-sdl.h18
-rw-r--r--uisimulator/sdl/thread-sdl.h7
-rw-r--r--uisimulator/sdl/uisdl.c38
-rw-r--r--uisimulator/sdl/uisdl.h9
13 files changed, 431 insertions, 286 deletions
diff --git a/uisimulator/common/lcd-playersim.c b/uisimulator/common/lcd-playersim.c
index ea5b1da2f4..156f83e639 100644
--- a/uisimulator/common/lcd-playersim.c
+++ b/uisimulator/common/lcd-playersim.c
@@ -35,7 +35,7 @@
35#define CHAR_WIDTH 6 35#define CHAR_WIDTH 6
36#define CHAR_HEIGHT 8 36#define CHAR_HEIGHT 8
37#define ICON_HEIGHT 24 37#define ICON_HEIGHT 24
38#define CHAR_PIXEL 4 38#define CHAR_PIXEL 2
39#define BORDER_MARGIN 2 39#define BORDER_MARGIN 2
40 40
41static int double_height=1; 41static int double_height=1;
diff --git a/uisimulator/sdl/SOURCES b/uisimulator/sdl/SOURCES
index cbb39a4e6a..41890048de 100644
--- a/uisimulator/sdl/SOURCES
+++ b/uisimulator/sdl/SOURCES
@@ -1,5 +1,13 @@
1button.c 1button.c
2kernel.c 2kernel.c
3#ifdef HAVE_LCD_BITMAP
4lcd-bitmap.c
5#elif HAVE_LCD_CHARCELLS
6lcd-charcell.c
7#endif
8#ifdef HAVE_REMOTE_LCD
9lcd-remote.c
10#endif
3lcd-sdl.c 11lcd-sdl.c
4sound.c 12sound.c
5thread-sdl.c 13thread-sdl.c
diff --git a/uisimulator/sdl/lcd-bitmap.c b/uisimulator/sdl/lcd-bitmap.c
new file mode 100644
index 0000000000..db4a98d823
--- /dev/null
+++ b/uisimulator/sdl/lcd-bitmap.c
@@ -0,0 +1,79 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2006 Dan Everton
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19
20#include "uisdl.h"
21#include "lcd-sdl.h"
22
23SDL_Surface* lcd_surface;
24
25#if LCD_DEPTH <= 8
26SDL_Color lcd_color_zero = {UI_LCD_BGCOLORLIGHT, 0};
27SDL_Color lcd_color_max = {0, 0, 0, 0};
28#endif
29
30static inline Uint32 get_lcd_pixel(int x, int y)
31{
32#if LCD_DEPTH == 1
33 return ((lcd_framebuffer[y/8][x] >> (y & 7)) & 1);
34#elif LCD_DEPTH == 2
35#if LCD_PIXELFORMAT == HORIZONTAL_PACKING
36 return ((lcd_framebuffer[y][x/4] >> (2 * (x & 3))) & 3);
37#else
38 return ((lcd_framebuffer[y/4][x] >> (2 * (y & 3))) & 3);
39#endif
40#elif LCD_DEPTH == 16
41#if LCD_PIXELFORMAT == RGB565SWAPPED
42 unsigned bits = lcd_framebuffer[y][x];
43 return (bits >> 8) | (bits << 8);
44#else
45 return lcd_framebuffer[y][x];
46#endif
47#endif
48}
49
50void lcd_update(void)
51{
52 /* update a full screen rect */
53 lcd_update_rect(0, 0, LCD_WIDTH, LCD_HEIGHT);
54}
55
56void lcd_update_rect(int x_start, int y_start, int width, int height)
57{
58 sdl_update_rect(lcd_surface, x_start, y_start, width, height, LCD_WIDTH, LCD_HEIGHT,
59 background ? UI_LCD_POSX : 0, background? UI_LCD_POSY : 0,
60 get_lcd_pixel);
61}
62
63
64/* initialise simulator lcd driver */
65void sim_lcd_init(void)
66{
67#if LCD_DEPTH == 16
68 lcd_surface = SDL_CreateRGBSurface(SDL_SWSURFACE, LCD_WIDTH * display_zoom,
69 LCD_HEIGHT * display_zoom, LCD_DEPTH, 0, 0, 0, 0);
70#else
71 lcd_surface = SDL_CreateRGBSurface(SDL_SWSURFACE, LCD_WIDTH * display_zoom,
72 LCD_HEIGHT * display_zoom, 8, 0, 0, 0, 0);
73#endif
74
75#if LCD_DEPTH <= 8
76 sdl_set_gradient(lcd_surface, &lcd_color_zero, &lcd_color_max, (1<<LCD_DEPTH));
77#endif
78}
79
diff --git a/uisimulator/sdl/lcd-bitmap.h b/uisimulator/sdl/lcd-bitmap.h
new file mode 100644
index 0000000000..514c4d3ffb
--- /dev/null
+++ b/uisimulator/sdl/lcd-bitmap.h
@@ -0,0 +1,29 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2006 Dan Everton
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19
20#ifndef __LCDBITMAP_H__
21#define __LCDBITMAP_H__
22
23#include "lcd.h"
24#include "SDL.h"
25
26void sim_lcd_init(void);
27
28#endif // #ifndef __LCDBITMAP_H__
29
diff --git a/uisimulator/sdl/lcd-charcell.c b/uisimulator/sdl/lcd-charcell.c
new file mode 100644
index 0000000000..5f51e44810
--- /dev/null
+++ b/uisimulator/sdl/lcd-charcell.c
@@ -0,0 +1,115 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2006 Dan Everton
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19
20#include "lcd.h"
21#include "lcd-playersim.h"
22#include "uisdl.h"
23#include "lcd-sdl.h"
24
25SDL_Surface* lcd_surface;
26SDL_Color lcd_color_zero = {UI_LCD_BGCOLORLIGHT, 0};
27SDL_Color lcd_color_max = {0, 0, 0, 0};
28
29/* Defined in lcd-playersim.c */
30extern void lcd_print_char(int x, int y);
31
32void lcd_update(void)
33{
34 int x, y;
35 SDL_Rect dest = {UI_LCD_POSX, UI_LCD_POSY, UI_LCD_WIDTH, UI_LCD_HEIGHT};
36
37 SDL_LockSurface(lcd_surface);
38
39 for (y=0; y<2; y++) {
40 for (x=0; x<11; x++) {
41 lcd_print_char(x, y);
42 }
43 }
44
45 SDL_UnlockSurface(lcd_surface);
46
47 if (!background) {
48 dest.x -= UI_LCD_POSX;
49 dest.y -= UI_LCD_POSY;
50 }
51
52 SDL_BlitSurface(lcd_surface, NULL, gui_surface, &dest);
53 SDL_UpdateRect(gui_surface, dest.x, dest.y, dest.w, dest.h);
54 SDL_Flip(gui_surface);
55}
56
57void drawdots(int color, struct coordinate *points, int count)
58{
59 SDL_Rect dest;
60 Uint32 sdlcolor;
61
62 SDL_LockSurface(lcd_surface);
63
64 if (color == 1) {
65 sdlcolor = SDL_MapRGB(lcd_surface->format, lcd_color_max.r, lcd_color_max.g, lcd_color_max.b);
66 } else {
67 sdlcolor = SDL_MapRGB(lcd_surface->format, lcd_color_zero.r, lcd_color_zero.g, lcd_color_zero.b);
68 }
69
70 while (count--) {
71 dest.x = points[count].x * display_zoom;
72 dest.y = points[count].y * display_zoom;
73 dest.w = 1 * display_zoom;
74 dest.h = 1 * display_zoom;
75
76 SDL_FillRect(lcd_surface, &dest, sdlcolor);
77 }
78
79 SDL_UnlockSurface(lcd_surface);
80}
81
82void drawrectangles(int color, struct rectangle *points, int count)
83{
84 SDL_Rect dest;
85 Uint32 sdlcolor;
86
87 SDL_LockSurface(lcd_surface);
88
89 if (color == 1) {
90 sdlcolor = SDL_MapRGB(lcd_surface->format, lcd_color_max.r, lcd_color_max.g, lcd_color_max.b);
91 } else {
92 sdlcolor = SDL_MapRGB(lcd_surface->format, lcd_color_zero.r, lcd_color_zero.g, lcd_color_zero.b);
93 }
94
95 while (count--) {
96 dest.x = points[count].x * display_zoom;
97 dest.y = points[count].y * display_zoom;
98 dest.w = points[count].width * display_zoom;
99 dest.h = points[count].height * display_zoom;
100
101 SDL_FillRect(lcd_surface, &dest, sdlcolor);
102 }
103
104 SDL_UnlockSurface(lcd_surface);
105}
106
107/* initialise simulator lcd driver */
108void sim_lcd_init(void)
109{
110 lcd_surface = SDL_CreateRGBSurface(SDL_SWSURFACE, LCD_WIDTH * display_zoom,
111 LCD_HEIGHT * display_zoom, 8, 0, 0, 0, 0);
112
113 sdl_set_gradient(lcd_surface, &lcd_color_zero, &lcd_color_max, (1<<LCD_DEPTH));
114}
115
diff --git a/uisimulator/sdl/lcd-charcell.h b/uisimulator/sdl/lcd-charcell.h
new file mode 100644
index 0000000000..e82412f574
--- /dev/null
+++ b/uisimulator/sdl/lcd-charcell.h
@@ -0,0 +1,29 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2006 Dan Everton
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19
20#ifndef __LCDCHARCELL_H__
21#define __LCDCHARCELL_H__
22
23#include "lcd.h"
24#include "SDL.h"
25
26void sim_lcd_init(void);
27
28#endif // #ifndef __LCDCHARCELL_H__
29
diff --git a/uisimulator/sdl/lcd-remote.c b/uisimulator/sdl/lcd-remote.c
new file mode 100644
index 0000000000..4d592e67f5
--- /dev/null
+++ b/uisimulator/sdl/lcd-remote.c
@@ -0,0 +1,57 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2006 Dan Everton
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19
20#include "uisdl.h"
21#include "lcd-sdl.h"
22#include "lcd-remote.h"
23
24SDL_Surface *remote_surface;
25
26SDL_Color remote_color_zero = {UI_REMOTE_BGCOLORLIGHT, 0};
27SDL_Color remote_color_max = {0, 0, 0, 0};
28
29extern unsigned char lcd_remote_framebuffer[LCD_REMOTE_HEIGHT/8][LCD_REMOTE_WIDTH];
30
31static inline Uint32 get_lcd_remote_pixel(int x, int y) {
32 return ((lcd_remote_framebuffer[y/8][x] >> (y & 7)) & 1);
33}
34
35void lcd_remote_update (void)
36{
37 lcd_remote_update_rect(0, 0, LCD_REMOTE_WIDTH, LCD_REMOTE_HEIGHT);
38}
39
40void lcd_remote_update_rect(int x_start, int y_start, int width, int height)
41{
42 sdl_update_rect(remote_surface, x_start, y_start, width, height,
43 LCD_REMOTE_WIDTH, LCD_REMOTE_HEIGHT, background ? UI_REMOTE_POSX : 0,
44 (background? UI_REMOTE_POSY : 0) + UI_LCD_HEIGHT, get_lcd_remote_pixel);
45}
46
47/* initialise simulator lcd remote driver */
48void sim_lcd_remote_init(void)
49{
50 remote_surface = SDL_CreateRGBSurface(SDL_SWSURFACE,
51 LCD_REMOTE_WIDTH * display_zoom, LCD_REMOTE_HEIGHT * display_zoom,
52 8, 0, 0, 0, 0);
53
54 sdl_set_gradient(remote_surface, &remote_color_zero, &remote_color_max,
55 (1<<LCD_REMOTE_DEPTH));
56}
57
diff --git a/uisimulator/sdl/lcd-remote.h b/uisimulator/sdl/lcd-remote.h
new file mode 100644
index 0000000000..aebe304fb9
--- /dev/null
+++ b/uisimulator/sdl/lcd-remote.h
@@ -0,0 +1,29 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2006 Dan Everton
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19
20#ifndef __LCDREMOTE_H__
21#define __LCDREMOTE_H__
22
23#include "lcd.h"
24#include "SDL.h"
25
26void sim_lcd_remote_init(void);
27
28#endif // #ifndef __LCDREMOTE_H__
29
diff --git a/uisimulator/sdl/lcd-sdl.c b/uisimulator/sdl/lcd-sdl.c
index 1a6e8da8e8..4a0962dbec 100644
--- a/uisimulator/sdl/lcd-sdl.c
+++ b/uisimulator/sdl/lcd-sdl.c
@@ -17,296 +17,67 @@
17 * 17 *
18 ****************************************************************************/ 18 ****************************************************************************/
19 19
20#include "lcd-sdl.h"
20#include "uisdl.h" 21#include "uisdl.h"
21#include "lcd.h"
22#include "lcd-playersim.h"
23 22
24SDL_Surface* lcd_surface; 23int display_zoom = 1;
25 24
26#if LCD_DEPTH == 16 25void sdl_update_rect(SDL_Surface *surface, int x_start, int y_start, int width,
27#else 26 int height, int max_x, int max_y, int ui_x, int ui_y,
28SDL_Color lcd_palette[(1<<LCD_DEPTH)]; 27 Uint32 (*getpixel)(int, int))
29SDL_Color lcd_color_zero = {UI_LCD_BGCOLORLIGHT, 0};
30SDL_Color lcd_color_max = {0, 0, 0, 0};
31
32#endif
33
34#ifdef HAVE_LCD_BITMAP
35
36#ifdef HAVE_REMOTE_LCD
37SDL_Surface *remote_surface;
38SDL_Color remote_palette[(1<<LCD_REMOTE_DEPTH)];
39SDL_Color remote_color_zero = {UI_REMOTE_BGCOLORLIGHT, 0};
40SDL_Color remote_color_max = {0, 0, 0, 0};
41
42#endif
43
44void lcd_update (void)
45{
46 /* update a full screen rect */
47 lcd_update_rect(0, 0, LCD_WIDTH, LCD_HEIGHT);
48}
49
50void lcd_update_rect(int x_start, int y_start, int width, int height)
51{ 28{
52 int x, y; 29 int x, y;
53 int xmax, ymax; 30 int xmax, ymax;
31 SDL_Rect dest;
54 32
55 ymax = y_start + height; 33 ymax = y_start + height;
56 xmax = x_start + width; 34 xmax = x_start + width;
57 35
58 if(xmax > LCD_WIDTH) 36 if(xmax > max_x)
59 xmax = LCD_WIDTH; 37 xmax = max_x;
60 if(ymax >= LCD_HEIGHT) 38 if(ymax >= max_y)
61 ymax = LCD_HEIGHT; 39 ymax = max_y;
62
63 SDL_LockSurface(lcd_surface);
64 40
65 int bpp = lcd_surface->format->BytesPerPixel; 41 SDL_LockSurface(surface);
66 42
67 for (x = x_start; x < xmax; x++) 43 dest.w = display_zoom;
68 { 44 dest.h = display_zoom;
69 for (y = y_start; y < ymax; y++) 45
70 { 46 for (x = x_start; x < xmax; x++) {
71 Uint8 *p = (Uint8 *)lcd_surface->pixels + y * lcd_surface->pitch + x * bpp; 47 dest.x = x * display_zoom;
72 48
73#if LCD_DEPTH == 1 49 for (y = y_start; y < ymax; y++) {
74 *p = ((lcd_framebuffer[y/8][x] >> (y & 7)) & 1); 50 dest.y = y * display_zoom;
75#elif LCD_DEPTH == 2 51
76#if LCD_PIXELFORMAT == HORIZONTAL_PACKING 52 SDL_FillRect(surface, &dest, getpixel(x, y));
77 *p = ((lcd_framebuffer[y][x/4] >> (2 * (x & 3))) & 3);
78#else
79 *p = ((lcd_framebuffer[y/4][x] >> (2 * (y & 3))) & 3);
80#endif
81#elif LCD_DEPTH == 16
82#if LCD_PIXELFORMAT == RGB565SWAPPED
83 unsigned bits = lcd_framebuffer[y][x];
84 *(Uint16 *)p = (bits >> 8) | (bits << 8);
85#else
86 *(Uint16 *)p = lcd_framebuffer[y][x];
87#endif
88#endif
89 } 53 }
90 } 54 }
91 55
92 SDL_UnlockSurface(lcd_surface); 56 SDL_UnlockSurface(surface);
93
94 SDL_Rect src = {x_start, y_start, xmax, ymax};
95 SDL_Rect dest = {UI_LCD_POSX + x_start, UI_LCD_POSY + y_start, xmax, ymax};
96 57
97 if (!background) { 58 SDL_Rect src = {x_start * display_zoom, y_start * display_zoom, xmax * display_zoom, ymax * display_zoom};
98 dest.x -= UI_LCD_POSX; 59 dest.x = (ui_x + x_start) * display_zoom;
99 dest.y -= UI_LCD_POSY; 60 dest.y = (ui_y + y_start) * display_zoom;;
100 } 61 dest.w = xmax * display_zoom;
62 dest.h = ymax * display_zoom;
101 63
102 SDL_BlitSurface(lcd_surface, &src, gui_surface, &dest); 64 SDL_BlitSurface(surface, &src, gui_surface, &dest);
103 SDL_UpdateRect(gui_surface, dest.x, dest.y, dest.w, dest.h); 65 SDL_UpdateRect(gui_surface, dest.x, dest.y, dest.w, dest.h);
104 SDL_Flip(gui_surface); 66 SDL_Flip(gui_surface);
105
106} 67}
107 68
108#ifdef HAVE_REMOTE_LCD
109
110extern unsigned char lcd_remote_framebuffer[LCD_REMOTE_HEIGHT/8][LCD_REMOTE_WIDTH];
111
112void lcd_remote_update (void)
113{
114 lcd_remote_update_rect(0, 0, LCD_REMOTE_WIDTH, LCD_REMOTE_HEIGHT);
115}
116
117void lcd_remote_update_rect(int x_start, int y_start,
118 int width, int height)
119{
120 int x, y;
121 int xmax, ymax;
122
123 ymax = y_start + height;
124 xmax = x_start + width;
125
126 if(xmax > LCD_REMOTE_WIDTH)
127 xmax = LCD_REMOTE_WIDTH;
128 if(ymax >= LCD_REMOTE_HEIGHT)
129 ymax = LCD_REMOTE_HEIGHT;
130
131 SDL_LockSurface(remote_surface);
132
133 int bpp = remote_surface->format->BytesPerPixel;
134
135 for (x = x_start; x < xmax; x++)
136 for (y = y_start; y < ymax; y++)
137 {
138 Uint8 *p = (Uint8 *)remote_surface->pixels + y * remote_surface->pitch + x * bpp;
139
140 *p = ((lcd_remote_framebuffer[y/8][x] >> (y & 7)) & 1);
141 }
142
143 SDL_UnlockSurface(remote_surface);
144
145 SDL_Rect src = {x_start, y_start, xmax, ymax};
146 SDL_Rect dest = {UI_REMOTE_POSX + x_start, UI_REMOTE_POSY + y_start, xmax, ymax};
147
148 if (!background) {
149 dest.x -= UI_REMOTE_POSX;
150 dest.y -= UI_REMOTE_POSY;
151 dest.y += UI_LCD_HEIGHT;
152 }
153
154 SDL_BlitSurface(remote_surface, &src, gui_surface, &dest);
155 SDL_UpdateRect(gui_surface, dest.x, dest.y, dest.w, dest.h);
156 SDL_Flip(gui_surface);
157
158}
159
160#endif /* HAVE_REMOTE_LCD */
161#endif /* HAVE_LCD_BITMAP */
162
163#ifdef HAVE_LCD_CHARCELLS
164/* Defined in lcd-playersim.c */
165extern void lcd_print_char(int x, int y);
166extern bool lcd_display_redraw;
167extern unsigned char hardware_buffer_lcd[11][2];
168static unsigned char lcd_buffer_copy[11][2];
169
170void lcd_update(void)
171{
172 int x, y;
173 bool changed = false;
174 SDL_Rect dest = {UI_LCD_POSX, UI_LCD_POSY, UI_LCD_WIDTH, UI_LCD_HEIGHT};
175
176 for (y = 0; y < 2; y++)
177 {
178 for (x = 0; x < 11; x++)
179 {
180 if (lcd_display_redraw ||
181 lcd_buffer_copy[x][y] != hardware_buffer_lcd[x][y])
182 {
183 lcd_buffer_copy[x][y] = hardware_buffer_lcd[x][y];
184 lcd_print_char(x, y);
185 changed = true;
186 }
187 }
188 }
189
190 if (changed)
191 {
192 if (!background) {
193 dest.x -= UI_LCD_POSX;
194 dest.y -= UI_LCD_POSY;
195 }
196
197 SDL_BlitSurface(lcd_surface, NULL, gui_surface, &dest);
198 SDL_UpdateRect(gui_surface, dest.x, dest.y, dest.w, dest.h);
199 SDL_Flip(gui_surface);
200 }
201
202 lcd_display_redraw = false;
203}
204
205void drawdots(int color, struct coordinate *points, int count)
206{
207 int bpp = lcd_surface->format->BytesPerPixel;
208
209 SDL_LockSurface(lcd_surface);
210
211 while (count--)
212 {
213 Uint8 *p = (Uint8 *)lcd_surface->pixels + (points[count].y) * lcd_surface->pitch + (points[count].x) * bpp;
214
215 *p = color;
216 }
217
218 SDL_UnlockSurface(lcd_surface);
219}
220
221void drawrectangles(int color, struct rectangle *points, int count)
222{
223 int bpp = lcd_surface->format->BytesPerPixel;
224
225 SDL_LockSurface(lcd_surface);
226
227 while (count--)
228 {
229 int x;
230 int y;
231 int ix;
232 int iy;
233
234 for (x = points[count].x, ix = 0; ix < points[count].width; x++, ix++)
235 {
236 for (y = points[count].y, iy = 0; iy < points[count].height; y++, iy++)
237 {
238 Uint8 *p = (Uint8 *)lcd_surface->pixels + y * lcd_surface->pitch + x * bpp;
239
240 *p = color;
241 }
242 }
243 }
244
245 SDL_UnlockSurface(lcd_surface);
246}
247#endif /* HAVE_LCD_CHARCELLS */
248
249#if LCD_DEPTH <= 8
250/* set a range of bitmap indices to a gradient from startcolour to endcolour */ 69/* set a range of bitmap indices to a gradient from startcolour to endcolour */
251void lcdcolors(int index, int count, SDL_Color *start, SDL_Color *end) 70void sdl_set_gradient(SDL_Surface *surface, SDL_Color *start, SDL_Color *end, int steps)
252{ 71{
253 int i; 72 int i;
73 SDL_Color palette[steps];
254 74
255 count--; 75 for (i = 0; i < steps; i++) {
256 for (i = 0; i <= count; i++) 76 palette[i].r = start->r + (end->r - start->r) * i / steps;
257 { 77 palette[i].g = start->g + (end->g - start->g) * i / steps;
258 lcd_palette[i+index].r = start->r 78 palette[i].b = start->b + (end->b - start->b) * i / steps;
259 + (end->r - start->r) * i / count;
260 lcd_palette[i+index].g = start->g
261 + (end->g - start->g) * i / count;
262 lcd_palette[i+index].b = start->b
263 + (end->b - start->b) * i / count;
264 } 79 }
265 80
266 SDL_SetPalette(lcd_surface, SDL_LOGPAL|SDL_PHYSPAL, lcd_palette, index, count); 81 SDL_SetPalette(surface, SDL_LOGPAL|SDL_PHYSPAL, palette, 0, steps);
267} 82}
268#endif
269 83
270#ifdef HAVE_REMOTE_LCD
271/* set a range of bitmap indices to a gradient from startcolour to endcolour */
272void lcdremotecolors(int index, int count, SDL_Color *start, SDL_Color *end)
273{
274 int i;
275
276 count--;
277 for (i = 0; i <= count; i++)
278 {
279 remote_palette[i+index].r = start->r
280 + (end->r - start->r) * i / count;
281 remote_palette[i+index].g = start->g
282 + (end->g - start->g) * i / count;
283 remote_palette[i+index].b = start->b
284 + (end->b - start->b) * i / count;
285 }
286
287 SDL_SetPalette(remote_surface, SDL_LOGPAL|SDL_PHYSPAL, remote_palette, index, count);
288}
289#endif
290
291/* initialise simulator lcd driver */
292void simlcdinit(void)
293{
294#if LCD_DEPTH == 16
295 lcd_surface = SDL_CreateRGBSurface(SDL_SWSURFACE, LCD_WIDTH, LCD_HEIGHT, 16,
296 0, 0, 0, 0);
297#else
298 lcd_surface = SDL_CreateRGBSurface(SDL_SWSURFACE, LCD_WIDTH, LCD_HEIGHT, 8,
299 0, 0, 0, 0);
300#endif
301
302#if LCD_DEPTH <= 8
303 lcdcolors(0, (1<<LCD_DEPTH), &lcd_color_zero, &lcd_color_max);
304#endif
305
306#ifdef HAVE_REMOTE_LCD
307 remote_surface = SDL_CreateRGBSurface(SDL_SWSURFACE, LCD_REMOTE_WIDTH, LCD_REMOTE_HEIGHT, 8,
308 0, 0, 0, 0);
309
310 lcdremotecolors(0, (1<<LCD_REMOTE_DEPTH), &remote_color_zero, &remote_color_max);
311#endif
312}
diff --git a/uisimulator/sdl/lcd-sdl.h b/uisimulator/sdl/lcd-sdl.h
index 312ae0d01f..d371639a64 100644
--- a/uisimulator/sdl/lcd-sdl.h
+++ b/uisimulator/sdl/lcd-sdl.h
@@ -20,20 +20,18 @@
20#ifndef __LCDSDL_H__ 20#ifndef __LCDSDL_H__
21#define __LCDSDL_H__ 21#define __LCDSDL_H__
22 22
23#include "uisdl.h"
24#include "lcd.h" 23#include "lcd.h"
24#include "SDL.h"
25 25
26extern SDL_Surface* lcd_surface; 26/* Default display zoom level */
27#if LCD_DEPTH <= 8 27extern int display_zoom;
28extern SDL_Color lcd_palette[(1<<LCD_DEPTH)];
29#endif
30 28
31#ifdef HAVE_REMOTE_LCD 29void sdl_update_rect(SDL_Surface *surface, int x_start, int y_start, int width,
32extern SDL_Surface* remote_surface; 30 int height, int max_x, int max_y, int ui_x, int ui_y,
33extern SDL_Color remote_palette[(1<<LCD_REMOTE_DEPTH)]; 31 Uint32 (*getpixel)(int, int));
34#endif
35 32
36void simlcdinit(void); 33void sdl_set_gradient(SDL_Surface *surface, SDL_Color *start, SDL_Color *end,
34 int steps);
37 35
38#endif // #ifndef __LCDSDL_H__ 36#endif // #ifndef __LCDSDL_H__
39 37
diff --git a/uisimulator/sdl/thread-sdl.h b/uisimulator/sdl/thread-sdl.h
index a661f582a4..30d0adae49 100644
--- a/uisimulator/sdl/thread-sdl.h
+++ b/uisimulator/sdl/thread-sdl.h
@@ -17,7 +17,14 @@
17 * 17 *
18 ****************************************************************************/ 18 ****************************************************************************/
19 19
20#ifndef __THREADSDL_H__
21#define __THREADSDL_H__
22
23#include "SDL_thread.h"
24
20extern SDL_Thread* threads[256]; 25extern SDL_Thread* threads[256];
21extern int threadCount; 26extern int threadCount;
22extern SDL_mutex* mutex; 27extern SDL_mutex* mutex;
23 28
29#endif // #ifndef __THREADSDL_H__
30
diff --git a/uisimulator/sdl/uisdl.c b/uisimulator/sdl/uisdl.c
index 2dd6b93122..178090403f 100644
--- a/uisimulator/sdl/uisdl.c
+++ b/uisimulator/sdl/uisdl.c
@@ -20,14 +20,25 @@
20#include <stdlib.h> 20#include <stdlib.h>
21#include <string.h> 21#include <string.h>
22#include "autoconf.h" 22#include "autoconf.h"
23#include "uisdl.h"
24#include "button.h" 23#include "button.h"
25#include "thread.h" 24#include "thread.h"
26#include "thread-sdl.h"
27#include "kernel.h" 25#include "kernel.h"
28#include "sound.h" 26#include "sound.h"
27#include "uisdl.h"
28#include "lcd-sdl.h"
29#ifdef HAVE_LCD_BITMAP
30#include "lcd-bitmap.h"
31#elif HAVE_LCD_CHARCELLS
32#include "lcd-charcell.h"
33#endif
34#ifdef HAVE_REMOTE_LCD
35#include "lcd-remote.h"
36#endif
37#include "thread-sdl.h"
38#include "SDL_mutex.h"
39#include "SDL_thread.h"
29 40
30// extern functions 41/* extern functions */
31extern void app_main (void *); // mod entry point 42extern void app_main (void *); // mod entry point
32extern void new_key(int key); 43extern void new_key(int key);
33extern void sim_tick_tasks(void); 44extern void sim_tick_tasks(void);
@@ -43,8 +54,8 @@ SDL_TimerID tick_timer_id;
43SDL_Thread *sound_thread; 54SDL_Thread *sound_thread;
44#endif 55#endif
45 56
46bool lcd_display_redraw=true; // Used for player simulator 57bool lcd_display_redraw = true; /* Used for player simulator */
47char having_new_lcd=true; // Used for player simulator 58char having_new_lcd=true; /* Used for player simulator */
48 59
49long start_tick; 60long start_tick;
50 61
@@ -130,14 +141,17 @@ bool gui_startup()
130 } 141 }
131 142
132 143
133 if ((gui_surface = SDL_SetVideoMode(width, height, 24, SDL_HWSURFACE|SDL_DOUBLEBUF)) == NULL) { 144 if ((gui_surface = SDL_SetVideoMode(width * display_zoom, height * display_zoom, 24, SDL_HWSURFACE|SDL_DOUBLEBUF)) == NULL) {
134 fprintf(stderr, "fatal: %s\n", SDL_GetError()); 145 fprintf(stderr, "fatal: %s\n", SDL_GetError());
135 return false; 146 return false;
136 } 147 }
137 148
138 SDL_WM_SetCaption(UI_TITLE, NULL); 149 SDL_WM_SetCaption(UI_TITLE, NULL);
139 150
140 simlcdinit(); 151 sim_lcd_init();
152#ifdef HAVE_REMOTE_LCD
153 sim_lcd_remote_init();
154#endif
141 155
142 SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); 156 SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
143 157
@@ -190,16 +204,26 @@ int main(int argc, char *argv[])
190 } else if (!strcmp("--old_lcd", argv[x])) { 204 } else if (!strcmp("--old_lcd", argv[x])) {
191 having_new_lcd = false; 205 having_new_lcd = false;
192 printf("Using old LCD layout.\n"); 206 printf("Using old LCD layout.\n");
207 } else if (!strcmp("--zoom", argv[x])) {
208 x++;
209 display_zoom=atoi(argv[x]);
210 printf("Window zoom is %d\n", display_zoom);
193 } else { 211 } else {
194 printf("rockboxui\n"); 212 printf("rockboxui\n");
195 printf("Arguments:\n"); 213 printf("Arguments:\n");
196 printf(" --background \t Use background image of hardware\n"); 214 printf(" --background \t Use background image of hardware\n");
197 printf(" --old_lcd \t [Player] simulate old playermodel (ROM version<4.51)\n"); 215 printf(" --old_lcd \t [Player] simulate old playermodel (ROM version<4.51)\n");
216 printf(" --zoom \t window zoom (will disable backgrounds)\n");
198 exit(0); 217 exit(0);
199 } 218 }
200 } 219 }
201 } 220 }
202 221
222 if (display_zoom > 1) {
223 background = false;
224 }
225
226
203 if (!gui_startup()) 227 if (!gui_startup())
204 return -1; 228 return -1;
205 229
diff --git a/uisimulator/sdl/uisdl.h b/uisimulator/sdl/uisdl.h
index 25e31040cd..989ca364d1 100644
--- a/uisimulator/sdl/uisdl.h
+++ b/uisimulator/sdl/uisdl.h
@@ -20,10 +20,8 @@
20#ifndef __UISDL_H__ 20#ifndef __UISDL_H__
21#define __UISDL_H__ 21#define __UISDL_H__
22 22
23#include <SDL.h> 23#include <stdbool.h>
24#include <SDL_mutex.h> 24#include "SDL.h"
25#include <SDL_thread.h>
26#include "lcd-sdl.h"
27 25
28/* colour definitions are R, G, B */ 26/* colour definitions are R, G, B */
29 27
@@ -93,7 +91,7 @@
93#define UI_REMOTE_WIDTH 128 91#define UI_REMOTE_WIDTH 128
94#define UI_REMOTE_HEIGHT 64 92#define UI_REMOTE_HEIGHT 64
95 93
96#elif defined(IRIVER_H300_SERIES) 94#elif defined(IRIVER_H300)
97#define UI_TITLE "iriver H300" 95#define UI_TITLE "iriver H300"
98#define UI_WIDTH 288 // width of GUI window 96#define UI_WIDTH 288 // width of GUI window
99#define UI_HEIGHT 581 // height of GUI window 97#define UI_HEIGHT 581 // height of GUI window
@@ -176,6 +174,7 @@
176 174
177extern SDL_Surface *gui_surface; 175extern SDL_Surface *gui_surface;
178extern bool background; /* True if the background image is enabled */ 176extern bool background; /* True if the background image is enabled */
177extern int display_zoom;
179 178
180#endif // #ifndef __UISDL_H__ 179#endif // #ifndef __UISDL_H__
181 180