Tinyfpga wrote:I managed to compile pjw's last posted Matrix!!! code on my system as
follows:-
It looks, er, interesting
x=scr_xlim:y=scr_ylim
window x,y,0,0:cls:g%=x/12-1
open #1,scr_
Since you appear to be interested to get to grips with SBASIC, I can
try to explain (although there clearly are some differences between
SMS2 SBASIC and up-to-date SMSQ/E SBASIC, so beware!):
When you start a new interpreter instance (SBASIC daughter job), eg
with EX <program>_bas, any attempt to access the screen causes a
console to be opened. This weird console is described in various
places, including a document by Tony Tebby called DIFFER.DOC. He
explains:
To use the facility to create SBASIC daughter jobs with just
window #0 open, all the standard commands which default to window #1
or #2 will default to window #0 if channel #1 or #2 is not open. This
may not apply to extension commands.
Since SCR_XLIM/SCR_YLIM both require a channel (default #0) using them
opens the default console, thus immediately providing channel #0. The
next two screen calls,
window and
cls, act on this channel.
g%=x/12-1 just creates an index of the screen columns, starting from
0. (I found that g= works just as well as g%=)
But now we need a real window to operate on, so we open a new screen
as channel #1.
rep p
window 10,y,rnd(g%)*12,0:ink#1,rnd(1000):scroll s/5
if rnd(1):bput#1;rnd(31,99):s=5:else:s=15
end rep p
SCROLL moves the contents of a given window down (or up) and replaces
the displaced pixel lines with the paper colour. You can scroll only
part of a window, but here we want to scroll the whole window down by
<s> pixels. So we make window#1 the width of the column, and the
height of the whole screen. The column to operate on is chosen
randomly for effect (
rnd(g)*12 ). This becomes the x-offset of the
window and column.
Perhaps ideally, we'd print the character into our randomly selected
column and then scroll the column, but to avoid an extra
endif, it was
done like the above. Its so fast the difference wont be noticed anyway.
Now we print the character, some random character between ASCII 31 and
99 (99 was chosen simply to save a byte. It could just as well have
been 191.) (I see you added the random ink colour here: You could have
dispensed with the #1, as INK defaults to channel #1 anyway. You could
also have limited yourself to
ink rnd(1,7), or just
ink rnd(7).. )
Initially I randomly printed spaces, but they are not needed as the
scrolling takes care of that. Hence the
s=5 (normal character) and
s=
15 (space).
Normally, you want loops to be as efficient as possible, so all
calculations where the answer is known in advance are done outside the
loop. Thus it would make more sense to change the clauses
:s=5:else:s=
15 to
:s=1:else:s=3, and the clause
scroll s/5 to
scroll s, as this
has the exact same meaning and shaves a few micro seconds of a any
loop that has to do real work! (However, you may be attempting to slow
the loop down a fraction by adding the extra calculation..?)
I still don't fully understand the program but was able to add
random colours to the raining text to see what it would look like. To
slow the rain I divided s by 5.
I hope the workings of the code has become clearer now. Of course,
this was exceptionally terse and a little convoluted. But often I feel
that reams of beautifully formatted code with long, descriptive names
dont necessarily make things clearer; they just obscure bad
programming! (IMHO) There has to be a balance.
PS: To slow the loop it would make more sense to make a sub routine,
W, that does some complicated math in a FOR loop, or something..
def proc W: for i=0 to 999: x = 3^3
And put the
W after
scroll s.