• Research Center for Advanced Commodore Study

  • by HowlinAl

Making Tomorrows World Better With Yesterdays Technology Today



For just a taste of DotBASIC Plus, I invite you to follow along with me on this short tutorial.

Here's a short DotBASIC tutorial. I'll show you how easy it is to write a simple menu. I'm going to skip explaining how to create your work disk and instead will plunge right in. Refer to the DotBASIC manual to get you started. For our purposes, just know that when you create your Work Disk, DotBASIC automatically generates the first few lines of your BASIC program -- what happens next is up to you.

I start by telling DB+ that I'll be using these DotCommands.

11 rem.p@,.pc
12 rem.box,.menu
 13 rem.stash,.restr

Save the program with GOTO60000, then LOAD"B.DEV",d and RUN. Anytime during your programming session that you want to add DotCommands, just add the new command to these REM statements and re-run B.DEV. This way, you get all the new DotCommands you need, and nothing else.

Now, let’s get started! In this example, I want to put the menu in a box that has a shadow. This is fairly easy with DB+. But first, change the screen colors to black by modifying the .br and .bg DotCommands in line 40.

     40 .tx,14: print”{clr}”;:.bg,0:.br,0

Note the .tx DotCommand. That stands for -- you guessed it -- Text Color.

Now put the title of the program on the screen and learn another handy DotCommand:

      100 .pc,0,”MY MENU PROGRAM”

Syntax: .PC,Y,STRING$

This DotCommand prints STRING$ centered on row Y.

Next I need a different background. Black does not work well for shadows! I could just change the background color with .BG,color, but that is not fancy enough! I want black – the background color – to be the color of all the text. Sounds confusing, maybe – but hang in there and all will be made clear.  And you’ll learn a neat trick to boot!

Enter this:

102 .box,0,1,40,18,160,1

Let's look at the BOX DotCommand. It's an important one.


.BOX draws a box on the screen with the upper left corner at X,Y, a width of W, and a Height of H. SC stands for Screen Code — usually 32 for a blank screen or 160 for REVERSEd spaces. CO is COlor, of course. If you use 255 for SC, the area is painted with CO. Add 16 to CO to draw a frame around the box. This DotCommand does a lot!

To parse out line 140: the .BOX will extend from column 0, row 1 (thus skipping row 0 and our title) for 40 columns and 18 rows. It will use screen code 160— a REVERSE space — in the color of 1 (white).

Now to put the menu on the screen. This is "in the rough." I just want to find where it will look best.

150 .p@,14,5,"A. Item 1{F7}B. Item 2{F7}E. Exit"

Syntax: .P@,X,Y,STRING$

PRINT AT prints STRING$ at the X/Y screen text cell coordinates. It so happens I have already positioned this text to be centered under the title. But you can easily move it around by changing the two coordinates (X and Y). The {F7}'s are carriage returns to the beginning column on the next line of the PRINT AT. This is a good alternative to using a separate .P@ for each line.

Now that the menu text is positioned correctly, I need to put a box around it.

140 .box,13,4,12,5,160,8

Again, I have already done the calculations. But it is pretty easy to figure out. The left edge of the box is one space to the left of the text. The top is one row above the first line of the menu. Width and Height/Items will depend on what is printed.

I'm making the box in REVERSE space characters (160) in the color Orange (8). I will want the text to also be in REVERSE orange, so I add a line:

141 .tx,8+128

This is why I like the .TX command! Just add 128 to REVERSE the text.

You can run the program at this point if you want. In fact, you can run it after each line is added. And remember, don't forget, do a GOTO60000 often to SAVE your project.

One last thing a shadow. List line 140 and change the line number to 138 and press RETURN. Now LIST 138-140. Edit line 138 by adding 1 to each of the first two values (the upper left corner of the BOX). Then change the color to 15 (light gray), like this:

138 .box,14,5,12,5,160,15

When you run the program now, a shadow appears.

Now the Box that is going to contain the menu items is in place and looks suitably snazzy. The items that make up the menu choices are looking good and they are where they should be. The final step is the .MENU DotCommand that will turn this into a real menu.

Syntax: .MENU,X,Y,W,I,U,H,HK$

This DotCommand turns screen rows defined by you into menu lines. X/Y set the upper left corner of the menu area. W is the width of the menu bar, and I is the number of items. U is the color of unhighlighted items, and H is the color of the highlighted item. HK$ allows us to define “hotkeys”. The number of the menu line the user chooses is returned in SL% (as in SeLection).

Positioning the menu is not hard. Set the X/Y to the place where I printed the first line (“A. Item1”). Set the Width to one less than the width of the Box. Then set I to the number of items in the menu. I’ll also add some ‘hotkeys’ so the user can select the menu items with the keyboard if so desired. So for this menu, enter:

160 .menu,14,5,10,3,8,7,"abe"

8 is the unhighlighted color (to match the box) and 7 is the highlighted color. The hotkeys are listed in a string "abe".

There you go!

I'll fancy this up just a bit more. Enter:

155 .stash,208


I want to have the menu screen come back after a selection is made, so I'll Stash it in a nice safe place in memory. The best two places for screen stashes start at pages 208 and 216 — underneath the I/O.

.MENU returns the item number in SL%. So all I need to do is create an ON-GOSUB to direct the program. When the subroutine returns, I .RESTR (restore)  the screen I stashed at 208, then GOTO line 160.

170 onsl%gosub1000,2000,3000
180 .restr,208
190 goto160

Now, I will do something simple for each menu Item.

1000 .tx,1:print"{clr}Item 1"
1010 .do:.ma:.un l2%orpeek(198)

1020 poke198,0: return
2000 .tx,3:print"{clr}Item 2"
2010 goto1010
3000 .tx,1:.bg,6:.br,14:?"{clr}"
3010 .of:end

Note line 1010. We begin a DO loop. Then we scan the mouse with .MA (Mouse Ask) UNTIL (.UN) a mouse button is clicked (L2%) or a key is pressed (PEEK 198).

You can see how easy it will be to create great programs, listing all the features in the menu. It can also be seen how “modern” looking drop-down menus can be created using .MENU along with .STASH and .RESTR. DotBASIC Plus will take care of the presentation; all you have to do is write the features!

I hope this made a little bit of sense! I also hope more folks like me, who are casual BASIC programmers, will give DotBASIC a try!

Leave a Comment

You must be signed-in to post comments.


wizardnj 1/25/2013

If I get a chance this weekend I will try to follow this tutorial. Thanks for posting it.