Author Topic: BBC BASIC for Windows  (Read 43131 times)

rtrussell

  • Guest
BBC BASIC for Windows
« on: January 14, 2014, 09:40:14 AM »
It should be interesting watching David and Richard fight over the BBC BASIC Windows user base.

As you've kindly allowed me to join the forum I suppose I should respond!  I strongly suspect that there is negligible overlap between the potential user base of Napoleon Brandy BASIC and BBC BASIC for Windows.

Brandy has always concentrated on maximising compatibility with the 'Acorn' fork of BBC BASIC (6502, ARM), whereas BB4W is - naturally - very much part of the 'Russell' fork (Z80, x86, IA-32).  These two variants of the language went their separate ways very early on (mid 1980s if not before) largely triggered by my dissatisfaction, at the time, with some features of the original Acorn 6502 version (I remember being particularly upset at the very limited nesting depth and the lack of support for writing text files).

Of course Acorn resolved those shortcomings eventually, and indeed there was something of a coming-together of the two 'forks' when I released BBC BASIC for Windows in 2001, when I made a conscious effort to improve compatibility with Acorn's BASIC V.  Nevertheless there remain significant differences when you look under the hood.

And of course there are factors other than the differences between the language dialects, such as that BB4W is primarily designed to build standalone Windows executables (I'm not sure how practical it is for Brandy to do that) and has a built-in 32-bit Intel x86 assembler (because of its cross-platform nature Brandy has no assembler).

Nevertheless it will be interesting to see how Napoleon Brandy BASIC develops.

Richard.

Offline John

  • Forum Support / SB Dev
  • Posts: 3512
    • ScriptBasic Open Source Project
Re: BBC BASIC for Windows
« Reply #1 on: January 14, 2014, 10:04:06 AM »
Welcome Richard!

I'm just getting up to speed with BBC BASIC and it's history. It seems to parallel Business BASIC in many ways stemming from the same origins.

I don't know if I will put any more effort into Brandy but if you see value in Brandy for the Linux / Android users, your feedback and help would be appreciated.

FYI I just purchased a copy of BBC BASIC for Windows. Looking forward to giving it a try.

I installed BBC4Windows under Wine.



<a href="http://files.allbasic.info/BBCWin/bbcw_sprites.swf" target="_blank" rel="noopener noreferrer" class="bbc_link bbc_flash_disabled new_win">http://files.allbasic.info/BBCWin/bbcw_sprites.swf</a>

Note Please excuse the artifacts in the recording of this example. It looks great running under Wine.

Code: [Select]
      REM. Demonstration of BBC BASIC for Windows sprites
      INSTALL @lib$+"SPRITELIB"
      :
      IF FN_initsprites(2) = 0 STOP
      ON CLOSE PROC_exitsprites : QUIT
      ON ERROR ON ERROR OFF : PROC_exitsprites : PRINT 'REPORT$ : END
      IF FN_createsprite(0, @dir$+"bbcmicro.ico", 64, 64) = 0 ERROR 0, "Cannot create sprite 0"
      IF FN_createsprite(1, @dir$+"bbcmicro.ico", 64, 64) = 0 ERROR 0, "Cannot create sprite 1"
      :
      MODE 8
      DIM X%(1),Y%(1),XI%(1),YI%(1)
      Y%() = 120
      XI%() = 3,2
      YI%() = 2,3
      :
      OFF
      REPEAT
        FOR I% = 1 TO 20
          FOR S% = 0 TO 1
            X%(S%) += XI%(S%)
            Y%(S%) += YI%(S%)
            PROC_movesprite(S%, X%(S%), Y%(S%), 1)
            IF X%(S%) > 1152 OR X%(S%) < 0   XI%(S%) *= -1
            IF Y%(S%) > 1022 OR Y%(S%) < 120 YI%(S%) *= -1
          NEXT
          pause% = INKEY(1)
        NEXT I%
        :
        x=RND(1280)
        y=RND(1023)
        r=RND(300)+50
        GCOL RND(15)
        CIRCLE FILL x,y,r
        GCOL 0
        CIRCLE x,y,r
      UNTIL FALSE
      END
« Last Edit: January 14, 2014, 11:26:56 AM by John »

rtrussell

  • Guest
Re: BBC BASIC for Windows
« Reply #2 on: January 14, 2014, 11:36:11 AM »
I installed BBC4Windows under Wine.

Its compatibility with Wine is pretty good, but you do need at least Wine 1.5 for good results.

I should add that most of the supplied demos, such as the ones you show, run fine with the free trial version of BB4W.

Richard.

Offline John

  • Forum Support / SB Dev
  • Posts: 3512
    • ScriptBasic Open Source Project
Re: BBC BASIC for Windows
« Reply #3 on: January 14, 2014, 12:25:36 PM »
It's nice to see the ASM feature set of BBCW working under Wine. (1.6.1) The ASM based zoom-able Mandelbrot Set was amazing!

So far I'm very happy with my purchase.

« Last Edit: January 14, 2014, 01:51:15 PM by John »

rtrussell

  • Guest
Re: BBC BASIC for Windows
« Reply #4 on: January 14, 2014, 01:52:22 PM »
It's nice to see the ASM feature set of BBCW working under Wine.

Many of my applications consist of BASIC for the bulk of the program with assembler code for the speed-critical bits, such as my Colour Recovery software:

http://colourrecovery.wikispaces.com/Software+versions

Richard.
« Last Edit: January 14, 2014, 01:53:54 PM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 3512
    • ScriptBasic Open Source Project
Re: BBC BASIC for Windows
« Reply #5 on: January 14, 2014, 01:56:33 PM »
It's really nice to see a Windows application (language) follow the Windows API rules allowing it to shine on Wine.

I did try the Mandelbrot (ASM based) zoom-able demo and it was very cool. Fractals are a fun pastime for me. Mike is passionate in this area as well.

I attached the compiled version of the MANDEL.BBC I'm curious if anyone has an issue with it being compiled on Wine.
« Last Edit: January 14, 2014, 02:05:50 PM by John »

rtrussell

  • Guest
Re: BBC BASIC for Windows
« Reply #6 on: January 14, 2014, 02:25:42 PM »
I did try the Mandelbrot (ASM based) zoom-able demo and it was very cool. Fractals are a fun pastime for me. Mike is passionate in this area as well.

That version does all its calculations in 32-bit floats, so gets inaccurate relatively quickly if you zoom in too far.  I have an SSE2-based (64-bit double) version somewhere, but of course it can only do two calculations in parallel rather than four and is noticeably slower.

Richard.

Mike Lobanovsky

  • Guest
Re: BBC BASIC for Windows
« Reply #7 on: January 14, 2014, 03:32:00 PM »
I'm curious if anyone has an issue with it being compiled on Wine.

Not an issue here, runs very smooth and super fast. Anyway, theis is what assembly is all about!

FBSL is enriched with both assembly and ANSI C JIT compilers for the exact same purposes.

Offline John

  • Forum Support / SB Dev
  • Posts: 3512
    • ScriptBasic Open Source Project
Re: BBC BASIC for Windows
« Reply #8 on: January 14, 2014, 03:36:37 PM »
Thanks Mike for the confirmation.

Richard's choice of colors for his Mandelbrot Set works well with your Windows theme.  8)
« Last Edit: January 14, 2014, 05:38:19 PM by John »

Mike Lobanovsky

  • Guest
Re: BBC BASIC for Windows
« Reply #9 on: January 14, 2014, 03:56:49 PM »
is noticeably slower

I have once come across a super fast high-resolution Mandelbrot zoomer app on the net. It was built around a complex numbers library for almost never-ending resolution but still performed surprisingly fast. I described how it did that here. Unfortunately, I've lost my copy somewhere so I can't share it with you.

Offline John

  • Forum Support / SB Dev
  • Posts: 3512
    • ScriptBasic Open Source Project
Re: BBC BASIC for Windows
« Reply #10 on: January 14, 2014, 04:42:30 PM »
Quote
I've lost my copy somewhere so I can't share it with you.

Hate when that happens.  :'(

Maybe this will keep you occupied until you find your code.  ;)

