Randomize and rotate left.

The place for codemasters or beginners to talk about programming any language for the Spectrum.
Nomad
Manic Miner
Posts: 600
Joined: Thu Dec 28, 2017 12:38 pm

Re: Randomize and rotate left.

Post by Nomad »

Seven.FFF wrote: Tue Jan 09, 2018 5:22 pm Perhaps even more useful. The "1" first parameter of zeusprint() prints r every time, and the "r=127" condition only breaks when r is 127. It's effectively two separate breakpoint expressions chained together. The value of the last chained expression decides whether to break.

Code: Select all

zeusdatabreakpoint 1, "zeusprint(1, r), r=127", $
Thanks, it worked fine. As you say R is just an linear incrementing output. hmmm.. well its good to know.

lol zeus should really play this at these moments

Image
:lol: ok... i'll get my coat.
User avatar
lister_of_smeg
Microbot
Posts: 145
Joined: Thu Nov 16, 2017 1:44 pm

Re: Randomize and rotate left.

Post by lister_of_smeg »

For the high byte:

Code: Select all

          ld   b, 2 
loop:     sub  85
          jr   c, loop_end
          djnz loop
loop_end:
This slightly favours the attributes for the top third of the screen, but it's fast and small.
AndyC
Dynamite Dan
Posts: 1388
Joined: Mon Nov 13, 2017 5:12 am

Re: Randomize and rotate left.

Post by AndyC »

Technically R is 8-bit, but only the bottom 7 bits increment, so it will either count 0-127 or 128-255 depending upon what bit 7 is set to. As said, it's not good if you need a steady stream of random data but if you just need something simple and not very often (say choosing one of a few starting rooms ala Knight Lore) then it can be less fuss than a real random number. And, as you can see from the discussion here, getting a random number in a specific range can be a PITA if you need a nice even distribution!
Nomad
Manic Miner
Posts: 600
Joined: Thu Dec 28, 2017 12:38 pm

Re: Randomize and rotate left.

Post by Nomad »

Muhahahahahaha my potato brain was working much better this morning.

(still not enough to figure out how to get the values to print out in zeus though - I ended up having to copy the output down from fuse.. thus why there are only 143 data points.)

the P Rak code is working and spitting out ints. In this trivial example it gets printed to the screen.



Image

*cue victory dance* :lol:

Image

This would have looked a lot better if there were more data points...

Image
Post Reply