Classic Computer Magazine Archive ANTIC VOL. 3, NO. 5 / SEPTEMBER 1984

Assembly language

ROTATE YOUR PLAYER

Special effects with machine language

By LARRY PARKER

SYNOPSIS
This article demonstrates some of machine language's special capabilities.  Listing 1 requires BASIC; listing 2 requires the Assembler Editor cartridge.  The second listing is a routine to be called from BASIC - it does not run on its own.  Both programs run on all Atari computers.

Player/Missile graphics are easy to use.  Their flexibility and versatility allow you to experiment and create interesting effects.  The following program gives the effect of a ball in P/M rolling right or left.
   Type in and SAVE the first listing.  RUNning the program shows you a smiling face which you can move with the joystick.  As the face moves left or right, it appears to be rolling.
   The key to this effect is the machine language program stored in ROT$.  To call it, a USR command must be executed as follows:

A=USR(ML,ADR,NUM,DIR)

where ML is the address of the routine, ADR is the address to rotate, NUM is the number of bytes to rotate, and DIR is the direction to rotate (O = left, I = right).  The machine language routine itself is quite simple.  Its source code is in Listing two and is documented.
Use the following steps to produce a rolling effect:
1. Shift every bit in each byte you want to rotate;
2. Check the carry bit;
3. If the carry bit is a 1, set bit 7 if shifting right, or set bit 0 if shifting left.
   These steps cause each bit to move left or right and wrap around.
   Note that in the USR call (LINE 450), the second parameter is offset by 2 (P0+2), so the top two bytes of the face are not rotated.  If they are, the face will not appear to roll.  To see this, change the + 2 in LINE 450 to a + 0 and RUN the program.  The result shows that the routine has some restrictions.  In order to completely produce the illusion of rotation, the portion to rotate must be eight bits wide.
   This is just one of the many special results produced by Player/Missile graphics.  After experimenting with them, you can produce your own special effects.

Larry Parker entered the College of Engineering at the University of Michigan last year.  In the past several years, he has written and sold several dozen programs in BASIC, using machine language routines.

Listing 1: ROTATE.BAS Download

Listing 2: ROTATE.ASM Download / View

Listing 1

10 REM ANTIC MAGAZINE
20 REM PLAYER MISSILE ROTATOR
30 REM BY LARRY PARKER
40 REM
70 REM READ MACHINE LANGUAGE DATA
80 REM INTO ROT$
100 DIM ROT$(60)
110 FOR I=1 TO 57:READ A:ROT$(I,I)=CHR
$(A) NEXT I
120 DATA 104,104,133,204,104,133,203
130 DATA 104,104,133,205,104,104,133
140 DATA 206,160,0,24,165,206,208
150 DATA 11,177,203,10,144,14,24
160 DATA 105,1,24,144,8,177,203
170 DATA 74,144,3,24,105,128,145
180 DATA 203,200,196,205,208,225,96
200 REM PLAYER MISSILE SETUP
220 RAM=PEEK(106):POKE 106,RAM-8:GRAPH
ICS 0:POKE 752,1:?
230 U=PEEK(106):X=120
240 POKE 704,14
250 POKE 54279,U
260 PM=256*U
270 FOR I=PM+512 TO PM+640:POKE I,0:NE
XT I
280 P0=PM+512+80
290 RESTORE 360
300 FOR I=P0 TO P0+7
310 READ A
320 POKE I,A
330 NEXT I
340 POKE 559,46:POKE 53277,3
350 POKE 53248,X
360 DATA 60,126,219,255,189,195,126,60
380 REM ROTATE PLAYER
400 S=STICK(0)
410 IF S=7 THEN DIR=1:X=X+1:GOTO 440
420 IF S=ll THEN DIR=0:X=X-1:GOTO 440
430 GOTO 400
440 POKE 53248,X
450 A=USR(ADR(ROT$),P0+2,4,DIR)
460 FOR D=1 TO 3:NEXT D
470 GOTO 400
 

Listing 2

0   *=$600
20 ;
30 ; -------------------------------
40 ; A=USR(ML,ADR,# BYTES,DIRECTION)
50 ;
60 ; ROTATES DATA LEFT OR RIGHT
70 ;
80 ; -------------------------------
90 ;
0100 ADR   = $CB
0110 BYTES = $CD
0120 DIR   = $CE
0130  PLA               ;IGNORE
0140  PLA               ;GET HI BYTE OF
 ADDRESS
0150  STA ADR+1
0160  PLA              ;GET LO BYTE OF
ADDRESS
0170  STA ADR
0180  PLA              ;IGNORE
0190  PLA              ;GET NUMBER OF B
YTES
0200  STA BYTES
0210  PLA              ;IGNORE
0220  PLA              ;GET DIRECTION
0230  STA DIR
0240 ;
0250  LDY #0
0260 LOOP CLC
0270  LDA DIR
0280  BNE RIGHT        ;RIGHT IF A 1
0290 ;
0300 LEFT LDA (ADR),Y
0310  ASL A            ;SHIFT LEFT
0320  BCC STORE        ;NO CARRY BIT
0330  CLC
0340  ADC #1           ;SET BIT 0
0350  CLC
0360  BCC STORE
0370 RIGHT LDA (ADR),Y
0380  LSR A            ;SHIFT RIGHT
0390  BCC STORE        ;NO CARRY BIT
0400  CLC
0410  ADC #128         ;SET BIT 7
0420 STORE STA (ADR),Y
0430  INY
0440  CPY BYTES        ;DONE?
0450  BNE LOOP         ;NO
0460  RTS              ;YES- RETURN TO
BASIC