Offline John

  • Forum Support / SB Dev
  • Posts: 3512
    • ScriptBasic Open Source Project
BBC BASIC for Windows - Examples
« Reply #11 on: January 14, 2014, 08:32:55 PM »
BBC Basic: the people's language



Code: [Select]
REM. Patterns created by rotating ellipses
REM. Richard Russell 06-Jul-2004

MODE 8
OFF
INSTALL @lib$+"ELLIPSE"

A% = 0
REPEAT
  GCOL 3,RND(15)
  PROCellipsefill(640,512,80,480,A%*PI/20)
  GCOL RND(15)
  PROCellipse(640,512,80,480,A%*PI/20)
  A% = (A%+1) MOD 20
UNTIL INKEY(5) <> -1



Code: [Select]
REM OpenGL AUXDEMO program translated into BBC BASIC for Windows
REM Richard Russell, 16-Oct-2010

SYS"LoadLibrary","OPENGL32.DLL" TO ogl%
GPA$="GetProcAddress"
SYSGPA$,ogl%,"wglCreateContext" TO `wglCreateContext`
SYSGPA$,ogl%,"wglDeleteContext" TO `wglDeleteContext`
SYSGPA$,ogl%,"wglMakeCurrent" TO `wglMakeCurrent`
SYSGPA$,ogl%,"glClearColor" TO `glClearColor`
SYSGPA$,ogl%,"glClearDepth" TO `glClearDepth`
SYSGPA$,ogl%,"glEnable" TO `glEnable`
SYSGPA$,ogl%,"glMatrixMode" TO `glMatrixMode`
SYSGPA$,ogl%,"glNewList" TO `glNewList`
SYSGPA$,ogl%,"glEndList" TO `glEndList`
SYSGPA$,ogl%,"glPushMatrix" TO `glPushMatrix`
SYSGPA$,ogl%,"glRotatef" TO `glRotatef`
SYSGPA$,ogl%,"glTranslatef" TO `glTranslatef`
SYSGPA$,ogl%,"glPopMatrix" TO `glPopMatrix`
SYSGPA$,ogl%,"glClear" TO `glClear`
SYSGPA$,ogl%,"glColor3b" TO `glColor3b`
SYSGPA$,ogl%,"glCallList" TO `glCallList`
SYS"LoadLibrary","GLU32.DLL" TO glu%
SYSGPA$,glu%,"gluPerspective" TO `gluPerspective`
SYSGPA$,glu%,"gluNewQuadric" TO `gluNewQuadric`
SYSGPA$,glu%,"gluQuadricDrawStyle" TO `gluQuadricDrawStyle`
SYSGPA$,glu%,"gluSphere" TO `gluSphere`
SYSGPA$,glu%,"gluQuadricNormals" TO `gluQuadricNormals`
SYSGPA$,glu%,"gluCylinder" TO `gluCylinder`

