MOVSPR

From C64-Wiki
Jump to navigationJump to search
BASIC keyword
Keyword: MOVSPR
Abbreviation: M SHIFT+O
Type: Function
Token code: $fe $06 (254 6)
Handling routine
in BASIC ROM:
List of all BASIC keywords


Remark: This article describes the BASIC function MOVSPR in Commodore BASIC V7.0 or higher.

Type: Function
General Programming-Syntax: MOVSPR <sprite>, [ + | - ]<X>, [ + | - ]<Y> or MOVSPR <sprite>, <distance>;<angle> or MOVSPR <sprite>, <angle>#<speed>

The MOVSPR instruction sets the position or direction of movement and speed of a sprite. The command has 3 parameters, the first of which specifies the number of the affected sprite. This may be between 1 and 8, otherwise the error message 'ILLEGAL QUANTITY ERROR' is output. The meaning of the following pair of parameters depends on the separator between the two values:

Separator is a comma (,)
Set the position of the sprite in Cartesian coordinates, either absolute or relative to the current position.
  • <X>: Horizontal, scaled Coordinate; If a sign is placed in front of the value, the amount is added (if +) or subtracted (if -) from the current X position.
  • <Y>: Vertical, scaled coordinate; If a sign is placed in front of the value, the amount is added to (at +) or subtracted from (at -) the current Y-position.

Expressions for relative coordinates must be placed in brackets. Relative and absolute specifications may be mixed. Both parameters may lie in the value range from -65535 to +65535, otherwise an ?ILLEGAL QUANTITY ERROR is triggered. Expressions with a negative result are converted to a positive value on the interpreter side according to the formula 65536-<amount parameter>.

Separator is a semicolon (;)
Move the sprite at a specified angle by a specified distance relative to the current position.
  • <distance>: Scaled number of pixels by which the sprite is moved. Allowed range of values is -65535 to +65535. Results outside this range will trigger an ?ILLEGAL QUANTITY ERROR. Expressions with a negative result are converted to a positive value on the interpreter side using the formula 65536-<amount parameter>.
  • <angle: Angle in degrees clockwise in which the sprite is moved. Angle 0 stands for vertically upwards. Values above 359 are calculated modulo 360 (remainder when divided by 360). The result of the expression must lie in the value range from -65535 to +65535, otherwise an error ?ILLEGAL QUANTITY ERROR occurs. Expressions with a negative result are converted to a positive value according to special laws (see Examples). For example, an angle of -1 does not effectively result in 359°, but 255°.
Separator is a hash (#)
Setting the direction and speed of movement of the sprite.
  • <angle>: See above.
  • <speed>: Speed at which the sprite is moved. Allowed range of values is -65535 to +65535. Results outside this range will trigger an ?ILLEGAL QUANTITY ERROR. Expressions with a negative result are converted to a positive value on the interpreter side using the formula 65536-<amount parameter>. Only the first 4 bits of the amount are used, so that effectively 16 speed levels can be set:
    • 0: No movement.
    • 1: Minimum movement (pixel speed) is about 0.5 pixels per raster interrupt, i.e. about 25 pixels/s for PAL and about 30 pixels/s for NTSC.
    • 2 to 15: The minimum pixel speed multiplied by this value gives the effective one.
Sprite movement is only carried out for active (visible) sprites.

Another sprite commands in BASIC 7.0 are RSPCOLOR, RSPPOS, RSPRITE, SPRCOLOR, SPRITE, SPRDEF and SPRSAV, also BUMP, COLLISION, GSHAPE and SSHAPE.


Examples[edit | edit source]

MOVSPR 1,24,50

Positions the first sprite at the top left corner of the screen.

MOVSPR 2,24,+10

Positions the second sprite at the left edge and moves it vertically 10 pixels down at the same time.

[SCALE]] 1,320,400
MOVSPR 2,24,+10

As above, but the sprite is only moved by 5 pixels due to the scaling (independent of the active graphics mode).

DO: FOR W=0 TO 359 STEP 5: MOVSPR 1,2;W: NEXT: LOOP

The sprite moves endlessly in a circle.

MOVSPR 1,45#15

The sprite moves across the screen from bottom left to top right at maximum speed.


Negative angles

