Techno-Plaza
Site Navigation [ News | Our Software | Calculators | Programming | Assembly | Downloads | Links | Cool Graphs | Feedback ]
 Main
   Site News

   Our Software

   Legal Information

   Credits

 Calculators
   Information

   C Programming

   Assembly

   Downloads

 Miscellaneous
   Links

   Cool Graphs

   Feedback Form

C Programming Lessons

TIGCC Programming Lessons

The following is part of a series of lessons designed to help teach people how to program in C for the TI-89, 92+, and V200 calculators using TIGCC.

If you wish, you can download the program source code, project files, and binaries here.

Lesson 1 - A Classic Hello World Example

To program in TIGCC, we will need two tools. Setup and installation of these tools will be detailed in the first two steps.

  1. TIGCC. The lessons here use version 0.96 b8. Later versions may or may not be compatible.
  2. TiEmu and AMS image.

Step 1 - Install TIGCC

The first step towards programming C for the TI-89 or 92+ is to install the development environment we will use to create and modify calculator projects. This program is called TIGCC. It is a modified version of the GNU gcc compiler for TI 68k calculators. You can download TIGCC from our archives. Run the setup program and follow the instructions.

In the component section, make sure you have the TIGCC IDE selected. The other selections are optional, and are not currently used in any lessons on Techno-Plaza.

You may have also heard about the TI SDK for calculator development. While it is a perfectly useable alternative, it is not the favored choice for hobbyist programmers. Techno-Plaza has no information on using the official TI SDK.

Step 2 - Install TiEmu

The next step in the process is to install our testing environment. This is a program we can use to test out our software before running it on a real calculator. This has a number of benefits. It saves battery life on your calculator. It is easier to send programs to an emulator than to a real calculator. It has debugging tools that can assist you with software bugs. It also is easier to reset if your program accidentally crashes. You can find TiEmu in our archives.

TiEmu depends upon a set of libraries called GTK+ to run, so we will need to install these first. You can download the installer from our archives.

Once you have both the GTK+ library installer and the TiEmu installer, we can begin by installing the GTK+ libraries. Run the installer and follow the prompts. I recommend leaving all the default values.

Now we can finally install TiEmu. Run the installer and follow the prompts. Again, all the default values should be appropriate.

There is one more thing we require before we can use TiEmu, and that is an AMS image. An AMS image (aka a ROM image) is a copy of the software used by the calculator. There are several ways to get it, but I recommend downloading it from Texas Instruments. TI changes their links pretty often, so you may need to hunt around to find the right page. Currently, the links are TI-89 Titanium AMS Image and Voyage 200 AMS Image. If these links are no longer valid, then just go to TIs website, search for the calculator, and look for AMS, Flash updates, Operating Systems, Downloads, or something similar. I cannot put the images on Techno-Plaza due to legal issues. The current system versions are 3.10 for the TI-89 Titanium and Voyage 200.

Now that we have all our pieces, let's setup TiEmu. Start TiEmu. When the wizard dialog pops up, select the FLASH upgrade option. Select the file you downloaded from TI's website. Once you are done, TiEmu is all ready for use. It will bring up a display that looks just like the calculator (either TI-89 Titanium or Voyage 200) and go to its start screen.

Play around with TiEmu if you like. It is a pretty easy program to use, most of the time. We will come back to it later, but now let's start using TIGCC.

Step 3 - The TIGCC Development Environment

TIGCC is actually a suite a programs that we will use to develop software for our calculator. It has a preprocessor, compiler, assembler, linker, IDE, an extended library, and a ton of documentation of the calculator, assembled programs, and the API. If these things don't mean anything to you right now, don't worry, it's not that important. The part we want to use right now is the TIGCC IDE. So go ahead and start it.

When the program first starts, it will bring up a blank window in the right half of the screen, and a project file chooser on the left side. The top has the menu bar and toolbar controls.

To begin a new project, simply choose File, New, Project from the menu. Since we already had a blank project, this won't seem to do anything, but it's best to make sure we start clean. Now let's make our first program.

The first step is to make a new C source file. Select File, New, C Source File from the menu. On the left side of the window where our "New File" is, right click is and select rename. Rename it to hello.

A lot of stuff will pop up in the code editing window now, but most of it is junk. So let's start by deleting it all. After you have done this replace it with the following.

hello.c


#include <tigcclib.h>

