6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sat Nov 23, 2024 12:09 pm

All times are UTC




Post new topic Reply to topic  [ 63 posts ]  Go to page Previous  1, 2, 3, 4, 5  Next
Author Message
PostPosted: Tue Oct 22, 2019 1:12 pm 
Online
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10986
Location: England
Hmm, it doesn't seem to like line 50. I entered it, it lists as blank, and I can't add line 60 either.


Top
 Profile  
Reply with quote  
PostPosted: Tue Oct 22, 2019 4:24 pm 
Offline
User avatar

Joined: Tue Mar 21, 2017 6:57 pm
Posts: 81
I'll have to call Bill Gates for advice


Top
 Profile  
Reply with quote  
PostPosted: Tue Oct 22, 2019 11:54 pm 
Offline
User avatar

Joined: Tue Mar 21, 2017 6:57 pm
Posts: 81
After a lengthy phone conversation, the line 50 issue is found. However, Bill noted that "DIV" and "VDU7" are still "?SYNTAX ERROR's" [his words].

Attachment:
MSBASIC.gt1.zip [7.68 KiB]
Downloaded 95 times

Edit: And so are "FOR J%" and "FOR I%". I tried to fix the program, but the interpreter then crashes. So another debugging session is called for.


Top
 Profile  
Reply with quote  
PostPosted: Wed Oct 23, 2019 8:36 am 
Online
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10986
Location: England
Thanks for the fix! I do believe I've read somewhere that MS Basic doesn't allow loop variables to be integers, so that's most likely as expected. VDU 7 is just a beep, and in this case DIV is rather like divide, possibly with an INT, so we should be good to go.


Top
 Profile  
Reply with quote  
PostPosted: Thu Oct 24, 2019 4:36 am 
Offline

Joined: Mon May 21, 2018 8:09 pm
Posts: 1462
Right - DIV is provided in floating-point BASICs to explicitly perform an integer division, usually accompanied by a MOD keyword to provide the corresponding remainder. In an integer BASIC there is no need for them.


Top
 Profile  
Reply with quote  
PostPosted: Thu Oct 24, 2019 10:34 am 
Online
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10986
Location: England
Hmm, next obstacle with the Pi spigot, I get an out of memory error at line 90. Is the expression too complex? I'd only entered up to line 110 and ran with an input of 9.


Top
 Profile  
Reply with quote  
PostPosted: Thu Oct 24, 2019 11:25 am 
Offline
User avatar

Joined: Tue Mar 21, 2017 6:57 pm
Posts: 81
As said:

mvk wrote:
I tried to fix the program, but the interpreter then crashes. So another debugging session is called for.


Regarding out of memory: It should be able to do two FOR levels. (Three levels is still too much.)


Last edited by mvk on Thu Oct 24, 2019 11:33 am, edited 2 times in total.

Top
 Profile  
Reply with quote  
PostPosted: Thu Oct 24, 2019 11:26 am 
Offline
User avatar

Joined: Tue Mar 21, 2017 6:57 pm
Posts: 81
Chromatix wrote:
Right - DIV is provided in floating-point BASICs to explicitly perform an integer division, usually accompanied by a MOD keyword to provide the corresponding remainder. In an integer BASIC there is no need for them.

Micro-Soft BASIC is a floating point BASIC (that was the whole point). It doesn't have DIV. This program isn't an MS BASIC program, so it must be rewritten.


Top
 Profile  
Reply with quote  
PostPosted: Thu Oct 24, 2019 11:42 am 
Online
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10986
Location: England
Oh, sorry, I missed that there was still work in progress.

(In this case, / will work just as well as DIV - the change from / to DIV was purely for performance on a Beeb.)


Top
 Profile  
Reply with quote  
PostPosted: Thu Oct 24, 2019 11:49 am 
Offline
User avatar

Joined: Tue Mar 21, 2017 6:57 pm
Posts: 81
I wonder if all that %-fuss really makes much of a difference. All calculations are done as floating point anyway. Even the "bytes free" message is printed by the floating point routine.


Top
 Profile  
Reply with quote  
PostPosted: Thu Oct 24, 2019 2:13 pm 
Online
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10986
Location: England
It certainly helps in BBC Basic, and I think I've seen it help in MS Basic in the past. That's when I would have come across the oddity that loop variables must be floats.


Top
 Profile  
Reply with quote  
PostPosted: Thu Oct 24, 2019 3:47 pm 
Offline
User avatar

Joined: Tue Mar 21, 2017 6:57 pm
Posts: 81
All these back-and-forth conversions make integer variables slower in MS BASIC. I can only see their point in large arrays. This is easy to test:

Attachment:
Screenshot 2019-10-24 at 17.32.12.png
Screenshot 2019-10-24 at 17.32.12.png [ 344.83 KiB | Viewed 1905 times ]


Result in video mode 3:
Attachment:
Screenshot 2019-10-24 at 17.19.38.png
Screenshot 2019-10-24 at 17.19.38.png [ 317.22 KiB | Viewed 1905 times ]


