Author Topic: TI-Nspire: needing help coding under Ndless  (Read 6700 times)

0 Members and 1 Guest are viewing this topic.

SirCmpwn

  • Guest
TI-Nspire: needing help coding under Ndless
« on: October 25, 2010, 05:32:17 pm »
Hello,
Any Npsire developers, it would be awesome if someone could make a quick tutorial to get users up to speed on how to code under Ndless.
I've been able to get code to run, and I know the basics of C based languages (I know C# intimately), but I know nothing of pointers and the like on C.  Aside from a nice tutorial, could someone fill me in on how to use pointers in C?
Also, the showSimpleDialogBox function, I'm not sure how to use it.  I pulled Util.h into my project directory and included it, but gcc says that the reference wasn't found.  My code is just a modified hello world:
Code: [Select]
#include <os.h>
#include "utils.h"

int main(void) {
// required because stdout needs the interrupts currently disabled by Ndless
unsigned intmask = TCT_Local_Control_Interrupts(0);
showSimpleDialogBox("Test", "Hello World!");
TCT_Local_Control_Interrupts(intmask);
return 0;
}
Thanks!
« Last Edit: October 25, 2010, 09:07:37 pm by DJ Omnimaga »

Offline apcalc

  • The Game
  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1393
  • Rating: +120/-2
  • VGhlIEdhbWUh (Base 64 :))
    • View Profile
Re: TI-Nspire
« Reply #1 on: October 25, 2010, 05:55:08 pm »
Sir, showSimpleDialogBox( is probably not working because utils.h was not added as a object in the MakeFile.   Open it up and change the objects to read "main.o utils.o".  That should fix it.


SirCmpwn

  • Guest
Re: TI-Nspire
« Reply #2 on: October 25, 2010, 05:55:47 pm »
Mwahahaha, that worked.  Thank you.
What about pointers?  How would I load an image onto the display, for instance?

Offline kyllopardiun

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 178
  • Rating: +14/-4
  • Kyllopardiun over 2000 results in google.
    • View Profile
    • Kyllo's blog (a blog about poetry, videos and computing)
Re: TI-Nspire
« Reply #3 on: October 25, 2010, 06:10:18 pm »
I don't know about nspire,
but in standart C, a pointer looks like:

int *point  //pointer for integer
and likewise:
 char *champs;

or

double* p1,p2; //In this case both p1 and p2 are pointer...


Hope this can be helpful for you.

SirCmpwn

  • Guest
Re: TI-Nspire
« Reply #4 on: October 25, 2010, 06:11:17 pm »
Thanks!  But what if I know that there is something special at 0x01234567.  How would I get it?

Offline apcalc

  • The Game
  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1393
  • Rating: +120/-2
  • VGhlIEdhbWUh (Base 64 :))
    • View Profile
Re: TI-Nspire
« Reply #5 on: October 25, 2010, 06:13:55 pm »
Is this what you need:

Code: [Select]
*(volatile unsigned*) 0x01234567


SirCmpwn

  • Guest
Re: TI-Nspire
« Reply #6 on: October 25, 2010, 06:14:47 pm »
Okay, could you explain that?
And how do I access the value there?

Offline apcalc

  • The Game
  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1393
  • Rating: +120/-2
  • VGhlIEdhbWUh (Base 64 :))
    • View Profile
Re: TI-Nspire
« Reply #7 on: October 25, 2010, 06:18:57 pm »
That is the notation used to read and write to the memory-mapped I/O Ports (documented on hackspire).  Here is an example for the contrast, 0x900F0020 (Is it sad that I have that memorized :P)

Code: [Select]
//Read the value here
contrast=*(volatile unsigned*) 0x900F0020;
//Write here
*(volatile unsigned*) 0x900F0020=0x90;


SirCmpwn

  • Guest
Re: TI-Nspire
« Reply #8 on: October 25, 2010, 06:25:31 pm »
O, i c wut u did thar.
Thanks!

Offline kyllopardiun

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 178
  • Rating: +14/-4
  • Kyllopardiun over 2000 results in google.
    • View Profile
    • Kyllo's blog (a blog about poetry, videos and computing)
Re: TI-Nspire
« Reply #9 on: October 25, 2010, 06:26:39 pm »
Thanks!  But what if I know that there is something special at 0x01234567.  How would I get it?
you mean this as a memory address?

well, I'll try to give and example to help you figure it out:

Code: [Select]
int main(){
   int *p, a=2,c[10];
   p=&a; //you point to the address of a
  printf("%d",p); //this will print the address as decimal perhaps you would be more likely to get it in %x [hexa]
  printf("%d",*p); //this wil print 2
  p=c; //points p to the first place of the vector
  printf("%d",*(++p)); //this will print some garbage in memory as not was defined in c[1]
  return 0;
  }
}

EDIT: i didn't see the others posts...
« Last Edit: October 25, 2010, 06:39:10 pm by kyllopardiun »

SirCmpwn

  • Guest
Re: TI-Nspire
« Reply #10 on: October 25, 2010, 06:28:00 pm »
Thanks.  I think I understand more.  I've learned low level assembly and high level C#, now I have to meet somewhere in the middle.

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: TI-Nspire: needing help coding under Ndless
« Reply #11 on: October 25, 2010, 09:08:09 pm »
I edited the title of this topic to make it more relevant to its topic.

SirCmpwn

  • Guest
Re: TI-Nspire: needing help coding under Ndless
« Reply #12 on: October 25, 2010, 11:50:17 pm »
So I have the following:
Code: [Select]
unsigned char* p = (unsigned char*)SCREEN_BASE_ADDRESS;
int i;
for (i = 0; i < SCREEN_BYTES_SIZE; ++i)
{
*p = 0xFF;
}
Which should set the entire screen to black.  However, this is not working.  Any ideas?
(I'm still just trying to get a feel for C and Ndless programming)

XD figured out out, 0xF is darkest and 0x0 is lightest.
« Last Edit: October 25, 2010, 11:52:07 pm by SirCmpwn »

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: TI-Nspire: needing help coding under Ndless
« Reply #13 on: October 26, 2010, 02:50:13 am »
Isn't there also a shade of gray that is repeated over 2 values? If I remember, the Nspire is in fact 15 level grayscale, not 16.

SirCmpwn

  • Guest
Re: TI-Nspire: needing help coding under Ndless
« Reply #14 on: October 26, 2010, 08:47:25 am »
Hmm, I didn't know.
So I've started experimenting, and whenever I clear the screen in a loop, it always ends up flickery.  A solution to this would be to use a buffer, but how would I allocate this memory?