Author Topic: Post your Nspire routines here!  (Read 105191 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 #105 on: August 26, 2010, 03:44:37 pm »
Wow...that is quite amazing.
It sure solves a lot of our problems :D

Offline ExtendeD

  • CoT Emeritus
  • LV8 Addict (Next: 1000)
  • *
  • Posts: 825
  • Rating: +167/-2
    • View Profile
Re: Post your Nspire routines here!
« Reply #106 on: August 26, 2010, 03:46:24 pm »
Nice :) So this is the event loop? There may be other interesting events to listen to, aren't there?
Ndless.me with the finest TI-Nspire programs

Offline Goplat

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 289
  • Rating: +82/-0
    • View Profile
Re: Post your Nspire routines here!
« Reply #107 on: August 26, 2010, 07:02:48 pm »
Event 0x8 is key down, 0x10 is key up. There's also event 0x20, appearing after 5 minutes of idleness, which perhaps is a timer used for automatic power down. I don't (yet) know if or how you can set your own timers.

Some other things of note:

  • Most keys will only generate one key down event per press, but the arrow keys will repeat if held down long enough.
  • The last word in the structure (the one I called "control", but now I see it's more general and would better be called "modifiers") describes what modifier keys are active after this event (Shift = 3, Ctrl = 4, Caps = 0x10).
  • The "key" field is filled in incorrectly for some keys. For example, Q and U both give key code 0x62. Presumably U is supposed to be 0x61 (Shift-U does give 0x61, contrasting with Shift-Q which is still 0x62).
Numquam te deseram; numquam te deficiam; numquam circa curram et te desolabo
Numquam te plorare faciam; numquam valedicam; numquam mendacium dicam et te vulnerabo

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 #108 on: August 27, 2010, 07:05:58 am »
Very nice Goplat!  Thank you for posting. :D

EDIT: I have been playing around with the Makefile included with Ndless 1.1 in order to make it compatible with including the headers from the skeleton.  I have successfully made it include the header files in the "./headers" directory, but it dosen't like the "./system" directory, complaining of missing files which are incompatible when replaced.  I have attached 1. An edited copy of the Makefile for Windows, 2. An edited copy of nspire-gcc for including the right headers, and 3. An edited copy of nspire-as for including the right headers. I am working on getting it to include the system files from the skeleton, but for now, it just uses the ones in Ndless (they are included from nspire-ld).  The Makefile should replace the Makefile in the skeleton directory, and nspire-gcc and nspire-as should replace those in the Ndless /bin directory.  All three of the needed files are included in the zip attached.
« Last Edit: August 27, 2010, 08:45:38 am by apcalc »


Offline fb39ca4

  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1749
  • Rating: +60/-3
    • View Profile
Re: Post your Nspire routines here!
« Reply #109 on: August 29, 2010, 12:40:04 pm »
Is there a way to write a masked sprite routine that uses memcpy? I have a routine, but its based on the old routine.

Offline bwang

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 634
  • Rating: +30/-11
    • View Profile
Re: Post your Nspire routines here!
« Reply #110 on: August 29, 2010, 01:32:17 pm »
@apcalc: if you'll post a known working version of the skeleton for Ndless 1.1, I'll attach it to the OP. Thanks in advance!
@fb39ca4: Hmm...can you explain what a masked sprite is? I'm not so good with sprites and such :(

_player1537

  • Guest
Re: Post your Nspire routines here!
« Reply #111 on: August 29, 2010, 01:34:29 pm »
Imo, it will write to the screen only what you say to. Such as, it will not overwrite the entire area of the sprite, it will only overwrite what you tell it to overwrite.

Offline fb39ca4

  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1749
  • Rating: +60/-3
    • View Profile
Re: Post your Nspire routines here!
« Reply #112 on: August 29, 2010, 01:43:15 pm »
@bwang: A sprite mask determines which pixels in an image are transparent, so those pixels don't get copied to the screen. There is a more detailed explanation here. There are two ways to do this: create a second buffer with the mask data, or have one color in the image represent transparent.

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 #113 on: August 29, 2010, 03:41:07 pm »
Having one color represent transparency is probably the best way to go, because the Nspire can only display 15 shades of gray. And I doubt using memcpy would work (especially because there are two pixels per byte)
"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 #114 on: August 29, 2010, 04:23:49 pm »
Well then, here's my masked sprite function:
Code: [Select]
void masksprite(char* scrbuf, char* sprite, int x, int y, int w, int h)
{
  int i, j;
  for (i = 0; i < w; i++) {
    for (j = 0; j < h; j++) {
      if (sprite[i + w * j] < 16) {
        setPixelBuf(scrbuf, i + x, j + y, sprite[i + w * j]);
      }
    }
  }
}
Any value over 15 in the sprite will be treated as transparent.
« Last Edit: August 29, 2010, 04:26:14 pm by fb39ca4 »

Offline bwang

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 634
  • Rating: +30/-11
    • View Profile
Re: Post your Nspire routines here!
« Reply #115 on: September 04, 2010, 12:44:21 pm »
I've attached skeleton-static-1.0.0.zip. This experimental version has all of the routines compiled into a static library. The Makefile links against this library, instead of compiling all those .c files. As such, the .c source for the libraries have been moved to the directory src/, and all of the .h files have been moved to the directory headers/.
Try it and see if it works!

Offline Goplat

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 289
  • Rating: +82/-0
    • View Profile
Re: Post your Nspire routines here!
« Reply #116 on: September 04, 2010, 02:43:48 pm »
Thanks bwang. I've been meaning to criticize some of the Nspire C code that's going around, having it all in one place makes that easier :)

