Author Topic: Brandy BASIC V  (Read 35464 times)

Offline John

  • Forum Support / SB Dev
  • Posts: 3510
    • ScriptBasic Open Source Project
Brandy BASIC V
« on: January 04, 2014, 11:00:19 AM »
I have been playing with the Windows version of Napoleon Brandy Basic V Interpreter under Wine and I have to say that it's very fast for an interpreter. The good news is that the graphics are done using SDL and the author indicated that the library should be compatible with Linux. My thought at this point is to wrap the NBB5 SDL graphics library as an extension module for ScriptBasic and call it bb5.so and use the BBC calling syntax used in NBB5. Here are a few screen shots of NBB5 running on Ubuntu 64 bit under Wine 1.6.

Basic 5 Documentation

This is 100K iterations in total.


ScriptBasic comparison:
Code: [Select]
REM Sieve of Eratosthenes Prime Number Program

size = 10000
iterations = 10
FOR c = 1 TO iterations
  count = 0
  SPLITA STRING(size,"1") BY "" TO flags
  FOR i = 0 TO size
    IF flags[i] THEN
      prime = i + i + 3
      k = i + prime
      WHILE k <= size
        flags[k]= 0
        k += prime
      WEND
      count += 1
    END IF
  NEXT
  UNDEF flags
NEXT
PRINT "There are ",count," primes\n"

jrs@laptop:~/sb/sb22/test$ time scriba bb5sieve.sb
There are 2261 primes

real   0m0.142s
user   0m0.132s
sys   0m0.008s
jrs@laptop:~/sb/sb22/test$


This is rendered in real time by the pixel.


Seems easy to use.


« Last Edit: January 04, 2014, 04:37:05 PM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 3510
    • ScriptBasic Open Source Project
Re: Brandy BASIC V
« Reply #1 on: January 04, 2014, 07:57:53 PM »
I found my version of Brandy Basic 5 for Linux and fired it up. I now remember it's a console only interactive BBC BASIC with no graphics extensions.  :(


jrs@laptop:~/Brandy/brandy-1.0.19/examples$ ./brandy
Brandy Basic V Interpreter Version 1.0.19 (Linux) 09/10/2005

Starting with 524288 bytes free

Basicvars is at &0x64a5a0, tokenised line is at &0x64a060
Workspace is at &0x7f4631599010, size is &80000, page = &0x7f4631599010, himem = &0x7f4631619010
>

jrs@laptop:~/Brandy/brandy-1.0.19/examples$ ./brandy sieve
10 iterations.
Doing 1
Doing 2
Doing 3
Doing 4
Doing 5
Doing 6
Doing 7
Doing 8
Doing 9
Doing 10
There are 2261 primes
Time taken=0.07 seconds
>list
    1REM Sieve of Eratosthenes Prime Number Program
    2:
    3size%=10000
    4iterations%=10
    5:
    6DIM flags%(size%)
    7:
    8T=TIME
    9PRINT;iterations%;" iterations."
   10FOR C%=1 TO iterations%
   11PRINT"Doing ";C%
   12count%=0
   13flags%()=TRUE
   14FOR I%=0 TO size%
   15IF flags%(I%) THEN
   16prime%=I%+I%+3
   17K%=I%+prime%
   18WHILE K%<=size%
   19flags%(K%)=FALSE
   20K%+=prime%
   21ENDWHILE
   22count%+=1
   23ENDIF
   24NEXT
   25NEXT
   26PRINT"There are ";count%;" primes"
   27PRINT"Time taken=";(TIME-T)/100;" seconds"
   28END
>


« Last Edit: January 04, 2014, 08:12:53 PM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 3510
    • ScriptBasic Open Source Project
