Alternatively, join us on Discord.

Pong for KnightOS - An example C project

Started by SirCmpwn, April 23, 2015, 12:43:25 am

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

SirCmpwn

To demonstrate the improvements being made to KnightOS's C support, I've started to make a Real Project in C.



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:


  • Images are kept as PNG files, and then magically converted to object files and linked into your application through kimg and scwrap. English: the sprites are PNG files, not hex written into the code

  • This separates everything into separate C files for the sake of organization and they're all linked together correctly

  • Globals work now! And libc is working well, and some bugs were fixed in unused function optimization and in kcc. Not really a feature of this project, but it wouldn't work without.



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!

Duke "Tape" Eiyeron

NIce work! Now add hundreds of balls and epic GFX! :p

Snektron

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
Legends say if you spam more than DJ Omnimaga, you will become a walrus...


Duke "Tape" Eiyeron

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.

Snektron

Well thats just personal preference though. I'd write it like
typedef struct coordinates coordinates_t;
struct coordinates
{
uint8_t x, y;
};

Probably
Legends say if you spam more than DJ Omnimaga, you will become a walrus...


Duke "Tape" Eiyeron

I'm talking about the sturcture definition, not the formatting though.

Snektron

Legends say if you spam more than DJ Omnimaga, you will become a walrus...


SirCmpwn

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.

pimathbrainiac

Will the exact same source work for all KOS calcs? If not, what modifications would need to be made for cross-compatibility?
Well, I'm bach here too!


pimathbrainiac

Good to know! I'm building the SDK as I type this. Hopefully I'll be able to make something soon!
Well, I'm bach here too!

SirCmpwn

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).

DJ Omnimaga

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.

Snektron

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 >.<
Legends say if you spam more than DJ Omnimaga, you will become a walrus...


matrefeytontias

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.
My TI games (some got their own article on non-calc websites !) : http://www.ticalc.org/archives/files/authors/112/11202.html

My moozik (100% free metal) : http://www.soundcloud.com/matrefeytontias

Powered by EzPortal