openMSX
VDP.hh
Go to the documentation of this file.
1 #ifndef VDP_HH
2 #define VDP_HH
3 
4 #include "MSXDevice.hh"
5 #include "Schedulable.hh"
7 #include "SimpleDebuggable.hh"
8 #include "TclCallback.hh"
9 #include "InfoTopic.hh"
10 #include "IRQHelper.hh"
11 #include "Clock.hh"
12 #include "DisplayMode.hh"
13 #include "Observer.hh"
14 #include "openmsx.hh"
15 #include "outer.hh"
16 #include <memory>
17 #include <array>
18 
19 namespace openmsx {
20 
21 class PostProcessor;
22 class Renderer;
23 class VDPCmdEngine;
24 class VDPVRAM;
25 class MSXCPU;
26 class SpriteChecker;
27 class Display;
28 class RawFrame;
29 class Setting;
30 template<typename> class EnumSetting;
31 namespace VDPAccessSlots {
32  enum Delta : int;
33  class Calculator;
34 }
35 
61 class VDP final : public MSXDevice, private VideoSystemChangeListener
62  , private Observer<Setting>
63 {
64 public:
67  static constexpr int TICKS_PER_SECOND = 3579545 * 6; // 21.5MHz;
69 
72  static constexpr int TICKS_PER_LINE = 1368;
73 
74  explicit VDP(const DeviceConfig& config);
75  ~VDP() override;
76 
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;
82 
87  [[nodiscard]] PostProcessor* getPostProcessor() const;
88 
93  [[nodiscard]] inline bool isMSX1VDP() const {
94  return (version & VM_MSX1) != 0;
95  }
96 
100  [[nodiscard]] inline bool isVDPwithPALonly() const {
101  return (version & VM_PAL) != 0;
102  }
103 
107  [[nodiscard]] inline bool vdpLacksMirroring() const {
108  return (version & VM_NO_MIRRORING) != 0;
109  }
110 
114  [[nodiscard]] inline bool vdpHasPatColMirroring() const {
115  return (version & VM_PALCOL_MIRRORING) != 0;
116  }
117 
121  [[nodiscard]] inline bool isVDPwithVRAMremapping() const {
122  return (version & VM_VRAM_REMAPPING) != 0;
123  }
124 
128  [[nodiscard]] inline bool hasYJK() const {
129  return (version & VM_YJK) != 0;
130  }
131 
136  [[nodiscard]] std::array<std::array<uint8_t, 3>, 16> getMSX1Palette() const;
137 
141  [[nodiscard]] inline DisplayMode getDisplayMode() const {
142  return displayMode;
143  }
144 
147  [[nodiscard]] inline VDPVRAM& getVRAM() {
148  return *vram;
149  }
150 
155  [[nodiscard]] inline const RawFrame* isSuperimposing() const {
156  // Note that bit 0 of r#0 has no effect on an V9938 or higher,
157  // but this bit is masked out. Also note that on an MSX1, if
158  // bit 0 of r#0 is enabled and there is no external video
159  // source, then we lose sync.
160  // Also note that because this property is fixed per frame we
161  // cannot (re)calculate it from register values.
162  return superimposing;
163  }
164 
167  [[nodiscard]] inline SpriteChecker& getSpriteChecker() {
168  return *spriteChecker;
169  }
170 
174  [[nodiscard]] inline bool getTransparency() const {
175  return (controlRegs[8] & 0x20) == 0;
176  }
177 
180  [[nodiscard]] bool canSpriteColor0Collide() const {
181  // On MSX1 (so far only tested a TMS9129(?)) sprites with
182  // color=0 can always collide with other sprites. Though on
183  // V99x8 (only tested V9958) collisions only occur when color 0
184  // is not transparent. For more details see:
185  // https://github.com/openMSX/openMSX/issues/1198
186  return isMSX1VDP() || !getTransparency();
187  }
188 
192  [[nodiscard]] inline int getForegroundColor() const {
193  return controlRegs[7] >> 4;
194  }
195 
204  [[nodiscard]] inline int getBackgroundColor() const {
205  byte reg7 = controlRegs[7];
206  if (displayMode.getByte() == DisplayMode::GRAPHIC7) {
207  return reg7;
208  } else {
209  return reg7 & 0x0F;
210  }
211  }
212 
216  [[nodiscard]] inline int getBlinkForegroundColor() const {
217  return controlRegs[12] >> 4;
218  }
219 
223  [[nodiscard]] inline int getBlinkBackgroundColor() const {
224  return controlRegs[12] & 0x0F;
225  }
226 
230  [[nodiscard]] inline bool getBlinkState() const {
231  return blinkState;
232  }
233 
239  [[nodiscard]] inline word getPalette(int index) const {
240  return palette[index];
241  }
242 
248  [[nodiscard]] inline bool isDisplayEnabled() const {
249  return isDisplayArea && displayEnabled;
250  }
251 
256  [[nodiscard]] inline bool spritesEnabled() const {
257  return displayEnabled &&
258  (displayMode.getSpriteMode(isMSX1VDP()) != 0) &&
259  spriteEnabled;
260  }
261 
265  [[nodiscard]] inline bool spritesEnabledFast() const {
266  assert(displayMode.getSpriteMode(isMSX1VDP()) != 0);
267  return displayEnabled && spriteEnabled;
268  }
269 
273  [[nodiscard]] inline bool spritesEnabledRegister() const {
274  return spriteEnabled;
275  }
276 
280  [[nodiscard]] inline byte getVerticalScroll() const {
281  return controlRegs[23];
282  }
283 
289  [[nodiscard]] inline byte getHorizontalScrollLow() const {
290  return controlRegs[27];
291  }
292 
298  [[nodiscard]] inline byte getHorizontalScrollHigh() const {
299  return controlRegs[26];
300  }
301 
307  [[nodiscard]] inline bool isBorderMasked() const {
308  return (controlRegs[25] & 0x02) != 0;
309  }
310 
317  [[nodiscard]] inline bool isMultiPageScrolling() const {
318  return (controlRegs[25] & 0x01) && (controlRegs[2] & 0x20);
319  }
320 
325  [[nodiscard]] inline int getLineZero() const {
326  return displayStart / TICKS_PER_LINE;
327  }
328 
333  [[nodiscard]] inline bool isPalTiming() const {
334  return palTiming;
335  }
336 
344  [[nodiscard]] inline bool isInterlaced() const {
345  return interlaced;
346  }
347 
358  [[nodiscard]] inline bool isFastBlinkEnabled() const {
359  return (controlRegs[1] & 4) != 0;
360  }
361 
373  [[nodiscard]] inline bool isEvenOddEnabled() const {
374  if (isFastBlinkEnabled()) return false;
375  return (controlRegs[9] & 4) != 0;
376  }
377 
381  [[nodiscard]] inline bool getEvenOdd() const {
382  return (statusReg2 & 2) != 0;
383  }
384 
396  [[nodiscard]] inline int getEvenOddMask() const {
397  // TODO: Verify which page is displayed on even fields.
398  assert(!isFastBlinkEnabled());
399  return (((~controlRegs[9] & 4) << 6) | ((statusReg2 & 2) << 7)) &
400  (!blinkState << 8);
401  }
402 
409  [[nodiscard]] inline int getEvenOddMask(int line) const {
410  if (isFastBlinkEnabled()) {
411  // EO and IL not considered in this mode
412  auto p = calculateLineBlinkState(line);
413  return (!p.first) << 8;
414  } else {
415  return getEvenOddMask();
416  }
417  }
418 
423  [[nodiscard]] inline std::pair<bool, int> calculateLineBlinkState(unsigned line) const {
424  assert(isFastBlinkEnabled());
425 
426  if (blinkCount == 0) { // not changing
427  return {blinkState, blinkCount};
428  }
429 
430  unsigned evenLen = ((controlRegs[13] >> 4) & 0x0F) * 10;
431  unsigned oddLen = ((controlRegs[13] >> 0) & 0x0F) * 10;
432  unsigned totalLen = evenLen + oddLen;
433  assert(totalLen != 0); // because this implies 'blinkCount == 0'
434  line %= totalLen; // reduce double flips
435 
436  bool resultState = blinkState; // initial guess, adjusted later
437  if (blinkState) {
438  // We start in the 'even' period -> check first for
439  // even/odd transition, next for odd/even
440  } else {
441  // We start in the 'odd' period -> do the opposite
442  std::swap(evenLen, oddLen);
443  }
444  int newCount = blinkCount - line;
445  if (newCount <= 0) {
446  // switch even->odd (or odd->even)
447  resultState = !resultState;
448  newCount += oddLen;
449  if (newCount <= 0) {
450  // switch odd->even (or even->odd)
451  resultState = !resultState;
452  newCount += evenLen;
453  assert(newCount > 0);
454  }
455  }
456  return {resultState, newCount};
457  }
458 
462  [[nodiscard]] inline int getTicksThisFrame(EmuTime::param time) const {
463  return frameStartTime.getTicksTill_fast(time);
464  }
465 
466  [[nodiscard]] inline EmuTime::param getFrameStartTime() const {
467  return frameStartTime.getTime();
468  }
469 
472  [[nodiscard]] inline int getSpriteSize() const {
473  return ((controlRegs[1] & 2) << 2) + 8;
474  }
475 
478  [[nodiscard]] inline bool isSpriteMag() const {
479  return controlRegs[1] & 1;
480  }
481 
485  [[nodiscard]] inline bool getCmdBit() const {
486  return (controlRegs[25] & 0x40) != 0;
487  }
488 
491  [[nodiscard]] inline int getLinesPerFrame() const {
492  return palTiming ? 313 : 262;
493  }
494 
497  [[nodiscard]] inline int getTicksPerFrame() const {
498  return getLinesPerFrame() * TICKS_PER_LINE;
499  }
500 
510  [[nodiscard]] inline bool isInsideFrame(EmuTime::param time) const {
511  return time >= frameStartTime.getTime() &&
513  }
514 
518  [[nodiscard]] inline int getHorizontalAdjust() const {
519  return horizontalAdjust;
520  }
521 
529  [[nodiscard]] inline int getLeftSprites() const {
530  return 100 + 102 + 56
531  + (horizontalAdjust - 7) * 4
532  + (displayMode.isTextMode() ? 36 : 0);
533  }
534 
540  [[nodiscard]] inline int getLeftBorder() const {
541  return getLeftSprites() + (isBorderMasked() ? 8 * 4 : 0);
542  }
543 
547  [[nodiscard]] inline int getRightBorder() const {
548  return getLeftSprites()
549  + (displayMode.isTextMode() ? 960 : 1024);
550  }
551 
557  [[nodiscard]] inline int getLeftBackground() const {
558  return getLeftSprites() + getHorizontalScrollLow() * 4;
559  }
560 
564  [[nodiscard]] byte getStatusReg0() const { return statusReg0; }
565 
574  void setSpriteStatus(byte value)
575  {
576  statusReg0 = (statusReg0 & 0x80) | (value & 0x7F);
577  }
578 
582  [[nodiscard]] bool getVRMode() const {
583  return (controlRegs[8] & 8) != 0;
584  }
585 
588  void setExternalVideoSource(const RawFrame* externalSource) {
589  externalVideo = externalSource;
590  }
591 
594  [[nodiscard]] bool getBrokenCmdTiming() const {
595  return brokenCmdTiming;
596  }
597 
600  [[nodiscard]] EmuTime getAccessSlot(EmuTime::param time, VDPAccessSlots::Delta delta) const;
601 
612  EmuTime::param time, EmuTime::param limit) const;
613 
631  void scheduleCmdSync(EmuTime t) {
632  auto now = getCurrentTime();
633  if (t <= now) {
634  // The largest amount of VDP cycles between 'progress'
635  // in command emulation:
636  // - worst case the LMMM takes 120+64 cycles to fully process one pixel
637  // - the largest gap between access slots is 70 cycles
638  // - but if we're unlucky the CPU steals that slot
639  int LARGEST_STALL = 184 + 2 * 70;
640 
641  t = now + VDPClock::duration(LARGEST_STALL);
642  }
643  syncCmdDone.setSyncPoint(t);
644  }
645 
646  template<typename Archive>
647  void serialize(Archive& ar, unsigned version);
648 
649 private:
650  void initTables();
651 
652  // VdpVersion bitmasks
653  static constexpr unsigned VM_MSX1 = 1; // set-> MSX1, unset-> MSX2 or MSX2+
654  static constexpr unsigned VM_PAL = 2; // set-> fixed PAL, unset-> fixed NTSC or switchable
655  static constexpr unsigned VM_NO_MIRRORING = 4; // set-> no (screen2) mirroring
656  static constexpr unsigned VM_PALCOL_MIRRORING = 8; // set-> pattern/color-table mirroring
657  static constexpr unsigned VM_VRAM_REMAPPING = 16; // set-> 4k,8/16k VRAM remapping
658  static constexpr unsigned VM_TOSHIBA_PALETTE = 32; // set-> has Toshiba palette
659  static constexpr unsigned VM_YJK = 64; // set-> has YJK (MSX2+)
660  static constexpr unsigned VM_YM2220_PALETTE = 128; // set-> has YM2220 palette
661 
663  enum VdpVersion {
668  TMS99X8A = VM_MSX1 | VM_PALCOL_MIRRORING | VM_VRAM_REMAPPING,
669 
671  TMS9929A = VM_MSX1 | VM_PALCOL_MIRRORING | VM_VRAM_REMAPPING | VM_PAL,
672 
674  TMS9129 = VM_MSX1 | VM_PAL,
675 
677  TMS91X8 = VM_MSX1,
678 
680  T6950PAL = VM_MSX1 | VM_TOSHIBA_PALETTE | VM_NO_MIRRORING | VM_PAL,
681 
683  T6950NTSC = VM_MSX1 | VM_TOSHIBA_PALETTE | VM_NO_MIRRORING,
684 
686  T7937APAL = VM_MSX1 | VM_TOSHIBA_PALETTE | VM_PAL,
687 
689  T7937ANTSC = VM_MSX1 | VM_TOSHIBA_PALETTE,
690 
692  YM2220PAL = VM_MSX1 | VM_YM2220_PALETTE | VM_PALCOL_MIRRORING | VM_PAL,
693 
695  YM2220NTSC = VM_MSX1 | VM_YM2220_PALETTE | VM_PALCOL_MIRRORING,
696 
698  V9938 = 0,
699 
701  V9958 = VM_YJK,
702  };
703 
704  struct SyncBase : public Schedulable {
705  explicit SyncBase(VDP& vdp_) : Schedulable(vdp_.getScheduler()) {}
709  protected:
710  ~SyncBase() = default;
711  };
712 
713  struct SyncVSync final : public SyncBase {
714  explicit SyncVSync(VDP& vdp) : SyncBase(vdp) {}
715  void executeUntil(EmuTime::param time) override {
716  auto& vdp = OUTER(VDP, syncVSync);
717  vdp.execVSync(time);
718  }
719  } syncVSync;
720 
721  struct SyncDisplayStart final : public SyncBase {
722  explicit SyncDisplayStart(VDP& vdp) : SyncBase(vdp) {}
723  void executeUntil(EmuTime::param time) override {
724  auto& vdp = OUTER(VDP, syncDisplayStart);
725  vdp.execDisplayStart(time);
726  }
727  } syncDisplayStart;
728 
729  struct SyncVScan final : public SyncBase {
730  explicit SyncVScan(VDP& vdp) : SyncBase(vdp) {}
731  void executeUntil(EmuTime::param time) override {
732  auto& vdp = OUTER(VDP, syncVScan);
733  vdp.execVScan(time);
734  }
735  } syncVScan;
736 
737  struct SyncHScan final : public SyncBase {
738  explicit SyncHScan(VDP& vdp) : SyncBase(vdp) {}
739  void executeUntil(EmuTime::param /*time*/) override {
740  auto& vdp = OUTER(VDP, syncHScan);
741  vdp.execHScan();
742  }
743  } syncHScan;
744 
745  struct SyncHorAdjust final : public SyncBase {
746  explicit SyncHorAdjust(VDP& vdp) : SyncBase(vdp) {}
747  void executeUntil(EmuTime::param time) override {
748  auto& vdp = OUTER(VDP, syncHorAdjust);
749  vdp.execHorAdjust(time);
750  }
751  } syncHorAdjust;
752 
753  struct SyncSetMode final : public SyncBase {
754  explicit SyncSetMode(VDP& vdp) : SyncBase(vdp) {}
755  void executeUntil(EmuTime::param time) override {
756  auto& vdp = OUTER(VDP, syncSetMode);
757  vdp.execSetMode(time);
758  }
759  } syncSetMode;
760 
761  struct SyncSetBlank final : public SyncBase {
762  explicit SyncSetBlank(VDP& vdp) : SyncBase(vdp) {}
763  void executeUntil(EmuTime::param time) override {
764  auto& vdp = OUTER(VDP, syncSetBlank);
765  vdp.execSetBlank(time);
766  }
767  } syncSetBlank;
768 
769  struct SyncSetSprites final : public SyncBase {
770  explicit SyncSetSprites(VDP& vdp) : SyncBase(vdp) {}
771  void executeUntil(EmuTime::param time) override {
772  auto& vdp = OUTER(VDP, syncSetSprites);
773  vdp.execSetSprites(time);
774  }
775  } syncSetSprites;
776 
777  struct SyncCpuVramAccess final : public SyncBase {
778  explicit SyncCpuVramAccess(VDP& vdp) : SyncBase(vdp) {}
779  void executeUntil(EmuTime::param time) override {
780  auto& vdp = OUTER(VDP, syncCpuVramAccess);
781  vdp.execCpuVramAccess(time);
782  }
783  } syncCpuVramAccess;
784 
785  struct SyncCmdDone final : public SyncBase {
786  explicit SyncCmdDone(VDP& vdp) : SyncBase(vdp) {}
787  void executeUntil(EmuTime::param time) override {
788  auto& vdp = OUTER(VDP, syncCmdDone);
789  vdp.execSyncCmdDone(time);
790  }
791  } syncCmdDone;
792 
793  void execVSync(EmuTime::param time);
794  void execDisplayStart(EmuTime::param time);
795  void execVScan(EmuTime::param time);
796  void execHScan();
797  void execHorAdjust(EmuTime::param time);
798  void execSetMode(EmuTime::param time);
799  void execSetBlank(EmuTime::param time);
800  void execSetSprites(EmuTime::param time);
801  void execCpuVramAccess(EmuTime::param time);
802  void execSyncCmdDone(EmuTime::param time);
803 
807  [[nodiscard]] inline int getNumberOfLines() const {
808  return controlRegs[9] & 0x80 ? 212 : 192;
809  }
810 
814  [[nodiscard]] int getVerticalAdjust() const {
815  return (controlRegs[18] >> 4) ^ 0x07;
816  }
817 
827  [[nodiscard]] inline bool getHR(int ticksThisFrame) const {
828  // Note: These constants are located inside this function because
829  // GCC 4.0.x won't link if they are in the class scope.
833  static constexpr int HBLANK_LEN_TXT = 404;
837  static constexpr int HBLANK_LEN_GFX = 312;
838  return (ticksThisFrame + TICKS_PER_LINE - getRightBorder()) % TICKS_PER_LINE
839  < (displayMode.isTextMode() ? HBLANK_LEN_TXT : HBLANK_LEN_GFX);
840  }
841 
842  // VideoSystemChangeListener interface:
843  void preVideoSystemChange() noexcept override;
844  void postVideoSystemChange() noexcept override;
845 
850  void resetInit();
851 
856  void resetMasks(EmuTime::param time);
857 
861  void frameStart(EmuTime::param time);
862 
870  void scheduleDisplayStart(EmuTime::param time);
871 
877  void scheduleVScan(EmuTime::param time);
878 
884  void scheduleHScan(EmuTime::param time);
885 
888  void vramWrite(byte value, EmuTime::param time);
889 
892  [[nodiscard]] byte vramRead(EmuTime::param time);
893 
895  void scheduleCpuVramAccess(bool isRead, byte write, EmuTime::param time);
896  void executeCpuVramAccess(EmuTime::param time);
897 
900  [[nodiscard]] byte peekStatusReg(byte reg, EmuTime::param time) const;
901  [[nodiscard]] byte readStatusReg(byte reg, EmuTime::param time);
902 
905  void changeRegister(byte reg, byte val, EmuTime::param time);
906 
909  void syncAtNextLine(SyncBase& type, EmuTime::param time);
910 
913  void createRenderer();
914 
918  void updateNameBase(EmuTime::param time);
919 
923  void updateColorBase(EmuTime::param time);
924 
928  void updatePatternBase(EmuTime::param time);
929 
933  void updateSpriteAttributeBase(EmuTime::param time);
934 
938  void updateSpritePatternBase(EmuTime::param time);
939 
943  void updateDisplayMode(DisplayMode newMode, bool cmdBit, EmuTime::param time);
944 
951  void setPalette(int index, word grb, EmuTime::param time);
952 
953  // Observer<Setting>
954  void update(const Setting& setting) noexcept override;
955 
956 private:
957  Display& display;
958  EnumSetting<bool>& cmdTiming;
959  EnumSetting<bool>& tooFastAccess;
960 
961  struct RegDebug final : SimpleDebuggable {
962  explicit RegDebug(VDP& vdp);
963  [[nodiscard]] byte read(unsigned address) override;
964  void write(unsigned address, byte value, EmuTime::param time) override;
965  } vdpRegDebug;
966 
967  struct StatusRegDebug final : SimpleDebuggable {
968  explicit StatusRegDebug(VDP& vdp);
969  [[nodiscard]] byte read(unsigned address, EmuTime::param time) override;
970  } vdpStatusRegDebug;
971 
972  struct PaletteDebug final : SimpleDebuggable {
973  explicit PaletteDebug(VDP& vdp);
974  [[nodiscard]] byte read(unsigned address) override;
975  void write(unsigned address, byte value, EmuTime::param time) override;
976  } vdpPaletteDebug;
977 
978  struct VRAMPointerDebug final : SimpleDebuggable {
979  explicit VRAMPointerDebug(VDP& vdp);
980  [[nodiscard]] byte read(unsigned address) override;
981  void write(unsigned address, byte value, EmuTime::param time) override;
982  } vramPointerDebug;
983 
984  class Info : public InfoTopic {
985  public:
986  void execute(span<const TclObject> tokens,
987  TclObject& result) const override;
988  [[nodiscard]] std::string help(const std::vector<std::string>& tokens) const override;
989  [[nodiscard]] virtual int calc(const EmuTime& time) const = 0;
990  protected:
991  Info(VDP& vdp_, const std::string& name, std::string helpText_);
992  ~Info() = default;
993  VDP& vdp;
994  const std::string helpText;
995  };
996 
997  struct FrameCountInfo final : Info {
998  explicit FrameCountInfo(VDP& vdp);
999  [[nodiscard]] int calc(const EmuTime& time) const override;
1000  } frameCountInfo;
1001 
1002  struct CycleInFrameInfo final : Info {
1003  explicit CycleInFrameInfo(VDP& vdp);
1004  [[nodiscard]] int calc(const EmuTime& time) const override;
1005  } cycleInFrameInfo;
1006 
1007  struct LineInFrameInfo final : Info {
1008  explicit LineInFrameInfo(VDP& vdp);
1009  [[nodiscard]] int calc(const EmuTime& time) const override;
1010  } lineInFrameInfo;
1011 
1012  struct CycleInLineInfo final : Info {
1013  explicit CycleInLineInfo(VDP& vdp);
1014  [[nodiscard]] int calc(const EmuTime& time) const override;
1015  } cycleInLineInfo;
1016 
1017  struct MsxYPosInfo final : Info {
1018  explicit MsxYPosInfo(VDP& vdp);
1019  [[nodiscard]] int calc(const EmuTime& time) const override;
1020  } msxYPosInfo;
1021 
1022  struct MsxX256PosInfo final : Info {
1023  explicit MsxX256PosInfo(VDP& vdp);
1024  [[nodiscard]] int calc(const EmuTime& time) const override;
1025  } msxX256PosInfo;
1026 
1027  struct MsxX512PosInfo final : Info {
1028  explicit MsxX512PosInfo(VDP& vdp);
1029  [[nodiscard]] int calc(const EmuTime& time) const override;
1030  } msxX512PosInfo;
1031 
1034  std::unique_ptr<Renderer> renderer;
1035 
1038  std::unique_ptr<VDPCmdEngine> cmdEngine;
1039 
1042  std::unique_ptr<SpriteChecker> spriteChecker;
1043 
1046  std::unique_ptr<VDPVRAM> vram;
1047 
1051  const RawFrame* externalVideo;
1052 
1058  const RawFrame* superimposing;
1059 
1062  VDPClock frameStartTime;
1063 
1066  OptionalIRQHelper irqVertical;
1067 
1070  OptionalIRQHelper irqHorizontal;
1071 
1074  EmuTime displayStartSyncTime;
1075 
1078  EmuTime vScanSyncTime;
1079 
1082  EmuTime hScanSyncTime;
1083 
1084  TclCallback tooFastCallback;
1085 
1088  VdpVersion version;
1089 
1094  int saturationPr;
1095 
1100  int saturationPb;
1101 
1107  int frameCount;
1108 
1111  int displayStart;
1112 
1116  int horizontalScanOffset;
1117 
1121  int horizontalAdjust;
1122 
1125  byte controlRegs[32];
1126 
1131  int controlRegMask;
1132 
1139  byte controlValueMasks[32];
1140 
1144  int blinkCount;
1145 
1149  int vramPointer;
1150 
1153  word palette[16];
1154 
1157  bool isDisplayArea;
1158 
1164  bool palTiming;
1165 
1169  bool interlaced;
1170 
1175  byte statusReg0;
1176 
1182  byte statusReg1;
1183 
1188  byte statusReg2;
1189 
1192  bool blinkState;
1193 
1196  byte dataLatch;
1197 
1200  bool registerDataStored;
1201 
1204  bool paletteDataStored;
1205 
1213  byte cpuVramData;
1214 
1218  bool cpuVramReqIsRead;
1219  bool pendingCpuAccess; // always equal to pendingSyncPoint(CPU_VRAM_ACCESS)
1220 
1224  bool cpuExtendedVram;
1225 
1231  DisplayMode displayMode;
1232 
1237  bool displayEnabled;
1238 
1244  bool spriteEnabled;
1245 
1249  bool warningPrinted;
1250 
1252  bool brokenCmdTiming;
1253  bool allowTooFastAccess;
1254 
1256  MSXCPU& cpu;
1257  const byte fixedVDPIOdelayCycles;
1258 };
1260 
1261 } // namespace openmsx
1262 
1263 #endif
TclObject t
static constexpr EmuDuration duration(unsigned ticks)
Calculates the duration of the given number of ticks at this clock's frequency.
Definition: Clock.hh:35
constexpr unsigned getTicksTill_fast(EmuTime::param e) const
Same as above, only faster, Though the time interval may not be too large.
Definition: Clock.hh:70
constexpr EmuTime::param getTime() const
Gets the time at which the last clock tick occurred.
Definition: Clock.hh:46
Represents a VDP display mode.
Definition: DisplayMode.hh:16
constexpr bool isTextMode() const
Is the current mode a text mode? Text1 and Text2 are text modes.
Definition: DisplayMode.hh:130
constexpr byte getByte() const
Get the dispay mode as a byte: YAE YJK M5..M1 combined.
Definition: DisplayMode.hh:101
constexpr int getSpriteMode(bool isMSX1) const
Get the sprite mode of this display mode.
Definition: DisplayMode.hh:166
An MSXDevice is an emulated hardware component connected to the bus of the emulated MSX.
Definition: MSXDevice.hh:33
Scheduler & getScheduler() const
Definition: MSXDevice.cc:143
EmuTime::param getCurrentTime() const
Definition: MSXDevice.cc:131
Generic Gang-of-Four Observer class, templatized edition.
Definition: Observer.hh:10
Abstract base class for post processors.
A video frame as output by the VDP scanline conversion unit, before any postprocessing filters are ap...
Definition: RawFrame.hh:14
void setSyncPoint(EmuTime::param timestamp)
Definition: Schedulable.cc:23
bool pendingSyncPoint() const
Definition: Schedulable.cc:38
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.
Definition: VDPVRAM.hh:387
Unified implementation of MSX Video Display Processors (VDPs).
Definition: VDP.hh:63
int getHorizontalAdjust() const
This is a combination of the (horizontal) set adjust register and the YJK-mode bit.
Definition: VDP.hh:518
bool getEvenOdd() const
Is the even or odd field being displayed?
Definition: VDP.hh:381
word getPalette(int index) const
Gets a palette entry.
Definition: VDP.hh:239
int getLinesPerFrame() const
Gets the number of lines per frame.
Definition: VDP.hh:491
int getEvenOddMask(int line) const
Similar to the above getEvenOddMask() method, but can also be called when 'isFastBlinkEnabled() == tr...
Definition: VDP.hh:409
int getEvenOddMask() const
Expresses the state of even/odd page interchange in a mask on the line number.
Definition: VDP.hh:396
VDPVRAM & getVRAM()
Get the VRAM object for this VDP.
Definition: VDP.hh:147
bool spritesEnabled() const
Are sprites enabled?
Definition: VDP.hh:256
int getSpriteSize() const
Gets the sprite size in pixels (8/16).
Definition: VDP.hh:472
int getLeftBackground() const
Gets the number of VDP clockticks between start of line and the time when the background pixel with X...
Definition: VDP.hh:557
int getBackgroundColor() const
Gets the current background color.
Definition: VDP.hh:204
bool getBrokenCmdTiming() const
Value of the cmdTiming setting, true means commands have infinite speed.
Definition: VDP.hh:594
bool isEvenOddEnabled() const
Get even/odd page alternation status.
Definition: VDP.hh:373
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.
Definition: VDP.cc:653
void scheduleCmdSync(EmuTime t)
Only used when there are commandExecuting-probe listeners.
Definition: VDP.hh:631
bool spritesEnabledRegister() const
Still faster variant (just looks at the sprite-enabled-bit).
Definition: VDP.hh:273
static constexpr int TICKS_PER_SECOND
Number of VDP clock ticks per second.
Definition: VDP.hh:67
bool isFastBlinkEnabled() const
Get 'fast-blink' status.
Definition: VDP.hh:358
std::array< std::array< uint8_t, 3 >, 16 > getMSX1Palette() const
Get the (fixed) palette for this MSX1 VDP.
Definition: VDP.cc:1527
PostProcessor * getPostProcessor() const
Used by Video9000 to be able to couple the VDP and V9990 output.
Definition: VDP.cc:245
bool isVDPwithPALonly() const
Is this a VDP only capable of PAL?
Definition: VDP.hh:100
bool getCmdBit() const
Are commands possible in non Graphic modes? (V9958 only)
Definition: VDP.hh:485
VDPAccessSlots::Calculator getAccessSlotCalculator(EmuTime::param time, EmuTime::param limit) const
Same as getAccessSlot(), but it can be much faster for repeated calls, e.g.
Definition: VDP.cc:876
void reset(EmuTime::param time) override
This method is called on reset.
Definition: VDP.cc:322
bool isBorderMasked() const
Gets the current border mask setting.
Definition: VDP.hh:307
std::pair< bool, int > calculateLineBlinkState(unsigned line) const
Calculates what 'blinkState' and 'blinkCount' would be at a specific line.
Definition: VDP.hh:423
byte getStatusReg0() const
Should only be used by SpriteChecker.
Definition: VDP.hh:564
bool spritesEnabledFast() const
Same as spritesEnabled(), but may only be called in sprite mode 1 or 2.
Definition: VDP.hh:265
int getForegroundColor() const
Gets the current foreground color.
Definition: VDP.hh:192
static constexpr int TICKS_PER_LINE
Number of VDP clock ticks per line.
Definition: VDP.hh:72
int getBlinkBackgroundColor() const
Gets the current blinking color for blinking text.
Definition: VDP.hh:223
int getTicksPerFrame() const
Gets the number of VDP clockticks (21MHz) per frame.
Definition: VDP.hh:497
bool isInsideFrame(EmuTime::param time) const
Is the given timestamp inside the current frame? Mainly useful for debugging, because relevant timest...
Definition: VDP.hh:510
void serialize(Archive &ar, unsigned version)
Definition: VDP.cc:1839
void setSpriteStatus(byte value)
Should only be used by SpriteChecker.
Definition: VDP.hh:574
Clock< TICKS_PER_SECOND > VDPClock
Definition: VDP.hh:68
byte getHorizontalScrollHigh() const
Gets the current horizontal scroll higher bits.
Definition: VDP.hh:298
int getRightBorder() const
Gets the number of VDP clockticks between start of line and the start of the right border.
Definition: VDP.hh:547
DisplayMode getDisplayMode() const
Get the display mode the VDP is in.
Definition: VDP.hh:141
~VDP() override
Definition: VDP.cc:219
bool getBlinkState() const
Gets the current blink state.
Definition: VDP.hh:230
int getLineZero() const
Get the absolute line number of display line zero.
Definition: VDP.hh:325
int getBlinkForegroundColor() const
Gets the current blinking color for blinking text.
Definition: VDP.hh:216
void setExternalVideoSource(const RawFrame *externalSource)
Enable superimposing.
Definition: VDP.hh:588
bool isMSX1VDP() const
Is this an MSX1 VDP?
Definition: VDP.hh:93
byte getVerticalScroll() const
Gets the current vertical scroll (line displayed at Y=0).
Definition: VDP.hh:280
bool isVDPwithVRAMremapping() const
Does this VDP have VRAM remapping when switching from 4k to 8/16k mode?
Definition: VDP.hh:121
bool hasYJK() const
Does this VDP support YJK display?
Definition: VDP.hh:128
EmuTime::param getFrameStartTime() const
Definition: VDP.hh:466
bool canSpriteColor0Collide() const
Can a sprite which has color=0 collide with some other sprite?
Definition: VDP.hh:180
bool isMultiPageScrolling() const
Is multi page scrolling enabled? It is considered enabled if both the multi page scrolling flag is en...
Definition: VDP.hh:317
byte peekIO(word port, EmuTime::param time) const override
Read a byte from a given IO port.
Definition: VDP.cc:985
int getLeftBorder() const
Gets the number of VDP clockticks between start of line and the end of the left border.
Definition: VDP.hh:540
EmuTime getAccessSlot(EmuTime::param time, VDPAccessSlots::Delta delta) const
Get the earliest access slot that is at least 'delta' cycles in the future.
Definition: VDP.cc:870
bool isSpriteMag() const
Are sprites magnified?
Definition: VDP.hh:478
bool vdpHasPatColMirroring() const
Is this a VDP that has pattern/colortable mirroring?
Definition: VDP.hh:114
bool isPalTiming() const
Is PAL timing active? This setting is fixed at start of frame.
Definition: VDP.hh:333
bool isInterlaced() const
Get interlace status.
Definition: VDP.hh:344
bool getTransparency() const
Gets the current transparency setting.
Definition: VDP.hh:174
bool getVRMode() const
Returns current VR mode.
Definition: VDP.hh:582
byte readIO(word port, EmuTime::param time) override
Read a byte from an IO port at a certain time from this device.
Definition: VDP.cc:965
bool isDisplayEnabled() const
Is the display enabled? Both the regular border and forced blanking by clearing the display enable bi...
Definition: VDP.hh:248
const RawFrame * isSuperimposing() const
Are we currently superimposing? In case of superimpose, returns a pointer to the to-be-superimposed f...
Definition: VDP.hh:155
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.
Definition: VDP.hh:462
bool vdpLacksMirroring() const
Is this a VDP that lacks mirroring?
Definition: VDP.hh:107
SpriteChecker & getSpriteChecker()
Get the sprite checker for this VDP.
Definition: VDP.hh:167
byte getHorizontalScrollLow() const
Gets the current horizontal scroll lower bits.
Definition: VDP.hh:289
VDP(const DeviceConfig &config)
Definition: VDP.cc:65
void powerUp(EmuTime::param time) override
This method is called when MSX is powered up.
Definition: VDP.cc:316
int getLeftSprites() const
Gets the number of VDP clockticks between start of line and the start of the sprite plane.
Definition: VDP.hh:529
Definition: span.hh:126
This file implemented 3 utility functions:
Definition: Autofire.cc:9
IntHelper< OptionalIRQ > OptionalIRQHelper
Definition: IRQHelper.hh:136
AmdFlash::SectorInfo Info
Definition: RomManbow2.cc:17
uint16_t word
16 bit unsigned integer
Definition: openmsx.hh:29
SERIALIZE_CLASS_VERSION(CassettePlayer, 2)
#define OUTER(type, member)
Definition: outer.hh:41