Tileset Memory
6.1 Overview
The tileset memory is the largest contiguous part of the video RAM, it spreads across 64KB, it lies on the second half of the total 128KB of memory mapped for Zeal Video Board.
It stores the 16x16 tiles or pixels that are used in graphic modes, it is unused in text modes but still available for read and write. As such, it is possible to prepare this the tilset that will be shown in graphics mode while still being intext mode. This is very convenient to prepare the tileset before switching mode.
This memory can be written at anytime, even if the video controller is not in a H-blank or V-blank period.
In firmware v0.1.0, this memory was read-only. It is advised to update the firmware to 1.0.0 or above to have full read-write access to this part of VRAM.
6.2 In 8-bit Tiled Mode
In 8-bit tiled mode, each 16x16px tile is 256 bytes in size, with each byte representing a pixel. This gives a maximum of 64 KB / 256 = 256 tiles in total. These tiles are used by both tilemaps (layer0 and layer1), and by sprites.
Pixel values range from 0 to 255 and act as indices into the Palette Memory. This means the appearance of a tile can be changed by modifying the palette entries it references, without altering the tile data itself. However, be aware that this will affect all tiles that use the same color indices. In this mode, all tiles share the same 256-color Palette Memory.
Color index 0 is treated specially when rendered by tilemap layer1: it is considered transparent and will allow pixels from layer0 to show through. The same rule applies to sprites, pixels with color index 0 will be transparent. If both the sprite and layer1 pixels at a given position are transparent, then the corresponding pixel from layer0 will be displayed.
Tiles are stored linearly in memory: the first tile (tile 0), of 16x16 pixels, occupies the first 256 bytes; the second tile (tile 1) is stored in the next 256 bytes, and so on.
6.3 In 4-bit Tile Mode
In 4-bit tiled mode, each 16x16px tile is now 128 bytes in size, with each nibble (4-bit) representing a pixel and so one byte representing two adjacent pixels. This gives a maximum of 64 KB / 128 = 512 tiles in total. These tiles are used by both tilemap layer0 and by sprites. Be aware that this memory granularity s still 8-bit, which means taht the smallest value the host CPU can write is 8-bit, and so two pixels will be affected with performing a write.
Pixel values range from 0 to 15 and act as the lowest 4-bit of an index into the Palette Memory. The upper 4-bit of the palette index are either stored in the tilemap layer1 for tiles, either stored in the sprites attributes for the sprites. Together, these two values make an 8-bit index in the Palette Memory. This means that a single tile can be shown with different colors on screen as it can be shown with two different palettes.
In other words, in this mode, the palette can be seen as 16 independent palettes of 16 colors each, and each sprite and tile can choose any of these 16 palettes.
In 4-bit tiled mode, color index 0 is still treated as transparent, but this now applies only to sprites since layer1 does not use tiles in this mode, check Tilemap Memory for more details. As a result, sprite pixels with color index 0 are transparent, allowing the underlying layer0 pixels to be rendered.
Tiles are still organized linearly: the first tile (tile 0), of 16x16 pixels, occupies the first 128 bytes; the second tile (tile 1) is stored in the next 128 bytes, and so on.
6.4 In Bitmap Modes
In both bitmap modes, tileset memory is reused as a linear framebuffer, where each byte represents a single pixel. Pixels are organized row by row in memory, with no tiling involved. The pixel values are 8-bit color indices that reference entries in the Palette Memory, just like in 8-bit tiled mode.
Depending on the resolution, the memory usage is as follows:
- 320×200 = 64,000 bytes
- 256×240 = 61,440 bytes
This means the first scanline occupies the first 320 or 256 bytes, the second line immediately follows, and so on. Even in the 320x200 mode, there's a small amount of unused space left, which can be used for other purposes if needed.
The palette behavior is the same as in tiled mode: since each pixel is just a reference to a palette entry, it is possible to alter the appearance of the rendered image, such as applying a color shift or lighting effect, by modifying palette entries without touching the framebuffer itself.
Because these bitmap resolutions don't match the 4:3 screen ratio, borders are added to center the image:
- 320x200 shows borders at the top and bottom
- 256x240 shows borders on the left and right
You can change the color of these borders by writing to the last byte of tileset memory at offset 0xffff. This value is still used as a color index during border rendering, so you can customize the border color or even update it while the screen is being drawn.