Difference between revisions of "C SDK Tips and Tricks"

From Learn @ Cemetech
Jump to navigationJump to search
 
(17 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
==Setting up the SDK on linux==
 
==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.
 
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 [http://imgur.com/a/vXSIz here] for a higher quality album of the screenshots''
 
----
 
----
 
===Files===
 
===Files===
Line 7: Line 9:
  
 
Extract it wherever you want, though putting it in the home directory is easiest.
 
Extract it wherever you want, though putting it in the home directory is easiest.
 +
 +
http://i.imgur.com/efX1W2rl.png
 +
http://i.imgur.com/eozLrjpl.png
 +
 
===Environment Variables===
 
===Environment Variables===
 
----
 
----
 
<nowiki>- Open your ~/.bashrc file. (It is a hidden file in your home directory, [Ctl + H] to make it visible)
 
<nowiki>- Open your ~/.bashrc file. (It is a hidden file in your home directory, [Ctl + H] to make it visible)
 
</nowiki>
 
</nowiki>
 +
 +
http://i.imgur.com/9dNrmrXl.png
 
  <nowiki>- Add these lines to the end of the document:</nowiki>
 
  <nowiki>- Add these lines to the end of the document:</nowiki>
  
 
  export PATH=$PATH:~/CEdev/bin/
 
  export PATH=$PATH:~/CEdev/bin/
 
  export CEDEV=~/CEdev/
 
  export CEDEV=~/CEdev/
 +
 +
http://i.imgur.com/nS3NFWGl.png
 
<nowiki>- 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.</nowiki>
 
<nowiki>- 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.</nowiki>
 
----
 
----
Line 35: Line 45:
 
The others are pretty self explanatory, and the comments at the top of the file will help with explanation.
 
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.
 
You will want to add '''graphx fileioc keypadc''' to '''L :=''' to be able to use the libraries.
 +
 +
http://i.imgur.com/XfNMfAil.png
  
 
That is just about everything you need to know about the makefile
 
That is just about everything you need to know about the makefile
 
----
 
----
 +
 
===Tweaking the main.c file===
 
===Tweaking the main.c file===
 
----
 
----
Line 52: Line 66:
 
  #include <debug.h>
 
  #include <debug.h>
  
Next, uncomment '''PrgmCleanUp();'''
+
Then, add '''gfx_Begin( gfx_8bpp );'''. This will make your program able to use the graphics libraries.
  
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.
  
You may also want to add '''gfx_FillScreen(gfx_white);''' to color the screen white.
+
http://i.imgur.com/8Sxcpadl.png
  
 
Remember, you can edit it more to tailor to your own needs, but this is what I do.
 
Remember, you can edit it more to tailor to your own needs, but this is what I do.
 
----
 
----
 +
 
==="Making" the program===
 
==="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'''
 
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'' '''
+
'''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:
 
Open a terminal and CD to your program's main directory. My command to cd is:
 
  cd /CEdev/Programs/[program folder name]/
 
  cd /CEdev/Programs/[program folder name]/
 +
 +
http://i.imgur.com/793PHYpl.png
 
You can also right click in the folder and hit ''open in terminal''.
 
You can also right click in the folder and hit ''open in terminal''.
  
 
Now, once you are in the correct directory, run.
 
Now, once you are in the correct directory, run.
 
  wine /home/[username]/CEdev/bin/make.exe
 
  wine /home/[username]/CEdev/bin/make.exe
 +
 +
http://i.imgur.com/We3Izhul.png
 
If CEdev is not in your home directory, just change the path to that location
 
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'''.
 
It should run, and if you look in '''/bin/''' you should see a '''*.8xp'''.
 +
 +
http://i.imgur.com/ECOQwjDl.png
 +
 +
Put that on a calculator or [https://github.com/CE-Programming/CEmu CEmu] with the [https://github.com/CE-Programming/libraries 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 [https://github.com/CE-Programming/toolchain/releases/tag/v5.2 here].
 +
 +
Extract it wherever you want, though putting it in the home directory is easiest.
 +
===Environment Variables===
 +
----
 +
There is now a streamlined and easy process to install the environment variables. Just extract CEdev and run the win_setup.exe as admin, and it will create them for you. You will have to put CEdev in C:\ but, that is not a big deal :)
 +
----
 +
 +
===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>
 +
 +
Then, add '''gfx_Begin( gfx_8bpp );'''. 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 [https://github.com/CE-Programming/CEmu CEmu] with the [https://github.com/CE-Programming/libraries C libraries], and you are all set!
 
Put that on a calculator or [https://github.com/CE-Programming/CEmu CEmu] with the [https://github.com/CE-Programming/libraries 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 [https://github.com/CE-Programming/CEmu CEmu] (if you don't know how to build it, download the latest version from [http://pimathbrainiac.me/CEmu/ 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

Latest revision as of 22:23, 26 November 2016

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>

Then, add gfx_Begin( gfx_8bpp );. 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


There is now a streamlined and easy process to install the environment variables. Just extract CEdev and run the win_setup.exe as admin, and it will create them for you. You will have to put CEdev in C:\ but, that is not a big deal :)


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>

Then, add gfx_Begin( gfx_8bpp );. 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