TAD_uk wrote:Gunstick wrote:also note that bresenham routine (that's what we are talking about here) for polygons or lines is also very useful to play modfiles. Maybe addx was first used for music players. That's where I first heard about it.

Thats where I used to use the ADDX trick to step through the sample at different rates.

Using 16.16 fixed point maths to store the position (offset.part = 32 bits) and step (integer.fraction = 32 bits) a 'normal' 16.16 fixed point add.l would be like this:

d0 = (offset.0) << 16 + (part)

d4 = (integer.0) << 16 + (fraction)

add.l d4, d0

but you'll need a swap to access the top 31..16 bits of d0 (the offset.0 value)

swap d0 ; swap offset <--> part

move.w d0, (a0)+ ; store the offset value

swap d0 ; restore d0 value

If you are careful you can also chain multiple ADDX together for more than 1 polygon edge OR sample voice step.

(example from my memory, so hopefully correct)

move.w d0-d3, (a0)+ ; store the integer offsets d0,d1,d2,d3

addx.l d4, d0

addx.l d5, d1

addx.l d6, d2

addx.l d7, d3

the set up of the d4 to d7 register use bits 31-16 as fractional step and bits 15-0 as the integer step BUT not in the normal way !!

If you set up your registers something like this:-

d0 = (part.1) << 16 + (offset.0)

d1 = (part.2) << 16 + (offset.1)

d2 = (part.3) << 16 + (offset.2)

d3 = (part.0) << 16 + (offset.3)

and STEP value like this:-

d4 = (fraction.1) << 16 + (integer.0)

d5 = (fraction.2) << 16 + (integer.1)

d6 = (fraction.3) << 16 + (integer.2)

d7 = (fraction.0) << 16 + (integer.3)

NOTE: The part.0 ... part.3 and fraction.0 ... 3 are 'out of sync' so one ADDX will increment both integer.X value as well as fraction.x+1 value.

Hope this all makes senses.

Cheers

TAD_uk

I have posted a new topic regarding the above: http://www.atari-forum.com/viewtopic.php?f=68&t=20168

If anyone can shed a bit more light on how this works I would be very grateful.