* WalrusIRC

You need to have 5 posts and not be part of restricted usergroups in order to use the WalrusIRC embedded shoutbox. However, you can also access our IRC channel called #CodeWalrus via EFnet.

Author Topic: C support in KOS  (Read 5392 times)

0 Members and 1 Guest are viewing this topic.

Offline Max Leiter

  • Full User
  • Join Date: Oct 2015
  • Location: California
  • Posts: 87
  • Post Rating Ratio: +0/-0
C support in KOS
« 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) 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




Offline Ivoah

  • Super User
  • Join Date: Dec 2014
  • Location:
  • Posts: 523
  • Post Rating Ratio: +6/-0
    • @NoahRosamilia
    • Ivoah
    • @UCmgDyh_AeaHALohvR7PKXIw
    • /u/Ivoah
    • Ivoah
    • 114/11421
    • Codinghobbit
  • Gender: Male
  • WalriiPoints: 100
Re: C support in KOS
« Reply #1 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:
  • 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

Offline ben_g

  • Full User
  • Safe-haven access
  • Join Date: Dec 2014
  • Location:
  • Posts: 167
  • Post Rating Ratio: +12/-0
Re: C support in KOS
« Reply #2 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

Offline Max Leiter

  • Full User
  • Join Date: Oct 2015
  • Location: California
  • Posts: 87
  • Post Rating Ratio: +0/-0
Re: C support in KOS
« Reply #3 on: December 29, 2015, 05:28:57 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!
« Last Edit: December 29, 2015, 05:57:00 pm by Max Leiter »

Offline xlibman

  • Omni founder & CW co-founder
  • Super User
  • Original 5
  • CodeWalrus Supporter
  • *
  • Join Date: Nov 2014
  • Location: Quebec, Canada
  • Posts: 18907
  • Post Rating Ratio: +100/-5
    • dj_omnimaga
    • DJOmnimaga.music
    • @DJOmnimaga
    • dj_omnimaga
    • @DJOmnimaga
    • /u/DJ_Omnimaga
    • DJOmnimaga
    • 112/11286
    • @djomnimaga
    • @DJOmnimaga
    • DJ Omnimaga music store
  • Gender: Male
Re: C support in KOS
« Reply #4 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.
  • Calculators owned: TI-57, 73, TI-80 (broken), TI-81, TI-82, TI-83, TI-83+ (broken), TI-83+ (broken), TI-83+SE (broken), TI-84+, TI-84+CSE, TI-84+CE, TI-85, TI-86, TI-89T, TI-92, TI-Nspire, TI-Nspire CX (semi-broken), HP 39gII, HP Prime, Casio fx-7000G, fx-7400G+, fx-7700GE, fx-9750G+, fx-9750GII, fx-9860G, cfx-9850G, FX-1.0+, fx-CG10, fx-CP400
  • Consoles, mobile devices and vintage computers owned: Samsung i5510, Nexus 5, Atari 2600, Lynx, SMS, Game Gear, Genesis, Dreamcast, NES, SNES, N64, GCN, Wii, Wii U, GBA, DS, 3DS, PS2, PS3, PS4, PSP, PSVita, XBox 360, XBOne

Bandcamp|Reverbnation|Facebook|Youtube|Twitter
Retired Omnimaga admin (2001-11) and editor (2012-14)

Offline Max Leiter

  • Full User
  • Join Date: Oct 2015
  • Location: California
  • Posts: 87
  • Post Rating Ratio: +0/-0
Re: C support in KOS
« Reply #5 on: December 30, 2015, 06:43:49 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.

Offline xlibman

  • Omni founder & CW co-founder
  • Super User
  • Original 5
  • CodeWalrus Supporter
  • *
  • Join Date: Nov 2014
  • Location: Quebec, Canada
  • Posts: 18907
  • Post Rating Ratio: +100/-5
    • dj_omnimaga
    • DJOmnimaga.music
    • @DJOmnimaga
    • dj_omnimaga
    • @DJOmnimaga
    • /u/DJ_Omnimaga
    • DJOmnimaga
    • 112/11286
    • @djomnimaga
    • @DJOmnimaga
    • DJ Omnimaga music store
  • Gender: Male
