CodeWalrus

Featured Member Projects => Completed and Inactive Projects => [Inactive] KnightOS (TI-73/83+/84+/CSE) => Topic started by: SirCmpwn on April 23, 2015, 12:43:25 am

Title: Pong for KnightOS - An example C project
Post by: SirCmpwn on April 23, 2015, 12:43:25 am
To demonstrate the improvements being made to KnightOS's C support, I've started to make a Real Project in C.

(https://codewalr.us/proxy.php?request=http%3A%2F%2Fa.pomf.se%2Fpqvege.gif&hash=4b983049ccf095b1b7cd671f8af139b2)

The source code is here, it's worth browsing (especially if you know C): https://github.com/SirCmpwn/pong

Pong is a pretty simple project, but since this is meant to be an example I've been keeping it carefully organized so that it's a clear example of how you might structure a large C project for KnightOS. Some important things going on here include:



I haven't put it in place yet, but dynamic linking with KnightOS libraries (i.e. corelib, configlib, etc) works and I'll be putting that into this game somehow.

Other than that, this is your usual project updates thread. Pong! Currently the ball logic is implemented (for bouncing around and scoring points), and you can move paddles around. Collision between paddle and ball isn't in place yet, nor is any sort of main menu or any other UI. More on that to come!
Title: Re: Pong for KnightOS - An example C project
Post by: Duke "Tape" Eiyeron on April 23, 2015, 07:13:59 am
NIce work! Now add hundreds of balls and epic GFX! :p
Title: Re: Pong for KnightOS - An example C project
Post by: Snektron on April 23, 2015, 07:33:42 am
Awesome! also i saw the source before, very clean :). I hope more C projects are going to pop up now, especially if kcc also has tios support :D
Title: Re: Pong for KnightOS - An example C project
Post by: Duke "Tape" Eiyeron on April 23, 2015, 08:07:32 am
It's a pong, you can't really mess up such game code unless you really want to.

typedef struct {
uint8_t x, y;
} coordinates_t;


I prefer using

typedef struct coordinates coordinates_t;
struct coordinates {
uint8_t x, y;
};


But in this case this change nothing, this form only allow a structure to include a variable member of the same type.
Title: Re: Pong for KnightOS - An example C project
Post by: Snektron on April 23, 2015, 08:29:30 am
Well thats just personal preference though. I'd write it like
typedef struct coordinates coordinates_t;
struct coordinates
{
uint8_t x, y;
};

Probably
Title: Re: Pong for KnightOS - An example C project
Post by: Duke "Tape" Eiyeron on April 23, 2015, 08:36:50 am
I'm talking about the sturcture definition, not the formatting though.
Title: Re: Pong for KnightOS - An example C project
Post by: Snektron on April 23, 2015, 08:38:09 am
Oh okay.
Title: Re: Pong for KnightOS - An example C project
Post by: SirCmpwn on April 23, 2015, 02:06:35 pm
Quote from: Duke "Tape" Eiyeron on April 23, 2015, 07:13:59 am
NIce work! Now add hundreds of balls and epic GFX! :p


The first goal of this project is to be a rock solid example of a C project done right on KnightOS, for others to reference. So adding complexity isn't something I'm really up for. However, it is open source, so feel free to fork it and make your own version with hundreds of balls and epic GFX.
Title: Re: Pong for KnightOS - An example C project
Post by: pimathbrainiac on April 24, 2015, 05:44:44 pm
Will the exact same source work for all KOS calcs? If not, what modifications would need to be made for cross-compatibility?
Title: Re: Pong for KnightOS - An example C project
Post by: SirCmpwn on April 24, 2015, 06:15:23 pm
Quote from: pimathbrainiac on April 24, 2015, 05:44:44 pm
Will the exact same source work for all KOS calcs?


Yes.
Title: Re: Pong for KnightOS - An example C project
Post by: pimathbrainiac on April 24, 2015, 06:15:56 pm
Good to know! I'm building the SDK as I type this. Hopefully I'll be able to make something soon!
Title: Re: Pong for KnightOS - An example C project
Post by: SirCmpwn on April 24, 2015, 06:22:47 pm
Quote from: pimathbrainiac on April 24, 2015, 06:15:56 pm
Good to know! I'm building the SDK as I type this. Hopefully I'll be able to make something soon!


