yobson
Posts: 20
Joined: Wed Sep 14, 2016 6:31 pm
Location: Leeds
Contact: Website

RISC OS C Development Tutorial Series

Sat Oct 22, 2016 6:42 pm

Hello!

I've started making a tutorial series for wimp development in C.
You can find it here:
https://www.youtube.com/watch?v=ALiMp-GHIX4

The thing is, I'm only making it because I don't think there is enough information out there in the topic. I have no idea how to make tutorials :D

If anyone could suggest improvements and content it would be ace

Thanks

James

User avatar
DavidS
Posts: 4334
Joined: Thu Dec 15, 2011 6:39 am
Location: USA
Contact: Website

Re: RISC OS C Development Tutorial Series

Sun Oct 23, 2016 1:21 am

Better wording below...........
Last edited by DavidS on Sun Oct 23, 2016 3:32 am, edited 1 time in total.
RPi = The best ARM based RISC OS computer around
More than 95% of posts made from RISC OS on RPi 1B/1B+ computers. Most of the rest from RISC OS on RPi 2B/3B/3B+ computers

User avatar
DavidS
Posts: 4334
Joined: Thu Dec 15, 2011 6:39 am
Location: USA
Contact: Website

Re: RISC OS C Development Tutorial Series

Sun Oct 23, 2016 2:43 am

mnmnmnmn
Last edited by DavidS on Sun Oct 23, 2016 3:31 am, edited 1 time in total.
RPi = The best ARM based RISC OS computer around
More than 95% of posts made from RISC OS on RPi 1B/1B+ computers. Most of the rest from RISC OS on RPi 2B/3B/3B+ computers

User avatar
DavidS
Posts: 4334
Joined: Thu Dec 15, 2011 6:39 am
Location: USA
Contact: Website

Re: RISC OS C Development Tutorial Series

Sun Oct 23, 2016 3:30 am

The content seems to be good so far
Still downloading the last two parts, though it looks good so far.

The only change I would recommend is to use SharedCLib instead of UnixLib. This will produce AIF format programs, which is the native format of a program for RISC OS, thus not needing a special loader (as elf files do). Also using UnixLib breaks on some CPU's, like the ARM Cortex-A53 used int he Raspberry Pi 3B.

Otherwise great job, nice tutorials.
RPi = The best ARM based RISC OS computer around
More than 95% of posts made from RISC OS on RPi 1B/1B+ computers. Most of the rest from RISC OS on RPi 2B/3B/3B+ computers

dfeugey
Posts: 119
Joined: Mon Nov 03, 2014 2:38 pm
Location: France
Contact: Website

Re: RISC OS C Development Tutorial Series

Sun Oct 23, 2016 5:32 am

This will produce AIF format programs
This part should not be a problem, as I believe tools are present to convert elf to aif.
RISC OS FR - All RISC OS, in french (but not only)
http://www.riscos.fr/

User avatar
DavidS
Posts: 4334
Joined: Thu Dec 15, 2011 6:39 am
Location: USA
Contact: Website

Re: RISC OS C Development Tutorial Series

Sun Oct 23, 2016 5:45 am

dfeugey wrote:
This will produce AIF format programs
This part should not be a problem, as I believe tools are present to convert elf to aif.
Only if you staticaly link the application, that requires a much larger WimpSlot when compiling (at least 96MB instead of just 16MB), and it makes the program huge (because everything is linked into the application), not to mention that it takes a few extra steps, and it commits you to using the GPL as you are staticaly linking in code that is licensed under the GPL (much of the library code is GPL not LGPL).

Just compiling against the SharedCLibrary solves the problems. And it the SharedCLibrary is a complete C standard library.

And the current UnixLib contains SWP opcodes, that means no Raspberry Pi 3 for many UnixLib programs.
RPi = The best ARM based RISC OS computer around
More than 95% of posts made from RISC OS on RPi 1B/1B+ computers. Most of the rest from RISC OS on RPi 2B/3B/3B+ computers

yobson
Posts: 20
Joined: Wed Sep 14, 2016 6:31 pm
Location: Leeds
Contact: Website

Re: RISC OS C Development Tutorial Series

Sun Oct 23, 2016 7:07 pm

DavidS wrote:The content seems to be good so far
Still downloading the last two parts, though it looks good so far.

