36VDPVRAM::LogicalVRAMDebuggable::LogicalVRAMDebuggable(
const VDP& vdp_)
37 : SimpleDebuggable(vdp_.getMotherBoard(), vdp_.getName() ==
"VDP" ?
"VRAM" :
38 vdp_.getName() +
" VRAM",
39 "CPU view on video RAM given the current display mode.",
44unsigned VDPVRAM::LogicalVRAMDebuggable::transform(
unsigned address)
46 const auto& vram =
OUTER(VDPVRAM, logicalVRAMDebug);
47 return vram.vdp.getDisplayMode().isPlanar()
48 ? ((address << 16) | (address >> 1)) & 0x1FFFF
52byte VDPVRAM::LogicalVRAMDebuggable::read(
unsigned address, EmuTime::param time)
54 auto& vram =
OUTER(VDPVRAM, logicalVRAMDebug);
55 return vram.cpuRead(
transform(address), time);
58void VDPVRAM::LogicalVRAMDebuggable::write(
59 unsigned address,
byte value, EmuTime::param time)
61 auto& vram =
OUTER(VDPVRAM, logicalVRAMDebug);
62 vram.cpuWrite(
transform(address), value, time);
68VDPVRAM::PhysicalVRAMDebuggable::PhysicalVRAMDebuggable(
69 const VDP& vdp_,
unsigned actualSize_)
70 : SimpleDebuggable(vdp_.getMotherBoard(), vdp_.getName() ==
"VDP" ?
71 "physical VRAM" :
strCat(
"physical ", vdp_.getName(),
" VRAM"),
72 "VDP-screen-mode-independent view on the video RAM.",
77byte VDPVRAM::PhysicalVRAMDebuggable::read(
unsigned address, EmuTime::param time)
79 auto& vram =
OUTER(VDPVRAM, physicalVRAMDebug);
80 return vram.cpuRead(address, time);
83void VDPVRAM::PhysicalVRAMDebuggable::write(
84 unsigned address,
byte value, EmuTime::param time)
86 auto& vram =
OUTER(VDPVRAM, physicalVRAMDebug);
87 vram.cpuWrite(address, value, time);
93static constexpr unsigned bufferSize(
unsigned size)
100 return std::max(0x20000u, size);
103VDPVRAM::VDPVRAM(
VDP& vdp_,
unsigned size, EmuTime::param time)
105 , data(*vdp_.getDeviceConfig2().getXML(), bufferSize(size))
106 , logicalVRAMDebug (vdp)
107 , physicalVRAMDebug(vdp, size)
109 , vrMode(vdp.getVRMode())
110 , cmdReadWindow(data)
111 , cmdWriteWindow(data)
115 , bitmapVisibleWindow(data)
116 , bitmapCacheWindow(data)
117 , spriteAttribTable(data)
118 , spritePatternTable(data)
132 if (data.
size() != actualSize) {
133 assert(data.
size() > actualSize);
152 cmdEngine->
sync(time);
160 cmdEngine->
sync(time);
165void VDPVRAM::setSizeMask(EmuTime::param time)
167 unsigned newSizeMask = (
170 ? (std::bit_ceil(actualSize) - 1) | (1u << 16)
172 : (
std::min(
std::bit_ceil(actualSize), 0x4000u) - 1) | (1u << 14)
185 sizeMask = newSizeMask;
187static constexpr unsigned swapAddr(
unsigned x)
193 return 1 | ((x & 0x007F) << 1) | ((x & 0x7FC0) << 2);
197 if (vrMode == newVRmode) {
207 for (
int i = 0x7FFF; i >=0; --i) {
208 std::swap(data[i], data[swapAddr(i)]);
212 for (
auto i :
xrange(0x8000)) {
213 std::swap(data[i], data[swapAddr(i)]);
220 renderer = newRenderer;
275 std::array<byte, 0x4000> tmp;
278 for (
unsigned addr8 = 0; addr8 < 0x4000; addr8 += 64) {
279 unsigned addr4 = (addr8 & 0x203F) |
280 ((addr8 & 0x1000) >> 6) |
281 ((addr8 & 0x0FC0) << 1);
283 subspan<64>(tmp, addr4));
287 for (
unsigned addr4 = 0; addr4 < 0x4000; addr4 += 64) {
288 unsigned addr8 = (addr4 & 0x203F) |
289 ((addr4 & 0x0040) << 6) |
290 ((addr4 & 0x1F80) >> 1);
292 subspan<64>(tmp, addr8));
300template<
typename Archive>
303 ar.serialize(
"baseAddr", baseAddr,
304 "baseMask", origBaseMask,
305 "indexMask", indexMask);
306 if constexpr (Archive::IS_LOADER) {
307 effectiveBaseMask = origBaseMask & sizeMask;
308 combiMask = ~effectiveBaseMask | indexMask;
313template<
typename Archive>
316 if constexpr (Archive::IS_LOADER) {
318 setSizeMask(
static_cast<MSXDevice&
>(vdp).getCurrentTime());
321 ar.serialize_blob(
"data", std::span{data.
data(), actualSize});
Represents a VDP display mode.
An MSXDevice is an emulated hardware component connected to the bus of the emulated MSX.
Abstract base class for Renderers.
virtual void updateDisplayMode(DisplayMode mode, EmuTime::param time)=0
Informs the renderer of a VDP display mode change.
virtual void updateSpritesEnabled(bool enabled, EmuTime::param time)=0
Informs the renderer of a VDP sprites enabled change.
virtual void updateDisplayEnabled(bool enabled, EmuTime::param time)=0
Informs the renderer of a VDP display enabled change.
void updateDisplayMode(DisplayMode mode, EmuTime::param time)
Informs the sprite checker of a VDP display mode change.
void updateDisplayEnabled(bool enabled, EmuTime::param time)
Informs the sprite checker of a VDP display enabled change.
void updateSpritesEnabled(bool enabled, EmuTime::param time)
Informs the sprite checker of sprite enable changes.
void updateDisplayMode(DisplayMode mode, bool cmdBit, EmuTime::param time)
Informs the command engine of a VDP display mode change.
void sync(EmuTime::param time)
Synchronizes the command engine with the VDP.
Manages VRAM contents and synchronizes the various users of the VRAM.
void updateSpritesEnabled(bool enabled, EmuTime::param time)
Used by the VDP to signal sprites enabled changes.
VRAMWindow spriteAttribTable
void clear()
Initialize VRAM content to power-up state.
void setRenderer(Renderer *renderer, EmuTime::param time)
void updateVRMode(bool mode, EmuTime::param time)
Change between VR=0 and VR=1 mode.
VRAMWindow bitmapCacheWindow
void updateDisplayEnabled(bool enabled, EmuTime::param time)
Used by the VDP to signal display enabled changes.
void updateDisplayMode(DisplayMode mode, bool cmdBit, EmuTime::param time)
Used by the VDP to signal display mode changes.
VRAMWindow bitmapVisibleWindow
void serialize(Archive &ar, unsigned version)
VRAMWindow spritePatternTable
VRAMWindow cmdWriteWindow
void change4k8kMapping(bool mapping8k)
TMS99x8 VRAM can be mapped in two ways.
Unified implementation of MSX Video Display Processors (VDPs).
bool isInsideFrame(EmuTime::param time) const
Is the given timestamp inside the current frame? Mainly useful for debugging, because relevant timest...
bool getVRMode() const
Returns current VR mode.
void setMask(unsigned newBaseMask, unsigned newIndexMask, unsigned newSizeMask, EmuTime::param time)
Sets the mask and enables this window.
void serialize(Archive &ar, unsigned version)
void setSizeMask(unsigned newSizeMask, EmuTime::param time)
Inform VRAMWindow of changed sizeMask.
VRAMWindow(const VRAMWindow &)=delete
void setObserver(VRAMObserver *newObserver)
Register an observer on this VRAM window.
void resetObserver()
Unregister the observer of this VRAM window.
This file implemented 3 utility functions:
constexpr void fill(ForwardRange &&range, const T &value)
auto transform(InputRange &&range, OutputIter out, UnaryOperation op)
constexpr auto copy(InputRange &&range, OutputIter out)
#define OUTER(type, member)
constexpr auto subspan(Range &&range, size_t offset, size_t count=std::dynamic_extent)
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
constexpr auto xrange(T e)