Path: blob/master/libsnes/bsnes/snes/ppu/counter/counter.hpp
2 views
//PPUcounter emulates the H/V latch counters of the S-PPU2.1//2//real hardware has the S-CPU maintain its own copy of these counters that are3//updated based on the state of the S-PPU Vblank and Hblank pins. emulating this4//would require full lock-step synchronization for every clock tick.5//to bypass this and allow the two to run out-of-order, both the CPU and PPU6//classes inherit PPUcounter and keep their own counters.7//the timers are kept in sync, as the only differences occur on V=240 and V=261,8//based on interlace. thus, we need only synchronize and fetch interlace at any9//point before this in the frame, which is handled internally by this class at10//V=128.1112class PPUcounter {13public:14alwaysinline void tick();15alwaysinline void tick(unsigned clocks);1617alwaysinline bool field () const;18alwaysinline uint16 vcounter() const;19alwaysinline uint16 hcounter() const;20inline uint16 hdot() const;21inline uint16 lineclocks() const;2223alwaysinline bool field (unsigned offset) const;24alwaysinline uint16 vcounter(unsigned offset) const;25alwaysinline uint16 hcounter(unsigned offset) const;2627inline void reset();28function<void ()> scanline;29void serialize(serializer&);3031private:32inline void vcounter_tick();3334struct {35bool interlace;36bool field;37uint16 vcounter;38uint16 hcounter;39} status;4041struct {42bool field[2048];43uint16 vcounter[2048];44uint16 hcounter[2048];4546int32 index;47} history;48};495051