openMSX
NinjaTap.cc
Go to the documentation of this file.
1 #include "NinjaTap.hh"
2 #include "JoystickPort.hh"
3 #include "serialize.hh"
4 
5 namespace openmsx {
6 
7 NinjaTap::NinjaTap(PluggingController& pluggingController_, std::string name_)
8  : JoyTap(pluggingController_, std::move(name_))
9 {
10  status = 0x3F; // TODO check initial value
11  previous = 0;
12  for (auto& b : buf) {
13  b = 0xFF;
14  }
15 }
16 
18 {
19  return "MSX Ninja Tap device";
20 }
21 
22 
23 void NinjaTap::plugHelper(Connector& /*connector*/, EmuTime::param /*time*/)
24 {
25  createPorts("Ninja Tap port ");
26 }
27 
29 {
30  return status;
31 }
32 
34 {
35  // bit 0 -> pin 6
36  // bit 1 -> pin 7
37  // bit 2 -> pin 8
38  if (value & 2) {
39  // pin7 = 1 : read mode
40  if (!(value & 1) && (previous & 1)) {
41  // pin 6 1->0 : query joysticks
42  // TODO does output change?
43  for (int i = 0; i < 4; ++i) {
44  byte t = slaves[i]->read(time);
45  buf[i] = ((t & 0x0F) << 4) |
46  ((t & 0x30) >> 4) |
47  0x0C;
48  }
49  }
50  if (!(value & 4) && (previous & 4)) {
51  // pin 8 1->0 : shift values
52  // TODO what about b4 and b5?
53  byte t = 0;
54  for (int i = 0; i < 4; ++i) {
55  if (buf[i] & 1) t |= (1 << i);
56  buf[i] >>= 1;
57  }
58  status = (status & ~0x0F) | t;
59  }
60  } else {
61  // pin 7 = 0 : detect mode, b5 is inverse of pin8
62  // TODO what happens with other bits?
63  if (value & 4) {
64  status &= ~0x20;
65  } else {
66  status |= 0x20;
67  }
68  }
69  previous = value;
70 }
71 
72 
73 template<typename Archive>
74 void NinjaTap::serialize(Archive& ar, unsigned /*version*/)
75 {
76  ar.template serializeBase<JoyTap>(*this);
77  ar.serialize("status", status);
78  ar.serialize("previous", previous);
79  ar.serialize("buf", buf);
80 }
83 
84 } // namespace openmsx
This device is pluged in into the joyports and consolidates several other joysticks plugged into it...
Definition: JoyTap.hh:20
REGISTER_POLYMORPHIC_INITIALIZER(Pluggable, CassettePlayer, "CassettePlayer")
void write(byte value, EmuTime::param time) override
Write a value to the joystick device.
Definition: NinjaTap.cc:33
Represents something you can plug devices into.
Definition: Connector.hh:20
void createPorts(const std::string &baseDescription)
Definition: JoyTap.cc:20
uint8_t byte
8 bit unsigned integer
Definition: openmsx.hh:26
STL namespace.
This class implements a subset of the proposal for std::string_ref (proposed for the next c++ standar...
Definition: string_ref.hh:18
Central administration of Connectors and Pluggables.
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
std::unique_ptr< JoystickPort > slaves[4]
Definition: JoyTap.hh:42
void plugHelper(Connector &connector, EmuTime::param time) override
Definition: NinjaTap.cc:23
NinjaTap(PluggingController &pluggingController, std::string name)
Definition: NinjaTap.cc:7
byte read(EmuTime::param time) override
Read from the joystick device.
Definition: NinjaTap.cc:28
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
Definition: serialize.hh:840
string_ref getDescription() const override
Description for this pluggable.
Definition: NinjaTap.cc:17
void serialize(Archive &ar, unsigned version)
Definition: NinjaTap.cc:74