Libndls: Difference between revisions

From Hackspire
Jump to navigation Jump to search
(Created)
 
(Add sleep())
Line 1: Line 1:
''libndls'' is a set of macros and functions available as a [http://en.wikipedia.org/wiki/Static_library static library] when building with Ndless.
''libndls'' is a set of macros and functions available as a [http://en.wikipedia.org/wiki/Static_library static library] when building with Ndless. The library is automatically linked by <tt>nspire-ld</tt> if required.


These definitions are available in Ndless 1.7. Definitions marked with (C) are only available in C. Definitions marked with (asm) are only available in assembly.
These definitions are available in Ndless 1.7. Definitions marked with (C) are only available in C. Definitions marked with (asm) are only available in assembly.
Line 21: Line 21:


==Time==
==Time==
*<tt>void idle(void)</tt>: switch to low-power state until the next interrupt occurs. The use of this function is encouraged when waiting in loops for something to save the batteries.
*<tt>void idle(void)</tt>: switch to low-power state until the next interrupt occurs. The use of this function is encouraged when waiting in loops for an event to save the batteries.
*<tt>void sleep(unsigned m)</tt>: delay for a specified amount of time. The CPU is regularly switched to low-power state while blocking.


==Debugging==
==Debugging==
*<tt>void halt(void)</tt>: stops the execution flow with an endless loop. If you are using the [http://www.omnimaga.org/index.php?topic=4280.0 Ncubate] emulator, use the <tt>j</tt> debugger command to jump over the instruction.
*<tt>void halt(void)</tt>: stops the execution flow with an endless loop. If you are using the [http://www.omnimaga.org/index.php?topic=4280.0 Ncubate] emulator, use the <tt>j</tt> debugger command to jump over the instruction.
*<tt>halt</tt> (asm) (macro): similar to <tt>halt()</tt>
*<tt>halt</tt> (asm) (macro): similar to <tt>halt()</tt>

Revision as of 20:45, 28 October 2010

libndls is a set of macros and functions available as a static library when building with Ndless. The library is automatically linked by nspire-ld if required.

These definitions are available in Ndless 1.7. Definitions marked with (C) are only available in C. Definitions marked with (asm) are only available in assembly.

Common types

  • typedef enum bool {FALSE = 0, TRUE = 1} BOOL;

Math

  • number abs(number)
  • number min(number, number)
  • number max(number, number)

Screen

  • SCREEN_BASE_ADDRESS: address of the screen buffer. Each grayscaled pixel is 4-bit long. 1111 is white, 0000 is black.
  • SCREEN_BYTES_SIZE: size of the screen buffer
  • SCREEN_WIDTH: screen width in pixels
  • SCREEN_HEIGHT: screen height in pixels

Keyboard

isKeyPressed(key): non-blocking key press test. key must be one of the KEY_NSPIRE_* constants defined in ndls.h.

Time

  • void idle(void): switch to low-power state until the next interrupt occurs. The use of this function is encouraged when waiting in loops for an event to save the batteries.
  • void sleep(unsigned m): delay for a specified amount of time. The CPU is regularly switched to low-power state while blocking.

Debugging

  • void halt(void): stops the execution flow with an endless loop. If you are using the Ncubate emulator, use the j debugger command to jump over the instruction.
  • halt (asm) (macro): similar to halt()