home *** CD-ROM | disk | FTP | other *** search
- u
- DotBASIC Cookbook
- by Dave Moorman
-
-
- Here is a "blow by blow" look at
- the COOKBOOK program. Many of these
- routines will help you make really
- snazzy programs with DotBASIC.
-
- We open with the standard DotBASIC
- template:
-
- 10 dv=peek(186):ifdv<8thendv=8
- 11 print"<clr><white>"
- 90 sys4608,224
-
- This SYS initiates the Event
- Driver. 224 is the location of the
- .MED file in memory (pages 224 - 242).
- You can put your .MED files anywhere
- you have 18 free pages. Just change
- this parameter to find it.
-
-
- 100 .do:.ee:.wb:.un e%:.of
- 102 end
-
- The MAIN EVENT DRIVER LOOP. .DO
- begins a Do-Loop. .EE Enables Event
- Driving (which is turned off during
- Event Handling). .WB Waits for BACK
- ARROW. When the <BACK ARROW> is
- pressed, E% becomes -1.
-
- .UN is UNtil E% is not 0. Until
- that happens, the program loops back
- to the .DO command. .OF is OFf,
- turning off all of DotBASIC's exotic
- features.
-
-
- 200 .ru,210,215
- 202 e%=i%*2
- 204 .er
- 206 return
-
-
- The EXIT Event Region is assigned
- line number 200 for Event Handling.
- The .RU command puts an "Are You Sure"
- dialog box on the screen. The colors
- (.RU,unhi,hi) have 208 added to them
- in order to reverse/unreverse the
- Yes/No options.
-
- If NO is selected, I%=0. If YES,
- I%=-1. We put I%*2 into E%. When this
- routine is over and the program
- returns to the Main Loop, E% not
- equaling zero will end the loop and
- stop the program. We put -2 in E% so
- that we can sort between an Exit and a
- <BACK ARROW> Stop.
-
-
- DRAG AND DROP
- -------------
-
- Windows seems to love this
- feature, where you can point and click
- on an object then, holding down the
- mouse button, drag that object
- anywhere on the screen.
-
- Well, we can do it to!
-
- 1000 rem" Drag 'n' Drop
- 1002 .bx,0,39,0,24,32,1
- 1004 poke1024+s,42
-
- This clears the screen with the
- .BX command, and pokes an asterisk
- into screen memory. S will hold the
- position of the asterisk.
-
-
- 1006 :.do
- 1008 :ift<tithen:.bx,0,39,24,24,32,1
-
- The Outer Do-Loop. Line 1008 is
- rather extraneous, clearing a line on
- the screen after a certain time has
- elapsed.
-
- 1010 : :.do
- 1012 : :.ma
- 1014 : :.kp,"_"
- 1016 : :.un i% or l2% or r2%
-
- The Inner Do-Loop. .MA is Mouse
- Ask, which brings mouse information
- into BASIC variables. .KP watches for
- a KeyPress -- in this case, for a BACK
- ARROW.
-
- This loop will continue until one
- of these variables become Not Zero:
-
- I% - The result of .KP
-
- L2% - A new click on the
- left mouse button
-
- R2% - A new click on the
- right mouse button
-
-
- 1018 :if i% or r2% then 1024
- 1020 :c = cx%+40*cy%
- 1022 :if c=s then gosub 1030
- 1024 :.un i% or r2%
- 1026 .er
- 1028 return
-
- When we fall through the .UN, we
- have to sort out which variable did
- it. If I% or r2% are Not Zero, we jump
- to line 1024.
-
- Otherwise, we handle a new left
- click. C holds the location of the
- mouse pointer. (CX% and CY% are
- generated by .MA -- the Character Cell
- X and Y coordinates of the pointer.)
- If C=S, the mouse was clicked over the
- asterisk, so we Gosub to the next
- step, at line 1030
-
- The .UN watches for i% or r2% to
- be Not Zero. If not, we return to the
- Outer Do.
-
- However, if there is a new right
- click or a <BACK ARROW> key press, the
- routine is over. .ER restores the
- Event Screen. RETURN returns to the
- Main Loop.
-
- If you are into Double-clicking,
- here is how it can be done:
-
- 1030 for x= 1 to 20
- 1032 .ma
- 1034 if l2% then x = 99
- 1036 next
- 1038 if x < 100 then 1044
- 1040 .p@,1,24,"Double Click"
- 1042 t = ti + 60
-
- Just wait a bit, checking .MA for
- a new left click. In this code, we put
- the words, "Double Click" on the
- screen, then set the timer to hold it
- for at least a second.
-
- But now for the DRAG code:
-
- 1044 :.do
- 1046 :.ma
- 1048 :c = cx% + 40 * cy%
- 1050 :poke1024+s,32
- 1052 :poke1024+c,42
- 1054 :s=c
- 1056 :.wh l1%
- 1058 return
-
- This Do-Loop uses .WH L1% --
- because we are going to do this loop
- WHile L1% is Not Zero. As long as you
- hold down the left button, L1% will be
- 1.
-
- We update C, turn off the
- asterisk where it was (S), then turn
- it back on at the pointer's location
- (C). We make S=C and we are done.
-
- It you don't like to see the
- asterisk flicker a bit, add this line:
-
- 1049 if c=s then 1056
-
-
- GET DIRECTORY
- -------------
-
- File Requestors are the sign of
- caring coders. Since the GREAT DECREE
- of Fender Tucker in 1992, LOADSTAR
- programs that accessed the disk drive
- give the user a list of files to
- choose from.
-
- Getting the Directory into BASIC
- used to be a real chore. But thanks to
- the Toolboxes of Jeff Jones and now
- Mr.Mouse, we have no excuse for
- leaving the user to:
-
- INPUT FILENAME?
-
- Here is a better way:
-
- 2000 rem" Get Directory I
- 2002 .ss,208
- 2004 .p@,1,24,"eClick rQUITr for
- More"
- *2005 .qs
- *2006 .b$,"$:*",dv,40960,235
- *2007 .qr
- *2008 .ml,5,255,0,20,2,1,7,7,40960,
- t$,b$
- *2009 if w$="" then 2100
- 2010 .bx,0,30,24,24,32,1
- 2012 .p@,1,24,"File: "+f$
- 2014 .do:.ma:.un l2% or peek(198)
- 2016 poke198,0
- 2018 .er
- 2020 return
-
- The essential Requestor requires
- just five lines. In 2006, we bload the
- directory to memory under ROM. Note
- the .QS command just before the .B$.
- Anytime you do disk access, it is more
- than a good idea to turn off the IRQ
- routines used by DotBASIC. .QS is irQ
- Suspend. In line 2007, we use .QR --
- irQ Restore.
-
- Line 2008 puts the data into a
- scrolling menu. Line 2008 checks to
- see if a file was selected.
-
- The .B$ command asks for the
- directory ("$:*"), and you can include
- any search characters.
-
- On drive DV
- To location 40960 (page 160)
- With 235 directory items.
-
- Limiting the number of directory
- entries keeps the file from over-
- running available memory. A 16K chunk
- of memory can hold 255 directory
- lines.
-
- Here is the .ML (Menu scrolL)
- command:
-
- .ML,X1,X2,Y1,Y2,BX,IC,U,H,L,T$,B$
-
- X1 - left column
- X2 - right column
- Y1 - top row
- Y2 - bottom row
-
- of the menu box. If X2 is 255, the
- box is automatically the width of a
- file requestor. Then the colors are
- set
-
- BX - Box
- IC - Icon ("Home", etc)
- U - Unhighlighted items
- H - Hightlighted item
-
- The L parameter is the Location of
- the data in memory. We will look at
- this later. In a simple case, L = the
- location where you bloaded the file.
-
- T$ and B$ are texts that will
- appear at the top and bottom of the
- menu. When a .B$ is performed, T$
- holds the Disk Name and B$ holds the
- Blocks Free information.
-
- When the user selects, the whole
- line chosen is returned in W$. The
- filename itself is returned in F$
-
-
- GET DIRECTORY II
- ----------------
-
- Showing the whole directory line
- may not be the style you want. Here is
- how to display only the filenames.
-
- 2100 rem" Get Directory II
- 2102 .sr,208
- 2104 .p@,1,24,"eClick rQUITr for
- More"
- *2106 .qs:.b$,"$:*",dv,40960,235:.qr
- *2108 .rk,40960
- *2110 .$l,40960
- *2112 for x = 1 to n%
- *2114 .ri,x
- *2116 .$p,f$
- *2118 next
- *2120 .rk,40960
- *2122 .ml,10,28,5,15,3,1,7,7,0,"",""
- *2124 if w$="" then 2200
- 2126 f$=w$
- 2128 goto2010
-
- Again, the essential lines are
- marked with asterisks. In this case,
- we RACK the data in line 2108. This
- turns the data into a virtual string
- array!
-
- Then, in 2110, we set a location
- where will Put strings into memory.
- In this case, we will put our strings
- right on top of the original data,
- since the data we are creating will
- not be longer than the orginal.
-
- With a FOR-NEXT loop, we .RI (Rack
- Index) each line of the data, then .$P
- (String Put) the Filename into the
- data block we are creating. The .$P
- command copies the string to memory,
- beginning with the location set with
- .$L. Each string follows the previous
- one.
-
- When finished building our data
- block, we .RK (RacK) it again. We now
- have the Filenames ready for a
- scrolling menu.
-
- NOTE: In this .ML command, we set
- the LOCATION to 0. We have already
- Racked the data, so we do not have to
- do it again for the scrolling menu.
-
-
- 2200 rem" Sort!
- *2202 .az,1
- *2204 .ml,10,28,5,15,3,1,7,7,0,"",""
- 2206 ifw$=""then2300
- 2208 f$=w$
- 2210 goto2010
-
- We can automatically SORT the
- filenames with the .AZ command. The
- parameter is the position of the first
- character to be used in the sort.
-
-
- SEARCHING FOR STRINGS
- ---------------------
-
- One weakness of C=DOS is that the
- directory cannot be limited to a
- single extension (such as .MED in this
- case. DotBASIC gives you the tools to
- search for any string within the
- filenames, and build a custom file
- requestor.
-
- 2300 rem" Directory of .med files
- 2302 .sr,208
- *2304 .qs:.b$,"$:*",dv,40960,235:.qr
- *2306 .rk,40960
- *2308 .$l,40960
- *2310 y=0
- *2312 forx=1ton%
- *2314 .ri,x
- *2316 .$i,".med",f$
- *2318 if i% then:.$p,w$:y=1
- *2320 next
- *2322 ify=0then2350
- *2324 .rk,40960
- *2326 .ml,5,255,0,20,1,2,3,4,0,t$,b$
- 2328 .er
- 2330 return
-
-
- The lines with asterisks do the
- work. Note that this is very similar
- to collecting just the filenames
- above. The difference is line 2316.
-
- The .$I is the INSTRING command,
- searching for the first given
- string in the second string variable.
- The position of the search string
- characters in the target string is
- returned in I% (0 if not found). So,
- if the search string was found, we
- know it in line 2318, and .$P,W$ into
- our new data block. We use Y to
- indicate if any searches were
- successful.
-
- Then we Rack and put the results
- in a scrolling menu.
-
- What you do with the requested
- files is your problem!
-
-
- DISABLED REGIONS
- ----------------
-
- The Event Driver for DotBASIC is
- pretty basic. It always changes the
- colors of the Event Regions when
- rolled-over. You can change colors at
- run-time, but what about situations
- where you want to do things completely
- differently.
-
- Here is some code that does the
- same thing as the Event Driver, but
- with the Driver turned off. For some
- programs, you may want to abandon
- Event Driving all together. DotBASIC
- certainly has enough commands to do
- the work right out in front where you
- can control it.
-
- 3000 rem" Disable Regions
- 3002 og=4
- 3004 for x = 2 to 4
- 3006 .ra,x,255,4
- 3008 next
- *3010 .do
- *3012 .ma
- *3014 .kp,"e1234567_"
- *3016 if i%=9then i%=-1:goto3032
- *3018 if i% then l2%=1:og=i%:goto3032
- 3020 if rg%>1 and rg%<5 then3032
- 3022 if og>1andog<5then3028
- *3024 if rg%=og then3032
- *3026 .ra,og,255,1
- *3028 .ra,rg%,255,7
- *3030 og=rg%
- *3032 .un l2% or i%=-1
- *3034 ifi%=-1thene%=i%:.er:return
- 3036 if og=1then3060
- 3038 if og<5 then3010
- *3040 .ss,232
- *3042 onog-4gosub4000,5200,6000,7000
- 3044 ifog=5thenreturn
- *3046 goto3010
- 3060 .ss,232:gosub200
- 3070 ifi%thenreturn
- 3072 goto3010
-
- The essential code is again
- marked. We use the Do-Loop, .MA, and
- .KP to get input. OG is the Old
- reGion, used to unhighlight regions
- when the pointer moves off.
-
- The rest of the code turns off
- regions 2, 3, and 4. Might be useful!
-
- 4000 rem" Re-enable
- 4002 forx=2to4
- 4006 .ra,x,255,1
- 4008 next
- 4010 return
-
- This code just undoes what Disable
- did -- mostly by just RETURNing to the
- Event Driver Main Loop.
-
-
- DISABLE EVENTS
- --------------
-
- Here is another way to manage your
- own Event driving.
-
- 5000 rem" Disable Events
- 5002 og=6:de=abs(de-1):
- ifde=0thenreturn
-
- DE marks Disabled Events. When it
- toggles back to 0, the following code
- is ignored.
-
-
- 5004 forx=1to8:uc(x)=210:
- hc(x)=215:next
- 5005 uc(4)=1:hc(4)=1:uc(5)=1:hc(5)=1
-
- Here we set up the Unhighlighted
- and Highlighted colors for each
- region.
-
-
- 5006 .ss,208
-
- Screen Stash the current screen to
- page 208 (under I/O).
-
-
- 5008 .ra,og,255,hc(og)
-
- OG holds the Old reGion. Here we
- turn it to the Highlighted color.
-
-
- 5010 .do
- 5012 .ma
- 5014 .kp,"e1234567_"
- 5016 if i%=9then i%=-1:goto5032
- 5018 if i% then l2%=1:og=i%:goto5032
- 5024 if rg%=og then5032
- 5026 .ra,og,255,uc(og)
- 5028 .ra,rg%,255,hc(rg%)
- 5030 og=rg%
- 5032 .un l2% or i%=-1
-
- Our Do-Loop. Since all the color
- codes are in arrays, it is much
- simpler than above.
-
-
- 5034 ifi%=-1thene%=i%:.er:return
- 5036 if og=1then5060
- 5040 .ss,232
- 5041 ifog=0thenog=1
- *5042 onog-1gosub 1000, 2000, 5200,
- 5200, 5000, 6000, 7000
- 5044 ifde=0then5100
- 5046 goto5010
-
- To disable events, we simply send
- the program to line 5200, which is a
- RETURN. Nothing happens.
-
- 5060 .ss,232:gosub200
- 5070 ifi%thenreturn
- 5072 goto5010
- 5100 .sr,208
- 5104 return
- 5200 return
-
- As you will see as you run this
- program, all is not yet well with the
- Event or Region disabling code. The
- ideas are sound. My implimentation has
- fallen short. The darn computer is
- doing exactly what I tell it to do,
- not what I want it to do.
-
- Which only goes to show that even
- DotBASIC does not read minds! Someone
- needs to sit down and work out how to
- best accomplish these tasks. You have
- the essential code!
-
-
- DIALOG BOXES
- ------------
-
- If you are creating an elegant
- program, you will need to "visit" with
- your user. Lines 6500-6818 will
- produce three kinds of Dialogs
-
- OK
- Yes/No
- THREE CHOICES
-
-
- 6000 rem" Dialog Boxes
- 6002 w$="This a Message Box"
- 6004 bc=3
- 6006 hc=7
- 6008 ty=1
- 6010 gosub6500
-
- Put the message in W$. Set the Box
- Color (BC), the Highlight Color (HC),
- and choose the Type (TY). TY will
- equal the number of responses you want
- to give your user.
-
-
- 6020 w$="This is a Message Box"
- 6022 bc=7
- 6024 hc=3
- 6026 ty=1
- 6028 gosub6500
-
- We included this to show that
- messages with even or odd lengths
- still looked good.
-
-
- 6030 w$="Do You Like This?"
- 6032 bc=14
- 6034 hc=6
- 6036 ty=2
- 6038 gosub6500
-
- Here is a Yes/No box, followed by
- an OK box to show the response to the
- Yes/No box.
-
- 6040 a$="No.":ifi%thena$="Yes."
- 6042 w$="You Chose "+a$
- 6044 bc=7
- 6046 hc=3
- 6048 ty=1
- 6050 gosub6500
-
- Then a Yes/No to see if the user
- wants to try again.
-
- 6052 w$="Try Again?"
- 6054 ty=2
- 6056 gosub6500
- 6058 if i% then 6030
-
-
- 6060 w$="Now Choose Between:"
- 6062 a1$="Validate"
- 6064 a2$="Extricate"
- 6066 a3$="Pontificate"
- 6068 bc=4
- 6070 hc=3
- 6072 ty=3:hk$="vep"
- 6074 gosub6500
-
- For the THREE CHOICE box, you must
- give the three choices and set HK$ to
- the hotkeys for each choice. HK$=""
- disables any hotkey control.
-
- 6076 a$=a1$
- 6078 ifsl%=2 then a$=a2$
- 6080 ifsl%=3 then a$=a3$
- 6082 w$="You Chose "+a$
- 6084 bc=7
- 6086 hc=3
- 6088 ty=1
- 6090 gosub6500
- 6092 w$="Try Again?"
- 6094 ty=2
- 6096 gosub6500
- 6098 if i% then6060
- 6100 w$="Good Bye"
- 6102 bc=14
- 6104 hc=7
- 6106 ty=1
- 6108 gosub6500
- 6110 .er
- 6112 return
-
- This code just displays the choice
- and asks if the user wants to try
- again. If not, it says "Good Bye" in
- an OK box.
-
-
- Now we get to the Message Box
- routine itself. You can look through
- it if you want. Or just copy it to
- your own programs! That's what
- Cookbooks are for.
-
- 6500 .ss,216
- 6502 x=0
- 6504 w=len(w$)/2
- 6508 if ty=3 then gosub 6550
- 6510 x1=19-w
- 6512 x2=20+w
-
- The width of the box is wide
- enough to hold W$.
-
- 6514 .bx,x1,x2,5,9,160,bc
- 6516 .tx,bc+128
- 6518 print"<rev>";
- 6520 .pc,6,w$
-
- This is fairly standard code. Once
- a reverse box is drawn, set the color
- to the same as the box using .TX,BC --
- with +128 to REVERSE the characters.
-
- 6522 on ty gosub 6600,6700,6800
- 6524 .sr,216
- 6526 return
-
-
- 6550 a1=len(a1$)
- 6552 a2=len(a2$)
- 6554 a3=len(a3$)
- 6556 x=(a1+a2+a3+2)/2
- 6558 ifx>w then w=x
- 6560 y1=20-x
- 6562 return
-
- This code makes sure the box is
- wide enough for all three answers.
-
- 6600 .p1,646,hc
- 6602 print
- 6604 poke198,0
- 6606 .pc,8,"OK"
- 6608 .do
- 6610 .ma
- 6612 .un l2% or peek(198)
- 6614 poke198,0
- 6616 return
-
- The OK response.
-
- 6700 .yn,17,8,bc+208,hc+208
- 6702 return
-
- The Yes/No response uses the
- YES/NO command. Easy, huh!
-
- 6800 y2=y1+a1-1
- 6802 y3=y2+2
- 6804 y4=y3+a2-1
- 6806 y5=y4+2
- 6808 y6=y5+a3-1
- 6810 .p@,y1,8,a1$
- 6812 .p@,y3,8,a2$
- 6814 .p@,y5,8,a3$
- 6816 .mz, 3, y1, y2, y3, y4, y5, y6,
- 8, 8, bc, hc, hk$
- 6818 return
-
- .MZ is a multi-column menu put
- into service to present the three
- choices.
-
-
- RIGHT CLICKING
- --------------
-
- When you assign Right Click to an
- Event Region in VDOt, the right click
- event is given its own Event Handling
- line number, which is 256 larger than
- the left click's Event Handling line
- number. Lines 7000 and 7256 show this
- off.
-
- 7000 w$="You LEFT CLICKED"
- 7002 bc=8
- 7004 hc=7
- 7006 ty=1
- 7008 gosub6500
- 7010 .er
- 7012 return
-
- 7256 w$="You RIGHT CLICKED"
- 7258 goto7002
-
-
- DRIVE ACCESS
- ------------
-
- This was a last minute addition to
- this Cookbook. If you are doing File
- Requesting, you should give your user
- the chance to pick which drive. This
- code polls all active drives between 8
- and 15 and puts them into a menu.
-
- 8000 rem" Get Disk Drive
- 8001 dd=dv
- 8002 ifdkthen8013
-
- DK is the Drive Kount. If it is
- not zero, the drives have already been
- polled.
-
- 8004 .qs:close2
- 8006 forx=8to18
- 8008 open2,x,2:close2
- 8010 ifst=0thendk=dk+1:d%(dk)=x
- 8012 next:.qr:poke186,dd
-
- This code polls the drives to see
- if they are active. Note, the current
- drive information at location 186 is
- changed by this routine. POKE186,DD
- returns it to the base drive.
-
- 8013 .ss,208
- 8014 .bx,0,5,0,3+dk,160,8
- 8016 .p1,646,8
- 8018 .p@,1,1,"rDisk"
- 8020 forx=1todk
- 8022 .p@,1,2+x,str$(d%(x))
- 8024 next
- 8026 .mu,2,4,3,2+dk,8,1,""
-
- This makes a proportioned menu of
- the drive numbers.
-
- 8027 .sr,208
- 8028 ifsl%=0then8048
- 8030 dv=d%(sl%)
- -8032 w$="Your Disk is"+str$(dv)
- -8034 ty=1
- -8036 bc=8
- -8038 hc=1
- -8040 gosub6500
- -8042 dv=dd
- -8044 w$="Now it is"+str$(dv)
- -8046 gosub6500
- 8048 .er:return
-
- You will certainly want to do more
- than just announce the results.
-
-
- SUMMARY
- -------
-
- DotBASIC is incredibly powerful.
- If you have only a little experience
- with BASIC 2.0, you should find
- DotBASIC the perfect way to add
- pazzazz without a lot of skull sweat!
-
- Print this out, along with the
- DotBASIC Command Summary, and step
- through the COOKBOOK program to see
- what is happening.
-
- DMM
-
-
-