Author Topic: A few questions about Nspire C programming  (Read 7700 times)

0 Members and 1 Guest are viewing this topic.

Offline Zerbob

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 5
  • Rating: +0/-0
    • View Profile
A few questions about Nspire C programming
« on: January 05, 2012, 06:02:55 pm »
Hello, I've just started programming on TI-Nspire and I'd like to ask a few questions. I know there's documentation on hackspire but it's not always clear (such as, does this particular piece of information refer to ndless 1,2 or 3 etc), besides I don't know much about hardware and direct access to memory (I usually program in OCaml ;D ).
So, here are my questions (for some of them I could just check the source code, I know):
  • os.h seems to be the only necessary file to include. Is there anything else I might want to use or is the whole of libndls and the stdlib in os.h? A lot of programs have an "utils.h" include directive, but it isn't in the sdk - is it replaced by something else?
  • Do you need to do something particular when entering/exiting the program (saving and restoring the screen, disabling some os function...)? All my test programs trigger a reboot in nspire_emu at exit...
  • When should I use TCT_Local_Control_Interrupts (or anything related to interrupts)?
  • Is there any graphics library available? or some project I could contribute to?
  • (if the answer to last question is no) How to actually write on the screen? I suppose it is something like that (adding an extra pointer and a memcpy for double buffering):
    unsigned char * scr = (unsigned char*)SCREEN_BASE_ADDRESS;
    *(scr + /*some operation with ints x and y*/) = (unsigned char) color; //how are color coded, by the way?
  • How do you get the time? I gather that you can get the time in seconds with:
    int time = *((volatile int*)0x90090000); //not sure about the types though
    Can you get a more precise value?
  • Are ints 32 or 16 bits?
  • Is there anything to do to have float support? I tried to compile a program with floats using yagarto and I got "undefined reference to __arm__addf" or something like that (I'm on Linux right now I can't check).
  • Unimportant: Did anyone get nspire_emu or ncubate working on 64bits Linux? It crashes when you press I to load the os for me (but i have a dual boot, I don't really need it. Btw, the nspire-gcc script doesn't work out of the box on Ubuntu because packaged versions of gcc have a version number: the script looks for arm-linux-gnueabi-gcc (or ld etc) but it's arm-linux-gnueabi-gcc-4.5 (or 4.6), you've got to edit it manually.).
  • Really unimportant: how do you change your profile with this forum? ???
That's about it, I know those are quite noobish questions but being noobish is my nature, I can't help it. :-[

Offline ExtendeD

  • CoT Emeritus
  • LV8 Addict (Next: 1000)
  • *
  • Posts: 825
  • Rating: +167/-2
    • View Profile
Re: A few questions about Nspire C programming
« Reply #1 on: January 06, 2012, 03:43:07 am »
Welcome Zerbob!

Here a a few answers to your questions.

* os.h is the indeed the only file that needs to be included
* Nothing is needed, Ndless's program loader does this for you. Try to remove as much code as possible to find the problem in your program that crashes, and post your code if you need more help
* Interrupts are disabled when a program is run. Writing to stdout requires the interrupts to be enabled with "TCT_Local_Control_Interrupts(0)", but as this display the OS clock you will only use it for debugging purposes.
* nRGBlib is currently under development. There are also independent initiatives by alberthrocks and totorigolo and to port the SDL library to the TI-Nspire
* The screen format is decribed here
* Timers can also be used. The sleep() function is also available in libndls depending on what you want to do.
* Ints are 32 bits long. I should add the standard types with explicit size to Ndless's headers, I'm not sure they are available through newlib.
* Makes sure *not* to use "-nostdlib" to enable newlib for float numbers support.
* Use Wine to run nspire_emu on Linux
*You should create a symbolic that points from arm-linux-gnueabi-gcc-4.5 to arm-linux-gnueabi-gcc, since this would break the Ndless script anyway each time GCC is updated.

Don't hesitate to edit yourself the Hackspire Wiki if you find some parts incomplete (you need to ask for an account as described on the front page, this protect us from spamming).
« Last Edit: January 06, 2012, 03:45:17 am by ExtendeD »
Ndless.me with the finest TI-Nspire programs

Offline Jim Bauwens

  • Lua! Nspire! Linux!
  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1881
  • Rating: +206/-7
  • Linux!
    • View Profile
    • nothing...
Re: A few questions about Nspire C programming
« Reply #2 on: January 06, 2012, 04:02:49 am »
  • Really unimportant: how do you change your profile with this forum? ???
Just click to "Profile" button in the top bar, and use the left side menu to navigate to different settings pages :)