The only change I would recommend is to use SharedCLib instead of UnixLib. This will produce AIF format programs, which is the native format of a program for RISC OS, thus not needing a special loader (as elf files do). Also using UnixLib breaks on some CPU's, like the ARM Cortex-A53 used int he Raspberry Pi 3B.

Otherwise great job, nice tutorials.
Sadly GCC 4 can only output ELF format

yobson
Posts: 20
Joined: Wed Sep 14, 2016 6:31 pm
Location: Leeds
Contact: Website

Re: RISC OS C Development Tutorial Series

Sun Oct 23, 2016 7:09 pm

But I will check out all the stuff you have said

Thanks Man

User avatar
DavidS
Posts: 4334
Joined: Thu Dec 15, 2011 6:39 am
Location: USA
Contact: Website

Re: RISC OS C Development Tutorial Series

Sun Oct 23, 2016 7:32 pm

yobson wrote:
DavidS wrote:The content seems to be good so far
Still downloading the last two parts, though it looks good so far.

The only change I would recommend is to use SharedCLib instead of UnixLib. This will produce AIF format programs, which is the native format of a program for RISC OS, thus not needing a special loader (as elf files do). Also using UnixLib breaks on some CPU's, like the ARM Cortex-A53 used int he Raspberry Pi 3B.

Otherwise great job, nice tutorials.
Sadly GCC 4 can only output ELF format
Incorrect. If you specifically compile for SharedCLib it will produce an AIF.

The manual is inside the !GCC app folder. Just middle click on !GCC and go to the help item in the !GCC sub menu, it explains the usage to produce SharedCLibrary programs, it is pretty easy (and better than I could explain it).

Though you will need a copy of OSLib for GCC + SharedCLibrary as you are using OSLib and the copy you are using is for UnixLib. You can get that from the OSLib website.
yobson wrote:But I will check out all the stuff you have said

Thanks Man
No problem.
RPi = The best ARM based RISC OS computer around
More than 95% of posts made from RISC OS on RPi 1B/1B+ computers. Most of the rest from RISC OS on RPi 2B/3B/3B+ computers

dfeugey
Posts: 119
Joined: Mon Nov 03, 2014 2:38 pm
Location: France
Contact: Website

Re: RISC OS C Development Tutorial Series

Mon Oct 24, 2016 1:04 pm

Seems to be a lot of confusion here. Yes, GCC generates ELF. But yes, there is a tool to convert ELF to AIF.
Only if you staticaly link the application, that requires a much larger WimpSlot when compiling (at least 96MB instead of just 16MB)
Last time I tried, I did not see any overhead for the compile phase.
and it makes the program huge (because everything is linked into the application), not to mention that it takes a few extra steps, and it commits you to using the GPL as you are staticaly linking in code that is licensed under the GPL (much of the library code is GPL not LGPL).
Huge? BC for example is only 247 kB. And it's a very complex piece of code.

Anyway, this is not true. All AIF binaries are statically linked, including SharedCLib ones. But there is a runtime for SharedCLib, in order to reduce the size of executable. For UnixLib, just make an ELF file. Then it's dynamically compiled. Even in static form, it's not so big.

Second point, no, UnixLib is not GPL (any more). So no problem of licence. See: !GCC\docs\libunixlib\
Just compiling against the SharedCLibrary solves the problems. And it the SharedCLibrary is a complete C standard library.
Yes, but not a Posix one.
And the current UnixLib contains SWP opcodes, that means no Raspberry Pi 3 for many UnixLib programs.
Problem (mostly) solved since months. http://www.riscos.info/pipermail/gcc/20 ... hread.html
But, yes, you'll probably need to download the latest sources and build you own version.
RISC OS FR - All RISC OS, in french (but not only)
http://www.riscos.fr/

dfeugey
Posts: 119
Joined: Mon Nov 03, 2014 2:38 pm
Location: France
Contact: Website

Re: RISC OS C Development Tutorial Series

Mon Oct 24, 2016 1:08 pm

Nota: UnixLib is the default choice for GCC. When going to Wimp, the switch to OSLib (as James did) is the natural direction, IMHO. BTW, James, feel free to apply to this: https://www.riscos.fr/concours.html
;)
RISC OS FR - All RISC OS, in french (but not only)
http://www.riscos.fr/

User avatar
DavidS
Posts: 4334
Joined: Thu Dec 15, 2011 6:39 am
Location: USA
Contact: Website

Re: RISC OS C Development Tutorial Series

Mon Oct 24, 2016 2:24 pm

