blob: a39f448d10e44d220c4d4ab8fb4cafa5984970ff (
plain) (
tree)
|
|
#include <nds.h>
#include "../bang.h"
#include "input.h"
// Read gamepad state into an input device.
void inp_read_gamepad(InputDevice *inp) {
u32 held = keysHeld();
u8 gamepad = (
TEST(held, KEY_UP) << 7
| TEST(held, KEY_DOWN) << 6
| TEST(held, KEY_LEFT) << 5
| TEST(held, KEY_RIGHT) << 4
| TEST(held, KEY_A) << 3
| TEST(held, KEY_B) << 2
| TEST(held, KEY_X) << 1
| TEST(held, KEY_Y) << 0
);
if (gamepad != inp->gamepad) {
inp->wake = TRUE;
inp->gamepad = gamepad;
}
}
// Read navigation state into an input device.
void inp_read_navigation(InputDevice *inp) {
u32 held = keysHeld();
u8 navigation = (
TEST(held, KEY_UP) << 7
| TEST(held, KEY_DOWN) << 6
| TEST(held, KEY_LEFT) << 5
| TEST(held, KEY_RIGHT) << 4
| TEST(held, KEY_A) << 3
| TEST(held, KEY_B) << 2
| TEST(held, KEY_R) << 1
| TEST(held, KEY_L) << 0
);
if (navigation != inp->navigation) {
inp->wake = TRUE;
inp->navigation = navigation;
}
}
// Read touchscreen state into an input device.
void inp_read_touch(InputDevice *inp) {
bool pointer = TEST(keysHeld(), KEY_TOUCH);
if (pointer != inp->pointer) {
inp->wake = TRUE;
inp->pointer = pointer;
}
if (pointer) {
touchPosition pos;
touchRead(&pos);
if (pos.px != inp->x || pos.py != inp->y) {
inp->wake = TRUE;
inp->x = pos.px;
inp->y = pos.py;
}
}
}
|