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.

Messages - Richard Russell

Pages: [1]
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).

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.

BBC BASIC / Re: Interfacing with a DHT11/12/22 sensor
« on: June 04, 2019, 08:18:41 AM »
It seems when you use the custom syntax highlighting option, Select All is no longer available. You can still select the text but you have to do it manually.

That's a pity.  I find manual selection difficult (on this laptop PC, at least), particularly if it needs to scroll; maybe if I had a proper mouse with a scrollwheel it would be easier.  It seems odd that one useful feature would be removed at the same time as adding another.  [I'd add a frown but emoticons are seemingly broken on this forum!]

BBC BASIC / Re: Interfacing with a DHT11/12/22 sensor
« on: June 03, 2019, 08:16:33 PM »
The syntax highlighting is great, thank you, but the 'Select All' option seems to have gone! It was there before, wasn't it, or did I imagine it?

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!

  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
  4.       INSTALL @lib$ + "gpiolib"
  5.       GPIO% = FN_gpio_setup
  6.       PIN% = 2 : REM BCM pin no.
  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
  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%
  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
  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
  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"
  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
  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
  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
  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
  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

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).

BBC BASIC / Re: Simple GPIO demo
« on: April 30, 2019, 10:19:02 PM »
Have you had any luck with the RPi Sense HAT board? Will your GPIO library allow use of the Sense HAT emulator that comes with Raspbian?

I don't have a Sense HAT here.  My understanding is that it's an I2C device and therefore not really accessible via the GPIO (I know that the I2C clock and data lines appear on GPIO pins, but it would be a bit daft to try to interface with I2C devices that way!).   So to that extent my GPIO library isn't really relevant to the Sense HAT, but BBC BASIC could no doubt access it via the virtual I2C device at /dev/i2c-*.

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:
      FOR I% = 1 TO 6
        READ pin%
        PROC_gpio_inp(GPIO%, pin%)

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

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

« on: April 19, 2019, 04:37:25 PM »
On Windows, Charles Pegge (OxygenBasic author) wrote an extension module that provides a dynamic FFI definition and full use of the O2.JIT compiler to create virtual DLLs and code in ASM.
It's a shame it's Windows only.  I want to discourage platform-specific extensions to BBC BASIC for SDL 2.0, especially as one of its great strengths is the cross-platform compatibility.  So although the assembler is invaluable for debugging (notably the profiler, list variables and trace features rely on it) I generally don't use it in application programs.

I've recently been experimenting with shader programming in BBC BASIC, and that opens up the possibility of using the GPU to provide acceleration.  Of course it isn't ideally suited to 'general purpose' programming, but increasingly GPUs are used in applications other than graphics.  It potentially has the advantage of being fully cross-platform because all GPUs will run the same source code (it even gets around Apple's prohibition on running arbitrary code in iOS!).

« on: April 17, 2019, 05:54:18 PM »
This was the reason I thought BBC BASIC was a BASIC to ASM compiler.

An assembler and a compiler are very different things!

Traditionally BBC BASIC has incorporated an assembler as part of its run-time engine, making it easy to include assembly language subroutines in what is otherwise a BASIC program, typically when interpreted BASIC isn't fast enough or to do things that BBC BASIC doesn't support (such as callbacks).

So the original BBC Micro had an integral 6502 assembler, ARM BBC BASIC had an ARM assembler, BBC BASIC for Windows has a 32-bit x86 assembler etc.  The various editions of BBC BASIC for SDL 2.0 have an assembler appropriate to the platform (32-bit x86, 64-bit 86 or 32-bit ARM).

The exception to this rule is Brandy (and its offspring Napoleon Brandy and Matrix Brandy).  Although 'BBC BASIC' they don't include an assembler, and indeed they are generally less extensible and adaptable than most versions of BBC BASIC are.

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
Music and 3D animation
Shader programming

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

Pages: [1]