Here I post updates as I learn more about RISC OS. The newest posts are shown first.
Return to portal.I've not worked on this in some time, I have gotten absorbed by other interests and am no longer hyperfixated on this project. I would say that I kind of burned myself out on it by working on it as much as possible for 3 weeks straight!
I'm still interested in the project and may pick it up at a later time.
I will leave this blog up in the meantime.
I have accomplished some things so far, like using linked lists to represent multitudes of channels and servers without any hard limit, and a little progress on parsing information with the server and doing something useful with it. I have decided to read from the socket character by character and break on newlines, so that I can use the buffer provided by the operating system to store the whole response from the server instead of making my own. There is certainly more work to be done, like negotiating with the server about nicks already being used and dealing with CAP. I have been chipping away at it a bit day by day, so even if its slow and I don't have anything cool to show by now, progress is still being made every day.
I have some gripes about RISC OS! The window management is terrible! StrongED spawns new windows instead of tabs and it is hell on earth to deal with them all when i have a lot going on. RISC OS doesnt really provide any window management aids other than dropping a window to the bottom of the stack and iconifying to the desktop. There is no analog to what we see on modern operating systems when one presses Alt-Tab...at least not by default. I did find a program that implements alt tab switching! You can find it here under the name "Coolswitch". But, by default, it is a painful experience to have numerous windows open and navigate between them. I wish the task bar on the bottom of the screen included facilities for window management like other environments do, like KDE, Windows, and MacOS.
I have also had an issue with the DDE compiler where it reported an internal error instead of pointing to problems in my own code. I was able to figure out the problem by spending some time commenting out certain lines until it worked again. But the official tools don't seem to be very helpful for a novice like me. I may be missing something, maybe there are useful utilities included with the DDE for debugging, but what I have found so far is something that basically just spits out assembly instead of sort of thing that the GNU debugger does on linux. I would also like to use Valgrind on RISC OS to measure memory leaks. I will look more into this topic later.
Motivation is not lost! I am still very excited to get this program working and I want it to be useful to other RISC OS users. It may take me some months to get it to a sharable state but I'm cool with that.
Today has been an all-day crash course in thinking about and defining data structures and dealing with memory management. It took a lot longer than I expected but I finally have an idea of how I will be storing data in Starlight. Tasks for tomorrow include, at the very least, starting on parsing IRC server output. I have to do things like respond to messages and pings and whatnot from the server, and do things like examine a channel in the data and put the message in the right channel buffer.
I implemented something of a cirular buffer to store messages in each channel. By default the client will store an arbituary amount of messages for each channel, which i am currently defining as 2048, and when the buffer is full, the oldest message is overwritten and the newest one is recorded. This is implemented by keeping track of the last write position and writing or reading accordingly. There's no rearrangement of the items in the array, so it should be pretty fast. I generated up to 500,000 thousand message objects and stored the max amount in a fake channel to test for memory leaks (using valgrind) during message procressing, and it completed quickly and memory is in check.
Huge shoutout to all the nice people on the #programming channel on tilde.town and also to the members of the RISC OS forums who have answered my questions and gave me some *pointers about how things work.
Things were a little slow some days, admittedly a couple days I was feeling like this whole project is too much to swallow for a C beginner and I walked away for the night, but I've recognized that won't get me anywhere and intentionally spent the weekend grinding away at it and slowly learning new things between dealing with frustrations. Again, huge thanks to the people who have helped me learn things along the way.
It really is quite the project, learning a new programming language, dealing with the intricacies of an operating system I've never worked with before, writing code in an editor that I'm not familiar with, and working with systems and libraries that have questionable amounts of documentation and little to no code examples available online. But I'm dead set on getting this done and I'm happy with the progress I've made in the last couple days alone.
On to week 2!
From RISC OS (instead of Linux), I was able to make a connection to an IRC
server, register the NICK and PRIVMSG the appropriate channel, which is very
good! I had to fumble about to find the right headers to #include. There are
some problems that I need to work through...first of all, if the port is not
accessible for some reason, the code just blindly executes anyways without
throwing any errors. There may be a returned value from connect()
that I am
not reading or checking, which only just occurred to me as I typed out this
sentence, lol! I do check for a value of -1 on inet_pton()
and socket()
.
connect()
probably functions the same way.
I have been highly reliant on reviewing !Nettle source code. I think it works with sockets thoroughly enough for me to learn what I need from it. This is a great advantage of FOSS over proprietary software, as it enables beginners like me to learn how systems work =)
Here is the code (without any fixes to the connect()
call)
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "unistd.h"
#include "sys/types.h"
#include "socklib.h"
#include "inetlib.h"
#include "sys/socket.h"
#include "arpa/inet.h"
int main () {
int s = socket(AF_INET, SOCK_STREAM, 0);
if (s < 0) {
printf("No socket!\n");
exit(EXIT_FAILURE);
}
struct sockaddr_in address;
char sendbuffer[1024];
address.sin_family = AF_INET;
address.sin_port = htons(6667);
if (inet_pton(AF_INET, "192.168.1.28", &address.sin_addr) < 0) {
printf("No address!\n");
exit(EXIT_FAILURE);
}
// fixme
connect(s,(struct sockaddr*) &address, sizeof(address));
snprintf(sendbuffer, sizeof(sendbuffer), "NICK c-test\n");
send(s, sendbuffer, strlen(sendbuffer), 0);
snprintf(sendbuffer, sizeof(sendbuffer), "USER c-test 0 * :c test\n");
send(s, sendbuffer, strlen(sendbuffer), 0);
snprintf(sendbuffer, sizeof(sendbuffer), "JOIN #programming\n");
send(s, sendbuffer, strlen(sendbuffer), 0);
snprintf(sendbuffer, sizeof(sendbuffer), "PRIVMSG #programming :i hail from C!\n");
send(s, sendbuffer, strlen(sendbuffer), 0);
sleep(5);
close(s);
}
So I've deviated from Steve Fryatt's tutorials to work on some networking stuff. I had a lot of trouble at first, but thanks to wonderful folks on the tilde.town IRC channels, I managed to get a program running that was able to send data to the IRC server and post a message on a channel before parting. However, that was on Linux, not on RISC OS, so that will need to be ported.
I admit, it is a bit intimidating at the moment that I want to make a whole IRC client, but every project has to start somewhere, right? I have done this stuff on Python, my main challenge right now is figuring out how to allocate data to memory in C. Strings are confusing me, having to allocate the size of them and whatnot. Python truly spoiled me on that front. In the end, I want multiple channels, multiple server support, with thousands of messages in buffers. Much to learn!
StrongED seems to be a fine editor, but I haven't mastered it yet. I actually fumbled enough today that i overwrote an important file in my source code with another file, by misusing the drag and drop save feature before changing the file name. I like emacs, I like vim, and learning how strongED works is probably going to take about as much effort and/or time as it took to learn the others.
I'mma keep truckin' on...
Things are truckin' along. I have not yet deviated from Steve's tutorial series as far as writing code goes, but I have briefly pondered or explored a few other items related to this project. I still need to learn how to access the internet from a C application on RISC OS. I will tackle this issue before I finish Steve's tutorial series, which has no mention of using the internet, so that is an excercise for me, myself, and I.
There is the IRCv3 standard site and I can begin pondering how to implement it. I will aim for basic functionality first but need to be mindful of having to expand on that later.
I was thinking about the name of the project and also what the icon for it should look like. I have decided the name of the project going forward will be "Starlight" or "StarlightIRC".
I am not 100% about the icon though. I cracked open an image editor and quickly realized I have no idea how to draw things in GIMP. I also looked up various "free icon" websites on Google, and I found an icon that I do quite like, if I could tweak it a bit I may go for it, but for now I will consider it a placeholder. I do like the isometric look, it is surprisingly similar to the isometric folder icons used by the filer in RISC OS. It is tilted in the right direction and even appears to be about the same angle. Icons8's website allows one to color the icon, and I quite like how it looks with #CA9DD7 applied to it.
I made another web page today, dedicated to collecting links and my favorite software related to RISC OS. A lot of these links are obscure on search engines and I've discovered a lot of them by rifling through the forums. I have not started the favorite software section yet, it is of course a living document so it will be updated regularly. It is accessible from my home page as the "RISC OS Portal".
Steve Fryatt's website is absolutely fantastic. The way he explains things in his tutorial series is easy for me to understand, so I feel like I know what I'm doing as I go along, and not just blindly copy/pasting example code. I am happy to have been told about this.
The DDE tools work great. No problems loading the libraries I need. Not only does it include the C compiler but it also has a makefile system. And lots of other things I have not explored yet.
Today is the official start date of the tilde30 project jam, and my project is to build a graphical IRC client for RISC OS. Unfortunately, I have been hung up on technical problems for a while. I still have had no luck with getting GCC to locate the OSLib library files and thus, have not compiled or wrote a single line of useful code. The forum thread has recieved a lot of helpful responses but none of it ended up solving the problem.
So, I am giving up on GCC and I bought the DDE. I have just recieved the download link for the purchased software, and I will post here once I get something interesting done.
The forum thread directed me to a very useful looking tutorial series. This details how to get OSLib set up with the DDE (not GCC) so I don't think I'll be wading around in the dark over how to set that up. This, as well as the youtube tutorial series I posted the other day, should help me a lot.
Good news, I found a youtube series about programming C on RISC OS. It uses OSLib and covers WIMP. Even though the author has some things even he is stumped about, it has been the most helpful resource I have found so far. Bad news, it operates on the assumption that OSLib and UnixLib can be installed via the package manager using a third party repository. But, that repo throws a 404 when accessed. The official website of OSLib is still up (see my last post) but, I currently have no idea where to install it or get GCC to be able to #include those files in a standardized way. I could just copy all the files into my local build/dev directory but i feel like that is a hack and that theres got to be a way to install it on the system in a more "standardized" place, like libraries installed by package managers do (at least on Linux)
I made a thread on the RISC OS forums. Hopefully I can get some help with this.
I looked around the filesystem and in !GCC but i have not been able to locate where libraries are, not even the standard C library. Really, let's be honest, I have no idea what I'm doing. But I won't give up. I make a little progress every day.
I found something that appears to be an alternative to DeskLib and this may solve my confusion! Here is the link. It says it has support for both GCC and the DDE compilers.
I continued to play around with RISC OS last night, trying to use StrongED to write a hello world C program, but every time I invoked gcc, it complained about an invalid file format. I intend to get to the bottom of this today.
I would like to do my introductory C programming on RISC OS itself, if I can find documentation and answers to questions on pages that run on NetSurf. RISC OS does not have modern browsers like Firefox or Chromium, so I must use a browser which has limited to no support for modern css and javascript. I need to review documentation and ask google questions in order to proceed at this point!
I am only just beginning to understand the UI, file structure, and overall character of the system. First impressions...this is not Linux or Unix! At all! It's not like Windows or DOS either. Or BeOS. Or really anything I have used before. It throws out every paradigm I've ever been familiar with, including keyboard shortcuts, things one does with the mouse buttons, and vocabulary. It does have a package manager, but I do not yet know how the packages work and if it can be extended with other sources.
RISC OS was, in its heyday, a completely proprietary system. In recent years, it was re-licensed under the Apache 2.0 license. Many programs for this newly open sourced system that are available via the official distribution channels do not have open source code and are available for a fee, some of which are quite expensive. Unlike Linux, a lot of the ecosystem is not free software.
Now, my confusion! There are...multiple sources online that one can find copies of the RISC OS system library for C. And there is a thing called the Desktop Development Environment, which includes a C compiler among many other things, but not that library. I would imagine that this DDE is the ideal way to go about writing applications for the platform in C. But there is also a port of the GNU C Compiler, available in the official package manager! The official DDE costs some money, and GCC does not. At first glance, GCC seems like the obvious choice, but read what this page about the aforementioned system library has to say! To quote the most confusing part:
A newer version is available at http://www.riscos.info/index.php/DeskLib; however that version is going off in its own direction and future releases will be ELF only (meaning that it will only work with GCC). Indeed, a lot of things have changed to support GCC's not-quite-RISC-OS way of working, such as naming header files with a '/h' suffix instead of them being in an 'h' subdirectory, plus a future library in an ELF file - pretty much guarantees that the "RISC OS library" will not work with the official toolchain.
This raises some questions for me!
I may have to join some sort of IRC channel or other online community for RISC OS if I'm going to continue to be serious about utilizing it. Also, for what it is worth, it is difficult to find easy answers and tutorials about RISC OS. It's nowhere near as popular as the other operating systems I have used, which have lots of asked and answered questions on things like StackExchange and Reddit.
Now, I still need to learn how to write any decent C code before I can become proficient at creating proper GUI applications for this system. I have a lot of experience with python and a couple lisps, but I have never dealt with memory management and pointers. I have dedicated most of my free time today on getting this web blog running, but tomorrow I'm going to be sitting down and continuing to figure out my current and first C challenge, which is creating a simple todo-list application which stores and reads data in CSV format. I will not be making a GUI for that, but rather something simple that works over the command line.
My tilde30.2 project for September is to work on a graphical IRC client for the RISC OS desktop. There's a million of them on Linux but certainly not RISC OS. So I hope to create something that can be useful for the broader RISC OS using community, which means I have to get this cross-hardware compatibility stuff figured out.
To infinity, and beyond!