I give my apology, I did not know that the licensing of UnixLib was no longer GPL.


Though a test Hello World application compiled with UnixLib staticly linked (so can get an AIF) was many times bigger than it should be (I think it was over 20KB).
RPi = The best ARM based RISC OS computer around
More than 95% of posts made from RISC OS on RPi 1B/1B+ computers. Most of the rest from RISC OS on RPi 2B/3B/3B+ computers

dfeugey
Posts: 119
Joined: Mon Nov 03, 2014 2:38 pm
Location: France
Contact: Website

Re: RISC OS C Development Tutorial Series

Tue Oct 25, 2016 5:13 am

So the overhead is around 20 kB. That's OK for me for a Posix layer.
I prefer not to imagine the overhead of static linking under Linux :)
RISC OS FR - All RISC OS, in french (but not only)
http://www.riscos.fr/

User avatar
DavidS
Posts: 4334
Joined: Thu Dec 15, 2011 6:39 am
Location: USA
Contact: Website

Re: RISC OS C Development Tutorial Series

Tue Oct 25, 2016 2:31 pm

@yobson:
I hope that many new to programming on RISC OS see the tutorials. Your presentation is very good, and it may get more people interested in RISC OS.

Keep up the very good work, I look forward to reviewing your continuing series of tutorials in video form.
dfeugey wrote:So the overhead is around 20 kB. That's OK for me for a Posix layer.
I prefer not to imagine the overhead of static linking under Linux :)
Ok I just redid the test, so that I can say without having to rely on my memory.

For a simple hello world application (c.hello):

Code: Select all

#include <stdio.h>

int main(void)
{
  puts("Hello World!");
  return 0;
}
We get the following by compiling to AIF with SharedCLibrary and UnixLib:

Code: Select all

*gcc -mlibscl -Wall -o helloSCL hello.c
*gcc -static -Wall -o helloUnixL hello.c
*elf2aif helloUnixL
*helloSCL
Hello World!
*HelloUnixL
Hello World!
*info hello*
helloSCL     WR/     Absolute  08:17:21 25-Oct-2016 3276  bytes
helloUnixL   WR/     Absolute  08:18:36 25-Oct-2016  154 kbytes
As you can see the SharedCLibrary version is about 3KB and the UnixLib version is 154KB (way way over 20KB).

Also compiling the UnixLib version took about 10 times longer than compiling the SharedCLibrary version.

So if using UnixLib to produce AIF (thus not requiring the ELF loader), you will produce some truely huge results.

And why is Posix a good thing for RISC OS software?
I can see the use for porting programs from Unix like systems, though as for programs written for RISC OS using the Posix layer does not make since, at least not to me.
RPi = The best ARM based RISC OS computer around
More than 95% of posts made from RISC OS on RPi 1B/1B+ computers. Most of the rest from RISC OS on RPi 2B/3B/3B+ computers

dfeugey
Posts: 119
Joined: Mon Nov 03, 2014 2:38 pm
Location: France
Contact: Website

Re: RISC OS C Development Tutorial Series

Tue Oct 25, 2016 8:48 pm

you will produce some truely huge results
Huge... Almost as small as dynamically linked software under Linux :D
Anyway, use ELF. Problem solved.
I can see the use for porting programs from Unix like systems, though as for programs written for RISC OS using the Posix layer does not make since, at least not to me.
Much bigger API, and code portable under Linux :)
RISC OS FR - All RISC OS, in french (but not only)
http://www.riscos.fr/

User avatar
DavidS
Posts: 4334
Joined: Thu Dec 15, 2011 6:39 am
Location: USA
Contact: Website

Re: RISC OS C Development Tutorial Series

Tue Oct 25, 2016 11:06 pm

dfeugey wrote:
you will produce some truely huge results
Huge... Almost as small as dynamically linked software under Linux :D
Anyway, use ELF. Problem solved.
And I bet that a lot of the size of the Linux version is the ELF. The ELF of the UnixLib version is over 1MB on RISC OS:

Code: Select all

*gcc -static -Wall hello.c -o helloUnixLib
*info helloUnixLib
helloUnixLib WR/R    ELF       15:57:21 25-Oct-2016 1094 kbytes
*elf2aif helloUnixLib
*info helloUnixLib
helloUnixLib WR/     Absolute  15:58:37 25-Oct-2016  154 kbytes
*
Though yes it does solve the ELF problem.