That's about it, I know those are quite noobish questions but being noobish is my nature, I can't help it. :-[
Don't worry at all, those were very good questions :)

And welcome to Omnimaga!
If you stay here longer, don't hesitate to introduce yourself :)

Offline Zerbob

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 5
  • Rating: +0/-0
    • View Profile
Re: A few questions about Nspire C programming
« Reply #3 on: January 06, 2012, 04:15:27 pm »
Thank you very much for your answers, I don't have much time tonight but I'll probably have some more questions tomorrow.
Just click to "Profile" button in the top bar, and use the left side menu to navigate to different settings pages :)
I saw it just after posting but it wasn't here before (there were only account settings). I suppose you need one post before editing your profile, or you can't do it on your first session (I had created this account quite a while ago but I don't think I had ever used it).

Offline lkj

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 485
  • Rating: +58/-1
    • View Profile
Re: A few questions about Nspire C programming
« Reply #4 on: January 06, 2012, 05:45:59 pm »
* Ints are 32 bits long. I should add the standard types with explicit size to Ndless's headers, I'm not sure they are available through newlib.

uint8_t and so on are available through gcc without newlib, if you mean these.

Offline ExtendeD

  • CoT Emeritus
  • LV8 Addict (Next: 1000)
  • *
  • Posts: 825
  • Rating: +167/-2
    • View Profile
Re: A few questions about Nspire C programming
« Reply #5 on: January 07, 2012, 05:22:57 am »
These types are actually provided by stdint.h, which is included by Ndless's headers.
Ndless.me with the finest TI-Nspire programs

Offline Zerbob

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 5
  • Rating: +0/-0
    • View Profile
Re: A few questions about Nspire C programming
« Reply #6 on: January 07, 2012, 10:34:31 am »
I'm back...
* Use Wine to run nspire_emu on Linux
I followed the tutorial on hackspire (prefacing all comands with "wine"), the program starts but when I press I to load the os image it hangs. The same binaries work fine on Windows.

Apart from that I managed to use the real time clock and to write on the screen using a buffer (i made square that moves every second and bounces on the edges of the screen while fading away and then back, impressing isn't it ?). I think the crashes I got were caused by a memory leak (I accidentally deleted the code...).

I still have questions concerning time handling : if I program a slow paced game (board game or something like that) or a menu I understand I should call the idle function in the main loop to save power, is that the use of it ? Hackspire says "Changing the timer frequency have effects on the latency of this function. " : which timer is that, 0x900D0000 ?
I'd like to use one of the other timers as a more precise real-time clock (I don't care if it loops back to 0 at some point, the purpose is to handle framerate and keypad input with a more precise unit than "iterations").
I gather from hackspire I should : set 0x900D0014 to 0b11111, 0x900D0010 to 31, and read volatile uint16s from 0x900D000C. Does that work ?
Besides, it's written on hackspire that the timer is set to 100Hz but 10 ticks of 32kHz is 3200Hz, is the number false or didn't I understand something ?

Finally, are there any text drawing routines available ? Or should I just use a few dozen sprites ?
Also, does ti nspire computer link modify files or can a program read them just like it works on a pc ? (not that I plan to use it right now but it's worth knowing)

That's it, and thank you for all the answers which I don't doubt will come.

Offline ExtendeD

  • CoT Emeritus
  • LV8 Addict (Next: 1000)
  • *
  • Posts: 825
  • Rating: +167/-2
    • View Profile
Re: A few questions about Nspire C programming
« Reply #7 on: January 07, 2012, 10:43:21 am »
* Try to type I in the nspire_emu console (not the GUI) multiple times.
* Memory leaks shouldn't provoke crashes.
* Yes idle() depends on 0x900D0000.
* Ticks are set to 32 kHz, the timer divider to 10, and the timer value to 32, that makes a 100Hz timer.
* There are text routines available in one of these programs, not sure which ones: http://www.ticalc.org/pub/nspire/asm/
* Computer Link does not modify the file content, just make sure the extension is .tns and you can transfer program data.
« Last Edit: January 07, 2012, 12:15:58 pm by ExtendeD »
Ndless.me with the finest TI-Nspire programs

Offline Zerbob

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 5
  • Rating: +0/-0
    • View Profile
Re: A few questions about Nspire C programming
« Reply #8 on: January 07, 2012, 12:14:41 pm »
* Memory leaks shouldn't provoke crashes.
Well I don't know what the problem was then... likely a seg fault but I can't see why.
* Ticks are set to 32 kHz, the timer divider to 10, and the timer value to 32, that makes a 100Hz timer.
Oh ok I hadn't understood the way the os uses it.
* Computer Link does modify the file content, just make sure the extension is .tns and you can transfer program data.
I suppose you mean "does not"... I made a test program to display the content of a file created on the computer and it worked fine on both my ti and nspire_emu (I took a display routine from some other board, I think it was made by bwang).
The default working directory seems to be Documents. How can I get the program's directory to open files using relative paths ?

Offline ExtendeD

  • CoT Emeritus
  • LV8 Addict (Next: 1000)
  • *
  • Posts: 825
  • Rating: +167/-2
    • View Profile
Re: A few questions about Nspire C programming
« Reply #9 on: January 07, 2012, 12:17:02 pm »
argv[0] is the full path of the program being run.
Ndless.me with the finest TI-Nspire programs

Offline Zerbob

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 5
  • Rating: +0/-0
    • View Profile
Re: A few questions about Nspire C programming
« Reply #10 on: January 07, 2012, 12:52:14 pm »
Thank you. I didn't know you could use argv.
Well I think I'll just play around now and stop annoying you.
I'll come back if I have other questions or if I program anything worthwhile (not quite sure what I want to do for now).

Offline ExtendeD

  • CoT Emeritus
  • LV8 Addict (Next: 1000)
  • *
  • Posts: 825
  • Rating: +167/-2
    • View Profile
Re: A few questions about Nspire C programming
« Reply #11 on: January 07, 2012, 06:16:16 pm »
Good luck, don't hesitate to share any work in progress.
Ndless.me with the finest TI-Nspire programs

Offline njaddison

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 176
  • Rating: +24/-27
    • View Profile
Re: A few questions about Nspire C programming
« Reply #12 on: January 26, 2012, 10:21:22 pm »
Does Nover affect the speed of the ti-84 keypad? and is there a way to make a program like CodeBlocks:: for the nspire for on-calc c programming?
<a href="http://www.nerdtests.com/ft_nt2.php">
<img src="http://www.nerdtests.com/images/badge/nt2/5f42ec78e054645d.png" alt="NerdTests.com says I'm a Highly Dorky Nerd God.  Click here to take the Nerd Test, get geeky images and jokes, and talk to others on the nerd forum!">
</a>


Offline Lionel Debroux

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2135
  • Rating: +290/-45
    • View Profile
    • TI-Chess Team
Re: A few questions about Nspire C programming
« Reply #13 on: January 30, 2012, 02:23:07 am »
Quote
and is there a way to make a program like CodeBlocks:: for the nspire for on-calc c programming?
It was made for the the TI-68k series, with GTC and its IDE, so it's certainly possible for the Nspire.
But that's a lot of work, not just for making an IDE.
Member of the TI-Chess Team.
Co-maintainer of GCC4TI (GCC4TI online documentation), TILP and TIEmu.
Co-admin of TI-Planet.