| |
Rudi Account closed
Registered: May 2010 Posts: 125 |
tables, mod/and of 16-bit number
Hi,
I found some months old C-code that I wish to translate into 6510 asm.
This is what I need:
(an element in this case is a byte)
- an lookup-table of 4160 elements
- another lookup-table of 16 elements.
i also have a mod40 table of 1000 elements.
- a for loop of 4160 elements in size
some logic operations are done in the for loop.
one of these operations needs to take the modulus of 4096, or AND-operator on 0xfff.
doing AND for a byte is easy, just do AND #$ff etc. but this is a 16-bit number.
i need to take only the AND #$f of the hi-byte right?
and then branch if zero or negative status flag is set?
the number mod'ed is 16-bit index to 4160 array, any tricks for this or just straightforward?
another option is to make the mod-table of 4160 elements instead of doing the above (like the mod40 table).
it'l probably be faster, but the downside it takes alot of RAM.
the modtable logic looks like this:
if (mod40table[i] == 39) x += 80;
the rest of the logic is quite easy, just requires some setbits and addition of 16-bit numbers. |
|
| |
Mixer
Registered: Apr 2008 Posts: 452 |
Some 2 screens wide char image or colordata, for plasma or rotozoomer perhaps? :)
Could you code the loops with simple comparison instead of modulo? |
| |
Oswald
Registered: Apr 2002 Posts: 5094 |
if its a demo effect it should be recoded so tables are max 8 bit. there is always a way. what you describe sounds overcoded.
anyway 16 bit number anding: you need to and both lo/hi and check both for 0, only then you can be sure all bits are 0 after the 16 bit and operation! |
| |
ChristopherJam
Registered: Aug 2004 Posts: 1409 |
If i is just looping from 0 to 4159, then as Mixer said, I'd go with a simple timer that resets ever 40.
However, if i is random, then you have another puzzle.
I gather you want to compare (i%4096)%40 with 39?
In which case, you can break that up into ( (i&0xf00)%40+(i&0xff)%40 ) %40
as the contributions from the hex digits is additive.
that just becomes a pair of table lookups, (T1[hi(i)] + T2[lo(i)])%40
Now, the two table lookups will sum at most 78,
so the final modulo 40 is not required, as sums in the range 40..78 mod 40 will never equal 39
clc
ldx i+1
lda t1,x
ldx i
adc t2,x
cmp#39
bne dont_add_80
t1=[((x%16)*256)%40 for x in range(17)]
t2=[( x )%40 for x in range(256)]
that said, you also mention a 1000 element table for mod 40, so I'm unclear as to your input range.. |
| |
ChristopherJam
Registered: Aug 2004 Posts: 1409 |
(key identity: (a+b)%c = ((a%c)+(b%c))%c ) |
| |
Rudi Account closed
Registered: May 2010 Posts: 125 |
Quote: Some 2 screens wide char image or colordata, for plasma or rotozoomer perhaps? :)
Could you code the loops with simple comparison instead of modulo?
the effect is similar to Game of Life, but the logic is different.
yes, its 80x50 cells. so basically use the standard block-chars for it. so it has to have 16 possible combinations per char in screenmem.
Oswald:
ill try figure that out. 8-bits are definitively easier than 16! the problem is the edges. it basically has to be a "torus", a periodic boundary that is. |
| |
chatGPZ
Registered: Dec 2001 Posts: 11386 |
Quote:
the modtable logic looks like this:
if (mod40table == 39) x += 80;
as said on IRC the other day... generate the table like this:
table[i] = ((i%40)==39) ? 80 : 0;
... then the above becomes simple addition:
x+=table[i]
... which is much faster than comparing and adding conditionally |
| |
Rudi Account closed
Registered: May 2010 Posts: 125 |
Quote: Quote:
the modtable logic looks like this:
if (mod40table == 39) x += 80;
as said on IRC the other day... generate the table like this:
table[i] = ((i%40)==39) ? 80 : 0;
... then the above becomes simple addition:
x+=table[i]
... which is much faster than comparing and adding conditionally
ah. ofc. why didnt i see that. i was too tired yesterday. now it works. |