## [stella] Qb: Horizontal Positioning of sprites

 Subject: [stella] Qb: Horizontal Positioning of sprites From: "Andrew Davie" Date: Mon, 12 Feb 2001 01:50:17 +1100
```I had a bit of fun with the horizontal positioning.  I'm sure everyone
stumbles on this one.... 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

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

```

Attachment: push.bin
Description: Binary data