Raspberry BASIC

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - Richard Russell

Pages: 1 2 [3]
31
BBC BASIC / BBC BASIC for SDL 2.0 version 1.09a released
« on: January 17, 2020, 11:33:56 PM »
I've released version 1.09a of BBC BASIC for SDL 2.0 - the cross-platform programming language for Windows, MacOS, Linux, Raspbian, Android and iOS.  The changes in this version are as follows:

  •   BASIC Interpreter / Run Time Engine

    Worked around a regression in SDL 2.0.10, which caused the fern demo not to run on some platforms.

    Improved compatibility with GCC 4.9.

  •   IDEs and Utilities

    SDLIDE: Added the Memory Usage Monitor (similar to the BB4W equivalent) to the Utilities menu.  Now you can find out how close your program is to running out of memory (or whether you have allocated much more memory than you need!).  The BASIC program must be run in Debug mode for this to work.

  •   Libraries

    Modified dlglib.bbc to improve the responsiveness of the listbox to slow mouse button clicks.

  •   Example Programs

    Updated Ceefax.bbc (and capitalised its name!) to include Weather, Traffic and Local News pages, and to be navigable using an Amazon Fire TV remote.  With the demise of the BBC's digital ('red button') text service at the end of this month, this is my attempt to provide a substitute!  This program also runs in BBC BASIC for Windows if you copy 'Bedstead-ext.otf' into BB4W's LIB directory.

This new version may be downloaded, for all the supported platforms, from the usual location.  The GitHub repository has been updated (used to build the MacOS, Raspbian, iOS and 64-bit Linux editions, currently).

Please remember that if you use the Android Application Generator you should download a new APK template to ensure that any updates to the run-time engine are incorporated in your own apps.