Same program (using my own asm puts() function) written in assembly is 164 bytes, done correctly as it would be in C for calling convention. Thus the 3KB of the SharedCLib version is big, the 154 KB of the UnixLib AIF is huge and the 1MB + 74KB of the UnixLib ELF is giant.
I can see the use for porting programs from Unix like systems, though as for programs written for RISC OS using the Posix layer does not make since, at least not to me.
Much bigger API, and code portable under Linux :)
Yes UnixLib with its Posixish API is useful if porting from Unix Like OS's (such as Linux), at least till the ported software can be more propperly ported to RISC OS.
RPi = The best ARM based RISC OS computer around
More than 95% of posts made from RISC OS on RPi 1B/1B+ computers. Most of the rest from RISC OS on RPi 2B/3B/3B+ computers

dfeugey
Posts: 119
Joined: Mon Nov 03, 2014 2:38 pm
Location: France
Contact: Website

Re: RISC OS C Development Tutorial Series

Wed Oct 26, 2016 5:08 am

and the 1MB + 74KB of the UnixLib ELF is giant.
SharedCLibrary also has a size, you know, even if it's inside ROM.
1/ Put the dynamic version of UnixLib on you disc
2/ Loose a 'huge' 1 MB (sic.)
3/ Save MB of space for all the ELF software that'll use it.

Not a big deal anyway. RISC OS can manage several hundred of megabytes of RAM and gigabytes of disc.
Of course, you're free to save some of it... and to loose functionalities too.

Back to topic, the fact is that GCC is by default ELF+UnixLib. So the tutorial takes the simpler and best way.
And then goes to more specific things, as OSLib.
RISC OS FR - All RISC OS, in french (but not only)
http://www.riscos.fr/

User avatar
DavidS
Posts: 4334
Joined: Thu Dec 15, 2011 6:39 am
Location: USA
Contact: Website

Re: RISC OS C Development Tutorial Series

Wed Oct 26, 2016 5:58 am

David:
Yes the shared nature is what is supposed to be. Though if you save 1MB per prog file and waste tens of KB for each ELF times hundreds of ELF's you have lost (multiple MB used in wasted space, I estimate about 50MB in wasted space from ELF's on my RISC OS system). SCL not so much lost, it is in the SharedCLibrary Module and not linked in.

Back on topic:
This is a good tutorial series. Regardless of method of compile it is providing good information for those new to programming for RISC OS.

It should be watched by those new to RISC OS. Do not forget to look up how to download YouTube Videos on RISC OS, and use ffplay to watch them.
RPi = The best ARM based RISC OS computer around
More than 95% of posts made from RISC OS on RPi 1B/1B+ computers. Most of the rest from RISC OS on RPi 2B/3B/3B+ computers

yobson
Posts: 20
Joined: Wed Sep 14, 2016 6:31 pm
Location: Leeds
Contact: Website

Re: RISC OS C Development Tutorial Series

Fri Oct 28, 2016 9:32 pm

I've been trying to make the next few but they are way too long. Instead, would it be a better idea to put the code on github and go through and explain it all in each video?

Cause it's windows next without templates and typing that out is a long one. I'd much rather talk about technique such as separating code into smaller files etc.

Thanks

User avatar
DavidS
Posts: 4334
Joined: Thu Dec 15, 2011 6:39 am
Location: USA
Contact: Website

Re: RISC OS C Development Tutorial Series

Sat Oct 29, 2016 2:39 am

yobson wrote:I've been trying to make the next few but they are way too long. Instead, would it be a better idea to put the code on github and go through and explain it all in each video?

Cause it's windows next without templates and typing that out is a long one. I'd much rather talk about technique such as separating code into smaller files etc.

Thanks
As long as your code is well commented I would say that would be a very good way around it.

Though maybe not github, because NetSurf can not download an entire repo (with the zip option of github), do to not enough java script support. And unfortunately not everyone knows how to use SVN on RISC OS to clone a github repo (it took me an hour to learn when I got my github repo).

perhaps get a sub-domain on riscos.fr. Talk to DFeugey about that one.
RPi = The best ARM based RISC OS computer around
More than 95% of posts made from RISC OS on RPi 1B/1B+ computers. Most of the rest from RISC OS on RPi 2B/3B/3B+ computers

User avatar
DavidS
Posts: 4334
Joined: Thu Dec 15, 2011 6:39 am
Location: USA
Contact: Website

