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

  1. u
  2.           DotBASIC Cookbook
  3.            by Dave Moorman
  4.  
  5.  
  6.     Here is a "blow by blow" look at
  7. the COOKBOOK program. Many of these
  8. routines will help you make really
  9. snazzy programs with DotBASIC.
  10.  
  11.     We open with the standard DotBASIC
  12. template:
  13.  
  14.  10 dv=peek(186):ifdv<8thendv=8
  15.  11 print"<clr><white>"
  16.  90 sys4608,224
  17.  
  18.     This SYS initiates the Event
  19. Driver. 224 is the location of the
  20. .MED file in memory (pages 224 - 242).
  21. You can put your .MED files anywhere
  22. you have 18 free pages. Just change
  23. this parameter to find it.
  24.  
  25.  
  26.  100 .do:.ee:.wb:.un e%:.of
  27.  102 end
  28.  
  29.     The MAIN EVENT DRIVER LOOP. .DO
  30. begins a Do-Loop. .EE Enables Event
  31. Driving (which is turned off during
  32. Event Handling). .WB Waits for BACK
  33. ARROW. When the <BACK ARROW> is
  34. pressed, E% becomes -1.
  35.  
  36.     .UN is UNtil E% is not 0. Until
  37. that happens, the program loops back
  38. to the .DO command. .OF is OFf,
  39. turning off all of DotBASIC's exotic
  40. features.
  41.  
  42.  
  43.  200 .ru,210,215
  44.  202 e%=i%*2
  45.  204 .er
  46.  206 return
  47.  
  48.  
  49.     The EXIT Event Region is assigned
  50. line number 200 for Event Handling.
  51. The .RU command puts an "Are You Sure"
  52. dialog box on the screen. The colors
  53. (.RU,unhi,hi) have 208 added to them
  54. in order to reverse/unreverse the
  55. Yes/No options.
  56.  
  57.     If NO is selected, I%=0. If YES,
  58. I%=-1. We put I%*2 into E%. When this
  59. routine is over and the program
  60. returns to the Main Loop, E% not
  61. equaling zero will end the loop and
  62. stop the program. We put -2 in E% so
  63. that we can sort between an Exit and a
  64. <BACK ARROW> Stop.
  65.  
  66.  
  67. DRAG AND DROP
  68. -------------
  69.  
  70.     Windows seems to love this
  71. feature, where you can point and click
  72. on an object then, holding down the
  73. mouse button, drag that object
  74. anywhere on the screen.
  75.  
  76.     Well, we can do it to!
  77.  
  78.  1000 rem"  Drag 'n' Drop
  79.  1002 .bx,0,39,0,24,32,1
  80.  1004 poke1024+s,42
  81.  
  82.     This clears the screen with the
  83. .BX command, and pokes an asterisk
  84. into screen memory. S will hold the
  85. position of the asterisk.
  86.  
  87.  
  88.  1006 :.do
  89.  1008 :ift<tithen:.bx,0,39,24,24,32,1
  90.  
  91.     The Outer Do-Loop. Line 1008 is
  92. rather extraneous, clearing a line on
  93. the screen after a certain time has
  94. elapsed.
  95.  
  96.  1010 :  :.do
  97.  1012 :  :.ma
  98.  1014 :  :.kp,"_"
  99.  1016 :  :.un i% or l2% or r2%
  100.  
  101.     The Inner Do-Loop. .MA is Mouse
  102. Ask, which brings mouse information
  103. into BASIC variables. .KP watches for
  104. a KeyPress -- in this case, for a BACK
  105. ARROW.
  106.  
  107.     This loop will continue until one
  108. of these variables become Not Zero:
  109.  
  110.         I%  - The result of .KP
  111.  
  112.         L2% - A new click on the
  113.               left mouse button
  114.  
  115.         R2% - A new click on the
  116.               right mouse button
  117.  
  118.  
  119.  1018 :if i% or r2% then 1024
  120.  1020 :c = cx%+40*cy%
  121.  1022 :if c=s then gosub 1030
  122.  1024 :.un i% or r2%
  123.  1026 .er
  124.  1028 return
  125.  
  126.     When we fall through the .UN, we
  127. have to sort out which variable did
  128. it. If I% or r2% are Not Zero, we jump
  129. to line 1024.
  130.  
  131.     Otherwise, we handle a new left
  132. click. C holds the location of the
  133. mouse pointer. (CX% and CY% are
  134. generated by .MA -- the Character Cell
  135. X and Y coordinates of the pointer.)
  136. If C=S, the mouse was clicked over the
  137. asterisk, so we Gosub to the next
  138. step, at line 1030
  139.  
  140.     The .UN watches for i% or r2% to
  141. be Not Zero. If not, we return to the
  142. Outer Do.
  143.  
  144.     However, if there is a new right
  145. click or a <BACK ARROW> key press, the
  146. routine is over. .ER restores the
  147. Event Screen. RETURN returns to the
  148. Main Loop.
  149.  
  150.     If you are into Double-clicking,
  151. here is how it can be done:
  152.  
  153.  1030 for x= 1 to 20
  154.  1032 .ma
  155.  1034 if l2% then x = 99
  156.  1036 next
  157.  1038 if x < 100 then 1044
  158.  1040 .p@,1,24,"Double Click"
  159.  1042 t = ti + 60
  160.  
  161.     Just wait a bit, checking .MA for
  162. a new left click. In this code, we put
  163. the words, "Double Click" on the
  164. screen, then set the timer to hold it
  165. for at least a second.
  166.  
  167.     But now for the DRAG code:
  168.  
  169.  1044 :.do
  170.  1046 :.ma
  171.  1048 :c = cx% + 40 * cy%
  172.  1050 :poke1024+s,32
  173.  1052 :poke1024+c,42
  174.  1054 :s=c
  175.  1056 :.wh l1%
  176.  1058 return
  177.  
  178.     This Do-Loop uses .WH L1% --
  179. because we are going to do this loop
  180. WHile L1% is Not Zero. As long as you
  181. hold down the left button, L1% will be
  182. 1.
  183.  
  184.     We update C, turn off the
  185. asterisk where it was (S), then turn
  186. it back on at the pointer's location
  187. (C). We make S=C and we are done.
  188.  
  189.     It you don't like to see the
  190. asterisk flicker a bit, add this line:
  191.  
  192.  1049 if c=s then 1056
  193.  
  194.  
  195. GET DIRECTORY
  196. -------------
  197.  
  198.     File Requestors are the sign of
  199. caring coders. Since the GREAT DECREE
  200. of Fender Tucker in 1992, LOADSTAR
  201. programs that accessed the disk drive
  202. give the user a list of files to
  203. choose from.
  204.  
  205.     Getting the Directory into BASIC
  206. used to be a real chore. But thanks to
  207. the Toolboxes of Jeff Jones and now
  208. Mr.Mouse, we have no excuse for
  209. leaving the user to:
  210.  
  211.         INPUT FILENAME?
  212.  
  213.     Here is a better way:
  214.  
  215.  2000 rem"     Get Directory I
  216.  2002 .ss,208
  217.  2004 .p@,1,24,"eClick rQUITr for
  218.       More"
  219. *2005 .qs
  220. *2006 .b$,"$:*",dv,40960,235
  221. *2007 .qr
  222. *2008 .ml,5,255,0,20,2,1,7,7,40960,
  223.       t$,b$
  224. *2009 if w$="" then 2100
  225.  2010 .bx,0,30,24,24,32,1
  226.  2012 .p@,1,24,"File: "+f$
  227.  2014 .do:.ma:.un l2% or peek(198)
  228.  2016 poke198,0
  229.  2018 .er
  230.  2020 return
  231.  
  232.     The essential Requestor requires
  233. just five lines. In 2006, we bload the
  234. directory to memory under ROM. Note
  235. the .QS command just before the .B$.
  236. Anytime you do disk access, it is more
  237. than a good idea to turn off the IRQ
  238. routines used by DotBASIC. .QS is irQ
  239. Suspend. In line 2007, we use .QR --
  240. irQ Restore.
  241.  
  242.     Line 2008 puts the data into a
  243. scrolling menu. Line 2008 checks to
  244. see if a file was selected.
  245.  
  246.     The .B$ command asks for the
  247. directory ("$:*"), and you can include
  248. any search characters.
  249.  
  250.     On drive DV
  251.     To location 40960 (page 160)
  252.     With 235 directory items.
  253.  
  254.     Limiting the number of directory
  255. entries keeps the file from over-
  256. running available memory. A 16K chunk
  257. of memory can hold 255 directory
  258. lines.
  259.  
  260.     Here is the .ML (Menu scrolL)
  261. command:
  262.  
  263.  .ML,X1,X2,Y1,Y2,BX,IC,U,H,L,T$,B$
  264.  
  265.     X1 - left column
  266.     X2 - right column
  267.     Y1 - top row
  268.     Y2 - bottom row
  269.  
  270.  of the menu box. If X2 is 255, the
  271. box is automatically the width of a
  272. file requestor. Then the colors are
  273. set
  274.  
  275.     BX - Box
  276.     IC - Icon ("Home", etc)
  277.     U  - Unhighlighted items
  278.     H  - Hightlighted item
  279.  
  280.     The L parameter is the Location of
  281. the data in memory. We will look at
  282. this later. In a simple case, L = the
  283. location where you bloaded the file.
  284.  
  285.     T$ and B$ are texts that will
  286. appear at the top and bottom of the
  287. menu. When a .B$ is performed, T$
  288. holds the Disk Name and B$ holds the
  289. Blocks Free information.
  290.  
  291.     When the user selects, the whole
  292. line chosen is returned in W$. The
  293. filename itself is returned in F$
  294.  
  295.  
  296. GET DIRECTORY II
  297. ----------------
  298.  
  299.     Showing the whole directory line
  300. may not be the style you want. Here is
  301. how to display only the filenames.
  302.  
  303.  2100 rem"     Get Directory II
  304.  2102 .sr,208
  305.  2104 .p@,1,24,"eClick rQUITr for
  306.       More"
  307. *2106 .qs:.b$,"$:*",dv,40960,235:.qr
  308. *2108 .rk,40960
  309. *2110 .$l,40960
  310. *2112 for x = 1 to n%
  311. *2114 .ri,x
  312. *2116 .$p,f$
  313. *2118 next
  314. *2120 .rk,40960
  315. *2122 .ml,10,28,5,15,3,1,7,7,0,"",""
  316. *2124 if w$="" then 2200
  317.  2126 f$=w$
  318.  2128 goto2010
  319.  
  320.     Again, the essential lines are
  321. marked with asterisks. In this case,
  322. we RACK the data in line 2108. This
  323. turns the data into a virtual string
  324. array!
  325.  
  326.     Then, in 2110, we set a location
  327. where will Put strings into memory.
  328. In this case, we will put our strings
  329. right on top of the original data,
  330. since the data we are creating will
  331. not be longer than the orginal.
  332.  
  333.     With a FOR-NEXT loop, we .RI (Rack
  334. Index) each line of the data, then .$P
  335. (String Put) the Filename into the
  336. data block we are creating. The .$P
  337. command copies the string to memory,
  338. beginning with the location set with
  339. .$L. Each string follows the previous
  340. one.
  341.  
  342.     When finished building our data
  343. block, we .RK (RacK) it again. We now
  344. have the Filenames ready for a
  345. scrolling menu.
  346.  
  347.     NOTE: In this .ML command, we set
  348. the LOCATION to 0. We have already
  349. Racked the data, so we do not have to
  350. do it again for the scrolling menu.
  351.  
  352.  
  353.  2200 rem"     Sort!
  354. *2202 .az,1
  355. *2204 .ml,10,28,5,15,3,1,7,7,0,"",""
  356.  2206 ifw$=""then2300
  357.  2208 f$=w$
  358.  2210 goto2010
  359.  
  360.     We can automatically SORT the
  361. filenames with the .AZ command. The
  362. parameter is the position of the first
  363. ch