# HG changeset patch # User Michael Pavone # Date 1459733851 25200 # Node ID b87b3ad5068c9f9533edadff8056e9187d2971bf # Parent 78068060313abd86c0ef6b6c926a2ab0878de9e0 Forgot to add the controller source files diff -r 78068060313a -r b87b3ad5068c src/controller.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/controller.c Sun Apr 03 18:37:31 2016 -0700 @@ -0,0 +1,37 @@ +#include +#include +#include "controller.h" + +static controllers *current_context; + +//UDLR SMAB CXYZ + +void controller_init(controllers *context) +{ + memset(context, 0, sizeof(controllers)); + current_context = context; +} + +void controller_pressed(int which, uint16_t buttons) +{ + if (which > 1) { + return; + } + current_context->state[which] |= buttons; +} + +void controller_released(int which, uint16_t buttons) +{ + if (which > 1) { + return; + } + current_context->state[which] &= (~buttons) & 0xFFF; +} + +uint16_t controller_read(controllers *context, int which) +{ + if (which > 1) { + return 0xFFFF; + } + return context->state[which]; +} diff -r 78068060313a -r b87b3ad5068c src/controller.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/controller.h Sun Apr 03 18:37:31 2016 -0700 @@ -0,0 +1,12 @@ +#ifndef CONTROLLER_H_ +#define CONTROLLER_H_ +typedef struct { + uint16_t state[2]; +} controllers; + +void controller_init(controllers *context); +void controller_pressed(int which, uint16_t buttons); +void controller_released(int which, uint16_t buttons); +uint16_t controller_read(controllers *context, int which); + +#endif //CONTROLLER_H_