Difference between revisions of "Tilemap"
(testing new NextRegNo template second argument to display decimal form inside the parentheses next to the hexa) |
|||
(12 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
== Tilemap == | == Tilemap == | ||
− | A screen mode similar to hardware text linked to the ULA modes which allows for either 40x32 or 80x32 16-colour 8x8 tiles. | + | A screen mode similar to hardware text linked to the ULA modes which allows for either 40x32 or 80x32, 16-colour or 2-colour, 8x8 tiles. |
− | The tilemap is enabled using {{NextRegNo|$6B| / 107}} | + | '''''Note''' that [[NextBASIC]] also has an older software tilemap, which operates quite differently from the hardware tilemap (sometimes called layer 3) described here. NextBASIC doesn't yet have commands to access hardware tilemap natively, although the techniques described here can be used with `REG` and manual memory control. And the software tilemap is not directly accessible to assembly language programs, although the <tt>IDE_TOKENISER</tt> and <tt>IDE_BASIC</tt> [[API|NextZXOS API]] calls can execute arbitrary BASIC commands.'' |
+ | |||
+ | The hardware tilemap is enabled using {{NextRegNo|$6B| / 107}} | ||
bit 7: 0=disable tilemap, 1=enable tilemap | bit 7: 0=disable tilemap, 1=enable tilemap | ||
Line 9: | Line 11: | ||
bit 5: 0=attributes in tilemap, 1=no attributes in tilemap | bit 5: 0=attributes in tilemap, 1=no attributes in tilemap | ||
bit 4: 0=primary palette, 1=secondary palette | bit 4: 0=primary palette, 1=secondary palette | ||
− | + | bit 3: Select textmode (soft reset = 0) | |
+ | bit 2: reserved | ||
bit 1: 0=256 tile mode, 1=512 tile mode | bit 1: 0=256 tile mode, 1=512 tile mode | ||
bit 0: 1=tilemap over ULA | bit 0: 1=tilemap over ULA | ||
Line 20: | Line 23: | ||
Each tile description is a 32 byte block of 4-bit values describing the indices of each pixel of a tile in row major order. | Each tile description is a 32 byte block of 4-bit values describing the indices of each pixel of a tile in row major order. | ||
+ | |||
+ | In textmode, tiles are monochrome and take 8 bytes, making them essentially the same as ULA text chars and UDGs. | ||
=== Tilemap === | === Tilemap === | ||
Line 25: | Line 30: | ||
The tilemap begins at the location stored in bits 5-0 of {{NextRegNo|$6E| / 110}}. | The tilemap begins at the location stored in bits 5-0 of {{NextRegNo|$6E| / 110}}. | ||
− | This map either consists of either pairs of tile numbers and tile attributes, or a list of tile numbers. If no attributes are present (bit 5 of Nextreg $6B=1) then the attributes for all tiles come from {{NextRegNo|$6C| / 108}}. | + | This map either consists of either pairs of tile numbers and tile attributes, or a list of tile numbers. If no attributes are present (bit 5 of Nextreg $6B=1) then the attributes for all tiles come globally from {{NextRegNo|$6C| / 108}}. |
+ | |||
+ | In textmode, the map attribute byte and the global attribute lose the x mirror, y mirror and rotate, so bits 7-1 become a much larger palette offset that can take values between 0 and 127. The palette offset then points to one of 128 different paper/ink pairs in the palette. The paper colour palette index is (palette offset * 2), and the ink colour index is ((palette offset * 2) + 1). | ||
==== Tile Attribute ==== | ==== Tile Attribute ==== | ||
+ | |||
+ | In default 16 colour mode: | ||
bits 7-4: palette offset | bits 7-4: palette offset | ||
Line 33: | Line 42: | ||
bit 2: mirror Y | bit 2: mirror Y | ||
bit 1: Rotate | bit 1: Rotate | ||
+ | bit 0: In 256-tile mode ULA over tilemap, in 512-tile mode bit 8 of tile number | ||
+ | |||
+ | In textmode: | ||
+ | |||
+ | bits 7-1: palette offset | ||
bit 0: In 256-tile mode ULA over tilemap, in 512-tile mode bit 8 of tile number | bit 0: In 256-tile mode ULA over tilemap, in 512-tile mode bit 8 of tile number | ||
Line 82: | Line 96: | ||
(if either are transparent the result is transparent otherwise the | (if either are transparent the result is transparent otherwise the | ||
result is a logical AND of both colours) | result is a logical AND of both colours) | ||
+ | |||
+ | === More info === | ||
+ | [https://www.specnext.com/tilemap-mode/ Article about Tilemap Mode] |
Latest revision as of 14:58, 8 March 2024
Contents
Tilemap
A screen mode similar to hardware text linked to the ULA modes which allows for either 40x32 or 80x32, 16-colour or 2-colour, 8x8 tiles.
Note that NextBASIC also has an older software tilemap, which operates quite differently from the hardware tilemap (sometimes called layer 3) described here. NextBASIC doesn't yet have commands to access hardware tilemap natively, although the techniques described here can be used with `REG` and manual memory control. And the software tilemap is not directly accessible to assembly language programs, although the IDE_TOKENISER and IDE_BASIC NextZXOS API calls can execute arbitrary BASIC commands.
The hardware tilemap is enabled using Tilemap Control Register ($6B / 107)
bit 7: 0=disable tilemap, 1=enable tilemap bit 6: 0=40x32, 1=80x32 bit 5: 0=attributes in tilemap, 1=no attributes in tilemap bit 4: 0=primary palette, 1=secondary palette bit 3: Select textmode (soft reset = 0) bit 2: reserved bit 1: 0=256 tile mode, 1=512 tile mode bit 0: 1=tilemap over ULA
The tilemap consists of two data areas: tile descriptions and an actual tilemap; both of which are located in 16k page 5
Tile Description
The tile description area is a contiguous list of tile descriptions starting at the location indicated by bits 5-0 of the value in Tile Definitions Base Address Register ($6F / 111).
Each tile description is a 32 byte block of 4-bit values describing the indices of each pixel of a tile in row major order.
In textmode, tiles are monochrome and take 8 bytes, making them essentially the same as ULA text chars and UDGs.
Tilemap
The tilemap begins at the location stored in bits 5-0 of Tilemap Base Address Register ($6E / 110).
This map either consists of either pairs of tile numbers and tile attributes, or a list of tile numbers. If no attributes are present (bit 5 of Nextreg $6B=1) then the attributes for all tiles come globally from Default Tilemap Attribute Register ($6C / 108).
In textmode, the map attribute byte and the global attribute lose the x mirror, y mirror and rotate, so bits 7-1 become a much larger palette offset that can take values between 0 and 127. The palette offset then points to one of 128 different paper/ink pairs in the palette. The paper colour palette index is (palette offset * 2), and the ink colour index is ((palette offset * 2) + 1).
Tile Attribute
In default 16 colour mode:
bits 7-4: palette offset bit 3: mirror X bit 2: mirror Y bit 1: Rotate bit 0: In 256-tile mode ULA over tilemap, in 512-tile mode bit 8 of tile number
In textmode:
bits 7-1: palette offset bit 0: In 256-tile mode ULA over tilemap, in 512-tile mode bit 8 of tile number
Additional Registers
Clip Window Tilemap Register ($1B / 27)
bits 7-0: Coord. of the clip window 1st write = X1 position 2nd write = X2 position 3rd write = Y1 position 4rd write = Y2 position The values are 0,159,0,255 after a Reset Reads do not advance the clip position
Tilemap Offset X MSB Register ($2F / 47)
bits 7-2: Reserved (0) bits 1-0: MSB X Offset Meaningful Range is 0-319 in 40 char mode, 0-639 in 80 char mode
Tilemap Offset X LSB Register ($30 / 48)
bits 7-0: LSB X Offset Meaningful range is 0-319 in 40 char mode, 0-639 in 80 char mode
Tilemap Offset Y Register ($31 / 49)
bits 7-0: Y Offset (0-255)
Enhanced ULA Control Register ($43 / 67)
bit 7: '1' to disable palette write auto-increment. bits 6-4: Select palette for reading or writing: 000 = ULA first palette 100 = ULA second palette 001 = Layer 2 first palette 101 = Layer 2 second palette 010 = Sprites first palette 110 = Sprites second palette 011 = Tilemap first palette 111 = Tilemap second palette bit 3: Select Sprites palette (0 = first palette, 1 = second palette) bit 2: Select Layer 2 palette (0 = first palette, 1 = second palette) bit 1: Select ULA palette (0 = first palette, 1 = second palette) bit 0: Enable Enhanced ULA mode if 1 (0 after a reset)
ULA Control Register ($68 / 104)
bit 7: 1 to disable ULA output bit 6: 0=select the ULA colour for blending in SLU modes 6 & 7 1=select the ULA/tilemap mix for blending in SLU modes 6 & 7 bits 5-1: Reserved (0) bit 0: 1=enable stencil mode when both the ULA and tilemap are enabled (if either are transparent the result is transparent otherwise the result is a logical AND of both colours)