Awesome! Have fun, and let me know if you need any help. Remember that C support is still very experimental (and also undocumented).
Title: Re: Pong for KnightOS - An example C project
Post by: DJ Omnimaga on April 25, 2015, 06:51:07 am
Does that include the CSE? I forgot if KOS automatically scaled program graphics up if they were ran on a color calc instead of monochrome.
Title: Re: Pong for KnightOS - An example C project
Post by: Snektron on April 25, 2015, 07:40:16 am
Quote from: pimathbrainiac on April 24, 2015, 06:15:56 pm
Good to know! I'm building the SDK as I type this. Hopefully I'll be able to make something soon!

Oh dear, building things... Someone will have to help me with this when i try this out >.<
Title: Re: Pong for KnightOS - An example C project
Post by: matrefeytontias on April 25, 2015, 09:29:02 am
KnightOS for the CSE lets programs decide themselves whether or not to use the color screen or the legacy mode, which emulates the monochrome display. Legacy mode is the default mode, so programs will also work on the CSE.
Title: Re: Pong for KnightOS - An example C project
Post by: SirCmpwn on April 25, 2015, 04:28:39 pm
Quote from: DJ Omnimaga on April 25, 2015, 06:51:07 am
Does that include the CSE? I forgot if KOS automatically scaled program graphics up if they were ran on a color calc instead of monochrome.

Most KnightOS programs will work correctly on the CSE without any changes, in legacy mode. This simulates the older screen at 2x zoom. Then, if you choose, you can make your programs run in color mode, and take advantage of the full screen.

Quote from: Cumred_Snektron on April 25, 2015, 07:40:16 am
Oh dear, building things... Someone will have to help me with this when i try this out >.<

It's very easy! I don't think you'll have trouble.
Title: Re: Pong for KnightOS - An example C project
Post by: Duke "Tape" Eiyeron on April 25, 2015, 04:32:15 pm
*Suddlenty, a wild Matref appears.*
Title: Re: Pong for KnightOS - An example C project
Post by: Snektron on April 25, 2015, 04:46:32 pm
Quote from: SirCmpwn on April 25, 2015, 04:28:39 pm
Quote from: Cumred_Snektron on April 25, 2015, 07:40:16 am
Oh dear, building things... Someone will have to help me with this when i try this out >.<

It's very easy! I don't think you'll have trouble.


Maybe it's a good idea if someone writes a tutorial for this... and with support for win7 wo/ VS noobs... :3
Title: Re: Pong for KnightOS - An example C project
Post by: SirCmpwn on April 25, 2015, 04:49:27 pm
Quote from: Cumred_Snektron on April 25, 2015, 04:46:32 pm
Maybe it's a good idea if someone writes a tutorial for this... and with support for win7 wo/ VS noobs... :3

Windows users write KnightOS software on Cygwin, which provides a Unix environment. No VS required. Here's the tutorial you're after: http://www.knightos.org/documentation/tutorials/getting-started/
Title: Re: Pong for KnightOS - An example C project
Post by: Snektron on April 25, 2015, 04:50:31 pm
Oh great! Though i use mingw... ah it'll be fine probably, though i heard there was a lot of hate towards mingw
Title: Re: Pong for KnightOS - An example C project
Post by: SirCmpwn on April 25, 2015, 04:52:18 pm
Quote from: Cumred_Snektron on April 25, 2015, 04:50:31 pm
Oh great! Though i use mingw... ah it'll be fine probably, though i heard there was a lot of hate towards mingw

