1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2006 Dan Everton
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.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
22 #include "lcd-charcell.h"
28 #include "lcd-playersim.h"
32 /* extern functions, needed for screendump() */
33 extern int sim_creat(const char *name
);
35 SDL_Surface
* lcd_surface
;
36 SDL_Color lcd_color_zero
= {UI_LCD_BGCOLOR
, 0};
37 SDL_Color lcd_backlight_color_zero
= {UI_LCD_BGCOLORLIGHT
, 0};
38 SDL_Color lcd_color_max
= {UI_LCD_FGCOLOR
, 0};
39 SDL_Color lcd_backlight_color_max
= {UI_LCD_FGCOLORLIGHT
, 0};
42 static unsigned long get_lcd_pixel(int x
, int y
)
44 return sim_lcd_framebuffer
[y
][x
];
47 void sim_lcd_update_rect(int x_start
, int y_start
, int width
, int height
)
49 sdl_update_rect(lcd_surface
, x_start
, y_start
, width
, height
,
50 SIM_LCD_WIDTH
, SIM_LCD_HEIGHT
, get_lcd_pixel
);
51 sdl_gui_update(lcd_surface
, x_start
, y_start
, width
, height
,
52 SIM_LCD_WIDTH
, SIM_LCD_HEIGHT
,
53 background
? UI_LCD_POSX
: 0, background
? UI_LCD_POSY
: 0);
60 for (y
= 0; y
< lcd_pattern_count
; y
++)
61 if (lcd_patterns
[y
].count
> 0)
62 sim_lcd_define_pattern(y
, lcd_patterns
[y
].pattern
);
64 for (y
= 0; y
< LCD_HEIGHT
; y
++)
65 for (x
= 0; x
< LCD_WIDTH
; x
++)
66 lcd_print_char(x
, y
, lcd_charbuffer
[y
][x
]);
68 if (lcd_cursor
.visible
)
69 lcd_print_char(lcd_cursor
.x
, lcd_cursor
.y
, lcd_cursor
.hw_char
);
71 sim_lcd_update_rect(0, ICON_HEIGHT
, SIM_LCD_WIDTH
,
72 LCD_HEIGHT
*CHAR_HEIGHT
*CHAR_PIXEL
);
76 void sim_backlight(int value
)
79 sdl_set_gradient(lcd_surface
, &lcd_backlight_color_zero
,
80 &lcd_backlight_color_max
,
83 sdl_set_gradient(lcd_surface
, &lcd_color_zero
, &lcd_color_max
,
87 sim_lcd_update_rect(0, 0, SIM_LCD_WIDTH
, SIM_LCD_HEIGHT
);
91 /* initialise simulator lcd driver */
92 void sim_lcd_init(void)
94 lcd_surface
= SDL_CreateRGBSurface(SDL_SWSURFACE
,
95 SIM_LCD_WIDTH
* display_zoom
,
96 SIM_LCD_HEIGHT
* display_zoom
,
99 sdl_set_gradient(lcd_surface
, &lcd_backlight_color_zero
, &lcd_color_max
,
103 #define BMP_COMPRESSION 0 /* BI_RGB */
104 #define BMP_NUMCOLORS (1 << LCD_DEPTH)
106 #define BMP_LINESIZE (((SIM_LCD_WIDTH + 31) / 32) * 4)
108 #define BMP_HEADERSIZE (54 + 4 * BMP_NUMCOLORS)
109 #define BMP_DATASIZE (BMP_LINESIZE * SIM_LCD_HEIGHT)
110 #define BMP_TOTALSIZE (BMP_HEADERSIZE + BMP_DATASIZE)
112 #define LE16_CONST(x) (x)&0xff, ((x)>>8)&0xff
113 #define LE32_CONST(x) (x)&0xff, ((x)>>8)&0xff, ((x)>>16)&0xff, ((x)>>24)&0xff
115 static const unsigned char bmpheader
[] =
117 0x42, 0x4d, /* 'BM' */
118 LE32_CONST(BMP_TOTALSIZE
), /* Total file size */
119 0x00, 0x00, 0x00, 0x00, /* Reserved */
120 LE32_CONST(BMP_HEADERSIZE
), /* Offset to start of pixel data */
122 0x28, 0x00, 0x00, 0x00, /* Size of (2nd) header */
123 LE32_CONST(SIM_LCD_WIDTH
), /* Width in pixels */
124 LE32_CONST(SIM_LCD_HEIGHT
), /* Height in pixels */
125 0x01, 0x00, /* Number of planes (always 1) */
126 LE16_CONST(BMP_BPP
), /* Bits per pixel 1/4/8/16/24 */
127 LE32_CONST(BMP_COMPRESSION
),/* Compression mode */
128 LE32_CONST(BMP_DATASIZE
), /* Size of bitmap data */
129 0xc4, 0x0e, 0x00, 0x00, /* Horizontal resolution (pixels/meter) */
130 0xc4, 0x0e, 0x00, 0x00, /* Vertical resolution (pixels/meter) */
131 LE32_CONST(BMP_NUMCOLORS
), /* Number of used colours */
132 LE32_CONST(BMP_NUMCOLORS
), /* Number of important colours */
134 0x90, 0xee, 0x90, 0x00, /* Colour #0 */
135 0x00, 0x00, 0x00, 0x00 /* Colour #1 */
138 void screen_dump(void)
141 char filename
[MAX_PATH
];
143 static unsigned char line
[BMP_LINESIZE
];
145 create_numbered_filename(filename
, "", "dump_", ".bmp", 4
146 IF_CNFN_NUM_(, NULL
));
147 DEBUGF("screen_dump\n");
149 fd
= sim_creat(filename
);
153 write(fd
, bmpheader
, sizeof(bmpheader
));
154 SDL_LockSurface(lcd_surface
);
156 /* BMP image goes bottom up */
157 for (y
= SIM_LCD_HEIGHT
- 1; y
>= 0; y
--)
159 Uint8
*src
= (Uint8
*)lcd_surface
->pixels
160 + y
* SIM_LCD_WIDTH
* display_zoom
* display_zoom
;
161 unsigned char *dst
= line
;
162 unsigned dst_mask
= 0x80;
164 memset(line
, 0, sizeof(line
));
165 for (x
= SIM_LCD_WIDTH
; x
> 0; x
--)
177 write(fd
, line
, sizeof(line
));
179 SDL_UnlockSurface(lcd_surface
);