Omnimaga
Calculator Community => TI Calculators => General Calculator Help => Topic started 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:
#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!
-
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.
-
Mwahahaha, that worked. Thank you.
What about pointers? How would I load an image onto the display, for instance?
-
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.
-
Thanks! But what if I know that there is something special at 0x01234567. How would I get it?
-
Is this what you need:
*(volatile unsigned*) 0x01234567
-
Okay, could you explain that?
And how do I access the value there?
-
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)
//Read the value here
contrast=*(volatile unsigned*) 0x900F0020;
//Write here
*(volatile unsigned*) 0x900F0020=0x90;
-
O, i c wut u did thar.
Thanks!
-
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:
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...
-
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.
-
I edited the title of this topic to make it more relevant to its topic.
-
So I have the following:
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.
-
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.
-
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?
-
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).
-
For the screenbuffer, use
char* scrbuf = (char*) malloc(SCREEN_BYTES_SIZE);
where scrbuf is the name you want for the pointer to it.
-
To set the screen black:
memset(buffer,0x00,SCREEN_BYTES_SIZE);
And yes, the two darkest shades (0 and 1) are the same on the Nspire.
-
Thanks!