guymark
Posts: 15
Joined: Fri Sep 14, 2018 2:56 am

A compilable basic that uses line numbers for Pi?

Tue Sep 18, 2018 3:26 am

Hi.

First of all, I did TRY and search the forums to see if anyone had requested info on BASIC before but the keyword is to common so it didn't work!

Many years ago (about 35, I used to program in good old fashioned GWBASIC (for Pegasus software). Since then I have done VERY little coding, but what little I have done has been either with GW or Qbasic.

I mention the following purely to explain why I am not embracing new programming languages - after a small stroke around 10 years ago, I now find it almost impossible to learn new tasks of any real complexity. I can function absolutely fine - but I can sit down and spend 5 hours learning a new skill and tomorrow I will only retain the vaguest of details. It's a bit of a nuisance. Daft example, just before the brain hiccuped, I was learning PHP and although not a good coder, I was making modest progress. Since then, nothing "newly learned" with PHP seems to stick at all. Meh.

Anyway, enough of the background.

So, although I realise I might need to use a dosbox or other emulator AND I also accept that speed may welll be grim - what I am trying to find is the following.

Basic where I can use line numbers - GW,BASIC, QBASIC would be awesome but other similar ones are fine too.
Can be compiled (long story short it is not for serious security but it is to stop folks easily cheating on a small game)
Will allow me (even if needs much faffing about) to access at least TWO GPIO pins - one input and one output.

I have found several versions of basic which will do TWO of the above list, but not yet found one which can do all three. I know that DOSBOX will run old dos games (so should run compiled qbasic ok) - I just don't know how to go about accessing the IO ports.

Any help would be awesome - as otherwise my options are a little bit limited.

Many Thanks

User avatar
topguy
Posts: 5018
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: A compilable basic that uses line numbers for Pi?

Tue Sep 18, 2018 8:49 am

Maybe search the forum for "freebasic" or "fuze basic" will get you better results.

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 20944
Joined: Sat Jul 30, 2011 7:41 pm

Re: A compilable basic that uses line numbers for Pi?

Tue Sep 18, 2018 9:01 am

guymark wrote:
Tue Sep 18, 2018 3:26 am
It's a bit of a nuisance.
Perhaps the most understated and British comment I have ever seen on the forums here!

Sorry to hear about your health issue, but thank you for the comment!
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Please direct all questions to the forum, I do not do support via PM.

User avatar
rpiMike
Posts: 544
Joined: Fri Aug 10, 2012 12:38 pm
Location: Cumbria, UK

Re: A compilable basic that uses line numbers for Pi?

Tue Sep 18, 2018 9:25 am

You could try Richard Russell's Basic:

http://www.bbcbasic.co.uk/bbcsdl/index.html

Line numbers appear to be optional !

User avatar
scruss
Posts: 1874
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: A compilable basic that uses line numbers for Pi?

Tue Sep 18, 2018 11:40 am

Richard's BBC BASIC for SDL (and Matrix Brandy BASIC - another BBC BASIC implementation) isn't compiled. It's pretty neat, though.

Couple of compilers:
  • FreeBASIC — similar to MS QuickBASIC. You can use line numbers (I think) but most examples don't. This is probably the one you want.
  • X11-Basicmay accept line numbers. Also based on GFA BASIC, which only allows one command per line. Quirky but fast, just like GFA BASIC
If you really want the old-school experience, there's PC-BASIC, which almost perfectly mimics GW-BASIC's shell, and cbmbasic, which is the BASIC ROM from a C64 converted to C++ instructions. Both are interpreters and text-only, but they have the authentic look and feel.

Let me know if you need installation help. It's been a while since I ran FreeBASIC on a Raspberry Pi.
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

guymark
Posts: 15
Joined: Fri Sep 14, 2018 2:56 am

Re: A compilable basic that uses line numbers for Pi?

Tue Sep 18, 2018 5:14 pm

Thank you all very much for your help and suggestions. I will go through all the links offered and see what I can find.

I will do a separate search for accessing the GPIO from Basic too - as I am guessing there must be some way to either "Print# or Poke the right memory area to send an output or (get# / peek) read one.

Thank you all again, much appreciated :)

User avatar
bensimmo
Posts: 3501
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: A compilable basic that uses line numbers for Pi?

Tue Sep 18, 2018 5:31 pm

https://www.raspberrypi.org/forums/view ... p?t=175703
The SDL one should have it built in now.