void _main(void) {
    // clear the screen
    ClrScr();

    // print the string at the top left corner of the display
    DrawStr(0, 0, "Hello, World!", A_NORMAL);

    // wait for a key press before the program exits
    ngetchx();
}

Step 4 - Your first TIGCC Program

Now go ahead and save the project under the name hello. The project name will also be the name of the program on the calculator.

Don't worry about understanding what you put in there right now. Let's first take a look at what it does. The first step is to make the program. Select Project, Make and the program will be created.

Now we can test it. To do this, we will use TiEmu. So start TiEmu if you closed it earlier. Take the calculator to the HOME screen if it is not already there. Then, from the TIGCC IDE, choose Debug, Run. If you switch back to TiEmu, you should see the program running. It's a very simple program. It just displays "Hello, World!" at the top of the screen and waits a key press before returning to the HOME screen.

TI-89 Titanium AMS 3.10 hello.89z V200 AMS 3.10 hello.v2z

Step 5 - The Components of a C program

There are at least two components in every C program, the preprocessor section, and the code section.

The preprocessor section contains the lines at the top which are prefixed with a pound '#' sign. For now, most of the preprocessor section will be just a single #include directive. #include directives tell the preprocessor to add the contents of one file into this file before we do anything with it. Our only #include directive in the hello program is to include some file called tigcclib.h. This file is part of the TIGCC library, and has many useful things that we can use to make programs with.

The other section is the code section, which is where we put our program code and tell the calculator what to do. In C, all code is put into segments called functions. These functions comprise our program. The hello program only has one function: _main. The _main function is where all programs start and is required for all TIGCC programs.

Step 6 - In Detail: Analysis of the hello Program

As mentioned above, the _main function is where the program starts. All functions have a return type, a name, and an argument list. The _main function has a void return type, and a void argument list. It's name is _main. A return type is what the function returns, which in our case is nothing. An argument list is information we can give to a function to, kind of like an equation. We don't give anything to _main.

The _main() method has only 3 lines of code. It is a very simple program. Let's examine these lines in more detail so you can get an idea of what they do.

// clear the screen
ClrScr();

All the lines that start with a double // are comments and are ignored. I will use comments to help describe as much as possible.

The next line is the first line of code. It is used to clear the display. ClrScr() is a function used by our hello program. It is a built-in part of the AMS software of the calculator. There are hundreds of these built-in functions we can to help us write programs.

// print the string at the top left corner of the display
DrawStr(0, 0, "Hello, World!", A_NORMAL);

Our next command is another built-in function, DrawStr, short for "draw string". The function takes four arguments. Remember from above that some functions have argument lists and we can supply things to the function. Here, we want to tell it where to draw our string, what string to draw, and how it should be printed.

The 0, 0 are the coordinates where the string will be displayed. In this case, 0,0 refers to the upper left corner of the display. The bottom right corner for the TI-89 is 159,99, and for a TI-92+/V200 239,127. These positions correspond with the number of pixels in the display, 160x100 for the TI-89 and 240x128 for the TI-92+/V200.

The next argument is the string, which is simply "Hello, World!". Finally, the A_NORMAL argument tells DrawStr to draw the string without any kind of effect. DrawStr can do some different kind of string drawing upon request, but we will stick with A_NORMAL for now. You may wish to take a look at the TIGCC documentation for more information. To do that bring up the docs from the start menu, go to the index, and type in DrawStr. Double click it and it will tell you all about the DrawStr function, including all the other drawing effects.

// wait for the user to press a key before the program exits
ngetchx();

This last command is used to get keyboard input. In this instance, we are using it to wait for the user to press a key before the program exits. If we don't stop the program from exiting, it will print the string and go back to the calculator screen so fast, we won't be able to see what happened. So for little programs like these, we will stop the program at the end so we can view the results. So, once the program has displayed the string, it will wait until the user presses a key before exiting.

Step 7 - Review

I hope you have learned something from this lesson. I know it's very basic, but it introduces the basic concepts of programming in the TIGCC environment and using TiEmu to test programs. The next lesson won't be so simple.

Play around with the source. Change things and see what happens. What happens if you change the 0,0 to other numbers. What happens if you don't ClrScr() before printing. Take a look at the TIGCC docs on ClrScr, ngetchx, and DrawStr.

 


Lesson 1: A Classic "Hello World" Example
Questions or Comments? Feel free to contact us.


 

Copyright © 1998-2007 Techno-Plaza
All Rights Reserved Unless Otherwise Noted

Get Firefox!    Valid HTML 4.01!    Made with jEdit