@@ -1268,6 +1268,23 @@ static XEMU_INLINE void vic4_do_sprites ( void )
12681268}
12691269
12701270
1271+ static XEMU_INLINE Uint32 blend32 ( const Uint32 a , const Uint32 b , const Uint8 s )
1272+ {
1273+ // Used by the FCM alpha-blend renderer on SDL2 colour representation (RGBA
1274+ // per bytes within 32 bit unsigned integers). Technically I wouldn't need
1275+ // to "blend" the alpha channel, however I cannot be sure which byte is alpha
1276+ // (platform dependent, byte order ...). But since alpha channel is always $FF
1277+ // for "A" and "B" too, blending those wouldn't hurt. And btw, do not confuse
1278+ // the "alpha" in RGBA and the nature of alpha-blending, independent things.
1279+ return
1280+ (( a & 0xFF ) * s + ( b & 0xFF ) * (255U - s )) / 255U +
1281+ (((((a >> 8 ) & 0xFF ) * s + ((b >> 8 ) & 0xFF ) * (255U - s )) / 255U ) << 8 ) +
1282+ (((((a >> 16 ) & 0xFF ) * s + ((b >> 16 ) & 0xFF ) * (255U - s )) / 255U ) << 16 ) +
1283+ (((( a >> 24 ) * s + ( b >> 24 ) * (255U - s )) / 255U ) << 24 );
1284+ }
1285+
1286+
1287+
12711288// Render a monochrome character cell row
12721289// flip = 00 Dont flip, 01 = flip vertical, 10 = flip horizontal, 11 = flip both
12731290static XEMU_INLINE void vic4_render_mono_char_row ( Uint8 char_byte , const int glyph_width , const Uint8 bg_color , Uint8 fg_color , Uint8 vic3attr )
@@ -1339,6 +1356,16 @@ static XEMU_INLINE void vic4_render_fullcolor_char_row ( const Uint8* char_row,
13391356}
13401357
13411358
1359+ static XEMU_INLINE void vic4_render_fullcolor_char_row_with_alpha ( const Uint8 * char_row_ptr , const int glyph_width , const Uint32 bg_sdl_color , const Uint32 fg_sdl_color , const int hflip )
1360+ {
1361+ for (float cx = 0 ; cx < glyph_width && xcounter < border_x_right ; cx += char_x_step ) {
1362+ const Uint8 char_data = draw_mask & char_row_ptr [XEMU_LIKELY (!hflip ) ? (int )cx : glyph_width - 1 - (int )cx ];
1363+ * current_pixel ++ = blend32 (fg_sdl_color , bg_sdl_color , char_data );
1364+ is_fg [xcounter ++ ] = char_data ;
1365+ }
1366+ }
1367+
1368+
13421369// 16-color (Nybl) mode (4-bit per pixel / 16 pixel wide characters)
13431370static XEMU_INLINE void vic4_render_16color_char_row ( const Uint8 * char_row , const int glyph_width , const Uint32 bg_sdl_color , const Uint32 fg_sdl_color , const Uint32 * palette16 , const int hflip )
13441371{
@@ -1589,14 +1616,23 @@ static XEMU_INLINE void vic4_render_char_raster ( void )
15891616 // fgcolor in case of FCM should mean colour index $FF
15901617 // FIXME: check if the passed palette[color_data & 0xFF] is correct or another index should be used for that $FF colour stuff
15911618 const Uint32 * palette_now = ((REG_VICIII_ATTRIBS ) && SXA_ATTR_ALTPALETTE (color_data )) ? altpalette : used_palette ;
1592- vic4_render_fullcolor_char_row (
1593- main_ram + (((char_id * 64 ) + ((sel_char_row + char_fetch_offset ) * 8 )) & 0x7FFFF ),
1594- 8 - glyph_trim ,
1595- palette_now [char_bgcolor ], // bg SDL colour
1596- palette_now [color_data & 0xFF ], // fg SDL colour
1597- SXA_HORIZONTAL_FLIP (color_data ), // hflip?
1598- palette_now
1599- );
1619+ if (XEMU_UNLIKELY ((vic_registers [0x54 ] & 0x81 ) == 0x81 && SXA_ALPHA_BLEND (color_data )))
1620+ vic4_render_fullcolor_char_row_with_alpha (
1621+ main_ram + (((char_id * 64 ) + ((sel_char_row + char_fetch_offset ) * 8 )) & 0x7FFFF ),
1622+ 8 - glyph_trim ,
1623+ palette_now [char_bgcolor ], // bg SDL colour
1624+ palette_now [color_data & 0xFF ], // fg SDL colour
1625+ SXA_HORIZONTAL_FLIP (color_data ) // hflip?
1626+ );
1627+ else
1628+ vic4_render_fullcolor_char_row (
1629+ main_ram + (((char_id * 64 ) + ((sel_char_row + char_fetch_offset ) * 8 )) & 0x7FFFF ),
1630+ 8 - glyph_trim ,
1631+ palette_now [char_bgcolor ], // bg SDL colour
1632+ palette_now [color_data & 0xFF ], // fg SDL colour
1633+ SXA_HORIZONTAL_FLIP (color_data ), // hflip?
1634+ palette_now
1635+ );
16001636 } else if ((REG_MCM && ((color_data & 8 ) || (vic_registers [0x63 ] & 0x40 ))) || (REG_MCM && REG_BMM )) { // Multicolor character
16011637 // using static vars: faster in a rapid loop like this, no need to re-adjust stack pointer all the time to allocate space and this way using constant memory address
16021638 // also, as an optimization, later, some value can be re-used and not always initialized here, when in reality VIC
0 commit comments