32
BBC BASIC / BBC BASIC for SDL 2.0 version 1.06a released
« on: September 03, 2019, 03:51:26 PM »
I have released version 1.06a of BBC BASIC for SDL 2.0, the cross-platform programming language for Windows, MacOS, Linux, Raspbian, Android and iOS.  The changes in this version are as follows:
  • BASIC Interpreter / Run Time Engine

    Added support for antialiased 2D graphics (extending SDL2_gfx).

    Increased the maximum number of float parameters that can be passed by SYS from 6 to 8.

    Fixed a bug in the PRINT statement whereby a comma didn't unset 'hex' mode (64-bit and ARM editions).

    Modified the ARM and x86-64 assemblers so that the 'Jump out of range' error is not reported on the first pass if the destination label has been made LOCAL.

    Modified the ARM assembler so that numeric values may be used as aliases for register names (this improves compatibility with Acorn's assembler).

  • Libraries

    Added 'aagfxlib.bbc' to support antialiased 2D graphics.  This is functionally very similar to the GDIPLIB library supplied with BBC BASIC for Windows.

  • Example Programs

    Added 'aagfxdem.bbc' (in the examples/graphics folder) to demonstrate antialiased graphics.

    Added 'knots.bbc' (in the examples/graphics folder), a Celtic Knot program by David Marples which also makes good use of antialiased graphics.

    Added 'BBSterm.bbc' (in the examples/general folder; desktop editions only) which is a terminal program for Bulletin Board Services accessed by 'telnet'.
This new version may be downloaded, for all the supported platforms, from the usual location.  The GitHub repository has been updated (used to build the MacOS, Raspbian, iOS and 64-bit Linux editions, currently).

33
BBC BASIC / BBC BASIC for SDL 2.0 version 1.05a released
« on: July 25, 2019, 02:54:02 PM »
I have released version 1.05a of BBC BASIC for SDL 2.0, the cross-platform programming language for Windows, MacOS, Linux, Raspbian (Raspberry Pi), Android and iOS.  The changes in this version are as follows:

  • BASIC Interpreter / Run Time Engine

        Fixed a bug causing MOUSE and graphics coordinates to diverge if the window is resized without doing a VDU 26.

        Incorporated Jonathan Harston's modification to ignore SOUND statements specifying non-internal sound channels.

  • IDEs and Utilities

        The SDLIDE list of functions and procedures can now be scrolled using the PgUp and PgDn keys.

        SDLIDE will now load programs in plain text (.bas) format even if they contain TAB characters.

        Added a Go To Line menu selection to SDLIDE, similar to that in BBC BASIC for Windows v6.12a.

        Modified the search utility to fix a problem with it not having keyboard focus initially.

  • Libraries

        dlglib.bbc now supports comboboxes!

        Fixed a bug in datelib.bbc causing the FN_date$() function to misbehave with months starting with an M (March and May).  D'oh!

        The DejaVuSans font has been updated to a newer version with more Unicode symbols.

        Added the (incomplete) bigint.bbc library in case somebody fancies developing it further.

  • Example Programs

        Added a graphics demo fluid.bbc which uses GPU shader code to create a plasma-like effect.

        Modified dlgdemo.bbc to demonstrate the new combobox capability of the dialogue box library.

        Modified hangman.bbc to remove code which worked around the now fixed coordinate disparity.

        Added a 3D animation to accompany skaters.bbc.  This has a rather risqué Easter Egg, can you find it?!
This new version may be downloaded, for all the supported platforms, from the usual location.  The GitHub repository has been updated (used to build the MacOS, Raspbian, iOS and 64-bit Linux editions, currently).

34
BBC BASIC / BBC BASIC for SDL 2.0 version 1.04a released
« on: June 24, 2019, 04:19:25 PM »
I have released version 1.04a of BBC BASIC for SDL 2.0, the cross-platform programming language for Windows, MacOS, Linux, Raspbian, Android and iOS.  The changes in this version are as follows:
  • BASIC Interpreter / Run Time Engine

    The VDU 23,24,n| command updates the 'character spacing adjustment' when a proportional-spaced font is used (negative values cause the characters to close up, positive values cause them to spread apart).

    The @tmp$ system variable has been changed on Linux (including Raspbian) and MacOS so that it points to a user-specific directory.  Previously, problems could arise if BBC BASIC was run as 'root' (causing files with root ownership to be stored in @tmp$) and then subsequently as a user without privileges to delete them.  On other platforms @tmp$ has always been user-specific.
  • Example Programs

    hangman.bbc: David Williams' nice hangman program, ported to BBCSDL whilst preserving its original look-and-feel as closely as possible.

    figleaf.bbc: A rendition of Scott Joplin's 'Fig Leaf Rag' (transcribed by Ron Stickley for my Z80 Music program in 1984) accompanied by an animated 3D piano keyboard.
This new version may be downloaded, for all the supported platforms, from the usual location.  The GitHub repository has been updated (used to build the MacOS, Raspbian, iOS and 64-bit Linux editions, currently) although doubts have been expressed over whether GitHub is the right solution going forwards.

Please remember that if you use the Android Application Generator you should download a new APK template to ensure that any updates to the run-time engine are incorporated in your own apps.

35
BBC BASIC / Interfacing with a DHT11/12/22 sensor
« on: June 03, 2019, 04:21:14 PM »
The BBC BASIC program below interfaces with a DHT11/12 or DHT22 humidity and temperature sensor connected to a Raspberry Pi GPIO pin.  These sensors use a proprietary serial data format on a one-wire bidirectional bus, which has to be decoded in software.

Because of the variable latency associated with a user-mode program reading the GPIO, the data cannot always be decoded reliably.  The code uses a number of strategies to minimize this problem but mis-reads must be expected and dealt with (e.g. by means of retries) in any application using it.  Note that the DHT11/12 may be polled no faster than once per second and the DHT22 no faster than once every two seconds.

The code has been written to be functional rather than pretty!

Code: Text
  1.       REM DHT11/12/22 sensor interface for Raspberry Pi 3/3+ (Raspbian)
  2.       REM (c) Richard Russell, http://www.rtrussell.co.uk/, 03-Jun-2019
  3.  
  4.       INSTALL @lib$ + "gpiolib"
  5.       GPIO% = FN_gpio_setup
  6.       PIN% = 2 : REM BCM pin no.
  7.  
  8.       @% = &2010A
  9.       REPEAT
  10.         CASE FN_dht_read(GPIO%, PIN%, humidity, temperature) OF
  11.           WHEN 0: PRINT TIME$ "  Humidity = "; humidity "%, temperature = "; temperature "C"
  12.           WHEN 1: PRINT TIME$ "  DHT11/12/22 read failed: wrong number of transitions"
  13.           WHEN 2: PRINT TIME$ "  DHT11/12/22 read failed: checksum error"
  14.           WHEN 3: PRINT TIME$ "  DHT11/12/22 read failed: no response"
  15.         ENDCASE
  16.         WAIT 200
  17.       UNTIL FALSE
  18.       END
  19.  
  20.       REM Read from DHT11/12/22, G% is value returned from FN_gpio_setup, P% is BCM pin number:
  21.       DEF FN_dht_read(G%, P%, RETURN humidity, RETURN temperature)
  22.       LOCAL B%, C%, I%, J%, M%, N%, O%, T%, d&(), t%() : N% = 6000 : REM Adjust for CPU speed
  23.       DIM d&(4), t%(90), C% LOCAL N%*4 + 3
  24.       B% = G% + &34 : M% = 1 << P%
  25.  
  26.       REM Initialise the GPIO pin to be used, happens only on first call:
  27.       PRIVATE initialised
  28.       IF NOT initialised THEN
  29.         PROC_gpio_inp(G%, P%) : PROC_gpio_pull(G%, 2) : REM pull-up
  30.         PROC_gpio_pullclk0(G%, 1 << P%) : PROC_gpio_pullclk0(G%, 0)
  31.         initialised = TRUE
  32.         WAIT 10
  33.       ENDIF
  34.  
  35.       REM Send the start signal to the DHT11/12/22 and sample the data stream it responds with:
  36.       PROC_gpio_out(G%,P%) : G%!&28 = M% : REM Set data line to output and low
  37.       WAIT 2                             : REM Wait 20 ms
  38.       G%!&1C = M% : PROC_gpio_inp(G%,P%) : REM Set data line high and to input
  39.       FOR I% = C% TO C% + N%*4 STEP 4 !I%=!B% : NEXT : REM Sample at ~1 us intervals
  40.  
  41.       REM Scan the captured data for transitions and store their positions in an array:
  42.       FOR I% = C% + 32 TO C% + N%*4 STEP 4
  43.         IF !I% AND M% EOR O% t%(J%) = I% : O% EOR= M% : J% += 1 : IF J% > DIM(t%(),1) EXIT FOR
  44.       NEXT
  45.       IF J% < 5 THEN = 3 : REM If fewer than 5 transitions report no response
  46.       IF O% = 0 ERROR 100, "Sampling period not long enough to capture entire data stream"
  47.  
  48.       REM Measure the total 'low' time (except for the initial pulse) to establish timebase:
  49.       FOR I% = 1 TO J%-2 STEP 2 : T% += t%(I%+1) - t%(I%) : NEXT : T% DIV= 41
  50.  
  51.       REM If too few transitions attempt to infer where the missing pulse(s) was/were:
  52.       IF J% = 79 PROC_dht_fix(t%(), J%)
  53.       IF J% = 81 PROC_dht_fix(t%(), J%)
  54.       IF J% <> 83 THEN = 1 : REM Report uncorrectable wrong number of transitions
  55.  
  56.       REM Decode data using only the high-to-low transitions:
  57.       FOR I% = 0 TO 39 : d&(I% DIV 8) = d&(I% DIV 8) * 2 - ((t%(I%*2+3) - t%(I%*2+1) > 2 * T%)) : NEXT
  58.       IF d&(4) <> (SUM(d&()) - d&(4) AND &FF) THEN
  59.         REM If checksum error attempt to decode using only the low-to-high transitions:
  60.         FOR I% = 0 TO 39 : d&(I% DIV 8) = d&(I% DIV 8) * 2 - ((t%(I%*2+4) - t%(I%*2+2) > 2 * T%)) : NEXT
  61.       ELSE IF d&(4) <> (SUM(d&()) - d&(4) AND &FF) THEN ;
  62.         REM If still a checksum error attempt to decode using widths of high pulses:
  63.         FOR I% = 0 TO 39 : d&(I% DIV 8) = d&(I% DIV 8) * 2 - ((t%(I%*2+3) - t%(I%*2+2) > T%)) : NEXT
  64.       ENDIF
  65.       IF d&(4) <> (SUM(d&()) - d&(4) AND &FF) THEN = 2 : REM Report uncorrectable checksum error
  66.  
  67.       REM Get the humidity and temperature; REM or unREM as required for DHT11/12 or DHT22:
  68.       humidity = d&(0) + d&(1) / 10 : temperature = d&(2) + d&(3) / 10 : REM DHT11/12
  69.       REM humidity = (d&(0) * 256 + d&(1)) / 10 : REM DHT22
  70.       REM temperature = ((d&(2) AND &7F) * 256 + d&(3)) / 10 : IF d&(2) >= &80 temperature *= -1 : REM DHT22
  71.       = 0
  72.  
  73.       REM If the number of transitions was wrong attempt to insert the 'missing' pulse:
  74.       DEF PROC_dht_fix(t%(), RETURN J%)
  75.       LOCAL I%, M%, S%, T%
  76.       FOR I% = 1 TO J%-2 STEP 2
  77.         T% = t%(I%+1) - t%(I%)
  78.         IF T% > M% M% = T% : S% = I%
  79.       NEXT
  80.       FOR I% = J%+1 TO S%+3 STEP -1
  81.         t%(I%) = t%(I%-2)
  82.       NEXT
  83.       t%(S%+1) = t%(S%) + M% * 2 / 5 + 0.5 : REM new rising edge
  84.       t%(S%+2) = t%(S%) + M% * 3 / 5 + 0.5 : REM new falling edge
  85.       J% += 2
  86.       ENDPROC
  87.  

36
BBC BASIC / BBC BASIC for SDL 2.0 version 1.03a released
« on: May 13, 2019, 01:21:02 PM »
I have released version 1.03a of BBC BASIC for SDL 2.0, the cross-platform programming language for Windows, MacOS, Linux, Raspbian (Raspberry Pi), Android and iOS.  The changes in this version are as follows:

  • IDEs / Compiler

    BBCEdit: Andy Parkes' alternative IDE has been updated to fix a few bugs.

    SDLIDE: The Search BASIC Programs utility has been ported from BB4W and can be found in the Utilities menu.  It searches for a given string in both tokenised (.bbc) and plain-text (.bas) programs, recursively searching sub-directories.

  • BASIC Interpreter / Run Time Engine

    @dir$ and @lib$ now use backslash path delimiters consistently in Windows.  This is only a cosmetic change, since Windows will accept forward slashes at the API level, but eliminates an anomaly.

    Mouse wheel rotations are now ignored at the immediate-mode prompt and in the INPUT statement.

  • Libraries

    The dlglib.bbc library has been extended to support multi-column list boxes.

    The File Selector dialogue used in recorder.bbc and compiler.bbc has been hived-off into a separate library, filedlg.bbc, so that it is easier to use from other programs.

  • Example Programs

    mandel.bbc: This has been completely rewritten so that the calculations are performed on the GPU rather than the CPU, making it no longer x86-specific (and allowing it to run in iOS despite assembler code not being permitted).

This new version may be downloaded, for all the supported platforms, from the usual location.  The GitHub repository  has been updated (used to build the MacOS, Raspberry Pi, iOS and 64-bit Linux editions, currently).

37
BBC BASIC / Simple GPIO demo
« on: April 30, 2019, 05:00:57 PM »
This is a very simple demo of the Raspberry Pi's GPIO being controlled by BBC BASIC, using the supplied 'gpiolib' library.  It cycles through six of the outputs, setting each one high in sequence.  The code is listed below, and this is the result (with LEDs fitted to monitor the outputs):



Code: [Select]
      REM Initialise GPIO:
      INSTALL @lib$ + "gpiolib"
      GPIO% = FN_gpio_setup

      REM Pin numbers to activate, in sequence:
      DATA 17, 23, 25, 12, 16, 26

      REM Set to input first:
      RESTORE
      FOR I% = 1 TO 6
        READ pin%
        PROC_gpio_inp(GPIO%, pin%)
      NEXT

      REM Set pins to output:
      RESTORE
      FOR I% = 1 TO 6
        READ pin%
        PROC_gpio_out(GPIO%, pin%)
      NEXT

      REM Cycle LEDs in sequence:
      REPEAT
        RESTORE
        FOR I% = 1 TO 6
          READ pin%
          PROC_gpio_set(GPIO%, 2^pin%)
          WAIT 20
          PROC_gpio_clr(GPIO%, 2^pin%)
        NEXT
      UNTIL FALSE
      END

38
BBC BASIC / Introduction to BBC BASIC
« on: April 14, 2019, 09:58:19 AM »
BBC BASIC is the programming language originally specified and adopted by the British Broadcasting Corporation for its groundbreaking Computer Literacy Project of the early 1980s. It has since been extended and ported onto at least seven CPUs and more than thirty different platforms.  Today BBC BASIC is a modern, structured, language capable of most programming tasks.

The Raspbian edition of BBC BASIC is free and open-source.  It is highly compatible with the Windows, MacOS, Linux, Android and iOS editions, and generally BASIC programs will run on all these platforms with no modification, even if they use 2D or 3D graphics, sound, joystick input, file or network access etc. More than 100 example programs are supplied with BBC BASIC to demonstrate its capabilities.

Raspbian BBC BASIC needs at least an RPi 2; an RPi 3 or later is recommended for best performance.  It may be downloaded as a precompiled binary in the form of a Zip file or the source code, libraries and examples may be obtained from GitHub.  There is a makefile in the bin/raspi directory (the SDL2 development libraries must first be installed from the Raspbian repository).

Here are some YouTube videos which illustrate things that BBC BASIC can achieve on the Raspberry Pi:

Video games
2D graphics
3D graphics
Ceefax simulator
Sprites
Music and 3D animation
Shader programming

39
Interpreters / BBC BASIC
« on: April 13, 2019, 03:57:06 PM »
Will there be a child board for BBC BASIC?

Pages: 1 2 [3]