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

Go from lowly lizard to wicked Wyvern in...
Do you like questing, and do you like dragons? If not then boy is this not the announcement for you, as Loongcheer Game has unveiled Quest Dragon: Idle Mobile Game. Yes, it is amazing Square Enix hasn’t sued them for copyright infringement, but... | Read more »
Aether Gazer unveils Chapter 16 of its m...
After a bit of maintenance, Aether Gazer has released Chapter 16 of its main storyline, titled Night Parade of the Beasts. This big update brings a new character, a special outfit, some special limited-time events, and, of course, an engaging... | Read more »
Challenge those pesky wyverns to a dance...
After recently having you do battle against your foes by wildly flailing Hello Kitty and friends at them, GungHo Online has whipped out another surprising collaboration for Puzzle & Dragons. It is now time to beat your opponents by cha-cha... | Read more »
Pack a magnifying glass and practice you...
Somehow it has already been a year since Torchlight: Infinite launched, and XD Games is celebrating by blending in what sounds like a truly fantastic new update. Fans of Cthulhu rejoice, as Whispering Mist brings some horror elements, and tests... | Read more »
Summon your guild and prepare for war in...
Netmarble is making some pretty big moves with their latest update for Seven Knights Idle Adventure, with a bunch of interesting additions. Two new heroes enter the battle, there are events and bosses abound, and perhaps most interesting, a huge... | Read more »
Make the passage of time your plaything...
While some of us are still waiting for a chance to get our hands on Ash Prime - yes, don’t remind me I could currently buy him this month I’m barely hanging on - Digital Extremes has announced its next anticipated Prime Form for Warframe. Starting... | Read more »
If you can find it and fit through the d...
The holy trinity of amazing company names have come together, to release their equally amazing and adorable mobile game, Hamster Inn. Published by HyperBeard Games, and co-developed by Mum Not Proud and Little Sasquatch Studios, it's time to... | Read more »
Amikin Survival opens for pre-orders on...
Join me on the wonderful trip down the inspiration rabbit hole; much as Palworld seemingly “borrowed” many aspects from the hit Pokemon franchise, it is time for the heavily armed animal survival to also spawn some illegitimate children as Helio... | Read more »
PUBG Mobile teams up with global phenome...
Since launching in 2019, SpyxFamily has exploded to damn near catastrophic popularity, so it was only a matter of time before a mobile game snapped up a collaboration. Enter PUBG Mobile. Until May 12th, players will be able to collect a host of... | Read more »
Embark into the frozen tundra of certain...
Chucklefish, developers of hit action-adventure sandbox game Starbound and owner of one of the cutest logos in gaming, has released their roguelike deck-builder Wildfrost. Created alongside developers Gaziter and Deadpan Games, Wildfrost will... | Read more »

Price Scanner via MacPrices.net

Limited-time sale: 13-inch M3 MacBook Airs fo...
Amazon has the base 13″ M3 MacBook Air (8GB/256GB) in stock and on sale for a limited time for $989 shipped. That’s $110 off MSRP, and it’s the lowest price we’ve seen so far for an M3-powered... Read more
13-inch M2 MacBook Airs in stock today at App...
Apple has 13″ M2 MacBook Airs available for only $849 today in their Certified Refurbished store. These are the cheapest M2-powered MacBooks for sale at Apple. Apple’s one-year warranty is included,... Read more
New today at Apple: Series 9 Watches availabl...
Apple is now offering Certified Refurbished Apple Watch Series 9 models on their online store for up to $80 off MSRP, starting at $339. Each Watch includes Apple’s standard one-year warranty, a new... Read more
The latest Apple iPhone deals from wireless c...
We’ve updated our iPhone Price Tracker with the latest carrier deals on Apple’s iPhone 15 family of smartphones as well as previous models including the iPhone 14, 13, 12, 11, and SE. Use our price... Read more
Boost Mobile will sell you an iPhone 11 for $...
Boost Mobile, an MVNO using AT&T and T-Mobile’s networks, is offering an iPhone 11 for $149.99 when purchased with their $40 Unlimited service plan (12GB of premium data). No trade-in is required... Read more
Free iPhone 15 plus Unlimited service for $60...
Boost Infinite, part of MVNO Boost Mobile using AT&T and T-Mobile’s networks, is offering a free 128GB iPhone 15 for $60 per month including their Unlimited service plan (30GB of premium data).... Read more
$300 off any new iPhone with service at Red P...
Red Pocket Mobile has new Apple iPhones on sale for $300 off MSRP when you switch and open up a new line of service. Red Pocket Mobile is a nationwide MVNO using all the major wireless carrier... Read more
Clearance 13-inch M1 MacBook Airs available a...
Apple has clearance 13″ M1 MacBook Airs, Certified Refurbished, available for $759 for 8-Core CPU/7-Core GPU/256GB models and $929 for 8-Core CPU/8-Core GPU/512GB models. Apple’s one-year warranty is... Read more
Updated Apple MacBook Price Trackers
Our Apple award-winning MacBook Price Trackers are continually updated with the latest information on prices, bundles, and availability for 16″ and 14″ MacBook Pros along with 13″ and 15″ MacBook... Read more
Every model of Apple’s 13-inch M3 MacBook Air...
Best Buy has Apple 13″ MacBook Airs with M3 CPUs in stock and on sale today for $100 off MSRP. Prices start at $999. Their prices are the lowest currently available for new 13″ M3 MacBook Airs among... Read more

Jobs Board

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
DMR Technician - *Apple* /iOS Systems - Haml...
…relevant point-of-need technology self-help aids are available as appropriate. ** Apple Systems Administration** **:** Develops solutions for supporting, deploying, Read more
Omnichannel Associate - *Apple* Blossom Mal...
Omnichannel Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple 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.