AllBASIC Forum

BASIC Developer & Support Resources => Interpreters => Topic started by: rtrussell on January 14, 2014, 09:40:14 AM

Title: BBC BASIC for Windows
Post by: rtrussell 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.
Title: Re: BBC BASIC for Windows
Post by: John 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.

(http://files.allbasic.info/BBCWin/bbcwin_saucer.png)

http://files.allbasic.info/BBCWin/bbcw_sprites.swf

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
Title: Re: BBC BASIC for Windows
Post by: rtrussell 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.
Title: Re: BBC BASIC for Windows
Post by: John 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.

(http://files.allbasic.info/BBCWin/bbcw_asm.png)
Title: Re: BBC BASIC for Windows
Post by: rtrussell 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 (http://colourrecovery.wikispaces.com/Software+versions)

Richard.
Title: Re: BBC BASIC for Windows
Post by: John 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.
Title: Re: BBC BASIC for Windows
Post by: rtrussell 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.
Title: Re: BBC BASIC for Windows
Post by: Mike Lobanovsky 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! (http://www.fbsl.net/phpbb2/images/smilies/icon_biggrin.gif)

FBSL is enriched with both assembly and ANSI C JIT compilers for the exact same purposes.
Title: Re: BBC BASIC for Windows
Post by: John 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)
Title: Re: BBC BASIC for Windows
Post by: Mike Lobanovsky 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. (http://www.thinbasic.com/community/showthread.php?t=12334&p=90617&viewfull=1#post90617) Unfortunately, I've lost my copy somewhere so I can't share it with you.
Title: Re: BBC BASIC for Windows
Post by: John 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 (http://www.allbasic.info/forum/index.php?topic=294.msg3394#msg3394) will keep you occupied until you find your code.  ;)
Title: BBC BASIC for Windows - Examples
Post by: John on January 14, 2014, 08:32:55 PM
BBC Basic: the people's language (http://www.pcpro.co.uk/features/91575/bbc-basic-the-peoples-language)

(http://files.allbasic.info/BBCWin/bbcw_ellipes.png)

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

(http://files.allbasic.info/BBCWin/bbcw_opengl.png)

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)

(http://files.allbasic.info/BBCWin/bbcw_fern.png)

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.

(http://files.allbasic.info/BBCWin/bbcw_sliderule.png)

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
Title: Re: BBC BASIC for Windows
Post by: John 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.



Title: Re: BBC BASIC for Windows
Post by: rtrussell 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.
Title: Re: BBC BASIC for Windows
Post by: John 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.

Title: Re: BBC BASIC for Windows
Post by: John on January 15, 2014, 10:04:49 AM
Richard,

I have been looking at the existing libraries that come with BBCW to get a feel for how things work. I didn't realize that .BBC files need to be edited in the BBCW IDE as they have a binary format to them. I'm still unsure about some of the cryptic syntax outside the functions. The only red flag I've come across so far is the 65 KB string limitation. Is there a solution for dealing with large strings in BBCW?
Title: Re: BBC BASIC for Windows
Post by: rtrussell on January 15, 2014, 11:37:25 AM
I didn't realize that .BBC files need to be edited in the BBCW IDE as they have a binary format to them.

You can export them as regular text files: File... Save As... BASIC Text File (*.BAS).  But to be acceptable to the INSTALL statement you'll have to reverse the process in order to convert them back to the tokenised .BBC format.

Quote
The only red flag I've come across so far is the 65 KB string limitation. Is there a solution for dealing with large strings in BBCW?

That's a limitation of version 5 of BBC BASIC.  Version 6 has no practical string-length limitation (32-bit length field); I'm working towards releasing that but no date has been set.  The version 6 run-time engine forms part of my (freeware) product 'LB Booster', so is currently available to the end-user but without the convenience of an IDE.

Edit: I should add that, of course, when v6 is released it will be available free-of-charge to everybody who has purchased v5; I never charge for upgrades or bug fixes.

Richard.
Title: Re: BBC BASIC for Windows
Post by: John on January 15, 2014, 11:46:00 AM
That's great news Richard. The 64 KB current string limitation isn't a show stopper, only a future concern which you have elevated with your announcement of 6. I think that IUP will be much easier to work with for BBCW programmers looking for a forms based GUI. I think you have ease of use in graphics nailed.

Title: Re: BBC BASIC for Windows
Post by: John on January 15, 2014, 12:43:27 PM
Richard,

Is there an ODBC library for BBCW? My goal with this project is to use BBCW under Wine which includes using the Windows IUP library for the GUI. Wine's ODBC interface is native which means I can connect to my 64 bit MySQL and SQLite3 databases from BBCW.

Title: Re: BBC BASIC for Windows
Post by: rtrussell on January 15, 2014, 01:28:41 PM
Is there an ODBC library for BBCW?

I know that there have been user-generated libraries for MySQL and SQLite, but personally I have no experience of them and it's not an area in which I have any expertise.  If it's of interest the SQLite3 library is linked from this Wiki page:

http://bb4w.wikispaces.com/Libraries (http://bb4w.wikispaces.com/Libraries)

Richard.
Title: Re: BBC BASIC for Windows
Post by: John on January 15, 2014, 01:42:08 PM
Here is something you posted on your forum that didn't seem to go anywhere.

Code: [Select]
      SYS "LoadLibrary", "ODBC32.DLL" TO odbc%
      SYS "GetProcAddress", odbc%, "SQLAllocEnv" TO `SQLAllocEnv`
      SYS "GetProcAddress", odbc%, "SQLAllocConnect" TO `SQLAllocConnect`
      SYS "GetProcAddress", odbc%, "SQLDriverConnect" TO `SQLDriverConnect`
     
      SYS `SQLAllocEnv`, ^glEnv%
      IF glEnv% = 0 ERROR 100, "Unable to initialize ODBC API drivers"
     
      SYS `SQLAllocConnect`, glEnv%, ^glDbc%
      IF glDbc% = 0 ERROR 100, "Unable to allocate memory for connection handle"
     
      Connect$ = "DSN=" + DSN$ + ";UID=" + LoginID$ + ";PWD=" + Password$ + \
      \          ";APP=" + AppCode$ + ";DATABASE=" + Database$
     
      Result$ = STRING$(1024, CHR$0)
     
      SYS `SQLDriverConnect`, glDbc%, @hwnd%, Connect$, LEN(Connect$), \
      \                       Result$, LEN(Result$), ^size%, 0 TO res%
      IF res% ERROR 100, "Unable to connect to database"
     
      Result$ = LEFT$(Result$, size%)

I downloaded the user contributed SQLite library and plan on giving it a try. The ODBC interface is an attractive option for Wine.
Title: Re: BBC BASIC for Windows
Post by: rtrussell on January 15, 2014, 01:59:16 PM
Here is something you posted on your forum that didn't seem to go anywhere.

I don't recognise it; maybe somebody asked me to translate some C code into BBC BASIC.  For some reason, although I've taken an interest in all sorts of areas during my forty-odd years as a (part-time) programmer, database usage hasn't been one of them.  :)

Richard.
Title: Re: BBC BASIC for Windows
Post by: John on January 15, 2014, 02:20:58 PM
It was your reply to an Oracle connection request on the DB board.

I think BBC4W could have a very useful 2nd life under Wine. With XP's funeral in April, Wine and Linux isn't a bad alternative.


Title: Re: BBC BASIC for Windows
Post by: rtrussell on January 15, 2014, 03:43:02 PM
I think BBC4W could have a very useful 2nd life under Wine.

I'm happy for people to use it under Wine, at their own risk (!), but I don't offer specific support for that platform.  I've got a dual-boot Windows 7 / Ubuntu machine so I can run up Wine if I really need to, but I very rarely do.

When I last tried to update Ubuntu it crashed part way through, and I now have an installation which is neither one version nor another, and it won't update at all!  I'm told the solution is to re-install from a Ubuntu CD, but I'm terrified that if I do that it will bugger up the dual boot - that happened once and I couldn't boot into Windows at all.

And don't get me started on the stupidity of Grub reprogramming the video output of my PC so that my bog-standard Dell monitor won't lock, and simply displays 'No signal'.  Whoever thought that a boot loader should display graphics - even in a standard video mode - needs their head examined.  ::)

So I'm afraid my experiences with Linux have not been good, and I'm not a fan.

Richard.
Title: Re: BBC BASIC for Windows
Post by: John on January 15, 2014, 04:00:35 PM
Damn. That's a sad story.  :o

I'll be your Linux GOTO guy if you need a reference of someone using BBC4W and Wine.

FYI - The SQLite3 library worked fine.

(http://files.allbasic.info/BBCWin/bbc4w_sqlite3.png)

Code: [Select]
INSTALL @lib$+"SQLite"
PROCsqlite_initialise

ON ERROR PROCsqlite_close:PROCsqlite_finalise:PRINT:REPORT:END
ON CLOSE PROCsqlite_close:PROCsqlite_finalise:QUIT

file$=@dir$+"Phonenos.db"
PROCsqlite_open(file$)

PROCsqlite_exec( \
\ "CREATE TABLE IF NOT EXISTS phonenos (" + \
\     "name varchar(100), " + \
\     "phone varchar(100), " + \
\     "email varchar(100))")

PRINT "PhoneNos SQLite Example"
REPEAT
  PRINT '"  1. Create a record"
  PRINT "  2. Update a record"
  PRINT "  3. List all records"
  PRINT "  4. Search for a record"
  PRINT "  5. Delete a record"
  PRINT "  6. Exit"
  INPUT '"Enter 1-6 : "choice
  PRINT
  IF choice = 1 PROCcreate
  IF choice = 2 PROCupdate
  IF choice = 3 PROClist
  IF choice = 4 PROCsearch
  IF choice = 5 PROCdelete
UNTIL choice = 6
PROCsqlite_close
PROCsqlite_finalise
QUIT

DEF PROCcreate
LOCAL name$, phone$, email$
PRINT "Enter details"
INPUT LINE "    Name          : " name$
INPUT LINE "    Phone number  : " phone$
INPUT LINE "    Email address : " email$
name$ = FNsqlite_encodestring(name$)
phone$ = FNsqlite_encodestring(phone$)
email$ = FNsqlite_encodestring(email$)
PROCsqlite_exec( \
\ "INSERT INTO phonenos (name, phone, email) " + \
\ "VALUES ("+name$+","+phone$+","+email$+")")
ENDPROC

DEF PROCdelete
LOCAL id$
INPUT "Enter the RowID of the record to delete : "id$
id$ = FNsqlite_encodestring(id$)
PROCsqlite_exec( \
\ "DELETE FROM Phonenos " + \
\ "WHERE rowid="+id$+"")
ENDPROC

DEF PROClist
LOCAL row, numResults
PROCsqlite_get_array(\
\ "SELECT rowid, name, phone, email " + \
\     "FROM Phonenos ORDER BY name", A%())
numResults = DIM(A%(),1)
IF numResults = 0 THEN
  PRINT "No people found"
ELSE
  FOR row = 1 TO numResults
    PRINT "Person"
    PRINT "    RowID         : " $$A%(row, 0)
    PRINT "    Name          : " $$A%(row, 1)
    PRINT "    Phone number  : " $$A%(row, 2)
    PRINT "    Email address : " $$A%(row, 3)
    PRINT
  NEXT row
ENDIF
PROCsqlite_free_array(A%())
ENDPROC

DEF PROCsearch
LOCAL name$, row, numResults
INPUT"Enter the name to look for : "name$
name$ = FNsqlite_encodestring("%"+name$+"%")
PROCsqlite_get_array( \
\ "SELECT rowid, name, phone, email FROM Phonenos " +\
\ "WHERE name LIKE " + name$, A%())
numResults = DIM(A%(),1)
IF numResults = 0 THEN
  PRINT "Not found"
ELSE
  PRINT "    RowID         : " $$A%(1, 0)
  PRINT "    Name          : " $$A%(1, 1)
  PRINT "    Phone number  : " $$A%(1, 2)
  PRINT "    Email address : " $$A%(1, 3)
ENDIF
PROCsqlite_free_array(A%())
ENDPROC

DEF PROCupdate
LOCAL id$,  numResults, name$, phone$, email$, change$
INPUT"Enter the RowID of the record to update "id$
person$ = FNsqlite_encodestring(id$)
PROCsqlite_get_array( \
\ "SELECT rowid, name, phone, email FROM Phonenos "+ \
\ "WHERE rowid=" + id$, A%())
numResults = DIM(A%(),1)
PRINT
IF numResults = 0 THEN
  PRINT "Not found"
ELSE
  PRINT "Person"
  PRINT "    RowID         : " $$A%(1, 0)
  PRINT "    Name          : " $$A%(1, 1)
  PRINT "    Phone number  : " $$A%(1, 2)
  PRINT "    Email address : " $$A%(1, 3)
  INPUT "Change? (Y/N)" change$
  IF INSTR("Yy", change$) THEN
    PRINT '"Enter new details"
    INPUT LINE "    Name          : " name$
    INPUT LINE "    Phone number  : " phone$
    INPUT LINE "    Email address : " email$
    name$ = FNsqlite_encodestring(name$)
    phone$ = FNsqlite_encodestring(phone$)
    email$ = FNsqlite_encodestring(email$)
    id$ = FNsqlite_encodestring($$A%(1, 0))
    PROCsqlite_exec( \
    \ "UPDATE Phonenos SET " + \
    \     "name=" + name$ + \
    \     ", phone=" + phone$ + \
    \     ", email="+ email$ + \
    \ " WHERE rowid="+id$+"")
  ENDIF
  PROCsqlite_free_array(A%())
ENDIF
ENDPROC
Title: BBC BASIC for Windows - IUP
Post by: John on January 15, 2014, 09:33:11 PM
I was able to get a IUP Hello World example to work.

(http://files.allbasic.info/BBCWin/bbc4w_iuphello.png)

Code: [Select]
REM BBC4W IUP Hello World

SYS "GetModuleHandle", "kernel32.dll" TO _hdll%
SYS "GetProcAddress", _hdll%, "GetProcAddress" TO _%
SYS "LoadLibrary", @lib$+"iup.dll" TO _hdll%

SYS _%, _hdll%, "IupOpen" TO IupOpen%
SYS _%, _hdll%, "IupDialog" TO IupDialog%
SYS _%, _hdll%, "IupLabel" TO IupLabel%
SYS _%, _hdll%, "IupAppend" TO IupAppend%
SYS _%, _hdll%, "IupShow" TO IupShow%
SYS _%, _hdll%, "IupMainLoop" TO IupMainLoop%
SYS _%, _hdll%, "IupClose" TO IupClose%

SYS IupOpen%, 0, 0
SYS IupDialog% TO dlg%
SYS IupLabel%, "BBC BASIC for Windows" TO lbl%
SYS IupAppend%, dlg%, lbl%
SYS IupShow%
SYS IupMainLoop%
SYS IupClose%
END
Title: Re: BBC BASIC for Windows - IUP
Post by: rtrussell on January 16, 2014, 03:51:34 AM
Code: [Select]
SYS "GetModuleHandle", "kernel32.dll" TO _hdll%
SYS "GetProcAddress", _hdll%, "GetProcAddress" TO _%
SYS "LoadLibrary", @lib$+"iup.dll" TO _hdll%

SYS _%, _hdll%, "IupOpen" TO IupOpen%
SYS _%, _hdll%, "IupDialog" TO IupDialog%

Unless speed is critical (which it won't be here), feel free to simply use a string abbreviation of "GetProcAddress" rather than going to all the trouble of finding its numeric address:

Code: [Select]
gpa$ = "GetProcAddress"
SYS "LoadLibrary", @lib$+"iup.dll" TO _hdll%

SYS gpa$, _hdll%, "IupOpen" TO IupOpen%
SYS gpa$, _hdll%, "IupDialog" TO IupDialog%

Richard.
Title: Re: BBC BASIC for Windows - IUP
Post by: John on January 16, 2014, 09:20:58 AM
Thanks for the tip. I have a few questions before I take this further.

Title: Re: BBC BASIC for Windows - IUP
Post by: rtrussell on January 16, 2014, 10:35:23 AM
IUP creates its own dialog/window as does BBC4W. How do I hide the BBC4W created window?

This should do it:

Code: [Select]
      SYS "ShowWindow", @hwnd%, 0
If you end up compiling your program you can do it by selecting 'Hidden' as the 'Initial window state' in the Compile dialog.

Quote
I used the method in the SQLite3 example to load the iup.dll in  the Hello World example. Is there an easier way so I don't have to wrap all the SYS calls into BBC4W functions/procedures so I can nest them in my application code?

The only way of 'nesting' DLL function calls is to wrap them in FNs.  See the discussion on the BBC BASIC forum (http://bb4w.conforums.com/index.cgi?board=language&action=display&num=1389828725&start=0).   

Quote
I would like to create an IUP BBC4W library. What advice would you give creating it?

In what respect?  There's an article on writing libraries at the Wiki:

http://bb4w.wikispaces.com/Guide+to+writing+libraries (http://bb4w.wikispaces.com/Guide+to+writing+libraries)

Richard.
Title: Re: BBC BASIC for Windows - IUP
Post by: John on January 16, 2014, 11:14:59 AM
Thanks!

I think I have what I need to build an IUP library for BBC4W. The BBC4W window may come in handy for printing debug messages while in development.

Title: Re: BBC BASIC for Windows - IUP
Post by: John on January 17, 2014, 11:48:39 AM
Richard,

I converted my BBC4W IUP Hello World example to use a BBC4W library. I'm not seeing a IUP created dialog and the BBC4W windows is sitting at a prompt. It basically locks up Wine and I have to manually kill the Wine server to kill BBC4W. My original version using SYS only works fine.

IUP.BBC (IUP BBC4W Library)
Code: [Select]
      REM BBC4W IUP Library
      REM By John Spikowski - 1/16/2014


      DEF PROCiupopen
      LOCAL gpa$, ll%
      gpa$ = "GetProcAddress"
      SYS "LoadLibrary", @lib$+"iup.dll" TO ll%

      SYS gpa$, ll%, "IupOpen" TO IupOpen%
      SYS gpa$, ll%, "IupDialog" TO IupDialog%
      SYS gpa$, ll%, "IupLabel" TO IupLabel%
      SYS gpa$, ll%, "IupAppend" TO IupAppend%
      SYS gpa$, ll%, "IupShow" TO IupShow%
      SYS gpa$, ll%, "IupMainLoop" TO IupMainLoop%
      SYS gpa$, ll%, "IupClose" TO IupClose%

      SYS IupOpen%, 0, 0
      ENDPROC

      DEF PROCiupclose
      SYS IupClose%
      ENDPROC

      DEF PROCiupshow
      SYS IupShow%
      ENDPROC

      DEF PROCiupmainloop
      SYS IupMainLoop%
      ENDPROC

      DEF PROCiupappend(target%, dest%)
      SYS IupAppend%, dlg%, lbl%
      ENDPROC

      DEF FNiupdialog
      LOCAL dlg%
      SYS IupDialog% TO dlg%
      = dlg%

      DEF FNiuplabel(title$)
      LOCAL lbl%
      SYS IupLabel%, title$ TO lbl%
      = lbl%

HELLO2.BBC
Code: [Select]
      INSTALL @lib$+"IUP"

      PROCiupopen
      win% = FNiupdialog
      label% = FNiuplabel("BBC BASIC for Windows")
      PROCiupappend(win%, label%)
      PROCiupshow
      PROCiupmainloop
      PROCiupclose
Title: Re: BBC BASIC for Windows - IUP
Post by: rtrussell on January 17, 2014, 01:12:51 PM
My original version using SYS only works fine.

Sounds like you need to compare the working version with the non-working version!  To make that easier I would suggest temporarily copying the library into the 'main program' (you can use File Insert to do that) - that will give you a non-working version that doesn't involve any libraries.

Once you've got a working and a non-working version that both consist of a single source file it should hopefully be easy to see what difference is causing the problem.  The Differences utility (slot 1 in the Utilities menu) may be helpful.

Edit: This looks very suspicious!

Code: [Select]
      DEF PROCiupappend(target%, dest%)
      SYS IupAppend%, dlg%, lbl%
      ENDPROC

Richard.

Title: Re: BBC BASIC for Windows - IUP
Post by: John on January 17, 2014, 01:26:19 PM
I compared my original IUP SYS based test (see previous post for code) with what I just posted and I can't see why it doesn't work and locks up Wine.

Title: Re: BBC BASIC for Windows - IUP
Post by: rtrussell on January 17, 2014, 01:28:29 PM
This looks very suspicious!

The Cross-Reference utility (slot 5) would have alerted you to that faulty code.  Here is an edited extract of its report on your library:

Code: [Select]
Cross Reference Utility Report File
Created Fri.17 Jan 2014,21:26:35
....
Warnings:

  Possibly unused variables:
    PROCiupappend():
      target%
      dest%

  Shared variables which are not globals:
   ....
    PROCiupappend():
      IupAppend%
      dlg%
      lbl%

   ....
  Variables which violate naming guidelines:
    PROCiupappend():
      dlg%
      lbl%

Richard.

Title: Re: BBC BASIC for Windows - IUP
Post by: John on January 17, 2014, 01:33:19 PM
Code: [Select]
      REM INSTALL @lib$+"IUP"


      DEF PROCiupopen
      LOCAL _%, _hdll%
      SYS "GetModuleHandle", "kernel32.dll" TO _hdll%
      SYS "GetProcAddress", _hdll%, "GetProcAddress" TO _%
      SYS "LoadLibrary", @lib$+"iup.dll" TO _hdll%

      SYS _%, _hdll%, "IupOpen" TO IupOpen%
      SYS _%, _hdll%, "IupDialog" TO IupDialog%
      SYS _%, _hdll%, "IupLabel" TO IupLabel%
      SYS _%, _hdll%, "IupAppend" TO IupAppend%
      SYS _%, _hdll%, "IupShow" TO IupShow%
      SYS _%, _hdll%, "IupMainLoop" TO IupMainLoop%
      SYS _%, _hdll%, "IupClose" TO IupClose%

      SYS IupOpen%, 0, 0
      ENDPROC

      DEF PROCiupclose
      SYS IupClose%
      ENDPROC

      DEF PROCiupshow
      SYS IupShow%
      ENDPROC

      DEF PROCiupmainloop
      SYS IupMainLoop%
      ENDPROC

      DEF PROCiupappend(target%, dest%)
      SYS IupAppend%, dlg%, lbl%
      ENDPROC

      DEF FNiupdialog
      LOCAL dlg%
      SYS IupDialog% TO dlg%
      = dlg%

      DEF FNiuplabel(title$)
      LOCAL lbl%
      SYS IupLabel%, title$ TO lbl%
      = lbl%

      PROCiupopen
      win% = FNiupdialog
      label% = FNiuplabel("BBC BASIC for Windows")
      PROCiupappend(win%, label%)
      PROCiupshow
      PROCiupmainloop
      PROCiupclose

This combined version give me a runtime message of Not in a FN or PROC. Interesting but not a very help error message.
Title: Re: BBC BASIC for Windows - IUP
Post by: John on January 17, 2014, 01:38:43 PM
This looks very suspicious!

The Cross-Reference utility (slot 5) would have alerted you to that faulty code.  Here is an edited extract of its report on your library:

Code: [Select]
Cross Reference Utility Report File
Created Fri.17 Jan 2014,21:26:35
....
Warnings:

  Possibly unused variables:
    PROCiupappend():
      target%
      dest%

  Shared variables which are not globals:
   ....
    PROCiupappend():
      IupAppend%
      dlg%
      lbl%

   ....
  Variables which violate naming guidelines:
    PROCiupappend():
      dlg%
      lbl%

Richard.

Good Catch!

It works fine now. Thanks!
Title: Re: BBC BASIC for Windows
Post by: rtrussell on January 17, 2014, 01:41:52 PM
This combined version give me a runtime message of Not in a FN or PROC. Interesting but not a very help error message.
Would you prefer Missing END statement?  ;D

(it would be nice if the error reporting was that intelligent, but sadly it isn't).

Richard.
Title: Re: BBC BASIC for Windows - IUP
Post by: John on January 17, 2014, 02:12:48 PM
After you noticed my error I went back and redid the programs as I initially wrote them. This version doesn't seem to work. Here is the error message that is returned.

No such variable in module C:\BBCWin\lib\IUP

Code: [Select]
      INSTALL @lib$+"IUP"

      PROCIupOpen
      win% = FNIupDialog
      label% = FNIupLabel("BBC BASIC for Windows")
      PROCIupAppend(win%, label%)
      PROCIupShow
      PROCIupMainLoop
      PROCIupClose
      END

Code: [Select]
      REM BBC4W IUP Library
      REM By John Spikowski - 1/16/2014

      gpa$ = "GetProcAddress"
      SYS "LoadLibrary", @lib$+"iup.dll" TO ll%

      SYS gpa$, ll%, "IupOpen" TO IupOpen%
      SYS gpa$, ll%, "IupDialog" TO IupDialog%
      SYS gpa$, ll%, "IupLabel" TO IupLabel%
      SYS gpa$, ll%, "IupAppend" TO IupAppend%
      SYS gpa$, ll%, "IupShow" TO IupShow%
      SYS gpa$, ll%, "IupMainLoop" TO IupMainLoop%
      SYS gpa$, ll%, "IupClose" TO IupClose%

      DEF PROCIupOpen
      SYS IupOpen%, 0, 0
      ENDPROC

      DEF PROCIupClose
      SYS IupClose%
      ENDPROC

      DEF PROCIupShow
      SYS IupShow%
      ENDPROC

      DEF PROCIupMainLoop
      SYS IupMainLoop%
      ENDPROC

      DEF PROCIupAppend(target%, src%)
      SYS IupAppend%, target%, src%
      ENDPROC

      DEF FNIupDialog
      LOCAL dlg%
      SYS IupDialog% TO dlg%
      = dlg%

      DEF FNIupLabel(title$)
      LOCAL lbl%
      SYS IupLabel%, title$ TO lbl%
      = lbl%
Title: Re: BBC BASIC for Windows - IUP
Post by: rtrussell on January 17, 2014, 02:37:00 PM
After you noticed my error I went back and redid the programs as I initially wrote them. This version doesn't seem to work. Here is the error message that is returned.

Surely the problem is that you never execute the 'library initialisation' code which assigns values to IupOpen% etc?  In an earlier version of the program that initialisation was contained within PROCiupopen but now it appears to be 'dead' code that is sitting in the library but is never called (indeed there is no way of calling it because it isn't in a FN or PROC).

In time you will develop debugging techniques suited to BBC BASIC.  For example if an error message is reported (and no error trapping is in effect) the IDE will highlight the faulty statement in reverse video; in the case of a No such variable error that should tie down the undefined variable to only one or two possibilities, and if in doubt you can open the List Variables window to discover which is the one that wasn't defined.

If the error occurs within a library, as seems to be the case here, there's nothing for the IDE to highlight.  In that case you can either temporarily copy the library into the 'main program' (after the END or QUIT!) or you can use the Module Viewer utility (slot 4) in which case the IDE will be able to highlight the failing statement in the library's tab.

Richard.
Title: Re: BBC BASIC for Windows - IUP
Post by: John on January 17, 2014, 02:44:06 PM
Code: [Select]
      REM BBC4W IUP Library
      REM By John Spikowski - 1/16/2014

      DEF PROCIupOpen
      gpa$ = "GetProcAddress"
      SYS "LoadLibrary", @lib$+"iup.dll" TO ll%
      SYS gpa$, ll%, "IupOpen" TO IupOpen%
      SYS gpa$, ll%, "IupDialog" TO IupDialog%
      SYS gpa$, ll%, "IupLabel" TO IupLabel%
      SYS gpa$, ll%, "IupAppend" TO IupAppend%
      SYS gpa$, ll%, "IupShow" TO IupShow%
      SYS gpa$, ll%, "IupMainLoop" TO IupMainLoop%
      SYS gpa$, ll%, "IupClose" TO IupClose%
      SYS IupOpen%, 0, 0
      ENDPROC

      DEF PROCIupClose
      SYS IupClose%
      ENDPROC

      DEF PROCIupShow
      SYS IupShow%
      ENDPROC

      DEF PROCIupMainLoop
      SYS IupMainLoop%
      ENDPROC

      DEF PROCIupAppend(target%, src%)
      SYS IupAppend%, target%, src%
      ENDPROC

      DEF FNIupDialog
      LOCAL dlg%
      SYS IupDialog% TO dlg%
      = dlg%

      DEF FNIupLabel(title$)
      LOCAL lbl%
      SYS IupLabel%, title$ TO lbl%
      = lbl%

This works fine. ScriptBasic allows defining constants and global variables to the module outside of the module functions but within the MODULE/END MODULE directives. I think I'm ready to finish the IUP module now. Thanks for all the help getting up to speed with BBC4W.

Title: Re: BBC BASIC for Windows - IUP
Post by: John on January 17, 2014, 10:25:06 PM
I'm trying to test if CALLBACKs work with IUP and BBC4W. I get the following error message when trying to run the code.

No such variable

If I replace the PRINT with PRINT "Got Here". this is the message that is displayed.

Code: [Select]
Got Here

Not in a function

Code: [Select]
      INSTALL @lib$+"CALLBACK"
      INSTALL @lib$+"IUP"

      DEF FNButton_Click(^iup%, mbutton%, mpressed%)
      PRINT "Mouse Button: " + STR$(mbutton%)
      = -2

      PROCIupOpen
      win% = FNIupDialog
      but% = FNIupButton("Click Me")
      PROCIupAppend(win%, but%)
      PROCIupSetCallback(but%, "BUTTON_CB", FN_callback(FNButton_Click(), 3))
      PROCIupShow
      PROCIupMainLoop
      PROCIupClose
      END

Code: [Select]
      REM BBC4W IUP Library
      REM By John Spikowski - 1/16/2014

      DEF PROCIupOpen
      LOCAL gpa$, ll%
      gpa$ = "GetProcAddress"
      SYS "LoadLibrary", @lib$+"iup.dll" TO ll%
      SYS gpa$, ll%, "IupOpen" TO IupOpen%
      SYS gpa$, ll%, "IupDialog" TO IupDialog%
      SYS gpa$, ll%, "IupLabel" TO IupLabel%
      SYS gpa$, ll%, "IupButton" TO IupButton%
      SYS gpa$, ll%, "IupAppend" TO IupAppend%
      SYS gpa$, ll%, "IupShow" TO IupShow%
      SYS gpa$, ll%, "IupMainLoop" TO IupMainLoop%
      SYS gpa$, ll%, "IupClose" TO IupClose%
      SYS gpa$, ll%, "IupSetAttributes" TO IupSetAttributes%
      SYS qpa$, ll%, "IupSetCallback" TO IupSetCallback%
      SYS IupOpen%, 0, 0
      ENDPROC

      DEF PROCIupClose
      SYS IupClose%
      ENDPROC

      DEF PROCIupShow
      SYS IupShow%
      ENDPROC

      DEF PROCIupMainLoop
      SYS IupMainLoop%
      ENDPROC

      DEF PROCIupAppend(target%, src%)
      SYS IupAppend%, target%, src%
      ENDPROC

      DEF FNIupDialog
      LOCAL dlg%
      SYS IupDialog% TO dlg%
      = dlg%

      DEF FNIupLabel(title$)
      LOCAL lbl%
      SYS IupLabel%, title$ TO lbl%
      = lbl%

      DEF FNIupButton(title$)
      LOCAL btn%
      SYS IupButton%, title$ TO btn%
      = btn%

      DEF PROCIupSetAttributes(iup%, attribstr$)
      SYS IupSetAttributes%, iup%, attribstr$
      ENDPROC

      DEF PROCIupSetCallback(iup%, cbname$, cbfuncaddr%)
      SYS IupSetCallback%, iup%, cbname$, cbfuncaddr%
      ENDPROC
Title: Re: BBC BASIC for Windows - IUP
Post by: rtrussell on January 18, 2014, 02:50:59 AM
I get the following error message when trying to run the code.

You've got an inline function which consists of more than one line:

Code: [Select]
      DEF FNButton_Click(^iup%, mbutton%, mpressed%)
      PRINT "Mouse Button: " + STR$(mbutton%)
      = -2

Only single-line functions can be inlined, multi-line functions must be positioned after the END or QUIT.  This is a common requirement in BASIC.  Once again I think running the Cross Reference utility would have alerted you to problems in your code.

I don't think the first parameter of FNButton_Click above can be right: you can't specify a pointer (^iup%) as a formal parameter, it doesn't make sense.  You need to be particularly careful not to have errors in callbacks because everything can freeze up if BB4W aborts before it has a chance to return to the caller.

Lastly, it looks from the structure of your program that the callbacks happen within IupMainLoop.  In that case you will need to use the special non-blocking version of SYS when calling that API:

Code: [Select]
      DEF PROCIupMainLoop
      LOCAL dummy%
      SYS FN_syscalln(IupMainLoop%) TO !FN_systo(dummy%)
      ENDPROC

Richard.
Title: Re: BBC BASIC for Windows - IUP
Post by: John on January 18, 2014, 09:19:47 AM
Thanks for the tips and direction!

This is the error I'm now getting after the suggested changes were made.

No such variable in module C:\BBCWin\lib\IUP

The cross reference reports are included but due to names being truncated, it's hard to read. (trust)

BUTTON.BAC
Code: [Select]
      INSTALL @lib$+"CALLBACK"
      INSTALL @lib$+"IUP"

      PROCIupOpen
      win% = FNIupDialog
      but% = FNIupButton("Click Me")
      PROCIupAppend(win%, but%)
      PROCIupSetCallback(but%, "BUTTON_CB", FN_callback(FNButtonClick(), 3))
      PROCIupShow
      PROCIupMainLoop
      PROCIupClose
      END

      DEF FNButtonClick(iup%, mbutton%, mpressed%)
      PRINT "Mouse Button: " + STR$(mbutton%)
      = -2

BUTTON.rpt
Code: [Select]
Cross Reference Utility Report File
Created Sat.18 Jan 2014,09:08:54

Main program:

  Functions called:
    FNIupButto  [external]
    FNIupDialo  [external]

  Procedures called:
    PROCIupAppend()  [external]
    PROCIupClose  [external]
    PROCIupMainLoop  [external]
    PROCIupOpen  [external]
    PROCIupSetCallbac  [external]
    PROCIupShow  [external]

  Global variables:
    System variables:
      @lib$
    Integer variables:
      but%
      win%
    Variant variables:
      win

Functions:
  FNButtonClick
Procedures

Warnings:

  Possibly unused variables:
    Main program:
      but%
      win
      win%

  Possibly unused functions or procedures:
    FNButtonClick

End of report.

IUP.BAC (Library)
Code: [Select]
      REM BBC4W IUP Library
      REM By John Spikowski - 1/16/2014

      DEF PROCIupOpen
      LOCAL gpa$, ll%
      gpa$ = "GetProcAddress"
      SYS "LoadLibrary", @lib$+"iup.dll" TO ll%
      SYS gpa$, ll%, "IupOpen" TO IupOpen%
      SYS gpa$, ll%, "IupDialog" TO IupDialog%
      SYS gpa$, ll%, "IupLabel" TO IupLabel%
      SYS gpa$, ll%, "IupButton" TO IupButton%
      SYS gpa$, ll%, "IupAppend" TO IupAppend%
      SYS gpa$, ll%, "IupShow" TO IupShow%
      SYS gpa$, ll%, "IupMainLoop" TO IupMainLoop%
      SYS gpa$, ll%, "IupClose" TO IupClose%
      SYS gpa$, ll%, "IupSetAttributes" TO IupSetAttributes%
      SYS qpa$, ll%, "IupSetCallback" TO IupSetCallback%
      SYS IupOpen%, 0, 0
      ENDPROC

      DEF PROCIupClose
      SYS IupClose%
      ENDPROC

      DEF PROCIupShow
      SYS IupShow%
      ENDPROC

      DEF PROCIupMainLoop
      SYS IupMainLoop%
      ENDPROC

      DEF PROCIupAppend(target%, src%)
      SYS IupAppend%, target%, src%
      ENDPROC

      DEF FNIupDialog
      LOCAL dlg%
      SYS IupDialog% TO dlg%
      = dlg%

      DEF FNIupLabel(title$)
      LOCAL lbl%
      SYS IupLabel%, title$ TO lbl%
      = lbl%

      DEF FNIupButton(title$)
      LOCAL btn%
      SYS IupButton%, title$ TO btn%
      = btn%

      DEF PROCIupSetAttributes(iup%, attribstr$)
      SYS IupSetAttributes%, iup%, attribstr$
      ENDPROC

      DEF PROCIupMainLoop
      LOCAL dummy%
      SYS FN_syscalln(IupMainLoop%) TO !FN_systo(dummy%)
      ENDPROC

IUP.rpt
Code: [Select]
Cross Reference Utility Report File
Created Sat.18 Jan 2014,09:11:02
Main program

Functions:

  FNIupButton():
    Local variables:
      Integer variables:
        btn%
      Variant variables:
        ti
    Shared variables:
      Integer variables:
        IupButton%

  FNIupDialog:
    Local variables:
      Integer variables:
        dlg%
    Shared variables:
      Integer variables:
        IupDialog%

  FNIupLabel():
    Local variables:
      Integer variables:
        lbl%
      Variant variables:
        tit
    Shared variables:
      Integer variables:
        IupLabel%

Procedures:

  PROCIupAppend():
    Shared variables:
      Integer variables:
        IupAppend%
      Variant variables:
        ta

  PROCIupClose:
    Shared variables:
      Integer variables:
        IupClose%

  PROCIupMainLoo:
    Functions called:
      FN_syscalln()  [external]
    Shared variables:
      Variant variables:
        Iu

  PROCIupMainLoo:
    Shared variables:
      Integer variables:
        IupMainLoop%

  PROCIupOpen:
    Local variables:
      Integer variables:
        ll%
      String variables:
        gpa$
    Shared variables:
      Integer variables:
        IupOpen%
      String variables:
        qpa$

  PROCIupSetAttr:
    Shared variables:
      Variant variables:
        IupSetAttribut

  PROCIupShow:
    Shared variables:
      Integer variables:
        IupShow%

Warnings:

  Possibly unused variables:
    FNIupButton():
      IupButton%
      btn%
    FNIupDialog:
      IupDialog%
      dlg%
    FNIupLabel():
      IupLabel%
      lbl%
    PROCIupAppend():
      IupAppend%
      ta
    PROCIupClose:
      IupClose%
    PROCIupMainLoo:
      dummy%
      Iu
    PROCIupMainLoo:
      IupMainLoop%
    PROCIupOpen:
      IupOpen%
      qpa$
    PROCIupSetAttr:
      IupSetAttribut
    PROCIupShow:
      IupShow%

  Possibly unused functions or procedures:
    FNIupButton()
    FNIupDialog
    FNIupLabel()
    PROCIupAppend()
    PROCIupClose
    PROCIupMainLoo
    PROCIupMainLoo
    PROCIupOpen
    PROCIupSetAttr
    PROCIupShow

  Functions or procedures with the same name:
    PROCIupMainLoo
    PROCIupMainLoo

  Shared variables which are not globals:
    FNIupButton():
      IupButton%
    FNIupDialog:
      IupDialog%
    FNIupLabel():
      IupLabel%
    PROCIupAppend():
      IupAppend%
      ta
    PROCIupClose:
      IupClose%
    PROCIupMainLoo:
      Iu
    PROCIupMainLoo:
      IupMainLoop%
    PROCIupOpen:
      IupOpen%
      qpa$
    PROCIupSetAttr:
      IupSetAttribut
    PROCIupShow:
      IupShow%

  Variables which violate naming guidelines:
    PROCIupAppend():
      ta
    PROCIupOpen:
      qpa$

End of report.

Title: Re: BBC BASIC for Windows - IUP
Post by: rtrussell on January 18, 2014, 09:35:40 AM
The cross reference reports are included but due to names being truncated, it's hard to read.

No idea what's causing the truncation - it doesn't happen in Windows.  If you can't see the bug in your code perhaps a visit to the optometrist is in order, or you can study these sections of the report:   ;)

Code: [Select]
  Possibly unused variables:
    PROCIupOpen:
      qpa$

  Shared variables which are not globals:
    PROCIupOpen:
      qpa$

  Variables which violate naming guidelines:
    PROCIupOpen:
      qpa$

And there's a worrying warning here:

Code: [Select]
  Functions or procedures with the same name:
    PROCIupMainLoop
    PROCIupMainLoop

Take a bit more care!

Richard.
Title: Re: BBC BASIC for Windows - IUP
Post by: John on January 18, 2014, 09:48:18 AM
Quote
If you can't see the bug in your code perhaps a visit to the optometrist is in order, or you can study these sections of the report:

Cut me some slack. A g and a q look like cousins.  ;D

After that fix, this is the error I'm getting.

No such FN/PROC

Code: [Select]
Cross Reference Utility Report File
Created Sat.18 Jan 2014,09:47:23

Main program:

  Functions called:
    FNIupButton  [external]
    FNIupDialog  [external]

  Procedures called:
    PROCIupAppend()  [external]
    PROCIupClose  [external]
    PROCIupMainLoop  [external]
    PROCIupOpen  [external]
    PROCIupSetCallback  [external]
    PROCIupShow  [external]

  Global variables:
    System variables:
      @lib$
    Integer variables:
      but%
      win%

Functions:
  FNButtonClick()
Procedures

Warnings:

  Possibly unused variables:
    Main program:
      but%

  Possibly unused functions or procedures:
    FNButtonClick()

End of report.
Title: Re: BBC BASIC for Windows - IUP
Post by: rtrussell on January 18, 2014, 10:04:14 AM
After that fix, this is the error I'm getting.
No such FN/PROC

Look and see which line in your program is highlighted when the error occurs - this is the line which is calling a non-existent FN or PROC.   :)

Richard.
Title: Re: BBC BASIC for Windows - IUP
Post by: John on January 18, 2014, 10:17:37 AM
Code: [Select]
      PROCIupSetCallback(but%, "BUTTON_CB", FN_callback(FNButtonClick(), 3))

It seems this nesting of BBC4W functions isn't being recognized. (guess)

Code: [Select]
      INSTALL @lib$+"CALLBACK"
      INSTALL @lib$+"IUP"

      PROCIupOpen
      win% = FNIupDialog
      but% = FNIupButton("Click Me")
      PROCIupAppend(win%, but%)
      cbaddr% = FN_callback(FNButtonClick(), 3)
      PROCIupSetCallback(but%, "BUTTON_CB", cbaddr%)
      PROCIupShow
      PROCIupMainLoop
      PROCIupClose
      END

      DEF FNButtonClick(iup%, mbutton%, mpressed%)
      PRINT "Mouse Button: " + STR$(mbutton%)
      = -2

This doesn't help either.  :-[
Title: Re: BBC BASIC for Windows - IUP
Post by: rtrussell on January 18, 2014, 10:27:28 AM
Code: [Select]
      PROCIupSetCallback(but%, "BUTTON_CB", FN_callback(FNButtonClick(), 3))

It seems this nesting of BBC4W functions isn't being recognized. (guess)

There's nothing wrong with that code.  If it is causing a No such FN/PROC error really there's only one likely explanation - BBC BASIC doesn't think the procedure PROCIupSetCallback() exists.  In the most recent version of your library you listed it didn't - have you added it since?

The simplest explanation is often the correct one.

Richard.
Title: Re: BBC BASIC for Windows - IUP
Post by: John on January 18, 2014, 10:36:57 AM
Another good catch. I'm signing you up for the All Stars next year.  :)

No errors but no IUP dialog with a button either.

Code: [Select]
      REM BBC4W IUP Library
      REM By John Spikowski - 1/16/2014

      DEF PROCIupOpen
      LOCAL gpa$, ll%
      gpa$ = "GetProcAddress"
      SYS "LoadLibrary", @lib$+"iup.dll" TO ll%
      SYS gpa$, ll%, "IupOpen" TO IupOpen%
      SYS gpa$, ll%, "IupDialog" TO IupDialog%
      SYS gpa$, ll%, "IupLabel" TO IupLabel%
      SYS gpa$, ll%, "IupButton" TO IupButton%
      SYS gpa$, ll%, "IupAppend" TO IupAppend%
      SYS gpa$, ll%, "IupShow" TO IupShow%
      SYS gpa$, ll%, "IupMainLoop" TO IupMainLoop%
      SYS gpa$, ll%, "IupClose" TO IupClose%
      SYS gpa$, ll%, "IupSetAttributes" TO IupSetAttributes%
      SYS gpa$, ll%, "IupSetCallback" TO IupSetCallback%
      SYS IupOpen%, 0, 0
      ENDPROC

      DEF PROCIupClose
      SYS IupClose%
      ENDPROC

      DEF PROCIupShow
      SYS IupShow%
      ENDPROC

      DEF PROCIupMainLoop
      SYS IupMainLoop%
      ENDPROC

      DEF PROCIupAppend(target%, src%)
      SYS IupAppend%, target%, src%
      ENDPROC

      DEF FNIupDialog
      LOCAL dlg%
      SYS IupDialog% TO dlg%
      = dlg%

      DEF FNIupLabel(title$)
      LOCAL lbl%
      SYS IupLabel%, title$ TO lbl%
      = lbl%

      DEF FNIupButton(title$)
      LOCAL btn%
      SYS IupButton%, title$ TO btn%
      = btn%

      DEF PROCIupSetAttributes(iup%, attribstr$)
      SYS IupSetAttributes%, iup%, attribstr$
      ENDPROC

      DEF PROCIupMainLoop
      LOCAL dummy%
      SYS FN_syscalln(IupMainLoop%) TO !FN_systo(dummy%)
      ENDPROC

      DEF PROCIupSetCallback(iup%, cbtype$, cbaddr%)
      SYS IupSetCallback%, iup%, cbtype$, cbaddr%
      ENDPROC
Title: Re: BBC BASIC for Windows - IUP
Post by: John on January 18, 2014, 10:54:12 AM
My error. IupShow() needed something to show.

Code: [Select]
      INSTALL @lib$+"CALLBACK"
      INSTALL @lib$+"IUP"

      PROCIupOpen
      win% = FNIupDialog
      but% = FNIupButton("Click Me")
      PROCIupAppend(win%, but%)
      cbaddr% = FN_callback(FNButtonClick(), 3)
      PROCIupSetCallback(but%, "BUTTON_CB", cbaddr%)
      PROCIupShow(win%)
      PROCIupMainLoop
      PROCIupClose
      END

      DEF FNButtonClick(iup%, mbutton%, mpressed%)
      PRINT "Mouse Button: " + STR$(mbutton%)
      = -2

The IUP dialog shows with a button (no title) and puts the window in stress mode with a dialog popping. (non-responding - force quit)

Maybe the IupMainLoop() shouldn't have the special blocking SYS call?
Title: Re: BBC BASIC for Windows - IUP
Post by: rtrussell on January 18, 2014, 11:19:53 AM
Maybe the IupMainLoop() shouldn't have the special blocking SYS call?

Non-blocking.  You can try that, but I would have expected it to result in a deadlock.

More likely, I think, is that one or more of the other SYS calls does also need the special non-blocking version.  Try using it for IupShow:

Code: [Select]
      DEF PROCIupShow
      LOCAL dummy%
      SYS FN_syscalln("IupShow%") TO !FN_systo(dummy%)
      ENDPROC

Richard.
Title: Re: BBC BASIC for Windows - IUP
Post by: John on January 18, 2014, 11:26:01 AM
Using a standard SYS call for IupMainLoop seemed to solve the lockup (non-responding) issue. I'm not seeing events or can I close the IUP dialog or BBC4W.

(http://files.allbasic.info/BBCWin/bbc4w_button.png)

Can you download IUP for Windows and give this a try on your end? I'm using the VC10 DLL set.

Update

The IUP window closes correctly if I don't click the button first. As soon as I click the button, everything locks up.

Title: Re: BBC BASIC for Windows - IUP
Post by: rtrussell on January 18, 2014, 12:09:32 PM
Can you download IUP for Windows and give this a try on your end?

Where is the download?  When I tried to find it earlier on today all I could locate was a DLL with a dependency on Cygwin, which I don't have on any of my PCs (and don't want - I use MinGW).

Richard.
Title: Re: BBC BASIC for Windows - IUP 3.10
Post by: John on January 18, 2014, 12:16:08 PM
You're in luck. It seems IUP just released 3.10 within the last 24 hours.

Download Link (http://sourceforge.net/projects/iup/files/3.10/Windows%20Libraries/Dynamic/iup-3.10_Win32_dll10_lib.zip/download)

Title: Re: BBC BASIC for Windows - IUP 3.10
Post by: rtrussell on January 18, 2014, 01:02:17 PM
Download Link (http://sourceforge.net/projects/iup/files/3.10/Windows%20Libraries/Dynamic/iup-3.10_Win32_dll10_lib.zip/download)

Do I need all the DLLs in the zip, or just iup.dll?

I'll also need the latest versions of your test program and library.

Richard.
Title: Re: BBC BASIC for Windows - IUP
Post by: John on January 18, 2014, 01:21:12 PM
I just copied all the IUP DLLs (excluding the IupLua*.dll) to my SysWOW64 directory.

I will e-mail you a zip of my BUTTON.BCC and IUP.BCC files.

Title: Re: BBC BASIC for Windows - IUP
Post by: rtrussell on January 18, 2014, 03:44:53 PM
Right, everything works!  You will need to download CALLBACK_cdecl.BBC from here (http://wiggio.com/yui/folder/stream_file.php?doc_key=wFY6WXV1d4wc4RfkbI820N0dCiV5BqxnSqgCPCrkgAs=).  The BASIC files are listed below:

BUTTON.BBC
Code: [Select]
      INSTALL @lib$+"CALLBACK_cdecl"
      INSTALL @lib$+"IUP"

      PROCIupOpen
      win% = FNIupDialog
      but% = FNIupButton("Click Me")
      PROCIupAppend(win%, but%)
      cbaddr% = FN_callback(FNButtonClick(), 6)
      PROCIupSetCallback(but%, "BUTTON_CB", cbaddr%)
      PROCIupShow(win%)
      PROCIupMainLoop
      PROCIupClose
      END

      DEF FNButtonClick(ih%, button%, pressed%, x%, y%, status%)
      PRINT "Mouse Button: "; button% " " pressed%
      = -2

IUP.BBC
Code: [Select]
      REM BBC4W IUP Library
      REM By John Spikowski - 1/16/2014

      DEF PROCIupOpen
      LOCAL gpa$, ll%
      gpa$ = "GetProcAddress"
      SYS "LoadLibrary", "iup.dll" TO ll%
      SYS gpa$, ll%, "IupOpen" TO IupOpen%
      SYS gpa$, ll%, "IupDialog" TO IupDialog%
      SYS gpa$, ll%, "IupLabel" TO IupLabel%
      SYS gpa$, ll%, "IupButton" TO IupButton%
      SYS gpa$, ll%, "IupAppend" TO IupAppend%
      SYS gpa$, ll%, "IupShow" TO IupShow%
      SYS gpa$, ll%, "IupMainLoop" TO IupMainLoop%
      SYS gpa$, ll%, "IupClose" TO IupClose%
      SYS gpa$, ll%, "IupSetAttributes" TO IupSetAttributes%
      SYS gpa$, ll%, "IupSetCallback" TO IupSetCallback%
      SYS IupOpen%, 0, 0
      ENDPROC

      DEF PROCIupClose
      SYS IupClose%
      ENDPROC

      DEF PROCIupShow(iup%)
      LOCAL dummy%
      SYS FN_syscalln(IupShow%), iup% TO !FN_systo(dummy%)
      ENDPROC

      DEF PROCIupMainLoop
      LOCAL dummy%
      SYS FN_syscalln(IupMainLoop%) TO !FN_systo(dummy%)
      ENDPROC

      DEF PROCIupAppend(target%, src%)
      SYS IupAppend%, target%, src%
      ENDPROC

      DEF FNIupDialog
      LOCAL dlg%
      SYS IupDialog% TO dlg%
      = dlg%

      DEF FNIupLabel(title$)
      LOCAL lbl%
      SYS IupLabel%, title$ TO lbl%
      = lbl%

      DEF FNIupButton(title$)
      LOCAL btn%
      SYS IupButton%, title$, "" TO btn%
      = btn%

      DEF PROCIupSetAttributes(iup%, attribstr$)
      SYS IupSetAttributes%, iup%, attribstr$
      ENDPROC

      DEF PROCIupSetCallback(iup%, cbtype$, cbaddr%)
      LOCAL dummy%
      cbtype$ += CHR$(0)
      SYS FN_syscalln(IupSetCallback%), iup%, cbtype$, cbaddr% TO !FN_systo(dummy%)
      ENDPROC

Richard.
Title: Re: BBC BASIC for Windows - IUP
Post by: John on January 18, 2014, 04:22:52 PM
Thanks Richard!

IUP looks like a good fit for BBC BASIC for Windows. I slightly modified your BUTTON.BBC to print the mouse button number (1=left, 2=middle, 3=right) and the mouse button state. (pressed / released)

Wine 1.6.1

(http://files.allbasic.info/BBCWin/bbc4w_butfinal.png)

FYI: It seems IupShow() and IupMainLoop() are the only functions that need the special SYS call. IupSetCallback with a normal SYS works fine.
Title: Re: BBC BASIC for Windows - IUP
Post by: John on January 18, 2014, 10:21:49 PM
Nice to see XP theme support working with BBC4W and IUP on Windows XP. (VirtualBox) I haven't been able to get XP theme support to work on Wine yet.

Windows XP

(http://files.allbasic.info/BBCWin/bbc4w_butxp.png)


Windows 7 64 bit

(http://files.allbasic.info/BBCWin/bb4w_win7.png)

Title: Re: BBC BASIC for Windows - IUP vs. Native BBC GUI
Post by: John on January 19, 2014, 05:15:11 PM
Richard and I were having a discussion about the benefits of IUP to BBC4W users. Here is a BBC4W native version of the BUTTON.BBC example.

The native version is theming the button and takes less code to produce. It only detected the left mouse button and the click event as a whole but 95% of the time that is all you need.

(http://files.allbasic.info/BBCWin/bbc4w_gui.png)

Update

I spent some time this evening going over the BBC BASIC for Windows documentation on Windows programming. I try to avoid any language that depends on translating and passing Windows messages as a means of communicating with the GUI. The Windows message system is the ugliest thing I've ever seen and mastering that mess has never been a goal of mine.

I think direct positioning is a legacy technique and containerized self resizing controls are the way things are now done. The message loop handler has to be a bit smarter than a REPEAT/UNTIL waiting for something to generate FALSE state. For the quick one screen utility/game the native BBC4W GUI interface would more than likely work out fine. I wouldn't try to write anything for my clients using that direction. (non-maintainable)

I think BBC BASIC for Windows is a great interactive interpreter and you should be proud of your efforts maturing it to this point. The built-in assembler sets it above the rest with that feature alone. Graphics are another area you excel in with the BASIC.

One of the features of IUP I really like is the interactive GUI layout tool as an API call. Changes made via the dialog layout tool / property sheet are immediately reflected in the running application. Here is an example of our BUTTON.BBC demo using the IupLayoutDialog() function.

(http://files.allbasic.info/BBCWin/IUP/bbc4w_main.png)

(http://files.allbasic.info/BBCWin/IUP/bbc4w_output.png)

(http://files.allbasic.info/BBCWin/IUP/bbc4w_appwin.png)

(http://files.allbasic.info/BBCWin/IUP/bbc4w_layout.png)

(http://files.allbasic.info/BBCWin/IUP/bbc4w_prop.png)

(http://files.allbasic.info/BBCWin/IUP/bbc4w_propcb.png)

Notice how the background of the dialog was changed via the property sheet and the dialog layout showing the expanded window size. I could add / remove controls from the layout tool and generate a C, LED or Lua source code with the changes.

Title: Re: BBC BASIC for Windows - IUP vs. Native BBC GUI
Post by: John on January 20, 2014, 12:46:33 PM
Here is the Windows 7 64 bit version of the above screens running under Wine.

(http://files.allbasic.info/BBCWin/IUP/bbc4w_main_w7.png)

(http://files.allbasic.info/BBCWin/IUP/bbc4w_output_w7.png)

(http://files.allbasic.info/BBCWin/IUP/bbc4w_appwin_w7.png)

(http://files.allbasic.info/BBCWin/IUP/bbc4w_layout_w7.png)

(http://files.allbasic.info/BBCWin/IUP/bbc4w_prop_w7.png)
Title: BBC BASIC for Windows - Closing Post
Post by: John on January 20, 2014, 01:33:41 PM
I have enjoyed working with BBC BASIC for Windows and it's author Richard. BBC4W is one of the best interactive BASIC languages I have had the privilege to work with and recommend buying a copy for your toolbox.

Title: Re: BBC BASIC for Windows
Post by: John on February 05, 2014, 10:32:20 AM
Quote from: Richard - BP.org (http://forum.basicprogramming.org/index.php/topic,2984.msg23181.html)
This is not (at least, it was not intended to be) a 'my BASIC is better than yours' (and even less 'my OS is better than yours') thread.  It was specifically an attempt to seek out somebody who would be interested in porting BBC BASIC for Windows onto another platform by using my relocatable object modules.  Sadly nobody here seems to find this an interesting project; I will look elsewhere.

Putting the graphics aspect of BBC BASIC aside, what makes BBC BASIC for Windows a better BASIC then what is currently offered now? (most free) BaCon is a C translator so the advantage of a assembler in BBC4W rapidly diminishes.

I have said this from the beginning that my interest in BBC BASIC (Brandy BASIC V) was the easy to use (old school) graphics syntax and the auto clipping of off screen rendering. I have included the BBC graphics syntax in the ScriptBasic SDL extension module along with SDL_draw, SDL_image, SDL_terminal and a few routines I slapped together to fill in the holes.

You didn't seem to like my Back to the Future comment on your forum where  a BBC4ARM BASIC (possibly embedded) in Raspberry PI class development boards direction had merit. Taking advantage of your past ARM RISC knowledge when working on the original ACORN PCs seemed like a natural to me. With more home automation, security with mobile access, these project boards are becoming more of a draw to hobbyists and as a educational tool. It's would be a new adventure but in familiar territory. It all depends my much energy and effort you're willing to invest changing platforms IF this makes any sense to you.
 
Quote
Bringing Brandy up to an equivalent degree of functionality, as suggested earlier in the thread, is theoretically an alternative approach, but it would be far more work and probably quite impractical to achieve an acceptable degree of compatibility.  That would certainly qualify as 'reinventing the wheel'.

No one is arguing that BBC4W and Napoleon are more advanced / more compatible BBC BASIC than Brandy BASIC V (SDL). The point is that we have something working that is portable and lets each BASIC that binds to the BBC API  another twist on language. What's wrong with BBC Old School Graphics being a theme for the library? Lets get the Brandy SDL graphics compatible and then worry about making it faster / better. Not many are going to bitch about a second or two either way. BASIC should stand for easy to use and should hide the uglies under the covers for more qualified to maintain.

Quote
By finding the courage to be ourselves, we gain the power to make a difference.
 
-- Lindsey Stirling --
Title: Re: BBC BASIC for Windows
Post by: John on March 10, 2014, 01:02:48 PM
Quote from: Richard Russell - BBC4W forum
Where have the BB4W supporters gone?
   
Once upon a time there were plenty of enthusiastic BB4W users who were keen to support the language, for example in the creation of libraries (e.g. BB4WMAPM), support utilities (e.g. the API Viewer plug-in), documentation (e.g. the Beginners' Tutorial) etc.

But now that enthusiasm seems to have completely evaporated. Here are some examples of attempts to get the BB4W 'community' to help support the language which have failed:

  • DLGEDITCE (the Community Edition of the Dialogue Editor). At one time that project had at least three active members, but when I recently posted a message here asking for somebody to report on its status, there was not a single reply.
  • GUILIB (the proposed new library to support the Windows GUI). Despite me publishing a draft specification, and some initial activity, that project appears to have been abandoned because of an unwillingness by interested parties to cooperate.
  • BB4W version 6. This new version of BB4W, initially developed to support 'LB Booster', is stalled because of the several volunteers who offered to be testers only two have provided any feedback! Most haven't even acknowledged receipt of the Beta version.
  • BB4W for Linux. A while ago I asked for somebody to help port BB4W to Linux. You might think this is a worthwhile exercise that would attract some interest, but nothing!

This is all very disappointing and demotivating.

Richard.

I haven't seen much activity or interest in the Script BASIC BBC graphics extension module either. Maybe it's time to reinvent / return to the environment BBC BASIC has always been successful at. Hobbyists programming for fun. The Raspberry PI like boards and ARM/RISC processors seems like a natural for your offering. I personally think your wasting your time competing in the Windows environment with a nostalgic BASIC language that can't be decoupled from its IDE. I think your pushing the envelope using the term standalone compiled application. BBC4W has become too fragmented trying to adapt to Windows and still be relevant. IMHO
Title: Re: BBC BASIC for Windows
Post by: John on March 16, 2014, 10:59:04 AM
Quote from: Richard Russell - BP.org
Most BASIC code is functional, but not particularly pretty.  I thought I'd share what I consider to be a beautiful piece of BBC BASIC code (OK, admittedly I wrote it myself!) which not only runs blindingly fast - it does a least-squares fit of a 5th-order polynomial to 20,000 data points in 0.02 seconds - but also shows at a glance (at least, to a mathematician) how it works, without the need for any comments:

Code: [Select]
:
      sum_x = SUM(x())
      x2()  = x() * x()   : sum_x2  = SUM(x2())
      x3()  = x() * x2()  : sum_x3  = SUM(x3())
      x4()  = x2() * x2() : sum_x4  = SUM(x4())
      x5()  = x2() * x3() : sum_x5  = SUM(x5())
      x6()  = x3() * x3() : sum_x6  = SUM(x6())
      x7()  = x3() * x4() : sum_x7  = SUM(x7())
      x8()  = x4() * x4() : sum_x8  = SUM(x8())
      x9()  = x4() * x5() : sum_x9  = SUM(x9())
      x10() = x5() * x5() : sum_x10 = SUM(x10())

      sum_y = SUM(y())
      xy()  = x() * y()   : sum_xy  = SUM(xy())
      x2y() = x2() * y()  : sum_x2y = SUM(x2y())
      x3y() = x3() * y()  : sum_x3y = SUM(x3y())
      x4y() = x4() * y()  : sum_x4y = SUM(x4y())
      x5y() = x5() * y()  : sum_x5y = SUM(x5y())

      matrix() = \
      \ npts%,  sum_x,   sum_x2,  sum_x3,  sum_x4,  sum_x5, \
      \ sum_x,  sum_x2,  sum_x3,  sum_x4,  sum_x5,  sum_x6, \
      \ sum_x2, sum_x3,  sum_x4,  sum_x5,  sum_x6,  sum_x7, \
      \ sum_x3, sum_x4,  sum_x5,  sum_x6,  sum_x7,  sum_x8, \
      \ sum_x4, sum_x5,  sum_x6,  sum_x7,  sum_x8,  sum_x9, \
      \ sum_x5, sum_x6,  sum_x7,  sum_x8,  sum_x9,  sum_x10

      vector() = \
      \ sum_y,  sum_xy,  sum_x2y, sum_x3y, sum_x4y, sum_x5y

      PROC_invert(matrix())
      vector() = matrix().vector()

This solver code is only an extract.  The entire program (and a runnable EXE) can be found here.

How would you write this in your preferred BASIC dialect, and would it be as pretty?

Richard.

Nice example Richard! Matrix math is one of the features I had hoped to release in Script BASIC 2.2 as an addition to the Tools extension module. Script BASIC makes this even easier as it doesn't require you to DIM anything and there no limit to indices's (indexed or associative or a combination of both) or the type of data the elements contain. (long, double, string, another array or a mix of these) Script BASIC arrays can be created/populated within a C extension module and passed back an forth as arguments in a function/sub.
Title: Re: BBC BASIC for Windows
Post by: John on March 22, 2014, 10:16:21 PM
Quote from: Richard Russell - BBC4W forum
This is the first in an occasional series of posts on features of BBC BASIC for Windows which distinguish it from other BASICs, but which are so obscure that nobody ever uses them, unless of course you know different!

1. Outputting bottom-to-top text

BB4W supports outputting right-to-left text (for languages like Hebrew and Arabic) and top-to-bottom text (for Chinese, Japanese and Korean, rarely) but it also supports bottom-to-top text - both when output to the 'mainwin' and to the printer:

Code: [Select]
      *font Lucida Console,24
      VDU 23,16,12;0;0;0;13 : REM Bottom-to-top text
      PRINT "Hello world!"

But there is no national language written this way, as far as I know, so apart from as a gimmick it's unlikely this facility has ever been used in a real program.

Richard.

I don't see that feature as unique to BBC4W. I haven't tried it yet with the Script BASIC BBC extension module library. It would be interesting to know how BBC BASIC compatible the Script BASIC BBC library is. I personally don't have the time to learn BBC BASIC graphic primitives.

(http://files.allbasic.info/ScriptBasic/gfx/sbgfx_b2t.png)

Code: [Select]
' ScriptBasic GFX

IMPORT gfx.inc

scrn = gfx::Window(200, 200, "ScriptBasic GFX")
gfx::FontRotation 3
gfx::stringColor scrn, 100, 150,"Bottom To Top" & CHR(0), 0xffffffff
gfx::Update
WHILE gfx::KeyName(1) <> "+escape"
WEND
gfx::Close

(http://files.allbasic.info/ScriptBasic/gfx/sbgfx_b2t_2.png)

Code: [Select]
' ScriptBasic GFX

IMPORT gfx.inc

scrn = gfx::Window(200, 200, "ScriptBasic GFX")
FOR x = 1 TO 13
  gfx::stringColor scrn, 100, 180-x*12, MID("Bottom To Top",x,1) & CHR(0), 0xffffffff
NEXT
gfx::Update
WHILE gfx::KeyName(1) <> "+escape"
WEND
gfx::Close

This seems more BASIC like to me rather than dealing with cryptic codes based on bit flags.

(http://files.allbasic.info/ScriptBasic/gfx/sbgfx_b2tr2l.png)

Code: [Select]
  gfx::stringColor scrn, 180-x*11, 180-x*11, MID("Bottom To Top",x,1) & CHR(0), 0xffffffff

@Richard - What would be the VDU code for this one?   :)