Mingw isn't supported and won't work, just use cygwin or you'll piss off everyone in #knightos when you come ask for help (it happens a lot).
Title: Re: Pong for KnightOS - An example C project
Post by: Snektron on April 25, 2015, 04:53:31 pm
Okay, will do :P
Title: Re: Pong for KnightOS - An example C project
Post by: DJ Omnimaga on April 26, 2015, 04:53:47 am
By the way, if it ever became clear that we will never be able to install third-party OSes on the 84+CE, will the CE version of KnightOS simply be downscaled to a shell like Mirage/DCS?
Title: Re: Pong for KnightOS - An example C project
Post by: SirCmpwn on April 26, 2015, 04:55:10 am
Quote from: DJ Omnimaga on April 26, 2015, 04:53:47 am
By the way, if it ever became clear that we will never be able to install third-party OSes on the 84+CE, will the CE version of KnightOS simply be downscaled to a shell like Mirage/DCS?

I don't know enough about the CE yet to really say anything like that.
Title: Re: Pong for KnightOS - An example C project
Post by: Ivoah on April 26, 2015, 12:36:34 pm
Quote from: DJ Omnimaga on April 26, 2015, 04:53:47 am
By the way, if it ever became clear that we will never be able to install third-party OSes on the 84+CE, will the CE version of KnightOS simply be downscaled to a shell like Mirage/DCS?


There is a way to install 3rd party OSes on the CE, but it requires hacks that have not been disclosed yet.
Title: Re: Pong for KnightOS - An example C project
Post by: DJ Omnimaga on April 26, 2015, 04:26:20 pm
Oh OK, I thought it absolutely required the 2048 bit RSA key. That said I am betting that as soon as hacks or third-party OSes using them come out, then TI will patch them >.<
Title: Re: Pong for KnightOS - An example C project
Post by: SirCmpwn on April 26, 2015, 05:15:09 pm
The 84+ CE is also so different from the other supported calcs that I'm not sure exactly how KnightOS support will take shape. A high quality port of KnightOS to the CE will take a lot of work, but will be really cool. And yeah, we need an exploit and there aren't any public ones yet. I don't have time myself to go hunting for exploits.
Title: Re: Pong for KnightOS - An example C project
Post by: SirCmpwn on April 27, 2015, 03:56:18 am
I realized that I never really gave an update - the mini-project is effectively done now. The game works great and I was able to fix a few problems with KnightOS's C support while making it. The code is a great reference now for anyone else hoping to build projects for KnightOS in C.
Title: Re: Pong for KnightOS - An example C project
Post by: DJ Omnimaga on April 27, 2015, 04:25:06 am
Good to hear. :) I will need to check it out. I wonder how does the executable size compare with a TI-OS Axe or pure ASM one?
Title: Re: Pong for KnightOS - An example C project
Post by: SirCmpwn on April 27, 2015, 04:26:32 am
Quote from: DJ Omnimaga on April 27, 2015, 04:25:06 am
Good to hear. :) I will need to check it out. I wonder how does the executable size compare with a TI-OS Axe or pure ASM one?


It's 1719 bytes. You can get the package here: https://packages.knightos.org/community/pong
Title: Re: Pong for KnightOS - An example C project
Post by: Ivoah on April 27, 2015, 04:27:23 am
Quote from: DJ Omnimaga on April 26, 2015, 04:26:20 pm
Oh OK, I thought it absolutely required the 2048 bit RSA key. That said I am betting that as soon as hacks or third-party OSes using them come out, then TI will patch them >.<


Nope. Apparently TI messed up the ASIC, so the only way to fix them is with a very expensive hardware change.
Title: Re: Pong for KnightOS - An example C project
Post by: DJ Omnimaga on April 27, 2015, 04:37:59 am
Ah right, fail on their part then. I'm betting they would be ready to do anything at any cost to lock down their calcs, but since they seem to try less hard on Z80/ez80 calcs, then I bet it will take a few years before it happens (maybe only on their next calc?). I guess we have the path cleared to a certain extent for now.
Title: Re: Pong for KnightOS - An example C project
Post by: Lionel Debroux on April 27, 2015, 05:36:12 am
QuoteThe game works great and I was able to fix a few problems with KnightOS's C support while making it.

