Join us on Discord!
You can help CodeWalrus stay online by donating here.

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:
  • Calculators owned: TI-86 (now broken), TI SR-56, TI-Nspire CX CAS, TI-84+ SE, TI-84+ SE, TI-85, TI-73 Explorer VS, ViewScreen, TI-84+ CSE, TI-83+ SE

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

#3
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!

Dream of 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.
  • Calculators owned: TI-82 Advanced Edition Python TI-84+ TI-84+CSE TI-84+CE TI-84+CEP TI-86 TI-89T cfx-9940GT fx-7400G+ fx 1.0+ fx-9750G+ fx-9860G fx-CG10 HP 49g+ HP 39g+ HP 39gs (bricked) HP 39gII HP Prime G1 HP Prime G2 Sharp EL-9600C
  • Consoles, mobile devices and vintage computers owned: Huawei P30 Lite, Moto G 5G, Nintendo 64 (broken), Playstation, Wii U

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.

Dream of 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.
  • Calculators owned: TI-82 Advanced Edition Python TI-84+ TI-84+CSE TI-84+CE TI-84+CEP TI-86 TI-89T cfx-9940GT fx-7400G+ fx 1.0+ fx-9750G+ fx-9860G fx-CG10 HP 49g+ HP 39g+ HP 39gs (bricked) HP 39gII HP Prime G1 HP Prime G2 Sharp EL-9600C
  • Consoles, mobile devices and vintage computers owned: Huawei P30 Lite, Moto G 5G, Nintendo 64 (broken), Playstation, Wii U

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

Dream of Omnimaga

Oh, nifty. It would be cool to see more math applications for KOS in the future, especially now that C is supported. :)
  • Calculators owned: TI-82 Advanced Edition Python TI-84+ TI-84+CSE TI-84+CE TI-84+CEP TI-86 TI-89T cfx-9940GT fx-7400G+ fx 1.0+ fx-9750G+ fx-9860G fx-CG10 HP 49g+ HP 39g+ HP 39gs (bricked) HP 39gII HP Prime G1 HP Prime G2 Sharp EL-9600C
  • Consoles, mobile devices and vintage computers owned: Huawei P30 Lite, Moto G 5G, Nintendo 64 (broken), Playstation, Wii U

Max Leiter

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

https://sr.ht/HzJX.png

Dream of 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.
  • Calculators owned: TI-82 Advanced Edition Python TI-84+ TI-84+CSE TI-84+CE TI-84+CEP TI-86 TI-89T cfx-9940GT fx-7400G+ fx 1.0+ fx-9750G+ fx-9860G fx-CG10 HP 49g+ HP 39g+ HP 39gs (bricked) HP 39gII HP Prime G1 HP Prime G2 Sharp EL-9600C
  • Consoles, mobile devices and vintage computers owned: Huawei P30 Lite, Moto G 5G, Nintendo 64 (broken), Playstation, Wii U

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/

Dream of 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
  • Calculators owned: TI-82 Advanced Edition Python TI-84+ TI-84+CSE TI-84+CE TI-84+CEP TI-86 TI-89T cfx-9940GT fx-7400G+ fx 1.0+ fx-9750G+ fx-9860G fx-CG10 HP 49g+ HP 39g+ HP 39gs (bricked) HP 39gII HP Prime G1 HP Prime G2 Sharp EL-9600C
  • Consoles, mobile devices and vintage computers owned: Huawei P30 Lite, Moto G 5G, Nintendo 64 (broken), Playstation, Wii U

Powered by EzPortal