console.c
Has no protection against writing past the end of buf. Also, I think scrbuf is unnecessary; drawing directly to A4000100 should be fine. It shouldn't flicker; flicker comes from drawing to the same part of the screen in multiple passes. For example, if you first draw a background and then draw a sprite on top of that, there's a brief period of time when the sprite isn't there. Since putChar works in a single pass, it's just fine to use it directly on the screen.

dirlist.c
This is a bad function even in concept - the caller has no way to know how big an array to allocate for result unless it has already enumerated the directory itself.

screen.c
Looks ok.

string.c
itoa, strlen, strcpy, strcmp: Looks ok.
atoi: Doesn't conform to the C standard. Should allow initial whitespace characters (i.e. space, tab, line feed, vertical tab, form feed, and carriage return), and should stop at the first non-digit. A standards-conforming implementation of atoi exists in the TI OS at address 1018DC44 (non-CAS) or 1018D94C (CAS).

syscalls.c
What the heck is this?

utils.c
rect_intersect, refresh, clearScreen, clearBuf, setPixel, setPixelBuf, getPixel, getPixelBuf, rand, showSimpleDialogBox: Looks ok.
fade: The loop is one byte too short. Should start with i = 0.
scrollScreen: Works, but there is no reason why such a function should require a temporary buffer. Just use memmove (address 1018606C in the non-CAS OS, 10185D74 in the CAS OS):
Code: [Select]
memmove(scrbuf, scrbuf + bytesOffset, cpysize);
memset(scrbuf + cpysize, 0xFF, bytesOffset);
scrollScreenDown: Doesn't work, probably will crash. This should be done as:
Code: [Select]
memmove(scrbuf + bytesOffset, scrbuf, cpysize);
memset(scrbuf, 0xFF, bytesOffset);
scrollScreenUp: Function is identical to scrollScreen. No reason both should exist.
filesize, getch: Looks ok.
Numquam te deseram; numquam te deficiam; numquam circa curram et te desolabo
Numquam te plorare faciam; numquam valedicam; numquam mendacium dicam et te vulnerabo

Offline bwang

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 634
  • Rating: +30/-11
    • View Profile
Re: Post your Nspire routines here!
« Reply #117 on: September 04, 2010, 05:00:52 pm »
I haven't a clue what syscalls.c is. It came with Ndless.
I didn't have memmove when I wrote scrollScreen(). I'll fix that in a bit.
I'll add the OS calls for memmove and atoi.
How do you suggest I check for overflow in dirlist and console? Right now when I use those functions I just allocate a really big buffer.

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 #118 on: September 04, 2010, 06:01:15 pm »
I actually think it might be advantageous to make our own optimized memcpy, mommove, and memset routines for the Ndless library, because the versions in the OS can be very slow (it does it byte-by-byte in all cases)
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman

Offline bwang

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 634
  • Rating: +30/-11
    • View Profile
Re: Post your Nspire routines here!
« Reply #119 on: September 04, 2010, 06:38:29 pm »
Fixed some stuff. New folder is attached.