|Column Tag:||Basic School
Color & DragGrayRgn Explored
By Dave Kelly, MacTutor Editorial Board
MAC II takes on BASIC
Yes, I know that it has been about a year since the Macintosh II was released and not a word from me on how the Basic works on the Mac II. The Mac II really is a wonderful machine, although there are still a few incompatibilities and inconveniences. But all in all I still give the Mac II an A+.
The curiosity lies in figuring out what works (or doesnt work) on the Mac II. The Mac II has features that did not even exist when most of the versions of Basic were written. Some things like color and screen size arent supported properly, or at all, even though the software was capable before the Mac II came.
Its fast. For example, just take a look at what it did for the Byte Magazine January 1983 Prime number benchmark program, known as the Sieve. ZBasic comes up with a 2 second time, MS Basic Binary interpreter with 129 second time (about the same as True Basic on the Mac Plus), and 15 seconds for the MS Basic compiler. Of course, everything is faster so it is all relative. Since we already know that the Mac II is faster and have a good idea about which versions of Basic are faster, there is no need to go into that here. For more information comparing the various versions of Basic, see MacTutor, Aug 1986, Feb. 1987 and Mar. 1987.
Screen Size: With the advent of the larger screen (also available for Mac Plus and SE) we see the need to be fully compatible with all size monitors. MS Basic opens its default windows to 512 X 342, the size of the SE and MacPlus screens. That works out alright since it still isnt known what kind of Mac might be running the program. Double-clicking the title bar causes MS Basic windows to zoom to full screen size. The LIST windows wont expand horizontally beyond the 512 limit, but will expand vertically to the bottom of the screen. The most annoying thing is that none of the windows can be moved below a certain point on the screen which is very close to the place where the bottom of the 9" screen would be (342). This means that you can never move the command window out of the way; you have to close it just like on a Mac Plus.
True Basic v. 1.1, which I havent looked at for awhile, opens the default window to full screen size. Of course, True Basic still has all the HFS problems and other limitations which I have discussed in past issues of MacTutor (Best of MacTutor Vol 2, pg 379 or August 1986). (Version 1.1 is the latest that I have).
ZBasic Ver. 4.1 windows also open to full screen size. There doesnt appear to be any compatibility problems here at all. As I write this, the ZBasic promised editor has still not been completed.
Color support: This is only a big deal to those of you with a Mac II with a color monitor ( I wouldnt have one any other way!!). As you know, the original Quickdraw supports 8 colors already. I feel that it shows short-sightedness to not at least support that much. But both MS Basic and True Basic have NO color support even though both languages include means to change color from black to white. Other versions (on other computers whose names we wont say) of True Basic support a small set of colors. MS Basic uses color as a parameter in the syntax for the CIRCLE statement, yet you cant get any colors except black and white.
ZBasic, however, does support the 8 colors in Quickdraw. Thats only 8 colors for now, but I would expect that they will make improvements to this in some later version (who knows when?). So meanwhile, if you want color you will have to settle with the 8 basic colors. There are a few differences between ZBasic color statements and Quickdraw color statements. In order to standardize ZBasic, Zedcor has numbered the colors from 0 to 7. Quickdraw, however, has its own designation for each color as the following chart shows:
The color codes in ZBasic and QuickDraw CANNOT be substituted for each other. You will have to either use Quickdraw graphics or ZBasic graphics or be careful not to mix the code with the wrong call. Sure, setting the color is easy, but be sure to use the right code with the right statement.
This months program demonstrates the colors available in ZBasic and gives you an example of its use. All you have to do is set the color before issuing a graphics drawing statement and either Quickdraw or ZBasic (which probably uses Quickdraw anyway) will use the color you selected.
Whats missing? Color QuickDraw thats what. Fortunately, Zedcor has been very responsive to updating ZBasic. Im sure that it isnt easy for them to keep updating everyone so often. Lets hope that the next version of ZBasic will include the long awaited editor, Color QuickDraw and other major improvements. Read on!
[The slow response by the Basic compiler makers to upgrade their products to meet the requirements of Mutifinder, System 4.2 and the Macintosh II, has been really disappointing! There is still a pressing need for a reliable, engineering oriented Basic that provides full access to the Macintosh capabilities and can function in a workstation environment (ie, it can do math correctly and quickly). We encourage both the present Basic compiler makers to address this issue, as well as those we haven't seen in this marketplace, like Borland, to enter it, and hopefully unite a fragmented and frustrated market. -Ed]
By Dave Kelly
A color chart for future reference
EDIT MENU 2
MENU 3,1,1,ZBasic Commands
MENU 3,2,1,ToolBox Commands
MENU 3,3,1,Erase window
theEnd=0:REM theEnd will never come.
Make QuickDraw Color Assignments
Make ZBasic Color Assignments
WINDOW 1,Color Demo Window,(4,38)-(450,200),4
GOSUB ZBasic Colors: Print something to start
ON MENU GOSUB MenuEvent
theEnd=0:REM theEnd will never come.
IF Menunumber%=1 AND Menuitem%=1 THEN Quit
IF Menunumber%=3 AND Menuitem%=1 THEN
GOSUB ZBasic Colors
IF Menunumber%=3 AND Menuitem%=2 THEN
GOSUB QuickDraw Colors
IF Menunumber%=3 AND Menuitem%=3 THEN CLS:PRINT@(1,3)The Colors are
PRINT%(170,20) ZBasic Colors
BOX FILL 5,50 TO 55,100
BOX FILL 60,50 TO 110,100
BOX FILL 115,50 TO 165,100
BOX FILL 170,50 TO 220,100
BOX FILL 225,50 TO 275,100
BOX FILL 280,50 TO 330,100
BOX FILL 335,50 TO 385,100
BOX FILL 390,50 TO 440,100
BOX 5,50 TO 55,100
BOX 60,50 TO 110,100
BOX 115,50 TO 165,100
BOX 170,50 TO 220,100
BOX 225,50 TO 275,100
BOX 280,50 TO 330,100
BOX 335,50 TO 385,100
BOX 390,50 TO 440,100
PRINT%(150,140) QuickDraw Colors
CALL MOVETO (170,20)
CALL DRAWSTRING (ZBasic Colors)
CALL TEXTSIZE (10)
CALL MOVETO (25,48)
CALL MOVETO (75,48)
CALL MOVETO (130,48)
CALL MOVETO (190,48)
CALL MOVETO (240,48)
CALL MOVETO (300,48)
CALL MOVETO (355,48)
CALL MOVETO (410,48)
CALL MOVETO (25,112)
CALL MOVETO (75,112)
CALL MOVETO (130,112)
CALL MOVETO (190,112)
CALL MOVETO (240,112)
CALL MOVETO (300,112)
CALL MOVETO (350,112)
CALL MOVETO (410,112)
CALL MOVETO (150,140)
CALL DRAWSTRING (QuickDraw Colors)
Basic Answers to Basic Questions
Concerning the comment in the Nov. 1987 issue of MacTutor where Steve Millman suggested a method of applying an event loop for reading disk events: The main problem here is that a disk event might be inserted while not in the GetNextEvent loop. The disk insert would be missed completely. I have been assured by Zedcor that in a future release of ZBasic they will add the Disk insert event to the DIALOG functions. This is easy for them to do since GETNEXTEVENT returns this to them anyway. For now, just do what Steve Millman suggests or dont bother checking for disks at all until the new improvements come.
Q. I want to use in my program a DragGrayRect statement (the same as you see in MS Basic), but I want to use it in ZBasic. Is this possible?
A. DragGrayRect is only available as an MS Basic library call (previously known as a Clear Lake Research Library call). The alternative is to use DragGrayRgn where the region is in the shape of a rectangle. DragGrayRgn is a ROM call where as DragGrayRect is a library subroutine derived from ROM calls (probably uses DragGrayRgn). Another alternative that would require more work would be to write your own DragGrayRect function to use in any of your programs. The following program includes an example of this function. The function itself can be saved to the disk with SAVE+ and retrieved later for use in other programs with APPEND. Hope that this helps.
By Dave Kelly
Create DragGrayRect function
LONG FN DragGrayRect&(RL%,RT%,RR%,RB%, mousey,mousex, PL%,PT%,PR%,PB%,BL%,BT%,BR%,
Rect% = the rectangle to be moved
pt% = the point where the mouse was pushed.
pin% = the rectangular limits in which outline can be
bnd% = the rectangular boundary for a drag.
dir% = the direction to which the drag is constrained
0 = no constraint, 1 = horizontal, 2 = vertical
dis& = A point array that returns drag displacement.
dis&=FN DRAGGRAYRGN(RgnHand&, pt%(0), pin%(0), bnd%(0), dir%,Proc&)
Find out monitor size
MOUSE ON:MENU ON:DIALOG ON
ON MOUSE GOSUB MouseEvent
ON MENU GOSUB MenuEvent
ON DIALOG GOSUB DialogEvent
MOUSE OFF:MENU OFF:DIALOG OFF
IF D=4 THEN END
IF Menunumber=1 AND Menuitem=1 THEN END
dis&= FN DragGrayRect&(left,top, left+100, top+100, mousey,
mousex, PortLeft, PortTop, PortRight, PortBottom, PortLeft,
LONG IF dx<>0 AND dy<>0
CALL FORECOLOR(205): color = red