Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
MorsGames
GitHub Repository: MorsGames/sm64plus
Path: blob/master/lib/src/__osViInit.c
7857 views
1
#include "libultra_internal.h"
2
#include "hardware.h"
3
4
#ifdef VERSION_SH
5
extern s32 D_SH_80000300; // Potentially a TV type
6
#endif
7
8
#ifndef VERSION_JP
9
extern u32 osTvType;
10
#endif
11
12
OSViContext sViContexts[2] = { 0 };
13
OSViContext *__osViCurr = &sViContexts[0];
14
OSViContext *__osViNext = &sViContexts[1];
15
#ifdef VERSION_EU
16
u32 osViClock = 0x02E6D354; // used for audio frequency calculations
17
u32 sTvType = TV_TYPE_PAL;
18
#elif !defined(VERSION_SH)
19
u32 sTvType = TV_TYPE_NTSC;
20
u32 osViClock = 0x02E6D354;
21
#endif
22
23
extern OSViMode D_80334990;
24
extern OSViMode D_803349E0;
25
#if defined(VERSION_EU) || defined(VERSION_SH)
26
extern OSViMode D_80302FD0;
27
#endif
28
29
void __osViInit(void) {
30
//#ifdef VERSION_JP
31
#ifdef VERSION_US
32
sTvType = osTvType;
33
#endif
34
bzero(sViContexts, sizeof(sViContexts));
35
__osViCurr = &sViContexts[0];
36
__osViNext = &sViContexts[1];
37
__osViNext->retraceCount = 1;
38
__osViCurr->retraceCount = 1;
39
40
#if defined(VERSION_EU)
41
42
if (osTvType == TV_TYPE_PAL) {
43
__osViNext->modep = &D_80334990;
44
osViClock = 0x02F5B2D2;
45
} else if (osTvType == TV_TYPE_MPAL) {
46
__osViNext->modep = &D_803349E0;
47
osViClock = 0x02E6025C;
48
} else {
49
__osViNext->modep = &D_80302FD0;
50
osViClock = 0x02E6D354;
51
}
52
53
#elif defined(VERSION_SH)
54
55
__osViNext->buffer = (void *) 0x80000000;
56
__osViCurr->buffer = (void *) 0x80000000;
57
if (osTvType == TV_TYPE_PAL) {
58
__osViNext->modep = &D_80334990;
59
} else if (osTvType == TV_TYPE_MPAL) {
60
__osViNext->modep = &D_803349E0;
61
} else {
62
__osViNext->modep = &D_80302FD0;
63
}
64
65
#else
66
67
#ifdef VERSION_JP
68
if (sTvType != TV_TYPE_PAL)
69
#else
70
if (sTvType == TV_TYPE_NTSC)
71
#endif
72
{
73
__osViNext->modep = &D_80334990;
74
osViClock = 0x02E6D354;
75
} else {
76
__osViNext->modep = &D_803349E0;
77
#if defined(VERSION_JP)
78
osViClock = 0x02F5B2D2;
79
#elif defined(VERSION_US)
80
osViClock = 0x02E6025C;
81
#endif
82
}
83
#endif
84
85
__osViNext->unk00 = 0x20;
86
__osViNext->features = __osViNext->modep->comRegs.ctrl;
87
#ifndef VERSION_JP
88
while (HW_REG(VI_CURRENT_REG, u32) > 0xa) {
89
;
90
}
91
HW_REG(VI_STATUS_REG, u32) = 0;
92
#endif
93
__osViSwapContext();
94
}
95
96