Skip to content

Commit 299778d

Browse files
zbalatonkraxel
authored andcommitted
sm501: Introduce variable for commonly used value for better readability
The bytes per pixel value can be calculated from format but it's used freqently enough (and will be used more in subseqent patches) so store it in a variable for better readabilty. Also drop some unneded 0x prefix around where new variable is defined. Signed-off-by: BALATON Zoltan <[email protected]> Reviewed-by: Peter Maydell <[email protected]> Message-id: b9ea5ef2d68583db9f3fb73a2b859abbd7c044a8.1592686588.git.balaton@eik.bme.hu Signed-off-by: Gerd Hoffmann <[email protected]>
1 parent 1cb62e3 commit 299778d

File tree

1 file changed

+21
-20
lines changed

1 file changed

+21
-20
lines changed

hw/display/sm501.c

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -684,10 +684,11 @@ static void sm501_2d_operation(SM501State *s)
684684
{
685685
int cmd = (s->twoD_control >> 16) & 0x1F;
686686
int rtl = s->twoD_control & BIT(27);
687-
int format = (s->twoD_stretch >> 20) & 0x3;
688-
int rop_mode = (s->twoD_control >> 15) & 0x1; /* 1 for rop2, else rop3 */
687+
int format = (s->twoD_stretch >> 20) & 3;
688+
int bypp = 1 << format; /* bytes per pixel */
689+
int rop_mode = (s->twoD_control >> 15) & 1; /* 1 for rop2, else rop3 */
689690
/* 1 if rop2 source is the pattern, otherwise the source is the bitmap */
690-
int rop2_source_is_pattern = (s->twoD_control >> 14) & 0x1;
691+
int rop2_source_is_pattern = (s->twoD_control >> 14) & 1;
691692
int rop = s->twoD_control & 0xFF;
692693
unsigned int dst_x = (s->twoD_destination >> 16) & 0x01FFF;
693694
unsigned int dst_y = s->twoD_destination & 0xFFFF;
@@ -724,8 +725,8 @@ static void sm501_2d_operation(SM501State *s)
724725
}
725726

726727
if (dst_base >= get_local_mem_size(s) ||
727-
dst_base + (dst_x + width + (dst_y + height) * dst_pitch) *
728-
(1 << format) >= get_local_mem_size(s)) {
728+
dst_base + (dst_x + width + (dst_y + height) * dst_pitch) * bypp >=
729+
get_local_mem_size(s)) {
729730
qemu_log_mask(LOG_GUEST_ERROR, "sm501: 2D op dest is outside vram.\n");
730731
return;
731732
}
@@ -750,8 +751,8 @@ static void sm501_2d_operation(SM501State *s)
750751
}
751752

752753
if (src_base >= get_local_mem_size(s) ||
753-
src_base + (src_x + width + (src_y + height) * src_pitch) *
754-
(1 << format) >= get_local_mem_size(s)) {
754+
src_base + (src_x + width + (src_y + height) * src_pitch) * bypp >=
755+
get_local_mem_size(s)) {
755756
qemu_log_mask(LOG_GUEST_ERROR,
756757
"sm501: 2D op src is outside vram.\n");
757758
return;
@@ -763,8 +764,8 @@ static void sm501_2d_operation(SM501State *s)
763764
uint8_t *d = s->local_mem + dst_base;
764765

765766
for (y = 0; y < height; y++) {
766-
i = (dst_x + (dst_y + y) * dst_pitch) * (1 << format);
767-
for (x = 0; x < width; x++, i += (1 << format)) {
767+
i = (dst_x + (dst_y + y) * dst_pitch) * bypp;
768+
for (x = 0; x < width; x++, i += bypp) {
768769
switch (format) {
769770
case 0:
770771
d[i] = ~d[i];
@@ -801,31 +802,31 @@ static void sm501_2d_operation(SM501State *s)
801802
de = db + width + height * (width + dst_pitch);
802803
if (rtl && ((db >= sb && db <= se) || (de >= sb && de <= se))) {
803804
/* regions may overlap: copy via temporary */
804-
int llb = width * (1 << format);
805+
int llb = width * bypp;
805806
int tmp_stride = DIV_ROUND_UP(llb, sizeof(uint32_t));
806807
uint32_t *tmp = tmp_buf;
807808

808809
if (tmp_stride * sizeof(uint32_t) * height > sizeof(tmp_buf)) {
809810
tmp = g_malloc(tmp_stride * sizeof(uint32_t) * height);
810811
}
811812
pixman_blt((uint32_t *)&s->local_mem[src_base], tmp,
812-
src_pitch * (1 << format) / sizeof(uint32_t),
813-
tmp_stride, 8 * (1 << format), 8 * (1 << format),
813+
src_pitch * bypp / sizeof(uint32_t),
814+
tmp_stride, 8 * bypp, 8 * bypp,
814815
src_x, src_y, 0, 0, width, height);
815816
pixman_blt(tmp, (uint32_t *)&s->local_mem[dst_base],
816817
tmp_stride,
817-
dst_pitch * (1 << format) / sizeof(uint32_t),
818-
8 * (1 << format), 8 * (1 << format),
818+
dst_pitch * bypp / sizeof(uint32_t),
819+
8 * bypp, 8 * bypp,
819820
0, 0, dst_x, dst_y, width, height);
820821
if (tmp != tmp_buf) {
821822
g_free(tmp);
822823
}
823824
} else {
824825
pixman_blt((uint32_t *)&s->local_mem[src_base],
825826
(uint32_t *)&s->local_mem[dst_base],
826-
src_pitch * (1 << format) / sizeof(uint32_t),
827-
dst_pitch * (1 << format) / sizeof(uint32_t),
828-
8 * (1 << format), 8 * (1 << format),
827+
src_pitch * bypp / sizeof(uint32_t),
828+
dst_pitch * bypp / sizeof(uint32_t),
829+
8 * bypp, 8 * bypp,
829830
src_x, src_y, dst_x, dst_y, width, height);
830831
}
831832
}
@@ -842,8 +843,8 @@ static void sm501_2d_operation(SM501State *s)
842843
}
843844

844845
pixman_fill((uint32_t *)&s->local_mem[dst_base],
845-
dst_pitch * (1 << format) / sizeof(uint32_t),
846-
8 * (1 << format), dst_x, dst_y, width, height, color);
846+
dst_pitch * bypp / sizeof(uint32_t),
847+
8 * bypp, dst_x, dst_y, width, height, color);
847848
break;
848849
}
849850
default:
@@ -855,7 +856,7 @@ static void sm501_2d_operation(SM501State *s)
855856
if (dst_base >= get_fb_addr(s, crt) &&
856857
dst_base <= get_fb_addr(s, crt) + fb_len) {
857858
int dst_len = MIN(fb_len, ((dst_y + height - 1) * dst_pitch +
858-
dst_x + width) * (1 << format));
859+
dst_x + width) * bypp);
859860
if (dst_len) {
860861
memory_region_set_dirty(&s->local_mem_region, dst_base, dst_len);
861862
}

0 commit comments

Comments
 (0)