annotate src/controller.c @ 58:bed2d84eeabe

Fix ldimh special casing of loading labels for the case when the label is not a forward reference
author Michael Pavone <pavone@retrodev.com>
date Tue, 06 Sep 2016 09:42:31 -0700
parents b87b3ad5068c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 }