--- hatari/src/convert/macros.h 2019/04/01 07:13:19 1.1.1.2 +++ hatari/src/convert/macros.h 2019/04/09 08:49:47 1.1.1.6 @@ -95,6 +95,15 @@ static const Uint32 Remap_1_Plane[16] = }; + +/*----------------------------------------------------------------------*/ +/* Macros to convert from Atari's planar mode to chunky mode + * (1 byte per pixel). Convert by blocks of 4 pixels. + * 16 low res pixels -> 4 planes of 16 bits + * 16 med res pixels -> 2 planes of 16 bits + * 16 hi res pixels -> 1 plane of 16 bits + */ + #define LOW_BUILD_PIXELS_0 \ { \ ebx &= 0x0f0f0f0f; \ @@ -175,6 +184,169 @@ static const Uint32 Remap_1_Plane[16] = } + +/*----------------------------------------------------------------------*/ +/* Macros to plot Atari's pixels in the emulator's buffer + * (the buffer can be 32, 16 or 8 bits per pixel) + */ + +/* + * 32 bit screen format + */ + +/* Plot Low Resolution (320xH) 32-Bit pixels */ +#define PLOT_LOW_320_32BIT(offset) \ +{ \ + esi[offset] = (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]; \ +} + +/* Plot Low Resolution (640xH) 32-Bit pixels */ +#define PLOT_LOW_640_32BIT(offset) \ +{ \ + esi[offset+0] = esi[offset+1] = STRGBPalette[ecx & 0x000000ff]; \ + esi[offset+2] = esi[offset+3] = STRGBPalette[(ecx >> 8) & 0x000000ff]; \ + esi[offset+4] = esi[offset+5] = STRGBPalette[(ecx >> 16) & 0x000000ff]; \ + 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) \ +{ \ + esi[offset+0] = STRGBPalette[ecx & 0x000000ff]; \ + esi[offset+1] = STRGBPalette[(ecx >> 8) & 0x000000ff]; \ + esi[offset+2] = STRGBPalette[(ecx >> 16) & 0x000000ff]; \ + 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) \ +{ \ + esi[offset] = STRGBPalette[ecx & 0x000000ff]; \ +} + +/* Plot Spectrum512 Resolution (320xH) 32-Bit pixels */ +#define PLOT_SPEC512_MID_320_32BIT PLOT_LOW_320_32BIT + +/* Plot Spectrum512 Resolution(320xH) 32-Bit pixels */ +#define PLOT_SPEC512_END_LOW_320_32BIT(offset) \ +{ \ + esi[offset] = STRGBPalette[ecx & 0x000000ff]; \ + esi[offset+1] = STRGBPalette[(ecx >> 8) & 0x000000ff]; \ + esi[offset+2] = STRGBPalette[(ecx >> 16) & 0x000000ff]; \ +} + + +/* Plot Spectrum512 Resolution (640xH) 32-Bit pixels */ +#define PLOT_SPEC512_LEFT_LOW_640_32BIT(offset) \ +{ \ + esi[offset] = esi[offset+1] = STRGBPalette[ecx & 0x000000ff]; \ +} + +/* Plot Spectrum512 Resolution (640xH) 32-Bit pixels */ +#define PLOT_SPEC512_MID_640_32BIT PLOT_LOW_640_32BIT + +/* Plot Spectrum512 Resolution (640xH) 32-Bit pixels */ +#define PLOT_SPEC512_END_LOW_640_32BIT(offset) \ +{ \ + esi[offset+0] = esi[offset+1] = STRGBPalette[ecx & 0x000000ff]; \ + esi[offset+2] = esi[offset+3] = STRGBPalette[(ecx >> 8) & 0x000000ff]; \ + 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 + +#define PLOT_SPEC512_MID_MED_640_32BIT PLOT_SPEC512_MID_320_32BIT + +#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 + */ + /* Plot Low Resolution (320xH) 16-Bit pixels */ #define PLOT_LOW_320_16BIT(offset) \ { \ @@ -205,10 +377,10 @@ static const Uint32 Remap_1_Plane[16] = { \ ebpp = ecx + BASECOLOUR_LONG; \ ecx = ((ebpp & 0x0000ff00) << 8) | (ebpp & 0x000000ff); \ - esi[offset+PCScreenBytesPerLine/4] = \ + esi[offset+Screen4BytesPerLine] = \ esi[offset] = SDL_SwapLE32((ecx << 8) | ecx); \ ecx = ((ebpp & 0x00ff0000) >> 8) | (ebpp & 0xff000000); \ - esi[offset+1+PCScreenBytesPerLine/4] = \ + esi[offset+1+Screen4BytesPerLine] = \ esi[offset+1] = SDL_SwapLE32((ecx >> 8) | ecx); \ } @@ -225,13 +397,13 @@ static const Uint32 Remap_1_Plane[16] = #define PLOT_LOW_640_16BIT_DOUBLE_Y(offset) \ { \ ebx = STRGBPalette[ecx & 0x000000ff]; \ - esi[offset] = esi[offset+PCScreenBytesPerLine/4] = ebx; \ + esi[offset] = esi[offset+Screen4BytesPerLine] = ebx; \ ebx = STRGBPalette[(ecx >> 8) & 0x000000ff]; \ - esi[offset+1] = esi[offset+1+PCScreenBytesPerLine/4] = ebx; \ + esi[offset+1] = esi[offset+1+Screen4BytesPerLine] = ebx; \ ebx = STRGBPalette[(ecx >> 16) & 0x000000ff]; \ - esi[offset+2] = esi[offset+2+PCScreenBytesPerLine/4] = ebx; \ + esi[offset+2] = esi[offset+2+Screen4BytesPerLine] = ebx; \ ebx = STRGBPalette[(ecx >> 24) & 0x000000ff]; \ - esi[offset+3] = esi[offset+3+PCScreenBytesPerLine/4] = ebx; \ + esi[offset+3] = esi[offset+3+Screen4BytesPerLine] = ebx; \ } @@ -244,7 +416,7 @@ static const Uint32 Remap_1_Plane[16] = /* Plot Medium Resolution (640xH) 8-Bit pixels (Double on Y) */ #define PLOT_MED_640_8BIT_DOUBLE_Y(offset) \ { \ - esi[offset] = esi[offset+PCScreenBytesPerLine/4] =\ + esi[offset] = esi[offset+Screen4BytesPerLine] =\ SDL_SwapLE32(ecx + BASECOLOUR_LONG); \ } @@ -260,13 +432,13 @@ static const Uint32 Remap_1_Plane[16] = /* Plot Medium Resolution(640xH) 16-Bit pixels (Double on Y) */ #define PLOT_MED_640_16BIT_DOUBLE_Y(offset) \ { \ - esi[offset+PCScreenBytesPerLine/2] =\ + esi[offset+Screen2BytesPerLine] =\ esi[offset] = (Uint16)STRGBPalette[ecx & 0x000000ff]; \ - esi[offset+1+PCScreenBytesPerLine/2] =\ + esi[offset+1+Screen2BytesPerLine] =\ esi[offset+1] = (Uint16)STRGBPalette[(ecx >> 8) & 0x000000ff]; \ - esi[offset+2+PCScreenBytesPerLine/2] =\ + esi[offset+2+Screen2BytesPerLine] =\ esi[offset+2] = (Uint16)STRGBPalette[(ecx >> 16) & 0x000000ff]; \ - esi[offset+3+PCScreenBytesPerLine/2] =\ + esi[offset+3+Screen2BytesPerLine] =\ esi[offset+3] = (Uint16)STRGBPalette[(ecx >> 24) & 0x000000ff]; \ } @@ -285,7 +457,7 @@ static const Uint32 Remap_1_Plane[16] = } /* Plot Spectrum512 Resolution(320xH) 16-Bit pixels */ -#define PLOT_SPEC512_MID_320_16BIT PLOT_MED_640_16BIT +#define PLOT_SPEC512_MID_320_16BIT PLOT_LOW_640_16BIT /* Plot Spectrum512 Resolution(320xH) 16-Bit pixels */ #define PLOT_SPEC512_END_LOW_320_16BIT(offset) \ @@ -316,7 +488,7 @@ static const Uint32 Remap_1_Plane[16] = /* Plot Spectrum512 Resolution (640xH) 16-Bit pixels (Double on Y) */ #define PLOT_SPEC512_LEFT_LOW_640_16BIT_DOUBLE_Y(offset) \ { \ - esi[offset+PCScreenBytesPerLine/4] = \ + esi[offset+Screen4BytesPerLine] = \ esi[offset] = STRGBPalette[ecx & 0x000000ff]; \ } @@ -327,11 +499,51 @@ static const Uint32 Remap_1_Plane[16] = #define PLOT_SPEC512_END_LOW_640_16BIT_DOUBLE_Y(offset) \ { \ ebx = STRGBPalette[ecx & 0x000000ff]; \ - esi[offset] = esi[offset+PCScreenBytesPerLine/4] = ebx; \ + esi[offset] = esi[offset+Screen4BytesPerLine] = ebx; \ ebx = STRGBPalette[(ecx >> 8) & 0x000000ff]; \ - esi[offset+1] = esi[offset+1+PCScreenBytesPerLine/4] = ebx; \ + esi[offset+1] = esi[offset+1+Screen4BytesPerLine] = ebx; \ ebx = STRGBPalette[(ecx >> 16) & 0x000000ff]; \ - esi[offset+2] = esi[offset+2+PCScreenBytesPerLine/4] = ebx; \ + 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 + +#define PLOT_SPEC512_MID_MED_640_16BIT PLOT_SPEC512_MID_320_16BIT + +#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 + +/* on AMD XP, first one is 1/3 faster than aligned access, and + * final pixels access ~15% faster than aligned operation below + */ +# define GET_SPEC512_OFFSET_PIXELS(pixels, x) \ + (*(Uint32 *)(((Uint8 *)pixels) + x)) +# define GET_SPEC512_OFFSET_FINAL_PIXELS(pixels) \ + (*(Uint32 *)(((Uint8 *)pixels) + 13)) + +#else + +# define GET_SPEC512_OFFSET_PIXELS(pixels, x) \ + (((*(Uint32 *)(((Uint8 *)pixels) + x-1)) >> 8) \ + | ((*(Uint32 *)(((Uint8 *)pixels) + x+3)) << 24)) +# define GET_SPEC512_OFFSET_FINAL_PIXELS(pixels) \ + ((*(Uint32 *)(((Uint8 *)pixels) + 12)) >> 8) + +#endif /* __i386__ */ + + #endif /* HATARI_CONVERTMACROS_H */