PAlib: PA_Keys.h Source File

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

# PA_Keys.h

Go to the documentation of this file.

    00001 #ifndef _PA_KEYS
    00002 #define _PA_KEYS
    00003
    00004 #ifdef __cplusplus
    00005 extern "C" {
    00006 #endif
    00007
    00008 #include "PA9.h"
    00014
    00015 // Système pour les touches
    00017
    00018 // Keyboard defines
    00019 #define PA_BACKSPACE 1    // On va dire que la touche backspace a pour valeur 1...
    00020 #define PA_CAPS      2    // 2 pour CAPS
    00021 #define PA_ENTER     '\n'    // 3 pour Enter
    00022 #define PA_SHIFT     4    // etc
    00023 #define PA_RIEN      0    // Si y'a rien, faudra faire comme si on appuye sur rien
    00024 #define PA_TAB       3    // tab...
    00025
    00026
    00027 typedef struct {
    00028    u8 A, B, X, Y, L, R, Up, Down, Right, Left, Start, Select;
    00029 } PA_Pad;
    00030
    00031 typedef struct {
    00032    u8 Held, Released, Newpress, Newpress0;
    00033    s16 X, Y, altX, altY, Pressure, Vx, Vy, oldVx, oldVy;
    00034 } PA_Stylus;
    00035
    00036 extern PA_Stylus Stylus;
    00037
    00038 typedef struct {
    00039    PA_Pad Held, Released, Newpress; // Pressed si on appuye, Held si on garde appuyé, et Released si on relache
    00040 } Pads;
    00041
    00042 extern Pads Pad;
    00043 extern PA_Pad* PadPointer;
    00044
    00045 // Structure pour les sprites que l'on déplace...
    00046 typedef struct {
    00047        u8 Moving;
    00048        u8 Sprite;
    00049        s16 X, Y, Vx, Vy, NextVx, NextVy;
    00050        u8 Time; // Si trop longtemps sans bouger le sprite, il décroche...
    00051 } PA_movingsprite;
    00052
    00053 extern PA_movingsprite PA_MovedSprite;
    00054
    00055 extern u8 PA_MoveSpriteType;
    00056
    00057
    00058 // Button info
    00059 #define PA_BUTTONS (*(volatile u16*)0x04000130)
    00060
    00061 #ifndef REG_KEYCNT
    00062        #define REG_KEYCNT (*(volatile u16*)0x04000132)
    00063 #endif
    00064
    00065 #define BUTTON_A 1
    00066 #define BUTTON_B 2
    00067 #define BUTTON_SELECT 4
    00068 #define BUTTON_START 8
    00069 #define BUTTON_RIGHT 16
    00070 #define BUTTON_LEFT 32
    00071 #define BUTTON_UP 64
    00072 #define BUTTON_DOWN 128
    00073 #define BUTTON_R 256
    00074 #define BUTTON_L 512
    00075 #define BUTTON_X 1024
    00076 #define BUTTON_Y 2048
    00077
    00078
    00079
    00080 extern u16 CompletePad, ExPad, TempPad;
    00081 #define UPDATEPAD(type, pad)  type.A = pad & BUTTON_A;\
    00082    type.B = (pad & BUTTON_B) >> 1;\
    00083    type.Select = (pad & BUTTON_SELECT) >> 2;\
    00084    type.Start = (pad & BUTTON_START) >> 3;\
    00085    type.Right = (pad & BUTTON_RIGHT) >> 4;\
    00086    type.Left = (pad & BUTTON_LEFT) >> 5;\
    00087    type.Up = (pad & BUTTON_UP) >> 6;\
    00088    type.Down = (pad & BUTTON_DOWN) >> 7;\
    00089    type.R = (pad & BUTTON_R) >> 8;\
    00090    type.L = (pad & BUTTON_L) >> 9;\
    00091    type.X = (pad & BUTTON_X) >> 10;\
    00092    type.Y = (pad & BUTTON_Y) >> 11;
    00093
    00094 #define COPYPAD(new, old)  new.A = old.A;\
    00095    new.B = old.B;\
    00096    new.Select = old.Select;\
    00097    new.Start = old.Start;\
    00098    new.Right = old.Right;\
    00099    new.Left = old.Left;\
    00100    new.Up = old.Up;\
    00101    new.Down = old.Down;\
    00102    new.R = old.R;\
    00103    new.L =  old.L;\
    00104    new.X = old.X;\
    00105    new.Y = old.Y;
    00106 /*
    00107 #define PA_UpdatePad() ExPad = CompletePad;\
    00108    CompletePad = ~(BUTTONS + (((IPC->buttons)&3) << 10));\
    00109    UPDATEPAD(Pad.Held, CompletePad);\
    00110    UPDATEPAD(Pad.Released, (ExPad & (~CompletePad)));\
    00111    UPDATEPAD(Pad.Newpress, (CompletePad & (~ExPad)));
    00112
    00113 #define PA_UpdateStylus() u8 temp = ((~IPC->buttons) >> 6) & 1;\
    00114        Stylus.Newpress = temp & (!Stylus.Held);\
    00115        Stylus.Released = (!temp) & Stylus.Held;\
    00116        Stylus.Held = temp;\
    00117        if(Stylus.Held)Stylus.altX =  ((IPC->touchX - 0x0113) / 14);\
    00118        if(Stylus.Held)Stylus.altY =  ((IPC->touchY - 0x00E0) / 19);\
    00119        if(Stylus.Held)Stylus.X =  IPC->touchXpx;\
    00120        if(Stylus.Held)Stylus.Y =  IPC->touchYpx;\
    00121        if(Stylus.Held)Stylus.Pressure = (((Stylus.X * IPC->touchZ2) >> 6) / IPC->touchZ1) - (Stylus.X >> 6);
    00122 */
    00123 //#define BUTTON_AND 16384
    00124 //#define BUTTON_OR 0
    00125
    00137 void PA_UpdatePad(void);
    00138
    00139
    00140
    00147 void PA_UpdateStylus(void);
    00148
    00149
    00158 u8 PA_MoveSpritePix(u8 sprite);
    00159
    00160
    00161
    00162
    00163
    00164
    00165
    00174 #define PA_MoveSprite(sprite) PA_MoveSpriteEx(PA_Screen, sprite, PA_GetSpriteLx(0, sprite), PA_GetSpriteLy(0, sprite))
    00175
    00176
    00177
    00195 u8 PA_MoveSpriteEx(u8 screen, u8 sprite, u8 lx, u8 ly);
    00196
    00197
    00209 extern inline u8 PA_MoveSpriteDistance(u8 sprite, u8 distance){
    00210        PA_MoveSpriteType = 1; // mode distance
    00211        u8 touched = PA_MoveSpriteEx(PA_Screen, sprite, distance, distance);
    00212        PA_MoveSpriteType = 0; // normal mode
    00213        return touched;
    00214 }
    00215
    00222 extern inline void PA_UpdateMoveSprite(void) {
    00223        PA_MovedSprite.Time++;
    00224        if ((PA_MovedSprite.Time > 2) || Stylus.Released) {
    00225               PA_MovedSprite.Moving = 0;
    00226               PA_MovedSprite.Time = 0;
    00227        }
    00228 }
    00229
    00230
    00231
    00247 extern inline u8 PA_SpriteTouchedEx(u8 sprite, u8 lx, u8 ly){
    00248        return (Stylus.Held && (Stylus.X > PA_GetSpriteX(PA_Screen, sprite)) && (Stylus.X < PA_GetSpriteX(PA_Screen, sprite) + lx)&& (Stylus.Y > PA_GetSpriteY(PA_Screen, sprite)) && (Stylus.Y < PA_GetSpriteY(PA_Screen, sprite) + ly));
    00249 }
    00250
    00251
    00252
    00261 extern inline u8 PA_SpriteTouched(u8 sprite) {
    00262        return PA_SpriteTouchedEx(sprite, PA_GetSpriteLx(PA_Screen, sprite), PA_GetSpriteLy(PA_Screen, sprite));
    00263 }
    00264
    00265
    00266
    00267
    00268
    00269 extern inline u8 PA_SpriteTouchedPix(u8 sprite){
    00270 u16 x = Stylus.X - PA_GetSpriteX(PA_Screen, sprite);
    00271 u16 y = Stylus.Y - PA_GetSpriteY(PA_Screen, sprite);
    00272
    00273 return (Stylus.Held && (x < spriteanims[PA_Screen][sprite].lx) && (y < spriteanims[PA_Screen][sprite].ly) && PA_GetSpritePixel(PA_Screen, sprite, x, y));
    00274 }
    00275
    00276
    00277
    00278
    00296 #define PA_StylusInZone(x1, y1, x2, y2) ((Stylus.X>=x1)&&(Stylus.Y>=y1)&&(Stylus.X<x2)&&(Stylus.Y<y2))
    00297  // end of Keys
    00299
    00300 #ifdef __cplusplus
    00301 }
    00302 #endif
    00303 #endif