1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2006 Dan Everton
12 * 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.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
28 #include "lcd-charcell.h"
29 #include "screendump.h"
32 #include "lcd-playersim.h"
33 #include "sim-ui-defines.h"
36 /* can't include file.h here */
41 /* extern functions, needed for screendump() */
42 extern int sim_creat(const char *name
, mode_t mode
);
44 SDL_Surface
* lcd_surface
;
46 SDL_Color lcd_bl_color_dark
= {RED_CMP(LCD_BL_DARKCOLOR
),
47 GREEN_CMP(LCD_BL_DARKCOLOR
),
48 BLUE_CMP(LCD_BL_DARKCOLOR
), 0};
49 SDL_Color lcd_bl_color_bright
= {RED_CMP(LCD_BL_BRIGHTCOLOR
),
50 GREEN_CMP(LCD_BL_BRIGHTCOLOR
),
51 BLUE_CMP(LCD_BL_BRIGHTCOLOR
), 0};
52 SDL_Color lcd_color_dark
= {RED_CMP(LCD_DARKCOLOR
),
53 GREEN_CMP(LCD_DARKCOLOR
),
54 BLUE_CMP(LCD_DARKCOLOR
), 0};
55 SDL_Color lcd_color_bright
= {RED_CMP(LCD_BRIGHTCOLOR
),
56 GREEN_CMP(LCD_BRIGHTCOLOR
),
57 BLUE_CMP(LCD_BRIGHTCOLOR
), 0};
60 static unsigned long get_lcd_pixel(int x
, int y
)
62 return sim_lcd_framebuffer
[y
][x
];
65 void sim_lcd_update_rect(int x_start
, int y_start
, int width
, int height
)
67 sdl_update_rect(lcd_surface
, x_start
, y_start
, width
, height
,
68 SIM_LCD_WIDTH
, SIM_LCD_HEIGHT
, get_lcd_pixel
);
69 sdl_gui_update(lcd_surface
, x_start
, y_start
, width
, height
,
70 SIM_LCD_WIDTH
, SIM_LCD_HEIGHT
,
71 background
? UI_LCD_POSX
: 0, background
? UI_LCD_POSY
: 0);
78 for (y
= 0; y
< lcd_pattern_count
; y
++)
79 if (lcd_patterns
[y
].count
> 0)
80 sim_lcd_define_pattern(y
, lcd_patterns
[y
].pattern
);
82 for (y
= 0; y
< LCD_HEIGHT
; y
++)
83 for (x
= 0; x
< LCD_WIDTH
; x
++)
84 lcd_print_char(x
, y
, lcd_charbuffer
[y
][x
]);
86 if (lcd_cursor
.visible
)
87 lcd_print_char(lcd_cursor
.x
, lcd_cursor
.y
, lcd_cursor
.hw_char
);
89 sim_lcd_update_rect(0, ICON_HEIGHT
, SIM_LCD_WIDTH
,
90 LCD_HEIGHT
*CHAR_HEIGHT
*CHAR_PIXEL
);
94 void sim_backlight(int value
)
97 sdl_set_gradient(lcd_surface
, &lcd_bl_color_bright
,
98 &lcd_bl_color_dark
, 0, (1<<LCD_DEPTH
));
100 sdl_set_gradient(lcd_surface
, &lcd_color_bright
,
101 &lcd_color_dark
, 0, (1<<LCD_DEPTH
));
104 sim_lcd_update_rect(0, 0, SIM_LCD_WIDTH
, SIM_LCD_HEIGHT
);
108 /* initialise simulator lcd driver */
109 void sim_lcd_init(void)
111 lcd_surface
= SDL_CreateRGBSurface(SDL_SWSURFACE
,
112 SIM_LCD_WIDTH
* display_zoom
,
113 SIM_LCD_HEIGHT
* display_zoom
,
116 sdl_set_gradient(lcd_surface
, &lcd_bl_color_bright
,
117 &lcd_bl_color_dark
, 0, (1<<LCD_DEPTH
));
120 #define BMP_COMPRESSION 0 /* BI_RGB */
121 #define BMP_NUMCOLORS (1 << LCD_DEPTH)
123 #define BMP_LINESIZE (((SIM_LCD_WIDTH + 31) / 32) * 4)
125 #define BMP_HEADERSIZE (54 + 4 * BMP_NUMCOLORS)
126 #define BMP_DATASIZE (BMP_LINESIZE * SIM_LCD_HEIGHT)
127 #define BMP_TOTALSIZE (BMP_HEADERSIZE + BMP_DATASIZE)
129 #define LE16_CONST(x) (x)&0xff, ((x)>>8)&0xff
130 #define LE32_CONST(x) (x)&0xff, ((x)>>8)&0xff, ((x)>>16)&0xff, ((x)>>24)&0xff
132 static const unsigned char bmpheader
[] =
134 0x42, 0x4d, /* 'BM' */
135 LE32_CONST(BMP_TOTALSIZE
), /* Total file size */
136 0x00, 0x00, 0x00, 0x00, /* Reserved */
137 LE32_CONST(BMP_HEADERSIZE
), /* Offset to start of pixel data */
139 0x28, 0x00, 0x00, 0x00, /* Size of (2nd) header */
140 LE32_CONST(SIM_LCD_WIDTH
), /* Width in pixels */
141 LE32_CONST(SIM_LCD_HEIGHT
), /* Height in pixels */
142 0x01, 0x00, /* Number of planes (always 1) */
143 LE16_CONST(BMP_BPP
), /* Bits per pixel 1/4/8/16/24 */
144 LE32_CONST(BMP_COMPRESSION
),/* Compression mode */
145 LE32_CONST(BMP_DATASIZE
), /* Size of bitmap data */
146 0xc4, 0x0e, 0x00, 0x00, /* Horizontal resolution (pixels/meter) */
147 0xc4, 0x0e, 0x00, 0x00, /* Vertical resolution (pixels/meter) */
148 LE32_CONST(BMP_NUMCOLORS
), /* Number of used colours */
149 LE32_CONST(BMP_NUMCOLORS
), /* Number of important colours */
151 BMP_COLOR(LCD_BL_BRIGHTCOLOR
),
152 BMP_COLOR(LCD_BL_DARKCOLOR
)
155 void screen_dump(void)
158 char filename
[MAX_PATH
];
160 static unsigned char line
[BMP_LINESIZE
];
162 create_numbered_filename(filename
, "", "dump_", ".bmp", 4
163 IF_CNFN_NUM_(, NULL
));
164 DEBUGF("screen_dump\n");
166 fd
= sim_creat(filename
, 0666);
170 write(fd
, bmpheader
, sizeof(bmpheader
));
171 SDL_LockSurface(lcd_surface
);
173 /* BMP image goes bottom up */
174 for (y
= SIM_LCD_HEIGHT
- 1; y
>= 0; y
--)
176 Uint8
*src
= (Uint8
*)lcd_surface
->pixels
177 + y
* SIM_LCD_WIDTH
* display_zoom
* display_zoom
;
178 unsigned char *dst
= line
;
179 unsigned dst_mask
= 0x80;
181 memset(line
, 0, sizeof(line
));
182 for (x
= SIM_LCD_WIDTH
; x
> 0; x
--)
194 write(fd
, line
, sizeof(line
));
196 SDL_UnlockSurface(lcd_surface
);