gbpakinit.c
3.03 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*---------------------------------------------------------------------
Copyright (C) 1997, Nintendo.
File gbpakinit.c
Coded by Koji Mitsunari. Oct 2, 1997.
Modified by Koji Mitsunari. Apr 18, 1998.
Comments 64GB-PAK Initialize
$Id:
---------------------------------------------------------------------*/
/**************************************************************************
*
* $Revision: 1.2 $
* $Date: 2003/03/25 20:42:32 $
* $Source:
*
**************************************************************************/
#include "osint.h"
#include "controller.h"
#define GBPAK_INIT_WAIT 192000 /* micro sec. */
#ifndef BBPLAYER
OSTimer __osGbpakTimer;
OSMesgQueue __osGbpakTimerQ;
OSMesg __osGbpakTimerMsg;
#endif
s32
osGbpakInit(OSMesgQueue *mq, OSPfs *pfs, int channel)
{
#ifdef BBPLAYER
return PFS_ERR_DEVICE;
#else
int i;
s32 ret;
u8 temp[BLOCKSIZE];
pfs->status = 0;
/* broken CPAK or not ? */
for ( i = 0 ; i < BLOCKSIZE ; temp[i++] = OS_PFS_CHECK_ID);
ret = __osContRamWrite(mq, channel, PFS_BANK_ADDR, temp, 0);
if (ret == PFS_ERR_NEW_PACK) {
ret = __osContRamWrite(mq, channel, PFS_BANK_ADDR, temp, 0);
}
if (ret != 0) {
return(ret);
}
ret = __osContRamRead(mq, channel, PFS_BANK_ADDR, temp);
if (ret == PFS_ERR_NEW_PACK) {
ret = PFS_ERR_CONTRFAIL;
}
if (ret != 0) {
return(ret);
} else if (temp[0x1f] == OS_PFS_CHECK_ID) {
return(PFS_ERR_DEVICE);
}
/* Check GB-PAK ID */
for ( i = 0 ; i < BLOCKSIZE ; temp[i++] = OS_GBPAK_ID);
ret = __osContRamWrite(mq, channel, PFS_BANK_ADDR, temp, 0);
if (ret == PFS_ERR_NEW_PACK) {
ret = PFS_ERR_CONTRFAIL;
}
if (ret != 0) {
return(ret);
}
ret = __osContRamRead(mq, channel, PFS_BANK_ADDR, temp);
if (ret == PFS_ERR_NEW_PACK) {
ret = PFS_ERR_CONTRFAIL;
}
if (ret != 0) {
return(ret);
} else if ( temp[0x1f] != OS_GBPAK_ID ) {
return(PFS_ERR_DEVICE);
}
if ((ret = __osPfsGetStatus(mq, channel)) != 0){
return(ret);
}
osCreateMesgQueue(&__osGbpakTimerQ, &__osGbpakTimerMsg, 1);
osSetTimer(&__osGbpakTimer, OS_USEC_TO_CYCLES(GBPAK_INIT_WAIT), 0,
&__osGbpakTimerQ, &__osGbpakTimerMsg);
(void)osRecvMesg(&__osGbpakTimerQ, NULL, OS_MESG_BLOCK);
pfs->queue = mq;
pfs->status = PFS_GBPAK_INITIALIZED;
pfs->channel = channel;
pfs->activebank = OS_GBPAK_ID;
pfs->banks = 0xff; /* GB BANK */
pfs->version = 255; /* Memory Controller version */
pfs->dir_size = 255; /* RAM Size */
#if 0
pfs->label[0] = 1; /* flag for GBPAK Init */
pfs->label[1] = 0; /* flag for SRAM Init */
pfs->label[2] = 0xff; /* GB ROM BANK */
pfs->label[3] = 0xff; /* GB SRAM BANK */
#endif
#ifdef ROM_REG0_ERR_VERSION
pfs->label[4] = 0xff; /* flag for RAM ENABLE */
#endif
#if 0
#ifdef ROM_REG0_ERR_VERSION
for (i = 0 ; i < BLOCKSIZE ; temp[i++] = 0 ) ;
if ((i = osGbpakReadWrite(pfs, OS_WRITE, 0, temp, 32)) != 0 ) {
return(i);
} /* GB RAM ENABLE flag */
#endif
#endif
return(0);
#endif
}