35namespace VDPAccessSlots {
36 enum class Delta : int;
81 void powerUp(EmuTime::param time)
override;
82 void reset(EmuTime::param time)
override;
83 [[nodiscard]]
byte readIO(
word port, EmuTime::param time)
override;
84 [[nodiscard]]
byte peekIO(
word port, EmuTime::param time)
const override;
85 void writeIO(
word port,
byte value, EmuTime::param time)
override;
91 [[nodiscard]]
byte peekStatusReg(
byte reg, EmuTime::param time)
const;
109 return (version & VM_MSX1) != 0;
116 return (version & VM_PAL) != 0;
123 return (version & VM_NO_MIRRORING) != 0;
130 return (version & VM_PALCOL_MIRRORING) != 0;
137 return (version & VM_VRAM_REMAPPING) != 0;
143 [[nodiscard]]
inline bool hasYJK()
const {
144 return (version & VM_YJK) != 0;
151 [[nodiscard]] std::array<std::array<uint8_t, 3>, 16>
getMSX1Palette()
const;
177 return superimposing;
183 return *spriteChecker;
190 return (controlRegs[8] & 0x20) == 0;
208 return controlRegs[7] >> 4;
220 byte reg7 = controlRegs[7];
232 return controlRegs[12] >> 4;
239 return controlRegs[12] & 0x0F;
251 return controlRegs[4] << 11;
255 return (controlRegs[10] << 14) | (controlRegs[3] << 6);
259 return controlRegs[2] << 10;
263 return controlRegs[6] << 11;
267 return (controlRegs[11] << 15) | (controlRegs[5] << 7);
279 [[nodiscard]]
inline uint16_t
getPalette(
unsigned index)
const {
280 return palette[index];
282 [[nodiscard]]
inline std::span<const uint16_t, 16>
getPalette()
const {
300 return isDisplayArea && displayEnabled;
308 return displayEnabled &&
318 return displayEnabled && spriteEnabled;
325 return spriteEnabled;
332 return controlRegs[23];
341 return controlRegs[27];
350 return controlRegs[26];
359 return (controlRegs[25] & 0x02) != 0;
369 return (controlRegs[25] & 0x01) && (controlRegs[2] & 0x20);
376 return (controlRegs[2] >> 5) & 3;
417 return (controlRegs[1] & 4) != 0;
433 return (controlRegs[9] & 4) != 0;
440 return (statusReg2 & 2) != 0;
457 return (((~controlRegs[9] & 4) << 6) | ((statusReg2 & 2) << 7)) &
471 return (!p.state) << 8;
488 if (blinkCount == 0) {
489 return {blinkState, blinkCount};
492 unsigned evenLen = ((controlRegs[13] >> 4) & 0x0F) * 10;
493 unsigned oddLen = ((controlRegs[13] >> 0) & 0x0F) * 10;
494 unsigned totalLen = evenLen + oddLen;
495 assert(totalLen != 0);
498 bool resultState = blinkState;
504 std::swap(evenLen, oddLen);
506 int newCount = blinkCount - narrow<int>(line);
509 resultState = !resultState;
510 newCount += narrow<int>(oddLen);
513 resultState = !resultState;
514 newCount += narrow<int>(evenLen);
515 assert(newCount > 0);
518 return {resultState, newCount};
529 return frameStartTime.
getTime();
535 return ((controlRegs[1] & 2) << 2) + 8;
541 return controlRegs[1] & 1;
548 return (controlRegs[25] & 0x40) != 0;
554 return palTiming ? 313 : 262;
561 return controlRegs[9] & 0x80 ? 212 : 192;
580 return time >= frameStartTime.
getTime() &&
588 return horizontalAdjust;
599 return 100 + 102 + 56
600 + (horizontalAdjust - 7) * 4
645 statusReg0 = (statusReg0 & 0x80) | (value & 0x7F);
652 return (controlRegs[8] & 8) != 0;
658 externalVideo = externalSource;
664 return brokenCmdTiming;
681 EmuTime::param time, EmuTime::param limit)
const;
707 int LARGEST_STALL = 184 + 2 * 70;
711 syncCmdDone.setSyncPoint(
t);
735 template<
typename Archive>
736 void serialize(Archive& ar,
unsigned version);
742 static constexpr unsigned VM_MSX1 = 1;
743 static constexpr unsigned VM_PAL = 2;
744 static constexpr unsigned VM_NO_MIRRORING = 4;
745 static constexpr unsigned VM_PALCOL_MIRRORING = 8;
746 static constexpr unsigned VM_VRAM_REMAPPING = 16;
747 static constexpr unsigned VM_TOSHIBA_PALETTE = 32;
748 static constexpr unsigned VM_YJK = 64;
749 static constexpr unsigned VM_YM2220_PALETTE = 128;
757 TMS99X8A = VM_MSX1 | VM_PALCOL_MIRRORING | VM_VRAM_REMAPPING,
760 TMS9929A = VM_MSX1 | VM_PALCOL_MIRRORING | VM_VRAM_REMAPPING | VM_PAL,
763 TMS9129 = VM_MSX1 | VM_PAL,
769 T6950PAL = VM_MSX1 | VM_TOSHIBA_PALETTE | VM_NO_MIRRORING | VM_PAL,
772 T6950NTSC = VM_MSX1 | VM_TOSHIBA_PALETTE | VM_NO_MIRRORING,
775 T7937APAL = VM_MSX1 | VM_TOSHIBA_PALETTE | VM_PAL,
778 T7937ANTSC = VM_MSX1 | VM_TOSHIBA_PALETTE,
781 YM2220PAL = VM_MSX1 | VM_YM2220_PALETTE | VM_PALCOL_MIRRORING | VM_PAL,
784 YM2220NTSC = VM_MSX1 | VM_YM2220_PALETTE | VM_PALCOL_MIRRORING,
793 struct SyncBase :
public Schedulable {
794 explicit SyncBase(
const VDP& vdp_) : Schedulable(vdp_.
getScheduler()) {}
799 ~SyncBase() =
default;
802 struct SyncVSync final :
public SyncBase {
803 using SyncBase::SyncBase;
804 void executeUntil(EmuTime::param time)
override {
805 auto& vdp =
OUTER(VDP, syncVSync);
810 struct SyncDisplayStart final :
public SyncBase {
811 using SyncBase::SyncBase;
812 void executeUntil(EmuTime::param time)
override {
813 auto& vdp =
OUTER(VDP, syncDisplayStart);
814 vdp.execDisplayStart(time);
818 struct SyncVScan final :
public SyncBase {
819 using SyncBase::SyncBase;
820 void executeUntil(EmuTime::param time)
override {
821 auto& vdp =
OUTER(VDP, syncVScan);
826 struct SyncHScan final :
public SyncBase {
827 using SyncBase::SyncBase;
828 void executeUntil(EmuTime::param )
override {
829 auto& vdp =
OUTER(VDP, syncHScan);
834 struct SyncHorAdjust final :
public SyncBase {
835 using SyncBase::SyncBase;
836 void executeUntil(EmuTime::param time)
override {
837 auto& vdp =
OUTER(VDP, syncHorAdjust);
838 vdp.execHorAdjust(time);
842 struct SyncSetMode final :
public SyncBase {
843 using SyncBase::SyncBase;
844 void executeUntil(EmuTime::param time)
override {
845 auto& vdp =
OUTER(VDP, syncSetMode);
846 vdp.execSetMode(time);
850 struct SyncSetBlank final :
public SyncBase {
851 using SyncBase::SyncBase;
852 void executeUntil(EmuTime::param time)
override {
853 auto& vdp =
OUTER(VDP, syncSetBlank);
854 vdp.execSetBlank(time);
858 struct SyncSetSprites final :
public SyncBase {
859 using SyncBase::SyncBase;
860 void executeUntil(EmuTime::param time)
override {
861 auto& vdp =
OUTER(VDP, syncSetSprites);
862 vdp.execSetSprites(time);
866 struct SyncCpuVramAccess final :
public SyncBase {
867 using SyncBase::SyncBase;
868 void executeUntil(EmuTime::param time)
override {
869 auto& vdp =
OUTER(VDP, syncCpuVramAccess);
870 vdp.execCpuVramAccess(time);
874 struct SyncCmdDone final :
public SyncBase {
875 using SyncBase::SyncBase;
876 void executeUntil(EmuTime::param time)
override {
877 auto& vdp =
OUTER(VDP, syncCmdDone);
878 vdp.execSyncCmdDone(time);
882 void execVSync(EmuTime::param time);
883 void execDisplayStart(EmuTime::param time);
884 void execVScan(EmuTime::param time);
886 void execHorAdjust(EmuTime::param time);
887 void execSetMode(EmuTime::param time);
888 void execSetBlank(EmuTime::param time);
889 void execSetSprites(EmuTime::param time);
890 void execCpuVramAccess(EmuTime::param time);
891 void execSyncCmdDone(EmuTime::param time);
896 [[nodiscard]]
int getVerticalAdjust()
const {
897 return (controlRegs[18] >> 4) ^ 0x07;
909 [[nodiscard]]
inline bool getHR(
int ticksThisFrame)
const {
915 static constexpr int HBLANK_LEN_TXT = 404;
919 static constexpr int HBLANK_LEN_GFX = 312;
921 < (displayMode.
isTextMode() ? HBLANK_LEN_TXT : HBLANK_LEN_GFX);
925 void preVideoSystemChange() noexcept override;
926 void postVideoSystemChange() noexcept override;
938 void resetMasks(EmuTime::param time);
943 void frameStart(EmuTime::param time);
952 void scheduleDisplayStart(EmuTime::param time);
959 void scheduleVScan(EmuTime::param time);
966 void scheduleHScan(EmuTime::param time);
970 void vramWrite(
byte value, EmuTime::param time);
974 [[nodiscard]]
byte vramRead(EmuTime::param time);
977 void scheduleCpuVramAccess(
bool isRead,
byte write, EmuTime::param time);
978 void executeCpuVramAccess(EmuTime::param time);
982 [[nodiscard]]
byte readStatusReg(
byte reg, EmuTime::param time);
986 void syncAtNextLine(SyncBase& type, EmuTime::param time) const;
990 void createRenderer();
995 void updateNameBase(EmuTime::param time);
1000 void updateColorBase(EmuTime::param time);
1005 void updatePatternBase(EmuTime::param time);
1010 void updateSpriteAttributeBase(EmuTime::param time);
1015 void updateSpritePatternBase(EmuTime::param time);
1020 void updateDisplayMode(DisplayMode newMode,
bool cmdBit, EmuTime::param time);
1023 void update(const Setting&
setting) noexcept override;
1027 EnumSetting<
bool>& cmdTiming;
1028 EnumSetting<
bool>& tooFastAccess;
1030 struct RegDebug final : SimpleDebuggable {
1031 explicit RegDebug(
const VDP& vdp);
1032 [[nodiscard]]
byte read(
unsigned address)
override;
1033 void write(
unsigned address,
byte value, EmuTime::param time)
override;
1036 struct StatusRegDebug final : SimpleDebuggable {
1037 explicit StatusRegDebug(
const VDP& vdp);
1038 [[nodiscard]]
byte read(
unsigned address, EmuTime::param time)
override;
1039 } vdpStatusRegDebug;
1041 struct PaletteDebug final : SimpleDebuggable {
1042 explicit PaletteDebug(
const VDP& vdp);
1043 [[nodiscard]]
byte read(
unsigned address)
override;
1044 void write(
unsigned address,
byte value, EmuTime::param time)
override;
1047 struct VRAMPointerDebug final : SimpleDebuggable {
1048 explicit VRAMPointerDebug(
const VDP& vdp);
1049 [[nodiscard]]
byte read(
unsigned address)
override;
1050 void write(
unsigned address,
byte value, EmuTime::param time)
override;
1053 struct RegisterLatchStatusDebug final : SimpleDebuggable {
1054 explicit RegisterLatchStatusDebug(
const VDP& vdp);
1055 [[nodiscard]]
byte read(
unsigned address)
override;
1056 } registerLatchStatusDebug;
1058 struct VramAccessStatusDebug final : SimpleDebuggable {
1059 explicit VramAccessStatusDebug(
const VDP& vdp);
1060 [[nodiscard]]
byte read(
unsigned address)
override;
1061 } vramAccessStatusDebug;
1063 struct PaletteLatchStatusDebug final : SimpleDebuggable {
1064 explicit PaletteLatchStatusDebug(
const VDP& vdp);
1065 [[nodiscard]]
byte read(
unsigned address)
override;
1066 } paletteLatchStatusDebug;
1068 struct DataLatchDebug final : SimpleDebuggable {
1069 explicit DataLatchDebug(
const VDP& vdp);
1070 [[nodiscard]]
byte read(
unsigned address)
override;
1073 class Info :
public InfoTopic {
1075 void execute(std::span<const TclObject> tokens,
1076 TclObject& result)
const override;
1077 [[nodiscard]] std::string help(std::span<const TclObject> tokens)
const override;
1078 [[nodiscard]]
virtual int calc(
const EmuTime& time)
const = 0;
1080 Info(VDP& vdp_,
const std::string& name, std::string helpText_);
1083 const std::string helpText;
1086 struct FrameCountInfo final : Info {
1087 explicit FrameCountInfo(VDP& vdp);
1088 [[nodiscard]]
int calc(
const EmuTime& time)
const override;
1091 struct CycleInFrameInfo final : Info {
1092 explicit CycleInFrameInfo(VDP& vdp);
1093 [[nodiscard]]
int calc(
const EmuTime& time)
const override;
1096 struct LineInFrameInfo final : Info {
1097 explicit LineInFrameInfo(VDP& vdp);
1098 [[nodiscard]]
int calc(
const EmuTime& time)
const override;
1101 struct CycleInLineInfo final : Info {
1102 explicit CycleInLineInfo(VDP& vdp);
1103 [[nodiscard]]
int calc(
const EmuTime& time)
const override;
1106 struct MsxYPosInfo final : Info {
1107 explicit MsxYPosInfo(VDP& vdp);
1108 [[nodiscard]]
int calc(
const EmuTime& time)
const override;
1111 struct MsxX256PosInfo final : Info {
1112 explicit MsxX256PosInfo(VDP& vdp);
1113 [[nodiscard]]
int calc(
const EmuTime& time)
const override;
1116 struct MsxX512PosInfo final : Info {
1117 explicit MsxX512PosInfo(VDP& vdp);
1118 [[nodiscard]]
int calc(
const EmuTime& time)
const override;
1123 std::unique_ptr<Renderer> renderer;
1127 std::unique_ptr<VDPCmdEngine> cmdEngine;
1131 std::unique_ptr<SpriteChecker> spriteChecker;
1135 std::unique_ptr<VDPVRAM> vram;
1140 const RawFrame* externalVideo;
1147 const RawFrame* superimposing;
1163 EmuTime displayStartSyncTime;
1167 EmuTime vScanSyncTime;
1171 EmuTime hScanSyncTime;
1173 TclCallback tooFastCallback;
1174 TclCallback dotClockDirectionCallback;
1206 int horizontalScanOffset;
1211 int horizontalAdjust;
1215 std::array<byte, 32> controlRegs;
1221 byte controlRegMask;
1229 std::array<byte, 32> controlValueMasks;
1243 std::array<uint16_t, 16> palette;
1259 bool interlaced =
false;
1298 bool registerDataStored;
1302 bool paletteDataStored;
1316 bool cpuVramReqIsRead;
1317 bool pendingCpuAccess;
1322 bool cpuExtendedVram;
1329 DisplayMode displayMode;
1335 bool displayEnabled;
1347 bool warningPrinted =
false;
1350 bool brokenCmdTiming;
1351 bool allowTooFastAccess;
1355 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.
static constexpr uint8_t GRAPHIC7
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.
EmuTime::param getCurrentTime() const
Generic Gang-of-Four Observer class, templatized edition.
A post processor builds the frame that is displayed from the MSX frame, while applying effects such a...
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
Scheduler & getScheduler() 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?
int getLinesPerFrame() const
Gets the number of lines per frame.
int getNumberOfLines() const
Gets the number of display lines per screen.
unsigned getEvenOddMask() const
Expresses the state of even/odd page interchange in a mask on the line number.
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 clock ticks between start of line and the time when the background pixel with ...
SpriteChecker & getSpriteChecker()
Get the sprite checker for this VDP.
bool getBrokenCmdTiming() const
Value of the cmdTiming setting, true means commands have infinite speed.
int getNameTableBase() const
Get address of name table (only for debugger)
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 changeRegister(byte reg, byte val, EmuTime::param time)
VDP control register has changed, work out the consequences.
void scheduleCmdSync(EmuTime t)
Only used when there are commandExecuting-probe listeners.
byte peekRegister(unsigned address) const
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.
VDPVRAM & getVRAM()
Get the VRAM object for this VDP.
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.
int getSpritePatternTableBase() const
Get address of pattern table (only for debugger)
bool isVDPwithPALonly() const
Is this a VDP only capable of PAL?
const RawFrame * isSuperimposing() const
Are we currently superimposing? In case of superimpose, returns a pointer to the to-be-superimposed f...
int getVramPointer() const
Get vram pointer (14-bit) (only for debugger)
void getExtraDeviceInfo(TclObject &result) const override
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.
void setPalette(unsigned index, word grb, EmuTime::param time)
Sets a palette entry.
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 clock ticks (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)
unsigned getEvenOddMask(int line) const
Similar to the above getEvenOddMask() method, but can also be called when 'isFastBlinkEnabled() == tr...
void setSpriteStatus(byte value)
Should only be used by SpriteChecker.
Clock< TICKS_PER_SECOND > VDPClock
gl::ivec2 getMSXPos(EmuTime::param time) const
Returns the position of the raster beam expressed in 'narrow' MSX screen coordinates (like 'screen 7'...
uint16_t getPalette(unsigned index) const
Gets a palette entry.
byte getHorizontalScrollHigh() const
Gets the current horizontal scroll higher bits.
int getRightBorder() const
Gets the number of VDP clock ticks between start of line and the start of the right border.
DisplayMode getDisplayMode() const
Get the display mode the VDP is in.
int getPatternTableBase() const
Get address of pattern table (only for debugger)
int getDisplayPage() const
Only used by debugger.
bool getBlinkState() const
Gets the current blink state.
int getColorTableBase() const
Get address of color table (only for debugger)
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 getBackgroundColor() const
Gets the current background color.
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 clock ticks 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/color table 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.
int getSpriteAttributeTableBase() const
Get address of color table (only for debugger)
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.
std::string_view getVersionString() const
bool isDisplayEnabled() const
Is the display enabled? Both the regular border and forced blanking by clearing the display enable bi...
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?
byte getHorizontalScrollLow() const
Gets the current horizontal scroll lower bits.
byte peekStatusReg(byte reg, EmuTime::param time) const
void powerUp(EmuTime::param time) override
This method is called when MSX is powered up.
int getLeftSprites() const
Gets the number of VDP clock ticks between start of line and the start of the sprite plane.
std::span< const uint16_t, 16 > getPalette() const
This file implemented 3 utility functions:
IntHelper< OptionalIRQ > OptionalIRQHelper
uint16_t word
16 bit unsigned integer
#define OUTER(type, member)
Calculates what 'blinkState' and 'blinkCount' would be at a specific line.