Learning C on RISC-OS
Pages: 1 2
Rick Murray (539) 13840 posts |
I guess it’s the problem when we are all used to the grotty parts of task management because that’s “just how BASIC rolls”, and we all think we can all write a better library… ;-) Wasn’t there one called “EventLib” as well? A recent program I wrote used custom SWI functions in assembler. It was an exercise in writing a program with an extremely minimal library, able to build with no dependencies (other than CLib). For sure, any program of any real size, you’d be crazy not to use a library – be it DeskLib or OSLib or something else. Certainly, the big oft used libraries will be solid and reliable – not something you can always guarantee if you write your own (look at Heartbleed for a good example of the potential of one small oversight that nobody picked up before code deployment). Don’t ever get stuck in the NIH Syndrome. There are some nice libraries around. But better than all that, programmers on the whole tend to like doing “fun stuff” and not the boring repetitive crap. So a library could offer a call that does all of the mundane task setup stuff. One call and it’s on to the good bits, right? ;-) |
Tomas (2352) 8 posts |
I was very happy to find this thread yesterday: https://www.riscosopen.org/forum/forums/11/topics/1835 … and most importantly, a working example of a “WIMP Hello World program” using OSLib mentioned in there, to be found here: http://www.sfryatt.eclipse.co.uk/temp/wimp.html Thank you, thank you, especially Steve in this case. I was pulling my hair to figure out how to use the the OSLib library for things like WIMP programming. To be honest the examples supplied with OSLib are pretty useless. Slowly, very slowly I’m starting to see how things (can) work in C !!! So, to resume, I think I’ll made a reasonably good choice with my gcc + OSLib setup and I’m going to stick with that until I have enough experience to write my own library (wink : Rick!)
I definately recognise what you said, I’ve been doing that in BASIC as well… Funny enough I see you experienced guys indeed all making your own: Rick adapted DeskLib, Steve wrote his own… I think I’ll use just OSLib without OSLib support for the moment, I like the idea of still having a bit of a feel what’s going on. Too many layers, like maybe another event lib might confuse me even more. |
Tomas (2352) 8 posts |
Around this time of year some people are looking for egss, I’m trying to find bugs… After finding Steve Fryatt’s Wimp Example program, using OSLib, I tried making an adaption. Loading templates from a template file. I adapted the “register_task” function as below:
I started with a template made with TemplEd (from Dick Alstein). In this situation the program worked except that icon number 1 was missing in the window the program opened! Even when renumbering the icons, still, very consequently nr.1 was missing. Not either the writeable icon, or the button, but no, always nr.1. This phenomena disappeared when I made the template with WinEd instead of TemplEd. But when putting more icons (like 7 or 8) in the template the whole program crashed, freezing the mouse and the whole system. No, error msg, post-mortem dump, or whatever. While debugging I quit the program before opening the window or entering the poll loop. The error is definately in the wimp_open_template function, or more likely in my implementation of it ;-) For example: The template name need to be word-aligned (max. 12 bytes). How do I know/make sure this is right? Thanks for your help. Tomas The system: GCC 4.1.2 Release 2 (released 1 October 2012) WinEd and / or TemplEd |
Steve Fryatt (216) 2105 posts |
You’re not allocating the window block memory correctly.
is fine if your window has no icons (as my original example didn’t), because the structure in OSLib contains no allocated space for the icon definitions that follow the main window structure. You need to allocate that space yourself before trying to use it (because OSLib has no idea how many icons the window might have). However, when you do have variable size definitions and indirected data, you’re far better off reading the sizes via the Wimp’s API and then allocating the necessary space dynamically via For example, SFLib’s Windows module contains the following function:
You could use this (or similar) by changing your code to
and then
Note that this is untested — the library works, but the changes to your code are off the top of my head. ETA: You should initialise ETA2: Once you’ve called
|
Tomas (2352) 8 posts |
Thanks Steve, that helps! I got it working using the function ‘windows_load_template’ you supplied. Since that is part of your SFLib, I though, as a next step, why not give it a go and install your SFLib next to OSLib on my VirtRPC. I saw it had nice functionality, like sfprint-ing into icons… just what I need ;-) Of course I needed to adapt to the RO name convention, having a ‘h’ directory and headers without .h extension… You don’t have a version for SW FP? Or am I mistaken that I can only use SW FP on VRPC / RaspberryPi? Thanks again. |
Steve Fryatt (216) 2105 posts |
Apologies for the slow reply: the lead-up to a Wakefield Show probably isn’t the best time to ask questions of RISC OS developers (or, indeed, show organisers who also try to develop stuff as a sideline). :-)
I don’t at present, but it should be trivial to produce. I’ll see what I can do this week.
I think so: the hard-float version of SFLib is the one that I use for all my software, and as far as I know that runs fine on a Pi. |
David Gee (1833) 268 posts |
Yes, the Pi definitely has hardware floating point (VFP) support; the standard Raspbian Linux distro makes use of this (apparently it makes a big difference to performance over software FP). If you are using !GCC there are command line options that can select either soft or hard FP. In particular, using the Shared C Library via -mlibsclgives you hard float; apparently only soft float is available with Unixlib. There have been some recent articles in Archive magazine dealing with this. |
Steve Fryatt (216) 2105 posts |
That sounds about right for SCL vs Unixlib: I use the SCL for my software. Note that “hard float” doesn’t mean you actually need floating point hardware present. The Floating Point Emulator will step in if there’s no real floating point hardware in the machine (which is true of most RISC OS systems over the years). |
Theo Markettos (89) 919 posts |
(Better late than never) Note that ‘hard float’ typically means compiling for the old FPA instruction set – there were only two relevant ARM processors that supported this and the last one of those was released in 1996. Even on a Cortex A9 with VFP3, NEON, etc etc FPA will still get emulated. To get true hardware FP you’d need to compile with VFP2 (ARMv6 onwards) or VFP3 (ARMv7 onwards, with a few exceptions). I don’t think anyone has written an emulator so VFP instructions will work on old machines. |
Steve Drain (222) 1620 posts |
This will not be directly relevant to compiling C, but back at the start of the year I was exploring VFP for my own software, which is reflected in this topic: https://www.riscosopen.org/forum/forums/3/topics/2172There are limitations to what VFP can do to replace FPA directly, so I am not sure what a compiler can do or what is done on the Linux side. The result of my efforts is a module, provisionally called Float, which replicates as far as possible the FPA using VFP. Although it has SWIs, these have overheads that cancel most of the advantages of hardware FP, so the routines are also available directly. In that case it is quite satisfyingly fast. To enable software to run even when VFP is not available it reverts to FPA, with only a tiny overhead over using that directly. I have not released this, but if anyone is interested I could send a copy. |
Pages: 1 2