User avatar
rpdom
Posts: 12960
Joined: Sun May 06, 2012 5:17 am
Location: Ankh-Morpork

Re: A compilable basic that uses line numbers for Pi?

Tue Sep 18, 2018 6:06 pm

Simple ways of accessing the gpios that should work from almost any language:

a) If the BASIC has a way of running system commands, you could use WiringPi's gpio command.

b) Pretty much any BASIC should be able to read and write files, so use the sysfs gpio interface for straightforward gpio functions.

c) For low level access, read and write the /dev/gpiomem 'file'. This is the hardest way, but will give you a greater level of control.

User avatar
scruss
Posts: 1874
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: A compilable basic that uses line numbers for Pi?

Tue Sep 18, 2018 9:18 pm

FreeBASIC also has GPIO support through WiringPi
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

guymark
Posts: 15
Joined: Fri Sep 14, 2018 2:56 am

Re: A compilable basic that uses line numbers for Pi?

Wed Sep 19, 2018 9:43 pm

Again, thank you all for a wealth of constructive comments and really information, I'm still going through the links and making notes on what I find!

It will be good fun to get back into coding again - even if a quaint combination of hardware and OS.

All the very best!

RichardRussell
Posts: 187
Joined: Thu Jun 21, 2012 10:48 am

Re: A compilable basic that uses line numbers for Pi?

Thu Sep 20, 2018 12:46 pm

guymark wrote:
Tue Sep 18, 2018 3:26 am
Any help would be awesome - as otherwise my options are a little bit limited
As others have noted, 'BBC BASIC for SDL 2.0' (BBCSDL) meets your requirements except for not being 'compiled'. I appreciate your desire for a prorgram that cannot easily be 'reverse engineered', although it's fair to say that any language is vulnerable to this if enough effort is put into it.

Indeed it's rare these days for a language to be compiled in the traditional sense, i.e. all the way to 'machine code'. Far more commonly it will be translated to a relatively high level 'byte code' which then gets interpreted by a run-time engine: Java, Python and those languages using the Common Language Runtime (CLR). e.g. the .NET suite, all work that way.

If you were to choose BBC BASIC it is possible to obfuscate a program in such way as to reduce its 'visibility' to an end user. You can leverage the 'REM!Fast' functionality, in which references to variables, arrays, functions, procedures etc. are replaced by short inline binary codes. A program processed in that way will make little sense if viewed; I can provide an example of what such a program looks like if you are interested.

guymark
Posts: 15
Joined: Fri Sep 14, 2018 2:56 am

Re: A compilable basic that uses line numbers for Pi?

Mon Sep 24, 2018 5:11 am

Hi Richard.

At the moment I am having some joy with QBasic 4.5 and the BC compiler with linked. A very quick program thrown together ran fine on the interpreter and (after a little glitch where I forgot to put the brun45.lib in the same directory), managed to compile it too.

I realise that anyone with some time to kill can reverse engineer it - I don't mind that at all - I just didn't want people to be able to "easily cheat" - PLUS I wanted a simple program.exe that would run without needing to have them install and interpreter. It also helps to keep the speed up a smidge.

So thank you for your kind offer though I think I am doing ok so far with Qbasic, now just to see if I can get the hang of /dev/gpiomem for the input output pins.

At a push I can use the keyboard for the input button - and just need a single output which I can toggle quickly. It's good to be playing with software again even if it is a rather antiquated language.

Curiously, now I am starting to play around with the Pi, more ideas are coming to mind for simple but useful little systems where a conventional PC would be overkill - but an Pi would be ideal.

RichardRussell
Posts: 187
Joined: Thu Jun 21, 2012 10:48 am

Re: A compilable basic that uses line numbers for Pi?

Mon Sep 24, 2018 8:53 am

guymark wrote:
Mon Sep 24, 2018 5:11 am
At the moment I am having some joy with QBasic 4.5
I must admit I didn't know it was possible to run QBasic on a Raspberry Pi, what graphics capabilities does it provide?
just to see if I can get the hang of /dev/gpiomem for the input output pins.
The way BBC BASIC does it is to map /dev/gpiomem to memory using mmap, then it can simply treat the GPIO as memory locations. Here's the code in 'gpiolib.bbc':

