* 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: Pong for KnightOS - An example C project  (Read 6393 times)

0 Members and 1 Guest are viewing this topic.

Offline SirCmpwn

  • Full User
  • Join Date: Mar 2015
  • Location:
  • Posts: 81
  • Post Rating Ratio: +1/-0
Pong for KnightOS - An example C project
« 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.



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!



Offline Duke "Tape" Eiyeron

  • Urist McEiyolobster
  • Super User
  • Join Date: Nov 2014
  • Location: (V)(-_(//));(V)
  • Posts: 1636
  • Post Rating Ratio: +11/-2
  • Fanciest Walrus of the oceans.
    • @@Eiyeron
    • Eiyeron
    • /u/Eiyeron
    • Eiyeron
    • Rétro-Actif : Rétro/Prog/Blog
  • Gender: Male
Re: Pong for KnightOS - An example C project
« Reply #1 on: April 23, 2015, 07:13:59 am »
NIce work! Now add hundreds of balls and epic GFX! :p
  • Calculators owned: A lot.

Offline Snektron

  • Lvl 69 Russian Snake
  • CodeWalrus Staff
  • Super User
  • Topic Management
  • Join Date: Dec 2014
  • Location: Netherlands
  • Posts: 3165
  • Post Rating Ratio: +32/-0
  • SSSssssss.....
    • RobinDeWalvis
    • Kzyrox
    • RobinDeWalvis
    • quantuminfinity
  • Gender: Male
Re: Pong for KnightOS - An example C project
« Reply #2 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
  • Calculators owned: TI-84+
Legends say if you spam more than DJ Omnimaga, you will become a walrus...


Offline Duke "Tape" Eiyeron

  • Urist McEiyolobster
  • Super User
  • Join Date: Nov 2014
  • Location: (V)(-_(//));(V)
  • Posts: 1636
  • Post Rating Ratio: +11/-2
  • Fanciest Walrus of the oceans.
    • @@Eiyeron
    • Eiyeron
    • /u/Eiyeron
    • Eiyeron
    • Rétro-Actif : Rétro/Prog/Blog
  • Gender: Male
Re: Pong for KnightOS - An example C project
« Reply #3 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.

Code: [Select]
typedef struct {
uint8_t x, y;
} coordinates_t;

I prefer using
Code: [Select]
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.

Offline Snektron

  • Lvl 69 Russian Snake
  • CodeWalrus Staff
  • Super User
  • Topic Management
  • Join Date: Dec 2014
  • Location: Netherlands
  • Posts: 3165
  • Post Rating Ratio: +32/-0
  • SSSssssss.....
    • RobinDeWalvis
    • Kzyrox
    • RobinDeWalvis
    • quantuminfinity
  • Gender: Male
Re: Pong for KnightOS - An example C project
« Reply #4 on: April 23, 2015, 08:29:30 am »
Well thats just personal preference though. I'd write it like
Code: [Select]
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...


Offline Duke "Tape" Eiyeron

  • Urist McEiyolobster
  • Super User
  • Join Date: Nov 2014
  • Location: (V)(-_(//));(V)
  • Posts: 1636
  • Post Rating Ratio: +11/-2
  • Fanciest Walrus of the oceans.
    • @@Eiyeron
    • Eiyeron
    • /u/Eiyeron
    • Eiyeron
    • Rétro-Actif : Rétro/Prog/Blog
  • Gender: Male
Re: Pong for KnightOS - An example C project
« Reply #5 on: April 23, 2015, 08:36:50 am »
I'm talking about the sturcture definition, not the formatting though.
  • Calculators owned: A lot.

Offline Snektron

  • Lvl 69 Russian Snake
  • CodeWalrus Staff
  • Super User
  • Topic Management
  • Join Date: Dec 2014
  • Location: Netherlands
  • Posts: 3165
  • Post Rating Ratio: +32/-0
  • SSSssssss.....
    • RobinDeWalvis
    • Kzyrox
    • RobinDeWalvis
    • quantuminfinity
  • Gender: Male
Re: Pong for KnightOS - An example C project
« Reply #6 on: April 23, 2015, 08:38:09 am »
Oh okay.
  • Calculators owned: TI-84+
Legends say if you spam more than DJ Omnimaga, you will become a walrus...


Offline SirCmpwn

  • Full User
  • Join Date: Mar 2015
  • Location:
  • Posts: 81
  • Post Rating Ratio: +1/-0
Re: Pong for KnightOS - An example C project
« Reply #7 on: April 23, 2015, 02:06:35 pm »
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.

Offline pimathbrainiac

  • Full User
  • Original 5
  • Join Date: Nov 2014
  • Location:
  • Posts: 421
  • Post Rating Ratio: +2/-1
  • Formerly Banned CW Co-Founder Turned News Editor
    • pimathbrainiac
  • Gender: Other
Re: Pong for KnightOS - An example C project
« Reply #8 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?
Well, I'm bach here too!

Offline SirCmpwn

  • Full User
  • Join Date: Mar 2015
  • Location:
  • Posts: 81
  • Post Rating Ratio: +1/-0
Re: Pong for KnightOS - An example C project
« Reply #9 on: April 24, 2015, 06:15:23 pm »
Will the exact same source work for all KOS calcs?

Yes.

Offline pimathbrainiac

  • Full User
  • Original 5
  • Join Date: Nov 2014
  • Location:
  • Posts: 421
  • Post Rating Ratio: +2/-1
  • Formerly Banned CW Co-Founder Turned News Editor
    • pimathbrainiac
  • Gender: Other
Re: Pong for KnightOS - An example C project
« Reply #10 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!
Well, I'm bach here too!

Offline SirCmpwn

  • Full User
  • Join Date: Mar 2015
  • Location:
  • Posts: 81
  • Post Rating Ratio: +1/-0
Re: Pong for KnightOS - An example C project
« Reply #11 on: April 24, 2015, 06:22:47 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).

Online xlibman

  • Omni founder & CW co-founder
  • Super User
  • Original 5
  • CodeWalrus Supporter
  • *
  • Join Date: Nov 2014
  • Location: Quebec, Canada
  • Posts: 18739
  • Post Rating Ratio: +95/-4
    • dj_omnimaga
    • DJOmnimaga.music
    • @DJOmnimaga
    • dj_omnimaga
    • @DJOmnimaga
    • /u/DJ_Omnimaga
    • DJOmnimaga
    • 112/11286
    • @djomnimaga
    • @DJOmnimaga
    • DJ Omnimaga music store
  • Gender: Male
Re: Pong for KnightOS - An example C project
« Reply #12 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.
  • 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 Snektron

  • Lvl 69 Russian Snake
  • CodeWalrus Staff
  • Super User
  • Topic Management
  • Join Date: Dec 2014
  • Location: Netherlands
  • Posts: 3165
  • Post Rating Ratio: +32/-0
  • SSSssssss.....
    • RobinDeWalvis
    • Kzyrox
    • RobinDeWalvis
    • quantuminfinity
  • Gender: Male
Re: Pong for KnightOS - An example C project
« Reply #13 on: April 25, 2015, 07:40:16 am »
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...


Offline matrefeytontias

  • Full User
  • Join Date: Nov 2014
  • Location: France
  • Posts: 200
  • Post Rating Ratio: +5/-1
  • Axe metalhead of vengence
    • @matrefeytontias
    • matrefeytontias
    • matrefeytontias
  • Gender: Male
Re: Pong for KnightOS - An example C project
« Reply #14 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.
  • 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

 


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