Videopac / Odyssey2 forum
May 06, 2021, 03:00:35 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Join Rafael's Haunted Woods contest and win a copy of the game!
 
   Home   arcade Help Login Register links videopac.nl  
Pages: [1]   Go Down
  Print  
Author Topic: Having trouble with randomness  (Read 5184 times)
Chris!
Give this man a Jopac!
******
Posts: 1201



WWW
« on: May 28, 2016, 01:24:42 PM »

Suppose I want to make the color of a sprite random. Why won't this work?
Code:
mov r1,#006h
mov a,t
anl a,#0ffh  
add a,#0
movx @r1,a

mov r1,#006h
mov a,@r1
jb1 align_sprite

jmp ssss


align_sprite

mov r0,#006h
movx a,@r0
add a,#002h
movx @r0,a

ssss
mov r1,#006h
mov a,@r1
jb2 make_small

jmp otherstuff

make_small

mov r0,#006h
movx a,@r0
add a,#004h
movx @r0,a


otherstuff
        ;the rest of the code goes here...
Since bit one makes the even number of the sprite jut out (which I still don't understand why that would be useful), and bit 2 makes the sprite big (which I also don't want), this doesn't seem to do any good. What am I doing wrong here?
Logged

All my Odyssey2 projects, now in one place!
http://www.atari2600land.com/odyssey2.html
LD
Pedit5
Attacked the Timelord
*
Posts: 141



« Reply #1 on: May 28, 2016, 11:34:32 PM »

I see you're setting the same register over and over.
Once you set the register : mov R1,#006h
you don't need to set it again as R1 will keep with 006h address.

 I don't understand your code, but to set a random color I would use the clock register :

mov R1,#006h ;spr ctrl
mov R0,#03Eh ;int. RAM - clock
mov a,@R0
anl a,#0F8h    ;only the color bits (3-5)
mov R2,a      ;R2 = Clock value
movx a,@R1
anl a,#3       ;keep bit 0- 2 unchanged
ora a,R2
movx @R1,a
Logged
Chris!
Give this man a Jopac!
******
Posts: 1201



WWW
« Reply #2 on: May 29, 2016, 04:29:05 PM »

It doesn't like the ora opcode. I changed it to orl and the color kept being gray over and over again.
Logged

All my Odyssey2 projects, now in one place!
http://www.atari2600land.com/odyssey2.html
LD
Pedit5
Attacked the Timelord
*
Posts: 141



« Reply #3 on: May 30, 2016, 06:39:05 PM »

Yes, it is orl, sorry.

The time is not random, if you call the code at same time span, the color will be the same.
Anyway now I've tested the code and come with something simple:

Code:
mov R1,#002h ;spr ctrl
mov R0,#03Eh ;int. RAM - clock
mov a,@R0
anl a,#0F8h    ;only the color bits (3-5)
;rl a
movx @R1,a

This overrides the first bits BTW. Enable "rl a" for a faster effect. If you call the code every frame, the color blinks.
Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!