Author Topic: Post your Nspire routines here!  (Read 98465 times)

0 Members and 1 Guest are viewing this topic.

Offline bwang

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 634
  • Rating: +30/-11
    • View Profile
Re: Post your Nspire routines here!
« Reply #30 on: May 23, 2010, 10:14:37 pm »
Thanks to bwang, to access time use
Code: [Select]
int time = * (unsigned*) 0x90090000
Since that is memory-mapped hardware, you need to use * (volatile unsigned*)
Really? yoshi13 tells me just * (unsigned*) worked.

Offline calc84maniac

  • eZ80 Guru
  • Coder Of Tomorrow
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2912
  • Rating: +471/-17
    • View Profile
    • TI-Boy CE
Re: Post your Nspire routines here!
« Reply #31 on: May 23, 2010, 10:16:36 pm »
If you have optimization enabled, a loop that waits for this time value to reach a certain amount will probably optimize so 0x90090000 is only read once and that value is compared for the rest of the loop. Using "volatile" will guarantee that the memory will literally be read every time it is referenced.
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman

Offline fb39ca4

  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1749
  • Rating: +60/-3
    • View Profile
Re: Post your Nspire routines here!
« Reply #32 on: June 16, 2010, 02:59:48 pm »
I'm having trouble compiling with the skeleton environment. I was able to successfully compile the Ndless demo, whereas Bwang's raycaster and a small test program I wrote won't compile. It seems to not be loading the headers properly.

Here is the code:
Code: [Select]
#include <os.h>
#include <common.h>
#include <utils.h>

asm(".string \"PRG\"\n");

int main()

{
  int antx = 160;
  int anty = 120;
  int dir = 1;
 
  while (!isKeyPressed(KEY_NSPIRE_ESC)) {
    if (getpixel(antx,anty) == 15) {
      setpixel(anty,antx,0);
      dir = dir - 1;
      }
    else {
      setpixel(anty,antx,15);
      dir = dir + 1;
      }
    if (dir == 0)
      dir = 4;
    else if (dir == 5)
      dir = 1;
    if (dir == 1)
      antx = antx - 1;
    else if (dir == 2)
      anty = anty + 1;
    else if (dir == 3)
      antx = antx + 1;
    else
      anty = anty - 1;
    if (antx == 0)
      antx = 320;
    else if (antx == 321)
      antx = 1;
    if (anty == 0)
      anty = 240;
    else if (anty ==  241)
      anty = 1;
   }
   return 0;
}

And the the full output:
Code: [Select]
arm-elf-gcc -mcpu=arm7tdmi -O3 -Wall -W -fpie -fno-merge-constants -c -I./header
s -D NON_CAS main.c
In file included from ./headers/os.h:17,
                 from main.c:1:
./headers/common.h:62:20: warning: missing whitespace after the macro name
./headers/common.h:71:22: warning: missing whitespace after the macro name
./headers/common.h:114:20: warning: missing whitespace after the macro name
./headers/common.h:114:1: warning: "KEY_NSPIRE_" redefined
./headers/common.h:62:1: warning: this is the location of the previous definitio
n
./headers/common.h:116:20: warning: missing whitespace after the macro name
./headers/common.h:116:1: warning: "KEY_NSPIRE_" redefined
./headers/common.h:114:1: warning: this is the location of the previous definiti
on
main.c: In function 'setPixel':
main.c:23: warning: implicit declaration of function 'getpixel'
main.c:24: warning: implicit declaration of function 'setpixel'
main.c:52: warning: 'return' with a value, in function returning void
main.c: In function 'main':
main.c:53: error: expected declaration or statement at end of input
make: *** [main.o] Error 1

If it matters, I'm using the arm-elf-gcc version of yagarto.

Offline bwang

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 634
  • Rating: +30/-11
    • View Profile
Re: Post your Nspire routines here!
« Reply #33 on: June 16, 2010, 04:48:31 pm »
Fixed code:
Code: [Select]
#include <os.h>
//notice the quotes around utils.h
#include "utils.h"

asm(".string \"PRG\"\n");

