Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.

When emulating System 24 tilemaps (which Model 2 uses) MAME currently treats color 0 of any palette as transparent, but some Model 2 games use color 0 to encode tile-specific colors. Here is a screenshot of Behind Enemy Lines demonstrating the problem:
Here is what that screenshot is supposed to look like:
The Sega System 24 Hardware Notes specifies the following when ABSEL=0:
On Model 2, tilemap B is usually the bottommost layer unless it has the priority flag set, in which case either tilemap A or the framebuffer is the bottommost layer depending on whether tilemap A also has the priority flag set. However, I have observed that the polygon layer is never displayed if it is empty even if both tilemaps A and B have priority (Virtual On title screen). It is unknown whether tilemap A would instead be chosen if tilemap B has priority set and tilemap A does not, making tilemap A the bottommost layer; I have not observed any games that depend on this.
The easiest solution I have found is to display color 0 from the tile-specific palette of tilemap B if all three would otherwise be transparent; this seems to fix all tilegen issues. My current solution works by drawing the layers in this order:
The solution is not quite as neat as I'd like it to be so I'm submitting this commit as a draft for now; any ideas to make the solution more elegant are welcome.