Jump to content
IGNORED

CV BASIC - NEED HELP WITH SPRITES


Recommended Posts

Hello

Begiiner with CV Basic

Why the game display 2 times the same sprite ?????

 

SPRITE 0 & SPRITE 1 display the first same figure, the first one.. cannot understand why

 

' REGATES

DEFINE SPRITE 0,2,sprites_bitmaps

CLS
PRINT AT 10,"SUPER REGATES"

dim x(4)
dim y(4)
x(1)=50
y(1)=50

x(2)=150
y(2)=150

game_loop:
	WAIT

	SPRITE 0,y(1),x(1),0,9
	SPRITE 1,y(2),x(2),0,10

	IF cont.left THEN x(1)=x(1)-1
	IF cont.right THEN x(1)=x(1)+1
	IF cont.up THEN y(1)=y(1)-1
	IF cont.down THEN y(1)=y(1)+1

	GOTO game_loop


sprites_bitmaps:
	BITMAP ".......XX......."
	BITMAP ".....XXXXXX....."
	BITMAP "....XXXXXXXX...."
	BITMAP "...XXXXXXXXXX..."
	BITMAP "..XXXXXXXXXXXX.."
	BITMAP ".XXXXXXXXXXXXXX."
	BITMAP ".XXXXXXXXXXXXXX."
	BITMAP "XXXXXXXXXXXXXXXX"
	BITMAP ".......XX......."
	BITMAP "XXXXXXXXXXXXXXXX"
	BITMAP ".......XX......."
	BITMAP ".......XX......."
	BITMAP "XXXXXXXXXXXXXXXX"
	BITMAP "XXXX.XXXXXX.XXXX"
	BITMAP ".XXXXXXXXXXXXXX."
	BITMAP "..XXXXXXXXXXXX.."

	BITMAP "................"
	BITMAP "................"
	BITMAP "....XXXXXXXX...."
	BITMAP "...XXXXXXXXXX..."
	BITMAP "..XXXXXXXXXXXX.."
	BITMAP ".XXXXXXXXXXXXXX."
	BITMAP ".XXXXXXXXXXXXXX."
	BITMAP "XXXXXXXXXXXXXXXX"
	BITMAP ".......XX......."
	BITMAP ".XXXXXXXXXXXXXX."
	BITMAP ".......XX......."
	BITMAP ".......XX......."
	BITMAP "XXXXXXXXXXXXXXXX"
	BITMAP "XXXXXXXXXXXXXXXX"
	BITMAP ".XXXXXXXXXXXXXX."
	BITMAP "..XXXXXXXXXXXX.."

 

Link to comment
Share on other sites

SPRITE index,y,x,f,c

 

f is the sprite "frame". From the manual: F contains the sprite frame. You must multiply the desired sprite definition (0-63) by 4 to show the right sprite.

 

Try: SPRITE 1,y(2),x(2),4,10

It should show the 2nd pattern now

Link to comment
Share on other sites

Also, maybe you knew this already, but when you say dim x(4), that creates 4 instances of x, i.e. x(0), x(1), x(2), and x(3).

It might make more sense to have sprite 0 at location x(0), so it's all 0, rather than having sprite 0 at location x(1), which could be confusing.

/It's demo code, though, so, like I said, maybe nothing new for you here.

Link to comment
Share on other sites

Posted (edited)

ok thanks, indeed i should indicate 4 for the second Sprite... little strange... but OK it works

 

0 to 63 step 4.... Does it means that we are limite to 16 different sprites ???

Edited by drfloyd
Link to comment
Share on other sites

59 minutes ago, drfloyd said:

ok thanks, indeed i should indicate 4 for the second Sprite... little strange... but OK it works

 

0 to 63 step 4.... Does it means that we are limite to 16 different sprites ???

 

The sprite bitmap definitions are contained in a 2K block in the VRAM. For CVBasic this is set up to VRAM addresses $3800-$3fff.

 

The VDP allows a seldom used 8x8 pixels sprite mode, so by default, CVBasic starts with 16x16 pixels sprite mode. Each 16x16 sprite uses the space of four 8x8 sprites.

 

When defining sprites the first argument of DEFINE SPRITE is a sprite number 0-63, and CVBasic internally maps this to the VRAM where each 16x16 sprite uses 32 bytes of VRAM, for a total of 64 different sprite bitmaps.

 

However, the SPRITE statement data is written directly to the VDP, and the argument to select the sprite bitmap should be multiplied by 4 to account for the fact that each 16x16 sprites uses the space of four 8x8 sprites.

 

Link to comment
Share on other sites

There is no direct support for 8x8 sprites in CVBasic.

 

This will set the 8x8 sprite mode.

 

ASM halt
ASM ld bc,$C001
ASM call WRTVDP

 

When you define sprites, just remember CVBasic defines them in blocks of 4 sprites. So DEFINE SPRITE 0,64 would define the whole of the 256 sprites (64x4).

 

 

