Alternatively, join us on Discord.

C support in KOS

Started by Max Leiter, December 27, 2015, 11:53:26 pm

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Max Leiter

I had a better topic but accidentally reloaded the page and lost it  :(

Recently, I've been working on C bindings/the C library (libc) for KnightOS. Once I've finished the C bindings for corelib I plan to create some bindings for fx3dlib and configlib (both by @matrefeytontias).

I'm really hoping this will interest more people in KOS, mostly because a lot more people are familiar with C than z80 asm.

The compiler used is KCC, a fork of SDCC. There's a C library, libc, which has some POSIX-compliant functions where there's overlap between KOS and POSIX systems. There's also bindings for corelib, a userspace library, so hopefully some KOS C programs will start to show up.

To show off libc, here's a demo that SirCmpwn made: pong


And here's a demo I made demonstrating corelib: corelibcdemo (I'm very original when it comes to naming things)



So I guess if anyones curious about C support/has questions/errors/whatever, you can post here, ask me on IRC, or ask in #knightos on freenode


Ivoah

Looks nice! It's been great seeing all of the pull requests and stuff from you on IRC and in my email :) Keep up the good work :thumbsup:

ben_g

I looked at some source files, and:
Quote from: source fragment
double tan(double x) {
    return sin(x) / cos(x);
}

Does that mean we can use floating points on KOS in C? O.O

Max Leiter

December 29, 2015, 05:28:57 pm #3 Last Edit: December 29, 2015, 05:57:00 pm by Max Leiter
Quote from: ben_g on December 29, 2015, 12:30:42 pm
I looked at some source files, and:
Quote from: source fragment
double tan(double x) {
    return sin(x) / cos(x);
}

Does that mean we can use floating points on KOS in C? O.O

Well, kind of. I don't really understand it, but libc doesn't provide BCD (binary-coded decimal) floats. This means that 0.1 + 0.2 = 0.300000000001, but that probably won't affect you too badly.


EDIT:
Just PR'd my filestream bindings into libc, so now you can (kind of!) modify/create/etc files!

DJ Omnimaga

That is awesome. Is it useable yet? Because that would definitively be news material. A lot of people like C and the fact that KnightOS has an emulator (and I assume that other emus can be used with a KOS ROM) will probably help.

Max Leiter

Quote from: DJ Omnimaga on December 30, 2015, 06:24:43 am
That is awesome. Is it useable yet? Because that would definitively be news material. A lot of people like C and the fact that KnightOS has an emulator (and I assume that other emus can be used with a KOS ROM) will probably help.


Yeah, its definitely usable (see: demos), but there's a few small things that get annoying (C89, mainly). z80e, the emulator, can load TI-OS (with a few bugs) afaik, and I've been using it for KOS for the past few months. The one big downside imo is no keyboard/skin, but that's not really a huge deal.

DJ Omnimaga

Can you enlighten me about what C89 is? Because Google returns mostly results about ANSI C and irrelevant stuff. As for the lack of a keyboard/skin, it's ok for now, as long as the keyboard layout is identical to WabbitEmu/PindurTI, since those emulators have been used for almost a decade.

Lionel Debroux

C89 is the 1989 version of ANSI/ISO C, indeed.
Member of the TI-Chess Team.
Co-maintainer of GCC4TI (GCC4TI online documentation), TIEmu and TILP.
Co-admin of TI-Planet.

SirCmpwn

FWIW you can ask kcc to use C99 mode, but it's not entirely implemented.

Max Leiter

Having seen the many issues @ben_g has experienced using libc (none his fault, they're just things that seem like nobrainers to me because I wrote most of them), I've gone through and commented *most* C functions in libc and corelib.

Here's the corelib header file, fully documented :) : https://github.com/MaxLeiter/corelib/blob/master/corelib.h

I've decided to finally write up the KnightOS C tutorials that will be on the website. Here's a screenshot of the first one (haven't pushed it yet, plan to write the others first).
https://sr.ht/VvMS.png

Also, @ben_g threw together a pretty nice (WIP) calculator program in C

DJ Omnimaga

Oh, nifty. It would be cool to see more math applications for KOS in the future, especially now that C is supported. :)

Max Leiter

Finished up the C tutorial for using corelib (userspace library), drawing the corelib window, and userinput :)

https://sr.ht/HzJX.png

DJ Omnimaga

Darn, that's an elaborate tutorial. Nice. And I'm glad it will be on KOS website or established site/forum, rather than a small personal site, so it will remain online as long as KnightOS domain name is up.

Max Leiter

Quote from: DJ Omnimaga on January 26, 2016, 07:46:39 am
Darn, that's an elaborate tutorial. Nice. And I'm glad it will be on KOS website or established site/forum, rather than a small personal site, so it will remain online as long as KnightOS domain name is up.


Yep! Once I bother making a PR/finishing the tutorials, theyll be available here: http://www.knightos.org/documentation/

DJ Omnimaga

Thanks for the link. That reminds me, since CW no longer has a tutorials-specific board, we definitively need to make a list somewhere with links to external tutorials. It would be easier to find stuff. But that's offf-topic :P

Powered by EzPortal