MODE8
PFD_MAIN=0
PFD_TYPE_RGBA=0
PFD_DOUBLEBUFFER=1
PFD_DRAW_TO_WINDOW=4
PFD_SUPPORT_OPENGL=&20
GL_DEPTH_TEST=&0B71
GL_COMPILE=&1300
GL_MODELVIEW=&1700
GL_PROJECTION=&1701
GL_DEPTH_BUFFER_BIT=&0100
GL_COLOR_BUFFER_BIT=&4000
GLU_SMOOTH=100000
GLU_LINE=100011
GLU_FILL=100012
GLOBE=1
CYLINDER=2
CONE=3

ONCLOSE PROCcleanup:QUIT
ONERROR PROCcleanup:SYS"MessageBox",@hwnd%,REPORT$,0,48:QUIT

REM SetupPixelFormat:
DIMpfd{Size{l&,h&},Version{l&,h&},Flags%,PixelType&,ColorBits&,\
\RedBits&,RedShift&,GreenBits&,GreenShift&,BlueBits&,BlueShift&,\
\AlphaBits&,AlphaShift&,AccumBits&,AccumRedBits&,AccumGreenBits&,\
\AccumBlueBits&,AccumAlphaBits&,DepthBits&,StencilBits&,AuxBuffers&,\
\LayerType&,Reserved&,LayerMask%,VisibleMask%,DamageMask%}
pfd.Size.l&=DIM(pfd{})
pfd.Version.l&=1
pfd.Flags%=PFD_DRAW_TO_WINDOW OR PFD_SUPPORT_OPENGL OR PFD_DOUBLEBUFFER
pfd.LayerMask%=PFD_MAIN
pfd.PixelType&=PFD_TYPE_RGBA
pfd.ColorBits&=24
pfd.DepthBits&=16
SYS"GetDC",@hwnd% TO ghDC%
SYS"ChoosePixelFormat",ghDC%,pfd{} TO pf%
SYS"SetPixelFormat",ghDC%,pf%,pfd{}
SYS`wglCreateContext`,ghDC% TO ghRC%
SYS`wglMakeCurrent`,ghDC%,ghRC%

