So I decided to get into learning C so I can program for the CE. I have prior experience with some syntactically similar languages (PHP, JS, Java). I'll use this thread to post snippets of my first C project, a rewrite of my Polynomial math tool, and let you all comment/suggest other ways/or answer questions I may have.

To start:

Code:
#include <../../include/ce/c/tice.h>


int main(){
/* Variable Declarations */
   bool canRoll;
   bool canScore;
   int comboScores[13];
   bool comboScored[13];
   /* Code Start */
   boot_ClearVRAM();

   pgrm_CleanUp();

}
You may want to try actually using the toolchain, other than whatever that is. Wink
MateoConLechuga wrote:
You may want to try actually using the toolchain, other than whatever that is. Wink


I actually have it, but so far I'm keeping things small. Can you include all the files in it in one command?
ACagliano wrote:
MateoConLechuga wrote:
You may want to try actually using the toolchain, other than whatever that is. Wink


I actually have it, but so far I'm keeping things small. Can you include all the files in it in one command?

No, I mean; you have the main function returning an int. It's supposed to be void; all the examples will help you there. No, the point of include files is to be like that Smile
Oh cool, I found it. Now basically if i want graphics I want the graphics lib and if i want key interactions, i need the key lib. Smile
Make sure you edit the makefile for your program or else it won't compile correctly.
seanlego23 wrote:
Make sure you edit the makefile for your program or else it won't compile correctly.


Actually, Im using the development environment in XCode to build my project. I can create symlinks to the files I need and XCode can handle that when compiling.

On a related note, some questions:

1.

Code:
int SaveFile = ti_Open("YahtSav","r+");


Do I have to declare "int"? Can I use strings in the function, rather than declare them separately?


2. How exactly do we use the graphc/graphx libraries? If I'm not looking to do actual tilemapping, but toss a few sprites on the screen, should I use x?
Look at the examples on how to do things properly please Smile
ACagliano wrote:

On a related note, some questions:

1.
Code:
int SaveFile = ti_Open("YahtSav","r+");


Do I have to declare "int"? Can I use strings in the function, rather than declare them separately?


2. How exactly do we use the graphc/graphx libraries? If I'm not looking to do actual tilemapping, but toss a few sprites on the screen, should I use x?

I'd use the graphx library because it's better and more updated. Use the Sprite functions for sprites and the tilemapping functions for tilemaps.
Thanks sean!

MateoConLechuga wrote:
Look at the examples on how to do things properly please Smile

I did look at examples. My inexperience with C is what lends to me not fully seeing, at least at first, why and what is being done. Some people need to see that just bc a question is asked that they see as shown in examples, that to a relative novice, it may not be so easy to understand! :p
This is my first time EVER touching C, though I have used some similar languages, but not exactly the same.

On a somewhat unrelated note, how the current setup requires the libs and libload on calc, can the same be accomplished by making the libs source in C, and actually compiling them such that only the source needs the libs, not the calc?
ACagliano wrote:

On a somewhat unrelated note, how the current setup requires the libs and libload on calc, can the same be accomplished by making the libs source in C, and actually compiling them such that only the source needs the libs, not the calc?

Not that I know of because the libs are made such that all the commands are found in certain places so the calculator needs to be able to find them and it can't without them existing on the Calc and having the libload also.
Ah ok. I would think you could somehow put in a link to the location of all things on the calc in the C include stuff, but maybe I'm not understanding how it works.

Edit: If I'm using stuff only in the tice.h file, but not the libs, the resulting program doesnt need the libs, right?

Edit 2: Can you compile a program that *can* use the libs, but if they aren't present, can still run?

In other news, this shell script is spazzing on the mv command.

Code:
SRC="http://myimages.wikidot.com/local--files/start/CEdev.zip"
LIBS="http://myimages.wikidot.com/local--files/start/clibraries.zip"
CEDEV="/Users/acagliano/Desktop/ClrHome stuff/TI-84+ CE/CEdev/"

