6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Thu Nov 21, 2024 9:52 am

All times are UTC




Post new topic Reply to topic  [ 53 posts ]  Go to page Previous  1, 2, 3, 4  Next
Author Message
 Post subject: Re: A test program?
PostPosted: Wed Jun 20, 2018 5:30 am 
Offline
User avatar

Joined: Sun Jun 30, 2013 10:26 pm
Posts: 1949
Location: Sacramento, CA, USA
Hey, pretty nice Bill! It happens to print out exactly 80 columns, so it looked like it was "double-spaced" in 80-column Applesoft, but eliminating line 185 did the trick for my case. It reminds me of the one Martin_H was playing around with in Forth.

Mike B.


Top
 Profile  
Reply with quote  
 Post subject: Re: A test program?
PostPosted: Wed Jun 20, 2018 6:01 am 
Offline
User avatar

Joined: Fri Dec 12, 2008 10:40 pm
Posts: 1007
Location: Canada
Line 185 works for me since my normal Tera Term set up is for 132 columns.

In any case, this is my standard EhBASIC test program. It may not execute every command in BASIC, but it does enough in terms of 6502 instructions.

I was going to add some optimizations - but I've been "going to do that" for quite a while. :roll:

_________________
Bill


Top
 Profile  
Reply with quote  
 Post subject: Re: A test program?
PostPosted: Wed Jun 20, 2018 10:14 am 
Offline

Joined: Thu Mar 10, 2016 4:33 am
Posts: 181
I've got OSI Basic running on a 65C816, it gives the output below. I didn't need to change the code at all. I typed it in rather than pasting it, just like old times. Once I'd fixed my typing mistakes it ran fine. Should be the same for all Microsoft basics, I did have some trouble running programs from 101 Basic Computer Games as that DEC basic was a bit different.

Code:
RUN

                         *
                     *   *  *
                  *  *   *  *   *
              *   *  *   *  *   *  *
              *   *  *   *  *   *  *
              *   *  *   *  *   *  *
           *  *   *  *   *  *   *  *   *
           *  *   *   *  *   *  *  *   *
           *  *   *   *   *  *  *  *   *
       *   *  *   *    *  *   * *  *   *  *
       *   *  *    *   *    * *  * *   *  *
       *   *   *   *     *   *  **  *  *  *
       *   *   *    *      *    * * *  *  *
       *   *   *     *       *    * *  *  *
       *   *   *      *        *      **  *
       *   *    *       *         *       *
       *   *    *        *           *       *
       *   *     *         *            *        *
       *   *     *          *             *         *
       *   *     *          *               *         *
    *  *   *     *           *              *          *
       *   *     *          *               *         *
       *   *     *          *             *         *
       *   *     *         *            *        *
       *   *    *        *           *       *
       *   *    *       *         *       *
       *   *   *      *        *      **  *
       *   *   *     *       *    * *  *  *
       *   *   *    *      *    * * *  *  *
       *   *   *   *     *   *  **  *  *  *
       *   *  *    *   *    * *  * *   *  *
       *   *  *   *    *  *   * *  *   *  *
           *  *   *   *   *  *  *  *   *
           *  *   *   *  *   *  *  *   *
           *  *   *  *   *  *   *  *   *
              *   *  *   *  *   *  *
              *   *  *   *  *   *  *
              *   *  *   *  *   *  *
                  *  *   *  *   *
                     *   *  *
                         *

OK


Top
 Profile  
Reply with quote  
 Post subject: Re: A test program?
PostPosted: Wed Jun 20, 2018 11:10 am 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10985
Location: England
Interesting then that EhBasic has a different idea of what TAB should do.


Top
 Profile  
Reply with quote  
 Post subject: Re: A test program?
PostPosted: Wed Jun 20, 2018 12:28 pm 
Offline
User avatar

Joined: Tue Mar 05, 2013 4:31 am
Posts: 1385
Well, I dragged out my old C64 and Amdek Color-I, entered the program Mike provided verbatim and it works perfectly fine. Same exact output that JDS got running OSI Basic.

