-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
b10_isPal.c
61 lines (53 loc) · 1.14 KB
/
b10_isPal.c
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
55
56
57
58
59
60
61
#include "banks.h"
#define MYBANK BANK(10)
int isPal() {
volatile int cycles = 0;
volatile int limit = 6000;
// wait for VDP interrupt
// with limit loop, in case it doesn't physically exist
// EVPC card might not have VDP-INT hooked up...
// (or it may be connected to EXT-INT tb 1)
__asm__(
"limi 0\n\t"
"clr r12\n"
"loop_%=:\n\t"
"dec %0\n\t"
"jeq break_%=\n\t"
"tb 2\n\t"
"jeq loop_%=\n"
"break_%=:\n\t"
"movb @>8802,r12"
: "=r"(cycles)
: "r"(cycles)
: "r12"
);
if (cycles == 0) {
return 0;
}
// again, provides a normalized result
__asm__(
"clr r12\n\t"
"tb 2\n\t"
"jeq -4\n\t"
"movb @>8802,r12"
: : : "r12"
);
cycles = 0;
// now wait again, but count while we wait.
// and repeat this 4 times, a fraction of a second
// as it is not precise
for (int i = 0; i < 6; i++) {
__asm__(
"clr r12\n\t"
"inc %0\n\t"
"tb 2\n\t"
"jeq -6\n\t"
"movb @>8802,r12"
: "=r"(cycles)
: "r"(cycles)
: "r12"
);
}
// with 6 iterations, NTSC reaches about 6800, and PAL reaches 8000
return cycles >= 7500;
}