Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/libsnes/bsnes/snes/ppu/counter/counter.hpp
2 views
1
//PPUcounter emulates the H/V latch counters of the S-PPU2.
2
//
3
//real hardware has the S-CPU maintain its own copy of these counters that are
4
//updated based on the state of the S-PPU Vblank and Hblank pins. emulating this
5
//would require full lock-step synchronization for every clock tick.
6
//to bypass this and allow the two to run out-of-order, both the CPU and PPU
7
//classes inherit PPUcounter and keep their own counters.
8
//the timers are kept in sync, as the only differences occur on V=240 and V=261,
9
//based on interlace. thus, we need only synchronize and fetch interlace at any
10
//point before this in the frame, which is handled internally by this class at
11
//V=128.
12
13
class PPUcounter {
14
public:
15
alwaysinline void tick();
16
alwaysinline void tick(unsigned clocks);
17
18
alwaysinline bool field () const;
19
alwaysinline uint16 vcounter() const;
20
alwaysinline uint16 hcounter() const;
21
inline uint16 hdot() const;
22
inline uint16 lineclocks() const;
23
24
alwaysinline bool field (unsigned offset) const;
25
alwaysinline uint16 vcounter(unsigned offset) const;
26
alwaysinline uint16 hcounter(unsigned offset) const;
27
28
inline void reset();
29
function<void ()> scanline;
30
void serialize(serializer&);
31
32
private:
33
inline void vcounter_tick();
34
35
struct {
36
bool interlace;
37
bool field;
38
uint16 vcounter;
39
uint16 hcounter;
40
} status;
41
42
struct {
43
bool field[2048];
44
uint16 vcounter[2048];
45
uint16 hcounter[2048];
46
47
int32 index;
48
} history;
49
};
50
51