Code: Select all

      BCM2835_PERI_BASE = &3F000000 : REM RPi 2 & 3
      GPIO_BASE = BCM2835_PERI_BASE + &200000 : REM GPIO controller
      SIZE_BLOCK = &1000
      PROT_READ = 1
      PROT_WRITE = 2
      MAP_SHARED = 1
      O_RDWR = 2
      O_SYNC = &101000
      SYS "open", "/dev/gpiomem", O_RDWR OR O_SYNC TO F%
      IF F% < 0 ERROR 100, "Cannot open /dev/gpiomem"
      SYS "mmap", 0, SIZE_BLOCK, PROT_READ OR PROT_WRITE, MAP_SHARED, \
      \           F%, GPIO_BASE TO G%
      IF G% = TRUE ERROR 100, "Cannot map /dev/gpiomem"
      SYS "close", F%

User avatar
scruss
Posts: 1874
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: A compilable basic that uses line numbers for Pi?

Mon Sep 24, 2018 1:59 pm

guymark wrote:
Mon Sep 24, 2018 5:11 am
So thank you for your kind offer though I think I am doing ok so far with Qbasic, now just to see if I can get the hang of /dev/gpiomem for the input output pins.
If you're running QBasic / QuickBASIC under DosBox, I'd be amazed if you can access /dev/gpiomem. DosBox pretends everything is a PC, and doesn't (in any version I've seen, at any rate) expose anything of Linux beyond bits of the local filesystem.

I like DosBox, but I don't like the forum. It's got a heavy gatekeeper mentality that DosBox is only for running vintage games. Any questions about running other software are snuffed out quickly.
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

guymark
Posts: 15
Joined: Fri Sep 14, 2018 2:56 am

Re: A compilable basic that uses line numbers for Pi?

Mon Sep 24, 2018 8:39 pm

Hi Scrus & Richard

Scrus, you are absolutely right. I was struggling to make it handle the GPIO and the only way I could see of doing it was VERY ugly indeed - mounting the "C: drive" in /sys and dumping in all the other stuff there too. Really grim. Sadly you are right about the DOSBOX forum - the level of hostility to people simply asking questions about anything other than games surprised and disappointment me a little. Some fellow was using DOSBOX to lay around with a database at home and was told that "Nobody cares an iota about your database, DOSBOX is for gamers only" - or words very much to that effect.

It was still an interesting and educational experience though and I have made a lot of notes about some of the quirks I have found. Freebasic is the experiment for tonight as that seems to tick all my little boxes (line numbers, compilable and access to IO)



Richard, my logic was that if DOSBOX would let old DOS games run (many of which were just compiled QB), there was a sporting chance it would run - and it do so very happily. The graphics are 640 * 480 by default and when I downloaded an abandonware game to try it, it did indeed look EXACTLY like it used to - but it only used a small part of the screen. You CAN force it to scale to the screens real resolution but once I realised that access to the GPIO was going to be rather difficult, I didn't spend much more time with it. Frustrating but interesting and partly educational too.

Certainly though, there ARE ways you could have some IO with QB45 - just a real PITA. You could toggle the three lights on a keyboard (3 digital IO ports) in QB45 and if it is faithfully emulated, this might work still - and of course the keyboard provides inputs providing your requirements are very modest (low speed and not multi key presses) and DOSBOX / QB also allows mapping of other controllers though only via USB I think.

It also supports sound - and as I only need a single output channel, the thought did occur that I could simply have silence for 0 and a tone for 1 - then run the audio via a capacitor (ac only) and then a diode and another cap (weak DC signal in the presence of sound) and I could use sound and a tiny VOX switch circuit. Crude, but it would almost certainly work quite well. In fact the more I think about it, the more it might be my "if all else fails position!".



Anyway I am going to have a serious look at FreeBasic now - and see what I can find. It is so good to find such a friendly and constructive forum, really appreciate the help I have been given in here.

All the best.

The code was interesting, thank you and provided food for thought.

User avatar
scruss
Posts: 1874
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: A compilable basic that uses line numbers for Pi?

Mon Sep 24, 2018 10:41 pm

guymark wrote:
Mon Sep 24, 2018 8:39 pm
Scruss, you are absolutely right. I was struggling to make it handle the GPIO and the only way I could see of doing it was VERY ugly indeed - mounting the "C: drive" in /sys and dumping in all the other stuff there too. Really grim.
I'm genuinely, positively in awe of what you tried to do there, though. From a user point of view, there's no reason that it shouldn't work, and that's why computer systems can seem so illogical at times. I'm tempted to add

