aboutsummaryrefslogtreecommitdiff
path: root/sdk-modifications/libsrc/fs/disc_io/disc.c
blob: 8b5095320cfd411473f6cec83b39a3f33c5ca15c (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
187
188
189
190
191
192
193
194
/*

	disc.c

	uniformed io-interface to work with Chishm's FAT library

	Written by MightyMax
  

 Copyright (c) 2006 Michael "Chishm" Chisholm
	
 Redistribution and use in source and binary forms, with or without modification,
 are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice,
     this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice,
     this list of conditions and the following disclaimer in the documentation and/or
     other materials provided with the distribution.
  3. The name of the author may not be used to endorse or promote products derived
     from this software without specific prior written permission.

 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
 AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

	2005-11-06 - Chishm
		* Added WAIT_CR modifications for NDS

	2006-02-03 www.neoflash.com
		* Added SUPPORT_* defines, comment out any of the SUPPORT_* defines in disc_io.h to remove support
		  for the given interface and stop code being linked to the binary

	    * Added support for MK2 MMC interface

		* Added disc_Cache* functions

	2006-02-05 - Chishm
		* Added Supercard SD support

	2006-02-26 - Cytex
		* Added EFA2 support

	2006-05-18 - Chishm
		* Rewritten for FATlib disc.c
		
	2006-06-19 - Chishm
		* Changed read and write interface to accept a u32 instead of a u8 for the number of sectors
		
	2006-07-11 - Chishm
		* Removed disc_Cache* functions, since there is now a proper unified cache
		* Removed SUPPORT_* defines
		* Rewrote device detection functions
		* First libfat release
	
	2006-07-25 - Chishm
		* Changed IO_INTERFACEs to const
		
	2006-08-02 - Chishm
		* Added NinjaDS
*/

#include "disc.h"
#include "disc_io.h"

// Include known io-interfaces:
//#include "io_dldi.h"
//#include "io_mpcf.h"
//#include "io_m3cf.h"
//#include "io_m3sd.h"
//#include "io_sccf.h"
//#include "io_scsd.h"
//#include "io_fcsr.h"
//#include "io_nmmc.h"
//#include "io_efa2.h"
//#include "io_mmcf.h"
//#include "io_njsd.h"
//#include "io_acekard.h"
//#include "io_rpg_nand.h"
//#include "io_rpg_sd.h"
//#include "iointerface_sc.h"
#include "io_ds2_mmcf.h"

const IO_INTERFACE* ioInterfaces[] = {
	//&_io_dldi,
	//&_io_fcsr,
#ifdef NDS
	// Place Slot 1 (DS Card) interfaces here
	//&_io_rpg_sd, //&_io_rpg_nand, /*&_io_acekard, */
	// Place Slot 2 (GBA Cart) interfaces here
	//&_io_scsd, &_io_mpcf, &_io_m3cf, &_io_sccf, &_io_m3sd, &_io_fcsr
	// Experimental Slot 2 interfaces
	//, &_io_mmcf, &_io_efa2
    &_io_ds2_mmcf,
#endif
};

/*

	Hardware level disc funtions

*/


const IO_INTERFACE* _FAT_disc_gbaSlotFindInterface (void)
{
	// If running on an NDS, make sure the correct CPU can access
	// the GBA cart. First implemented by SaTa.
#ifdef NDS
 #ifdef ARM9
	REG_EXMEMCNT &= ~ARM7_OWNS_ROM;
 #endif
 #ifdef ARM7
	REG_EXMEMCNT |= ARM7_OWNS_ROM;
 #endif
#endif

	int i;

	for (i = 0; i < (sizeof(ioInterfaces) / sizeof(IO_INTERFACE*)); i++) {
		if ((ioInterfaces[i]->features & FEATURE_SLOT_GBA) && (ioInterfaces[i]->fn_startup())) {
			return ioInterfaces[i];
		}
	}
	return NULL;
}

#ifdef NDS
/*
 * Check the DS card slot for a valid memory card interface
 * If an interface is found, it is set as the default interace
 * and it returns true. Otherwise the default interface is left
 * untouched and it returns false.
 */
const IO_INTERFACE* _FAT_disc_dsSlotFindInterface (void)
{
#ifdef ARM9
	REG_EXMEMCNT &= ~ARM7_OWNS_CARD;
#endif
#ifdef ARM7
	REG_EXMEMCNT |= ARM7_OWNS_CARD;
#endif
	int i;

	for (i = 0; i < (sizeof(ioInterfaces) / sizeof(IO_INTERFACE*)); i++) {
		if ((ioInterfaces[i]->features & FEATURE_SLOT_NDS) && (ioInterfaces[i]->fn_startup())) {
			return ioInterfaces[i];
		}
	}

	return NULL;
}
#endif

/*
 * When running on an NDS, check the either slot for a valid memory
 * card interface. 
 * When running on a GBA, call _FAT_disc_gbaSlotFindInterface
 * If an interface is found, it is set as the default interace
 * and it returns true. Otherwise the default interface is left
 * untouched and it returns false.
 */
#ifdef NDS
const IO_INTERFACE* _FAT_disc_findInterface (void)
{
#ifdef ARM9
	REG_EXMEMCNT &= ~(ARM7_OWNS_CARD | ARM7_OWNS_ROM);
#endif
#ifdef ARM7
	REG_EXMEMCNT |= (ARM7_OWNS_CARD | ARM7_OWNS_ROM);
#endif

	int i;

	for (i = 0; i < (sizeof(ioInterfaces) / sizeof(IO_INTERFACE*)); i++) {
		if (ioInterfaces[i]->fn_startup()) {
			return ioInterfaces[i];
		}
	}

	return NULL;
}
#else
const IO_INTERFACE* _FAT_disc_findInterface (void)
{
	return _FAT_disc_gbaSlotFindInterface();
}
#endif