• Please review our updated Terms and Rules here

How to make a Sprite in c64?

Again it is a large set of POKEs involved. Let's go through them all.

First you need to define a sprite pattern. For a quick test program we can use the area between 8192 and 16383, which however conflicts with Basic workspace if you make any longer programs.

Every sprite consists of 21 rows * 24 pixels = 21*3 = 63 bytes. In this example we simply create a big solid block. It will look boring, but by using DATA statements you can make just about any shape you like.

FOR I=0 TO 62:pOKE 16256+I,255:NEXT

Next step is to set the sprite pointer to your shape. At this point it can be useful to mention the VIC-II chip can only see 16K of memory at a time, and that it defaults to the lower 16K (0-16383). It is possible to reconfigure it to another memory block, but there are other consequences of doing that. With BASE=0 and the sprite at 16256, we get (16256-BASE)/64 = 254.

POKE 2040,254

In order to set up sprites #1-7 we would use 2041-2047.

However, we have not yet even begun to display the sprite. In order to do so, we will work with the VIC-II registers. The base address of the VIC-II is 53248, which is a very important number to remember.

First, enable our sprite: POKE 53248+21,1

It still won't be visible, but it is there. Sprite #0 equals the lowest bit (1). If you want sprite #1, you would set the second bit (2), sprite #2 is the third bit (4) and so on. You can combine all eight sprites for a maximum value of 255: 128+64+32+16+8+4+2+1.

Now we position the sprite somewhere in the middle of the screen:
POKE 53248,100:pOKE 53249,100

Those are the X and Y location registers for sprite #0. Again, the next sprite is located by 53250-53251 and so on.

If you don't like the white colour, you can change it with POKE 53248+39,7 to make it yellow.
The next sprite would be 53248+40 and so on.

If you want the sprite to become bigger, you can expand it:
POKE 53248+23,1
POKE 53248+29,1

These two POKEs work in the same way as 53248+21 did above, with regard to one bit per sprite.

Now if you want to move around the sprite, you have to use FOR statements or similar and POKE the registers of 53248 and 53249 as required.

There is a lot more to read on this subject in books like the Commodore 64 Programmer's Reference Guide and other works.
 
Again it is a large set of POKEs involved. Let's go through them all.

First you need to define a sprite pattern. For a quick test program we can use the area between 8192 and 16383, which however conflicts with Basic workspace if you make any longer programs.

Every sprite consists of 21 rows * 24 pixels = 21*3 = 63 bytes. In this example we simply create a big solid block. It will look boring, but by using DATA statements you can make just about any shape you like.

FOR I=0 TO 62:pOKE 16256+I,255:NEXT

Next step is to set the sprite pointer to your shape. At this point it can be useful to mention the VIC-II chip can only see 16K of memory at a time, and that it defaults to the lower 16K (0-16383). It is possible to reconfigure it to another memory block, but there are other consequences of doing that. With BASE=0 and the sprite at 16256, we get (16256-BASE)/64 = 254.

POKE 2040,254

In order to set up sprites #1-7 we would use 2041-2047.

However, we have not yet even begun to display the sprite. In order to do so, we will work with the VIC-II registers. The base address of the VIC-II is 53248, which is a very important number to remember.

First, enable our sprite: POKE 53248+21,1

It still won't be visible, but it is there. Sprite #0 equals the lowest bit (1). If you want sprite #1, you would set the second bit (2), sprite #2 is the third bit (4) and so on. You can combine all eight sprites for a maximum value of 255: 128+64+32+16+8+4+2+1.

Now we position the sprite somewhere in the middle of the screen:
POKE 53248,100:pOKE 53249,100

Those are the X and Y location registers for sprite #0. Again, the next sprite is located by 53250-53251 and so on.

If you don't like the white colour, you can change it with POKE 53248+39,7 to make it yellow.
The next sprite would be 53248+40 and so on.

If you want the sprite to become bigger, you can expand it:
POKE 53248+23,1
POKE 53248+29,1

These two POKEs work in the same way as 53248+21 did above, with regard to one bit per sprite.

Now if you want to move around the sprite, you have to use FOR statements or similar and POKE the registers of 53248 and 53249 as required.

There is a lot more to read on this subject in books like the Commodore 64 Programmer's Reference Guide and other works.

This is a BLOCK?
 
Block, square, geometric shape with 90 degree corners.. it doesn't matter what you call it.

The VIC-II also has functions to detect collisions between sprites and background. Those depend on the sprite pattern, i.e. a big block will trigger more collisions than a small shape in the middle of the sprite pattern.
 
ahhh the good ol Poke and Peek commands. Your best bet is to google the C64 users manual. It has a section on how to create sprites. It also has sample code to create an air balloon that flies across the screen.
 
Back
Top