Code: Select all

mount P /proc
in my DosBox config and see what mayhem I can cause.
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

guymark
Posts: 15
Joined: Fri Sep 14, 2018 2:56 am

Re: A compilable basic that uses line numbers for Pi?

Tue Sep 25, 2018 1:28 am

Hi Scruss, thank you for your kind comments. Desperation with a computer can sometimes yield results! lol

There SEEMS to be a way around things (permissions notwithstanding and I am hoping that CHMOD / CHOWN might help there).

As well as mounting c to the qbasic directory, also:-
mount d /sys (gets around not being allowed to mount in root and not having to dump all the other files in the /sys directory)

Now, I can enter:

Open "O", #1, "d:/class/gpio/export",2 (not sure why this has a "2" at the end, I just copied this piece of code to set the pin)
print #1, "OUT": close #1

etc and it doesn't fall over. At this stage it doesn't do anything useful as I am not printing anything to the pin itself, just setting direction - but at least there is no "file not found" or other error and I am guessing it probably HAS set the pin for output.

I was just being dense at the time, mount C where the qbasic / programs etc and mount D so there is access to the GPIO area.

I am a *little* thwarted at the moment as depending on which examples I see elsewhere, I do not yet know the files I need to read and write to, some seem to suggest sys/device/virtual/gpio/gpio<n> where n is a number - others seem to be looking more at sys/class/gpio/export.

Alas in the first case, my file system is slightly different as there is no gpio director there - but I think still potentially on the right track.

If nothing else though, mounting another drive to allow you to access the /sys area certainly works

I will probably still end up experimenting with freebasic tomorrow when hopefully some spare SD cards arrive - but as you seemed interested in this, I thought I would share with you some modest progress of making qbasic talk to the GPIO.

It's fun trying to make square pegs fit in round holes :)

User avatar
rpdom
Posts: 12960
Joined: Sun May 06, 2012 5:17 am
Location: Ankh-Morpork

Re: A compilable basic that uses line numbers for Pi?

Tue Sep 25, 2018 5:13 am

guymark wrote:
Tue Sep 25, 2018 1:28 am
Now, I can enter:

Open "O", #1, "d:/class/gpio/export",2 (not sure why this has a "2" at the end, I just copied this piece of code to set the pin)
print #1, "OUT": close #1

etc and it doesn't fall over. At this stage it doesn't do anything useful as I am not printing anything to the pin itself, just setting direction - but at least there is no "file not found" or other error and I am guessing it probably HAS set the pin for output.
I don't know about the BASIC language here, but writing to /sys/class/gpio/export doesn't set the direction of a GPIO. It just enables access to a GPIO via the /sys interface.

For example, to have access to GPIO 27 (pin 13), you would write "27" to /sys/class/gpio/export.
Now you will have a bunch of files under /sys/class/gpio/gpio27.
To set the GPIO to output mode, you would write "out" (lower case, but I'm not sure that is essential) to /sys/class/gpio/gpio27/direction.

To set the output state of the GPIO to low or high, you would write "0" or "1" to /sys/class/gpio/gpio27/value.

Finally, to clean up when finished, you would write "27" to /sys/class/gpio/unexport and the /sys/class/gpio/gpio27 and all files under it will vanish.

guymark
Posts: 15
Joined: Fri Sep 14, 2018 2:56 am

Re: A compilable basic that uses line numbers for Pi?

Tue Sep 25, 2018 6:32 am

Thanks for that Rpdom. I will have another little play later on.

I am making plenty of mistakes but it wouldn't be so much fun if it worked right each time straight away. I am fairly sure I am going to go down the Freebasic route as it has GPIO facilities built in AND doesn't need to run in an emulator - but part of me just wants to see if making Qbasic write to the GPIO can be done anyway.

Now you have clarified a few things for me, I will tinker about a little more later on - in the meantime I have lost track of time a bit and at 07:25 starting to get a little dozy :)

Thanks again, I will post back to the thread if I can make it work with the code used just in case anyone else has a hankering to play around with QB45 and the Pi

RichardRussell
Posts: 187
Joined: Thu Jun 21, 2012 10:48 am

Re: A compilable basic that uses line numbers for Pi?

Tue Sep 25, 2018 8:25 am

