For some reason I decided to rewrite the "wave" program that I wrote in Basic-11, but using DECUS C. I thought that it would be easy, but I didn't count on there not being a math.h. This means that I had to work out how to calculate a sine and cosine for myself. Well, actually I went off to google to see if somebody had already done the hard work for me. Indeed they had, I found it here: www.bsdlover.cn/study/unixtree/V7/usr/src/libm/sin.c.html
That code was already in K&R syntax, but it used modf(), I think that I went off and found some source code for that somewhere else... Anyway, when I had it working, I decided that I might want to use these bits of maths code somewhere else - so I extracted it out into my own library and made "maths.h". So I can now use sin/cos wherever I want.
Anyway, since I went to all that trouble, I thought that I had better post the results. You need to compile maths.c into maths.obj, like this:
RUN C:AS DK:MATHS.S/D
Then, you can #include "maths.h" and link to the maths.obj we created above, like this example:
I expect I'll add more to my maths library as I go, but this is a start.
My blog has been quiet recently. Mainly because I have been busy learning OS development. At the moment I'm calling the result of my efforts by the name "ShedOS" in honour of men who build things in sheds. I count myself in that category - even if my hobby is more likely to be practiced in Costa Coffee (drinking a flat white) than an actual shed. Maybe I need to build a better shed, or maybe sheds should serve better coffee.
As I've mentioned before on this blog, I've been following Bran's Kernel Development tutorial, so my OS is based on that. But I have been busy customising it and adding new things. Currently, ShedOS has these features:
- 32 bit x86 operating system
- preemptive multitasking
- floppy disk driver
- limited support for FAT12 filesystems (read-only)
- text only video driver (16 colours)
- exports a few system calls, like 'print', 'plot' and 'exit'
- can load and run user programs from disk
- oops, still no keyboard driver
I have just started to implement some system calls, so that the kernel can expose an API to user programs, it seems to work. If I seem surprised; it's because I am. I have gotten to the point where the kernel boots, then loads a user program from a FAT12 disk. The user program runs, making use of the kernel's API to print to the screen. Then the program exits and returns full control to the kernel again. During that whole process the system continues to multitask. Not a bad start I suppose.
At some point I'll bring over some of my favourite features from the PDP-11 world, like the ability to drop machine-code instructions straight into memory. Running some code by typing the instructions in manually must be like a "rite of passage", and it's something that you can't do from windows. Surely if you can do that using an OS that you've built yourself then you're the man.
Right, I really must get round to posting my floppy driver source code, just in case anybody else out there finds it interesting... Sadly, I don't think there will be many other people developing drivers for floppy disks these days, but I'll post my code anyway.
So when I discussed checking out Bran's Kernel Development Tutorial apparently I wasn't kidding. I have now compiled my own kernel in C (and it actually works). As kernels go I suspect that it is unique, because I implemented a floppy disk driver before a keyboard driver :-) But hey, this is my OS so I can do whatever I like... Here it is in action:
So far, all it does is boot up, then find the first floppy disk and do a hex dump of the disk contents to the screen. But there is a *lot* of coding needed to make that work! At kernel level you have responsibility for stuff like turning the disk motor on and off and moving the drive heads to the right track. Plus the command set for accessing a floppy drive is pretty *nasty*. Also, I have had to remind myself all about tracks, heads and sectors.
The information and examples shown on the OSDEV tutorials have been essential reading. Without all their examples I would not have gotten this to work. I have tried not to just copy & paste somebody else's code, I have tried to write this in my own style - but credit has to go to all those people involved in the OSDEV tutorials.
My code is only designed to work with 3.5" drives (although it has not been near a real disk yet) I have only used it in VirtualBox. It does not seem to work in Bochs for some reason (I don't know why yet).
So anyway... this has been a challenge, and I'm very pleased that I've gotten something that actually works. I guess the next step is to begin writing FAT12 support, so I can get some proper file access.