X16Community / vera-module

Versatile Embedded Retro Adapter
MIT License
14 stars 5 forks source link

FIX for issue that hflipping 8-pixel-wide 2bpp tiles didnt work #27

Closed visual-trials closed 10 months ago

visual-trials commented 10 months ago

There is a bug in the layer renderer that makes 8-pixel-wide 2bpp tiles dissapear when trying to horizontally flip it.

As it turns out this is an old bug that has been in there since the beginning.

The bug has been reproduced on real hardware (for 0.3.1 and for 0.3.2): image The hflipped arrows are not visible. When run on the emulator it looks like this (which is correct): image

When looking at the verilog it became clear that the value for hflipped_xcnt was incorrect in the case of 2bpp 8-pixel-wide tiles: when flipped the value of xcnt_r was negated which resulted in hflipped_xcnt becoming >= 8. This is problematic since render_data_r[31:16] were zeroes (in this specific case).

The solution was to create a 2bpp-specific value for hflipped_xcnt named hflipped_xcnt_2bpp. This one makes sure that bit3 is set to 0 in this specific situation.

The result is a working 2bpp 8-pixel-wide hflip:

image

The LUT-cost is 9 LUTs.

This bitsteam still has to be tested more thouroughly. Most notably other layer modes/color depths.

Link to discord discussion:

https://discord.com/channels/547559626024157184/549247967945687071/1196902079189504050

visual-trials commented 10 months ago

HW testing results:

Below are the photos videos of these tests:

1bpp bitmap

bitmap_1bpp

2bpp bitmap

bitmap_2bpp

4bpp bitmap

bitmap_4bpp

8bpp bitmap

bitmap_8bpp

tiled non-flipped

https://github.com/X16Community/vera-module/assets/17767704/a413d88f-093c-4553-91fd-a77674357c19

tiled hor-flipped

https://github.com/X16Community/vera-module/assets/17767704/dca9fa3a-5c25-45cd-b591-c4812b8839f5

tiled ver-flipped

https://github.com/X16Community/vera-module/assets/17767704/c726ebea-44d2-4aeb-a32b-d39a60bbe4c3

tiled hor-and-ver-flipped

https://github.com/X16Community/vera-module/assets/17767704/6d74ca2c-526b-48e7-b2a9-539a0eefddae