diff options
Diffstat (limited to 'apps/plugins/lib/grey_core.c')
-rw-r--r-- | apps/plugins/lib/grey_core.c | 113 |
1 files changed, 55 insertions, 58 deletions
diff --git a/apps/plugins/lib/grey_core.c b/apps/plugins/lib/grey_core.c index 0fa7e28eb9..395a1130d5 100644 --- a/apps/plugins/lib/grey_core.c +++ b/apps/plugins/lib/grey_core.c | |||
@@ -30,13 +30,10 @@ | |||
30 | #define NEED_BOOST | 30 | #define NEED_BOOST |
31 | #endif | 31 | #endif |
32 | 32 | ||
33 | /* Global variables */ | ||
34 | struct plugin_api *_grey_rb = NULL; /* global api struct pointer */ | ||
35 | struct _grey_info _grey_info; /* global info structure */ | ||
36 | |||
37 | #ifndef SIMULATOR | 33 | #ifndef SIMULATOR |
38 | 34 | ||
39 | #if CONFIG_LCD == LCD_SSD1815 || CONFIG_LCD == LCD_IFP7XX || CONFIG_LCD == LCD_MROBE100 | 35 | #if CONFIG_LCD == LCD_SSD1815 || CONFIG_LCD == LCD_IFP7XX \ |
36 | || CONFIG_LCD == LCD_MROBE100 | ||
40 | /* measured and interpolated curve */ | 37 | /* measured and interpolated curve */ |
41 | /* TODO: check for iFP & m:robe 100 */ | 38 | /* TODO: check for iFP & m:robe 100 */ |
42 | static const unsigned char lcdlinear[256] = { | 39 | static const unsigned char lcdlinear[256] = { |
@@ -205,16 +202,16 @@ static inline void _deferred_update(void) | |||
205 | int y2 = MIN(_grey_info.y + _grey_info.height, LCD_HEIGHT); | 202 | int y2 = MIN(_grey_info.y + _grey_info.height, LCD_HEIGHT); |
206 | 203 | ||
207 | if (y1 > 0) /* refresh part above overlay, full width */ | 204 | if (y1 > 0) /* refresh part above overlay, full width */ |
208 | _grey_rb->lcd_update_rect(0, 0, LCD_WIDTH, y1); | 205 | _grey_info.rb->lcd_update_rect(0, 0, LCD_WIDTH, y1); |
209 | 206 | ||
210 | if (y2 < LCD_HEIGHT) /* refresh part below overlay, full width */ | 207 | if (y2 < LCD_HEIGHT) /* refresh part below overlay, full width */ |
211 | _grey_rb->lcd_update_rect(0, y2, LCD_WIDTH, LCD_HEIGHT - y2); | 208 | _grey_info.rb->lcd_update_rect(0, y2, LCD_WIDTH, LCD_HEIGHT - y2); |
212 | 209 | ||
213 | if (x1 > 0) /* refresh part to the left of overlay */ | 210 | if (x1 > 0) /* refresh part to the left of overlay */ |
214 | _grey_rb->lcd_update_rect(0, y1, x1, y2 - y1); | 211 | _grey_info.rb->lcd_update_rect(0, y1, x1, y2 - y1); |
215 | 212 | ||
216 | if (x2 < LCD_WIDTH) /* refresh part to the right of overlay */ | 213 | if (x2 < LCD_WIDTH) /* refresh part to the right of overlay */ |
217 | _grey_rb->lcd_update_rect(x2, y1, LCD_WIDTH - x2, y2 - y1); | 214 | _grey_info.rb->lcd_update_rect(x2, y1, LCD_WIDTH - x2, y2 - y1); |
218 | } | 215 | } |
219 | 216 | ||
220 | #ifndef SIMULATOR | 217 | #ifndef SIMULATOR |
@@ -222,18 +219,18 @@ static inline void _deferred_update(void) | |||
222 | static void _timer_isr(void) | 219 | static void _timer_isr(void) |
223 | { | 220 | { |
224 | #if LCD_PIXELFORMAT == HORIZONTAL_PACKING | 221 | #if LCD_PIXELFORMAT == HORIZONTAL_PACKING |
225 | _grey_rb->lcd_grey_phase_blit(_grey_info.values, _grey_info.phases, | 222 | _grey_info.rb->lcd_grey_phase_blit(_grey_info.values, _grey_info.phases, |
226 | _grey_info.bx, _grey_info.y, | 223 | _grey_info.bx, _grey_info.y, |
227 | _grey_info.bwidth, _grey_info.height, | 224 | _grey_info.bwidth, _grey_info.height, |
228 | _grey_info.width); | 225 | _grey_info.width); |
229 | #else | 226 | #else |
230 | _grey_rb->lcd_grey_phase_blit(_grey_info.values, _grey_info.phases, | 227 | _grey_info.rb->lcd_grey_phase_blit(_grey_info.values, _grey_info.phases, |
231 | _grey_info.x, _grey_info.by, | 228 | _grey_info.x, _grey_info.by, |
232 | _grey_info.width, _grey_info.bheight, | 229 | _grey_info.width, _grey_info.bheight, |
233 | _grey_info.width); | 230 | _grey_info.width); |
234 | #endif | 231 | #endif |
235 | 232 | ||
236 | if (_grey_info.flags & _GREY_DEFERRED_UPDATE) /* lcd_update() requested? */ | 233 | if (_grey_info.flags & _GREY_DEFERRED_UPDATE) /* lcd_update() requested? */ |
237 | { | 234 | { |
238 | _deferred_update(); | 235 | _deferred_update(); |
239 | _grey_info.flags &= ~_GREY_DEFERRED_UPDATE; /* clear request */ | 236 | _grey_info.flags &= ~_GREY_DEFERRED_UPDATE; /* clear request */ |
@@ -246,7 +243,7 @@ static int exp_s16p16(int x) | |||
246 | { | 243 | { |
247 | int t; | 244 | int t; |
248 | int y = 0x00010000; | 245 | int y = 0x00010000; |
249 | 246 | ||
250 | if (x < 0) x += 0xb1721, y >>= 16; | 247 | if (x < 0) x += 0xb1721, y >>= 16; |
251 | t = x - 0x58b91; if (t >= 0) x = t, y <<= 8; | 248 | t = x - 0x58b91; if (t >= 0) x = t, y <<= 8; |
252 | t = x - 0x2c5c8; if (t >= 0) x = t, y <<= 4; | 249 | t = x - 0x2c5c8; if (t >= 0) x = t, y <<= 4; |
@@ -326,7 +323,7 @@ bool grey_init(struct plugin_api* newrb, unsigned char *gbuf, long gbuf_size, | |||
326 | unsigned *dst, *end; | 323 | unsigned *dst, *end; |
327 | #endif | 324 | #endif |
328 | 325 | ||
329 | _grey_rb = newrb; | 326 | _grey_info.rb = newrb; |
330 | 327 | ||
331 | if ((unsigned) width > LCD_WIDTH | 328 | if ((unsigned) width > LCD_WIDTH |
332 | || (unsigned) height > LCD_HEIGHT) | 329 | || (unsigned) height > LCD_HEIGHT) |
@@ -347,10 +344,10 @@ bool grey_init(struct plugin_api* newrb, unsigned char *gbuf, long gbuf_size, | |||
347 | 344 | ||
348 | plane_size = _GREY_MULUQ(width, height); | 345 | plane_size = _GREY_MULUQ(width, height); |
349 | #ifdef CPU_COLDFIRE | 346 | #ifdef CPU_COLDFIRE |
350 | plane_size += (-plane_size) & 0xf; /* All buffers should be line aligned */ | 347 | plane_size += (-plane_size) & 0xf; /* All buffers should be line aligned */ |
351 | buftaken = (-(long)gbuf) & 0xf; | 348 | buftaken = (-(long)gbuf) & 0xf; |
352 | #else | 349 | #else |
353 | buftaken = (-(long)gbuf) & 3; /* All buffers must be long aligned. */ | 350 | buftaken = (-(long)gbuf) & 3; /* All buffers must be long aligned. */ |
354 | #endif | 351 | #endif |
355 | gbuf += buftaken; | 352 | gbuf += buftaken; |
356 | 353 | ||
@@ -371,17 +368,17 @@ bool grey_init(struct plugin_api* newrb, unsigned char *gbuf, long gbuf_size, | |||
371 | 368 | ||
372 | if (buftaken > gbuf_size) | 369 | if (buftaken > gbuf_size) |
373 | return false; | 370 | return false; |
374 | 371 | ||
375 | #ifndef SIMULATOR | 372 | #ifndef SIMULATOR |
376 | /* Init to white */ | 373 | /* Init to white */ |
377 | _grey_rb->memset(_grey_info.values, 0x80, plane_size); | 374 | _grey_info.rb->memset(_grey_info.values, 0x80, plane_size); |
378 | 375 | ||
379 | /* Init phases with random bits */ | 376 | /* Init phases with random bits */ |
380 | dst = (unsigned*)(_grey_info.phases); | 377 | dst = (unsigned*)(_grey_info.phases); |
381 | end = (unsigned*)(_grey_info.phases + plane_size); | 378 | end = (unsigned*)(_grey_info.phases + plane_size); |
382 | 379 | ||
383 | do | 380 | do |
384 | *dst++ = _grey_rb->rand(); | 381 | *dst++ = _grey_info.rb->rand(); |
385 | while (dst < end); | 382 | while (dst < end); |
386 | #endif | 383 | #endif |
387 | 384 | ||
@@ -444,46 +441,46 @@ void grey_show(bool enable) | |||
444 | { | 441 | { |
445 | _grey_info.flags |= _GREY_RUNNING; | 442 | _grey_info.flags |= _GREY_RUNNING; |
446 | #ifdef SIMULATOR | 443 | #ifdef SIMULATOR |
447 | _grey_rb->sim_lcd_ex_init(129, _grey_get_pixel); | 444 | _grey_info.rb->sim_lcd_ex_init(129, _grey_get_pixel); |
448 | grey_update(); | 445 | grey_update(); |
449 | #else /* !SIMULATOR */ | 446 | #else /* !SIMULATOR */ |
450 | #ifdef NEED_BOOST | 447 | #ifdef NEED_BOOST |
451 | _grey_rb->cpu_boost(true); | 448 | _grey_info.rb->cpu_boost(true); |
452 | #endif | 449 | #endif |
453 | #if CONFIG_LCD == LCD_SSD1815 | 450 | #if CONFIG_LCD == LCD_SSD1815 |
454 | _grey_rb->timer_register(1, NULL, TIMER_FREQ / 67, 1, _timer_isr); | 451 | _grey_info.rb->timer_register(1, NULL, TIMER_FREQ / 67, 1, _timer_isr); |
455 | #elif CONFIG_LCD == LCD_S1D15E06 | 452 | #elif CONFIG_LCD == LCD_S1D15E06 |
456 | _grey_rb->timer_register(1, NULL, TIMER_FREQ / 70, 1, _timer_isr); | 453 | _grey_info.rb->timer_register(1, NULL, TIMER_FREQ / 70, 1, _timer_isr); |
457 | #elif CONFIG_LCD == LCD_IPOD2BPP | 454 | #elif CONFIG_LCD == LCD_IPOD2BPP |
458 | #ifdef IPOD_1G2G | 455 | #ifdef IPOD_1G2G |
459 | _grey_rb->timer_register(1, NULL, TIMER_FREQ / 95, 1, _timer_isr); /* verified */ | 456 | _grey_info.rb->timer_register(1, NULL, TIMER_FREQ / 95, 1, _timer_isr); /* verified */ |
460 | #elif defined IPOD_3G | 457 | #elif defined IPOD_3G |
461 | _grey_rb->timer_register(1, NULL, TIMER_FREQ / 87, 1, _timer_isr); /* verified */ | 458 | _grey_info.rb->timer_register(1, NULL, TIMER_FREQ / 87, 1, _timer_isr); /* verified */ |
462 | #else | 459 | #else |
463 | /* FIXME: verify value */ | 460 | /* FIXME: verify value */ |
464 | _grey_rb->timer_register(1, NULL, TIMER_FREQ / 80, 1, _timer_isr); | 461 | _grey_info.rb->timer_register(1, NULL, TIMER_FREQ / 80, 1, _timer_isr); |
465 | #endif | 462 | #endif |
466 | #elif CONFIG_LCD == LCD_IPODMINI | 463 | #elif CONFIG_LCD == LCD_IPODMINI |
467 | _grey_rb->timer_register(1, NULL, TIMER_FREQ / 88, 1, _timer_isr); | 464 | _grey_info.rb->timer_register(1, NULL, TIMER_FREQ / 88, 1, _timer_isr); |
468 | #elif CONFIG_LCD == LCD_IFP7XX | 465 | #elif CONFIG_LCD == LCD_IFP7XX |
469 | _grey_rb->timer_register(1, NULL, TIMER_FREQ / 83, 1, _timer_isr); | 466 | _grey_info.rb->timer_register(1, NULL, TIMER_FREQ / 83, 1, _timer_isr); |
470 | #endif /* CONFIG_LCD */ | 467 | #endif /* CONFIG_LCD */ |
471 | #endif /* !SIMULATOR */ | 468 | #endif /* !SIMULATOR */ |
472 | _grey_rb->screen_dump_set_hook(grey_screendump_hook); | 469 | _grey_info.rb->screen_dump_set_hook(grey_screendump_hook); |
473 | } | 470 | } |
474 | else if (!enable && (_grey_info.flags & _GREY_RUNNING)) | 471 | else if (!enable && (_grey_info.flags & _GREY_RUNNING)) |
475 | { | 472 | { |
476 | #ifdef SIMULATOR | 473 | #ifdef SIMULATOR |
477 | _grey_rb->sim_lcd_ex_init(0, NULL); | 474 | _grey_info.rb->sim_lcd_ex_init(0, NULL); |
478 | #else | 475 | #else |
479 | _grey_rb->timer_unregister(); | 476 | _grey_info.rb->timer_unregister(); |
480 | #ifdef NEED_BOOST | 477 | #ifdef NEED_BOOST |
481 | _grey_rb->cpu_boost(false); | 478 | _grey_info.rb->cpu_boost(false); |
482 | #endif | 479 | #endif |
483 | #endif | 480 | #endif |
484 | _grey_info.flags &= ~_GREY_RUNNING; | 481 | _grey_info.flags &= ~_GREY_RUNNING; |
485 | _grey_rb->screen_dump_set_hook(NULL); | 482 | _grey_info.rb->screen_dump_set_hook(NULL); |
486 | _grey_rb->lcd_update(); /* restore whatever there was before */ | 483 | _grey_info.rb->lcd_update(); /* restore whatever there was before */ |
487 | } | 484 | } |
488 | } | 485 | } |
489 | 486 | ||
@@ -512,7 +509,7 @@ void grey_update_rect(int x, int y, int width, int height) | |||
512 | if (y + height > LCD_HEIGHT) | 509 | if (y + height > LCD_HEIGHT) |
513 | height = LCD_HEIGHT - y; | 510 | height = LCD_HEIGHT - y; |
514 | 511 | ||
515 | _grey_rb->sim_lcd_ex_update_rect(x, y, width, height); | 512 | _grey_info.rb->sim_lcd_ex_update_rect(x, y, width, height); |
516 | } | 513 | } |
517 | 514 | ||
518 | #else /* !SIMULATOR */ | 515 | #else /* !SIMULATOR */ |
@@ -523,20 +520,20 @@ void grey_update_rect(int x, int y, int width, int height) | |||
523 | 520 | ||
524 | if ((width <= 0) || (height <= 0)) | 521 | if ((width <= 0) || (height <= 0)) |
525 | return; /* nothing to do */ | 522 | return; /* nothing to do */ |
526 | 523 | ||
527 | if (y + height > _grey_info.height) | 524 | if (y + height > _grey_info.height) |
528 | height = _grey_info.height - y; | 525 | height = _grey_info.height - y; |
529 | if (x + width > _grey_info.width) | 526 | if (x + width > _grey_info.width) |
530 | width = _grey_info.width - x; | 527 | width = _grey_info.width - x; |
531 | 528 | ||
532 | src = _grey_info.buffer + _GREY_MULUQ(_grey_info.width, y) + x; | 529 | src = _grey_info.buffer + _GREY_MULUQ(_grey_info.width, y) + x; |
533 | 530 | ||
534 | #if LCD_PIXELFORMAT == HORIZONTAL_PACKING | 531 | #if LCD_PIXELFORMAT == HORIZONTAL_PACKING |
535 | dst = _grey_info.values + _GREY_MULUQ(_grey_info.width, y) + x; | 532 | dst = _grey_info.values + _GREY_MULUQ(_grey_info.width, y) + x; |
536 | 533 | ||
537 | do | 534 | do |
538 | { | 535 | { |
539 | _grey_rb->memcpy(dst, src, width); | 536 | _grey_info.rb->memcpy(dst, src, width); |
540 | dst += _grey_info.width; | 537 | dst += _grey_info.width; |
541 | src += _grey_info.width; | 538 | src += _grey_info.width; |
542 | } | 539 | } |
@@ -557,7 +554,7 @@ void grey_update_rect(int x, int y, int width, int height) | |||
557 | dst += _GREY_BSIZE; | 554 | dst += _GREY_BSIZE; |
558 | } | 555 | } |
559 | while (src_row < src_end); | 556 | while (src_row < src_end); |
560 | 557 | ||
561 | y++; | 558 | y++; |
562 | src += _grey_info.width; | 559 | src += _grey_info.width; |
563 | } | 560 | } |
@@ -587,7 +584,7 @@ void grey_deferred_lcd_update(void) | |||
587 | #endif | 584 | #endif |
588 | } | 585 | } |
589 | else | 586 | else |
590 | _grey_rb->lcd_update(); | 587 | _grey_info.rb->lcd_update(); |
591 | } | 588 | } |
592 | 589 | ||
593 | /*** Screenshot ***/ | 590 | /*** Screenshot ***/ |
@@ -662,10 +659,10 @@ static void grey_screendump_hook(int fd) | |||
662 | unsigned char *clut_entry; | 659 | unsigned char *clut_entry; |
663 | unsigned char linebuf[MAX(4*BMP_VARCOLORS,BMP_LINESIZE)]; | 660 | unsigned char linebuf[MAX(4*BMP_VARCOLORS,BMP_LINESIZE)]; |
664 | 661 | ||
665 | _grey_rb->write(fd, bmpheader, sizeof(bmpheader)); /* write header */ | 662 | _grey_info.rb->write(fd, bmpheader, sizeof(bmpheader)); /* write header */ |
666 | 663 | ||
667 | /* build clut */ | 664 | /* build clut */ |
668 | _grey_rb->memset(linebuf, 0, 4*BMP_VARCOLORS); | 665 | _grey_info.rb->memset(linebuf, 0, 4*BMP_VARCOLORS); |
669 | clut_entry = linebuf; | 666 | clut_entry = linebuf; |
670 | 667 | ||
671 | for (i = 0; i <= 128; i++) | 668 | for (i = 0; i <= 128; i++) |
@@ -675,17 +672,17 @@ static void grey_screendump_hook(int fd) | |||
675 | *clut_entry++ = _GREY_MULUQ(BMP_RED, i) >> 7; | 672 | *clut_entry++ = _GREY_MULUQ(BMP_RED, i) >> 7; |
676 | clut_entry++; | 673 | clut_entry++; |
677 | } | 674 | } |
678 | _grey_rb->write(fd, linebuf, 4*BMP_VARCOLORS); | 675 | _grey_info.rb->write(fd, linebuf, 4*BMP_VARCOLORS); |
679 | 676 | ||
680 | /* BMP image goes bottom -> top */ | 677 | /* BMP image goes bottom -> top */ |
681 | for (y = LCD_HEIGHT - 1; y >= 0; y--) | 678 | for (y = LCD_HEIGHT - 1; y >= 0; y--) |
682 | { | 679 | { |
683 | _grey_rb->memset(linebuf, 0, BMP_LINESIZE); | 680 | _grey_info.rb->memset(linebuf, 0, BMP_LINESIZE); |
684 | 681 | ||
685 | gy = y - _grey_info.y; | 682 | gy = y - _grey_info.y; |
686 | #if LCD_PIXELFORMAT == HORIZONTAL_PACKING | 683 | #if LCD_PIXELFORMAT == HORIZONTAL_PACKING |
687 | #if LCD_DEPTH == 2 | 684 | #if LCD_DEPTH == 2 |
688 | lcdptr = _grey_rb->lcd_framebuffer + _GREY_MULUQ(LCD_FBWIDTH, y); | 685 | lcdptr = _grey_info.rb->lcd_framebuffer + _GREY_MULUQ(LCD_FBWIDTH, y); |
689 | 686 | ||
690 | for (x = 0; x < LCD_WIDTH; x += 4) | 687 | for (x = 0; x < LCD_WIDTH; x += 4) |
691 | { | 688 | { |
@@ -718,7 +715,7 @@ static void grey_screendump_hook(int fd) | |||
718 | #else /* LCD_PIXELFORMAT == VERTICAL_PACKING */ | 715 | #else /* LCD_PIXELFORMAT == VERTICAL_PACKING */ |
719 | #if LCD_DEPTH == 1 | 716 | #if LCD_DEPTH == 1 |
720 | mask = 1 << (y & 7); | 717 | mask = 1 << (y & 7); |
721 | lcdptr = _grey_rb->lcd_framebuffer + _GREY_MULUQ(LCD_WIDTH, y >> 3); | 718 | lcdptr = _grey_info.rb->lcd_framebuffer + _GREY_MULUQ(LCD_WIDTH, y >> 3); |
722 | 719 | ||
723 | for (x = 0; x < LCD_WIDTH; x++) | 720 | for (x = 0; x < LCD_WIDTH; x++) |
724 | { | 721 | { |
@@ -734,8 +731,8 @@ static void grey_screendump_hook(int fd) | |||
734 | #else | 731 | #else |
735 | linebuf[x] = BMP_FIXEDCOLORS | 732 | linebuf[x] = BMP_FIXEDCOLORS |
736 | + _grey_info.values[_GREY_MULUQ(_grey_info.width, | 733 | + _grey_info.values[_GREY_MULUQ(_grey_info.width, |
737 | gy & ~_GREY_BMASK) | 734 | gy & ~_GREY_BMASK) |
738 | + (gx << _GREY_BSHIFT) | 735 | + (gx << _GREY_BSHIFT) |
739 | + (~gy & _GREY_BMASK)]; | 736 | + (~gy & _GREY_BMASK)]; |
740 | #endif | 737 | #endif |
741 | } | 738 | } |
@@ -747,7 +744,7 @@ static void grey_screendump_hook(int fd) | |||
747 | } | 744 | } |
748 | #elif LCD_DEPTH == 2 | 745 | #elif LCD_DEPTH == 2 |
749 | shift = 2 * (y & 3); | 746 | shift = 2 * (y & 3); |
750 | lcdptr = _grey_rb->lcd_framebuffer + _GREY_MULUQ(LCD_WIDTH, y >> 2); | 747 | lcdptr = _grey_info.rb->lcd_framebuffer + _GREY_MULUQ(LCD_WIDTH, y >> 2); |
751 | 748 | ||
752 | for (x = 0; x < LCD_WIDTH; x++) | 749 | for (x = 0; x < LCD_WIDTH; x++) |
753 | { | 750 | { |
@@ -777,6 +774,6 @@ static void grey_screendump_hook(int fd) | |||
777 | #endif /* LCD_DEPTH */ | 774 | #endif /* LCD_DEPTH */ |
778 | #endif /* LCD_PIXELFORMAT */ | 775 | #endif /* LCD_PIXELFORMAT */ |
779 | 776 | ||
780 | _grey_rb->write(fd, linebuf, BMP_LINESIZE); | 777 | _grey_info.rb->write(fd, linebuf, BMP_LINESIZE); |
781 | } | 778 | } |
782 | } | 779 | } |