I tried a few simple programs using the TAB command with EhBasic and they work fine except when using the ";" at the end of the PRINT statement. It starts out fine, then goes off the chart when the TAB offset gets above 13 or so, which explains the odd results I've been getting. Not sure if anyone else can confirm this... or it means I hosed something up in getting it to work. I'll admit it's not totally reliable, it does crash on changing/adding line statements now and then, which forces me to Cold start EhBasic. It's also managed to corrupt RAM to the point where the Monitor/BIOS needs a cold start.

As for Bill's Mandelbrot program (which I do like), that appears to function properly with EhBasic on my C02 Pocket SBC. As noted, endless MandelBrot generation. Perhaps I should look at switching over to the OSI version of MS-Basic... more digging to do.

_________________
Regards, KM
https://github.com/floobydust


Top
 Profile  
Reply with quote  
 Post subject: Re: A test program?
PostPosted: Thu Jun 21, 2018 6:55 am 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10985
Location: England
Hmm, the EhBasic source seems to be doing the right thing with TAB.

Code:
   PLA                 ; get token back
   CMP   #TK_TAB       ; was it TAB ?
   BNE   LAB_18B7      ; if not go do SPC

                       ; calculate TAB offset
   TXA                 ; copy integer value to A
   SBC   TPos          ; subtract terminal position
   BCC   LAB_18BD      ; branch if result was < 0 (can't TAB backwards)

                       ; print A spaces

But here's a thought - might decimal mode be set? That would mess up the SBC result. Can you put a CLD in somewhere in the initialisation? Or perhaps PRINT HEX$(4) would do the trick, as it uses decimal mode and then reverts to binary.


Top
 Profile  
Reply with quote  
 Post subject: Re: A test program?
PostPosted: Thu Jun 21, 2018 2:53 pm 
Offline
User avatar

Joined: Fri Dec 12, 2008 10:40 pm
Posts: 1007
Location: Canada
There is definitely a problem with the TAB() function in EhBASIC. It seems that it works correctly only to the 15th column then every TAB(), regardless of the value passed, tabs over 15 spaces.

Code:
10 FOR X = 0 TO 20
20 PRINT TAB(X)"*";
30 NEXT X
RUN
***************              *              *              *              *              *              *
Ready

_________________
Bill


Top
 Profile  
Reply with quote  
 Post subject: Re: A test program?
PostPosted: Thu Jun 21, 2018 3:14 pm 
Offline
User avatar

Joined: Fri Dec 12, 2008 10:40 pm
Posts: 1007
Location: Canada
Ahhh,

I think I have found the problem.

The default terminal width is set to 15 in EhBASIC.

Code:
TWidth      = $0F      ; BASIC terminal width byte


I'll make the change and re-assemble BASIC to see it that makes the difference

_________________
Bill


Top
 Profile  
Reply with quote  
 Post subject: Re: A test program?
PostPosted: Thu Jun 21, 2018 3:22 pm 
Offline

Joined: Sat Jul 28, 2012 11:41 am
Posts: 442
Location: Wiesbaden, Germany
...or simply use the WIDTH statement to define the terminal's line width.

The $0F defines the zero page address of TWidth, NOT the value!!!

_________________
6502 sources on GitHub: https://github.com/Klaus2m5


Top
 Profile  
Reply with quote  
 Post subject: Re: A test program?
PostPosted: Thu Jun 21, 2018 3:29 pm 
Offline
User avatar

Joined: Fri Dec 12, 2008 10:40 pm
Posts: 1007
Location: Canada
Thanks Klaus, you saved me some headaches.

WIDTH would be good for a test, but Where would one change the default value?

EDIT: Okay, I found it in the zero page initialization table.

_________________
Bill


Top
 Profile  
Reply with quote  
 Post subject: Re: A test program?
PostPosted: Thu Jun 21, 2018 3:44 pm 
Offline
User avatar

Joined: Fri Dec 12, 2008 10:40 pm
Posts: 1007
Location: Canada
So setting the width to 132 and running the program gives the correct result. Nothing wrong with EhBASIC after all.

Code:
Ready
WIDTH 132

Ready
5 DEF FNA(Z)=30*EXP(-Z*Z/100)
100 PRINT
110 FOR X=-0 TO 30 STEP 1.5
120 L=0
130 Y1=5*INT(SQR900-X*X)/5)
140 FOR Y=Y1 TO -Y1 STEP -5
150 Z=INT(25+FNA(SQR(X*X+Y*Y))-.7*)
160 IF Z<=L THEN 190
170 L=Z
180 PRINT TAB(Z)"*";
190 NEXT Y
200 PRINT
210 NEXT X
300 END
RUN

                         *
                     *   *  *
                  *  *   *  *   *
              *   *  *   *  *   *  *
              *   *  *   *  *   *  *
              *   *  *   *  *   *  *
           *  *   *  *   *  *   *  *   *
           *  *   *   *  *   *  *  *   *
           *  *   *   *   *  *  *  *   *
       *   *  *   *    *  *   * *  *   *  *
       *   *  *    *   *    * *  * *   *  *
       *   *   *   *     *   *  **  *  *  *
       *   *   *    *      *    * * *  *  *
       *   *   *     *       *    * *  *  *
       *   *   *      *        *      **  *
       *   *    *       *         *       *
       *   *    *        *           *       *
       *   *     *         *            *        *
       *   *     *          *             *         *
       *   *     *          *               *         *
    *  *   *     *           *              *          *
       *   *     *          *               *         *
       *   *     *          *             *         *
       *   *     *         *            *        *
       *   *    *        *           *       *
       *   *    *       *         *       *
       *   *   *      *        *      **  *
       *   *   *     *       *    * *  *  *
       *   *   *    *      *    * * *  *  *
       *   *   *   *     *   *  **  *  *  *
       *   *  *    *   *    * *  * *   *  *
       *   *  *   *    *  *   * *  *   *  *
           *  *   *   *   *  *  *  *   *
           *  *   *   *  *   *  *  *   *
           *  *   *  *   *  *   *  *   *
              *   *  *   *  *   *  *
              *   *  *   *  *   *  *
              *   *  *   *  *   *  *
                  *  *   *  *   *
                     *   *  *
                         *