Re: C support in KOS
« Reply #6 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.
  • Calculators owned: TI-57, 73, TI-80 (broken), TI-81, TI-82, TI-83, TI-83+ (broken), TI-83+ (broken), TI-83+SE (broken), TI-84+, TI-84+CSE, TI-84+CE, TI-85, TI-86, TI-89T, TI-92, TI-Nspire, TI-Nspire CX (semi-broken), HP 39gII, HP Prime, Casio fx-7000G, fx-7400G+, fx-7700GE, fx-9750G+, fx-9750GII, fx-9860G, cfx-9850G, FX-1.0+, fx-CG10, fx-CP400
  • Consoles, mobile devices and vintage computers owned: Samsung i5510, Nexus 5, Atari 2600, Lynx, SMS, Game Gear, Genesis, Dreamcast, NES, SNES, N64, GCN, Wii, Wii U, GBA, DS, 3DS, PS2, PS3, PS4, PSP, PSVita, XBox 360, XBOne

Bandcamp|Reverbnation|Facebook|Youtube|Twitter
Retired Omnimaga admin (2001-11) and editor (2012-14)

Offline Lionel Debroux

  • Full User
  • Join Date: Jan 2015
  • Location:
  • Posts: 231
  • Post Rating Ratio: +11/-0
    • debrouxl
    • 58/5891
Re: C support in KOS
« Reply #7 on: December 30, 2015, 07:14:27 am »
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.

Offline SirCmpwn

  • Full User
  • Join Date: Mar 2015
  • Location:
  • Posts: 81
  • Post Rating Ratio: +1/-0
Re: C support in KOS
« Reply #8 on: December 30, 2015, 03:30:16 pm »
FWIW you can ask kcc to use C99 mode, but it's not entirely implemented.

Offline Max Leiter

  • Full User
  • Join Date: Oct 2015
  • Location: California
  • Posts: 87
  • Post Rating Ratio: +0/-0
Re: C support in KOS
« Reply #9 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

Offline xlibman

  • Omni founder & CW co-founder
  • Super User
  • Original 5
  • CodeWalrus Supporter
  • *
  • Join Date: Nov 2014
  • Location: Quebec, Canada
  • Posts: 18907
  • Post Rating Ratio: +100/-5
    • dj_omnimaga
    • DJOmnimaga.music
    • @DJOmnimaga
    • dj_omnimaga
    • @DJOmnimaga
    • /u/DJ_Omnimaga
    • DJOmnimaga
    • 112/11286
    • @djomnimaga
    • @DJOmnimaga
    • DJ Omnimaga music store
  • Gender: Male
Re: C support in KOS
« Reply #10 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. :)
  • Calculators owned: TI-57, 73, TI-80 (broken), TI-81, TI-82, TI-83, TI-83+ (broken), TI-83+ (broken), TI-83+SE (broken), TI-84+, TI-84+CSE, TI-84+CE, TI-85, TI-86, TI-89T, TI-92, TI-Nspire, TI-Nspire CX (semi-broken), HP 39gII, HP Prime, Casio fx-7000G, fx-7400G+, fx-7700GE, fx-9750G+, fx-9750GII, fx-9860G, cfx-9850G, FX-1.0+, fx-CG10, fx-CP400
  • Consoles, mobile devices and vintage computers owned: Samsung i5510, Nexus 5, Atari 2600, Lynx, SMS, Game Gear, Genesis, Dreamcast, NES, SNES, N64, GCN, Wii, Wii U, GBA, DS, 3DS, PS2, PS3, PS4, PSP, PSVita, XBox 360, XBOne

Bandcamp|Reverbnation|Facebook|Youtube|Twitter
Retired Omnimaga admin (2001-11) and editor (2012-14)

Offline Max Leiter

  • Full User
  • Join Date: Oct 2015
  • Location: California
  • Posts: 87
  • Post Rating Ratio: +0/-0
