summaryrefslogtreecommitdiff
path: root/uisimulator/win32/lcd.c
diff options
context:
space:
mode:
Diffstat (limited to 'uisimulator/win32/lcd.c')
-rw-r--r--uisimulator/win32/lcd.c440
1 files changed, 440 insertions, 0 deletions
diff --git a/uisimulator/win32/lcd.c b/uisimulator/win32/lcd.c
new file mode 100644
index 0000000000..2d1d80ccc7
--- /dev/null
+++ b/uisimulator/win32/lcd.c
@@ -0,0 +1,440 @@
1#include <windows.h>
2#include <process.h>
3#include "uisw32.h"
4#include "lcd.h"
5
6#ifdef HAVE_LCD_CHARCELLS
7# ifndef JBP_OLD
8
9static char const lcd_ascii[] =
10{
11/*****************************************************************************************/
12/* x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 xA xB xC xD xE xF */
13/* ************************************************************************************/
14/* 0x */ 0x00,0x01,0x02,0x03,0x00,0x00,0x00,0x00,0x04,0x05,0x00,0x00,0x00,0x00,0x00,0x00,
15/* 1x */ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
16/* 2x */ 0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F,
17/* 3x */ 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C,0x3D,0x3E,0x3F,
18/* 4x */ 0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,0x4D,0x4E,0x4F,
19/* 5x */ 0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5A,0x5B,0x5C,0x5D,0x5E,0x5F,
20/* 6x */ 0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6A,0x6B,0x6C,0x6D,0x6E,0x6F,
21/* 7x */ 0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A,0x20,0x20,0x20,0x20,0x20,
22/* 8x */ 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
23/* 9x */ 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
24/* Ax */ 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
25/* Bx */ 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
26/* Cx */ 0x41,0x41,0x41,0x41,0x41,0x41,0x20,0x43,0x45,0x45,0x45,0x45,0x49,0x49,0x49,0x49,
27/* Dx */ 0x44,0x4E,0x4F,0x4F,0x4F,0x4F,0x4F,0x20,0x20,0x55,0x55,0x55,0x55,0x59,0x20,0x20,
28/* Ex */ 0x61,0x61,0x61,0x61,0x61,0x61,0x20,0x63,0x65,0x65,0x65,0x65,0x69,0x69,0x69,0x69,
29/* Fx */ 0x64,0x6E,0x6F,0x6F,0x6F,0x6F,0x6F,0x20,0x20,0x75,0x75,0x75,0x75,0x79,0x79,0x79
30/******/
31 };
32
33# else
34
35static char const lcd_ascii[] =
36 {
37/*****************************************************************************************/
38/* x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 xA xB xC xD xE xF */
39/* ************************************************************************************/
40/* 0x */ 0x00,0x01,0x02,0x03,0x00,0x00,0x00,0x00,0x85,0x89,0x00,0x00,0x00,0x00,0x00,0x00,
41/* 1x */ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
42/* 2x */ 0x24,0x25,0x26,0x37,0x06,0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F,0x30,0x31,0x32,0x33,
43/* 3x */ 0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C,0x3D,0x3E,0x3F,0x40,0x41,0x42,0x43,
44/* 4x */ 0x44,0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,0x4D,0x4E,0x4F,0x50,0x51,0x52,0x53,
45/* 5x */ 0x54,0x55,0x56,0x57,0x58,0x59,0x5A,0x5B,0x5C,0x5D,0x5E,0xA9,0x33,0xCE,0x00,0x15,
46/* 6x */ 0x00,0x65,0x66,0x67,0x68,0x69,0x6A,0x6B,0x6C,0x6D,0x6E,0x6F,0x70,0x71,0x72,0x73,
47/* 7x */ 0x74,0x75,0x76,0x77,0x78,0x79,0x7A,0x7B,0x7C,0x7D,0x7E,0x24,0x24,0x24,0x24,0x24,
48/* 8x */ 0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,
49/* 9x */ 0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,
50/* Ax */ 0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,
51/* Bx */ 0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,
52/* Cx */ 0x45,0x45,0x45,0x45,0x45,0x45,0x24,0x47,0x49,0x49,0x49,0x49,0x4D,0x4D,0x4D,0x4D,
53/* Dx */ 0x48,0x52,0x53,0x53,0x53,0x53,0x53,0x24,0x24,0x59,0x59,0x59,0x59,0x5D,0x24,0x24,
54/* Ex */ 0x65,0x65,0x65,0x65,0x65,0x65,0x24,0x67,0x69,0x69,0x69,0x69,0x6D,0x6D,0x6D,0x6D,
55/* Fx */ 0x73,0x72,0x73,0x73,0x73,0x73,0x73,0x24,0x24,0x79,0x79,0x79,0x79,0x7D,0x24,0x7D
56/******/
57 };
58
59# endif
60
61void lcd_puts (char const *string)
62{
63 while (*string)
64 lcd_data (LCD_ASCII(*string++));
65}
66
67void lcd_putns (char const *string,int n)
68{
69 while (n--)
70 lcd_data (LCD_ASCII(*string++));
71}
72
73void lcd_putc (int character)
74{
75 lcd_data (LCD_ASCII(character));
76}
77
78void lcd_pattern (int which,char const *pattern,int count)
79{
80 lcd_instruction (LCD_PRAM|which);
81 lcd_copy ((void *)pattern,count);
82}
83
84void lcd_puthex (unsigned int value,int digits)
85{
86 switch (digits) {
87 case 8:
88 lcd_puthex (value >> 16,4);
89 case 4:
90 lcd_puthex (value >> 8,2);
91 case 2:
92 lcd_puthex (value >> 4,1);
93 case 1:
94 value &= 15;
95 lcd_putc (value+((value < 10) ? '0' : ('A'-10)));
96 }
97}
98
99
100/* HAVE_LCD_CHARCELLS */
101#elif defined(HAVE_LCD_BITMAP)
102
103/*
104 * All bitmaps have this format:
105 * Bits within a byte are arranged veritcally, LSB at top.
106 * Bytes are stored in column-major format, with byte 0 at top left,
107 * byte 1 is 2nd from top, etc. Bytes following left-most column
108 * starts 2nd left column, etc.
109 *
110 * Note: The HW takes bitmap bytes in row-major order.
111 *
112 * Memory copy of display bitmap
113 */
114unsigned char display[DISP_X][DISP_Y/8];
115
116/*
117 * ASCII character generation tables
118 *
119 * This contains only the printable characters (0x20-0x7f).
120 * Each element in this table is a character pattern bitmap.
121 */
122#define ASCII_MIN 0x20 /* First char in table */
123#define ASCII_MAX 0x7f /* Last char in table */
124
125extern const unsigned char char_gen_6x8[][5][1];
126extern const unsigned char char_gen_8x12[][7][2];
127extern const unsigned char char_gen_12x16[][11][2];
128
129
130/* All zeros and ones bitmaps for area filling */
131static const unsigned char zeros[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
132 0x00, 0x00 };
133static const unsigned char ones[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
134 0xff, 0xff };
135
136static int lcd_y; /* Current pixel row */
137static int lcd_x; /* Current pixel column */
138static int lcd_size; /* Current font width */
139
140/*
141 * Clear the display
142 */
143void lcd_clear_display (void)
144{
145 lcd_position (0, 0, 8);
146 memset (display, 0, sizeof display);
147}
148
149/*
150 * Set current x,y position and font size
151 */
152void lcd_position (int x, int y, int size)
153{
154 if (x >= 0 && x < DISP_X && y >= 0 && y < DISP_Y)
155 {
156 lcd_x = x;
157 lcd_y = y;
158 }
159
160 lcd_size = size;
161}
162
163/*
164 * Display a string at current position and size
165 */
166void lcd_string (const char *str)
167{
168 int x = lcd_x;
169 int nx = lcd_size;
170 int ny, ch;
171 const unsigned char *src;
172
173 if (nx == 12)
174 ny = 16;
175 else if (nx == 8)
176 ny = 12;
177 else
178 {
179 nx = 6;
180 ny = 8;
181 }
182
183 while ((ch = *str++) != '\0')
184 {
185 if (ch == '\n' || lcd_x + nx > DISP_X)
186 {
187 /* Wrap to next line */
188 lcd_x = x;
189 lcd_y += ny;
190 }
191
192 if (lcd_y + ny > DISP_Y)
193 return;
194
195 /* Limit to char generation table */
196 if (ch >= ASCII_MIN && ch <= ASCII_MAX)
197 {
198 if (nx == 12)
199 src = char_gen_12x16[ch-ASCII_MIN][0];
200 else if (nx == 8)
201 src = char_gen_8x12[ch-ASCII_MIN][0];
202 else
203 src = char_gen_6x8[ch-ASCII_MIN][0];
204
205 lcd_bitmap (src, lcd_x, lcd_y, nx-1, ny, TRUE);
206 lcd_bitmap (zeros, lcd_x+nx-1, lcd_y, 1, ny, TRUE);
207
208 lcd_x += nx;
209 }
210 }
211}
212
213/*
214 * Display a bitmap at (x, y), size (nx, ny)
215 * clear is TRUE to clear destination area first
216 */
217void lcd_bitmap (const unsigned char *src, int x, int y, int nx, int ny,
218 bool clear)
219{
220 unsigned char *dst;
221 unsigned char *dst2 = &display[x][y/8];
222 unsigned int data, mask, mask2, mask3, mask4;
223 int shift = y & 7;
224
225 ny += shift;
226
227 /* Calculate bit masks */
228 mask4 = ~(0xfe << ((ny-1) & 7));
229 if (clear)
230 {
231 mask = ~(0xff << shift);
232 mask2 = 0;
233 mask3 = ~mask4;
234 if (ny <= 8)
235 mask3 |= mask;
236 }
237 else
238 mask = mask2 = mask3 = 0xff;
239
240 /* Loop for each column */
241 for (x = 0; x < nx; x++)
242 {
243 dst = dst2;
244 dst2 += DISP_Y/8;
245 data = 0;
246 y = 0;
247
248 if (ny > 8)
249 {
250 /* First partial row */
251 data = *src++ << shift;
252 *dst = (*dst & mask) ^ data;
253 data >>= 8;
254 dst++;
255
256 /* Intermediate rows */
257 for (y = 8; y < ny-8; y += 8)
258 {
259 data |= *src++ << shift;
260 *dst = (*dst & mask2) ^ data;
261 data >>= 8;
262 dst++;
263 }
264 }
265
266 /* Last partial row */
267 if (y + shift < ny)
268 data |= *src++ << shift;
269 *dst = (*dst & mask3) ^ (data & mask4);
270 }
271}
272
273/*
274 * Clear a rectangular area at (x, y), size (nx, ny)
275 */
276void lcd_clearrect (int x, int y, int nx, int ny)
277{
278 int i;
279 for (i = 0; i < nx; i++)
280 lcd_bitmap (zeros, x+i, y, 1, ny, TRUE);
281}
282
283/*
284 * Fill a rectangular area at (x, y), size (nx, ny)
285 */
286void lcd_fillrect (int x, int y, int nx, int ny)
287{
288 int i;
289 for (i = 0; i < nx; i++)
290 lcd_bitmap (ones, x+i, y, 1, ny, TRUE);
291}
292
293/* Invert a rectangular area at (x, y), size (nx, ny) */
294void lcd_invertrect (int x, int y, int nx, int ny)
295{
296 int i;
297 for (i = 0; i < nx; i++)
298 lcd_bitmap (ones, x+i, y, 1, ny, FALSE);
299}
300
301#define DRAW_PIXEL(x,y) display[x][y/8] |= (1<<(y&7))
302#define CLEAR_PIXEL(x,y) display[x][y/8] &= ~(1<<(y&7))
303
304void lcd_drawline( int x1, int y1, int x2, int y2 )
305{
306 int numpixels;
307 int i;
308 int deltax, deltay;
309 int d, dinc1, dinc2;
310 int x, xinc1, xinc2;
311 int y, yinc1, yinc2;
312
313 deltax = abs(x2 - x1);
314 deltay = abs(y2 - y1);
315
316 if(deltax >= deltay)
317 {
318 numpixels = deltax;
319 d = 2 * deltay - deltax;
320 dinc1 = deltay * 2;
321 dinc2 = (deltay - deltax) * 2;
322 xinc1 = 1;
323 xinc2 = 1;
324 yinc1 = 0;
325 yinc2 = 1;
326 }
327 else
328 {
329 numpixels = deltay;
330 d = 2 * deltax - deltay;
331 dinc1 = deltax * 2;
332 dinc2 = (deltax - deltay) * 2;
333 xinc1 = 0;
334 xinc2 = 1;
335 yinc1 = 1;
336 yinc2 = 1;
337 }
338 numpixels++; /* include endpoints */
339
340 if(x1 > x2)
341 {
342 xinc1 = -xinc1;
343 xinc2 = -xinc2;
344 }
345
346 if(y1 > y2)
347 {
348 yinc1 = -yinc1;
349 yinc2 = -yinc2;
350 }
351
352 x = x1;
353 y = y1;
354
355 for(i=0; i<numpixels; i++)
356 {
357 DRAW_PIXEL(x,y);
358
359 if(d < 0)
360 {
361 d += dinc1;
362 x += xinc1;
363 y += yinc1;
364 }
365 else
366 {
367 d += dinc2;
368 x += xinc2;
369 y += yinc2;
370 }
371 }
372}
373
374/*
375 * Set a single pixel
376 */
377void lcd_drawpixel(int x, int y)
378{
379 DRAW_PIXEL(x,y);
380}
381
382/*
383 * Clear a single pixel
384 */
385void lcd_clearpixel(int x, int y)
386{
387 CLEAR_PIXEL(x,y);
388}
389
390
391#else
392/* no LCD defined, no code to use */
393#endif
394
395//
396//
397//
398// simulator specific code
399//
400//
401//
402
403// varaibles
404unsigned char display[DISP_X][DISP_Y/8]; // the display
405char bitmap[DISP_Y][DISP_X]; // the ui display
406
407BITMAPINFO2 bmi =
408{
409 sizeof (BITMAPINFOHEADER),
410 DISP_X, -DISP_Y, 1, 8,
411 BI_RGB, 0, 0, 0, 2, 2,
412 UI_LCD_COLOR, 0, // green background color
413 0, 0, 0, 0 // black color
414}; // bitmap information
415
416
417// lcd_init
418// init lcd controler
419void lcd_init()
420{
421 lcd_clear_display ();
422}
423
424// lcd_update
425// update lcd
426void lcd_update()
427{
428 int x, y;
429 if (hGUIWnd == NULL)
430 _endthread ();
431
432 for (x = 0; x < DISP_X; x++)
433 for (y = 0; y < DISP_Y; y++)
434 bitmap[y][x] = ((display[x][y/8] >> (y & 7)) & 1);
435
436 InvalidateRect (hGUIWnd, NULL, FALSE);
437
438 // natural sleep :)
439 Sleep (50);
440} \ No newline at end of file