2961
|
1 /* Copyright (C) 2006 yopyop
|
|
2 yopyop156@ifrance.com
|
|
3 yopyop156.ifrance.com
|
|
4
|
|
5 Copyright (C) 2007 shash
|
|
6
|
|
7 This file is part of DeSmuME
|
|
8
|
|
9 DeSmuME is free software; you can redistribute it and/or modify
|
|
10 it under the terms of the GNU General Public License as published by
|
|
11 the Free Software Foundation; either version 2 of the License, or
|
|
12 (at your option) any later version.
|
|
13
|
|
14 DeSmuME is distributed in the hope that it will be useful,
|
|
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
17 GNU General Public License for more details.
|
|
18
|
|
19 You should have received a copy of the GNU General Public License
|
|
20 along with DeSmuME; if not, write to the Free Software
|
|
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
22 */
|
|
23
|
|
24 #ifndef MMU_H
|
|
25 #define MMU_H
|
|
26
|
|
27 #include "FIFO.h"
|
|
28 #include "dscard.h"
|
|
29
|
|
30 #include "ARM9.h"
|
|
31 #include "mc.h"
|
|
32
|
|
33 #ifdef __cplusplus
|
|
34 extern "C" {
|
|
35 #endif
|
|
36
|
|
37 extern char szRomPath[512];
|
|
38 extern char szRomBaseName[512];
|
|
39
|
|
40 /* theses macros are designed for reading/writing in memory (m is a pointer to memory, like MMU.MMU_MEM[proc], and a is an adress, like 0x04000000 */
|
|
41 #define MEM_8(m, a) (((u8*)(m[((a)>>20)&0xff]))[((a)&0xfff)])
|
|
42
|
|
43 /* theses ones for reading in rom data */
|
|
44 #define ROM_8(m, a) (((u8*)(m))[(a)])
|
|
45
|
|
46 #define IPCFIFO 0
|
|
47 #define MAIN_MEMORY_DISP_FIFO 2
|
|
48
|
|
49 typedef struct {
|
|
50 //ARM7 mem
|
|
51 u8 ARM7_BIOS[0x4000];
|
|
52 u8 ARM7_ERAM[0x10000];
|
|
53 u8 ARM7_REG[0x10000];
|
|
54 u8 ARM7_WIRAM[0x10000];
|
|
55
|
|
56 u8 vram_mode[9];
|
|
57 u8 vScreen;
|
|
58
|
|
59 //Shared ram
|
|
60 u8 SWIRAM[0x8000];
|
|
61
|
|
62 //Card rom & ram
|
|
63 u8 * CART_ROM;
|
|
64 u8 CART_RAM[0x10000];
|
|
65
|
|
66 //Unused ram
|
|
67 u8 UNUSED_RAM[4];
|
|
68
|
|
69 u8 * * MMU_MEM[2];
|
|
70 u32 * MMU_MASK[2];
|
|
71
|
|
72 u8 ARM9_RW_MODE;
|
|
73
|
|
74 FIFO fifos[16];
|
|
75
|
|
76 u32 * MMU_WAIT16[2];
|
|
77 u32 * MMU_WAIT32[2];
|
|
78
|
|
79 u32 DTCMRegion;
|
|
80 u32 ITCMRegion;
|
|
81
|
|
82 u16 timer[2][4];
|
|
83 s32 timerMODE[2][4];
|
|
84 u32 timerON[2][4];
|
|
85 u32 timerRUN[2][4];
|
|
86 u16 timerReload[2][4];
|
|
87
|
|
88 u32 reg_IME[2];
|
|
89 u32 reg_IE[2];
|
|
90 u32 reg_IF[2];
|
|
91
|
|
92 u32 DMAStartTime[2][4];
|
|
93 s32 DMACycle[2][4];
|
|
94 u32 DMACrt[2][4];
|
|
95 BOOL DMAing[2][4];
|
|
96
|
|
97 memory_chip_t fw;
|
|
98 memory_chip_t bupmem;
|
|
99
|
|
100 nds_dscard dscard[2];
|
|
101
|
|
102 } MMU_struct;
|
|
103
|
|
104 extern MMU_struct MMU;
|
|
105
|
|
106
|
|
107 struct armcpu_memory_iface {
|
|
108 /** the 32 bit instruction prefetch */
|
|
109 u32 FASTCALL (*prefetch32)( void *data, u32 adr);
|
|
110
|
|
111 /** the 16 bit instruction prefetch */
|
|
112 u16 FASTCALL (*prefetch16)( void *data, u32 adr);
|
|
113
|
|
114 /** read 8 bit data value */
|
|
115 u8 FASTCALL (*read8)( void *data, u32 adr);
|
|
116 /** read 16 bit data value */
|
|
117 u16 FASTCALL (*read16)( void *data, u32 adr);
|
|
118 /** read 32 bit data value */
|
|
119 u32 FASTCALL (*read32)( void *data, u32 adr);
|
|
120
|
|
121 /** write 8 bit data value */
|
|
122 void FASTCALL (*write8)( void *data, u32 adr, u8 val);
|
|
123 /** write 16 bit data value */
|
|
124 void FASTCALL (*write16)( void *data, u32 adr, u16 val);
|
|
125 /** write 32 bit data value */
|
|
126 void FASTCALL (*write32)( void *data, u32 adr, u32 val);
|
|
127
|
|
128 void *data;
|
|
129 };
|
|
130
|
|
131
|
|
132
|
|
133 static void mmu_select_savetype(int type, int *bmemtype, u32 *bmemsize) {
|
|
134 if (type<0 || type > 5) return;
|
|
135 *bmemtype=save_types[type][0];
|
|
136 *bmemsize=save_types[type][1];
|
|
137 mc_realloc(&MMU.bupmem, *bmemtype, *bmemsize);
|
|
138 }
|
|
139
|
|
140 void MMU_Init(void);
|
|
141 void MMU_DeInit(void);
|
|
142
|
|
143 void MMU_clearMem( void);
|
|
144
|
|
145 void MMU_setRom(u8 * rom, u32 mask);
|
|
146 void MMU_unsetRom( void);
|
|
147
|
|
148
|
|
149 /**
|
|
150 * Memory reading
|
|
151 */
|
|
152 u8 FASTCALL MMU_read8(u32 proc, u32 adr);
|
|
153 u16 FASTCALL MMU_read16(u32 proc, u32 adr);
|
|
154 u32 FASTCALL MMU_read32(u32 proc, u32 adr);
|
|
155
|
|
156 #ifdef MMU_ENABLE_ACL
|
|
157 u8 FASTCALL MMU_read8_acl(u32 proc, u32 adr, u32 access);
|
|
158 u16 FASTCALL MMU_read16_acl(u32 proc, u32 adr, u32 access);
|
|
159 u32 FASTCALL MMU_read32_acl(u32 proc, u32 adr, u32 access);
|
|
160 #else
|
|
161 #define MMU_read8_acl(proc,adr,access) MMU_read8(proc,adr)
|
|
162 #define MMU_read16_acl(proc,adr,access) MMU_read16(proc,adr)
|
|
163 #define MMU_read32_acl(proc,adr,access) MMU_read32(proc,adr)
|
|
164 #endif
|
|
165
|
|
166 /**
|
|
167 * Memory writing
|
|
168 */
|
|
169 void FASTCALL MMU_write8(u32 proc, u32 adr, u8 val);
|
|
170 void FASTCALL MMU_write16(u32 proc, u32 adr, u16 val);
|
|
171 void FASTCALL MMU_write32(u32 proc, u32 adr, u32 val);
|
|
172
|
|
173 #ifdef MMU_ENABLE_ACL
|
|
174 void FASTCALL MMU_write8_acl(u32 proc, u32 adr, u8 val);
|
|
175 void FASTCALL MMU_write16_acl(u32 proc, u32 adr, u16 val);
|
|
176 void FASTCALL MMU_write32_acl(u32 proc, u32 adr, u32 val);
|
|
177 #else
|
|
178 #define MMU_write8_acl MMU_write8
|
|
179 #define MMU_write16_acl MMU_write16
|
|
180 #define MMU_write32_acl MMU_write32
|
|
181 #endif
|
|
182
|
|
183 void FASTCALL MMU_doDMA(u32 proc, u32 num);
|
|
184
|
|
185
|
|
186 /*
|
|
187 * The base ARM memory interfaces
|
|
188 */
|
|
189 extern struct armcpu_memory_iface arm9_base_memory_iface;
|
|
190 extern struct armcpu_memory_iface arm7_base_memory_iface;
|
|
191 extern struct armcpu_memory_iface arm9_direct_memory_iface;
|
|
192
|
|
193
|
|
194 #ifdef __cplusplus
|
|
195 }
|
|
196 #endif
|
|
197
|
|
198 #endif
|