Is Vpoke-ing sprites actually faster?

By Pineapple

Supporter (12)

Pineapple's picture

21-05-2020, 04:39

I read that you can get a speed boost in basic by using VPOKE instead of putsprite, so I tracked down the memory location and tried it, but it doesn't seem to be any faster... Unless I'm doing it wrong.

Here's what I tried:

10 SCREEN1:CLS
20 SPRITE$(0)=CHR$(&HD8)+CHR$(&H50)+CHR$(&HF8)+CHR$(&HA8)+CHR$(&H73)+CHR$(&H3E)+CHR$(&H7E)+CHR$(&HC7)
30 '** TEST1 PUTSPRITE 1
40 TIME=0:X=0:Y=99:A=10
50 X=X+1
60 PUTSPRITE0,(X,Y),15,0
70 IF X>254 AND A>0 THEN X=0:A=A-1
80 IF A=0 THEN GOTO 100
90 GOTO 50
100 PRINT TIME
110 '** TEST2 PUTSPRITE 2
120 TIME=0:X=0:Y=99:A=10
130 X=X+1
140 PUTSPRITE0,(X,Y)
150 IF X>254 AND A>0 THEN X=0:A=A-1
160 IF A=0 THEN GOTO 180
170 GOTO 130
180 PRINT TIME
190 '** TEST3 VPOKE 1
200 TIME=0:X=0:Y=99:A=10
210 X=X+1
220 VPOKE BASE(8),Y:VPOKE BASE(8)+1,X
230 IF X>254 AND A>0 THEN X=0:A=A-1
240 IF A=0 THEN GOTO 260
250 GOTO 210
260 PRINT TIME
270 '** TEST4 VPOKE 2
280 TIME=0:X=0:Y=99:A=10
290 X=X+1
300 VPOKE 6912,Y:VPOKE 6913,X
310 IF X>254 AND A>0 THEN X=0:A=A-1
320 IF A=0 THEN GOTO 340
330 GOTO 290
340 PRINT TIME

For test 1 "Putsprite 0,(X,Y),15,0" I got 2579
For test 2 "Putsprite 0,(X,Y)" I got 2356
For test 3 "Vpoke Base(8)" I got 3179
For test 4 "Vpoke 6912" I got 2403

It seems that Put Sprite minus the color and sprite definition is actually faster than Vpoke-ing the X and Y.

But perhaps one of you who are more experienced know how to Vpoke the sprite position better? I couldn't figure out how to combine both the X and Y coordinates into one Vpoke.

Login or register to post comments

By thegeps

Champion (442)

thegeps's picture

21-05-2020, 09:11

Well, doing putsprite with less parameter is like doing less vpokes (it updates few values). Basic is slow, anyway. Vpoke is faster only if you have to update only one param. If you have to change only x value then vpoke only in x vram location... because you can't vpoke 2 values at the same time. Infact if you have to move the sprite diagonally, using vpoke you'll see the sprite uodated first in one direction then in the other (depends wich coordinate you update first). Putsprite, instead, updates them at the same time. You can speed up a little by defining variables as integers at the beginning (defint startvariable-endvariable, removing spaces from the listing and doing some precalc in the first part of your program. Well, probably something can be done by tricking but you have to be really skilled to study how to do. I write a post on how to update vram using "print" instead a seties of vpoke, maybe it can help...

https://www.msx.org/forum/msx-talk/development/another-cool-...

By Dolphin101546015

Champion (269)

Dolphin101546015's picture

21-05-2020, 09:47

VDP data fill is more faster.

By Pineapple

Supporter (12)

Pineapple's picture

01-06-2020, 03:52

After further research, it turns out that vpoking the sprite coordinates is faster than putsprite... but only in x-basic, not regular basic.