Dan Everton | b585e87 | 2006-02-09 21:49:28 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
| 8 | * $Id$ |
| 9 | * |
| 10 | * Copyright (C) 2006 Dan Everton |
| 11 | * |
Daniel Stenberg | 2acc0ac | 2008-06-28 18:10:04 +0000 | [diff] [blame^] | 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. |
Dan Everton | b585e87 | 2006-02-09 21:49:28 +0000 | [diff] [blame] | 16 | * |
| 17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 18 | * KIND, either express or implied. |
| 19 | * |
| 20 | ****************************************************************************/ |
| 21 | |
Jens Arnold | 8325e0b | 2006-05-23 07:48:43 +0000 | [diff] [blame] | 22 | #include "debug.h" |
Dan Everton | b585e87 | 2006-02-09 21:49:28 +0000 | [diff] [blame] | 23 | #include "lcd.h" |
Jens Arnold | 54ea2e4 | 2007-03-31 09:58:49 +0000 | [diff] [blame] | 24 | #include "lcd-charcell.h" |
Jens Arnold | 8325e0b | 2006-05-23 07:48:43 +0000 | [diff] [blame] | 25 | #include "misc.h" |
| 26 | #include <string.h> |
Jens Arnold | 25f3860 | 2006-05-23 10:00:11 +0000 | [diff] [blame] | 27 | #include <unistd.h> |
| 28 | #include <fcntl.h> |
Jens Arnold | 8325e0b | 2006-05-23 07:48:43 +0000 | [diff] [blame] | 29 | |
Dan Everton | b585e87 | 2006-02-09 21:49:28 +0000 | [diff] [blame] | 30 | #include "lcd-playersim.h" |
| 31 | #include "uisdl.h" |
| 32 | #include "lcd-sdl.h" |
| 33 | |
Jens Arnold | 8325e0b | 2006-05-23 07:48:43 +0000 | [diff] [blame] | 34 | /* extern functions, needed for screendump() */ |
Jens Arnold | 67eb154 | 2007-02-01 23:08:15 +0000 | [diff] [blame] | 35 | extern int sim_creat(const char *name); |
Jens Arnold | 8325e0b | 2006-05-23 07:48:43 +0000 | [diff] [blame] | 36 | |
Dan Everton | b585e87 | 2006-02-09 21:49:28 +0000 | [diff] [blame] | 37 | SDL_Surface* lcd_surface; |
Dan Everton | 3ba0060 | 2006-02-13 21:46:28 +0000 | [diff] [blame] | 38 | SDL_Color lcd_color_zero = {UI_LCD_BGCOLOR, 0}; |
| 39 | SDL_Color lcd_backlight_color_zero = {UI_LCD_BGCOLORLIGHT, 0}; |
Robert Kukla | 3e3e1d5 | 2008-03-02 21:28:26 +0000 | [diff] [blame] | 40 | SDL_Color lcd_color_max = {UI_LCD_FGCOLOR, 0}; |
| 41 | SDL_Color lcd_backlight_color_max = {UI_LCD_FGCOLORLIGHT, 0}; |
Dan Everton | b585e87 | 2006-02-09 21:49:28 +0000 | [diff] [blame] | 42 | |
Jens Arnold | 54ea2e4 | 2007-03-31 09:58:49 +0000 | [diff] [blame] | 43 | |
| 44 | static unsigned long get_lcd_pixel(int x, int y) |
| 45 | { |
| 46 | return sim_lcd_framebuffer[y][x]; |
| 47 | } |
| 48 | |
| 49 | void sim_lcd_update_rect(int x_start, int y_start, int width, int height) |
| 50 | { |
| 51 | sdl_update_rect(lcd_surface, x_start, y_start, width, height, |
| 52 | SIM_LCD_WIDTH, SIM_LCD_HEIGHT, get_lcd_pixel); |
| 53 | sdl_gui_update(lcd_surface, x_start, y_start, width, height, |
| 54 | SIM_LCD_WIDTH, SIM_LCD_HEIGHT, |
| 55 | background ? UI_LCD_POSX : 0, background ? UI_LCD_POSY : 0); |
| 56 | } |
Dan Everton | b585e87 | 2006-02-09 21:49:28 +0000 | [diff] [blame] | 57 | |
| 58 | void lcd_update(void) |
| 59 | { |
| 60 | int x, y; |
Dan Everton | b585e87 | 2006-02-09 21:49:28 +0000 | [diff] [blame] | 61 | |
Jens Arnold | 54ea2e4 | 2007-03-31 09:58:49 +0000 | [diff] [blame] | 62 | for (y = 0; y < lcd_pattern_count; y++) |
| 63 | if (lcd_patterns[y].count > 0) |
| 64 | sim_lcd_define_pattern(y, lcd_patterns[y].pattern); |
Dan Everton | b585e87 | 2006-02-09 21:49:28 +0000 | [diff] [blame] | 65 | |
Jens Arnold | 54ea2e4 | 2007-03-31 09:58:49 +0000 | [diff] [blame] | 66 | for (y = 0; y < LCD_HEIGHT; y++) |
| 67 | for (x = 0; x < LCD_WIDTH; x++) |
| 68 | lcd_print_char(x, y, lcd_charbuffer[y][x]); |
Dan Everton | b585e87 | 2006-02-09 21:49:28 +0000 | [diff] [blame] | 69 | |
Jens Arnold | 54ea2e4 | 2007-03-31 09:58:49 +0000 | [diff] [blame] | 70 | if (lcd_cursor.visible) |
| 71 | lcd_print_char(lcd_cursor.x, lcd_cursor.y, lcd_cursor.hw_char); |
| 72 | |
| 73 | sim_lcd_update_rect(0, ICON_HEIGHT, SIM_LCD_WIDTH, |
| 74 | LCD_HEIGHT*CHAR_HEIGHT*CHAR_PIXEL); |
Dan Everton | b585e87 | 2006-02-09 21:49:28 +0000 | [diff] [blame] | 75 | } |
| 76 | |
Jens Arnold | 47bf6c5 | 2007-04-12 22:12:13 +0000 | [diff] [blame] | 77 | #ifdef HAVE_BACKLIGHT |
Dan Everton | 3ba0060 | 2006-02-13 21:46:28 +0000 | [diff] [blame] | 78 | void sim_backlight(int value) |
| 79 | { |
| 80 | if (value > 0) { |
Robert Kukla | 3e3e1d5 | 2008-03-02 21:28:26 +0000 | [diff] [blame] | 81 | sdl_set_gradient(lcd_surface, &lcd_backlight_color_zero, |
| 82 | &lcd_backlight_color_max, |
Jens Arnold | 6a972e0 | 2006-02-26 13:37:42 +0000 | [diff] [blame] | 83 | 0, (1<<LCD_DEPTH)); |
Dan Everton | 3ba0060 | 2006-02-13 21:46:28 +0000 | [diff] [blame] | 84 | } else { |
Jens Arnold | 6a972e0 | 2006-02-26 13:37:42 +0000 | [diff] [blame] | 85 | sdl_set_gradient(lcd_surface, &lcd_color_zero, &lcd_color_max, |
| 86 | 0, (1<<LCD_DEPTH)); |
Dan Everton | 3ba0060 | 2006-02-13 21:46:28 +0000 | [diff] [blame] | 87 | } |
Jens Arnold | 54ea2e4 | 2007-03-31 09:58:49 +0000 | [diff] [blame] | 88 | |
| 89 | sim_lcd_update_rect(0, 0, SIM_LCD_WIDTH, SIM_LCD_HEIGHT); |
Dan Everton | 3ba0060 | 2006-02-13 21:46:28 +0000 | [diff] [blame] | 90 | } |
| 91 | #endif |
| 92 | |
Dan Everton | b585e87 | 2006-02-09 21:49:28 +0000 | [diff] [blame] | 93 | /* initialise simulator lcd driver */ |
| 94 | void sim_lcd_init(void) |
| 95 | { |
Jens Arnold | ad4e3d6 | 2007-03-26 07:52:13 +0000 | [diff] [blame] | 96 | lcd_surface = SDL_CreateRGBSurface(SDL_SWSURFACE, |
| 97 | SIM_LCD_WIDTH * display_zoom, |
| 98 | SIM_LCD_HEIGHT * display_zoom, |
| 99 | 8, 0, 0, 0, 0); |
Dan Everton | b585e87 | 2006-02-09 21:49:28 +0000 | [diff] [blame] | 100 | |
Jens Arnold | 8325e0b | 2006-05-23 07:48:43 +0000 | [diff] [blame] | 101 | sdl_set_gradient(lcd_surface, &lcd_backlight_color_zero, &lcd_color_max, |
Jens Arnold | 6a972e0 | 2006-02-26 13:37:42 +0000 | [diff] [blame] | 102 | 0, (1<<LCD_DEPTH)); |
Dan Everton | b585e87 | 2006-02-09 21:49:28 +0000 | [diff] [blame] | 103 | } |
| 104 | |
Jens Arnold | 8325e0b | 2006-05-23 07:48:43 +0000 | [diff] [blame] | 105 | #define BMP_COMPRESSION 0 /* BI_RGB */ |
| 106 | #define BMP_NUMCOLORS (1 << LCD_DEPTH) |
| 107 | #define BMP_BPP 1 |
Jens Arnold | ad4e3d6 | 2007-03-26 07:52:13 +0000 | [diff] [blame] | 108 | #define BMP_LINESIZE (((SIM_LCD_WIDTH + 31) / 32) * 4) |
Jens Arnold | 8325e0b | 2006-05-23 07:48:43 +0000 | [diff] [blame] | 109 | |
| 110 | #define BMP_HEADERSIZE (54 + 4 * BMP_NUMCOLORS) |
Jens Arnold | ad4e3d6 | 2007-03-26 07:52:13 +0000 | [diff] [blame] | 111 | #define BMP_DATASIZE (BMP_LINESIZE * SIM_LCD_HEIGHT) |
Jens Arnold | 8325e0b | 2006-05-23 07:48:43 +0000 | [diff] [blame] | 112 | #define BMP_TOTALSIZE (BMP_HEADERSIZE + BMP_DATASIZE) |
| 113 | |
| 114 | #define LE16_CONST(x) (x)&0xff, ((x)>>8)&0xff |
| 115 | #define LE32_CONST(x) (x)&0xff, ((x)>>8)&0xff, ((x)>>16)&0xff, ((x)>>24)&0xff |
| 116 | |
| 117 | static const unsigned char bmpheader[] = |
| 118 | { |
| 119 | 0x42, 0x4d, /* 'BM' */ |
| 120 | LE32_CONST(BMP_TOTALSIZE), /* Total file size */ |
| 121 | 0x00, 0x00, 0x00, 0x00, /* Reserved */ |
| 122 | LE32_CONST(BMP_HEADERSIZE), /* Offset to start of pixel data */ |
| 123 | |
| 124 | 0x28, 0x00, 0x00, 0x00, /* Size of (2nd) header */ |
Jens Arnold | ad4e3d6 | 2007-03-26 07:52:13 +0000 | [diff] [blame] | 125 | LE32_CONST(SIM_LCD_WIDTH), /* Width in pixels */ |
| 126 | LE32_CONST(SIM_LCD_HEIGHT), /* Height in pixels */ |
Jens Arnold | 8325e0b | 2006-05-23 07:48:43 +0000 | [diff] [blame] | 127 | 0x01, 0x00, /* Number of planes (always 1) */ |
| 128 | LE16_CONST(BMP_BPP), /* Bits per pixel 1/4/8/16/24 */ |
| 129 | LE32_CONST(BMP_COMPRESSION),/* Compression mode */ |
| 130 | LE32_CONST(BMP_DATASIZE), /* Size of bitmap data */ |
| 131 | 0xc4, 0x0e, 0x00, 0x00, /* Horizontal resolution (pixels/meter) */ |
| 132 | 0xc4, 0x0e, 0x00, 0x00, /* Vertical resolution (pixels/meter) */ |
| 133 | LE32_CONST(BMP_NUMCOLORS), /* Number of used colours */ |
| 134 | LE32_CONST(BMP_NUMCOLORS), /* Number of important colours */ |
| 135 | |
| 136 | 0x90, 0xee, 0x90, 0x00, /* Colour #0 */ |
| 137 | 0x00, 0x00, 0x00, 0x00 /* Colour #1 */ |
| 138 | }; |
| 139 | |
| 140 | void screen_dump(void) |
| 141 | { |
| 142 | int fd; |
| 143 | char filename[MAX_PATH]; |
| 144 | int x, y; |
| 145 | static unsigned char line[BMP_LINESIZE]; |
| 146 | |
Michael Sevakis | 4aa01ed | 2006-11-06 18:36:10 +0000 | [diff] [blame] | 147 | create_numbered_filename(filename, "", "dump_", ".bmp", 4 |
Michael Sevakis | 0f5cb94 | 2006-11-06 18:07:30 +0000 | [diff] [blame] | 148 | IF_CNFN_NUM_(, NULL)); |
Jens Arnold | 8325e0b | 2006-05-23 07:48:43 +0000 | [diff] [blame] | 149 | DEBUGF("screen_dump\n"); |
| 150 | |
Jens Arnold | 67eb154 | 2007-02-01 23:08:15 +0000 | [diff] [blame] | 151 | fd = sim_creat(filename); |
Jens Arnold | 8325e0b | 2006-05-23 07:48:43 +0000 | [diff] [blame] | 152 | if (fd < 0) |
| 153 | return; |
| 154 | |
| 155 | write(fd, bmpheader, sizeof(bmpheader)); |
| 156 | SDL_LockSurface(lcd_surface); |
| 157 | |
| 158 | /* BMP image goes bottom up */ |
Jens Arnold | ad4e3d6 | 2007-03-26 07:52:13 +0000 | [diff] [blame] | 159 | for (y = SIM_LCD_HEIGHT - 1; y >= 0; y--) |
Jens Arnold | 8325e0b | 2006-05-23 07:48:43 +0000 | [diff] [blame] | 160 | { |
| 161 | Uint8 *src = (Uint8 *)lcd_surface->pixels |
Jens Arnold | ad4e3d6 | 2007-03-26 07:52:13 +0000 | [diff] [blame] | 162 | + y * SIM_LCD_WIDTH * display_zoom * display_zoom; |
Jens Arnold | 8325e0b | 2006-05-23 07:48:43 +0000 | [diff] [blame] | 163 | unsigned char *dst = line; |
| 164 | unsigned dst_mask = 0x80; |
| 165 | |
| 166 | memset(line, 0, sizeof(line)); |
Jens Arnold | ad4e3d6 | 2007-03-26 07:52:13 +0000 | [diff] [blame] | 167 | for (x = SIM_LCD_WIDTH; x > 0; x--) |
Jens Arnold | 8325e0b | 2006-05-23 07:48:43 +0000 | [diff] [blame] | 168 | { |
| 169 | if (*src) |
| 170 | *dst |= dst_mask; |
| 171 | src += display_zoom; |
| 172 | dst_mask >>= 1; |
| 173 | if (dst_mask == 0) |
| 174 | { |
| 175 | dst++; |
| 176 | dst_mask = 0x80; |
| 177 | } |
| 178 | } |
| 179 | write(fd, line, sizeof(line)); |
| 180 | } |
| 181 | SDL_UnlockSurface(lcd_surface); |
| 182 | close(fd); |
| 183 | } |