BBC Basic for windows and Android - *DISPLAY and swiping

Discuss all aspects of programming here. From 8-bit through to modern architectures.
User avatar
pixelblip
Posts: 1534
Joined: Wed Feb 04, 2015 7:19 pm
Location: London
Contact:

BBC Basic for windows and Android - *DISPLAY and swiping

Post by pixelblip » Mon Dec 30, 2019 9:41 pm

Hi there

I wanted to load a set of pictures (my own) in BBC Basic for windows.
There is a command *DISPLAY which displays a .bmp.

What I wanted to do was if you press space bar it loads a random picture with *DISPLAY and picks a name out of the hat ( or a number and opens that bmp e.g. 2.bmp)

I tried writing a string e.g. name$="C:\gallery\pics) but that won't work with *DISPLAY as far as I can see.
Can anyone chime in here or is there another command I can use please?

Also sorry to bunch this up but I was thinking of producing an app /apk as well in android everyone could use using BBC Basic. How do I go about doing this: If you swipe up it loads the next picture from a set of names/ swipe down it goes back to the previous picture.

I could puts some navigation buttons on the screen I suppose but people are much more used to swiping on their phone when viewing pictures....

Thanks!
Last edited by pixelblip on Tue Dec 31, 2019 5:50 am, edited 1 time in total.

User avatar
Richard Russell
Posts: 1138
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: BBC Basic for windows and Android - *DISPLAY and swiping

Post by Richard Russell » Mon Dec 30, 2019 10:29 pm

pixelblip wrote:
Mon Dec 30, 2019 9:41 pm
I tried writing a string e.g. name$="C:\gallery\pics) but that won't work with *DISPLAY as far as I can see.
The statement you are looking for is OSCLI:

