[PATCH 1/2] Simplify low/med-rez screen doubling code

[ Thread Index | Date Index | More lists.tuxfamily.org/hatari-devel Archives ]


- Remove pixel Y-direction doubling done (with cryptic macros)
  in the screen conversion functions inner loop
- Add function to do same with memcpy() in the outer loop

Result is simpler & faster than the previous C-code
(converted from the WinSTon emulator x86 assembly).
---
 src/convert/low640x16.c      |  74 +++++--------------
 src/convert/low640x16_spec.c |  66 +++++------------
 src/convert/low640x32.c      |  76 +++++--------------
 src/convert/low640x32_spec.c |  66 +++++------------
 src/convert/macros.h         | 137 +----------------------------------
 src/convert/med640x16.c      |  71 +++++-------------
 src/convert/med640x16_spec.c |  22 ++----
 src/convert/med640x32.c      |  68 +++++------------
 src/convert/med640x32_spec.c |  22 ++----
 src/screen.c                 |  17 +++++
 10 files changed, 150 insertions(+), 469 deletions(-)

diff --git a/src/convert/low640x16.c b/src/convert/low640x16.c
index 8d69fe95..395c6f70 100644
--- a/src/convert/low640x16.c
+++ b/src/convert/low640x16.c
@@ -11,10 +11,9 @@ static void Line_ConvertLowRes_640x16Bit(Uint32 *edi, Uint32 *ebp, Uint32 *esi,
 {
 	Uint32 edx;
 	Uint32 ebx, ecx;
-	int x, update, Screen4BytesPerLine;
+	int x, update;
 
 	x = STScreenWidthBytes>>3;   /* Amount to draw across in 16-pixels(8 bytes) */
-	Screen4BytesPerLine = PCScreenBytesPerLine/4;
 	update = ScrUpdateFlag & PALETTEMASK_UPDATEMASK;
 
 	do    /* x-loop */
@@ -30,57 +29,25 @@ static void Line_ConvertLowRes_640x16Bit(Uint32 *edi, Uint32 *ebp, Uint32 *esi,
 			bScreenContentsChanged = true;
 
 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
-			/* Plot in 'right-order' on big endian systems */
-			if (!bScrDoubleY)                     /* Double on Y? */
-			{
-				/* Plot pixels */
-				LOW_BUILD_PIXELS_0 ;              /* Generate 'ecx' as pixels [12,13,14,15] */
-				PLOT_LOW_640_16BIT(12) ;
-				LOW_BUILD_PIXELS_1 ;              /* Generate 'ecx' as pixels [4,5,6,7] */
-				PLOT_LOW_640_16BIT(4) ;
-				LOW_BUILD_PIXELS_2 ;              /* Generate 'ecx' as pixels [8,9,10,11] */
-				PLOT_LOW_640_16BIT(8) ;
-				LOW_BUILD_PIXELS_3 ;              /* Generate 'ecx' as pixels [0,1,2,3] */
-				PLOT_LOW_640_16BIT(0) ;
-			}
-			else
-			{
-				/* Plot pixels */
-				LOW_BUILD_PIXELS_0 ;              /* Generate 'ecx' as pixels [12,13,14,15] */
-				PLOT_LOW_640_16BIT_DOUBLE_Y(12) ;
-				LOW_BUILD_PIXELS_1 ;              /* Generate 'ecx' as pixels [4,5,6,7] */
-				PLOT_LOW_640_16BIT_DOUBLE_Y(4) ;
-				LOW_BUILD_PIXELS_2 ;              /* Generate 'ecx' as pixels [8,9,10,11] */
-				PLOT_LOW_640_16BIT_DOUBLE_Y(8) ;
-				LOW_BUILD_PIXELS_3 ;              /* Generate 'ecx' as pixels [0,1,2,3] */
-				PLOT_LOW_640_16BIT_DOUBLE_Y(0)
-			}
+			/* Plot pixels in 'right-order' on big endian systems */
+			LOW_BUILD_PIXELS_0 ;              /* Generate 'ecx' as pixels [12,13,14,15] */
+			PLOT_LOW_640_16BIT(12) ;
+			LOW_BUILD_PIXELS_1 ;              /* Generate 'ecx' as pixels [4,5,6,7] */
+			PLOT_LOW_640_16BIT(4) ;
+			LOW_BUILD_PIXELS_2 ;              /* Generate 'ecx' as pixels [8,9,10,11] */
+			PLOT_LOW_640_16BIT(8) ;
+			LOW_BUILD_PIXELS_3 ;              /* Generate 'ecx' as pixels [0,1,2,3] */
+			PLOT_LOW_640_16BIT(0) ;
 #else
-			/* Plot in 'wrong-order', as ebx is 68000 endian */
-			if (!bScrDoubleY)                  /* Double on Y? */
-			{
-				/* Plot pixels */
-				LOW_BUILD_PIXELS_0 ;              /* Generate 'ecx' as pixels [4,5,6,7] */
-				PLOT_LOW_640_16BIT(4) ;
-				LOW_BUILD_PIXELS_1 ;              /* Generate 'ecx' as pixels [12,13,14,15] */
-				PLOT_LOW_640_16BIT(12) ;
-				LOW_BUILD_PIXELS_2 ;              /* Generate 'ecx' as pixels [0,1,2,3] */
-				PLOT_LOW_640_16BIT(0) ;
-				LOW_BUILD_PIXELS_3 ;              /* Generate 'ecx' as pixels [8,9,10,11] */
-				PLOT_LOW_640_16BIT(8) ;
-			}
-			else
-			{
-				/* Plot pixels */
-				LOW_BUILD_PIXELS_0 ;              /* Generate 'ecx' as pixels [4,5,6,7] */
-				PLOT_LOW_640_16BIT_DOUBLE_Y(4) ;
-				LOW_BUILD_PIXELS_1 ;              /* Generate 'ecx' as pixels [12,13,14,15] */
-				PLOT_LOW_640_16BIT_DOUBLE_Y(12) ;
-				LOW_BUILD_PIXELS_2 ;              /* Generate 'ecx' as pixels [0,1,2,3] */
-				PLOT_LOW_640_16BIT_DOUBLE_Y(0) ;
-				LOW_BUILD_PIXELS_3 ;              /* Generate 'ecx' as pixels [8,9,10,11] */
-				PLOT_LOW_640_16BIT_DOUBLE_Y(8)
-			}
+			/* Plot pixels in 'wrong-order', as ebx is 68000 endian */
+			LOW_BUILD_PIXELS_0 ;              /* Generate 'ecx' as pixels [4,5,6,7] */
+			PLOT_LOW_640_16BIT(4) ;
+			LOW_BUILD_PIXELS_1 ;              /* Generate 'ecx' as pixels [12,13,14,15] */
+			PLOT_LOW_640_16BIT(12) ;
+			LOW_BUILD_PIXELS_2 ;              /* Generate 'ecx' as pixels [0,1,2,3] */
+			PLOT_LOW_640_16BIT(0) ;
+			LOW_BUILD_PIXELS_3 ;              /* Generate 'ecx' as pixels [8,9,10,11] */
+			PLOT_LOW_640_16BIT(8) ;
 #endif
 
 		}
@@ -104,7 +71,6 @@ static void ConvertLowRes_640x16Bit(void)
 
 	for (y = STScreenStartHorizLine; y < STScreenEndHorizLine; y++)
 	{
-
 		/* Get screen addresses */
 		eax = STScreenLineOffset[y] + STScreenLeftSkipBytes;  /* Offset for this line + Amount to skip on left hand side */
 		edi = (Uint32 *)((Uint8 *)pSTScreen + eax);        /* ST format screen 4-plane 16 colors */
@@ -116,6 +82,6 @@ static void ConvertLowRes_640x16Bit(void)
 		else
 			Line_ConvertLowRes_640x16Bit(edi, ebp, esi, eax);
 
-		pPCScreenDest = (((Uint8 *)pPCScreenDest)+PCScreenBytesPerLine*2);  /* Offset to next line */
+		pPCScreenDest = Double_ScreenLine(pPCScreenDest, PCScreenBytesPerLine);
 	}
 }
diff --git a/src/convert/low640x16_spec.c b/src/convert/low640x16_spec.c
index 832d83a6..de06181b 100644
--- a/src/convert/low640x16_spec.c
+++ b/src/convert/low640x16_spec.c
@@ -25,8 +25,7 @@ static void ConvertLowRes_640x16Bit_Spec(void)
 
 		Line_ConvertLowRes_640x16Bit_Spec(edi, ebp, esi, eax);
 
-		/* Offset to next line (double on Y) */
-		pPCScreenDest = (((Uint8 *)pPCScreenDest) + PCScreenBytesPerLine * 2);
+		pPCScreenDest = Double_ScreenLine(pPCScreenDest, PCScreenBytesPerLine);
 	}
 
         bScreenContentsChanged = true;
