## [stella] Horizontal Positioning of sprites

 Subject: [stella] Horizontal Positioning of sprites From: "Andrew Davie" Date: Mon, 12 Feb 2001 01:47:20 +1100
```I had a bit of fun with the horizontal positioning.  I'm sure everyone
stumbles on this one.... thank goodness for the list :)  The following
routine works for me - it correctly positions (relative to my background)
two sprites described by pixel position "PlayerX".  Bin attached shows it in
action.  Can anyone improve the initial "divide by 15" for me?  I was
thinking something like a divide by 16, and then an adjust...  there's a
definite pattern.  How are others doing this calculation efficiently (that
is, converting pixel pos to loop counters).

Anyway, here's my current horizontal position routine (which works)...

----------------------------------------------
PositionSprites

; Set the horizontal position of the two sprites, based upon their
coordinates

ldx #1
PosSP

ldy #2                          ; fudged start offset

; Count 15-pixel loops
sec
lda PlayerX,x                   ; absolute X pixel
CountX  sbc #15
iny
bcs CountX

; Use remainder for fine adjustment
eor #15
sbc #7                          ; -8 to +7
asl
asl
asl
asl
sta HMCLR                       ; clear any previous movement
sta HMP0,x                      ; fine movement

sta WSYNC

Jiggle  dey
bpl Jiggle
nop

sta RESP0,x
sta WSYNC
sta HMOVE

dex
bpl PosSP

; Now fine-adjust to make it sit nicely on my cubes...

jsr Ret
jsr Ret                         ; at least... 24 cycle mystery time

lda #%01000000
sta HMP0
sta HMP1
sta WSYNC
sta HMOVE

Ret     rts

----------------------------------------------

This uses, essentially, 3 scan lines.... is there a better way?
Thanks
A

--
_  _  _| _ _        _| _    * _                               _  ,
(_|| )(_|( (/_\/\/  (_|(_|\/(_(/_                           ,~' L_|\
,-'        \
see my Museum of Soviet Calculators at                  (            \
http://www.taswegian.com/MOSCOW/soviet.html              \    __     /
L,~'  "\__/
@--> v

-
Archives (includes files) at http://www.biglist.com/lists/stella/archives/
Unsub & more at http://www.biglist.com/lists/stella/

```