Videopac / Odyssey2 forum

Programming the Videopac / Odyssey2 => Programming => Topic started by: Chris! on November 14, 2018, 02:57:48 PM



Title: Sprite colors
Post by: Chris! on November 14, 2018, 02:57:48 PM
So I want a particular sprite, sprite 1, to get a random color. Right now, I have this code:
Code:
mov r1,#006h
mov a,t
anl a,#0F8h   
movx @r1,a
Which does a good job, but it only selects from half the available colors (0, 2, 4, and 6). I want to know why this is happening and if there's a way to make the program "choose" from all 8 colors instead of just 4.


Title: Re: Sprite colors
Post by: Sdw on November 14, 2018, 03:59:13 PM
It seems like you are getting your value from a timer, right?
I'd say that some kind of pseudo-random function would be better suited for this.


Title: Re: Sprite colors
Post by: TedFoolery on November 14, 2018, 04:40:42 PM
Yes, a random function generator would be ideal, but for the sake of speed or byte size you could also try using a different group of bits from the timer. This uses the first three bits and moves them to the correct position:
Code:
mov r1,#006h
mov a,t
anl a,#03h
rl a
rl a
rl a
movx @r1,a

or use the last three bits:
Code:
mov r1,#006h
mov a,t
anl a,#0e0h
rr a
movx @r1,a


Title: Re: Sprite colors
Post by: Chris! on November 14, 2018, 05:02:18 PM
I was fiddling around with the code a little and found this gives great results, and it's random every time you turn the Odyssey2 on:
Code:
mov r0,#lettercolor
movx a,@r0
add a,#8
movx @r0,a

mov R1,#lettercolor
mov R0,#03Eh
mov a,t
anl a,#0F8h   
movx @R1,a
I put this in a call routine when the sprite color needs to be changed.
The "lettercolor" is actually a sprite. The sprites are letters. I got bored of the standard ones so I made a couple of new ones. They're lowercase this time. I thought the Odyssey 2 had an RNG, the t (for timer) function. Or am I wrong?