TweetFollow Us on Twitter

Dialog Events
Volume Number:3
Issue Number:1
Column Tag:Basic School

Dialog Events in ZBasic

By Dave Kelly

DIALOG MANIA

The word 'mania' as used in the title of this month's Basic column has a kind of dual meaning. My dictionary says that 'mania' means: 1. wild or violent mental disorder 2. an excessive enthusiasm; obsession. I find both definitions express what it is like to program with ZBasic. Many of you have been following the 'Basic Wars' as they have been progressing. MS Basic 3.0 has been announced as of the writing of this column, although I have not seen it yet. This is supposed to be a $25 upgrade. The MS Basic compiler is also supposed to be out, at least Microsoft is marketing it by direct mail. (Note: The MS Basic compiler and version 3.0 of the MS Basic interpreter are two different products, both of which you need to compile programs!) Pterodactyl Software's PCMacBasic has not come back off the drawing board and True Basic is no better off than when I reviewed it back in August. But there has still been some hope. Zedcor has been scrambling to fix bugs in ZBasic and release version 3.02. They are to be commended for their dedication to making their product a success.

Why do I say that both definitions of 'mania' describe programming with ZBasic? The second definition comes to mind first. I'm excited to see the big improvements that have been incorporated into ZBasic. In fact, the BOMB is a much less frequent sight. In fact, the BOMBs that appear from time to time now are more obscure. In fact, some of the BOMBs are 'self inflicted'. In other words, sometimes things that I am not doing correctly turn out to be the problem. But there have been a few problems that demonstrate that not all the problems have been removed from the compiler.

One such example of what I am talking about was brought to my attention by one of our subscribers from Switzerland. He summed up ZBasic nicely when he said "...ZBasic is really a great Basic if only it worked!" He described to me a problem he was having when working with DIALOGs and ZBasic. He stated that he could not "flush the value of the DIALOG(1) function". The answer to his problem turns out to not be too hard, however, it reveals to us some other difficulties that ZBasic has 'built in' to it.

First, the solution to the DIALOG(1) problem is that it is not a problem. It will be helpful to understand how the DIALOG functions operate. The DIALOG function originates with MS Basic. The excitement comes when I see all the enhancements that have been added to the ZBasic implementation of DIALOGs. The purpose of the DIALOG function is to inform us when events (such as BUTTON, EDIT FIELD and WINDOWs) that occur between the DIALOG ON and DIALOG OFF statements.

It is important, when using DIALOG functions, to know when the function data is valid. The DIALOG(0) function is the key to it all. When an event occurs, the DIALOG functions are stored up in a 64 event queue. The ON DIALOG GOSUB statement is supposed to cause an interrupt to occur when some kind of event has happened. I say it is 'supposed to' because when writing the sample program included here I found that some of the items in the queue were not automatically read until another event occurred. Of course the new event was then pushed onto the queue and would not automatically interrupt via ON DIALOG. My solution was to poll the event queue continuously unless it was empty by accessing the DIALOG(0) function. Anyway, ideally the ON DIALOG should notify the program whenever any DIALOG events occur. The are seven events that are common to ZBasic and MS Basic. ZBasic now has 16 DIALOG functions including functions which support the Zoom windows and keyboard events. The DIALOG(0) function will return a number 1-16 (1-7 in MS BASIC) which will indicate to you what kind of event occurred. At the same time, the function that coresponds to the DIALOG(0) result will be updated. The functions ( DIALOG (1-16) ) are ONLY valid just after the DIALOG(0) function returns an event of that type. Otherwise the last event of that type remains on, stored up in the DIALOG functions. The figure shows a flow chart of what happens when DIALOG(0) has an event to be processed. Just remember to poll DIALOG(0) first to find out which of the other functions you will need to poll next.

Figure 2.

Another phenomenon that was observed was that when events are active ( the lines between DIALOG ON, MENU ON, BREAK ON, MOUSE ON and DIALOG OFF, MENU OFF, BREAK OFF, MOUSE OFF) the program seems to run much slower than without events on. I tried to turn off events wherever possible with some increase in speed, but there seems to be some delay between polling the time an event occurs and when it is finally processed. Has anyone done any benchmarks to compare speed when events are turned on? It is a difficult thing to compare as the implementation varies so much from one language to another.