REM InitializeGL:
SYS`glClearColor`,0,0,0,0
SYS`glClearDepth`,FN_dl(1.0),FN_dh(1.0)
SYS`glEnable`,GL_DEPTH_TEST
SYS`glMatrixMode`,GL_PROJECTION
SYS`gluPerspective`,FN_dl(45.0),FN_dh(45.0),FN_dl(1.25),FN_dh(1.25),FN_dl(3.0),FN_dh(3.0),FN_dl(7.0),FN_dh(7.0)
SYS`glMatrixMode`,GL_MODELVIEW
lat=0.0
long=0.0
latinc=0.5
longinc=0.5

REM CreateObjects:
SYS`glNewList`,GLOBE,GL_COMPILE
SYS`gluNewQuadric` TO obj%
SYS`gluQuadricDrawStyle`,obj%,GLU_LINE
SYS`gluSphere`,obj%,FN_dl(1.5),FN_dh(1.5),16,16
SYS`glEndList`
SYS`glNewList`,CONE,GL_COMPILE
SYS`gluNewQuadric` TO obj%
SYS`gluQuadricDrawStyle`,obj%,GLU_FILL
SYS`gluQuadricNormals`,obj%,GLU_SMOOTH
SYS`gluCylinder`,obj%,FN_dl(0.3),FN_dh(0.3),FN_dl(0.0),FN_dh(0.0),FN_dl(0.6),FN_dh(0.6),15,10
SYS`glEndList`
SYS`glNewList`,CYLINDER,GL_COMPILE
SYS`glPushMatrix`
SYS`glRotatef`,FN_f4(90.0),FN_f4(1.0),FN_f4(0.0),FN_f4(0.0)
SYS`glTranslatef`,FN_f4(0.0),FN_f4(0.0),FN_f4(-1.0)
SYS`gluNewQuadric` TO obj%
SYS`gluQuadricDrawStyle`,obj%,GLU_FILL
SYS`gluQuadricNormals`,obj%,GLU_SMOOTH
SYS`gluCylinder`,obj%,FN_dl(0.3),FN_dh(0.3),FN_dl(0.3),FN_dh(0.3),FN_dl(0.6),FN_dh(0.6),12,2
SYS`glPopMatrix`
SYS`glEndList`

REM Draw scene:
OFF
REPEAT
  K%=INKEY(2)
  CASEK%OF
    WHEN136:longinc+=0.5
    WHEN137:longinc-=0.5
    WHEN139:latinc+=0.5
    WHEN138:latinc-=0.5
  ENDCASE
  SYS`glClear`,GL_COLOR_BUFFER_BIT OR GL_DEPTH_BUFFER_BIT
  SYS`glPushMatrix`
  lat+=latinc
  long+=longinc
  SYS`glTranslatef`,FN_f4(0.0),FN_f4(0.0),FN_f4(-4.5)
  SYS`glRotatef`,FN_f4(-lat),FN_f4(1.0),FN_f4(0.0),FN_f4(0.0)
  SYS`glRotatef`,FN_f4(long),FN_f4(0.0),FN_f4(0.0),FN_f4(1.0)
  SYS`glColor3b`,127,0,0
  SYS`glCallList`,CONE
  SYS`glColor3b`,0,0,127
  SYS`glCallList`,GLOBE
  SYS`glColor3b`,0,127,0
  SYS`glPushMatrix`
  SYS`glTranslatef`,FN_f4(0.8),FN_f4(-0.65),FN_f4(0.0)
  SYS`glRotatef`,FN_f4(30.0),FN_f4(1.0),FN_f4(0.5),FN_f4(1.0)
  SYS`glCallList`,CYLINDER
  SYS`glPopMatrix`
  SYS`glPopMatrix`
  SYS"SwapBuffers",ghDC%
