34namespace VDPAccessSlots {
80 void powerUp(EmuTime::param time)
override;
81 void reset(EmuTime::param time)
override;
82 [[nodiscard]]
byte readIO(
word port, EmuTime::param time)
override;
83 [[nodiscard]]
byte peekIO(
word port, EmuTime::param time)
const override;
84 void writeIO(
word port,
byte value, EmuTime::param time)
override;
90 [[nodiscard]]
byte peekStatusReg(
byte reg, EmuTime::param time)
const;
108 return (version & VM_MSX1) != 0;
115 return (version & VM_PAL) != 0;
122 return (version & VM_NO_MIRRORING) != 0;
129 return (version & VM_PALCOL_MIRRORING) != 0;
136 return (version & VM_VRAM_REMAPPING) != 0;
142 [[nodiscard]]
inline bool hasYJK()
const {
143 return (version & VM_YJK) != 0;
150 [[nodiscard]] std::array<std::array<uint8_t, 3>, 16>
getMSX1Palette()
const;
176 return superimposing;
182 return *spriteChecker;
189 return (controlRegs[8] & 0x20) == 0;
207 return controlRegs[7] >> 4;
219 byte reg7 = controlRegs[7];
231 return controlRegs[12] >> 4;
238 return controlRegs[12] & 0x0F;
250 return controlRegs[4] << 11;
254 return (controlRegs[10] << 14) | (controlRegs[3] << 6);
258 return controlRegs[2] << 10;
262 return controlRegs[6] << 11;
266 return (controlRegs[11] << 15) | (controlRegs[5] << 7);
278 [[nodiscard]]
inline uint16_t
getPalette(
unsigned index)
const {
279 return palette[index];
281 [[nodiscard]]
inline std::span<const uint16_t, 16>
getPalette()
const {
299 return isDisplayArea && displayEnabled;
307 return displayEnabled &&
317 return displayEnabled && spriteEnabled;
324 return spriteEnabled;
331 return controlRegs[23];
340 return controlRegs[27];
349 return controlRegs[26];
358 return (controlRegs[25] & 0x02) != 0;
368 return (controlRegs[25] & 0x01) && (controlRegs[2] & 0x20);
375 return (controlRegs[2] >> 5) & 3;
416 return (controlRegs[1] & 4) != 0;
432 return (controlRegs[9] & 4) != 0;
439 return (statusReg2 & 2) != 0;
456 return (((~controlRegs[9] & 4) << 6) | ((statusReg2 & 2) << 7)) &
470 return (!p.state) << 8;
487 if (blinkCount == 0) {
488 return {blinkState, blinkCount};
491 unsigned evenLen = ((controlRegs[13] >> 4) & 0x0F) * 10;
492 unsigned oddLen = ((controlRegs[13] >> 0) & 0x0F) * 10;
493 unsigned totalLen = evenLen + oddLen;
494 assert(totalLen != 0);
497 bool resultState = blinkState;
503 std::swap(evenLen, oddLen);
505 int newCount = blinkCount - narrow<int>(line);
508 resultState = !resultState;
509 newCount += narrow<int>(oddLen);
512 resultState = !resultState;
513 newCount += narrow<int>(evenLen);
514 assert(newCount > 0);
517 return {resultState, newCount};
528 return frameStartTime.
getTime();
534 return ((controlRegs[1] & 2) << 2) + 8;
540 return controlRegs[1] & 1;
547 return (controlRegs[25] & 0x40) != 0;
553 return palTiming ? 313 : 262;
560 return controlRegs[9] & 0x80 ? 212 : 192;
579 return time >= frameStartTime.
getTime() &&
587 return horizontalAdjust;
598 return 100 + 102 + 56
599 + (horizontalAdjust - 7) * 4
644 statusReg0 = (statusReg0 & 0x80) | (value & 0x7F);
651 return (controlRegs[8] & 8) != 0;
657 externalVideo = externalSource;
663 return brokenCmdTiming;
680 EmuTime::param time, EmuTime::param limit)
const;
706 int LARGEST_STALL = 184 + 2 * 70;
710 syncCmdDone.setSyncPoint(
t);
713 template<
typename Archive>
714 void serialize(Archive& ar,
unsigned version);
720 static constexpr unsigned VM_MSX1 = 1;
721 static constexpr unsigned VM_PAL = 2;
722 static constexpr unsigned VM_NO_MIRRORING = 4;
723 static constexpr unsigned VM_PALCOL_MIRRORING = 8;
724 static constexpr unsigned VM_VRAM_REMAPPING = 16;
725 static constexpr unsigned VM_TOSHIBA_PALETTE = 32;
726 static constexpr unsigned VM_YJK = 64;
727 static constexpr unsigned VM_YM2220_PALETTE = 128;
735 TMS99X8A = VM_MSX1 | VM_PALCOL_MIRRORING | VM_VRAM_REMAPPING,
738 TMS9929A = VM_MSX1 | VM_PALCOL_MIRRORING | VM_VRAM_REMAPPING | VM_PAL,
741 TMS9129 = VM_MSX1 | VM_PAL,
747 T6950PAL = VM_MSX1 | VM_TOSHIBA_PALETTE | VM_NO_MIRRORING | VM_PAL,
750 T6950NTSC = VM_MSX1 | VM_TOSHIBA_PALETTE | VM_NO_MIRRORING,
753 T7937APAL = VM_MSX1 | VM_TOSHIBA_PALETTE | VM_PAL,
756 T7937ANTSC = VM_MSX1 | VM_TOSHIBA_PALETTE,
759 YM2220PAL = VM_MSX1 | VM_YM2220_PALETTE | VM_PALCOL_MIRRORING | VM_PAL,
762 YM2220NTSC = VM_MSX1 | VM_YM2220_PALETTE | VM_PALCOL_MIRRORING,
771 struct SyncBase :
public Schedulable {
772 explicit SyncBase(
const VDP& vdp_) : Schedulable(vdp_.
getScheduler()) {}
777 ~SyncBase() =
default;
780 struct SyncVSync final :
public SyncBase {
781 using SyncBase::SyncBase;
782 void executeUntil(EmuTime::param time)
override {
783 auto& vdp =
OUTER(VDP, syncVSync);
788 struct SyncDisplayStart final :
public SyncBase {
789 using SyncBase::SyncBase;
790 void executeUntil(EmuTime::param time)
override {
791 auto& vdp =
OUTER(VDP, syncDisplayStart);
792 vdp.execDisplayStart(time);
796 struct SyncVScan final :
public SyncBase {
797 using SyncBase::SyncBase;
798 void executeUntil(EmuTime::param time)
override {
799 auto& vdp =
OUTER(VDP, syncVScan);
804 struct SyncHScan final :
public SyncBase {
805 using SyncBase::SyncBase;
806 void executeUntil(EmuTime::param )
override {
807 auto& vdp =
OUTER(VDP, syncHScan);
812 struct SyncHorAdjust final :
public SyncBase {
813 using SyncBase::SyncBase;
814 void executeUntil(EmuTime::param time)
override {
815 auto& vdp =
OUTER(VDP, syncHorAdjust);
816 vdp.execHorAdjust(time);
820 struct SyncSetMode final :
public SyncBase {
821 using SyncBase::SyncBase;
822 void executeUntil(EmuTime::param time)
override {
823 auto& vdp =
OUTER(VDP, syncSetMode);
824 vdp.execSetMode(time);
828 struct SyncSetBlank final :
public SyncBase {
829 using SyncBase::SyncBase;
830 void executeUntil(EmuTime::param time)
override {
831 auto& vdp =
OUTER(VDP, syncSetBlank);
832 vdp.execSetBlank(time);
836 struct SyncSetSprites final :
public SyncBase {
837 using SyncBase::SyncBase;
838 void executeUntil(EmuTime::param time)
override {
839 auto& vdp =
OUTER(VDP, syncSetSprites);
840 vdp.execSetSprites(time);
844 struct SyncCpuVramAccess final :
public SyncBase {
845 using SyncBase::SyncBase;
846 void executeUntil(EmuTime::param time)
override {
847 auto& vdp =
OUTER(VDP, syncCpuVramAccess);
848 vdp.execCpuVramAccess(time);
852 struct SyncCmdDone final :
public SyncBase {
853 using SyncBase::SyncBase;
854 void executeUntil(EmuTime::param time)
override {
855 auto& vdp =
OUTER(VDP, syncCmdDone);
856 vdp.execSyncCmdDone(time);
860 void execVSync(EmuTime::param time);
861 void execDisplayStart(EmuTime::param time);
862 void execVScan(EmuTime::param time);
864 void execHorAdjust(EmuTime::param time);
865 void execSetMode(EmuTime::param time);
866 void execSetBlank(EmuTime::param time);
867 void execSetSprites(EmuTime::param time);
868 void execCpuVramAccess(EmuTime::param time);
869 void execSyncCmdDone(EmuTime::param time);
874 [[nodiscard]]
int getVerticalAdjust()
const {
875 return (controlRegs[18] >> 4) ^ 0x07;
887 [[nodiscard]]
inline bool getHR(
int ticksThisFrame)
const {
893 static constexpr int HBLANK_LEN_TXT = 404;
897 static constexpr int HBLANK_LEN_GFX = 312;
899 < (displayMode.
isTextMode() ? HBLANK_LEN_TXT : HBLANK_LEN_GFX);
903 void preVideoSystemChange() noexcept override;
904 void postVideoSystemChange() noexcept override;
916 void resetMasks(EmuTime::param time);
921 void frameStart(EmuTime::param time);
930 void scheduleDisplayStart(EmuTime::param time);
937 void scheduleVScan(EmuTime::param time);
944 void scheduleHScan(EmuTime::param time);
948 void vramWrite(
byte value, EmuTime::param time);
952 [[nodiscard]]
byte vramRead(EmuTime::param time);
955 void scheduleCpuVramAccess(
bool isRead,
byte write, EmuTime::param time);
956 void executeCpuVramAccess(EmuTime::param time);
960 [[nodiscard]]
byte readStatusReg(
byte reg, EmuTime::param time);
964 void syncAtNextLine(SyncBase& type, EmuTime::param time) const;
968 void createRenderer();
973 void updateNameBase(EmuTime::param time);
978 void updateColorBase(EmuTime::param time);
983 void updatePatternBase(EmuTime::param time);
988 void updateSpriteAttributeBase(EmuTime::param time);
993 void updateSpritePatternBase(EmuTime::param time);
998 void updateDisplayMode(DisplayMode newMode,
bool cmdBit, EmuTime::param time);
1001 void update(const Setting&
setting) noexcept override;
1005 EnumSetting<
bool>& cmdTiming;
1006 EnumSetting<
bool>& tooFastAccess;
1008 struct RegDebug final : SimpleDebuggable {
1009 explicit RegDebug(
const VDP& vdp);
1010 [[nodiscard]]
byte read(
unsigned address)
override;
1011 void write(
unsigned address,
byte value, EmuTime::param time)
override;
1014 struct StatusRegDebug final : SimpleDebuggable {
1015 explicit StatusRegDebug(
const VDP& vdp);
1016 [[nodiscard]]
byte read(
unsigned address, EmuTime::param time)
override;
1017 } vdpStatusRegDebug;
1019 struct PaletteDebug final : SimpleDebuggable {
1020 explicit PaletteDebug(
const VDP& vdp);
1021 [[nodiscard]]
byte read(
unsigned address)
override;
1022 void write(
unsigned address,
byte value, EmuTime::param time)
override;
1025 struct VRAMPointerDebug final : SimpleDebuggable {
1026 explicit VRAMPointerDebug(
const VDP& vdp);
1027 [[nodiscard]]
byte read(
unsigned address)
override;
1028 void write(
unsigned address,
byte value, EmuTime::param time)
override;
1031 struct RegisterLatchStatusDebug final : SimpleDebuggable {
1032 explicit RegisterLatchStatusDebug(
const VDP& vdp);
1033 [[nodiscard]]
byte read(
unsigned address)
override;
1034 } registerLatchStatusDebug;
1036 struct VramAccessStatusDebug final : SimpleDebuggable {
1037 explicit VramAccessStatusDebug(
const VDP& vdp);
1038 [[nodiscard]]
byte read(
unsigned address)
override;
1039 } vramAccessStatusDebug;
1041 struct PaletteLatchStatusDebug final : SimpleDebuggable {
1042 explicit PaletteLatchStatusDebug(
const VDP& vdp);
1043 [[nodiscard]]
byte read(
unsigned address)
override;
1044 } paletteLatchStatusDebug;
1046 struct DataLatchDebug final : SimpleDebuggable {
1047 explicit DataLatchDebug(
const VDP& vdp);
1048 [[nodiscard]]
byte read(
unsigned address)
override;
1051 class Info :
public InfoTopic {
1053 void execute(std::span<const TclObject> tokens,
1054 TclObject& result)
const override;
1055 [[nodiscard]] std::string help(std::span<const TclObject> tokens)
const override;
1056 [[nodiscard]]
virtual int calc(
const EmuTime& time)
const = 0;
1058 Info(VDP& vdp_,
const std::string& name, std::string helpText_);
1061 const std::string helpText;
1064 struct FrameCountInfo final :
Info {
1065 explicit FrameCountInfo(VDP& vdp);
1066 [[nodiscard]]
int calc(
const EmuTime& time)
const override;
1069 struct CycleInFrameInfo final :
Info {
1070 explicit CycleInFrameInfo(VDP& vdp);
1071 [[nodiscard]]
int calc(
const EmuTime& time)
const override;
1074 struct LineInFrameInfo final :
Info {
1075 explicit LineInFrameInfo(VDP& vdp);
1076 [[nodiscard]]
int calc(
const EmuTime& time)
const override;
1079 struct CycleInLineInfo final :
Info {
1080 explicit CycleInLineInfo(VDP& vdp);
1081 [[nodiscard]]
int calc(
const EmuTime& time)
const override;
1084 struct MsxYPosInfo final :
Info {
1085 explicit MsxYPosInfo(VDP& vdp);
1086 [[nodiscard]]
int calc(
const EmuTime& time)
const override;
1089 struct MsxX256PosInfo final :
Info {
1090 explicit MsxX256PosInfo(VDP& vdp);
1091 [[nodiscard]]
int calc(
const EmuTime& time)
const override;
1094 struct MsxX512PosInfo final :
Info {
1095 explicit MsxX512PosInfo(VDP& vdp);
1096 [[nodiscard]]
int calc(
const EmuTime& time)
const override;
1101 std::unique_ptr<Renderer> renderer;
1105 std::unique_ptr<VDPCmdEngine> cmdEngine;
1109 std::unique_ptr<SpriteChecker> spriteChecker;
1113 std::unique_ptr<VDPVRAM> vram;
1118 const RawFrame* externalVideo;
1125 const RawFrame* superimposing;
1141 EmuTime displayStartSyncTime;
1145 EmuTime vScanSyncTime;
1149 EmuTime hScanSyncTime;
1151 TclCallback tooFastCallback;
1183 int horizontalScanOffset;
1188 int horizontalAdjust;
1192 std::array<byte, 32> controlRegs;
1198 byte controlRegMask;
1206 std::array<byte, 32> controlValueMasks;
1220 std::array<uint16_t, 16> palette;
1236 bool interlaced =
false;
1275 bool registerDataStored;
1279 bool paletteDataStored;
1293 bool cpuVramReqIsRead;
1294 bool pendingCpuAccess;
1299 bool cpuExtendedVram;
1306 DisplayMode displayMode;
1312 bool displayEnabled;
1324 bool warningPrinted =
false;
1327 bool brokenCmdTiming;
1328 bool allowTooFastAccess;
1332 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.
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
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
AmdFlash::SectorInfo Info
uint16_t word
16 bit unsigned integer
#define OUTER(type, member)
Calculates what 'blinkState' and 'blinkCount' would be at a specific line.