1 | /* |
---|
2 | io_mpcf.c based on |
---|
3 | |
---|
4 | compact_flash.c |
---|
5 | By chishm (Michael Chisholm) |
---|
6 | |
---|
7 | Hardware Routines for reading a compact flash card |
---|
8 | using the GBA Movie Player |
---|
9 | |
---|
10 | CF routines modified with help from Darkfader |
---|
11 | |
---|
12 | Copyright (c) 2006 Michael "Chishm" Chisholm |
---|
13 | |
---|
14 | Redistribution and use in source and binary forms, with or without modification, |
---|
15 | are permitted provided that the following conditions are met: |
---|
16 | |
---|
17 | 1. Redistributions of source code must retain the above copyright notice, |
---|
18 | this list of conditions and the following disclaimer. |
---|
19 | 2. Redistributions in binary form must reproduce the above copyright notice, |
---|
20 | this list of conditions and the following disclaimer in the documentation and/or |
---|
21 | other materials provided with the distribution. |
---|
22 | 3. The name of the author may not be used to endorse or promote products derived |
---|
23 | from this software without specific prior written permission. |
---|
24 | |
---|
25 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
---|
26 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY |
---|
27 | AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE |
---|
28 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
---|
29 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
---|
30 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
---|
31 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
---|
32 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, |
---|
33 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
---|
34 | */ |
---|
35 | |
---|
36 | |
---|
37 | #include "io_mpcf.h" |
---|
38 | #include "io_cf_common.h" |
---|
39 | |
---|
40 | //--------------------------------------------------------------- |
---|
41 | // DMA |
---|
42 | #ifdef _IO_USE_DMA |
---|
43 | #ifndef NDS |
---|
44 | #include "gba_dma.h" |
---|
45 | #else |
---|
46 | #include <nds/dma.h> |
---|
47 | #ifdef ARM9 |
---|
48 | #include <nds/arm9/cache.h> |
---|
49 | #endif |
---|
50 | #endif |
---|
51 | #endif |
---|
52 | |
---|
53 | //--------------------------------------------------------------- |
---|
54 | // GBAMP CF Addresses |
---|
55 | #define REG_MPCF_STS ((vu16*)0x098C0000) // Status of the CF Card / Device control |
---|
56 | #define REG_MPCF_CMD ((vu16*)0x090E0000) // Commands sent to control chip and status return |
---|
57 | #define REG_MPCF_ERR ((vu16*)0x09020000) // Errors / Features |
---|
58 | |
---|
59 | #define REG_MPCF_SEC ((vu16*)0x09040000) // Number of sector to transfer |
---|
60 | #define REG_MPCF_LBA1 ((vu16*)0x09060000) // 1st byte of sector address |
---|
61 | #define REG_MPCF_LBA2 ((vu16*)0x09080000) // 2nd byte of sector address |
---|
62 | #define REG_MPCF_LBA3 ((vu16*)0x090A0000) // 3rd byte of sector address |
---|
63 | #define REG_MPCF_LBA4 ((vu16*)0x090C0000) // last nibble of sector address | 0xE0 |
---|
64 | |
---|
65 | #define REG_MPCF_DATA ((vu16*)0x09000000) // Pointer to buffer of CF data transered from card |
---|
66 | |
---|
67 | static const CF_REGISTERS _MPCF_Registers = { |
---|
68 | REG_MPCF_DATA, |
---|
69 | REG_MPCF_STS, |
---|
70 | REG_MPCF_CMD, |
---|
71 | REG_MPCF_ERR, |
---|
72 | REG_MPCF_SEC, |
---|
73 | REG_MPCF_LBA1, |
---|
74 | REG_MPCF_LBA2, |
---|
75 | REG_MPCF_LBA3, |
---|
76 | REG_MPCF_LBA4 |
---|
77 | }; |
---|
78 | |
---|
79 | /*----------------------------------------------------------------- |
---|
80 | _MPCF_startup |
---|
81 | initializes the CF interface, returns true if successful, |
---|
82 | otherwise returns false |
---|
83 | -----------------------------------------------------------------*/ |
---|
84 | static bool _MPCF_startup(void) { |
---|
85 | return _CF_startup(&_MPCF_Registers); |
---|
86 | } |
---|
87 | |
---|
88 | /*----------------------------------------------------------------- |
---|
89 | the actual interface structure |
---|
90 | -----------------------------------------------------------------*/ |
---|
91 | const IO_INTERFACE _io_mpcf = { |
---|
92 | DEVICE_TYPE_MPCF, |
---|
93 | FEATURE_MEDIUM_CANREAD | FEATURE_MEDIUM_CANWRITE | FEATURE_SLOT_GBA, |
---|
94 | (FN_MEDIUM_STARTUP)&_MPCF_startup, |
---|
95 | (FN_MEDIUM_ISINSERTED)&_CF_isInserted, |
---|
96 | (FN_MEDIUM_READSECTORS)&_CF_readSectors, |
---|
97 | (FN_MEDIUM_WRITESECTORS)&_CF_writeSectors, |
---|
98 | (FN_MEDIUM_CLEARSTATUS)&_CF_clearStatus, |
---|
99 | (FN_MEDIUM_SHUTDOWN)&_CF_shutdown |
---|
100 | } ; |
---|