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

Fresh From the Land Down Under – The Tou...
After a two week hiatus, we are back with another episode of The TouchArcade Show. Eli is fresh off his trip to Australia, which according to him is very similar to America but more upside down. Also kangaroos all over. Other topics this week... | Read more »
TouchArcade Game of the Week: ‘Dungeon T...
I’m a little conflicted on this week’s pick. Pretty much everyone knows the legend of Dungeon Raid, the match-3 RPG hybrid that took the world by storm way back in 2011. Everyone at the time was obsessed with it, but for whatever reason the... | Read more »
SwitchArcade Round-Up: Reviews Featuring...
Hello gentle readers, and welcome to the SwitchArcade Round-Up for July 19th, 2024. In today’s article, we finish up the week with the unusual appearance of a review. I’ve spent my time with Hot Lap Racing, and I’m ready to give my verdict. After... | Read more »
Draknek Interview: Alan Hazelden on Thin...
Ever since I played my first release from Draknek & Friends years ago, I knew I wanted to sit down with Alan Hazelden and chat about the team, puzzle games, and much more. | Read more »
The Latest ‘Marvel Snap’ OTA Update Buff...
I don’t know about all of you, my fellow Marvel Snap (Free) players, but these days when I see a balance update I find myself clenching my… teeth and bracing for the impact to my decks. They’ve been pretty spicy of late, after all. How will the... | Read more »
‘Honkai Star Rail’ Version 2.4 “Finest D...
HoYoverse just announced the Honkai Star Rail (Free) version 2.4 “Finest Duel Under the Pristine Blue" update alongside a surprising collaboration. Honkai Star Rail 2.4 follows the 2.3 “Farewell, Penacony" update. Read about that here. | Read more »
‘Vampire Survivors+’ on Apple Arcade Wil...
Earlier this month, Apple revealed that poncle’s excellent Vampire Survivors+ () would be heading to Apple Arcade as a new App Store Great. I reached out to poncle to check in on the DLC for Vampire Survivors+ because only the first two DLCs were... | Read more »
Homerun Clash 2: Legends Derby opens for...
Since launching in 2018, Homerun Clash has performed admirably for HAEGIN, racking up 12 million players all eager to prove they could be the next baseball champions. Well, the title will soon be up for grabs again, as Homerun Clash 2: Legends... | Read more »
‘Neverness to Everness’ Is a Free To Pla...
Perfect World Games and Hotta Studio (Tower of Fantasy) announced a new free to play open world RPG in the form of Neverness to Everness a few days ago (via Gematsu). Neverness to Everness has an urban setting, and the two reveal trailers for it... | Read more »
Meditative Puzzler ‘Ouros’ Coming to iOS...
Ouros is a mediative puzzle game from developer Michael Kamm that launched on PC just a couple of months back, and today it has been revealed that the title is now heading to iOS and Android devices next month. Which is good news I say because this... | Read more »

Price Scanner via MacPrices.net

Amazon is still selling 16-inch MacBook Pros...
Prime Day in July is over, but Amazon is still selling 16-inch Apple MacBook Pros for $500-$600 off MSRP. Shipping is free. These are the lowest prices available this weekend for new 16″ Apple... Read more
Walmart continues to sell clearance 13-inch M...
Walmart continues to offer clearance, but new, Apple 13″ M1 MacBook Airs (8GB RAM, 256GB SSD) online for $699, $300 off original MSRP, in Space Gray, Silver, and Gold colors. These are new MacBooks... Read more
Apple is offering steep discounts, up to $600...
Apple has standard-configuration 16″ M3 Max MacBook Pros available, Certified Refurbished, starting at $2969 and ranging up to $600 off MSRP. Each model features a new outer case, shipping is free,... Read more
Save up to $480 with these 14-inch M3 Pro/M3...
Apple has 14″ M3 Pro and M3 Max MacBook Pros in stock today and available, Certified Refurbished, starting at $1699 and ranging up to $480 off MSRP. Each model features a new outer case, shipping is... Read more
Amazon has clearance 9th-generation WiFi iPad...
Amazon has Apple’s 9th generation 10.2″ WiFi iPads on sale for $80-$100 off MSRP, starting only $249. Their prices are the lowest available for new iPads anywhere: – 10″ 64GB WiFi iPad (Space Gray or... Read more
Apple is offering a $50 discount on 2nd-gener...
Apple has Certified Refurbished White and Midnight HomePods available for $249, Certified Refurbished. That’s $50 off MSRP and the lowest price currently available for a full-size Apple HomePod today... Read more
The latest MacBook Pro sale at Amazon: 16-inc...
Amazon is offering instant discounts on 16″ M3 Pro and 16″ M3 Max MacBook Pros ranging up to $400 off MSRP as part of their early July 4th sale. Shipping is free. These are the lowest prices... Read more
14-inch M3 Pro MacBook Pros with 36GB of RAM...
B&H Photo has 14″ M3 Pro MacBook Pros with 36GB of RAM and 512GB or 1TB SSDs in stock today and on sale for $200 off Apple’s MSRP, each including free 1-2 day shipping: – 14″ M3 Pro MacBook Pro (... Read more
14-inch M3 MacBook Pros with 16GB of RAM on s...
B&H Photo has 14″ M3 MacBook Pros with 16GB of RAM and 512GB or 1TB SSDs in stock today and on sale for $150-$200 off Apple’s MSRP, each including free 1-2 day shipping: – 14″ M3 MacBook Pro (... Read more
Amazon is offering $170-$200 discounts on new...
Amazon is offering a $170-$200 discount on every configuration and color of Apple’s M3-powered 15″ MacBook Airs. Prices start at $1129 for models with 8GB of RAM and 256GB of storage: – 15″ M3... Read more

Jobs Board

*Apple* Systems Engineer - Chenega Corporati...
…LLC,** a **Chenega Professional Services** ' company, is looking for a ** Apple Systems Engineer** to support the Information Technology Operations and Maintenance Read more
Solutions Engineer - *Apple* - SHI (United...
**Job Summary** An Apple Solution Engineer's primary role is tosupport SHI customers in their efforts to select, deploy, and manage Apple operating systems and Read more
*Apple* / Mac Administrator - JAMF Pro - Ame...
Amentum is seeking an ** Apple / Mac Administrator - JAMF Pro** to provide support with the Apple Ecosystem to include hardware and software to join our team and Read more
Operations Associate - *Apple* Blossom Mall...
Operations Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Read more
Cashier - *Apple* Blossom Mall - JCPenney (...
Cashier - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Blossom Mall Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.