- Centralized NDS keypad update.

- Added get_keypad function to get current keypad state.
- Use SDL keynames for keyboard.
This commit is contained in:
evilynux 2007-01-14 21:28:17 +00:00
parent 661652ba76
commit cf35dbd115
2 changed files with 34 additions and 12 deletions

View File

@ -106,6 +106,25 @@ void set_mouse_coord(signed long x,signed long y)
} }
#endif // !GTK_UI #endif // !GTK_UI
/* Update NDS keypad */
void update_keypad(u16 keys)
{
((u16 *)ARM9Mem.ARM9_REG)[0x130>>1] = ~keys & 0x3FF;
((u16 *)MMU.ARM7_REG)[0x130>>1] = ~(keys >> 10) & 0x3;
/* Update X and Y buttons */
MMU.ARM7_REG[0x136] = ( ~( keys >> 10) & 0x3 ) | (MMU.ARM7_REG[0x136] & ~0x3);
}
/* Retrieve current NDS keypad */
u16 get_keypad()
{
u16 keypad;
keypad = ~((unsigned short *)MMU.ARM7_REG)[0x130>>1];
keypad = (keypad & 0x3) << 10;
keypad |= ~((unsigned short *)ARM9Mem.ARM9_REG)[0x130>>1] & 0x3FF;
return keypad;
}
/* Manage input events */ /* Manage input events */
u16 process_ctrls_events(u16 keypad) u16 process_ctrls_events(u16 keypad)
{ {
@ -179,14 +198,14 @@ u16 process_ctrls_events(u16 keypad)
case SDLK_DOWN: ADD_KEY( keypad, 0x80); break; case SDLK_DOWN: ADD_KEY( keypad, 0x80); break;
case SDLK_RIGHT: ADD_KEY( keypad, 0x10); break; case SDLK_RIGHT: ADD_KEY( keypad, 0x10); break;
case SDLK_LEFT: ADD_KEY( keypad, 0x20); break; case SDLK_LEFT: ADD_KEY( keypad, 0x20); break;
case 'c': ADD_KEY( keypad, 0x1); break; case SDLK_c: ADD_KEY( keypad, 0x1); break;
case 'x': ADD_KEY( keypad, 0x2); break; case SDLK_x: ADD_KEY( keypad, 0x2); break;
case SDLK_BACKSPACE:ADD_KEY( keypad, 0x4); break; case SDLK_BACKSPACE:ADD_KEY( keypad, 0x4); break;
case SDLK_RETURN: ADD_KEY( keypad, 0x8); break; case SDLK_RETURN: ADD_KEY( keypad, 0x8); break;
case 's': ADD_KEY( keypad, 0x100); break; case SDLK_e: ADD_KEY( keypad, 0x100); break; // R
case 'd': ADD_KEY( keypad, 0x200); break; case SDLK_w: ADD_KEY( keypad, 0x200); break; // L
case 'w': ADD_KEY( keypad, 0x400); break; case SDLK_d: ADD_KEY( keypad, 0x400); break; // X
case 'e': ADD_KEY( keypad, 0x800); break; case SDLK_s: ADD_KEY( keypad, 0x800); break; // Y
} }
break; break;
@ -197,14 +216,14 @@ u16 process_ctrls_events(u16 keypad)
case SDLK_DOWN: RM_KEY( keypad, 0x80); break; case SDLK_DOWN: RM_KEY( keypad, 0x80); break;
case SDLK_RIGHT: RM_KEY( keypad, 0x10); break; case SDLK_RIGHT: RM_KEY( keypad, 0x10); break;
case SDLK_LEFT: RM_KEY( keypad, 0x20); break; case SDLK_LEFT: RM_KEY( keypad, 0x20); break;
case 'c': RM_KEY( keypad, 0x1); break; case SDLK_c: RM_KEY( keypad, 0x1); break;
case 'x': RM_KEY( keypad, 0x2); break; case SDLK_x: RM_KEY( keypad, 0x2); break;
case SDLK_BACKSPACE:RM_KEY( keypad, 0x4); break; case SDLK_BACKSPACE:RM_KEY( keypad, 0x4); break;
case SDLK_RETURN: RM_KEY( keypad, 0x8); break; case SDLK_RETURN: RM_KEY( keypad, 0x8); break;
case 's': RM_KEY( keypad, 0x100); break; case SDLK_e: RM_KEY( keypad, 0x100); break; // R
case 'd': RM_KEY( keypad, 0x200); break; case SDLK_w: RM_KEY( keypad, 0x200); break; // L
case 'w': RM_KEY( keypad, 0x400); break; case SDLK_d: RM_KEY( keypad, 0x400); break; // X
case 'e': RM_KEY( keypad, 0x800); break; case SDLK_s: RM_KEY( keypad, 0x800); break; // Y
} }
break; break;

View File

@ -28,6 +28,7 @@
#include <unistd.h> #include <unistd.h>
#include <pthread.h> #include <pthread.h>
#include <SDL/SDL.h> #include <SDL/SDL.h>
#include "MMU.h"
#include "types.h" #include "types.h"
@ -59,6 +60,8 @@ void set_mouse_coord(signed long x,signed long y);
BOOL init_joy(u16 joyCfg[]); BOOL init_joy(u16 joyCfg[]);
void uninit_joy(); void uninit_joy();
u16 get_set_joy_key(int index); u16 get_set_joy_key(int index);
void update_keypad(u16 keys);
u16 get_keypad();
u16 process_ctrls_events(u16 oldkeypad); u16 process_ctrls_events(u16 oldkeypad);
#endif /* CTRLSSDL_H */ #endif /* CTRLSSDL_H */