With the basic graphics and sound functionality done, and plenty of logic space left in the FPGA, I started to think about what else I could make this chip do. Having a bitmap mode would be nice, as there are many things this could be used for that can’t be easily done with tile and sprite graphics. Could I squeeze a bitmap mode into this project?
The first problem is that there were only four line buffers available, and I really didn’t want to add a fifth. Instead, I gave the graphics mode register some additional functionality, and attached some logic to it beyond simply enabling the individual engines. Previously the graphics chip had four individual engines in it (text, tile A, tile B, and sprite). I added a field for a fifth, but also ensured that only four would be permitted to be active at a time, and added mapping logic to rearrange the connections between the engines and the line buffers, so that each of the maximum of four enabled engines would still have its own line buffer.
I added additional bits to the graphics mode register to control the resolution and color depth of the bitmap. Two resolutions are available: 160x120, and 320x240. There are also four color depths available: 2 color, 4 color, 16 color, or 256 color. I also added a separate bitmap palette area in memory which stores up to 16 colors, to be used as the palette in the lower color modes.
The biggest challenge was where to store the memory required for bitmap modes. I still had about 24K of general purpose block RAM left in the FPGA, which was enough for some of the graphics modes. I could fit any color depth bitmap at 160x120, and 2 or 4 color modes at 320x240. For the higher color depth full resolution modes, I put in a feature to allow the bitmap to use other parts of the chip’s memory, disabling the sprite, tile, and text engines as needed to free up the space. A full resolution, full color bitmap image requires all of the other engines to be disabled, freeing up all of the available graphics memory for the bitmap. This was also where I added in the ability for the sprite bitmaps to draw from other parts of the memory, enabling up to 64K of memory to be available for sprites by disabling other graphics engines.
The other problem was how to allow the external CPU to access all of this memory. To the external CPU, the FPGA appears as a 64K memory device. Essentially all of that 64K space was already spoken for, but here I wanted to add an additional 24K of addressable space. I handled this in a slightly inelegant way, adding a remap register to the control registers that allows the last 16K of the memory space to be remapped between three different regions of memory, making the new areas of memory available to the external CPU.
With this new feature, I could recreate the original parrot image demo from a Basic program, loading the image from files on the SD card instead of having it hard-coded in the FPGA’s memory.
I could also now do a full-resolution Mandlebrot set demo.
And at lower resolution or color depth, I can layer bitmap graphics on top of text, tiles, or sprites. I added a number of Basic commands to automate the drawing of lines, circles, rectangles, and other shapes, as well as to automatically handle memory address calculation and remapping.



