| e8555c89 Andy McCall |
1 |
#include "SVIPSG.hh" |
| 2 |
|
| 3 |
#include "JoystickPort.hh" |
| 4 |
#include "LedStatus.hh" |
| 5 |
#include "MSXCPUInterface.hh" |
| 6 |
#include "MSXMotherBoard.hh" |
| 7 |
#include "serialize.hh" |
| 8 |
|
| 9 |
#include "stl.hh" |
| 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 |
namespace openmsx { |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
SVIPSG::SVIPSG(const DeviceConfig& config) |
| 52 |
: MSXDevice(config) |
| 53 |
, ports(generate_array<2>([&](auto i) { return &getMotherBoard().getJoystickPort(unsigned(i)); })) |
| 54 |
, ay8910("PSG", *this, config, getCurrentTime()) |
| 55 |
{ |
| 56 |
reset(getCurrentTime()); |
| 57 |
} |
| 58 |
|
| 59 |
SVIPSG::~SVIPSG() |
| 60 |
{ |
| 61 |
powerDown(EmuTime::dummy()); |
| 62 |
} |
| 63 |
|
| 64 |
void SVIPSG::reset(EmuTime time) |
| 65 |
{ |
| 66 |
registerLatch = 0; |
| 67 |
ay8910.reset(time); |
| 68 |
} |
| 69 |
|
| 70 |
void SVIPSG::powerDown(EmuTime ) |
| 71 |
{ |
| 72 |
getMotherBoard().getLedStatus().setLed(LedStatus::CAPS, false); |
| 73 |
} |
| 74 |
|
| 75 |
byte SVIPSG::readIO(uint16_t , EmuTime time) |
| 76 |
{ |
| 77 |
return ay8910.readRegister(registerLatch, time); |
| 78 |
} |
| 79 |
|
| 80 |
byte SVIPSG::peekIO(uint16_t , EmuTime time) const |
| 81 |
{ |
| 82 |
return ay8910.peekRegister(registerLatch, time); |
| 83 |
} |
| 84 |
|
| 85 |
void SVIPSG::writeIO(uint16_t port, byte value, EmuTime time) |
| 86 |
{ |
| 87 |
switch (port & 0x07) { |
| 88 |
case 0: |
| 89 |
registerLatch = value & 0x0F; |
| 90 |
break; |
| 91 |
case 4: |
| 92 |
ay8910.writeRegister(registerLatch, value, time); |
| 93 |
break; |
| 94 |
} |
| 95 |
} |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
byte SVIPSG::readA(EmuTime time) |
| 100 |
{ |
| 101 |
return byte(((ports[1]->read(time) & 0x0F) << 4) | |
| 102 |
((ports[0]->read(time) & 0x0F) << 0)); |
| 103 |
} |
| 104 |
|
| 105 |
void SVIPSG::writeB(byte value, EmuTime ) |
| 106 |
{ |
| 107 |
getMotherBoard().getLedStatus().setLed(LedStatus::CAPS, (value & 0x20) != 0); |
| 108 |
|
| 109 |
|
| 110 |
byte psReg = 0; |
| 111 |
switch (~value & 0x14) { |
| 112 |
case 0x04: |
| 113 |
psReg = 0xa0; |
| 114 |
break; |
| 115 |
case 0x10: |
| 116 |
psReg = 0xf0; |
| 117 |
break; |
| 118 |
} |
| 119 |
switch (~value & 0x0B) { |
| 120 |
case 1: |
| 121 |
if ((~value & 0x80) || (~value & 0x40)) { |
| 122 |
psReg = 0x50; |
| 123 |
} |
| 124 |
|
| 125 |
psReg |= 0x05; |
| 126 |
break; |
| 127 |
case 2: |
| 128 |
psReg |= 0x0a; |
| 129 |
break; |
| 130 |
case 8: |
| 131 |
psReg |= 0x0f; |
| 132 |
break; |
| 133 |
} |
| 134 |
getMotherBoard().getCPUInterface().setPrimarySlots(psReg); |
| 135 |
|
| 136 |
prev = value; |
| 137 |
} |
| 138 |
|
| 139 |
template<typename Archive> |
| 140 |
void SVIPSG::serialize(Archive& ar, unsigned ) |
| 141 |
{ |
| 142 |
ar.template serializeBase<MSXDevice>(*this); |
| 143 |
ar.serialize("ay8910", ay8910, |
| 144 |
"registerLatch", registerLatch); |
| 145 |
byte portB = prev; |
| 146 |
ar.serialize("portB", portB); |
| 147 |
if constexpr (Archive::IS_LOADER) { |
| 148 |
writeB(portB, getCurrentTime()); |
| 149 |
} |
| 150 |
} |
| 151 |
INSTANTIATE_SERIALIZE_METHODS(SVIPSG); |
| 152 |
REGISTER_MSXDEVICE(SVIPSG, "SVI-328 PSG"); |
| 153 |
|
| 154 |
} |