Close

Boolean Drawing

A project log for Dodo: 6502 Game System

Handheld Game System featuring the 6502

peter-noyesPeter Noyes 04/14/2016 at 04:242 Comments

While waiting for the game cartridges I updated the sprite drawing capabilities. It now supports basic boolean operations. This allows sprite drawing such that certain areas are transparent so that the background can be seen right up against the edges of the sprite.

The 3 modes supported now are Replace, AND, and OR. The common technique to make use of these operations is to use a sprite mask. The mask contains a 1 for every pixel that is outside of the sprite and should allow the background to be seen, and a 0 for every pixel that covers the sprite. The mask is first drawing using the AND operation. The result of this operation is to erase a spot for the sprite. The final step is to draw the sprite using OR.

The above video shows the sprite drawing in action. The demo is running in the Dodo simulator in the console. To keep the performance of the sprite drawing function fast, a lot of code needed to be duplicated. The code duplication is to avoid having a series of tests for the drawing modes for each and every byte that contains a block of pixels. Instead, the code that loops over the bytes in video memory is duplicated for each mode. Also, the code did end up varying slightly in structure for a few of the complex cases.

A funny consequence is that in some cases the 'Replace' function is actually slower than AND or OR. This happens when y is not on a row that is divisible by 8. When a sprite is not aligned to a page boundary it spans multiple pages and is shifted into position. The shifting leaves a gap on the top of the 1st page, and the bottom of the last page that the sprite covers. I can only copy in whole bytes because the video memory is packed. The gaps needs to be filled with something so that the background doesn't get wiped out where the gaps are. For OR, I can just make sure the gaps are filled with 0s. For AND, I need to fill the gaps with 1s. For replace I need to effectively make sure that the existing background is in the gaps. The quickest way to do this is basically push two bytes in a row in, the first being a mask that gets AND'd into place, and the next is the byte that has 0s in the gaps and it gets ORd, a single byte version of the above masking technique.

Discussions

Peter Noyes wrote 04/14/2016 at 05:13 point

Thanks!

  Are you sure? yes | no

Yann Guidon / YGDES wrote 04/14/2016 at 04:34 point

Awesome work ! you're doing great !

  Are you sure? yes | no