UNTILFALSE
END

DEFPROCcleanup
ghRC%+=0:IFghRC%SYS`wglDeleteContext`,ghRC%:ghRC%=0
ghDC%+=0:IFghDC%SYS"ReleaseDC",@hwnd%,ghDC%:ghDC%=0
ENDPROC

REM Convert to 4-byte float
DEFFN_f4(A#)
LOCALA%,P%
PRIVATEF%
IFF%=0THEN
  DIMP%10
  [OPT 2
  .F%
  mov esi,[ebp+2]:mov edi,[ebp+7]
  fld qword [esi]:fstp dword [edi]
  ret
  ]
ENDIF
A#*=1.0#
CALLF%,A#,A%
=A%

REM Convert to 8-byte double (low 4 bytes)
DEFFN_dl(A#)
A#*=1.0#
=!^A#

REM Convert to 8-byte double (high 4 bytes)
DEFFN_dh(A#)
A#*=1.0#
=!(^A#+4)



Code: [Select]
REM 'Fake' fractal fern
REM Original QBASIC program published in PC Magazine
REM BB4W version by David Williams
:
MODE 8
OFF
GCOL 2
:
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%

This is a slick demo of a slide rule. I have attached the compiled version of it.



Code: [Select]
REM Animated sliderule, inspired by Anatoly Sheyanov's LB program
REM By Richard Russell, http://www.rtrussell.co.uk/, 17-Dec-2013

INSTALL @lib$+"SPRITELIB"
IF FN_initsprites(2) = 0 STOP

ON CLOSE PROC_exitsprites : QUIT
ON ERROR SYS "MessageBox", @hwnd%, REPORT$, 0, 0 : PROC_exitsprites : QUIT

SYS "SetWindowText", @hwnd%, "Slide Rule - move the cursor and slider with the mouse or finger"

VDU 23,22,960;256;16,16,16,0
VDU 5
Margin% = 20
size = 924

REM Create the mottled cursor sprite:
FOR C% = 9 TO 15
  COLOUR C%, 160+2*C%, 160+2*C%, 160+2*C%
NEXT
FOR X% = 2 TO 294 STEP 4
  FOR Y% = 0 TO 28 STEP 4 : GCOL 8+RND(7) : PLOT X%,Y% : NEXT
  FOR Y% = 226 TO 254 STEP 4 : GCOL 8+RND(7) : PLOT X%,Y% : NEXT
NEXT
FOR Y% = 32 TO 224 STEP 4
  FOR X% = 2 TO 18 STEP 4 : GCOL 8+RND(7) : PLOT X%,Y% : NEXT
  FOR X% = 278 TO 294 STEP 4 : GCOL 8+RND(7) : PLOT X%,Y% : NEXT
NEXT

GCOL 0 : RECTANGLE FILL 22,28,256,194
MOVE 0,-2 : MOVE 0,30 : PLOT 85,32,-2
MOVE 300,-2 : MOVE 300,30 : PLOT 85,268,-2
MOVE 0,254 : MOVE 0,222 : PLOT 85,32,254
MOVE 300,254 : MOVE 300,222 : PLOT 85,268,254
GCOL 1 : LINE 150,30,150,222

GCOL 15 : RECTANGLE FILL 24,284,252,194
MOVE 0,254 : MOVE 0,284 : PLOT 85,30,254
MOVE 300,254 : MOVE 300,284 : PLOT 85,270,254
MOVE 0,510 : MOVE 0,480 : PLOT 85,30,510
MOVE 300,510 : MOVE 300,480 : PLOT 85,270,510
GCOL 0 : LINE 150,286,150,478

cursor$ = @tmp$ + "cursor.bmp"
OSCLI "GSAVE """ + cursor$ + """ 0, 0, 300, 512"
IF FN_createspritefrombmp(1, cursor$) = 0 STOP

REM Create the slider sprite:
CLS
GCOL 1
COLOUR 1, 230, 224, 72
RECTANGLE FILL 0,190,1920,128
GCOL 8

REM B scale:
@vdu%!220 = 16 : *FONT Arial Bold
MOVE 8,308 : PRINT "B"
start = 0
FOR C% = 0 TO 1
  PROCscale(1 - (C%<>0)*0.02, 2.001, 0.02, 0.1, 318, -14, start, start+size/2, TRUE)
  PROCscale(2.05, 5.001, 0.05, 0.1, 318, -14, start, start+size/2, TRUE)
  PROCscale(5.1, 10.001, 0.1, 0.5, 318, -14, start, start+size/2, TRUE)
  start += size/2
NEXT
REM C scale:
@vdu%!220 = 16 : *FONT Arial Bold
MOVE 8,232 : PRINT "C"
PROCscale(1, 2.001, 0.01, 0.05, 194, 14, 0, size, TRUE)
PROCscale(2.02, 4.001, 0.02, 0.1, 194, 14, 0, size, TRUE)
PROCscale(4.05, 10.001, 0.05, 0.1, 194, 14, 0, size, TRUE)
PROCpi(218, 12, size)

slider$ = @tmp$ + "slider.bmp"
OSCLI "GSAVE """ + slider$ + """ 0, 192, 1920, 258"
IF FN_createspritefrombmp(0, slider$) = 0 STOP

REM Draw the rest of the slide rule:
COLOUR 0, 0, 80, 150
CLG
GCOL 1
RECTANGLE FILL 0,62,1920,128
RECTANGLE FILL 0,318,1920,128
GCOL 8
LINE 0, 62, 1920, 62 : LINE 0, 448, 1920, 448
LINE 0, 192, 1920, 192 : LINE 0, 320, 1920, 320

REM K scale:
@vdu%!220 = 16 : *FONT Arial Bold
MOVE 8,420 : PRINT "K"
start = 0
FOR C% = 0 TO 2
  PROCscale(1 - (C%<>0)*0.05, 3.001, 0.05, 0.1, 380, 14, start, start+size/3, TRUE)
  PROCscale(3.1, 6.001, 0.1, 0.5, 380, 14, start, start+size/3, TRUE)
  PROCscale(6.2, 10.001, 0.2, 1.0, 380, 14, start, start+size/3, TRUE)
  start += size/3
NEXT
REM A scale:
@vdu%!220 = 16 : *FONT Arial Bold
MOVE 8,362 : PRINT "A"
start = 0
FOR C% = 0 TO 1
  PROCscale(1 - (C%<>0)*0.02, 2.001, 0.02, 0.1, 322, 14, start, start+size/2, TRUE)
  PROCscale(2.05, 5.001, 0.05, 0.1, 322, 14, start, start+size/2, TRUE)
  PROCscale(5.1, 10.001, 0.1, 0.5, 322, 14, start, start+size/2, TRUE)
  start += size/2
NEXT
REM D scale:
@vdu%!220 = 16 : *FONT Arial Bold
MOVE 8,182 : PRINT "D"
PROCscale(1, 2.001, 0.01, 0.05, 190, -14, 0, size, TRUE)
PROCscale(2.02, 4.001, 0.02, 0.1, 190, -14, 0, size, TRUE)
PROCscale(4.05, 10.001, 0.05, 0.1, 190, -14, 0, size, TRUE)
PROCpi(166, -12, size)
REM L scale:
@vdu%!220 = 16 : *FONT Arial Bold
MOVE 8,120 : PRINT "L"
PROCscale(0, 1.001, 0.005, 0.01, 124, -14, 0, size, FALSE)

REM Animate the slide rule:
slider% = 20
cursor% = 100
capture% = 0
MOUSE oldX%,Y%,B%
PROC_movesprite(0, slider%, 320, 1)
PROC_updatesprite(1, cursor%, 512, 1, 150, 256)
A% = 0
REPEAT
  MOUSE X%,Y%,B%
  IF A% AND B% AND 4 IF Y%>0 IF Y%<512 THEN
    IF X%<>oldX% THEN
      delta% = X%-oldX%
      IF capture%=1 OR capture%=0 AND X%>cursor% AND X%<cursor%+300 THEN
        capture% = 1
        cursor% += delta%
        IF cursor% < -280 cursor% = -280
        IF cursor% > 1900 cursor% = 1900
        PROC_updatesprite(1, cursor%, 512, 1, 150, 256)
      ELSE IF capture%=2 OR X%>slider% AND X%<slider%+1920 AND Y%>192 AND Y%<330 THEN;
        capture% = 2
        slider% += delta%
        IF slider% < -1900 slider% = -1900
        IF slider% > +1900 slider% = +1900
        PROC_movesprite(0, slider%, 320, 1)
      ENDIF
    ENDIF
  ELSE
    capture% = 0
  ENDIF
  A% = B%
  oldX% = X%
  WAIT 2
UNTIL FALSE
END

REM Plot one 'cycle' of a scale:
DEF PROCscale(v1, v2, vs, vl, y, l, x1, x2, f%)
LOCAL x, v, V%
FOR v = v1 TO v2 STEP vs
  IF f% x = Margin%+x1+LOG(v)*(x2-x1) ELSE x = Margin%+x1+v*(x2-x1)
  IF ABS(v/vl-INT(v/vl+0.5))<0.0001 THEN
    PROCaaline(x,y,y+l*1.5)
    V% = INT(v*10+0.5)
    IF vs <= 0.01 IF ABS(V%-v*10)<0.0001 IF V% MOD 10 THEN
      IF l>0 MOVE BY -6,24 ELSE MOVE BY -6,0
      @vdu%!220 = 13 : *FONT Arial
      PRINT ; V% MOD 10 ;
    ENDIF
  ELSE
    PROCaaline(x,y,y+l)
  ENDIF
  V% = INT(v+0.5)
  IF ABS(v-V%)<0.0001 THEN
    IF l>0 MOVE BY -6,30 ELSE MOVE BY -6,0
    @vdu%!220 = 16 : *FONT Arial
    PRINT LEFT$(STR$V%,1) ;
  ENDIF
NEXT
ENDPROC

REM Plot the PI symbol:
DEF PROCpi(y, l, s)
LOCAL x
x = Margin%+LOG(PI)*s
PROCaaline(x,y,y+l)
IF l>0 MOVE BY -8,30 ELSE MOVE BY -8,8
@vdu%!220 = 16 : *FONT Symbol
PRINT "p";
ENDPROC

REM Plot an antialiased vertical line:
DEF PROCaaline(x, y1%, y2%)
LOCAL X%, T%
GCOL 2
X% = INT(x) : x -= X% : X% *= 2
T% = TINT(X%, y2%)
COLOUR 2, (T% AND &FF) * x, (T% >> 8 AND &FF) * x, (T% >> 16) * x
LINE X%, y1%, X%, y2%
x = 1 - x
COLOUR 2, (T% AND &FF) * x, (T% >> 8 AND &FF) * x, (T% >> 16) * x
LINE X%+2, y1%, X%+2, y2%
GCOL 8
ENDPROC
« Last Edit: January 14, 2014, 10:17:55 PM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 3512
    • ScriptBasic Open Source Project
Re: BBC BASIC for Windows
« Reply #12 on: January 14, 2014, 11:55:39 PM »
Richard,

Can BBCW handle functions like the C printf() with a variable number of arguments? (using stdarg method)

I would like to try BBCW with IUP. I need variadic functionality and callback support to make it work.




rtrussell

  • Guest
Re: BBC BASIC for Windows
« Reply #13 on: January 15, 2014, 01:39:52 AM »
Can BBCW handle functions like the C printf() with a variable number of arguments?

Do you mean can it call variadic functions in an external library?  If so, yes it can (at least, it can so long as the ABI passes all the parameters on the stack, like stdcall or cdecl).  Here is an example of calling sprintf from BBC BASIC:

Code: [Select]
      SYS "GetModuleHandle", "MSVCRT.DLL" TO msvcrt%
      SYS "GetProcAddress", msvcrt%, "sprintf" TO sprintf

      ret$ = STRING$(255, CHR$0)
      SYS sprintf, ret$, "I have %i %s", 12, "apples" TO num%
      PRINT LEFT$(ret$, num%)

Richard.

Offline John

  • Forum Support / SB Dev
  • Posts: 3512
    • ScriptBasic Open Source Project
Re: BBC BASIC for Windows
« Reply #14 on: January 15, 2014, 02:05:37 AM »
Thanks Richard. I will give that a try. Ideally I would like to build a BBCW IUP library but haven't gotten that far yet.