| e8555c89 Andy McCall |
1 |
#include "Video9000.hh" |
| 2 |
|
| 3 |
#include "Display.hh" |
| 4 |
#include "PostProcessor.hh" |
| 5 |
#include "V9990.hh" |
| 6 |
#include "VDP.hh" |
| 7 |
|
| 8 |
#include "CommandException.hh" |
| 9 |
#include "Event.hh" |
| 10 |
#include "EventDistributor.hh" |
| 11 |
#include "MSXMotherBoard.hh" |
| 12 |
#include "Reactor.hh" |
| 13 |
#include "VideoSourceSetting.hh" |
| 14 |
#include "serialize.hh" |
| 15 |
|
| 16 |
namespace openmsx { |
| 17 |
|
| 18 |
Video9000::Video9000(const DeviceConfig& config) |
| 19 |
: MSXDevice(config) |
| 20 |
, VideoLayer(getMotherBoard(), getName()) |
| 21 |
, videoSourceSetting(getMotherBoard().getVideoSource()) |
| 22 |
{ |
| 23 |
|
| 24 |
EventDistributor& distributor = getReactor().getEventDistributor(); |
| 25 |
distributor.registerEventListener(EventType::FINISH_FRAME, *this); |
| 26 |
getReactor().getDisplay().attach(*this); |
| 27 |
} |
| 28 |
|
| 29 |
void Video9000::init() |
| 30 |
{ |
| 31 |
MSXDevice::init(); |
| 32 |
auto refs = getReferences(); |
| 33 |
bool error = false; |
| 34 |
if (refs.size() != 2) error = true; |
| 35 |
if (!error && !dynamic_cast<VDP*>(refs[0])) { |
| 36 |
std::swap(refs[0], refs[1]); |
| 37 |
} |
| 38 |
if (!error) vdp = dynamic_cast<VDP* >(refs[0]); |
| 39 |
if (!error) v9990 = dynamic_cast<V9990*>(refs[1]); |
| 40 |
if (error || !vdp || !v9990) { |
| 41 |
throw MSXException( |
| 42 |
"Invalid Video9000 configuration: " |
| 43 |
"need reference to VDP and V9990 device."); |
| 44 |
} |
| 45 |
reset(EmuTime::dummy()); |
| 46 |
} |
| 47 |
|
| 48 |
Video9000::~Video9000() |
| 49 |
{ |
| 50 |
EventDistributor& distributor = getReactor().getEventDistributor(); |
| 51 |
distributor.unregisterEventListener(EventType::FINISH_FRAME, *this); |
| 52 |
getReactor().getDisplay().detach(*this); |
| 53 |
} |
| 54 |
|
| 55 |
void Video9000::reset(EmuTime time) |
| 56 |
{ |
| 57 |
Video9000::writeIO(0x6f, 0x10, time); |
| 58 |
} |
| 59 |
|
| 60 |
void Video9000::writeIO(uint16_t , uint8_t newValue, EmuTime ) |
| 61 |
{ |
| 62 |
if (newValue == value) return; |
| 63 |
value = newValue; |
| 64 |
recalculate(); |
| 65 |
} |
| 66 |
|
| 67 |
void Video9000::recalculate() |
| 68 |
{ |
| 69 |
int video9000id = getVideoSource(); |
| 70 |
v99x8Layer = vdp ->getPostProcessor(); |
| 71 |
v9990Layer = v9990->getPostProcessor(); |
| 72 |
assert(!!v99x8Layer == !!v9990Layer); |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
bool showV99x8 = ((value & 0x10) == 0x10); |
| 78 |
bool showV9990 = ((value & 0x18) != 0x10); |
| 79 |
assert(showV99x8 || showV9990); |
| 80 |
using enum VideoLayer::Video9000Active; |
| 81 |
if (v99x8Layer) v99x8Layer->setVideo9000Active( |
| 82 |
video9000id, |
| 83 |
showV99x8 ? (showV9990 ? BACK : FRONT) : NO); |
| 84 |
if (v9990Layer) v9990Layer->setVideo9000Active( |
| 85 |
video9000id, showV9990 ? FRONT : NO); |
| 86 |
activeLayer = showV9990 ? v9990Layer : v99x8Layer; |
| 87 |
|
| 88 |
recalculateVideoSource(); |
| 89 |
} |
| 90 |
|
| 91 |
void Video9000::recalculateVideoSource() |
| 92 |
{ |
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
bool superimpose = ((value & 0x18) == 0x18); |
| 97 |
v9990->setExternalVideoSource( |
| 98 |
superimpose && (videoSourceSetting.getSource() == getVideoSource())); |
| 99 |
} |
| 100 |
|
| 101 |
void Video9000::preVideoSystemChange() noexcept |
| 102 |
{ |
| 103 |
activeLayer = nullptr; |
| 104 |
} |
| 105 |
|
| 106 |
void Video9000::postVideoSystemChange() noexcept |
| 107 |
{ |
| 108 |
|
| 109 |
|
| 110 |
} |
| 111 |
|
| 112 |
void Video9000::paint(OutputSurface& output) |
| 113 |
{ |
| 114 |
if (!activeLayer) { |
| 115 |
recalculate(); |
| 116 |
} |
| 117 |
|
| 118 |
|
| 119 |
activeLayer->paint(output); |
| 120 |
} |
| 121 |
|
| 122 |
void Video9000::takeRawScreenShot(std::optional<unsigned> height, const std::string& filename) |
| 123 |
{ |
| 124 |
auto* layer = dynamic_cast<VideoLayer*>(activeLayer); |
| 125 |
if (!layer) { |
| 126 |
throw CommandException("TODO"); |
| 127 |
} |
| 128 |
layer->takeRawScreenShot(height, filename); |
| 129 |
} |
| 130 |
|
| 131 |
bool Video9000::signalEvent(const Event& event) |
| 132 |
{ |
| 133 |
int video9000id = getVideoSource(); |
| 134 |
|
| 135 |
assert(getType(event) == EventType::FINISH_FRAME); |
| 136 |
const auto& ffe = get_event<FinishFrameEvent>(event); |
| 137 |
if (ffe.isSkipped()) return false; |
| 138 |
if (videoSourceSetting.getSource() != video9000id) return false; |
| 139 |
|
| 140 |
bool superimpose = ((value & 0x18) == 0x18); |
| 141 |
if (superimpose && v99x8Layer && v9990Layer && |
| 142 |
(ffe.getSource() == v99x8Layer->getVideoSource())) { |
| 143 |
|
| 144 |
v9990Layer->setSuperimposeVdpFrame(v99x8Layer->getPaintFrame()); |
| 145 |
} |
| 146 |
|
| 147 |
bool showV9990 = ((value & 0x18) != 0x10); |
| 148 |
if (( showV9990 && v9990Layer && (ffe.getSource() == v9990Layer->getVideoSource())) || |
| 149 |
(!showV9990 && v99x8Layer && (ffe.getSource() == v99x8Layer->getVideoSource()))) { |
| 150 |
getReactor().getEventDistributor().distributeEvent( |
| 151 |
FinishFrameEvent(video9000id, video9000id, false)); |
| 152 |
} |
| 153 |
return false; |
| 154 |
} |
| 155 |
|
| 156 |
void Video9000::update(const Setting& setting) noexcept |
| 157 |
{ |
| 158 |
VideoLayer::update(setting); |
| 159 |
if (&setting == &videoSourceSetting) { |
| 160 |
recalculateVideoSource(); |
| 161 |
} |
| 162 |
} |
| 163 |
|
| 164 |
template<typename Archive> |
| 165 |
void Video9000::serialize(Archive& ar, unsigned ) |
| 166 |
{ |
| 167 |
ar.template serializeBase<MSXDevice>(*this); |
| 168 |
ar.serialize("value", value); |
| 169 |
if constexpr (Archive::IS_LOADER) { |
| 170 |
recalculate(); |
| 171 |
} |
| 172 |
} |
| 173 |
INSTANTIATE_SERIALIZE_METHODS(Video9000); |
| 174 |
REGISTER_MSXDEVICE(Video9000, "Video9000"); |
| 175 |
|
| 176 |
} |