Omnimaga

Calculator Community => TI Calculators => General Calculator Help => Topic started by: SirCmpwn on October 25, 2010, 05:32:17 pm

Title: TI-Nspire: needing help coding under Ndless
Post by: SirCmpwn 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!
Title: Re: TI-Nspire
Post by: apcalc 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.
Title: Re: TI-Nspire
Post by: SirCmpwn 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?
Title: Re: TI-Nspire
Post by: kyllopardiun 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.
Title: Re: TI-Nspire
Post by: SirCmpwn 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?
Title: Re: TI-Nspire
Post by: apcalc on October 25, 2010, 06:13:55 pm
Is this what you need:

Code: [Select]
*(volatile unsigned*) 0x01234567
Title: Re: TI-Nspire
Post by: SirCmpwn on October 25, 2010, 06:14:47 pm
Okay, could you explain that?
And how do I access the value there?
Title: Re: TI-Nspire
Post by: apcalc 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;
Title: Re: TI-Nspire
Post by: SirCmpwn on October 25, 2010, 06:25:31 pm
O, i c wut u did thar.
Thanks!
Title: Re: TI-Nspire
Post by: kyllopardiun 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...
Title: Re: TI-Nspire
Post by: SirCmpwn 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.
Title: Re: TI-Nspire: needing help coding under Ndless
Post by: DJ Omnimaga on October 25, 2010, 09:08:09 pm
I edited the title of this topic to make it more relevant to its topic.
Title: Re: TI-Nspire: needing help coding under Ndless
Post by: SirCmpwn 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.
Title: Re: TI-Nspire: needing help coding under Ndless
Post by: DJ Omnimaga 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.
Title: Re: TI-Nspire: needing help coding under Ndless
Post by: SirCmpwn 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?
Title: Re: TI-Nspire: needing help coding under Ndless
Post by: ExtendeD on October 26, 2010, 12:10:01 pm
Use malloc(), free() and memcpy() (see http://hackspire.unsads.com/wiki/index.php/Syscalls).

For advanced LCD synchronization, calc84maniac could perhaps give you some hints (see http://hackspire.unsads.com/wiki/index.php/Memory-mapped_I/O_ports#C0000000_-_LCD_controller and  http://hackspire.unsads.com/wiki/index.php/Interrupts).
Title: Re: TI-Nspire: needing help coding under Ndless
Post by: fb39ca4 on October 26, 2010, 03:49:49 pm
For the screenbuffer, use
Code: [Select]
char* scrbuf = (char*) malloc(SCREEN_BYTES_SIZE);where scrbuf is the name you want for the pointer to it.
Title: Re: TI-Nspire: needing help coding under Ndless
Post by: apcalc on October 26, 2010, 06:06:56 pm
To set the screen black:

Code: [Select]
memset(buffer,0x00,SCREEN_BYTES_SIZE);

And yes, the two darkest shades (0 and 1) are the same on the Nspire.
Title: Re: TI-Nspire: needing help coding under Ndless
Post by: SirCmpwn on October 26, 2010, 07:09:23 pm
Thanks!