Commodore's port; hi-res graphics from Simon's Basic. John J. Anderson.
Avast, maties! Lower the mains'l and heave to. Put in to Commodore's Port for a short while and replenish your stores of unbiased news, reviews, and applications for your Commodore 64. We've got lots to do, so full steam ahead!
You might have heard by this time that Jack Tramiel, founder and former head of Commodore, is now the head of Atari. Lineups in the microcomputer industry change as quickly as in professional baseball, don't they? Well, we'll see if Jack can keep the same impressive bating averae for a team in Silicon Valley. He certainly has his work cut out for him. Talk About Mixing Metaphors!
Got a phone call and a care package from Deep Boat the other day. Though he has watched many of his compatriots jump ship in the latest round of battle, he remains loyally at his station, awaiting further orders. Seems a bit of shanghaiing has been going on, and Commodore is not at all happy with the idea that Mr. Tramiel has assembled his order of command with deserters and mutineers from Commodore itself. But Deep Boat will have none of it. He's a Commodorian through and through. While expressing his respect for Mr. Tramiel, he also underscored his confidence in Commodore--assuring me that they are not about to allow TTL (Tramiel Technologies Ltd.) Atari to wrest away Commodore's claim to number one in home computers. (Read Outpost: Atari for more information regarding the Tramiel take-over.) Speak of the Devil
Deep Boat backed up his prediction with some very hard evidence: a beta copy of the arcade game, Satan's Hollow, for the C-64. I could hardly believe my eyes when I booted up the game. It compares extremely favorably with the arcade version, which (you may or may not remember) featured absolutely incredible graphics.
Though Satan's Hollow is to some degree a rehash of Galaxian, it is an extremely engaging rehash, and it has some neat little features all its own. As an arcade game translation, it is utterly superlative, as Deep Boat assured me it would be. The sound effects of the game are also outstanding--completely true to their arcade namesake. Without a doubt, the Commodore 64 has established itself as a graphics and sound machine of unimpeachable repute.
Deep Boat, best of luck, and keep it coming. You never steer us wrong. Simon's Sight and Sound
If you have followed the last couple of columns, you know that we have been running a tutorial series from Commodore 64 Sight and Sound, a new book available from Creative Computing Press. This month we excerpt a section on hi-res graphics from Simon's Basic.
You may be one of the few C-64 owners around who still hasn't gotten a hold of Simon's Basic. That's a shame, since you are missing out on just about the finest programmer's learning tool available to you. I strongly recommend that you purchase it (it is priced very reasonably)--along with a copy of Sight and Sound of course. If you are having trouble locating the book at your local bookstore or software dealer, give us a call here at the magazine, and order one direct.
Enough shameless plugging. On to the good stuff. Hi-Res Graphics
Simon's Basic puts the powers of high-resolution graphics at the fingertips of the beginning programmer. As opposed to low-res character graphics, hi-res allows you to plot geometric shapes. With just a few simple commands, you can build complex, multicolor pictures. HIRES
The HIREs command tells the C-64 to go into high-resolution mode and in what screen and plot color to do so. By plot color, we mean the color the C-64 will use to draw on the hi-res background color when we get around to drawing on it. The format is
HIRES screen color, plot color RETURN
A HIRES command cannot work on its own, however. It needs some help. LINE
The LINE command allows you to draw a line on the hi-res screen from one point to another. The program
10 HIRES 0,1
20 LINE 20, 40, 300, 250, 1
30 GOTO 30 draws a diagonal line across the screen. The format for the LINE command is as follows:
LINE beg x, beg y, fin x, fin y, plot
type where beg x is the beginning x value of the line, beg y is the beginning y value, fin x is the final x value, fin y is the final y value, and the plot type is set to 0, 1, or 2. For now we will always use a plot type set to 1.
At first you are bound to be confused by the placement of x and y plots across the screen. Figure 1 may h elp give you a feel for the hi-res screen.
Play around with the x and y values for line plots. Before long you will develop a rough idea of where plots occur on the hi-res screen.
Now let's get a taste of the animation potential of Simon's Basic in hi-res. The simple program shown here as Listing 1 allows you to create an animated line plot. You can build on this basic principle to create sophisticated moving pictures. It is used simply here, but can be used in sophisticated ways as well.
As you can see from the listing, all you need to do is build a counter for the x and y values, then set up a loop. Each time through the loop, the line plots to the incremented x and y values. The result: an animated drawing. REC
Any guess what the REC command allows you to draw on a hi-res screen? You got it, a rectangle. As with LINE, it takes a while to get used to the numbers you need to use with the rectangle command, but you can get the hang of it with a bit of practice.
First, you tell the computer where you want the top lefthand corner of the rectangle to be. You do this by specifying X and Y coordinates. The only way to get a good feel for these coordinates is to experiment.
Next, you tell the computer how wide and how long you want the rectangle to be. Again, it takes practice to learn what numbers give you the result you want.
Listing 2 is an example of the use of the REC command. Type it in, and see where this set of coordinates places the traingle. The command is
REC beg x,beg y, width, length,plot
type where beg x and beg y are the coordinates of the top lefhand corner of the rectangle, width is the horizontal width of the rectangle, and length is the vertical length of the rectangle.
What about that strange number 1 tacked on the end of the expression? Well it tells the computer that this is a normal plot. We will look at inverse and clear plots just ahead. For now, all you need to know about is plot type 1.
First, look at Listing 3. It puts the REC command to work for you in an animated plot.
Pretty good results for just a wee bit of effort, wouldn't you say? This program is very easy to understand once you get a trip on the REC command. It is a loop, and each time through the loop it increments the corners of the rectangle. The top lefthand corner moves down and to the right, while the bottom righthand corner moves up and to the right. This gives a three-dimensional effect. We stop plotting when X gets to 251, so we won't error out. We actually begin plotting the entire figure again, but you can't see it happen, because it is ploting right over itself. A Closer Look at Plot Types
Let's try to gain an understanding of plot types by playing with the plot types in our last example program. We'll change the plot type of the program by changing the last value in the REC statement, the plot type, to 0. What happens?
If we specify a plot type of 0, nothing gets plotted. If a plot type 0 encounters a plotted line, it will actually erase it. this comes in handy for "undrawing" animated shapes. Listing 4 provides an example.
As we saw earlier, a plot type of 1 is a normal plot, drawing a shape in the plot color across the background. No need to look any further at that plot type right now.
A plot type of 2 "inverses" whatever encounters. It turns a plot off if it is on, and on if it is off. We can use a plot type of 2 to make our animated rectangle change shape continuously as it does in Listing 5. Multi-Res--Best of Both Worlds
So far we have been looking at the hi-res mode, in which we can put one plot color on top of one background color. Now get ready for the multi-res mode, which allows us to plot in three plotting colors, and with a little sneaky footwork, even more.
The multicolor mode, which we shall call multi-res, is a variant of the hi-res mode--with half the horizontal resolution but three times the color. It is up to you to decide which resolution to use with which graphics trade-offs. MULTI
The MULTI command, when used following a call to the HIRES command, will cause all plotting to take place in multi-res. Format for the command is
HIRES plot color, background color:
MULTI color 1, color 2, color 2
plot color = 0 -15
background color = 0 - 15
color 1 = 0 - 15
color 2 = 0 - 15
color 3 = 0 - 15
Note that a MULTI command must always follow a HIRES command. The three parameters following MULTI define the plot colores you wish to use.
Each plot color is selected by its MULTI command designation as the plot type in a plotting command. We will clarify this just ahead. Listings 6 and 7 are some examples of hi-res graphics transposed into multi-res.
In multi-res, each pixel is twice as wide as it appears in hi-res. As a result, multi-res has half the horizontal resolution of hi-res. Still, multi-res has a pretty respectable look, and the trade off results in the ability to put multicolors on the screen. Plot Types in Multi-Res
Plot types work slightly differently in multi-res than they do in hi-res to account for the additional colors available. A plot type of 0 still functions to clear a dot. A plot type of 1 plots a dot in color 1. A plot type of 2 plots in color 2, and a plot type of 3 plots in color 3.
If you specify a plot type of 4, the plot will inverse dot color--in the following fashion:
color 0 changes to color 3
color 1 changes to color 2
color 2 changes to color 1
color 3 changes to color 0
This plot type can give you animated rainbow effects for a small expenditure of code.
Creative use of plot types can make animation a cinch. Listings 8 and 9 are some starting points.
We'll continue our look at hi-res graphics next month. Until then, keep yourself booted up, and enjoy.