Omnimaga: The Coders Of Tomorrow
Welcome, Guest. Please login or register.
 
Omnimaga: The Coders Of Tomorrow
19 May, 2013, 09:05:26 *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   home   news downloads projects tutorials misc forums rules new posts irc about Login Register  
+-OmnomIRC

You must Register, be logged in and have at least 40 posts to use this shout-box! If it still doesn't show up afterward, it might be that OmnomIRC is disabled for your group or under maintenance.

Note: You can also use an IRC client like mIRC, X-Chat or Mibbit to connect to an EFnet server and #omnimaga.

Pages: [1]   Go Down
  Print  
Author Topic: A few questions about Nspire C programming - I'm new to this and a bit confused about a few things...  (Read 1257 times) Bookmark and Share
0 Members and 1 Guest are viewing this topic.
Zerbob
LV1 Newcomer (Next: 20)
*
Offline Offline

Gender: Male
Last Login: 14 January, 2012, 20:34:52
Date Registered: 21 May, 2011, 17:33:24
Location: Paris, France
Posts: 5

Topic starter
Total Post Ratings: 0

View Profile
« on: 06 January, 2012, 01:02:55 »
0

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 Grin ).
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? Huh?
That's about it, I know those are quite noobish questions but being noobish is my nature, I can't help it. Embarrassed
Logged
ExtendeD
Coder Of Tomorrow
LV8 Addict (Next: 1000)
*
Offline Offline

Gender: Male
Last Login: 17 May, 2013, 08:07:39
Date Registered: 02 January, 2010, 13:03:41
Location: France
Posts: 765

Total Post Ratings: +151

View Profile
« Reply #1 on: 06 January, 2012, 10:43:07 »
+1

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: 06 January, 2012, 10:45:17 by ExtendeD » Logged

ndlessly - Progress and insights on Ndless
Ndless / Hackspire - Third-party TI-Nspire development
Jim Bauwens
Lua! Nspire! Linux!
Editor
LV10 31337 u53r (Next: 2000)
*
Offline Offline

Gender: Male
Last Login: Today at 00:21:22
Date Registered: 28 February, 2011, 22:32:12
Location: Belgium
Posts: 1733


Total Post Ratings: +180

View Profile WWW
« Reply #2 on: 06 January, 2012, 11:02:49 »
0

  • Really unimportant: how do you change your profile with this forum? Huh?
Just click to "Profile" button in the top bar, and use the left side menu to navigate to different settings pages Smiley

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

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

Zerbob
LV1 Newcomer (Next: 20)
*
Offline Offline

Gender: Male
Last Login: 14 January, 2012, 20:34:52
Date Registered: 21 May, 2011, 17:33:24
Location: Paris, France
Posts: 5

Topic starter
Total Post Ratings: 0

View Profile
« Reply #3 on: 06 January, 2012, 23:15:27 »
0

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 Smiley
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).
Logged
lkj
LV6 Super Member (Next: 500)
******
Offline Offline

Gender: Male
Last Login: Today at 01:23:53
Date Registered: 07 September, 2011, 20:05:25
Posts: 348

Total Post Ratings: +40

View Profile
« Reply #4 on: 07 January, 2012, 00:45:59 »
0

* 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.
Logged

My Nspire Ndless C projects:
ExtendeD
Coder Of Tomorrow
LV8 Addict (Next: 1000)
*
Offline Offline

Gender: Male
Last Login: 17 May, 2013, 08:07:39
Date Registered: 02 January, 2010, 13:03:41
Location: France
Posts: 765

Total Post Ratings: +151

View Profile
« Reply #5 on: 07 January, 2012, 12:22:57 »
0

These types are actually provided by stdint.h, which is included by Ndless's headers.
Logged

ndlessly - Progress and insights on Ndless
Ndless / Hackspire - Third-party TI-Nspire development
Zerbob
LV1 Newcomer (Next: 20)
*
Offline Offline

