openMSX
SG1000JoystickIO.cc
Go to the documentation of this file.
1#include "SG1000JoystickIO.hh"
2#include "MSXMotherBoard.hh"
3#include "JoystickPort.hh"
4#include "serialize.hh"
5
6namespace openmsx {
7
8// MSXDevice
10 : MSXDevice(config)
11
12{
13 MSXMotherBoard& motherBoard = getMotherBoard();
14 auto time = getCurrentTime();
15 for (unsigned i = 0; i < 2; i++) {
16 ports[i] = &motherBoard.getJoystickPort(i);
17 // Clear strobe bit, or MSX joysticks will stay silent.
18 ports[i]->write(0xFB, time);
19 }
20}
21
22byte SG1000JoystickIO::readIO(word port, EmuTime::param time)
23{
24 return peekIO(port, time);
25}
26
27byte SG1000JoystickIO::peekIO(word port, EmuTime::param time) const
28{
29 // Joystick hardware cannot detect when it's being read, so using the
30 // read() method for peeking should be safe.
31 if (port & 1) {
32 byte joy2 = ports[1]->read(time) & 0x3F;
33 return 0xF0 | (joy2 >> 2);
34 } else {
35 byte joy1 = ports[0]->read(time) & 0x3F;
36 byte joy2 = ports[1]->read(time) & 0x3F;
37 return joy1 | (joy2 << 6);
38 }
39}
40
41
42template<typename Archive>
43void SG1000JoystickIO::serialize(Archive& ar, unsigned /*version*/)
44{
45 ar.template serializeBase<MSXDevice>(*this);
46}
49
50} // namespace openmsx
An MSXDevice is an emulated hardware component connected to the bus of the emulated MSX.
Definition: MSXDevice.hh:34
MSXMotherBoard & getMotherBoard() const
Get the mother board this device belongs to.
Definition: MSXDevice.cc:70
EmuTime::param getCurrentTime() const
Definition: MSXDevice.cc:125
JoystickPortIf & getJoystickPort(unsigned port)
I/O port access to the joysticks for the Sega SG-1000.
SG1000JoystickIO(const DeviceConfig &config)
void serialize(Archive &ar, unsigned version)
byte readIO(word port, EmuTime::param time) override
Read a byte from an IO port at a certain time from this device.
byte peekIO(word port, EmuTime::param time) const override
Read a byte from a given IO port.
This file implemented 3 utility functions:
Definition: Autofire.cc:9
REGISTER_MSXDEVICE(ChakkariCopy, "ChakkariCopy")
uint16_t word
16 bit unsigned integer
Definition: openmsx.hh:29
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
Definition: serialize.hh:1021