summaryrefslogtreecommitdiff
path: root/src/libultra/io/vi.c
blob: e4bdfe5597040adaa782d5acae58ce14369b51d0 (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
#include "ultra64.h"
#include "alignment.h"

static __OSViContext vi[2] ALIGNED(8) = { 0 };
__OSViContext* __osViCurr = &vi[0];
__OSViContext* __osViNext = &vi[1];

void __osViInit(void) {
    bzero(vi, sizeof(vi));
    __osViCurr = &vi[0];
    __osViNext = &vi[1];
    __osViNext->retraceCount = 1;
    __osViCurr->retraceCount = 1;
    __osViNext->buffer = (void*)K0BASE;
    __osViCurr->buffer = (void*)K0BASE;

    if (osTvType == OS_TV_PAL) {
        __osViNext->modep = &osViModePalLan1;
    } else if (osTvType == OS_TV_MPAL) {
        __osViNext->modep = &osViModeMpalLan1;
    } else { // OS_TV_NTSC or OS_TV_UNK28
        __osViNext->modep = &osViModeNtscLan1;
    }

    __osViNext->state = 0x20;
    __osViNext->features = __osViNext->modep->comRegs.ctrl;

    while (IO_READ(VI_CURRENT_REG) > 10) {}

    IO_WRITE(VI_STATUS_REG, 0);

    __osViSwapContext();
}