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

0 Members and 2 Guests are viewing this topic.

Online 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: Post your Nspire routines here!
« Reply #60 on: July 06, 2010, 10:00:29 pm »
How do you prevent the flickering, though?

Offline bwang

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 634
  • Rating: +30/-11
    • View Profile
Re: Post your Nspire routines here!
« Reply #61 on: July 06, 2010, 10:01:55 pm »
Hmmm...interesting.
I remember my raycaster flickering like crazy until I got double-buffering working.
Are you doing anything special?

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 #62 on: July 06, 2010, 10:04:07 pm »
Hmmm...interesting.
I remember my raycaster flickering like crazy until I got double-buffering working.
Are you doing anything special?
Well, in my emulators I'm not clearing the buffer and then drawing new graphics. I draw the graphics over the current buffer line-by-line (which is how the systems I'm emulating tend to operate anyway)
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman

Online 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: Post your Nspire routines here!
« Reply #63 on: July 06, 2010, 10:06:41 pm »
oooh I see, that explains why sprites won't flicker while the map is getting displayed. I assume they're drawn at the same time as the map, right?

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 #64 on: July 06, 2010, 10:10:28 pm »
oooh I see, that explains why sprites won't flicker while the map is getting displayed. I assume they're drawn at the same time as the map, right?
That's right. It's how some sprites are able to be displayed behind the map.

Actually, now that I think about it, I do have a very minimal form of double-buffering. In my GBC emulator, I draw the 160 pixels in a line to a small buffer, then copy it to the screen buffer (1 or 2 lines depending on the position, for aspect ratio purposes). In the TI-83+ and TI-89 emulators, there is stored an internal buffer of the emulated screen contents, and it is upscaled onto the screen buffer.
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman

Online 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: Post your Nspire routines here!
« Reply #65 on: July 06, 2010, 10:57:17 pm »
Aaah I see ^^

Nice job on the emus regardless, though

Offline fb39ca4

  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1749
  • Rating: +60/-3
    • View Profile
Re: Post your Nspire routines here!
« Reply #66 on: July 07, 2010, 11:39:38 am »
I've got the buffering all figured out, but it seems like nmath.h is missing from the skeleton. When I tried to compile a program using line, I got an error saying nmath.h doesn't exist.

Offline apcalc

  • The Game
  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1393
  • Rating: +120/-2
  • VGhlIEdhbWUh (Base 64 :))
    • View Profile
Re: Post your Nspire routines here!
« Reply #67 on: July 07, 2010, 11:56:48 am »
I've got the buffering all figured out, but it seems like nmath.h is missing from the skeleton. When I tried to compile a program using line, I got an error saying nmath.h doesn't exist.

I am assuming that the abs( function is from nmath.h (that is the only one that did not "exist").  A simple solution would be to write your own abs( function, get rid of the "#include "nmath.h"" at the top and add your own abs( to the header.  Here is a very basic one I wrote.  I am sure that a smaller and faster version could be written:

Code: [Select]
int abs(int x) {
if (x<0) {
x*=-1;
}
return x;
}
« Last Edit: July 07, 2010, 11:58:13 am by apcalc »


Offline fb39ca4

  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1749
  • Rating: +60/-3
    • View Profile
Re: Post your Nspire routines here!
« Reply #68 on: July 07, 2010, 01:03:52 pm »
How do I use the sprite function, specifically, how would I define the sprite?

Offline apcalc

  • The Game
  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1393
  • Rating: +120/-2
  • VGhlIEdhbWUh (Base 64 :))
    • View Profile
Re: Post your Nspire routines here!
« Reply #69 on: July 07, 2010, 01:09:29 pm »
Declare a sprite like this:

Code: [Select]
              char sprite[32]={15,15,15,0,0,15,15,15,
                                15,15, 0, 0,0, 0,15,15,
                                15, 0, 0, 0, 0, 0, 0,15,
                                 0 , 0, 0, 0, 0, 0, 0, 0};

The number of elements in the array should be equal to the height*width of the sprite.  Each element should be the color you want the pixel to be.  Bwang's sprite drawing functoin takes the syntax:

Code: [Select]
void sprite(char* scrbuf, char* sprite, int x, int y, int w, int h);
Where scrbuf is the buffer, sprite is the spite you want to draw, x is the x coordinate of the sprite, y is the y coordinate, w is the width, and h is the heigth

If you read my first, unedited post, please disregard it b/c some of the info was wrong. :)
« Last Edit: July 07, 2010, 02:09:26 pm by apcalc »


Offline fb39ca4

  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1749
  • Rating: +60/-3
    • View Profile
Re: Post your Nspire routines here!
« Reply #70 on: July 07, 2010, 02:51:36 pm »
Unfortunately, apcalc, I read you unedited post, but now it's all sorted out, and I can play pong on my nspire.  8)

Offline apcalc

  • The Game
  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1393
  • Rating: +120/-2
  • VGhlIEdhbWUh (Base 64 :))
    • View Profile
