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

Tokkun Studio unveils alpha trailer for...
We are back on the MMORPG news train, and this time it comes from the sort of international developers Tokkun Studio. They are based in France and Japan, so it counts. Anyway, semantics aside, they have released an alpha trailer for the upcoming... | Read more »
Win a host of exclusive in-game Honor of...
To celebrate its latest Jujutsu Kaisen crossover event, Honor of Kings is offering a bounty of login and achievement rewards kicking off the holiday season early. [Read more] | Read more »
Miraibo GO comes out swinging hard as it...
Having just launched what feels like yesterday, Dreamcube Studio is wasting no time adding events to their open-world survival Miraibo GO. Abyssal Souls arrives relatively in time for the spooky season and brings with it horrifying new partners to... | Read more »
Ditch the heavy binders and high price t...
As fun as the real-world equivalent and the very old Game Boy version are, the Pokemon Trading Card games have historically been received poorly on mobile. It is a very strange and confusing trend, but one that The Pokemon Company is determined to... | Read more »
Peace amongst mobile gamers is now shatt...
Some of the crazy folk tales from gaming have undoubtedly come from the EVE universe. Stories of spying, betrayal, and epic battles have entered history, and now the franchise expands as CCP Games launches EVE Galaxy Conquest, a free-to-play 4x... | Read more »
Lord of Nazarick, the turn-based RPG bas...
Crunchyroll and A PLUS JAPAN have just confirmed that Lord of Nazarick, their turn-based RPG based on the popular OVERLORD anime, is now available for iOS and Android. Starting today at 2PM CET, fans can download the game from Google Play and the... | Read more »
Digital Extremes' recent Devstream...
If you are anything like me you are impatiently waiting for Warframe: 1999 whilst simultaneously cursing the fact Excalibur Prime is permanently Vault locked. To keep us fed during our wait, Digital Extremes hosted a Double Devstream to dish out a... | Read more »
The Frozen Canvas adds a splash of colou...
It is time to grab your gloves and layer up, as Torchlight: Infinite is diving into the frozen tundra in its sixth season. The Frozen Canvas is a colourful new update that brings a stylish flair to the Netherrealm and puts creativity in the... | Read more »
Back When AOL WAS the Internet – The Tou...
In Episode 606 of The TouchArcade Show we kick things off talking about my plans for this weekend, which has resulted in this week’s show being a bit shorter than normal. We also go over some more updates on our Patreon situation, which has been... | Read more »
Creative Assembly's latest mobile p...
The Total War series has been slowly trickling onto mobile, which is a fantastic thing because most, if not all, of them are incredibly great fun. Creative Assembly's latest to get the Feral Interactive treatment into portable form is Total War:... | Read more »

Price Scanner via MacPrices.net

Early Black Friday Deal: Apple’s newly upgrad...
Amazon has Apple 13″ MacBook Airs with M2 CPUs and 16GB of RAM on early Black Friday sale for $200 off MSRP, only $799. Their prices are the lowest currently available for these newly upgraded 13″ M2... Read more
13-inch 8GB M2 MacBook Airs for $749, $250 of...
Best Buy has Apple 13″ MacBook Airs with M2 CPUs and 8GB of RAM in stock and on sale on their online store for $250 off MSRP. Prices start at $749. Their prices are the lowest currently available for... Read more
Amazon is offering an early Black Friday $100...
Amazon is offering early Black Friday discounts on Apple’s new 2024 WiFi iPad minis ranging up to $100 off MSRP, each with free shipping. These are the lowest prices available for new minis anywhere... Read more
Price Drop! Clearance 14-inch M3 MacBook Pros...
Best Buy is offering a $500 discount on clearance 14″ M3 MacBook Pros on their online store this week with prices available starting at only $1099. Prices valid for online orders only, in-store... Read more
Apple AirPods Pro with USB-C on early Black F...
A couple of Apple retailers are offering $70 (28%) discounts on Apple’s AirPods Pro with USB-C (and hearing aid capabilities) this weekend. These are early AirPods Black Friday discounts if you’re... Read more
Price drop! 13-inch M3 MacBook Airs now avail...
With yesterday’s across-the-board MacBook Air upgrade to 16GB of RAM standard, Apple has dropped prices on clearance 13″ 8GB M3 MacBook Airs, Certified Refurbished, to a new low starting at only $829... Read more
Price drop! Apple 15-inch M3 MacBook Airs now...
With yesterday’s release of 15-inch M3 MacBook Airs with 16GB of RAM standard, Apple has dropped prices on clearance Certified Refurbished 15″ 8GB M3 MacBook Airs to a new low starting at only $999.... Read more
Apple has clearance 15-inch M2 MacBook Airs a...
Apple has clearance, Certified Refurbished, 15″ M2 MacBook Airs now available starting at $929 and ranging up to $410 off original MSRP. These are the cheapest 15″ MacBook Airs for sale today at... Read more
Apple drops prices on 13-inch M2 MacBook Airs...
Apple has dropped prices on 13″ M2 MacBook Airs to a new low of only $749 in their Certified Refurbished store. These are the cheapest M2-powered MacBooks for sale at Apple. Apple’s one-year warranty... Read more
Clearance 13-inch M1 MacBook Airs available a...
Apple has clearance 13″ M1 MacBook Airs, Certified Refurbished, now available for $679 for 8-Core CPU/7-Core GPU/256GB models. Apple’s one-year warranty is included, shipping is free, and each... Read more

Jobs Board

Seasonal Cashier - *Apple* Blossom Mall - J...
Seasonal Cashier - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Read more
Seasonal Fine Jewelry Commission Associate -...
…Fine Jewelry Commission Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) Read more
Seasonal Operations Associate - *Apple* Blo...
Seasonal Operations Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Read more
Hair Stylist - *Apple* Blossom Mall - JCPen...
Hair Stylist - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Blossom 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.