summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAidan MacDonald <amachronic@protonmail.com>2022-10-02 00:54:11 +0100
committerAidan MacDonald <amachronic@protonmail.com>2022-10-12 07:34:15 -0400
commit6acc8a81a73114b614102beaaaf732b92f4e6ddd (patch)
treea04c7065ea1893fec08ae60910532ab578348391
parent726673c638f5ecc8928ee66bb2e10b651e60e325 (diff)
downloadrockbox-6acc8a81a73114b614102beaaaf732b92f4e6ddd.tar.gz
rockbox-6acc8a81a73114b614102beaaaf732b92f4e6ddd.zip
lcd: Cosmetic variable renaming
Assign lcd_current_viewport to a local variable for easier typing. Change-Id: Ib5d4283fd1c5a21c94d3bd3c2c28ce206383fb96
-rw-r--r--firmware/drivers/lcd-16bit-common.c64
-rw-r--r--firmware/drivers/lcd-16bit-vert.c26
-rw-r--r--firmware/drivers/lcd-16bit.c26
-rw-r--r--firmware/drivers/lcd-1bit-vert.c26
-rw-r--r--firmware/drivers/lcd-24bit.c71
-rw-r--r--firmware/drivers/lcd-2bit-horz.c21
-rw-r--r--firmware/drivers/lcd-2bit-vert.c27
-rw-r--r--firmware/drivers/lcd-2bit-vi.c27
8 files changed, 163 insertions, 125 deletions
diff --git a/firmware/drivers/lcd-16bit-common.c b/firmware/drivers/lcd-16bit-common.c
index ad41485dfe..a3a6dc6663 100644
--- a/firmware/drivers/lcd-16bit-common.c
+++ b/firmware/drivers/lcd-16bit-common.c
@@ -31,14 +31,15 @@
31/* Clear the current viewport */ 31/* Clear the current viewport */
32void lcd_clear_viewport(void) 32void lcd_clear_viewport(void)
33{ 33{
34 struct viewport *vp = lcd_current_viewport;
34 fb_data *dst, *dst_end; 35 fb_data *dst, *dst_end;
35 int x, y, width, height; 36 int x, y, width, height;
36 int len, step; 37 int len, step;
37 38
38 x = lcd_current_viewport->x; 39 x = vp->x;
39 y = lcd_current_viewport->y; 40 y = vp->y;
40 width = lcd_current_viewport->width; 41 width = vp->width;
41 height = lcd_current_viewport->height; 42 height = vp->height;
42 43
43 len = STRIDE_MAIN(width, height); 44 len = STRIDE_MAIN(width, height);
44 step = STRIDE_MAIN(ROW_INC, COL_INC); 45 step = STRIDE_MAIN(ROW_INC, COL_INC);
@@ -46,18 +47,18 @@ void lcd_clear_viewport(void)
46 dst = FBADDR(x, y); 47 dst = FBADDR(x, y);
47 dst_end = FBADDR(x + width - 1 , y + height - 1); 48 dst_end = FBADDR(x + width - 1 , y + height - 1);
48 49
49 if (lcd_current_viewport->drawmode & DRMODE_INVERSEVID) 50 if (vp->drawmode & DRMODE_INVERSEVID)
50 { 51 {
51 do 52 do
52 { 53 {
53 memset16(dst, lcd_current_viewport->fg_pattern, len); 54 memset16(dst, vp->fg_pattern, len);
54 dst += step; 55 dst += step;
55 } 56 }
56 while (dst <= dst_end); 57 while (dst <= dst_end);
57 } 58 }
58 else 59 else
59 { 60 {
60 if (lcd_backdrop && lcd_current_viewport->buffer == &lcd_framebuffer_default) 61 if (lcd_backdrop && vp->buffer == &lcd_framebuffer_default)
61 { 62 {
62 do 63 do
63 { 64 {
@@ -71,19 +72,19 @@ void lcd_clear_viewport(void)
71 { 72 {
72 do 73 do
73 { 74 {
74 memset16(dst, lcd_current_viewport->bg_pattern, len); 75 memset16(dst, vp->bg_pattern, len);
75 dst += step; 76 dst += step;
76 } 77 }
77 while (dst <= dst_end); 78 while (dst <= dst_end);
78 } 79 }
79 } 80 }
80 81
81 if (lcd_current_viewport == &default_vp) 82 if (vp == &default_vp)
82 lcd_scroll_stop(); 83 lcd_scroll_stop();
83 else 84 else
84 lcd_scroll_stop_viewport(lcd_current_viewport); 85 lcd_scroll_stop_viewport(vp);
85 86
86 lcd_current_viewport->flags &= ~(VP_FLAG_VP_SET_CLEAN); 87 vp->flags &= ~(VP_FLAG_VP_SET_CLEAN);
87} 88}
88 89
89/*** low-level drawing functions ***/ 90/*** low-level drawing functions ***/
@@ -128,6 +129,7 @@ lcd_fastpixelfunc_type* const * lcd_fastpixelfuncs = lcd_fastpixelfuncs_bgcolor;
128/* Fill a rectangular area */ 129/* Fill a rectangular area */
129void lcd_fillrect(int x, int y, int width, int height) 130void lcd_fillrect(int x, int y, int width, int height)
130{ 131{
132 struct viewport *vp = lcd_current_viewport;
131 unsigned bits = 0; 133 unsigned bits = 0;
132 enum fill_opt fillopt = OPT_NONE; 134 enum fill_opt fillopt = OPT_NONE;
133 fb_data *dst, *dst_end; 135 fb_data *dst, *dst_end;
@@ -137,14 +139,14 @@ void lcd_fillrect(int x, int y, int width, int height)
137 return; 139 return;
138 140
139 /* drawmode and optimisation */ 141 /* drawmode and optimisation */
140 if (lcd_current_viewport->drawmode & DRMODE_INVERSEVID) 142 if (vp->drawmode & DRMODE_INVERSEVID)
141 { 143 {
142 if (lcd_current_viewport->drawmode & DRMODE_BG) 144 if (vp->drawmode & DRMODE_BG)
143 { 145 {
144 if (!lcd_backdrop) 146 if (!lcd_backdrop)
145 { 147 {
146 fillopt = OPT_SET; 148 fillopt = OPT_SET;
147 bits = lcd_current_viewport->bg_pattern; 149 bits = vp->bg_pattern;
148 } 150 }
149 else 151 else
150 fillopt = OPT_COPY; 152 fillopt = OPT_COPY;
@@ -152,13 +154,13 @@ void lcd_fillrect(int x, int y, int width, int height)
152 } 154 }
153 else 155 else
154 { 156 {
155 if (lcd_current_viewport->drawmode & DRMODE_FG) 157 if (vp->drawmode & DRMODE_FG)
156 { 158 {
157 fillopt = OPT_SET; 159 fillopt = OPT_SET;
158 bits = lcd_current_viewport->fg_pattern; 160 bits = vp->fg_pattern;
159 } 161 }
160 } 162 }
161 if (fillopt == OPT_NONE && lcd_current_viewport->drawmode != DRMODE_COMPLEMENT) 163 if (fillopt == OPT_NONE && vp->drawmode != DRMODE_COMPLEMENT)
162 return; 164 return;
163 165
164 dst = FBADDR(x, y); 166 dst = FBADDR(x, y);
@@ -213,6 +215,7 @@ void ICODE_ATTR lcd_mono_bitmap_part(const unsigned char *src, int src_x,
213 int src_y, int stride, int x, int y, 215 int src_y, int stride, int x, int y,
214 int width, int height) 216 int width, int height)
215{ 217{
218 struct viewport *vp = lcd_current_viewport;
216 if (!lcd_clip_viewport_rect(&x, &y, &width, &height, &src_x, &src_y)) 219 if (!lcd_clip_viewport_rect(&x, &y, &width, &height, &src_x, &src_y))
217 return; 220 return;
218 221
@@ -221,7 +224,7 @@ void ICODE_ATTR lcd_mono_bitmap_part(const unsigned char *src, int src_x,
221 src_y &= 7; 224 src_y &= 7;
222 225
223 unsigned dmask = 0; 226 unsigned dmask = 0;
224 int drmode = lcd_current_viewport->drawmode; 227 int drmode = vp->drawmode;
225 228
226 if (drmode & DRMODE_INVERSEVID) 229 if (drmode & DRMODE_INVERSEVID)
227 { 230 {
@@ -267,7 +270,7 @@ void ICODE_ATTR lcd_mono_bitmap_part(const unsigned char *src, int src_x,
267 break; 270 break;
268 271
269 case DRMODE_BG: 272 case DRMODE_BG:
270 bg = lcd_current_viewport->bg_pattern; 273 bg = vp->bg_pattern;
271 do { 274 do {
272 data = (*src_col++ ^ dmask) >> src_y; 275 data = (*src_col++ ^ dmask) >> src_y;
273 if(!(data & 0x01)) 276 if(!(data & 0x01))
@@ -278,7 +281,7 @@ void ICODE_ATTR lcd_mono_bitmap_part(const unsigned char *src, int src_x,
278 break; 281 break;
279 282
280 case DRMODE_FG: 283 case DRMODE_FG:
281 fg = lcd_current_viewport->fg_pattern; 284 fg = vp->fg_pattern;
282 do { 285 do {
283 data = (*src_col++ ^ dmask) >> src_y; 286 data = (*src_col++ ^ dmask) >> src_y;
284 if(data & 0x01) 287 if(data & 0x01)
@@ -289,7 +292,7 @@ void ICODE_ATTR lcd_mono_bitmap_part(const unsigned char *src, int src_x,
289 break; 292 break;
290 293
291 case DRMODE_SOLID|DRMODE_INT_BD: 294 case DRMODE_SOLID|DRMODE_INT_BD:
292 fg = lcd_current_viewport->fg_pattern; 295 fg = vp->fg_pattern;
293 bo = lcd_backdrop_offset; 296 bo = lcd_backdrop_offset;
294 do { 297 do {
295 data = (*src_col++ ^ dmask) >> src_y; 298 data = (*src_col++ ^ dmask) >> src_y;
@@ -303,8 +306,8 @@ void ICODE_ATTR lcd_mono_bitmap_part(const unsigned char *src, int src_x,
303 break; 306 break;
304 307
305 case DRMODE_SOLID: 308 case DRMODE_SOLID:
306 fg = lcd_current_viewport->fg_pattern; 309 fg = vp->fg_pattern;
307 bg = lcd_current_viewport->bg_pattern; 310 bg = vp->bg_pattern;
308 do { 311 do {
309 data = (*src_col++ ^ dmask) >> src_y; 312 data = (*src_col++ ^ dmask) >> src_y;
310 if(data & 0x01) 313 if(data & 0x01)
@@ -416,9 +419,10 @@ static void ICODE_ATTR lcd_alpha_bitmap_part_mix(const fb_data* image,
416 int width, int height, 419 int width, int height,
417 int stride_image, int stride_src) 420 int stride_image, int stride_src)
418{ 421{
422 struct viewport *vp = lcd_current_viewport;
419 fb_data *dst, *dst_row; 423 fb_data *dst, *dst_row;
420 unsigned dmask = 0x00000000; 424 unsigned dmask = 0x00000000;
421 int drmode = lcd_current_viewport->drawmode; 425 int drmode = vp->drawmode;
422 426
423 if (!lcd_clip_viewport_rect(&x, &y, &width, &height, &src_x, &src_y)) 427 if (!lcd_clip_viewport_rect(&x, &y, &width, &height, &src_x, &src_y))
424 return; 428 return;
@@ -545,7 +549,7 @@ static void ICODE_ATTR lcd_alpha_bitmap_part_mix(const fb_data* image,
545 while (--col); 549 while (--col);
546 break; 550 break;
547 case DRMODE_BG: 551 case DRMODE_BG:
548 bg = lcd_current_viewport->bg_pattern; 552 bg = vp->bg_pattern;
549 do 553 do
550 { 554 {
551 *dst = blend_two_colors(bg, *dst, data & ALPHA_COLOR_LOOKUP_SIZE ); 555 *dst = blend_two_colors(bg, *dst, data & ALPHA_COLOR_LOOKUP_SIZE );
@@ -565,7 +569,7 @@ static void ICODE_ATTR lcd_alpha_bitmap_part_mix(const fb_data* image,
565 while (--col); 569 while (--col);
566 break; 570 break;
567 case DRMODE_FG: 571 case DRMODE_FG:
568 fg = lcd_current_viewport->fg_pattern; 572 fg = vp->fg_pattern;
569 do 573 do
570 { 574 {
571 *dst = blend_two_colors(*dst, fg, data & ALPHA_COLOR_LOOKUP_SIZE ); 575 *dst = blend_two_colors(*dst, fg, data & ALPHA_COLOR_LOOKUP_SIZE );
@@ -576,7 +580,7 @@ static void ICODE_ATTR lcd_alpha_bitmap_part_mix(const fb_data* image,
576 break; 580 break;
577 case DRMODE_SOLID|DRMODE_INT_BD: 581 case DRMODE_SOLID|DRMODE_INT_BD:
578 bo = lcd_backdrop_offset; 582 bo = lcd_backdrop_offset;
579 fg = lcd_current_viewport->fg_pattern; 583 fg = vp->fg_pattern;
580 do 584 do
581 { 585 {
582 fb_data *c = (fb_data *)((uintptr_t)dst + bo); 586 fb_data *c = (fb_data *)((uintptr_t)dst + bo);
@@ -587,7 +591,7 @@ static void ICODE_ATTR lcd_alpha_bitmap_part_mix(const fb_data* image,
587 while (--col); 591 while (--col);
588 break; 592 break;
589 case DRMODE_SOLID|DRMODE_INT_IMG: 593 case DRMODE_SOLID|DRMODE_INT_IMG:
590 bg = lcd_current_viewport->bg_pattern; 594 bg = vp->bg_pattern;
591 img_offset = image - dst; 595 img_offset = image - dst;
592 do 596 do
593 { 597 {
@@ -610,8 +614,8 @@ static void ICODE_ATTR lcd_alpha_bitmap_part_mix(const fb_data* image,
610 while (--col); 614 while (--col);
611 break; 615 break;
612 case DRMODE_SOLID: 616 case DRMODE_SOLID:
613 bg = lcd_current_viewport->bg_pattern; 617 bg = vp->bg_pattern;
614 fg = lcd_current_viewport->fg_pattern; 618 fg = vp->fg_pattern;
615 do 619 do
616 { 620 {
617 *dst = blend_two_colors(bg, fg, data & ALPHA_COLOR_LOOKUP_SIZE ); 621 *dst = blend_two_colors(bg, fg, data & ALPHA_COLOR_LOOKUP_SIZE );
diff --git a/firmware/drivers/lcd-16bit-vert.c b/firmware/drivers/lcd-16bit-vert.c
index c721ef6302..1c0d441af4 100644
--- a/firmware/drivers/lcd-16bit-vert.c
+++ b/firmware/drivers/lcd-16bit-vert.c
@@ -62,16 +62,17 @@ static void ICODE_ATTR lcd_alpha_bitmap_part_mix(const fb_data* image,
62/* Draw a horizontal line (optimised) */ 62/* Draw a horizontal line (optimised) */
63void lcd_hline(int x1, int x2, int y) 63void lcd_hline(int x1, int x2, int y)
64{ 64{
65 struct viewport *vp = lcd_current_viewport;
65 fb_data *dst, *dst_end; 66 fb_data *dst, *dst_end;
66 int stride_dst; 67 int stride_dst;
67 68
68 lcd_fastpixelfunc_type *pfunc = lcd_fastpixelfuncs[lcd_current_viewport->drawmode]; 69 lcd_fastpixelfunc_type *pfunc = lcd_fastpixelfuncs[vp->drawmode];
69 70
70 if (!lcd_clip_viewport_hline(&x1, &x2, &y)) 71 if (!lcd_clip_viewport_hline(&x1, &x2, &y))
71 return; 72 return;
72 73
73 dst = FBADDR(x1, y); 74 dst = FBADDR(x1, y);
74 stride_dst = lcd_current_viewport->buffer->stride; 75 stride_dst = vp->buffer->stride;
75 dst_end = dst + (x2 - x1) * stride_dst; 76 dst_end = dst + (x2 - x1) * stride_dst;
76 77
77 do 78 do
@@ -85,6 +86,7 @@ void lcd_hline(int x1, int x2, int y)
85/* Draw a vertical line (optimised) */ 86/* Draw a vertical line (optimised) */
86void lcd_vline(int x, int y1, int y2) 87void lcd_vline(int x, int y1, int y2)
87{ 88{
89 struct viewport *vp = lcd_current_viewport;
88 int height; 90 int height;
89 unsigned bits = 0; 91 unsigned bits = 0;
90 enum fill_opt fillopt = OPT_NONE; 92 enum fill_opt fillopt = OPT_NONE;
@@ -96,14 +98,14 @@ void lcd_vline(int x, int y1, int y2)
96 height = y2 - y1 + 1; 98 height = y2 - y1 + 1;
97 99
98 /* drawmode and optimisation */ 100 /* drawmode and optimisation */
99 if (lcd_current_viewport->drawmode & DRMODE_INVERSEVID) 101 if (vp->drawmode & DRMODE_INVERSEVID)
100 { 102 {
101 if (lcd_current_viewport->drawmode & DRMODE_BG) 103 if (vp->drawmode & DRMODE_BG)
102 { 104 {
103 if (!lcd_backdrop) 105 if (!lcd_backdrop)
104 { 106 {
105 fillopt = OPT_SET; 107 fillopt = OPT_SET;
106 bits = lcd_current_viewport->bg_pattern; 108 bits = vp->bg_pattern;
107 } 109 }
108 else 110 else
109 fillopt = OPT_COPY; 111 fillopt = OPT_COPY;
@@ -111,13 +113,13 @@ void lcd_vline(int x, int y1, int y2)
111 } 113 }
112 else 114 else
113 { 115 {
114 if (lcd_current_viewport->drawmode & DRMODE_FG) 116 if (vp->drawmode & DRMODE_FG)
115 { 117 {
116 fillopt = OPT_SET; 118 fillopt = OPT_SET;
117 bits = lcd_current_viewport->fg_pattern; 119 bits = vp->fg_pattern;
118 } 120 }
119 } 121 }
120 if (fillopt == OPT_NONE && lcd_current_viewport->drawmode != DRMODE_COMPLEMENT) 122 if (fillopt == OPT_NONE && vp->drawmode != DRMODE_COMPLEMENT)
121 return; 123 return;
122 124
123 dst = FBADDR(x, y1); 125 dst = FBADDR(x, y1);
@@ -147,6 +149,7 @@ void ICODE_ATTR lcd_bitmap_part(const fb_data *src, int src_x, int src_y,
147 int stride, int x, int y, int width, 149 int stride, int x, int y, int width,
148 int height) 150 int height)
149{ 151{
152 struct viewport *vp = lcd_current_viewport;
150 fb_data *dst; 153 fb_data *dst;
151 int stride_dst; 154 int stride_dst;
152 155
@@ -155,7 +158,7 @@ void ICODE_ATTR lcd_bitmap_part(const fb_data *src, int src_x, int src_y,
155 158
156 src += stride * src_x + src_y; /* move starting point */ 159 src += stride * src_x + src_y; /* move starting point */
157 dst = FBADDR(x, y); 160 dst = FBADDR(x, y);
158 stride_dst = lcd_current_viewport->buffer->stride; 161 stride_dst = vp->buffer->stride;
159 fb_data *dst_end = dst + width * stride_dst; 162 fb_data *dst_end = dst + width * stride_dst;
160 163
161 do 164 do
@@ -172,6 +175,7 @@ void ICODE_ATTR lcd_bitmap_transparent_part(const fb_data *src, int src_x,
172 int src_y, int stride, int x, 175 int src_y, int stride, int x,
173 int y, int width, int height) 176 int y, int width, int height)
174{ 177{
178 struct viewport *vp = lcd_current_viewport;
175 fb_data *dst, *dst_end; 179 fb_data *dst, *dst_end;
176 int stride_dst; 180 int stride_dst;
177 181
@@ -180,7 +184,7 @@ void ICODE_ATTR lcd_bitmap_transparent_part(const fb_data *src, int src_x,
180 184
181 src += stride * src_x + src_y; /* move starting point */ 185 src += stride * src_x + src_y; /* move starting point */
182 dst = FBADDR(x, y); 186 dst = FBADDR(x, y);
183 stride_dst = lcd_current_viewport->buffer->stride; 187 stride_dst = vp->buffer->stride;
184 dst_end = dst + width * stride_dst; 188 dst_end = dst + width * stride_dst;
185 189
186 do 190 do
@@ -189,7 +193,7 @@ void ICODE_ATTR lcd_bitmap_transparent_part(const fb_data *src, int src_x,
189 for(i = 0;i < height;i++) 193 for(i = 0;i < height;i++)
190 { 194 {
191 if (src[i] == REPLACEWITHFG_COLOR) 195 if (src[i] == REPLACEWITHFG_COLOR)
192 dst[i] = lcd_current_viewport->fg_pattern; 196 dst[i] = vp->fg_pattern;
193 else if(src[i] != TRANSPARENT_COLOR) 197 else if(src[i] != TRANSPARENT_COLOR)
194 dst[i] = src[i]; 198 dst[i] = src[i];
195 } 199 }
diff --git a/firmware/drivers/lcd-16bit.c b/firmware/drivers/lcd-16bit.c
index fd032c0956..f802a1bfbb 100644
--- a/firmware/drivers/lcd-16bit.c
+++ b/firmware/drivers/lcd-16bit.c
@@ -62,6 +62,7 @@ static void ICODE_ATTR lcd_alpha_bitmap_part_mix(const fb_data* image,
62/* Draw a horizontal line (optimised) */ 62/* Draw a horizontal line (optimised) */
63void lcd_hline(int x1, int x2, int y) 63void lcd_hline(int x1, int x2, int y)
64{ 64{
65 struct viewport *vp = lcd_current_viewport;
65 int width; 66 int width;
66 unsigned bits = 0; 67 unsigned bits = 0;
67 enum fill_opt fillopt = OPT_NONE; 68 enum fill_opt fillopt = OPT_NONE;
@@ -73,14 +74,14 @@ void lcd_hline(int x1, int x2, int y)
73 width = x2 - x1 + 1; 74 width = x2 - x1 + 1;
74 75
75 /* drawmode and optimisation */ 76 /* drawmode and optimisation */
76 if (lcd_current_viewport->drawmode & DRMODE_INVERSEVID) 77 if (vp->drawmode & DRMODE_INVERSEVID)
77 { 78 {
78 if (lcd_current_viewport->drawmode & DRMODE_BG) 79 if (vp->drawmode & DRMODE_BG)
79 { 80 {
80 if (!lcd_backdrop) 81 if (!lcd_backdrop)
81 { 82 {
82 fillopt = OPT_SET; 83 fillopt = OPT_SET;
83 bits = lcd_current_viewport->bg_pattern; 84 bits = vp->bg_pattern;
84 } 85 }
85 else 86 else
86 fillopt = OPT_COPY; 87 fillopt = OPT_COPY;
@@ -88,13 +89,13 @@ void lcd_hline(int x1, int x2, int y)
88 } 89 }
89 else 90 else
90 { 91 {
91 if (lcd_current_viewport->drawmode & DRMODE_FG) 92 if (vp->drawmode & DRMODE_FG)
92 { 93 {
93 fillopt = OPT_SET; 94 fillopt = OPT_SET;
94 bits = lcd_current_viewport->fg_pattern; 95 bits = vp->fg_pattern;
95 } 96 }
96 } 97 }
97 if (fillopt == OPT_NONE && lcd_current_viewport->drawmode != DRMODE_COMPLEMENT) 98 if (fillopt == OPT_NONE && vp->drawmode != DRMODE_COMPLEMENT)
98 return; 99 return;
99 100
100 dst = FBADDR(x1, y); 101 dst = FBADDR(x1, y);
@@ -122,15 +123,16 @@ void lcd_hline(int x1, int x2, int y)
122/* Draw a vertical line (optimised) */ 123/* Draw a vertical line (optimised) */
123void lcd_vline(int x, int y1, int y2) 124void lcd_vline(int x, int y1, int y2)
124{ 125{
126 struct viewport *vp = lcd_current_viewport;
125 fb_data *dst, *dst_end; 127 fb_data *dst, *dst_end;
126 int stride_dst; 128 int stride_dst;
127 lcd_fastpixelfunc_type *pfunc = lcd_fastpixelfuncs[lcd_current_viewport->drawmode]; 129 lcd_fastpixelfunc_type *pfunc = lcd_fastpixelfuncs[vp->drawmode];
128 130
129 if (!lcd_clip_viewport_vline(&x, &y1, &y2)) 131 if (!lcd_clip_viewport_vline(&x, &y1, &y2))
130 return; 132 return;
131 133
132 dst = FBADDR(x, y1); 134 dst = FBADDR(x, y1);
133 stride_dst = lcd_current_viewport->buffer->stride; 135 stride_dst = vp->buffer->stride;
134 dst_end = dst + (y2 - y1) * stride_dst; 136 dst_end = dst + (y2 - y1) * stride_dst;
135 137
136 do 138 do
@@ -146,6 +148,7 @@ void ICODE_ATTR lcd_bitmap_part(const fb_data *src, int src_x, int src_y,
146 int stride, int x, int y, int width, 148 int stride, int x, int y, int width,
147 int height) 149 int height)
148{ 150{
151 struct viewport *vp = lcd_current_viewport;
149 fb_data *dst; 152 fb_data *dst;
150 int stride_dst; 153 int stride_dst;
151 154
@@ -154,7 +157,7 @@ void ICODE_ATTR lcd_bitmap_part(const fb_data *src, int src_x, int src_y,
154 157
155 src += stride * src_y + src_x; /* move starting point */ 158 src += stride * src_y + src_x; /* move starting point */
156 dst = FBADDR(x, y); 159 dst = FBADDR(x, y);
157 stride_dst = lcd_current_viewport->buffer->stride; 160 stride_dst = vp->buffer->stride;
158 161
159 do 162 do
160 { 163 {
@@ -170,9 +173,10 @@ void ICODE_ATTR lcd_bitmap_transparent_part(const fb_data *src, int src_x,
170 int src_y, int stride, int x, 173 int src_y, int stride, int x,
171 int y, int width, int height) 174 int y, int width, int height)
172{ 175{
176 struct viewport *vp = lcd_current_viewport;
173 fb_data *dst; 177 fb_data *dst;
174 unsigned fg = lcd_current_viewport->fg_pattern; 178 unsigned fg = vp->fg_pattern;
175 int stride_dst = lcd_current_viewport->buffer->stride; 179 int stride_dst = vp->buffer->stride;
176 180
177 if (!lcd_clip_viewport_rect(&x, &y, &width, &height, &src_x, &src_y)) 181 if (!lcd_clip_viewport_rect(&x, &y, &width, &height, &src_x, &src_y))
178 return; 182 return;
diff --git a/firmware/drivers/lcd-1bit-vert.c b/firmware/drivers/lcd-1bit-vert.c
index 9c69b82e51..548dd96994 100644
--- a/firmware/drivers/lcd-1bit-vert.c
+++ b/firmware/drivers/lcd-1bit-vert.c
@@ -237,6 +237,7 @@ void LCDFN(clear_viewport)(void)
237/* Draw a horizontal line (optimised) */ 237/* Draw a horizontal line (optimised) */
238void LCDFN(hline)(int x1, int x2, int y) 238void LCDFN(hline)(int x1, int x2, int y)
239{ 239{
240 struct viewport *vp = CURRENT_VP;
240 int width; 241 int width;
241 unsigned char *dst, *dst_end; 242 unsigned char *dst, *dst_end;
242 unsigned mask; 243 unsigned mask;
@@ -247,7 +248,7 @@ void LCDFN(hline)(int x1, int x2, int y)
247 248
248 width = x2 - x1 + 1; 249 width = x2 - x1 + 1;
249 250
250 bfunc = LCDFN(blockfuncs)[CURRENT_VP->drawmode]; 251 bfunc = LCDFN(blockfuncs)[vp->drawmode];
251 dst = LCDFB(x1,y>>3); 252 dst = LCDFB(x1,y>>3);
252 mask = BIT_N(y & 7); 253 mask = BIT_N(y & 7);
253 254
@@ -260,6 +261,7 @@ void LCDFN(hline)(int x1, int x2, int y)
260/* Draw a vertical line (optimised) */ 261/* Draw a vertical line (optimised) */
261void LCDFN(vline)(int x, int y1, int y2) 262void LCDFN(vline)(int x, int y1, int y2)
262{ 263{
264 struct viewport *vp = CURRENT_VP;
263 int ny; 265 int ny;
264 FBFN(data) *dst; 266 FBFN(data) *dst;
265 int stride_dst; 267 int stride_dst;
@@ -269,12 +271,12 @@ void LCDFN(vline)(int x, int y1, int y2)
269 if (!LCDFN(clip_viewport_vline)(&x, &y1, &y2)) 271 if (!LCDFN(clip_viewport_vline)(&x, &y1, &y2))
270 return; 272 return;
271 273
272 bfunc = LCDFN(blockfuncs)[CURRENT_VP->drawmode]; 274 bfunc = LCDFN(blockfuncs)[vp->drawmode];
273 dst = LCDFB(x,y1>>3); 275 dst = LCDFB(x,y1>>3);
274 ny = y2 - (y1 & ~7); 276 ny = y2 - (y1 & ~7);
275 mask = 0xFFu << (y1 & 7); 277 mask = 0xFFu << (y1 & 7);
276 mask_bottom = 0xFFu >> (~ny & 7); 278 mask_bottom = 0xFFu >> (~ny & 7);
277 stride_dst = CURRENT_VP->buffer->stride; 279 stride_dst = vp->buffer->stride;
278 280
279 for (; ny >= 8; ny -= 8) 281 for (; ny >= 8; ny -= 8)
280 { 282 {
@@ -289,6 +291,7 @@ void LCDFN(vline)(int x, int y1, int y2)
289/* Fill a rectangular area */ 291/* Fill a rectangular area */
290void LCDFN(fillrect)(int x, int y, int width, int height) 292void LCDFN(fillrect)(int x, int y, int width, int height)
291{ 293{
294 struct viewport *vp = CURRENT_VP;
292 int ny; 295 int ny;
293 FBFN(data) *dst, *dst_end; 296 FBFN(data) *dst, *dst_end;
294 int stride_dst; 297 int stride_dst;
@@ -300,27 +303,27 @@ void LCDFN(fillrect)(int x, int y, int width, int height)
300 if (!LCDFN(clip_viewport_rect)(&x, &y, &width, &height, NULL, NULL)) 303 if (!LCDFN(clip_viewport_rect)(&x, &y, &width, &height, NULL, NULL))
301 return; 304 return;
302 305
303 if (CURRENT_VP->drawmode & DRMODE_INVERSEVID) 306 if (vp->drawmode & DRMODE_INVERSEVID)
304 { 307 {
305 if (CURRENT_VP->drawmode & DRMODE_BG) 308 if (vp->drawmode & DRMODE_BG)
306 { 309 {
307 fillopt = true; 310 fillopt = true;
308 } 311 }
309 } 312 }
310 else 313 else
311 { 314 {
312 if (CURRENT_VP->drawmode & DRMODE_FG) 315 if (vp->drawmode & DRMODE_FG)
313 { 316 {
314 fillopt = true; 317 fillopt = true;
315 bits = 0xFFu; 318 bits = 0xFFu;
316 } 319 }
317 } 320 }
318 bfunc = LCDFN(blockfuncs)[CURRENT_VP->drawmode]; 321 bfunc = LCDFN(blockfuncs)[vp->drawmode];
319 dst = LCDFB(x,y>>3); 322 dst = LCDFB(x,y>>3);
320 ny = height - 1 + (y & 7); 323 ny = height - 1 + (y & 7);
321 mask = 0xFFu << (y & 7); 324 mask = 0xFFu << (y & 7);
322 mask_bottom = 0xFFu >> (~ny & 7); 325 mask_bottom = 0xFFu >> (~ny & 7);
323 stride_dst = CURRENT_VP->buffer->stride; 326 stride_dst = vp->buffer->stride;
324 327
325 for (; ny >= 8; ny -= 8) 328 for (; ny >= 8; ny -= 8)
326 { 329 {
@@ -368,6 +371,7 @@ void ICODE_ATTR LCDFN(bitmap_part)(const unsigned char *src, int src_x,
368 int src_y, int stride, int x, int y, 371 int src_y, int stride, int x, int y,
369 int width, int height) 372 int width, int height)
370{ 373{
374 struct viewport *vp = CURRENT_VP;
371 int shift, ny; 375 int shift, ny;
372 FBFN(data) *dst, *dst_end; 376 FBFN(data) *dst, *dst_end;
373 int stride_dst; 377 int stride_dst;
@@ -381,17 +385,17 @@ void ICODE_ATTR LCDFN(bitmap_part)(const unsigned char *src, int src_x,
381 src_y &= 7; 385 src_y &= 7;
382 y -= src_y; 386 y -= src_y;
383 dst = LCDFB(x,y>>3); 387 dst = LCDFB(x,y>>3);
384 stride_dst = CURRENT_VP->buffer->stride; 388 stride_dst = vp->buffer->stride;
385 shift = y & 7; 389 shift = y & 7;
386 ny = height - 1 + shift + src_y; 390 ny = height - 1 + shift + src_y;
387 391
388 bfunc = LCDFN(blockfuncs)[CURRENT_VP->drawmode]; 392 bfunc = LCDFN(blockfuncs)[vp->drawmode];
389 mask = 0xFFu << (shift + src_y); 393 mask = 0xFFu << (shift + src_y);
390 mask_bottom = 0xFFu >> (~ny & 7); 394 mask_bottom = 0xFFu >> (~ny & 7);
391 395
392 if (shift == 0) 396 if (shift == 0)
393 { 397 {
394 bool copyopt = (CURRENT_VP->drawmode == DRMODE_SOLID); 398 bool copyopt = (vp->drawmode == DRMODE_SOLID);
395 399
396 for (; ny >= 8; ny -= 8) 400 for (; ny >= 8; ny -= 8)
397 { 401 {
diff --git a/firmware/drivers/lcd-24bit.c b/firmware/drivers/lcd-24bit.c
index d95415e957..be0d3e239c 100644
--- a/firmware/drivers/lcd-24bit.c
+++ b/firmware/drivers/lcd-24bit.c
@@ -61,14 +61,15 @@ static void ICODE_ATTR lcd_alpha_bitmap_part_mix(const fb_data* image,
61/* Clear the current viewport */ 61/* Clear the current viewport */
62void lcd_clear_viewport(void) 62void lcd_clear_viewport(void)
63{ 63{
64 struct viewport *vp = lcd_current_viewport;
64 fb_data *dst, *dst_end; 65 fb_data *dst, *dst_end;
65 int x, y, width, height; 66 int x, y, width, height;
66 int len, step; 67 int len, step;
67 68
68 x = lcd_current_viewport->x; 69 x = vp->x;
69 y = lcd_current_viewport->y; 70 y = vp->y;
70 width = lcd_current_viewport->width; 71 width = vp->width;
71 height = lcd_current_viewport->height; 72 height = vp->height;
72 73
73 len = STRIDE_MAIN(width, height); 74 len = STRIDE_MAIN(width, height);
74 step = STRIDE_MAIN(ROW_INC, COL_INC); 75 step = STRIDE_MAIN(ROW_INC, COL_INC);
@@ -76,9 +77,9 @@ void lcd_clear_viewport(void)
76 dst = FBADDR(x, y); 77 dst = FBADDR(x, y);
77 dst_end = FBADDR(x + width - 1 , y + height - 1); 78 dst_end = FBADDR(x + width - 1 , y + height - 1);
78 79
79 if (lcd_current_viewport->drawmode & DRMODE_INVERSEVID) 80 if (vp->drawmode & DRMODE_INVERSEVID)
80 { 81 {
81 fb_data px = FB_SCALARPACK(lcd_current_viewport->fg_pattern); 82 fb_data px = FB_SCALARPACK(vp->fg_pattern);
82 do 83 do
83 { 84 {
84 fb_data *end = dst + len; 85 fb_data *end = dst + len;
@@ -93,7 +94,7 @@ void lcd_clear_viewport(void)
93 { 94 {
94 if (!lcd_backdrop) 95 if (!lcd_backdrop)
95 { 96 {
96 fb_data px = FB_SCALARPACK(lcd_current_viewport->bg_pattern); 97 fb_data px = FB_SCALARPACK(vp->bg_pattern);
97 do 98 do
98 { 99 {
99 fb_data *end = dst + len; 100 fb_data *end = dst + len;
@@ -116,12 +117,12 @@ void lcd_clear_viewport(void)
116 } 117 }
117 } 118 }
118 119
119 if (lcd_current_viewport == &default_vp) 120 if (vp == &default_vp)
120 lcd_scroll_stop(); 121 lcd_scroll_stop();
121 else 122 else
122 lcd_scroll_stop_viewport(lcd_current_viewport); 123 lcd_scroll_stop_viewport(vp);
123 124
124 lcd_current_viewport->flags &= ~(VP_FLAG_VP_SET_CLEAN); 125 vp->flags &= ~(VP_FLAG_VP_SET_CLEAN);
125} 126}
126 127
127/*** low-level drawing functions ***/ 128/*** low-level drawing functions ***/
@@ -167,6 +168,7 @@ lcd_fastpixelfunc_type* const * lcd_fastpixelfuncs = lcd_fastpixelfuncs_bgcolor;
167/* Fill a rectangular area */ 168/* Fill a rectangular area */
168void lcd_fillrect(int x, int y, int width, int height) 169void lcd_fillrect(int x, int y, int width, int height)
169{ 170{
171 struct viewport *vp = lcd_current_viewport;
170 enum fill_opt fillopt = OPT_NONE; 172 enum fill_opt fillopt = OPT_NONE;
171 fb_data *dst, *dst_end; 173 fb_data *dst, *dst_end;
172 int len, step; 174 int len, step;
@@ -177,14 +179,14 @@ void lcd_fillrect(int x, int y, int width, int height)
177 return; 179 return;
178 180
179 /* drawmode and optimisation */ 181 /* drawmode and optimisation */
180 if (lcd_current_viewport->drawmode & DRMODE_INVERSEVID) 182 if (vp->drawmode & DRMODE_INVERSEVID)
181 { 183 {
182 if (lcd_current_viewport->drawmode & DRMODE_BG) 184 if (vp->drawmode & DRMODE_BG)
183 { 185 {
184 if (!lcd_backdrop) 186 if (!lcd_backdrop)
185 { 187 {
186 fillopt = OPT_SET; 188 fillopt = OPT_SET;
187 bits = FB_SCALARPACK(lcd_current_viewport->bg_pattern); 189 bits = FB_SCALARPACK(vp->bg_pattern);
188 } 190 }
189 else 191 else
190 fillopt = OPT_COPY; 192 fillopt = OPT_COPY;
@@ -192,13 +194,13 @@ void lcd_fillrect(int x, int y, int width, int height)
192 } 194 }
193 else 195 else
194 { 196 {
195 if (lcd_current_viewport->drawmode & DRMODE_FG) 197 if (vp->drawmode & DRMODE_FG)
196 { 198 {
197 fillopt = OPT_SET; 199 fillopt = OPT_SET;
198 bits = FB_SCALARPACK(lcd_current_viewport->fg_pattern); 200 bits = FB_SCALARPACK(vp->fg_pattern);
199 } 201 }
200 } 202 }
201 if (fillopt == OPT_NONE && lcd_current_viewport->drawmode != DRMODE_COMPLEMENT) 203 if (fillopt == OPT_NONE && vp->drawmode != DRMODE_COMPLEMENT)
202 return; 204 return;
203 205
204 dst = FBADDR(x, y); 206 dst = FBADDR(x, y);
@@ -259,10 +261,11 @@ void ICODE_ATTR lcd_mono_bitmap_part(const unsigned char *src, int src_x,
259 int src_y, int stride, int x, int y, 261 int src_y, int stride, int x, int y,
260 int width, int height) 262 int width, int height)
261{ 263{
264 struct viewport *vp = lcd_current_viewport;
262 const unsigned char *src_end; 265 const unsigned char *src_end;
263 fb_data *dst, *dst_col; 266 fb_data *dst, *dst_col;
264 unsigned dmask = 0x100; /* bit 8 == sentinel */ 267 unsigned dmask = 0x100; /* bit 8 == sentinel */
265 int drmode = lcd_current_viewport->drawmode; 268 int drmode = vp->drawmode;
266 int row; 269 int row;
267 270
268 if (!lcd_clip_viewport_rect(&x, &y, &width, &height, &src_x, &src_y)) 271 if (!lcd_clip_viewport_rect(&x, &y, &width, &height, &src_x, &src_y))
@@ -332,7 +335,7 @@ void ICODE_ATTR lcd_mono_bitmap_part(const unsigned char *src, int src_x,
332 break; 335 break;
333 336
334 case DRMODE_BG: 337 case DRMODE_BG:
335 bg = FB_SCALARPACK(lcd_current_viewport->bg_pattern); 338 bg = FB_SCALARPACK(vp->bg_pattern);
336 do 339 do
337 { 340 {
338 if (!(data & 0x01)) 341 if (!(data & 0x01))
@@ -345,7 +348,7 @@ void ICODE_ATTR lcd_mono_bitmap_part(const unsigned char *src, int src_x,
345 break; 348 break;
346 349
347 case DRMODE_FG: 350 case DRMODE_FG:
348 fg = FB_SCALARPACK(lcd_current_viewport->fg_pattern); 351 fg = FB_SCALARPACK(vp->fg_pattern);
349 do 352 do
350 { 353 {
351 if (data & 0x01) 354 if (data & 0x01)
@@ -358,7 +361,7 @@ void ICODE_ATTR lcd_mono_bitmap_part(const unsigned char *src, int src_x,
358 break; 361 break;
359 362
360 case DRMODE_SOLID|DRMODE_INT_BD: 363 case DRMODE_SOLID|DRMODE_INT_BD:
361 fg = FB_SCALARPACK(lcd_current_viewport->fg_pattern); 364 fg = FB_SCALARPACK(vp->fg_pattern);
362 bo = lcd_backdrop_offset; 365 bo = lcd_backdrop_offset;
363 do 366 do
364 { 367 {
@@ -371,8 +374,8 @@ void ICODE_ATTR lcd_mono_bitmap_part(const unsigned char *src, int src_x,
371 break; 374 break;
372 375
373 case DRMODE_SOLID: 376 case DRMODE_SOLID:
374 fg = FB_SCALARPACK(lcd_current_viewport->fg_pattern); 377 fg = FB_SCALARPACK(vp->fg_pattern);
375 bg = FB_SCALARPACK(lcd_current_viewport->bg_pattern); 378 bg = FB_SCALARPACK(vp->bg_pattern);
376 do 379 do
377 { 380 {
378 *dst = (data & 0x01) ? fg : bg; 381 *dst = (data & 0x01) ? fg : bg;
@@ -442,9 +445,10 @@ static void ICODE_ATTR lcd_alpha_bitmap_part_mix(const fb_data* image,
442 int width, int height, 445 int width, int height,
443 int stride_image, int stride_src) 446 int stride_image, int stride_src)
444{ 447{
448 struct viewport *vp = lcd_current_viewport;
445 fb_data *dst, *dst_row; 449 fb_data *dst, *dst_row;
446 unsigned dmask = 0x00000000; 450 unsigned dmask = 0x00000000;
447 int drmode = lcd_current_viewport->drawmode; 451 int drmode = vp->drawmode;
448 452
449 if (!lcd_clip_viewport_rect(&x, &y, &width, &height, &src_x, &src_y)) 453 if (!lcd_clip_viewport_rect(&x, &y, &width, &height, &src_x, &src_y))
450 return; 454 return;
@@ -570,7 +574,7 @@ static void ICODE_ATTR lcd_alpha_bitmap_part_mix(const fb_data* image,
570 while (--col); 574 while (--col);
571 break; 575 break;
572 case DRMODE_BG: 576 case DRMODE_BG:
573 bg = lcd_current_viewport->bg_pattern; 577 bg = vp->bg_pattern;
574 do 578 do
575 { 579 {
576 unsigned px = FB_UNPACK_SCALAR_LCD(*dst); 580 unsigned px = FB_UNPACK_SCALAR_LCD(*dst);
@@ -593,7 +597,7 @@ static void ICODE_ATTR lcd_alpha_bitmap_part_mix(const fb_data* image,
593 while (--col); 597 while (--col);
594 break; 598 break;
595 case DRMODE_FG: 599 case DRMODE_FG:
596 fg = lcd_current_viewport->fg_pattern; 600 fg = vp->fg_pattern;
597 do 601 do
598 { 602 {
599 unsigned px = FB_UNPACK_SCALAR_LCD(*dst); 603 unsigned px = FB_UNPACK_SCALAR_LCD(*dst);
@@ -605,7 +609,7 @@ static void ICODE_ATTR lcd_alpha_bitmap_part_mix(const fb_data* image,
605 break; 609 break;
606 case DRMODE_SOLID|DRMODE_INT_BD: 610 case DRMODE_SOLID|DRMODE_INT_BD:
607 bo = lcd_backdrop_offset; 611 bo = lcd_backdrop_offset;
608 fg = lcd_current_viewport->fg_pattern; 612 fg = vp->fg_pattern;
609 do 613 do
610 { 614 {
611 unsigned c = FB_UNPACK_SCALAR_LCD(*(fb_data *)((uintptr_t)dst + bo)); 615 unsigned c = FB_UNPACK_SCALAR_LCD(*(fb_data *)((uintptr_t)dst + bo));
@@ -616,7 +620,7 @@ static void ICODE_ATTR lcd_alpha_bitmap_part_mix(const fb_data* image,
616 while (--col); 620 while (--col);
617 break; 621 break;
618 case DRMODE_SOLID|DRMODE_INT_IMG: 622 case DRMODE_SOLID|DRMODE_INT_IMG:
619 bg = lcd_current_viewport->bg_pattern; 623 bg = vp->bg_pattern;
620 img_offset = image - dst; 624 img_offset = image - dst;
621 do 625 do
622 { 626 {
@@ -641,8 +645,8 @@ static void ICODE_ATTR lcd_alpha_bitmap_part_mix(const fb_data* image,
641 while (--col); 645 while (--col);
642 break; 646 break;
643 case DRMODE_SOLID: 647 case DRMODE_SOLID:
644 bg = lcd_current_viewport->bg_pattern; 648 bg = vp->bg_pattern;
645 fg = lcd_current_viewport->fg_pattern; 649 fg = vp->fg_pattern;
646 do 650 do
647 { 651 {
648 *dst = blend_two_colors(bg, fg, data & ALPHA_COLOR_LOOKUP_SIZE ); 652 *dst = blend_two_colors(bg, fg, data & ALPHA_COLOR_LOOKUP_SIZE );
@@ -689,9 +693,10 @@ static void ICODE_ATTR lcd_alpha_bitmap_part_mix(const fb_data* image,
689/* Draw a horizontal line (optimised) */ 693/* Draw a horizontal line (optimised) */
690void lcd_hline(int x1, int x2, int y) 694void lcd_hline(int x1, int x2, int y)
691{ 695{
696 struct viewport *vp = lcd_current_viewport;
692 int width; 697 int width;
693 fb_data *dst, *dst_end; 698 fb_data *dst, *dst_end;
694 lcd_fastpixelfunc_type *pfunc = lcd_fastpixelfuncs[lcd_current_viewport->drawmode]; 699 lcd_fastpixelfunc_type *pfunc = lcd_fastpixelfuncs[vp->drawmode];
695 700
696 if (!lcd_clip_viewport_hline(&x1, &x2, &y)) 701 if (!lcd_clip_viewport_hline(&x1, &x2, &y))
697 return; 702 return;
@@ -710,8 +715,9 @@ void lcd_hline(int x1, int x2, int y)
710/* Draw a vertical line (optimised) */ 715/* Draw a vertical line (optimised) */
711void lcd_vline(int x, int y1, int y2) 716void lcd_vline(int x, int y1, int y2)
712{ 717{
718 struct viewport *vp = lcd_current_viewport;
713 fb_data *dst, *dst_end; 719 fb_data *dst, *dst_end;
714 lcd_fastpixelfunc_type *pfunc = lcd_fastpixelfuncs[lcd_current_viewport->drawmode]; 720 lcd_fastpixelfunc_type *pfunc = lcd_fastpixelfuncs[vp->drawmode];
715 721
716 if (!lcd_clip_viewport_vline(&x, &y1, &y2)) 722 if (!lcd_clip_viewport_vline(&x, &y1, &y2))
717 return; 723 return;
@@ -754,6 +760,7 @@ void ICODE_ATTR lcd_bitmap_transparent_part(const fb_data *src, int src_x,
754 int src_y, int stride, int x, 760 int src_y, int stride, int x,
755 int y, int width, int height) 761 int y, int width, int height)
756{ 762{
763 struct viewport *vp = lcd_current_viewport;
757 fb_data *dst; 764 fb_data *dst;
758 fb_data fg, transparent, replacewithfg; 765 fb_data fg, transparent, replacewithfg;
759 766
@@ -765,7 +772,7 @@ void ICODE_ATTR lcd_bitmap_transparent_part(const fb_data *src, int src_x,
765 772
766 transparent = FB_SCALARPACK(TRANSPARENT_COLOR); 773 transparent = FB_SCALARPACK(TRANSPARENT_COLOR);
767 replacewithfg = FB_SCALARPACK(REPLACEWITHFG_COLOR); 774 replacewithfg = FB_SCALARPACK(REPLACEWITHFG_COLOR);
768 fg = FB_SCALARPACK(lcd_current_viewport->fg_pattern); 775 fg = FB_SCALARPACK(vp->fg_pattern);
769#define CMP(c1, c2) (c1.r == c2.r && c1.g == c2.g && c1.b == c2.b) 776#define CMP(c1, c2) (c1.r == c2.r && c1.g == c2.g && c1.b == c2.b)
770 777
771 do 778 do
diff --git a/firmware/drivers/lcd-2bit-horz.c b/firmware/drivers/lcd-2bit-horz.c
index cf7e20d4a8..e5d683be9e 100644
--- a/firmware/drivers/lcd-2bit-horz.c
+++ b/firmware/drivers/lcd-2bit-horz.c
@@ -378,6 +378,7 @@ void lcd_clear_viewport(void)
378/* Draw a horizontal line (optimised) */ 378/* Draw a horizontal line (optimised) */
379void lcd_hline(int x1, int x2, int y) 379void lcd_hline(int x1, int x2, int y)
380{ 380{
381 struct viewport *vp = lcd_current_viewport;
381 int nx; 382 int nx;
382 unsigned char *dst; 383 unsigned char *dst;
383 unsigned mask, mask_right; 384 unsigned mask, mask_right;
@@ -386,7 +387,7 @@ void lcd_hline(int x1, int x2, int y)
386 if (!lcd_clip_viewport_hline(&x1, &x2, &y)) 387 if (!lcd_clip_viewport_hline(&x1, &x2, &y))
387 return; 388 return;
388 389
389 bfunc = lcd_blockfuncs[lcd_current_viewport->drawmode]; 390 bfunc = lcd_blockfuncs[vp->drawmode];
390 dst = FBADDR(x1>>2,y); 391 dst = FBADDR(x1>>2,y);
391 nx = x2 - (x1 & ~3); 392 nx = x2 - (x1 & ~3);
392 mask = 0xFFu >> (2 * (x1 & 3)); 393 mask = 0xFFu >> (2 * (x1 & 3));
@@ -404,6 +405,7 @@ void lcd_hline(int x1, int x2, int y)
404/* Draw a vertical line (optimised) */ 405/* Draw a vertical line (optimised) */
405void lcd_vline(int x, int y1, int y2) 406void lcd_vline(int x, int y1, int y2)
406{ 407{
408 struct viewport *vp = lcd_current_viewport;
407 unsigned char *dst, *dst_end; 409 unsigned char *dst, *dst_end;
408 int stride_dst; 410 int stride_dst;
409 unsigned mask; 411 unsigned mask;
@@ -412,9 +414,9 @@ void lcd_vline(int x, int y1, int y2)
412 if (!lcd_clip_viewport_vline(&x, &y1, &y2)) 414 if (!lcd_clip_viewport_vline(&x, &y1, &y2))
413 return; 415 return;
414 416
415 bfunc = lcd_blockfuncs[lcd_current_viewport->drawmode]; 417 bfunc = lcd_blockfuncs[vp->drawmode];
416 dst = FBADDR(x>>2,y1); 418 dst = FBADDR(x>>2,y1);
417 stride_dst = LCD_FBSTRIDE(lcd_current_viewport->buffer->stride, 0); 419 stride_dst = LCD_FBSTRIDE(vp->buffer->stride, 0);
418 mask = pixmask[x & 3]; 420 mask = pixmask[x & 3];
419 421
420 dst_end = dst + (y2 - y1) * stride_dst; 422 dst_end = dst + (y2 - y1) * stride_dst;
@@ -429,6 +431,7 @@ void lcd_vline(int x, int y1, int y2)
429/* Fill a rectangular area */ 431/* Fill a rectangular area */
430void lcd_fillrect(int x, int y, int width, int height) 432void lcd_fillrect(int x, int y, int width, int height)
431{ 433{
434 struct viewport *vp = lcd_current_viewport;
432 int nx; 435 int nx;
433 unsigned char *dst, *dst_end; 436 unsigned char *dst, *dst_end;
434 int stride_dst; 437 int stride_dst;
@@ -438,9 +441,9 @@ void lcd_fillrect(int x, int y, int width, int height)
438 if (!lcd_clip_viewport_rect(&x, &y, &width, &height, NULL, NULL)) 441 if (!lcd_clip_viewport_rect(&x, &y, &width, &height, NULL, NULL))
439 return; 442 return;
440 443
441 bfunc = lcd_blockfuncs[lcd_current_viewport->drawmode]; 444 bfunc = lcd_blockfuncs[vp->drawmode];
442 dst = FBADDR(x>>2,y); 445 dst = FBADDR(x>>2,y);
443 stride_dst = LCD_FBSTRIDE(lcd_current_viewport->buffer->stride, 0); 446 stride_dst = LCD_FBSTRIDE(vp->buffer->stride, 0);
444 nx = width - 1 + (x & 3); 447 nx = width - 1 + (x & 3);
445 mask = 0xFFu >> (2 * (x & 3)); 448 mask = 0xFFu >> (2 * (x & 3));
446 mask_right = 0xFFu << (2 * (~nx & 3)); 449 mask_right = 0xFFu << (2 * (~nx & 3));
@@ -485,12 +488,13 @@ void ICODE_ATTR lcd_mono_bitmap_part(const unsigned char *src, int src_x,
485 int src_y, int stride, int x, int y, 488 int src_y, int stride, int x, int y,
486 int width, int height) 489 int width, int height)
487{ 490{
491 struct viewport *vp = lcd_current_viewport;
488 const unsigned char *src_end; 492 const unsigned char *src_end;
489 fb_data *dst, *dst_end; 493 fb_data *dst, *dst_end;
490 int stride_dst; 494 int stride_dst;
491 unsigned dmask = 0x100; /* bit 8 == sentinel */ 495 unsigned dmask = 0x100; /* bit 8 == sentinel */
492 unsigned dst_mask; 496 unsigned dst_mask;
493 int drmode = lcd_current_viewport->drawmode; 497 int drmode = vp->drawmode;
494 498
495 if (!lcd_clip_viewport_rect(&x, &y, &width, &height, &src_x, &src_y)) 499 if (!lcd_clip_viewport_rect(&x, &y, &width, &height, &src_x, &src_y))
496 return; 500 return;
@@ -500,7 +504,7 @@ void ICODE_ATTR lcd_mono_bitmap_part(const unsigned char *src, int src_x,
500 src_end = src + width; 504 src_end = src + width;
501 505
502 dst = FBADDR(x >> 2,y); 506 dst = FBADDR(x >> 2,y);
503 stride_dst = LCD_FBSTRIDE(lcd_current_viewport->buffer->stride, 0); 507 stride_dst = LCD_FBSTRIDE(vp->buffer->stride, 0);
504 dst_end = dst + height * stride_dst; 508 dst_end = dst + height * stride_dst;
505 dst_mask = pixmask[x & 3]; 509 dst_mask = pixmask[x & 3];
506 510
@@ -652,6 +656,7 @@ void ICODE_ATTR lcd_bitmap_part(const unsigned char *src, int src_x,
652 int src_y, int stride, int x, int y, 656 int src_y, int stride, int x, int y,
653 int width, int height) 657 int width, int height)
654{ 658{
659 struct viewport *vp = lcd_current_viewport;
655 int shift, nx; 660 int shift, nx;
656 unsigned char *dst, *dst_end; 661 unsigned char *dst, *dst_end;
657 int stride_dst; 662 int stride_dst;
@@ -666,7 +671,7 @@ void ICODE_ATTR lcd_bitmap_part(const unsigned char *src, int src_x,
666 src_x &= 3; 671 src_x &= 3;
667 x -= src_x; 672 x -= src_x;
668 dst = FBADDR(x>>2,y); 673 dst = FBADDR(x>>2,y);
669 stride_dst = LCD_FBSTRIDE(lcd_current_viewport->buffer->stride, 0); 674 stride_dst = LCD_FBSTRIDE(vp->buffer->stride, 0);
670 shift = x & 3; 675 shift = x & 3;
671 nx = width - 1 + shift + src_x; 676 nx = width - 1 + shift + src_x;
672 677
diff --git a/firmware/drivers/lcd-2bit-vert.c b/firmware/drivers/lcd-2bit-vert.c
index c4bdba67cb..354c8802fc 100644
--- a/firmware/drivers/lcd-2bit-vert.c
+++ b/firmware/drivers/lcd-2bit-vert.c
@@ -380,6 +380,7 @@ void lcd_clear_viewport(void)
380/* Draw a horizontal line (optimised) */ 380/* Draw a horizontal line (optimised) */
381void lcd_hline(int x1, int x2, int y) 381void lcd_hline(int x1, int x2, int y)
382{ 382{
383 struct viewport *vp = lcd_current_viewport;
383 int width; 384 int width;
384 fb_data *dst, *dst_end; 385 fb_data *dst, *dst_end;
385 unsigned mask; 386 unsigned mask;
@@ -390,7 +391,7 @@ void lcd_hline(int x1, int x2, int y)
390 391
391 width = x2 - x1 + 1; 392 width = x2 - x1 + 1;
392 393
393 bfunc = lcd_blockfuncs[lcd_current_viewport->drawmode]; 394 bfunc = lcd_blockfuncs[vp->drawmode];
394 dst = FBADDR(x1,y>>2); 395 dst = FBADDR(x1,y>>2);
395 mask = pixmask[y & 3]; 396 mask = pixmask[y & 3];
396 397
@@ -403,6 +404,7 @@ void lcd_hline(int x1, int x2, int y)
403/* Draw a vertical line (optimised) */ 404/* Draw a vertical line (optimised) */
404void lcd_vline(int x, int y1, int y2) 405void lcd_vline(int x, int y1, int y2)
405{ 406{
407 struct viewport *vp = lcd_current_viewport;
406 int ny; 408 int ny;
407 fb_data *dst; 409 fb_data *dst;
408 int stride_dst; 410 int stride_dst;
@@ -412,9 +414,9 @@ void lcd_vline(int x, int y1, int y2)
412 if (!lcd_clip_viewport_vline(&x, &y1, &y2)) 414 if (!lcd_clip_viewport_vline(&x, &y1, &y2))
413 return; 415 return;
414 416
415 bfunc = lcd_blockfuncs[lcd_current_viewport->drawmode]; 417 bfunc = lcd_blockfuncs[vp->drawmode];
416 dst = FBADDR(x,y1>>2); 418 dst = FBADDR(x,y1>>2);
417 stride_dst = lcd_current_viewport->buffer->stride; 419 stride_dst = vp->buffer->stride;
418 ny = y2 - (y1 & ~3); 420 ny = y2 - (y1 & ~3);
419 mask = 0xFFu << (2 * (y1 & 3)); 421 mask = 0xFFu << (2 * (y1 & 3));
420 mask_bottom = 0xFFu >> (2 * (~ny & 3)); 422 mask_bottom = 0xFFu >> (2 * (~ny & 3));
@@ -432,6 +434,7 @@ void lcd_vline(int x, int y1, int y2)
432/* Fill a rectangular area */ 434/* Fill a rectangular area */
433void lcd_fillrect(int x, int y, int width, int height) 435void lcd_fillrect(int x, int y, int width, int height)
434{ 436{
437 struct viewport *vp = lcd_current_viewport;
435 int ny; 438 int ny;
436 fb_data *dst, *dst_end; 439 fb_data *dst, *dst_end;
437 int stride_dst; 440 int stride_dst;
@@ -443,9 +446,9 @@ void lcd_fillrect(int x, int y, int width, int height)
443 if (!lcd_clip_viewport_rect(&x, &y, &width, &height, NULL, NULL)) 446 if (!lcd_clip_viewport_rect(&x, &y, &width, &height, NULL, NULL))
444 return; 447 return;
445 448
446 if (lcd_current_viewport->drawmode & DRMODE_INVERSEVID) 449 if (vp->drawmode & DRMODE_INVERSEVID)
447 { 450 {
448 if ((lcd_current_viewport->drawmode & DRMODE_BG) && !lcd_backdrop) 451 if ((vp->drawmode & DRMODE_BG) && !lcd_backdrop)
449 { 452 {
450 fillopt = true; 453 fillopt = true;
451 bits = bg_pattern; 454 bits = bg_pattern;
@@ -453,15 +456,15 @@ void lcd_fillrect(int x, int y, int width, int height)
453 } 456 }
454 else 457 else
455 { 458 {
456 if (lcd_current_viewport->drawmode & DRMODE_FG) 459 if (vp->drawmode & DRMODE_FG)
457 { 460 {
458 fillopt = true; 461 fillopt = true;
459 bits = fg_pattern; 462 bits = fg_pattern;
460 } 463 }
461 } 464 }
462 bfunc = lcd_blockfuncs[lcd_current_viewport->drawmode]; 465 bfunc = lcd_blockfuncs[vp->drawmode];
463 dst = FBADDR(x,y>>2); 466 dst = FBADDR(x,y>>2);
464 stride_dst = lcd_current_viewport->buffer->stride; 467 stride_dst = vp->buffer->stride;
465 ny = height - 1 + (y & 3); 468 ny = height - 1 + (y & 3);
466 mask = 0xFFu << (2 * (y & 3)); 469 mask = 0xFFu << (2 * (y & 3));
467 mask_bottom = 0xFFu >> (2 * (~ny & 3)); 470 mask_bottom = 0xFFu >> (2 * (~ny & 3));
@@ -512,6 +515,7 @@ void ICODE_ATTR lcd_mono_bitmap_part(const unsigned char *src, int src_x,
512 int src_y, int stride, int x, int y, 515 int src_y, int stride, int x, int y,
513 int width, int height) 516 int width, int height)
514{ 517{
518 struct viewport *vp = lcd_current_viewport;
515 int shift, ny; 519 int shift, ny;
516 fb_data *dst, *dst_end; 520 fb_data *dst, *dst_end;
517 int stride_dst; 521 int stride_dst;
@@ -525,14 +529,14 @@ void ICODE_ATTR lcd_mono_bitmap_part(const unsigned char *src, int src_x,
525 src_y &= 7; 529 src_y &= 7;
526 y -= src_y; 530 y -= src_y;
527 dst = FBADDR(x,y>>2); 531 dst = FBADDR(x,y>>2);
528 stride_dst = lcd_current_viewport->buffer->stride; 532 stride_dst = vp->buffer->stride;
529 shift = y & 3; 533 shift = y & 3;
530 ny = height - 1 + shift + src_y; 534 ny = height - 1 + shift + src_y;
531 mask = 0xFFFFu << (2 * (shift + src_y)); 535 mask = 0xFFFFu << (2 * (shift + src_y));
532 /* Overflowing bits aren't important. */ 536 /* Overflowing bits aren't important. */
533 mask_bottom = 0xFFFFu >> (2 * (~ny & 7)); 537 mask_bottom = 0xFFFFu >> (2 * (~ny & 7));
534 538
535 bfunc = lcd_blockfuncs[lcd_current_viewport->drawmode]; 539 bfunc = lcd_blockfuncs[vp->drawmode];
536 540
537 if (shift == 0) 541 if (shift == 0)
538 { 542 {
@@ -662,6 +666,7 @@ void ICODE_ATTR lcd_bitmap_part(const fb_data *src, int src_x, int src_y,
662 int stride, int x, int y, int width, 666 int stride, int x, int y, int width,
663 int height) 667 int height)
664{ 668{
669 struct viewport *vp = lcd_current_viewport;
665 int shift, ny; 670 int shift, ny;
666 fb_data *dst, *dst_end; 671 fb_data *dst, *dst_end;
667 int stride_dst; 672 int stride_dst;
@@ -674,7 +679,7 @@ void ICODE_ATTR lcd_bitmap_part(const fb_data *src, int src_x, int src_y,
674 src_y &= 3; 679 src_y &= 3;
675 y -= src_y; 680 y -= src_y;
676 dst = FBADDR(x,y>>2); 681 dst = FBADDR(x,y>>2);
677 stride_dst = lcd_current_viewport->buffer->stride; 682 stride_dst = vp->buffer->stride;
678 shift = y & 3; 683 shift = y & 3;
679 ny = height - 1 + shift + src_y; 684 ny = height - 1 + shift + src_y;
680 685
diff --git a/firmware/drivers/lcd-2bit-vi.c b/firmware/drivers/lcd-2bit-vi.c
index 99bd32c77b..7de4a57577 100644
--- a/firmware/drivers/lcd-2bit-vi.c
+++ b/firmware/drivers/lcd-2bit-vi.c
@@ -413,6 +413,7 @@ void LCDFN(clear_viewport)(void)
413/* Draw a horizontal line (optimised) */ 413/* Draw a horizontal line (optimised) */
414void LCDFN(hline)(int x1, int x2, int y) 414void LCDFN(hline)(int x1, int x2, int y)
415{ 415{
416 struct viewport *vp = CURRENT_VP;
416 int width; 417 int width;
417 FBFN(data) *dst, *dst_end; 418 FBFN(data) *dst, *dst_end;
418 unsigned mask; 419 unsigned mask;
@@ -423,7 +424,7 @@ void LCDFN(hline)(int x1, int x2, int y)
423 424
424 width = x2 - x1 + 1; 425 width = x2 - x1 + 1;
425 426
426 bfunc = LCDFN(blockfuncs)[CURRENT_VP->drawmode]; 427 bfunc = LCDFN(blockfuncs)[vp->drawmode];
427 dst = LCDFB(x1,y>>3); 428 dst = LCDFB(x1,y>>3);
428 mask = 0x0101 << (y & 7); 429 mask = 0x0101 << (y & 7);
429 430
@@ -436,6 +437,7 @@ void LCDFN(hline)(int x1, int x2, int y)
436/* Draw a vertical line (optimised) */ 437/* Draw a vertical line (optimised) */
437void LCDFN(vline)(int x, int y1, int y2) 438void LCDFN(vline)(int x, int y1, int y2)
438{ 439{
440 struct viewport *vp = CURRENT_VP;
439 int ny; 441 int ny;
440 FBFN(data) *dst; 442 FBFN(data) *dst;
441 int stride_dst; 443 int stride_dst;
@@ -445,9 +447,9 @@ void LCDFN(vline)(int x, int y1, int y2)
445 if (!LCDFN(clip_viewport_vline)(&x, &y1, &y2)) 447 if (!LCDFN(clip_viewport_vline)(&x, &y1, &y2))
446 return; 448 return;
447 449
448 bfunc = LCDFN(blockfuncs)[CURRENT_VP->drawmode]; 450 bfunc = LCDFN(blockfuncs)[vp->drawmode];
449 dst = LCDFB(x,y1>>3); 451 dst = LCDFB(x,y1>>3);
450 stride_dst = CURRENT_VP->buffer->stride; 452 stride_dst = vp->buffer->stride;
451 ny = y2 - (y1 & ~7); 453 ny = y2 - (y1 & ~7);
452 mask = (0xFFu << (y1 & 7)) & 0xFFu; 454 mask = (0xFFu << (y1 & 7)) & 0xFFu;
453 mask |= mask << 8; 455 mask |= mask << 8;
@@ -467,6 +469,7 @@ void LCDFN(vline)(int x, int y1, int y2)
467/* Fill a rectangular area */ 469/* Fill a rectangular area */
468void LCDFN(fillrect)(int x, int y, int width, int height) 470void LCDFN(fillrect)(int x, int y, int width, int height)
469{ 471{
472 struct viewport *vp = CURRENT_VP;
470 int ny; 473 int ny;
471 FBFN(data) *dst, *dst_end; 474 FBFN(data) *dst, *dst_end;
472 int stride_dst; 475 int stride_dst;
@@ -478,9 +481,9 @@ void LCDFN(fillrect)(int x, int y, int width, int height)
478 if (!LCDFN(clip_viewport_rect)(&x, &y, &width, &height, NULL, NULL)) 481 if (!LCDFN(clip_viewport_rect)(&x, &y, &width, &height, NULL, NULL))
479 return; 482 return;
480 483
481 if (CURRENT_VP->drawmode & DRMODE_INVERSEVID) 484 if (vp->drawmode & DRMODE_INVERSEVID)
482 { 485 {
483 if ((CURRENT_VP->drawmode & DRMODE_BG) && !backdrop) 486 if ((vp->drawmode & DRMODE_BG) && !backdrop)
484 { 487 {
485 fillopt = true; 488 fillopt = true;
486 bits = bg_pattern; 489 bits = bg_pattern;
@@ -488,15 +491,15 @@ void LCDFN(fillrect)(int x, int y, int width, int height)
488 } 491 }
489 else 492 else
490 { 493 {
491 if (CURRENT_VP->drawmode & DRMODE_FG) 494 if (vp->drawmode & DRMODE_FG)
492 { 495 {
493 fillopt = true; 496 fillopt = true;
494 bits = fg_pattern; 497 bits = fg_pattern;
495 } 498 }
496 } 499 }
497 bfunc = LCDFN(blockfuncs)[CURRENT_VP->drawmode]; 500 bfunc = LCDFN(blockfuncs)[vp->drawmode];
498 dst = LCDFB(x,y>>3); 501 dst = LCDFB(x,y>>3);
499 stride_dst = CURRENT_VP->buffer->stride; 502 stride_dst = vp->buffer->stride;
500 ny = height - 1 + (y & 7); 503 ny = height - 1 + (y & 7);
501 mask = (0xFFu << (y & 7)) & 0xFFu; 504 mask = (0xFFu << (y & 7)) & 0xFFu;
502 mask |= mask << 8; 505 mask |= mask << 8;
@@ -549,6 +552,7 @@ void ICODE_ATTR LCDFN(mono_bitmap_part)(const unsigned char *src, int src_x,
549 int src_y, int stride, int x, int y, 552 int src_y, int stride, int x, int y,
550 int width, int height) 553 int width, int height)
551{ 554{
555 struct viewport *vp = CURRENT_VP;
552 int shift, ny; 556 int shift, ny;
553 FBFN(data) *dst, *dst_end; 557 FBFN(data) *dst, *dst_end;
554 int stride_dst; 558 int stride_dst;
@@ -562,11 +566,11 @@ void ICODE_ATTR LCDFN(mono_bitmap_part)(const unsigned char *src, int src_x,
562 src_y &= 7; 566 src_y &= 7;
563 y -= src_y; 567 y -= src_y;
564 dst = LCDFB(x,y>>3); 568 dst = LCDFB(x,y>>3);
565 stride_dst = CURRENT_VP->buffer->stride; 569 stride_dst = vp->buffer->stride;
566 shift = y & 7; 570 shift = y & 7;
567 ny = height - 1 + shift + src_y; 571 ny = height - 1 + shift + src_y;
568 572
569 bfunc = LCDFN(blockfuncs)[CURRENT_VP->drawmode]; 573 bfunc = LCDFN(blockfuncs)[vp->drawmode];
570 mask = 0xFFu << (shift + src_y); 574 mask = 0xFFu << (shift + src_y);
571 /* not byte-doubled here because shift+src_y can be > 7 */ 575 /* not byte-doubled here because shift+src_y can be > 7 */
572 mask_bottom = 0xFFu >> (~ny & 7); 576 mask_bottom = 0xFFu >> (~ny & 7);
@@ -670,6 +674,7 @@ void ICODE_ATTR LCDFN(bitmap_part)(const FBFN(data) *src, int src_x,
670 int src_y, int stride, int x, int y, 674 int src_y, int stride, int x, int y,
671 int width, int height) 675 int width, int height)
672{ 676{
677 struct viewport *vp = CURRENT_VP;
673 int shift, ny; 678 int shift, ny;
674 FBFN(data) *dst, *dst_end; 679 FBFN(data) *dst, *dst_end;
675 int stride_dst; 680 int stride_dst;
@@ -682,7 +687,7 @@ void ICODE_ATTR LCDFN(bitmap_part)(const FBFN(data) *src, int src_x,
682 src_y &= 7; 687 src_y &= 7;
683 y -= src_y; 688 y -= src_y;
684 dst = LCDFB(x,y>>3); 689 dst = LCDFB(x,y>>3);
685 stride_dst = CURRENT_VP->buffer->stride; 690 stride_dst = vp->buffer->stride;
686 shift = y & 7; 691 shift = y & 7;
687 ny = height - 1 + shift + src_y; 692 ny = height - 1 + shift + src_y;
688 693