Re: Post your Nspire routines here!
« Reply #71 on: July 07, 2010, 04:22:34 pm »
Unfortunately, apcalc, I read you unedited post, but now it's all sorted out, and I can play pong on my nspire.  8)

Thats great to hear! I was used to the way you draw sprites on the 89, so I just assumed it was the same way. Feel free to ask if you have any more questions! :)


Offline bwang

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 634
  • Rating: +30/-11
    • View Profile
Re: Post your Nspire routines here!
« Reply #72 on: July 07, 2010, 05:50:04 pm »
That sprite routine is not production ready. It works, but don't use it for anything fancy!
I need to change it to a proper sprite function that copies blocks of memory one row at a time.
I also attached nmath.h/c. Please please please don't use this in sensitive programs! Its slow, poorly written, and not all that accurate (e.g. sine and cosine are approximated with a couple of power series terms) - I was just collecting some routines for personal use. Your mileage with this file will vary, depending on the program.
Here's a nice way to do abs():
Code: [Select]
#define abs(a) (a) > 0 ? (a) : -(a)
« Last Edit: July 07, 2010, 05:56:40 pm by bwang »

Offline apcalc

  • The Game
  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1393
  • Rating: +120/-2
  • VGhlIEdhbWUh (Base 64 :))
    • View Profile
Re: Post your Nspire routines here!
« Reply #73 on: July 07, 2010, 09:41:24 pm »
I've been having a very odd bug with an Nspire C program.  Every time I exit the program pressing ESC (for some reason my loss detection dosen't work) the calculator reboots (the emulator says "CPU Reset") (I have only tried this on the emulator).  All of the other ASM programs I have on the emulator (ncaster, gbc4nspire, ndless demo) work correctly. Also in my code you will see that I have the loss detection commented out.  When I have this part of the code, the calc reboots right after the dialog box displays.  Here is the code:

Code: [Select]
#include <os.h>
#include "utils.h"

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

int main(void) {
  char marker[32]={15,15,15,0,0,15,15,15,15,15,0,0,0,0,15,15,15,0,0,0,0,0,0,15,0,0,0,0,0,0,0,0};
  short int leftx,length,ycord,lengthchange;
  float spritepos;
  char* scrbuf = (char*) malloc(SCREEN_BYTES_SIZE);
  char* tempbuf = (char*) malloc(SCREEN_BYTES_SIZE);
  showSimpleDialogBox("TI-Nspire Tunnel","TI-Nspire Tunnel\nWritten in C by Danny Clark\n\nUse the arrow keys to control ship");
  clearScreen();
  leftx=120,length=120,lengthchange=1000,ycord=0;
  spritepos=180;
  clearBuf(scrbuf);
  for(ycord=0;ycord<SCREEN_HEIGHT;ycord++) {
  horizontalline(scrbuf,0,leftx,ycord,0);
  horizontalline(scrbuf,leftx+length,319,ycord,0);}
  sprite(scrbuf,marker,150,236,8,4);
  refresh(scrbuf);
  leftx=120;
  ycord=0;
  while (!isKeyPressed(KEY_NSPIRE_ESC)) {
  if (isKeyPressed(KEY_NSPIRE_LEFT)) {
  sprite(scrbuf,marker,spritepos,236,8,4);
  spritepos-=0.7;
  sprite(scrbuf,marker,spritepos,236,8,4);}
  if (isKeyPressed(KEY_NSPIRE_RIGHT)) {
  sprite(scrbuf,marker,spritepos,236,8,4);
  spritepos+=0.7;
  sprite(scrbuf,marker,spritepos,236,8,4);}
  sprite(scrbuf,marker,spritepos,236,8,4);
  lengthchange--;
  if (lengthchange==0) {length--;lengthchange=1000;}
  scrollScreen(scrbuf,tempbuf,1);
  horizontalline(scrbuf,0,leftx,ycord,0);
  horizontalline(scrbuf,leftx,leftx+length,ycord,15);
  horizontalline(scrbuf,leftx+length,319,ycord,0);
  sprite(scrbuf,marker,spritepos,236,8,4);
  refresh(scrbuf);
  //if (getPixel(spritepos-1,ycord-3)||getPixel(spritepos+8,ycord-3)) {free(scrbuf);free(tempbuf);return 0;}
  }
free(scrbuf);
free(tempbuf);
return 0;
}


Also, I don't have the code for the function horizontal line there but I am sure that is not the problem because it was defined and used well before I experienced this problem.  This program was working fine earlier today, but I made a few small additons and now I have no idea what is causing this.  Also, I made one small modification to the function "scrollScreen(".  I changed the two signs in the function (+ to - and - to +) to make the screen go down instead of up.
« Last Edit: July 07, 2010, 09:44:11 pm by apcalc »


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 #74 on: July 07, 2010, 09:54:57 pm »
Are you supposed to be able to use floats as arguments to the sprite routine?
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman