This article is reproduced by permission from the Jan., 1989 MIDWEST NEWS, the monthly journal of the Midwest Commodore Users Group. Permission is granted to reproduce this article for non-profit purposes only.
128 WINDOWS: CLEARED UP
By Steve Mitchell
Here's a footnote in the never-ending search for new ways to jazz up screens: Using the window command to clear your screens. Chr$(147) does an adequate job--but sort of plain-jane. Here's a group of 1-liners that does the same job with a little flash. What we'll do is use the optional clear flag on the end of the window command. In way of review; the window command must have 4 parameters following it--the beginning col and row then the ending col and row. You also may add a ",1" to the end to clear the window as it is made. We will create a series of windows, each bigger than the last in the direction(s) that we choose.
First, let's fill the screen with the letter "A". Lines 100-120 do that. Then we create our series of windows. Using a for/next loop in line 600 we create 24 windows as wide as the screen, each starting at the top of the screen and each extending one line lower than the last. Finally the last window is the size of the normal 40 col screen. That was easy, huh? Go ahead and type in the short demo at the end of this column and see the results for yourself. The demo has 6 different examples of this technique. It would take a long article to give you a blow-by-blow of each of them, but they can be easily understood by seeing them one time. However, there are 2 constructions that may seem unfamiliar to some readers, so I'll explain them (we're all here to learn together, right?).
The first is the RWINDOW command. You could look it up in most any manual, but I'll explain it anyway. The RWINDOW command returns information similar to the way RSPPOS (read sprite position) and RREG (reads the processor registers) do. There are three possible values that can be put into parenthesis after the command. RWINDOW(0) returns the number of rows -1 in current window. RWINDOW(1) returns the number of columns -1 in the current window. RWINDOW(2) returns the width of the current screen (40 or 80). Using the RWINDOW(2) command you could make a title screen center itself whether you are in 40 or 80 col mode. Also the RWINDOW command can be used in loops to do something the same number of times that you have columns on your screen. Any of these demos could be converted to work in 40 and 80 col quite easily. There are other uses for RWINDOW but they are beyond what we're doing here today.
The second construction that may cause some puzzlement is the formulas used in the examples that go from center-out and from top-left to bottom-right. Let's figure out what we want one of them to do and then figure out how it does it.
Let's do the top-left to bottom-right. We want to start in the upper left corner with the first window and increment the window bigger each way till it fills the screen. But wait! the screen is not square so we will reach the bottom before we reach the right side. That will result in an illegal quantity error. Here is how I resolved this dilemma. I know that I only want to go down a certain number of times--i.e.24. In this loop of 24 cycles I want to increment sideways a total of 39 times. So using a ratio, I can figure that to do it absolutely evenly, I would need to go sideways 39/24 for each increment down. That could be written as (increment * 39/24). Follow me so far? Good. The problem is that the window command must have integers so I rewrote it to say int(increment*(39/24)). Not trusting my own math, I made a truth chart showing the integer increment sideways for each of the 24 vertical increments. It works!
There may be faster ways to do this such as inserting a decimal (1.625) instead of the fraction 39/24--or making a variable equal to 1.625 and inserting the variable, but the important thing in this column is that not that you are impressed by a construction you don't understand, but that you understand why something works and hey, maybe you can go on to improve it yourself! If you do, by all means, run it my way.