C SDK Tips and Tricks

From Learn @ Cemetech
Revision as of 19:05, 3 September 2016 by Unicorn (talk | contribs) (→‎Files)
Jump to navigationJump to search

Setting up the SDK on linux

This section will help you set up the C SDK on linux. It is best to do it in this same order, but that is your choice.

Go here for a higher quality album of the screenshots


Files


Download the C toolchain here.

Extract it wherever you want, though putting it in the home directory is easiest.

efX1W2rl.png eozLrjpl.png

Environment Variables


- Open your ~/.bashrc file. (It is a hidden file in your home directory, [Ctl + H] to make it visible)

9dNrmrXl.png

- Add these lines to the end of the document:
export PATH=$PATH:~/CEdev/bin/
export CEDEV=~/CEdev/

nS3NFWGl.png - If you extracted CEdev to somewhere else other than your home, change the paths to that location. Keep in mind that CEDEV needs to point to the Cedev folder, and PATH needs to point to the CEdev/bin folder.


Setting up the Template makefile


Once you have the Environment Variables set up, create a New folder where you will put all of your projects. (I put mine in CEdev/Programs)

Once you have that folder, go into CEdev/examples and copy template.

Paste the template in your programs folder.

Open it up and edit the makefile.

It should look something like this: http://pastebin.com/N7K4ppBD

Edit TARGET ?= DEMOT and replace DEMOT with your program name.

Keep DEBUGMODE ?= as NDEBUG until you decide to use the Debug features in your program.

The others are pretty self explanatory, and the comments at the top of the file will help with explanation.

IMPORTANT

You will want to add graphx fileioc keypadc to L := to be able to use the libraries.

XfNMfAil.png

That is just about everything you need to know about the makefile


Tweaking the main.c file


If you head into /src/ you will main.c. Go ahead and open it. It will look something like this: http://pastebin.com/QqEgTBid

If you make that file, it will not do anything. To make it easier to set up a new project, we will edit it.

To make anything work, we will have to include the libraries, add the following text underneath #include <string.h>

#include <graphx.h>
#include <keypadc.h>
#include <fileioc.h>
#include <debug.h>

Next, uncomment PrgmCleanUp();

Then, add gfx_Begin( gfx_8bpp ); above that. This will make your program able to use the graphics libraries.

You may also want to add gfx_FillScreen(gfx_white); to color the screen white.

8Sxcpadl.png

Remember, you can edit it more to tailor to your own needs, but this is what I do.


"Making" the program


Once you have edited and created your program, you will want to test it. To do so, you will have to "make" your program, and doing so will create a .8xp in /[program location/bin

Remember, this is on linux, and it will not work on windows.

Open a terminal and CD to your program's main directory. My command to cd is:

cd /CEdev/Programs/[program folder name]/

793PHYpl.png You can also right click in the folder and hit open in terminal.

Now, once you are in the correct directory, run.

wine /home/[username]/CEdev/bin/make.exe

We3Izhul.png If CEdev is not in your home directory, just change the path to that location

It should run, and if you look in /bin/ you should see a *.8xp.

ECOQwjDl.png

Put that on a calculator or CEmu with the C libraries, and you are all set!


Setting up the SDK on Windows

This section will help you set up the C SDK on windows. It is best to do it in this same order, but that is your choice.


Files


Download the C toolchain here.

Extract it wherever you want, though putting it in the home directory is easiest.

Environment Variables


You can follow this tutorial.

A more in-depth process will come, once I get on windows again, or someone else fills it out.


Setting up the Template makefile


Once you have the Environment Variables set up, create a New folder where you will put all of your projects. (I put mine in CEdev/Programs/)

Once you have that folder, go into CEdev/examples/ and copy template.

Paste the template in your programs folder.

Open it up and edit the makefile.

It should look something like this: http://pastebin.com/N7K4ppBD

Edit TARGET ?= DEMOT and replace DEMOT with your program name.

Keep DEBUGMODE ?= as NDEBUG until you decide to use the Debug features in your program.

The others are pretty self explanatory, and the comments at the top of the file will help with explanation. IMPORTANT: You will want to add graphx fileioc keypadc to L := to be able to use the libraries.

That is just about everything you need to know about the makefile


Tweaking the main.c file


If you head into /src/ you will main.c. Go ahead and open it. It will look something like this: http://pastebin.com/QqEgTBid

If you make that file, it will not do anything. To make it easier to set up a new project, we will edit it.

To make anything work, we will have to include the libraries, add the following text underneath #include <string.h>

#include <graphx.h>
#include <keypadc.h>
#include <fileioc.h>
#include <debug.h>

Next, uncomment PrgmCleanUp();

Then, add gfx_Begin( gfx_8bpp ); above that. This will make your program able to use the graphics libraries.

You may also want to add gfx_FillScreen(gfx_white); to color the screen white.

Remember, you can edit it more to tailor to your own needs, but this is what I do.


"Making" the program


Once you have edited and created your program, you will want to test it. To do so, you will have to "make" your program, and doing so will create a .8xp in /[program location/bin/

Remember, this is on windows, and it will not work on linux.

Open a terminal and CD to your program's main directory. My command to cd is:

cd /CEdev/Programs/[program folder name]/

Now, once you are in the correct directory, run.

make

It should run, and if you look in /bin/ you will see a *.8xp.

Put that on a calculator or CEmu with the C libraries, and you are all set!


Debug.h


You may have found that being able to display and locate bugs might be helpful, but how would you do that? This part of the guide will show you how.


Requirements


You need to download CEmu (if you don't know how to build it, download the latest version from pimath's website. Be sure to also add #include <debug.h> at the top of your program, and change NDEBUG to DEBUG in the makefile


dbg_sprintf()


The first and most important command, dbg_sprintf() lets you print variables and strings to the CEmu console

To print a string, run this: dbg_sprintf(dbgout, "This is my string!\n");

To print a variable, run this: dbg_sprintf(dbgout, "%d\n", variableName);

To print a variable and a string, run this: dbg_sprintf(dbgout, "This is my variable: %d\n", variableName);


Getting the Ouput


After you have inserted those commands, to get the output, send your program to CEmu, and enable the console: Docks > Console

Start your program, and you should see your text in the console whenever it ran.


Other Info


There is some documentation of the library here: https://github.com/CE-Programming/toolchain/blob/master/CEdev/include/ce/c/debug.h