Look out here comes another bug... As it turns out, the DIALOG(8) and DIALOG(9) statements work great. The problem is that Zoom windows still don't work quite right. In ZBasic 3.02 the demo program below will BOMB if Zoom windows are made active. I have set it up to demonstrate how it should work. The PEEK (&28E) AND 128 statement towards the beginning of the program checks to see if the Mac has old 64K ROMS or the new 128K ROMS installed. If the new ROMS are available then the window type should be set to 9 when the windows are created.

The example program outlines the basic flow which you will want to use when you implement your own ZBasic event loops. Notice that Menu events and Dialog events are mixed in the same event loop. This same structure also applies for MS BASIC. Any questions?

REM ZBasic V3.02 Dialog Example
REM ©MacTutor 1987
REM By Dave Kelly

WINDOW OFF:REM Always use this as first line of program to prevent default 
window from being created
COORDINATE WINDOW:REM Set window to  Macintosh coordinate system
False=0:True=NOT False
IF PEEK(&28E) AND 128 THEN Wtype=1 ELSE Wtype=9
Wtype=1:REM  Due to Bugs in ZBasic 3.02 Zoom window will not be used.

MENU 1,0,1,"File"
MENU 1,1,1,"Quit"
DIALOG OFF
WINDOW 1,"Window 1",(10,50)-(250,200),Wtype
TEXT 4,9,0,0
BUTTON 1,1,"Button 1",(20,20)-(100,50)
BUTTON 2,1,"Button 2",(20,60)-(100,90)
WINDOW 2,"Window 2",(275,50)-(500,200),Wtype
TEXT 4,9,0,0
EDIT FIELD 1,"",(10,10)-(100,35),1,1
EDIT FIELD 2,"",(10,40)-(100,65),1,1
WINDOW 3,"Dialog Event (Window #3)", (10,250)-(500,340),28
TEXT 4,9,0,0
ON DIALOG   GOSUB "DialogEvent"
ON BREAK    GOSUB "BreakEvent"
ON MENU GOSUB "MenuEvent"
DIALOG ON:BREAK ON:MENU ON
"Mainloop":DO:D=DIALOG(0)
IF D>0 THEN GOSUB "DEvent"
UNTIL D=0
GOTO "Mainloop"

"MenuEvent"
DIALOG STOP:
Menunumber=MENU(0):Itemnumber=MENU(1)
IF Menunumber=1 AND Itemnumber=1 THEN END
DIALOG ON
RETURN
"BreakEvent"
STOP

"DialogEvent"
D = DIALOG(0):REM check to see what event occured
"DEvent"
DIALOG STOP
Currentwindow = WINDOW(0)
Windowselection = WINDOW(1)
WINDOW OUTPUT 3
IF D = 1 GOSUB "Buttonevent"
IF D = 2 GOSUB "EditEvent"
IF D = 3 GOSUB "InactiveWindow"
IF D = 4 GOSUB "Closebox"
IF D = 5 GOSUB "Refresh"
IF D = 6 GOSUB "Returnkey"
IF D = 7 GOSUB "Tabkey"
IF D = 8 GOSUB "Zoomin"
IF D = 9 GOSUB "Zoomout"
IF D =10 GOSUB "Shifttab"
IF D =11 GOSUB "Clearkey"
IF D =12 GOSUB "LeftArrow"
IF D =13 GOSUB "RightArrow"
IF D =14 GOSUB "UpArrow"
IF D =15 GOSUB "DownArrow"
IF D =16 GOSUB "Keypress"
PRINT @(50,3) "DIALOG(0) :        ";D
PRINT @(50,4) "Active Window #";Currentwindow
PRINT @(50,5) "Output Window #";Windowselection
WINDOW OUTPUT Outwindow:WINDOW Windowselection
DIALOG ON
RETURN

