A test program?

A forum for users of EhBASIC (Enhanced BASIC), a portable BASIC interpreter for 6502 microcomputers written by Lee Davison.
User avatar
floobydust
Posts: 1394
Joined: 05 Mar 2013

A test program?

Post by floobydust »

I've recently ported the EhBasic code (2.22p3) over to my C02 Pocket SBC board and have it working, albeit I need to integrate it into the monitor code, get the Xmodem load/save working, etc. However, I was wondering if anyone has some sample BASIC program that can be used to test EhBasic itself. I've never been much of a BASIC programmer but am looking for something that I can use as a loop test for the system.
User avatar
barrym95838
Posts: 2056
Joined: 30 Jun 2013
Location: Sacramento, CA, USA

Re: A test program?

Post by barrym95838 »

What kind of output device is available? If it's a text terminal, how about:

Code: Select all

5 DEF FNA(Z)=30*EXP(-Z*Z/100)
100 PRINT
110 FOR X=-30 TO 30 STEP 1.5
120 L=0
130 Y1=5*INT(SQR(900-X*X)/5)
140 FOR Y=Y1 TO -Y1 STEP -5
150 Z=INT(25+FNA(SQR(X*X+Y*Y))-.7*Y)
160 IF Z<=L THEN 190
170 L=Z
180 PRINT TAB(Z)"*";
190 NEXT Y
200 PRINT
210 NEXT X
300 END
(credit: 101 BASIC Computer Games, D.E.C., 1975)

Mike B.
User avatar
BigEd
Posts: 11463
Joined: 11 Dec 2008
Location: England
Contact:

Re: A test program?

Post by BigEd »

That's nice! I pasted it over serial into a Beeb and it ran unchanged - hidden line removal on the cheap!
User avatar
floobydust
Posts: 1394
Joined: 05 Mar 2013

Re: A test program?

Post by floobydust »

barrym95838 wrote:
What kind of output device is available? If it's a text terminal, how about:

Code: Select all

5 DEF FNA(Z)=30*EXP(-Z*Z/100)
100 PRINT
110 FOR X=-30 TO 30 STEP 1.5
120 L=0
130 Y1=5*INT(SQR(900-X*X)/5)
140 FOR Y=Y1 TO -Y1 STEP -5
150 Z=INT(25+FNA(SQR(X*X+Y*Y))-.7*Y)
160 IF Z<=L THEN 190
170 L=Z
180 PRINT TAB(Z)"*";
190 NEXT Y
200 PRINT
210 NEXT X
300 END
(credit: 101 BASIC Computer Games, D.E.C., 1975)

Mike B.
Thanks Mike,

I just did a copy/paste directly into the serial port terminal window and it entered the entire program in a few seconds 8)
I've been using a native terminal app for OSX called Serial which I prefer over ExtraPutty (which is windoze only). I also added a few extra lines to print a loop count. It seems to work okay.... guess letting it run for an extended period of time will tell. The output is all asterisk characters oddly placed on the screen but each loop of the main program has the same result, so I guess it's correct.

I have had a few errant crashes when either entering a line into EhBasic or trying to RUN the program. It's intermittent so I've not attempted to track it down just yet. I still need to finish the Xmodem upload code for the Monitor, then integrate that into EhBasic's load/save functions, plus integrate launching EhBasic into the Monitor CTRL-? commands.

So far, doing a warm start doesn't work, as you can have a program there which will LIST but won't RUN... so some work to do yet.
User avatar
BigEd
Posts: 11463
Joined: 11 Dec 2008
Location: England
Contact:

Re: A test program?

Post by BigEd »

You could try TAB(Z/2) if your screen isn't very wide. On a 40 col mode it didn't look very impressive but on an 80 col mode I could see the point!
User avatar
floobydust
Posts: 1394
Joined: 05 Mar 2013

Re: A test program?

Post by floobydust »

BigEd wrote:
You could try TAB(Z/2) if your screen isn't very wide. On a 40 col mode it didn't look very impressive but on an 80 col mode I could see the point!
Hi Ed,

Actually, I am using an 80 column wide screen... just not sure what the output should be (meaning I could have an issue with EhBasic). Here's what the output looks like:

Code: Select all

                         *
                     *                 *                *
                  *                *                 *                *                               *
              *                 *                *                 *                *                               *                              *
              *                 *                *                 *                *                               *                              *
              *                 *                *                 *                *                               *                              *
           *  *                 *                *                 *                *                               *                              *                               *
           *  *                 *                 *                *                 *                              *                              *                               *
           *  *                 *                 *                 *                *                              *                              *                               *
       *   *  *                 *                  *                *                 *                             *                              *                               *                              *
       *   *  *                  *                 *                  *                             *                              *                             *                               *                              *
       *   *   *                 *                   *                 *                              *                            *                              *                              *                              *
       *   *   *                  *                    *                  *                             *                             *                              *                              *
       *   *   *                   *                     *                                *                             *                              *                              *
       *   *   *                    *                      *                                  *                            *                              *
       *   *    *                     *                       *                                   *
       *   *    *                      *                         *                                   *
       *   *     *                       *                          *                                    *
       *   *     *                        *                                         *                                                   *
       *   *     *                        *                                           *                                                   *
    *  *   *     *                         *                                          *                                                    *
       *   *     *                        *                                           *                                                   *
       *   *     *                        *                                         *                                                   *
       *   *     *                       *                          *                                    *
       *   *    *                      *                         *                                   *
       *   *    *                     *                       *                                   *
       *   *   *                    *                      *                                  *                            *                              *
       *   *   *                   *                     *                                *                             *                              *                              *
       *   *   *                  *                    *                  *                             *                             *                              *                              *
       *   *   *                 *                   *                 *                              *                            *                              *                              *                              *
       *   *  *                  *                 *                  *                             *                              *                             *                               *                              *
       *   *  *                 *                  *                *                 *                             *                              *                               *                              *
           *  *                 *                 *                 *                *                              *                              *                               *
           *  *                 *                 *                *                 *                              *                              *                               *
           *  *                 *                *                 *                *                               *                              *                               *
              *                 *                *                 *                *                               *                              *
              *                 *                *                 *                *                               *                              *
              *                 *                *                 *                *                               *                              *
                  *                *                 *                *                               *
                     *                 *                *
                         *
I think I have a hint what it's trying to do.... but, not quite correct... hmmmmm...
User avatar
BigEd
Posts: 11463
Joined: 11 Dec 2008
Location: England
Contact:

Re: A test program?

Post by BigEd »

It should look like some overlapping peaks... try TAB(Z/4) or TAB(Z/10) and you'll get the idea, then perhaps you can figure out what's happening. PRINT "X";TAB(4);"X" should print 4 spaces between the Xs, I think.
User avatar
floobydust
Posts: 1394
Joined: 05 Mar 2013

Re: A test program?

Post by floobydust »

Okay, I changed like 180 to:
PRINT TAB(Z/4)"*";
and it printed this:

Code: Select all

      *
     ***
    *****
   *******
   *******
   *******
  *********
  *********
  *********
 ***********
 ***** ******
 **** *******
 *** ** *****
 *** * *****
 *** * * ***
 ** * * * *
 ** * *  * *
 ** * *   * *
 ** *  *  *  *
 ** *  *   * *
 ****  *   * *
 ** *  *   * *
 ** *  *  *  *
 ** * *   * *
 ** * *  * *
 ** * * * *
 *** * * ***
 *** * *****
 *** ** *****
 **** *******
 ***** ******
 ***********
  *********
  *********
  *********
   *******
   *******
   *******
    *****
     ***
      *
Looking at the manual for EhBasic, using the SPC function might be a better option... same output using SPC(Z/4)"*";