Code: Select all

      random% = RND(9)
      bmp$ = "C:\gallery\pics\" + STR$(random%) + ".bmp"
      OSCLI "DISPLAY """ + bmp$ + """"
How do I go about doing this: If you swipe up it loads the next picture from a set of names/ swipe down it goes back to the previous picture.
One easy way would be to use MOUSE x,y,b to record the coordinates when you touch the screen and then record them again when you release. You can then determine whether it's a swipe (e.g. by checking that the distance moved is greater than some threshold) and if so in what direction. If you additionally want to measure the speed that's easily done by also recording the TIMEs.

User avatar
pixelblip
Posts: 1534
Joined: Wed Feb 04, 2015 7:19 pm
Location: London
Contact:

Re: BBC Basic for windows and Android - *DISPLAY and swiping

Post by pixelblip » Mon Dec 30, 2019 10:32 pm

Thanks for answering my questions so quickly Richard! BBC Basic is so great and versatile.
Mike

User avatar
Richard Russell
Posts: 1138
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: BBC Basic for windows and Android - *DISPLAY and swiping

Post by Richard Russell » Tue Dec 31, 2019 2:55 am

pixelblip wrote:
Mon Dec 30, 2019 10:32 pm
BBC Basic is so great and versatile.
Nevertheless it isn't so "versatile" that you should attempt to write a program in BBC BASIC for Windows and then port it to Android; that is likely to end in tears! If you are aiming to run a program on Android, and you want to develop it on Windows, then you should use BBC BASIC for SDL 2.0 not BBC BASIC for Windows.

This is the process I would recommend for developing Android apps in BBC BASIC:
  1. Write and test the program in Windows, using BBC BASIC for SDL 2.0. Keep in mind the specific needs of Android when doing so, such as case-dependent filenames and all file paths being relative to @dir$, @usr$ or @tmp$. Also make sure it never QUITs or exits to immediate mode; you will need to trap or disable the ESCape error. Using a Windows PC with a touchscreen will help with testing the user interface.

  2. Once the program is working to your satisfaction in Windows, connect a suitable Android device (on which BBC BASIC has been installed) to the PC using a USB lead and configure it as a remote file system. Run BBC BASIC on both devices so that you can edit the program in Windows and instantly run it on Android; this is much easier than using the limited editing capabilities provided on Android.

  3. When every aspect of your program is running as desired on Android, convert it to a standalone app using the BBC2APK utility. You will then be able to install it on the Android device and run it independently of BBC BASIC.

User avatar
Richard Russell
Posts: 1138
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: BBC Basic for windows and Android - *DISPLAY and swiping

Post by Richard Russell » Tue Dec 31, 2019 10:15 am

Something else to add, although it ought not to need saying, is that Android devices are almost invariably battery powered so even more attention than usual should be paid to keeping CPU activity to a minimum.

For example if you are continuously polling the mouse/touchscreen to detect a swipe, choose the rate at which you do so carefully. Poll too quickly and your program may consume more power than it should, poll too slowly and you may miss (or mis-categorise) a fast swipe.

You might want to consider an adaptive scheme, whereby you poll more often whilst the screen is being touched than when not. You could even consider using an ON MOUSE 'interrupt' to initiate polling, so that none is performed at all when the program is idle (e.g. just displaying an image).

User avatar
pixelblip
Posts: 1534
Joined: Wed Feb 04, 2015 7:19 pm
Location: London
Contact:

Re: BBC Basic for windows and Android - *DISPLAY and swiping

Post by pixelblip » Tue Dec 31, 2019 10:17 am

Great Richard. Loads of useful advice in there thank you!

User avatar
Richard Russell
Posts: 1138
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: BBC Basic for windows and Android - *DISPLAY and swiping

Post by Richard Russell » Tue Dec 31, 2019 12:40 pm

pixelblip wrote:
Tue Dec 31, 2019 10:17 am
Loads of useful advice in there thank you!
I should have added that one benefit of using BBC BASIC for SDL 2.0 is that you can *DISPLAY JPG (and GIF, PNG) images, which is likely to be what you want to do in the application you describe. Converting the images to .BMP format, which would have been necessary in BBC BASIC for Windows (or using a non-portable Windows API method to load them), would have been inconvenient and wasteful of storage space.

User avatar
pixelblip
Posts: 1534
Joined: Wed Feb 04, 2015 7:19 pm
Location: London
Contact:

Re: BBC Basic for windows and Android - *DISPLAY and swiping

Post by pixelblip » Tue Dec 31, 2019 12:46 pm

Another good tip!

User avatar
pixelblip
Posts: 1534
Joined: Wed Feb 04, 2015 7:19 pm
Location: London
Contact:

Re: BBC Basic for windows and Android - *DISPLAY and swiping

Post by pixelblip » Tue Dec 31, 2019 5:37 pm

I am coming on leaps and bounds with this Richard :D


User avatar
pixelblip
Posts: 1534
Joined: Wed Feb 04, 2015 7:19 pm
Location: London
Contact:

Re: BBC Basic for windows and Android - *DISPLAY and swiping

Post by pixelblip » Tue Dec 31, 2019 7:10 pm

Gallery
Attachments
bbcbasicGallery.gif
bbcbasicGallery.gif (325.55 KiB) Viewed 503 times

User avatar
pixelblip
Posts: 1534
Joined: Wed Feb 04, 2015 7:19 pm
Location: London
Contact:

Re: BBC Basic for windows and Android - *DISPLAY and swiping

Post by pixelblip » Tue Dec 31, 2019 7:26 pm

Hi again Richard....sorry for all these questions!
Quite a lot of my pictures are gifs.....really it's old fashioned colour cycling on the BBC micro I've turned into gifs.
Can you think a way that isn't too difficult of being able to display these? I guess I will have to export one frame at a time and then get them to cycle loading one pic at a time....it's a bit of a challenge isn't it......if you can think of another way then super!
Thank you - and have a great New Year's eve. I am just at home programming!
Last edited by pixelblip on Tue Dec 31, 2019 9:34 pm, edited 1 time in total.

User avatar
Richard Russell
Posts: 1138
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: BBC Basic for windows and Android - *DISPLAY and swiping

Post by Richard Russell » Tue Dec 31, 2019 9:08 pm

pixelblip wrote:
Tue Dec 31, 2019 7:26 pm
I guess I will have to export one frame at a time and then get them to cycle loading one pic at a time
Google agrees with you, and finds several sites to make it easy (yes, you could write a BBC BASIC for Windows program for it, but why bother if there are online tools that will do it for 'free'). Although if you've got the original palette-cycling code couldn't you adapt that?

User avatar
Richard Russell
Posts: 1138
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: BBC Basic for windows and Android - *DISPLAY and swiping

Post by Richard Russell » Wed Jan 01, 2020 12:16 pm

Richard Russell wrote:
Tue Dec 31, 2019 9:08 pm
Although if you've got the original palette-cycling code couldn't you adapt that?
The more I think about it the more it seems that's the right way to go. Starting with a BBC Micro demo that uses a dynamically switched palette, converting it to an animated GIF, then figuring out a way to display an animated GIF in SDL2 (which has no built-in support for them) seems to be a very roundabout way of emulating something that SDL2 (and Windows) can do, i.e. dynamically switch a palette!

User avatar
pixelblip
Posts: 1534
Joined: Wed Feb 04, 2015 7:19 pm
Location: London
Contact:

Re: BBC Basic for windows and Android - *DISPLAY and swiping

Post by pixelblip » Wed Jan 01, 2020 6:27 pm

Yes I agree with you Richard....I am not sure if I still have all the bbc files to all the pictures ( lost in time ) but point taken this would be the best way.....but if you save a mode 2 picture out from a BBC I wonder the best of way of loading that on top of a 16 bit bmp...I'll have to experiment with that.

It might be in the end I just do it in bbc basic fow windows and leave it as that...or even output it all to youtube like that video....I am all for simplicity with things as my programming skills aren't that great......anyway thanks for your suggestions it is food for thought.
Mike

julie_m
Posts: 134
Joined: Wed Jul 24, 2019 8:53 pm
Location: Derby, UK
Contact:

Re: BBC Basic for windows and Android - *DISPLAY and swiping

Post by julie_m » Wed Jan 01, 2020 6:36 pm

Can't you just split up the animated GIFs into separate images for each frame? If you export them as .png, anything modern ought to be able to display them, or you could convert them back to BBC format.

User avatar
Richard Russell
Posts: 1138
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: BBC Basic for windows and Android - *DISPLAY and swiping

Post by Richard Russell » Wed Jan 01, 2020 8:18 pm

julie_m wrote:
Wed Jan 01, 2020 6:36 pm
Can't you just split up the animated GIFs into separate images for each frame?
That's what was suggested a few posts ago, to which I responded that Google finds online sites which will do it for you. But it just seems a very roundabout way of achieving what the BBC Micro did using palette animation. So why not use palette animation?! It's true that modern displays are rarely if ever paletted, but both Windows and SDL2 support palette animation on intermediate bitmaps, so you can still do it - and example BBC BASIC code is readily available.

julie_m
Posts: 134
Joined: Wed Jul 24, 2019 8:53 pm
Location: Derby, UK
Contact:

Re: BBC Basic for windows and Android - *DISPLAY and swiping

Post by julie_m » Wed Jan 01, 2020 10:07 pm

I thought an animated GIF always had just one 256-colour palette for all frames? Been awhile since I had to mess with graphics data directly without the aid of a good library, so I might have forgotten some of the details!

User avatar
Richard Russell
Posts: 1138
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: BBC Basic for windows and Android - *DISPLAY and swiping

Post by Richard Russell » Wed Jan 01, 2020 10:59 pm

julie_m wrote:
Wed Jan 01, 2020 10:07 pm
I thought an animated GIF always had just one 256-colour palette for all frames?
My understanding is that a GIF89A file can use a global palette, but the option to have a separate palette for each frame is supported. Obviously there's a cost in file size if you use separate palettes. But in any case if we're talking about palette animation on a BBC Micro there are only 8 different physical colours (not counting flashing colours) so having a single global palette is not a limitation.

User avatar
Richard Russell
Posts: 1138
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: BBC Basic for windows and Android - *DISPLAY and swiping

Post by Richard Russell » Wed Jan 01, 2020 11:18 pm

This is the output from the example program colorcycle.bbc (supplied with all editions of BBC BASIC for SDL 2.0) converted to an animated GIF with a global palette:

Image

User avatar
FourthStone
Posts: 846
Joined: Thu Nov 17, 2016 2:29 am
Location: Brisbane, Australia
Contact:

Re: BBC Basic for windows and Android - *DISPLAY and swiping

Post by FourthStone » Thu Jan 02, 2020 3:51 am

pixelblip wrote:
Wed Jan 01, 2020 6:27 pm
Yes I agree with you Richard....I am not sure if I still have all the bbc files to all the pictures ( lost in time ) but point taken this would be the best way.....but if you save a mode 2 picture out from a BBC I wonder the best of way of loading that on top of a 16 bit bmp...I'll have to experiment with that.
Technically you can use Art4Eva to import BBC format files and then export as the animated color cycled sequence.

Let me know that's not what you need, I understand what you're trying to do I think which is to display the Gif frames one by one to make it appear to be colour cycling? Shouldn't be too much work to make that happen, if you need to do the same function within BBC Basic for Windows (or SDL) we could look at using the format conversion and colour cycling code from Art4Eva.

Loving the gallery vid, very nice way to view your pics!

User avatar
pixelblip
Posts: 1534
Joined: Wed Feb 04, 2015 7:19 pm
Location: London
Contact:

Re: BBC Basic for windows and Android - *DISPLAY and swiping

Post by pixelblip » Thu Jan 02, 2020 8:12 pm

Hi Fourthstone

This was the idea I had...or many of them!

What I wanted to do was create a gallery - just simple stuff - it pick a random picture and a random room that was pre-rendered ( I could render those and do some quite interesting ones ). It then puts the pic into the frame. I could go further and try to categorise the whole thing in sections but I think maybe that isn't worth it - just use randomisation ( and put the name of the pic over the top of the image).
It would be nice if it the program could scroll so as you go to the next picture it sideways scrolls to the next image.....I quite like the idea of that.

As for the gifs, I don't know where the .bbc files are for these. It would take a lot of work trying to find them all. I think it's better to use the gifs already there (if that is possible). The problem with that is that they are different sizes - not always 640x512 -sometimes 320x256. So it's working out how to do that.
I could do it so level 1 is just paintings and level 2 is gifs ( which runs a different bbc basic routine for gifs). At the moment I have got all the paintings together and just numbered them 1 to 500 and got the program to pick one from this list.

I even had the idea at one stage to do it on a BBC micro but I thought hmmm that presents a few challenges. I thought I could do a teletext front page with different levels then set up some kind of navigation to each painting.

I think for now keep it simple and we'll work out how to do the gifs.....either I try to find all the original files or I split the gifs up into seperate folders.....with individual pictures.

I was going to do it all in 3d and vr but you know what....I thought really all people want to do is look at the pics....so I thought pre-render some scenes and put the pics in those frames. It is quite enticing the thought of getting this working so it works in Android...I like the idea of it growing so for example it looks at a folder on the internet that can be updated with pictures....so every time I do one I can add it to the folder....

Sorry it's all ideas here.....don't want to get too ambitious or ahead of myself.

User avatar
Richard Russell
Posts: 1138
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: BBC Basic for windows and Android - *DISPLAY and swiping

Post by Richard Russell » Thu Jan 02, 2020 11:05 pm

pixelblip wrote:
Thu Jan 02, 2020 8:12 pm
I was going to do it all in 3d and vr but you know what....I thought really all people want to do is look at the pics
Texture mapping an image onto a plane rectangle within a 3D scene is straightforward. I expect you remember my rotating cube with images on each face, which was a trivial example. BBC BASIC makes that kind of thing so easy:

https://www.youtube.com/watch?v=Ja7RRdpL1QI

User avatar
pixelblip
Posts: 1534
Joined: Wed Feb 04, 2015 7:19 pm
Location: London
Contact:

Re: BBC Basic for windows and Android - *DISPLAY and swiping

Post by pixelblip » Fri Jan 03, 2020 2:19 am

Ahh thanks Richard. That is an interesting thought. It means I cold design rooms in different ways and use angles which could provide much more variety.

It will be I interesting to see how this gallery develops.

I had a few tries at running bbctoapk but I found it hangs. It seems to be when clicking download template...it says download but then then the window doesn't close. It then won't generate the APK and I have to force quit.
It could be something I am doing as I was just experimenting.....

User avatar
Richard Russell
Posts: 1138
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: BBC Basic for windows and Android - *DISPLAY and swiping

Post by Richard Russell » Fri Jan 03, 2020 10:01 am

pixelblip wrote:
Fri Jan 03, 2020 2:19 am
it says download but then then the window doesn't close.
How long did you wait? It's a fairly large download. The code it's using, as you can probably guess, is this from the BB4W manual, so it's pretty standard and I've not known it to fail in normal circumstances (by which I mean assuming you're not behind a firewall or proxy).

Can I also remind you that it isn't sensible to run BBC2APK until you've thoroughly tested your program on an Android device. Expecting to be able to convert a BBC BASIC program to an Android APK, and for it to work without ever having tried it on that platform, is unreasonable. You might get away with it for the very simplest programs, but that's not typical.

BBC2APK is the tool to use as the very last step in developing an Android app, when you know it's fully compatible and working.

User avatar
pixelblip
Posts: 1534
Joined: Wed Feb 04, 2015 7:19 pm
Location: London
Contact:

Re: BBC Basic for windows and Android - *DISPLAY and swiping

Post by pixelblip » Fri Jan 03, 2020 1:01 pm

Ok Richard that is a good point. I didn't realise it took so long to download the template. Apololgies.
I will do what you said and test it all out first on Android.
Mike

User avatar
pixelblip
Posts: 1534
Joined: Wed Feb 04, 2015 7:19 pm
Location: London
Contact:

Re: BBC Basic for windows and Android - *DISPLAY and swiping

Post by pixelblip » Fri Jan 03, 2020 4:45 pm

Hi Richard
Can I ask you to debug my program please :lol: Sorry I know this is probably annoying!

I tried this program below in BBC Basic for SDL
It works fine.
When I tried to make an apk of it I wasn't quite sure what to do ( RTFM ) concerning the paths.
I took out the word "C\pics" so it just said
20pic$ = "P" + STR$(randomp%) + ".jpg"

Sorry I wasn't sure where to put the pics in Android or what to use in terms of file paths...
When I ran the APK it just said
File or Path not found at line 10

I am using the emulator Bluestacks to let you know but that should just function like you are running an ordinary phone....
Can you think what might be wrong here?
I added all the jpeg pictures to the dir$ directory in the BBCtoAPK app before I built it.
Sorry I have no idea what I am doing but what the heck!
Thanks for any help.
Mike




10randomp% = RND(10)
20pic$ = "C:\pics\" + "P" + STR$(randomp%) + ".jpg"
30OSCLI "DISPLAY """ + pic$ + """"

40random% = RND(538)
50bmp$ = "C:\pics\" + "(" + STR$(random%) + ")" + ".jpg"
60OSCLI "DISPLAY """ + bmp$ + """" +" 510,416,1040,700 "
70WAIT 500
80GOTO 10
90
100REM
110REM *DISPLAY c:\gallery\december.bmp 510,416,1040,700
120
130REM *DISPLAY c:\gallery\ancient.bmp 510,416,1040,700
140
150A$=GET$
160GOTO 40

User avatar
pixelblip
Posts: 1534
Joined: Wed Feb 04, 2015 7:19 pm
Location: London
Contact:

Re: BBC Basic for windows and Android - *DISPLAY and swiping

Post by pixelblip » Fri Jan 03, 2020 4:50 pm

I've just ran that on my phone to test it's not Bluestacks.

It says 'File or path not found at line 30' on my phone (rather than line 10 when run on Bluestacks)

So it doesn't like the path in the OSCLI command....that variable pic$. Sorry it must be a schoolboy error

30OSCLI "DISPLAY """ + pic$ + """"

User avatar
Richard Russell
Posts: 1138
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: BBC Basic for windows and Android - *DISPLAY and swiping

Post by Richard Russell » Fri Jan 03, 2020 5:05 pm

pixelblip wrote:
Fri Jan 03, 2020 4:45 pm
When I tried to make an apk of it I wasn't quite sure what to do ( RTFM ) concerning the paths.
Had you RTFM this is what you would have found: "Android does not support the concept of 'current directory' therefore all files should be specified using an absolute path rather than a relative path. This is most easily achieved by using the @dir$, @lib$, @tmp$ and @usr$ system variables". You appear to have done the exact opposite and converted an absolute path (albeit an invalid one) into a relative path! :roll:

Generally speaking everything wlll work if you write your code as if you were going to 'compile' it in BB4W or BBCSDL for distribution to other users. You wouldn't refer to C:\pics then, would you, since you can't know that the end-user has a folder called C:\pics (and in non-Windows OSes drives are not described that way anyway)? Any 'resource' files that your program uses (images, music, sounds etc.) will normally be in @dir$ or (preferably) a sub-directory of @dir$ and that will work fine in Android too.
Sorry I have no idea what I am doing but what the heck!
That really isn't an approach I can recommend! I was aware that in creating BBC2APK I was potentially tempting people to run before they can walk, which is why I have emphasised that you should test your program on Android using the 'interactive' version of BBC BASIC (I listed the steps in an earlier post) before trying to build an APK. I can't think of anything much worse than a software development cycle that includes creating and installing an APK every time 'around the loop'!

User avatar
pixelblip
Posts: 1534
Joined: Wed Feb 04, 2015 7:19 pm
Location: London
Contact:

Re: BBC Basic for windows and Android - *DISPLAY and swiping

Post by pixelblip » Fri Jan 03, 2020 9:01 pm

Thank you Richard for your patience with me and taking the time to point me to the right place.
You have been very helpful.
When I say I don't know what I am doing that is true but there is always a bit of 'let's try this and see what happens' in the things I do....sometimes I get a result with a little help from my friends :)

I do hope I can suprise you all and do something cool with this app/program!

I agree with what you say...testing an APK out by building it is not very smart....I wasn't quite sure how to set it all up so I thought let's give that a go first...anway I am on the right path now I think!

Mike

Post Reply