Omnimaga

Calculator Community => TI Calculators => Calculator C => Topic started by: Zerbob on January 05, 2012, 06:02:55 pm

Title: A few questions about Nspire C programming
Post by: Zerbob 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):
That's about it, I know those are quite noobish questions but being noobish is my nature, I can't help it. :-[
Title: Re: A few questions about Nspire C programming
Post by: ExtendeD 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 (http://ourl.ca/14731) 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 (http://hackspire.unsads.com/wiki/index.php/Memory-mapped_I/O_ports#A4000000_-_Internal_SRAM)
* Timers (http://hackspire.unsads.com/wiki/index.php/Memory-mapped_I/O_ports#900D0000_-_Second_timer) 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).
Title: Re: A few questions about Nspire C programming
Post by: Jim Bauwens 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 :)
Title: Re: A few questions about Nspire C programming
Post by: Zerbob 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).
Title: Re: A few questions about Nspire C programming
Post by: lkj 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.
Title: Re: A few questions about Nspire C programming
Post by: ExtendeD on January 07, 2012, 05:22:57 am
These types are actually provided by stdint.h, which is included by Ndless's headers.
Title: Re: A few questions about Nspire C programming
Post by: Zerbob 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.
Title: Re: A few questions about Nspire C programming
Post by: ExtendeD 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.
Title: Re: A few questions about Nspire C programming
Post by: Zerbob 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 ?
Title: Re: A few questions about Nspire C programming
Post by: ExtendeD on January 07, 2012, 12:17:02 pm
argv[0] is the full path of the program being run.
Title: Re: A few questions about Nspire C programming
Post by: Zerbob 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).
Title: Re: A few questions about Nspire C programming
Post by: ExtendeD on January 07, 2012, 06:16:16 pm
Good luck, don't hesitate to share any work in progress.
Title: Re: A few questions about Nspire C programming
Post by: njaddison 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?
Title: Re: A few questions about Nspire C programming
Post by: Lionel Debroux 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.