From 08cc6527227fa414fa15e4c9084d51bf7973cef9 Mon Sep 17 00:00:00 2001 From: Matthew Berry Date: Thu, 4 Feb 2021 00:09:58 -0800 Subject: [PATCH] brightness effects for sprites, allows official bios to render properly --- src/crab/ppu.cr | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/crab/ppu.cr b/src/crab/ppu.cr index 60936e6..3a444b1 100644 --- a/src/crab/ppu.cr +++ b/src/crab/ppu.cr @@ -304,8 +304,17 @@ class PPU if sprite_pixel.priority == priority && sprite_pixel.palette > 0 selected_color = (@pram + 0x200).to_unsafe.as(UInt16*)[sprite_pixel.palette] if top_color.nil? # todo: brightness for sprites - top_color = selected_color - return top_color unless sprite_pixel.blends || (@bldcnt.is_bg_target(4, target: 1) && effects) + if !(sprite_pixel.blends || (@bldcnt.is_bg_target(4, target: 1) && effects)) + return selected_color + elsif @bldcnt.color_special_effect == 1 # alpha blending + top_color = selected_color + elsif @bldcnt.color_special_effect == 2 # brightness increase + bgr16 = BGR16.new(selected_color) + return (bgr16 + (BGR16.new(0xFFFF) - bgr16) * (Math.min(16, @bldy.evy_coefficient) / 16)).value + else # brightness decrease + bgr16 = BGR16.new(selected_color) + return (bgr16 - bgr16 * (Math.min(16, @bldy.evy_coefficient) / 16)).value + end else if @bldcnt.is_bg_target(4, target: 2) || sprite_pixel.blends color = BGR16.new(top_color) * (Math.min(16, @bldalpha.eva_coefficient) / 16) + BGR16.new(selected_color) * (Math.min(16, @bldalpha.evb_coefficient) / 16)