Link to comment
Share on other sites

I get why the sprite ID jumps in increments of four (each sprite consists of 4 blocks of 8x8 graphic data), but I don't get why the X and Y coordinates are reversed in the SPRITE command. Isn't it common to specify horizontal, then vertical coordinates?

Link to comment
Share on other sites

26 minutes ago, Jess Ragan said:

I get why the sprite ID jumps in increments of four (each sprite consists of 4 blocks of 8x8 graphic data), but I don't get why the X and Y coordinates are reversed in the SPRITE command. Isn't it common to specify horizontal, then vertical coordinates?

It is because that is the order in the VRAM memory.

Link to comment
Share on other sites

12 hours ago, Jess Ragan said:

I get why the sprite ID jumps in increments of four (each sprite consists of 4 blocks of 8x8 graphic data), but I don't get why the X and Y coordinates are reversed in the SPRITE command. Isn't it common to specify horizontal, then vertical coordinates?

It's a technical quick of the graphics chip, and the reason for it has to do with the "207 code": In the sprite attribute table, when the VDP encounters the value "207" as the "y" value, it interprets this as "end of sprite list", and it will ignore the rest of the data in the sprite attribute table.

 

So for example, let's say you have only two sprites to display on the screen, you place the 207 value in the "y" value of the third sprite, and only those two sprites will be displayed.

 

For this to work properly, the "y" value has to be the first byte of each sprite in the table, so that's why "y" comes before "x". It makes life simpler for the VDP.

 

Link to comment
Share on other sites

The correct value to end sprite processing is 208.

 

However, CVBasic currently does sprite flicker by default (rearranging sprites on the screen), so you need to invoke SPRITE FLICKER OFF to use the 208 value.

 

Link to comment
Share on other sites

hi,

 

How diseable the display of a sprite on the screen ? Except by putting it out of the screen ?

 

It's strange, when a change BANK to another BANK, the sprite of the last Bank is still displayed on the screen

Link to comment
Share on other sites

Posted (edited)

Banks only apply to the cartridge, while VRAM (video RAM) is located inside the ColecoVision console. Once you place data in VRAM, it stays there until you change it. Switching to a different bank does nothing to VRAM all by itself.

 

EDIT: To answer your sprite question, the VDP will always display all 32 sprites in the sprite attribute table during every screen refresh cycle unless you place the y=208 marker somewhere in that table. So if the number of sprites to display on screen varies as your game progresses (adding/removing projectiles, or whatever) then you just have to manage your usage of the sprite attribute table properly.

 

EDIT #2:

 

"However, CVBasic currently does sprite flicker by default (rearranging sprites on the screen), so you need to invoke SPRITE FLICKER OFF to use the 208 value."

 

Ah, so where CVBasic is concerned, "sprite flicker management" means "automatic sprite attribute table management". Good to know.  :)

 

Edited by Pixelboy
Link to comment
Share on other sites

6 hours ago, drfloyd said:

hi,

 

How diseable the display of a sprite on the screen ? Except by putting it out of the screen ?

 

It's strange, when a change BANK to another BANK, the sprite of the last Bank is still displayed on the screen

 

Anything you write to VRAM (DEFINE CHAR, DEFINE BITMAP, DEFINE SPRITE, SPRITE, SCREEN) is "eternal" until you erase it. It doesn't matter if you change banks, as these are local to CPU, and the VRAM is completely separate.

 

The correct way to disable a sprite is by using SPRITE num,$D1,0,0,0

 

For example, you can see an example in Camelot Knights source code where I erase sprites 4 to 31.

 

	FOR c = 4 TO 31
		SPRITE c, $d1, 0, 0, 0
	NEXT c

 

Link to comment
Share on other sites

On 5/9/2024 at 5:48 PM, Jess Ragan said:

I get why the sprite ID jumps in increments of four (each sprite consists of 4 blocks of 8x8 graphic data), but I don't get why the X and Y coordinates are reversed in the SPRITE command. Isn't it common to specify horizontal, then vertical coordinates?

The VDP expects to be fed the sprite bytes in the order y, x, pattern, color.  When calculating position in linear bitmap memory it's convenient to have y come first because it's y*horiz resolution + x

Link to comment
Share on other sites

  • 2 weeks later...
On 5/9/2024 at 6:37 PM, nanochess said:

There is no direct support for 8x8 sprites in CVBasic.

 

This will set the 8x8 sprite mode.

 

ASM halt
ASM ld bc,$C001
ASM call WRTVDP

 

When you define sprites, just remember CVBasic defines them in blocks of 4 sprites. So DEFINE SPRITE 0,64 would define the whole of the 256 sprites (64x4).

 

 

 

I put the 3 ASM lines this at the beginning of my code (to come back to 8x8 sprites)

 

But it generate freeze of my program

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...