This is not a completely fair comparison because the GOTO20 is a bit faster than the GOTO50. But if you remove line 10-40, the integer loop still runs slower (3337 ticks).

This now also gives us our apples-to-apples benchmark reference, without having to port another Pi program (we already have one for TinyBASIC of course).

Attachment:
Screenshot 2019-10-24 at 17.22.53.png
Screenshot 2019-10-24 at 17.22.53.png [ 304.29 KiB | Viewed 1905 times ]


Hmm, I wonder how we can compute their ratio? Oh wait, there's only one way that's appropriate:

Attachment:
Screenshot 2019-10-24 at 17.28.55.png
Screenshot 2019-10-24 at 17.28.55.png [ 320.31 KiB | Viewed 1905 times ]


Wow: non-trivial machine code v6502 is only 5.7 times slower than the real thing?! Perhaps that's too good to be true, Edit: but confirmed by a stopwatch. This debunks the "v6502 is 10 times slower than the original 6502"-myth, and refines our earlier "8x slowdown" guesstimate. In reality we're running very close to 75 KIPS, or 3 instructions per scanline. Sweet 8)


Top
 Profile  
Reply with quote  
PostPosted: Mon Oct 28, 2019 9:20 am 
Offline
User avatar

Joined: Tue Mar 21, 2017 6:57 pm
Posts: 81
BigEd wrote:
Hmm, next obstacle with the Pi spigot, I get an out of memory error at line 90. Is the expression too complex? I'd only entered up to line 110 and ran with an input of 9.

Indeed your program is "too complex" for the miniature stack it gets. The stack smashes the CHRGET/CHRGOT routines that live in the zero page. The only solution is some interpreter rewriting to create more space. These routines alone eat 24 precious bytes. But first we should run this in a PET emulator to figure out how many stack bytes the program needs. Some other time... Fixing this will be a weekend project.


Top
 Profile  
Reply with quote  
PostPosted: Tue Oct 29, 2019 10:57 am 
Offline
User avatar

Joined: Tue Mar 21, 2017 6:57 pm
Posts: 81
I hacked CHRGET such that it doesn't need to be copied to the zero page. It means there's a 3.5% speed penalty, as a proper solution is way too much work. But it appears to give your program just enough stack space to run to completion. From the commit notes:

Code:
commit f87436760c751280d22ad3586ea0ea55e01bbad2 (HEAD -> master, master/master)
Date:   Tue Oct 29 11:35:16 2019 +0100

    MSBASIC: Don't copy CHRGET/CHRGET to zero page
   
    To free up more zero page and allow for a deeper stack. TXTPTR is
    still in zero page, so the program doesn't grow a lot. We now do:
   
                    sty SCRATCH
                    ldy #0
                    lda (TXTPTR),y
                    ldy SCRATCH
   
    instead of:
   
            TXTPTR=*+1
                    lda 60000       ; Self modifying operand
       
    All this incurs a slow down of 3.5% in benchmarks. This speed might
    be won back if we put the responsibility of saving Y to the caller
    (as must have been done in CBM-128 BASIC 7.0). But there are so many
    calling sites, this can be too much work.
   
    This benchmark now works:
   
            10 INPUT"HOW MANY DIGITS";N
            20 T=TIME
            30 L=INT(10*N/3)+1:DIM A(L)
            40 Z$="000000":T$="999999"
            50 FOR I=1TOL:A(I)=2:NEXT
            60 M=0:P=0
            70 FOR J=1TON:Q=0:K=2*L+1
            80 FOR I=L TO 1 STEP -1
            90 K=K-2:X=10*A(I)+Q*I
            100 Q=INT(X/K):A(I)=X-Q*K
            110 NEXT
            120 Y=INT(Q/10):A(1)=Q-10*Y:Q=Y
            130 IF Q=9 THEN M=M+1:GOTO170
            140 IF Q>9 THEN PRINT CHR$(49+P);LEFT$(Z$,M);:GOTO170
            150 PRINT CHR$(48+P);LEFT$(T$,M);
            160 P=Q:M=0
            170 NEXT
            180 PRINT CHR$(48+P)
            190 PRINT (TIME-T)/60
   
    Results:
   
            Micro-Soft BASIC        28 digits       510 s   (radix 10)
            Micro-Soft BASIC        14 digits       130 s   (radix 10)
   
    For reference:
   
            10 REM 28 digits of pi
            20 M=94:FOR I=0 TO M-1
            30 Z(I)=20:NEXTI:?"PI=";
            40 E=D%100:D=0:FORI=1TOM
            50 J=M-I:D=D+D*J+Z(J)*100
            60 A=J+J+1:Z(J)=D%A:D=D/A
            70 NEXTI:M=M-6:E=E+D/100
            80 ?E/10;:IF M=88 ?".";
            90 ?E%10;:IF M>10 GOTO 40
   
    Result:
   
            Tiny BASIC              28 digits       65 s    (radix 100)



Updated MSBASIC.gt1 binary is in GitHub as well.


Top
 Profile  
Reply with quote  
PostPosted: Tue Oct 29, 2019 12:18 pm 
Online
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10986
Location: England
Hurrah! Well done.


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 6 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: