Update Draw Instructions to Use Bitplanes
With the bitplane selector in place (see issue #27), the various draw functions need to be updated to only update elements on the selected bitplane(s). As mentioned before, the bitplane selector sets which planes are impacted by the draw operations:
0- means no plane is selected, and thus nothing is updpated.1- means the first bitplane is selected - only items on this bitplane are updated.2- means the second bitplane selected - only items on this bitplane are updated.3- means both bitplanes are selected.
The following instructions need to be updated to obey the bitplane selector:
00Cn- scroll downnlines00E0- clear pixels on the current bitplane00FB- scroll right 4 pixels00FC- scroll left 4 pixelsDxy0- draw sprite
For the instructions above, new rules are inplace when pixels are written or cleared. Where the original Chip8 implementation used XOR to either turn a pixel on or off, now overlapping pixels on bitplanes are introduced. Pixels drawn on the first bitplane use color_1, while pixels drawn on the second bitplane use color_2. If a pixel is to be turned on in both the first bitplane, and its corresponding pixel is turned on in the second bitplane, then color_3 is used. If no pixel is turned on in either bitplane, then color_0 is used.
A special case arises when both bitplanes are selected. First, the VF register should be updated to register a collision if either bitplane results in a zero value being written. Second, the draw command will consume twice as many bytes for pixel information. The first set of bytes will draw to the first plane, and the second set of bytes will draw to the second plane (in the same pixel locations). For example, if the draw command uses a 4-byte value, then the bytes i to i+3 are written to the first bitplane, and i+4 to i+7 are written to the second bitplane.