OXYGENHUB
◆ main openmsx / src / input / JoystickDevice.hh
1.7 KiB · C++ · last changed chore(): initial commit 1 month ago source blame history raw
1
#ifndef JOYSTICKDEVICE_HH
2
#define JOYSTICKDEVICE_HH
3
4
#include "Pluggable.hh"
5
#include <cstdint>
6
7
namespace openmsx {
8
9
class JoystickDevice : public Pluggable
10
{
11
public:
12
	/**
13
	 * Read from the joystick device. The bits in the read byte have
14
	 * following meaning:
15
	 *   7    6       5         4         3       2      1     0
16
	 * | xx | xx | BUTTON_B | BUTTON_A | RIGHT | LEFT | DOWN | UP  |
17
	 * | xx | xx | pin7     | pin6     | pin4  | pin3 | pin2 | pin1|
18
	 */
19
	[[nodiscard]] virtual uint8_t read(EmuTime time) = 0;
20
21
	/**
22
	 * Write a value to the joystick device. The bits in the written
23
	 * byte have following meaning:
24
	 *     7    6    5    4    3     2      1      0
25
	 *   | xx | xx | xx | xx | xx | pin8 | pin7 | pin6 |
26
	 * As an optimization, this method might not be called when the
27
	 * new value is the same as the previous one.
28
	 */
29
	virtual void write(uint8_t value, EmuTime time) = 0;
30
31
	[[nodiscard]] zstring_view getClass() const final;
32
33
	/* Missing pin descriptions
34
	 * pin 5 : +5V
35
	 * pin 9 : GND
36
	 */
37
38
	// use in the read() method
39
	static constexpr uint8_t JOY_UP      = 0x01;
40
	static constexpr uint8_t JOY_DOWN    = 0x02;
41
	static constexpr uint8_t JOY_LEFT    = 0x04;
42
	static constexpr uint8_t JOY_RIGHT   = 0x08;
43
	static constexpr uint8_t JOY_BUTTONA = 0x10;
44
	static constexpr uint8_t JOY_BUTTONB = 0x20;
45
	static constexpr uint8_t RD_PIN1 = 0x01;
46
	static constexpr uint8_t RD_PIN2 = 0x02;
47
	static constexpr uint8_t RD_PIN3 = 0x04;
48
	static constexpr uint8_t RD_PIN4 = 0x08;
49
	static constexpr uint8_t RD_PIN6 = 0x10;
50
	static constexpr uint8_t RD_PIN7 = 0x20;
51
52
	// use in the write() method
53
	static constexpr uint8_t WR_PIN6 = 0x01;
54
	static constexpr uint8_t WR_PIN7 = 0x02;
55
	static constexpr uint8_t WR_PIN8 = 0x04;
56
};
57
58
} // namespace openmsx
59
60
#endif