summaryrefslogtreecommitdiff
path: root/src/dolphin/gba/GBAGetProcessStatus.c
blob: 6f720061defea45e76548c8057fcf532b45eea64 (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
#include "dolphin/gba/GBAPriv.h"

s32 GBAGetProcessStatus(s32 chan, u8* percentp) {
    BOOL enabled;           // r26
    s32 ret;                // r29
    GBAControl* gba;        // r25
    GBABootInfo* bootInfo;  // r31
    u8 percent;             // r30
    OSTime t;               // r27

    gba = &__GBA[chan];
    bootInfo = &__GBA[chan].bootInfo;

    if (gba->callback != NULL || bootInfo->callback != NULL) {
        ret = GBA_BUSY;

        if (bootInfo->callback != NULL) {
            percent = (bootInfo->curOffset * 100) / bootInfo->realLength;
            if (bootInfo->begin != 0) {
                t = OSGetTime() - bootInfo->begin;
                if (OSTicksToMilliseconds(t) < 5500) {
                    percent = (percent * t) / OSMillisecondsToTicks(5500ll);
                }

                if (percent >= 100) {
                    percent = 100;
                }
            }

            if (percentp != NULL) {
                *percentp = percent;
            }
        }
    } else {
        ret = GBA_READY;
    }

    return ret;
}