| e8555c89 Andy McCall |
1 |
#include "MSXOPL3Cartridge.hh" |
| 2 |
|
| 3 |
#include "serialize.hh" |
| 4 |
|
| 5 |
#include "unreachable.hh" |
| 6 |
|
| 7 |
namespace openmsx { |
| 8 |
|
| 9 |
MSXOPL3Cartridge::MSXOPL3Cartridge(const DeviceConfig& config) |
| 10 |
: MSXDevice(config) |
| 11 |
, ymf262(getName(), config, false) |
| 12 |
{ |
| 13 |
reset(getCurrentTime()); |
| 14 |
} |
| 15 |
|
| 16 |
void MSXOPL3Cartridge::reset(EmuTime time) |
| 17 |
{ |
| 18 |
ymf262.reset(time); |
| 19 |
|
| 20 |
|
| 21 |
opl3latch = 0; |
| 22 |
} |
| 23 |
|
| 24 |
byte MSXOPL3Cartridge::readIO(uint16_t port, EmuTime ) |
| 25 |
{ |
| 26 |
|
| 27 |
switch (port & 0x03) { |
| 28 |
case 0: |
| 29 |
case 2: |
| 30 |
return ymf262.readStatus(); |
| 31 |
case 1: |
| 32 |
case 3: |
| 33 |
return ymf262.readReg(opl3latch); |
| 34 |
default: |
| 35 |
UNREACHABLE; |
| 36 |
} |
| 37 |
} |
| 38 |
|
| 39 |
byte MSXOPL3Cartridge::peekIO(uint16_t port, EmuTime ) const |
| 40 |
{ |
| 41 |
switch (port & 0x03) { |
| 42 |
case 0: |
| 43 |
case 2: |
| 44 |
return ymf262.peekStatus(); |
| 45 |
case 1: |
| 46 |
case 3: |
| 47 |
return ymf262.peekReg(opl3latch); |
| 48 |
default: |
| 49 |
UNREACHABLE; |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
void MSXOPL3Cartridge::writeIO(uint16_t port, byte value, EmuTime time) |
| 54 |
{ |
| 55 |
switch (port & 0x03) { |
| 56 |
case 0: |
| 57 |
opl3latch = value; |
| 58 |
break; |
| 59 |
case 2: |
| 60 |
opl3latch = value | 0x100; |
| 61 |
break; |
| 62 |
case 1: |
| 63 |
case 3: |
| 64 |
ymf262.writeReg(opl3latch, value, time); |
| 65 |
break; |
| 66 |
default: |
| 67 |
UNREACHABLE; |
| 68 |
} |
| 69 |
} |
| 70 |
|
| 71 |
template<typename Archive> |
| 72 |
void MSXOPL3Cartridge::serialize(Archive& ar, unsigned ) |
| 73 |
{ |
| 74 |
ar.template serializeBase<MSXDevice>(*this); |
| 75 |
ar.serialize("ymf262", ymf262, |
| 76 |
"opl3latch", opl3latch); |
| 77 |
} |
| 78 |
INSTANTIATE_SERIALIZE_METHODS(MSXOPL3Cartridge); |
| 79 |
REGISTER_MSXDEVICE(MSXOPL3Cartridge, "OPL3Cartridge"); |
| 80 |
|
| 81 |
} |