Zal0 / ZGB

Game Boy / Color engine with lots of features
MIT License
706 stars 50 forks source link

Chance to update CGB tile attribute outside proper times #65

Closed ShenMansellPersonal closed 9 months ago

ShenMansellPersonal commented 9 months ago

https://github.com/Zal0/ZGB/blob/ffca1a1bcb8407a592ec559d5dfac9bebc543836/common/src/Scroll.c#L133

This line should be replaced with SetTile (id, replacement);

which will check STAT_REG & 2 before writing.

This is similar to the call directly above to write the tile data

Zal0 commented 9 months ago

Yes, you are right I haven't changed this because to be honest I am not sure why SetTile is sometimes faster than set_bkg_tile_xy which is the function I wanted to use because it is the one that comes with GBDK You are mentioning "proper times" in the description, what exactly do you mean?

ShenMansellPersonal commented 9 months ago

by outside proper times I meant while VRAM shouldn't be written.

This can cause failures where the attribute data doesn't get written, and will also throw an exception in bgb or emulicious if they are enabled

SetTile is doing checks to avoid this by looping on STAT_REG & 2 before writing.

Zal0 commented 9 months ago

As far as i know set_bkg_tiles should be doing this too The only reason why wrote SetTile back on the day is because set_bkg_tile_xy didn't exist. We have set_bkg_tiles which was slower because it expected an rect of tiles as entry param instead of a single tile When set_bkg_tile_xy was added I did a little profiling and sometimes SetTile was still faster than set_bkg_tile_xy so I didn't change it

Anyways it should be either set_bkg_tile_xy in both calls or SetTile but not a mix so I'll change it

Zal0 commented 9 months ago

that fix from Toxa should fix the issue