diff options
author | Nebuleon Fumika | 2013-02-08 05:50:22 -0500 |
---|---|---|
committer | Nebuleon Fumika | 2013-02-08 05:50:22 -0500 |
commit | 927d456306672110870eb3386742c1c1ef8eb4f6 (patch) | |
tree | 509da9ac1727570b02572068aefb9cdf102ad75b /source/memmap.cpp | |
parent | 433749b6ef1e2b070755c3bb7fc0d81b5ecaa7b1 (diff) | |
parent | d4fcf2697c9a45594e3ee0b8bf82e480ddd0b69b (diff) | |
download | snesemu-927d456306672110870eb3386742c1c1ef8eb4f6.tar.gz snesemu-927d456306672110870eb3386742c1c1ef8eb4f6.tar.bz2 snesemu-927d456306672110870eb3386742c1c1ef8eb4f6.zip |
Merge branch 'master' into 8bitsound
Conflicts:
source/nds/entry.cpp
Diffstat (limited to 'source/memmap.cpp')
-rw-r--r-- | source/memmap.cpp | 161 |
1 files changed, 135 insertions, 26 deletions
diff --git a/source/memmap.cpp b/source/memmap.cpp index 04bc621..20110f9 100644 --- a/source/memmap.cpp +++ b/source/memmap.cpp @@ -113,6 +113,12 @@ #include "unzip/unzip.h" +#ifdef DS2_DMA +#include "ds2_cpu.h" +#include "ds2_dma.h" +#include "dma_adj.h" +#endif + #ifdef __W32_HEAP #include <malloc.h> #endif @@ -214,6 +220,7 @@ void S9xDeinterleaveType1(int TotalFileSize, uint8 * base) blocks [i * 2] = i + nblocks; blocks [i * 2 + 1] = i; } + // DS2 DMA notes: base may or may not be 32-byte aligned uint8 *tmp = (uint8 *) malloc (0x8000); if (tmp) { @@ -223,10 +230,14 @@ void S9xDeinterleaveType1(int TotalFileSize, uint8 * base) { if (blocks [j] == i) { - memmove (tmp, &base [blocks [j] * 0x8000], 0x8000); - memmove (&base [blocks [j] * 0x8000], + // memmove converted: Different mallocs [Neb] + memcpy (tmp, &base [blocks [j] * 0x8000], 0x8000); + // memmove converted: Different addresses, or identical for blocks[i] == blocks[j] [Neb] + // DS2 DMA notes: Don't do DMA at all if blocks[i] == blocks[j] + memcpy (&base [blocks [j] * 0x8000], &base [blocks [i] * 0x8000], 0x8000); - memmove (&base [blocks [i] * 0x8000], tmp, 0x8000); + // memmove converted: Different mallocs [Neb] + memcpy (&base [blocks [i] * 0x8000], tmp, 0x8000); uint8 b = blocks [j]; blocks [j] = blocks [i]; blocks [i] = b; @@ -250,13 +261,18 @@ void S9xDeinterleaveGD24(int TotalFileSize, uint8 * base) SET_UI_COLOR(0,255,255); } + // DS2 DMA notes: base may or may not be 32-byte aligned uint8 *tmp = (uint8 *) malloc (0x80000); if (tmp) { - memmove(tmp, &base[0x180000], 0x80000); - memmove(&base[0x180000], &base[0x200000], 0x80000); - memmove(&base[0x200000], &base[0x280000], 0x80000); - memmove(&base[0x280000], tmp, 0x80000); + // memmove converted: Different mallocs [Neb] + memcpy(tmp, &base[0x180000], 0x80000); + // memmove converted: Different addresses [Neb] + memcpy(&base[0x180000], &base[0x200000], 0x80000); + // memmove converted: Different addresses [Neb] + memcpy(&base[0x200000], &base[0x280000], 0x80000); + // memmove converted: Different mallocs [Neb] + memcpy(&base[0x280000], tmp, 0x80000); free ((char *) tmp); S9xDeinterleaveType1(TotalFileSize, base); @@ -399,14 +415,22 @@ char *CMemory::Safe (const char *s) /**********************************************************************************************/ bool8 CMemory::Init () { + // DS2 DMA notes: These would do well to be allocated with 32 extra bytes + // so they can be 32-byte aligned. [Neb] RAM = (uint8 *) malloc (0x20000); SRAM = (uint8 *) malloc (0x20000); VRAM = (uint8 *) malloc (0x10000); +#ifdef DS2_DMA + ROM = (uint8 *) AlignedMalloc (MAX_ROM_SIZE + 0x200 + 0x8000, 32, &PtrAdj.ROM); +#else ROM = (uint8 *) malloc (MAX_ROM_SIZE + 0x200 + 0x8000); +#endif memset (RAM, 0, 0x20000); memset (SRAM, 0, 0x20000); memset (VRAM, 0, 0x10000); - memset (ROM, 0, MAX_ROM_SIZE + 0x200 + 0x8000); + // This needs to be initialised with a ROM first anyway, so don't + // bother memsetting. [Neb] + // memset (ROM, 0, MAX_ROM_SIZE + 0x200 + 0x8000); BSRAM = (uint8 *) malloc (0x80000); memset (BSRAM, 0, 0x80000); @@ -437,9 +461,9 @@ bool8 CMemory::Init () // Add 0x8000 to ROM image pointer to stop SuperFX code accessing // unallocated memory (can cause crash on some ports). - ROM += 0x8000; + ROM += 0x8000; // still 32-byte aligned - C4RAM = ROM + 0x400000 + 8192 * 8; + C4RAM = ROM + 0x400000 + 8192 * 8; // still 32-byte aligned ::ROM = ROM; ::SRAM = SRAM; ::RegRAM = FillRAM; @@ -453,7 +477,7 @@ bool8 CMemory::Init () SuperFX.nRomBanks = (2 * 1024 * 1024) / (32 * 1024); SuperFX.pvRom = (uint8 *) ROM; #endif - + ZeroMemory (IPPU.TileCache [TILE_2BIT], MAX_2BIT_TILES * 128); ZeroMemory (IPPU.TileCache [TILE_4BIT], MAX_4BIT_TILES * 128); ZeroMemory (IPPU.TileCache [TILE_8BIT], MAX_8BIT_TILES * 128); @@ -493,7 +517,11 @@ void CMemory::Deinit () if (ROM) { ROM -= 0x8000; +#ifdef DS2_RAM + AlignedFree ((char *) ROM, PtrAdj.ROM); +#else free ((char *) ROM); +#endif ROM = NULL; } @@ -627,7 +655,21 @@ again: ((hi_score > lo_score && ScoreHiROM (TRUE) > hi_score) || (hi_score <= lo_score && ScoreLoROM (TRUE) > lo_score))) { +#ifdef DS2_DMA + __dcache_writeback_all(); + { + unsigned int i; + for (i = 0; i < TotalFileSize; i += 512) + { + ds2_DMAcopy_32Byte (2 /* channel: emu internal */, Memory.ROM + i, Memory.ROM + i + 512, 512); + ds2_DMA_wait(2); + ds2_DMA_stop(2); + } + } +#else + // memmove required: Overlapping addresses [Neb] memmove (Memory.ROM, Memory.ROM + 512, TotalFileSize - 512); +#endif TotalFileSize -= 512; S9xMessage (S9X_INFO, S9X_HEADER_WARNING, "Try specifying the -nhd command line option if the game doesn't work\n"); @@ -636,7 +678,7 @@ again: orig_lo_score = lo_score = ScoreLoROM (FALSE); } - CalculatedSize = (TotalFileSize / 0x2000) * 0x2000; + CalculatedSize = TotalFileSize & ~0x1FFF; // round down to lower 0x2000 ZeroMemory (ROM + CalculatedSize, MAX_ROM_SIZE - CalculatedSize); if(CalculatedSize >0x400000&& @@ -871,6 +913,7 @@ uint32 CMemory::FileLoader (uint8* buffer, const char* filename, int32 maxsize) _makepath (fname, drive, dir, name, ext); #ifdef __WIN32__ + // memmove required: Overlapping addresses [Neb] memmove (&ext [0], &ext[1], 4); #endif @@ -936,12 +979,27 @@ uint32 CMemory::FileLoader (uint8* buffer, const char* filename, int32 maxsize) FileSize = fread (ptr, 1, maxsize + 0x200 - (ptr - ROM), ROMFile); fclose (ROMFile); - int calc_size = (FileSize / 0x2000) * 0x2000; + int calc_size = FileSize & ~0x1FFF; // round to the lower 0x2000 if ((FileSize - calc_size == 512 && !Settings.ForceNoHeader) || Settings.ForceHeader) { + // memmove required: Overlapping addresses [Neb] + // DS2 DMA notes: Can be split into 512-byte DMA blocks [Neb] +#ifdef DS2_DMA + __dcache_writeback_all(); + { + unsigned int i; + for (i = 0; i < calc_size; i += 512) + { + ds2_DMAcopy_32Byte (2 /* channel: emu internal */, ptr + i, ptr + i + 512, 512); + ds2_DMA_wait(2); + ds2_DMA_stop(2); + } + } +#else memmove (ptr, ptr + 512, calc_size); +#endif HeaderCount++; FileSize -= 512; } @@ -958,6 +1016,7 @@ uint32 CMemory::FileLoader (uint8* buffer, const char* filename, int32 maxsize) more = TRUE; ext [0]++; #ifdef __WIN32__ + // memmove required: Overlapping addresses [Neb] memmove (&ext [1], &ext [0], 4); ext [0] = '.'; #endif @@ -972,6 +1031,7 @@ uint32 CMemory::FileLoader (uint8* buffer, const char* filename, int32 maxsize) more = TRUE; name [len - 1]++; #ifdef __WIN32__ + // memmove required: Overlapping addresses [Neb] memmove (&ext [1], &ext [0], 4); ext [0] = '.'; #endif @@ -1180,21 +1240,48 @@ void S9xDeinterleaveType2 (bool8 reset) blocks [i] = (i & ~0xF) | ((i & 3) << 2) | ((i & 12) >> 2); } - + +#ifdef DS2_DMA + unsigned int TmpAdj; + uint8 *tmp = (uint8 *) AlignedMalloc (0x10000, 32, &TmpAdj); +#else uint8 *tmp = (uint8 *) malloc (0x10000); +#endif if (tmp) { +#ifdef DS2_DMA + __dcache_writeback_all(); +#endif for (i = 0; i < nblocks * 2; i++) { for (int j = i; j < nblocks * 2; j++) { if (blocks [j] == i) { - memmove (tmp, &Memory.ROM [blocks [j] * 0x10000], 0x10000); - memmove (&Memory.ROM [blocks [j] * 0x10000], +#ifdef DS2_DMA + ds2_DMAcopy_32Byte (2 /* channel: emu internal */, tmp, &Memory.ROM [blocks [j] * 0x10000], 0x10000); + ds2_DMA_wait(2); + ds2_DMA_stop(2); + + ds2_DMAcopy_32Byte (2 /* channel: emu internal */, &Memory.ROM [blocks [j] * 0x10000], &Memory.ROM [blocks [i] * 0x10000], 0x10000); - memmove (&Memory.ROM [blocks [i] * 0x10000], tmp, 0x10000); + ds2_DMA_wait(2); + ds2_DMA_stop(2); + + ds2_DMAcopy_32Byte (2 /* channel: emu internal */, &Memory.ROM [blocks [i] * 0x10000], tmp, 0x10000); + ds2_DMA_wait(2); + ds2_DMA_stop(2); +#else + // memmove converted: Different mallocs [Neb] + memcpy (tmp, &Memory.ROM [blocks [j] * 0x10000], 0x10000); + + // memmove converted: Different addresses, or identical if blocks[i] == blocks[j] [Neb] + memcpy (&Memory.ROM [blocks [j] * 0x10000], + &Memory.ROM [blocks [i] * 0x10000], 0x10000); + // memmove converted: Different mallocs [Neb] + memcpy (&Memory.ROM [blocks [i] * 0x10000], tmp, 0x10000); +#endif uint8 b = blocks [j]; blocks [j] = blocks [i]; blocks [i] = b; @@ -1605,6 +1692,7 @@ bool8 CMemory::LoadSRAM (const char *filename) if (len - size == 512) { // S-RAM file has a header - remove it + // memmove required: Overlapping addresses [Neb] memmove (::SRAM, ::SRAM + 512, size); } if (len == size + SRTC_SRAM_PAD) @@ -1705,7 +1793,8 @@ void CMemory::ResetSpeedMap() void CMemory::WriteProtectROM () { - memmove ((void *) WriteMap, (void *) Map, sizeof (Map)); + // memmove converted: Different mallocs [Neb] + memcpy ((void *) WriteMap, (void *) Map, sizeof (Map)); for (int c = 0; c < 0x1000; c++) { if (BlockIsROM [c]) @@ -2543,10 +2632,24 @@ void CMemory::SuperFXROMMap () // Replicate the first 2Mb of the ROM at ROM + 2MB such that each 32K // block is repeated twice in each 64K block. +#ifdef DS2_DMA + __dcache_writeback_all(); +#endif for (c = 0; c < 64; c++) { - memmove (&ROM [0x200000 + c * 0x10000], &ROM [c * 0x8000], 0x8000); - memmove (&ROM [0x208000 + c * 0x10000], &ROM [c * 0x8000], 0x8000); +#ifdef DS2_DMA + ds2_DMAcopy_32Byte(2 /* channel: emu internal */, &ROM [0x200000 + c * 0x10000], &ROM [c * 0x8000], 0x8000); + ds2_DMAcopy_32Byte(3 /* channel: emu internal 2 */, &ROM [0x208000 + c * 0x10000], &ROM [c * 0x8000], 0x8000); + ds2_DMA_wait(2); + ds2_DMA_wait(3); + ds2_DMA_stop(2); + ds2_DMA_stop(3); +#else + // memmove converted: Different addresses [Neb] + memcpy (&ROM [0x200000 + c * 0x10000], &ROM [c * 0x8000], 0x8000); + // memmove converted: Different addresses [Neb] + memcpy (&ROM [0x208000 + c * 0x10000], &ROM [c * 0x8000], 0x8000); +#endif } WriteProtectROM (); @@ -2612,8 +2715,10 @@ void CMemory::SA1ROMMap () WriteProtectROM (); // Now copy the map and correct it for the SA1 CPU. - memmove ((void *) SA1.WriteMap, (void *) WriteMap, sizeof (WriteMap)); - memmove ((void *) SA1.Map, (void *) Map, sizeof (Map)); + // memmove converted: Different mallocs [Neb] + memcpy ((void *) SA1.WriteMap, (void *) WriteMap, sizeof (WriteMap)); + // memmove converted: Different mallocs [Neb] + memcpy ((void *) SA1.Map, (void *) Map, sizeof (Map)); // Banks 00->3f and 80->bf for (c = 0; c < 0x400; c += 16) @@ -3025,8 +3130,10 @@ void CMemory::GNextROMMap () WriteProtectROM (); // Now copy the map and correct it for the SA1 CPU. - memmove ((void *) SA1.WriteMap, (void *) WriteMap, sizeof (WriteMap)); - memmove ((void *) SA1.Map, (void *) Map, sizeof (Map)); + // memmove converted: Different mallocs [Neb] + memcpy ((void *) SA1.WriteMap, (void *) WriteMap, sizeof (WriteMap)); + // memmove converted: Different mallocs [Neb] + memcpy ((void *) SA1.Map, (void *) Map, sizeof (Map)); // Banks 00->3f and 80->bf for (c = 0; c < 0x400; c += 16) @@ -4385,9 +4492,11 @@ void CMemory::ParseSNESHeader(uint8* RomHeader) ROMChecksum = RomHeader [0x2e] + (RomHeader [0x2f] << 8); ROMComplementChecksum = RomHeader [0x2c] + (RomHeader [0x2d] << 8); ROMRegion= RomHeader[0x29]; - memmove (ROMId, &RomHeader [0x2], 4); + // memmove converted: Different mallocs [Neb] + memcpy (ROMId, &RomHeader [0x2], 4); if(RomHeader[0x2A]==0x33) - memmove (CompanyId, &RomHeader [0], 2); + // memmove converted: Different mallocs [Neb] + memcpy (CompanyId, &RomHeader [0], 2); else sprintf(CompanyId, "%02X", RomHeader[0x2A]); } |