summaryrefslogtreecommitdiff
path: root/src/m_Do/m_Do_DVDError.cpp
blob: 96ff06999818fdf437116dc8703ce3ea11c43a93 (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//
// Generated by dtk
// Translation Unit: m_Do_DVDError.cpp
//

#include "m_Do/m_Do_DVDError.h"
#include "JSystem/JKernel/JKRThread.h"
#include "dolphin/os/OS.h"
#include "global.h"
#include "m_Do/m_Do_dvd_thread.h"
#include "m_Do/m_Do_ext.h"

OSThread DvdErr_thread;
u8 DvdErr_stack[0x1000] ALIGN_DECL(32);

static OSAlarm Alarm;
bool mDoDvdErr_initialized;

void mDoDvdErr_Watch(void*);
void AlarmHandler(OSAlarm*, OSContext*);

/* 80018BE0-80018CA0       .text mDoDvdErr_ThdInit__Fv */
void mDoDvdErr_ThdInit() {
    if (!mDoDvdErr_initialized) {
        OSTime time = OSGetTime();
        OSThread* curThread = OSGetCurrentThread();
        OSPriority priority = OSGetThreadPriority(curThread);

        OSCreateThread(&DvdErr_thread, (void*)mDoDvdErr_Watch, NULL, DvdErr_stack + sizeof(DvdErr_stack),
                       sizeof(DvdErr_stack), priority - 3, 1);
        OSResumeThread(&DvdErr_thread);
        OSCreateAlarm(&Alarm);
        OSSetPeriodicAlarm(&Alarm, time, OS_BUS_CLOCK / 4, AlarmHandler);

        mDoDvdErr_initialized = true;
    }
}

/* 80018CA0-80018CE8       .text mDoDvdErr_ThdCleanup__Fv */
void mDoDvdErr_ThdCleanup() {
    if (mDoDvdErr_initialized) {
        OSCancelThread(&DvdErr_thread);
        OSCancelAlarm(&Alarm);
        mDoDvdErr_initialized = false;
    }
}

/* 80018CE8-80018D44       .text mDoDvdErr_Watch__FPv */
void mDoDvdErr_Watch(void*) {
#if VERSION > VERSION_DEMO
    {
        JKRThread thread(OSGetCurrentThread(), 0);
    }

    JKRHeap* heap = NULL;
    heap->becomeCurrentHeap();
#endif

    do {
        if (DVDGetDriveStatus() == DVD_STATE_FATAL_ERROR) {
            mDoDvdThd::suspend();
        }
        OSSuspendThread(&DvdErr_thread);
    } while (true);
}

/* 80018D44-80018D6C       .text AlarmHandler__FP7OSAlarmP9OSContext */
void AlarmHandler(OSAlarm*, OSContext*) {
    OSResumeThread(&DvdErr_thread);
}