Small projects, especially for new platforms / environments, usually have that effect. In 2011, advancing an old Lua port to the TI-68k/AMS series, and partially porting "p14p" python-on-a-chip to the same, yielded improvements in GCC4TI.
That's also why in 2010, I suggested the making of a demo (in the demoscene sense) for the Nspire platform.
Title: Re: Pong for KnightOS - An example C project
Post by: SirCmpwn on April 27, 2015, 05:38:46 am
Quote from: Lionel Debroux on April 27, 2015, 05:36:12 am
QuoteThe game works great and I was able to fix a few problems with KnightOS's C support while making it.

Small projects, especially for new platforms / environments, usually have that effect. In 2011, advancing an old Lua port to the TI-68k/AMS series, and partially porting "p14p" python-on-a-chip to the same, yielded improvements in GCC4TI.
That's also why in 2010, I suggested the making of a demo (in the demoscene sense) for the Nspire platform.


Yep, that was the goal of this project in the first place. I'll be doing a few more projects with the same goal in mind.
Title: Re: Pong for KnightOS - An example C project
Post by: DJ Omnimaga on April 27, 2015, 05:43:33 am
Now that Lionel mentions the TI-Nspire, that makes me wish that Jacobly and Calc84maniac's respective attempts at creating TI-84+ emulators for the Nspire came to fruition. I don't remember if there is any other such project in the works, but it could be a way for people to use KnightOS on their Nspire if there are no plan to port KOS directly to that platform. But I guess that's for another topic.
Title: Re: Pong for KnightOS - An example C project
Post by: SirCmpwn on April 27, 2015, 05:44:32 am
Quote from: DJ Omnimaga on April 27, 2015, 05:43:33 am
Now that Lionel mentions the TI-Nspire, that makes me wish that Jacobly and Calc84maniac's respective attempts at creating TI-84+ emulators for the Nspire came to fruition. I don't remember if there is any other such project in the works, but it could be a way for people to use KnightOS on their Nspire if there are no plan to port KOS directly to that platform. But I guess that's for another topic.


matref has ported z80e (the KnightOS project's emulator) to the Nspire, and I would love to see more contributors come in and help develop it.
Title: Re: Pong for KnightOS - An example C project
Post by: DJ Omnimaga on April 27, 2015, 05:47:56 am
Ah thanks for pointing out. Now that you mention matref, I think I remember hearing some tidbits about such project. I didn't know it went this far, though.
Title: Re: Pong for KnightOS - An example C project
Post by: SirCmpwn on April 27, 2015, 05:51:15 am
Quote from: DJ Omnimaga on April 27, 2015, 05:47:56 am
Ah thanks for pointing out. Now that you mention matref, I think I remember hearing some tidbits about such project. I didn't know it went this far, though.


Unfortunately, no one is really working on z80e right now. It's the default emulator for the SDK, and it powers the live demo on knightos.org, but it can't emulate TIOS and it has poor performance.
Title: Re: Pong for KnightOS - An example C project
Post by: DJ Omnimaga on April 28, 2015, 07:35:25 pm
Aah ok thanks for clarifying. As for performance I remember issues about lag and stuff. On my 2010 computer, when I had juju's topic open (which had the emulator embedded in) my browser would take 100% of the CPU and my mouse cursor moved at about 2 FPS when it was loading. And when it was done loading, typing posts was like 4 letters per second max. Hopefully if this project gets revived, you guys can find a way to get it run faster on older machines.
Title: Re: Pong for KnightOS - An example C project
Post by: SirCmpwn on April 28, 2015, 07:36:42 pm
Quote from: DJ Omnimaga on April 28, 2015, 07:35:25 pm
Aah ok thanks for clarifying. As for performance I remember issues about lag and stuff. On my 2010 computer, when I had juju's topic open (which had the emulator embedded in) my browser would take 100% of the CPU and my mouse cursor moved at about 2 FPS when it was loading. And when it was done loading, typing posts was like 4 letters per second max. Hopefully if this project gets revived, you guys can find a way to get it run faster on older machines.


It runs at a much more reasonable speed natively. It's just in the browser that performance is abhorrent.