Re: [stella] MultiSpriteDemo update (source+binary)

Subject: Re: [stella] MultiSpriteDemo update (source+binary)
From: emooney@xxxxxxxxxxxxxxxx (Erik Mooney)
Date: Sat, 05 Apr 1997 21:35:08 GMT
>; Straight from "Air sea battle", here's the routine
>; to convert from standard X positions to FC positions.
>; Could a good man explain me how it works?

It's tricky, but I think I've figured it out.  First, it makes the X-coord
zero if it's out of range (not between zero and 159.)  Then, it takes the
fine and coarse values in base-16 of the number (which are simply the high
and low nibbles).  To convert base-16 FC to base-15 FC, you add the F and C
values and put that in F; if that's >15, you subtract 15 from F and add one
to C. (Trust me, this works mathematically, though it's difficult to
explain.)  The rest of the code cleans up and puts the F and C values
together into one register.

>CNV:   STA    TEMP+1
>       BPL    LF34B
>       CMP    #$9E
>       BCC    LF34B
>       LDA    #$00
>       STA    TEMP+1
>LF34B:
here, the X-coordinate has been converted to zero if it was previously out
of range, and it's in both A and Temp+1.

>LSR
>       LSR
>       LSR
>       LSR
>       TAY
Y=A/16 (Xcoord/16).  Y = C in base-16.

>       LDA    TEMP+1
>       AND    #$0F
A=A mod 16 (Xcoord mod 16). A = F in base-16.

>       STY    TEMP+1
>       CLC
>       ADC    TEMP+1

A = (Xcoord/16 + Xcoord mod 16)
A now has the sum of the fine/coarse base-16 coordinates.

>       CMP    #$0F
>       BCC    LF360
>       SBC    #$0F
>       INY
>LF360:

The key section.  The coarse coordinate is now in Y, and A has the fine
coordinate (zero to 14.)  Y*15+A should equal the original X-coord (try
tracing through the code with a few different values.)

>CMP    #$08
>       EOR    #$0F
>       BCS    LF369
>       ADC    #$01
>       DEY
>LF369: INY

This converts the 0 to 14 setup of the fine coordinates to the +7 to -7
setup that HMxx and HMOVE want.  I think we increment Y here because we
want to use a DEY/BNE loop, so zero iterations of the loop means Y should
equal 1 (?)

>       ASL
>       ASL
>       ASL
>       ASL
>       STA    TEMP+1
>       TYA
>       ORA    TEMP+1

And this just puts the fine and coarse together into the same 8-bit
register.

>       RTS

Obviously, the whole thing would be 12 cycles faster as a macro instead of
as a subroutine if you can spare the space and only use it a few times.

--
Archives available at http://www.biglist.com/lists/stella/archives/
E-mail UNSUBSCRIBE in the body to stella-request@xxxxxxxxxxx to be removed.

Current Thread