Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
You are not logged in - nap
CSDb User Forums


Forums > C64 Coding > tables, mod/and of 16-bit number
2016-02-04 15:27
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.
2016-02-04 16:39
Mixer

Registered: Apr 2008
Posts: 422
Some 2 screens wide char image or colordata, for plasma or rotozoomer perhaps? :)

Could you code the loops with simple comparison instead of modulo?
2016-02-04 16:47
Oswald

Registered: Apr 2002
Posts: 5017
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!
2016-02-04 17:03
ChristopherJam

Registered: Aug 2004
Posts: 1378
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..
2016-02-04 17:05
ChristopherJam

Registered: Aug 2004
Posts: 1378
(key identity: (a+b)%c = ((a%c)+(b%c))%c )
2016-02-04 17:05
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.
2016-02-04 17:10
chatGPZ

Registered: Dec 2001
Posts: 11114
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
2016-02-04 17:15
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.
RefreshSubscribe to this thread:

You need to be logged in to post in the forum.

Search the forum:
Search   for   in  
All times are CET.
Search CSDb
Advanced
Users Online
Twoflower/ΤRIΛD
macx
t0m3000/ibex-crew
Airwolf/F4CG
Guests online: 127
Top Demos
1 Next Level  (9.8)
2 Mojo  (9.7)
3 Coma Light 13  (9.7)
4 Edge of Disgrace  (9.6)
5 Comaland 100%  (9.6)
6 No Bounds  (9.6)
7 Uncensored  (9.6)
8 Wonderland XIV  (9.6)
9 Bromance  (9.6)
10 Memento Mori  (9.6)
Top onefile Demos
1 It's More Fun to Com..  (9.7)
2 Party Elk 2  (9.7)
3 Cubic Dream  (9.6)
4 Copper Booze  (9.5)
5 TRSAC, Gabber & Pebe..  (9.5)
6 Rainbow Connection  (9.5)
7 Onscreen 5k  (9.5)
8 Wafer Demo  (9.5)
9 Dawnfall V1.1  (9.5)
10 Quadrants  (9.5)
Top Groups
1 Oxyron  (9.3)
2 Nostalgia  (9.3)
3 Booze Design  (9.3)
4 Censor Design  (9.3)
5 Crest  (9.3)
Top Musicians
1 Rob Hubbard  (9.7)
2 Jeroen Tel  (9.6)
3 Stinsen  (9.6)
4 Mutetus  (9.6)
5 Linus  (9.6)

Home - Disclaimer
Copyright © No Name 2001-2024
Page generated in: 0.061 sec.