diff options
author | mwksoul | 2015-02-22 16:02:44 +0000 |
---|---|---|
committer | mwksoul | 2015-02-22 16:02:44 +0000 |
commit | 1f2818bdd38cc225faa840e1aca100866e515046 (patch) | |
tree | 7381b2d03f7294823ea253a97a0fb4638051e7f5 /source | |
parent | 7114688cf0f5707768135ec05184635b34d54f79 (diff) | |
download | snes9x2005-1f2818bdd38cc225faa840e1aca100866e515046.tar.gz snes9x2005-1f2818bdd38cc225faa840e1aca100866e515046.tar.bz2 snes9x2005-1f2818bdd38cc225faa840e1aca100866e515046.zip |
Backported S-DD1 emulation.
Diffstat (limited to 'source')
-rw-r--r-- | source/dma.c | 119 | ||||
-rw-r--r-- | source/memmap.c | 8 | ||||
-rw-r--r-- | source/sdd1.c | 55 | ||||
-rw-r--r-- | source/sdd1.h | 4 | ||||
-rw-r--r-- | source/sdd1emu.c | 112 | ||||
-rw-r--r-- | source/sdd1emu.h | 3 | ||||
-rw-r--r-- | source/snes9x.h | 1 |
7 files changed, 14 insertions, 288 deletions
diff --git a/source/dma.c b/source/dma.c index 8a87868..9ba746c 100644 --- a/source/dma.c +++ b/source/dma.c @@ -107,7 +107,7 @@ #endif #ifdef SDD1_DECOMP -uint8_t buffer[0x10000]; +static uint8_t sdd1_decode_buffer[0x10000]; #endif extern int HDMA_ModeByteCounts [8]; @@ -149,6 +149,7 @@ void S9xDoDMA(uint8_t Channel) int count = d->TransferBytes; + // Prepare for custom chip DMA if (count == 0) count = 0x10000; @@ -171,124 +172,28 @@ void S9xDoDMA(uint8_t Channel) FLUSH_REDRAW(); break; } + // S-DD1 +#ifdef SDD1_DECOMP if (Settings.SDD1) { if (d->AAddressFixed && Memory.FillRAM [0x4801] > 0) { - // Hacky support for pre-decompressed S-DD1 data + // XXX: Should probably verify that we're DMAing from ROM? + // And somewhere we should make sure we're not running across a mapping boundary too. inc = !d->AAddressDecrement ? 1 : -1; - uint32_t address = (((d->ABank << 16) | d->AAddress) & 0xfffff) << 4; - - address |= Memory.FillRAM [0x4804 + ((d->ABank - 0xc0) >> 4)]; -#ifdef SDD1_DECOMP - if (Settings.SDD1Pack) + uint8_t *in_ptr = GetBasePointer(((d->ABank << 16) | d->AAddress)); + if (in_ptr) { - uint8_t* in_ptr = GetBasePointer(((d->ABank << 16) | d->AAddress)); - in_ptr += d->AAddress; - - SDD1_decompress(buffer, in_ptr, d->TransferBytes); - in_sdd1_dma = buffer; -#ifdef SDD1_VERIFY - void* ptr = bsearch(&address, Memory.SDD1Index, - Memory.SDD1Entries, 12, S9xCompareSDD1IndexEntries); - if (memcmp(buffer, ptr, d->TransferBytes)) - { - uint8_t* p = Memory.SDD1LoggedData; - bool found = false; - uint8_t SDD1Bank = Memory.FillRAM [0x4804 + ((d->ABank - 0xc0) >> 4)] | 0xf0; - - for (uint32_t i = 0; i < Memory.SDD1LoggedDataCount; i++, p += 8) - { - if (*p == d->ABank || - *(p + 1) == (d->AAddress >> 8) && - *(p + 2) == (d->AAddress & 0xff) && - *(p + 3) == (count >> 8) && - *(p + 4) == (count & 0xff) && - *(p + 7) == SDD1Bank) - found = true; - } - if (!found && Memory.SDD1LoggedDataCount < MEMMAP_MAX_SDD1_LOGGED_ENTRIES) - { - int j = 0; - while (ptr[j] == buffer[j]) - j++; - - *p = d->ABank; - *(p + 1) = d->AAddress >> 8; - *(p + 2) = d->AAddress & 0xff; - *(p + 3) = j & 0xFF; - *(p + 4) = (j >> 8) & 0xFF; - *(p + 7) = SDD1Bank; - Memory.SDD1LoggedDataCount += 1; - } - } -#endif - } - - else - { -#endif -#if defined(__linux__) || defined (__WIN32__) - void* ptr = bsearch(&address, Memory.SDD1Index, - Memory.SDD1Entries, 12, S9xCompareSDD1IndexEntries); - if (ptr) - in_sdd1_dma = *(uint32_t*)((uint8_t*) ptr + 4) + Memory.SDD1Data; -#else - uint8_t* ptr = Memory.SDD1Index; - - uint32_t e; - for (e = 0; e < Memory.SDD1Entries; e++, ptr += 12) - { - if (address == *(uint32_t*) ptr) - { - in_sdd1_dma = *(uint32_t*)(ptr + 4) + Memory.SDD1Data; - break; - } - } -#endif - - if (!in_sdd1_dma) - { - // No matching decompressed data found. Must be some new - // graphics not encountered before. Log it if it hasn't been - // already. - uint8_t* p = Memory.SDD1LoggedData; - bool found = false; - uint8_t SDD1Bank = Memory.FillRAM [0x4804 + ((d->ABank - 0xc0) >> 4)] | 0xf0; - - uint32_t i; - for (i = 0; i < Memory.SDD1LoggedDataCount; i++, p += 8) - { - if (*p == d->ABank || - ((*(p + 1) == (d->AAddress >> 8)) && - (*(p + 2) == (d->AAddress & 0xff)) && - (*(p + 3) == (count >> 8)) && - (*(p + 4) == (count & 0xff)) && - (*(p + 7) == SDD1Bank))) - { - found = true; - break; - } - } - if (!found && Memory.SDD1LoggedDataCount < MEMMAP_MAX_SDD1_LOGGED_ENTRIES) - { - *p = d->ABank; - *(p + 1) = d->AAddress >> 8; - *(p + 2) = d->AAddress & 0xff; - *(p + 3) = count >> 8; - *(p + 4) = count & 0xff; - *(p + 7) = SDD1Bank; - Memory.SDD1LoggedDataCount += 1; - } - } + in_ptr += d->AAddress; + SDD1_decompress(sdd1_decode_buffer, in_ptr, d->TransferBytes); } -#ifdef SDD1_DECOMP + in_sdd1_dma = sdd1_decode_buffer; } -#endif Memory.FillRAM [0x4801] = 0; } +#endif if (Settings.SPC7110 && (d->AAddress == 0x4800 || d->ABank == 0x50)) { uint32_t i, j; diff --git a/source/memmap.c b/source/memmap.c index 12d65ff..01d0707 100644 --- a/source/memmap.c +++ b/source/memmap.c @@ -1250,9 +1250,6 @@ void InitROM(bool Interleaved) if ((Memory.ROMType & 0xf0) == 0x40) Settings.SDD1 = !Settings.ForceNoSDD1; - if (Settings.SDD1) - S9xLoadSDD1Data(); - if (((Memory.ROMType & 0xF0) == 0xF0) & ((Memory.ROMSpeed & 0x0F) != 5)) { Memory.SRAMSize = 2; @@ -1534,8 +1531,6 @@ bool LoadSRAM(const char* filename) S9xHardResetSRTC(); return (false); } - if (Settings.SDD1) - S9xSDD1LoadLoggedData(); return (true); } @@ -1555,9 +1550,6 @@ bool SaveSRAM(const char* filename) S9xSRTCPreSaveState(); } - if (Settings.SDD1) - S9xSDD1SaveLoggedData(); - if (size > 0x20000) size = 0x20000; diff --git a/source/sdd1.c b/source/sdd1.c index 79b06f6..c61e116 100644 --- a/source/sdd1.c +++ b/source/sdd1.c @@ -89,14 +89,9 @@ #include "snes9x.h" #include "memmap.h" -#include "ppu.h" #include "sdd1.h" #include "display.h" -#ifdef __linux -#include <unistd.h> -#endif - void S9xSetSDD1MemoryMap(uint32_t bank, uint32_t value) { bank = 0xc00 + bank * 0x100; @@ -131,53 +126,3 @@ void S9xSDD1PostLoadState() for (i = 0; i < 4; i++) S9xSetSDD1MemoryMap(i, Memory.FillRAM [0x4804 + i]); } - -static int S9xCompareSDD1LoggedDataEntries(const void* p1, const void* p2) -{ - uint8_t* b1 = (uint8_t*) p1; - uint8_t* b2 = (uint8_t*) p2; - uint32_t a1 = (*b1 << 16) + (*(b1 + 1) << 8) + *(b1 + 2); - uint32_t a2 = (*b2 << 16) + (*(b2 + 1) << 8) + *(b2 + 2); - - return (a1 - a2); -} - -void S9xSDD1SaveLoggedData() -{ - if (Memory.SDD1LoggedDataCount != Memory.SDD1LoggedDataCountPrev) - { - qsort(Memory.SDD1LoggedData, Memory.SDD1LoggedDataCount, 8, - S9xCompareSDD1LoggedDataEntries); - - FILE* fs = fopen(S9xGetFilename("dat"), "wb"); - - if (fs) - { - fwrite(Memory.SDD1LoggedData, 8, - Memory.SDD1LoggedDataCount, fs); - fclose(fs); -#if defined(__linux) - chown(S9xGetFilename("dat"), getuid(), getgid()); -#endif - } - Memory.SDD1LoggedDataCountPrev = Memory.SDD1LoggedDataCount; - } -} - -void S9xSDD1LoadLoggedData() -{ - FILE* fs = fopen(S9xGetFilename("dat"), "rb"); - - Memory.SDD1LoggedDataCount = Memory.SDD1LoggedDataCountPrev = 0; - - if (fs) - { - int c = fread(Memory.SDD1LoggedData, 8, - MEMMAP_MAX_SDD1_LOGGED_ENTRIES, fs); - - if (c != EOF) - Memory.SDD1LoggedDataCount = Memory.SDD1LoggedDataCountPrev = c; - fclose(fs); - } -} - diff --git a/source/sdd1.h b/source/sdd1.h index 52e93b6..a2380c4 100644 --- a/source/sdd1.h +++ b/source/sdd1.h @@ -89,10 +89,10 @@ #ifndef _SDD1_H_ #define _SDD1_H_ + void S9xSetSDD1MemoryMap(uint32_t bank, uint32_t value); void S9xResetSDD1(); void S9xSDD1PostLoadState(); -void S9xSDD1SaveLoggedData(); -void S9xSDD1LoadLoggedData(); + #endif diff --git a/source/sdd1emu.c b/source/sdd1emu.c index cccbf27..4fbfac5 100644 --- a/source/sdd1emu.c +++ b/source/sdd1emu.c @@ -343,115 +343,3 @@ void SDD1_decompress(uint8_t* out, uint8_t* in, int len) break; } } - -static uint8_t cur_plane; -static uint8_t num_bits; -static uint8_t next_byte; - -void SDD1_init(uint8_t* in) -{ - bitplane_type = in[0] >> 6; - - switch (in[0] & 0x30) - { - case 0x00: - high_context_bits = 0x01c0; - low_context_bits = 0x0001; - break; - case 0x10: - high_context_bits = 0x0180; - low_context_bits = 0x0001; - break; - case 0x20: - high_context_bits = 0x00c0; - low_context_bits = 0x0001; - break; - case 0x30: - high_context_bits = 0x0180; - low_context_bits = 0x0003; - break; - } - - in_stream = (in[0] << 11) | (in[1] << 3); - valid_bits = 5; - in_buf = in + 2; - memset(bit_ctr, 0, sizeof(bit_ctr)); - memset(context_states, 0, sizeof(context_states)); - memset(context_MPS, 0, sizeof(context_MPS)); - memset(prev_bits, 0, sizeof(prev_bits)); - - cur_plane = 0; - num_bits = 0; -} - -uint8_t SDD1_get_byte(void) -{ - uint8_t bit; - uint8_t byte = 0; - - switch (bitplane_type) - { - case 0: - num_bits += 16; - if (num_bits & 16) - { - next_byte = 0; - for (bit = 0x80; bit; bit >>= 1) - { - if (GetBit(0)) byte |= bit; - if (GetBit(1)) next_byte |= bit; - } - return byte; - } - else - return next_byte; - - case 1: - num_bits += 16; - if (num_bits & 16) - { - next_byte = 0; - for (bit = 0x80; bit; bit >>= 1) - { - if (GetBit(cur_plane)) byte |= bit; - if (GetBit(cur_plane + 1)) next_byte |= bit; - } - return byte; - } - else - { - if (!num_bits) cur_plane = (cur_plane + 2) & 7; - return next_byte; - } - - case 2: - num_bits += 16; - if (num_bits & 16) - { - next_byte = 0; - for (bit = 0x80; bit; bit >>= 1) - { - if (GetBit(cur_plane)) byte |= bit; - if (GetBit(cur_plane + 1)) next_byte |= bit; - } - return byte; - } - else - { - if (!num_bits) cur_plane ^= 2; - return next_byte; - } - - case 3: - for (cur_plane = 0, bit = 1; bit; bit <<= 1, cur_plane++) - { - if (GetBit(cur_plane)) byte |= bit; - } - return byte; - - default: - /* should never happen */ - return 0; - } -} - diff --git a/source/sdd1emu.h b/source/sdd1emu.h index 5b06e02..695716f 100644 --- a/source/sdd1emu.h +++ b/source/sdd1emu.h @@ -93,7 +93,4 @@ void SDD1_decompress(uint8_t* out, uint8_t* in, int output_length); -void SDD1_init(uint8_t* in); -uint8_t SDD1_get_byte(void); - #endif diff --git a/source/snes9x.h b/source/snes9x.h index e8bc7ba..f201b8f 100644 --- a/source/snes9x.h +++ b/source/snes9x.h @@ -352,7 +352,6 @@ typedef struct uint16_t DisplayColor; int SoundDriver; int AIDOShmId; - bool SDD1Pack; bool NoPatch; bool ForceInterleaveGD24; #ifdef DEBUG_MAXCOUNT |