Random Noise Generator

Basic and Machine Language

Moderator: Moderators

Post Reply
javelinatina
Vic 20 Newbie
Posts: 4
Joined: Tue Mar 26, 2019 8:00 am
Location: Bham, AL

Random Noise Generator

Post by javelinatina »

So I tried out a one line random noise generator program based off one I know about for the C64. Goes like so:

10 POKE 36874+RND(1)*25,RND(1)*256 : GOTO 10

But when I run this the VIC-20 (right now just an emulator for experimenting, I should say) the screen explodes into random color madness, and while this is delightful, I would like a certain degree of control over it. How would I prevent this? Also, if I didn't want to prevent this, how would I be able to stop it and get back to programming? When the ball gets rolling on the above program and I hit STOP it leaves the screen as a blob of color and characters.

Thanks!
User avatar
Kweepa
Vic 20 Scientist
Posts: 1315
Joined: Fri Jan 04, 2008 5:11 pm
Location: Austin, Texas
Occupation: Game maker

Re: Random Noise Generator

Post by Kweepa »

Well, geez, you are poking garbage into the vic registers, so it's expected that the vic goes crazy.
To get it back you can copy the original state, and replace it once done.
If you break into the program you should be able to type goto30 to run the recovery code.

10 dimv(26):fori=0to25:v(i)=peek(36874+i):next
20 fori=1to200:poke36874+rnd(1)*25,rnd(1)*256:next
30 fori=0to25:poke36874+i,v(i):next
javelinatina
Vic 20 Newbie
Posts: 4
Joined: Tue Mar 26, 2019 8:00 am
Location: Bham, AL

Re: Random Noise Generator

Post by javelinatina »

Hey thanks! Is there a way to do this without any effect on the screen?
User avatar
Stormcrow
Vic 20 Enthusiast
Posts: 177
Joined: Mon Dec 24, 2012 9:46 pm
Website: http://trimboli.name
Location: Ronkonkoma, NY

Re: Random Noise Generator

Post by Stormcrow »

You just want random white noise?

Code: Select all

10 POKE 36878,15
20 POKE 36877,RND(0)*128+128
30 GOTO 20
40 POKE 36878,0
50 POKE 36877,0
When you're done listening, press STOP then RUN 40 to make the noise go away.

36877 is the white noise register (values 128–255), and 36878 is the volume (values 0–15).
User avatar
Stormcrow
Vic 20 Enthusiast
Posts: 177
Joined: Mon Dec 24, 2012 9:46 pm
Website: http://trimboli.name
Location: Ronkonkoma, NY

Re: Random Noise Generator

Post by Stormcrow »

Or even more noise:

Code: Select all

10 POKE 36878,15
20 POKE 36874+RND(0)*4,128+RND(0)*128
30 GOTO 20
40 FOR I=36874 TO 36878
50 POKE I,0
60 NEXT
javelinatina
Vic 20 Newbie
Posts: 4
Joined: Tue Mar 26, 2019 8:00 am
Location: Bham, AL

Re: Random Noise Generator

Post by javelinatina »

That second one is exactly what I was looking for! Very cool! Thanks a lot!
Post Reply