@@ -35,8 +34,8 @@ static void ConvertLowRes_640x16Bit_Spec(void)
 
 static void Line_ConvertLowRes_640x16Bit_Spec(Uint32 *edi, Uint32 *ebp, Uint32 *esi, Uint32 eax)
 {
+	int x;
 	Uint32 ebx, ecx, edx;
-	int x, Screen4BytesPerLine;
 	Uint32 pixelspace[5]; /* Workspace to store pixels to so can print in right order for Spec512 */
 
 	/* on x86, unaligned access macro touches also
@@ -47,7 +46,6 @@ static void Line_ConvertLowRes_640x16Bit_Spec(Uint32 *edi, Uint32 *ebp, Uint32 *
 	Spec512_StartScanLine();        /* Build up palettes for every 4 pixels, store in 'ScanLinePalettes' */
 
 	x = STScreenWidthBytes >> 3;   /* Amount to draw across in 16-pixels (8 bytes) */
-	Screen4BytesPerLine = PCScreenBytesPerLine/4;
 
 	do  /* x-loop */
 	{
@@ -77,48 +75,24 @@ static void Line_ConvertLowRes_640x16Bit_Spec(Uint32 *edi, Uint32 *ebp, Uint32 *
 		/* And plot, the Spec512 is offset by 1 pixel and works on 'chunks' of 4 pixels */
 		/* So, we plot 1_4_4_4_3 to give 16 pixels, changing palette between */
 		/* (last one is used for first of next 16-pixels) */
-		if (!bScrDoubleY)           /* Double on Y? */
-		{
-			ecx = pixelspace[0];
-			PLOT_SPEC512_LEFT_LOW_640_16BIT(0);
-			Spec512_UpdatePaletteSpan();
-
-			ecx = GET_SPEC512_OFFSET_PIXELS(pixelspace, 1);
-			PLOT_SPEC512_MID_640_16BIT(1);
-			Spec512_UpdatePaletteSpan();
-
-			ecx = GET_SPEC512_OFFSET_PIXELS(pixelspace, 5);
-			PLOT_SPEC512_MID_640_16BIT(5);
-			Spec512_UpdatePaletteSpan();
-
-			ecx = GET_SPEC512_OFFSET_PIXELS(pixelspace, 9);
-			PLOT_SPEC512_MID_640_16BIT(9);
-			Spec512_UpdatePaletteSpan();
-
-			ecx = GET_SPEC512_OFFSET_FINAL_PIXELS(pixelspace);
-			PLOT_SPEC512_END_LOW_640_16BIT(13);
-		}
-		else
-		{
-			ecx = pixelspace[0];
-			PLOT_SPEC512_LEFT_LOW_640_16BIT_DOUBLE_Y(0);
-			Spec512_UpdatePaletteSpan();
-
-			ecx = GET_SPEC512_OFFSET_PIXELS(pixelspace, 1);
-			PLOT_SPEC512_MID_640_16BIT_DOUBLE_Y(1);
-			Spec512_UpdatePaletteSpan();
-
-			ecx = GET_SPEC512_OFFSET_PIXELS(pixelspace, 5);
-			PLOT_SPEC512_MID_640_16BIT_DOUBLE_Y(5);
-			Spec512_UpdatePaletteSpan();
-
-			ecx = GET_SPEC512_OFFSET_PIXELS(pixelspace, 9);
-			PLOT_SPEC512_MID_640_16BIT_DOUBLE_Y(9);
-			Spec512_UpdatePaletteSpan();
-
-			ecx = GET_SPEC512_OFFSET_FINAL_PIXELS(pixelspace);
-			PLOT_SPEC512_END_LOW_640_16BIT_DOUBLE_Y(13);
-		}
+		ecx = pixelspace[0];
+		PLOT_SPEC512_LEFT_LOW_640_16BIT(0);
+		Spec512_UpdatePaletteSpan();
+
+		ecx = GET_SPEC512_OFFSET_PIXELS(pixelspace, 1);
+		PLOT_SPEC512_MID_640_16BIT(1);
+		Spec512_UpdatePaletteSpan();
+
+		ecx = GET_SPEC512_OFFSET_PIXELS(pixelspace, 5);
+		PLOT_SPEC512_MID_640_16BIT(5);
+		Spec512_UpdatePaletteSpan();
+
+		ecx = GET_SPEC512_OFFSET_PIXELS(pixelspace, 9);
+		PLOT_SPEC512_MID_640_16BIT(9);
+		Spec512_UpdatePaletteSpan();
+
+		ecx = GET_SPEC512_OFFSET_FINAL_PIXELS(pixelspace);
+		PLOT_SPEC512_END_LOW_640_16BIT(13);
 
 		esi += 16;                  /* Next PC pixels */
 		edi += 2;                   /* Next ST pixels */
diff --git a/src/convert/low640x32.c b/src/convert/low640x32.c
index 5ebea29c..b2614566 100644
--- a/src/convert/low640x32.c
+++ b/src/convert/low640x32.c
@@ -11,10 +11,9 @@ static void Line_ConvertLowRes_640x32Bit(Uint32 *edi, Uint32 *ebp, Uint32 *esi,
 {
 	Uint32 edx;
 	Uint32 ebx, ecx;
-	int x, update, Screen4BytesPerLine;
+	int x, update;
 
 	x = STScreenWidthBytes>>3;   /* Amount to draw across in 16-pixels (8 bytes) */
-	Screen4BytesPerLine = PCScreenBytesPerLine/4;
 	update = ScrUpdateFlag & PALETTEMASK_UPDATEMASK;
 
 	do    /* x-loop */
@@ -30,61 +29,27 @@ static void Line_ConvertLowRes_640x32Bit(Uint32 *edi, Uint32 *ebp, Uint32 *esi,
 			bScreenContentsChanged = true;
 
 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
-			/* Plot in 'right-order' on big endian systems */
-			if (!bScrDoubleY)                   /* Double on Y? */
-			{
-				/* Plot pixels */
-				LOW_BUILD_PIXELS_0;             /* Generate 'ecx' as pixels [12,13,14,15] */
-				PLOT_LOW_640_32BIT(24);
-				LOW_BUILD_PIXELS_1;             /* Generate 'ecx' as pixels [4,5,6,7] */
-				PLOT_LOW_640_32BIT(8);
-				LOW_BUILD_PIXELS_2;             /* Generate 'ecx' as pixels [8,9,10,11] */
-				PLOT_LOW_640_32BIT(16);
-				LOW_BUILD_PIXELS_3;             /* Generate 'ecx' as pixels [0,1,2,3]] */
-				PLOT_LOW_640_32BIT(0);
-			}
-			else
-			{
-				/* Plot pixels */
-				LOW_BUILD_PIXELS_0;             /* Generate 'ecx' as pixels [12,13,14,15] */
-				PLOT_LOW_640_32BIT_DOUBLE_Y(24);
-				LOW_BUILD_PIXELS_1;             /* Generate 'ecx' as pixels [4,5,6,7] */
-				PLOT_LOW_640_32BIT_DOUBLE_Y(8);
-				LOW_BUILD_PIXELS_2;             /* Generate 'ecx' as pixels [8,9,10,11] */
-				PLOT_LOW_640_32BIT_DOUBLE_Y(16);
-				LOW_BUILD_PIXELS_3;             /* Generate 'ecx' as pixels [0,1,2,3]] */
-				PLOT_LOW_640_32BIT_DOUBLE_Y(0);
-			}
+			/* Plot pixels in 'right-order' on big endian systems */
+			LOW_BUILD_PIXELS_0;             /* Generate 'ecx' as pixels [12,13,14,15] */
+			PLOT_LOW_640_32BIT(24);
+			LOW_BUILD_PIXELS_1;             /* Generate 'ecx' as pixels [4,5,6,7] */
+			PLOT_LOW_640_32BIT(8);
+			LOW_BUILD_PIXELS_2;             /* Generate 'ecx' as pixels [8,9,10,11] */
+			PLOT_LOW_640_32BIT(16);
+			LOW_BUILD_PIXELS_3;             /* Generate 'ecx' as pixels [0,1,2,3]] */
+			PLOT_LOW_640_32BIT(0);
 #else
-			/* Plot in 'wrong-order', as ebx is 68000 endian */
-			if (!bScrDoubleY)                   /* Double on Y? */
-			{
-				/* Plot pixels */
-				LOW_BUILD_PIXELS_0;             /* Generate 'ecx' as pixels [4,5,6,7] */
-				PLOT_LOW_640_32BIT(8);
-				LOW_BUILD_PIXELS_1;             /* Generate 'ecx' as pixels [12,13,14,15] */
-				PLOT_LOW_640_32BIT(24);
-				LOW_BUILD_PIXELS_2;             /* Generate 'ecx' as pixels [0,1,2,3] */
-				PLOT_LOW_640_32BIT(0);
-				LOW_BUILD_PIXELS_3;             /* Generate 'ecx' as pixels [8,9,10,11] */
-				PLOT_LOW_640_32BIT(16);
-			}
-			else
-			{
-				/* Plot pixels */
-				LOW_BUILD_PIXELS_0;             /* Generate 'ecx' as pixels [4,5,6,7] */
-				PLOT_LOW_640_32BIT_DOUBLE_Y(8);
-				LOW_BUILD_PIXELS_1;             /* Generate 'ecx' as pixels [12,13,14,15] */
-				PLOT_LOW_640_32BIT_DOUBLE_Y(24);
-				LOW_BUILD_PIXELS_2;             /* Generate 'ecx' as pixels [0,1,2,3] */
-				PLOT_LOW_640_32BIT_DOUBLE_Y(0);
-				LOW_BUILD_PIXELS_3;             /* Generate 'ecx' as pixels [8,9,10,11] */
-				PLOT_LOW_640_32BIT_DOUBLE_Y(16);
-			}
+			/* Plot pixels in 'wrong-order', as ebx is 68000 endian */
+			LOW_BUILD_PIXELS_0;             /* Generate 'ecx' as pixels [4,5,6,7] */
+			PLOT_LOW_640_32BIT(8);
+			LOW_BUILD_PIXELS_1;             /* Generate 'ecx' as pixels [12,13,14,15] */
+			PLOT_LOW_640_32BIT(24);
+			LOW_BUILD_PIXELS_2;             /* Generate 'ecx' as pixels [0,1,2,3] */
+			PLOT_LOW_640_32BIT(0);
+			LOW_BUILD_PIXELS_3;             /* Generate 'ecx' as pixels [8,9,10,11] */
+			PLOT_LOW_640_32BIT(16);
 #endif
-
 		}
-
 		esi += 32;                      /* Next PC pixels */
 		edi += 2;                       /* Next ST pixels */
 		ebp += 2;                       /* Next ST copy pixels */
@@ -104,7 +69,6 @@ static void ConvertLowRes_640x32Bit(void)
 
 	for (y = STScreenStartHorizLine; y < STScreenEndHorizLine; y++)
 	{
-
 		/* Get screen addresses */
 		eax = STScreenLineOffset[y] + STScreenLeftSkipBytes;  /* Offset for this line + Amount to skip on left hand side */
 		edi = (Uint32 *)((Uint8 *)pSTScreen + eax);        /* ST format screen 4-plane 16 colors */
@@ -116,6 +80,6 @@ static void ConvertLowRes_640x32Bit(void)
 		else
 			Line_ConvertLowRes_640x32Bit(edi, ebp, esi, eax);
 
-		pPCScreenDest = (((Uint8 *)pPCScreenDest)+PCScreenBytesPerLine*2);  /* Offset to next line */
+		pPCScreenDest = Double_ScreenLine(pPCScreenDest, PCScreenBytesPerLine);
 	}
 }
diff --git a/src/convert/low640x32_spec.c b/src/convert/low640x32_spec.c
index d22e4a09..68aa3709 100644
--- a/src/convert/low640x32_spec.c
+++ b/src/convert/low640x32_spec.c
@@ -25,8 +25,7 @@ static void ConvertLowRes_640x32Bit_Spec(void)
 
 		Line_ConvertLowRes_640x32Bit_Spec(edi, ebp, esi, eax);
 
-		/* Offset to next line (double on Y) */
-		pPCScreenDest = (((Uint8 *)pPCScreenDest) + PCScreenBytesPerLine * 2);
+		pPCScreenDest = Double_ScreenLine(pPCScreenDest, PCScreenBytesPerLine);
 	}
 
         bScreenContentsChanged = true;
@@ -35,8 +34,8 @@ static void ConvertLowRes_640x32Bit_Spec(void)
 
 static void Line_ConvertLowRes_640x32Bit_Spec(Uint32 *edi, Uint32 *ebp, Uint32 *esi, Uint32 eax)
 {
+	int x;
 	Uint32 ebx, ecx, edx;
-	int x, Screen4BytesPerLine;
 	Uint32 pixelspace[5]; /* Workspace to store pixels to so can print in right order for Spec512 */
 
 	/* on x86, unaligned access macro touches also
@@ -47,7 +46,6 @@ static void Line_ConvertLowRes_640x32Bit_Spec(Uint32 *edi, Uint32 *ebp, Uint32 *
 	Spec512_StartScanLine();        /* Build up palettes for every 4 pixels, store in 'ScanLinePalettes' */
 
 	x = STScreenWidthBytes >> 3;   /* Amount to draw across in 16-pixels (8 bytes) */
-	Screen4BytesPerLine = PCScreenBytesPerLine/4;
 
 	do  /* x-loop */
 	{
@@ -77,48 +75,24 @@ static void Line_ConvertLowRes_640x32Bit_Spec(Uint32 *edi, Uint32 *ebp, Uint32 *
 		/* And plot, the Spec512 is offset by 1 pixel and works on 'chunks' of 4 pixels */
 		/* So, we plot 1_4_4_4_3 to give 16 pixels, changing palette between */
 		/* (last one is used for first of next 16-pixels) */
-		if (!bScrDoubleY)           /* Double on Y? */
-		{
-			ecx = pixelspace[0];
-			PLOT_SPEC512_LEFT_LOW_640_32BIT(0);
-			Spec512_UpdatePaletteSpan();
-
-			ecx = GET_SPEC512_OFFSET_PIXELS(pixelspace, 1);
-			PLOT_SPEC512_MID_640_32BIT(2);
-			Spec512_UpdatePaletteSpan();
-
-			ecx = GET_SPEC512_OFFSET_PIXELS(pixelspace, 5);
-			PLOT_SPEC512_MID_640_32BIT(10);
-			Spec512_UpdatePaletteSpan();
-
-			ecx = GET_SPEC512_OFFSET_PIXELS(pixelspace, 9);
-			PLOT_SPEC512_MID_640_32BIT(18);
-			Spec512_UpdatePaletteSpan();
-
-			ecx = GET_SPEC512_OFFSET_FINAL_PIXELS(pixelspace);
-			PLOT_SPEC512_END_LOW_640_32BIT(26);
-		}
-		else
-		{
-			ecx = pixelspace[0];
-			PLOT_SPEC512_LEFT_LOW_640_32BIT_DOUBLE_Y(0);
-			Spec512_UpdatePaletteSpan();
-
-			ecx = GET_SPEC512_OFFSET_PIXELS(pixelspace, 1);
-			PLOT_SPEC512_MID_640_32BIT_DOUBLE_Y(2);
-			Spec512_UpdatePaletteSpan();
-
-			ecx = GET_SPEC512_OFFSET_PIXELS(pixelspace, 5);
-			PLOT_SPEC512_MID_640_32BIT_DOUBLE_Y(10);
-			Spec512_UpdatePaletteSpan();
-
-			ecx = GET_SPEC512_OFFSET_PIXELS(pixelspace, 9);
-			PLOT_SPEC512_MID_640_32BIT_DOUBLE_Y(18);
-			Spec512_UpdatePaletteSpan();
-
-			ecx = GET_SPEC512_OFFSET_FINAL_PIXELS(pixelspace);
-			PLOT_SPEC512_END_LOW_640_32BIT_DOUBLE_Y(26);
-		}
+		ecx = pixelspace[0];
+		PLOT_SPEC512_LEFT_LOW_640_32BIT(0);
+		Spec512_UpdatePaletteSpan();
+
+		ecx = GET_SPEC512_OFFSET_PIXELS(pixelspace, 1);
+		PLOT_SPEC512_MID_640_32BIT(2);
+		Spec512_UpdatePaletteSpan();
+
+		ecx = GET_SPEC512_OFFSET_PIXELS(pixelspace, 5);
+		PLOT_SPEC512_MID_640_32BIT(10);
+		Spec512_UpdatePaletteSpan();
+
+		ecx = GET_SPEC512_OFFSET_PIXELS(pixelspace, 9);
+		PLOT_SPEC512_MID_640_32BIT(18);
+		Spec512_UpdatePaletteSpan();
+
+		ecx = GET_SPEC512_OFFSET_FINAL_PIXELS(pixelspace);
+		PLOT_SPEC512_END_LOW_640_32BIT(26);
 
 		esi += 32;                  /* Next PC pixels */
 		edi += 2;                   /* Next ST pixels */
diff --git a/src/convert/macros.h b/src/convert/macros.h
index f0f1955f..957de329 100644
--- a/src/convert/macros.h
+++ b/src/convert/macros.h
@@ -162,7 +162,7 @@ static const Uint32 Remap_2_Planes_Upper[256] = {
 /* Plot Low Resolution (320xH) 32-Bit pixels */
 #define PLOT_LOW_320_32BIT(offset)  \
 { \
-	esi[offset]   = (Uint32)STRGBPalette[ecx & 0x00ff]; \
+	esi[offset+0] = (Uint32)STRGBPalette[ecx & 0x00ff]; \
 	esi[offset+1] = (Uint32)STRGBPalette[(ecx >> 8) & 0x00ff]; \
 	esi[offset+2] = (Uint32)STRGBPalette[(ecx >> 16) & 0x00ff]; \
 	esi[offset+3] = (Uint32)STRGBPalette[(ecx >> 24) & 0x00ff]; \
@@ -177,23 +177,6 @@ static const Uint32 Remap_2_Planes_Upper[256] = {
 	esi[offset+6] = esi[offset+7] = STRGBPalette[(ecx >> 24) & 0x000000ff]; \
 } 
 
-/* Plot Low Resolution (640xH) 16-Bit pixels (Double on Y) */
-#define PLOT_LOW_640_32BIT_DOUBLE_Y(offset) \
-{ \
-	ebx = STRGBPalette[ecx & 0x000000ff]; \
-	esi[offset+0] = esi[offset+1] = esi[offset+Screen4BytesPerLine+0] \
-	   = esi[offset+Screen4BytesPerLine+1] = ebx; \
-	ebx = STRGBPalette[(ecx >> 8) & 0x000000ff]; \
-	esi[offset+2] = esi[offset+3] = esi[offset+Screen4BytesPerLine+2] \
-	   = esi[offset+Screen4BytesPerLine+3] = ebx; \
-	ebx = STRGBPalette[(ecx >> 16) & 0x000000ff]; \
-	esi[offset+4] = esi[offset+5] = esi[offset+Screen4BytesPerLine+4] \
-	   = esi[offset+Screen4BytesPerLine+5] = ebx; \
-	ebx = STRGBPalette[(ecx >> 24) & 0x000000ff]; \
-	esi[offset+6] = esi[offset+7] = esi[offset+Screen4BytesPerLine+6] \
-	   = esi[offset+Screen4BytesPerLine+7] = ebx; \
-}
-
 /* Plot Medium Resolution(640xH) 32-Bit pixels */
 #define PLOT_MED_640_32BIT(offset) \
 { \
@@ -203,19 +186,6 @@ static const Uint32 Remap_2_Planes_Upper[256] = {
 	esi[offset+3] = STRGBPalette[(ecx >> 24) & 0x000000ff]; \
 }
 
-/* Plot Medium Resolution(640xH) 32-Bit pixels (Double on Y) */
-#define PLOT_MED_640_32BIT_DOUBLE_Y(offset) \
-{ \
-	esi[offset+0+Screen4BytesPerLine]   = \
-	esi[offset+0] = STRGBPalette[ecx & 0x000000ff]; \
-	esi[offset+1+Screen4BytesPerLine] = \
-	esi[offset+1] = STRGBPalette[(ecx >> 8) & 0x000000ff]; \
-	esi[offset+2+Screen4BytesPerLine] = \
-	esi[offset+2] = STRGBPalette[(ecx >> 16) & 0x000000ff]; \
-	esi[offset+3+Screen4BytesPerLine] = \
-	esi[offset+3] = STRGBPalette[(ecx >> 24) & 0x000000ff]; \
-}
-
 
 /* Plot Spectrum512 Resolution (320xH) 32-Bit pixels */
 #define PLOT_SPEC512_LEFT_LOW_320_32BIT(offset)	\
@@ -229,7 +199,7 @@ static const Uint32 Remap_2_Planes_Upper[256] = {
 /* Plot Spectrum512 Resolution(320xH) 32-Bit pixels */
 #define PLOT_SPEC512_END_LOW_320_32BIT(offset) \
 { \
-	esi[offset]   = STRGBPalette[ecx & 0x000000ff]; \
+	esi[offset+0] = STRGBPalette[ecx & 0x000000ff]; \
 	esi[offset+1] = STRGBPalette[(ecx >> 8) & 0x000000ff]; \
 	esi[offset+2] = STRGBPalette[(ecx >> 16) & 0x000000ff]; \
 }
@@ -252,30 +222,6 @@ static const Uint32 Remap_2_Planes_Upper[256] = {
 	esi[offset+4] = esi[offset+5] = STRGBPalette[(ecx >> 16) & 0x000000ff]; \
 }
 
-/* Plot Spectrum512 Resolution (640xH) 32-Bit pixels (Double on Y) */
-#define PLOT_SPEC512_LEFT_LOW_640_32BIT_DOUBLE_Y(offset)	\
-{ \
-	esi[offset+Screen4BytesPerLine] = esi[offset+Screen4BytesPerLine+1] = \
-	esi[offset] = esi[offset+1] = STRGBPalette[ecx & 0x000000ff]; \
-}
-
-/* Plot Spectrum512 Resolution (640xH) 32-Bit pixels (Double on Y) */
-#define PLOT_SPEC512_MID_640_32BIT_DOUBLE_Y PLOT_LOW_640_32BIT_DOUBLE_Y
-
-/* Plot Spectrum512 Resolution (640xH) 32-Bit pixels (Double on Y) */
-#define PLOT_SPEC512_END_LOW_640_32BIT_DOUBLE_Y(offset)	\
-{ \
-	ebx = STRGBPalette[ecx & 0x000000ff]; \
-	esi[offset+Screen4BytesPerLine] = esi[offset+Screen4BytesPerLine+1] \
-	    = esi[offset] = esi[offset+1] = ebx; \
-	ebx = STRGBPalette[(ecx >> 8) & 0x000000ff]; \
-	esi[offset+2+Screen4BytesPerLine] = esi[offset+3+Screen4BytesPerLine] \
-	    = esi[offset+2] = esi[offset+3] = ebx; \
-	ebx = STRGBPalette[(ecx >> 16) & 0x000000ff]; \
-	esi[offset+4+Screen4BytesPerLine] = esi[offset+5+Screen4BytesPerLine] \
-	    = esi[offset+4] = esi[offset+5] = ebx; \
-}
-
 
 /* Plot Spectrum512 Medium Resolution (640xH) 32-Bit pixels */
 #define PLOT_SPEC512_LEFT_MED_640_32BIT	PLOT_SPEC512_LEFT_LOW_320_32BIT
@@ -285,29 +231,6 @@ static const Uint32 Remap_2_Planes_Upper[256] = {
 #define PLOT_SPEC512_END_MED_640_32BIT PLOT_SPEC512_END_LOW_320_32BIT
 
 
-/* Plot Spectrum512 Medium Resolution (640xH) 32-Bit pixels (Double on Y) */
-#define PLOT_SPEC512_LEFT_MED_640_32BIT_DOUBLE_Y(offset) \
-{ \
-	esi[offset+Screen4BytesPerLine] = esi[offset] = STRGBPalette[ecx & 0x000000ff]; \
-}
-
-#define PLOT_SPEC512_MID_MED_640_32BIT_DOUBLE_Y(offset) \
-{ \
-	esi[offset+0+Screen4BytesPerLine] = esi[offset+0] = STRGBPalette[ecx & 0x000000ff]; \
-	esi[offset+1+Screen4BytesPerLine] = esi[offset+1] = STRGBPalette[(ecx >> 8) & 0x000000ff]; \
-	esi[offset+2+Screen4BytesPerLine] = esi[offset+2] = STRGBPalette[(ecx >> 16) & 0x000000ff]; \
-	esi[offset+3+Screen4BytesPerLine] = esi[offset+3] = STRGBPalette[(ecx >> 24) & 0x000000ff]; \
-}
-
-#define PLOT_SPEC512_END_MED_640_32BIT_DOUBLE_Y(offset) \
-{ \
-	esi[offset+0+Screen4BytesPerLine] = esi[offset+0] = STRGBPalette[ecx & 0x000000ff]; \
-	esi[offset+1+Screen4BytesPerLine] = esi[offset+1] = STRGBPalette[(ecx >> 8) & 0x000000ff]; \
-	esi[offset+2+Screen4BytesPerLine] = esi[offset+2] = STRGBPalette[(ecx >> 16) & 0x000000ff]; \
-}
-
-
-
 /*
  * 16 bit screen format
  */
@@ -330,19 +253,6 @@ static const Uint32 Remap_2_Planes_Upper[256] = {
  esi[offset+3] = STRGBPalette[(ecx >> 24) & 0x000000ff]; \
 } 
 
-/* Plot Low Resolution (640xH) 16-Bit pixels (Double on Y) */
-#define PLOT_LOW_640_16BIT_DOUBLE_Y(offset) \
-{ \
- ebx = STRGBPalette[ecx & 0x000000ff]; \
- esi[offset]   = esi[offset+Screen4BytesPerLine]   = ebx; \
- ebx = STRGBPalette[(ecx >> 8) & 0x000000ff]; \
- esi[offset+1] = esi[offset+1+Screen4BytesPerLine] = ebx; \
- ebx = STRGBPalette[(ecx >> 16) & 0x000000ff]; \
- esi[offset+2] = esi[offset+2+Screen4BytesPerLine] = ebx; \
- ebx = STRGBPalette[(ecx >> 24) & 0x000000ff]; \
- esi[offset+3] = esi[offset+3+Screen4BytesPerLine] = ebx; \
-}
-
 
 /* Plot Medium Resolution(640xH) 16-Bit pixels */
 #define PLOT_MED_640_16BIT(offset) \
@@ -353,19 +263,6 @@ static const Uint32 Remap_2_Planes_Upper[256] = {
  esi[offset+3] = (Uint16)STRGBPalette[(ecx >> 24) & 0x000000ff]; \
 }
 
-/* Plot Medium Resolution(640xH) 16-Bit pixels (Double on Y) */
-#define PLOT_MED_640_16BIT_DOUBLE_Y(offset) \
-{ \
- esi[offset+Screen2BytesPerLine]   =\
- esi[offset]   = (Uint16)STRGBPalette[ecx & 0x000000ff]; \
- esi[offset+1+Screen2BytesPerLine] =\
- esi[offset+1] = (Uint16)STRGBPalette[(ecx >> 8) & 0x000000ff]; \
- esi[offset+2+Screen2BytesPerLine] =\
- esi[offset+2] = (Uint16)STRGBPalette[(ecx >> 16) & 0x000000ff]; \
- esi[offset+3+Screen2BytesPerLine] =\
- esi[offset+3] = (Uint16)STRGBPalette[(ecx >> 24) & 0x000000ff]; \
-}
-
 
 /* Plot Spectrum512 Resolution(320xH) 16-Bit pixels */
 #define PLOT_SPEC512_LEFT_LOW_320_16BIT(offset)	\
@@ -402,27 +299,6 @@ static const Uint32 Remap_2_Planes_Upper[256] = {
   esi[offset+2] = STRGBPalette[(ecx >> 16) & 0x000000ff]; \
 }
 
-/* Plot Spectrum512 Resolution (640xH) 16-Bit pixels (Double on Y) */
-#define PLOT_SPEC512_LEFT_LOW_640_16BIT_DOUBLE_Y(offset)	\
-{ \
-  esi[offset+Screen4BytesPerLine] = \
-  esi[offset] = STRGBPalette[ecx & 0x000000ff]; \
-}
-
-/* Plot Spectrum512 Resolution (640xH) 16-Bit pixels (Double on Y) */
-#define PLOT_SPEC512_MID_640_16BIT_DOUBLE_Y PLOT_LOW_640_16BIT_DOUBLE_Y
-
-/* Plot Spectrum512 Resolution (640xH) 16-Bit pixels (Double on Y) */
-#define PLOT_SPEC512_END_LOW_640_16BIT_DOUBLE_Y(offset)	\
-{ \
-  ebx = STRGBPalette[ecx & 0x000000ff]; \
-  esi[offset]   = esi[offset+Screen4BytesPerLine]   = ebx; \
-  ebx = STRGBPalette[(ecx >> 8) & 0x000000ff]; \
-  esi[offset+1] = esi[offset+1+Screen4BytesPerLine] = ebx; \
-  ebx = STRGBPalette[(ecx >> 16) & 0x000000ff]; \
-  esi[offset+2] = esi[offset+2+Screen4BytesPerLine] = ebx; \
-}
-
 
 /* Plot Spectrum512 Medium Resolution (640xH) 16-Bit pixels */
 #define PLOT_SPEC512_LEFT_MED_640_16BIT	PLOT_SPEC512_LEFT_LOW_320_16BIT
@@ -432,15 +308,6 @@ static const Uint32 Remap_2_Planes_Upper[256] = {
 #define PLOT_SPEC512_END_MED_640_16BIT PLOT_SPEC512_END_LOW_320_16BIT
 
 
-/* Plot Spectrum512 Medium Resolution (640xH) 16-Bit pixels (Double on Y) */
-#define PLOT_SPEC512_LEFT_MED_640_16BIT_DOUBLE_Y PLOT_SPEC512_LEFT_MED_640_32BIT_DOUBLE_Y
-
-#define PLOT_SPEC512_MID_MED_640_16BIT_DOUBLE_Y PLOT_SPEC512_MID_MED_640_32BIT_DOUBLE_Y
-
-#define PLOT_SPEC512_END_MED_640_16BIT_DOUBLE_Y PLOT_SPEC512_END_MED_640_32BIT_DOUBLE_Y
-
-
-
 /* Get Spec512 pixels which are offset by 1 pixel */
 #if defined(__i386__)    // Unaligned direct access is only supported on i86 platforms
 
diff --git a/src/convert/med640x16.c b/src/convert/med640x16.c
index f3f03794..7bfcb82c 100644
--- a/src/convert/med640x16.c
+++ b/src/convert/med640x16.c
@@ -1,5 +1,5 @@
 /*
-  Hatari - low320x8.c
+  Hatari - low320x16.c
 
   This file is distributed under the GNU General Public License, version 2
   or at your option any later version. Read the file gpl.txt for details.
@@ -29,8 +29,7 @@ static void ConvertMediumRes_640x16Bit(void)
 		else
 			Line_ConvertLowRes_640x16Bit(edi, ebp, (Uint32 *)esi, eax);
 
-		/* Offset to next line */
-		pPCScreenDest = (((Uint8 *)pPCScreenDest) + PCScreenBytesPerLine * 2);
+		pPCScreenDest = Double_ScreenLine(pPCScreenDest, PCScreenBytesPerLine);
 	}
 }
 
@@ -38,72 +37,41 @@ static void ConvertMediumRes_640x16Bit(void)
 static void Line_ConvertMediumRes_640x16Bit(Uint32 *edi, Uint32 *ebp, Uint16 *esi, Uint32 eax)
 {
 	Uint32 ebx, ecx;
-	int x, update, Screen2BytesPerLine;
+	int x, update;
 
 	x = STScreenWidthBytes >> 2;   /* Amount to draw across in 16-pixels (4 bytes) */
-	Screen2BytesPerLine = PCScreenBytesPerLine/2;
 	update = ScrUpdateFlag & PALETTEMASK_UPDATEMASK;
 
 	do  /* x-loop */
 	{
-
 		/* Do 16 pixels at one time */
 		ebx = *edi;
 
 		if (update || ebx != *ebp)      /* Does differ? */
 		{
 			/* copy word */
-
 			bScreenContentsChanged = true;
 
 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
 			/* Plot in 'right-order' on big endian systems */
-			if (!bScrDoubleY)                     /* Double on Y? */
-			{
-				MED_BUILD_PIXELS_0 ;              /* Generate 'ecx' as pixels [12,13,14,15] */
-				PLOT_MED_640_16BIT(12) ;
-				MED_BUILD_PIXELS_1 ;              /* Generate 'ecx' as pixels [4,5,6,7] */
-				PLOT_MED_640_16BIT(4) ;
-				MED_BUILD_PIXELS_2 ;              /* Generate 'ecx' as pixels [8,9,10,11] */
-				PLOT_MED_640_16BIT(8) ;
-				MED_BUILD_PIXELS_3 ;              /* Generate 'ecx' as pixels [0,1,2,3] */
-				PLOT_MED_640_16BIT(0) ;
-			}
-			else
-			{
-				MED_BUILD_PIXELS_0 ;              /* Generate 'ecx' as pixels [12,13,14,15] */
-				PLOT_MED_640_16BIT_DOUBLE_Y(12) ;
-				MED_BUILD_PIXELS_1 ;              /* Generate 'ecx' as pixels [4,5,6,7] */
-				PLOT_MED_640_16BIT_DOUBLE_Y(4) ;
-				MED_BUILD_PIXELS_2 ;              /* Generate 'ecx' as pixels [8,9,10,11] */
-				PLOT_MED_640_16BIT_DOUBLE_Y(8) ;
-				MED_BUILD_PIXELS_3 ;              /* Generate 'ecx' as pixels [0,1,2,3] */
-				PLOT_MED_640_16BIT_DOUBLE_Y(0) ;
-			}
+			MED_BUILD_PIXELS_0 ;              /* Generate 'ecx' as pixels [12,13,14,15] */
+			PLOT_MED_640_16BIT(12) ;
+			MED_BUILD_PIXELS_1 ;              /* Generate 'ecx' as pixels [4,5,6,7] */
+			PLOT_MED_640_16BIT(4) ;
+			MED_BUILD_PIXELS_2 ;              /* Generate 'ecx' as pixels [8,9,10,11] */
+			PLOT_MED_640_16BIT(8) ;
+			MED_BUILD_PIXELS_3 ;              /* Generate 'ecx' as pixels [0,1,2,3] */
+			PLOT_MED_640_16BIT(0) ;
 #else
 			/* Plot in 'wrong-order', as ebx is 68000 endian */
-			if (!bScrDoubleY)                     /* Double on Y? */
-			{
-				MED_BUILD_PIXELS_0 ;              /* Generate 'ecx' as pixels [4,5,6,7] */
-				PLOT_MED_640_16BIT(4) ;
-				MED_BUILD_PIXELS_1 ;              /* Generate 'ecx' as pixels [12,13,14,15] */
-				PLOT_MED_640_16BIT(12) ;
-				MED_BUILD_PIXELS_2 ;              /* Generate 'ecx' as pixels [0,1,2,3] */
-				PLOT_MED_640_16BIT(0) ;
-				MED_BUILD_PIXELS_3 ;              /* Generate 'ecx' as pixels [8,9,10,11] */
-				PLOT_MED_640_16BIT(8) ;
-			}
-			else
-			{
-				MED_BUILD_PIXELS_0 ;              /* Generate 'ecx' as pixels [4,5,6,7] */
-				PLOT_MED_640_16BIT_DOUBLE_Y(4) ;
-				MED_BUILD_PIXELS_1 ;              /* Generate 'ecx' as pixels [12,13,14,15] */
-				PLOT_MED_640_16BIT_DOUBLE_Y(12) ;
-				MED_BUILD_PIXELS_2 ;              /* Generate 'ecx' as pixels [0,1,2,3] */
-				PLOT_MED_640_16BIT_DOUBLE_Y(0) ;
-				MED_BUILD_PIXELS_3 ;              /* Generate 'ecx' as pixels [8,9,10,11] */
-				PLOT_MED_640_16BIT_DOUBLE_Y(8) ;
-			}
+			MED_BUILD_PIXELS_0 ;              /* Generate 'ecx' as pixels [4,5,6,7] */
+			PLOT_MED_640_16BIT(4) ;
+			MED_BUILD_PIXELS_1 ;              /* Generate 'ecx' as pixels [12,13,14,15] */
+			PLOT_MED_640_16BIT(12) ;
+			MED_BUILD_PIXELS_2 ;              /* Generate 'ecx' as pixels [0,1,2,3] */
+			PLOT_MED_640_16BIT(0) ;
+			MED_BUILD_PIXELS_3 ;              /* Generate 'ecx' as pixels [8,9,10,11] */
+			PLOT_MED_640_16BIT(8) ;
 #endif
 		}
 
@@ -112,5 +80,4 @@ static void Line_ConvertMediumRes_640x16Bit(Uint32 *edi, Uint32 *ebp, Uint16 *es
 		ebp += 1;                       /* Next ST copy pixels */
 	}
 	while (--x);                        /* Loop on X */
-
 }
diff --git a/src/convert/med640x16_spec.c b/src/convert/med640x16_spec.c
index 718f7618..2d9ef6bc 100644
--- a/src/convert/med640x16_spec.c
+++ b/src/convert/med640x16_spec.c
@@ -28,8 +28,7 @@ static void ConvertMediumRes_640x16Bit_Spec(void)
 		else
 			Line_ConvertLowRes_640x16Bit_Spec(edi, ebp, (Uint32 *)esi, eax);	/* low res line (double on X) */
 
-		/* Offset to next line (double on Y) */
-		pPCScreenDest = (((Uint8 *)pPCScreenDest) + PCScreenBytesPerLine * 2);
+		pPCScreenDest = Double_ScreenLine(pPCScreenDest, PCScreenBytesPerLine);
 	}
 
         bScreenContentsChanged = true;
@@ -38,8 +37,8 @@ static void ConvertMediumRes_640x16Bit_Spec(void)
 
 static void Line_ConvertMediumRes_640x16Bit_Spec(Uint32 *edi, Uint32 *ebp, Uint16 *esi, Uint32 eax)
 {
+	int x;
 	Uint32 ebx, ecx;
-	int x, Screen4BytesPerLine;
 	Uint32 pixelspace[5]; /* Workspace to store pixels to so can print in right order for Spec512 */
 
 	/* on x86, unaligned access macro touches also
@@ -50,14 +49,12 @@ static void Line_ConvertMediumRes_640x16Bit_Spec(Uint32 *edi, Uint32 *ebp, Uint1
 	Spec512_StartScanLine();        /* Build up palettes for every 4 pixels, store in 'ScanLinePalettes' */
 
 	x = STScreenWidthBytes >> 2;   /* Amount to draw across in 16-pixels (4 bytes) */
-	Screen4BytesPerLine = PCScreenBytesPerLine/2;
 
 	do  /* x-loop */
 	{
 		/* Do 16 pixels at one time */
 		ebx = *edi;
 
-
 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
 		/* Plot in 'right-order' on big endian systems */
 		MED_BUILD_PIXELS_0 ;              /* Generate 'ecx' as pixels [12,13,14,15] */
@@ -85,28 +82,23 @@ static void Line_ConvertMediumRes_640x16Bit_Spec(Uint32 *edi, Uint32 *ebp, Uint1
 		/* NOTE : In med res, we display 16 pixels in 8 cycles, so palette should be */
 		/* updated every 8 pixels, not every 4 pixels (as in low res) */
 		ecx = pixelspace[0];
-		if (!bScrDoubleY)	{ PLOT_SPEC512_LEFT_MED_640_16BIT(0); }
-		else			{ PLOT_SPEC512_LEFT_MED_640_16BIT_DOUBLE_Y(0); }
+		PLOT_SPEC512_LEFT_MED_640_16BIT(0);
 //		Spec512_UpdatePaletteSpan();
 
 		ecx = GET_SPEC512_OFFSET_PIXELS(pixelspace, 1);
-		if (!bScrDoubleY)	{ PLOT_SPEC512_MID_MED_640_16BIT(1); }
-		else			{ PLOT_SPEC512_MID_MED_640_16BIT_DOUBLE_Y(1); }
+		PLOT_SPEC512_MID_MED_640_16BIT(1);
 		Spec512_UpdatePaletteSpan();
 
 		ecx = GET_SPEC512_OFFSET_PIXELS(pixelspace, 5);
-		if (!bScrDoubleY)	{ PLOT_SPEC512_MID_MED_640_16BIT(5); }
-		else			{ PLOT_SPEC512_MID_MED_640_16BIT_DOUBLE_Y(5); }
+		PLOT_SPEC512_MID_MED_640_16BIT(5);
 //		Spec512_UpdatePaletteSpan();
 
 		ecx = GET_SPEC512_OFFSET_PIXELS(pixelspace, 9);
-		if (!bScrDoubleY)	{ PLOT_SPEC512_MID_MED_640_16BIT(9); }
-		else			{ PLOT_SPEC512_MID_MED_640_16BIT_DOUBLE_Y(9); }
+		PLOT_SPEC512_MID_MED_640_16BIT(9);
 		Spec512_UpdatePaletteSpan();
 
 		ecx = GET_SPEC512_OFFSET_FINAL_PIXELS(pixelspace);
-		if (!bScrDoubleY)	{ PLOT_SPEC512_END_MED_640_16BIT(13); }
-		else			{ PLOT_SPEC512_END_MED_640_16BIT_DOUBLE_Y(13); }
+		PLOT_SPEC512_END_MED_640_16BIT(13);
 
 		esi += 16;                      /* Next PC pixels */
 		edi += 1;                       /* Next ST pixels */
diff --git a/src/convert/med640x32.c b/src/convert/med640x32.c
index 85e3f546..1310c274 100644
--- a/src/convert/med640x32.c
+++ b/src/convert/med640x32.c
@@ -29,8 +29,7 @@ static void ConvertMediumRes_640x32Bit(void)
 		else
 			Line_ConvertLowRes_640x32Bit(edi, ebp, esi, eax);
 
-		/* Offset to next line */
-		pPCScreenDest = (((Uint8 *)pPCScreenDest) + PCScreenBytesPerLine * 2);
+		pPCScreenDest = Double_ScreenLine(pPCScreenDest, PCScreenBytesPerLine);
 	}
 }
 
@@ -38,15 +37,13 @@ static void ConvertMediumRes_640x32Bit(void)
 static void Line_ConvertMediumRes_640x32Bit(Uint32 *edi, Uint32 *ebp, Uint32 *esi, Uint32 eax)
 {
 	Uint32 ebx, ecx;
-	int x, update, Screen4BytesPerLine;
+	int x, update;
 
 	x = STScreenWidthBytes >> 2;   /* Amount to draw across in 16-pixels (4 bytes) */
-	Screen4BytesPerLine = PCScreenBytesPerLine/4;
 	update = ScrUpdateFlag & PALETTEMASK_UPDATEMASK;
 
 	do  /* x-loop */
 	{
-
 		/* Do 16 pixels at one time */
 		ebx = *edi;
 
@@ -58,52 +55,24 @@ static void Line_ConvertMediumRes_640x32Bit(Uint32 *edi, Uint32 *ebp, Uint32 *es
 
 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
 			/* Plot in 'right-order' on big endian systems */
-			if (!bScrDoubleY)                     /* Double on Y? */
-			{
-				MED_BUILD_PIXELS_0 ;              /* Generate 'ecx' as pixels [12,13,14,15] */
-				PLOT_MED_640_32BIT(12) ;
-				MED_BUILD_PIXELS_1 ;              /* Generate 'ecx' as pixels [4,5,6,7] */
-				PLOT_MED_640_32BIT(4) ;
-				MED_BUILD_PIXELS_2 ;              /* Generate 'ecx' as pixels [8,9,10,11] */
-				PLOT_MED_640_32BIT(8) ;
-				MED_BUILD_PIXELS_3 ;              /* Generate 'ecx' as pixels [0,1,2,3] */
-				PLOT_MED_640_32BIT(0) ;
-			}
-			else
-			{
-				MED_BUILD_PIXELS_0 ;              /* Generate 'ecx' as pixels [12,13,14,15] */
-				PLOT_MED_640_32BIT_DOUBLE_Y(12) ;
-				MED_BUILD_PIXELS_1 ;              /* Generate 'ecx' as pixels [4,5,6,7] */
-				PLOT_MED_640_32BIT_DOUBLE_Y(4) ;
-				MED_BUILD_PIXELS_2 ;              /* Generate 'ecx' as pixels [8,9,10,11] */
-				PLOT_MED_640_32BIT_DOUBLE_Y(8) ;
-				MED_BUILD_PIXELS_3 ;              /* Generate 'ecx' as pixels [0,1,2,3] */
-				PLOT_MED_640_32BIT_DOUBLE_Y(0) ;
-			}
+			MED_BUILD_PIXELS_0 ;              /* Generate 'ecx' as pixels [12,13,14,15] */
+			PLOT_MED_640_32BIT(12) ;
+			MED_BUILD_PIXELS_1 ;              /* Generate 'ecx' as pixels [4,5,6,7] */
+			PLOT_MED_640_32BIT(4) ;
+			MED_BUILD_PIXELS_2 ;              /* Generate 'ecx' as pixels [8,9,10,11] */
+			PLOT_MED_640_32BIT(8) ;
+			MED_BUILD_PIXELS_3 ;              /* Generate 'ecx' as pixels [0,1,2,3] */
+			PLOT_MED_640_32BIT(0) ;
 #else
 			/* Plot in 'wrong-order', as ebx is 68000 endian */
-			if (!bScrDoubleY)                     /* Double on Y? */
-			{
-				MED_BUILD_PIXELS_0 ;              /* Generate 'ecx' as pixels [4,5,6,7] */
-				PLOT_MED_640_32BIT(4) ;
-				MED_BUILD_PIXELS_1 ;              /* Generate 'ecx' as pixels [12,13,14,15] */
-				PLOT_MED_640_32BIT(12) ;
-				MED_BUILD_PIXELS_2 ;              /* Generate 'ecx' as pixels [0,1,2,3] */
-				PLOT_MED_640_32BIT(0) ;
-				MED_BUILD_PIXELS_3 ;              /* Generate 'ecx' as pixels [8,9,10,11] */
-				PLOT_MED_640_32BIT(8) ;
-			}
-			else
-			{
-				MED_BUILD_PIXELS_0 ;              /* Generate 'ecx' as pixels [4,5,6,7] */
-				PLOT_MED_640_32BIT_DOUBLE_Y(4) ;
-				MED_BUILD_PIXELS_1 ;              /* Generate 'ecx' as pixels [12,13,14,15] */
-				PLOT_MED_640_32BIT_DOUBLE_Y(12) ;
-				MED_BUILD_PIXELS_2 ;              /* Generate 'ecx' as pixels [0,1,2,3] */
-				PLOT_MED_640_32BIT_DOUBLE_Y(0) ;
-				MED_BUILD_PIXELS_3 ;              /* Generate 'ecx' as pixels [8,9,10,11] */
-				PLOT_MED_640_32BIT_DOUBLE_Y(8) ;
-			}
+			MED_BUILD_PIXELS_0 ;              /* Generate 'ecx' as pixels [4,5,6,7] */
+			PLOT_MED_640_32BIT(4) ;
+			MED_BUILD_PIXELS_1 ;              /* Generate 'ecx' as pixels [12,13,14,15] */
+			PLOT_MED_640_32BIT(12) ;
+			MED_BUILD_PIXELS_2 ;              /* Generate 'ecx' as pixels [0,1,2,3] */
+			PLOT_MED_640_32BIT(0) ;
+			MED_BUILD_PIXELS_3 ;              /* Generate 'ecx' as pixels [8,9,10,11] */
+			PLOT_MED_640_32BIT(8) ;
 #endif
 		}
 
@@ -112,5 +81,4 @@ static void Line_ConvertMediumRes_640x32Bit(Uint32 *edi, Uint32 *ebp, Uint32 *es
 		ebp += 1;                       /* Next ST copy pixels */
 	}
 	while (--x);                        /* Loop on X */
-
 }
diff --git a/src/convert/med640x32_spec.c b/src/convert/med640x32_spec.c
index 65ecdc98..cb9c5515 100644
--- a/src/convert/med640x32_spec.c
+++ b/src/convert/med640x32_spec.c
@@ -28,8 +28,7 @@ static void ConvertMediumRes_640x32Bit_Spec(void)
 		else
 			Line_ConvertLowRes_640x32Bit_Spec(edi, ebp, esi, eax);		/* low res line (double on X) */
 
-		/* Offset to next line (double on Y) */
-		pPCScreenDest = (((Uint8 *)pPCScreenDest) + PCScreenBytesPerLine * 2);
+		pPCScreenDest = Double_ScreenLine(pPCScreenDest, PCScreenBytesPerLine);
 	}
 
         bScreenContentsChanged = true;
@@ -38,8 +37,8 @@ static void ConvertMediumRes_640x32Bit_Spec(void)
 
 static void Line_ConvertMediumRes_640x32Bit_Spec(Uint32 *edi, Uint32 *ebp, Uint32 *esi, Uint32 eax)
 {
+	int x;
 	Uint32 ebx, ecx;
-	int x, Screen4BytesPerLine;
 	Uint32 pixelspace[5]; /* Workspace to store pixels to so can print in right order for Spec512 */
 
 	/* on x86, unaligned access macro touches also
@@ -50,14 +49,12 @@ static void Line_ConvertMediumRes_640x32Bit_Spec(Uint32 *edi, Uint32 *ebp, Uint3
 	Spec512_StartScanLine();        /* Build up palettes for every 4 pixels, store in 'ScanLinePalettes' */
 
 	x = STScreenWidthBytes >> 2;   /* Amount to draw across in 16-pixels (4 bytes) */
-	Screen4BytesPerLine = PCScreenBytesPerLine/4;
 
 	do  /* x-loop */
 	{
 		/* Do 16 pixels at one time */
 		ebx = *edi;
 
-
 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
 		/* Plot in 'right-order' on big endian systems */
 		MED_BUILD_PIXELS_0 ;              /* Generate 'ecx' as pixels [12,13,14,15] */
@@ -85,28 +82,23 @@ static void Line_ConvertMediumRes_640x32Bit_Spec(Uint32 *edi, Uint32 *ebp, Uint3
 		/* NOTE : In med res, we display 16 pixels in 8 cycles, so palette should be */
 		/* updated every 8 pixels, not every 4 pixels (as in low res) */
 		ecx = pixelspace[0];
-		if (!bScrDoubleY)	{ PLOT_SPEC512_LEFT_MED_640_32BIT(0); }
-		else			{ PLOT_SPEC512_LEFT_MED_640_32BIT_DOUBLE_Y(0); }
+		PLOT_SPEC512_LEFT_MED_640_32BIT(0);
 //		Spec512_UpdatePaletteSpan();
 
 		ecx = GET_SPEC512_OFFSET_PIXELS(pixelspace, 1);
-		if (!bScrDoubleY)	{ PLOT_SPEC512_MID_MED_640_32BIT(1); }
-		else			{ PLOT_SPEC512_MID_MED_640_32BIT_DOUBLE_Y(1); }
+		PLOT_SPEC512_MID_MED_640_32BIT(1);
 		Spec512_UpdatePaletteSpan();
 
 		ecx = GET_SPEC512_OFFSET_PIXELS(pixelspace, 5);
-		if (!bScrDoubleY)	{ PLOT_SPEC512_MID_MED_640_32BIT(5); }
-		else			{ PLOT_SPEC512_MID_MED_640_32BIT_DOUBLE_Y(5); }
+		PLOT_SPEC512_MID_MED_640_32BIT(5);
 //		Spec512_UpdatePaletteSpan();
 
 		ecx = GET_SPEC512_OFFSET_PIXELS(pixelspace, 9);
-		if (!bScrDoubleY)	{ PLOT_SPEC512_MID_MED_640_32BIT(9); }
-		else			{ PLOT_SPEC512_MID_MED_640_32BIT_DOUBLE_Y(9); }
+		PLOT_SPEC512_MID_MED_640_32BIT(9);
 		Spec512_UpdatePaletteSpan();
 
 		ecx = GET_SPEC512_OFFSET_FINAL_PIXELS(pixelspace);
-		if (!bScrDoubleY)	{ PLOT_SPEC512_END_MED_640_32BIT(13); }
-		else			{ PLOT_SPEC512_END_MED_640_32BIT_DOUBLE_Y(13); }
+		PLOT_SPEC512_END_MED_640_32BIT(13);
 
 		esi += 16;                      /* Next PC pixels */
 		edi += 1;                       /* Next ST pixels */
diff --git a/src/screen.c b/src/screen.c
index 5e07feff..d3ef4be4 100644
--- a/src/screen.c
+++ b/src/screen.c
@@ -1600,6 +1600,23 @@ static void Convert_StartFrame(void)
 		AdjustLinePaletteRemap(y++);     /* Update palette */
 }
 
+/*-----------------------------------------------------------------------*/
+/**
+ * Copy given line (address) of given length, to line below it,
+ * or skip it, depending on bScrDoubleY.
+ *
+ * Return address to next line after the copy
+ */
+static Uint8* Double_ScreenLine(Uint8 *line, int size)
+{
+	if (bScrDoubleY)
+	{
+		Uint8 *next = line + size;
+		memcpy(next, line, size);
+	}
+	return line + 2 * size;
+}
+
 /* lookup tables and conversion macros */
 #include "convert/macros.h"
 
-- 
2.20.1


--------------6A7DF27EC3B53E20A87C360F--



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/