PAlib: PA_Keys.h File Reference

Main Page | Modules | File List | Globals | Search for

# PA_Keys.h File Reference

Everything concerning the keys and stylus. More...

Go to the source code of this file.

## Data Structures

struct | PA_Pad
struct | PA_Stylus
struct | Pads
struct | PA_movingsprite

## Defines

#define | PA_BACKSPACE 1
#define | PA_CAPS 2
#define | PA_ENTER '\n'
#define | PA_SHIFT 4
#define | PA_RIEN 0
#define | PA_TAB 3
#define | PA_BUTTONS (*(volatile u16*)0x04000130)
#define | REG_KEYCNT (*(volatile u16*)0x04000132)
#define | BUTTON_A 1
#define | BUTTON_B 2
#define | BUTTON_SELECT 4
#define | BUTTON_START 8
#define | BUTTON_RIGHT 16
#define | BUTTON_LEFT 32
#define | BUTTON_UP 64
#define | BUTTON_DOWN 128
#define | BUTTON_R 256
#define | BUTTON_L 512
#define | BUTTON_X 1024
#define | BUTTON_Y 2048
#define | UPDATEPAD(type, pad)
#define | COPYPAD(new, old)
#define | PA_MoveSprite(sprite) PA_MoveSpriteEx(PA_Screen, sprite, PA_GetSpriteLx(0, sprite), PA_GetSpriteLy(0, sprite))

Move a sprite according to the stylus's position. The sprite will be 'hooked' if the stylus passes over it, and then they'll be linked together. Returns 1 if the sprite is moved. You can also get information from PA_MovedSprite.Moving (1 if you are moving a sprite), .Sprite (sprite moved), .X (X position of the center of the sprite), .Y (Y position of the center of the sprite), .Vx (horizontal speed ! useful if you want to make the sprite continue to move when you release the stylus...), and .Vy

#define | PA_StylusInZone(x1, y1, x2, y2) ((Stylus.X>=x1)&&(Stylus.Y>=y1)&&(Stylus.X<x2)&&(Stylus.Y<y2))
| Check if the stylus is in a given zone... Returns 1 if yes, 0 if not

## Functions

void | PA_UpdatePad (void)
| Update the Keypad, use it once per frame (in the VBL for example). You can then retrieve the held down keys with Pad.Held.A (or Up, Down...), Newly pressed keys with Pad.Newpress.R, and the just released keys with Pad.Released.Up...
void | PA_UpdateStylus (void)
| Update the Stylus position. You can then check if the stylus is current in use (Stylus.Held), newly pressed (Stylus.Newpress), or released (Stylus.Released), and get it's position (Stylus.X, Stylus.Y).
u8 | PA_MoveSpritePix (u8 sprite)

Move a sprite according to the stylus's position, only if you touch a sprite's pixel. This is similar to PA_MoveSprite, but slightly slower and requires PA_InitSpriteDraw(screen, sprite) before. The sprite will be 'hooked' if the stylus passes over it, and then they'll be linked together. Returns 1 if the sprite is moved. You can also get information from PA_MovedSprite.Moving (1 if you are moving a sprite), .Sprite (sprite moved), .X (X position of the top left corner of the sprite), .Y (Y position of the top left corner of the sprite), .Vx (horizontal speed ! useful if you want to make the sprite continue to move when you release the stylus...), and .Vy

u8 | PA_MoveSpriteEx (u8 screen, u8 sprite, u8 lx, u8 ly)

Move a sprite according to the stylus's position. See PA_MoveSprite for more details... The difference is that here you chose the sprite dimension (lx and ly), which is useful if the sprite is smaller than the DS standard sizes... (for example 20x20...). This will also limit the 'hooking' distance

u8 | PA_MoveSpriteDistance (u8 sprite, u8 distance)
| Move a sprite according to the stylus's position. See PA_MoveSprite for more details... The difference is that here you chose the hooking distance in pixels
void | PA_UpdateMoveSprite (void)
| Update the moving sprite info. If you don't put this in the VBL (it already is in PA_InitVBL), then if you stop moving around a sprite, it might not be able to pick up other sprites...
u8 | PA_SpriteTouchedEx (u8 sprite, u8 lx, u8 ly)
| Check if a given sprite is touched. Returns 1 if touched... You can chose the width and height around the sprite
u8 | PA_SpriteTouched (u8 sprite)
| Check if a given sprite is touched. Returns 1 if touched...
u8 | PA_SpriteTouchedPix (u8 sprite)

## Variables

PA_Stylus | Stylus
Pads | Pad
PA_Pad * | PadPointer
PA_movingsprite | PA_MovedSprite
u8 | PA_MoveSpriteType
u16 | CompletePad
u16 | ExPad
u16 | TempPad

## Detailed Description

Everything concerning the keys and stylus.

Update the keys and stylus inputs

## Define Documentation

#define COPYPAD | ( | new,
|  | old |  | ) |

Value:

    new.A = old.A;\
       new.B = old.B;\
       new.Select = old.Select;\
       new.Start = old.Start;\
       new.Right = old.Right;\
       new.Left = old.Left;\
       new.Up = old.Up;\
       new.Down = old.Down;\
       new.R = old.R;\
       new.L =  old.L;\
       new.X = old.X;\
       new.Y = old.Y;

#define UPDATEPAD | ( | type,
|  | pad |  | ) |

Value:

    type.A = pad & BUTTON_A;\
       type.B = (pad & BUTTON_B) >> 1;\
       type.Select = (pad & BUTTON_SELECT) >> 2;\
       type.Start = (pad & BUTTON_START) >> 3;\
       type.Right = (pad & BUTTON_RIGHT) >> 4;\
       type.Left = (pad & BUTTON_LEFT) >> 5;\
       type.Up = (pad & BUTTON_UP) >> 6;\
       type.Down = (pad & BUTTON_DOWN) >> 7;\
       type.R = (pad & BUTTON_R) >> 8;\
       type.L = (pad & BUTTON_L) >> 9;\
       type.X = (pad & BUTTON_X) >> 10;\
       type.Y = (pad & BUTTON_Y) >> 11;