"Buttonevent"
Buttonclicked=DIALOG(1)
Bstatus=BUTTON(Buttonclicked):BUTTON Buttonclicked,3-Bstatus
PRINT@(1,1)   "Button clicked :   ";Buttonclicked
RETURN

"EditEvent":
EditField=DIALOG(2)
PRINT@(1,2)   "Edit Field :       ";EditField
RETURN
"InactiveWindow"
Windowselection=DIALOG(3)
PRINT@(1,3)   "Inactive Window :  ";Windowselection
RETURN
"Closebox":
ClosedWindow=DIALOG(4)
IF ClosedWindow=3 THEN END
PRINT@(1,4)   "Closed Window :    ";ClosedWindow
RETURN
"Refresh":
ErasedWindow=DIALOG(5)
PRINT @(1,5)  "Erased Window :    ";ErasedWindow
RETURN
"Returnkey":
Returnpress=DIALOG(6)
PRINT @(25,1) "Return press :     ";Returnpress
RETURN
"Tabkey":
Tabpress=DIALOG(7)
PRINT @(25,2) "Tab press :        ";Tabpress
RETURN

"Zoomin": REM NEW ROMS ONLY
Zin=DIALOG(8)
WINDOW Zin
PRINT@(1,1) "Thank you for zooming in window";Zin
PRINT @(25,3) "Zoom in window :   ";Zin
RETURN
"Zoomout":
Zout=DIALOG(9)
WINDOW Zout
PRINT@(1,1)"Thank you for zooming out window";Zout
PRINT @(25,4) "Zoom out window :  ";Zout
RETURN
"Shifttab":
CurrentEdit=DIALOG(10)
PRINT @(25,5) "Current Edit Field:";CurrentEdit
RETURN
"Clearkey":
CurrentEdit=DIALOG(11)
PRINT @(25,5) "Current Edit Field:";CurrentEdit
RETURN

"LeftArrow":
CurrentEdit=DIALOG(12)
PRINT @(25,5) "Current Edit Field:";CurrentEdit
RETURN
"RightArrow":
CurrentEdit=DIALOG(13)
PRINT @(25,5) "Current Edit Field:";CurrentEdit
RETURN
"UpArrow":
CurrentEdit=DIALOG(14)
PRINT @(25,5) "Current Edit Field:";CurrentEdit
RETURN
"DownArrow":
CurrentEdit=DIALOG(15)
PRINT @(25,5) "Current Edit Field:";CurrentEdit
RETURN

"Keypress":
ASCIIkey=DIALOG(16)
PRINT @(50,1) "ASCII key pressed :";ASCIIkey;"  "
PRINT @(75,1) " ":PRINT @(75,1) CHR$(ASCIIkey)
RETURN
END
 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Latest Forum Discussions

See All

Top Mobile Game Discounts
Every day, we pick out a curated list of the best mobile discounts on the App Store and post them here. This list won't be comprehensive, but it every game on it is recommended. Feel free to check out the coverage we did on them in the links... | Read more »
Price of Glory unleashes its 1.4 Alpha u...
As much as we all probably dislike Maths as a subject, we do have to hand it to geometry for giving us the good old Hexgrid, home of some of the best strategy games. One such example, Price of Glory, has dropped its 1.4 Alpha update, stocked full... | Read more »
The SLC 2025 kicks off this month to cro...
Ever since the Solo Leveling: Arise Championship 2025 was announced, I have been looking forward to it. The promotional clip they released a month or two back showed crowds going absolutely nuts for the previous competitions, so imagine the... | Read more »
Dive into some early Magicpunk fun as Cr...
Excellent news for fans of steampunk and magic; the Precursor Test for Magicpunk MMORPG Crystal of Atlan opens today. This rather fancy way of saying beta test will remain open until March 5th and is available for PC - boo - and Android devices -... | Read more »
Prepare to get your mind melted as Evang...
If you are a fan of sci-fi shooters and incredibly weird, mind-bending anime series, then you are in for a treat, as Goddess of Victory: Nikke is gearing up for its second collaboration with Evangelion. We were also treated to an upcoming... | Read more »
Square Enix gives with one hand and slap...
We have something of a mixed bag coming over from Square Enix HQ today. Two of their mobile games are revelling in life with new events keeping them alive, whilst another has been thrown onto the ever-growing discard pile Square is building. I... | Read more »
Let the world burn as you have some fest...
It is time to leave the world burning once again as you take a much-needed break from that whole “hero” lark and enjoy some celebrations in Genshin Impact. Version 5.4, Moonlight Amidst Dreams, will see you in Inazuma to attend the Mikawa Flower... | Read more »
Full Moon Over the Abyssal Sea lands on...
Aether Gazer has announced its latest major update, and it is one of the loveliest event names I have ever heard. Full Moon Over the Abyssal Sea is an amazing name, and it comes loaded with two side stories, a new S-grade Modifier, and some fancy... | Read more »
Open your own eatery for all the forest...
Very important question; when you read the title Zoo Restaurant, do you also immediately think of running a restaurant in which you cook Zoo animals as the course? I will just assume yes. Anyway, come June 23rd we will all be able to start up our... | Read more »
Crystal of Atlan opens registration for...
Nuverse was prominently featured in the last month for all the wrong reasons with the USA TikTok debacle, but now it is putting all that behind it and preparing for the Crystal of Atlan beta test. Taking place between February 18th and March 5th,... | Read more »