This programme displays two sprites, where one sprite gets the original negative angle, while the other sprite is moved with the corresponding, calculated positive angle for control. This way you can convince yourself of the correctness of the conversion. With the CRSR  keys the angle can be changed with left/right in steps of one and with up/down in steps of 100. After each change, the sprites move slightly away from the centre of the screen in the corresponding direction.

 100 GRAPHIC 1,1
 110 REM SPRITE ERZEUGEN (GROSSES X)
 120 DRAW 1, 0,0 TO 23,20
 121 DRAW 1, 0,20 TO 23,0
 130 S=1: REM SPRITE ORIGINAL
 131 P=2: REM SPRITE KONTROLLE
 140 SSHAPE A$, 0,0,23,20
 150 SPRSAV A$,S
 151 SPRSAV A$,P
 160 SPRITE S,1,8,0,0,0,0
 161 SPRITE P,1,11,0,0,0,0
 170 MOVSPR S,21,50
 171 MOVSPR P,21,50
1000 GRAPHIC 0
1010 PRINT "{CLR}"
1020 AO=-32500 : REM GRENZWERTNAEHE 
1030 V=4
1050 DO
1060 MOVSPR S,180,150
1061 MOVSPR P,180,150
1100 MOVSPR S,AO#V : REM ORIGINALPOSITION
1101 AA=AO
1102 IF AA>=0 GOTO 1109
1103 M=360:IF AO>-32513 THEN M=256 : REM MODUL
1104 D=(65536+AA)/M : REM WINKEL POSITIV MACHEN
1105 AA=INT((D-INT(D))*M+.5) : REM RESTWERT GEMAESS MODUL
1109 MOVSPR P,AA#V : REM UMGERECHNETE POSITION
1200 PRINT "{HOME}WINKEL: SPRITE1="AO;"{LEFT} SPRITE2="AA"{LEFT}  "
1280 DO
1290 GET A$:IF A$="" THEN LOOP
1300 IF A$="{LEFT}" AND AO>=-65535 THEN AO=AO-1
1301 IF A$="{RGHT}" AND AO<=355 THEN AO=AO+1: IF AO>=360 THEN AO=0
1302 IF A$="{UP}" AND AO>=-65535 THEN AO=AO-100
1303 IF A$="{DOWN}" AND AO<=355 THEN AO=AO+100: IF AO>=360 THEN AO=0
1390 LOOP UNTIL 1
1400 LOOP

The positive angle corresponding to a negative angle is not uniform over the entire negative value range.
For the angle WI (in brackets as hexadecimal value of the corresponding 2's complement representation):

  • -32512 ($8100) bis -1 ($FFFF): MOD(65536-ABS(WI),256)
  • -65535 ($FFFF) bis -32513 ($80FF): MOD(65536-ABS(WI),360)

assuming a modulo function MOD(<value>,<module>). This is reproduced in the programme with the help of the division and function INT().


BASIC V7.0 Commands

ABS | AND | APPEND | ASC | ATN | AUTO | BACKUP | BANK | BEGIN | BEND | BLOAD | BOOT | BOX | BSAVE | BUMP | CATALOG | CHAR | CHR$ | CIRCLE | CLOSE | CLR | CMD | COLLECT | COLLISION | COLOR | CONCAT | CONT | COPY | COS | DATA | DCLEAR | DCLOSE | DEC | DEF FN | DELETE | DIM | DIRECTORY | DLOAD | DO | DOPEN | DRAW | DS | DS$ | DSAVE | DVERIFY | EL | ELSE | END | ENVELOPE | ER | ERR$ | EXIT | EXP | FAST | FETCH | FILTER | FN | FOR | FRE | GET | GET# | GETKEY | GO64 | GOSUB | GOTO | GRAPHIC | GSHAPE | HEADER | HELP | HEX$ | IF | INPUT | INPUT# | INSTR | INT | JOY | KEY | LEFT$ | LEN | LET | LIST | LOAD | LOCATE | LOG | LOOP | MID$ | MONITOR | MOVSPR | NEW | NEXT | NOT | (OFF) | ON | OPEN | OR | PAINT | PEEK | PEN | (PI) | PLAY | POINTER | POKE | POS | POT | PRINT | PRINT USING | PRINT# | PUDEF | (QUIT) | RCLR | RDOT | READ | RECORD | REM | RENAME | RENUMBER | RESTORE | RESUME | RETURN | RGR | RIGHT$ | RND | RREG | RSPCOLOR | RSPPOS | RSPRITE | RUN | RWINDOW | SAVE | SCALE | SCNCLR | SCRATCH | SGN | SIN | SLEEP | SLOW | SOUND | SPC( | SPRCOLOR | SPRDEF | SPRITE | SPRSAV | SQR | SSHAPE | ST | STASH | STEP | STOP | STR$ | SWAP | SYS | TAB( | TAN | TEMPO | THEN | TI | TI$ | TO | TRAP | TROFF | TRON | USR | VAL | VERIFY | VOL | WAIT | WHILE | WINDOW | WIDTH | XOR