aboutsummaryrefslogtreecommitdiff
path: root/backends/platform/ds/arm9/source/fat/io_scsd.c
blob: a2fccf45d2a367ac0627c2a113570d3127b393ea (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
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/*
	io_scsd.c by SaTa.
	based on io_sccf.c
	
	
*/

/*
	io_sccf.c based on

	compact_flash.c
	By chishm (Michael Chisholm)

	Hardware Routines for reading a compact flash card
	using the Super Card CF

	CF routines modified with help from Darkfader

	This software is completely free. No warranty is provided.
	If you use it, please give me credit and email me about your
	project at chishm@hotmail.com

	See gba_nds_fat.txt for help and license details.
*/


#include "io_scsd.h"

/*-----------------------------------------------------------------
Since all CF addresses and commands are the same for the GBAMP,
simply use it's functions instead.
-----------------------------------------------------------------*/

extern bool MPCF_IsInserted (void);
extern bool MPCF_ClearStatus (void);
extern bool MPCF_ReadSectors (u32 sector, u8 numSecs, void* buffer);
extern bool MPCF_WriteSectors (u32 sector, u8 numSecs, void* buffer);

//	add by SaTa.
extern void InitSCMode(void);	//	CF�Ɠ���
extern void ReadSector(u16 *buff,u32 sector,u8 ReadNumber);
extern void WriteSector(u16 *buff,u32 sector,u8 writeNumber);
extern bool MemoryCard_IsInserted(void);	//	CF�ƈႤ
//	

/*-----------------------------------------------------------------
SCSD_Unlock
Returns true if SuperCard was unlocked, false if failed
Added by MightyMax
Modified by Chishm
-----------------------------------------------------------------*/
bool SCSD_Unlock(void)
{
	InitSCMode();
	return MemoryCard_IsInserted();
} 

bool SCSD_Shutdown(void) {
	return MPCF_ClearStatus() ;
} ;

bool SCSD_StartUp(void) {
	return SCSD_Unlock() ;
} ;

bool SCSD_ReadSectors (u32 sector, u8 ReadNumber, void* buff)
{
	ReadSector((u16 *)buff,sector,ReadNumber);
	return true;
}

bool SCSD_WriteSectors (u32 sector, u8 writeNumber, void* buff)
{
	WriteSector((u16 *)buff,sector,writeNumber);
	return true;
}


IO_INTERFACE io_scsd = {
	0x44534353,	// 'SCSD'
	FEATURE_MEDIUM_CANREAD | FEATURE_MEDIUM_CANWRITE,
	(FN_MEDIUM_STARTUP)&SCSD_StartUp,
	(FN_MEDIUM_ISINSERTED)&SCSD_Unlock,
	(FN_MEDIUM_READSECTORS)&SCSD_ReadSectors,
	(FN_MEDIUM_WRITESECTORS)&SCSD_WriteSectors,
	(FN_MEDIUM_CLEARSTATUS)&MPCF_ClearStatus,
	(FN_MEDIUM_SHUTDOWN)&SCSD_Shutdown
} ;


LPIO_INTERFACE SCSD_GetInterface(void) {
	return &io_scsd ;
} ;
/*
	io_scsd.c by SaTa.
	based on io_sccf.c
	
	
*/

/*
	io_sccf.c based on

	compact_flash.c
	By chishm (Michael Chisholm)

	Hardware Routines for reading a compact flash card
	using the Super Card CF

	CF routines modified with help from Darkfader

	This software is completely free. No warranty is provided.
	If you use it, please give me credit and email me about your
	project at chishm@hotmail.com

	See gba_nds_fat.txt for help and license details.
*/


#include "io_scsd.h"

/*-----------------------------------------------------------------
Since all CF addresses and commands are the same for the GBAMP,
simply use it's functions instead.
-----------------------------------------------------------------*/

extern bool MPCF_IsInserted (void);
extern bool MPCF_ClearStatus (void);
extern bool MPCF_ReadSectors (u32 sector, u8 numSecs, void* buffer);
extern bool MPCF_WriteSectors (u32 sector, u8 numSecs, void* buffer);

//	add by SaTa.
extern void InitSCMode(void);	//	CF�Ɠ���
extern void ReadSector(u16 *buff,u32 sector,u8 ReadNumber);
extern void WriteSector(u16 *buff,u32 sector,u8 writeNumber);
extern bool MemoryCard_IsInserted(void);	//	CF�ƈႤ
//	

/*-----------------------------------------------------------------
SCSD_Unlock
Returns true if SuperCard was unlocked, false if failed
Added by MightyMax
Modified by Chishm
-----------------------------------------------------------------*/
bool SCSD_Unlock(void)
{
	InitSCMode();
	return MemoryCard_IsInserted();
} 

bool SCSD_Shutdown(void) {
	return MPCF_ClearStatus() ;
} ;

bool SCSD_StartUp(void) {
	return SCSD_Unlock() ;
} ;

bool SCSD_ReadSectors (u32 sector, u8 ReadNumber, void* buff)
{
	ReadSector((u16 *)buff,sector,ReadNumber);
	return true;
}

bool SCSD_WriteSectors (u32 sector, u8 writeNumber, void* buff)
{
	WriteSector((u16 *)buff,sector,writeNumber);
	return true;
}


IO_INTERFACE io_scsd = {
	0x44534353,	// 'SCSD'
	FEATURE_MEDIUM_CANREAD | FEATURE_MEDIUM_CANWRITE,
	(FN_MEDIUM_STARTUP)&SCSD_StartUp,
	(FN_MEDIUM_ISINSERTED)&SCSD_Unlock,
	(FN_MEDIUM_READSECTORS)&SCSD_ReadSectors,
	(FN_MEDIUM_WRITESECTORS)&SCSD_WriteSectors,
	(FN_MEDIUM_CLEARSTATUS)&MPCF_ClearStatus,
	(FN_MEDIUM_SHUTDOWN)&SCSD_Shutdown
} ;


LPIO_INTERFACE SCSD_GetInterface(void) {
	return &io_scsd ;
} ;