| ... | ... |
@@ -322,7 +322,7 @@ struct MMU_struct |
| 322 | 322 |
// an extra 128KB for blank memory, directly after arm9_lcd, so that |
| 323 | 323 |
// we can easily map things to the end of arm9_lcd to represent |
| 324 | 324 |
// an unmapped state |
| 325 |
- uint8_t blank_memory[0x20000]; |
|
| 325 |
+ uint8_t blank_memory[0x100000 - 0xA4000]; |
|
| 326 | 326 |
}; |
| 327 | 327 |
#include "PACKED_END.h" |
| 328 | 328 |
|
* Removed a couple files that were not being used.
* Cleanups found with clang's -Weverything (and shutting it up about a
lot of things that were ridiculous, as well as ignoring some of the
warnings still coming up).
| ... | ... |
@@ -82,6 +82,8 @@ enum EDMADestinationUpdate |
| 82 | 82 |
class TRegister_32 |
| 83 | 83 |
{
|
| 84 | 84 |
public: |
| 85 |
+ virtual ~TRegister_32() { }
|
|
| 86 |
+ |
|
| 85 | 87 |
virtual uint32_t read32() = 0; |
| 86 | 88 |
virtual void write32(uint32_t val) = 0; |
| 87 | 89 |
void write(int size, uint32_t adr, uint32_t val) |
| ... | ... |
@@ -131,6 +133,7 @@ struct TGXSTAT : public TRegister_32 |
| 131 | 133 |
this->fifo_empty = true; |
| 132 | 134 |
this->fifo_low = false; |
| 133 | 135 |
} |
| 136 |
+ virtual ~TGXSTAT() { }
|
|
| 134 | 137 |
uint8_t tb; // test busy |
| 135 | 138 |
uint8_t tr; // test result |
| 136 | 139 |
uint8_t se; // stack error |
| ... | ... |
@@ -238,6 +241,7 @@ public: |
| 238 | 241 |
DmaController *controller; |
| 239 | 242 |
uint32_t *const ptr; |
| 240 | 243 |
AddressRegister(uint32_t *_ptr) : ptr(_ptr) { }
|
| 244 |
+ virtual ~AddressRegister() { }
|
|
| 241 | 245 |
virtual uint32_t read32() |
| 242 | 246 |
{
|
| 243 | 247 |
return *this->ptr; |
| ... | ... |
@@ -254,6 +258,7 @@ public: |
| 254 | 258 |
// we pass in a pointer to the controller here so we can alert it if anything changes |
| 255 | 259 |
DmaController *controller; |
| 256 | 260 |
ControlRegister() { }
|
| 261 |
+ virtual ~ControlRegister() { }
|
|
| 257 | 262 |
virtual uint32_t read32() |
| 258 | 263 |
{
|
| 259 | 264 |
return this->controller->read32(); |
| ... | ... |
@@ -17,8 +17,7 @@ |
| 17 | 17 |
along with the this software. If not, see <http://www.gnu.org/licenses/>. |
| 18 | 18 |
*/ |
| 19 | 19 |
|
| 20 |
-#ifndef MMU_H |
|
| 21 |
-#define MMU_H |
|
| 20 |
+#pragma once |
|
| 22 | 21 |
|
| 23 | 22 |
#include "FIFO.h" |
| 24 | 23 |
#include "mem.h" |
| ... | ... |
@@ -812,5 +811,3 @@ template<int PROCNUM, MMU_ACCESS_TYPE AT> inline uint32_t _MMU_read32(uint32_t a |
| 812 | 811 |
template<int PROCNUM, MMU_ACCESS_TYPE AT> inline void _MMU_write08(uint32_t addr, uint8_t val) { _MMU_write08(PROCNUM, AT, addr, val); }
|
| 813 | 812 |
template<int PROCNUM, MMU_ACCESS_TYPE AT> inline void _MMU_write16(uint32_t addr, uint16_t val) { _MMU_write16(PROCNUM, AT, addr, val); }
|
| 814 | 813 |
template<int PROCNUM, MMU_ACCESS_TYPE AT> inline void _MMU_write32(uint32_t addr, uint32_t val) { _MMU_write32(PROCNUM, AT, addr, val); }
|
| 815 |
- |
|
| 816 |
-#endif |
| ... | ... |
@@ -26,15 +26,18 @@ |
| 26 | 26 |
#include "mc.h" |
| 27 | 27 |
#include "bits.h" |
| 28 | 28 |
#include "readwrite.h" |
| 29 |
-//#include "debug.h" |
|
| 30 | 29 |
|
| 31 | 30 |
#ifdef HAVE_LUA |
| 32 | 31 |
#include "lua-engine.h" |
| 33 | 32 |
#endif |
| 34 | 33 |
|
| 34 |
+#ifdef HAVE_JIT |
|
| 35 |
+#include "arm_jit.h" |
|
| 36 |
+#endif |
|
| 37 |
+ |
|
| 35 | 38 |
#define ARMCPU_ARM7 1 |
| 36 | 39 |
#define ARMCPU_ARM9 0 |
| 37 |
-#define ARMPROC (PROCNUM ? NDS_ARM7:NDS_ARM9) |
|
| 40 |
+#define ARMPROC (PROCNUM ? NDS_ARM7 : NDS_ARM9) |
|
| 38 | 41 |
|
| 39 | 42 |
typedef const uint8_t TWaitState; |
| 40 | 43 |
|
| ... | ... |
@@ -74,61 +77,71 @@ enum EDMADestinationUpdate |
| 74 | 77 |
EDMADestinationUpdate_IncrementReload = 3 |
| 75 | 78 |
}; |
| 76 | 79 |
|
| 77 |
-//TODO |
|
| 78 |
-//n.b. this may be a bad idea, for complex registers like the dma control register. |
|
| 79 |
-//we need to know exactly what part was written to, instead of assuming all 32bits were written. |
|
| 80 |
+// TODO |
|
| 81 |
+// n.b. this may be a bad idea, for complex registers like the dma control register. |
|
| 82 |
+// we need to know exactly what part was written to, instead of assuming all 32bits were written. |
|
| 80 | 83 |
class TRegister_32 |
| 81 | 84 |
{
|
| 82 | 85 |
public: |
| 83 | 86 |
virtual uint32_t read32() = 0; |
| 84 |
- virtual void write32(const uint32_t val) = 0; |
|
| 85 |
- void write(const int size, const uint32_t adr, const uint32_t val) {
|
|
| 86 |
- if(size==32) write32(val); |
|
| 87 |
- else {
|
|
| 88 |
- const uint32_t offset = adr&3; |
|
| 89 |
- if(size==8) {
|
|
| 87 |
+ virtual void write32(uint32_t val) = 0; |
|
| 88 |
+ void write(int size, uint32_t adr, uint32_t val) |
|
| 89 |
+ {
|
|
| 90 |
+ if (size == 32) |
|
| 91 |
+ this->write32(val); |
|
| 92 |
+ else |
|
| 93 |
+ {
|
|
| 94 |
+ uint32_t offset = adr & 3; |
|
| 95 |
+ if (size == 8) |
|
| 96 |
+ {
|
|
| 90 | 97 |
printf("WARNING! 8BIT DMA ACCESS\n");
|
| 91 |
- uint32_t mask = 0xFF<<(offset<<3); |
|
| 92 |
- write32((read32()&~mask)|(val<<(offset<<3))); |
|
| 98 |
+ uint32_t mask = 0xFF << (offset << 3); |
|
| 99 |
+ this->write32((this->read32() & ~mask) | (val << (offset << 3))); |
|
| 93 | 100 |
} |
| 94 |
- else if(size==16) {
|
|
| 95 |
- uint32_t mask = 0xFFFF<<(offset<<3); |
|
| 96 |
- write32((read32()&~mask)|(val<<(offset<<3))); |
|
| 101 |
+ else if (size == 16) |
|
| 102 |
+ {
|
|
| 103 |
+ uint32_t mask = 0xFFFF << (offset << 3); |
|
| 104 |
+ this->write32((this->read32() & ~mask) | (val << (offset << 3))); |
|
| 97 | 105 |
} |
| 98 | 106 |
} |
| 99 | 107 |
} |
| 100 | 108 |
|
| 101 |
- uint32_t read(const int size, const uint32_t adr) |
|
| 109 |
+ uint32_t read(int size, uint32_t adr) |
|
| 102 | 110 |
{
|
| 103 |
- if(size==32) return read32(); |
|
| 104 |
- else {
|
|
| 105 |
- const uint32_t offset = adr&3; |
|
| 106 |
- if(size==8) { printf("WARNING! 8BIT DMA ACCESS\n"); return (read32()>>(offset<<3))&0xFF; }
|
|
| 107 |
- else return (read32()>>(offset<<3))&0xFFFF; |
|
| 111 |
+ if (size == 32) |
|
| 112 |
+ return this->read32(); |
|
| 113 |
+ else |
|
| 114 |
+ {
|
|
| 115 |
+ uint32_t offset = adr & 3; |
|
| 116 |
+ if (size == 8) |
|
| 117 |
+ {
|
|
| 118 |
+ printf("WARNING! 8BIT DMA ACCESS\n");
|
|
| 119 |
+ return (this->read32() >> (offset << 3)) & 0xFF; |
|
| 120 |
+ } |
|
| 121 |
+ else |
|
| 122 |
+ return (this->read32() >> (offset << 3)) & 0xFFFF; |
|
| 108 | 123 |
} |
| 109 | 124 |
} |
| 110 | 125 |
}; |
| 111 | 126 |
|
| 112 | 127 |
struct TGXSTAT : public TRegister_32 |
| 113 | 128 |
{
|
| 114 |
- TGXSTAT() {
|
|
| 115 |
- gxfifo_irq = se = tr = tb = sb = 0; |
|
| 116 |
- fifo_empty = true; |
|
| 117 |
- fifo_low = false; |
|
| 129 |
+ TGXSTAT() |
|
| 130 |
+ {
|
|
| 131 |
+ this->gxfifo_irq = this->se = this->tr = this->tb = this->sb = 0; |
|
| 132 |
+ this->fifo_empty = true; |
|
| 133 |
+ this->fifo_low = false; |
|
| 118 | 134 |
} |
| 119 |
- uint8_t tb; //test busy |
|
| 120 |
- uint8_t tr; //test result |
|
| 121 |
- uint8_t se; //stack error |
|
| 122 |
- uint8_t sb; //stack busy |
|
| 123 |
- uint8_t gxfifo_irq; //irq configuration |
|
| 135 |
+ uint8_t tb; // test busy |
|
| 136 |
+ uint8_t tr; // test result |
|
| 137 |
+ uint8_t se; // stack error |
|
| 138 |
+ uint8_t sb; // stack busy |
|
| 139 |
+ uint8_t gxfifo_irq; // irq configuration |
|
| 124 | 140 |
|
| 125 | 141 |
bool fifo_empty, fifo_low; |
| 126 | 142 |
|
| 127 | 143 |
virtual uint32_t read32(); |
| 128 |
- virtual void write32(const uint32_t val); |
|
| 129 |
- |
|
| 130 |
- //void savestate(EMUFILE *f); |
|
| 131 |
- bool loadstate(EMUFILE *f); |
|
| 144 |
+ virtual void write32(uint32_t val); |
|
| 132 | 145 |
}; |
| 133 | 146 |
|
| 134 | 147 |
void triggerDma(EDMAMode mode); |
| ... | ... |
@@ -136,54 +149,25 @@ void triggerDma(EDMAMode mode); |
| 136 | 149 |
class DivController |
| 137 | 150 |
{
|
| 138 | 151 |
public: |
| 139 |
- DivController() |
|
| 140 |
- : mode(0), busy(0) |
|
| 141 |
- {}
|
|
| 152 |
+ DivController() : mode(0), busy(0) { }
|
|
| 142 | 153 |
void exec(); |
| 143 | 154 |
uint8_t mode, busy, div0; |
| 144 |
- uint16_t read16() { return mode|(busy<<15)|(div0<<14); }
|
|
| 145 |
- void write16(uint16_t val) {
|
|
| 146 |
- mode = val&3; |
|
| 147 |
- //todo - do we clear the div0 flag here or is that strictly done by the divider unit? |
|
| 148 |
- } |
|
| 149 |
- /*void savestate(EMUFILE* os) |
|
| 155 |
+ uint16_t read16() { return this->mode | (this->busy << 15) | (this->div0 << 14); }
|
|
| 156 |
+ void write16(uint16_t val) |
|
| 150 | 157 |
{
|
| 151 |
- write8le(&mode,os); |
|
| 152 |
- write8le(&busy,os); |
|
| 153 |
- write8le(&div0,os); |
|
| 154 |
- }*/ |
|
| 155 |
- bool loadstate(EMUFILE* is, int) |
|
| 156 |
- {
|
|
| 157 |
- int ret = 1; |
|
| 158 |
- ret &= read8le(&mode,is); |
|
| 159 |
- ret &= read8le(&busy,is); |
|
| 160 |
- ret &= read8le(&div0,is); |
|
| 161 |
- return ret==1; |
|
| 158 |
+ this->mode = val & 3; |
|
| 159 |
+ // todo - do we clear the div0 flag here or is that strictly done by the divider unit? |
|
| 162 | 160 |
} |
| 163 | 161 |
}; |
| 164 | 162 |
|
| 165 | 163 |
class SqrtController |
| 166 | 164 |
{
|
| 167 | 165 |
public: |
| 168 |
- SqrtController() |
|
| 169 |
- : mode(0), busy(0) |
|
| 170 |
- {}
|
|
| 166 |
+ SqrtController() : mode(0), busy(0) { }
|
|
| 171 | 167 |
void exec(); |
| 172 | 168 |
uint8_t mode, busy; |
| 173 |
- uint16_t read16() { return mode|(busy<<15); }
|
|
| 174 |
- void write16(uint16_t val) { mode = val&1; }
|
|
| 175 |
- /*void savestate(EMUFILE* os) |
|
| 176 |
- {
|
|
| 177 |
- write8le(&mode,os); |
|
| 178 |
- write8le(&busy,os); |
|
| 179 |
- }*/ |
|
| 180 |
- bool loadstate(EMUFILE* is, int) |
|
| 181 |
- {
|
|
| 182 |
- int ret=1; |
|
| 183 |
- ret &= read8le(&mode,is); |
|
| 184 |
- ret &= read8le(&busy,is); |
|
| 185 |
- return ret==1; |
|
| 186 |
- } |
|
| 169 |
+ uint16_t read16() { return this->mode | (this->busy << 15); }
|
|
| 170 |
+ void write16(uint16_t val) { this->mode = val & 1; }
|
|
| 187 | 171 |
}; |
| 188 | 172 |
|
| 189 | 173 |
class DmaController |
| ... | ... |
@@ -199,26 +183,23 @@ public: |
| 199 | 183 |
uint32_t saddr, daddr; |
| 200 | 184 |
uint32_t saddr_user, daddr_user; |
| 201 | 185 |
|
| 202 |
- //indicates whether the dma needs to be checked for triggering |
|
| 186 |
+ // indicates whether the dma needs to be checked for triggering |
|
| 203 | 187 |
bool dmaCheck; |
| 204 | 188 |
|
| 205 |
- //indicates whether the dma right now is logically running |
|
| 206 |
- //(though for now we copy all the data when it triggers) |
|
| 189 |
+ // indicates whether the dma right now is logically running |
|
| 190 |
+ // (though for now we copy all the data when it triggers) |
|
| 207 | 191 |
bool running; |
| 208 | 192 |
|
| 209 | 193 |
bool paused; |
| 210 | 194 |
|
| 211 |
- //this flag will sometimes be set when a start condition is triggered |
|
| 212 |
- //other conditions may be automatically triggered based on scanning conditions |
|
| 195 |
+ // this flag will sometimes be set when a start condition is triggered |
|
| 196 |
+ // other conditions may be automatically triggered based on scanning conditions |
|
| 213 | 197 |
bool triggered; |
| 214 | 198 |
|
| 215 | 199 |
uint64_t nextEvent; |
| 216 | 200 |
|
| 217 | 201 |
int procnum, chan; |
| 218 | 202 |
|
| 219 |
- //void savestate(EMUFILE *f); |
|
| 220 |
- bool loadstate(EMUFILE *f); |
|
| 221 |
- |
|
| 222 | 203 |
void exec(); |
| 223 | 204 |
template<int PROCNUM> void doCopy(); |
| 224 | 205 |
void doPause(); |
| ... | ... |
@@ -231,8 +212,8 @@ public: |
| 231 | 212 |
wordcount(0), startmode(EDMAMode_Immediate), |
| 232 | 213 |
bitWidth(EDMABitWidth_16), |
| 233 | 214 |
sar(EDMASourceUpdate_Increment), dar(EDMADestinationUpdate_Increment), |
| 234 |
- //if saddr isnt cleared then rings of fate will trigger copy protection |
|
| 235 |
- //by inspecting dma3 saddr when it boots |
|
| 215 |
+ // if saddr isnt cleared then rings of fate will trigger copy protection |
|
| 216 |
+ // by inspecting dma3 saddr when it boots |
|
| 236 | 217 |
saddr(0), daddr(0), |
| 237 | 218 |
saddr_user(0), daddr_user(0), |
| 238 | 219 |
dmaCheck(false), |
| ... | ... |
@@ -243,50 +224,53 @@ public: |
| 243 | 224 |
sad(&saddr_user), |
| 244 | 225 |
dad(&daddr_user) |
| 245 | 226 |
{
|
| 246 |
- sad.controller = this; |
|
| 247 |
- dad.controller = this; |
|
| 248 |
- ctrl.controller = this; |
|
| 249 |
- regs[0] = &sad; |
|
| 250 |
- regs[1] = &dad; |
|
| 251 |
- regs[2] = &ctrl; |
|
| 227 |
+ this->sad.controller = this; |
|
| 228 |
+ this->dad.controller = this; |
|
| 229 |
+ this->ctrl.controller = this; |
|
| 230 |
+ this->regs[0] = &this->sad; |
|
| 231 |
+ this->regs[1] = &this->dad; |
|
| 232 |
+ this->regs[2] = &this->ctrl; |
|
| 252 | 233 |
} |
| 253 | 234 |
|
| 254 |
- class AddressRegister : public TRegister_32 {
|
|
| 235 |
+ class AddressRegister : public TRegister_32 |
|
| 236 |
+ {
|
|
| 255 | 237 |
public: |
| 256 |
- //we pass in a pointer to the controller here so we can alert it if anything changes |
|
| 257 |
- DmaController* controller; |
|
| 258 |
- uint32_t * const ptr; |
|
| 259 |
- AddressRegister(uint32_t* _ptr) |
|
| 260 |
- : ptr(_ptr) |
|
| 261 |
- {}
|
|
| 262 |
- virtual uint32_t read32() {
|
|
| 263 |
- return *ptr; |
|
| 238 |
+ // we pass in a pointer to the controller here so we can alert it if anything changes |
|
| 239 |
+ DmaController *controller; |
|
| 240 |
+ uint32_t *const ptr; |
|
| 241 |
+ AddressRegister(uint32_t *_ptr) : ptr(_ptr) { }
|
|
| 242 |
+ virtual uint32_t read32() |
|
| 243 |
+ {
|
|
| 244 |
+ return *this->ptr; |
|
| 264 | 245 |
} |
| 265 |
- virtual void write32(const uint32_t val) {
|
|
| 266 |
- *ptr = val; |
|
| 246 |
+ virtual void write32(uint32_t val) |
|
| 247 |
+ {
|
|
| 248 |
+ *this->ptr = val; |
|
| 267 | 249 |
} |
| 268 | 250 |
}; |
| 269 | 251 |
|
| 270 |
- class ControlRegister : public TRegister_32 {
|
|
| 252 |
+ class ControlRegister : public TRegister_32 |
|
| 253 |
+ {
|
|
| 271 | 254 |
public: |
| 272 |
- //we pass in a pointer to the controller here so we can alert it if anything changes |
|
| 273 |
- DmaController* controller; |
|
| 274 |
- ControlRegister() {}
|
|
| 275 |
- virtual uint32_t read32() {
|
|
| 276 |
- return controller->read32(); |
|
| 255 |
+ // we pass in a pointer to the controller here so we can alert it if anything changes |
|
| 256 |
+ DmaController *controller; |
|
| 257 |
+ ControlRegister() { }
|
|
| 258 |
+ virtual uint32_t read32() |
|
| 259 |
+ {
|
|
| 260 |
+ return this->controller->read32(); |
|
| 277 | 261 |
} |
| 278 |
- virtual void write32(const uint32_t val) {
|
|
| 279 |
- return controller->write32(val); |
|
| 262 |
+ virtual void write32(uint32_t val) |
|
| 263 |
+ {
|
|
| 264 |
+ return this->controller->write32(val); |
|
| 280 | 265 |
} |
| 281 | 266 |
}; |
| 282 | 267 |
|
| 283 | 268 |
AddressRegister sad, dad; |
| 284 | 269 |
ControlRegister ctrl; |
| 285 |
- TRegister_32* regs[3]; |
|
| 270 |
+ TRegister_32 *regs[3]; |
|
| 286 | 271 |
|
| 287 |
- void write32(const uint32_t val); |
|
| 272 |
+ void write32(uint32_t val); |
|
| 288 | 273 |
uint32_t read32(); |
| 289 |
- |
|
| 290 | 274 |
}; |
| 291 | 275 |
|
| 292 | 276 |
enum ECardMode |
| ... | ... |
@@ -296,9 +280,8 @@ enum ECardMode |
| 296 | 280 |
CardMode_KEY2 |
| 297 | 281 |
}; |
| 298 | 282 |
|
| 299 |
-typedef struct |
|
| 283 |
+struct nds_dscard |
|
| 300 | 284 |
{
|
| 301 |
- |
|
| 302 | 285 |
uint8_t command[8]; |
| 303 | 286 |
|
| 304 | 287 |
uint32_t address; |
| ... | ... |
@@ -308,68 +291,74 @@ typedef struct |
| 308 | 291 |
|
| 309 | 292 |
// NJSD stuff |
| 310 | 293 |
int blocklen; |
| 294 |
+}; |
|
| 311 | 295 |
|
| 312 |
-} nds_dscard; |
|
| 296 |
+#define DUP2(x) x, x |
|
| 297 |
+#define DUP4(x) x, x, x, x |
|
| 298 |
+#define DUP8(x) x, x, x, x, x, x, x, x |
|
| 299 |
+#define DUP16(x) x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x |
|
| 313 | 300 |
|
| 314 | 301 |
struct MMU_struct |
| 315 | 302 |
{
|
| 316 | 303 |
//ARM9 mem |
| 317 | 304 |
uint8_t ARM9_ITCM[0x8000]; |
| 318 |
- uint8_t ARM9_DTCM[0x4000]; |
|
| 305 |
+ uint8_t ARM9_DTCM[0x4000]; |
|
| 319 | 306 |
|
| 320 |
- //u8 MAIN_MEM[4*1024*1024]; //expanded from 4MB to 8MB to support debug consoles |
|
| 321 |
- //u8 MAIN_MEM[8*1024*1024]; //expanded from 8MB to 16MB to support dsi |
|
| 322 |
- uint8_t MAIN_MEM[16*1024*1024]; //expanded from 8MB to 16MB to support dsi |
|
| 323 |
- uint8_t ARM9_REG[0x1000000]; |
|
| 324 |
- uint8_t ARM9_BIOS[0x8000]; |
|
| 325 |
- uint8_t ARM9_VMEM[0x800]; |
|
| 307 |
+ //u8 MAIN_MEM[4*1024*1024]; // expanded from 4MB to 8MB to support debug consoles |
|
| 308 |
+ //u8 MAIN_MEM[8*1024*1024]; // expanded from 8MB to 16MB to support dsi |
|
| 309 |
+ uint8_t MAIN_MEM[16*1024*1024]; // expanded from 8MB to 16MB to support dsi |
|
| 310 |
+ uint8_t ARM9_REG[0x1000000]; |
|
| 311 |
+ uint8_t ARM9_BIOS[0x8000]; |
|
| 312 |
+ uint8_t ARM9_VMEM[0x800]; |
|
| 326 | 313 |
|
| 327 |
- #include "PACKED.h" |
|
| 328 |
- struct {
|
|
| 314 |
+#include "PACKED.h" |
|
| 315 |
+ struct |
|
| 316 |
+ {
|
|
| 329 | 317 |
uint8_t ARM9_LCD[0xA4000]; |
| 330 |
- //an extra 128KB for blank memory, directly after arm9_lcd, so that |
|
| 331 |
- //we can easily map things to the end of arm9_lcd to represent |
|
| 332 |
- //an unmapped state |
|
| 318 |
+ // an extra 128KB for blank memory, directly after arm9_lcd, so that |
|
| 319 |
+ // we can easily map things to the end of arm9_lcd to represent |
|
| 320 |
+ // an unmapped state |
|
| 333 | 321 |
uint8_t blank_memory[0x20000]; |
| 334 | 322 |
}; |
| 335 |
- #include "PACKED_END.h" |
|
| 323 |
+#include "PACKED_END.h" |
|
| 336 | 324 |
|
| 337 |
- uint8_t ARM9_OAM[0x800]; |
|
| 325 |
+ uint8_t ARM9_OAM[0x800]; |
|
| 338 | 326 |
|
| 339 |
- uint8_t* ExtPal[2][4]; |
|
| 340 |
- uint8_t* ObjExtPal[2][2]; |
|
| 327 |
+ uint8_t *ExtPal[2][4]; |
|
| 328 |
+ uint8_t *ObjExtPal[2][2]; |
|
| 341 | 329 |
|
| 342 |
- struct TextureInfo {
|
|
| 343 |
- uint8_t* texPalSlot[6]; |
|
| 344 |
- uint8_t* textureSlotAddr[4]; |
|
| 330 |
+ struct TextureInfo |
|
| 331 |
+ {
|
|
| 332 |
+ uint8_t *texPalSlot[6]; |
|
| 333 |
+ uint8_t *textureSlotAddr[4]; |
|
| 345 | 334 |
} texInfo; |
| 346 | 335 |
|
| 347 |
- //ARM7 mem |
|
| 336 |
+ // ARM7 mem |
|
| 348 | 337 |
uint8_t ARM7_BIOS[0x4000]; |
| 349 |
- uint8_t ARM7_ERAM[0x10000]; |
|
| 338 |
+ uint8_t ARM7_ERAM[0x10000]; // 64KB of exclusive WRAM |
|
| 350 | 339 |
uint8_t ARM7_REG[0x10000]; |
| 351 |
- uint8_t ARM7_WIRAM[0x10000]; |
|
| 340 |
+ uint8_t ARM7_WIRAM[0x10000]; // WIFI ram |
|
| 352 | 341 |
|
| 353 | 342 |
// VRAM mapping |
| 354 | 343 |
uint8_t VRAM_MAP[4][32]; |
| 355 | 344 |
uint32_t LCD_VRAM_ADDR[10]; |
| 356 | 345 |
uint8_t LCDCenable[10]; |
| 357 | 346 |
|
| 358 |
- //Shared ram |
|
| 347 |
+ // 32KB of shared WRAM - can be switched between ARM7 & ARM9 in two blocks |
|
| 359 | 348 |
uint8_t SWIRAM[0x8000]; |
| 360 | 349 |
|
| 361 |
- //Card rom & ram |
|
| 350 |
+ // Card rom & ram |
|
| 362 | 351 |
uint8_t * CART_ROM; |
| 363 | 352 |
|
| 364 |
- //Unused ram |
|
| 353 |
+ // Unused ram |
|
| 365 | 354 |
uint8_t UNUSED_RAM[4]; |
| 366 | 355 |
|
| 367 |
- //this is here so that we can trap glitchy emulator code |
|
| 368 |
- //which is accessing offsets 5,6,7 of unused ram due to unaligned accesses |
|
| 369 |
- //(also since the emulator doesn't prevent unaligned accesses) |
|
| 356 |
+ // this is here so that we can trap glitchy emulator code |
|
| 357 |
+ // which is accessing offsets 5,6,7 of unused ram due to unaligned accesses |
|
| 358 |
+ // (also since the emulator doesn't prevent unaligned accesses) |
|
| 370 | 359 |
uint8_t MORE_UNUSED_RAM[4]; |
| 371 | 360 |
|
| 372 |
- static uint8_t * MMU_MEM[2][256]; |
|
| 361 |
+ static uint8_t *MMU_MEM[2][256]; |
|
| 373 | 362 |
static uint32_t MMU_MASK[2][256]; |
| 374 | 363 |
|
| 375 | 364 |
uint8_t ARM9_RW_MODE; |
| ... | ... |
@@ -386,13 +375,11 @@ struct MMU_struct |
| 386 | 375 |
uint32_t reg_IME[2]; |
| 387 | 376 |
uint32_t reg_IE[2]; |
| 388 | 377 |
|
| 389 |
- //these are the user-controlled IF bits. some IF bits are generated as necessary from hardware conditions |
|
| 378 |
+ // these are the user-controlled IF bits. some IF bits are generated as necessary from hardware conditions |
|
| 390 | 379 |
uint32_t reg_IF_bits[2]; |
| 391 |
- //these flags are set occasionally to indicate that an irq should have entered the pipeline, and processing will be deferred a tiny bit to help emulate things |
|
| 380 |
+ // these flags are set occasionally to indicate that an irq should have entered the pipeline, and processing will be deferred a tiny bit to help emulate things |
|
| 392 | 381 |
uint32_t reg_IF_pending[2]; |
| 393 | 382 |
|
| 394 |
- //uint32_t reg_DISP3DCNT_bits; |
|
| 395 |
- |
|
| 396 | 383 |
template<int PROCNUM> uint32_t gen_IF(); |
| 397 | 384 |
|
| 398 | 385 |
bool divRunning; |
| ... | ... |
@@ -409,7 +396,7 @@ struct MMU_struct |
| 409 | 396 |
uint16_t AUX_SPI_CNT; |
| 410 | 397 |
uint16_t AUX_SPI_CMD; |
| 411 | 398 |
|
| 412 |
- //uint64_t gfx3dCycles; |
|
| 399 |
+ uint8_t WRAMCNT; |
|
| 413 | 400 |
|
| 414 | 401 |
uint8_t powerMan_CntReg; |
| 415 | 402 |
bool powerMan_CntRegWritten; |
| ... | ... |
@@ -420,16 +407,13 @@ struct MMU_struct |
| 420 | 407 |
nds_dscard dscard[2]; |
| 421 | 408 |
}; |
| 422 | 409 |
|
| 423 |
-//everything in here is derived from libnds behaviours. no hardware tests yet |
|
| 410 |
+// everything in here is derived from libnds behaviours. no hardware tests yet |
|
| 424 | 411 |
class DSI_TSC |
| 425 | 412 |
{
|
| 426 | 413 |
public: |
| 427 | 414 |
DSI_TSC(); |
| 428 | 415 |
void reset_command(); |
| 429 | 416 |
uint16_t write16(uint16_t val); |
| 430 |
- //bool save_state(EMUFILE* os); |
|
| 431 |
- //bool load_state(EMUFILE* is); |
|
| 432 |
- |
|
| 433 | 417 |
private: |
| 434 | 418 |
uint16_t read16(); |
| 435 | 419 |
uint8_t reg_selection; |
| ... | ... |
@@ -437,17 +421,17 @@ private: |
| 437 | 421 |
int32_t state; |
| 438 | 422 |
int32_t readcount; |
| 439 | 423 |
|
| 440 |
- //registers[0] contains the current page. |
|
| 441 |
- //we are going to go ahead and save these out in case we want to change the way this is emulated in the future.. |
|
| 442 |
- //we may want to poke registers in here at more convenient times and have the TSC dumbly pluck them out, |
|
| 443 |
- //rather than generate the values on the fly |
|
| 424 |
+ // registers[0] contains the current page. |
|
| 425 |
+ // we are going to go ahead and save these out in case we want to change the way this is emulated in the future.. |
|
| 426 |
+ // we may want to poke registers in here at more convenient times and have the TSC dumbly pluck them out, |
|
| 427 |
+ // rather than generate the values on the fly |
|
| 444 | 428 |
uint8_t registers[0x80]; |
| 445 | 429 |
}; |
| 446 | 430 |
|
| 447 |
-//this contains things which can't be memzeroed because they are smarter classes |
|
| 431 |
+// this contains things which can't be memzeroed because they are smarter classes |
|
| 448 | 432 |
struct MMU_struct_new |
| 449 | 433 |
{
|
| 450 |
- MMU_struct_new() ; |
|
| 434 |
+ MMU_struct_new(); |
|
| 451 | 435 |
BackupDevice backupDevice; |
| 452 | 436 |
DmaController dma[2][4]; |
| 453 | 437 |
TGXSTAT gxstat; |
| ... | ... |
@@ -455,65 +439,22 @@ struct MMU_struct_new |
| 455 | 439 |
DivController div; |
| 456 | 440 |
DSI_TSC dsi_tsc; |
| 457 | 441 |
|
| 458 |
- void write_dma(const int proc, const int size, const uint32_t adr, const uint32_t val); |
|
| 459 |
- uint32_t read_dma(const int proc, const int size, const uint32_t adr); |
|
| 460 |
- bool is_dma(const uint32_t adr) { return adr >= _REG_DMA_CONTROL_MIN && adr <= _REG_DMA_CONTROL_MAX; }
|
|
| 442 |
+ void write_dma(int proc, int size, uint32_t adr, uint32_t val); |
|
| 443 |
+ uint32_t read_dma(int proc, int size, uint32_t adr); |
|
| 444 |
+ bool is_dma(uint32_t adr) { return adr >= _REG_DMA_CONTROL_MIN && adr <= _REG_DMA_CONTROL_MAX; }
|
|
| 461 | 445 |
}; |
| 462 | 446 |
|
| 463 | 447 |
extern MMU_struct MMU; |
| 464 | 448 |
extern MMU_struct_new MMU_new; |
| 465 | 449 |
|
| 466 |
- |
|
| 467 |
-/*struct armcpu_memory_iface {*/
|
|
| 468 |
- /** the 32 bit instruction prefetch */ |
|
| 469 |
- //uint32_t FASTCALL (*prefetch32)( void *data, uint32_t adr); |
|
| 470 |
- |
|
| 471 |
- /** the 16 bit instruction prefetch */ |
|
| 472 |
- //uint16_t FASTCALL (*prefetch16)( void *data, uint32_t adr); |
|
| 473 |
- |
|
| 474 |
- /** read 8 bit data value */ |
|
| 475 |
- //uint8_t FASTCALL (*read8)( void *data, uint32_t adr); |
|
| 476 |
- /** read 16 bit data value */ |
|
| 477 |
- //uint16_t FASTCALL (*read16)( void *data, uint32_t adr); |
|
| 478 |
- /** read 32 bit data value */ |
|
| 479 |
- //uint32_t FASTCALL (*read32)( void *data, uint32_t adr); |
|
| 480 |
- |
|
| 481 |
- /** write 8 bit data value */ |
|
| 482 |
- //void FASTCALL (*write8)( void *data, uint32_t adr, uint8_t val); |
|
| 483 |
- /** write 16 bit data value */ |
|
| 484 |
- //void FASTCALL (*write16)( void *data, uint32_t adr, uint16_t val); |
|
| 485 |
- /** write 32 bit data value */ |
|
| 486 |
- /*void FASTCALL (*write32)( void *data, uint32_t adr, uint32_t val); |
|
| 487 |
- |
|
| 488 |
- void *data; |
|
| 489 |
-};*/ |
|
| 490 |
- |
|
| 491 |
- |
|
| 492 | 450 |
void MMU_Init(); |
| 493 | 451 |
void MMU_DeInit(); |
| 494 | 452 |
|
| 495 | 453 |
void MMU_Reset(); |
| 496 | 454 |
|
| 497 |
-void MMU_setRom(uint8_t * rom, uint32_t mask); |
|
| 455 |
+void MMU_setRom(uint8_t *rom, uint32_t mask); |
|
| 498 | 456 |
void MMU_unsetRom(); |
| 499 | 457 |
|
| 500 |
-//void print_memory_profiling(); |
|
| 501 |
- |
|
| 502 |
-// Memory reading/writing (old) |
|
| 503 |
-//uint8_t FASTCALL MMU_read8(uint32_t proc, uint32_t adr); |
|
| 504 |
-//uint16_t FASTCALL MMU_read16(uint32_t proc, uint32_t adr); |
|
| 505 |
-//uint32_t FASTCALL MMU_read32(uint32_t proc, uint32_t adr); |
|
| 506 |
-//void FASTCALL MMU_write8(uint32_t proc, uint32_t adr, uint8_t val); |
|
| 507 |
-//void FASTCALL MMU_write16(uint32_t proc, uint32_t adr, uint16_t val); |
|
| 508 |
-//void FASTCALL MMU_write32(uint32_t proc, uint32_t adr, uint32_t val); |
|
| 509 |
- |
|
| 510 |
-//template<int PROCNUM> void FASTCALL MMU_doDMA(uint32_t num); |
|
| 511 |
- |
|
| 512 |
-//The base ARM memory interfaces |
|
| 513 |
-//extern struct armcpu_memory_iface arm9_base_memory_iface; |
|
| 514 |
-//extern struct armcpu_memory_iface arm7_base_memory_iface; |
|
| 515 |
-//extern struct armcpu_memory_iface arm9_direct_memory_iface; |
|
| 516 |
- |
|
| 517 | 458 |
#define VRAM_BANKS 9 |
| 518 | 459 |
#define VRAM_BANK_A 0 |
| 519 | 460 |
#define VRAM_BANK_B 1 |
| ... | ... |
@@ -530,54 +471,46 @@ void MMU_unsetRom(); |
| 530 | 471 |
#define VRAM_PAGE_AOBJ 256 |
| 531 | 472 |
#define VRAM_PAGE_BOBJ 384 |
| 532 | 473 |
|
| 533 |
- |
|
| 534 |
-struct VramConfiguration {
|
|
| 535 |
- |
|
| 536 |
- enum Purpose {
|
|
| 537 |
- OFF, INVALID, ABG, BBG, AOBJ, BOBJ, LCDC, ARM7, TEX, TEXPAL, ABGEXTPAL, BBGEXTPAL, AOBJEXTPAL, BOBJEXTPAL |
|
| 474 |
+struct VramConfiguration |
|
| 475 |
+{
|
|
| 476 |
+ enum Purpose |
|
| 477 |
+ {
|
|
| 478 |
+ OFF, |
|
| 479 |
+ INVALID, |
|
| 480 |
+ ABG, |
|
| 481 |
+ BBG, |
|
| 482 |
+ AOBJ, |
|
| 483 |
+ BOBJ, |
|
| 484 |
+ LCDC, |
|
| 485 |
+ ARM7, |
|
| 486 |
+ TEX, |
|
| 487 |
+ TEXPAL, |
|
| 488 |
+ ABGEXTPAL, |
|
| 489 |
+ BBGEXTPAL, |
|
| 490 |
+ AOBJEXTPAL, |
|
| 491 |
+ BOBJEXTPAL |
|
| 538 | 492 |
}; |
| 539 | 493 |
|
| 540 |
- struct BankInfo {
|
|
| 494 |
+ struct BankInfo |
|
| 495 |
+ {
|
|
| 541 | 496 |
Purpose purpose; |
| 542 | 497 |
int ofs; |
| 543 | 498 |
} banks[VRAM_BANKS]; |
| 544 | 499 |
|
| 545 |
- inline void clear() {
|
|
| 546 |
- for(int i=0;i<VRAM_BANKS;i++) {
|
|
| 500 |
+ void clear() |
|
| 501 |
+ {
|
|
| 502 |
+ for (int i = 0; i < VRAM_BANKS; ++i) |
|
| 503 |
+ {
|
|
| 547 | 504 |
banks[i].ofs = 0; |
| 548 | 505 |
banks[i].purpose = OFF; |
| 549 | 506 |
} |
| 550 | 507 |
} |
| 551 |
- |
|
| 552 |
- //std::string describePurpose(Purpose p); |
|
| 553 |
- //std::string describe(); |
|
| 554 | 508 |
}; |
| 555 | 509 |
|
| 556 | 510 |
extern VramConfiguration vramConfiguration; |
| 557 | 511 |
|
| 558 |
-#define VRAM_ARM9_PAGES 512 |
|
| 512 |
+const int VRAM_ARM9_PAGES = 512; |
|
| 559 | 513 |
extern uint8_t vram_arm9_map[VRAM_ARM9_PAGES]; |
| 560 |
-/*inline void* MMU_gpu_map(uint32_t vram_addr) |
|
| 561 |
-{
|
|
| 562 |
- //this is supposed to map a single gpu vram address to emulator host memory |
|
| 563 |
- //but it returns a pointer to some zero memory in case of accesses to unmapped memory. |
|
| 564 |
- //this correctly handles the case with tile accesses to unmapped memory. |
|
| 565 |
- //it could also potentially go through a different LUT than vram_arm9_map in case we discover |
|
| 566 |
- //that it needs to be set up with different or no mirroring |
|
| 567 |
- //(I think it is a reasonable possibility that only the cpu has the nutty mirroring rules) |
|
| 568 |
- // |
|
| 569 |
- //if this system isn't used, Fantasy Aquarium displays garbage in the first ingame screen |
|
| 570 |
- //due to it storing 0x0F0F or somesuch in screen memory which points to a ridiculously big tile |
|
| 571 |
- //which should contain all 0 pixels |
|
| 572 |
- |
|
| 573 |
- uint32_t vram_page = (vram_addr>>14)&(VRAM_ARM9_PAGES-1); |
|
| 574 |
- uint32_t ofs = vram_addr & 0x3FFF; |
|
| 575 |
- vram_page = vram_arm9_map[vram_page]; |
|
| 576 |
- //blank pages are handled by the extra 16KB of blank memory at the end of ARM9_LCD |
|
| 577 |
- //and the fact that blank pages are mapped to appear at that location |
|
| 578 |
- return MMU.ARM9_LCD + (vram_page<<14) + ofs; |
|
| 579 |
-}*/ |
|
| 580 |
- |
|
| 581 | 514 |
|
| 582 | 515 |
template<int PROCNUM, MMU_ACCESS_TYPE AT> uint8_t _MMU_read08(uint32_t addr); |
| 583 | 516 |
template<int PROCNUM, MMU_ACCESS_TYPE AT> uint16_t _MMU_read16(uint32_t addr); |
| ... | ... |
@@ -612,191 +545,161 @@ extern uint32_t partie; |
| 612 | 545 |
extern uint32_t _MMU_MAIN_MEM_MASK; |
| 613 | 546 |
extern uint32_t _MMU_MAIN_MEM_MASK16; |
| 614 | 547 |
extern uint32_t _MMU_MAIN_MEM_MASK32; |
| 615 |
-/*inline void SetupMMU(bool debugConsole) {
|
|
| 616 |
- if(debugConsole) _MMU_MAIN_MEM_MASK = 0x7FFFFF; |
|
| 617 |
- else _MMU_MAIN_MEM_MASK = 0x3FFFFF; |
|
| 618 |
- _MMU_MAIN_MEM_MASK16 = _MMU_MAIN_MEM_MASK & ~1; |
|
| 619 |
- _MMU_MAIN_MEM_MASK32 = _MMU_MAIN_MEM_MASK & ~3; |
|
| 620 |
-}*/ |
|
| 621 | 548 |
void SetupMMU(bool debugConsole, bool dsi); |
| 622 | 549 |
|
| 623 |
-/*inline void CheckMemoryDebugEvent(EDEBUG_EVENT event, const MMU_ACCESS_TYPE type, const uint32_t procnum, const uint32_t addr, const uint32_t size, const uint32_t val) |
|
| 624 |
-{
|
|
| 625 |
- //TODO - ugh work out a better prefetch event system |
|
| 626 |
- if(type == MMU_AT_CODE && event == DEBUG_EVENT_READ) |
|
| 627 |
- event = DEBUG_EVENT_EXECUTE; |
|
| 628 |
- if(CheckDebugEvent(event)) |
|
| 629 |
- {
|
|
| 630 |
- DebugEventData.memAccessType = type; |
|
| 631 |
- DebugEventData.procnum = procnum; |
|
| 632 |
- DebugEventData.addr = addr; |
|
| 633 |
- DebugEventData.size = size; |
|
| 634 |
- DebugEventData.val = val; |
|
| 635 |
- HandleDebugEvent(event); |
|
| 636 |
- } |
|
| 637 |
-}*/ |
|
| 638 |
- |
|
| 639 |
- |
|
| 640 |
-//ALERT!!!!!!!!!!!!!! |
|
| 641 |
-//the following inline functions dont do the 0x0FFFFFFF mask. |
|
| 642 |
-//this may result in some unexpected behavior |
|
| 550 |
+// ALERT!!!!!!!!!!!!!! |
|
| 551 |
+// the following inline functions dont do the 0x0FFFFFFF mask. |
|
| 552 |
+// this may result in some unexpected behavior |
|
| 643 | 553 |
|
| 644 |
-inline uint8_t _MMU_read08(const int PROCNUM, const MMU_ACCESS_TYPE AT, const uint32_t addr) |
|
| 554 |
+inline uint8_t _MMU_read08(int PROCNUM, MMU_ACCESS_TYPE AT, uint32_t addr) |
|
| 645 | 555 |
{
|
| 646 |
- //CheckMemoryDebugEvent(DEBUG_EVENT_READ,AT,PROCNUM,addr,8,0); |
|
| 647 |
- |
|
| 648 |
- //special handling for DMA: read 0 from TCM |
|
| 649 |
- if(PROCNUM==ARMCPU_ARM9 && AT == MMU_AT_DMA) |
|
| 556 |
+ // special handling for DMA: read 0 from TCM |
|
| 557 |
+ if (PROCNUM == ARMCPU_ARM9 && AT == MMU_AT_DMA) |
|
| 650 | 558 |
{
|
| 651 |
- if(addr<0x02000000) return 0; //itcm |
|
| 652 |
- if((addr&(~0x3FFF)) == MMU.DTCMRegion) return 0; //dtcm |
|
| 559 |
+ if (addr < 0x02000000) |
|
| 560 |
+ return 0; // itcm |
|
| 561 |
+ if ((addr & ~0x3FFF) == MMU.DTCMRegion) |
|
| 562 |
+ return 0; // dtcm |
|
| 653 | 563 |
} |
| 654 | 564 |
|
| 655 | 565 |
#ifdef HAVE_LUA |
| 656 | 566 |
CallRegisteredLuaMemHook(addr, 1, /*FIXME*/ 0, LUAMEMHOOK_READ); |
| 657 | 567 |
#endif |
| 658 | 568 |
|
| 659 |
- if(PROCNUM==ARMCPU_ARM9) |
|
| 660 |
- if((addr&(~0x3FFF)) == MMU.DTCMRegion) |
|
| 661 |
- {
|
|
| 662 |
- //Returns data from DTCM (ARM9 only) |
|
| 663 |
- return T1ReadByte(MMU.ARM9_DTCM, addr & 0x3FFF); |
|
| 664 |
- } |
|
| 569 |
+ if (PROCNUM == ARMCPU_ARM9 && (addr & ~0x3FFF) == MMU.DTCMRegion) |
|
| 570 |
+ // Returns data from DTCM (ARM9 only) |
|
| 571 |
+ return T1ReadByte(MMU.ARM9_DTCM, addr & 0x3FFF); |
|
| 665 | 572 |
|
| 666 |
- if ( (addr & 0x0F000000) == 0x02000000) |
|
| 667 |
- return T1ReadByte( MMU.MAIN_MEM, addr & _MMU_MAIN_MEM_MASK); |
|
| 573 |
+ if ((addr & 0x0F000000) == 0x02000000) |
|
| 574 |
+ return T1ReadByte(MMU.MAIN_MEM, addr & _MMU_MAIN_MEM_MASK); |
|
| 668 | 575 |
|
| 669 |
- if(PROCNUM==ARMCPU_ARM9) return _MMU_ARM9_read08(addr); |
|
| 670 |
- else return _MMU_ARM7_read08(addr); |
|
| 576 |
+ if (PROCNUM == ARMCPU_ARM9) |
|
| 577 |
+ return _MMU_ARM9_read08(addr); |
|
| 578 |
+ else |
|
| 579 |
+ return _MMU_ARM7_read08(addr); |
|
| 671 | 580 |
} |
| 672 | 581 |
|
| 673 |
-inline uint16_t _MMU_read16(const int PROCNUM, const MMU_ACCESS_TYPE AT, const uint32_t addr) |
|
| 582 |
+inline uint16_t _MMU_read16(int PROCNUM, MMU_ACCESS_TYPE AT, uint32_t addr) |
|
| 674 | 583 |
{
|
| 675 |
- //CheckMemoryDebugEvent(DEBUG_EVENT_READ,AT,PROCNUM,addr,16,0); |
|
| 676 |
- |
|
| 677 |
- //special handling for DMA: read 0 from TCM |
|
| 678 |
- if(PROCNUM==ARMCPU_ARM9 && AT == MMU_AT_DMA) |
|
| 584 |
+ // special handling for DMA: read 0 from TCM |
|
| 585 |
+ if (PROCNUM == ARMCPU_ARM9 && AT == MMU_AT_DMA) |
|
| 679 | 586 |
{
|
| 680 |
- if(addr<0x02000000) return 0; //itcm |
|
| 681 |
- if((addr&(~0x3FFF)) == MMU.DTCMRegion) return 0; //dtcm |
|
| 587 |
+ if (addr < 0x02000000) |
|
| 588 |
+ return 0; // itcm |
|
| 589 |
+ if ((addr & ~0x3FFF) == MMU.DTCMRegion) |
|
| 590 |
+ return 0; // dtcm |
|
| 682 | 591 |
} |
| 683 | 592 |
|
| 684 | 593 |
#ifdef HAVE_LUA |
| 685 | 594 |
CallRegisteredLuaMemHook(addr, 2, /*FIXME*/ 0, LUAMEMHOOK_READ); |
| 686 | 595 |
#endif |
| 687 | 596 |
|
| 688 |
- //special handling for execution from arm9, since we spend so much time in there |
|
| 689 |
- if(PROCNUM==ARMCPU_ARM9 && AT == MMU_AT_CODE) |
|
| 597 |
+ // special handling for execution from arm9, since we spend so much time in there |
|
| 598 |
+ if (PROCNUM == ARMCPU_ARM9 && AT == MMU_AT_CODE) |
|
| 690 | 599 |
{
|
| 691 | 600 |
if ((addr & 0x0F000000) == 0x02000000) |
| 692 |
- return T1ReadWord_guaranteedAligned( MMU.MAIN_MEM, addr & _MMU_MAIN_MEM_MASK16); |
|
| 601 |
+ return T1ReadWord_guaranteedAligned(MMU.MAIN_MEM, addr & _MMU_MAIN_MEM_MASK16); |
|
| 693 | 602 |
|
| 694 |
- if(addr<0x02000000) |
|
| 603 |
+ if (addr < 0x02000000) |
|
| 695 | 604 |
return T1ReadWord_guaranteedAligned(MMU.ARM9_ITCM, addr&0x7FFE); |
| 696 | 605 |
|
| 697 | 606 |
goto dunno; |
| 698 | 607 |
} |
| 699 | 608 |
|
| 700 |
- if(PROCNUM==ARMCPU_ARM9) |
|
| 701 |
- if((addr&(~0x3FFF)) == MMU.DTCMRegion) |
|
| 702 |
- {
|
|
| 703 |
- //Returns data from DTCM (ARM9 only) |
|
| 704 |
- return T1ReadWord_guaranteedAligned(MMU.ARM9_DTCM, addr & 0x3FFE); |
|
| 705 |
- } |
|
| 609 |
+ if (PROCNUM == ARMCPU_ARM9 && (addr & ~0x3FFF) == MMU.DTCMRegion) |
|
| 610 |
+ // Returns data from DTCM (ARM9 only) |
|
| 611 |
+ return T1ReadWord_guaranteedAligned(MMU.ARM9_DTCM, addr & 0x3FFE); |
|
| 706 | 612 |
|
| 707 |
- if ( (addr & 0x0F000000) == 0x02000000) |
|
| 708 |
- return T1ReadWord_guaranteedAligned( MMU.MAIN_MEM, addr & _MMU_MAIN_MEM_MASK16); |
|
| 613 |
+ if ((addr & 0x0F000000) == 0x02000000) |
|
| 614 |
+ return T1ReadWord_guaranteedAligned(MMU.MAIN_MEM, addr & _MMU_MAIN_MEM_MASK16); |
|
| 709 | 615 |
|
| 710 | 616 |
dunno: |
| 711 |
- if(PROCNUM==ARMCPU_ARM9) return _MMU_ARM9_read16(addr); |
|
| 712 |
- else return _MMU_ARM7_read16(addr); |
|
| 617 |
+ if (PROCNUM == ARMCPU_ARM9) |
|
| 618 |
+ return _MMU_ARM9_read16(addr); |
|
| 619 |
+ else |
|
| 620 |
+ return _MMU_ARM7_read16(addr); |
|
| 713 | 621 |
} |
| 714 | 622 |
|
| 715 |
-inline uint32_t _MMU_read32(const int PROCNUM, const MMU_ACCESS_TYPE AT, const uint32_t addr) |
|
| 623 |
+inline uint32_t _MMU_read32(int PROCNUM, MMU_ACCESS_TYPE AT, uint32_t addr) |
|
| 716 | 624 |
{
|
| 717 |
- //CheckMemoryDebugEvent(DEBUG_EVENT_READ,AT,PROCNUM,addr,32,0); |
|
| 718 |
- |
|
| 719 |
- //special handling for DMA: read 0 from TCM |
|
| 720 |
- if(PROCNUM==ARMCPU_ARM9 && AT == MMU_AT_DMA) |
|
| 625 |
+ // special handling for DMA: read 0 from TCM |
|
| 626 |
+ if (PROCNUM == ARMCPU_ARM9 && AT == MMU_AT_DMA) |
|
| 721 | 627 |
{
|
| 722 |
- if(addr<0x02000000) return 0; //itcm |
|
| 723 |
- if((addr&(~0x3FFF)) == MMU.DTCMRegion) return 0; //dtcm |
|
| 628 |
+ if (addr < 0x02000000) |
|
| 629 |
+ return 0; // itcm |
|
| 630 |
+ if ((addr & ~0x3FFF) == MMU.DTCMRegion) |
|
| 631 |
+ return 0; // dtcm |
|
| 724 | 632 |
} |
| 725 | 633 |
|
| 726 | 634 |
#ifdef HAVE_LUA |
| 727 | 635 |
CallRegisteredLuaMemHook(addr, 4, /*FIXME*/ 0, LUAMEMHOOK_READ); |
| 728 | 636 |
#endif |
| 729 | 637 |
|
| 730 |
- //special handling for execution from arm9, since we spend so much time in there |
|
| 731 |
- if(PROCNUM==ARMCPU_ARM9 && AT == MMU_AT_CODE) |
|
| 638 |
+ //s pecial handling for execution from arm9, since we spend so much time in there |
|
| 639 |
+ if (PROCNUM == ARMCPU_ARM9 && AT == MMU_AT_CODE) |
|
| 732 | 640 |
{
|
| 733 |
- if ( (addr & 0x0F000000) == 0x02000000) |
|
| 734 |
- return T1ReadLong_guaranteedAligned( MMU.MAIN_MEM, addr & _MMU_MAIN_MEM_MASK32); |
|
| 641 |
+ if ((addr & 0x0F000000) == 0x02000000) |
|
| 642 |
+ return T1ReadLong_guaranteedAligned(MMU.MAIN_MEM, addr & _MMU_MAIN_MEM_MASK32); |
|
| 735 | 643 |
|
| 736 |
- if(addr<0x02000000) |
|
| 644 |
+ if (addr < 0x02000000) |
|
| 737 | 645 |
return T1ReadLong_guaranteedAligned(MMU.ARM9_ITCM, addr&0x7FFC); |
| 738 | 646 |
|
| 739 |
- //what happens when we execute from DTCM? nocash makes it look like we get 0xFFFFFFFF but i can't seem to verify it |
|
| 740 |
- //historically, desmume would fall through to its old memory map struct |
|
| 741 |
- //which would return unused memory (0) |
|
| 742 |
- //it seems the hardware returns 0 or something benign because in actuality 0xFFFFFFFF is an undefined opcode |
|
| 743 |
- //and we know our handling for that is solid |
|
| 647 |
+ // what happens when we execute from DTCM? nocash makes it look like we get 0xFFFFFFFF but i can't seem to verify it |
|
| 648 |
+ // historically, desmume would fall through to its old memory map struct |
|
| 649 |
+ // which would return unused memory (0) |
|
| 650 |
+ // it seems the hardware returns 0 or something benign because in actuality 0xFFFFFFFF is an undefined opcode |
|
| 651 |
+ // and we know our handling for that is solid |
|
| 744 | 652 |
|
| 745 | 653 |
goto dunno; |
| 746 | 654 |
} |
| 747 | 655 |
|
| 748 |
- //special handling for execution from arm7. try reading from main memory first |
|
| 749 |
- if(PROCNUM==ARMCPU_ARM7) |
|
| 750 |
- {
|
|
| 751 |
- if ( (addr & 0x0F000000) == 0x02000000) |
|
| 752 |
- return T1ReadLong_guaranteedAligned( MMU.MAIN_MEM, addr & _MMU_MAIN_MEM_MASK32); |
|
| 753 |
- else if((addr & 0xFF800000) == 0x03800000) |
|
| 754 |
- return T1ReadLong_guaranteedAligned(MMU.ARM7_ERAM, addr&0xFFFC); |
|
| 755 |
- else if((addr & 0xFF800000) == 0x03000000) |
|
| 756 |
- return T1ReadLong_guaranteedAligned(MMU.SWIRAM, addr&0x7FFC); |
|
| 757 |
- } |
|
| 758 |
- |
|
| 656 |
+ // special handling for execution from arm7. try reading from main memory first |
|
| 657 |
+ if (PROCNUM == ARMCPU_ARM7 && (addr & 0x0F000000) == 0x02000000) |
|
| 658 |
+ return T1ReadLong_guaranteedAligned(MMU.MAIN_MEM, addr & _MMU_MAIN_MEM_MASK32); |
|
| 759 | 659 |
|
| 760 |
- //for other arm9 cases, we have to check from dtcm first because it is patched on top of the main memory range |
|
| 761 |
- if(PROCNUM==ARMCPU_ARM9) |
|
| 660 |
+ // for other arm9 cases, we have to check from dtcm first because it is patched on top of the main memory range |
|
| 661 |
+ if (PROCNUM == ARMCPU_ARM9) |
|
| 762 | 662 |
{
|
| 763 |
- if((addr&(~0x3FFF)) == MMU.DTCMRegion) |
|
| 764 |
- {
|
|
| 765 |
- //Returns data from DTCM (ARM9 only) |
|
| 663 |
+ if ((addr & ~0x3FFF) == MMU.DTCMRegion) |
|
| 664 |
+ // Returns data from DTCM (ARM9 only) |
|
| 766 | 665 |
return T1ReadLong_guaranteedAligned(MMU.ARM9_DTCM, addr & 0x3FFC); |
| 767 |
- } |
|
| 768 | 666 |
|
| 769 |
- if ( (addr & 0x0F000000) == 0x02000000) |
|
| 770 |
- return T1ReadLong_guaranteedAligned( MMU.MAIN_MEM, addr & _MMU_MAIN_MEM_MASK32); |
|
| 667 |
+ if ((addr & 0x0F000000) == 0x02000000) |
|
| 668 |
+ return T1ReadLong_guaranteedAligned(MMU.MAIN_MEM, addr & _MMU_MAIN_MEM_MASK32); |
|
| 771 | 669 |
} |
| 772 | 670 |
|
| 773 | 671 |
dunno: |
| 774 |
- if(PROCNUM==ARMCPU_ARM9) return _MMU_ARM9_read32(addr); |
|
| 775 |
- else return _MMU_ARM7_read32(addr); |
|
| 672 |
+ if (PROCNUM == ARMCPU_ARM9) |
|
| 673 |
+ return _MMU_ARM9_read32(addr); |
|
| 674 |
+ else |
|
| 675 |
+ return _MMU_ARM7_read32(addr); |
|
| 776 | 676 |
} |
| 777 | 677 |
|
| 778 |
-inline void _MMU_write08(const int PROCNUM, const MMU_ACCESS_TYPE AT, const uint32_t addr, uint8_t val) |
|
| 678 |
+inline void _MMU_write08(int PROCNUM, MMU_ACCESS_TYPE AT, uint32_t addr, uint8_t val) |
|
| 779 | 679 |
{
|
| 780 |
- //CheckMemoryDebugEvent(DEBUG_EVENT_WRITE,AT,PROCNUM,addr,8,val); |
|
| 781 |
- |
|
| 782 |
- //special handling for DMA: discard writes to TCM |
|
| 783 |
- if(PROCNUM==ARMCPU_ARM9 && AT == MMU_AT_DMA) |
|
| 680 |
+ // special handling for DMA: discard writes to TCM |
|
| 681 |
+ if (PROCNUM == ARMCPU_ARM9 && AT == MMU_AT_DMA) |
|
| 784 | 682 |
{
|
| 785 |
- if(addr<0x02000000) return; //itcm |
|
| 786 |
- if((addr&(~0x3FFF)) == MMU.DTCMRegion) return; //dtcm |
|
| 683 |
+ if (addr < 0x02000000) |
|
| 684 |
+ return; // itcm |
|
| 685 |
+ if ((addr & ~0x3FFF) == MMU.DTCMRegion) |
|
| 686 |
+ return; // dtcm |
|
| 787 | 687 |
} |
| 788 | 688 |
|
| 789 |
- if(PROCNUM==ARMCPU_ARM9) |
|
| 790 |
- if((addr&(~0x3FFF)) == MMU.DTCMRegion) |
|
| 791 |
- {
|
|
| 792 |
- T1WriteByte(MMU.ARM9_DTCM, addr & 0x3FFF, val); |
|
| 689 |
+ if (PROCNUM == ARMCPU_ARM9 && (addr & ~0x3FFF) == MMU.DTCMRegion) |
|
| 690 |
+ {
|
|
| 691 |
+ T1WriteByte(MMU.ARM9_DTCM, addr & 0x3FFF, val); |
|
| 793 | 692 |
#ifdef HAVE_LUA |
| 794 |
- CallRegisteredLuaMemHook(addr, 1, val, LUAMEMHOOK_WRITE); |
|
| 693 |
+ CallRegisteredLuaMemHook(addr, 1, val, LUAMEMHOOK_WRITE); |
|
| 795 | 694 |
#endif |
| 796 |
- return; |
|
| 797 |
- } |
|
| 695 |
+ return; |
|
| 696 |
+ } |
|
| 798 | 697 |
|
| 799 |
- if ( (addr & 0x0F000000) == 0x02000000) {
|
|
| 698 |
+ if ((addr & 0x0F000000) == 0x02000000) |
|
| 699 |
+ {
|
|
| 700 |
+#ifdef HAVE_JIT |
|
| 701 |
+ JIT_COMPILED_FUNC_KNOWNBANK(addr, MAIN_MEM, _MMU_MAIN_MEM_MASK, 0) = 0; |
|
| 702 |
+#endif |
|
| 800 | 703 |
T1WriteByte( MMU.MAIN_MEM, addr & _MMU_MAIN_MEM_MASK, val); |
| 801 | 704 |
#ifdef HAVE_LUA |
| 802 | 705 |
CallRegisteredLuaMemHook(addr, 1, val, LUAMEMHOOK_WRITE); |
| ... | ... |
@@ -804,35 +707,40 @@ inline void _MMU_write08(const int PROCNUM, const MMU_ACCESS_TYPE AT, const uint |
| 804 | 707 |
return; |
| 805 | 708 |
} |
| 806 | 709 |
|
| 807 |
- if(PROCNUM==ARMCPU_ARM9) _MMU_ARM9_write08(addr,val); |
|
| 808 |
- else _MMU_ARM7_write08(addr,val); |
|
| 710 |
+ if (PROCNUM == ARMCPU_ARM9) |
|
| 711 |
+ _MMU_ARM9_write08(addr, val); |
|
| 712 |
+ else |
|
| 713 |
+ _MMU_ARM7_write08(addr, val); |
|
| 809 | 714 |
#ifdef HAVE_LUA |
| 810 | 715 |
CallRegisteredLuaMemHook(addr, 1, val, LUAMEMHOOK_WRITE); |
| 811 | 716 |
#endif |
| 812 | 717 |
} |
| 813 | 718 |
|
| 814 |
-inline void _MMU_write16(const int PROCNUM, const MMU_ACCESS_TYPE AT, const uint32_t addr, uint16_t val) |
|
| 719 |
+inline void _MMU_write16(int PROCNUM, MMU_ACCESS_TYPE AT, uint32_t addr, uint16_t val) |
|
| 815 | 720 |
{
|
| 816 |
- //CheckMemoryDebugEvent(DEBUG_EVENT_WRITE,AT,PROCNUM,addr,16,val); |
|
| 817 |
- |
|
| 818 |
- //special handling for DMA: discard writes to TCM |
|
| 819 |
- if(PROCNUM==ARMCPU_ARM9 && AT == MMU_AT_DMA) |
|
| 721 |
+ // special handling for DMA: discard writes to TCM |
|
| 722 |
+ if (PROCNUM == ARMCPU_ARM9 && AT == MMU_AT_DMA) |
|
| 820 | 723 |
{
|
| 821 |
- if(addr<0x02000000) return; //itcm |
|
| 822 |
- if((addr&(~0x3FFF)) == MMU.DTCMRegion) return; //dtcm |
|
| 724 |
+ if (addr < 0x02000000) |
|
| 725 |
+ return; // itcm |
|
| 726 |
+ if ((addr & ~0x3FFF) == MMU.DTCMRegion) |
|
| 727 |
+ return; // dtcm |
|
| 823 | 728 |
} |
| 824 | 729 |
|
| 825 |
- if(PROCNUM==ARMCPU_ARM9) |
|
| 826 |
- if((addr&(~0x3FFF)) == MMU.DTCMRegion) |
|
| 827 |
- {
|
|
| 828 |
- T1WriteWord(MMU.ARM9_DTCM, addr & 0x3FFE, val); |
|
| 730 |
+ if (PROCNUM == ARMCPU_ARM9 && (addr & ~0x3FFF) == MMU.DTCMRegion) |
|
| 731 |
+ {
|
|
| 732 |
+ T1WriteWord(MMU.ARM9_DTCM, addr & 0x3FFE, val); |
|
| 829 | 733 |
#ifdef HAVE_LUA |
| 830 |
- CallRegisteredLuaMemHook(addr, 2, val, LUAMEMHOOK_WRITE); |
|
| 734 |
+ CallRegisteredLuaMemHook(addr, 2, val, LUAMEMHOOK_WRITE); |
|
| 831 | 735 |
#endif |
| 832 |
- return; |
|
| 833 |
- } |
|
| 736 |
+ return; |
|
| 737 |
+ } |
|
| 834 | 738 |
|
| 835 |
- if ( (addr & 0x0F000000) == 0x02000000) {
|
|
| 739 |
+ if ((addr & 0x0F000000) == 0x02000000) |
|
| 740 |
+ {
|
|
| 741 |
+#ifdef HAVE_JIT |
|
| 742 |
+ JIT_COMPILED_FUNC_KNOWNBANK(addr, MAIN_MEM, _MMU_MAIN_MEM_MASK16, 0) = 0; |
|
| 743 |
+#endif |
|
| 836 | 744 |
T1WriteWord( MMU.MAIN_MEM, addr & _MMU_MAIN_MEM_MASK16, val); |
| 837 | 745 |
#ifdef HAVE_LUA |
| 838 | 746 |
CallRegisteredLuaMemHook(addr, 2, val, LUAMEMHOOK_WRITE); |
| ... | ... |
@@ -840,35 +748,41 @@ inline void _MMU_write16(const int PROCNUM, const MMU_ACCESS_TYPE AT, const uint |
| 840 | 748 |
return; |
| 841 | 749 |
} |
| 842 | 750 |
|
| 843 |
- if(PROCNUM==ARMCPU_ARM9) _MMU_ARM9_write16(addr,val); |
|
| 844 |
- else _MMU_ARM7_write16(addr,val); |
|
| 751 |
+ if (PROCNUM == ARMCPU_ARM9) |
|
| 752 |
+ _MMU_ARM9_write16(addr, val); |
|
| 753 |
+ else |
|
| 754 |
+ _MMU_ARM7_write16(addr, val); |
|
| 845 | 755 |
#ifdef HAVE_LUA |
| 846 | 756 |
CallRegisteredLuaMemHook(addr, 2, val, LUAMEMHOOK_WRITE); |
| 847 | 757 |
#endif |
| 848 | 758 |
} |
| 849 | 759 |
|
| 850 |
-inline void _MMU_write32(const int PROCNUM, const MMU_ACCESS_TYPE AT, const uint32_t addr, uint32_t val) |
|
| 760 |
+inline void _MMU_write32(int PROCNUM, MMU_ACCESS_TYPE AT, uint32_t addr, uint32_t val) |
|
| 851 | 761 |
{
|
| 852 |
- //CheckMemoryDebugEvent(DEBUG_EVENT_WRITE,AT,PROCNUM,addr,32,val); |
|
| 853 |
- |
|
| 854 |
- //special handling for DMA: discard writes to TCM |
|
| 855 |
- if(PROCNUM==ARMCPU_ARM9 && AT == MMU_AT_DMA) |
|
| 762 |
+ // special handling for DMA: discard writes to TCM |
|
| 763 |
+ if (PROCNUM == ARMCPU_ARM9 && AT == MMU_AT_DMA) |
|
| 856 | 764 |
{
|
| 857 |
- if(addr<0x02000000) return; //itcm |
|
| 858 |
- if((addr&(~0x3FFF)) == MMU.DTCMRegion) return; //dtcm |
|
| 765 |
+ if (addr < 0x02000000) |
|
| 766 |
+ return; // itcm |
|
| 767 |
+ if ((addr & ~0x3FFF) == MMU.DTCMRegion) |
|
| 768 |
+ return; // dtcm |
|
| 859 | 769 |
} |
| 860 | 770 |
|
| 861 |
- if(PROCNUM==ARMCPU_ARM9) |
|
| 862 |
- if((addr&(~0x3FFF)) == MMU.DTCMRegion) |
|
| 863 |
- {
|
|
| 864 |
- T1WriteLong(MMU.ARM9_DTCM, addr & 0x3FFC, val); |
|
| 771 |
+ if (PROCNUM == ARMCPU_ARM9 && (addr & ~0x3FFF) == MMU.DTCMRegion) |
|
| 772 |
+ {
|
|
| 773 |
+ T1WriteLong(MMU.ARM9_DTCM, addr & 0x3FFC, val); |
|
| 865 | 774 |
#ifdef HAVE_LUA |
| 866 |
- CallRegisteredLuaMemHook(addr, 4, val, LUAMEMHOOK_WRITE); |
|
| 775 |
+ CallRegisteredLuaMemHook(addr, 4, val, LUAMEMHOOK_WRITE); |
|
| 867 | 776 |
#endif |
| 868 |
- return; |
|
| 869 |
- } |
|
| 777 |
+ return; |
|
| 778 |
+ } |
|
| 870 | 779 |
|
| 871 |
- if ( (addr & 0x0F000000) == 0x02000000) {
|
|
| 780 |
+ if ((addr & 0x0F000000) == 0x02000000) |
|
| 781 |
+ {
|
|
| 782 |
+#ifdef HAVE_JIT |
|
| 783 |
+ JIT_COMPILED_FUNC_KNOWNBANK(addr, MAIN_MEM, _MMU_MAIN_MEM_MASK32, 0) = 0; |
|
| 784 |
+ JIT_COMPILED_FUNC_KNOWNBANK(addr, MAIN_MEM, _MMU_MAIN_MEM_MASK32, 1) = 0; |
|
| 785 |
+#endif |
|
| 872 | 786 |
T1WriteLong( MMU.MAIN_MEM, addr & _MMU_MAIN_MEM_MASK32, val); |
| 873 | 787 |
#ifdef HAVE_LUA |
| 874 | 788 |
CallRegisteredLuaMemHook(addr, 4, val, LUAMEMHOOK_WRITE); |
| ... | ... |
@@ -876,65 +790,27 @@ inline void _MMU_write32(const int PROCNUM, const MMU_ACCESS_TYPE AT, const uint |
| 876 | 790 |
return; |
| 877 | 791 |
} |
| 878 | 792 |
|
| 879 |
- if(PROCNUM==ARMCPU_ARM9) _MMU_ARM9_write32(addr,val); |
|
| 880 |
- else _MMU_ARM7_write32(addr,val); |
|
| 793 |
+ if (PROCNUM == ARMCPU_ARM9) |
|
| 794 |
+ _MMU_ARM9_write32(addr, val); |
|
| 795 |
+ else |
|
| 796 |
+ _MMU_ARM7_write32(addr, val); |
|
| 881 | 797 |
#ifdef HAVE_LUA |
| 882 | 798 |
CallRegisteredLuaMemHook(addr, 4, val, LUAMEMHOOK_WRITE); |
| 883 | 799 |
#endif |
| 884 | 800 |
} |
| 885 | 801 |
|
| 886 |
- |
|
| 887 |
-//#ifdef MMU_ENABLE_ACL |
|
| 888 |
-// void FASTCALL MMU_write8_acl(uint32_t proc, uint32_t adr, uint8_t val); |
|
| 889 |
-// void FASTCALL MMU_write16_acl(uint32_t proc, uint32_t adr, uint16_t val); |
|
| 890 |
-// void FASTCALL MMU_write32_acl(uint32_t proc, uint32_t adr, uint32_t val); |
|
| 891 |
-// uint8_t FASTCALL MMU_read8_acl(uint32_t proc, uint32_t adr, uint32_t access); |
|
| 892 |
-// uint16_t FASTCALL MMU_read16_acl(uint32_t proc, uint32_t adr, uint32_t access); |
|
| 893 |
-// uint32_t FASTCALL MMU_read32_acl(uint32_t proc, uint32_t adr, uint32_t access); |
|
| 894 |
-//#else |
|
| 895 |
-// #define MMU_write8_acl(proc, adr, val) _MMU_write08<proc>(adr, val) |
|
| 896 |
-// #define MMU_write16_acl(proc, adr, val) _MMU_write16<proc>(adr, val) |
|
| 897 |
-// #define MMU_write32_acl(proc, adr, val) _MMU_write32<proc>(adr, val) |
|
| 898 |
-// #define MMU_read8_acl(proc,adr,access) _MMU_read08<proc>(adr) |
|
| 899 |
-// #define MMU_read16_acl(proc,adr,access) ((access==CP15_ACCESS_EXECUTE)?_MMU_read16<proc,MMU_AT_CODE>(adr):_MMU_read16<proc,MMU_AT_DATA>(adr)) |
|
| 900 |
-// #define MMU_read32_acl(proc,adr,access) ((access==CP15_ACCESS_EXECUTE)?_MMU_read32<proc,MMU_AT_CODE>(adr):_MMU_read32<proc,MMU_AT_DATA>(adr)) |
|
| 901 |
-//#endif |
|
| 902 |
- |
|
| 903 |
-// Use this macros for reading/writing, so the GDB stub isn't broken |
|
| 904 |
-#ifdef GDB_STUB |
|
| 905 |
- #define READ32(a,b) cpu->mem_if->read32(a,(b) & 0xFFFFFFFC) |
|
| 906 |
- #define WRITE32(a,b,c) cpu->mem_if->write32(a,(b) & 0xFFFFFFFC,c) |
|
| 907 |
- #define READ16(a,b) cpu->mem_if->read16(a,(b) & 0xFFFFFFFE) |
|
| 908 |
- #define WRITE16(a,b,c) cpu->mem_if->write16(a,(b) & 0xFFFFFFFE,c) |
|
| 909 |
- #define READ8(a,b) cpu->mem_if->read8(a,b) |
|
| 910 |
- #define WRITE8(a,b,c) cpu->mem_if->write8(a,b,c) |
|
| 911 |
-#else |
|
| 912 |
- #define READ32(a,b) _MMU_read32<PROCNUM>((b) & 0xFFFFFFFC) |
|
| 913 |
- #define WRITE32(a,b,c) _MMU_write32<PROCNUM>((b) & 0xFFFFFFFC,c) |
|
| 914 |
- #define READ16(a,b) _MMU_read16<PROCNUM>((b) & 0xFFFFFFFE) |
|
| 915 |
- #define WRITE16(a,b,c) _MMU_write16<PROCNUM>((b) & 0xFFFFFFFE,c) |
|
| 916 |
- #define READ8(a,b) _MMU_read08<PROCNUM>(b) |
|
| 917 |
- #define WRITE8(a,b,c) _MMU_write08<PROCNUM>(b, c) |
|
| 918 |
-#endif |
|
| 919 |
- |
|
| 920 |
-template<int PROCNUM, MMU_ACCESS_TYPE AT> |
|
| 921 |
-inline uint8_t _MMU_read08(uint32_t addr) { return _MMU_read08(PROCNUM, AT, addr); }
|
|
| 922 |
- |
|
| 923 |
-template<int PROCNUM, MMU_ACCESS_TYPE AT> |
|
| 924 |
-inline uint16_t _MMU_read16(uint32_t addr) { return _MMU_read16(PROCNUM, AT, addr); }
|
|
| 925 |
- |
|
| 926 |
-template<int PROCNUM, MMU_ACCESS_TYPE AT> |
|
| 927 |
-inline uint32_t _MMU_read32(uint32_t addr) { return _MMU_read32(PROCNUM, AT, addr); }
|
|
| 928 |
- |
|
| 929 |
-template<int PROCNUM, MMU_ACCESS_TYPE AT> |
|
| 930 |
-inline void _MMU_write08(uint32_t addr, uint8_t val) { _MMU_write08(PROCNUM, AT, addr, val); }
|
|
| 931 |
- |
|
| 932 |
-template<int PROCNUM, MMU_ACCESS_TYPE AT> |
|
| 933 |
-inline void _MMU_write16(uint32_t addr, uint16_t val) { _MMU_write16(PROCNUM, AT, addr, val); }
|
|
| 934 |
- |
|
| 935 |
-template<int PROCNUM, MMU_ACCESS_TYPE AT> |
|
| 936 |
-inline void _MMU_write32(uint32_t addr, uint32_t val) { _MMU_write32(PROCNUM, AT, addr, val); }
|
|
| 937 |
- |
|
| 938 |
-//void FASTCALL MMU_DumpMemBlock(uint8_t proc, uint32_t address, uint32_t size, uint8_t *buffer); |
|
| 802 |
+#define READ32(a,b) _MMU_read32<PROCNUM>((b) & 0xFFFFFFFC) |
|
| 803 |
+#define WRITE32(a,b,c) _MMU_write32<PROCNUM>((b) & 0xFFFFFFFC,c) |
|
| 804 |
+#define READ16(a,b) _MMU_read16<PROCNUM>((b) & 0xFFFFFFFE) |
|
| 805 |
+#define WRITE16(a,b,c) _MMU_write16<PROCNUM>((b) & 0xFFFFFFFE,c) |
|
| 806 |
+#define READ8(a,b) _MMU_read08<PROCNUM>(b) |
|
| 807 |
+#define WRITE8(a,b,c) _MMU_write08<PROCNUM>(b, c) |
|
| 808 |
+ |
|
| 809 |
+template<int PROCNUM, MMU_ACCESS_TYPE AT> inline uint8_t _MMU_read08(uint32_t addr) { return _MMU_read08(PROCNUM, AT, addr); }
|
|
| 810 |
+template<int PROCNUM, MMU_ACCESS_TYPE AT> inline uint16_t _MMU_read16(uint32_t addr) { return _MMU_read16(PROCNUM, AT, addr); }
|
|
| 811 |
+template<int PROCNUM, MMU_ACCESS_TYPE AT> inline uint32_t _MMU_read32(uint32_t addr) { return _MMU_read32(PROCNUM, AT, addr); }
|
|
| 812 |
+template<int PROCNUM, MMU_ACCESS_TYPE AT> inline void _MMU_write08(uint32_t addr, uint8_t val) { _MMU_write08(PROCNUM, AT, addr, val); }
|
|
| 813 |
+template<int PROCNUM, MMU_ACCESS_TYPE AT> inline void _MMU_write16(uint32_t addr, uint16_t val) { _MMU_write16(PROCNUM, AT, addr, val); }
|
|
| 814 |
+template<int PROCNUM, MMU_ACCESS_TYPE AT> inline void _MMU_write32(uint32_t addr, uint32_t val) { _MMU_write32(PROCNUM, AT, addr, val); }
|
|
| 939 | 815 |
|
| 940 | 816 |
#endif |
| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,940 @@ |
| 1 |
+/* |
|
| 2 |
+ Copyright (C) 2006 yopyop |
|
| 3 |
+ Copyright (C) 2007 shash |
|
| 4 |
+ Copyright (C) 2007-2012 DeSmuME team |
|
| 5 |
+ |
|
| 6 |
+ This file is free software: you can redistribute it and/or modify |
|
| 7 |
+ it under the terms of the GNU General Public License as published by |
|
| 8 |
+ the Free Software Foundation, either version 2 of the License, or |
|
| 9 |
+ (at your option) any later version. |
|
| 10 |
+ |
|
| 11 |
+ This file is distributed in the hope that it will be useful, |
|
| 12 |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 13 |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 14 |
+ GNU General Public License for more details. |
|
| 15 |
+ |
|
| 16 |
+ You should have received a copy of the GNU General Public License |
|
| 17 |
+ along with the this software. If not, see <http://www.gnu.org/licenses/>. |
|
| 18 |
+*/ |
|
| 19 |
+ |
|
| 20 |
+#ifndef MMU_H |
|
| 21 |
+#define MMU_H |
|
| 22 |
+ |
|
| 23 |
+#include "FIFO.h" |
|
| 24 |
+#include "mem.h" |
|
| 25 |
+#include "registers.h" |
|
| 26 |
+#include "mc.h" |
|
| 27 |
+#include "bits.h" |
|
| 28 |
+#include "readwrite.h" |
|
| 29 |
+//#include "debug.h" |
|
| 30 |
+ |
|
| 31 |
+#ifdef HAVE_LUA |
|
| 32 |
+#include "lua-engine.h" |
|
| 33 |
+#endif |
|
| 34 |
+ |
|
| 35 |
+#define ARMCPU_ARM7 1 |
|
| 36 |
+#define ARMCPU_ARM9 0 |
|
| 37 |
+#define ARMPROC (PROCNUM ? NDS_ARM7:NDS_ARM9) |
|
| 38 |
+ |
|
| 39 |
+typedef const uint8_t TWaitState; |
|
| 40 |
+ |
|
| 41 |
+enum EDMAMode |
|
| 42 |
+{
|
|
| 43 |
+ EDMAMode_Immediate = 0, |
|
| 44 |
+ EDMAMode_VBlank = 1, |
|
| 45 |
+ EDMAMode_HBlank = 2, |
|
| 46 |
+ EDMAMode_HStart = 3, |
|
| 47 |
+ EDMAMode_MemDisplay = 4, |
|
| 48 |
+ EDMAMode_Card = 5, |
|
| 49 |
+ EDMAMode_GBASlot = 6, |
|
| 50 |
+ EDMAMode_GXFifo = 7, |
|
| 51 |
+ EDMAMode7_Wifi = 8, |
|
| 52 |
+ EDMAMode7_GBASlot = 9 |
|
| 53 |
+}; |
|
| 54 |
+ |
|
| 55 |
+enum EDMABitWidth |
|
| 56 |
+{
|
|
| 57 |
+ EDMABitWidth_16 = 0, |
|
| 58 |
+ EDMABitWidth_32 = 1 |
|
| 59 |
+}; |
|
| 60 |
+ |
|
| 61 |
+enum EDMASourceUpdate |
|
| 62 |
+{
|
|
| 63 |
+ EDMASourceUpdate_Increment = 0, |
|
| 64 |
+ EDMASourceUpdate_Decrement = 1, |
|
| 65 |
+ EDMASourceUpdate_Fixed = 2, |
|
| 66 |
+ EDMASourceUpdate_Invalid = 3 |
|
| 67 |
+}; |
|
| 68 |
+ |
|
| 69 |
+enum EDMADestinationUpdate |
|
| 70 |
+{
|
|
| 71 |
+ EDMADestinationUpdate_Increment = 0, |
|
| 72 |
+ EDMADestinationUpdate_Decrement = 1, |
|
| 73 |
+ EDMADestinationUpdate_Fixed = 2, |
|
| 74 |
+ EDMADestinationUpdate_IncrementReload = 3 |
|
| 75 |
+}; |
|
| 76 |
+ |
|
| 77 |
+//TODO |
|
| 78 |
+//n.b. this may be a bad idea, for complex registers like the dma control register. |
|
| 79 |
+//we need to know exactly what part was written to, instead of assuming all 32bits were written. |
|
| 80 |
+class TRegister_32 |
|
| 81 |
+{
|
|
| 82 |
+public: |
|
| 83 |
+ virtual uint32_t read32() = 0; |
|
| 84 |
+ virtual void write32(const uint32_t val) = 0; |
|
| 85 |
+ void write(const int size, const uint32_t adr, const uint32_t val) {
|
|
| 86 |
+ if(size==32) write32(val); |
|
| 87 |
+ else {
|
|
| 88 |
+ const uint32_t offset = adr&3; |
|
| 89 |
+ if(size==8) {
|
|
| 90 |
+ printf("WARNING! 8BIT DMA ACCESS\n");
|
|
| 91 |
+ uint32_t mask = 0xFF<<(offset<<3); |
|
| 92 |
+ write32((read32()&~mask)|(val<<(offset<<3))); |
|
| 93 |
+ } |
|
| 94 |
+ else if(size==16) {
|
|
| 95 |
+ uint32_t mask = 0xFFFF<<(offset<<3); |
|
| 96 |
+ write32((read32()&~mask)|(val<<(offset<<3))); |
|
| 97 |
+ } |
|
| 98 |
+ } |
|
| 99 |
+ } |
|
| 100 |
+ |
|
| 101 |
+ uint32_t read(const int size, const uint32_t adr) |
|
| 102 |
+ {
|
|
| 103 |
+ if(size==32) return read32(); |
|
| 104 |
+ else {
|
|
| 105 |
+ const uint32_t offset = adr&3; |
|
| 106 |
+ if(size==8) { printf("WARNING! 8BIT DMA ACCESS\n"); return (read32()>>(offset<<3))&0xFF; }
|
|
| 107 |
+ else return (read32()>>(offset<<3))&0xFFFF; |
|
| 108 |
+ } |
|
| 109 |
+ } |
|
| 110 |
+}; |
|
| 111 |
+ |
|
| 112 |
+struct TGXSTAT : public TRegister_32 |
|
| 113 |
+{
|
|
| 114 |
+ TGXSTAT() {
|
|
| 115 |
+ gxfifo_irq = se = tr = tb = sb = 0; |
|
| 116 |
+ fifo_empty = true; |
|
| 117 |
+ fifo_low = false; |
|
| 118 |
+ } |
|
| 119 |
+ uint8_t tb; //test busy |
|
| 120 |
+ uint8_t tr; //test result |
|
| 121 |
+ uint8_t se; //stack error |
|
| 122 |
+ uint8_t sb; //stack busy |
|
| 123 |
+ uint8_t gxfifo_irq; //irq configuration |
|
| 124 |
+ |
|
| 125 |
+ bool fifo_empty, fifo_low; |
|
| 126 |
+ |
|
| 127 |
+ virtual uint32_t read32(); |
|
| 128 |
+ virtual void write32(const uint32_t val); |
|
| 129 |
+ |
|
| 130 |
+ //void savestate(EMUFILE *f); |
|
| 131 |
+ bool loadstate(EMUFILE *f); |
|
| 132 |
+}; |
|
| 133 |
+ |
|
| 134 |
+void triggerDma(EDMAMode mode); |
|
| 135 |
+ |
|
| 136 |
+class DivController |
|
| 137 |
+{
|
|
| 138 |
+public: |
|
| 139 |
+ DivController() |
|
| 140 |
+ : mode(0), busy(0) |
|
| 141 |
+ {}
|
|
| 142 |
+ void exec(); |
|
| 143 |
+ uint8_t mode, busy, div0; |
|
| 144 |
+ uint16_t read16() { return mode|(busy<<15)|(div0<<14); }
|
|
| 145 |
+ void write16(uint16_t val) {
|
|
| 146 |
+ mode = val&3; |
|
| 147 |
+ //todo - do we clear the div0 flag here or is that strictly done by the divider unit? |
|
| 148 |
+ } |
|
| 149 |
+ /*void savestate(EMUFILE* os) |
|
| 150 |
+ {
|
|
| 151 |
+ write8le(&mode,os); |
|
| 152 |
+ write8le(&busy,os); |
|
| 153 |
+ write8le(&div0,os); |
|
| 154 |
+ }*/ |
|
| 155 |
+ bool loadstate(EMUFILE* is, int) |
|
| 156 |
+ {
|
|
| 157 |
+ int ret = 1; |
|
| 158 |
+ ret &= read8le(&mode,is); |
|
| 159 |
+ ret &= read8le(&busy,is); |
|
| 160 |
+ ret &= read8le(&div0,is); |
|
| 161 |
+ return ret==1; |
|
| 162 |
+ } |
|
| 163 |
+}; |
|
| 164 |
+ |
|
| 165 |
+class SqrtController |
|
| 166 |
+{
|
|
| 167 |
+public: |
|
| 168 |
+ SqrtController() |
|
| 169 |
+ : mode(0), busy(0) |
|
| 170 |
+ {}
|
|
| 171 |
+ void exec(); |
|
| 172 |
+ uint8_t mode, busy; |
|
| 173 |
+ uint16_t read16() { return mode|(busy<<15); }
|
|
| 174 |
+ void write16(uint16_t val) { mode = val&1; }
|
|
| 175 |
+ /*void savestate(EMUFILE* os) |
|
| 176 |
+ {
|
|
| 177 |
+ write8le(&mode,os); |
|
| 178 |
+ write8le(&busy,os); |
|
| 179 |
+ }*/ |
|
| 180 |
+ bool loadstate(EMUFILE* is, int) |
|
| 181 |
+ {
|
|
| 182 |
+ int ret=1; |
|
| 183 |
+ ret &= read8le(&mode,is); |
|
| 184 |
+ ret &= read8le(&busy,is); |
|
| 185 |
+ return ret==1; |
|
| 186 |
+ } |
|
| 187 |
+}; |
|
| 188 |
+ |
|
| 189 |
+class DmaController |
|
| 190 |
+{
|
|
| 191 |
+public: |
|
| 192 |
+ uint8_t enable, irq, repeatMode, _startmode; |
|
| 193 |
+ uint8_t userEnable; |
|
| 194 |
+ uint32_t wordcount; |
|
| 195 |
+ EDMAMode startmode; |
|
| 196 |
+ EDMABitWidth bitWidth; |
|
| 197 |
+ EDMASourceUpdate sar; |
|
| 198 |
+ EDMADestinationUpdate dar; |
|
| 199 |
+ uint32_t saddr, daddr; |
|
| 200 |
+ uint32_t saddr_user, daddr_user; |
|
| 201 |
+ |
|
| 202 |
+ //indicates whether the dma needs to be checked for triggering |
|
| 203 |
+ bool dmaCheck; |
|
| 204 |
+ |
|
| 205 |
+ //indicates whether the dma right now is logically running |
|
| 206 |
+ //(though for now we copy all the data when it triggers) |
|
| 207 |
+ bool running; |
|
| 208 |
+ |
|
| 209 |
+ bool paused; |
|
| 210 |
+ |
|
| 211 |
+ //this flag will sometimes be set when a start condition is triggered |
|
| 212 |
+ //other conditions may be automatically triggered based on scanning conditions |
|
| 213 |
+ bool triggered; |
|
| 214 |
+ |
|
| 215 |
+ uint64_t nextEvent; |
|
| 216 |
+ |
|
| 217 |
+ int procnum, chan; |
|
| 218 |
+ |
|
| 219 |
+ //void savestate(EMUFILE *f); |
|
| 220 |
+ bool loadstate(EMUFILE *f); |
|
| 221 |
+ |
|
| 222 |
+ void exec(); |
|
| 223 |
+ template<int PROCNUM> void doCopy(); |
|
| 224 |
+ void doPause(); |
|
| 225 |
+ void doStop(); |
|
| 226 |
+ void doSchedule(); |
|
| 227 |
+ void tryTrigger(EDMAMode mode); |
|
| 228 |
+ |
|
| 229 |
+ DmaController() : |
|
| 230 |
+ enable(0), irq(0), repeatMode(0), _startmode(0), |
|
| 231 |
+ wordcount(0), startmode(EDMAMode_Immediate), |
|
| 232 |
+ bitWidth(EDMABitWidth_16), |
|
| 233 |
+ sar(EDMASourceUpdate_Increment), dar(EDMADestinationUpdate_Increment), |
|
| 234 |
+ //if saddr isnt cleared then rings of fate will trigger copy protection |
|
| 235 |
+ //by inspecting dma3 saddr when it boots |
|
| 236 |
+ saddr(0), daddr(0), |
|
| 237 |
+ saddr_user(0), daddr_user(0), |
|
| 238 |
+ dmaCheck(false), |
|
| 239 |
+ running(false), |
|
| 240 |
+ paused(false), |
|
| 241 |
+ triggered(false), |
|
| 242 |
+ nextEvent(0), |
|
| 243 |
+ sad(&saddr_user), |
|
| 244 |
+ dad(&daddr_user) |
|
| 245 |
+ {
|
|
| 246 |
+ sad.controller = this; |
|
| 247 |
+ dad.controller = this; |
|
| 248 |
+ ctrl.controller = this; |
|
| 249 |
+ regs[0] = &sad; |
|
| 250 |
+ regs[1] = &dad; |
|
| 251 |
+ regs[2] = &ctrl; |
|
| 252 |
+ } |
|
| 253 |
+ |
|
| 254 |
+ class AddressRegister : public TRegister_32 {
|
|
| 255 |
+ public: |
|
| 256 |
+ //we pass in a pointer to the controller here so we can alert it if anything changes |
|
| 257 |
+ DmaController* controller; |
|
| 258 |
+ uint32_t * const ptr; |
|
| 259 |
+ AddressRegister(uint32_t* _ptr) |
|
| 260 |
+ : ptr(_ptr) |
|
| 261 |
+ {}
|
|
| 262 |
+ virtual uint32_t read32() {
|
|
| 263 |
+ return *ptr; |
|
| 264 |
+ } |
|
| 265 |
+ virtual void write32(const uint32_t val) {
|
|
| 266 |
+ *ptr = val; |
|
| 267 |
+ } |
|
| 268 |
+ }; |
|
| 269 |
+ |
|
| 270 |
+ class ControlRegister : public TRegister_32 {
|
|
| 271 |
+ public: |
|
| 272 |
+ //we pass in a pointer to the controller here so we can alert it if anything changes |
|
| 273 |
+ DmaController* controller; |
|
| 274 |
+ ControlRegister() {}
|
|
| 275 |
+ virtual uint32_t read32() {
|
|
| 276 |
+ return controller->read32(); |
|
| 277 |
+ } |
|
| 278 |
+ virtual void write32(const uint32_t val) {
|
|
| 279 |
+ return controller->write32(val); |
|
| 280 |
+ } |
|
| 281 |
+ }; |
|
| 282 |
+ |
|
| 283 |
+ AddressRegister sad, dad; |
|
| 284 |
+ ControlRegister ctrl; |
|
| 285 |
+ TRegister_32* regs[3]; |
|
| 286 |
+ |
|
| 287 |
+ void write32(const uint32_t val); |
|
| 288 |
+ uint32_t read32(); |
|
| 289 |
+ |
|
| 290 |
+}; |
|
| 291 |
+ |
|
| 292 |
+enum ECardMode |
|
| 293 |
+{
|
|
| 294 |
+ CardMode_Normal = 0, |
|
| 295 |
+ CardMode_KEY1, |
|
| 296 |
+ CardMode_KEY2 |
|
| 297 |
+}; |
|
| 298 |
+ |
|
| 299 |
+typedef struct |
|
| 300 |
+{
|
|
| 301 |
+ |
|
| 302 |
+ uint8_t command[8]; |
|
| 303 |
+ |
|
| 304 |
+ uint32_t address; |
|
| 305 |
+ uint32_t transfer_count; |
|
| 306 |
+ |
|
| 307 |
+ ECardMode mode; |
|
| 308 |
+ |
|
| 309 |
+ // NJSD stuff |
|
| 310 |
+ int blocklen; |
|
| 311 |
+ |
|
| 312 |
+} nds_dscard; |
|
| 313 |
+ |
|
| 314 |
+struct MMU_struct |
|
| 315 |
+{
|
|
| 316 |
+ //ARM9 mem |
|
| 317 |
+ uint8_t ARM9_ITCM[0x8000]; |
|
| 318 |
+ uint8_t ARM9_DTCM[0x4000]; |
|
| 319 |
+ |
|
| 320 |
+ //u8 MAIN_MEM[4*1024*1024]; //expanded from 4MB to 8MB to support debug consoles |
|
| 321 |
+ //u8 MAIN_MEM[8*1024*1024]; //expanded from 8MB to 16MB to support dsi |
|
| 322 |
+ uint8_t MAIN_MEM[16*1024*1024]; //expanded from 8MB to 16MB to support dsi |
|
| 323 |
+ uint8_t ARM9_REG[0x1000000]; |
|
| 324 |
+ uint8_t ARM9_BIOS[0x8000]; |
|
| 325 |
+ uint8_t ARM9_VMEM[0x800]; |
|
| 326 |
+ |
|
| 327 |
+ #include "PACKED.h" |
|
| 328 |
+ struct {
|
|
| 329 |
+ uint8_t ARM9_LCD[0xA4000]; |
|
| 330 |
+ //an extra 128KB for blank memory, directly after arm9_lcd, so that |
|
| 331 |
+ //we can easily map things to the end of arm9_lcd to represent |
|
| 332 |
+ //an unmapped state |
|
| 333 |
+ uint8_t blank_memory[0x20000]; |
|
| 334 |
+ }; |
|
| 335 |
+ #include "PACKED_END.h" |
|
| 336 |
+ |
|
| 337 |
+ uint8_t ARM9_OAM[0x800]; |
|
| 338 |
+ |
|
| 339 |
+ uint8_t* ExtPal[2][4]; |
|
| 340 |
+ uint8_t* ObjExtPal[2][2]; |
|
| 341 |
+ |
|
| 342 |
+ struct TextureInfo {
|
|
| 343 |
+ uint8_t* texPalSlot[6]; |
|
| 344 |
+ uint8_t* textureSlotAddr[4]; |
|
| 345 |
+ } texInfo; |
|
| 346 |
+ |
|
| 347 |
+ //ARM7 mem |
|
| 348 |
+ uint8_t ARM7_BIOS[0x4000]; |
|
| 349 |
+ uint8_t ARM7_ERAM[0x10000]; |
|
| 350 |
+ uint8_t ARM7_REG[0x10000]; |
|
| 351 |
+ uint8_t ARM7_WIRAM[0x10000]; |
|
| 352 |
+ |
|
| 353 |
+ // VRAM mapping |
|
| 354 |
+ uint8_t VRAM_MAP[4][32]; |
|
| 355 |
+ uint32_t LCD_VRAM_ADDR[10]; |
|
| 356 |
+ uint8_t LCDCenable[10]; |
|
| 357 |
+ |
|
| 358 |
+ //Shared ram |
|
| 359 |
+ uint8_t SWIRAM[0x8000]; |
|
| 360 |
+ |
|
| 361 |
+ //Card rom & ram |
|
| 362 |
+ uint8_t * CART_ROM; |
|
| 363 |
+ |
|
| 364 |
+ //Unused ram |
|
| 365 |
+ uint8_t UNUSED_RAM[4]; |
|
| 366 |
+ |
|
| 367 |
+ //this is here so that we can trap glitchy emulator code |
|
| 368 |
+ //which is accessing offsets 5,6,7 of unused ram due to unaligned accesses |
|
| 369 |
+ //(also since the emulator doesn't prevent unaligned accesses) |
|
| 370 |
+ uint8_t MORE_UNUSED_RAM[4]; |
|
| 371 |
+ |
|
| 372 |
+ static uint8_t * MMU_MEM[2][256]; |
|
| 373 |
+ static uint32_t MMU_MASK[2][256]; |
|
| 374 |
+ |
|
| 375 |
+ uint8_t ARM9_RW_MODE; |
|
| 376 |
+ |
|
| 377 |
+ uint32_t DTCMRegion; |
|
| 378 |
+ uint32_t ITCMRegion; |
|
| 379 |
+ |
|
| 380 |
+ uint16_t timer[2][4]; |
|
| 381 |
+ int32_t timerMODE[2][4]; |
|
| 382 |
+ uint32_t timerON[2][4]; |
|
| 383 |
+ uint32_t timerRUN[2][4]; |
|
| 384 |
+ uint16_t timerReload[2][4]; |
|
| 385 |
+ |
|
| 386 |
+ uint32_t reg_IME[2]; |
|
| 387 |
+ uint32_t reg_IE[2]; |
|
| 388 |
+ |
|
| 389 |
+ //these are the user-controlled IF bits. some IF bits are generated as necessary from hardware conditions |
|
| 390 |
+ uint32_t reg_IF_bits[2]; |
|
| 391 |
+ //these flags are set occasionally to indicate that an irq should have entered the pipeline, and processing will be deferred a tiny bit to help emulate things |
|
| 392 |
+ uint32_t reg_IF_pending[2]; |
|
| 393 |
+ |
|
| 394 |
+ //uint32_t reg_DISP3DCNT_bits; |
|
| 395 |
+ |
|
| 396 |
+ template<int PROCNUM> uint32_t gen_IF(); |
|
| 397 |
+ |
|
| 398 |
+ bool divRunning; |
|
| 399 |
+ int64_t divResult; |
|
| 400 |
+ int64_t divMod; |
|
| 401 |
+ uint64_t divCycles; |
|
| 402 |
+ |
|
| 403 |
+ bool sqrtRunning; |
|
| 404 |
+ uint32_t sqrtResult; |
|
| 405 |
+ uint64_t sqrtCycles; |
|
| 406 |
+ |
|
| 407 |
+ uint16_t SPI_CNT; |
|
| 408 |
+ uint16_t SPI_CMD; |
|
| 409 |
+ uint16_t AUX_SPI_CNT; |
|
| 410 |
+ uint16_t AUX_SPI_CMD; |
|
| 411 |
+ |
|
| 412 |
+ //uint64_t gfx3dCycles; |
|
| 413 |
+ |
|
| 414 |
+ uint8_t powerMan_CntReg; |
|
| 415 |
+ bool powerMan_CntRegWritten; |
|
| 416 |
+ uint8_t powerMan_Reg[5]; |
|
| 417 |
+ |
|
| 418 |
+ memory_chip_t fw; |
|
| 419 |
+ |
|
| 420 |
+ nds_dscard dscard[2]; |
|
| 421 |
+}; |
|
| 422 |
+ |
|
| 423 |
+//everything in here is derived from libnds behaviours. no hardware tests yet |
|
| 424 |
+class DSI_TSC |
|
| 425 |
+{
|
|
| 426 |
+public: |
|
| 427 |
+ DSI_TSC(); |
|
| 428 |
+ void reset_command(); |
|
| 429 |
+ uint16_t write16(uint16_t val); |
|
| 430 |
+ //bool save_state(EMUFILE* os); |
|
| 431 |
+ //bool load_state(EMUFILE* is); |
|
| 432 |
+ |
|
| 433 |
+private: |
|
| 434 |
+ uint16_t read16(); |
|
| 435 |
+ uint8_t reg_selection; |
|
| 436 |
+ uint8_t read_flag; |
|
| 437 |
+ int32_t state; |
|
| 438 |
+ int32_t readcount; |
|
| 439 |
+ |
|
| 440 |
+ //registers[0] contains the current page. |
|
| 441 |
+ //we are going to go ahead and save these out in case we want to change the way this is emulated in the future.. |
|
| 442 |
+ //we may want to poke registers in here at more convenient times and have the TSC dumbly pluck them out, |
|
| 443 |
+ //rather than generate the values on the fly |
|
| 444 |
+ uint8_t registers[0x80]; |
|
| 445 |
+}; |
|
| 446 |
+ |
|
| 447 |
+//this contains things which can't be memzeroed because they are smarter classes |
|
| 448 |
+struct MMU_struct_new |
|
| 449 |
+{
|
|
| 450 |
+ MMU_struct_new() ; |
|
| 451 |
+ BackupDevice backupDevice; |
|
| 452 |
+ DmaController dma[2][4]; |
|
| 453 |
+ TGXSTAT gxstat; |
|
| 454 |
+ SqrtController sqrt; |
|
| 455 |
+ DivController div; |
|
| 456 |
+ DSI_TSC dsi_tsc; |
|
| 457 |
+ |
|
| 458 |
+ void write_dma(const int proc, const int size, const uint32_t adr, const uint32_t val); |
|
| 459 |
+ uint32_t read_dma(const int proc, const int size, const uint32_t adr); |
|
| 460 |
+ bool is_dma(const uint32_t adr) { return adr >= _REG_DMA_CONTROL_MIN && adr <= _REG_DMA_CONTROL_MAX; }
|
|
| 461 |
+}; |
|
| 462 |
+ |
|
| 463 |
+extern MMU_struct MMU; |
|
| 464 |
+extern MMU_struct_new MMU_new; |
|
| 465 |
+ |
|
| 466 |
+ |
|
| 467 |
+/*struct armcpu_memory_iface {*/
|
|
| 468 |
+ /** the 32 bit instruction prefetch */ |
|
| 469 |
+ //uint32_t FASTCALL (*prefetch32)( void *data, uint32_t adr); |
|
| 470 |
+ |
|
| 471 |
+ /** the 16 bit instruction prefetch */ |
|
| 472 |
+ //uint16_t FASTCALL (*prefetch16)( void *data, uint32_t adr); |
|
| 473 |
+ |
|
| 474 |
+ /** read 8 bit data value */ |
|
| 475 |
+ //uint8_t FASTCALL (*read8)( void *data, uint32_t adr); |
|
| 476 |
+ /** read 16 bit data value */ |
|
| 477 |
+ //uint16_t FASTCALL (*read16)( void *data, uint32_t adr); |
|
| 478 |
+ /** read 32 bit data value */ |
|
| 479 |
+ //uint32_t FASTCALL (*read32)( void *data, uint32_t adr); |
|
| 480 |
+ |
|
| 481 |
+ /** write 8 bit data value */ |
|
| 482 |
+ //void FASTCALL (*write8)( void *data, uint32_t adr, uint8_t val); |
|
| 483 |
+ /** write 16 bit data value */ |
|
| 484 |
+ //void FASTCALL (*write16)( void *data, uint32_t adr, uint16_t val); |
|
| 485 |
+ /** write 32 bit data value */ |
|
| 486 |
+ /*void FASTCALL (*write32)( void *data, uint32_t adr, uint32_t val); |
|
| 487 |
+ |
|
| 488 |
+ void *data; |
|
| 489 |
+};*/ |
|
| 490 |
+ |
|
| 491 |
+ |
|
| 492 |
+void MMU_Init(); |
|
| 493 |
+void MMU_DeInit(); |
|
| 494 |
+ |
|
| 495 |
+void MMU_Reset(); |
|
| 496 |
+ |
|
| 497 |
+void MMU_setRom(uint8_t * rom, uint32_t mask); |
|
| 498 |
+void MMU_unsetRom(); |
|
| 499 |
+ |
|
| 500 |
+//void print_memory_profiling(); |
|
| 501 |
+ |
|
| 502 |
+// Memory reading/writing (old) |
|
| 503 |
+//uint8_t FASTCALL MMU_read8(uint32_t proc, uint32_t adr); |
|
| 504 |
+//uint16_t FASTCALL MMU_read16(uint32_t proc, uint32_t adr); |
|
| 505 |
+//uint32_t FASTCALL MMU_read32(uint32_t proc, uint32_t adr); |
|
| 506 |
+//void FASTCALL MMU_write8(uint32_t proc, uint32_t adr, uint8_t val); |
|
| 507 |
+//void FASTCALL MMU_write16(uint32_t proc, uint32_t adr, uint16_t val); |
|
| 508 |
+//void FASTCALL MMU_write32(uint32_t proc, uint32_t adr, uint32_t val); |
|
| 509 |
+ |
|
| 510 |
+//template<int PROCNUM> void FASTCALL MMU_doDMA(uint32_t num); |
|
| 511 |
+ |
|
| 512 |
+//The base ARM memory interfaces |
|
| 513 |
+//extern struct armcpu_memory_iface arm9_base_memory_iface; |
|
| 514 |
+//extern struct armcpu_memory_iface arm7_base_memory_iface; |
|
| 515 |
+//extern struct armcpu_memory_iface arm9_direct_memory_iface; |
|
| 516 |
+ |
|
| 517 |
+#define VRAM_BANKS 9 |
|
| 518 |
+#define VRAM_BANK_A 0 |
|
| 519 |
+#define VRAM_BANK_B 1 |
|
| 520 |
+#define VRAM_BANK_C 2 |
|
| 521 |
+#define VRAM_BANK_D 3 |
|
| 522 |
+#define VRAM_BANK_E 4 |
|
| 523 |
+#define VRAM_BANK_F 5 |
|
| 524 |
+#define VRAM_BANK_G 6 |
|
| 525 |
+#define VRAM_BANK_H 7 |
|
| 526 |
+#define VRAM_BANK_I 8 |
|
| 527 |
+ |
|
| 528 |
+#define VRAM_PAGE_ABG 0 |
|
| 529 |
+#define VRAM_PAGE_BBG 128 |
|
| 530 |
+#define VRAM_PAGE_AOBJ 256 |
|
| 531 |
+#define VRAM_PAGE_BOBJ 384 |
|
| 532 |
+ |
|
| 533 |
+ |
|
| 534 |
+struct VramConfiguration {
|
|
| 535 |
+ |
|
| 536 |
+ enum Purpose {
|
|
| 537 |
+ OFF, INVALID, ABG, BBG, AOBJ, BOBJ, LCDC, ARM7, TEX, TEXPAL, ABGEXTPAL, BBGEXTPAL, AOBJEXTPAL, BOBJEXTPAL |
|
| 538 |
+ }; |
|
| 539 |
+ |
|
| 540 |
+ struct BankInfo {
|
|
| 541 |
+ Purpose purpose; |
|
| 542 |
+ int ofs; |
|
| 543 |
+ } banks[VRAM_BANKS]; |
|
| 544 |
+ |
|
| 545 |
+ inline void clear() {
|
|
| 546 |
+ for(int i=0;i<VRAM_BANKS;i++) {
|
|
| 547 |
+ banks[i].ofs = 0; |
|
| 548 |
+ banks[i].purpose = OFF; |
|
| 549 |
+ } |
|
| 550 |
+ } |
|
| 551 |
+ |
|
| 552 |
+ //std::string describePurpose(Purpose p); |
|
| 553 |
+ //std::string describe(); |
|
| 554 |
+}; |
|
| 555 |
+ |
|
| 556 |
+extern VramConfiguration vramConfiguration; |
|
| 557 |
+ |
|
| 558 |
+#define VRAM_ARM9_PAGES 512 |
|
| 559 |
+extern uint8_t vram_arm9_map[VRAM_ARM9_PAGES]; |
|
| 560 |
+/*inline void* MMU_gpu_map(uint32_t vram_addr) |
|
| 561 |
+{
|
|
| 562 |
+ //this is supposed to map a single gpu vram address to emulator host memory |
|
| 563 |
+ //but it returns a pointer to some zero memory in case of accesses to unmapped memory. |
|
| 564 |
+ //this correctly handles the case with tile accesses to unmapped memory. |
|
| 565 |
+ //it could also potentially go through a different LUT than vram_arm9_map in case we discover |
|
| 566 |
+ //that it needs to be set up with different or no mirroring |
|
| 567 |
+ //(I think it is a reasonable possibility that only the cpu has the nutty mirroring rules) |
|
| 568 |
+ // |
|
| 569 |
+ //if this system isn't used, Fantasy Aquarium displays garbage in the first ingame screen |
|
| 570 |
+ //due to it storing 0x0F0F or somesuch in screen memory which points to a ridiculously big tile |
|
| 571 |
+ //which should contain all 0 pixels |
|
| 572 |
+ |
|
| 573 |
+ uint32_t vram_page = (vram_addr>>14)&(VRAM_ARM9_PAGES-1); |
|
| 574 |
+ uint32_t ofs = vram_addr & 0x3FFF; |
|
| 575 |
+ vram_page = vram_arm9_map[vram_page]; |
|
| 576 |
+ //blank pages are handled by the extra 16KB of blank memory at the end of ARM9_LCD |
|
| 577 |
+ //and the fact that blank pages are mapped to appear at that location |
|
| 578 |
+ return MMU.ARM9_LCD + (vram_page<<14) + ofs; |
|
| 579 |
+}*/ |
|
| 580 |
+ |
|
| 581 |
+ |
|
| 582 |
+template<int PROCNUM, MMU_ACCESS_TYPE AT> uint8_t _MMU_read08(uint32_t addr); |
|
| 583 |
+template<int PROCNUM, MMU_ACCESS_TYPE AT> uint16_t _MMU_read16(uint32_t addr); |
|
| 584 |
+template<int PROCNUM, MMU_ACCESS_TYPE AT> uint32_t _MMU_read32(uint32_t addr); |
|
| 585 |
+template<int PROCNUM, MMU_ACCESS_TYPE AT> void _MMU_write08(uint32_t addr, uint8_t val); |
|
| 586 |
+template<int PROCNUM, MMU_ACCESS_TYPE AT> void _MMU_write16(uint32_t addr, uint16_t val); |
|
| 587 |
+template<int PROCNUM, MMU_ACCESS_TYPE AT> void _MMU_write32(uint32_t addr, uint32_t val); |
|
| 588 |
+ |
|
| 589 |
+template<int PROCNUM> inline uint8_t _MMU_read08(uint32_t addr) { return _MMU_read08<PROCNUM, MMU_AT_DATA>(addr); }
|
|
| 590 |
+template<int PROCNUM> inline uint16_t _MMU_read16(uint32_t addr) { return _MMU_read16<PROCNUM, MMU_AT_DATA>(addr); }
|
|
| 591 |
+template<int PROCNUM> inline uint32_t _MMU_read32(uint32_t addr) { return _MMU_read32<PROCNUM, MMU_AT_DATA>(addr); }
|
|
| 592 |
+template<int PROCNUM> inline void _MMU_write08(uint32_t addr, uint8_t val) { _MMU_write08<PROCNUM, MMU_AT_DATA>(addr,val); }
|
|
| 593 |
+template<int PROCNUM> inline void _MMU_write16(uint32_t addr, uint16_t val) { _MMU_write16<PROCNUM, MMU_AT_DATA>(addr,val); }
|
|
| 594 |
+template<int PROCNUM> inline void _MMU_write32(uint32_t addr, uint32_t val) { _MMU_write32<PROCNUM, MMU_AT_DATA>(addr,val); }
|
|
| 595 |
+ |
|
| 596 |
+void FASTCALL _MMU_ARM9_write08(uint32_t adr, uint8_t val); |
|
| 597 |
+void FASTCALL _MMU_ARM9_write16(uint32_t adr, uint16_t val); |
|
| 598 |
+void FASTCALL _MMU_ARM9_write32(uint32_t adr, uint32_t val); |
|
| 599 |
+uint8_t FASTCALL _MMU_ARM9_read08(uint32_t adr); |
|
| 600 |
+uint16_t FASTCALL _MMU_ARM9_read16(uint32_t adr); |
|
| 601 |
+uint32_t FASTCALL _MMU_ARM9_read32(uint32_t adr); |
|
| 602 |
+ |
|
| 603 |
+void FASTCALL _MMU_ARM7_write08(uint32_t adr, uint8_t val); |
|
| 604 |
+void FASTCALL _MMU_ARM7_write16(uint32_t adr, uint16_t val); |
|
| 605 |
+void FASTCALL _MMU_ARM7_write32(uint32_t adr, uint32_t val); |
|
| 606 |
+uint8_t FASTCALL _MMU_ARM7_read08(uint32_t adr); |
|
| 607 |
+uint16_t FASTCALL _MMU_ARM7_read16(uint32_t adr); |
|
| 608 |
+uint32_t FASTCALL _MMU_ARM7_read32(uint32_t adr); |
|
| 609 |
+ |
|
| 610 |
+extern uint32_t partie; |
|
| 611 |
+ |
|
| 612 |
+extern uint32_t _MMU_MAIN_MEM_MASK; |
|
| 613 |
+extern uint32_t _MMU_MAIN_MEM_MASK16; |
|
| 614 |
+extern uint32_t _MMU_MAIN_MEM_MASK32; |
|
| 615 |
+/*inline void SetupMMU(bool debugConsole) {
|
|
| 616 |
+ if(debugConsole) _MMU_MAIN_MEM_MASK = 0x7FFFFF; |
|
| 617 |
+ else _MMU_MAIN_MEM_MASK = 0x3FFFFF; |
|
| 618 |
+ _MMU_MAIN_MEM_MASK16 = _MMU_MAIN_MEM_MASK & ~1; |
|
| 619 |
+ _MMU_MAIN_MEM_MASK32 = _MMU_MAIN_MEM_MASK & ~3; |
|
| 620 |
+}*/ |
|
| 621 |
+void SetupMMU(bool debugConsole, bool dsi); |
|
| 622 |
+ |
|
| 623 |
+/*inline void CheckMemoryDebugEvent(EDEBUG_EVENT event, const MMU_ACCESS_TYPE type, const uint32_t procnum, const uint32_t addr, const uint32_t size, const uint32_t val) |
|
| 624 |
+{
|
|
| 625 |
+ //TODO - ugh work out a better prefetch event system |
|
| 626 |
+ if(type == MMU_AT_CODE && event == DEBUG_EVENT_READ) |
|
| 627 |
+ event = DEBUG_EVENT_EXECUTE; |
|
| 628 |
+ if(CheckDebugEvent(event)) |
|
| 629 |
+ {
|
|
| 630 |
+ DebugEventData.memAccessType = type; |
|
| 631 |
+ DebugEventData.procnum = procnum; |
|
| 632 |
+ DebugEventData.addr = addr; |
|
| 633 |
+ DebugEventData.size = size; |
|
| 634 |
+ DebugEventData.val = val; |
|
| 635 |
+ HandleDebugEvent(event); |
|
| 636 |
+ } |
|
| 637 |
+}*/ |
|
| 638 |
+ |
|
| 639 |
+ |
|
| 640 |
+//ALERT!!!!!!!!!!!!!! |
|
| 641 |
+//the following inline functions dont do the 0x0FFFFFFF mask. |
|
| 642 |
+//this may result in some unexpected behavior |
|
| 643 |
+ |
|
| 644 |
+inline uint8_t _MMU_read08(const int PROCNUM, const MMU_ACCESS_TYPE AT, const uint32_t addr) |
|
| 645 |
+{
|
|
| 646 |
+ //CheckMemoryDebugEvent(DEBUG_EVENT_READ,AT,PROCNUM,addr,8,0); |
|
| 647 |
+ |
|
| 648 |
+ //special handling for DMA: read 0 from TCM |
|
| 649 |
+ if(PROCNUM==ARMCPU_ARM9 && AT == MMU_AT_DMA) |
|
| 650 |
+ {
|
|
| 651 |
+ if(addr<0x02000000) return 0; //itcm |
|
| 652 |
+ if((addr&(~0x3FFF)) == MMU.DTCMRegion) return 0; //dtcm |
|
| 653 |
+ } |
|
| 654 |
+ |
|
| 655 |
+#ifdef HAVE_LUA |
|
| 656 |
+ CallRegisteredLuaMemHook(addr, 1, /*FIXME*/ 0, LUAMEMHOOK_READ); |
|
| 657 |
+#endif |
|
| 658 |
+ |
|
| 659 |
+ if(PROCNUM==ARMCPU_ARM9) |
|
| 660 |
+ if((addr&(~0x3FFF)) == MMU.DTCMRegion) |
|
| 661 |
+ {
|
|
| 662 |
+ //Returns data from DTCM (ARM9 only) |
|
| 663 |
+ return T1ReadByte(MMU.ARM9_DTCM, addr & 0x3FFF); |
|
| 664 |
+ } |
|
| 665 |
+ |
|
| 666 |
+ if ( (addr & 0x0F000000) == 0x02000000) |
|
| 667 |
+ return T1ReadByte( MMU.MAIN_MEM, addr & _MMU_MAIN_MEM_MASK); |
|
| 668 |
+ |
|
| 669 |
+ if(PROCNUM==ARMCPU_ARM9) return _MMU_ARM9_read08(addr); |
|
| 670 |
+ else return _MMU_ARM7_read08(addr); |
|
| 671 |
+} |
|
| 672 |
+ |
|
| 673 |
+inline uint16_t _MMU_read16(const int PROCNUM, const MMU_ACCESS_TYPE AT, const uint32_t addr) |
|
| 674 |
+{
|
|
| 675 |
+ //CheckMemoryDebugEvent(DEBUG_EVENT_READ,AT,PROCNUM,addr,16,0); |
|
| 676 |
+ |
|
| 677 |
+ //special handling for DMA: read 0 from TCM |
|
| 678 |
+ if(PROCNUM==ARMCPU_ARM9 && AT == MMU_AT_DMA) |
|
| 679 |
+ {
|
|
| 680 |
+ if(addr<0x02000000) return 0; //itcm |
|
| 681 |
+ if((addr&(~0x3FFF)) == MMU.DTCMRegion) return 0; //dtcm |
|
| 682 |
+ } |
|
| 683 |
+ |
|
| 684 |
+#ifdef HAVE_LUA |
|
| 685 |
+ CallRegisteredLuaMemHook(addr, 2, /*FIXME*/ 0, LUAMEMHOOK_READ); |
|
| 686 |
+#endif |
|
| 687 |
+ |
|
| 688 |
+ //special handling for execution from arm9, since we spend so much time in there |
|
| 689 |
+ if(PROCNUM==ARMCPU_ARM9 && AT == MMU_AT_CODE) |
|
| 690 |
+ {
|
|
| 691 |
+ if ((addr & 0x0F000000) == 0x02000000) |
|
| 692 |
+ return T1ReadWord_guaranteedAligned( MMU.MAIN_MEM, addr & _MMU_MAIN_MEM_MASK16); |
|
| 693 |
+ |
|
| 694 |
+ if(addr<0x02000000) |
|
| 695 |
+ return T1ReadWord_guaranteedAligned(MMU.ARM9_ITCM, addr&0x7FFE); |
|
| 696 |
+ |
|
| 697 |
+ goto dunno; |
|
| 698 |
+ } |
|
| 699 |
+ |
|
| 700 |
+ if(PROCNUM==ARMCPU_ARM9) |
|
| 701 |
+ if((addr&(~0x3FFF)) == MMU.DTCMRegion) |
|
| 702 |
+ {
|
|
| 703 |
+ //Returns data from DTCM (ARM9 only) |
|
| 704 |
+ return T1ReadWord_guaranteedAligned(MMU.ARM9_DTCM, addr & 0x3FFE); |
|
| 705 |
+ } |
|
| 706 |
+ |
|
| 707 |
+ if ( (addr & 0x0F000000) == 0x02000000) |
|
| 708 |
+ return T1ReadWord_guaranteedAligned( MMU.MAIN_MEM, addr & _MMU_MAIN_MEM_MASK16); |
|
| 709 |
+ |
|
| 710 |
+dunno: |
|
| 711 |
+ if(PROCNUM==ARMCPU_ARM9) return _MMU_ARM9_read16(addr); |
|
| 712 |
+ else return _MMU_ARM7_read16(addr); |
|
| 713 |
+} |
|
| 714 |
+ |
|
| 715 |
+inline uint32_t _MMU_read32(const int PROCNUM, const MMU_ACCESS_TYPE AT, const uint32_t addr) |
|
| 716 |
+{
|
|
| 717 |
+ //CheckMemoryDebugEvent(DEBUG_EVENT_READ,AT,PROCNUM,addr,32,0); |
|
| 718 |
+ |
|
| 719 |
+ //special handling for DMA: read 0 from TCM |
|
| 720 |
+ if(PROCNUM==ARMCPU_ARM9 && AT == MMU_AT_DMA) |
|
| 721 |
+ {
|
|
| 722 |
+ if(addr<0x02000000) return 0; //itcm |
|
| 723 |
+ if((addr&(~0x3FFF)) == MMU.DTCMRegion) return 0; //dtcm |
|
| 724 |
+ } |
|
| 725 |
+ |
|
| 726 |
+#ifdef HAVE_LUA |
|
| 727 |
+ CallRegisteredLuaMemHook(addr, 4, /*FIXME*/ 0, LUAMEMHOOK_READ); |
|
| 728 |
+#endif |
|
| 729 |
+ |
|
| 730 |
+ //special handling for execution from arm9, since we spend so much time in there |
|
| 731 |
+ if(PROCNUM==ARMCPU_ARM9 && AT == MMU_AT_CODE) |
|
| 732 |
+ {
|
|
| 733 |
+ if ( (addr & 0x0F000000) == 0x02000000) |
|
| 734 |
+ return T1ReadLong_guaranteedAligned( MMU.MAIN_MEM, addr & _MMU_MAIN_MEM_MASK32); |
|
| 735 |
+ |
|
| 736 |
+ if(addr<0x02000000) |
|
| 737 |
+ return T1ReadLong_guaranteedAligned(MMU.ARM9_ITCM, addr&0x7FFC); |
|
| 738 |
+ |
|
| 739 |
+ //what happens when we execute from DTCM? nocash makes it look like we get 0xFFFFFFFF but i can't seem to verify it |
|
| 740 |
+ //historically, desmume would fall through to its old memory map struct |
|
| 741 |
+ //which would return unused memory (0) |
|
| 742 |
+ //it seems the hardware returns 0 or something benign because in actuality 0xFFFFFFFF is an undefined opcode |
|
| 743 |
+ //and we know our handling for that is solid |
|
| 744 |
+ |
|
| 745 |
+ goto dunno; |
|
| 746 |
+ } |
|
| 747 |
+ |
|
| 748 |
+ //special handling for execution from arm7. try reading from main memory first |
|
| 749 |
+ if(PROCNUM==ARMCPU_ARM7) |
|
| 750 |
+ {
|
|
| 751 |
+ if ( (addr & 0x0F000000) == 0x02000000) |
|
| 752 |
+ return T1ReadLong_guaranteedAligned( MMU.MAIN_MEM, addr & _MMU_MAIN_MEM_MASK32); |
|
| 753 |
+ else if((addr & 0xFF800000) == 0x03800000) |
|
| 754 |
+ return T1ReadLong_guaranteedAligned(MMU.ARM7_ERAM, addr&0xFFFC); |
|
| 755 |
+ else if((addr & 0xFF800000) == 0x03000000) |
|
| 756 |
+ return T1ReadLong_guaranteedAligned(MMU.SWIRAM, addr&0x7FFC); |
|
| 757 |
+ } |
|
| 758 |
+ |
|
| 759 |
+ |
|
| 760 |
+ //for other arm9 cases, we have to check from dtcm first because it is patched on top of the main memory range |
|
| 761 |
+ if(PROCNUM==ARMCPU_ARM9) |
|
| 762 |
+ {
|
|
| 763 |
+ if((addr&(~0x3FFF)) == MMU.DTCMRegion) |
|
| 764 |
+ {
|
|
| 765 |
+ //Returns data from DTCM (ARM9 only) |
|
| 766 |
+ return T1ReadLong_guaranteedAligned(MMU.ARM9_DTCM, addr & 0x3FFC); |
|
| 767 |
+ } |
|
| 768 |
+ |
|
| 769 |
+ if ( (addr & 0x0F000000) == 0x02000000) |
|
| 770 |
+ return T1ReadLong_guaranteedAligned( MMU.MAIN_MEM, addr & _MMU_MAIN_MEM_MASK32); |
|
| 771 |
+ } |
|
| 772 |
+ |
|
| 773 |
+dunno: |
|
| 774 |
+ if(PROCNUM==ARMCPU_ARM9) return _MMU_ARM9_read32(addr); |
|
| 775 |
+ else return _MMU_ARM7_read32(addr); |
|
| 776 |
+} |
|
| 777 |
+ |
|
| 778 |
+inline void _MMU_write08(const int PROCNUM, const MMU_ACCESS_TYPE AT, const uint32_t addr, uint8_t val) |
|
| 779 |
+{
|
|
| 780 |
+ //CheckMemoryDebugEvent(DEBUG_EVENT_WRITE,AT,PROCNUM,addr,8,val); |
|
| 781 |
+ |
|
| 782 |
+ //special handling for DMA: discard writes to TCM |
|
| 783 |
+ if(PROCNUM==ARMCPU_ARM9 && AT == MMU_AT_DMA) |
|
| 784 |
+ {
|
|
| 785 |
+ if(addr<0x02000000) return; //itcm |
|
| 786 |
+ if((addr&(~0x3FFF)) == MMU.DTCMRegion) return; //dtcm |
|
| 787 |
+ } |
|
| 788 |
+ |
|
| 789 |
+ if(PROCNUM==ARMCPU_ARM9) |
|
| 790 |
+ if((addr&(~0x3FFF)) == MMU.DTCMRegion) |
|
| 791 |
+ {
|
|
| 792 |
+ T1WriteByte(MMU.ARM9_DTCM, addr & 0x3FFF, val); |
|
| 793 |
+#ifdef HAVE_LUA |
|
| 794 |
+ CallRegisteredLuaMemHook(addr, 1, val, LUAMEMHOOK_WRITE); |
|
| 795 |
+#endif |
|
| 796 |
+ return; |
|
| 797 |
+ } |
|
| 798 |
+ |
|
| 799 |
+ if ( (addr & 0x0F000000) == 0x02000000) {
|
|
| 800 |
+ T1WriteByte( MMU.MAIN_MEM, addr & _MMU_MAIN_MEM_MASK, val); |
|
| 801 |
+#ifdef HAVE_LUA |
|
| 802 |
+ CallRegisteredLuaMemHook(addr, 1, val, LUAMEMHOOK_WRITE); |
|
| 803 |
+#endif |
|
| 804 |
+ return; |
|
| 805 |
+ } |
|
| 806 |
+ |
|
| 807 |
+ if(PROCNUM==ARMCPU_ARM9) _MMU_ARM9_write08(addr,val); |
|
| 808 |
+ else _MMU_ARM7_write08(addr,val); |
|
| 809 |
+#ifdef HAVE_LUA |
|
| 810 |
+ CallRegisteredLuaMemHook(addr, 1, val, LUAMEMHOOK_WRITE); |
|
| 811 |
+#endif |
|
| 812 |
+} |
|
| 813 |
+ |
|
| 814 |
+inline void _MMU_write16(const int PROCNUM, const MMU_ACCESS_TYPE AT, const uint32_t addr, uint16_t val) |
|
| 815 |
+{
|
|
| 816 |
+ //CheckMemoryDebugEvent(DEBUG_EVENT_WRITE,AT,PROCNUM,addr,16,val); |
|
| 817 |
+ |
|
| 818 |
+ //special handling for DMA: discard writes to TCM |
|
| 819 |
+ if(PROCNUM==ARMCPU_ARM9 && AT == MMU_AT_DMA) |
|
| 820 |
+ {
|
|
| 821 |
+ if(addr<0x02000000) return; //itcm |
|
| 822 |
+ if((addr&(~0x3FFF)) == MMU.DTCMRegion) return; //dtcm |
|
| 823 |
+ } |
|
| 824 |
+ |
|
| 825 |
+ if(PROCNUM==ARMCPU_ARM9) |
|
| 826 |
+ if((addr&(~0x3FFF)) == MMU.DTCMRegion) |
|
| 827 |
+ {
|
|
| 828 |
+ T1WriteWord(MMU.ARM9_DTCM, addr & 0x3FFE, val); |
|
| 829 |
+#ifdef HAVE_LUA |
|
| 830 |
+ CallRegisteredLuaMemHook(addr, 2, val, LUAMEMHOOK_WRITE); |
|
| 831 |
+#endif |
|
| 832 |
+ return; |
|
| 833 |
+ } |
|
| 834 |
+ |
|
| 835 |
+ if ( (addr & 0x0F000000) == 0x02000000) {
|
|
| 836 |
+ T1WriteWord( MMU.MAIN_MEM, addr & _MMU_MAIN_MEM_MASK16, val); |
|
| 837 |
+#ifdef HAVE_LUA |
|
| 838 |
+ CallRegisteredLuaMemHook(addr, 2, val, LUAMEMHOOK_WRITE); |
|
| 839 |
+#endif |
|
| 840 |
+ return; |
|
| 841 |
+ } |
|
| 842 |
+ |
|
| 843 |
+ if(PROCNUM==ARMCPU_ARM9) _MMU_ARM9_write16(addr,val); |
|
| 844 |
+ else _MMU_ARM7_write16(addr,val); |
|
| 845 |
+#ifdef HAVE_LUA |
|
| 846 |
+ CallRegisteredLuaMemHook(addr, 2, val, LUAMEMHOOK_WRITE); |
|
| 847 |
+#endif |
|
| 848 |
+} |
|
| 849 |
+ |
|
| 850 |
+inline void _MMU_write32(const int PROCNUM, const MMU_ACCESS_TYPE AT, const uint32_t addr, uint32_t val) |
|
| 851 |
+{
|
|
| 852 |
+ //CheckMemoryDebugEvent(DEBUG_EVENT_WRITE,AT,PROCNUM,addr,32,val); |
|
| 853 |
+ |
|
| 854 |
+ //special handling for DMA: discard writes to TCM |
|
| 855 |
+ if(PROCNUM==ARMCPU_ARM9 && AT == MMU_AT_DMA) |
|
| 856 |
+ {
|
|
| 857 |
+ if(addr<0x02000000) return; //itcm |
|
| 858 |
+ if((addr&(~0x3FFF)) == MMU.DTCMRegion) return; //dtcm |
|
| 859 |
+ } |
|
| 860 |
+ |
|
| 861 |
+ if(PROCNUM==ARMCPU_ARM9) |
|
| 862 |
+ if((addr&(~0x3FFF)) == MMU.DTCMRegion) |
|
| 863 |
+ {
|
|
| 864 |
+ T1WriteLong(MMU.ARM9_DTCM, addr & 0x3FFC, val); |
|
| 865 |
+#ifdef HAVE_LUA |
|
| 866 |
+ CallRegisteredLuaMemHook(addr, 4, val, LUAMEMHOOK_WRITE); |
|
| 867 |
+#endif |
|
| 868 |
+ return; |
|
| 869 |
+ } |
|
| 870 |
+ |
|
| 871 |
+ if ( (addr & 0x0F000000) == 0x02000000) {
|
|
| 872 |
+ T1WriteLong( MMU.MAIN_MEM, addr & _MMU_MAIN_MEM_MASK32, val); |
|
| 873 |
+#ifdef HAVE_LUA |
|
| 874 |
+ CallRegisteredLuaMemHook(addr, 4, val, LUAMEMHOOK_WRITE); |
|
| 875 |
+#endif |
|
| 876 |
+ return; |
|
| 877 |
+ } |
|
| 878 |
+ |
|
| 879 |
+ if(PROCNUM==ARMCPU_ARM9) _MMU_ARM9_write32(addr,val); |
|
| 880 |
+ else _MMU_ARM7_write32(addr,val); |
|
| 881 |
+#ifdef HAVE_LUA |
|
| 882 |
+ CallRegisteredLuaMemHook(addr, 4, val, LUAMEMHOOK_WRITE); |
|
| 883 |
+#endif |
|
| 884 |
+} |
|
| 885 |
+ |
|
| 886 |
+ |
|
| 887 |
+//#ifdef MMU_ENABLE_ACL |
|
| 888 |
+// void FASTCALL MMU_write8_acl(uint32_t proc, uint32_t adr, uint8_t val); |
|
| 889 |
+// void FASTCALL MMU_write16_acl(uint32_t proc, uint32_t adr, uint16_t val); |
|
| 890 |
+// void FASTCALL MMU_write32_acl(uint32_t proc, uint32_t adr, uint32_t val); |
|
| 891 |
+// uint8_t FASTCALL MMU_read8_acl(uint32_t proc, uint32_t adr, uint32_t access); |
|
| 892 |
+// uint16_t FASTCALL MMU_read16_acl(uint32_t proc, uint32_t adr, uint32_t access); |
|
| 893 |
+// uint32_t FASTCALL MMU_read32_acl(uint32_t proc, uint32_t adr, uint32_t access); |
|
| 894 |
+//#else |
|
| 895 |
+// #define MMU_write8_acl(proc, adr, val) _MMU_write08<proc>(adr, val) |
|
| 896 |
+// #define MMU_write16_acl(proc, adr, val) _MMU_write16<proc>(adr, val) |
|
| 897 |
+// #define MMU_write32_acl(proc, adr, val) _MMU_write32<proc>(adr, val) |
|
| 898 |
+// #define MMU_read8_acl(proc,adr,access) _MMU_read08<proc>(adr) |
|
| 899 |
+// #define MMU_read16_acl(proc,adr,access) ((access==CP15_ACCESS_EXECUTE)?_MMU_read16<proc,MMU_AT_CODE>(adr):_MMU_read16<proc,MMU_AT_DATA>(adr)) |
|
| 900 |
+// #define MMU_read32_acl(proc,adr,access) ((access==CP15_ACCESS_EXECUTE)?_MMU_read32<proc,MMU_AT_CODE>(adr):_MMU_read32<proc,MMU_AT_DATA>(adr)) |
|
| 901 |
+//#endif |
|
| 902 |
+ |
|
| 903 |
+// Use this macros for reading/writing, so the GDB stub isn't broken |
|
| 904 |
+#ifdef GDB_STUB |
|
| 905 |
+ #define READ32(a,b) cpu->mem_if->read32(a,(b) & 0xFFFFFFFC) |
|
| 906 |
+ #define WRITE32(a,b,c) cpu->mem_if->write32(a,(b) & 0xFFFFFFFC,c) |
|
| 907 |
+ #define READ16(a,b) cpu->mem_if->read16(a,(b) & 0xFFFFFFFE) |
|
| 908 |
+ #define WRITE16(a,b,c) cpu->mem_if->write16(a,(b) & 0xFFFFFFFE,c) |
|
| 909 |
+ #define READ8(a,b) cpu->mem_if->read8(a,b) |
|
| 910 |
+ #define WRITE8(a,b,c) cpu->mem_if->write8(a,b,c) |
|
| 911 |
+#else |
|
| 912 |
+ #define READ32(a,b) _MMU_read32<PROCNUM>((b) & 0xFFFFFFFC) |
|
| 913 |
+ #define WRITE32(a,b,c) _MMU_write32<PROCNUM>((b) & 0xFFFFFFFC,c) |
|
| 914 |
+ #define READ16(a,b) _MMU_read16<PROCNUM>((b) & 0xFFFFFFFE) |
|
| 915 |
+ #define WRITE16(a,b,c) _MMU_write16<PROCNUM>((b) & 0xFFFFFFFE,c) |
|
| 916 |
+ #define READ8(a,b) _MMU_read08<PROCNUM>(b) |
|
| 917 |
+ #define WRITE8(a,b,c) _MMU_write08<PROCNUM>(b, c) |
|
| 918 |
+#endif |
|
| 919 |
+ |
|
| 920 |
+template<int PROCNUM, MMU_ACCESS_TYPE AT> |
|
| 921 |
+inline uint8_t _MMU_read08(uint32_t addr) { return _MMU_read08(PROCNUM, AT, addr); }
|
|
| 922 |
+ |
|
| 923 |
+template<int PROCNUM, MMU_ACCESS_TYPE AT> |
|
| 924 |
+inline uint16_t _MMU_read16(uint32_t addr) { return _MMU_read16(PROCNUM, AT, addr); }
|
|
| 925 |
+ |
|
| 926 |
+template<int PROCNUM, MMU_ACCESS_TYPE AT> |
|
| 927 |
+inline uint32_t _MMU_read32(uint32_t addr) { return _MMU_read32(PROCNUM, AT, addr); }
|
|
| 928 |
+ |
|
| 929 |
+template<int PROCNUM, MMU_ACCESS_TYPE AT> |
|
| 930 |
+inline void _MMU_write08(uint32_t addr, uint8_t val) { _MMU_write08(PROCNUM, AT, addr, val); }
|
|
| 931 |
+ |
|
| 932 |
+template<int PROCNUM, MMU_ACCESS_TYPE AT> |
|
| 933 |
+inline void _MMU_write16(uint32_t addr, uint16_t val) { _MMU_write16(PROCNUM, AT, addr, val); }
|
|
| 934 |
+ |
|
| 935 |
+template<int PROCNUM, MMU_ACCESS_TYPE AT> |
|
| 936 |
+inline void _MMU_write32(uint32_t addr, uint32_t val) { _MMU_write32(PROCNUM, AT, addr, val); }
|
|
| 937 |
+ |
|
| 938 |
+//void FASTCALL MMU_DumpMemBlock(uint8_t proc, uint32_t address, uint32_t size, uint8_t *buffer); |
|
| 939 |
+ |
|
| 940 |
+#endif |