| 1 |
#include "SVIPPI.hh" |
| 2 |
|
| 3 |
#include "CassettePort.hh" |
| 4 |
#include "GlobalSettings.hh" |
| 5 |
#include "JoystickPort.hh" |
| 6 |
#include "MSXMotherBoard.hh" |
| 7 |
#include "Reactor.hh" |
| 8 |
#include "serialize.hh" |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
namespace openmsx { |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
SVIPPI::SVIPPI(const DeviceConfig& config) |
| 71 |
: MSXDevice(config) |
| 72 |
, cassettePort(getMotherBoard().getCassettePort()) |
| 73 |
, i8255(*this, getCurrentTime(), config.getGlobalSettings().getInvalidPpiModeSetting()) |
| 74 |
, click(config) |
| 75 |
, keyboard( |
| 76 |
config.getMotherBoard(), |
| 77 |
config.getMotherBoard().getScheduler(), |
| 78 |
config.getMotherBoard().getCommandController(), |
| 79 |
config.getMotherBoard().getReactor().getEventDistributor(), |
| 80 |
config.getMotherBoard().getMSXEventDistributor(), |
| 81 |
config.getMotherBoard().getStateChangeDistributor(), |
| 82 |
Keyboard::Matrix::SVI, config) |
| 83 |
{ |
| 84 |
ports[0] = &getMotherBoard().getJoystickPort(0); |
| 85 |
ports[1] = &getMotherBoard().getJoystickPort(1); |
| 86 |
|
| 87 |
auto time = getCurrentTime(); |
| 88 |
ports[0]->write(0, time); |
| 89 |
ports[1]->write(0, time); |
| 90 |
|
| 91 |
reset(time); |
| 92 |
} |
| 93 |
|
| 94 |
void SVIPPI::reset(EmuTime time) |
| 95 |
{ |
| 96 |
i8255.reset(time); |
| 97 |
click.reset(time); |
| 98 |
} |
| 99 |
|
| 100 |
uint8_t SVIPPI::readIO(uint16_t port, EmuTime time) |
| 101 |
{ |
| 102 |
return i8255.read(port & 0x03, time); |
| 103 |
} |
| 104 |
|
| 105 |
uint8_t SVIPPI::peekIO(uint16_t port, EmuTime time) const |
| 106 |
{ |
| 107 |
return i8255.peek(port & 0x03, time); |
| 108 |
} |
| 109 |
|
| 110 |
void SVIPPI::writeIO(uint16_t port, uint8_t value, EmuTime time) |
| 111 |
{ |
| 112 |
i8255.write(port & 0x03, value, time); |
| 113 |
} |
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
uint8_t SVIPPI::readA(EmuTime time) |
| 119 |
{ |
| 120 |
uint8_t triggers = ((ports[0]->read(time) & 0x10) ? 0x10 : 0) | |
| 121 |
((ports[1]->read(time) & 0x10) ? 0x20 : 0); |
| 122 |
|
| 123 |
|
| 124 |
uint8_t cassetteReady = 0; |
| 125 |
|
| 126 |
uint8_t cassetteInput = cassettePort.cassetteIn(time) ? 0x80 : 0x00; |
| 127 |
|
| 128 |
return triggers | cassetteReady | cassetteInput; |
| 129 |
} |
| 130 |
uint8_t SVIPPI::peekA(EmuTime ) const |
| 131 |
{ |
| 132 |
return 0; |
| 133 |
} |
| 134 |
void SVIPPI::writeA(uint8_t , EmuTime ) |
| 135 |
{ |
| 136 |
} |
| 137 |
|
| 138 |
uint8_t SVIPPI::readB(EmuTime time) |
| 139 |
{ |
| 140 |
return peekB(time); |
| 141 |
} |
| 142 |
uint8_t SVIPPI::peekB(EmuTime ) const |
| 143 |
{ |
| 144 |
return keyboard.getKeys()[selectedRow]; |
| 145 |
} |
| 146 |
void SVIPPI::writeB(uint8_t , EmuTime ) |
| 147 |
{ |
| 148 |
} |
| 149 |
|
| 150 |
uint4_t SVIPPI::readC1(EmuTime time) |
| 151 |
{ |
| 152 |
return peekC1(time); |
| 153 |
} |
| 154 |
uint4_t SVIPPI::peekC1(EmuTime ) const |
| 155 |
{ |
| 156 |
return 15; |
| 157 |
} |
| 158 |
uint4_t SVIPPI::readC0(EmuTime time) |
| 159 |
{ |
| 160 |
return peekC0(time); |
| 161 |
} |
| 162 |
uint4_t SVIPPI::peekC0(EmuTime ) const |
| 163 |
{ |
| 164 |
return selectedRow; |
| 165 |
} |
| 166 |
void SVIPPI::writeC1(uint4_t value, EmuTime time) |
| 167 |
{ |
| 168 |
if ((prevBits ^ value) & 1) { |
| 169 |
cassettePort.setMotor((value & 1) == 0, time); |
| 170 |
} |
| 171 |
if ((prevBits ^ value) & 2) { |
| 172 |
cassettePort.cassetteOut((value & 2) != 0, time); |
| 173 |
} |
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
if ((prevBits ^ value) & 8) { |
| 178 |
click.setClick((value & 8) != 0, time); |
| 179 |
} |
| 180 |
prevBits = value; |
| 181 |
} |
| 182 |
void SVIPPI::writeC0(uint4_t value, EmuTime ) |
| 183 |
{ |
| 184 |
selectedRow = value; |
| 185 |
} |
| 186 |
|
| 187 |
template<typename Archive> |
| 188 |
void SVIPPI::serialize(Archive& ar, unsigned ) |
| 189 |
{ |
| 190 |
ar.template serializeBase<MSXDevice>(*this); |
| 191 |
ar.serialize("i8255", i8255); |
| 192 |
|
| 193 |
|
| 194 |
auto portC = uint8_t((prevBits << 4) | (selectedRow << 0)); |
| 195 |
ar.serialize("portC", portC); |
| 196 |
if constexpr (Archive::IS_LOADER) { |
| 197 |
selectedRow = (portC >> 0) & 0xF; |
| 198 |
uint4_t bits = (portC >> 4) & 0xF; |
| 199 |
writeC1(bits, getCurrentTime()); |
| 200 |
} |
| 201 |
ar.serialize("keyboard", keyboard); |
| 202 |
} |
| 203 |
INSTANTIATE_SERIALIZE_METHODS(SVIPPI); |
| 204 |
REGISTER_MSXDEVICE(SVIPPI, "SVI-328 PPI"); |
| 205 |
|
| 206 |
} |