summaryrefslogtreecommitdiff
path: root/src/Dolphin/si/SISamplingRate.c
blob: c9b96ca693ab56958f8df215769665c01067a068 (plain)
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
53
54
#include "dolphin/sipriv.h"
#include "dolphin/vi.h"
#pragma dont_inline on
static u32 SamplingRate;

typedef struct XY {
  u16 line;
  u8 count;
} XY;

static XY XYNTSC[12] = {
    {263 - 17, 2}, {15, 18}, {30, 9}, {44, 6},  {52, 5},  {65, 4},
    {87, 3},       {87, 3}, {87, 3}, {131, 2}, {131, 2}, {131, 2},
};

static XY XYPAL[12] = {
    {313 - 17, 2}, {15, 21}, {29, 11}, {45, 7},  {52, 6},  {63, 5},
    {78, 4},       {104, 3}, {104, 3}, {104, 3}, {104, 3}, {156, 2},
};

void SISetSamplingRate(u32 msec) {
  XY* xy;
  BOOL enabled;

  if (msec > 11) {
    msec = 11;
  }

  enabled = OSDisableInterrupts();

  SamplingRate = msec;

  switch (VIGetTvFormat()) {
  case VI_NTSC:
  case VI_MPAL:
  case VI_EURGB60:
    xy = XYNTSC;
    break;
  case VI_PAL:
    xy = XYPAL;
    break;
  default:
    OSReport("SISetSamplingRate: unknown TV format. Use default.");
    msec = 0;
    xy = XYNTSC;
    break;
  }

  SISetXY((__VIRegs[54] & 1 ? 2u : 1u) * xy[msec].line, xy[msec].count);
  OSRestoreInterrupts(enabled);
}

void SIRefreshSamplingRate() { SISetSamplingRate(SamplingRate); }
#pragma dont_inline reset