Simple Sprites
The hardware sprites available on the C64 are quite limited but if used well can be quite effective. Sprites are controlled but the VIC chip and by setting different registers in the VIC chip the sprites can be displayed and manipulated.
So what is a sprite? Well in simple terms its a graphical image which is 24 x 22 pixels in hi res mode and 12 x 22 pixels in multi colour mode. And yes 24 x 22 is high res, its all relative.
In hi res a sprite can be 2 colours and by two colours I mean one colour and transparent. In multi colour mode sprites have three colours and transparent but two of the colours are the same for all sprites and one can be unique to each sprite. Sounds limiting, yep it is.
Sprites can also be double width and double height but that doesn't mean there are more pixels to work with, the pixels are just double the width or height making the sprite look more chunky.
Due to a limitation in the amount of memory the VIC chip is able to address the location of all VIC data is set relative to VIC page, this is covered in the banking kernal and BASIC section. For the purpose of this section assume that kernal and BASIC are switched out and that the screen has been remapped to $C000. This is explained fully in the kernal section.
To control a sprite we must give the VIC certain information, this is done by setting values into the memory that can be read by the VIC chip.
The important values we need are:
- X co-ordinate of the sprite
- How far across the screen should the sprite be drawn, this point is the top left of the sprite graphic including any transparent pixels
- Y co-ordinate of the sprite
- How far down the screen should the sprite be drawn, this point is the top left of the sprite graphic including any transparent pixels
- The sprites individual colour
- Each sprite has one colour that can be set independently of all other sprites
- Is the sprite double width
- Simple toggle on or off
- Is the sprite double heigh
- Simple toggle on or off
- Where is the graphic for the sprite
- I'll go into greater detail on this below
- Is the sprite enabled
- Each sprite can be turned on or off individually
So lets look at the X co-ordinate for the sprite. There are 320 visible pixels across the screen of but there is also the screen border. It is possible to place a sprite into the border but the only part that will be displayed is parts which over lap onto the viewable screen. The border is 24 pixels wide so the top left of the viewable screen starts at 24 not 0. There are then 320 pixels across the viewable screen so the last addressable pixel in the viewable area is 343. This is a problem. Its a problem because the memory location used to store the X co-ordinate is a single byte, values of 0 - 255, so we need to a second byte to hold hold the high value of X. As I mentioned above memory is was at a premium and as the max value X can't attain is 376 the developer realised that they didn't need a full byte they only needed on extra bit.
Theory bit to be completed..... Hayes needs the sample code
Theory bit to be completed..... Hayes needs the sample code
No comments:
Post a Comment