Ready

_________________
Bill


Top
 Profile  
Reply with quote  
 Post subject: Re: A test program?
PostPosted: Thu Jun 21, 2018 3:46 pm 
Offline

Joined: Sat Jul 28, 2012 11:41 am
Posts: 442
Location: Wiesbaden, Germany
It seems to be here (Although I do not yet fully understand the limit for TAB thing):
Code:
; page zero initialisation table $00-$12 inclusive

StrTab
      .byte $4C               ; JMP opcode
      .word LAB_COLD          ; initial warm start vector (cold start)

      .byte $00               ; these bytes are not used by BASIC
      .word $0000             ;
      .word $0000             ;
      .word $0000             ;

      .byte $4C               ; JMP opcode
      .word LAB_FCER          ; initial user function vector ("Function call" error)
      .byte $00               ; default NULL count
      .byte $00               ; clear terminal position
      .byte $00               ; default terminal width byte
      .byte $F2               ; default limit for TAB = 14
      .word Ram_base          ; start of user RAM
EndTab
The documentation says
Quote:
WIDTH {b1|,b2|b1,b2}
Sets the terminal width and TAB spacing. b1 is the terminal width and b2 is the tab spacing, default is 80 and 14. Width can be zero, for "infinite" terminal width, or from 16 to 255. The tab size is from 2 to width-1 or 127, whichever is smaller.
which is wrong as the default width is 0 as we can see in the code snippet above.

_________________
6502 sources on GitHub: https://github.com/Klaus2m5


