File: counter.cpp

package info (click to toggle)
libretro-bsnes-mercury 094%2Bgit20160126-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 9,632 kB
  • sloc: cpp: 109,056; ansic: 3,097; makefile: 638; xml: 11; sh: 1
file content (52 lines) | stat: -rw-r--r-- 1,151 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#ifdef DSP_CPP

//counter_rate = number of samples per counter event
//all rates are evenly divisible by counter_range (0x7800, 30720, or 2048 * 5 * 3)
//note that rate[0] is a special case, which never triggers

const uint16 DSP::counter_rate[32] = {
     0, 2048, 1536,
  1280, 1024,  768,
   640,  512,  384,
   320,  256,  192,
   160,  128,   96,
    80,   64,   48,
    40,   32,   24,
    20,   16,   12,
    10,    8,    6,
     5,    4,    3,
           2,
           1,
};

//counter_offset = counter offset from zero
//counters do not appear to be aligned at zero for all rates

const uint16 DSP::counter_offset[32] = {
    0, 0, 1040,
  536, 0, 1040,
  536, 0, 1040,
  536, 0, 1040,
  536, 0, 1040,
  536, 0, 1040,
  536, 0, 1040,
  536, 0, 1040,
  536, 0, 1040,
  536, 0, 1040,
       0,
       0,
};

inline void DSP::counter_tick() {
  state.counter--;
  if(state.counter < 0) state.counter = counter_range - 1;
}

//return true if counter event should trigger

inline bool DSP::counter_poll(unsigned rate) {
  if(rate == 0) return false;
  return (((unsigned)state.counter + counter_offset[rate]) % counter_rate[rate]) == 0;
}

#endif