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

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
  • Calculators owned: A lot.

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
  • Calculators owned: TI-84+
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.
  • Calculators owned: A lot.

Snektron

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

Probably
  • Calculators owned: TI-84+
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.
  • Calculators owned: A lot.

Snektron

  • Calculators owned: TI-84+
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).

Dream of 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.
  • 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

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 >.<
  • Calculators owned: TI-84+
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.
  • Calculators owned: TI-83+.fr, TI-Nspire CAS prototype, TI-84+ CSE, TI-Nspire CX
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