summaryrefslogtreecommitdiff
path: root/firmware/drivers/lcd-2bit-vi.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/drivers/lcd-2bit-vi.c')
-rw-r--r--firmware/drivers/lcd-2bit-vi.c145
1 files changed, 17 insertions, 128 deletions
diff --git a/firmware/drivers/lcd-2bit-vi.c b/firmware/drivers/lcd-2bit-vi.c
index 0580705a05..b19fdba266 100644
--- a/firmware/drivers/lcd-2bit-vi.c
+++ b/firmware/drivers/lcd-2bit-vi.c
@@ -103,6 +103,8 @@ static void *LCDFN(frameaddress_default)(int x, int y)
103 return fb->FBFN(ptr) + element;/*(element % fb->elems);*/ 103 return fb->FBFN(ptr) + element;/*(element % fb->elems);*/
104} 104}
105 105
106#include "lcd-bitmap-common.c"
107
106/* LCD init */ 108/* LCD init */
107void LCDFN(init)(void) 109void LCDFN(init)(void)
108{ 110{
@@ -453,10 +455,8 @@ void LCDFN(clear_viewport)(void)
453/* Set a single pixel */ 455/* Set a single pixel */
454void LCDFN(drawpixel)(int x, int y) 456void LCDFN(drawpixel)(int x, int y)
455{ 457{
456 if ( ((unsigned)x < (unsigned)CURRENT_VP->width) 458 if (LCDFN(clip_viewport_pixel)(&x, &y))
457 && ((unsigned)y < (unsigned)CURRENT_VP->height) 459 LCDFN(pixelfuncs)[CURRENT_VP->drawmode](x, y);
458 )
459 LCDFN(pixelfuncs)[CURRENT_VP->drawmode](CURRENT_VP->x+x, CURRENT_VP->y+y);
460} 460}
461 461
462/* Draw a line */ 462/* Draw a line */
@@ -468,6 +468,7 @@ void LCDFN(drawline)(int x1, int y1, int x2, int y2)
468 int d, dinc1, dinc2; 468 int d, dinc1, dinc2;
469 int x, xinc1, xinc2; 469 int x, xinc1, xinc2;
470 int y, yinc1, yinc2; 470 int y, yinc1, yinc2;
471 int x_vp, y_vp, w_vp, h_vp;
471 LCDFN(pixelfunc_type) *pfunc = LCDFN(pixelfuncs)[CURRENT_VP->drawmode]; 472 LCDFN(pixelfunc_type) *pfunc = LCDFN(pixelfuncs)[CURRENT_VP->drawmode];
472 473
473 deltax = abs(x2 - x1); 474 deltax = abs(x2 - x1);
@@ -522,12 +523,15 @@ void LCDFN(drawline)(int x1, int y1, int x2, int y2)
522 x = x1; 523 x = x1;
523 y = y1; 524 y = y1;
524 525
526 x_vp = CURRENT_VP->x;
527 y_vp = CURRENT_VP->y;
528 w_vp = CURRENT_VP->width;
529 h_vp = CURRENT_VP->height;
530
525 for (i = 0; i < numpixels; i++) 531 for (i = 0; i < numpixels; i++)
526 { 532 {
527 if ( ((unsigned)x < (unsigned)CURRENT_VP->width) 533 if (x >= 0 && y >= 0 && x < w_vp && y < h_vp)
528 && ((unsigned)y < (unsigned)CURRENT_VP->height) 534 pfunc(x + x_vp, y + y_vp);
529 )
530 pfunc(CURRENT_VP->x + x, CURRENT_VP->y + y);
531 535
532 if (d < 0) 536 if (d < 0)
533 { 537 {
@@ -547,36 +551,14 @@ void LCDFN(drawline)(int x1, int y1, int x2, int y2)
547/* Draw a horizontal line (optimised) */ 551/* Draw a horizontal line (optimised) */
548void LCDFN(hline)(int x1, int x2, int y) 552void LCDFN(hline)(int x1, int x2, int y)
549{ 553{
550 int x;
551 int width; 554 int width;
552 FBFN(data) *dst, *dst_end; 555 FBFN(data) *dst, *dst_end;
553 unsigned mask; 556 unsigned mask;
554 LCDFN(blockfunc_type) *bfunc; 557 LCDFN(blockfunc_type) *bfunc;
555 558
556 /* direction flip */ 559 if (!LCDFN(clip_viewport_hline)(&x1, &x2, &y))
557 if (x2 < x1)
558 {
559 x = x1;
560 x1 = x2;
561 x2 = x;
562 }
563
564 /******************** In viewport clipping **********************/
565 /* nothing to draw? */
566 if (((unsigned)y >= (unsigned)CURRENT_VP->height) || (x1 >= CURRENT_VP->width)
567 || (x2 < 0))
568 return; 560 return;
569 561
570 if (x1 < 0)
571 x1 = 0;
572 if (x2 >= CURRENT_VP->width)
573 x2 = CURRENT_VP->width-1;
574
575 /* adjust x1 and y to viewport */
576 x1 += CURRENT_VP->x;
577 x2 += CURRENT_VP->x;
578 y += CURRENT_VP->y;
579
580 width = x2 - x1 + 1; 562 width = x2 - x1 + 1;
581 563
582 bfunc = LCDFN(blockfuncs)[CURRENT_VP->drawmode]; 564 bfunc = LCDFN(blockfuncs)[CURRENT_VP->drawmode];
@@ -598,30 +580,9 @@ void LCDFN(vline)(int x, int y1, int y2)
598 unsigned mask, mask_bottom; 580 unsigned mask, mask_bottom;
599 LCDFN(blockfunc_type) *bfunc; 581 LCDFN(blockfunc_type) *bfunc;
600 582
601 /* direction flip */ 583 if (!LCDFN(clip_viewport_vline)(&x, &y1, &y2))
602 if (y2 < y1)
603 {
604 ny = y1;
605 y1 = y2;
606 y2 = ny;
607 }
608
609 /******************** In viewport clipping **********************/
610 /* nothing to draw? */
611 if (((unsigned)x >= (unsigned)CURRENT_VP->width) || (y1 >= CURRENT_VP->height)
612 || (y2 < 0))
613 return; 584 return;
614 585
615 if (y1 < 0)
616 y1 = 0;
617 if (y2 >= CURRENT_VP->height)
618 y2 = CURRENT_VP->height-1;
619
620 /* adjust for viewport */
621 y1 += CURRENT_VP->y;
622 y2 += CURRENT_VP->y;
623 x += CURRENT_VP->x;
624
625 bfunc = LCDFN(blockfuncs)[CURRENT_VP->drawmode]; 586 bfunc = LCDFN(blockfuncs)[CURRENT_VP->drawmode];
626 dst = LCDFB(x,y1>>3); 587 dst = LCDFB(x,y1>>3);
627 stride_dst = CURRENT_VP->buffer->stride; 588 stride_dst = CURRENT_VP->buffer->stride;
@@ -667,31 +628,9 @@ void LCDFN(fillrect)(int x, int y, int width, int height)
667 LCDFN(blockfunc_type) *bfunc; 628 LCDFN(blockfunc_type) *bfunc;
668 bool fillopt = false; 629 bool fillopt = false;
669 630
670 /******************** In viewport clipping **********************/ 631 if (!LCDFN(clip_viewport_rect)(&x, &y, &width, &height, NULL, NULL))
671 /* nothing to draw? */
672 if ((width <= 0) || (height <= 0) || (x >= CURRENT_VP->width)
673 || (y >= CURRENT_VP->height) || (x + width <= 0) || (y + height <= 0))
674 return; 632 return;
675 633
676 if (x < 0)
677 {
678 width += x;
679 x = 0;
680 }
681 if (y < 0)
682 {
683 height += y;
684 y = 0;
685 }
686 if (x + width > CURRENT_VP->width)
687 width = CURRENT_VP->width - x;
688 if (y + height > CURRENT_VP->height)
689 height = CURRENT_VP->height - y;
690
691 /* adjust for viewport */
692 x += CURRENT_VP->x;
693 y += CURRENT_VP->y;
694
695 if (CURRENT_VP->drawmode & DRMODE_INVERSEVID) 634 if (CURRENT_VP->drawmode & DRMODE_INVERSEVID)
696 { 635 {
697 if ((CURRENT_VP->drawmode & DRMODE_BG) && !backdrop) 636 if ((CURRENT_VP->drawmode & DRMODE_BG) && !backdrop)
@@ -769,33 +708,9 @@ void ICODE_ATTR LCDFN(mono_bitmap_part)(const unsigned char *src, int src_x,
769 unsigned data, mask, mask_bottom; 708 unsigned data, mask, mask_bottom;
770 LCDFN(blockfunc_type) *bfunc; 709 LCDFN(blockfunc_type) *bfunc;
771 710
772 /******************** Image in viewport clipping **********************/ 711 if (!LCDFN(clip_viewport_rect)(&x, &y, &width, &height, &src_x, &src_y))
773 /* nothing to draw? */
774 if ((width <= 0) || (height <= 0) || (x >= CURRENT_VP->width) ||
775 (y >= CURRENT_VP->height) || (x + width <= 0) || (y + height <= 0))
776 return; 712 return;
777 713
778 if (x < 0)
779 {
780 width += x;
781 src_x -= x;
782 x = 0;
783 }
784 if (y < 0)
785 {
786 height += y;
787 src_y -= y;
788 y = 0;
789 }
790 if (x + width > CURRENT_VP->width)
791 width = CURRENT_VP->width - x;
792 if (y + height > CURRENT_VP->height)
793 height = CURRENT_VP->height - y;
794
795 /* adjust for viewport */
796 x += CURRENT_VP->x;
797 y += CURRENT_VP->y;
798
799 src += stride * (src_y >> 3) + src_x; /* move starting point */ 714 src += stride * (src_y >> 3) + src_x; /* move starting point */
800 src_y &= 7; 715 src_y &= 7;
801 y -= src_y; 716 y -= src_y;
@@ -913,33 +828,9 @@ void ICODE_ATTR LCDFN(bitmap_part)(const FBFN(data) *src, int src_x,
913 int stride_dst; 828 int stride_dst;
914 unsigned mask, mask_bottom; 829 unsigned mask, mask_bottom;
915 830
916 /******************** Image in viewport clipping **********************/ 831 if (!LCDFN(clip_viewport_rect)(&x, &y, &width, &height, &src_x, &src_y))
917 /* nothing to draw? */
918 if ((width <= 0) || (height <= 0) || (x >= CURRENT_VP->width)
919 || (y >= CURRENT_VP->height) || (x + width <= 0) || (y + height <= 0))
920 return; 832 return;
921 833
922 if (x < 0)
923 {
924 width += x;
925 src_x -= x;
926 x = 0;
927 }
928 if (y < 0)
929 {
930 height += y;
931 src_y -= y;
932 y = 0;
933 }
934 if (x + width > CURRENT_VP->width)
935 width = CURRENT_VP->width - x;
936 if (y + height > CURRENT_VP->height)
937 height = CURRENT_VP->height - y;
938
939 /* adjust for viewport */
940 x += CURRENT_VP->x;
941 y += CURRENT_VP->y;
942
943 src += stride * (src_y >> 3) + src_x; /* move starting point */ 834 src += stride * (src_y >> 3) + src_x; /* move starting point */
944 src_y &= 7; 835 src_y &= 7;
945 y -= src_y; 836 y -= src_y;
@@ -1036,5 +927,3 @@ void LCDFN(bitmap)(const FBFN(data) *src, int x, int y, int width, int height)
1036{ 927{
1037 LCDFN(bitmap_part)(src, 0, 0, width, x, y, width, height); 928 LCDFN(bitmap_part)(src, 0, 0, width, x, y, width, height);
1038} 929}
1039
1040#include "lcd-bitmap-common.c"