gbpakgetstatus.c
1.76 KB
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
/*---------------------------------------------------------------------
Copyright (C) 1997, Nintendo.
File gbpakgetstatus.c
Coded by Koji Mitsunari. Oct 2, 1997.
Modified by Koji Mitsunari. Apr 16, 1998.
Comments Get status of 64GB-PAK
$Id:
---------------------------------------------------------------------*/
/**************************************************************************
*
* $Revision: 1.2 $
* $Date: 2003/03/25 20:42:32 $
* $Source:
*
**************************************************************************/
#include "osint.h"
#include "controller.h"
s32
osGbpakGetStatus(OSPfs *pfs, u8 *status)
{
#ifdef BBPLAYER
return PFS_ERR_DEVICE;
#else
s32 ret, i;
u32 temp[BLOCKSIZE/(sizeof(u32)/sizeof(u8))];
/* Check if the bank may be changed */
ret = __osContRamRead(pfs->queue, pfs->channel, PFS_BANK_ADDR, (u8 *)temp);
if (ret == PFS_ERR_NEW_PACK || ((u8 *)temp)[BLOCKSIZE-1] != OS_GBPAK_ID) {
if ((ret = osGbpakInit(pfs->queue, pfs, pfs->channel)) != 0) {
return(ret);
}
}
/* Read status data */
ret = __osContRamRead(pfs->queue, pfs->channel, GB_POWER_ADDR, (u8 *)temp);
if (ret == 0) {
if ((ret = __osPfsGetStatus(pfs->queue, pfs->channel)) != 0){
return(ret);
}
*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 & 0x80) == 0) {
ret = PFS_ERR_NO_GBCART;
} else if ((*status & 0x40) != 0) {
ret = PFS_ERR_NEW_GBCART;
}
} else if (ret == PFS_ERR_NEW_PACK) {
ret = PFS_ERR_CONTRFAIL;
}
return(ret);
#endif
}