playing with copies (was:Re: [stella] discovering the tricks(maybe))

Subject: playing with copies (was:Re: [stella] discovering the tricks(maybe))
From: Piero Cavina <p.cavina@xxxxxxxxxxxxx>
Date: Thu, 6 Mar 1997 22:42:07 +0100
At 13:00 -0700 6-03-1997, Nick S Bensema wrote:

>>
>>I suspect that a common technique for putting more objects on the screen
>>must be based on the multiple copies feature of Atari 2600 sprites.
>>
>>Think about Activision Plaque Attack enemies (or a lot of other shooters),
>>where you have groups of three aliens:
>>
>>  X  X  X
>
>Space Invaders, and I think Galaxian, used groups of six, or rather,
>two groups of three.

uh, Galaxian maybe more that 6 if I remember correctly (creeps...)

>
>This is a perfect opportunity to make your life simpler through tables.

yeah!

>It would probably take 16 bytes; 14 if you take it as given in your
>code that 000 means nothing shows up... very wise, since there is no
>NUSIZ register for "nothing shows up".

hmm, not really, as 000 means one copy only (see stella reference guide).
we need a way to say that a sprite is missing. (see below)

>>is needed, as said above. Or maybe you might use the other sprite to draw
>>the exploding alien. Or just let them disappear... :-)
>
>Or the missile.  Of course, Space Invaders did id the hard way, and I
>suggest you check the source code to figure out how they pulled
>that one off.

thanks no, I've enough for this week and there's Bob code to study :-)

Here we go: a routine to handle collisions between a sprite in multiple
copies and a missile.
The result will be a sprite with the appropriate configuration shifted in
the correct position.

; WARNING: UNTESTED CODE!!
;
;MXPOS: missile X position. Missile must have width=1 clock.
;SXPOS: sprite position. Sprite must be in "med" mode, note that the second
copy position will be
;SXPOS+16 and the third SXPOS+32.

;SCONF: index to sprite configuration, 5 possible values (see table below).
$4 means that the sprite ;does not exist!
;
;        NUSIZ       sprite
;SCONF   register    mode
;
;  0     xxxxx000    X....
;  1     xxxxx001    X.X..
;  2     xxxxx010    X...X
;  3     xxxxx011    X X X
;
;  4     --------    .....


;we suppose that a collision between the sprite and a missile has been
detected.

;1 - find out which copy has been hit.
;hint: MXPOS>=SXPOS, as the copies as drawn left to right from the first @
SXPOS

 LDA MXPOS
 SEC
 SBC SXPOS
 LSR A
 LSR A
 LSR A
 LSR A ; divide by 16 so that A=0..2, index to the hit copy

;2 - find the index to the table values for the new configuration/offset:
; X = index to hit copy * 4 + index to sprite configuration

 ASL A
 ASL A ; whoops! that's stupid after four LSR, I've left all otherwise the
code might be obscure

 CLC
 ADC SCONF
 TAX

;3 - get the new configuration

 LDA newconftable,X
 BMI error ; this situation is impossible,  don't do anything
 STA SCONF

;4 - get the offset and add it to get the new position

 CLC
 LDA SXPOS
 ADC offsettable,X
 STA SXPOS

error:
 RTS

;done. will it work?


newconftable byte $4,  $0,  $0,  $1
             byte $FF, $0,  $FF, $2
             byte $FF, $FF, $0,  $1

offsettable  byte $0,  $10, $20, $10
             byte $FF, $0,  $FF, $0
             byte $FF, $FF, $0,  $0

; $FF means "ERROR" - a table value that should never be accessed.



; example
;
;SCONF=3   "X X X"
;SXPOS=120
;MXPOS=138
;
;MXPOS-SXPOS=18
;[18/16] = 1  so the second copy was hit.
;
;X = 1*4+3 = 7
;
;The indexed value of sconftable is 2 = "X   X", now the second copy is
missing.
;The indexed value of offsettable is 0, thus the X position doesn't change.


Ciao,
 P.








--
To unsubscribe, send the word UNSUBSCRIBE in the body of a message to
stella-request@xxxxxxxxxxx

Current Thread