Re: [stella] Delightful horizontal position code...

Subject: Re: [stella] Delightful horizontal position code...
From: "Andrew Davie" <adavie@xxxxxxxxxxxxx>
Date: Mon, 12 Feb 2001 20:27:44 +1100
> I'm using a different constant timed routine, which i
> found somewhere. I think it's an old standard routine
> which is based on the same idea that you have
> reinvented again.

Thanks for that one, Thomas.  I *did* actually ask first if anybody had such
an algorithm/code, but it seems I'm working quicker than people can get me
replies :)  In any case I'm quite delighted to see just how close those
sections of code actually are.   I'm sure there is very little that one can
do, these days, on the 2600... .that hasn't been tackled before :)

It was still fun - even if not quite the most efficient version :)

Cheers
A


----- Original Message -----
From: "Thomas Jentzsch" <tjentzsch@xxxxxx>
To: <stella@xxxxxxxxxxx>
Sent: Monday, February 12, 2001 7:15 PM
Subject: Re: [stella] Delightful horizontal position code...


> At 12.02.2001, 07:44, Andrew Davie wrote:
> > I did a bit of work on my sprite horizontal position code, and am quite
> > delighted with this contribution... it figures out and positions two
sprites
> > horizontally, based on their pixel position (X) held in PlayerX[2].  I
> > analysed the differences between dividing by 16 (4 shifts) and dividing
by
> > 15 (repeated subtractions) and wrote a CONSTANT-TIME algorithm to do the
> > adjustment.  That is, rather than multiple subtractions, this code does
some
> > shifting and additions (constant time) to figure the player positions.
It
> > works, and is quickish - but best of all... constant execution time!
>
> > This is the sort of trick code I like doing :)
>
> I'm using a different constant timed routine, which i
> found somewhere. I think it's an old standard routine
> which is based on the same idea that you have
> reinvented again.
> (i changed the code a little bit to get minimum average
> timing, the worst case time is slightly increased)
>
> CalcXPos:
>     tay                         ; 2
>     lsr                         ; 2
>     lsr                         ; 2
>     lsr                         ; 2
>     lsr                         ; 2
>     sta     tmpVar              ; 3 = 13
>     tya                         ; 2
>     and     #$0f                ; 2
>     clc                         ; 2
>     adc     tmpVar              ; 3
>     cmp     #$0f                ; 2
>     bcc     .nextPos            ; 2³
>     sbc     #$0f                ; 2
>     inc     tmpVar              ; 5
> .nextPos:                       ;   = 14/20
>     eor     #%00000111          ; 2
>     asl                         ; 2
>     asl                         ; 2
>     asl                         ; 2
>     asl                         ; 2
>     ldy     tmpVar              ; 3
>     rts                         ; 6 = 19
>
>     ...
>
>     lda   xpos
>     jsr   CalcXPos
>     sta   WSYNC
>     sta   HMPx
>     ...                         ; some extra cycles needed here
> .wait:
>     dey
>     bpl   .wait
>     sta   RESPx
>     sta   WSYNC
>     sta   HMOVE
>
> I think it's a little bit more compact than your approach.
>
> Have fun!
> Thomas
> _______________________________________________________
> Thomas Jentzsch         | *** Every bit is sacred ! ***
> tjentzsch at web dot de |
>
>
>
> -
> Archives (includes files) at http://www.biglist.com/lists/stella/archives/
> Unsub & more at http://www.biglist.com/lists/stella/
>

--
 _  _  _| _ _        _| _    * _                               _  ,
(_|| )(_|( (/_\/\/  (_|(_|\/(_(/_                           ,~' 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/

Current Thread