Skip to content

Commit

Permalink
Head stepping sounds now work for 1581 mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
pi1541 committed Nov 25, 2018
1 parent e3e25b8 commit 0bbe454
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 13 deletions.
1 change: 1 addition & 0 deletions src/Pi1581.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,5 +295,6 @@ void Pi1581::Insert(DiskImage* diskImage)
// CIA.GetPortB()->SetInput(PORTB_PINS_WPAT, !diskImage->GetReadOnly());
CIA.GetPortA()->SetInput(PORTA_PINS_DISKCHNG, true);
wd177x.Insert(diskImage);
this->diskImage = diskImage;
}

3 changes: 3 additions & 0 deletions src/Pi1581.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ class Pi1581

void Insert(DiskImage* diskImage);

inline const DiskImage* GetDiskImage() const { return diskImage; }

inline bool IsLEDOn() const { return LED; }
inline bool IsMotorOn() const { return wd177x.IsExternalMotorAsserted(); }
inline void SetLED(bool value) { LED = value; }
Expand All @@ -54,6 +56,7 @@ class Pi1581
unsigned int RDYDelayCount;

private:
DiskImage* diskImage;
bool LED;

//u8 Memory[0xc000];
Expand Down
65 changes: 61 additions & 4 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ extern "C"
#include "ssd_logo.h"

unsigned versionMajor = 1;
unsigned versionMinor = 17;
unsigned versionMinor = 18;

// When the emulated CPU starts we execute the first million odd cycles in non-real-time (ie as fast as possible so the emulated 1541 becomes responsive to CBM-Browser asap)
// During these cycles the CPU is executing the ROM self test routines (these do not need to be cycle accurate)
Expand Down Expand Up @@ -853,7 +853,7 @@ EXIT_TYPE Emulate1581(FileBrowser* fileBrowser)
int headSoundFreqCounter = 0;
// const int headSoundFreq = 833; // 1200Hz = 1/1200 * 10^6;
const int headSoundFreq = 1000000 / options.SoundOnGPIOFreq(); // 1200Hz = 1/1200 * 10^6;
unsigned char oldHeadDir;
unsigned int oldTrack;
int resetCount = 0;

unsigned numberOfImages = diskCaddy.GetNumberOfImages();
Expand All @@ -880,6 +880,8 @@ EXIT_TYPE Emulate1581(FileBrowser* fileBrowser)
//resetWhileEmulating = false;
selectedViaIECCommands = false;

oldTrack = pi1581.wd177x.GetCurrentTrack();

while (exitReason == EXIT_UNKNOWN)
{
for (int cycle2MHz = 0; cycle2MHz < 2; ++cycle2MHz)
Expand Down Expand Up @@ -917,7 +919,7 @@ EXIT_TYPE Emulate1581(FileBrowser* fileBrowser)
IEC_Bus::RefreshOuts1581(); // Now output all outputs.
}

if (cycleCount >= FAST_BOOT_CYCLES) // cycleCount is used so we can quickly get through 1541's self test code. This will make the emulated 1541 responsive to commands asap. During this time we don't need to set outputs.
//if (cycleCount >= FAST_BOOT_CYCLES) // cycleCount is used so we can quickly get through 1541's self test code. This will make the emulated 1541 responsive to commands asap. During this time we don't need to set outputs.
{
IEC_Bus::OutputLED = pi1581.IsLEDOn();
if (IEC_Bus::OutputLED ^ oldLED)
Expand All @@ -926,7 +928,21 @@ EXIT_TYPE Emulate1581(FileBrowser* fileBrowser)
oldLED = IEC_Bus::OutputLED;
}

//IEC_Bus::RefreshOuts1581(); // Now output all outputs.
// Do head moving sound
unsigned int track = pi1581.wd177x.GetCurrentTrack();
if (track != oldTrack) // Need to start a new sound?
{
oldTrack = track;
if (options.SoundOnGPIO())
{
headSoundCounter = 1000 * options.SoundOnGPIODuration();
headSoundFreqCounter = headSoundFreq;
}
else
{
PlaySoundDMA();
}
}
}


Expand Down Expand Up @@ -975,6 +991,47 @@ EXIT_TYPE Emulate1581(FileBrowser* fileBrowser)
}
ctBefore = ctAfter;

if (options.SoundOnGPIO() && headSoundCounter > 0)
{
headSoundFreqCounter--; // Continue updating a GPIO non DMA sound.
if (headSoundFreqCounter <= 0)
{
headSoundFreqCounter = headSoundFreq;
headSoundCounter -= headSoundFreq * 8;
IEC_Bus::OutputSound = !IEC_Bus::OutputSound;
}
}

if (numberOfImages > 1)
{
bool nextDisk = inputMappings->NextDisk();
bool prevDisk = inputMappings->PrevDisk();
if (nextDisk)
{
pi1581.Insert(diskCaddy.PrevDisk());
}
else if (prevDisk)
{
pi1581.Insert(diskCaddy.NextDisk());
}
else if (inputMappings->directDiskSwapRequest != 0)
{
for (caddyIndex = 0; caddyIndex < numberOfImagesMax; ++caddyIndex)
{
if (inputMappings->directDiskSwapRequest & (1 << caddyIndex))
{
DiskImage* diskImage = diskCaddy.SelectImage(caddyIndex);
if (diskImage && diskImage != pi1581.GetDiskImage())
{
pi1581.Insert(diskImage);
break;
}
}
}
inputMappings->directDiskSwapRequest = 0;
}
}

}
return exitReason;
}
Expand Down
9 changes: 0 additions & 9 deletions src/wd177x.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@

extern Pi1581 pi1581;

extern bool bLoggingCYCs;
int stepcount = 0;
int racount = 0;

// Clocks
// Master 16Mhz
// into 74ls93
Expand Down Expand Up @@ -1198,8 +1194,6 @@ void WD177x::Write(unsigned int address, unsigned char value)

// An interrupt is generated at the completion of the command.
stepDirection = -1;
stepcount++;
//DEBUG_LOG("STEP OUT %d\r\n", stepcount);

commandType = 1;
break;
Expand Down Expand Up @@ -1256,9 +1250,6 @@ void WD177x::Write(unsigned int address, unsigned char value)

readAddressState = SEARCHING_FOR_NEXT_ID;

racount++;
//DEBUG_LOG("READ_ADDRESS %d\r\n", racount);

commandType = 3;
break;

Expand Down

0 comments on commit 0bbe454

Please sign in to comment.