Updated the Sound class so it has a new set method which also takes as an

argument the number of CPU cycles elapsed since the last TIA sound update.
The default implementation of this method invokes the old set method for
backwards compatibility with derived classes.

This new set method will be used in the 1.3 release to improve the quality
of the sound emulation (e.g., to support games like Pitfall II which update
the sound registers many times during a frame).

The TIA class was updated to invoke the new set method of the Sound class.
Finally, the TIA pauseState data member was renamed to myPauseState to be
consistent with the other data members.


git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@55 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
bwmott 2002-03-28 02:02:24 +00:00
parent e24dd2c994
commit 36ed979ece
4 changed files with 82 additions and 34 deletions

View File

@ -8,12 +8,12 @@
// SS SS tt ee ll ll aa aa // SS SS tt ee ll ll aa aa
// SSSS ttt eeeee llll llll aaaaa // SSSS ttt eeeee llll llll aaaaa
// //
// Copyright (c) 1995-1998 by Bradford W. Mott // Copyright (c) 1995-2002 by Bradford W. Mott
// //
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: Sound.cxx,v 1.1.1.1 2001-12-27 19:54:23 bwmott Exp $ // $Id: Sound.cxx,v 1.2 2002-03-28 02:02:24 bwmott Exp $
//============================================================================ //============================================================================
#include "Sound.hxx" #include "Sound.hxx"
@ -29,7 +29,15 @@ Sound::~Sound()
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Sound::set(Sound::Register, uInt8) void Sound::set(Sound::Register r, uInt8 v, uInt32)
{
// For backwards compatibility we invoke the two argument version of this
// method. This should keep all of the old derived sound classes happy.
set(r, v);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Sound::set(Sound::Register r, uInt8 v)
{ {
// This sound class doesn't do anything when a register is set // This sound class doesn't do anything when a register is set
// since we're not handling sound // since we're not handling sound

View File

@ -8,12 +8,12 @@
// SS SS tt ee ll ll aa aa // SS SS tt ee ll ll aa aa
// SSSS ttt eeeee llll llll aaaaa // SSSS ttt eeeee llll llll aaaaa
// //
// Copyright (c) 1995-1998 by Bradford W. Mott // Copyright (c) 1995-2002 by Bradford W. Mott
// //
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: Sound.hxx,v 1.1.1.1 2001-12-27 19:54:23 bwmott Exp $ // $Id: Sound.hxx,v 1.2 2002-03-28 02:02:24 bwmott Exp $
//============================================================================ //============================================================================
#ifndef SOUND_HXX #ifndef SOUND_HXX
@ -27,7 +27,7 @@
for a specific operating system. for a specific operating system.
@author Bradford W. Mott @author Bradford W. Mott
@version $Id: Sound.hxx,v 1.1.1.1 2001-12-27 19:54:23 bwmott Exp $ @version $Id: Sound.hxx,v 1.2 2002-03-28 02:02:24 bwmott Exp $
*/ */
class Sound class Sound
{ {
@ -53,8 +53,19 @@ class Sound
public: public:
/** /**
Set the value of the specified sound register Set the value of the specified sound register.
@param reg The sound register to set
@param val The new value for the sound register
@param cycles The number of elapsed CPU cycles since the last set
*/
virtual void set(Sound::Register reg, uInt8 val, uInt32 cycles);
/**
Set the value of the specified sound register. This method is being
kept for backwards compatibility. There's a good chance it will be
removed in the 1.3 release of Stella as the sound system is overhauled.
@param reg The sound register to set @param reg The sound register to set
@param val The new value for the sound register @param val The new value for the sound register
*/ */

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: TIA.cxx,v 1.8 2002-03-18 14:38:34 gunfight Exp $ // $Id: TIA.cxx,v 1.9 2002-03-28 02:02:24 bwmott Exp $
//============================================================================ //============================================================================
#include <assert.h> #include <assert.h>
@ -31,13 +31,14 @@
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
TIA::TIA(const Console& console, Sound& sound) TIA::TIA(const Console& console, Sound& sound)
: myConsole(console) : myConsole(console),
,mySound(sound) mySound(sound),
,myCOLUBK(myColor[0]) myPauseState(false),
,myCOLUPF(myColor[1]) myLastSoundUpdateCycle(0),
,myCOLUP0(myColor[2]) myCOLUBK(myColor[0]),
,myCOLUP1(myColor[3]) myCOLUPF(myColor[1]),
,pauseState(false) myCOLUP0(myColor[2]),
myCOLUP1(myColor[3])
{ {
// Allocate buffers for two frame buffers // Allocate buffers for two frame buffers
myCurrentFrameBuffer = new uInt8[160 * 300]; myCurrentFrameBuffer = new uInt8[160 * 300];
@ -111,6 +112,9 @@ const char* TIA::name() const
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void TIA::reset() void TIA::reset()
{ {
// Reset sound cycle indicator
myLastSoundUpdateCycle = 0;
// Clear frame buffers // Clear frame buffers
for(uInt32 i = 0; i < 160 * 300; ++i) for(uInt32 i = 0; i < 160 * 300; ++i)
{ {
@ -219,6 +223,9 @@ void TIA::systemCyclesReset()
// Get the current system cycle // Get the current system cycle
uInt32 cycles = mySystem->cycles(); uInt32 cycles = mySystem->cycles();
// Adjust the sound cycle indicator
myLastSoundUpdateCycle -= cycles;
// Adjust the dump cycle // Adjust the dump cycle
myDumpDisabledCycle -= cycles; myDumpDisabledCycle -= cycles;
@ -264,8 +271,10 @@ void TIA::install(System& system)
void TIA::update() void TIA::update()
{ {
// Don't do an update if the emulator is paused // Don't do an update if the emulator is paused
if(pauseState) if(myPauseState)
{
return; return;
}
uInt8* tmp = myCurrentFrameBuffer; uInt8* tmp = myCurrentFrameBuffer;
myCurrentFrameBuffer = myPreviousFrameBuffer; myCurrentFrameBuffer = myPreviousFrameBuffer;
@ -303,16 +312,20 @@ void TIA::update()
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool TIA::pause(bool state) bool TIA::pause(bool state)
{ {
// Ignore multiple calls to do the same thing if(myPauseState == state)
if(pauseState == state) {
// Ignore multiple calls to do the same thing
return false; return false;
}
else
{
myPauseState = state;
pauseState = state; // Propagate the pause state to the sound object
mySound.mute(myPauseState);
// Now pause the Sound device return true;
mySound.mute(pauseState); }
return true;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -2079,37 +2092,49 @@ void TIA::poke(uInt16 addr, uInt8 value)
case 0x15: // Audio control 0 case 0x15: // Audio control 0
{ {
mySound.set(Sound::AUDC0, value); mySound.set(Sound::AUDC0, value,
mySystem->cycles() - myLastSoundUpdateCycle);
myLastSoundUpdateCycle = mySystem->cycles();
break; break;
} }
case 0x16: // Audio control 1 case 0x16: // Audio control 1
{ {
mySound.set(Sound::AUDC1, value); mySound.set(Sound::AUDC1, value,
mySystem->cycles() - myLastSoundUpdateCycle);
myLastSoundUpdateCycle = mySystem->cycles();
break; break;
} }
case 0x17: // Audio frequency 0 case 0x17: // Audio frequency 0
{ {
mySound.set(Sound::AUDF0, value); mySound.set(Sound::AUDF0, value,
mySystem->cycles() - myLastSoundUpdateCycle);
myLastSoundUpdateCycle = mySystem->cycles();
break; break;
} }
case 0x18: // Audio frequency 1 case 0x18: // Audio frequency 1
{ {
mySound.set(Sound::AUDF1, value); mySound.set(Sound::AUDF1, value,
mySystem->cycles() - myLastSoundUpdateCycle);
myLastSoundUpdateCycle = mySystem->cycles();
break; break;
} }
case 0x19: // Audio volume 0 case 0x19: // Audio volume 0
{ {
mySound.set(Sound::AUDV0, value); mySound.set(Sound::AUDV0, value,
mySystem->cycles() - myLastSoundUpdateCycle);
myLastSoundUpdateCycle = mySystem->cycles();
break; break;
} }
case 0x1A: // Audio volume 1 case 0x1A: // Audio volume 1
{ {
mySound.set(Sound::AUDV1, value); mySound.set(Sound::AUDV1, value,
mySystem->cycles() - myLastSoundUpdateCycle);
myLastSoundUpdateCycle = mySystem->cycles();
break; break;
} }

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: TIA.hxx,v 1.2 2002-03-17 19:37:00 stephena Exp $ // $Id: TIA.hxx,v 1.3 2002-03-28 02:02:24 bwmott Exp $
//============================================================================ //============================================================================
#ifndef TIA_HXX #ifndef TIA_HXX
@ -38,7 +38,7 @@ class System;
be displayed on screen. be displayed on screen.
@author Bradford W. Mott @author Bradford W. Mott
@version $Id: TIA.hxx,v 1.2 2002-03-17 19:37:00 stephena Exp $ @version $Id: TIA.hxx,v 1.3 2002-03-28 02:02:24 bwmott Exp $
*/ */
class TIA : public Device , public MediaSource class TIA : public Device , public MediaSource
{ {
@ -197,6 +197,13 @@ class TIA : public Device , public MediaSource
// Sound object used by the TIA // Sound object used by the TIA
Sound& mySound; Sound& mySound;
// Indicates whether the emulation is paused or not
bool myPauseState;
private:
// Indicates the CPU cycle when a TIA sound register was last updated
Int32 myLastSoundUpdateCycle;
private: private:
// Pointer to the current frame buffer // Pointer to the current frame buffer
uInt8* myCurrentFrameBuffer; uInt8* myCurrentFrameBuffer;
@ -426,8 +433,5 @@ class TIA : public Device , public MediaSource
// Assignment operator isn't supported by this class so make it private // Assignment operator isn't supported by this class so make it private
TIA& operator = (const TIA&); TIA& operator = (const TIA&);
// Indicates whether the current emulation cycle should is paused
bool pauseState;
}; };
#endif #endif