# Download and extract mains
cd ~/Desktop
wget $SRC
unzip CEdev.zip
cd CEdev
mv -v ~/Desktop/CEdev/* $CEDEV

Am I being dumb here? Why is mv not working?
ACagliano wrote:
so say i want to create a C routine, input, where the only argument is a location to store the input string to. is the setup input( *location) or input (&location)? string should be const char, iirc?

KermMartian wrote:
A const char is a character that cannot be mutated. For example, const char my_char = 'a';. Strings are arrays of characters. Rather than char[], they're usually represented as char*, because arrays are pointers and pointers are arrays.

ACagliano wrote:
so just char. that works. tnx. learning a new language is always a trip :p

KermMartian wrote:
No.


A string would be a char*, as I said, so you might have something like char* mutable_string; or const char* const_string = "Can't change this";. In your case, you'd want either a char** (a pointer to a string, also known as a pointer to an array of characters or a pointer to a pointer to a character) that you could modify, and to access its content, you'd dereference it with * (a la char** location; input(location); do_stuff_with(*location);). Another option would be to use a char*, but pass it by reference: char* location; input(&location); do_stuff_with(location);.
KermMartian wrote:

A string would be a char*, as I said, so you might have something like char* mutable_string; or const char* const_string = "Can't change this";. In your case, you'd want either a char** (a pointer to a string, also known as a pointer to an array of characters or a pointer to a pointer to a character) that you could modify, and to access its content, you'd dereference it with * (a la char** location; input(location); do_stuff_with(*location);). Another option would be to use a char*, but pass it by reference: char* location; input(&location); do_stuff_with(location);.

Alright that helps. I chose the latter one bc i've seen it before. Am I correct in saying the following are true?

Code:
location++;    \* increment address pointed to by location *\
&location = value;    \* Set value at pointed address to value *\


Or is that backwards? Also I looked into the header/lib files and there seems to be no already-made string input routine. That's a bummer. Not that I can't make one.
ACagliano wrote:

Alright that helps. I chose the latter one bc i've seen it before. Am I correct in saying the following are true?

Code:
location++;    \* increment address pointed to by location *\
&location = value;    \* Set value at pointed address to value *\


Or is that backwards? Also I looked into the header/lib files and there seems to be no already-made string input routine. That's a bummer. Not that I can't make one.

If the variable location is a pointer then if I'm correct, replace the & with *. If I had a computer in front of me, I could confirm it for you, but I don't so... I hope I'm right.
Well lets put it this way. Take Axe for instance. How L1 can be expressed with either L1, which may have a value of $6D4E, or as {L1} which is the value at $6D4E. I assume that in my example:

location = whatever the address is
*location = the value at that address
But what I dont understand is what does the & mean? Why did Kerm's example have two *'s? Why do you put the * on the char declaration, not the variable itself? Does putting it as char* variable tell it to make variable a pointer, and that's like the only case you'd do that?

Other TI-related questions.
1. os_PutStrFull and os_FontDrawText -- do they both draw to the screen, or does C differentiate between home and graph?

2. If I use a C float type to do floating point math, when the program runs on the calculator, will the calculator handle the floating point math right?

I know I had more questions but I can remember them rn.
Your location variable is still stored at an address. Say it's stored at $8000. Since it is a pointer, which is denoted as * when you declare the variable, that means the address $8000 holds the address of another variable, when location becomes defined. So:

Code:
char* location;     //defines location as a variable at address $8000
*location = &value;     //stores the address of value in the location pointer.
location;     //the address of location
*location;      //the address location points to

The & symbol denotes the address of a variable. The double pointer, denoted as **, means a variable is a pointer that points to another pointer that points to a variable. So:

Code:
char** doubleP;
**doubleP = &location;

I think that's the correct syntax because the address of location, which holds the address of the variable value, is stored into the double pointer variable doubleP. So doubleP points to location which points to value.

1. I don't know how to answer those questions because I don't use those functions ever.

2. It should run correctly. Can you give an example of what kind of math you're talking about. Smile
seanlego23 wrote:
2. It should run correctly. Can you give an example of what kind of math you're talking about. Smile

Thanks for all the stuff about pointers. Think I understand now. In your example above, does value already need to be declared?
As for what I cited above, have you seen/used/heard of my "Polynomials All-In-One" tool? If not, it's at http://clrhome.org/products/#polyaiov3. I want to rewrite this tool in C for the CE.
ACagliano wrote:
seanlego23 wrote:
2. It should run correctly. Can you give an example of what kind of math you're talking about. Smile

Thanks for all the stuff about pointers. Think I understand now. In your example above, does value already need to be declared?
As for what I cited above, have you seen/used/heard of my "Polynomials All-In-One" tool? If not, it's at http://clrhome.org/products/#polyaiov3. I want to rewrite this tool in C for the CE.
Yes I should have declared value so confusion wasn't a problem. Oops.
No I have never used your Polynomial program, probably because I don't have a TI-83+, which I'm assuming that's what it's on considering that's what the website said. Since this is done in TI-Basic, it shouldn't be that hard to rewrite to C for the CE. I recommend using Mateo's toolchain.
Ok, so here is the start of my input routine:


Code:
void input(&polyIn) {
    while (os_getCSC() != skEnter){
        int key;
        key = os_getCSC();
        if (key < skAdd){
            if (key == skLeft){
                /* move typer left */
            }
            if (key == skRight){
                /* move typer right */
            }
        } else {
            /* append character to input memory */
            const char inRef = "+-*/^ _369)";
        }     
    }
}

I still have yet to do most of it, but the plan is to use the getCSC code as an offset to reference the character typed in inRef, which will then be written to *polyIn. I still have yet to complete the inRef list, but hit a snag. How do you express tokens, like (-) and tan( and others in C? Better yet, is there a better way to do this?
  
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
» Goto page 1, 2, 3, 4, 5, 6  Next
» View previous topic :: View next topic  
Page 1 of 6
» 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