2020: NameSpaces are going to be implemented this year to better separate content. OS-9 Al (talk) 11:18, 15 April 2020 (CDT)
2020-05-17: If a page gives you an error about some revision not being found, just EDIT the page and the old page should appear in the editor. If it does, just SAVE that and the page should be restored. OS-9 Al (talk) 12:22, 17 May 2020 (CDT)
Get and Put
|Looking for CoCo help? If you are trying to do something with your old Color Computer, read this quick reference. Want to contribute to this wiki? Be sure to read this first. This CoCo wiki project was started on October 29, 2004. --OS-9 Al|
This page was last updated on 05/18/2019. Total Pages: 680. Total Files: 956.
GET AND PUT High-Res Graphic Movement By J. E. Pennett
How would you like to be able to move an image around the screen in BASIC. Sure. there are several ways to accomplish this. One way is to draw a picture. erase it, and then draw it in a new location.
The problem with this method is that it is very slow and creates a flickering effect. Tandy came to our rescue with the Color Computer graphic commands GET and PUT. These commands help you avoid the problems of speed and flicker. and still use just BASIC to write your programs. The manual for Extended Color Basic but doesn’t explain their use to the average programmer. This article will explain how you can use these commands in your own programs.
First, there are several other things that must be done before you can call up GET and PUT. In order to illustrate these things, we will write a program to help us.
The first item on our list is to define the size array we will need for our picture. This array will be used each time we either GET a picture or PUT a picture.
Its size is limited to how much memory we wish to dedicate to the picture. On a 16K RAM Color Computer. you have about 1400 elements of array storage. This is because each element uses 5 bytes of memory. At 1400 elements. you will use 7000 bytes (1400 elements * 5 bytes = 7K). In the highest mode of resolution. this leaves little for program use. To figure out the size array needed. just draw your picture, to scale, on paper. Then count how many pixels across it is (width) and how many pixels high it is (length).
As an example, enter this program and run it:
10 PMODE 4,1:PCLS:SCREEN 1,1 20 CIRCLE (128,96),5 30 GOTO 30
This program displays a circle in the center of the screen, 10 pixels across. The array size needed to cover this circle is 10 wide by 10 long. This gives us an array of 100 elements in size. and uses 500 bytes of memory. Using this size, add the following line to the example program you've typed in:
- 5 DIM A(9,9)
The GET command has a format that you must follow to insure accurate coverage of the picture you wish to store. This format is: GET (STARTPOINT) - (ENDPOINT), DESTINAIION, G
The STARTPOINT is the upper left corner coordinates of your display. The ENDPOINT is the lower right corner coordinates of your display. The DESTINATION refers to the array name you have DIMensioned in Line 5. in this case, array A. The "G" will tell the computer that you wish to have the array stored with full graphics detail. This is optional, but we'll use it here and you should, too, for best results.
Now back to the program. Make the following changes:
What we've done is change the center point of the circle to be stated in terms of variables instead of fixed numeric points. Our circle will still be in the center of the screen. but we can now use the variables later without redefining their value.
Now. add the following line:
- 25 GET (A-5,B-5)-(A+5,B+5),A,G
As you can see, we have used the variables to allow us to set our start and end points more easily. The numeric equivalents of the variables would show we are now defining a square that is 10 pixels on a side. This will allow us to GET the complete circle we have previously drawn.
When the program is run, the circle will be stored in array A. Now that it is stored. what do we do with it? Well. how about drawing it in another location to prove it is stored in memory? We can do this by using the PUT command to place our circle anywhere we want on the screen.
The PUT command has the format: PUT (STARTPOINT) - (ENDPOINT), SOURCE, ACTION
The STARTPOINT and ENDPOINT are the new locations of the corners of our array. These can be any values that are within screen limits AND that hold the array to the size that was defined earlier in the program. In our example, the size is 10x10. The SOURCE is the name of the array we have stored earlier, array A. The ACTION is one of five options — PSET. PRESET, AND, NOT and OR.
PSET is the action command we will use. This will allow all points (pixels) that are set in the original array to be set in the target location.
PRESET will reset any pixels in the target location that were originally set.
AND will compare the points in the original array with the points in the target location. If both are set, the new point will remain set. If one or the other is not set, the point will be reset.
NOT will reverse the state of every point in the target location. That is, if the point is set, it will be reset; if it is reset, it will be set.
OR will compare the points in the array with the points in the target location and if either is set. the screen will be set.
with all this in mind, add the following lines to your program:
30 A=A+INT(JOYSTK(0)/6.3)-5:B=B+INT(JOYSTK(l)6.3)-5 40 PUT (A-5,B-5)-(A+5,B+5),PSET 50 GOTO 30
Line 30 will now allow the right joystick to control movement in any direction at a maximum speed of up to five pixels at a time. This movement can be stopped by bringing the joystick to the exact center. The farther you move from the center, the faster the circle will move. Line 40 will PUT the circle at the location you have defined with the joystick. Line 50 will branch the program back to Line 30 for an update of the joystick location.
Run the program and you will see that there are several problems with the operation. First, if you allow the circle to get too close to the screen edge, you will get a function call error. Let's take care of this problem 'by limiting the screen movement of the circle. We do this by adding:
31 IF A<=5 THEN A=5 32 IF A>=250 THEN A=250 33 IF B<=5 THEN B=5 34 IF B>=186 THEN B=186
After adding these lines, we can move the circle anywhere on the screen and it will stop or move along the edge if it gets close. The other problem we have is that the circle leaves a trail as it moves. While this can be used to create some pretty patterns, that isn't what we want to do.
We can eliminate the problem in two ways. Either we must enlarge the array to allow for the five pixel maximum movement of the circle. or we must decrease the size of the drawing to allow for a blank border around the drawing.
Both methods have drawbacks. but either can be used. If you increase the array size, you will use more memory and chance running into the nefarious OM error if your program is long. If you decrease the drawing size, you lose resolution, possibly affecting the effect you wanted. Since we have plenty of memory in this small program. we will use the first method. Make the following changes:
Change Line 5 to: 5 DIMA(20,20) Change Line 25 to: 25 GET (A-10,B-10)-(A+10,B+10), A,G Change Lines 31-34 to: 31 IF A<=10 THEN A=10 32 IF A>=245 THEN A=245 33 IF B<=10 THEN B=10 34 IF B>=181 Change Line 40 to: 40 PUT (A-10,B-10)-(A+10,B+10), A,PSET
Now we have a circle that will move under direction of the joystick and does not flicker. The speed of movement can be altered by changing the values in line 30, but you must also change the size of your array if you wish a faster movement. Otherwise, you will again leave a trail of picture parts on the screen.
Experiment with the other action command options. You might be pleasantly surprised with them.
Now that you have a better understanding of GET and PUT, look back through the last several issues of the RAINBOW and see how I used them in LASER STAR and HELO BATTLE. Remember, you have to use the same PMODE to PUT that you used to GET, or you may not obtain the results you tried to achieve.
Have fun with these and be sure to let me know via the RAINBOW how you are doing or if you have any questions or problems with which I can help.