guymark wrote:
Mon Sep 24, 2018 8:39 pm
Richard, my logic was that if DOSBOX would let old DOS games run (many of which were just compiled QB), there was a sporting chance it would run - and it do so very happily.
All understood, and good luck! My interests in BASIC are very different from yours: what I want to be able to do is to leverage all the capabilities of a modern computer: accelerated 3D graphics, stereo sound, network access etc., but from BASIC rather than (say) Python. Obviously a BASIC running under DOSBOX is not going to able to do all these things, however cunning you might be, which is where a 'modern' BASIC like BBC BASIC for SDL 2.0 comes in (not that the BBC BASIC language itself is modern of course, it's actually about a decade older than QBasic!).

User avatar
scruss
Posts: 1874
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: A compilable basic that uses line numbers for Pi?

Wed Sep 26, 2018 2:17 am

guymark, I got basic GPIO working with FreeBASIC. I've saved a copy here: scruss/FreeBASIC_Blink: GPIO LED Blink using FreeBASIC and WiringPi
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

guymark
Posts: 15
Joined: Fri Sep 14, 2018 2:56 am

Re: A compilable basic that uses line numbers for Pi?

Wed Sep 26, 2018 5:52 pm

Hi Scruss

Well the new SD card arrived today (plus a couple of spares for backups) so I am going to do a fresh install from Noobs today and then install Freebasic and see how it goes.

If it goes well, I might even see if I can make an image file available for folks as I have gathered that installing Freebasic on a Pi is an "interesting experience" depending on which set of instructions you follow!

Thanks for the link, I will install from the "Nightly build" of Freebasic and then see if I can make an LED blink. Will be very happy to see that happen as once I can get the basics going (no pun intended), I can happily fiddle about for ages :)

All the best

Mark

User avatar
scruss
Posts: 1874
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: A compilable basic that uses line numbers for Pi?

Wed Sep 26, 2018 6:45 pm

If you're following my ancient Running FreeBASIC on Raspberry Pi guide, it's best ignored. Like any advice about Raspberry Pi that's over a year old, it's likely wrong. Just download and install the most recent nightly binary from http://users.freebasic-portal.de/stw/bu ... armv6-rpi/ - and you're done! No need to make a distro, as this takes all of a couple of minutes.
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

guymark
Posts: 15
Joined: Fri Sep 14, 2018 2:56 am

Re: A compilable basic that uses line numbers for Pi?

Wed Sep 26, 2018 9:03 pm

Please excuse the noob question, but I have started again with a clean install of Raspberian and having issues trying to install FreeBasic. Can you see if I have done something obviously wrong please with the following:-

Put Noobs on a new SD card (16GB), installed it into Pi and powered up
Allowed all updates & reboots etc
Created FreeBasic directory in the default "pi" directory (where documents, downloads etc live)
Copied over unzipped files into the FreeBasic directory
Read the instructions for Linux (which I am GUESSING) is the one for Raspberian (as opposed to Windows and Dos)
Opened Terminal
Changed into the FreeBasic directory
Copied and pasted the command line from the README.TXT file
sudo ./install.sh -i
...and then pressed ENTER of course :)
sudo ./install.sh -i : Command not found.

I know I am going to be doing something silly - but I cannot fathom it. I did look at your original installation instructions - which listed lots of additional things to install first but as you suggested I should just stick to what the instruction said in the nightly build file, that's what I did.

I did make sure I downloaded the one for the Pi - the name being fbc_linux_armv6_rpi_0294_2018-09-26.zip

If you can see where I have goofed, please enlighten me. I know the file (install.sh) is in the right directory as it shows up when I DIR it.

Loathed to keep asking for help, but Google and the README.txt file are not giving me enough clues to sort it yet!

User avatar
rpiMike
Posts: 544
Joined: Fri Aug 10, 2012 12:38 pm
Location: Cumbria, UK

Re: A compilable basic that uses line numbers for Pi?

Wed Sep 26, 2018 9:59 pm

Looks like you just need to make the install.sh script executable:

Code: Select all

sudo chmod +x install.sh
For completeness I used:

Code: Select all

cd ~
wget http://users.freebasic-portal.de/stw/builds/linux-armv6-rpi/fbc_linux_armv6_rpi_0004_2015-02-24.zip
unzip fbc_linux_armv6_rpi_0004_2015-02-24.zip
cd fbc_linux_armv6_rpi/
sudo chmod +x install.sh
sudo ./install.sh -i

Return to “Other programming languages”