CodeWalrus

Featured Member Projects => Completed and Inactive Projects => [Inactive] KnightOS (TI-73/83+/84+/CSE) => Topic started by: Max Leiter on December 27, 2015, 11:53:26 pm

Title: C support in KOS
Post by: Max Leiter on December 27, 2015, 11:53:26 pm
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 (http://www.github.com/knightos/libc)) for KnightOS. Once I've finished the C bindings for corelib (https://github.com/MaxLeiter/corelib/blob/master/bindings.c) 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 (http://www.github.com/knightos/kcc), a fork of SDCC. There's a C library, libc (http://github.com/knightos/libc), which has some POSIX-compliant functions where there's overlap between KOS and POSIX systems. There's also bindings for corelib (https://github.com/KnightOS/corelib/blob/master/bindings.c), 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 (https://github.com/SirCmpwn/pong)
(https://camo.githubusercontent.com/2813aa9a69022a90cdd9020499da620621b0f93d/687474703a2f2f612e706f6d662e73652f6a6e67647a612e676966)

And here's a demo I made demonstrating corelib: corelibcdemo (https://github.com/maxleiter/corelibcdemo) (I'm very original when it comes to naming things)
(https://sr.ht/D-I2.gif)


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

Title: Re: C support in KOS
Post by: Ivoah on December 28, 2015, 03:41:16 am
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:
Title: Re: C support in KOS
Post by: 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
Title: Re: C support in KOS
Post by: Max Leiter on December 29, 2015, 05:28:57 pm
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!
Title: Re: C support in KOS
Post by: 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.
Title: Re: C support in KOS
Post by: Max Leiter on December 30, 2015, 06:43:49 am
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 (https://www.github.com/knightos/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.
Title: Re: C support in KOS
Post by: DJ Omnimaga on December 30, 2015, 06:55:22 am
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.
Title: Re: C support in KOS
Post by: Lionel Debroux on December 30, 2015, 07:14:27 am
C89 is the 1989 version of ANSI/ISO C, indeed.
Title: Re: C support in KOS
Post by: SirCmpwn on December 30, 2015, 03:30:16 pm
FWIW you can ask kcc to use C99 mode, but it's not entirely implemented.
Title: Re: C support in KOS
Post by: Max Leiter on December 31, 2015, 03:52:08 am
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
(https://codewalr.us/proxy.php?request=http%3A%2F%2Fimg.codewalr.us%2Fcalc.gif&hash=7a0c423410f58d899716cdfa37e2a103)
Title: Re: C support in KOS
Post by: DJ Omnimaga on December 31, 2015, 09:04:09 am
Oh, nifty. It would be cool to see more math applications for KOS in the future, especially now that C is supported. :)
Title: Re: C support in KOS
Post by: Max Leiter on January 01, 2016, 12:01:04 am
Finished up the C tutorial for using corelib (userspace library), drawing the corelib window, and userinput :)

https://sr.ht/HzJX.png
Title: Re: C support in KOS
Post by: 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.
Title: Re: C support in KOS
Post by: Max Leiter on January 26, 2016, 07:51:26 am
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/
Title: Re: C support in KOS
Post by: DJ Omnimaga on January 26, 2016, 07:55:01 am
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
Title: Re: C support in KOS
Post by: Max Leiter on February 05, 2016, 04:40:29 am
The two finished C tutorials are now live :)
http://www.knightos.org/documentation/tutorials/getting-started-c/

Hopefully people decide to make some C programs, because the KOS program ecosystem is severely lacking.
Title: Re: C support in KOS
Post by: DJ Omnimaga on February 05, 2016, 06:11:38 am
Good to see tutorials ready now. :D As for programs, it might take a while before more are made, though, because if even the CE doesn't get many programs, then imagine for a third-party OS. :P But yeah it would definitively be nice to see more games and perhaps math tools for KOS.
Title: Re: C support in KOS
Post by: Max Leiter on February 12, 2016, 04:11:03 am
(https://sr.ht/rAUL.gif)

Began some work on color C bindings (http://www.knightos.org/documentation/reference/color.html) tonight, hopefully I'll be able to create a copy of the gfxdemo in C sometime soonish, and I'm on break from school this week so should have plenty of time to.

Here's a higher quality mp4 version of the GIF: https://sr.ht/0IX1.mp4
Title: Re: C support in KOS
Post by: Max Leiter on February 18, 2016, 04:17:15 pm
Update: The color C bindings have now been merged (https://github.com/KnightOS/libc/pull/13)
Title: Re: C support in KOS
Post by: Max Leiter on March 02, 2016, 03:34:16 am
Went ahead and added wrappers for the (action)Pixel kernel functions (invert_pixel, set_pixel, and reset_pixel).
https://github.com/KnightOS/libc/commit/d50ffc682fdf2f44bdffb45f64270f16dfbfdfd9
Title: Re: C support in KOS
Post by: DJ Omnimaga on March 02, 2016, 03:35:37 am
Thanks for the update. I'M glad to see more progress on this Max Leiter. I hope that one day we will be able to easily port C games between multiple calculators and KnightOS (even if it means changing the graphics in the monochrome version).
Title: Re: C support in KOS
Post by: Max Leiter on March 02, 2016, 03:37:31 am
Quote from: DJ Omnimaga on March 02, 2016, 03:35:37 am
Thanks for the update. I'M glad to see more progress on this Max Leiter. I hope that one day we will be able to easily port C games between multiple calculators and KnightOS (even if it means changing the graphics in the monochrome version).

I'm currently experimenting porting a Prizm game (Game of Life by @merthsoft) to KnightOS, it's pretty easy so far. The hardest part is making a game made for color calculators look nice on a monochrome screen, but besides that most of the functions have direct "translations." I don't plan to release the game, but will post a finished version here if I ever finish it.

EDIT: Added all the draw_rect() functions/variations, so now the KOS Display section is implemented! (ie www.knightos.org/documentation/reference/display.html)
Title: Re: C support in KOS
Post by: DJ Omnimaga on March 22, 2016, 06:12:10 am
Nice that cross calculator brand porting isn't too hard. Monochrome graphics can usually be adapted to just be small rectangles or squares if they can't be converted easily anyway. Even a Pac-Man game would still be enjoyable with 3x3 blocks if that meant the entire board fit on screen without being flipped sideways.

Did you work more on the game, by the way? I am curious if you could post a screenshot.
Title: Re: C support in KOS
Post by: Ivoah on March 22, 2016, 06:14:31 am
Quote from: DJ Omnimaga on March 22, 2016, 06:12:10 am
Nice that cross calculator brand porting isn't too hard. Monochrome graphics can usually be adapted to just be small rectangles or squares if they can't be converted easily anyway. Even a Pac-Man game would still be enjoyable with 3x3 blocks if that meant the entire board fit on screen without being flipped sideways.

Porting stuff from TI-OS to KOS is super easy, I managed to port the rubiks cube program, and I still don't even know exactly how it works :)
Title: Re: C support in KOS
Post by: Max Leiter on March 22, 2016, 06:20:00 am
Quote from: DJ Omnimaga on March 22, 2016, 06:12:10 am
Nice that cross calculator brand porting isn't too hard. Monochrome graphics can usually be adapted to just be small rectangles or squares if they can't be converted easily anyway. Even a Pac-Man game would still be enjoyable with 3x3 blocks if that meant the entire board fit on screen without being flipped sideways.

Did you work more on the game, by the way? I am curious if you could post a screenshot.


too much relied on colors for it to be ported easily (I couldn't tell if it was working correctly with just black/white, I didnt put much time in it :( )
Title: Re: C support in KOS
Post by: DJ Omnimaga on March 23, 2016, 03:06:37 am
Quote from: Ivoah on March 22, 2016, 06:14:31 am
Quote from: DJ Omnimaga on March 22, 2016, 06:12:10 am
Nice that cross calculator brand porting isn't too hard. Monochrome graphics can usually be adapted to just be small rectangles or squares if they can't be converted easily anyway. Even a Pac-Man game would still be enjoyable with 3x3 blocks if that meant the entire board fit on screen without being flipped sideways.

Porting stuff from TI-OS to KOS is super easy, I managed to port the rubiks cube program, and I still don't even know exactly how it works :)
Lol nice. Actually my main difficulty concern was converting a 320x240 game to 96x64, hence my suggestion. But nice to hear. Maybe at one point someone could port various calc games to KOS and make some sort of CW arcade using the emulator. Porting games would probably require the permission of certain authors, though.