Page 1 of 1

BBC BASIC for SDL 2.0 v0.26a released

Posted: Sat 03 Nov 2018, 22:49
by guest
I have today released version 0.26a of BBC BASIC for SDL 2.0, the cross-platform programming language for Windows, Linux, MacOS, Raspberry Pi, Android and iOS. The changes in this version are as follows:
  • IDEs / Compiler

    The SDLIDE file selector no longer lists sub-directories starting with a 'dot' unless 'All files' is selected.

    The 'Create application' facility now recognises the REM!Icon compiler directive.

    The 'touch IDE' (primarily for Android and iOS) has been extended so that the Delete command will delete entire directories (folders) as well as files - use with care!
  • BASIC Interpreter

    The 'command line tail' is now returned in the @cmd$ variable. Note however that when using this facility with a 'compiled' (standalone) application, command line parameters must have the form of a 'switch', i.e. start with a hyphen.

    Fixed a bug in the ARM assembler causing the STR instruction to encode incorrectly in one addressing mode.
  • Libraries

    The '' library now reports a more sensible error if a function taking a socket as a parameter is passed a non-opened socket. This should not normally happen.
  • Example Programs

    A new graphics example '' acts as a stress test of multiple sprite plotting.

    A new game '' is an almost exact clone of the Liberty BASIC program of the same name. It has been adapted from the LB program by permission of its author Rod Bird.
This new version may be downloaded, for all the supported platforms, from the usual place. The released source code (used to build the Raspberry Pi, iOS and 64-bit Linux editions currently) has been updated to this latest version, and can be found at the link previously announced.

Re: BBC BASIC for SDL 2.0 v0.26a released

Posted: Fri 09 Nov 2018, 17:37
by guest
guest wrote:
Sat 03 Nov 2018, 22:49
A new graphics example '' acts as a stress test of multiple sprite plotting.
A new game '' is an almost exact clone of the Liberty BASIC program of the same name.
I try to ensure that new example programs illustrate one or more language features, or programming techniques, that have not previously been highlighted. Here are some from these two programs:
  • 1. In animated games programs it is commonly convenient to use structure arrays to represent the state of sprites and other dynamic objects, for example their positions, velocities, bitmap pointers etc. Structure arrays are particularly suitable because of their ability to contain members of different types (for example a texture pointer might need to be a 64-bit integer, dimensions might need to be integer numbers of pixels, positions and velocities might need to be floats etc.). However a significant disadvantage of a structure array is the overhead of having to specify (and evaluate) the array index when referencing every member; one might end up with code such as:

    Code: Select all

          dst.w% = aliens{(index%)}.w%
          dst.h% = aliens{(index%)}.h%
          Dst.x% = aliens{(index%)}.x - Dst.w% / 2
          Dst.y% = aliens{(index%)}.y - Dst.h% / 2
          angle# = aliens{(index%)}.a
          texture%% = aliens{(indexI%)}.t%%
    The repeated evaluation of the {(index%)} term is very wasteful, especially in the case of an interpreted language like BBC BASIC, and may significantly impact on overall speed. We can eliminate it by moving the code into a procedure and passing the array element as a parameter:

    Code: Select all

          DEF PROCalien(a{})
          dst.w% = a.w%
          dst.h% = a.h%
          Dst.x% = a.x - Dst.w% / 2
          Dst.y% = a.y - Dst.h% / 2
          angle# = a.a
          texture%% = .t%%
    Now the index is evaluated only once. Of course there is an overhead of a procedure call but if several structure members are being accessed there is likely to be a net improvement.
  • 2. Plotting sprites with shadows can often increase the realism and impact of the graphics, even if the shadow isn't technically accurate. This is particularly easy to achieve with the API functions provided by SDL 2.0. Here is the relevant code from which creates two textures, one for the object itself and the other for its shadow:

    Code: Select all

          Alien%% = FNloadsprite(@dir$ + "alien.png")
          Shadow%% = FNloadsprite(@dir$ + "alien.png")
          SYS "SDL_SetTextureColorMod", Shadow%%, 0, 0, 0
          SYS "SDL_SetTextureAlphaMod", Shadow%%, &80
    To create the shadow texture we firstly modify the RGB values of the object so that they are all zero, then we halve its alpha (opacity) value. Now when we plot the shadow sprite it simply has the effect of attenuating the background in regions where the object is opaque but not where it is transparent. If the degree of opacity varies (such as would be the case for an anti-aliased sprite) then the degree of attenuation does too, which is exactly what we want. Now all we have to do it plot the shadow first and then plot the object displaced by an appropriate amount.
  • 3. Games programs are often accompanied by both background music and sound effects. Previous BBCSDL implementations, for example of David Williams' prizewinning 'Forces of Darkness' game, have not supported background music and have also had the limitation that only one sound effect can be playing at a time. These limitations are highly undesirable but were thought to be unavoidable without BBCSDL being linked to the SDL_mixer library, which would be a big overhead and introduce dependencies difficult to meet in a cross-platform context.

    However I recently realised that it is, after all, possible to overcome these limitations using only basic SDL 2.0 API functions. This is demonstrated in '' which plays background music as well as sound effects that can 'overlap'; I have encapsulated the code in PROCmixsound(). The only significant limitation is that all the different WAV files must use the same encoding format (sampling rate, number of channels etc.), so that they can easily be mixed together, but this usually isn't a major issue because format conversion is readily available, for example online or even using SDL itself. It would even be possible to carry out the necessary conversion during program initialisation.

    If you want the program to provide the option to disable the background music, you must instead stream 'silence' so that there is something for the sounds effects to be mixed 'with'.

Re: BBC BASIC for SDL 2.0 v0.26a released

Posted: Sun 11 Nov 2018, 21:13
by guest
guest wrote:
Fri 09 Nov 2018, 17:37
I try to ensure that new example programs illustrate one or more language features
Another feature demonstrated by '' is the use of the @zoom%, @panx% and @pany% system variables to automatically scale and centre the program's output if the window is resized or maximised. In BB4W it's actually quite difficult to write a program (e.g. a game) that can run either in a window or full-screen, but in BBCSDL it's much more straightforward.

The ON MOVE handler looks like this:

Code: Select all

      DEF PROCresize(M%, L%) IF M% <> 5 ENDPROC
      LOCAL W%, H%
      W% = L% AND &FFFF
      H% = L% >>> 16
      IF W%/H% > 800/500 THEN
        @zoom% = &8000 * H% / 500
        @zoom% = &8000 * W% / 800
      IF @zoom% < &8000 @zoom% = &8000
      @panx% = (800 * @zoom% / &8000 - W%) / 2
      @pany% = (500 * @zoom% / &8000 - H%) / 2