31 namespace VDPAccessSlots {
77 void powerUp(EmuTime::param time)
override;
78 void reset(EmuTime::param time)
override;
79 [[nodiscard]]
byte readIO(
word port, EmuTime::param time)
override;
80 [[nodiscard]]
byte peekIO(
word port, EmuTime::param time)
const override;
81 void writeIO(
word port,
byte value, EmuTime::param time)
override;
94 return (version & VM_MSX1) != 0;
101 return (version & VM_PAL) != 0;
108 return (version & VM_NO_MIRRORING) != 0;
115 return (version & VM_PALCOL_MIRRORING) != 0;
122 return (version & VM_VRAM_REMAPPING) != 0;
128 [[nodiscard]]
inline bool hasYJK()
const {
129 return (version & VM_YJK) != 0;
136 [[nodiscard]] std::array<std::array<uint8_t, 3>, 16>
getMSX1Palette()
const;
162 return superimposing;
168 return *spriteChecker;
175 return (controlRegs[8] & 0x20) == 0;
193 return controlRegs[7] >> 4;
205 byte reg7 = controlRegs[7];
217 return controlRegs[12] >> 4;
224 return controlRegs[12] & 0x0F;
240 return palette[index];
249 return isDisplayArea && displayEnabled;
257 return displayEnabled &&
267 return displayEnabled && spriteEnabled;
274 return spriteEnabled;
281 return controlRegs[23];
290 return controlRegs[27];
299 return controlRegs[26];
308 return (controlRegs[25] & 0x02) != 0;
318 return (controlRegs[25] & 0x01) && (controlRegs[2] & 0x20);
359 return (controlRegs[1] & 4) != 0;
375 return (controlRegs[9] & 4) != 0;
382 return (statusReg2 & 2) != 0;
399 return (((~controlRegs[9] & 4) << 6) | ((statusReg2 & 2) << 7)) &
413 return (!p.state) << 8;
430 if (blinkCount == 0) {
431 return {blinkState, blinkCount};
434 unsigned evenLen = ((controlRegs[13] >> 4) & 0x0F) * 10;
435 unsigned oddLen = ((controlRegs[13] >> 0) & 0x0F) * 10;
436 unsigned totalLen = evenLen + oddLen;
437 assert(totalLen != 0);
440 bool resultState = blinkState;
446 std::swap(evenLen, oddLen);
448 int newCount = blinkCount - line;
451 resultState = !resultState;
455 resultState = !resultState;
457 assert(newCount > 0);
460 return {resultState, newCount};
471 return frameStartTime.
getTime();
477 return ((controlRegs[1] & 2) << 2) + 8;
483 return controlRegs[1] & 1;
490 return (controlRegs[25] & 0x40) != 0;
496 return palTiming ? 313 : 262;
515 return time >= frameStartTime.
getTime() &&
523 return horizontalAdjust;
534 return 100 + 102 + 56
535 + (horizontalAdjust - 7) * 4
580 statusReg0 = (statusReg0 & 0x80) | (value & 0x7F);
587 return (controlRegs[8] & 8) != 0;
593 externalVideo = externalSource;
599 return brokenCmdTiming;
616 EmuTime::param time, EmuTime::param limit)
const;
643 int LARGEST_STALL = 184 + 2 * 70;
647 syncCmdDone.setSyncPoint(
t);
650 template<
typename Archive>
651 void serialize(Archive& ar,
unsigned version);
657 static constexpr
unsigned VM_MSX1 = 1;
658 static constexpr
unsigned VM_PAL = 2;
659 static constexpr
unsigned VM_NO_MIRRORING = 4;
660 static constexpr
unsigned VM_PALCOL_MIRRORING = 8;
661 static constexpr
unsigned VM_VRAM_REMAPPING = 16;
662 static constexpr
unsigned VM_TOSHIBA_PALETTE = 32;
663 static constexpr
unsigned VM_YJK = 64;
664 static constexpr
unsigned VM_YM2220_PALETTE = 128;
672 TMS99X8A = VM_MSX1 | VM_PALCOL_MIRRORING | VM_VRAM_REMAPPING,
675 TMS9929A = VM_MSX1 | VM_PALCOL_MIRRORING | VM_VRAM_REMAPPING | VM_PAL,
678 TMS9129 = VM_MSX1 | VM_PAL,
684 T6950PAL = VM_MSX1 | VM_TOSHIBA_PALETTE | VM_NO_MIRRORING | VM_PAL,
687 T6950NTSC = VM_MSX1 | VM_TOSHIBA_PALETTE | VM_NO_MIRRORING,
690 T7937APAL = VM_MSX1 | VM_TOSHIBA_PALETTE | VM_PAL,
693 T7937ANTSC = VM_MSX1 | VM_TOSHIBA_PALETTE,
696 YM2220PAL = VM_MSX1 | VM_YM2220_PALETTE | VM_PALCOL_MIRRORING | VM_PAL,
699 YM2220NTSC = VM_MSX1 | VM_YM2220_PALETTE | VM_PALCOL_MIRRORING,
714 ~SyncBase() =
default;
717 struct SyncVSync final :
public SyncBase {
718 explicit SyncVSync(
VDP& vdp) : SyncBase(vdp) {}
719 void executeUntil(EmuTime::param time)
override {
725 struct SyncDisplayStart final :
public SyncBase {
726 explicit SyncDisplayStart(
VDP& vdp) : SyncBase(vdp) {}
727 void executeUntil(EmuTime::param time)
override {
728 auto& vdp =
OUTER(
VDP, syncDisplayStart);
729 vdp.execDisplayStart(time);
733 struct SyncVScan final :
public SyncBase {
734 explicit SyncVScan(
VDP& vdp) : SyncBase(vdp) {}
735 void executeUntil(EmuTime::param time)
override {
741 struct SyncHScan final :
public SyncBase {
742 explicit SyncHScan(
VDP& vdp) : SyncBase(vdp) {}
743 void executeUntil(EmuTime::param )
override {
749 struct SyncHorAdjust final :
public SyncBase {
750 explicit SyncHorAdjust(
VDP& vdp) : SyncBase(vdp) {}
751 void executeUntil(EmuTime::param time)
override {
752 auto& vdp =
OUTER(
VDP, syncHorAdjust);
753 vdp.execHorAdjust(time);
757 struct SyncSetMode final :
public SyncBase {
758 explicit SyncSetMode(
VDP& vdp) : SyncBase(vdp) {}
759 void executeUntil(EmuTime::param time)
override {
760 auto& vdp =
OUTER(
VDP, syncSetMode);
761 vdp.execSetMode(time);
765 struct SyncSetBlank final :
public SyncBase {
766 explicit SyncSetBlank(
VDP& vdp) : SyncBase(vdp) {}
767 void executeUntil(EmuTime::param time)
override {
768 auto& vdp =
OUTER(
VDP, syncSetBlank);
769 vdp.execSetBlank(time);
773 struct SyncSetSprites final :
public SyncBase {
774 explicit SyncSetSprites(
VDP& vdp) : SyncBase(vdp) {}
775 void executeUntil(EmuTime::param time)
override {
776 auto& vdp =
OUTER(
VDP, syncSetSprites);
777 vdp.execSetSprites(time);
781 struct SyncCpuVramAccess final :
public SyncBase {
782 explicit SyncCpuVramAccess(
VDP& vdp) : SyncBase(vdp) {}
783 void executeUntil(EmuTime::param time)
override {
784 auto& vdp =
OUTER(
VDP, syncCpuVramAccess);
785 vdp.execCpuVramAccess(time);
789 struct SyncCmdDone final :
public SyncBase {
790 explicit SyncCmdDone(
VDP& vdp) : SyncBase(vdp) {}
791 void executeUntil(EmuTime::param time)
override {
792 auto& vdp =
OUTER(
VDP, syncCmdDone);
793 vdp.execSyncCmdDone(time);
797 void execVSync(EmuTime::param time);
798 void execDisplayStart(EmuTime::param time);
799 void execVScan(EmuTime::param time);
801 void execHorAdjust(EmuTime::param time);
802 void execSetMode(EmuTime::param time);
803 void execSetBlank(EmuTime::param time);
804 void execSetSprites(EmuTime::param time);
805 void execCpuVramAccess(EmuTime::param time);
806 void execSyncCmdDone(EmuTime::param time);
811 [[nodiscard]]
inline int getNumberOfLines()
const {
812 return controlRegs[9] & 0x80 ? 212 : 192;
818 [[nodiscard]]
int getVerticalAdjust()
const {
819 return (controlRegs[18] >> 4) ^ 0x07;
831 [[nodiscard]]
inline bool getHR(
int ticksThisFrame)
const {
837 static constexpr
int HBLANK_LEN_TXT = 404;
841 static constexpr
int HBLANK_LEN_GFX = 312;
843 < (displayMode.
isTextMode() ? HBLANK_LEN_TXT : HBLANK_LEN_GFX);
847 void preVideoSystemChange() noexcept override;
848 void postVideoSystemChange() noexcept override;
860 void resetMasks(EmuTime::param time);
865 void frameStart(EmuTime::param time);
874 void scheduleDisplayStart(EmuTime::param time);
881 void scheduleVScan(EmuTime::param time);
888 void scheduleHScan(EmuTime::param time);
892 void vramWrite(
byte value, EmuTime::param time);
896 [[nodiscard]]
byte vramRead(EmuTime::param time);
899 void scheduleCpuVramAccess(
bool isRead,
byte write, EmuTime::param time);
900 void executeCpuVramAccess(EmuTime::param time);
904 [[nodiscard]]
byte peekStatusReg(
byte reg, EmuTime::param time) const;
905 [[nodiscard]]
byte readStatusReg(
byte reg, EmuTime::param time);
909 void changeRegister(
byte reg,
byte val, EmuTime::param time);
913 void syncAtNextLine(SyncBase& type, EmuTime::param time);
917 void createRenderer();
922 void updateNameBase(EmuTime::param time);
927 void updateColorBase(EmuTime::param time);
932 void updatePatternBase(EmuTime::param time);
937 void updateSpriteAttributeBase(EmuTime::param time);
942 void updateSpritePatternBase(EmuTime::param time);
947 void updateDisplayMode(DisplayMode newMode,
bool cmdBit, EmuTime::param time);
955 void setPalette(
int index,
word grb, EmuTime::param time);
958 void update(const Setting&
setting) noexcept override;
962 EnumSetting<
bool>& cmdTiming;
963 EnumSetting<
bool>& tooFastAccess;
965 struct RegDebug final : SimpleDebuggable {
966 explicit RegDebug(
VDP& vdp);
967 [[nodiscard]]
byte read(
unsigned address)
override;
968 void write(
unsigned address,
byte value, EmuTime::param time)
override;
971 struct StatusRegDebug final : SimpleDebuggable {
972 explicit StatusRegDebug(
VDP& vdp);
973 [[nodiscard]]
byte read(
unsigned address, EmuTime::param time)
override;
976 struct PaletteDebug final : SimpleDebuggable {
977 explicit PaletteDebug(
VDP& vdp);
978 [[nodiscard]]
byte read(
unsigned address)
override;
979 void write(
unsigned address,
byte value, EmuTime::param time)
override;
982 struct VRAMPointerDebug final : SimpleDebuggable {
983 explicit VRAMPointerDebug(
VDP& vdp);
984 [[nodiscard]]
byte read(
unsigned address)
override;
985 void write(
unsigned address,
byte value, EmuTime::param time)
override;
988 class Info :
public InfoTopic {
990 void execute(std::span<const TclObject> tokens,
991 TclObject& result)
const override;
992 [[nodiscard]] std::string help(std::span<const TclObject> tokens)
const override;
993 [[nodiscard]]
virtual int calc(
const EmuTime& time)
const = 0;
995 Info(
VDP& vdp_,
const std::string& name, std::string helpText_);
998 const std::string helpText;
1001 struct FrameCountInfo final :
Info {
1002 explicit FrameCountInfo(
VDP& vdp);
1003 [[nodiscard]]
int calc(
const EmuTime& time)
const override;
1006 struct CycleInFrameInfo final :
Info {
1007 explicit CycleInFrameInfo(
VDP& vdp);
1008 [[nodiscard]]
int calc(
const EmuTime& time)
const override;
1011 struct LineInFrameInfo final :
Info {
1012 explicit LineInFrameInfo(
VDP& vdp);
1013 [[nodiscard]]
int calc(
const EmuTime& time)
const override;
1016 struct CycleInLineInfo final :
Info {
1017 explicit CycleInLineInfo(
VDP& vdp);
1018 [[nodiscard]]
int calc(
const EmuTime& time)
const override;
1021 struct MsxYPosInfo final :
Info {
1022 explicit MsxYPosInfo(
VDP& vdp);
1023 [[nodiscard]]
int calc(
const EmuTime& time)
const override;
1026 struct MsxX256PosInfo final :
Info {
1027 explicit MsxX256PosInfo(
VDP& vdp);
1028 [[nodiscard]]
int calc(
const EmuTime& time)
const override;
1031 struct MsxX512PosInfo final :
Info {
1032 explicit MsxX512PosInfo(
VDP& vdp);
1033 [[nodiscard]]
int calc(
const EmuTime& time)
const override;
1038 std::unique_ptr<Renderer> renderer;
1042 std::unique_ptr<VDPCmdEngine> cmdEngine;
1046 std::unique_ptr<SpriteChecker> spriteChecker;
1050 std::unique_ptr<VDPVRAM> vram;
1055 const RawFrame* externalVideo;
1062 const RawFrame* superimposing;
1078 EmuTime displayStartSyncTime;
1082 EmuTime vScanSyncTime;
1086 EmuTime hScanSyncTime;
1088 TclCallback tooFastCallback;
1120 int horizontalScanOffset;
1125 int horizontalAdjust;
1129 byte controlRegs[32];
1143 byte controlValueMasks[32];
1204 bool registerDataStored;
1208 bool paletteDataStored;
1222 bool cpuVramReqIsRead;
1223 bool pendingCpuAccess;
1228 bool cpuExtendedVram;
1235 DisplayMode displayMode;
1241 bool displayEnabled;
1253 bool warningPrinted;
1256 bool brokenCmdTiming;
1257 bool allowTooFastAccess;
1261 const byte fixedVDPIOdelayCycles;
static constexpr EmuDuration duration(unsigned ticks)
Calculates the duration of the given number of ticks at this clock's frequency.
constexpr unsigned getTicksTill_fast(EmuTime::param e) const
Same as above, only faster, Though the time interval may not be too large.
constexpr EmuTime::param getTime() const
Gets the time at which the last clock tick occurred.
Represents a VDP display mode.
constexpr bool isTextMode() const
Is the current mode a text mode? Text1 and Text2 are text modes.
constexpr byte getByte() const
Get the display mode as a byte: YAE YJK M5..M1 combined.
constexpr int getSpriteMode(bool isMSX1) const
Get the sprite mode of this display mode.
An MSXDevice is an emulated hardware component connected to the bus of the emulated MSX.
Scheduler & getScheduler() const
EmuTime::param getCurrentTime() const
Generic Gang-of-Four Observer class, templatized edition.
Abstract base class for post processors.
A video frame as output by the VDP scanline conversion unit, before any postprocessing filters are ap...
void setSyncPoint(EmuTime::param timestamp)
bool pendingSyncPoint() const
virtual byte read(unsigned address, EmuTime::param time)
byte read(unsigned address) override
void write(unsigned address, byte value) override
VDP-VRAM access slot calculator, meant to be used in the inner loops of the VDPCmdEngine commands.
Manages VRAM contents and synchronizes the various users of the VRAM.
Unified implementation of MSX Video Display Processors (VDPs).
int getHorizontalAdjust() const
This is a combination of the (horizontal) set adjust register and the YJK-mode bit.
bool getEvenOdd() const
Is the even or odd field being displayed?
word getPalette(int index) const
Gets a palette entry.
int getLinesPerFrame() const
Gets the number of lines per frame.
int getEvenOddMask(int line) const
Similar to the above getEvenOddMask() method, but can also be called when 'isFastBlinkEnabled() == tr...
int getEvenOddMask() const
Expresses the state of even/odd page interchange in a mask on the line number.
VDPVRAM & getVRAM()
Get the VRAM object for this VDP.
bool spritesEnabled() const
Are sprites enabled?
int getSpriteSize() const
Gets the sprite size in pixels (8/16).
int getLeftBackground() const
Gets the number of VDP clockticks between start of line and the time when the background pixel with X...
int getBackgroundColor() const
Gets the current background color.
bool getBrokenCmdTiming() const
Value of the cmdTiming setting, true means commands have infinite speed.
bool isEvenOddEnabled() const
Get even/odd page alternation status.
void writeIO(word port, byte value, EmuTime::param time) override
Write a byte to a given IO port at a certain time to this device.
void scheduleCmdSync(EmuTime t)
Only used when there are commandExecuting-probe listeners.
bool spritesEnabledRegister() const
Still faster variant (just looks at the sprite-enabled-bit).
BlinkStateCount calculateLineBlinkState(unsigned line) const
static constexpr int TICKS_PER_SECOND
Number of VDP clock ticks per second.
bool isFastBlinkEnabled() const
Get 'fast-blink' status.
std::array< std::array< uint8_t, 3 >, 16 > getMSX1Palette() const
Get the (fixed) palette for this MSX1 VDP.
PostProcessor * getPostProcessor() const
Used by Video9000 to be able to couple the VDP and V9990 output.
bool isVDPwithPALonly() const
Is this a VDP only capable of PAL?
bool getCmdBit() const
Are commands possible in non Graphic modes? (V9958 only)
VDPAccessSlots::Calculator getAccessSlotCalculator(EmuTime::param time, EmuTime::param limit) const
Same as getAccessSlot(), but it can be much faster for repeated calls, e.g.
void reset(EmuTime::param time) override
This method is called on reset.
bool isBorderMasked() const
Gets the current border mask setting.
byte getStatusReg0() const
Should only be used by SpriteChecker.
bool spritesEnabledFast() const
Same as spritesEnabled(), but may only be called in sprite mode 1 or 2.
int getForegroundColor() const
Gets the current foreground color.
static constexpr int TICKS_PER_LINE
Number of VDP clock ticks per line.
int getBlinkBackgroundColor() const
Gets the current blinking color for blinking text.
int getTicksPerFrame() const
Gets the number of VDP clockticks (21MHz) per frame.
bool isInsideFrame(EmuTime::param time) const
Is the given timestamp inside the current frame? Mainly useful for debugging, because relevant timest...
void serialize(Archive &ar, unsigned version)
void setSpriteStatus(byte value)
Should only be used by SpriteChecker.
Clock< TICKS_PER_SECOND > VDPClock
byte getHorizontalScrollHigh() const
Gets the current horizontal scroll higher bits.
int getRightBorder() const
Gets the number of VDP clockticks between start of line and the start of the right border.
DisplayMode getDisplayMode() const
Get the display mode the VDP is in.
bool getBlinkState() const
Gets the current blink state.
int getLineZero() const
Get the absolute line number of display line zero.
int getBlinkForegroundColor() const
Gets the current blinking color for blinking text.
void setExternalVideoSource(const RawFrame *externalSource)
Enable superimposing.
bool isMSX1VDP() const
Is this an MSX1 VDP?
byte getVerticalScroll() const
Gets the current vertical scroll (line displayed at Y=0).
bool isVDPwithVRAMremapping() const
Does this VDP have VRAM remapping when switching from 4k to 8/16k mode?
bool hasYJK() const
Does this VDP support YJK display?
EmuTime::param getFrameStartTime() const
bool canSpriteColor0Collide() const
Can a sprite which has color=0 collide with some other sprite?
bool isMultiPageScrolling() const
Is multi page scrolling enabled? It is considered enabled if both the multi page scrolling flag is en...
byte peekIO(word port, EmuTime::param time) const override
Read a byte from a given IO port.
int getLeftBorder() const
Gets the number of VDP clockticks between start of line and the end of the left border.
EmuTime getAccessSlot(EmuTime::param time, VDPAccessSlots::Delta delta) const
Get the earliest access slot that is at least 'delta' cycles in the future.
bool isSpriteMag() const
Are sprites magnified?
bool vdpHasPatColMirroring() const
Is this a VDP that has pattern/colortable mirroring?
bool isPalTiming() const
Is PAL timing active? This setting is fixed at start of frame.
bool isInterlaced() const
Get interlace status.
bool getTransparency() const
Gets the current transparency setting.
bool getVRMode() const
Returns current VR mode.
byte readIO(word port, EmuTime::param time) override
Read a byte from an IO port at a certain time from this device.
bool isDisplayEnabled() const
Is the display enabled? Both the regular border and forced blanking by clearing the display enable bi...
const RawFrame * isSuperimposing() const
Are we currently superimposing? In case of superimpose, returns a pointer to the to-be-superimposed f...
int getTicksThisFrame(EmuTime::param time) const
Gets the number of VDP clock ticks (21MHz) elapsed between a given time and the start of this frame.
bool vdpLacksMirroring() const
Is this a VDP that lacks mirroring?
SpriteChecker & getSpriteChecker()
Get the sprite checker for this VDP.
byte getHorizontalScrollLow() const
Gets the current horizontal scroll lower bits.
VDP(const DeviceConfig &config)
void powerUp(EmuTime::param time) override
This method is called when MSX is powered up.
int getLeftSprites() const
Gets the number of VDP clockticks between start of line and the start of the sprite plane.
This file implemented 3 utility functions:
IntHelper< OptionalIRQ > OptionalIRQHelper
AmdFlash::SectorInfo Info
uint16_t word
16 bit unsigned integer
SERIALIZE_CLASS_VERSION(CassettePlayer, 2)
#define OUTER(type, member)
Calculates what 'blinkState' and 'blinkCount' would be at a specific line.