Re: RISC OS C Development Tutorial Series

Sat Oct 29, 2016 2:42 am

Also if I may suggest:

If you could upload a copy of your videos as normal files somewhere so that RISC OS users may more easily download them for viewing it would likely help alot. As it is I have to reboot into Puppy Linux to download your videos from youtube, and I strongly prefer to stay in RISC OS.

Perhaps ZIP the movies before uploading them to some site, as to save a little size for the downloads.
RPi = The best ARM based RISC OS computer around
More than 95% of posts made from RISC OS on RPi 1B/1B+ computers. Most of the rest from RISC OS on RPi 2B/3B/3B+ computers

User avatar
DavidS
Posts: 4334
Joined: Thu Dec 15, 2011 6:39 am
Location: USA
Contact: Website

Re: RISC OS C Development Tutorial Series

Sat Oct 29, 2016 5:19 am

One ne more thing that may be helpful:

Instead of showing the use of the Task Manager window to set the wimpslot for a task window to compile in, why not show an Obey file contaning a TaskWindow command, to open a task window with the correct amount of ram allocated (and not changing next)?

Something like:

Code: Select all

dir <Obey$Dir>
TaskWindow "echo Command window for compiling in directory <Obey$Dir>" -wimpslot 65535K -name compile
This put into the working directory sets the current directory, and opens a task window with 64MB of RAM allocated, I name it shell. Obviously save it as type Obey, and copy it to the working directory of what ever you are compiling.
RPi = The best ARM based RISC OS computer around
More than 95% of posts made from RISC OS on RPi 1B/1B+ computers. Most of the rest from RISC OS on RPi 2B/3B/3B+ computers

User avatar
DavidS
Posts: 4334
Joined: Thu Dec 15, 2011 6:39 am
Location: USA
Contact: Website

Re: RISC OS C Development Tutorial Series

Sun Oct 30, 2016 12:50 am

Any update on the tutorial series?
RPi = The best ARM based RISC OS computer around
More than 95% of posts made from RISC OS on RPi 1B/1B+ computers. Most of the rest from RISC OS on RPi 2B/3B/3B+ computers

yobson
Posts: 20
Joined: Wed Sep 14, 2016 6:31 pm
Location: Leeds
Contact: Website

Re: RISC OS C Development Tutorial Series

Sun Oct 30, 2016 5:29 pm

DavidS wrote:One ne more thing that may be helpful:

Instead of showing the use of the Task Manager window to set the wimpslot for a task window to compile in, why not show an Obey file contaning a TaskWindow command, to open a task window with the correct amount of ram allocated (and not changing next)?

Something like:

Code: Select all

dir <Obey$Dir>
TaskWindow "echo Command window for compiling in directory <Obey$Dir>" -wimpslot 65535K -name compile
This put into the working directory sets the current directory, and opens a task window with 64MB of RAM allocated, I name it shell. Obviously save it as type Obey, and copy it to the working directory of what ever you are compiling.
Just made next two videos. I haven't gone for the git hub option yet but I have made a tutorial which goes through some more pointer stuff in C and shows the viewer how to make a shortcut on their pin board which runs the above obey script as suggested. I have also made a 7th tutorial on creating windows (without templates). Next tutorial I will go into icons. Then templates and any stuff people on here request.

I can't upload them to another site yet because I actually have to delete the files after uploading them due to size limitations on my laptop. But, having said that, when I have some free time, I'll download them and look into an upload solution.

I haven't looked into the GCC ELF vs AIF and UNIXLib vs SharedCLib yet as I have exams coming up and feel like that may take some tinkering.

Sorry for the delay BTW. Its really hard to make videos. People keep making noise and spoiling them or I make too many mistakes! But don't worry, though not regularly, they will be released one by one.

Thanks guys for all the input btw, its really helpful

James Hobson
Last edited by yobson on Sun Oct 30, 2016 7:04 pm, edited 1 time in total.

yobson
Posts: 20
Joined: Wed Sep 14, 2016 6:31 pm
Location: Leeds
Contact: Website

Re: RISC OS C Development Tutorial Series

Sun Oct 30, 2016 6:00 pm

To entertain you I thought I would share with you my current "studio" which is an old monitor, my phone and as the camera mount, two tissue packets in a drinking glass!
Attachments
Studio.jpg
My low-tech studio
Studio.jpg (52.56 KiB) Viewed 5152 times

Return to “RISCOS”