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
= {0, 0, 0, 0};
41 static unsigned long get_lcd_pixel(int x
, int y
)
43 return sim_lcd_framebuffer
[y
][x
];
46 void sim_lcd_update_rect(int x_start
, int y_start
, int width
, int height
)
48 sdl_update_rect(lcd_surface
, x_start
, y_start
, width
, height
,
49 SIM_LCD_WIDTH
, SIM_LCD_HEIGHT
, get_lcd_pixel
);
50 sdl_gui_update(lcd_surface
, x_start
, y_start
, width
, height
,
51 SIM_LCD_WIDTH
, SIM_LCD_HEIGHT
,
52 background
? UI_LCD_POSX
: 0, background
? UI_LCD_POSY
: 0);
59 for (y
= 0; y
< lcd_pattern_count
; y
++)
60 if (lcd_patterns
[y
].count
> 0)
61 sim_lcd_define_pattern(y
, lcd_patterns
[y
].pattern
);
63 for (y
= 0; y
< LCD_HEIGHT
; y
++)
64 for (x
= 0; x
< LCD_WIDTH
; x
++)
65 lcd_print_char(x
, y
, lcd_charbuffer
[y
][x
]);
67 if (lcd_cursor
.visible
)
68 lcd_print_char(lcd_cursor
.x
, lcd_cursor
.y
, lcd_cursor
.hw_char
);
70 sim_lcd_update_rect(0, ICON_HEIGHT
, SIM_LCD_WIDTH
,
71 LCD_HEIGHT
*CHAR_HEIGHT
*CHAR_PIXEL
);
75 void sim_backlight(int value
)
78 sdl_set_gradient(lcd_surface
, &lcd_backlight_color_zero
, &lcd_color_max
,
81 sdl_set_gradient(lcd_surface
, &lcd_color_zero
, &lcd_color_max
,
85 sim_lcd_update_rect(0, 0, SIM_LCD_WIDTH
, SIM_LCD_HEIGHT
);
89 /* initialise simulator lcd driver */
90 void sim_lcd_init(void)
92 lcd_surface
= SDL_CreateRGBSurface(SDL_SWSURFACE
,
93 SIM_LCD_WIDTH
* display_zoom
,
94 SIM_LCD_HEIGHT
* display_zoom
,
97 sdl_set_gradient(lcd_surface
, &lcd_backlight_color_zero
, &lcd_color_max
,
101 #define BMP_COMPRESSION 0 /* BI_RGB */
102 #define BMP_NUMCOLORS (1 << LCD_DEPTH)
104 #define BMP_LINESIZE (((SIM_LCD_WIDTH + 31) / 32) * 4)
106 #define BMP_HEADERSIZE (54 + 4 * BMP_NUMCOLORS)
107 #define BMP_DATASIZE (BMP_LINESIZE * SIM_LCD_HEIGHT)
108 #define BMP_TOTALSIZE (BMP_HEADERSIZE + BMP_DATASIZE)
110 #define LE16_CONST(x) (x)&0xff, ((x)>>8)&0xff
111 #define LE32_CONST(x) (x)&0xff, ((x)>>8)&0xff, ((x)>>16)&0xff, ((x)>>24)&0xff
113 static const unsigned char bmpheader
[] =
115 0x42, 0x4d, /* 'BM' */
116 LE32_CONST(BMP_TOTALSIZE
), /* Total file size */
117 0x00, 0x00, 0x00, 0x00, /* Reserved */
118 LE32_CONST(BMP_HEADERSIZE
), /* Offset to start of pixel data */
120 0x28, 0x00, 0x00, 0x00, /* Size of (2nd) header */
121 LE32_CONST(SIM_LCD_WIDTH
), /* Width in pixels */
122 LE32_CONST(SIM_LCD_HEIGHT
), /* Height in pixels */
123 0x01, 0x00, /* Number of planes (always 1) */
124 LE16_CONST(BMP_BPP
), /* Bits per pixel 1/4/8/16/24 */
125 LE32_CONST(BMP_COMPRESSION
),/* Compression mode */
126 LE32_CONST(BMP_DATASIZE
), /* Size of bitmap data */
127 0xc4, 0x0e, 0x00, 0x00, /* Horizontal resolution (pixels/meter) */
128 0xc4, 0x0e, 0x00, 0x00, /* Vertical resolution (pixels/meter) */
129 LE32_CONST(BMP_NUMCOLORS
), /* Number of used colours */
130 LE32_CONST(BMP_NUMCOLORS
), /* Number of important colours */
132 0x90, 0xee, 0x90, 0x00, /* Colour #0 */
133 0x00, 0x00, 0x00, 0x00 /* Colour #1 */
136 void screen_dump(void)
139 char filename
[MAX_PATH
];
141 static unsigned char line
[BMP_LINESIZE
];
143 create_numbered_filename(filename
, "", "dump_", ".bmp", 4
144 IF_CNFN_NUM_(, NULL
));
145 DEBUGF("screen_dump\n");
147 fd
= sim_creat(filename
);
151 write(fd
, bmpheader
, sizeof(bmpheader
));
152 SDL_LockSurface(lcd_surface
);
154 /* BMP image goes bottom up */
155 for (y
= SIM_LCD_HEIGHT
- 1; y
>= 0; y
--)
157 Uint8
*src
= (Uint8
*)lcd_surface
->pixels
158 + y
* SIM_LCD_WIDTH
* display_zoom
* display_zoom
;
159 unsigned char *dst
= line
;
160 unsigned dst_mask
= 0x80;
162 memset(line
, 0, sizeof(line
));
163 for (x
= SIM_LCD_WIDTH
; x
> 0; x
--)
175 write(fd
, line
, sizeof(line
));
177 SDL_UnlockSurface(lcd_surface
);