Re: Brandy BASIC V
« Reply #2 on: January 04, 2014, 10:46:56 PM »
I was able to find a newer version of Brandy for Linux that uses SDL for the graphics part. (like the Windows version but doesn't seem as complete)

Brandy 1.20 w/SDL Ubuntu 64 bit

Offline John

  • Forum Support / SB Dev
  • Posts: 3510
    • ScriptBasic Open Source Project
Re: Brandy BASIC V
« Reply #3 on: January 05, 2014, 05:17:24 PM »
I made a little more progress updating the Linux version of Brandy BASIC 5 with the latest Windows version that was announced on the BP.org site.

Update: I got the mouse working in Brandy BASIC V. (Ubuntu 64 bit version)



Code: [Select]
   10REM POLYGON
   20REM FROM AN ORIGINAL PROGRAM BY JOHN A COLL
   30REM IBM VERSION / 23 MAR 86; MODIFIED 26 SEP 98
   40CLS
   50 MODE 32
   60CLS
   70VDU 26
   80
   90Width% = X%
  100Height% = Y%
  110
  120
  130
  140DIM X(10)
  150DIM Y(10)
  160: count=0
  170REPEAT
  180count=count+1
  190xorigin=RND(640*2)
  200yorigin=RND(512*2)
  210Radius=RND(300)+50
  220VDU29,xorigin;yorigin;
  230sides=RND(8)+2
  240MOVE Radius,0
  250MOVE 10,10
  260:
  270C=RND(64)-1:T=(RND(4)-1)<<6:GCOL 0,C TINT T
  280FOR SIDE=1 TO sides
  290angle=(SIDE-1)*2*PI/sides
  300X(SIDE)=Radius*COS(angle)
  310Y(SIDE)=Radius*SIN(angle)
  320MOVE 0,0
  330PLOT 85,X(SIDE),Y(SIDE)
  340NEXT SIDE
  350MOVE 0,0
  360PLOT 85,Radius,0
  370:
  380REPEAT D=RND(64)-1:UNTIL (D AND 63)<>(C AND 6):GCOL 0,D TINT T
  390FOR SIDE=1 TO sides
  400FOR Line=SIDE TO sides
  410MOVE X(SIDE), Y(SIDE)
  420DRAW X(Line), Y(Line)
  430NEXT Line
  440NEXT SIDE
  450IF count=50::count=0:delay%=10
  460REM K% = INKEY(1)
  470UNTIL FALSE
« Last Edit: January 05, 2014, 08:07:23 PM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 3510
    • ScriptBasic Open Source Project
Re: Brandy BASIC V
« Reply #4 on: January 05, 2014, 08:48:45 PM »
I got the Mandelbrot Set example to work at high resolution. (32 bit color) When I finish with the Windows Brandy BASIC V migration of enhancements to the Linux version, I'll post a Ubuntu 64 bit and Android version of the BASIC. I probably won't start the bb5.so SB extension module until sprites are working. I hope David Burnard (Napoleon Brandy Basic V Interpreter for Windows author) continues with his efforts. I will setup a Bitbucket project for the Linux/Android version of Brandy BASIC V when both the Windows version and the Linux version are in sync.



Code: [Select]
REM From Rosetta code BBC Basic version
REM Modified to run under BB4W and Napoleon Brandy Basic
REM February 2013 by David John Burnard
REM January 2014 by John Spikowski - Ubuntu 64 bit version
t = TIME
sizex% = 800
sizey% = 600
maxiter% = 128
MODE 32
ORIGIN 0, sizey%
FOR x% = 0 TO 2 * sizex% - 2 STEP 2
  xi = x% / 400 - 2
  FOR y% = 0 TO sizey% - 2 STEP 2
    yi = y% / 400
    x = 0
    y = 0
    i% = 1
    WHILE i% <= maxiter% AND x * x + y * y <= 4
      xt = xi + x * x - y * y
      y = yi + 2 * x * y
      x = xt
      i% = i% + 1
    ENDWHILE
    IF i% > maxiter% i% = 0
    GCOL i% * 15, i% * 8, 0
    PLOT 69, x%, y%
    PLOT 69, x%, -y%
  NEXT y%
NEXT x%
PRINT "Time taken = ";(TIME - t) / 100;" seconds"
END
« Last Edit: January 07, 2014, 11:36:14 PM by John »

David Burnard

  • Guest
Re: Brandy BASIC V
« Reply #5 on: January 06, 2014, 10:42:41 AM »
The "artifacts" in the polygon drawing program are a bug in the RND() function in brandy basic

should return

RND returns a random integer 0 - &FFFFFFFF.
RND(n) returns an integer in the range 1 to n (n>1).
RND(1) returns a real number in the range 0.0 to .99999999.

fixed in windows version

Offline John

  • Forum Support / SB Dev
  • Posts: 3510
    • ScriptBasic Open Source Project
Re: Brandy BASIC V
« Reply #6 on: January 06, 2014, 11:04:25 AM »
Welcome David!

I haven't made all your changes yet to the Ubuntu version and was concentrating on getting the graphics working so I could mirror your examples.

I'll get the Bitbucket project going as soon as I'm in sync.


Offline John

  • Forum Support / SB Dev
  • Posts: 3510
    • ScriptBasic Open Source Project
Brandy BASIC V - Beta Testers
« Reply #7 on: January 06, 2014, 03:14:00 PM »
If you have used BBC BASIC in the past and would like to participate in the Brandy BASIC V beta testing, please register on the All BASIC Developer mailing list to help with the effort.
« Last Edit: January 06, 2014, 03:18:54 PM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 3510
    • ScriptBasic Open Source Project
Re: Brandy BASIC V
« Reply #8 on: January 06, 2014, 07:04:20 PM »
Once I catch up to David's Windows version, I would like to incorporate the SDL_terminal library into Brandy BASIC V. The main window will be for graphics and the terminal window for interactive programming and debugging. I'll use one of the undefined function keys to toggle the terminal window.



Offline John

  • Forum Support / SB Dev
  • Posts: 3510
    • ScriptBasic Open Source Project
Re: Brandy BASIC V
« Reply #9 on: January 06, 2014, 09:54:33 PM »
I may have gotten ahead of myself and made some assumptions that aren't true. The Brandy BASIC V version 1.20 for Linux seems to run fine. I made the RND() casting change but I really didn't see a big difference with the polygon example. Since both David's and the original Brandy BASIC site have SourceForge project sites I would be reproducing the effort with Bitbucket. I'm going to do a bit more testing under Ubuntu 64 bit before trying to compile it on Android.

The changes David made for the Windows version are specific to that OS and would require rethinking the approach in Linux. I will try to create a list of changes and see if anyone wants to try implementing them under Linux. I have enough to start porting the graphic part of Brandy BASIC V to a ScriptBasic extension module. (bb5.so) David is working on a cross platform font engine using TrueType fonts as a generation source. (he will have to explain in more detail) I'm looking forward to when sprite support is added and I hope it's cross platform.



Code: [Select]
REM A Flying Saucer ?
REM A simple but effective 3D drawing
MODE 32: ORIGIN 800,600
XS=2:YS=2
GCOL 14:OFF
A=700:B=A*A:C=600
FOR X=0 TO A STEP XS:S=X*X:P=SQR(B-S)
  FOR I=-P TO P STEP 6*YS
    R=SQR(S+I*I)/A
    Q=(R-1)*SIN(24*R)
    Y=INT(I/3+Q*C)
    IF I=-P M=Y:N=Y
    IF Y>M M=Y
    IF Y<N N=Y
    IF M=Y OR N=Y PLOT 69,NOTX,Y:PLOT 69,X,Y
  NEXT:NEXT
REPEAT WAIT 1:UNTIL FALSE



Code: [Select]
REM 'Fake' fractal fern
 REM Original QBASIC program published in PC Magazine
 REM BB4W version by David Williams
 t = TIME
 MODE 32: ORIGIN 200,100
 OFF
 GCOL 14
 x=0
 y=0
 FOR i%=1 TO 80000
   r = RND(1)
   CASE TRUE OF
     WHEN r<=0.1: A=0: B=0: C=0: D=0.16: E=0: F=0
     WHEN r>0.1 AND r<=0.86: A=.85: B=.04: C=-.04: D=.85: E=0: F=1.6
     WHEN r>0.86 AND r<=0.93: A=.2: B=-.26: C=.23: D=.22: E=0: F=1.6
     WHEN r>0.93: A=-.15: B =.28: C=.26: D=.24: E=0: F=.44
   ENDCASE
   newx=A*x+B*y+E
   newy=C*x+D*y+F
   x=newx
   y=newy
   MOVE 600+96*x, 32+96*y
   DRAW 600+96*x, 32+96*y
 NEXT i%
 PRINT "Time taken = ";(TIME - t) / 100;" seconds"
 END
« Last Edit: January 06, 2014, 10:16:17 PM by John »

David Burnard

  • Guest
Re: Brandy BASIC V
« Reply #10 on: January 07, 2014, 05:13:37 AM »
Fern under Napoleon Brandy BASIC , Windows 7, Dell Vostro 220 2.5Ghz Dual core Pentium 0.19s
Saucer  under Napoleon Brandy BASIC , Windows 7, Dell Vostro 220 2.5Ghz Dual core Pentium 0.05s

How Do I insert images on this forum?

What spec is your PC John?

David Burnard

  • Guest
Re: Brandy BASIC V
« Reply #11 on: January 07, 2014, 05:23:47 AM »
Also these examples are taken from Richard Russels BB4W, is he ok with you using them - his code is commercial !!

Offline John

  • Forum Support / SB Dev
  • Posts: 3510
    • ScriptBasic Open Source Project
Re: Brandy BASIC V
« Reply #12 on: January 07, 2014, 09:53:02 AM »
Quote
Also these examples are taken from Richard Russels BB4W, is he ok with you using them - his code is commercial !!

I'm surprised anyone is still trying to sell a novelty BASIC of a 80s vintage. I give credit to the authors of these relics if provided. What is the story behind Liberty BASIC and LBB? Did Richard buy the rights to Liberty BASIC or BBC BASIC or is he just trying to make a buck off nostalgic BASIC programmers? If Richard has any problems with what is going on here on the All BASIC Developer forum, have him contact me.

You can attach images and files to your posts (see Attachments and other options) below the left corner of your edit box. If you have a server or way to provide a URL to an image, encapsulate the URL with the BB IMG tag.

I'm developing on a Toshiba laptop. (64 bit dual core 2.1 ghz with 4 GB of system memory)

If adding a SDL_terminal for text to BBV isn't going to be a lot of work, I might take a shot at it. My interests is an Android version of BBV and using the graphic portion of BBV with ScriptBasic as an extension module. How much effort I put into BBV depends on your commitments to BBC BASIC.
« Last Edit: January 07, 2014, 10:06:38 AM by John »

Mike Lobanovsky

  • Guest
Re: Brandy BASIC V
« Reply #13 on: January 07, 2014, 11:14:38 AM »
Gentlemen,

Let me add my two cents to the discussion. I think it's worth it.

1. John, there must be something seriously wrong with your code performance. The benchmarks should be at least an order of magnitude faster than in your snapshots, as David correctly points out. We have compatible CPU's and good graphics cards so our figures shouldn't differ that much.

2. Also, unless your snapshot is heavily minified, there must be something very seriously wrong with BB4W's coordinate system. This code isn't compatible with standard BASIC's or other languages.

Firstly, this plot cannot fit into a window whose size it less than 1680x1050 pixels as the parameter values used won't permit it. Have a look at this code as it runs in FBSL's BASIC and Dynamic C in a 1500x1000 px window:

FBSL BASIC:


FBSL DYNC:


Secondly, BB4W Y coordinate is flipped upside down. I append a zip below for you to try FBSL's  BASIC and C code. The zip also contains the latest Fbsl.exe binary. You can edit the script in any text editor and launch it for execution by either drag-and-dropping its icon onto Fbsl.exe's icon or typing > Fbsl.exe UFO.fbs at your command prompt on having switched to the directory where both the script and binary reside.

And lastly, reproducing this code in every other language I have yields the exact same results as seen in the FBSL snapshots.

3.
Quote
Also these examples are taken from Richard Russels BB4W, is he ok with you using them - his code is commercial !!

I'm afraid this is not so, David. At least the UFO code doesn't seem to belong to Russel and frankly I don't know what it's doing in a commercial package.

The original code can be found on the Liberty BASIC site and it has been there for quite some time with comments written by its author in some rather shaky English. I'm sorry I don't have time enough to leaf through all of their numerous pages to give you a direct link but here's a link to my submission on FBSL forum where the original script was attributed to LB and the author's comments were preserved intact. The submission dates back to December 2012.

I'm too lazy to dig into the Fern fractal case but I'm perfectly sure I'd find some evidence if I only go for it.  ;)

Offline John

  • Forum Support / SB Dev
  • Posts: 3510
    • ScriptBasic Open Source Project
Re: Brandy BASIC V
« Reply #14 on: January 07, 2014, 12:10:20 PM »
David had mentioned in a e-mail that Brandy BASIC V using SDL is slower than his Windows implementation. My interest in BBV is portability and ease of enhancing the BASIC. Once I get this running on Android I hope to experiment with the ARM RISC features of BBC BASIC V.

Quote
The ARM architecture is similar to a Reduced Instruction Set Computer (RISC) architecture, as it incorporates these typical RISC architecture features:

* A uniform register file load/store architecture, where data processing operates only on register contents, not directly on memory contents.
* Simple addressing modes, with all load/store addresses determined from register contents and instruction fields only.

Enhancements to a basic RISC architecture enable ARM processors to achieve a good balance of high performance, small code size, low power consumption and small silicon area.

Quote from: Mike
2. Also, unless your snapshot is heavily minified, there must be something very seriously wrong with BB4W's coordinate system. This code isn't compatible with standard BASIC's or other languages.

BBV uses a MODE screen resolution setting and everything is based off that. The BBC BASIC V method of graphics handling is interesting and seems to still have a strong following and maybe more so if it can phoenix its origin in RISC with ARM.
« Last Edit: January 07, 2014, 12:51:16 PM by John »