basic windowing, passing tonc window demo

This commit is contained in:
Matthew Berry 2021-01-31 22:57:38 -08:00
parent 88405ff36c
commit 686e53ed73

View file

@ -285,8 +285,21 @@ class PPU
end
def calculate_color(col : Int) : UInt16
enables, effects = if @dispcnt.window_0_display && @win0h.x1 <= col < @win0h.x2 && @win0v.y1 <= @vcount < @win0v.y2 # win0
{bits(@winin.value, 0..4), @winin.window_0_color_special_effect}
elsif @dispcnt.window_1_display && @win1h.x1 <= col < @win1h.x2 && @win1v.y1 <= @vcount < @win1v.y2 # win1
{bits(@winin.value, 8..12), @winin.window_1_color_special_effect}
elsif @dispcnt.obj_window_display && @sprite_pixels[col].window # obj win
{bits(@winout.value, 8..12), @winout.obj_window_color_special_effect}
elsif @dispcnt.window_0_display || @dispcnt.window_1_display || @dispcnt.obj_window_display # winout
{bits(@winout.value, 0..4), @winout.outside_color_special_effect}
else # no windows
{bits(@dispcnt.value, 8..12), true}
end
top_color = nil
4.times do |priority|
if bit?(enables, 4)
sprite_pixel = @sprite_pixels[col]
if sprite_pixel.priority == priority
if sprite_pixel.palette > 0 # todo: abstract out this duplicated work
@ -304,7 +317,9 @@ class PPU
end
end
end
end
4.times do |bg|
if bit?(enables, bg)
if @bgcnt[bg].priority == priority
palette = @layer_palettes[bg][col]
next if palette == 0
@ -324,6 +339,7 @@ class PPU
end
end
end
end
top_color || @pram.to_unsafe.as(UInt16*)[0]
end