Gender: Male
Last Login: 14 January, 2012, 20:34:52
Date Registered: 21 May, 2011, 17:33:24
Location: Paris, France
Posts: 5

Topic starter
Total Post Ratings: 0

View Profile
« Reply #6 on: 07 January, 2012, 17:34:31 »
0

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.
Logged
ExtendeD
Coder Of Tomorrow
LV8 Addict (Next: 1000)
*
Offline Offline

Gender: Male
Last Login: 17 May, 2013, 08:07:39
Date Registered: 02 January, 2010, 13:03:41
Location: France
Posts: 765

Total Post Ratings: +151

View Profile
« Reply #7 on: 07 January, 2012, 17:43:21 »
0

* 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: 07 January, 2012, 19:15:58 by ExtendeD » Logged

ndlessly - Progress and insights on Ndless
Ndless / Hackspire - Third-party TI-Nspire development
Zerbob
LV1 Newcomer (Next: 20)
*
Offline Offline

Gender: Male
Last Login: 14 January, 2012, 20:34:52
Date Registered: 21 May, 2011, 17:33:24
Location: Paris, France
Posts: 5

Topic starter
Total Post Ratings: 0

View Profile
« Reply #8 on: 07 January, 2012, 19:14:41 »
0

* 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 ?
Logged
ExtendeD
Coder Of Tomorrow
LV8 Addict (Next: 1000)
*
Offline Offline

Gender: Male
Last Login: 17 May, 2013, 08:07:39
Date Registered: 02 January, 2010, 13:03:41
Location: France
Posts: 765

Total Post Ratings: +151

View Profile
« Reply #9 on: 07 January, 2012, 19:17:02 »
0

argv[0] is the full path of the program being run.
Logged

ndlessly - Progress and insights on Ndless
Ndless / Hackspire - Third-party TI-Nspire development
Zerbob
LV1 Newcomer (Next: 20)
*
Offline Offline

Gender: Male
Last Login: 14 January, 2012, 20:34:52
Date Registered: 21 May, 2011, 17:33:24
Location: Paris, France
Posts: 5

Topic starter
Total Post Ratings: 0

View Profile
« Reply #10 on: 07 January, 2012, 19:52:14 »
0

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).
Logged
ExtendeD
Coder Of Tomorrow
LV8 Addict (Next: 1000)
*
Offline Offline

Gender: Male
Last Login: 17 May, 2013, 08:07:39
Date Registered: 02 January, 2010, 13:03:41
Location: France
Posts: 765

Total Post Ratings: +151

View Profile
« Reply #11 on: 08 January, 2012, 01:16:16 »
0

Good luck, don't hesitate to share any work in progress.
Logged

ndlessly - Progress and insights on Ndless
Ndless / Hackspire - Third-party TI-Nspire development
njaddison
LV4 Regular (Next: 200)
****
Offline Offline

Gender: Male
Last Login: 15 May, 2013, 02:46:53
Date Registered: 08 November, 2011, 03:56:20
Location: South Carolina(USA)
Posts: 153


Total Post Ratings: -5

View Profile
« Reply #12 on: 27 January, 2012, 05:21:22 »
0

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?
Logged


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!


Lionel Debroux
LV10 31337 u53r (Next: 2000)
**********
Offline Offline

Gender: Male
Last Login: Today at 08:36:08
Date Registered: 17 December, 2009, 09:37:25
Location: France
Posts: 1853

Total Post Ratings: +208

View Profile WWW
« Reply #13 on: 30 January, 2012, 09:23:07 »
0

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.
Logged

Member of the TI-Chess Team.
Co-maintainer of GCC4TI (GCC4TI online documentation), TILP and TIEmu.
Co-admin of TI-Planet.
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by EzPortal
Powered by MySQL Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Powered by PHP
Page created in 0.335 seconds with 30 queries.
Skin by DJ Omnimaga edited from SMF default theme with the help of tr1p1ea.
All programs, games and songs avaliable on this website are property of their respective owners.
Best viewed in Opera, Firefox, Chrome and Safari with a resolution of 1024x768 or above.