BBC BASIC
General >> Announcements >> BBC BASIC for SDL 2.0 v0.16a released http://bbcbasic.conforums.com/index.cgi?board=announcements&action=display&num=1485942746 BBC BASIC for SDL 2.0 v0.16a released
Post by Richard Russell on Feb 1st, 2017, 08:52am
I'm pleased to announce a new release of BBCSDL, the cross-platform edition of BBC BASIC for Windows, Linux (x86), Mac OS-X and Android. Version 0.16a may be downloaded as follows:
The Android edition has been rebuilt using the latest version of SDL: 2.0.5. It should install and run on any modern Android device, whether using an Intel (x86) CPU or an ARM CPU, although please note that ARM does not support 80-bit extended-precision floats.
Interpreter:
As discussed in the 'bug alert' thread, a test has been added to detect the unstable state that can arise if a user-defined function, passed as an 'actual' parameter to a FN/PROC, modifies a string variable used as a 'formal' paramater of that same FN/PROC. In that event the 'Incorrect arguments' error (code 31) is raised.
Also as discussed elsewhere, two issues related to addresses being 'unsigned', when they should be 'signed' (a structure in the first case and the address-of operator in the second), have been fixed.
OS/VDU emulation:
Support for 256-colour palettes has been improved.
The SOUND pitch accuracy, especially the lower notes, has been improved.
Added a workaround for an SDL bug affecting PLOT codes 8-15 ('omit last point' or more correctly 'plot last point twice'). However they still do not work exactly as they should on Linux.
IDEs:
The 'Touch IDE' used by the Android edition of BBCSDL now supports changing the size of the font using a 'pinch' zoom gesture. The new size is remembered and will be used in future sessions.
SDLIDE now incorporates a 'File... Compare' menu selection to list the differences between a program and an earlier version (very similar to the BB4W 'Differences' add-in utility).
BBCEdit has been updated to version 0.31.0.
Example Programs:
New in the 'games' directory: 2048.bbc, dibley.bbc and triples.bbc
New in the 'general' directory: optics.bbc, polyfit.bbc and solve.bbc
New in the 'graphics' directory: bounce.bbc, scarab.bbc, snowscene.bbc and squares.bbc
The DLGDEMO and OPENGL example programs are now also included with the Android edition of BBCSDL.
Libraries:
The DLGLIB library has been adapted to allow buttons and other controls to be used on the 'main window' rather than in a dialogue box (although this is rather a kludge). This library is now also included with the Android edition of BBCSDL.
The SORTLIB library has been adapted to be suitable for both x86 and ARM-based systems.
I still need volunteers to contribute to the documentation, help viewer, addin utilities and libraries.
Richard. Re: BBC BASIC for SDL 2.0 v0.16a released
Post by michael on Feb 2nd, 2017, 01:32am
Quote:
SDL 2.0: The Android edition has been rebuilt using the latest version of SDL: 2.0.5. It should install and run on any modern Android device, whether using an Intel (x86) CPU or an ARM CPU, although please note that ARM does not support 80-bit extended-precision floats.
AWESOME!! I have been waiting for years to get a proper IDE for my Samsung Galaxy Tablet..
I will get on this right away
Re: BBC BASIC for SDL 2.0 v0.16a released
Post by Richard Russell on Feb 4th, 2017, 09:17am
I've updated the Android edition to address a couple of issues as follows:
Support for very high resolution displays is improved. Previously, any display with more than 2048 pixels in the longer dimension gave rise to an unwanted 'scaling' error in graphics coordinates.
A fault which could, in rare circumstances, result in an 'Unfortunately BBC Basic has stopped' message has been fixed.
If you are not affected by either of these issues there is no benefit in upgrading. But if you are, or you think you might be, the new version (0.16c) is in the usual place:
Android should recognise this as an upgrade and your personal files should not be affected.
Richard. Re: BBC BASIC for SDL 2.0 v0.16a released
Post by mavison on Feb 5th, 2017, 2:16pm
I was alerted to the new SDL version of Basic by your post about the Andriod version on the RISC OS Open website.
I have used BBC Basic for Windows in a small way for some years now - is code written for that compatible with the new SDL version for Windows? If not, is there any documentation of the differences?
Will code that runs on the Windows SDL version also run on the MacOS SDL version? Assuming of course that no Windows SYS calls are used!
I am considering moving some programs that currently run under Basic in RISC OS to Windows SDL Basic for development, but they will be used on MacOS! They only read & write sequential files, and display messages - nothing fancy! Re: BBC BASIC for SDL 2.0 v0.16a released
Post by Richard Russell on Feb 5th, 2017, 5:51pm
Is code written for that compatible with the new SDL version for Windows? If not, is there any documentation of the differences?
With very few exceptions, code written for BBC BASIC for Windows will run unmodified in BBCSDL so long as it doesn't call any Windows API functions and doesn't rely on any libraries that are not supplied with BBCSDL.
One exception is the *FONT command, which if used will need to be modified to select one of the fonts supplied with BBCSDL (or one which you provide yourself) and to specify the full path to its .ttf file. Look at the example programs supplied with BBCSDL for guidance.
Obviously if the code does call Windows API functions then it will require some conversion. Unfortunately it's impossible to give general guidance on this: APIs range from ones that have trivial equivalents at one extreme to being almost impossible to emulate at the other.
Quote:
Will code that runs on the Windows SDL version also run on the MacOS SDL version? Assuming of course that no Windows SYS calls are used!
Generally yes, the degree of compatibility is very good. However you can get caught out by 'sillies', like using backslashes rather than forward-slashes in path names (Windows is happy with forward-slashes, but Mac OS isn't happy with backslashes).
Compatibility with the Linux and Android versions is very good too, but with them you have to be careful about case-sensitivity in file and path names. And of course if you want your program to run on an ARM-based Android device you must avoid assembly language code (or provide both x86 and ARM code, which is possible).
Quote:
I am considering moving some programs that currently run under Basic in RISC OS to Windows SDL Basic for development, but they will be used on MacOS!
If you don't have a Mac on which to test them I can't guarantee that they will run flawlessly, but if you are careful about the issues discussed above they should.
Unfortunately BBCSDL does not yet support creating standalone Mac applications. It actually isn't difficult - it's probably the easiest of all the platforms supported by BBCSDL on which to achieve that - but it hasn't been a high priority for me. If necessary I can give you some guidance on how to do it manually, or you can tell your end-user(s) to install BBCSDL.
Richard. Re: BBC BASIC for SDL 2.0 v0.16a released
Post by mavison on Feb 5th, 2017, 10:10pm
Thanks Richard for that comprehensive and quick reply.
I think I can do what I want in pure Basic without using Windows or SDL APIs - even if I have to Spool some *dir output and read it back to get a list of files in a directory!
If I get my slashes sloping in the right way it could even run on Windows & Mac. Just in case, is there a way for a program to discover which it is running on? (apart from cheating by recognising the @dir$ value!)
I will have access to the Mac for testing, and I can install BBCSDL there, but most development would be done on Windows.
The programs are currently being run on the Mac using RPCEmu to emulate a RISC PC, then running RISC OS 5 under that, then running the programs - so even using BBCSDL would be a big improvement!
You have given me the confidence to try some experimenting, and to remind myself how to move a program from RISC OS to BB4W.
Thanks for your work, and your help. Martin
Re: BBC BASIC for SDL 2.0 v0.16a released
Post by Richard Russell on Feb 6th, 2017, 08:49am
even if I have to Spool some *dir output and read it back to get a list of files in a directory!
You can 'borrow' code for doing that from either touchide.bbc or SDLIDE.bbc (they use basically the same code). Using a sneaky trick with WIDTH 20 they even manage to parse the *dir output to cope with filenames containing spaces!
Quote:
is there a way for a program to discover which it is running on? (apart from cheating by recognising the @dir$ value!)
INKEY(-256) will tell you if it is running in RISC OS, BB4W or BBCSDL. Having ascertained that it is running in BBCSDL you can test the least-significant byte of the @platform% variable which is 0 for Windows, 1 for Linux, 2 for MacOS and 3 for Android.
Quote:
to remind myself how to move a program from RISC OS to BB4W.
BB4W will read and automatically convert Acorn's tokenised program format, but BBCSDL won't. So if you want to import that format go through BB4W first. Otherwise spool your program to plain text (.bas); both BB4W and BBCSDL will read that.
Richard. Re: BBC BASIC for SDL 2.0 v0.16a released
Post by mavison on Feb 6th, 2017, 10:18am
Thanks for all the hints. Most useful.
Is the only current way to run a program using SDL is to start an IDE, navigate to the program.bas and then run it?
I only realised double-clicking it externally simply used BB4W - hard to tell the difference until I used INKEY(-256)!
Thanks Martin
Re: BBC BASIC for SDL 2.0 v0.16a released
Post by Richard Russell on Feb 6th, 2017, 1:53pm
Is the only current way to run a program using SDL is to start an IDE, navigate to the program.bas and then run it?
On most platforms you can simply specify the name of a BASIC program (as a tokenized .bbc file) on the command line. For example on both Windows and Linux you can do:
Code:
bbcsdl path/to/program.bbc
and it will run that program. Indeed if you omit the command-line argument BBCSDL will search for the file bbcsdl.bbc in the current directory and run it if found. That's the mechanism by which the 'choose IDE' launcher is executed.
I have to confess that Mac OS is more of a mystery to me, because rather than a simple executable file like bbcsdl there is an 'application package', and I'm not sure whether the concept of 'command line arguments' applies.
If the worst comes to the worst and that facility isn't directly available on the Mac all you would need to do is take a copy of the BBC Basic application, navigate 'inside' the package using Finder, and replace the supplied bbcsdl.bbc with your own program of the same name.
BBC BASIC will not realise your subterfuge and will automatically run your program when the application is executed. The only 'gotcha' is that the resulting application won't have a valid digital signature which might cause issues during deployment.
Quote:
I only realised double-clicking it externally simply used BB4W - hard to tell the difference until I used INKEY(-256)!
I'm not too sure what you mean. BBCSDL has no dependence on BB4W, and the latter doesn't even need to be installed.
Edit: Unless you mean double-clicking on a .bbc file, when of course what application gets executed depends entirely on the 'file associations'. It could be BB4W or it could be BBCSDL, depending on how you've configured Windows.
Richard. Re: BBC BASIC for SDL 2.0 v0.16a released
Post by mavison on Feb 6th, 2017, 5:27pm
Thanks for the parameter info. I will include that when I do some experiments - and if I discover anything about the Mac I will post again.
Quote:
It could be BB4W or it could be BBCSDL, depending on how you've configured Windows.
Yes - obvious when you realise what is happening!
Martin Re: BBC BASIC for SDL 2.0 v0.16a released
Post by Richard Russell on Feb 8th, 2017, 9:28pm
I've updated the Android edition of BBC BASIC once again, this time to version 0.16d. Changes in this release are:
Fixed another issue affecting displays with a resolution in excess of 2048 pixels.
Fixed pasting BBC BASIC code put on the clipboard by another Android app.
Version 0.16d may be downloaded from the usual place:
Android should recognise this as an upgrade and your personal files should not be affected.
Richard. Re: BBC BASIC for SDL 2.0 v0.16a released
Post by DDRM on Feb 9th, 2017, 12:44pm
Hi Richard,
Upgrading to 0.16d for Android results in BBC Basic failing to start with a "couldn't allocate memory" error on my Google Nexus 7. Any ideas about why? I'm currently running Android 4.4.4.
Best wishes,
David
Re: BBC BASIC for SDL 2.0 v0.16a released
Post by Richard Russell on Feb 9th, 2017, 2:35pm
It means what it says! I'm surprised that there isn't enough memory available on your device for BBC BASIC (it tries to allocate 256 Mbytes initially, but will fall back to smaller amounts if it has to). It probably means you have several apps open 'in the background'.
The first thing to try is closing all those background apps (press on the 'square' or 'menu' button; depending on the version of Android there may be a 'close all' selection or you may have to close each one individually). Failing that a full reboot is the next step.
I'm no Android expert, but it may be that Java apps are able to cooperate more closely in their use of memory, but a native app like BBC BASIC gets what it is given and no more.
I've put a program 'mmap.bbc' in the tools directory which you can use to get more information than you could possibly want about the current memory map.
Richard.
Re: BBC BASIC for SDL 2.0 v0.16a released
Post by Richard Russell on Feb 10th, 2017, 10:32am
The first thing to try is closing all those background apps (press on the 'square' or 'menu' button; depending on the version of Android there may be a 'close all' selection or you may have to close each one individually). Failing that a full reboot is the next step.
Did that fix the problem?
Once it's working again you can get a (very) rough feel for how close you are to running out of memory by checking the value of PAGE. e.g. by running 'about.bbc'. BBC BASIC tries to allocate memory starting from the bottom, so the higher the resulting address the nearer you were to getting the error message.
Different versions of Android seem to be quite variable in how they allocate memory, and on the machines I have here BBC BASIC seems typically to end up at a lower address in Marshmallow (Android 6.0) than it does in KitKat (Android 4.4).
Richard. Re: BBC BASIC for SDL 2.0 v0.16a released
Post by DDRM on Feb 11th, 2017, 6:19pm
Hi Richard,
No, even with all apps shut and after a restart .16d wouldn't run. I've uninstalled it and reinstalled .16a, which runs fine, though I haven't had much chance to play with it.
That reports PAGE=&20031700, and HIMEM as &20231700, with available memory as 2,097,152 bytes.
I make that PAGE value a bit over 500MB. The Nexus has 2GB of memory, so there shouldn't be an issue...
Best wishes,
D
Re: BBC BASIC for SDL 2.0 v0.16a released
Post by Richard Russell on Feb 11th, 2017, 7:55pm
I've uninstalled it and reinstalled .16a, which runs fine, though I haven't had much chance to play with it.
UNDER NO CIRCUMSTANCES must you use 0.16a. It has a MAJOR BUG which is liable to crash your device.
Are you saying that 0.16d does not run after a full reboot? I would find that surprising, but if it is the case it unfortunately means that your device is not suitable for running BBC BASIC since it cannot make available the necessary memory.
It may be worth upgrading to a newer version of Android, if available, to see if that helps.
Richard. Re: BBC BASIC for SDL 2.0 v0.16a released
Post by Richard Russell on Feb 12th, 2017, 11:45am
I've updated BBCSDL once again (all editions), this time to v0.16e. This version uses an even more aggressive memory-allocation strategy - it will attempt to squeeze itself into a smaller gap - in the hope that it may solve the reported "Couldn't allocate memory" message.
Version 0.16e may be downloaded for the various platforms as follows:
I've found out how to check my memory, and .16d won't run even when there is 1.4GB of RAM free!
It's the old fragmentation problem. It doesn't matter how much memory is free if there isn't a contiguous block big enough to contain BBC BASIC's heap/stack (it attempts to allocate 256 Mbytes). It's a problem on Windows too, but Android has a less sophisticated memory management system so is likely to suffer more.
Quote:
However, I downloaded .16e, and that appears to run fine
It takes more liberties than 0.16d! As I mentioned previously, you can run mmap.bbc (in the tools directory) to get a feel for how fragmented your memory is. If the screen fills with allocations you can tap on it to scroll through more; if that proves to be necessary it gives you an idea of the problem!
Richard. Re: BBC BASIC for SDL 2.0 v0.16a released
Post by DDRM on Feb 14th, 2017, 08:34am
Hmm. Obviously I couldn't run mmap until I had a recent working version. It's certainly a sobering insight into a modern operating system!
I note that you said "reboot" the device. Is that different from turning it off (i.e. power down, not just sleep) and back on? IS there a generic Android way of doing that? I'm guessing that things might then take consecutive blocks of memory, rather than being scattered all over.
I don't really want to put it back to factory defaults, deleting all apps etc...
Best wishes,
D
Re: BBC BASIC for SDL 2.0 v0.16a released
Post by Richard Russell on Feb 14th, 2017, 11:28am
Usually achieved by holding down the on/off button until it prompts you to power it down. The crucial thing is that when you next power up it should take quite a long time, probably initially displaying the Android logo (or the manufacturer's logo if customised) whilst it reboots, so it can't easily be mistaken for waking from sleep.
Mind you the Facebook app regularly crashes so badly that it causes my phone to reboot, so it happens whether I want it to or not!
Quote:
I don't really want to put it back to factory defaults, deleting all apps etc...
No, of course not. That should definitely not be necessary.
If you do have many apps that run automatically at boot-up, because they need to monitor things 'in the background' (and an awful lot of apps seem to think they do) it's unlikely that you can - or would want to - do anything about that.
My Android phone is short of memory and quite often fails to install new apps for that reason, but it's all the 'pre-installed' apps that I don't want, but can't get rid of (other than by 'rooting' it), that are responsible. It's annoying, but presumably the manufacturer gets a lucrative deal from the vendors of those apps in exchange for forcing them on their users.
Richard. Re: BBC BASIC for SDL 2.0 v0.16a released
Post by DDRM on Feb 15th, 2017, 08:07am
OK, thanks - that's what I did, and it still didn't help. I hoped that when it started up "from cold" they'd all take contiguous memory,and leave a nice big chunk at the end for BBCSDL. Anyway, .16e seems to have done the trick!
I have rather few apps installed (by me) - but you're right, there are a ridiculous number that I can't even delete, mostly trying to get me to buy things from the Play store...
D
Re: BBC BASIC for SDL 2.0 v0.16a released
Post by Richard Russell on Feb 15th, 2017, 08:17am
I hoped that when it started up "from cold" they'd all take contiguous memory,and leave a nice big chunk at the end for BBCSDL.
Me too, but the fly in the ointment is quite possibly ASLR (Address Space Layout Randomization) which is a security measure implemented by all modern operating systems:
Richard.
Re: BBC BASIC for SDL 2.0 v0.16a released
Post by Richard Russell on Feb 18th, 2017, 5:50pm
I've discovered a minor bug, which affects only the ARM editions (i.e. Android and Raspberry Pi): INKEY(-10), INKEY(-11) and INKEY(-12), which should detect the mouse buttons, were not working. This is fixed in version 0.16g; there are no other changes.