int main()
{
  int antx = 160;
  int anty = 120;
  int dir = 1;

  while (!isKeyPressed(KEY_NSPIRE_ESC)) {
    if (getPixel(antx,anty) == 15) {
      setPixel(anty,antx,0);
      dir = dir - 1;
      }
    else {
      setPixel(anty,antx,15);
      dir = dir + 1;
      }
    if (dir == 0)
      dir = 4;
    else if (dir == 5)
      dir = 1;
    if (dir == 1)
      antx = antx - 1;
    else if (dir == 2)
      anty = anty + 1;
    else if (dir == 3)
      antx = antx + 1;
    else
      anty = anty - 1;
    if (antx == 0)
      antx = 320;
    else if (antx == 321)
      antx = 1;
    if (anty == 0)
      anty = 240;
    else if (anty ==  241)
      anty = 1;
   }
   return 0;
}
I also updated skeleton.zip to use willrandship's common.h, as well as some other minor changes.
« Last Edit: June 16, 2010, 04:51:01 pm by bwang »

Offline fb39ca4

  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1749
  • Rating: +60/-3
    • View Profile
Re: Post your Nspire routines here!
« Reply #34 on: June 17, 2010, 06:24:32 pm »
I tried that, and I'm still getting the same error message.

-Edit: I feel so stupid! The problem with the getPixel and setPixel was me not capitalizing the P. Now, I get the demo.bin and demo.elf files, but maketns won't work. Here's the error message:

Code: [Select]
process_begin: CreateProcess(C:\Users\Amar\Desktop\skeleton\tools\MakeTNS\MakeTNS, ./tools/MakeTNS/MakeTNS demo.bin demo-noncas.tns, ...) failed.
make (e=193): Error 193
make: *** [demo] Error 193
« Last Edit: June 17, 2010, 06:39:59 pm by fb39ca4 »

Offline bwang

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 634
  • Rating: +30/-11
    • View Profile
Re: Post your Nspire routines here!
« Reply #35 on: June 18, 2010, 01:19:00 am »
What does manually running the MakeTNS command do?
yoshi13 said he installed mingw first, then msys.
« Last Edit: June 18, 2010, 01:21:21 am by bwang »

Offline fb39ca4

  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1749
  • Rating: +60/-3
    • View Profile
Re: Post your Nspire routines here!
« Reply #36 on: June 18, 2010, 09:48:57 am »
Windows says its not a valid program. I am not using minGW or msys, just yagarto and yagarto-tools.
« Last Edit: June 18, 2010, 09:49:59 am by fb39ca4 »

Offline bwang

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 634
  • Rating: +30/-11
    • View Profile
Re: Post your Nspire routines here!
« Reply #37 on: June 18, 2010, 04:02:40 pm »
Hmmm...my fault :( The MakeTNS in the skeleton is a Linux version. Go get a fresh copy of Ndless and copy the MakeTNS in it to the appropriate directory.
I shall fix the skeleton when I have time.
EDIT: Fixed!
« Last Edit: June 18, 2010, 04:11:50 pm by bwang »

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55941
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Post your Nspire routines here!
« Reply #38 on: June 18, 2010, 05:38:04 pm »
Nice to see an update (and to see you return), bwang ^^

Offline fb39ca4

  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1749
  • Rating: +60/-3
    • View Profile
Re: Post your Nspire routines here!
« Reply #39 on: June 19, 2010, 12:22:20 pm »
I replaced makeTNS and it worked! My test program was a Langton's Ant, which runs crazy fast! Now my only problem is that the calc crashes when I press esc. Anyone know why that's happening?

Offline bwang

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 634
  • Rating: +30/-11
    • View Profile
Re: Post your Nspire routines here!
« Reply #40 on: June 19, 2010, 04:59:06 pm »
You might be running out of bounds with your setPixel().

Offline calc84maniac

  • eZ80 Guru
  • Coder Of Tomorrow
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2912
  • Rating: +471/-17
    • View Profile
    • TI-Boy CE
Re: Post your Nspire routines here!
« Reply #41 on: June 19, 2010, 07:52:32 pm »
Yeah, looking at that code, you getPixel(antx,anty) but setPixel(anty,antx,color). Is it supposed to be x,y or y,x?
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman

Offline fb39ca4

  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1749
  • Rating: +60/-3
    • View Profile
Re: Post your Nspire routines here!
« Reply #42 on: June 20, 2010, 07:20:18 pm »
Oh, I think the code I posted was an old version. My current version fills the whole screen.

Offline bwang

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 634
  • Rating: +30/-11
    • View Profile
Re: Post your Nspire routines here!
« Reply #43 on: June 20, 2010, 07:51:34 pm »
If your pixels travel out of the screen and you don't check the bounds, you will get a crash.

Offline bwang

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 634
  • Rating: +30/-11
    • View Profile
Re: Post your Nspire routines here!
« Reply #44 on: June 21, 2010, 01:59:55 am »
Hmmm...I have to doublepost :(
I edited the first post and attached some possibly useful fast (addition only) circle and line routines.