@@ -684,10 +684,11 @@ static void sm501_2d_operation(SM501State *s)
684
684
{
685
685
int cmd = (s -> twoD_control >> 16 ) & 0x1F ;
686
686
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 */
689
690
/* 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 ;
691
692
int rop = s -> twoD_control & 0xFF ;
692
693
unsigned int dst_x = (s -> twoD_destination >> 16 ) & 0x01FFF ;
693
694
unsigned int dst_y = s -> twoD_destination & 0xFFFF ;
@@ -724,8 +725,8 @@ static void sm501_2d_operation(SM501State *s)
724
725
}
725
726
726
727
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 )) {
729
730
qemu_log_mask (LOG_GUEST_ERROR , "sm501: 2D op dest is outside vram.\n" );
730
731
return ;
731
732
}
@@ -750,8 +751,8 @@ static void sm501_2d_operation(SM501State *s)
750
751
}
751
752
752
753
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 )) {
755
756
qemu_log_mask (LOG_GUEST_ERROR ,
756
757
"sm501: 2D op src is outside vram.\n" );
757
758
return ;
@@ -763,8 +764,8 @@ static void sm501_2d_operation(SM501State *s)
763
764
uint8_t * d = s -> local_mem + dst_base ;
764
765
765
766
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 ) {
768
769
switch (format ) {
769
770
case 0 :
770
771
d [i ] = ~d [i ];
@@ -801,31 +802,31 @@ static void sm501_2d_operation(SM501State *s)
801
802
de = db + width + height * (width + dst_pitch );
802
803
if (rtl && ((db >= sb && db <= se ) || (de >= sb && de <= se ))) {
803
804
/* regions may overlap: copy via temporary */
804
- int llb = width * ( 1 << format ) ;
805
+ int llb = width * bypp ;
805
806
int tmp_stride = DIV_ROUND_UP (llb , sizeof (uint32_t ));
806
807
uint32_t * tmp = tmp_buf ;
807
808
808
809
if (tmp_stride * sizeof (uint32_t ) * height > sizeof (tmp_buf )) {
809
810
tmp = g_malloc (tmp_stride * sizeof (uint32_t ) * height );
810
811
}
811
812
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 ,
814
815
src_x , src_y , 0 , 0 , width , height );
815
816
pixman_blt (tmp , (uint32_t * )& s -> local_mem [dst_base ],
816
817
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 ,
819
820
0 , 0 , dst_x , dst_y , width , height );
820
821
if (tmp != tmp_buf ) {
821
822
g_free (tmp );
822
823
}
823
824
} else {
824
825
pixman_blt ((uint32_t * )& s -> local_mem [src_base ],
825
826
(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 ,
829
830
src_x , src_y , dst_x , dst_y , width , height );
830
831
}
831
832
}
@@ -842,8 +843,8 @@ static void sm501_2d_operation(SM501State *s)
842
843
}
843
844
844
845
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 );
847
848
break ;
848
849
}
849
850
default :
@@ -855,7 +856,7 @@ static void sm501_2d_operation(SM501State *s)
855
856
if (dst_base >= get_fb_addr (s , crt ) &&
856
857
dst_base <= get_fb_addr (s , crt ) + fb_len ) {
857
858
int dst_len = MIN (fb_len , ((dst_y + height - 1 ) * dst_pitch +
858
- dst_x + width ) * ( 1 << format ) );
859
+ dst_x + width ) * bypp );
859
860
if (dst_len ) {
860
861
memory_region_set_dirty (& s -> local_mem_region , dst_base , dst_len );
861
862
}
0 commit comments