home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Loadstar 236
/
236.d81
/
t.cookbook
< prev
next >
Wrap
Text File
|
2022-08-26
|
18KB
|
853 lines
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
ch