Price Scanner via MacPrices.net

AT&T is offering a 65% discount on the ne...
AT&T is offering the new iPhone 16e for up to 65% off their monthly finance fee with 36-months of service. No trade-in is required. Discount is applied via monthly bill credits over the 36 month... Read more
Use this code to get a free iPhone 13 at Visi...
For a limited time, use code SWEETDEAL to get a free 128GB iPhone 13 Visible, Verizon’s low-cost wireless cell service, Visible. Deal is valid when you purchase the Visible+ annual plan. Free... Read more
M4 Mac minis on sale for $50-$80 off MSRP at...
B&H Photo has M4 Mac minis in stock and on sale right now for $50 to $80 off Apple’s MSRP, each including free 1-2 day shipping to most US addresses: – M4 Mac mini (16GB/256GB): $549, $50 off... Read more
Buy an iPhone 16 at Boost Mobile and get one...
Boost Mobile, an MVNO using AT&T and T-Mobile’s networks, is offering one year of free Unlimited service with the purchase of any iPhone 16. Purchase the iPhone at standard MSRP, and then choose... Read more
Get an iPhone 15 for only $299 at Boost Mobil...
Boost Mobile, an MVNO using AT&T and T-Mobile’s networks, is offering the 128GB iPhone 15 for $299.99 including service with their Unlimited Premium plan (50GB of premium data, $60/month), or $20... Read more
Unreal Mobile is offering $100 off any new iP...
Unreal Mobile, an MVNO using AT&T and T-Mobile’s networks, is offering a $100 discount on any new iPhone with service. This includes new iPhone 16 models as well as iPhone 15, 14, 13, and SE... Read more
Apple drops prices on clearance iPhone 14 mod...
With today’s introduction of the new iPhone 16e, Apple has discontinued the iPhone 14, 14 Pro, and SE. In response, Apple has dropped prices on unlocked, Certified Refurbished, iPhone 14 models to a... Read more
B&H has 16-inch M4 Max MacBook Pros on sa...
B&H Photo is offering a $360-$410 discount on new 16-inch MacBook Pros with M4 Max CPUs right now. B&H offers free 1-2 day shipping to most US addresses: – 16″ M4 Max MacBook Pro (36GB/1TB/... Read more
Amazon is offering a $100 discount on the M4...
Amazon has the M4 Pro Mac mini discounted $100 off MSRP right now. Shipping is free. Their price is the lowest currently available for this popular mini: – Mac mini M4 Pro (24GB/512GB): $1299, $100... Read more
B&H continues to offer $150-$220 discount...
B&H Photo has 14-inch M4 MacBook Pros on sale for $150-$220 off MSRP. B&H offers free 1-2 day shipping to most US addresses: – 14″ M4 MacBook Pro (16GB/512GB): $1449, $150 off MSRP – 14″ M4... Read more

Jobs Board

All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.