summaryrefslogtreecommitdiff
path: root/lib/ultralib/src/io/gbpakgetstatus.c
blob: d17d15c6c0607787cef4b69d7027bd5f5a755c1d (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 "PR/os_internal.h"
#include "controller.h"

s32 osGbpakGetStatus(OSPfs* pfs, u8* status) {
    s32 ret;
    s32 i;
    u32 temp[BLOCKSIZE / sizeof(u32)];

    ret = __osContRamRead(pfs->queue, pfs->channel, CONT_BLOCK_GB_POWER, (u8*)temp);

    if ((ret == PFS_ERR_NEW_PACK) || (((u8*)temp)[BLOCKSIZE - 1] != GB_POWER_ON)) {
        ERRCK(osGbpakInit(pfs->queue, pfs, pfs->channel));
    }

    ret = __osContRamRead(pfs->queue, pfs->channel, CONT_BLOCK_GB_STATUS, (u8*)temp);

    if (ret == 0) {
        ERRCK(__osPfsGetStatus(pfs->queue, pfs->channel));

        *status = ((u8*)temp)[0];

        for (i = 1; i < BLOCKSIZE; i++) {
            *status |= ((u8*)temp)[i];
        }

        *status &= (OS_GBPAK_GBCART_PULL | OS_GBPAK_RSTB_DETECTION);
        *status |= ((u8*)temp)[BLOCKSIZE - 1];

        if (!(*status & OS_GBPAK_GBCART_ON)) {
            ret = PFS_ERR_NO_GBCART;
        } else if (*status & OS_GBPAK_GBCART_PULL) {
            ret = PFS_ERR_NEW_GBCART;
        }
    } else if (ret == 2) {
        ret = PFS_ERR_CONTRFAIL;
    }

    return ret;
}