Section 1: Introduction

Preface:
In this section of the tutorial, you’ll learn where to find resources for learning computer C, as well as set up the Prizm SDK which will start you coding right away.

Resources:
First off you will need to have to know C, or C++. C is recommended since coding C++ for the Prizm is very splotchy. If you have no clue what C is we recommend visiting:
www.cprogramming.com
If you have any questions concerning code become a member here and post:
www.cemetech.net

Setting up the SDK and other Files
Now we are sure you have some coding experience you will need a source code editor, most preferably Notepad++. This allows you to code in the easiest way possible. Google or Bing search it and download.
Now Go to:
www.prizm.cemetech.net
Click on:
For Programmers: Prizm Programming Portal for SDKs, syscall references, and useful routines
Click on something that looks like this:
PrizmSDK: PrizmSDK v0.3
This will bring you to the cemetech website, you can download the .tar or the .zip file. I prefer the .zip because it is easier to extract.
.Zip file:
Find the folder where the Prizm SDK was downloaded (possibly in downloads). Right click and select extract all, this will leave you with the empty .zip file, and a normal folder. The folder has all of the files you will need. Right click again and select cut, navigate to your computer C:/ file (local disk C:/). Right click and paste. Now you have the SDK in the correct place.



Section 2: The Basics

Preface
In this section of the tutorial, you’ll learn the development of icons, become more comfortable with the SDK, and learn the layout of a C program coded for the Prizm.
Various tasks you’ll be able to complete at the end of reading this section include:

- Correct Icon development
- Correctly compile C programs using the SDK
- Identify the general layout of a C program coded for the Prizm

Icon Development:
Go here: (credits go to JosJuice)
http://cemetech.net/forum/viewtopic.php?t=6211&start=0


Hello World -- Familiarizing Yourself With the Compiling Process
Since you should have the SDK set up and have the correct files where need be (if not read Section 1) we can continue. Open up Notpad++ and copy this into it.

Code:
#include <keyboard_syscalls.h>
#include <keyboard.hpp>
#include <display_syscalls.h>
#include <color.h>
#define true 1
int main() {

PrintXY(1, 1, "XXHello World!", TEXT_MODE_NORMAL, TEXT_COLOR_BLACK);

int key;

while(true) {

GetKey(&key);

Bdisp_PutDisp_DD();

}

return 0;
}


Save this file as a C source file named, "Hello_World". Click into the Prizm SDK and navigate into the projects folder. Copy and paste another folder of the "example" folder. Rename one of them to "Hello_World". You will need to do this for each project, always copying the example folder (this folder holds the basic files needed for each project). Now you will need to find where the "Hello_World" C source file is saved and move it into the new "Hello_World" folder.


Note: make sure your project folder name does not have spaces in it, either in the folder name or in the makefile; using spaces will cause the build system to not recognize your project.


Select your source and copy it into the “src” folder. Assuming you have your two icons made, we can continue. Rename your icons, “selected” and “unselected”. Next right click on the “Makefile” (this is the file not the Batch), and select “Edit it with Notepad++”. Scroll down until you will see this:

Code:
TARGET  := $(notdir $(CURDIR))
Where it says “$(notdir $(CURDIR))” replace it with “Hello_World” (or whatever your project name is)
Now scroll down again until you see this:
MKG3AFLAGS := -n basic:example -i uns:../unselected.bmp -i sel:../selected.bmp

Where it says “basic:example” replace the “example” with “Hello World”, you will rename this to whatever you want your add-in to be named.
Now time for compiling, run the make.bat (the batch file) and a command prompt screen should appear and compile your code. After compiling the .g3a file will be in your project folder. Connect your Prizm and drag it into the main memory folder.

The General C Format for the Prizm
Because you are programming C for the Prizm, you need to follow this general format that stays consistent. To be consistent, the program will continue until you press [menu] which returns you to the main menu.

Code:
//Headers go here
//defines go here
define true 1   //declares true to equal 1
//global variable declarations go here
int main () {
    //local variable declarations go here

int key;

while(true) {

GetKey(&key);

//code goes here
    }
return 0;
}
//functions go here

Along with following this format, indent each block of code (Notepad++ does this for you). This increases readability and allows others to understand your code.
This should be moved/copied onto the Prizm wiki eventually. I started making tutorials, but I stopped, hoping someone else would make some :\
Why not help me continue with it? Since I sort of slacked of since Ashbad moved on. It would be motivating if I had some help.
I am porting it to wikiprizm now.

Quote:
C is recommended since coding C++ for the Prizm is very splotchy.


I wouldn't say that it is bad. 3D checkers and my game engine both use C++ just fine. The checkers engine even has a full software floating point library in C++.

I will write up a separate article on using C++ on the prizm eventually.
Well I wouldn't say it is bad either Razz Just more support. Yeah C++ would be a good article.
Added the pages. When you have changes, let me know what you change Smile

Your last code example has errors. I will fix them on the wiki.
GCC is only for Linux if I got it right? I need to use "Code::Blocks with MinGW" sense im running Windows?

EDIT: I am using this "guide" http://www.cprogramming.com/code_blocks/ and it says that I can open "main.cpp" but all I got is "main.c" Is that okay to or am I doing something wrong?

Maby I should use my own thread for these questions sense this is a tutorial guide, if so mod can move my post. Smile
Add the "std=c99" to get C99 specifications, like the for(int i=0;...) to the Makefile, at the "CFLAGS".
lirkaren wrote:
GCC is only for Linux if I got it right? I need to use "Code::Blocks with MinGW" sense im running Windows?

EDIT: I am using this "guide" http://www.cprogramming.com/code_blocks/ and it says that I can open "main.cpp" but all I got is "main.c" Is that okay to or am I doing something wrong?
main.cpp is for C++ programs; main.c is for C programs. GCC is not only for Linux; you can compile it for Windows.
I followed the above instruction step by step. After compiling appears a Hello_World.bin file but no .g3a file in the project folder...
Sorry it worked! Thanks! Finally a working example!
prizmos wrote:
Sorry it worked! Thanks! Finally a working example!
What was wrong that you fixed between your two posts? Feel free to keep the questions coming.
my mistake...I have originally replaced “basic:example” with “Hello World”...
prizmos wrote:
my mistake...I have originally replaced “basic:example” with “Hello World”...
Ah, and that didn't work anymore. It should have at least spit out an error message of some sort for you, no?
Maybe it has...I closed the cmd window immediately so I didn't notice. But 3 files were created: 2 in folder build and the .bin file in the project folder.
prizmos wrote:
Maybe it has...I closed the cmd window immediately so I didn't notice. But 3 files were created: 2 in folder build and the .bin file in the project folder.
Oh, you're running under Windows? I recommend that your script that launches make actually contain:
Code:
make
pause
Bump. Any more tutorials? I am working on a bunch right now in my own section. Just wondering if any more are planned.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement