Thursday, April 08, 2021

S-BASIC vs. Turbo Pascal

My next experiment was to take some of those S-BASIC programs and convert them to Turbo Pascal.

It wasn't a surprise that the conversion was pretty easy.  Much easier than M-BASIC to S-BASIC.  S-BASIC has more in common with Pascal than MBASIC.

 

Overall, Turbo Pascal is much better than S-BASIC.

Turbo Pascal has an IDE.  With S-BASIC, I needed to use an external editor.  The one that I had was TE, but that's actually a relatively new program.   But I probably could have used Wordstar - to keep the Turbo Pascal comparison apples-to-apples.

Turbo Pascal can compile to memory.  This greatly increases the speed of which it tells you where your errors are and makes it able for you to test your program quicker.

With S-BASIC, it's save, exit the editor, run the compiler, go back into the editor - and remember the line that had the problem.

As far as creating an actual .COM file, Turbo Pascal might have a slight speed advantage, but not enough to really notice.

 

So the reason for S-BASIC star not rising is proven.  Turbo Pascal is so much better.

Please don't take this as meaning that S-BASIC is bad.  On the contrary, it's really good, and if Turbo Pascal hadn't come out, it probably would have gotten much more traction.


Monday, April 05, 2021

S-BASIC - Bunco game

 So we start with a simple Bunco game written in BASIC.

10 PRINT "BUNCO"
20 S=0:W=INT(RND(1)*200)+300
30 FOR R=1 TO 6
40 PRINT "ROLLING..."
50 FOR Q=1 TO W: X=RND(1): NEXT Q
60 D1=INT(RND(1)*6)+1:D2=INT(RND(1)*6)+1:D3=INT(RND(1)*6)+1
70 PRINT "ROUND:";R;"Rolls:";D1;D2;D3
80 IF (D1=D2) AND (D2=D3) THEN 150
90 IF D1=R THEN S=S+1
100 IF D2=R THEN S=S+1
110 IF D3=R THEN S=S+1
120 PRINT "SCORE ";S
125 INPUT "PRESS ENTER";A$
130 NEXT R
140 PRINT "FINAL SCORE=";S: END
150 IF D1=R THEN PRINT "BUNCO!": S=S+21: GOTO 120
160 PRINT "MINI BUNCO": S=S+5: GOTO 120

The original for this was probably written for my Pocket Computer 2.

The S-BASIC version looks like this:

var s,w,r,q,x,d1,d2,d3=integer
var a=char

PRINT "BUNCO"
S=0
W=INT(RND(1)*200)+300
FOR R=1 TO 6
    PRINT "ROLLING..."
    FOR Q=1 TO W
        X=RND(1)
    NEXT Q
    
    D1=INT(RND(1)*6)+1
    D2=INT(RND(1)*6)+1
    D3=INT(RND(1)*6)+1
    PRINT "ROUND:";R;" Rolls:";D1;D2;D3
    IF (D1=D2) AND (D2=D3) THEN BEGIN
        IF D1=R THEN begin
            PRINT "BUNCO!"
            S=S+21
            end
        else begin
            PRINT "MINI BUNCO"
            S=S+5
            end
        end
    else begin
        IF D1=R THEN S=S+1
        IF D2=R THEN S=S+1
        IF D3=R THEN S=S+1
    end
    
    PRINT "SCORE ";S
    INPUT "PRESS ENTER";A
NEXT R

PRINT "FINAL SCORE=";S

Now, it certainly is much easier to read and much of the original code is there, but there was a significant amount of change to make this work under S-BASIC.

One gotcha was the 

60 D1=INT(RND(1)*6)+1:D2=INT(RND(1)*6)+1:D3=INT(RND(1)*6)+1

The S-BASIC compiler did not flag that as an error, but the assignments to D2 and D3 were simply ignored.

But lines 150 and 160

150 IF D1=R THEN PRINT "BUNCO!": S=S+21: GOTO 120
160 PRINT "MINI BUNCO": S=S+5: GOTO 120

Did get a compiler error because they came after the PRINT.

Lines 150 and 160 also have a second gotcha: The way to those lines is a GOTO within the FOR loop.  Again, the S-BASIC compiler flagged no problem, but the FOR loop simply exited after the first iteration.

 

Sunday, April 04, 2021

S-BASIC

On the Kaypro, there was something called S-BASIC.  S-BASIC was an early attempt at creating a "structured BASIC" language.  Think of what C++ was to C.  S-BASIC is to BASIC.

But while C++ would compile C programs, S-BASIC would not compile Microsoft BASIC programs.

To convert an MBASIC program to S-BASIC, you need to:

  • Declare all variables before their use.  That means you need to go through your BASIC program, find all variables and declare their type.
  • Remove all multi-line statements.  S-BASIC doesn't support ":" between statements.  At best, it simply ignores all the code after the ":".  At worst, compiler errors.
  • You cannot GOTO out of a FOR loop, even if you GOTO back in.

Other downsides:

  • Compile time is slow.  So the amount of time between changing something and seeing if it works is a while.
  • No IDE.  You need a text editor to write your code.
  • It cannot READ data files written by MBASIC.
  • You can still write spaghetti code, but you have the option to not do so.

So to take your MBASIC program to S-BASIC will require a great deal of rewriting.  Even for the really simple programs that I did, it was not quick.

S-BASIC came out about the same time that Turbo Pascal was popular on CP/M.  Turbo Pascal had the IDE and is a much richer language.  So it's easy to see why S-BASIC didn't really rise in popularity.