From 1827c3f3b623f165794261521dc13016acd3b36c Mon Sep 17 00:00:00 2001 From: yabause Date: Sun, 29 Oct 2006 15:47:19 +0000 Subject: [PATCH] Almost all memory access are now using T1Memory functions, there's some u32 accesses that should use T2Memory left. u8 * casts are still here too but they should be ok. Most of those changes have been tested but not all, so there may be problems... --- desmume/src/GPU.c | 227 +++++++---------------------- desmume/src/GPU.h | 12 +- desmume/src/MMU.c | 185 +++++++++++------------ desmume/src/MMU.h | 3 - desmume/src/NDSSystem.c | 17 ++- desmume/src/NDSSystem.h | 20 ++- desmume/src/cflash.c | 14 +- desmume/src/gtk/main.c | 18 +-- desmume/src/gtk/tools/ioregsView.c | 11 +- desmume/src/mem.h | 12 ++ 10 files changed, 193 insertions(+), 326 deletions(-) diff --git a/desmume/src/GPU.c b/desmume/src/GPU.c index 6fc5a1c5f..a5e0d9471 100644 --- a/desmume/src/GPU.c +++ b/desmume/src/GPU.c @@ -24,7 +24,6 @@ #include "GPU.h" #include "debug.h" -#include "mem.h" #include "nds/video.h" @@ -83,44 +82,6 @@ void (*modeRender[8][4])(GPU * gpu, u8 num, u16 l, u16 * DST)= {lineText, lineText, lineText, lineText}, //7 }; -#if 0 -GPU::GPU(u8 l) : lcd(l) -{ - prop = 0; - BGProp[0] = BGProp[1] = BGProp[2] = BGProp[3] = 0; - BGBmpBB[0] = 0;BGBmpBB[1] = 0;BGBmpBB[2] = 0;BGBmpBB[3] = 0; - BGChBB[0] = 0;BGChBB[1] = 0;BGProp[2] = 0;BGChBB[3] = 0; - BGScrBB[0] = 0;BGScrBB[1] = 0;BGScrBB[2] = 0;BGScrBB[3] = 0; - BGExtPalSlot[0] = BGExtPalSlot[1] = BGExtPalSlot[2] = BGExtPalSlot[3] = 0; - BGSize[0][0] = BGSize[1][0] = BGSize[2][0] = BGSize[3][0] = 256; - BGSize[0][1] = BGSize[1][1] = BGSize[2][1] = BGSize[3][1] = 256; - BGSX[0] = BGSX[1] = BGSX[2] = BGSX[3] = 0; - BGSY[0] = BGSY[1] = BGSY[2] = BGSY[3] = 0; - BGX[0] = BGX[1] = BGX[2] = BGX[3] = 0; - BGY[0] = BGY[1] = BGY[2] = BGY[3] = 0; - BGPA[0] = BGPA[1] = BGPA[2] = BGPA[3] = 0; - BGPB[0] = BGPB[1] = BGPB[2] = BGPB[3] = 0; - BGPC[0] = BGPC[1] = BGPC[2] = BGPC[3] = 0; - BGPD[0] = BGPD[1] = BGPD[2] = BGPD[3] = 0; - BGIndex[0] = BGIndex[1] = BGIndex[2] = BGIndex[3] = 0; - dispBG[0] = dispBG[1] = dispBG[2] = dispBG[3] = TRUE; - nbBGActif = 0; - - spriteRender = sprite1D; - - if(lcd) - { - oam = (OAM *)(ARM9Mem.ARM9_OAM+0x400); - sprMem = ARM9Mem.ARM9_BOBJ; - } - else - { - oam = (OAM *)(ARM9Mem.ARM9_OAM); - sprMem = ARM9Mem.ARM9_AOBJ; - } -} -#endif - GPU * GPU_Init(u8 l) { GPU * g; @@ -162,48 +123,6 @@ void GPU_DeInit(GPU * gpu) free(gpu); } -/*void GPU::ligne(u16 * buffer, u16 l) -{ - u16 * dst = buffer + l*256; - u16 spr[256]; - u8 sprPrio[256]; - u8 bgprio; - - u32 c = ((u16 *)ARM9Mem.ARM9_VMEM)[0+lcd*0x200]; - c |= (c<<16); - - for(u8 i = 0; i< 128; ++i) - { - ((u32 *)dst)[i] = c; - ((u32 *)spr)[i] = c; - ((u16 *)sprPrio)[i] = (4<<8) | (4); - } - - if(!nbBGActif) - { - spriteRender(this, l, dst, sprPrio); - return; - } - - spriteRender(this, l, spr, sprPrio); - - if((BGProp[ordre[0]]&3)!=3) - { - for(u16 i = 0; i < 128; ++i) - ((u32 *)dst)[i] = ((u32 *)spr)[i]; - } - - for(u8 i = 0; i < nbBGActif; ++i) - { - modeRender[prop&7][ordre[i]](this, ordre[i], l, dst); - bgprio = BGProp[ordre[i]]&3; - for(u16 i = 0; i < 256; ++i) - if(bgprio>=sprPrio[i]) - dst[i] = spr[i]; - } -} -*/ - /* NOTICE: the name of function is unclear, but it's about writing in DISPLAY_CR */ void GPU_setVideoProp(GPU * gpu, u32 p) { @@ -449,15 +368,15 @@ void GPU_setBGProp(GPU * gpu, u16 num, u16 p) { gpu->BG_bmp_ram[num] = ((u8 *)ARM9Mem.ARM9_BBG) + BG_BMP_BASE_MASK(p) * 0x4000; gpu->BG_tile_ram[num] = ((u8 *)ARM9Mem.ARM9_BBG) + BG_TILE_BASE_MASK(p) * 0x4000; - gpu->BG_map_ram[num] = ((u16 *)ARM9Mem.ARM9_BBG) + BG_MAP_BASE_MASK(p) * 0x400; + gpu->BG_map_ram[num] = ARM9Mem.ARM9_BBG + BG_MAP_BASE_MASK(p) * 0x800; } else { gpu->BG_bmp_ram[num] = ((u8 *)ARM9Mem.ARM9_ABG) + BG_BMP_BASE_MASK(p) * 0x4000; gpu->BG_tile_ram[num] = ((u8 *)ARM9Mem.ARM9_ABG) + BG_TILE_BASE_MASK(p) * 0x4000 + DISPLAY_TILE_BASE_MASK(gpu->prop) * 0x10000; - gpu->BG_map_ram[num] = ((u16 *)ARM9Mem.ARM9_ABG) + BG_MAP_BASE_MASK(p) * 0x400 + DISPLAY_MAP_BASE_MASK(gpu->prop) * 0x8000; + gpu->BG_map_ram[num] = ARM9Mem.ARM9_ABG + BG_MAP_BASE_MASK(p) * 0x800 + DISPLAY_MAP_BASE_MASK(gpu->prop) * 0x10000; } - + /*if(!(p&(1<<7))) BGExtPalSlot[num] = 0; else @@ -613,7 +532,7 @@ INLINE void renderline_textBG(GPU * gpu, u8 num, u16 * DST, u16 X, u16 Y, u16 LG u16 lg = gpu->BGSize[num][0]; u16 ht = gpu->BGSize[num][1]; u16 tmp = ((Y&(ht-1))>>3); - u16 *map = gpu->BG_map_ram[num] + (tmp&31) * 32; + u8 * map = gpu->BG_map_ram[num] + (tmp&31) * 64; u16 *dst = DST; if(tmp>31) @@ -621,10 +540,10 @@ INLINE void renderline_textBG(GPU * gpu, u8 num, u16 * DST, u16 X, u16 Y, u16 LG switch(BG_SIZE_MASK(bgprop)) { case 2 : - map += 32*32; + map += 32 * 32 * 2; break; case 3 : - map += 32*64; + map += 32 * 64 * 2; break; } } @@ -644,22 +563,27 @@ INLINE void renderline_textBG(GPU * gpu, u8 num, u16 * DST, u16 X, u16 Y, u16 LG for(x = 0; x < LG;) { tmp = ((xoff&(lg-1))>>3); - u16 *mapinfo = map + (tmp&0x1F); - if(tmp>31) mapinfo += 32*32; - u8 *line = (u8 * )tile + (MAP_ENTRY_TILEID_MASK(*mapinfo) * 0x20) + (((*mapinfo)& MAP_ENTRY_FLIP_Y ? (7*4)-yoff : yoff)); + u8 * mapinfo = map + (tmp&0x1F) * 2; + u16 mapinfovalue; + + if(tmp>31) mapinfo += 32*32*2; + + mapinfovalue = T1ReadWord(mapinfo, 0); + + u8 *line = (u8 * )tile + (MAP_ENTRY_TILEID_MASK(mapinfovalue) * 0x20) + (((mapinfovalue)& MAP_ENTRY_FLIP_Y ? (7*4)-yoff : yoff)); u16 xfin = x + (8 - (xoff&7)); if (xfin > LG) xfin = LG; - if((*mapinfo) & MAP_ENTRY_FLIP_X) + if((mapinfovalue) & MAP_ENTRY_FLIP_X) { line += 3 - ((xoff&7)>>1); for(; x < xfin; ) { - if((*line)>>4) *dst = T1ReadWord(pal, (((*line)>>4) + MAP_ENTRY_PALETTE_MASK(*mapinfo) * 0x10) << 1); + if((*line)>>4) *dst = T1ReadWord(pal, (((*line)>>4) + MAP_ENTRY_PALETTE_MASK(mapinfovalue) * 0x10) << 1); //else *dst = 0x7FFF; dst++; x++; xoff++; - if((*line)&0xF) *dst = T1ReadWord(pal, (((*line)&0xF) + MAP_ENTRY_PALETTE_MASK(*mapinfo) * 0x10) << 1); + if((*line)&0xF) *dst = T1ReadWord(pal, (((*line)&0xF) + MAP_ENTRY_PALETTE_MASK(mapinfovalue) * 0x10) << 1); //else *dst = 0x7FFF; dst++; x++; xoff++; line--; @@ -670,10 +594,10 @@ INLINE void renderline_textBG(GPU * gpu, u8 num, u16 * DST, u16 X, u16 Y, u16 LG line += ((xoff&7)>>1); for(; x < xfin; ) { - if((*line)&0xF) *dst = T1ReadWord(pal, (((*line)&0xF) + MAP_ENTRY_PALETTE_MASK(*mapinfo) * 0x10) << 1); + if((*line)&0xF) *dst = T1ReadWord(pal, (((*line)&0xF) + MAP_ENTRY_PALETTE_MASK(mapinfovalue) * 0x10) << 1); //else *dst = 0x7FFF; dst++; x++; xoff++; - if((*line)>>4) *dst = T1ReadWord(pal, (((*line)>>4) + MAP_ENTRY_PALETTE_MASK(*mapinfo) * 0x10) << 1); + if((*line)>>4) *dst = T1ReadWord(pal, (((*line)>>4) + MAP_ENTRY_PALETTE_MASK(mapinfovalue) * 0x10) << 1); //else *dst = 0x7FFF; dst++; x++; xoff++; line++; @@ -692,14 +616,19 @@ INLINE void renderline_textBG(GPU * gpu, u8 num, u16 * DST, u16 X, u16 Y, u16 LG for(x = 0; x < LG;) { tmp = ((xoff&(lg-1))>>3); - u16 *mapinfo = map + (tmp&31); - if(tmp > 31) mapinfo += 32*32; - u8 *line = (u8 * )tile + (MAP_ENTRY_TILEID_MASK(*mapinfo)*0x40) + (((*mapinfo)& MAP_ENTRY_FLIP_Y ? (7*8)-yoff : yoff)); + u8 * mapinfo = map + (tmp & 31) * 2; + u16 mapinfovalue; + + if(tmp > 31) mapinfo += 32*32*2; + + mapinfovalue = T1ReadWord(mapinfo, 0); + + u8 *line = (u8 * )tile + (MAP_ENTRY_TILEID_MASK(mapinfovalue)*0x40) + (((mapinfovalue)& MAP_ENTRY_FLIP_Y ? (7*8)-yoff : yoff)); u16 xfin = x + (8 - (xoff&7)); if (xfin > LG) xfin = LG; - if((*mapinfo)& MAP_ENTRY_FLIP_X) + if((mapinfovalue)& MAP_ENTRY_FLIP_X) { line += (7 - (xoff&7)); for(; x < xfin; ++x, ++xoff) @@ -735,19 +664,24 @@ INLINE void renderline_textBG(GPU * gpu, u8 num, u16 * DST, u16 X, u16 Y, u16 LG for(x = 0; x < LG;) { tmp = ((xoff&(lg-1))>>3); - u16 * mapinfo = (u16 *)map + (tmp&0x1F); - if(tmp>31) mapinfo += 32*32; - u8 * line = (u8 * )tile + (MAP_ENTRY_TILEID_MASK(*mapinfo)*0x40) + (((*mapinfo)& MAP_ENTRY_FLIP_Y ? (7*8)-yoff : yoff)); + u8 * mapinfo = map + (tmp & 0x1F) * 2; + u16 mapinfovalue; + + if(tmp>31) mapinfo += 32 * 32 * 2; + + mapinfovalue = T1ReadWord(mapinfo, 0); + + u8 * line = (u8 * )tile + (MAP_ENTRY_TILEID_MASK(mapinfovalue)*0x40) + (((mapinfovalue)& MAP_ENTRY_FLIP_Y ? (7*8)-yoff : yoff)); u16 xfin = x + (8 - (xoff&7)); if (xfin > LG) xfin = LG; - if((*mapinfo)& MAP_ENTRY_FLIP_X) + if((mapinfovalue)& MAP_ENTRY_FLIP_X) { line += (7 - (xoff&7)); for(; x < xfin; ++x, ++xoff) { - if(*line) *dst = T1ReadWord(pal, (*line + ((*mapinfo>>12)&0xF)*0x100) << 1); + if(*line) *dst = T1ReadWord(pal, (*line + ((mapinfovalue>>12)&0xF)*0x100) << 1); //else *dst = 0x7FFF; dst++; line--; @@ -758,7 +692,7 @@ INLINE void renderline_textBG(GPU * gpu, u8 num, u16 * DST, u16 X, u16 Y, u16 LG line += (xoff&7); for(; x < xfin; ++x, ++xoff) { - if(*line) *dst = T1ReadWord(pal, (*line + ((*mapinfo>>12)&0xF)*0x100) << 1); + if(*line) *dst = T1ReadWord(pal, (*line + ((mapinfovalue>>12)&0xF)*0x100) << 1); //else *dst = 0x7FFF; dst++; line++; @@ -785,8 +719,8 @@ INLINE void rotBG2(GPU * gpu, u8 num, u16 * DST, u16 H, s32 X, s32 Y, s16 PA, s1 s32 ht = gpu->BGSize[num][1]; s32 lgmap = (lg>>3); - u8 * map = (u8 *)gpu->BG_map_ram[num]; - u8 * tile = (u8 *)gpu->BG_tile_ram[num]; + u8 * map = gpu->BG_map_ram[num]; + u8 * tile = (u8 *)gpu->BG_tile_ram[num]; u16 * dst = DST; u8 mapinfo; u8 coul; @@ -836,7 +770,7 @@ INLINE void extRotBG2(GPU * gpu, u8 num, u16 * DST, u16 H, s32 X, s32 Y, s16 PA, s16 ht = gpu->BGSize[num][1]; u16 lgmap = (lg>>3); - u8 * tile = (u8 *)gpu->BG_tile_ram[num]; + u8 * tile = (u8 *)gpu->BG_tile_ram[num]; u16 * dst = DST; u16 mapinfo; u8 coul; @@ -846,7 +780,7 @@ INLINE void extRotBG2(GPU * gpu, u8 num, u16 * DST, u16 H, s32 X, s32 Y, s16 PA, case 0 : case 1 : { - u16 * map = gpu->BG_map_ram[num]; + u8 * map = gpu->BG_map_ram[num]; u8 * pal = ARM9Mem.ExtPal[gpu->core][gpu->BGExtPalSlot[num]]; u16 i; if(!pal) return; @@ -862,7 +796,8 @@ INLINE void extRotBG2(GPU * gpu, u8 num, u16 * DST, u16 H, s32 X, s32 Y, s16 PA, } if ((auxX >= 0) && (auxX < lg) && (auxY >= 0) && (auxY < ht)) { - mapinfo = map[(auxX>>3) + (auxY>>3) * lgmap]; + mapinfo = T1ReadWord(map, ((auxX>>3) + (auxY>>3) * lgmap) << 1); + u16 x1 = (mapinfo & 0x400) ? 7 - (auxX&7) : (auxX&7); u16 y1 = (mapinfo & 0x800) ? 7 - (auxY&7) : (auxY&7); coul = tile[(mapinfo&0x3FF)*64 + x1 + (y1<<3)]; @@ -879,7 +814,7 @@ INLINE void extRotBG2(GPU * gpu, u8 num, u16 * DST, u16 H, s32 X, s32 Y, s16 PA, return; case 2 : { - u8 * map = (u8 *)gpu->BG_bmp_ram[num]; + u8 * map = gpu->BG_bmp_ram[num]; u8 * pal = ARM9Mem.ARM9_VMEM + gpu->core * 0x400; u16 i; for(i = 0; i < LG; ++i) @@ -907,7 +842,7 @@ INLINE void extRotBG2(GPU * gpu, u8 num, u16 * DST, u16 H, s32 X, s32 Y, s16 PA, return; case 3 : { - u16 * map = (u16 *)gpu->BG_bmp_ram[num]; + u8 * map = gpu->BG_bmp_ram[num]; u16 i; for(i = 0; i < LG; ++i) { @@ -920,7 +855,7 @@ INLINE void extRotBG2(GPU * gpu, u8 num, u16 * DST, u16 H, s32 X, s32 Y, s16 PA, } if ((auxX >= 0) && (auxX < lg) && (auxY >= 0) && (auxY < ht)) { - mapinfo = map[auxX + auxY * lg]; + mapinfo = T1ReadWord(map, (auxX + auxY * lg) << 1); if(mapinfo) *dst = mapinfo; //else *dst = 0x7FFF; @@ -988,34 +923,6 @@ void extRotBG(GPU * gpu, u8 num, u16 * DST) } #define nbShow 128 - /*u16 * src = (u16 *)(gpu->sprMem + ((aux->attr2&0x3FF)<sprBMPBlock) + (y*sprSize.x)); - if(aux->attr1&(1<<12)) - { - x = sprSize.x -x - 1; - for(u16 i = 0; i < lg; ++i, --x, ++sprX) - { - u8 c = src[x]; - if((c>>15) && (prioTab[sprX]>=prio)) - { - dst[sprX] = c; - prioTab[sprX] = prio; - } - else dst[sprX] = 0x7FFF; - } - continue; - } - for(u16 i = 0; i < lg; ++i, ++x, ++sprX) - { - u16 c = src[x]; - if((c>>15) && (prioTab[sprX]>=prio)) - { - dst[sprX] = c; - prioTab[sprX] = prio; - } - else dst[sprX] = 0x7FFF; - } - continue;*/ -/*(aux->attr2&0x3E0)*64 + (aux->attr2&0x1F)*8*/ void sprite1D(GPU * gpu, u16 l, u16 * dst, u8 * prioTab) { @@ -1061,8 +968,9 @@ void sprite1D(GPU * gpu, u16 l, u16 * dst, u8 * prioTab) if((aux->attr0&(3<<10))==(3<<10)) { - u16 * src = (u16 *)(gpu->sprMem) +(aux->attr2&0x3FF)*16 + (y<sprBMPBlock); + u8 * src = (gpu->sprMem) +(aux->attr2&0x3FF)*16 + (y<sprBMPBlock); u16 i; + if(aux->attr1&(1<<12)) { x = sprSize.x -x - 1; @@ -1080,7 +988,7 @@ void sprite1D(GPU * gpu, u16 l, u16 * dst, u8 * prioTab) } for(i = 0; i < lg; ++i, ++x, ++sprX) { - u16 c = src[x]; + u16 c = T1ReadWord(src, x << 1); if((c>>15) && (prioTab[sprX]>=prio)) { dst[sprX] = c; @@ -1224,35 +1132,6 @@ void sprite1D(GPU * gpu, u16 l, u16 * dst, u8 * prioTab) } } - /*u16 * src = (u16 *)(gpu->sprMem + ((aux->attr2&0x3FF)<sprBMPBlock) + (y*sprSize.x)); - if(aux->attr1&(1<<12)) - { - x = sprSize.x -x - 1; - for(u16 i = 0; i < lg; ++i, --x, ++sprX) - { - u8 c = src[x]; - if((c) && (prioTab[sprX]>=prio)) - { - dst[sprX] = c; - prioTab[sprX] = prio; - } - //else dst[sprX] = 0x7FFF; - } - continue; - } - for(u16 i = 0; i < lg; ++i, ++x, ++sprX) - { - u16 c = src[x]; - if((c) && (prioTab[sprX]>=prio)) - { - dst[sprX] = c; - prioTab[sprX] = prio; - } - //else dst[sprX] = 0x7FFF; - } - continue;*/ -/*gpu->sprBMPBlock*/ - void sprite2D(GPU * gpu, u16 l, u16 * dst, u8 * prioTab) { u16 i; @@ -1295,7 +1174,7 @@ void sprite2D(GPU * gpu, u16 l, u16 * dst, u8 * prioTab) if((aux->attr0&(3<<10))==(3<<10)) { - u16 * src = (u16 *)(gpu->sprMem) +(aux->attr2&0x3E0)*64 + (aux->attr2&0x1F)*8 + (y<<8); + u8 * src = (gpu->sprMem) +(aux->attr2&0x3E0)*64 + (aux->attr2&0x1F)*8 + (y<<8); u16 i; if(aux->attr1&(1<<12)) { @@ -1314,7 +1193,7 @@ void sprite2D(GPU * gpu, u16 l, u16 * dst, u8 * prioTab) } for(i = 0; i < lg; ++i, ++x, ++sprX) { - u16 c = src[x]; + u16 c = T1ReadWord(src, x << 1); if((c>>15) && (prioTab[sprX]>=prio)) { dst[sprX] = c; diff --git a/desmume/src/GPU.h b/desmume/src/GPU.h index d303ffabe..654a29b54 100644 --- a/desmume/src/GPU.h +++ b/desmume/src/GPU.h @@ -24,6 +24,7 @@ #include "ARM9.h" #include +#include "mem.h" #ifdef __cplusplus extern "C" { @@ -60,11 +61,10 @@ struct _GPU #define BGBmpBB BG_bmp_ram #define BGChBB BG_tile_ram -#define BGScrBB BG_map_ram - u8 *(BG_bmp_ram[4]); - u8 *(BG_tile_ram[4]); - u16 *(BG_map_ram[4]); + u8 *(BG_bmp_ram[4]); + u8 *(BG_tile_ram[4]); + u8 *(BG_map_ram[4]); u8 BGExtPalSlot[4]; u32 BGSize[4][2]; @@ -150,14 +150,14 @@ static INLINE void GPU_ligne(Screen * screen, u16 l) } } - u32 c = ((u16 *)ARM9Mem.ARM9_VMEM)[0 + gpu->lcd * 0x200]; + u32 c = T1ReadWord(ARM9Mem.ARM9_VMEM, gpu->lcd * 0x400); c |= (c<<16); for(i8 = 0; i8< 128; ++i8) { ((u32 *)dst)[i8] = c; ((u32 *)spr)[i8] = c; - ((u16 *)sprPrio)[i8] = (4<<8) | (4); + T1WriteWord(sprPrio, i8 << 1, (4 << 8) | (4)); } if(!gpu->nbBGActif) diff --git a/desmume/src/MMU.c b/desmume/src/MMU.c index 96e422c0e..1283b156a 100644 --- a/desmume/src/MMU.c +++ b/desmume/src/MMU.c @@ -438,7 +438,7 @@ u32 FASTCALL MMU_read32(u32 proc, u32 adr) if((proc == ARMCPU_ARM9) && ((adr & ~0x3FFF) == MMU.DTCMRegion)) { /* Returns data from DTCM (ARM9 only) */ - return ((u32 *)ARM9Mem.ARM9_DTCM)[(adr&0x3FFF)>>2]; + return T1ReadLong(ARM9Mem.ARM9_DTCM, adr & 0x3FFF); } // CFlash reading, Mic @@ -506,9 +506,8 @@ u32 FASTCALL MMU_read32(u32 proc, u32 adr) { if(!MMU.dscard[proc].adress) return 0; - //u32 val = ((u32 *)MMU.CART_ROM)[MMU.dscard[proc].adress >> 2]; - u32 val = ROM_32(MMU.CART_ROM, MMU.dscard[proc].adress); /* get data from rom */ - + u32 val = T1ReadLong(MMU.CART_ROM, MMU.dscard[proc].adress); + MMU.dscard[proc].adress += 4; /* increment adress */ MMU.dscard[proc].transfer_count--; /* update transfer counter */ @@ -518,7 +517,7 @@ u32 FASTCALL MMU_read32(u32 proc, u32 adr) } else /* transfer is done */ { - MEM_32(MMU.MMU_MEM[proc], CARD_CR2) &= ~(CARD_DATA_READY | CARD_ACTIVATE); /* we're done, edit control register */ + T1WriteLong(MMU.MMU_MEM[proc][(CARD_CR2 >> 20) & 0xff], CARD_CR2 & 0xfff, T1ReadLong(MMU.MMU_MEM[proc][(CARD_CR2 >> 20) & 0xff], CARD_CR2 & 0xfff) & ~(CARD_DATA_READY | CARD_ACTIVATE)); /* = 0x7f7fffff */ /* if needed, throw irq for the end of transfer */ @@ -538,7 +537,7 @@ u32 FASTCALL MMU_read32(u32 proc, u32 adr) } /* Returns data from memory */ - return ((u32 *)(MMU.MMU_MEM[proc][(adr>>20)&0xFF]))[(adr&MMU.MMU_MASK[proc][(adr>>20)&0xFF])>>2]; + return T1ReadLong(MMU.MMU_MEM[proc][(adr >> 20) & 0xFF], adr & MMU.MMU_MASK[proc][(adr >> 20) & 0xFF]); } void FASTCALL MMU_write8(u32 proc, u32 adr, u8 val) @@ -1175,31 +1174,31 @@ void FASTCALL MMU_write16(u32 proc, u32 adr, u16 val) case 0x04000002 : { //execute = FALSE; - u32 v = (((u32 *)(MMU.MMU_MEM[proc][0x40]))[0x0>>2]&0xFFFF)|((u32)val<<16); + u32 v = (T1ReadLong(MMU.MMU_MEM[proc][0x40], 0) & 0xFFFF) | ((u32) val << 16); GPU_setVideoProp(MainScreen.gpu, v); - ((u32 *)(MMU.MMU_MEM[proc][0x40]))[0x0>>2] = v; + T1WriteLong(MMU.MMU_MEM[proc][0x40], 0, v); } return; case 0x04000000 : { - u32 v = (((u32 *)(MMU.MMU_MEM[proc][0x40]))[0x0]&0xFFFF0000)|val; + u32 v = (T1ReadLong(MMU.MMU_MEM[proc][0x40], 0) & 0xFFFF0000) | val; GPU_setVideoProp(MainScreen.gpu, v); - ((u32 *)(MMU.MMU_MEM[proc][0x40]))[0x0] = v; + T1WriteLong(MMU.MMU_MEM[proc][0x40], 0, v); } return; case 0x04001002 : { //execute = FALSE; - u32 v = (((u32 *)(MMU.MMU_MEM[proc][0x40]))[0x1000>>2]&0xFFFF)|((u32)val<<16); + u32 v = (T1ReadLong(MMU.MMU_MEM[proc][0x40], 0x1000) & 0xFFFF) | ((u32) val << 16); GPU_setVideoProp(SubScreen.gpu, v); - ((u32 *)(MMU.MMU_MEM[proc][0x40]))[0x1000>>2] = v; + T1WriteLong(MMU.MMU_MEM[proc][0x40], 0x1000, v); } return; case 0x04001000 : { - u32 v = (((u32 *)(MMU.MMU_MEM[proc][0x40]))[0x1000>>2]&0xFFFF0000)|val; + u32 v = (T1ReadLong(MMU.MMU_MEM[proc][0x40], 0x1000) & 0xFFFF0000) | val; GPU_setVideoProp(SubScreen.gpu, v); - ((u32 *)(MMU.MMU_MEM[proc][0x40]))[0x1000>>2] = v; + T1WriteLong(MMU.MMU_MEM[proc][0x40], 0x1000, v); } return; //case 0x020D8460 : @@ -1211,9 +1210,9 @@ void FASTCALL MMU_write16(u32 proc, u32 adr, u16 val) //if(val&0x8000) execute = FALSE; //LOG("16 bit dma0 %04X\r\n", val); T1WriteWord(MMU.MMU_MEM[proc][0x40], 0xBA, val); - DMASrc[proc][0] = ((u32 *)(MMU.MMU_MEM[proc][0x40]))[0xB0>>2]; - DMADst[proc][0] = ((u32 *)(MMU.MMU_MEM[proc][0x40]))[0xB4>>2]; - u32 v = ((u32 *)(MMU.MMU_MEM[proc][0x40]))[0xB8>>2]; + DMASrc[proc][0] = T1ReadLong(MMU.MMU_MEM[proc][0x40], 0xB0); + DMADst[proc][0] = T1ReadLong(MMU.MMU_MEM[proc][0x40], 0xB4); + u32 v = T1ReadLong(MMU.MMU_MEM[proc][0x40], 0xB8); MMU.DMAStartTime[proc][0] = (proc ? (v>>28) & 0x3 : (v>>27) & 0x7); MMU.DMACrt[proc][0] = v; if(MMU.DMAStartTime[proc][0] == 0) @@ -1231,9 +1230,9 @@ void FASTCALL MMU_write16(u32 proc, u32 adr, u16 val) //if(val&0x8000) execute = FALSE; //LOG("16 bit dma1 %04X\r\n", val); T1WriteWord(MMU.MMU_MEM[proc][0x40], 0xC6, val); - DMASrc[proc][1] = ((u32 *)(MMU.MMU_MEM[proc][0x40]))[0xBC>>2]; - DMADst[proc][1] = ((u32 *)(MMU.MMU_MEM[proc][0x40]))[0xC0>>2]; - u32 v = ((u32 *)(MMU.MMU_MEM[proc][0x40]))[0xC4>>2]; + DMASrc[proc][1] = T1ReadLong(MMU.MMU_MEM[proc][0x40], 0xBC); + DMASrc[proc][1] = T1ReadLong(MMU.MMU_MEM[proc][0x40], 0xC0); + u32 v = T1ReadLong(MMU.MMU_MEM[proc][0x40], 0xC4); MMU.DMAStartTime[proc][1] = (proc ? (v>>28) & 0x3 : (v>>27) & 0x7); MMU.DMACrt[proc][1] = v; if(MMU.DMAStartTime[proc][1] == 0) @@ -1251,9 +1250,9 @@ void FASTCALL MMU_write16(u32 proc, u32 adr, u16 val) //if(val&0x8000) execute = FALSE; //LOG("16 bit dma2 %04X\r\n", val); T1WriteWord(MMU.MMU_MEM[proc][0x40], 0xD2, val); - DMASrc[proc][2] = ((u32 *)(MMU.MMU_MEM[proc][0x40]))[0xC8>>2]; - DMADst[proc][2] = ((u32 *)(MMU.MMU_MEM[proc][0x40]))[0xCC>>2]; - u32 v = ((u32 *)(MMU.MMU_MEM[proc][0x40]))[0xD0>>2]; + DMASrc[proc][2] = T1ReadLong(MMU.MMU_MEM[proc][0x40], 0xC8); + DMASrc[proc][2] = T1ReadLong(MMU.MMU_MEM[proc][0x40], 0xCC); + u32 v = T1ReadLong(MMU.MMU_MEM[proc][0x40], 0xD0); MMU.DMAStartTime[proc][2] = (proc ? (v>>28) & 0x3 : (v>>27) & 0x7); MMU.DMACrt[proc][2] = v; if(MMU.DMAStartTime[proc][2] == 0) @@ -1271,9 +1270,9 @@ void FASTCALL MMU_write16(u32 proc, u32 adr, u16 val) //if(val&0x8000) execute = FALSE; //LOG("16 bit dma3 %04X\r\n", val); T1WriteWord(MMU.MMU_MEM[proc][0x40], 0xDE, val); - DMASrc[proc][3] = ((u32 *)(MMU.MMU_MEM[proc][0x40]))[0xD4>>2]; - DMADst[proc][3] = ((u32 *)(MMU.MMU_MEM[proc][0x40]))[0xD8>>2]; - u32 v = ((u32 *)(MMU.MMU_MEM[proc][0x40]))[0xDC>>2]; + DMASrc[proc][3] = T1ReadLong(MMU.MMU_MEM[proc][0x40], 0xD4); + DMASrc[proc][3] = T1ReadLong(MMU.MMU_MEM[proc][0x40], 0xD8); + u32 v = T1ReadLong(MMU.MMU_MEM[proc][0x40], 0xDC); MMU.DMAStartTime[proc][3] = (proc ? (v>>28) & 0x3 : (v>>27) & 0x7); MMU.DMACrt[proc][3] = v; @@ -1302,7 +1301,7 @@ void FASTCALL MMU_write32(u32 proc, u32 adr, u32 val) { if((proc==ARMCPU_ARM9)&((adr&(~0x3FFF))==MMU.DTCMRegion)) { - ((u32 *)ARM9Mem.ARM9_DTCM)[(adr&0x3FFF)>>2] = val; + T1WriteLong(ARM9Mem.ARM9_DTCM, adr & 0x3FFF, val); return ; } @@ -1320,7 +1319,7 @@ void FASTCALL MMU_write32(u32 proc, u32 adr, u32 val) { #ifdef RENDER3D case 0x040004AC : - ((u32 *)(MMU.MMU_MEM[proc][0x40]))[0x4AC>>2] = val; + T1WriteLong(MMU.MMU_MEM[proc][0x40], 0x4AC, val); if(proc==ARMCPU_ARM9) OGLRender::glTexImage2D(testval, TRUE); //execute = FALSE; @@ -1567,18 +1566,18 @@ void FASTCALL MMU_write32(u32 proc, u32 adr, u32 val) GPU_setVideoProp(MainScreen.gpu, val); GPULOG("MAIN INIT 32B %08X\r\n", val); - ((u32 *)(MMU.MMU_MEM[proc][0x40]))[0x0] = val; + T1WriteLong(MMU.MMU_MEM[proc][0x40], 0, val); return; case 0x04001000 : GPU_setVideoProp(SubScreen.gpu, val); GPULOG("SUB INIT 32B %08X\r\n", val); - ((u32 *)(MMU.MMU_MEM[proc][0x40]))[0x1000>>2] = val; + T1WriteLong(MMU.MMU_MEM[proc][0x40], 0x1000, val); return; case REG_IME : MMU.reg_IME[proc] = val & 1; - ((u32 *)(MMU.MMU_MEM[proc][0x40]))[0x208>>2] = val; + T1WriteLong(MMU.MMU_MEM[proc][0x40], 0x208, val); return; case REG_IE : @@ -1622,11 +1621,11 @@ void FASTCALL MMU_write32(u32 proc, u32 adr, u32 val) { MMU.timerRUN[proc][(adr>>2)&0x3] = FALSE; } - ((u32 *)(MMU.MMU_MEM[proc][0x40]))[(adr&0xFFF)>>2] = val; + T1WriteLong(MMU.MMU_MEM[proc][0x40], adr & 0xFFF, val); return; case 0x04000298 : { - ((u32 *)(MMU.MMU_MEM[proc][0x40]))[0x298>>2] = val; + T1WriteLong(MMU.MMU_MEM[proc][0x40], 0x298, val); u16 cnt = T1ReadWord(MMU.MMU_MEM[proc][0x40], 0x280); s64 num = 0; s64 den = 1; @@ -1636,21 +1635,19 @@ void FASTCALL MMU_write32(u32 proc, u32 adr, u32 val) { case 0: { - num = (s64)(((s32 *)(MMU.MMU_MEM[proc][0x40]))[0x290>>2]); - den = (s64)(((s32 *)(MMU.MMU_MEM[proc][0x40]))[0x298>>2]); + num = (s64) (s32) T1ReadLong(MMU.MMU_MEM[proc][0x40], 0x290); + den = (s64) (s32) T1ReadLong(MMU.MMU_MEM[proc][0x40], 0x298); } break; case 1: { - num = ((s64*)(MMU.MMU_MEM[proc][0x40]))[0x290>>3]; - den = (s64)(((s32 *)(MMU.MMU_MEM[proc][0x40]))[0x298>>2]); + num = (s64) T1ReadQuad(MMU.MMU_MEM[proc][0x40], 0x290); + den = (s64) (s32) T1ReadLong(MMU.MMU_MEM[proc][0x40], 0x298); } break; case 2: { return; - //num = ((s64*)(MMU.MMU_MEM[proc][0x40]))[0x290>>3]; - //den = ((s64*)(MMU.MMU_MEM[proc][0x40]))[0x298>>3]; } break; default: @@ -1672,16 +1669,16 @@ void FASTCALL MMU_write32(u32 proc, u32 adr, u32 val) DIVLOG("BOUT1 %08X%08X / %08X%08X = %08X%08X\r\n", (u32)(num>>32), (u32)num, (u32)(den>>32), (u32)den, (u32)(res>>32), (u32)res); - ((u32 *)(MMU.MMU_MEM[proc][0x40]))[0x2A0>>2] = (u32)res; - ((u32 *)(MMU.MMU_MEM[proc][0x40]))[0x2A4>>2] = (u32)(res>>32); - ((u32 *)(MMU.MMU_MEM[proc][0x40]))[0x2A8>>2] = (u32)mod; - ((u32 *)(MMU.MMU_MEM[proc][0x40]))[0x2AC>>2] = (u32)(mod>>32); - ((u32 *)(MMU.MMU_MEM[proc][0x40]))[0x280>>2] = cnt; + T1WriteLong(MMU.MMU_MEM[proc][0x40], 0x2A0, (u32) res); + T1WriteLong(MMU.MMU_MEM[proc][0x40], 0x2A4, (u32) (res >> 32)); + T1WriteLong(MMU.MMU_MEM[proc][0x40], 0x2A8, (u32) mod); + T1WriteLong(MMU.MMU_MEM[proc][0x40], 0x2AC, (u32) (mod >> 32)); + T1WriteLong(MMU.MMU_MEM[proc][0x40], 0x280, cnt); } return; case 0x0400029C : { - ((u32 *)(MMU.MMU_MEM[proc][0x40]))[0x29C>>2] = val; + T1WriteLong(MMU.MMU_MEM[proc][0x40], 0x29C, val); u16 cnt = T1ReadWord(MMU.MMU_MEM[proc][0x40], 0x280); s64 num = 0; s64 den = 1; @@ -1691,22 +1688,18 @@ void FASTCALL MMU_write32(u32 proc, u32 adr, u32 val) { case 0: { - return;// - //num = (s64)(((s32 *)(MMU.MMU_MEM[proc][0x40]))[0x290>>2]); - //den = (s64)(((s32 *)(MMU.MMU_MEM[proc][0x40]))[0x298>>2]); + return; } break; case 1: { - return;// - //num = ((s64*)(MMU.MMU_MEM[proc][0x40]))[0x290>>3]; - //den = (s64)(((s32 *)(MMU.MMU_MEM[proc][0x40]))[0x298>>2]); + return; } break; case 2: { - num = ((s64*)(MMU.MMU_MEM[proc][0x40]))[0x290>>3]; - den = ((s64*)(MMU.MMU_MEM[proc][0x40]))[0x298>>3]; + num = (s64) T1ReadQuad(MMU.MMU_MEM[proc][0x40], 0x290); + den = (s64) T1ReadQuad(MMU.MMU_MEM[proc][0x40], 0x298); } break; default: @@ -1728,63 +1721,60 @@ void FASTCALL MMU_write32(u32 proc, u32 adr, u32 val) DIVLOG("BOUT2 %08X%08X / %08X%08X = %08X%08X\r\n", (u32)(num>>32), (u32)num, (u32)(den>>32), (u32)den, (u32)(res>>32), (u32)res); - ((u32 *)(MMU.MMU_MEM[proc][0x40]))[0x2A0>>2] = (u32)res; - ((u32 *)(MMU.MMU_MEM[proc][0x40]))[0x2A4>>2] = (u32)(res>>32); - ((u32 *)(MMU.MMU_MEM[proc][0x40]))[0x2A8>>2] = (u32)mod; - ((u32 *)(MMU.MMU_MEM[proc][0x40]))[0x2AC>>2] = (u32)(mod>>32); - ((u32 *)(MMU.MMU_MEM[proc][0x40]))[0x280>>2] = cnt; + T1WriteLong(MMU.MMU_MEM[proc][0x40], 0x2A0, (u32) res); + T1WriteLong(MMU.MMU_MEM[proc][0x40], 0x2A4, (u32) (res >> 32)); + T1WriteLong(MMU.MMU_MEM[proc][0x40], 0x2A8, (u32) mod); + T1WriteLong(MMU.MMU_MEM[proc][0x40], 0x2AC, (u32) (mod >> 32)); + T1WriteLong(MMU.MMU_MEM[proc][0x40], 0x280, cnt); } return; case 0x040002B8 : { //execute = FALSE; - ((u32 *)(MMU.MMU_MEM[proc][0x40]))[0x2B8>>2] = val; + T1WriteLong(MMU.MMU_MEM[proc][0x40], 0x2B8, val); u16 cnt = T1ReadWord(MMU.MMU_MEM[proc][0x40], 0x2B0); u64 v = 1; switch(cnt&1) { case 0: - v = (u64)(((u32 *)(MMU.MMU_MEM[proc][0x40]))[0x2B8>>2]); + v = (u64) T1ReadLong(MMU.MMU_MEM[proc][0x40], 0x2B8); break; case 1: return; - //v = ((u64*)(MMU.MMU_MEM[proc][0x40]))[0x2B8>>3]; - //break; } - ((u32 *)(MMU.MMU_MEM[proc][0x40]))[0x2B4>>2] = (u32)sqrt(v); - ((u32 *)(MMU.MMU_MEM[proc][0x40]))[0x2B0>>2] = cnt & 0x7FFF; + T1WriteLong(MMU.MMU_MEM[proc][0x40], 0x2B4, (u32) sqrt(v)); + T1WriteLong(MMU.MMU_MEM[proc][0x40], 0x2B0, cnt & 0x7FFF); SQRTLOG("BOUT1 sqrt(%08X%08X) = %08X\r\n", (u32)(v>>32), (u32)v, - ((u32 *)(MMU.MMU_MEM[proc][0x40]))[0x2B4>>2]); + T1ReadLong(MMU.MMU_MEM[proc][0x40], 0x2B4)); } return; case 0x040002BC : { - ((u32 *)(MMU.MMU_MEM[proc][0x40]))[0x2BC>>2] = val; + T1WriteLong(MMU.MMU_MEM[proc][0x40], 0x2BC, val); u16 cnt = T1ReadWord(MMU.MMU_MEM[proc][0x40], 0x2B0); u64 v = 1; switch(cnt&1) { case 0: return; - //v = (u64)(((u32 *)(MMU.MMU_MEM[proc][0x40]))[0x2B8>>2]); //break; case 1: - v = ((u64*)(MMU.MMU_MEM[proc][0x40]))[0x2B8>>3]; + v = T1ReadQuad(MMU.MMU_MEM[proc][0x40], 0x2B8); break; } - ((u32 *)(MMU.MMU_MEM[proc][0x40]))[0x2B4>>2] = (u32)sqrt(v); - ((u32 *)(MMU.MMU_MEM[proc][0x40]))[0x2B0>>2] = cnt & 0x7FFF; + T1WriteLong(MMU.MMU_MEM[proc][0x40], 0x2B4, (u32) sqrt(v)); + T1WriteLong(MMU.MMU_MEM[proc][0x40], 0x2B0, cnt & 0x7FFF); SQRTLOG("BOUT2 sqrt(%08X%08X) = %08X\r\n", (u32)(v>>32), (u32)v, - ((u32 *)(MMU.MMU_MEM[proc][0x40]))[0x2B4>>2]); + T1ReadLong(MMU.MMU_MEM[proc][0x40], 0x2B4)); } return; case 0x04000180 : { //execute=FALSE; u32 remote = (proc+1)&1; - u32 IPCSYNC_remote = ((u32 *)(MMU.MMU_MEM[remote][0x40]))[0x180>>2]; - ((u32 *)(MMU.MMU_MEM[proc][0x40]))[0x180>>2] = (val&0xFFF0)|((IPCSYNC_remote>>8)&0xF); - ((u32 *)(MMU.MMU_MEM[remote][0x40]))[0x180>>2] = (IPCSYNC_remote&0xFFF0)|((val>>8)&0xF); + u32 IPCSYNC_remote = T1ReadLong(MMU.MMU_MEM[remote][0x40], 0x180); + T1WriteLong(MMU.MMU_MEM[proc][0x40], 0x180, (val&0xFFF0)|((IPCSYNC_remote>>8)&0xF)); + T1WriteLong(MMU.MMU_MEM[remote][0x40], 0x180, (IPCSYNC_remote&0xFFF0)|((val>>8)&0xF)); MMU.reg_IF[remote] |= ((IPCSYNC_remote & (1<<14))<<2) & ((val & (1<<13))<<3);// & (MMU.reg_IME[remote] << 16);// & (MMU.reg_IE[remote] & (1<<16));// } return; @@ -1814,7 +1804,6 @@ void FASTCALL MMU_write32(u32 proc, u32 adr, u32 val) IPCFIFO_CNT_remote = (IPCFIFO_CNT_remote & 0xFCFF) | (MMU.fifos[fifonum].full<<10); T1WriteWord(MMU.MMU_MEM[proc][0x40], 0x184, IPCFIFO_CNT); T1WriteWord(MMU.MMU_MEM[remote][0x40], 0x184, IPCFIFO_CNT_remote); - //((u32 *)(MMU.MMU_MEM[rote][0x40]))[0x214>>2] = (IPCFIFO_CNT_remote & (1<<10))<<8; MMU.reg_IF[remote] |= ((IPCFIFO_CNT_remote & (1<<10))<<8);// & (MMU.reg_IME[remote] << 18);// & (MMU.reg_IE[remote] & 0x40000);// //execute = FALSE; } @@ -1822,11 +1811,11 @@ void FASTCALL MMU_write32(u32 proc, u32 adr, u32 val) return; case 0x040000B8 : //LOG("32 bit dma0 %04X\r\n", val); - DMASrc[proc][0] = ((u32 *)(MMU.MMU_MEM[proc][0x40]))[0xB0>>2]; - DMADst[proc][0] = ((u32 *)(MMU.MMU_MEM[proc][0x40]))[0xB4>>2]; + DMASrc[proc][0] = T1ReadLong(MMU.MMU_MEM[proc][0x40], 0xB0); + DMADst[proc][0] = T1ReadLong(MMU.MMU_MEM[proc][0x40], 0xB4); MMU.DMAStartTime[proc][0] = (proc ? (val>>28) & 0x3 : (val>>27) & 0x7); MMU.DMACrt[proc][0] = val; - ((u32 *)(MMU.MMU_MEM[proc][0x40]))[0xB8>>2]=val; + T1WriteLong(MMU.MMU_MEM[proc][0x40], 0xB8, val); if(MMU.DMAStartTime[proc][0] == 0) MMU_doDMA(proc, 0); #ifdef LOG_DMA2 @@ -1839,11 +1828,11 @@ void FASTCALL MMU_write32(u32 proc, u32 adr, u32 val) return; case 0x040000C4 : //LOG("32 bit dma1 %04X\r\n", val); - DMASrc[proc][1] = ((u32 *)(MMU.MMU_MEM[proc][0x40]))[0xBC>>2]; - DMADst[proc][1] = ((u32 *)(MMU.MMU_MEM[proc][0x40]))[0xC0>>2]; + DMASrc[proc][1] = T1ReadLong(MMU.MMU_MEM[proc][0x40], 0xBC); + DMADst[proc][1] = T1ReadLong(MMU.MMU_MEM[proc][0x40], 0xC0); MMU.DMAStartTime[proc][1] = (proc ? (val>>28) & 0x3 : (val>>27) & 0x7); MMU.DMACrt[proc][1] = val; - ((u32 *)(MMU.MMU_MEM[proc][0x40]))[0xC4>>2]=val; + T1WriteLong(MMU.MMU_MEM[proc][0x40], 0xC4, val); if(MMU.DMAStartTime[proc][1] == 0) MMU_doDMA(proc, 1); #ifdef LOG_DMA2 @@ -1855,11 +1844,11 @@ void FASTCALL MMU_write32(u32 proc, u32 adr, u32 val) return; case 0x040000D0 : //LOG("32 bit dma2 %04X\r\n", val); - DMASrc[proc][2] = ((u32 *)(MMU.MMU_MEM[proc][0x40]))[0xC8>>2]; - DMADst[proc][2] = ((u32 *)(MMU.MMU_MEM[proc][0x40]))[0xCC>>2]; + DMASrc[proc][2] = T1ReadLong(MMU.MMU_MEM[proc][0x40], 0xC8); + DMADst[proc][2] = T1ReadLong(MMU.MMU_MEM[proc][0x40], 0xCC); MMU.DMAStartTime[proc][2] = (proc ? (val>>28) & 0x3 : (val>>27) & 0x7); MMU.DMACrt[proc][2] = val; - ((u32 *)(MMU.MMU_MEM[proc][0x40]))[0xD0>>2]=val; + T1WriteLong(MMU.MMU_MEM[proc][0x40], 0xD0, val); if(MMU.DMAStartTime[proc][2] == 0) MMU_doDMA(proc, 2); #ifdef LOG_DMA2 @@ -1871,11 +1860,11 @@ void FASTCALL MMU_write32(u32 proc, u32 adr, u32 val) return; case 0x040000DC : //LOG("32 bit dma3 %04X\r\n", val); - DMASrc[proc][3] = ((u32 *)(MMU.MMU_MEM[proc][0x40]))[0xD4>>2]; - DMADst[proc][3] = ((u32 *)(MMU.MMU_MEM[proc][0x40]))[0xD8>>2]; + DMASrc[proc][3] = T1ReadLong(MMU.MMU_MEM[proc][0x40], 0xD4); + DMADst[proc][3] = T1ReadLong(MMU.MMU_MEM[proc][0x40], 0xD8); MMU.DMAStartTime[proc][3] = (proc ? (val>>28) & 0x3 : (val>>27) & 0x7); MMU.DMACrt[proc][3] = val; - ((u32 *)(MMU.MMU_MEM[proc][0x40]))[0xDC>>2]=val; + T1WriteLong(MMU.MMU_MEM[proc][0x40], 0xDC, val); if(MMU.DMAStartTime[proc][3] == 0) MMU_doDMA(proc, 3); #ifdef LOG_DMA2 @@ -1903,10 +1892,10 @@ void FASTCALL MMU_write32(u32 proc, u32 adr, u32 val) if(MMU.dscard[proc].adress == 0) { val &= ~CARD_ACTIVATE; - MEM_32(MMU.MMU_MEM[proc], CARD_CR2) = val; + T1WriteLong(MMU.MMU_MEM[proc][(CARD_CR2 >> 20) & 0xff], CARD_CR2 & 0xfff, val); return; } - MEM_32(MMU.MMU_MEM[proc], CARD_CR2) = val; + T1WriteLong(MMU.MMU_MEM[proc][(CARD_CR2 >> 20) & 0xff], CARD_CR2 & 0xfff, val); int i; @@ -1942,32 +1931,31 @@ void FASTCALL MMU_write32(u32 proc, u32 adr, u32 val) GPU_setBGProp(MainScreen.gpu, 0, (val&0xFFFF)); GPU_setBGProp(MainScreen.gpu, 1, (val>>16)); //if((val>>16)==0x400) execute = FALSE; - ((u32 *)ARM9Mem.ARM9_REG)[8>>2] = val; + T1WriteLong(ARM9Mem.ARM9_REG, 8, val); return; case 0x0400000C : GPU_setBGProp(MainScreen.gpu, 2, (val&0xFFFF)); GPU_setBGProp(MainScreen.gpu, 3, (val>>16)); - ((u32 *)ARM9Mem.ARM9_REG)[0xC>>2] = val; + T1WriteLong(ARM9Mem.ARM9_REG, 0xC, val); return; case 0x04001008 : GPU_setBGProp(SubScreen.gpu, 0, (val&0xFFFF)); GPU_setBGProp(SubScreen.gpu, 1, (val>>16)); - ((u32 *)ARM9Mem.ARM9_REG)[0x1008>>2] = val; + T1WriteLong(ARM9Mem.ARM9_REG, 0x1008, val); return; case 0x0400100C : GPU_setBGProp(SubScreen.gpu, 2, (val&0xFFFF)); GPU_setBGProp(SubScreen.gpu, 3, (val>>16)); - ((u32 *)ARM9Mem.ARM9_REG)[0x100C>>2] = val; + T1WriteLong(ARM9Mem.ARM9_REG, 0x100C, val); return; //case 0x21FDFF0 : if(val==0) execute = FALSE; //case 0x21FDFB0 : if(val==0) execute = FALSE; default : - ((u32 *)(MMU.MMU_MEM[proc][0x40]))[(adr&MMU.MMU_MASK[proc][(adr>>20)&0xFF])>>2]=val; + T1WriteLong(MMU.MMU_MEM[proc][0x40], adr & MMU.MMU_MASK[proc][(adr>>20)&0xFF], val); return; } } - ((u32 *)(MMU.MMU_MEM[proc][(adr>>20)&0xFF]))[(adr&MMU.MMU_MASK[proc][(adr>>20)&0xFF])>>2]=val; - + T1WriteLong(MMU.MMU_MEM[proc][(adr>>20)&0xFF], adr&MMU.MMU_MASK[proc][(adr>>20)&0xFF], val); } @@ -1977,7 +1965,7 @@ void FASTCALL MMU_doDMA(u32 proc, u32 num) u32 dst = DMADst[proc][num]; if(src==dst) { - ((u32 *)(MMU.MMU_MEM[proc][0x40]))[(0xB8 + (0xC*num))>>2] &= 0x7FFFFFFF; + T1WriteLong(MMU.MMU_MEM[proc][0x40], 0xB8 + (0xC*num), T1ReadLong(MMU.MMU_MEM[proc][0x40], 0xB8 + (0xC*num)) & 0x7FFFFFFF); return; } @@ -2198,7 +2186,4 @@ void FASTCALL MMU_doDMA(u32 proc, u32 num) } break; } - - //MMU.DMACrt[proc][num] &= 0x7FFFFFFF; - //((u32 *)(MMU.MMU_MEM[proc][0x40]))[(0xB8 + (0xC*num))>>2] = MMU.DMACrt[proc][num]; } diff --git a/desmume/src/MMU.h b/desmume/src/MMU.h index 94162de91..7137e67c4 100644 --- a/desmume/src/MMU.h +++ b/desmume/src/MMU.h @@ -37,12 +37,9 @@ extern char szRomPath[512]; /* theses macros are designed for reading/writing in memory (m is a pointer to memory, like MMU.MMU_MEM[proc], and a is an adress, like 0x04000000 */ #define MEM_8(m, a) (((u8*)(m[((a)>>20)&0xff]))[((a)&0xfff)]) -#define MEM_32(m, a) (((u32*)(m[((a)>>20)&0xff]))[((a)&0xfff)>>2]) /* theses ones for reading in rom data */ #define ROM_8(m, a) (((u8*)(m))[(a)]) -#define ROM_32(m, a) (((u32*)(m))[(a)>>2]) - #define IPCFIFO 0 diff --git a/desmume/src/NDSSystem.c b/desmume/src/NDSSystem.c index 7a2c7ebf0..8b54edce1 100644 --- a/desmume/src/NDSSystem.c +++ b/desmume/src/NDSSystem.c @@ -21,6 +21,7 @@ #include "NDSSystem.h" #include +#include NDSSystem nds; @@ -86,24 +87,24 @@ BOOL NDS_SetROM(u8 * rom, u32 mask) NDS_header * header = (NDS_header *)MMU.CART_ROM; - u32 src = header->ARM9src>>2; + u32 src = header->ARM9src; u32 dst = header->ARM9cpy; for(i = 0; i < (header->ARM9binSize>>2); ++i) { - MMU_writeWord(0, dst, ((u32 *)rom)[src]); - dst+=4; - ++src; + MMU_writeWord(0, dst, T1ReadLong(rom, src)); + dst += 4; + src += 4; } - src = header->ARM7src>>2; + src = header->ARM7src; dst = header->ARM7cpy; for(i = 0; i < (header->ARM7binSize>>2); ++i) { - MMU_writeWord(1, dst, ((u32 *)rom)[src]); - dst+=4; - ++src; + MMU_writeWord(1, dst, T1ReadLong(rom, src)); + dst += 4; + src += 4; } armcpu_init(&NDS_ARM7, header->ARM7exe); armcpu_init(&NDS_ARM9, header->ARM9exe); diff --git a/desmume/src/NDSSystem.h b/desmume/src/NDSSystem.h index 97a972612..b457934c7 100644 --- a/desmume/src/NDSSystem.h +++ b/desmume/src/NDSSystem.h @@ -39,8 +39,6 @@ extern BOOL click; //#define LOG_ARM9 //#define LOG_ARM7 -#define ARM9_IO_REGS ((u32 *)ARM9Mem.ARM9_REG) -#define ARM7_IO_REGS ((u32 *)MMU.ARM7_REG) #define REG_DIVCNT (0x280>>2) #define REG_DIV_NUMER_L (0x290>>2) #define REG_DIV_NUMER_H (0x294>>2) @@ -743,63 +741,63 @@ int NDS_LoadFirmware(const char *filename); if((MMU.DMAing[0][0])&&(MMU.DMACycle[0][0]<=nds.cycles)) { - ((u32 *)ARM9Mem.ARM9_REG)[(0xB8 + (0xC*0))>>2] &= 0x7FFFFFFF; + T1WriteLong(ARM9Mem.ARM9_REG, 0xB8 + (0xC*0), T1ReadLong(ARM9Mem.ARM9_REG, 0xB8 + (0xC*0)) & 0x7FFFFFFF); if((MMU.DMACrt[0][0])&(1<<30)) NDS_makeARM9Int(8); MMU.DMAing[0][0] = FALSE; } if((MMU.DMAing[0][1])&&(MMU.DMACycle[0][1]<=nds.cycles)) { - ((u32 *)ARM9Mem.ARM9_REG)[(0xB8 + (0xC*1))>>2] &= 0x7FFFFFFF; + T1WriteLong(ARM9Mem.ARM9_REG, 0xB8 + (0xC*1), T1ReadLong(ARM9Mem.ARM9_REG, 0xB8 + (0xC*1)) & 0x7FFFFFFF); if((MMU.DMACrt[0][1])&(1<<30)) NDS_makeARM9Int(9); MMU.DMAing[0][1] = FALSE; } if((MMU.DMAing[0][2])&&(MMU.DMACycle[0][2]<=nds.cycles)) { - ((u32 *)ARM9Mem.ARM9_REG)[(0xB8 + (0xC*2))>>2] &= 0x7FFFFFFF; + T1WriteLong(ARM9Mem.ARM9_REG, 0xB8 + (0xC*2), T1ReadLong(ARM9Mem.ARM9_REG, 0xB8 + (0xC*2)) & 0x7FFFFFFF); if((MMU.DMACrt[0][2])&(1<<30)) NDS_makeARM9Int(10); MMU.DMAing[0][2] = FALSE; } if((MMU.DMAing[0][3])&&(MMU.DMACycle[0][3]<=nds.cycles)) { - ((u32 *)ARM9Mem.ARM9_REG)[(0xB8 + (0xC*3))>>2] &= 0x7FFFFFFF; + T1WriteLong(ARM9Mem.ARM9_REG, 0xB8 + (0xC*3), T1ReadLong(ARM9Mem.ARM9_REG, 0xB8 + (0xC*3)) & 0x7FFFFFFF); if((MMU.DMACrt[0][3])&(1<<30)) NDS_makeARM9Int(11); MMU.DMAing[0][3] = FALSE; } if((MMU.DMAing[1][0])&&(MMU.DMACycle[1][0]<=nds.cycles)) { - ((u32 *)MMU.ARM7_REG)[(0xB8 + (0xC*0))>>2] &= 0x7FFFFFFF; + T1WriteLong(MMU.ARM7_REG, 0xB8 + (0xC*0), T1ReadLong(MMU.ARM7_REG, 0xB8 + (0xC*0)) & 0x7FFFFFFF); if((MMU.DMACrt[1][0])&(1<<30)) NDS_makeARM7Int(8); MMU.DMAing[1][0] = FALSE; } if((MMU.DMAing[1][1])&&(MMU.DMACycle[1][1]<=nds.cycles)) { - ((u32 *)MMU.ARM7_REG)[(0xB8 + (0xC*1))>>2] &= 0x7FFFFFFF; + T1WriteLong(MMU.ARM7_REG, 0xB8 + (0xC*1), T1ReadLong(MMU.ARM7_REG, 0xB8 + (0xC*1)) & 0x7FFFFFFF); if((MMU.DMACrt[1][1])&(1<<30)) NDS_makeARM7Int(9); MMU.DMAing[1][1] = FALSE; } if((MMU.DMAing[1][2])&&(MMU.DMACycle[1][2]<=nds.cycles)) { - ((u32 *)MMU.ARM7_REG)[(0xB8 + (0xC*2))>>2] &= 0x7FFFFFFF; + T1WriteLong(MMU.ARM7_REG, 0xB8 + (0xC*2), T1ReadLong(MMU.ARM7_REG, 0xB8 + (0xC*2)) & 0x7FFFFFFF); if((MMU.DMACrt[1][2])&(1<<30)) NDS_makeARM7Int(10); MMU.DMAing[1][2] = FALSE; } if((MMU.DMAing[1][3])&&(MMU.DMACycle[1][3]<=nds.cycles)) { - ((u32 *)MMU.ARM7_REG)[(0xB8 + (0xC*3))>>2] &= 0x7FFFFFFF; + T1WriteLong(MMU.ARM7_REG, 0xB8 + (0xC*3), T1ReadLong(MMU.ARM7_REG, 0xB8 + (0xC*3)) & 0x7FFFFFFF); if((MMU.DMACrt[1][3])&(1<<30)) NDS_makeARM7Int(11); MMU.DMAing[1][3] = FALSE; } if((MMU.reg_IF[0]&MMU.reg_IE[0]) && (MMU.reg_IME[0])) //if(NDS_ARM9.irqExeption()) - if(armcpu_irqExeption(&NDS_ARM9)) + if(armcpu_irqExeption(&NDS_ARM9)) { nds.ARM9Cycle = nds.cycles; } diff --git a/desmume/src/cflash.c b/desmume/src/cflash.c index 453833ab5..127d107e4 100644 --- a/desmume/src/cflash.c +++ b/desmume/src/cflash.c @@ -271,9 +271,6 @@ BOOL cflash_build_fat() { list_files(sRomPath); - //wsprintf(buffer,"Found %d files\n",numFiles); - //WriteConsole(hStdOut,buffer,lstrlen(buffer),(u32*)&dummy,NULL); - k = 0; clusterNum = rootCluster = (SECRESV + SECPERFAT)/SECPERCLUS; numClusters = 0; @@ -548,9 +545,6 @@ unsigned int cflash_read(unsigned int address) { int i; u32 cluster,cluster2,cluster3,fileLBA; - //wsprintf(buffer,"Reading from %08X\n",address); - //WriteConsole(hStdOut,buffer,lstrlen(buffer),(u32*)&dummy,NULL); - if (address == CF_REG_STS) { s = cf_reg_sts; return s; @@ -563,12 +557,12 @@ unsigned int cflash_read(unsigned int address) { // Reading from the MBR if (currLBA < 512) { p = (unsigned char*)&MBR; - s = *(u16 *)(p + currLBA); + s = T1ReadWord(p, currLBA); // Reading the FAT } else if ((currLBA >= filesysFAT*512) && (currLBA < filesysRootDir*512)) { p = (unsigned char*)&FAT16[0]; - s = *(u16 *)(p + (currLBA-filesysFAT*512)); + s = T1ReadWord(p, currLBA - filesysFAT * 512); // Reading directory entries } else if ((currLBA >= filesysRootDir*512) && @@ -578,13 +572,13 @@ unsigned int cflash_read(unsigned int address) { if (i < (dirEntriesInCluster[cluster3]*32)) { p = (unsigned char*)dirEntryPtr[cluster3]; - s = *(u16 *)(p + i); + s = T1ReadWord(p, i); } else { i /= 32; i -= dirEntriesInCluster[cluster3]; if ((i>=0)&&(ivbox), ecKey,TRUE, FALSE, 0); } @@ -551,7 +551,7 @@ void Edit_Controls(GtkWidget* widget, gpointer data) void Modify_ScreenCoeff(GtkWidget* widget, gpointer data) { - int Size = (int)data; + int Size = GPOINTER_TO_INT(data); gtk_drawing_area_size(GTK_DRAWING_AREA(pDrawingArea), 256 * Size, 384 * Size); gtk_widget_set_usize (pDrawingArea, 256 * Size, 384 * Size); @@ -888,7 +888,7 @@ int SelectFirmwareFile_Load(GtkWidget *w, gpointer data) void Modify_Frameskip(GtkWidget *widget, gpointer data) { - Frameskip = (int)data; + Frameskip = GPOINTER_TO_INT(data); } /////////////////////////////// TOOLS MANAGEMENT /////////////////////////////// @@ -902,7 +902,7 @@ BOOL *dTools_running; void Start_dTool(GtkWidget *widget, gpointer data) { - int tool = (int)data; + int tool = GPOINTER_TO_INT(data); if(dTools_running[tool]) return; @@ -1079,7 +1079,7 @@ int main (int argc, char *argv[]) sprintf(frameskipRadio_buf, "%d", i); if(i>0) mFrameskip_Radio[i] = gtk_radio_menu_item_new_with_label_from_widget(GTK_RADIO_MENU_ITEM(mFrameskip_Radio[i-1]), frameskipRadio_buf); else mFrameskip_Radio[i] = gtk_radio_menu_item_new_with_label(NULL, frameskipRadio_buf); - g_signal_connect(G_OBJECT(mFrameskip_Radio[i]), "activate", G_CALLBACK(Modify_Frameskip), (gpointer)i); + g_signal_connect(G_OBJECT(mFrameskip_Radio[i]), "activate", G_CALLBACK(Modify_Frameskip), GINT_TO_POINTER(i)); gtk_menu_shell_append(GTK_MENU_SHELL(mFrameskip), mFrameskip_Radio[i]); } gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(mFrameskip_Radio[0]), TRUE); @@ -1100,7 +1100,7 @@ int main (int argc, char *argv[]) sprintf(sizeRadio_buf, "x%d", i); if(i>1) mSize_Radio[i] = gtk_radio_menu_item_new_with_label_from_widget(GTK_RADIO_MENU_ITEM(mSize_Radio[i-1]), sizeRadio_buf); else mSize_Radio[i] = gtk_radio_menu_item_new_with_label(NULL, sizeRadio_buf); - g_signal_connect(G_OBJECT(mSize_Radio[i]), "activate", G_CALLBACK(Modify_ScreenCoeff), (gpointer)i); + g_signal_connect(G_OBJECT(mSize_Radio[i]), "activate", G_CALLBACK(Modify_ScreenCoeff), GINT_TO_POINTER(i)); gtk_menu_shell_append(GTK_MENU_SHELL(mSize), mSize_Radio[i]); } gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(mFrameskip_Radio[0]), TRUE); @@ -1154,7 +1154,7 @@ int main (int argc, char *argv[]) for(i = 0; i < dTools_list_size; i++) { pMenuItem = gtk_menu_item_new_with_label(dTools_list[i]->name); - g_signal_connect(G_OBJECT(pMenuItem), "activate", G_CALLBACK(Start_dTool), (gpointer)i); + g_signal_connect(G_OBJECT(pMenuItem), "activate", G_CALLBACK(Start_dTool), GINT_TO_POINTER(i)); gtk_menu_shell_append(GTK_MENU_SHELL(pMenu), pMenuItem); } diff --git a/desmume/src/gtk/tools/ioregsView.c b/desmume/src/gtk/tools/ioregsView.c index d0888a565..f579b5935 100644 --- a/desmume/src/gtk/tools/ioregsView.c +++ b/desmume/src/gtk/tools/ioregsView.c @@ -344,7 +344,7 @@ static void _clearContainer(GtkWidget *widget, gpointer data) static void selected_reg(GtkWidget* widget, gpointer data) { - int c = (int)data; + int c = GPOINTER_TO_INT(data); guint active = gtk_combo_box_get_active(GTK_COMBO_BOX(widget)); @@ -389,7 +389,8 @@ static void close() static void _closeOne(GtkWidget *widget, gpointer data) { - int c = (int)data; + int c = GPOINTER_TO_INT(data); + CPUS[c] = FALSE; if(c == 0 && !CPUS[1]) close(); if(c == 1 && !CPUS[0]) close(); @@ -424,7 +425,7 @@ static void open(int ID) mWin[c]= gtk_window_new(GTK_WINDOW_TOPLEVEL); if(c == 0) gtk_window_set_title(GTK_WINDOW(mWin[c]), TOOL_NAME " : ARM9"); else gtk_window_set_title(GTK_WINDOW(mWin[c]), TOOL_NAME " : ARM7"); - g_signal_connect(G_OBJECT(mWin[c]), "destroy", G_CALLBACK(&_closeOne), (gpointer)c); + g_signal_connect(G_OBJECT(mWin[c]), "destroy", G_CALLBACK(&_closeOne), GINT_TO_POINTER(c)); mVbox0[c] = gtk_vbox_new(FALSE, 0); gtk_container_add(GTK_CONTAINER(mWin[c]), mVbox0[c]); @@ -440,11 +441,11 @@ static void open(int ID) } gtk_combo_box_set_active(GTK_COMBO_BOX(mIoRegCombo[c]), 0); - g_signal_connect(G_OBJECT(mIoRegCombo[c]), "changed", G_CALLBACK(selected_reg), (gpointer)c); + g_signal_connect(G_OBJECT(mIoRegCombo[c]), "changed", G_CALLBACK(selected_reg), GINT_TO_POINTER(c)); gtk_box_pack_start(GTK_BOX(mVbox0[c]), mIoRegCombo[c], FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(mVbox0[c]), mRegInfos[c], FALSE, FALSE, 0); - selected_reg(mIoRegCombo[c], (gpointer)c); + selected_reg(mIoRegCombo[c], GINT_TO_POINTER(c)); gtk_widget_show_all(mWin[c]); } diff --git a/desmume/src/mem.h b/desmume/src/mem.h index d34a66d0e..a428009c2 100644 --- a/desmume/src/mem.h +++ b/desmume/src/mem.h @@ -50,6 +50,18 @@ static INLINE u32 T1ReadLong(u8 * mem, u32 addr) #endif } +static INLINE u64 T1ReadQuad(u8 * mem, u32 addr) +{ +#ifdef WORDS_BIGENDIAN + return (mem[addr] << 56 | mem[addr + 1] << 48 | + mem[addr + 2] << 40 | mem[addr + 3] << 32 | + mem[addr + 4] << 24 | mem[addr + 5] << 16 | + mem[addr + 6] << 8 | mem[addr + 7]); +#else + return *((u64 *) (mem + addr)); +#endif +} + static INLINE void T1WriteByte(u8 * mem, u32 addr, u8 val) { mem[addr] = val;