Re: C support in KOS
« Reply #11 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

Offline xlibman

  • Omni founder & CW co-founder
  • Super User
  • Original 5
  • CodeWalrus Supporter
  • *
  • Join Date: Nov 2014
  • Location: Quebec, Canada
  • Posts: 18907
  • Post Rating Ratio: +100/-5
    • dj_omnimaga
    • DJOmnimaga.music
    • @DJOmnimaga
    • dj_omnimaga
    • @DJOmnimaga
    • /u/DJ_Omnimaga
    • DJOmnimaga
    • 112/11286
    • @djomnimaga
    • @DJOmnimaga
    • DJ Omnimaga music store
  • Gender: Male
Re: C support in KOS
« Reply #12 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.
  • Calculators owned: TI-57, 73, TI-80 (broken), TI-81, TI-82, TI-83, TI-83+ (broken), TI-83+ (broken), TI-83+SE (broken), TI-84+, TI-84+CSE, TI-84+CE, TI-85, TI-86, TI-89T, TI-92, TI-Nspire, TI-Nspire CX (semi-broken), HP 39gII, HP Prime, Casio fx-7000G, fx-7400G+, fx-7700GE, fx-9750G+, fx-9750GII, fx-9860G, cfx-9850G, FX-1.0+, fx-CG10, fx-CP400
  • Consoles, mobile devices and vintage computers owned: Samsung i5510, Nexus 5, Atari 2600, Lynx, SMS, Game Gear, Genesis, Dreamcast, NES, SNES, N64, GCN, Wii, Wii U, GBA, DS, 3DS, PS2, PS3, PS4, PSP, PSVita, XBox 360, XBOne

Bandcamp|Reverbnation|Facebook|Youtube|Twitter
Retired Omnimaga admin (2001-11) and editor (2012-14)

Offline Max Leiter

  • Full User
  • Join Date: Oct 2015
  • Location: California
  • Posts: 87
  • Post Rating Ratio: +0/-0
Re: C support in KOS
« Reply #13 on: January 26, 2016, 07:51:26 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/

Offline xlibman

  • Omni founder & CW co-founder
  • Super User
  • Original 5
  • CodeWalrus Supporter
  • *
  • Join Date: Nov 2014
  • Location: Quebec, Canada
  • Posts: 18907
  • Post Rating Ratio: +100/-5
    • dj_omnimaga
    • DJOmnimaga.music
    • @DJOmnimaga
    • dj_omnimaga
    • @DJOmnimaga
    • /u/DJ_Omnimaga
    • DJOmnimaga
    • 112/11286
    • @djomnimaga
    • @DJOmnimaga
    • DJ Omnimaga music store
  • Gender: Male
Re: C support in KOS
« Reply #14 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
  • Calculators owned: TI-57, 73, TI-80 (broken), TI-81, TI-82, TI-83, TI-83+ (broken), TI-83+ (broken), TI-83+SE (broken), TI-84+, TI-84+CSE, TI-84+CE, TI-85, TI-86, TI-89T, TI-92, TI-Nspire, TI-Nspire CX (semi-broken), HP 39gII, HP Prime, Casio fx-7000G, fx-7400G+, fx-7700GE, fx-9750G+, fx-9750GII, fx-9860G, cfx-9850G, FX-1.0+, fx-CG10, fx-CP400
  • Consoles, mobile devices and vintage computers owned: Samsung i5510, Nexus 5, Atari 2600, Lynx, SMS, Game Gear, Genesis, Dreamcast, NES, SNES, N64, GCN, Wii, Wii U, GBA, DS, 3DS, PS2, PS3, PS4, PSP, PSVita, XBox 360, XBOne

Bandcamp|Reverbnation|Facebook|Youtube|Twitter
Retired Omnimaga admin (2001-11) and editor (2012-14)

 


You can also use the following HTML or bulletin board code to share it on your page or forum signature!


Also do not forget to check our affiliates below.
Planet Casio TI-Planet Calc.news BroniesQC BosaikNet Velocity Games