2 * Gamepad style buttons connected to IRQ/GPIO lines
4 * Copyright (c) 2007 CodeSourcery.
5 * Written by Paul Brook
7 * This code is licenced under the GPL.
20 gamepad_button
*buttons
;
25 static void stellaris_gamepad_put_key(void * opaque
, int keycode
)
27 gamepad_state
*s
= (gamepad_state
*)opaque
;
31 if (keycode
== 0xe0 && !s
->extension
) {
36 down
= (keycode
& 0x80) == 0;
37 keycode
= (keycode
& 0x7f) | s
->extension
;
39 for (i
= 0; i
< s
->num_buttons
; i
++) {
40 if (s
->buttons
[i
].keycode
== keycode
41 && s
->buttons
[i
].pressed
!= down
) {
42 s
->buttons
[i
].pressed
= down
;
43 qemu_set_irq(s
->buttons
[i
].irq
, down
);
50 static void stellaris_gamepad_save(QEMUFile
*f
, void *opaque
)
52 gamepad_state
*s
= (gamepad_state
*)opaque
;
55 qemu_put_be32(f
, s
->extension
);
56 for (i
= 0; i
< s
->num_buttons
; i
++)
57 qemu_put_byte(f
, s
->buttons
[i
].pressed
);
60 static int stellaris_gamepad_load(QEMUFile
*f
, void *opaque
, int version_id
)
62 gamepad_state
*s
= (gamepad_state
*)opaque
;
68 s
->extension
= qemu_get_be32(f
);
69 for (i
= 0; i
< s
->num_buttons
; i
++)
70 s
->buttons
[i
].pressed
= qemu_get_byte(f
);
75 /* Returns an array 5 ouput slots. */
76 void stellaris_gamepad_init(int n
, qemu_irq
*irq
, const int *keycode
)
81 s
= (gamepad_state
*)qemu_mallocz(sizeof (gamepad_state
));
82 s
->buttons
= (gamepad_button
*)qemu_mallocz(n
* sizeof (gamepad_button
));
83 for (i
= 0; i
< n
; i
++) {
84 s
->buttons
[i
].irq
= irq
[i
];
85 s
->buttons
[i
].keycode
= keycode
[i
];
88 qemu_add_kbd_event_handler(stellaris_gamepad_put_key
, s
);
89 register_savevm("stellaris_gamepad", -1, 1,
90 stellaris_gamepad_save
, stellaris_gamepad_load
, s
);