diff --git a/src/DiskImage.cpp b/src/DiskImage.cpp index 5eb4251..171075f 100644 --- a/src/DiskImage.cpp +++ b/src/DiskImage.cpp @@ -30,6 +30,8 @@ extern "C" #include "rpi-gpio.h" } +extern u32 HashBuffer(const void* pBuffer, u32 length); + unsigned char DiskImage::readBuffer[READBUFFER_SIZE]; static unsigned char compressionBuffer[HALF_TRACK_COUNT * MAX_TRACK_LENGTH]; @@ -144,6 +146,7 @@ void DiskImage::Close() memset(trackLengths, 0, sizeof(trackLengths)); diskType = NONE; fileInfo = 0; + hash = 0; } void DiskImage::DumpTrack(unsigned track) @@ -762,7 +765,9 @@ bool DiskImage::OpenG64(const FILINFO* fileInfo, unsigned char* diskImage, unsig if (memcmp(diskImage, "GCR-1541", 8) == 0) { - //DEBUG_LOG("Is G64\r\n"); + hash = HashBuffer(diskImage, size); + + //DEBUG_LOG("Is G64 %08x\r\n", hash); unsigned char numTracks = diskImage[9]; //DEBUG_LOG("numTracks = %d\r\n", numTracks); diff --git a/src/DiskImage.h b/src/DiskImage.h index a135c16..42a2a7a 100644 --- a/src/DiskImage.h +++ b/src/DiskImage.h @@ -167,6 +167,8 @@ public: bool WriteD64(char* name = 0); bool WriteG64(char* name = 0); + unsigned GetHash() const { return hash; } + private: void CloseD64(); void CloseG64(); @@ -204,6 +206,7 @@ private: unsigned attachedImageSize; DiskType diskType; const FILINFO* fileInfo; + unsigned hash; unsigned short trackLengths[HALF_TRACK_COUNT]; union diff --git a/src/main.cpp b/src/main.cpp index 9433eb6..7585397 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -580,6 +580,24 @@ static bool Snoop(u8 a) return false; } +//-------------------------------------------------------------------------------------- +// This is an implementation of FNV-1a +// (http://www.isthe.com/chongo/tech/comp/fnv/) +//-------------------------------------------------------------------------------------- +u32 HashBuffer(const void* pBuffer, u32 length) +{ + u8* pu8Buffer = (u8*)pBuffer; + u32 hash = 0x811c9dc5U; + + while (length) + { + hash ^= *pu8Buffer++; + hash *= 16777619U; + --length; + } + return hash; +} + EmulatingMode BeginEmulating(FileBrowser* fileBrowser, const char* filenameForIcon) { DiskImage* diskImage = diskCaddy.SelectFirstImage(); @@ -679,7 +697,7 @@ EXIT_TYPE Emulate1541(FileBrowser* fileBrowser) const int headSoundFreq = 1000000 / options.SoundOnGPIOFreq(); // 1200Hz = 1/1200 * 10^6; unsigned char oldHeadDir; int resetCount = 0; - + bool refreshOutsAfterCPUStep = true; unsigned numberOfImages = diskCaddy.GetNumberOfImages(); unsigned numberOfImagesMax = numberOfImages; if (numberOfImagesMax > 10) @@ -707,6 +725,14 @@ EXIT_TYPE Emulate1541(FileBrowser* fileBrowser) //resetWhileEmulating = false; selectedViaIECCommands = false; + u32 hash = pi1541.drive.GetDiskImage()->GetHash(); + // 0x42c02586 = maniac_mansion_s1[lucasfilm_1989](ntsc).g64 + // 0x18651422 = aliens[electric_dreams_1987].g64 + if (hash == 0x42c02586 || hash == 0x18651422) + { + refreshOutsAfterCPUStep = false; + } + while (exitReason == EXIT_UNKNOWN) { @@ -738,7 +764,9 @@ EXIT_TYPE Emulate1541(FileBrowser* fileBrowser) //read32(ARM_SYSTIMER_CLO); //read32(ARM_SYSTIMER_CLO); - IEC_Bus::RefreshOuts1541(); // Now output all outputs. +// IEC_Bus::ReadEmulationMode1541(); + if (refreshOutsAfterCPUStep) + IEC_Bus::RefreshOuts1541(); // Now output all outputs. IEC_Bus::OutputLED = pi1541.drive.IsLEDOn(); if (IEC_Bus::OutputLED ^ oldLED)