1 #include <bz/input/input_internal.h>
2 #include <bz/input/platform.h>
4 #include <bz/input/input_id_internal.h>
5 #include <playdate/entrypoint.h>
7 typedef enum BZInputCode
{
10 const BZInputCode BZInputCodeMax
= BZInputCodeQuit
;
12 typedef union BZInputTableEntry
{
18 static BZInput bzQuitInput
= { .id
= BZInputCodeQuit
, };
19 BZInputID bzQuitInputID
= &bzQuitInput
;
21 //const size_t inputTableSize = BZInputCodeMax + 1;
22 #define inputTableSize 8
23 static BZInputTableEntry inputTable
[inputTableSize
];
30 static Button buttons
[8];
32 /*int buttonIdx(SDL_KeyCode keyCode) {
58 for (size_t i
= 0; i
< 8; ++i
) {
59 buttons
[i
].down
= false;
63 void bzInputTeardown() {
67 void bzInputProcessFrame() {
68 for (size_t i
= 0; i
< inputTableSize
; ++i
) {
69 inputTable
[i
].integerValue
= 0; // FIXME, max size and whatever.
72 // for (size_t i = 0; i < 8; ++i) {
73 // buttons[i].down = buttons[i].down || buttons[i].pressed;
74 // buttons[i].pressed = false;
80 playdate
->system
->getButtonState(¤t
, &pushed
, &released
);
82 buttons
[1].down
= (current
& kButtonUp
) > 0;
83 buttons
[1].pressed
= (pushed
& kButtonUp
) > 0;
85 buttons
[2].down
= (current
& kButtonDown
) > 0;
86 buttons
[2].pressed
= (pushed
& kButtonDown
) > 0;
88 buttons
[3].down
= (current
& kButtonLeft
) > 0;
89 buttons
[3].pressed
= (pushed
& kButtonLeft
) > 0;
91 buttons
[4].down
= (current
& kButtonRight
) > 0;
92 buttons
[4].pressed
= (pushed
& kButtonRight
) > 0;
94 buttons
[5].down
= (current
& kButtonB
) > 0;
95 buttons
[5].pressed
= (pushed
& kButtonB
) > 0;
97 buttons
[6].down
= (current
& kButtonA
) > 0;
98 buttons
[6].pressed
= (pushed
& kButtonA
) > 0;
101 while (SDL_PollEvent(&event)) {
102 switch (event.type) {
104 inputTable[BZInputCodeQuit].booleanValue = true;
108 buttons[buttonIdx(event.key.keysym.sym)].pressed = true;
112 buttons[buttonIdx(event.key.keysym.sym)].pressed = false;
113 buttons[buttonIdx(event.key.keysym.sym)].down = false;
119 bool bzInputGetBooleanValue(BZInputID inputID
) {
120 return inputTable
[inputID
->id
].booleanValue
;
123 int bzInputGetIntegerValue(BZInputID inputID
) {
124 return inputTable
[inputID
->id
].integerValue
;
127 float bzInputGetFloatValue(BZInputID inputID
) {
128 return inputTable
[inputID
->id
].floatValue
;
131 bool bzInputBtn(int id
) {
132 return buttons
[id
].down
|| buttons
[id
].pressed
;
135 bool bzInputBtnP(int id
) {
136 return buttons
[id
].pressed
;