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