Mercurial > repos > simple16
annotate src/controller.c @ 50:8e39a877c651
Switch from RGB 444 to RGB 565 for palette entries
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Wed, 31 Aug 2016 20:29:45 -0700 |
parents | b87b3ad5068c |
children |
rev | line source |
---|---|
31
b87b3ad5068c
Forgot to add the controller source files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1 #include <stdint.h> |
b87b3ad5068c
Forgot to add the controller source files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2 #include <string.h> |
b87b3ad5068c
Forgot to add the controller source files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
3 #include "controller.h" |
b87b3ad5068c
Forgot to add the controller source files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
4 |
b87b3ad5068c
Forgot to add the controller source files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
5 static controllers *current_context; |
b87b3ad5068c
Forgot to add the controller source files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
6 |
b87b3ad5068c
Forgot to add the controller source files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
7 //UDLR SMAB CXYZ |
b87b3ad5068c
Forgot to add the controller source files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
8 |
b87b3ad5068c
Forgot to add the controller source files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
9 void controller_init(controllers *context) |
b87b3ad5068c
Forgot to add the controller source files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
10 { |
b87b3ad5068c
Forgot to add the controller source files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
11 memset(context, 0, sizeof(controllers)); |
b87b3ad5068c
Forgot to add the controller source files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
12 current_context = context; |
b87b3ad5068c
Forgot to add the controller source files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
13 } |
b87b3ad5068c
Forgot to add the controller source files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
14 |
b87b3ad5068c
Forgot to add the controller source files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
15 void controller_pressed(int which, uint16_t buttons) |
b87b3ad5068c
Forgot to add the controller source files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
16 { |
b87b3ad5068c
Forgot to add the controller source files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
17 if (which > 1) { |
b87b3ad5068c
Forgot to add the controller source files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
18 return; |
b87b3ad5068c
Forgot to add the controller source files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
19 } |
b87b3ad5068c
Forgot to add the controller source files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
20 current_context->state[which] |= buttons; |
b87b3ad5068c
Forgot to add the controller source files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
21 } |
b87b3ad5068c
Forgot to add the controller source files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
22 |
b87b3ad5068c
Forgot to add the controller source files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
23 void controller_released(int which, uint16_t buttons) |
b87b3ad5068c
Forgot to add the controller source files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
24 { |
b87b3ad5068c
Forgot to add the controller source files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
25 if (which > 1) { |
b87b3ad5068c
Forgot to add the controller source files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
26 return; |
b87b3ad5068c
Forgot to add the controller source files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
27 } |
b87b3ad5068c
Forgot to add the controller source files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
28 current_context->state[which] &= (~buttons) & 0xFFF; |
b87b3ad5068c
Forgot to add the controller source files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
29 } |
b87b3ad5068c
Forgot to add the controller source files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
30 |
b87b3ad5068c
Forgot to add the controller source files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
31 uint16_t controller_read(controllers *context, int which) |
b87b3ad5068c
Forgot to add the controller source files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
32 { |
b87b3ad5068c
Forgot to add the controller source files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
33 if (which > 1) { |
b87b3ad5068c
Forgot to add the controller source files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
34 return 0xFFFF; |
b87b3ad5068c
Forgot to add the controller source files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
35 } |
b87b3ad5068c
Forgot to add the controller source files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
36 return context->state[which]; |
b87b3ad5068c
Forgot to add the controller source files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
37 } |