blob: 70a9dd9f40e29c1fc56cac9dc25b514b96b67320 [file] [log] [blame]
Mats Lidell36e935f2002-10-11 11:10:52 +00001/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 by Alan Korr
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#include "config.h"
Mats Lidell786d2c32002-10-18 09:20:48 +000020#include "hwcompat.h"
Mats Lidell36e935f2002-10-11 11:10:52 +000021
Mats Lidell36e935f2002-10-11 11:10:52 +000022#include "lcd.h"
23#include "kernel.h"
24#include "thread.h"
25#include <string.h>
26#include <stdlib.h>
27#include "file.h"
28#include "debug.h"
29#include "system.h"
Kjell Ericsonccfa8482002-10-21 20:20:09 +000030
31#include "font-player.h"
Kjell Ericson32622072002-10-28 20:00:19 +000032#include "lcd-playersim.h"
Mats Lidell36e935f2002-10-11 11:10:52 +000033
34/*** definitions ***/
35
Mats Lidell786d2c32002-10-18 09:20:48 +000036#define CHAR_WIDTH 6
37#define CHAR_HEIGHT 8
Kjell Ericson32622072002-10-28 20:00:19 +000038#define ICON_HEIGHT 24
39#define CHAR_PIXEL 4
Kjell Ericson54d5e2c2002-11-01 13:38:21 +000040#define BORDER_MARGIN 5
Mats Lidell36e935f2002-10-11 11:10:52 +000041
Mats Lidell786d2c32002-10-18 09:20:48 +000042static int double_height=1;
Kjell Ericson32622072002-10-28 20:00:19 +000043extern bool lcd_display_redraw;
Kjell Ericsonea3d4d52003-01-10 10:02:27 +000044extern const unsigned short *lcd_ascii;
45extern unsigned char hardware_buffer_lcd[11][2];
Kjell Ericson32622072002-10-28 20:00:19 +000046
Mats Lidell36e935f2002-10-11 11:10:52 +000047
Kjell Ericsonccfa8482002-10-21 20:20:09 +000048void lcd_print_icon(int x, int icon_line, bool enable, char **icon)
49{
50 int xpos = x;
Mats Lidell097bd102002-10-31 17:33:41 +000051 int ypos = icon_line*(ICON_HEIGHT+CHAR_HEIGHT*2*4);
Kjell Ericsonccfa8482002-10-21 20:20:09 +000052 int row=0, col;
Kjell Ericson32622072002-10-28 20:00:19 +000053
54 int p=0, cp=0;
55 struct coordinate points[LCD_WIDTH * LCD_HEIGHT];
56 struct coordinate clearpoints[LCD_WIDTH * LCD_HEIGHT];
Kjell Ericsonccfa8482002-10-21 20:20:09 +000057
58 while (icon[row]) {
59 col=0;
60 while (icon[row][col]) {
Kjell Ericson32622072002-10-28 20:00:19 +000061 switch(icon[row][col]) {
62 case '*':
63 if (enable) {
64 /* set a dot */
65 points[p].x = xpos + col +BORDER_MARGIN;
66 points[p].y = ypos+row +BORDER_MARGIN;
67 p++; /* increase the point counter */
68 } else {
69 /* clear a dot */
70 clearpoints[cp].x = xpos + col +BORDER_MARGIN;
71 clearpoints[cp].y = ypos+row +BORDER_MARGIN;
72 cp++; /* increase the point counter */
73 }
74 break;
75 case ' ': /* Clear bit */
76 /* clear a dot */
77 clearpoints[cp].x = xpos + col+BORDER_MARGIN;
78 clearpoints[cp].y = ypos+row+BORDER_MARGIN;
79 cp++; /* increase the point counter */
80 break;
Kjell Ericsonccfa8482002-10-21 20:20:09 +000081 }
82 col++;
83 }
84 row++;
85 }
Kjell Ericsonffefc5d2003-06-05 08:29:21 +000086/* DEBUGF("icon draw %d/%d\n", p, cp);*/
87 if (cp)
88 drawdots(0, &clearpoints[0], cp);
89 if (p)
90 drawdots(1, &points[0], p);
Kjell Ericsonccfa8482002-10-21 20:20:09 +000091}
92
Kjell Ericson32622072002-10-28 20:00:19 +000093void lcd_print_char(int x, int y)
Kjell Ericsonccfa8482002-10-21 20:20:09 +000094{
Kjell Ericson32622072002-10-28 20:00:19 +000095 int xpos = x * CHAR_WIDTH * CHAR_PIXEL;
96 int ypos = y * CHAR_HEIGHT * CHAR_PIXEL + ICON_HEIGHT;
Kjell Ericsonccfa8482002-10-21 20:20:09 +000097 int col, row;
Kjell Ericson32622072002-10-28 20:00:19 +000098 int p=0, cp=0;
99 struct rectangle points[CHAR_HEIGHT*CHAR_WIDTH];
100 struct rectangle clearpoints[CHAR_HEIGHT*CHAR_WIDTH];
Kjell Ericsonea3d4d52003-01-10 10:02:27 +0000101 unsigned char ch=hardware_buffer_lcd[x][y];
Kjell Ericsonffefc5d2003-06-05 08:29:21 +0000102 static char bitmap_content[11*8][2*8];
Kjell Ericson32622072002-10-28 20:00:19 +0000103
Kjell Ericsonccfa8482002-10-21 20:20:09 +0000104 if (double_height == 2 && y == 1)
105 return; /* Second row can't be printed in double height. ??*/
106
Kjell Ericsonccfa8482002-10-21 20:20:09 +0000107 for (col=0; col<5; col++) {
Kjell Ericsonffefc5d2003-06-05 08:29:21 +0000108 unsigned char fontbitmap=(*font_player)[ch][col];
Kjell Ericsonccfa8482002-10-21 20:20:09 +0000109 for (row=0; row<7; row++) {
Kjell Ericsonffefc5d2003-06-05 08:29:21 +0000110 char fontbit=fontbitmap&(1<<row);
Kjell Ericson32622072002-10-28 20:00:19 +0000111 int height=CHAR_PIXEL*double_height;
Kjell Ericsonffefc5d2003-06-05 08:29:21 +0000112 int ypixel;
113 if (bitmap_content[x*8+col][y*8+row*double_height]!=fontbit ||
114 bitmap_content[x*8+col][y*8+row*double_height+double_height-1]!=
115 fontbit) {
116 bitmap_content[x*8+col][y*8+row*double_height]=fontbit;
117 bitmap_content[x*8+col][y*8+row*double_height+double_height-1]=fontbit;
Kjell Ericsonccfa8482002-10-21 20:20:09 +0000118
Kjell Ericsonffefc5d2003-06-05 08:29:21 +0000119 ypixel=CHAR_PIXEL*(double_height*row)+ypos;
120 if (double_height==2) {
121 if (row == 3) /* Adjust for blank row in the middle */
122 height=CHAR_PIXEL;
123 }
Kjell Ericsonccfa8482002-10-21 20:20:09 +0000124
Kjell Ericsonffefc5d2003-06-05 08:29:21 +0000125 if (fontbit) {
126 /* set a dot */
127 points[p].x = xpos + col*CHAR_PIXEL +BORDER_MARGIN;
128 points[p].y = ypixel +BORDER_MARGIN;
129 points[p].width=CHAR_PIXEL;
130 points[p].height=height;
131 p++; /* increase the point counter */
132 } else {
133 clearpoints[cp].x = xpos + col*CHAR_PIXEL +BORDER_MARGIN;
134 clearpoints[cp].y = ypixel +BORDER_MARGIN;
135 clearpoints[cp].width=CHAR_PIXEL;
136 clearpoints[cp].height=height;
137 cp++;
138 }
Kjell Ericsonccfa8482002-10-21 20:20:09 +0000139 }
140 }
141 }
Kjell Ericsonffefc5d2003-06-05 08:29:21 +0000142/* DEBUGF("print_char %d/%d\n", p, cp);*/
143 if (cp)
144 drawrectangles(0, &clearpoints[0], cp);
145 if (p)
146 drawrectangles(1, &points[0], p);
Kjell Ericsonccfa8482002-10-21 20:20:09 +0000147}
148
Mats Lidell36e935f2002-10-11 11:10:52 +0000149
150/*
Mats Lidell36e935f2002-10-11 11:10:52 +0000151 * Draw a rectangle with upper left corner at (x, y)
152 * and size (nx, ny)
153 */
154void lcd_drawrect (int x, int y, int nx, int ny)
155{
Kjell Ericson32622072002-10-28 20:00:19 +0000156 (void)x;
157 (void)y;
158 (void)nx;
159 (void)ny;
Mats Lidell36e935f2002-10-11 11:10:52 +0000160}
161
Mats Lidell36e935f2002-10-11 11:10:52 +0000162/* Invert a rectangular area at (x, y), size (nx, ny) */
163void lcd_invertrect (int x, int y, int nx, int ny)
164{
Kjell Ericson32622072002-10-28 20:00:19 +0000165 (void)x;
166 (void)y;
167 (void)nx;
168 (void)ny;
Mats Lidell36e935f2002-10-11 11:10:52 +0000169}
170
171void lcd_drawline( int x1, int y1, int x2, int y2 )
172{
Kjell Ericson32622072002-10-28 20:00:19 +0000173 (void)x1;
174 (void)x2;
175 (void)y1;
176 (void)y2;
Mats Lidell36e935f2002-10-11 11:10:52 +0000177}
178
179void lcd_clearline( int x1, int y1, int x2, int y2 )
180{
Kjell Ericson32622072002-10-28 20:00:19 +0000181 (void)x1;
182 (void)x2;
183 (void)y1;
184 (void)y2;
Mats Lidell36e935f2002-10-11 11:10:52 +0000185}
186
187/*
188 * Set a single pixel
189 */
190void lcd_drawpixel(int x, int y)
191{
Kjell Ericson32622072002-10-28 20:00:19 +0000192 (void)x;
193 (void)y;
Mats Lidell36e935f2002-10-11 11:10:52 +0000194}
195
196/*
197 * Clear a single pixel
198 */
199void lcd_clearpixel(int x, int y)
200{
Kjell Ericson32622072002-10-28 20:00:19 +0000201 (void)x;
202 (void)y;
Mats Lidell36e935f2002-10-11 11:10:52 +0000203}
204
205/*
206 * Invert a single pixel
207 */
208void lcd_invertpixel(int x, int y)
209{
Kjell Ericson32622072002-10-28 20:00:19 +0000210 (void)x;
211 (void)y;
Mats Lidell36e935f2002-10-11 11:10:52 +0000212}
213
Mats Lidell36e935f2002-10-11 11:10:52 +0000214
Mats Lidell786d2c32002-10-18 09:20:48 +0000215
216void lcd_double_height(bool on)
217{
218 double_height = 1;
219 if (on)
220 double_height = 2;
Kjell Ericsondae8dea2002-10-29 10:43:30 +0000221 lcd_display_redraw=true;
222 lcd_update();
Mats Lidell786d2c32002-10-18 09:20:48 +0000223}
224
Kjell Ericsonea3d4d52003-01-10 10:02:27 +0000225void lcd_define_hw_pattern(int which, char *pattern, int length)
Mats Lidell786d2c32002-10-18 09:20:48 +0000226{
227 int i, j;
228 int pat = which / 8;
Kjell Ericsonea3d4d52003-01-10 10:02:27 +0000229 unsigned char icon[8];
Mats Lidell786d2c32002-10-18 09:20:48 +0000230 memset(icon, 0, sizeof icon);
Kjell Ericsonccfa8482002-10-21 20:20:09 +0000231
Kjell Ericsondae8dea2002-10-29 10:43:30 +0000232 DEBUGF("Defining pattern %d:", pat);
Mats Lidell786d2c32002-10-18 09:20:48 +0000233 for (j = 0; j <= 5; j++) {
234 for (i = 0; i < length; i++) {
235 if ((pattern[i])&(1<<(j)))
236 icon[5-j] |= (1<<(i));
237 }
238 }
Kjell Ericsonccfa8482002-10-21 20:20:09 +0000239 for (i = 1; i <= 5; i++)
Mats Lidell786d2c32002-10-18 09:20:48 +0000240 {
Kjell Ericsondae8dea2002-10-29 10:43:30 +0000241 DEBUGF(" 0x%02x", icon[i]);
Kjell Ericson32622072002-10-28 20:00:19 +0000242 (*font_player)[pat][i-1] = icon[i];
Mats Lidell786d2c32002-10-18 09:20:48 +0000243 }
Kjell Ericsondae8dea2002-10-29 10:43:30 +0000244 DEBUGF("\n");
Kjell Ericson32622072002-10-28 20:00:19 +0000245 lcd_display_redraw=true;
246 lcd_update();
Mats Lidell786d2c32002-10-18 09:20:48 +0000247}
248