Code: Select all

      *
     *      *       *
    *     *      *       *        *
   *    *     *      *       *        *        *
   *    *     *      *       *        *        *
   *    *     *      *       *        *        *
  *   *    *     *      *       *        *        *         *
  *   *    *     *      *       *        *        *         *
  *   *    *     *      *       *        *        *         *
 *  *   *    *     *      *       *        *        *         *          *
 *  *   *    *     *       *       *        *        *         *          *
 *  *   *    *      *       *        *        *         *         *          *
 *  *   *     *      *        *        *         *         *          *
 *  *   *     *       *        *         *         *          *
 *  *   *     *       *         *         *          *
 *  *    *      *        *          *
 *  *    *      *         *           *
 *  *    *      *          *            *
 *  *    *       *          *             *
 *  *    *       *           *             *
 * *  *    *       *           *             *
 *  *    *       *           *             *
 *  *    *       *          *             *
 *  *    *      *          *            *
 *  *    *      *         *           *
 *  *    *      *        *          *
 *  *   *     *       *         *         *          *
 *  *   *     *       *        *         *         *          *
 *  *   *     *      *        *        *         *         *          *
 *  *   *    *      *       *        *        *         *         *          *
 *  *   *    *     *       *       *        *        *         *          *
 *  *   *    *     *      *       *        *        *         *          *
  *   *    *     *      *       *        *        *         *
  *   *    *     *      *       *        *        *         *
  *   *    *     *      *       *        *        *         *
   *    *     *      *       *        *        *
   *    *     *      *       *        *        *
   *    *     *      *       *        *        *
    *     *      *       *        *
     *      *       *
      *
User avatar
BigEd
Posts: 11463
Joined: 11 Dec 2008
Location: England
Contact:

Re: A test program?

Post by BigEd »

Ah, I wonder if your Basic is not tabbing to a specific column but tabbing by some number of spaces... so everything got stretched out.
User avatar
barrym95838
Posts: 2056
Joined: 30 Jun 2013
Location: Sacramento, CA, USA

Re: A test program?

Post by barrym95838 »

Yeah, SPC(Z) isn't the correct choice for this case. The TAB(Z) I know is supposed to keep track of the current output column position P and try to space to the requested column Z, but only if it's to the right of the current one. It'll output (Z-P) spaces, but no "negative" spaces.

Mike B.
User avatar
BigEd
Posts: 11463
Joined: 11 Dec 2008
Location: England
Contact:

Re: A test program?

Post by BigEd »

Here's a snapshot of the Beeb's output for
PRINT "X"TAB(4)"X"TAB(8)"X"
- you'll see the Xs are evenly spaced (and there are only three spaces printed between each pair)
TAB BBC Basic.png
User avatar
barrym95838
Posts: 2056
Joined: 30 Jun 2013
Location: Sacramento, CA, USA

Re: A test program?

Post by barrym95838 »

AppleSoft:
a2tab.JPG
Hmm ... it looks like TAB() treats the leftmost column as column 1, and POS() treats it as column 0.

Mike B.
User avatar
BigEd
Posts: 11463
Joined: 11 Dec 2008
Location: England
Contact:

Re: A test program?

Post by BigEd »

So SPC(Z-POS(0)) instead of TAB(Z) should do the trick?

edit: in BBC Basic, you'd use POS instead of POS(0)
User avatar
barrym95838
Posts: 2056
Joined: 30 Jun 2013
Location: Sacramento, CA, USA

Re: A test program?

Post by barrym95838 »

That or SPC(Z-POS(0)-1) with a risk of crashing if the argument winds up negative.

Mike B.
User avatar
BillO
Posts: 1038
Joined: 12 Dec 2008
Location: Canada

Re: A test program?

Post by BillO »

How about this?

It's been with me so long I don't know who to credit, but the only thing I did was port it to EhBASIC.

Code: Select all

10 MX=20
20 LET C$=" .,'~!^:;[/<&?oxOX#  "
30 FOR Y=-19 TO 19
40 FOR X=-49 TO 30
50 CR=X/30
70 CI=Y/15
80 ZR = CR
90 ZI = CI
95 CO = 1
100 ZM = ZR*ZR
105 ZN = ZI*ZI
107 ZL = ZM+ZN
110 IF ZL>4 THEN GOTO 170
120 ZJ=ZM-ZN+CR
130 ZI=ZR*ZI*2+CI
140 ZR=ZJ
150 CO=CO+1
160 IF CO<MX THEN GOTO 100
170 PRINT MID$(C$,1+COUNT,1);
180 NEXT X
185 PRINT ""
190 NEXT Y
200 GOTO 10
It should print endless Madelbrot sets.
Bill
Post Reply