1divert(-1) 2 3############################################################### 4# HARDWARE SPRITES USER CONFIGURATION 5# rebuild the library if changes are made 6# 7 8# In total 64 sprites of size 16x16 pixels are supported with 9# a limit of 12 visible per scanline. Sprites of lowest 10# priority are simply not drawn if the limit is passed. Sprite 11# priority is determined by sprite number 0-63 where a higher 12# number corresponds to a higher priority sprite. 13 14# Each of the 64 sprites are described by a four-byte sprite 15# attribute which is written to port 0x57. The four 16# byte sprite attribute determines the sprite's x,y coordinate, 17# pattern id (index of 16x16 graphic to use) and various flags 18# controlling visibility, rotation and mirroring. The x,y space 19# is 320x256 pixels with the range (32,32) to (287,223) inclusive 20# corresponding to the normal 256x192 display area of the zx next. 21# Coordinates outside this central area correspond to sprites 22# displaying on top of the border area. 23 24# Bits in nextreg 21 enable the sprite layer and determine if 25# sprites should be clipped to the active display area (ie, if 26# sprites are clipped to (32,32)->(287,223)). Sprites can also 27# be clipped to an arbitrary window in the main display's 28# 256x192 area but this bit will override that clipping rectangle 29# if set. 30 31# Each sprite's four-byte attribute also identifies which pattern 32# is displayed for the sprite. The pattern is simply an index 0-63 33# that identifies an associated 16x16 pixel image. In total 34# 64 such images are written to the fpga's sprite pattern memory 35# via port 0x5b. The 16x16 pixel images are one byte per pixel 36# stored in left to right, top to bottom order. Each byte is 37# an 8-bit colour index. It is this byte, before the offset is 38# applied, that is compared against the sprite transparency index 39# to determine if the pixel is transparent. If the pixel is not 40# transparent then the offset nibble from the sprite's attributes 41# is added to the 8-bit index in the top four bits to determine 42# the final sprite 8-bit colour index. In this way several sprites 43# can share the same image but have different colours applied. 44# This final 8-bit index is then passed through the sprite's RGB333 45# palette to determine final 9-bit colour. 46 47# Larger sprites can be formed by placing individual sprites 48# next to each other. In these cases, care must be taken to 49# change positions of the consistent sprites during vbi so that 50# relative movements are not seen while the screen is drawn. 51 52# There are three logical layers of video generated by the 53# zx next. One layer is the ula screen, another is layer 2 and 54# the third is the sprites layer. The layers can be stacked 55# atop each other in any order, with underlying layers 56# visible in transparent portions of overhead layers. 57 58# Some technical details: 59# 60# The 12 sprites visibile in the next scan line are determined 61# by the hardware during HBLANK after the right border is drawn 62# in the previous scan line. 63# 64# While the display area of the scan line is generated, the final 65# colour generated by the sprite layer for each pixel is determined 66# from the 12 selected sprites. 67 68# NEXTREG 20: Global Transparency Colour 69# 70# define(`__REG_GLOBAL_TRANSPARENCY_COLOR', 20) # the transparent RGB332 colour 71 72# NEXTREG 21: Layer Priority 73# 74# define(`__REG_SPRITE_LAYER_SYSTEM', 21) 75# define(`__RSLS_ENABLE_LORES', 0x80) 76# define(`__RSLS_LAYER_PRIORITY_SLU', 0x00) # sprites on top, layer 2, ula on bottom 77# define(`__RSLS_LAYER_PRIORITY_LSU', 0x04) 78# define(`__RSLS_LAYER_PRIORITY_SUL', 0x08) 79# define(`__RSLS_LAYER_PRIORITY_LUS', 0x0c) 80# define(`__RSLS_LAYER_PRIORITY_USL', 0x10) 81# define(`__RSLS_LAYER_PRIORITY_ULS', 0x14) 82# define(`__RSLS_SPRITES_OVER_BORDER', 0x02) # sprites display in border, overrides clipping window 83# define(`__RSLS_SPRITES_VISIBLE', 0x01) # sprite layer is enabled 84 85# NEXTREG 25: Sprite clipping rectangle, coordinates are inclusive 86# 87# Send clipping rectangle as XL,XR,YT,YB in pixels (reset internal index: register 28) 88# The clipping rectangle is in the main 256x192 display area and uses that coordinate space. 89# This clipping rectangle is overridden by the border clipping bit in register 21. 90# 91# define(`__REG_CLIP_WINDOW_SPRITES', 25) 92 93# NEXTREG 28: Clipping Window Control 94# 95# define(`__REG_CLIP_WINDOW_CONTROL', 28) 96# define(`__RCWC_RESET_ULA_CLIP_INDEX', 0x04) 97# define(`__RCWC_RESET_SPRITE_CLIP_INDEX', 0x02) # reset internal index for nextreg 25 98# define(`__RCWC_RESET_LAYER_2_CLIP_INDEX', 0x01) 99 100# NEXTREG 75: Sprite Transparency Index 101# 102# define(`__REG_SPRITE_TRANSPARENCY_INDEX', 75) 103 104# PORT 0x303B: Sprite Slot Selection (write only) 105 106define(`__IO_SPRITE_SLOT', 0x303b) 107 108# PORT 0x303B: Global Sprites Flag (read only) 109# Reading from the port resets the bits 110 111define(`__IO_SPRITE_FLAGS', 0x303b) 112 113define(`__ISF_MAX_SPRITES_PER_LINE', 0x02) # set if more than 12 sprites appear on any scanline 114define(`__ISF_COLLISION', 0x01) # set if non-transparent pixels of any two sprites overlap 115 116define(`__IO_303B_MAX_SPRITES_PER_LINE', __ISF_MAX_SPRITES_PER_LINE) 117define(`__IO_303B_COLLISION', __ISF_COLLISION) 118 119# PORT 0x57: Sprite Attributes (write only) 120# 121# Each of the 64 sprites are described by a four byte attribute: 122# BYTE 0 : X position (bits 7..0) 123# BYTE 1 : Y position (0-255) 124# BYTE 2 : bits 7..4 palette offset, bit 3 = X mirror, bit 2 = Y mirror, bit 1 = rotate, bit 0 = X MSB 125# BYTE 3 : bit 7 = visible, bits 5..0 pattern index (0-63) 126# To write a specific sprite's attributes, write the sprite_number to the slot selection port 0x303b 127# and then write the bytes to this port. Each write auto-increments the attribute index. 128 129define(`__IO_SPRITE_ATTRIBUTE', 0x57) 130 131# PORT 0x5B: Sprite Patterns (write only) 132# 133# Up to 64 sprite patterns can exist, with each pattern 16x16 pixels in size. Each pixel 134# is 8-bits so each each sprite pattern occupies 256 bytes. To change a sprite pattern, 135# first write the pattern id 0-63 to the slot selection port 0x303b and then write the bytes 136# to this port. Each write auto-increments the pattern index. 137 138define(`__IO_SPRITE_PATTERN', 0x5b) 139 140# 141# END OF USER CONFIGURATION 142############################################################### 143 144divert(0) 145 146dnl# 147dnl# COMPILE TIME CONFIG EXPORT FOR ASSEMBLY LANGUAGE 148dnl# 149 150ifdef(`CFG_ASM_PUB', 151` 152PUBLIC `__IO_SPRITE_SLOT' 153 154PUBLIC `__IO_SPRITE_FLAGS' 155 156PUBLIC `__ISF_MAX_SPRITES_PER_LINE' 157PUBLIC `__ISF_COLLISION' 158 159PUBLIC `__IO_303B_MAX_SPRITES_PER_LINE' 160PUBLIC `__IO_303B_COLLISION' 161 162PUBLIC `__IO_SPRITE_ATTRIBUTE' 163 164PUBLIC `__IO_SPRITE_PATTERN' 165') 166 167dnl# 168dnl# LIBRARY BUILD TIME CONFIG FOR ASSEMBLY LANGUAGE 169dnl# 170 171ifdef(`CFG_ASM_DEF', 172` 173defc `__IO_SPRITE_SLOT' = __IO_SPRITE_SLOT 174 175defc `__IO_SPRITE_FLAGS' = __IO_SPRITE_FLAGS 176 177defc `__ISF_MAX_SPRITES_PER_LINE' = __ISF_MAX_SPRITES_PER_LINE 178defc `__ISF_COLLISION' = __ISF_COLLISION 179 180defc `__IO_303B_MAX_SPRITES_PER_LINE' = __ISF_MAX_SPRITES_PER_LINE 181defc `__IO_303B_COLLISION' = __ISF_COLLISION 182 183defc `__IO_SPRITE_ATTRIBUTE' = __IO_SPRITE_ATTRIBUTE 184 185defc `__IO_SPRITE_PATTERN' = __IO_SPRITE_PATTERN 186') 187 188dnl# 189dnl# COMPILE TIME CONFIG EXPORT FOR C 190dnl# 191 192ifdef(`CFG_C_DEF', 193` 194`#define' `__IO_SPRITE_SLOT' __IO_SPRITE_SLOT 195 196`#define' `__IO_SPRITE_FLAGS' __IO_SPRITE_FLAGS 197 198`#define' `__ISF_MAX_SPRITES_PER_LINE' __ISF_MAX_SPRITES_PER_LINE 199`#define' `__ISF_COLLISION' __ISF_COLLISION 200 201`#define' `__IO_303B_MAX_SPRITES_PER_LINE' __ISF_MAX_SPRITES_PER_LINE 202`#define' `__IO_303B_COLLISION' __ISF_COLLISION 203 204`#define' `__IO_SPRITE_ATTRIBUTE' __IO_SPRITE_ATTRIBUTE 205 206`#define' `__IO_SPRITE_PATTERN' __IO_SPRITE_PATTERN 207') 208