Top
 Profile  
Reply with quote  
 Post subject: Re: A test program?
PostPosted: Thu Jun 21, 2018 4:15 pm 
Offline
User avatar

Joined: Fri Dec 12, 2008 10:40 pm
Posts: 1007
Location: Canada
I think $00 is supposed to be infinite terminal width. $F2 is 13 less than $FF, so it seems the TAB limit needs to be set the compliment of the required amount -1.

For example, if you wanted to set the default tab limit to 16 then change the value to $F0.

The default tab value should only be used when there is a comma in a print statement. The TAB command should override that, but it seems to be wonky beyond the default when the terminal width is set to $00.

I just tired setting the default terminal width to $84 and things work as expected. There only seems to be an issue when it is set to $00.

_________________
Bill


Top
 Profile  
Reply with quote  
 Post subject: Re: A test program?
PostPosted: Mon Jun 25, 2018 4:18 am 
Offline
User avatar

Joined: Thu Mar 11, 2004 7:42 am
Posts: 362
I've only tested these in Applesoft, but they should all run in EhBASIC.

Can you predict what this 5 liner is going to output without RUNning it? Better yet, can you explain why this works?
Code:
10 P=3
20 FOR I=1 TO 5
30 PRINT P
40 P=P+SIN(P)
50 NEXT


A 12 liner.
Code:
100 DIM N(104)
110 FOR T=1 TO 104:N(T)=2:NEXT
120 FOR D=1 TO 31
130 Q=0
140 FOR T=104 TO 1 STEP -1
150 B=2*T-1
160 IF T=1 THEN B=10
170 R=T*Q+N(T)*10:Q=INT(R/B):N(T)=R-Q*B
180 NEXT
190 PRINT Q;
200 IF D=1 THEN PRINT ".";
210 NEXT


This one is for 80 columns (where the characters about twice as tall as they are wide).
Code:
10 P=ATN(1)*4
20 FOR Y = -10.5 TO 10.5
30 FOR X = -10.75 TO 10.75 STEP .5
40 A=ATN(Y/X)+(X<0)*SGN(Y)*P
50 C=(SQR(X*X+Y*Y)-A/2)/P
60 PRINT CHR$(32+3*(C-INT(C)<.4));
70 NEXT
80 PRINT
90 NEXT

For 40 columns (where the characters are roughly square, i.e. they are about as tall as they are wide), I changed line 30 to this:
Code:
30 FOR X = -10.5 TO 10.5


A quine. (I didn't bother to match the spacing, since the different versions of Applesoft LIST with slightly different spacing, but it's not too difficult to fix that (or to replace ? with PRINT), if you want to have at it.)
Code:
1A$=":A$=CHR$(34)+A$:?1MID$(A$,3,3)A$A$":A$=CHR$(34)+A$:?1MID$(A$,3,3)A$A$


Rule 30 (with wraparound). I used W=39 (line 10) for 40 columns.
Code:
10 W=79
20 DIM A(W+1):A(W/2+1)=1
30 FOR I=0 TO 7:B(I)=ASC(MID$("00011110",8-I))-48:NEXT
40 P=A(W):A(W+1)=A(1):FOR I=1 TO W:N=A(I)
50 PRINT CHR$(32+3*N);
60 A(I)=B(4*P+2*N+A(I+1)):P=N:NEXT:PRINT
70 GOTO 40


Top
 Profile  
Reply with quote  
 Post subject: Re: A test program?
PostPosted: Mon Jun 25, 2018 6:24 am 
Offline

Joined: Mon May 21, 2018 8:09 pm
Posts: 1462
Quote:
Can you predict what this 5 liner is going to output without RUNning it? Better yet, can you explain why this works?

It should print a good approximation to pi. It works because sin(x) has a gradient asymptotically approaching -1 as x -> pi, and a value crossing zero at exactly pi.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 53 posts ]  Go to page Previous  1, 2, 3, 4  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: