How to peek into screen memory in basic?

I was playing around with the Julia set program from over in the Shed and
it occured to me that FOR loops plotting sequentially is painfully slow to watch; mand.bas
even assumes you want to save a bitmap at the end of the ordeal.

So I replaced them with a never ending DO loop and that just picks random points. (ie:
FOR X=0 to 319 becomes X=319*RND) The picocalc is fast enough that the image is recognizable in about 30 secs and somewhat entertaining to watch as the calculation/plotting drags on.

Of course, there’s nothing to stop it from hitting the same points over and over unless I keep track of what has been already plotted. (A 320x320 array is too big.) So can I PEEK into screen memory somehow and get what value is stored at the address corresponding to pixel X,Y?

1 Like

Instead of using random numbers, consider using a function that is guaranteed to hit every position only once. The simplest example I can think of is to have a simple counter going from 0 to 320*320, but you reverse the bits of the counter before converting it to a screen location. It’s a bit clunky to do the reversal, but I did find an implementation on TheBackShed (see the brv function):

To convert from the counter to a screen position, it’s simply y=count\320:x=count MOD 320. Note the backslash, that does an integer division.

I haven’t gotten back to mmbasic to try this out because I’ve been diverted by machikania (or is it phyllosoma? )basic: this compiled basic is so fast it really doesn’t matter whether you use for loops or some more creative way to make your iterating bug hop from pixel to pixel.